aboutsummaryrefslogtreecommitdiff
path: root/tests/runrom/mmc3/basic.s
blob: f97fe3f51299b56146e590bcf7e6716452b9283a (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
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
.segment "HEADER"
    .byte 'N', 'E', 'S', $1A
    .byte $10, $10
    .byte $43
    .byte $08
    .byte $00
    .byte $00
    .byte $70
    .res $05, $00

.segment "TAIL"
;;; asan:stack full

;;; TODO: into another segment, writing to WRAM clc; adc wr_whatever; sta wr_whatever; this is then called via different segments

.scope PPU
    m_status  = $2002
    m_address = $2006
.endscope

.scope MMC3
    m_bank_select = $8000
    m_bank_data   = $8001
    m_mirroring   = $A000
    m_ram_protect = $A001
    m_irq_disable = $E000
.endscope

.macro BANK_REGISTER_SET REGISTER_ID, REGISTER_VALUE
    lda #REGISTER_ID
    sta MMC3::m_bank_select
    lda #REGISTER_VALUE
    sta MMC3::m_bank_data
.endmacro

.proc regular_mmc3_init
    ;; Init scanline counter.
    bit PPU::m_status

    lda #$00
    sta PPU::m_address
    sta PPU::m_address
    lda #$10
    sta PPU::m_address
    sta PPU::m_address

    lda #$00
    sta PPU::m_address
    sta PPU::m_address
    lda #$10
    sta PPU::m_address
    sta PPU::m_address

    ;; Setup mirroring.
    lda #$00
    sta MMC3::m_mirroring

    ;; Disable interrupts.
    sta MMC3::m_irq_disable

    ;; Enable PRG RAM and allow writes to it.
    lda #$80
    sta MMC3::m_ram_protect

    ;; PRG banking setup.
    BANK_REGISTER_SET 6, 0
    BANK_REGISTER_SET 7, 1

    rts
.endproc

.proc basic
    jsr regular_mmc3_init

    jsr foo                     ; asan:safe

    BANK_REGISTER_SET 6, 1

    ;; NOTE: this is actually not safe, as it will call another_foo() instead :)
    jsr foo                     ; asan:safe

    ;; NOTE: calling a different address but it's the same function as per the
    ;; previous mapping :)
    jsr another_foo             ; asan:safe

    rts
.endproc

.proc no_writes_allowed
    jsr regular_mmc3_init

    lda #$C0
    sta MMC3::m_ram_protect

    jmp foo                     ; asan:safe
.endproc

.proc no_wram
    jsr regular_mmc3_init

    lda #$00
    sta MMC3::m_ram_protect

    jmp foo                     ; asan:safe
.endproc

.proc reset
    ;; NOTE: avoid warnings from unused functions.
    jsr basic
    jsr no_writes_allowed
    jsr no_wram

    rts
.endproc

.proc nmi
    rti
.endproc

.proc irq
    rti
.endproc

.segment "PRG0_00"

wr_value = $6000

.proc foo
    clc
    adc wr_value
    sta wr_value
    rts
.endproc

.segment "PRG0_01"

.proc another_foo
    inc wr_value
    rts
.endproc

.segment "CHARS"
.res $F000, $00
.res $F000, $00
.res $2000, $00

.segment "VECTORS"
    .addr nmi, reset, irq

.segment "PRG0_00"
.byte $00

.segment "PRG0_01"
.byte $00

.segment "PRG0_02"
.byte $00

.segment "PRG0_03"
.byte $00

.segment "PRG0_04"
.byte $00

.segment "PRG0_05"
.byte $00

.segment "PRG0_06"
.byte $00

.segment "PRG0_07"
.byte $00

.segment "PRG0_08"
.byte $00

.segment "PRG0_09"
.byte $00

.segment "PRG0_0A"
.byte $00

.segment "PRG0_0B"
.byte $00

.segment "PRG0_0C"
.byte $00

.segment "PRG0_0D"
.byte $00

.segment "PRG0_0E"
.byte $00

.segment "PRG1_00"
.byte $00

.segment "PRG1_01"
.byte $00

.segment "PRG1_02"
.byte $00

.segment "PRG1_03"
.byte $00

.segment "PRG1_04"
.byte $00

.segment "PRG1_05"
.byte $00

.segment "PRG1_06"
.byte $00

.segment "PRG1_07"
.byte $00

.segment "PRG1_08"
.byte $00

.segment "PRG1_09"
.byte $00

.segment "PRG1_0A"
.byte $00

.segment "PRG1_0B"
.byte $00

.segment "PRG1_0C"
.byte $00

.segment "PRG1_0D"
.byte $00

.segment "PRG1_0E"
.byte $00

.segment "FIXED"
.byte $00