-
Notifications
You must be signed in to change notification settings - Fork 0
/
vectors.asm
211 lines (157 loc) · 4.18 KB
/
vectors.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
ResetVector:
sei ; disable interrupts
clc
xce
cld
jmp !FastReset
FastReset:
.call M8
.call X16
ldx #STACK_TOP
txs ; set stack pointer to 1fff
lda #01
sta MEMSEL
; ---- Forced Blank
lda #80
sta INIDISP
jsr @ClearRegisters
; ---- BG settings
lda #09 ; bg 3 high prio, mode 1
sta BGMODE
.call RESET_OFFSET BG1HOFS, BG1VOFS
.call RESET_OFFSET BG2HOFS, BG2VOFS
lda #30
sta BG12NBA ; BG1 tiles @ VRAM[0000], BG2 tiles @ VRAM[6000]
lda #58
sta BG1SC ; BG1 MAP @ VRAM[b000]
lda #60
sta BG2SC ; BG2 MAP @ VRAM[c000]
lda #13 ; enable BG12 + sprites (0b10011)
sta TM
; ---- WINDOWING settings
lda #33
sta W12SEL
sta W34SEL
lda #03
sta WOBJSEL
lda #ff
sta WH0
lda #ef
sta WH1
lda #1f
sta TMW
; ---- OBJ settings
lda #62 ; sprite 16x16 small, 32x32 big
sta OBJSEL ; oam start @VRAM[8000]
; ---- Some initialization
; TODO: faster with manual transfer ?
.call WRAM_DMA_TRANSFER 01, @FastNmi, FastNmi_ROM, {FastNmi_end-FastNmi}w
.call WRAM_DMA_TRANSFER 01, @FastIRQ, FastIRQ_ROM, {FastIRQ_end-FastIRQ}w
.call WRAM_DMA_TRANSFER 01, @InitGSU, InitGSU_ROM, {InitGSU_end-InitGSU}w
.call WRAM_DMA_TRANSFER 01, @CallGSUFunction, CallGSUFunction_ROM, {CallGSUFunction_end-CallGSUFunction}w
ldx @NmiVector
stx @nmi_dummy_jump
ldx @NmiVector+2
stx @nmi_dummy_jump+2
ldx @IRQVector
stx @irq_dummy_jump
ldx @IRQVector+2
stx @irq_dummy_jump+2
jsr @InitOamBuffer
; ---- DMA Transfers
.call VRAM_DMA_TRANSFER 3000, bg2_tiles, BG2_TILES_SIZE ; VRAM[0x2000] (word step)
; should design a tilemap corresponding to tiles drawn by super FX
.call VRAM_DMA_TRANSFER 5800, bg1_map, BG1_MAP_SIZE ; VRAM[0xb000] (word step)
.call VRAM_DMA_TRANSFER 6000, bg2_map, BG2_MAP_SIZE ; VRAM[0xc000] (word step)
.call CGRAM_DMA_TRANSFER 00, bg1_pal, 80
jsr @TransferOamBuffer
; ; ---- Release Forced Blank
; lda #0f ; release forced blanking, set screen to full brightness
; sta INIDISP
; lda #81 ; enable NMI, turn on automatic joypad polling
; sta NMITIMEN
; cli
jmp @MainEntry
BreakVector:
rti
WaitNextVBlank:
stz @vblank_disable
wait_next_vblank:
lda @vblank_disable
beq @wait_next_vblank
stz @vblank_disable
rts
NmiVector:
jmp !FastNmi
FastNmi_ROM:
php
.call MX16
pha
phx
phy
.call M8
.call X16
lda RDNMI
inc @frame_counter
lda @horizontal_offset
sta BG1HOFS
lda @horizontal_offset+1
sta BG1HOFS
; copy char data from 70:2000 to bg1_tile tiles VRAM[0000]
; find way to transfer full buffer during NMI
; split transfer over multiple frame.
; .call VRAM_DMA_TRANSFER 0000, screen_base, 1780
; jsr @TransferOamBuffer ; should relocate this to RAM as well
; jsr @ReadJoyPad1 ; should relocate this to RAM as well
inc @vblank_disable
.call MX16
ply
plx
pla
plp
rti
FastNmi_ROM_end:
IRQVector:
jmp !FastIRQ
FastIRQ_ROM:
; read GSU status register bit 15
; if 1 -> irq was from GSU
lda SFRH
bit #80
bne @return_from_gsu
; regular irq
lda TIMEUP
stz MDMAEN
stz HDMAEN
; on reset -> copy full frame to buffer 1
; 4 steps
; frame 1 & 2 : show buffer 1 (if (frame & 0b11) & 0b10 == 0b0)
; 00, 01
; frame 1 -> copy first half to buffer 2L
; frame 2 -> copy second half to buffer 2H
; frame 3 & 4 : show buffer 2 (if (frame & 0b11) & 0b10 == 0b10)
; 10, 11
; frame 3 -> copy first half to buffer 1L
; frame 4 -> copy second half to buffer 1H
; screen_base_1
; screen_base_2
; ---- hdma begin
lda #^wh0_hdma
sta A1T3B
ldx #@wh0_hdma
stx A1T3L
lda #26
sta BBAD3
lda #00
sta DMAP3
lda #08
sta HDMAEN
; ---- hdma end
; enable DMA after HDMA
.call VRAM_DMA_TRANSFER 0000, screen_base, 2a00
bra @exit_irq
return_from_gsu:
; specific code here
exit_irq:
rti
FastIRQ_ROM_end: