.org 0 .equ INT_VECTOR 0xff00 call init ; ; Menu entry point ; menu: call clear_screen menu_loop: halt call stars_update call menu_draw ; read controller 1 ld b, 0xf0 port b, b ; start bit b, 7 bnz jmp menu_loop ; ; Gameplay entry point ; play: call init_game game_loop: halt call entities_erase call stars_update call entities_update call entities_draw call update_hud ; read controller 1 ld b, 0xf0 port b, b ; select to exit bit b, 6 bnz jmp game_loop jmp menu ; ; Setup the game after the menu ; init_game: call entities_init ; set player initial coordinates ld x, player_coord ld y, 56 ld [a : x], y inc x bo inc a ld y, 104 ld [a : x], y ; clear score ld x, score ld y, 6 ld b, 0 init_score_loop: ld [a : x], b dec y bnz jmp init_score_loop halt call clear_screen call entities_draw ret update_hud: ; 6 digits ld x, 6 push x ; addr of the BCD number ld x, score ; where we want the text ld b, 100 ld y, 4 call put_bcd_number pop x ret ; ; Helper to clear the screen ; clear_screen: ; erase the screen ld b, 0 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 ; ; Draws the menu ; menu_draw: ; hiscore ld x, hiscore_text ld b, 44 ld y, 10 call put_text ; 6 digits ld x, 6 push x ; addr of the BCD number ld x, hiscore ; where we want the text ld b, 60 ld y, 10 call put_bcd_number pop x ; settings mode ld y, 128 ld b, 0xb0 port b, y ; setup inc b ; addr: title sprite ld y, title port b, y ; x ld y, 26 port b, y ; y ld y, 40 port b, y ld y, 76 port b, y ld y, 21 port b, y ; blit dec b ; write, transparent ld y, 3 port b, y ld x, <press_start_text ld a, >press_start_text ld b, 40 ld y, 84 call put_text ; settings mode ld y, 128 ld b, 0xb0 port b, y ; setup inc b ; addr: usebox logo sprite ld y, <usebox port b, y ld y, >usebox port b, y ; x ld y, 44 port b, y ; y ld y, 118 port b, y ld y, 40 port b, y ld y, 8 port b, y ; blit dec b ; write, transparent ld y, 3 port b, y ret ; ; Init the TR8 (setup an int handler) ; init: ; setup an int handler so we ; can use the frame int to sync ld a, >INT_VECTOR ld x, <INT_VECTOR ld b, <int_handler ld [a : x], b inc x ld b, >int_handler ld [a : x], b ; enable interrupts cif ret int_handler: iret .include "text.asm" .include "random.asm" .include "starfield.asm" .include "entities.asm" .include "player.asm" .include "bullet.asm" ; in unpacked BCD format hiscore: .db 0, 1, 0, 0, 0, 0 score: .db 0, 0, 0, 0, 0, 0 ; ; entity data ; entities: ; type .db ET_PLAYER ; x, y player_coord: .db 0, 0 ; frame .db 0 .dw player_sprite .dw player_update ; 16 entities .ds 128, 0 ; end of list .db ET_END ; sprite data player_sprite: .incpng "assets/player.png" pbullet_sprite: .incpng "assets/pbullet.png" ; starfield data stars: ; video addr, speed, color .dw 0xc361 .db 1, 15 .dw 0xc204 .db 1, 6 .dw 0xcdf9 .db 1, 15 .dw 0xdb87 .db 1, 3 .dw 0xd242 .db 1, 15 .dw 0xdeea .db 1, 6 .dw 0xe7af .db 1, 15 .dw 0xed68 .db 1, 3 .dw 0xf812 .db 1, 15 .dw 0xfbca .db 1, 13 .dw 0xc361 .db 2, 8 .dw 0xc204 .db 2, 9 .dw 0xcdf9 .db 3, 7 .dw 0xdb87 .db 3, 4 .dw 0xd242 .db 2, 8 .dw 0xdeea .db 3, 9 .dw 0xe7af .db 3, 6 .dw 0xed68 .db 2, 9 .dw 0xf812 .db 3, 14 .dw 0xfbca .db 2, 3 ; end of list .dw 0xffff ; menu data title: .incpng "assets/title.png" font: .incpng "assets/font.png" usebox: .incpng "assets/usebox.png" ; texts press_start_text: .str "PRESS START!" .db 0 hiscore_text: .str "HI:" .db 0