Gilbert Francois Duivesteijn

If you want your program to run something in sync with the refresh rate of the screen, you can use the vblank interrupt. The way to call your function at the interrupt is to use the hook which is a fixed memory address, where 5 bytes are reserved for every hook. Normally they are filled with RET but you can replace these bytes with e.g. a JP addr command that points to your function.
This page MSX Wiki: System hooks gives an overview of all possible hooks.
A recommended way to use hooks is:
jp addr instruction at the place of the hook, pointing to your subroutine. End the hook with ret instructions.jp old_hook_address command.The example below is a minimal example, that gives a BEEP every second on a 50Hz machine. The HTIMI hook is used, which is triggered at the refresh rate of the screen (VBLANK).
x
; Simple interrupt test
; ==[ Constants ]===============================================
ORGADR equ $c000BEEP equ $00c0 ; Bios function, generates beepHTIMI equ $fd9f ; Interrupt hook address, triggered at vblankMaxCount equ 50
; ==[ Header ]==================================================
; Place header before the binary. org ORGADR - 7 ; BIN header, 7 bytes db $fe dw FileStart dw FileEnd - 1 dw Main ; ==[ Program ]=================================================
; org statement after the header org ORGADR
FileStart:Main: ; Install hook, run once di ; Preserve old hook instructions ld de, OldHook ld hl, HTIMI ld bc, 5 ldir ; Copy new hook instructions ld hl, NewHook ld de, HTIMI ld bc, 5 ldir
ei
; Return to Basic ret
NewHook: jp BeepFn ret nop
OldHook: ; Reserve 5 bytes to store the old hook db 0, 0, 0, 0, 0
BeepFn: ; Run at every interrupt ld hl, Counter dec (hl) ld a, (hl) jp nz, OldHook ; Reset counter and call BEEP ld (hl), MaxCount call BEEP
Counter: db MaxCount
FileEnd:Compile with VASM
xxxxxxxxxx$ vasmz80_oldstyle beep.asm -chklabels -nocase -Dvasm=1 -Fbin -L out.sym -o out.binor with Glass
xxxxxxxxxx$ java -jar Glass.jar beep.asm -L out.sym out.binOn the MSX, load and run with:
xxxxxxxxxxbload"out.bin",r