-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.s
More file actions
95 lines (78 loc) · 1.52 KB
/
init.s
File metadata and controls
95 lines (78 loc) · 1.52 KB
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
.p816
.i16
.a16
.segment "HEADERNAME"
.byte "SUPER SOKONYAN"
.segment "ROMINFO"
.byte $30 ; Fast LoROM
.byte 0 ; ROM-only cart
.byte $07 ; 128K ROM
.byte 0,0,0,0 ; No RAM, Japan, Homebrew, Version 0
.word $FFFF,$0000 ; dummy checksums
.segment "VECTORS"
.addr 0,0,0,0,0,nmi,0,0
.addr 0,0,0,0,0,0,reset,0
.segment "UNSIZED"
.include "preamble.inc"
reset:
clc ; native mode
xce
rep #$30 ; A/X/Y 16-bit
; We'll start in the 0th bank, but doing a long jump to `fastrom` (which ld65
; will put into the $80th bank, fast rom) will switch us.
jml fastrom
fastrom:
; Clear PPU registers
ldx #$33
@loop: stz $2100,x
stz $4200,x
dex
bpl @loop
lda #$8F
sta $4100
ldx #RETURN_STACK_ADDR
txs
ldx #DATA_STACK_ADDR
; Set Data Bank to the current (fast) Program Bank.
phk
plb
.import _SNES_MAIN
jsr _SNES_MAIN
forever:
jmp forever
.export not_implemented
not_implemented:
jmp not_implemented
nmi:
jml nmiFast
nmiFast:
; Thanks to Oziphantom (https://www.youtube.com/watch?v=rPcwGeX_hLs) for the NMI overview :)
; = Save registers =
; First save the data page and set it to the current code page (so we know that
; $4210 is indeed the ACK register).
phb
phk
plb
; ACK NMI
A8
bit $4210
; Make sure we save all 16 bits of each register.
A16
pha
phx
phy
phd
; Set direct page to 0 (Forth expects no offset).
lda #0000
tcd
; Call Forth NMI handler.
.import _SNES_NMI
jsr _SNES_NMI
; Restore registers.
A16
pld
ply
plx
pla
plb
rti