Jump to content

Photo

CC65 - WSYNC - work each frame


8 replies to this topic

#1 Yaron Nir OFFLINE  

Yaron Nir

    Chopper Commander

  • 125 posts

Posted Sat Apr 13, 2019 3:55 AM

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



#2 Xuel OFFLINE  

Xuel

    Dragonstomper

  • 747 posts
  • Location:US

Posted Sat Apr 13, 2019 9:18 AM

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.

#3 flashjazzcat ONLINE  

flashjazzcat

    Quadrunner

  • 14,497 posts
  • Location:United Kingdom

Posted Sat Apr 13, 2019 9:35 AM

I suspect you want to wait for the end of a frame:

	WaitForSync:
Loop1:
	lda VCount
	bne Loop1:
Loop2:
	lda VCount
	beq Loop2:
	rts


#4 Xuel OFFLINE  

Xuel

    Dragonstomper

  • 747 posts
  • Location:US

Posted Sat Apr 13, 2019 9:40 AM

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 */


#5 Yaron Nir OFFLINE  

Yaron Nir

    Chopper Commander

  • Topic Starter
  • 125 posts

Posted Sat Apr 13, 2019 11:21 AM

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)

#6 Wrathchild ONLINE  

Wrathchild

    River Patroller

  • 2,189 posts
  • Location:Reading, UK.

Posted Sat Apr 13, 2019 5:13 PM

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



#7 Yaron Nir OFFLINE  

Yaron Nir

    Chopper Commander

  • Topic Starter
  • 125 posts

Posted Sun Apr 14, 2019 1:22 PM

Wrathchild Tnx
Maybe you can contribute and add it to atarios?

#8 Irgendwer OFFLINE  

Irgendwer

    Stargunner

  • 1,462 posts
  • Location:Germany

Posted Sun Apr 14, 2019 2:49 PM

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".



#9 Wrathchild ONLINE  

Wrathchild

    River Patroller

  • 2,189 posts
  • Location:Reading, UK.

Posted Sun Apr 14, 2019 3:57 PM

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.






0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users