; ; Simple array based entity system ; .equ ET_NONE 0 .equ ET_PLAYER 1 .equ ET_ENEMY 2 .equ ET_BULLET 3 .equ ET_END 0xff .equ ET_BG 0xa000 entities_init: ld x, entities ; skip player add x, 8 bo inc a entities_init_next: ld y, [a : x] cmp y, ET_END bz ret ld y, ET_NONE ld [a : x], y add x, 8 bo inc a jmp entities_init_next entities_erase: ld x, entities entities_erase_next: ld y, [a : x] cmp y, ET_END bz ret cmp y, 0 bnz jmp entities_erase_in_use add x, 8 bo inc a jmp entities_erase_next entities_erase_in_use: ; settings mode ld y, 128 ld b, 0xb0 port b, y ; setup inc b ; addr: bg data ld y, ET_BG 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 jmp entities_erase_next entities_update: ld x, entities entities_update_next: ld y, [a : x] cmp y, ET_END bz ret cmp y, 0 bnz jmp entities_update_in_use add x, 8 bo inc a jmp entities_update_next entities_update_in_use: 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: ld x, entities entities_draw_next: ld y, [a : x] cmp y, ET_END bz ret cmp y, 0 bnz jmp entities_draw_in_use add x, 8 bo inc a jmp entities_draw_next entities_draw_in_use: ; draw sprite ; settings mode ld y, 128 ld b, 0xb0 port b, y ; setup inc b push a push x add x, 3 bo inc a ; frame number ld b, [a : x] inc x bo inc a ; sprite addr ld y, [a : x] push y inc x bo inc a ld y, [a : x] entity_draw_frame: dec b bo jmp entity_draw_frame_done ; calculate frame inc y jmp entity_draw_frame entity_draw_frame_done: ; settings port ld b, 0xb1 ld x, y pop y ; addr: sprite data port b, y port b, x pop x pop a inc x bo inc a ; x ld y, [a : x] port b, y inc x bo inc a ; y ld y, [a : x] port b, y ; 16x16 ld y, 16 port b, y port b, y ; blit dec b ; write, transparent ld y, 3 port b, y ; next entity add x, 6 bo inc a jmp entities_draw_next entities_new: ld x, entities entities_new_loop: ld y, [a : x] cmp y, ET_END ccf bz ret cmp y, 0 bz jmp entities_new_found add x, 8 bo inc a jmp entities_new_loop entities_new_found: scf ret