-
Notifications
You must be signed in to change notification settings - Fork 7
/
libOSKRoutines.asm
316 lines (284 loc) · 13.4 KB
/
libOSKRoutines.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
;******************************************************************************
;* Output a space *
;******************************************************************************
;* Outputs : *
;* None *
;******************************************************************************
SPACE
lda #CHR_Space ; Load Space
jmp krljmp_CHROUT$ ; Print Space
;******************************************************************************
;* Print Two Bytes In HEX (PBYTE2) *
;******************************************************************************
;* Inputs : *
;* Acc = Hi Byte *
;* X Reg = Lo Byte *
;******************************************************************************
PBYTE2
pha ; Push Hi byte to stack temporarily
txa ; Transfer Lo byte to accumulator
jsr PBYTE1 ; Print out Lo byte first
pla ; Get back Hi byte from stack and print that
;******************************************************************************
;* Print Byte In HEX (PBYTE1) *
;******************************************************************************
;* Inputs : *
;* Acc = Byte *
;******************************************************************************
PBYTE1
pha ; Push Byte to stack temporarily
lsr ; divide by 2
lsr ; divide by 4
lsr ; divide by 8
lsr ; divide by 16
jsr PBYTE ; print most siginificant nibble value (most significant 4 bits)
tax ; transfor Acc to X
pla ; get back orginal value from stack
and #15 ; mask out only least significant nibble (4 bits) and print that
PBYTE
clc
adc #$F6 ; check if greater than 10
bcc @PBYTE ; if carry is clear
adc #6 ; addes the Ascii code 'A' offset
@PBYTE
adc #$3A ; add ascii code '0' value
jmp krljmp_CHROUT$ ; print out accumulator
;******************************************************************************
;* Inputs Two Bytes In HEX (IBYTE2) *
;******************************************************************************
;* Outputs : *
;* Acc = Hi Byte *
;* X Reg = Lo Byte *
;******************************************************************************
IBYTE2
jsr IBYTE1 ; gets Hi Byte
pha ; store away temporarily
jsr IBYTE1 ; gets Lo Byte
tax ; move to X
pla ; get back Hi Byte
rts
;******************************************************************************
;* Input Byte In HEX (IBYTE1) *
;******************************************************************************
;* Outputs : *
;* Acc = Byte *
;******************************************************************************
IBYTE1
jsr INPUT_COMMAND ; get character
cmp #CHR_Return ; is it 'Return'?
bne @IBYTE1 ; No
jmp ERROR ; Yes, jump to Error
@IBYTE1
jsr IBYTE ; Get Most Significant nibble (4 Bits)
asl ; Multiply by 2
asl ; Multiply by 4
asl ; Multiply by 8
asl ; Multiply by 16
sta TEMP ; Store in Temp Byte
jsr INPUT_COMMAND ; Get Next Character
cmp #CHR_Return ; is it 'Return'?
bne @IBYTE2 ; No
jmp ERROR ; Yes, jump to error
@IBYTE2
jsr IBYTE ; Get Least Siginificant nibble (4 bits)
ora TEMP ; Merge with what we have already got
rts ; Return complete inputted byte value
IBYTE
clc
adc #$D0 ; Normalise Number
cmp #10 ; Test for 10
bcc @IBYTE ; Is lower than
sec
sbc #7 ; Relign number
@IBYTE
rts
;******************************************************************************
;* Show Error prompt *
;******************************************************************************
;* Outputs : *
;* None *
;******************************************************************************
ERROR
lda #"?"
jsr krljmp_CHROUT$ ; Print Out Character
;******************************************************************************
;* Show Ready prompt *
;******************************************************************************
;* Outputs : *
;* None *
;******************************************************************************
READY
jsr PrintCarrageReturnAndLineFeed
READY1
lda #">"
jsr krljmp_CHROUT$ ; Print out Character
jmp TOKANISER_COMMAND ; Jump back to Command Line
;******************************************************************************
;* Input Command from command line *
;******************************************************************************
;* Outputs : *
;* Acc = Command *
;******************************************************************************
INPUT_COMMAND
jsr krljmp_CHRIN$ ; Get Command
cmp #CHR_Return ; Check for 'Enter'
beq @INPUT ; Yes, finish input reading
cmp #CHR_Space
beq INPUT_COMMAND ; Is Space, then ignore and get next character
;cmp #"!" ; check for '!'
;bcc INPUT_COMMAND ; go back and fetch next command
;cmp #"[" ; check for '['
;bcs INPUT_COMMAND ; go back and fetch next command
@INPUT
rts
;******************************************************************************
;* Get 2 Byte Hex Value from Assembly Temp Text Store *
;******************************************************************************
;* Inputs : *
;* Y Reg = Starting Index in COM_TEXT *
;* Outputs : *
;* Acc = Hi Byte *
;* X Reg = Lo Byte *
;******************************************************************************
GET_HEX_2BYTE_VALUE
jsr GET_HEX_1BYTE_VALUE ; Get 2 digit hex value
pha ; Store result on Stack
iny ; Increase character position value
jsr GET_HEX_1BYTE_VALUE ; Get 2 digit hex value
tax ; move that to X
pla ; get back value from stact
rts
;******************************************************************************
;* Get 1 Byte Hex Value from Assembly Temp Text Store *
;******************************************************************************
;* Inputs : *
;* Y Reg = Starting Index in COM_TEXT *
;* Outputs : *
;* Acc = Byte *
;******************************************************************************
GET_HEX_1BYTE_VALUE
lda COM_TEXT - 1,y ; Get 1 digit from keyboard buffer
jsr IBYTE ; Run through hex convertor
asl ; x 2
asl ; x 4
asl ; x 8
asl ; x 16
sta TEMP ; Store Result away Temporarily
iny ; increase character position index
lda COM_TEXT - 1,y ; get next character
jsr IBYTE ; Run through hex convertor
ora TEMP ; OR result with previous value
rts
;******************************************************************************
;* NoByt *
;* This determines how many bytes to add for next instruction based on *
;* mode. *
;******************************************************************************
;* Inputs : *
;* Outputs : *
;******************************************************************************
NOBYT
lda #2 ; Default to 2 bytes
sta COM_NB ; Store in Command NoBytes
lda COM_MODE ; Load Mode
cmp #MODE_ABSOLUTE ; is it Absolute
bne NOB2 ; No, try another mode
jmp NOB1 ; Yes, then jump to absolute
NOB2
cmp #MODE_ABSOLUTE_X; is it Absolute,x
bne NOB3 ; No, try another mode
jmp NOB1 ; jump to absolute
NOB3
cmp #MODE_ABSOLUTE_Y; is it Absolute,y
bne NOB4 ; No, try another mode
jmp NOB1 ; Jump to Absolute mode
NOB4
cmp #MODE_INDIRECT ; is it Indirect
bne NOB5 ; No, try another mode
NOB1
lda #3 ; 3 byte opCodes
sta COM_NB ; Store in Command NoBytes
NOB5
lda COM_MODE ; Load Mode
cmp #MODE_IMPLIED ; Is it implied
bne NOB6 ; No, Jump out of routine
lda #1 ; Yes, then ist only 1 byte
sta COM_NB ; Store in Command NoBytes
NOB6
rts
;******************************************************************************
;* Tokanise the command aquired from command line *
;******************************************************************************
;* Outputs : *
;* Y = Command Index *
;******************************************************************************
TOKANISER_COMMAND
jsr INPUT_COMMAND ; Get Command
cmp #CHR_Return ; Check For 'Return'
beq READY ; Goto Ready Sign
ldy #0 ; Reset Comamnd Counter
TOK1
cmp COMMANDS,y ; Compare with command list
beq TOK2 ; identified the command
iny ; No match, so check next one
cpy #COMMANDPOINTERS - COMMANDS ; Number Of Commands
bne TOK1 ; keep trying
jmp ERROR ; no command found, so error
TOK2
tya ; Command found
asl ; multply by 2
tay ; move to index offset
lda COMMANDPOINTERS,y ; load command pointer lo
sta HT
lda COMMANDPOINTERS+1,y ; load command pointer hi
sta HT + 1
jmp (HTVEC) ; jump to the command
;******************************************************************************
PrintCarrageReturnAndLineFeed
lda #CHR_Return
jmp krljmp_CHROUT$
;******************************************************************************
;* ADDNB *
;* Add Com_NB to AddVec *
;******************************************************************************
;* Inputs : Com_NB : No of bytes to add *
;* : AddVec : The Vector to Add Com_NB too *
;* Outputs : AddVec : The resulting Vector *
;******************************************************************************
ADDNB
lda ADDVEC
clc
adc COM_NB
sta ADDVEC
bcc @ADDNB
inc ADDVEC + 1
@ADDNB
rts
COMMANDS
TEXT ">racdfghilmostx"
BYTE $3A, $3B, $2C, $23, $24, $25, $40;, $3F
BYTE $00
COMMANDPOINTERS
WORD TOKANISER_COMMAND
WORD COM_REGISTER
WORD COM_ASSEMBLE
WORD COM_COMMAND
WORD COM_DISASSEMBLE
WORD COM_FILL
WORD COM_GOSUB
WORD COM_HUNT
WORD COM_INTERP
WORD COM_LOAD
WORD COM_MEMORY
WORD COM_OUTPUT
WORD COM_SAVE
WORD COM_TRANSFER
WORD COM_EXIT
WORD COM_MEMORYPUT
WORD COM_REGISTERPUT
WORD COM_ASSEMBLE
WORD COM_DECIMAL
WORD COM_HEXDEC
WORD COM_BINARY
WORD COM_OCTAL
;WORD COM_HELP