-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTutorial Routines.asm
373 lines (353 loc) · 19.3 KB
/
Tutorial Routines.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
;*******************************************************************************
;* *
;* Tutorial Routines *
;* *
;*******************************************************************************
;* This has general routines for the tutorials *
;*******************************************************************************
;* Inputs : None *
;* Outputs : None *
;* : None *
;*******************************************************************************
;* Variables *
Print=$ffd2
Basin=$ffcf
FromNum=$b79e
GetLine=$a560
addlo=247
addhi=248
htlo=$14
hthi=$15
;*******************************************************************************
;* Marcos *
defm PrintText
ldy #>/1 ; Load Hi Byte to Y
lda #</1 ; Load Lo Byte to Acc.
jsr String ; Print The text until hit Zero
endm
;*******************************************************************************
;* *
;* GetNumber *
;* *
;*******************************************************************************
;* This asks the user to imput an number between 0 and 255 *
;*******************************************************************************
;* Inputs : None *
;* Outputs : X Register Contains Lo Byte *
;* : Acc Register Contains Hi Byte *
;*******************************************************************************
;* Variables *
;*******************************************************************************
;* Code *
GetNumber
jsr GetLine
lda #1
ldx #$ff
sta $7b
stx $7a
jsr $0073 ; 8-bit number
jsr $b79e ; 8-bit Number
rts
;*******************************************************************************
;* *
;* Get16BitNumber *
;* *
;*******************************************************************************
;* This asks the user to input an number between 0 and 65535 *
;*******************************************************************************
;* Inputs : None *
;* Outputs : x is Lo Byte *
;* : Acc is Hi Byte *
;*******************************************************************************
;* Variables *
;*******************************************************************************
;* Code *
Get16BitNumber
jsr GetLine
lda #1
ldx #$ff
sta $7b
stx $7a
jsr $0073 ; 16-bit number
jsr $ad8a
jsr $b7f7 ; 16-bit Number
;jsr $a96b
ldx $14
lda $15
rts
;*******************************************************************************
;* *
;* PrintAccumlator *
;* *
;*******************************************************************************
;* This prints the number from the Accumulator to binary / Hex / Decimal *
;*******************************************************************************
;* Inputs : Accumulator : Number To Print Out *
;*******************************************************************************
;* Variables *
StatusState
brk
NumberToPrint
brk
NumberToWork
brk
;*******************************************************************************
;* Code *
PrintAccumlator
php
sta NumberToPrint ; Store away the Accumulator
pla ; Pull Status From Stack
sta StatusState ; Store Status
pha
pha ; Push the Acc to Stack
txa ; Move X to Acc.
pha ; Push Acc (x) to Stack
tya ; Move Y to Acc.
pha ; Push Acc (y) to Stack
ldy #>rgtxt ; Load Hi Byte to Y
lda #<rgtxt ; Load Lo Byte to Acc.
jsr String ; Print The text until hit Zero
lda StatusState
jsr status_register
jsr space
jsr BinPrint ; Print Binary Array for NumberToPrint
jsr space ; Add a space
jsr HexadecimalPrint ; Print Hexadecimal for NumberToPrint
jsr space ; Add a space
jsr DecimalPrint ; Print Decimal for NumberToPrint
jsr CarrageReturn
pla ; Pull Acc (y) off Stack
tay ; Move Acc. To Y
pla ; Pull Acc (x) off Stack
tax ; Move Acc. to X
pla ; Pull Acc off Stack
plp
rts ; Return Back
;*******************************************************************************
;*******************************************************************************
;* *
;* space *
;* *
;*******************************************************************************
;* This rotuines prints a space on the screen *
;*******************************************************************************
;* Inputs : None *
;*******************************************************************************
;* Variables *
;*******************************************************************************
;* Code *
space
lda #CHR_Space ; Load Space Character
jmp Print ; Print This Character
;*******************************************************************************
;*******************************************************************************
;* *
;* CarrageReturn *
;* *
;*******************************************************************************
;* This rotuines prints a space on the screen *
;*******************************************************************************
;* Inputs : None *
;*******************************************************************************
;* Variables *
;*******************************************************************************
;* Code *
CarrageReturn
lda #CHR_Return ; Load Return Character
jmp Print ; Print This Character
;*******************************************************************************
;*******************************************************************************
;* *
;* String *
;* *
;*******************************************************************************
;* This routine prints a string of characters terminating in a zero byte *
;*******************************************************************************
;* Inputs : Accumulator : Lo Byte Address of String *
;* : Y Register : Hi Byte Address of String *
;*******************************************************************************
;* Variables *
;*******************************************************************************
;* Code *
String
sta htlo ; Store Lo Byte Address of String
sty hthi ; Store Hi Byte Address of String
string_nxtchr
ldy #0 ; Initialise Index Y
lda (htlo),y ; Load Character at address + Y
cmp #0 ; Is it Zero?
beq string_rts ; If Zero, goto end of routine
jsr Print ; Print this character
clc ; Clear The Carry
inc htlo ; Increase Lo Byte
bne string_nxtchr ; Branch away if Page Not Crossed
inc hthi ; Increase Hi byte
jmp string_nxtchr ; Jump back to get Next Character
string_rts
rts ; Return Back
;*******************************************************************************
rgtxt
byte CHR_Return
text "nv-bdizc binary hex dec."
byte CHR_Return
brk
;*******************************************************************************
;* *
;* status_register *
;* *
;*******************************************************************************
;* This routine prints the contents of the status register *
;*******************************************************************************
;* Inputs : Accumulator : Status Register *
;*******************************************************************************
;* Variables *
streg
brk
;*******************************************************************************
;* Code *
status_register
ldy #0 ; Initialise Y Register
streg1
sta streg ; Store Acc. into Status Register Variable
streg3
asl streg ; logically shift the acc left, and carry set or not
lda #0 ; Load Zero into Accu.
adc #"0" ; Add "0" to Acc. with carry
cpy #2 ; is y = 2
bne streg2 ; if yes, branch past the '-' symbol
lda #"-" ; Load Acc with "-"
streg2
jsr Print ; Print The contents of the Acc
iny ; increase the index Y
cpy#8 ; test for 8 (8th bit of the number)
bne streg3 ; Branch if not equal back to next bit
rts ; Return Back
;*******************************************************************************
;*******************************************************************************
;* *
;* BinPrint *
;* *
;*******************************************************************************
;* This routine prints the contents NumberToPrint as a binary number *
;*******************************************************************************
;* Inputs : None *
;*******************************************************************************
;* Variables *
;*******************************************************************************
;* Code *
BinPrint
jsr prPercent ; Print "%"
ldy #0 ; Initialise Y Index Register with zero
lda NumberToPrint ; Load Acc with number to print
sta NumberToWork ; Store Acc to Number To Work
binpr4
asl NumberToWork ; Logically shift left Number to Work into Carry
lda #0 ; Load Acc with Zero
adc #"0 ; Add Acc with "0" plus Carry
jsr Print ; Print this character either '0' ot '1'
iny ; increase Y index
cpy #8 ; have we hit bit 8?
bne binpr4 ; No, get next Bit
rts ; Return Back
;*******************************************************************************
;*******************************************************************************
;* *
;* DecimalPrint *
;* *
;*******************************************************************************
;* This routine prints the contents NumberToPrint as a decimal number *
;*******************************************************************************
;* Inputs : None *
;*******************************************************************************
;* Variables *
;*******************************************************************************
;* Code *
DecimalPrint
jsr prHash ; Print "#"
lda #$00 ; Initialise Acc with zero
ldx NumberToPrint ; Load X Register with NumberToPrint
stx NumberToWork ; Store X Register to NumberToWork
jmp $bdcd ; Jump To Basic Decimal Number Print Routine
;*******************************************************************************
prDollar
lda #"$"
byte 44
prBracketOpen
lda #"("
byte 44
prBracketClosed
lda #")"
byte 44
prComma
lda #","
byte 44
prx
lda #"x"
byte 44
pry
lda #"y"
byte 44
prPercent
lda #"%"
byte 44
prHash
lda #"#"
jmp Print
;*******************************************************************************
;* *
;* HexaDecimalPrint *
;* *
;*******************************************************************************
;* This routine prints the contents NumberToPrint as a hexadecimal number *
;*******************************************************************************
;* Inputs : None *
;*******************************************************************************
;* Variables *
;*******************************************************************************
;* Code *
HexadecimalPrint
jsr prDollar ; Print a "$"
ldx #$00 ; Initialise X Register with Zero
lda NumberToPrint ; Load Acc with NumberToPrint
sta NumberToWork ; Store Acc to NumberToPrint
jmp pbyte2 ; Jump to Hexadecimal routine
;*******************************************************************************
;*******************************************************************************
;* *
;* pbyte2 *
;* *
;*******************************************************************************
;* This routine evaluates and prints a four character hexadecimal number *
;*******************************************************************************
;* Inputs : Accumulator : Lo Byte of the number to be converted *
;* X Register : Hi Byte of the number to be converted *
;*******************************************************************************
;* Variables *
;*******************************************************************************
;* Code *
pbyte2
pha ; Push Acc to the Stack
txa ; Tansfer X register To Acc
jsr pbyte1 ; Execute 2 digit Hexadecimal convertor
pla ; Pull Acc from Stack
pbyte1
pha ; Push Acc to the Stack
; Convert Acc into a nibble Top '4 bits'
lsr ; Logically shift Right Acc
lsr ; Logically shift Right Acc
lsr ; Logically shift Right Acc
lsr ; Logically shift Right Acc
jsr pbyte ; Execute 1 digit Hexadecimal number
tax ; Transfer Acc back into X Register
pla ; Pull Acc from the Stack
and #15 ; AND with %00001111 to filter out lower nibble
pbyte
clc ; Clear the Carry
; Perform Test weather number is greater than 10
adc #$f6 ; Add #$F6 to Acc with carry
bcc pbyte_skip ; Branch is carry is still clear
adc #6 ; Add #$06 to Acc to align PETSCII Character 'A'
pbyte_skip
adc #$3a ; Add #$3A to align for PETSCII Character '0'
jmp Print ; Jump to the Print Routine for that character
;*******************************************************************************