; ; Simple array based entity system ; .equ ET_NONE 0 .equ ET_PLAYER 1 .equ ET_ENEMY 2 .equ ET_END 0xff .equ ET_BG 0xa000 entities_erase: ; bg is stored in ET_BG addr ld b, >ET_BG push b ld x, entities entities_erase_next: ld y, [a : x] cmp y, ET_END bz jmp entities_erase_done ; settings mode ld y, 128 ld b, 0xb0 port b, y ; setup inc b ; addr: bg data ld y, 0 port b, y ld y, [sp + 0] port b, y ; x inc x bo inc a ld y, [a : x] port b, y ; y inc x bo inc a ld y, [a : x] port b, y ; 16x16 ld y, 16 port b, y port b, y ; blit dec b ; write, no transparent ld y, 1 port b, y ; next entity add x, 6 bo inc a pop b inc b push b jmp entities_erase_next entities_erase_done: pop a ret entities_update: ld x, entities entities_update_next: ld y, [a : x] cmp y, ET_END bz ret push a push x add x, 6 bo inc a ld y, [a : x] inc x bo inc a ld b, [a : x] inc x bo inc a ld x, [sp + 0] ld a, [sp + 1] ; entity update push a push x call [b : y] pop x pop x pop x pop a ; next entity add x, 8 bo inc a jmp entities_update_next entities_draw: ; bg is stored in ET_BG addr ld b, >ET_BG push b ld x, entities entities_draw_next: ld y, [a : x] cmp y, ET_END bz jmp entities_draw_done ; two local variables to keep x, y coord inc x bo inc a ld y, [a : x] ; x coord push y inc x bo inc a ld y, [a : x] ; y coord push y inc x bo inc a ; a : x points to the frame ; save bg data ; settings mode ld y, 128 ld b, 0xb0 port b, y ; setup inc b ; addr: bg data saving space ld y, 0 port b, y ld y, [sp + 2] port b, y ; x ld y, [sp + 1] port b, y ; y ld y, [sp + 0] port b, y ; 16x16 ld y, 16 port b, y port b, y ; blit dec b ; read, no transparent ld y, 4 port b, y ; draw sprite ; settings mode ld y, 128 ld b, 0xb0 port b, y ; setup inc b ; prepare some local variables ; frame ld y, [a : x] inc x bo inc a push y ; sprite addr ld y, [a : x] push y inc x bo inc a ld y, [a : x] push y ; frame number ld b, [sp + 2] entity_draw_frame: dec b bo jmp entity_draw_frame_done ; calculate frame ld y, [sp + 0] inc y ld [sp + 0], y jmp entity_draw_frame entity_draw_frame_done: ; settings port ld b, 0xb1 ; addr: sprite data ld y, [sp + 1] port b, y ld y, [sp + 0] port b, y ; free local variables pop y pop y pop y ; x ld y, [sp + 1] port b, y ; y ld y, [sp + 0] port b, y ; 16x16 ld y, 16 port b, y port b, y ; blit dec b ; write, transparent ld y, 3 port b, y pop y pop y ; next entity add x, 3 bo inc a pop b inc b push b jmp entities_draw_next entities_draw_done: pop a ret