; ; example.asm for TR8 ; .org 0 ; address of the frame interrupt vector .equ INT_VECT 0xff00 ; setup an int handler so we ; can use the frame interrupt to sync ; and play sounds in background ld a, >INT_VECT ld x, int_handler ld [a : x], b ; enable interrupts cif ld b, 0 loop: call fill_screen push b ; update sprite position ld a, >incx ld x, px ld x, incx ld x, incy ld x, py ld x, incy ld x, -1 ; -1 -> 1 ld y, [a : x] ld b, 254 xor y, b ld [a : x], y ; change color ld b, [sp + 2] inc b and b, 15 ld [sp + 2], b ; play an effect when we turn ; alternating two sounds ld x, effect ld y, [a : x] xor y, 3 ld [a : x], y call sound_queue_effect ret ; ; fill frame-buffer ; ; in: reg b color fill_screen: ld a, 0xbf ld x, 0 ld y, 0x40 fill_loop: ld [a : x], b inc x bno jmp fill_loop inc a dec y bnz jmp fill_loop ret ; ; Draw the sprite ; ; in: coordinates in px, py draw_sprite: ; blitter in settings mode ld x, 128 ld a, 0xb0 port a, x ; setup inc a ; source ld x, sprite port a, x ; destination ld y, px ld x, [b : y] port a, x ld y, py ld x, [b : y] port a, x ; size 16x16 ld x, 16 port a, x port a, x ; now blit dec a ld x, 3 ; 3: write with transparent color support port a, x ret sprite: .incpng "assets/icon.png" incx: .db 1 px: .db 18 incy: .db 1 py: .db 64 effect: .db 1 ; ; Our int handler plays / stops sounds ; int_handler: push a push b push x push y call sound_play pop y pop x pop b pop a iret ; ; Queue a sound effect to be played ; ; in: y sound index (1 based) sound_queue_effect: ; can't be interrupted sif ld a, >sound_efx ld x, sound_queue ld y, sound_queue ld y, sound_queue ld y,