-
Notifications
You must be signed in to change notification settings - Fork 8
/
basic.s
276 lines (209 loc) · 3.75 KB
/
basic.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
;#######################################################################
; BASIC Program Save/Load Routines
;#######################################################################
;-----------------------------------------------------------------------
; Program I/O subroutine
SAVELOAD SUBROUTINE
LDA #1
CMP LOADB
BEQ .bload
LDA #1
CMP SAVEB
BEQ .bjmp
RTS
.bjmp
JMP .bsave
.bload
LDA #0
STA LOADB ; Clear BASIC load flag
JSR CLRSCR
LDX #0
LDY #0
JSR GOTOXY
LDA #<L_PROMPT
LDY #>L_PROMPT
JSR PRINTSTR
.keys
LDA KBDNEW
BEQ .keys ; wait for keypress
LDA #$0
STA KBDNEW ; reset keypress flag
JSR CLRSCR
LDX #0
LDY #0
JSR GOTOXY
LDA #<L_WAIT
LDY #>L_WAIT
JSR PRINTSTR
LDX #0
LDY #2
JSR GOTOXY
JSR XINITRX ; initial XMODEM transmission
JSR XRECV ; receive first block of data
LDX XABRT
CPX #1 ; check abort flag
BEQ .lmenu ; return to menu
LDX #2
LDA XBUF,X
STA PTRLO
INX
LDA XBUF,X
STA PTRHI
INX
STX XBUFIX ; set buffer index to first program byte after reading memory start loc
.lloop ; Load BASIC loop
LDX XBUFIX
LDA XBUF,X
INC XBUFIX
;TAX ; Debug print
;JSR HEXOUT
;TXA
LDY #0
STA (PTRLO),Y
LDX XBUFIX
CPX #$82 ; check for end of buffer
BNE .inc16a
; finished loading the block
LDX XFINAL ; was it the final block?
CPX #1
BEQ .ldone
; it was not the final block
LDX #2
STX XBUFIX ; reset buffer index
JSR XRECV ; receive next block of data
.inc16a
; increment BASIC ptr
INC PTRLO
BNE .inc16ena
INC PTRLO+1
.inc16ena
LDX XABRT
CPX #1 ; check abort flag
BEQ .ldone
JMP .lloop
; end of BASIC LOAD code
.ldone
; Save the current End of Basic Location
LDX PTRLO
STX EOB
LDX PTRLO+1
STX EOB+1
LDA #<L_DONE
LDY #>L_DONE
JSR PRINTSTR
; exit to menu
.lmenu
RTS
.lnorx
LDA KBDNEW
BEQ .lnokey
LDA #$0
STA KBDNEW
LDA KBDBYTE
BMI .ltrmkey ; Key's above $80 are special keys for the terminal
.ltrmkey
CMP #$F0 ; $F0 - Menu key
BEQ .lmenu
JMP .lloop
.lnokey
JMP .lloop
.bsave
LDA #0
STA SAVEB ; Clear BASIC save flag
STA FNAMEW
STA FNAMER
STA FNAME
JSR CLRSCR
LDX #0
LDY #0
JSR GOTOXY
LDA #<S_WAIT
LDY #>S_WAIT
JSR PRINTSTR
; Begin Saving
JSR XINITTX ; Initialize first XMODEM packet.
LDX #0
STX BTMP1
LDX #<SOB
STX PTRLO
LDY #>SOB
STY PTRHI
LDX BTMP1
LDY #0
LDA (PTRLO),Y
STA ENDLO ; Store end lo byte
; send SOB address
LDA #<SOB
JSR XSEND
LDA #>SOB
JSR XSEND
LDA ENDLO
.sloop
LDX BTMP1
LDY #0
LDA (PTRLO),Y
CPX #$01
BNE .read2
STA ENDHI ; store end hi byte
INX
STX BTMP1 ; increment BTMP1
CMP #0 ; check for hi byte of zero
BNE .read2 ; continue if not zero
LDA ENDLO
CMP #0 ; check for lo byte also zero
BEQ .savend ; reached program end
LDA ENDHI ; restore value in accumulator
.read2
LDX BTMP1
CPX #0
BNE .read3
INX
STX BTMP1 ; increment BTMP1
.read3
JSR XSEND ; send BASIC program byte
; increment BASIC ptr
INC PTRLO
BNE .inc16enb
INC PTRLO+1
.inc16enb
LDX PTRHI
CPX ENDHI ; cmp step ptr to end hi
BNE .sloop ; keep reading
LDX PTRLO
CPX ENDLO ; cmp step ptr to end lo
BNE .sloop ; keep reading
; reached the end of the current BASIC line, check for next pointer
LDY #0
LDA (PTRLO),Y
.newlo
PHA
JSR XSEND ; send the byte
PLA
STA ENDLO ; save the new ENDLO byte for the next line
LDX #1
STX BTMP1 ; set BTMP1 to read the ENDHI byte next
; increment BASIC ptr
INC PTRLO
BNE .inc16enc
INC PTRLO+1
.inc16enc
JMP .sloop
.savend
; end of BASIC SAVE code
LDA ENDHI
JSR XSEND ; send final end hi byte
JSR XFINISH ; finish transfer
LDA #<S_DONE
LDY #>S_DONE
JSR PRINTSTR
RTS
L_PROMPT
DC.B "HIT ANY KEY WHEN SENDER IS READY. ",0
S_WAIT
DC.B "SENDING PROGRAM DATA... ",0
S_DONE
DC.B "SAVING DONE!",0
L_WAIT
DC.B "WAITING FOR PROGRAM DATA... ",0
L_DONE
DC.B "LOADING DONE!",0