-
Notifications
You must be signed in to change notification settings - Fork 2
/
game.asm
154 lines (148 loc) · 2.8 KB
/
game.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
.ifndef GAME_INC
GAME_INC = 1
.include "x16.inc"
.include "player.asm"
.include "timer.asm"
.include "joystick.asm"
.include "superimpose.asm"
.include "debug.asm"
.include "levels.asm"
.include "loadbank.asm"
.include "fruit.asm"
.include "skull.asm"
.include "fireball.asm"
.include "bomb.asm"
.include "winscreen.asm"
.include "music.asm"
.include "soundfx.asm"
init_game:
lda #0
jsr MOUSE_CONFIG ; disable mouse cursor
jsr regenerate
jsr init_music
rts
game_tick: ; called after every VSYNC detected (60 Hz)
inc frame_num
lda frame_num
cmp #60
bne @tick
lda #0
sta frame_num
@tick:
jsr timer_tick
jsr joystick_tick
jsr sfx_tick
jsr check_input
lda start_prompt
ora paused
ora continue_prompt
bne @return
@play:
jsr player_tick
jsr enemy_tick
jsr fruit_tick
jsr level_tick
jsr skull_tick
jsr fireball_tick
jsr bomb_tick
jsr winscreen_tick
jsr music_tick
@return:
rts
check_input:
.if NUKE_ENABLED
lda joystick1_a
beq @check_start
jsr enemy_clear
jsr skull_clear
.endif
@check_start:
lda joystick1_start
and new_start
bne @check_start_action
lda joystick1_start
bne @start_still_pressed
lda #1
sta new_start
@start_still_pressed:
jmp check_input_return
@check_start_action:
stz new_start
lda start_prompt
bne @start_game
jmp @check_pause
@start_game:
; disable VRAM layer 1
lda VERA_dc_video
and #$DF
sta VERA_dc_video
; Setup level map on layer 1
lda #$A2 ; 128x128 map of 4bpp tiles
sta VERA_L1_config
lda #((VRAM_TILEMAP >> 9) & $FF)
sta VERA_L1_mapbase
; setup game parameters and initialize states
jsr init_game
; load level 1 bitmap from banked RAM into layer 0
lda #7
sta BITMAP_PO
; raster the bitmap twice to make sure it takes
jsr raster_bitmap
jsr raster_bitmap
lda #15
sta BITMAP_PO
; enable sprites and layers
lda VERA_dc_video
ora #$70
sta VERA_dc_video
jsr level_backup
stz start_prompt
bra check_input_return
@check_pause:
lda paused
beq @check_continue
SUPERIMPOSE_RESTORE
stz paused
jsr start_music
bra check_input_return
@check_continue:
lda continue_prompt
beq @pause
jsr continue
stz continue_prompt
bra check_input_return
@pause:
lda player
bit #$02
beq check_input_return
lda #1
sta paused
SUPERIMPOSE "paused", 7, 9
jsr stop_music
check_input_return:
rts
raster_bitmap:
stz VERA_ctrl
VERA_SET_ADDR VRAM_BITMAP, 1
lda #BITMAP_BANK
ldx #0
ldy #0
jsr bank2vram
lda #(BITMAP_BANK+1)
ldx #0
ldy #0
jsr bank2vram
lda #(BITMAP_BANK+2)
ldx #0
ldy #0
jsr bank2vram
lda #(BITMAP_BANK+3)
ldx #0
ldy #0
jsr bank2vram
lda #(BITMAP_BANK+4)
ldx #0
ldy #$B0
jsr bank2vram
rts
.endif