blob: 00e807cd98d30200b5f70ba68bec9ef4603fd61e (
plain)
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
|
.segment "CODE"
.scope Driver
;; Timer for the player to be able to pick up the joypad upon entering the
;; game.
;;
;; NOTE: this memory address is shared with `zp_title_timer`, as they can
;; never conflict with each other.
zp_player_timer = $30
PLAYER_TIMER_VALUE = HZ * 2
.ifdef PAL
;; Frame counter which resets every 5 frames.
zp_pal_counter = $31
.endif
;; Switch from the title screen to the main street. Note that this function
;; is to be called with the PPU disabled. If that's not the case, then it
;; will set the proper values to disable it on the next `nmi` call and set
;; the `title over` flag. With that, call again this function so the
;; switching is actually performed.
.proc switch
;; Some things from here require the PPU to be disabled. Hence, if
;; that's not the case, disable it now. The `ppu` and the `title over`
;; flags are set as well.
lda PPU::zp_mask
beq @do_switch
lda #%01000100
ora Globals::zp_flags
sta Globals::zp_flags
lda #$00
sta PPU::zp_mask
rts
@do_switch:
;; Get the assets ready for the main screen. That is, make sure that the
;; palettes and such are as desired since the title screen needed
;; another setup.
jsr Assets::prepare_for_main_screen
;; Switch to the other base nametable.
lda #%10001010
sta PPU::zp_control
;; Enable back the PPU.
lda #%00011110
sta PPU::zp_mask
;; Setup the player timer.
.ifdef PARTIAL
lda #1
.else
lda #PLAYER_TIMER_VALUE
.endif
sta zp_player_timer
;; Mark the state of the game as "game". That is, the player has
;; started. Also set the `ppu` flag and unset the `title over` one.
lda #%01000001
ora Globals::zp_flags
and #%11111011
sta Globals::zp_flags
rts
.endproc
.proc update
lda zp_player_timer
beq @game
dec zp_player_timer
beq @load_player
;; TODO: blinking of the selected player (every HZ count?).
rts
@load_player:
jsr Player::init
@game:
JAL Player::update
.endproc
.ifdef PAL
;; All the code that is needed to fix some values for PAL machines.
.proc pal_handler
;; Check if 5 frames have passed since last counter reset.
lda Driver::zp_pal_counter
cmp #4
beq @do_handle
;; Nope! Reset the player's step on PAL and increase the counter.
lda #1
sta Player::zp_step_on_pal
inc Driver::zp_pal_counter
bne @end
@do_handle:
;; Increase the step just for this frame and reset the counter.
lda Player::zp_step_on_pal
clc
adc #2
sta Player::zp_step_on_pal
lda #0
sta Driver::zp_pal_counter
@end:
rts
.endproc
.endif
.endscope
|