Jump to content
IGNORED

CC65 - WSYNC - work each frame


Recommended Posts

Is there a built in CC65 routine to wait uppon WSYNC event?

 

i saw a method called waitvsync() which is exactly what i was looking for but it is not supported in Atari CC65

 

i also saw some threads for comparing ANTIC.vcount with something to determine if a WSYNC has occured.

 

want to use an already tested and proved built in routine

 

thanks

Link to comment
Share on other sites

You can just write any value to WSYNC:

 

  __asm__ ("sta $D40A");

If you want to guarantee the next instruction starts on exactly cycle 105, then you can INC WSYNC as long as you know the INC will occur complete by cycle 103:

 

  __asm__ ("inc $D40A");

Altirra Hardware Reference Manual exceprt:

 

4.9 WSYNC

A write to WSYNC [D40A] halts CPU execution until the end of a scan line, allowing the CPU to synchronize to the display.

  • Like 1
Link to comment
Share on other sites

Rereading your message, looks like you may be mixing terms. WSYNC is for scan line synchronization while VSYNC and VCOUNT would be for vertical blank synchronization.

 

What is your use case?

 

If you just want to wait for the vertical blank, then you can loop on RTCLOK:

 

  char *jiffies, prev;
  jiffies = (char*)20;

  prev = *jiffies;
  while (prev == *jiffies) ;

  /* synced to vblank here */
  • Like 1
Link to comment
Share on other sites

So, indeed I was referring to vblank as i wish to do the main loop thing on each frame

I was looking for a built in solution in CC65 but couldnt find one.

All the suggested above I am familiar with

Another idea is to compare ANTIC.vcount to 124 and by that identify that vcount has occur

So was looking for something that was already written and tested in C (CC65)

Link to comment
Share on other sites

Utilise either of the Immediate or Deferred Vblank hooks:

#include <atari.h>
 
#define SETVBV 0xE45C
#define SYSVBV 0xE45F
 
void MyVbi()
{
    OS.color4++;
    asm("jmp %w", SYSVBV);
}
 
void SetVbi()
{
    asm("ldx #>%v", MyVbi);
    asm("ldy #<%v", MyVbi);
    asm("lda #6");
    asm("jsr %w", SETVBV);
}
 
int main()
{
    SetVbi();
    while (1);
    return 0;
}


Those system vectors are probably a good candidate for adding into _atarios.h

Link to comment
Share on other sites

Those system vectors are probably a good candidate for adding into _atarios.h

 

Maybe it's important to mention that the code of your "MyVbi"-function is restricted in using C functionality.

Accessing the C-stack as well as many library function will break the main-land program - so to make the usage somewhat safe I would prefer a more "prepared"-way to offer IRQ-"sub-routines".

Link to comment
Share on other sites

Indeed, keeping it simple within the VBI is wise.No harm in calling functions with no arguments and void return if you need to break things into manageable steps.

 

You can also include call-outs to asm routines, for example the RMT player's VB play routine. The VB interrupt is already covered by pushing the registers which are restored if exited properly.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...