-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcharactermode.asm
executable file
·464 lines (433 loc) · 6.77 KB
/
charactermode.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
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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
// Handles all character based routines ie printing text on screen
// While playing it is responsible for updating lower part of the screen
// Last 5 lines are used for stats etc
//.pc = $7000 "Character mode routines"
.pc = hiresEnd+1 "Character mode routines"
.label textarea = $0720
.label colorarea = $0db20
.label toPrint = $5e // Stores pointer to text to write on screen
.var lineWidth = 40
.var textRows = 5
.var totalChars = 200
.var toScroll = 160
.var positionFood = 34
.var positionHitpoints = 74
.var positionGold = 114
// Clear character area
ClearTextArea:
{
lda #' '
ldx #totalChars
loop: sta textarea,x
dex
bne loop
sta textarea,x
rts
}
scrollText:
ScrollText:
{
//Needs to be done line by line?
ldx #40
ldy #0
// First line
loop: lda textarea,x
sta textarea,y
inx
iny
cpx #69 //#totalChars
bne loop
// Second line
ldx #80
ldy #40
loop2: lda textarea,x
sta textarea,y
inx
iny
cpx #109 //#totalChars
bne loop2
// Third line
ldx #120
ldy #80
loop3: lda textarea,x
sta textarea,y
inx
iny
cpx #149 //#totalChars
bne loop3
// Clear last line
lda #' '
ldx #120 //#totalChars
loop4: sta textarea,x
inx
cpx #149 //#160
bne loop4 //*/
rts
}
ClearLastLine:
{
lda #' '
ldx #totalChars
loop: sta textarea,x
dex
cpx #160
bne loop
sta textarea,x
rts
}
writeColorRam:
{
lda #WHITE
ldx #totalChars
loop: sta colorarea,x
dex
bne loop
sta colorarea,x
rts
}
/*
// Pseudocommand to call writeText
.pseudocommand print text {
lda text
sta toPrint
lda _16bit_nextArgument(text)
sta toPrint+1
jsr WriteText
}
*/
WriteText:
{
/* ldy #00
ldx #161
loop: lda (toPrint),y
beq end
sta textarea,x
iny
inx
jmp loop*/
ldx #totalChars
write: lda messu2,x
sta textarea,x
dex
bne write
lda messu2,x
sta textarea,x
end: rts
}
askCommand:
{
ldx #00
ldy #120
write: lda TextCommand,x
beq end
sta textarea,y
inx
iny
jmp write
end: rts
}
printForward:
{
ldx #00
ldy #129
write: lda TextForward,x
beq end
sta textarea,y
inx
iny
jmp write
end: rts
}
printLeft:
{
ldx #00
ldy #129
write: lda TextTurnLeft,x
beq end
sta textarea,y
inx
iny
jmp write
end: rts
}
printRight:
{
ldx #00
ldy #129
write: lda TextTurnRight,x
beq end
sta textarea,y
inx
iny
jmp write
end: rts
}
printAround:
{
ldx #00
ldy #129
write: lda TextTurnAround,x
beq end
sta textarea,y
inx
iny
jmp write
end: rts
}
printHuh:
{
ldx #00
ldy #129
write: lda TextHuh,x
beq end
sta textarea,y
inx
iny
jmp write
end: rts
}
printPass:
{
ldx #00
ldy #129
write: lda TextPass,x
beq end
sta textarea,y
inx
iny
jmp write
end: rts
}
printDeathMessage:
{
ldx #00
write: lda TextDeath,x
beq end
sta textarea,x
inx
jmp write
end: rts
}
// Prints location of player to last line
printLocation:
{
clc
lda playerLocation
adc #$30 // Writing directly to screen ram
ldx #194 // So we need to add $30 to print decimal number
sta textarea, x
clc
lda playerLocation+1
adc #$30
ldx #198
sta textarea, x
rts
}
// Prints facing of player to last line
printFacing:
{
ldx #168
lda playerFacing
cmp #01
beq north
cmp #02
beq west
cmp #03
beq south
east: lda #'e'
sta textarea,x
rts
north: lda #'n'
sta textarea,x
rts
west: lda #'w'
sta textarea,x
rts
south: lda #'s'
sta textarea,x
rts
}
// *** Converts 4-bit bcd number to printable format
.pseudocommand addAscii
{
clc
adc #$30
}
.pseudocommand ror4
{
clc
ror
ror
ror
ror
}
// *** Prints amount of food to screen
printFood:
{
lda playerFood
sta binaryValue
lda playerFood+1
sta binaryValue+1
jsr binbcd16
ldx #positionFood // Cursor starting position 34
lda #' '
sta textarea,x
sta textarea+1,x
sta textarea+2,x
sta textarea+3,x
sta textarea+4,x
sta textarea+5,x
stx cursorStart
jsr printStat
rts
}
// *** Prints amount of hitpoints to screen
printHitpoints:
{
// First convert to bcd
lda playerHitpoints
sta binaryValue
lda playerHitpoints+1
sta binaryValue+1
jsr binbcd16
ldx #positionHitpoints // Cursor starting position 74
stx cursorStart
jsr printStat
rts
}
// *** Prints amount of gold to screen
printGold:
{
// First convert to bcd
lda playerGold
sta binaryValue
lda playerGold+1
sta binaryValue+1
jsr binbcd16
lda bcdValue
lda bcdValue+1
lda bcdValue+2
ldx #positionGold // Cursor starting position 114
stx cursorStart
jsr printStat
rts
}
printStat:
{
ldx cursorStart
ldy #03
checkHigh:
// Check for food decimal point
cpy #01
bne loadValue
lda cursorStart
cmp #positionFood // Food starts at cursor position 34
bne loadValue
lda bcdValue-1,y
and #$F0
:ror4
:addAscii
sta textarea,x
inx
lda #'.' // Write decimal point!
sta textarea,x
inx
jmp checkLow
loadValue:
lda bcdValue-1,y
and #$F0
bne writeHigh // Check for zero
cpx cursorStart // is it leading zero?
beq checkLow // Skip if so
writeHigh: // Else handle writing high bits of byte
:ror4
:addAscii
sta textarea,x
inx
checkLow:
lda bcdValue-1,y
and #$0F
bne writeLow // Check for zero
cpx cursorStart // is it leading zero?
beq checkForMore // Skip if so
writeLow:
:addAscii
sta textarea ,x
inx
checkForMore:
dey
bne checkHigh // Read more
rts
}
cursorStart:
.byte 00
// *** Converts 16-bit binary number to 24-bit bcd number
binbcd16:
{
sed // Switch to decimal mode
lda #00 // Ensure the result is clear
sta bcdValue+0
sta bcdValue+1
sta bcdValue+2
ldx #16 // Number of source bits
convertBit:
asl binaryValue+0 // Shift out one bit
rol binaryValue+1
lda bcdValue+0 // And add into result
adc bcdValue+0
sta bcdValue+0
lda bcdValue+1 // Propagating any carry..
adc bcdValue+1
sta bcdValue+1
lda bcdValue+2 // .. through the whole result
adc bcdValue+2
sta bcdValue+2
dex // And repeat for next bit
bne convertBit
cld // Back to binary
rts
}
binaryValue:
.word 00
bcdValue:
.byte 00, 00, 00
messu: .text " "
.text " "
.text " "
.text " "
.text " "
messu2: .text " food=73.4 "
.text " h.p.=22 "
.text " gold=0 "
.text " "
.text "facing: w.i.p. x: y: "
TextDeath:
.text " we mourn the passing of "
.text " the peasant and his computer "
.text " to invoke a miracle of resurrection "
.text " <hit esc key> "
.byte 0
// .text " "
// Command messages
TextCommand:
.text "command?"
.byte 0
TextForward:
.text "forward"
.byte 0
TextTurnRight:
.text "turn right"
.byte 0
TextTurnLeft:
.text "turn left"
.byte 0
TextTurnAround:
.text "turn around"
.byte 0
TextPass:
.text "pass"
.byte 0
TextHuh:
.text "huh?"
.byte 0
characterEnd: nop