Can this be done to wait VSYNC?

Page 2/2
1 |

By NYYRIKKI

Enlighted (6016)

NYYRIKKI's picture

11-04-2014, 22:05

No, MSX usually does not generate more than VDP interrupt when powered on. ie. to enable tR MIDI-interupts, you have to execute CALL MUSIC from BASIC or do something similar.

To make your program to work with extra interrupts, use this routine instead:


JIFFY:	ORG #FC9E

loop:
  ... Do the work here ...
  ei
  ld hl,JIFFY
  ld a,(hl)
wait:
  cp (hl)
  jr z,wait
  jp loop

JIFFY is same thing as TIME in BASIC.

By hit9918

Prophet (2927)

hit9918's picture

11-04-2014, 22:18

it maybe should be mentioned that it is no hardware counter, but updated by bios in interrupt.
when doing the fd9a patch with IN 0x99 consumption, that counter stops.
then do an own counter and the rest works same.

By hit9918

Prophet (2927)

hit9918's picture

11-04-2014, 22:34

and when the game is not speed critical, can go without interrupt servers and IN 99 stories and run nyyrikkis example out of the box.
but then turn off bios key click Smile

By NYYRIKKI

Enlighted (6016)

NYYRIKKI's picture

11-04-2014, 22:40

hit9918 wrote:

it maybe should be mentioned that it is no hardware counter, but updated by bios in interrupt.
when doing the fd9a patch with IN 0x99 consumption, that counter stops.
then do an own counter and the rest works same.

True... and if you do something like that then you have other problems to take care as well... such as keyboard not working.

By Grauw

Ascended (10699)

Grauw's picture

12-04-2014, 01:10

I would either set up a timer interrupt hook, or simply poll if JIFFY changes.

By DarkSchneider

Paladin (965)

DarkSchneider's picture

12-04-2014, 11:18

So JIFFY is updated on each interrupt if I have understood well. Then wait like in my method #2 in safe way using JIFFY.

By DarkSchneider

Paladin (965)

DarkSchneider's picture

12-04-2014, 12:54

Could it be modified to this?

JIFFY:	ORG #FC9E

loop:
  ... Do the work here ...
  ei
  ld hl,JIFFY
  ld a,(hl)
wait:
  halt ; this is new
  cp (hl)
  jr z,wait
  jp loop

With a halt so the CPU rests a bit Big smile
So we halt and if there is and interrupt but not the VDP one we return and wait again.

By DarkSchneider

Paladin (965)

DarkSchneider's picture

13-04-2014, 10:41

Well I think finally got the desired, here 2 methods:

With this one, if loop period is lesser than v-period it waits, if greater then starts the next loop iterarion immediately. That is the most similar I can think for Dynamic VSYNC.

JIFFY:	ORG #FC9E
loop
  ld hl,(JIFFY) ; copy JIFFY
  ld (jiffystart),hl ; to jiffystart
  ... Do the work here ...
  ei
  ld hl,JIFFY ; JIFFY is updated by BIOS on each VDP interrupt, as is it used by PLAY command for sync
  ld a,(jiffystart)  ; compare with the jiffystart not its current value
  jr $+1 ; the first iteration do not wait with halt
wait:
  halt
  cp (hl)
  jr z,wait

  jp loop

With this one, is like the previous but you can set a frameskip, so if you see that your loop rarely will run at full fps, then skip 1 or more frames per loop to get a more constant speed.

JIFFY:	ORG #FC9E
loop
  ld hl,(JIFFY) ; copy JIFFY
  ld (jiffystart),hl ; to jiffystart
  ... Do the work here ...
  ei
  ld hl,JIFFY ; JIFFY is updated by BIOS on each VDP interrupt, as is it used by PLAY command for sync
  ld a,(jiffystart) ; compare with the jiffystart not its current value
  add a,1 ; set the frameskip full/(#+1), so 1 is 30 fps
  jr $+1 ; the first iteration do not wait with halt
wait:
  halt ; maybe improved?, if it does rare things, remove this halt
  cp (hl)
  jp p,wait ; if JIFFY not reaches jiffystart+frameskip, wait again
  jr z,wait
  
  jp loop
Page 2/2
1 |