-
Notifications
You must be signed in to change notification settings - Fork 84
/
load.main
406 lines (406 loc) · 6.51 KB
/
load.main
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
;CPUT"@1:C64/LOAD.MAIN"
;LOADER FOR RESIDENT PET 6502
;ASSEMBLER
;MUST SET LOC; 0= $0801, 1= $C800
.SKI
;DECEMBER 13,1979
;CONVERTED TO CBM64 BY RJF
;ON 07/28/82
.SKI
;CONSTANTS FROM PET BASIC 2.0
READY =$E391 ;(NREADY) [NOT KERNAL]
CLRCHN =$FFCC ;CLOSE I/O CHANNELS
CHKIN =$FFC6 ;OPEN INPUT CHANNEL
BASIN =$FFCF ;INPUT SOURCE BYTE
BASOUT =$FFD2 ;OUTPUT CHARACTER TO CHAN
STOP =$FFE1 ;TEST FOR STOP KEY
CLOSE =$FFC3 ;CLOSE FILE .A
SETLFS =$FFBA ;SET LA FA SA
SETNAM =$FFBD ;SETNAME
OPEN =$FFC0 ;OPEN FILE
;+++
;PAGE ZERO VARIABLES
;---
STATUS =$90 ;I/O STATUS BYTE
* =$FB
LDADDR *=*+2 ;LOAD ADDRESS
.PAG 'PET LOADER'
.IFE LOC <
;LINE OF BASIC TEXT TO ALLOW
; USER TO TYPE 'RUN'
* =$0801
.BYT 13,8,10,0,158 ;10 SYS(2063)
.BYT '(2063)',0,0,0
.SKI 5
>
.IFE LOC-1 <
* = $C800
>
LOAD
JSR CLRCHN ;CLOSE CHANNEL
LDA #0 ;CLEAR VARIABLES
STA RECCNT
STA RECCNT+1
STA OFFSET
STA OFFSET+1
STA STATUS ;CLEAR I/O STATUS
LDX #OFFMSG-MSGS ;ASK FOR OFFSET
JSR MSG
JSR RDOA ;READ OFFSET (MUST BE FOUR CHARACTERS)
BCC LOAD ;DO IT AGAIN
.SKI
LDX #OBJMSG-MSGS ;ASK FOR OFFEST
JSR MSG
LDX #40
STX INDEX
LD10 DEC INDEX
BEQ LOAD
JSR BASIN
CMP #$20
BEQ LD10
CMP #$D
BNE GOLOAD
JMP DONE ;RETURN EXITS LOADER...
.PAG
GOLOAD ;ASK FOR FILENAME
LDX #0
STX OBJLEN
BEQ LD30
LD20 JSR BASIN
CMP #$20
BEQ LD40
LD30 CMP #$D
BEQ LD40
LDX OBJLEN
CPX #15 ;MAX OF 16 CHARACTERS
BEQ LOAD
STA OBJFIL,X
INX
STX OBJLEN
JMP LD20
LD40 LDA #',
STA OBJFIL,X
INX
LDA #'S
STA OBJFIL,X
INX
STX OBJLEN
LDA #$D
JSR BASOUT
.PAG
;+++
; INIT THE DRIVE
;---
LDA #7
LDX #8
LDY #15
JSR SETLFS
LDA #'I
STA CHKSUM
LDA #'0
STA CHKSUM+1
LDX #<CHKSUM
LDY #>CHKSUM
LDA #2
JSR SETNAM
JSR OPEN
LDA STATUS ;READ STATUS AFTER OPEN
BEQ INITOK
CMP #$40 ;EOI IS OK
BNE ERRORX
INITOK LDA #7
JSR CLOSE
;+++
;OPEN OBJECT FILE
;---
LDA #7
LDX #8
LDY #7
JSR SETLFS
LDX #<OBJFIL
LDY #>OBJFIL
LDA OBJLEN
JSR SETNAM
JSR OPEN
LDA STATUS ;DID OPEN GO OK
BEQ LOAF
CMP #$40
BEQ LOAF
ERRORX JMP ERROR0 ;DISK ERROR
.PAG
;+++
;BEGIN LOAF
;---
LOAF
LDX #7 ;SET CHANNEL
JSR CHKIN
LH1 JSR STOP ;STOP KEY?
BNE LHH1
JMP ERROR3 ;YES BREAK.....
LHH1 JSR GETCHR
CMP #'; ;RECORD INITIATOR?
BNE LH1 ;NO...KEEP LOOKING
.SKI
LDA #0
STA CHKSUM
STA CHKSUM+1
STA INDEX
JSR GETBYT ;READ BYTE COUNT
BNE LH2 ;NOT LAST RECORD
;CHECK END RECORD COUNT
JSR GETBYT
CMP RECCNT+1
BEQ LH1D
JMP ERROR4
LH1D JSR GETBYT
CMP RECCNT
BNE ERROR4
JMP DONE
.SKI
LH2 STA BYTCNT
INC RECCNT
BNE LH1B
INC RECCNT+1
LH1B JSR ADDCHK ;LENGTH TO CHECKSUM
JSR GETBYT
PHA ;SAVE FOR CHECKSUM
CLC
ADC OFFSET+1 ;ADD IN THE OFFSET
STA LDADDR+1 ;HIGH BYTE ADDRESS
PLA
JSR ADDCHK ;CHECKSUM ADD
JSR GETBYT ;GET LOW ADDRESS
PHA ;SAVE FOR CHECKSUM
CLC
ADC OFFSET ;CARRY SET
STA LDADDR
BCC LH1C
INC LDADDR+1
LH1C PLA
JSR ADDCHK ;DO CHECKSUM
;
LDA RECCNT
CMP #1 ;ONLY WHEN LO = 1
BNE LH3
LDA #$0D ;PRINT EVERY 256
JSR BASOUT
JSR WROA ;WRITE LOAD ADDRESS
.SKI
LH3 JSR GETBYT
LDY INDEX
STY OBJLEN ;SAVE FOR LAST ADDRESS
INC INDEX
STA (LDADDR),Y ;STORE DATA
CMP (LDADDR),Y ;GOOD STORE?
BNE ERROR1 ;NO...
JSR ADDCHK
DEC BYTCNT ;LAST BYTE?
BNE LH3 ;NO...
.SKI
JSR GETBYT ;TEST CHECKSUM HI
CMP CHKSUM+1
BNE ERROR2 ;CHECKSUM ERROR
JSR GETBYT ;GET CHECKSUM LO
CMP CHKSUM
BNE ERROR2 ;CHECKSUM ERROR
LDA #'. ;FINISHED RECORD
JSR BASOUT
JMP LH1 ;CONTINUE NEXT RECORD
.SKI
ERROR0 LDX #DSKERR-MSGS
.BYT $2C
ERROR1 LDX #CMPERR-MSGS
.BYT $2C
ERROR2 LDX #CHKERR-MSGS
.BYT $2C
ERROR3 LDX #BRKMSG-MSGS
.BYT $2C
ERROR4 LDX #RECERR-MSGS
JSR MSG
.SKI
DONE ;FINISHED WITH LOAD
JSR CLRCHN
LDA #7
JSR CLOSE
CLC ;PRINT LAST ADDRESS LOADED
LDA OBJLEN ;ADD IN INDEX
ADC LDADDR
STA LDADDR
LDA LDADDR+1
ADC #0
STA LDADDR+1
LDA #13
JSR BASOUT
JSR WROA ;PRINT THE ADDRESS
LDX #DNMSG-MSGS
JSR MSG
JMP READY
.SKI 5
.PAG 'SUBROUTINES'
;+++
;PRINT MESSAGE
;---
MSG STX INDEX
MS10 LDX INDEX
LDA MSGS,X
PHP
AND #$7F
JSR BASOUT
INC INDEX
PLP
BPL MS10
RTS
.SKI
HEXIT CMP #': ;NUMERIC?
PHP
AND #$0F
PLP
BCC HEXOUT ;0-9
ADC #8 ;ALPHA ADD 8+CY=9
HEXOUT RTS
;+++
;GET FROM CHANNEL
;---
GETCHR
JSR BASIN
PHA
LDA STATUS
BEQ GETOK
CMP #$40
BNE GETERR
GETOK PLA
RTS
GETERR PLA ;ERROR GET OUT
PLA
PLA
PLA
PLA
JMP ERROR0
;+++
;DO CHECKSUM
;---
ADDCHK CLC
ADC CHKSUM
STA CHKSUM
BCC ADD10
INC CHKSUM+1
ADD10 RTS
.PAG
;+++
;READ HEX ADR, RETURN IN OFFSET
;AND CY=1
;IF SP CY=0
;---
RDOA
JSR GETCHR
CMP #$0D
BEQ RDOA2 ;CR IS ZERO
CMP #$20
BEQ RDOA3
JSR RDOB1
BCC RDOA3
STA OFFSET+1 ;GOT HI BYTE
.SKI
JSR RDOB
BCC RDOA3
STA OFFSET ;GOT LO BYTE
RDOA2 ;RETURN OK
SEC
RTS
RDOA3 ;RETURN BAD
CLC
RTS
;+++
;READ HEX BYTE AND RETURN IN .A
;AND CY=1 IF SP CY=0
;---
GETBYT
RDOB LDA #0 ;SPACE
STA DATA ;READ NEXT CHAR
JSR GETCHR
RDOB1 CMP #$20
BNE RDOB2
JSR GETCHR ;READ NEXT CHAR
CMP #$20
BNE RDOB3
CLC ;CY=0
RTS
RDOB2 JSR HEXIT ;TO HEX
ASL A
ASL A
ASL A
ASL A
STA DATA
JSR GETCHR
RDOB3
JSR HEXIT
ORA DATA
SEC
RTS
.PAG
;+++
;WRITE ADDRESS
;---
WROA
LDA LDADDR
PHA
LDA LDADDR+1
JSR WROB
PLA
;WRITE BYTE --- .A = BYTE
;UNPACK BYTE DATA INTO TWO ASCII
;CHARACTERS. .A=BYTE; .X, .A=CHARS
WROB PHA
LSR A
LSR A
LSR A
LSR A
JSR ASCII ;CONVERT TO ASCII
TAX
PLA
AND #$0F
JSR ASCII
;WRITE 2 CHARS-- .X, .A=CHARS
WRTWO PHA
TXA
JSR BASOUT
PLA
JMP BASOUT
ASCII CLC ;MAKE ASCII
ADC #$F6
BCC ASC1
ADC #$06
ASC1 ADC #$3A
RTS
.PAG
;+++
;DATA AREA
;---
CHKSUM *=*+2 ;CHECKSUM OF CURRENT
OFFSET *=*+2 ;LOAD OFFSET (ADDED)
BYTCNT *=*+1 ;COUNT OF CURRENT BYTES
RECCNT *=*+2 ;TOTAL RECORDS LOADED
INDEX *=*+1 ;INDEX FROM LOAD ADDRESS
DATA *=*+1 ;HEX BYTE IN TRANSIT
OBJFIL *=*+18 ;USER OBJECT FILE NAME
OBJLEN *=*+1 ;LENGTH OF FILE NAME
.SKI
MSGS
RECERR .BYT $D,'BAD RECORD COUN',$D4
BRKMSG .BYT $D,'BREAK',$8D
DNMSG .BYT $D,'END OF LOA',$C4
CMPERR .BYT $D,'NON-RAM LOA',$C4
CHKERR .BYT $D,'CHECKSUM ERRO',$D2
DSKERR .BYT $D,'FILE ERRO',$D2
OFFMSG .BYT $D,$D,$D
.IFE LOC <
.BYT 'LO'
>
.IFE LOC-1 <
.BYT 'HI'
>
.BYT 'LOAD.C64 V072882',$D
.BYT '(C) 1982 BY COMMODORE BUSINESS MACHINES',$D,$D
.BYT $D,'HEX OFFSET (CR IF NONE) ?',$A0
OBJMSG .BYT $D,'OBJECT FILE NAME ?',$A0
.END