Skip to content

Instantly share code, notes, and snippets.

@2Tie
Created January 5, 2024 21:08
Show Gist options
  • Save 2Tie/d3738f50d4389fa7fdb25df0e3869171 to your computer and use it in GitHub Desktop.
Save 2Tie/d3738f50d4389fa7fdb25df0e3869171 to your computer and use it in GitHub Desktop.
sega mkiii tstate synchronizer
;let's try synching up with a cycle
syncloop:
in a, ($7E) ;11
cp 60 ;18
push af ;28
pop af ;39
ld d, a ;43
nop ;47
jp nz, syncloop ;57 (1/4 a scanline)
first: ;now guarantee the start of next scanline
in a, ($7E) ;11
push af ;22
pop af ;32
nop ;36
cp 0 ;43
cp d ;47
jp z, first ;57 (1/4 a scanline)
call waste153 ;210
dec de ;216
ld d, a ;220
nop
nop
lag:
in a, ($7E) ; 11
nop ; 15
call waste132 ;147
push af
pop af ;168
push af
pop af ;189
nop ;193
nop
nop ;201
nop
nop ;209
cp d ;213
ld d, a ;217
jp nz, lag ;227
;otherwise, we are now -1 at the cycle!
call waste153 ;152
call waste48 ;200
push af
pop af ;221
cp 0 ;228
nop
nop ;15 extra is fine?
nop ;16 is too much
;add more delay here after work??
;now let's wait until a certain scanline to start playback
loopStart:
in a, ($7E) ;11
cp 190 ;18
push af ;28 - ?
pop af ;39
nop
nop
jp nz, loopStart ;57
;need to sync up with s3end at 101
push af
pop af ; 78
cp 0 ; 85
dec de ; 91
jp s3end ;101
waste153: ;17
push af
pop af ;38
waste132:
push af
pop af ;59
push af
pop af ;80
push af
pop af ;101
push af
pop af ;122
waste48:
push af
pop af ;143
ret ;153
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment