Reply 20 of 63, by Scali
This is the code in the sprite part that synchronizes the drawing of the sprite with the beam position.
It does this by setting up the timer interrupt at 60 Hz (19912 ticks), synchronized to the vertical blank interval.
This means that the counter starts at 19912 ticks for a frame, and counts down to 0 as the beam travels over the screen. Each scanline takes exactly 76 ticks.
So, we know our sprite position, and we know how high the sprite is, so we can determine at which scanline the sprite is drawn by the beam. And then we can calculate the counter value at that scanline.
So we wait for the counter to reach that point.
This is the code, the expected counter value is in dx:
@@waitRaster:
mov al, 00000000b ; al = channel in bits 6 and 7, remaining bits clear
out 043h, al ; Send the latch command
in al, 040h ; al = low byte of count
mov ah, al ; ah = low byte of count
in al, 040h ; al = high byte of count
xchg al, ah ; al = low byte, ah = high byte (ax = current count)
cmp ax, dx
ja @@waitRaster
It looks like your counter is somehow not working properly, so it never exits the loop (the counter also triggers an interrupt at 60 Hz, and the music replayer is in there, so it will continue to play music during this wait-loop).