-
Notifications
You must be signed in to change notification settings - Fork 0
/
nestella.asm
301 lines (224 loc) · 4.87 KB
/
nestella.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
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
include "nesdefs.dasm"
include "vcs.h"
;;;;; VARIABLES
; 40 - 45 atari registers
var0 = $46 ; used by interrupt handler!!!!!
var1 = $47 ; used by interrupt handler!!!!! be careful
var2 = $48
var3 = $49
; Translator
NESInstSize = $4A
NESOpCode = $4B
NESAddrLo = $4C
NESAddrHi = $4D
OpCode = $4E
AddrLo = $4F
AddrHi = $50
InstSize = $51
InstType = $52
; 54 - 57 atari registers
BlockCycles = $58
BlockNESPCHi = $59 ; this will also contain the interrupt type in it, so it's
; stored in the table after the block is fully translated
; Rendering
ScanLine = $5A ; which scanline we're currently on
Sprite0H = $5C
Sprite1H = $5D
Sprite2H = $5E
Sprite3H = $5F
Sprite4H = $60
; Interrupt Handler
IntrID = $61
BranchHead = $62
IntA = $63
IntX = $64
IntY = $65
IntP = $66
; Temporary Pointers
TCachePtr = $69
TROMPtr = $6B
RollOver = $6D
; - 7F Plafield Blocks
; TIA I/O registers and timers
IORead = $100
IOWrite = $108
BGColor = $110
PFColor = $111
UpdateColor = $112
ColorSection = $113 ; which quarter of the screen we're in
PaletteCounter = $114 ; counts tiles and sets the palette after 6 tiles
Playfield = $115 ; - $128
; two 24 byte buffers should be enough jesus christ
DrawBuffer0 = $130
DrawBuffer1 = $148
PF0old = $160
PF1old = $161
PF2old = $162
PFLeft0 = $163
PFLeft1 = $164
PFLeft2 = $165
PFRight0 = $166
PFRight1 = $167
PFRight2 = $168
LineCycles = $169 ; how many cycles since the scanline started
LastDrawnPixel = $16A
FreeSprite = $16B
TimerCycles = $16C ; 10 bit value, stored a bit weird
TimerCounter = $16E
TimerInterval = $16F
CacheTableHalf0 = $170
Stack = $1F0
Sprites = $300
ATRPC = $2F1
IntS = $2F3
NESPC = $2F5
BlockIndex = $2F7
CacheFree = $2F9
CacheOldest = $2FB
; cache table
CacheTableHalf1 = $300
CodeBlocks = $400
CACHE_BLOCKS = $40
CACHE_BLOCKS_END = $7FF
JATARI = CacheTableHalf0 + CACHE_BLOCKS*0 ; lll1 hhhh -> 1111 hhhh llli iiii (i is row index)
JINT = CacheTableHalf0 + CACHE_BLOCKS*1 ; interrupt type
JCYCLES = CacheTableHalf1 + CACHE_BLOCKS*0 ; code block cycle count
JRETLO = CacheTableHalf1 + CACHE_BLOCKS*1 ; where to return to after the interrupt
JRETHI = CacheTableHalf1 + CACHE_BLOCKS*2
JINTPAR = CacheTableHalf1 + CACHE_BLOCKS*3 ; interrupt parameter if needed
INS_PHP = $08
INS_JSR = $20
INS_PHA = $48
INS_NOP = $ea
INS_JMP_ABS = $4c
INS_STA_ZPG = $85
INS_LDA_IMM = $a9
;;;;; Assembler Parameters
PERFORMANCE_MONITOR = 0
seg.u ZEROPAGE
org $0
;;;;; NES CARTRIDGE HEADER
NES_HEADER 0,1,1,0 ; mapper 0, 1 PRGs, 1 CHR, horiz. mirror
;;;;; START OF CODE
Start:
NES_INIT
jsr ClearRAM
lda #0
sta OAM_ADDR
lda #<ROM_RESET
sta ATRPC
lda #>ROM_RESET
sta ATRPC+1
lda #<CodeBlocks
sta CacheFree
lda #>CodeBlocks
sta CacheFree+1
lda #CACHE_BLOCKS-1
sta CacheOldest
lda #<ROM_RESET
sta TROMPtr
lda #>ROM_RESET
sta TROMPtr+1
lda #$E3
sta BranchHead
lda #-22
sta LineCycles
lda #0
sta TimerCycles
lda #0
sta TimerCounter
lda #$d
sta $104
; temporary static sprite palette
lda #$3f
sta PPU_ADDR
lda #$11
sta PPU_ADDR
lda #$06
sta PPU_DATA
sta PPU_DATA
sta PPU_DATA
ldy #5
sty PaletteCounter
SetColors
lda #$23
sta PPU_ADDR
tya
asl
asl
asl
clc
adc #$c9
sta PPU_ADDR
ldx #6
lda Attributes,y
.write
sta PPU_DATA
dex
bne .write
dey
bpl SetColors
lda #0
sta PPU_ADDR
sta PPU_ADDR
sta PPU_SCROLL
sta PPU_SCROLL
lda #MASK_BG | MASK_SPR
sta PPU_MASK ; enable rendering
lda #CTRL_NMI | CTRL_SPR_1000
sta PPU_CTRL ; enable NMI
jmp FindBlock
Attributes:
.byte $00, $50, $55, $AA, $FA, $FF
;;;;; COMMON SUBROUTINES
include "sprite.asm"
include "timer.asm"
include "graphics.asm"
include "interrupt.asm"
include "blocks.asm"
include "translate.asm"
include "execute.asm"
include "sync.asm"
include "input.asm"
org $d000
include "nmi.asm"
org $df00
include "data.asm"
include "nesppu.dasm"
.org $e300
bpl .branched
rts
.byte
bmi .branched
rts
.byte
bvc .branched
rts
.byte
bvs .branched
rts
.byte
bcc .branched
rts
.byte
bcs .branched
rts
.byte
bne .branched
rts
.byte
beq .branched
rts
.branched
txa
rts
org $effa
; Atari Vectors
;.hex 60 CD 00 B0 00 B0
;.word $CD60
;.word #ROM_RESET
;.word $B000
org $f000
incbin "rom.bin"
incbin "rom.bin"
incbin "tiles.chr"