-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnes.snz
190 lines (169 loc) · 3.45 KB
/
snes.snz
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
FUN cop [INTR] {}
FUN brk [INTR] {}
FUN irq [INTR] {}
FUN cop_emu [EMU, INTR] {}
FUN nmi_emu [EMU, INTR] {}
FUN irq_emu [EMU, INTR] {}
# Init code stolen shamelessly from
# https://en.wikibooks.org/wiki/Super_NES_Programming/Initialization_Tutorial/Snes_Init
FUN reset [EMU, INTR] {
SEI;
# No explicit switch to native mode - the [NAT] block handles that transition for us
[NAT] {
[WIDEM] {
# Setup the stack and zero page pointers
C := 0x01FF;
S := C;
C := 0x0000;
D := C;
}
A := 0x8F;
*0x2100 := A;
*0x2101 := 0;
*0x2102 := 0;
*0x2103 := 0;
*0x2105 := 0;
*0x2106 := 0;
*0x2107 := 0;
*0x2108 := 0;
*0x2109 := 0;
*0x210A := 0;
*0x210B := 0;
*0x210C := 0;
*0x210D := 0;
*0x210D := 0;
A := 0xFF;
*0x210E := A;
*0x2110 := A;
*0x2112 := A;
*0x2114 := A;
A := 0x07;
*0x210E := A;
*0x2110 := A;
*0x2112 := A;
*0x2114 := A;
*0x210f := 0;
*0x210f := 0;
*0x2111 := 0;
*0x2111 := 0;
*0x2113 := 0;
*0x2113 := 0;
A := 0x80;
*0x2115 := A;
*0x2116 := 0;
*0x2117 := 0;
*0x211A := 0;
*0x211B := 0;
A := 0x01;
*0x211B := A;
*0x211C := 0;
*0x211C := 0;
*0x211D := 0;
*0x211D := 0;
*0x211E := 0;
*0x211E := A;
*0x211F := 0;
*0x211F := 0;
*0x2120 := 0;
*0x2120 := 0;
*0x2121 := 0;
*0x2123 := 0;
*0x2124 := 0;
*0x2125 := 0;
*0x2126 := 0;
*0x2127 := 0;
*0x2128 := 0;
*0x2129 := 0;
*0x212A := 0;
*0x212B := 0;
*0x212C := A;
*0x212D := 0;
*0x212E := 0;
*0x212F := 0;
A := 0x30;
*0x2130 := A;
*0x2131 := 0;
A := 0xE0;
*0x2132 := A;
*0x2133 := 0;
A := 0xFF;
*0x4200 := 0;
*0x4201 := A;
*0x4202 := 0;
*0x4203 := 0;
*0x4204 := 0;
*0x4205 := 0;
*0x4206 := 0;
*0x4207 := 0;
*0x4208 := 0;
*0x4209 := 0;
*0x420A := 0;
*0x420B := 0;
*0x420C := 0;
*0x420D := 0;
CLI;
main();
}
}
# END setup boilerplate
VAR inidisp := 0x2100;
VAR cgdata := 0x2122;
VAR nmitimen := 0x4200;
VAR status := 0x0000;
FUN main {
# force-blanking is on from init, so we can set PPU registers
# Load a nice dark blue into the palette.
# cgaddr is already at address 0 from init
A := 0x3C;
cgdata := 0;
cgdata := A;
# TODO: Set our game state to its initial value
# Our init is done - enable NMI for first gamestate update
A := 2; # main loop done, NMI not done
status := A;
# All startup done - enable NMI and auto joypad read
A := 0x81;
nmitimen := A;
# Main Loop
DO {
# Wait for NMI
DO {
A := status;
} WHILE (A !& 1)
# TODO: Update game state
A := status;
A |= 2; # Set "main loop done" bit
A &= 0xFE; # Clear "NMI done" bit
status := A;
}
}
FUN nmi [INTR] {
[WIDEM, WIDEX] {
PUSH C;
PUSH X;
PUSH Y;
}
# Entering then leaving the WIDEM,WIDEX block above ensures we're in
# narrow M,X here post-interrupt-entry
# Check if game update is done
A := status;
IF (A && 2) {
# Enable force blank
A := 0x8F;
inidisp := A;
# TODO: Update PPU state for new game state
# Disable force blank
A := 0x0F;
inidisp := A;
# Signal to main loop that PPU is updated, and it can iterate again
A := status;
A |= 1; # Set "NMI done" bit
A &= 0xFD; # Clear "main loop done" bit
status := A;
}
[WIDEM, WIDEX] {
POP Y;
POP X;
POP C;
}
}