-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelloworld.s
341 lines (297 loc) · 5.98 KB
/
helloworld.s
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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
; /////////////////////////////////////////////////////////////
; /// VECTORS ///
; /////////////////////////////////////////////////////////////
.org 0 ; entry point
jmpf Start
.org $03 ; External int. (INTO) - IO1CR
reti
.org $0B ; External int. (INT1) - IO1CR
reti
.org $13 ; External int. (INT2) and Timer 0 low - I23CR and T0CNT
reti
.org $1B ; External int. (INT3) and base timer - I23CR and BTCR
reti
.org $23 ; Timer 0 high - T0CNT
reti
.org $2B ; Timer 1 Low and High - T1CNT
reti
.org $33 ; Serial IO 1 - SCON0
reti
.org $3B ; Serial IO 2 - SCON1
reti
.org $43 ; VMU to VMU comms - not listed? (160h/161h)
reti
.org $4B ; Port 3 interrupt - P3INT
clr1 P3INT, 1
mov #$FF, HaltCnt
reti
.org $1F0
goodbye:
not1 EXT, 0
jmpf goodbye
; /////////////////////////////////////////////////////////////
; /// DREAMCAST HEADER ///
; /////////////////////////////////////////////////////////////
.org $200
.byte "hello, world! " ; ................... 16-byte Title
.byte "by https://github.com/jvsTSX " ; ... 32-byte Description
; /////////////////////////////////////////////////////////////
; /// GAME ICON ///
; /////////////////////////////////////////////////////////////
.org $240 ; >>> ICON HEADER
.org $260 ; >>> PALETTE TABLE
.org $280 ; >>> ICON DATA
; /////////////////////////////////////////////////////////////
; /// GAME CODE ///
; /////////////////////////////////////////////////////////////
.include "sfr.i"
temp1 = $10
temp2 = $11
temp3 = $12
chptr = $13
HaltCnt = $14
Start:
mov #00000101, P3INT ; enable joypad interrupt
mov #0, T1CNT
clr1 BTCR, 6
; initialize screen
mov #$80, 2
mov #0, XBNK
.Loop:
xor ACC
st @r2 ; line 1
inc 2
st @r2
inc 2
st @r2
inc 2
st @r2
inc 2
st @r2
inc 2
st @r2
inc 2
st @r2 ; line 2
inc 2
st @r2
inc 2
st @r2
inc 2
st @r2
inc 2
st @r2
inc 2
st @r2
ld 2
add #5
st 2
bnz .Loop
bp XBNK, 0, .LoopDone
inc XBNK
mov #80, 2
br .Loop
.LoopDone:
; print hello world into the screen
set1 VSEL, 4 ; WRAM autoincrement on
mov #0, XBNK
mov #$80, 2
mov #12, temp1
mov #<String, temp2
mov #>String, temp3
call PrintStringFlash
Main: ; wait untill MODE is pressed
ld P3
bp ACC, 6, .NoMode
set1 BTCR, 6
jmp goodbye
.NoMode:
dbnz HaltCnt, Main
set1 PCON, 0
br Main
; /////////////////////////////////////////////////////////////
; /// SUBROUTINES ///
; /////////////////////////////////////////////////////////////
PrintStringFlash:
; r2 and XBNK = XRAM location (make sure even line)
; temp1 = char count
; temp2 = flash address low
; temp3 = flash address high
; initialize WRAM
ld temp1
clr1 PSW, 7
rorc
addc #0
st 1
call ClearCharCellsWRAM
; render text
ld temp1
st 1
mov #0, chptr
.StringLoop:
ld temp2
st TRL
ld temp3
st TRH
ldf
call DrawChar
inc temp2
ld temp2
bnz .NoCarry
inc temp3
.NoCarry:
dbnz 1, .StringLoop
; copy result
ld temp1
clr1 PSW, 7
rorc
addc #0
st 1
call PrintCharCells
ret
ClearCharCellsWRAM: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; initializes work RAM char cells because the rendering process involves OR masking
; r1 = char cell count (1 cell = 2 char)
mov #0, VRMAD1
set1 VRMAD2, 0
.CleanLoop:
xor ACC
st VTRBF
st VTRBF
st VTRBF
st VTRBF
st VTRBF
st VTRBF
dbnz 1, .CleanLoop
ret
PrintCharCells: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; renders char cells from WRAM into XRAM
; XBNK and r2 = position
; 1 = cell count
mov #0, C
ld 2
and #%00001111
be #6, .here
.here
bn PSW, 7, .evenline
inc C
.evenline:
mov #0, VRMAD1
set1 VRMAD2, 0
.CopyLoop:
mov #6, B
.SubLoop:
ld VTRBF
st @r2
ld 2
bp C, 0, .even
add #4
.even:
add #6
st 2
not1 C, 0
dbnz B, .SubLoop
ld 2
sub #$2F
st 2
dbnz 1, .CopyLoop
ret
DrawChar: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; renders one char to Work RAM
; chptr = location in WRAM (100 - 180)
; ACC = char to draw
be #$20, .here0
.here0:
bp PSW, 7, .BlankChar
be #$80, .here1
.here1:
bp PSW, 7, .EnglishChar
be #$A0, .here2
.here2:
bp PSW, 7, .BlankChar
be #$E0, .here3
.here3:
bp PSW, 7, .JapaneseChar
; fail condition = blank char
.BlankChar: ; don't render anything
inc chptr
ret
.EnglishChar:
mov #<En_Chars, TRL
mov #>En_Chars, TRH
sub #$20
br .Continue
.JapaneseChar:
mov #<Jp_Chars, TRL
mov #>Jp_Chars, TRH
sub #$A0
.Continue: ; multiply index by 6 and add char table offset to TR
st C
mov #6, B
xor ACC
mul
st B
ld C
add TRL
st TRL
ld B
addc TRH
st TRH
set1 VRMAD2, 0 ; get current cell
ld chptr
clr1 PSW, 7
rorc
st C
xor ACC
mov #6, B
; mask new char data into the cell and store new result
mov #6, 0
bp PSW, 7, MaskRight ; check odd/even
MaskLeft: ; mask regular
mul
ld C
st VRMAD1
.MaskLoop:
ldf
or VTRBF
dec VRMAD1
st VTRBF
inc TRL
ld TRL
bnz .NoCarry
inc TRH
.NoCarry
dbnz 0, .MaskLoop
inc chptr
ret
MaskRight: ; mask with ROR
mul
ld C
st VRMAD1
.MaskLoop:
ldf
ror
ror
ror
ror
or VTRBF
dec VRMAD1
st VTRBF
inc TRL
ld TRL
bnz .NoCarry
inc TRH
.NoCarry
dbnz 0, .MaskLoop
inc chptr
ret
; /////////////////////////////////////////////////////////////
; /// DATA SPACE ///
; /////////////////////////////////////////////////////////////
String:
.byte "Hello,World!"
En_Chars:
.include sprite "JIS_EN.png" header="no"
.include sprite "JIS_EN2.png" header="no"
.include sprite "JIS_EN3.png" header="no"
Jp_Chars:
.cnop 0, $200