-
Notifications
You must be signed in to change notification settings - Fork 1
/
loadsynt.asm
583 lines (533 loc) · 16.4 KB
/
loadsynt.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
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
;
; Slowdos Source Code
;
;
; $Id: loadsynt.asm,v 1.3 2003/06/17 17:39:10 dom Exp $
; $Author: dom $
; $Date: 2003/06/17 17:39:10 $
;
; Handle load/save syntax parsing
MODULE loadsave
INCLUDE "slowdos.def"
INCLUDE "syntaxdefs.def"
;; Error functions
EXTERN errorn
EXTERN usezer
EXTERN expt1n
EXTERN clufia
EXTERN rdopen
EXTERN rdblok
EXTERN wropen
EXTERN wrblok
EXTERN wrclos
EXTERN wos
EXTERN ros
;; Exported routines
PUBLIC load
PUBLIC save
PUBLIC merge
PUBLIC verify
PUBLIC snpcnt
PUBLIC settapn
PUBLIC settap
command_type: defb 0 ; VARIABLE - command required
; Load/save/merge syntax checking
; Syntax:
;
; LOAD Pdd"f"[S][!]
; LOAD Pdd"f" SCREEN$
; LOAD Pdd"f" DATA
; LOAD Pdd"f" CODE [a][,d]
; LOAD @dd,tt,ss,aa
load: ld a,1 ; Indicate "LOAD"
load0: ld (command_type),a
call rout32 ; Check for '@'
cp '@'
jp z,seclod ; Was a '@' goto the sector load routine
jr loadud
save: xor a ; Indicate "SAVE"
jr load0
verify: ld a,2 ; Indicate "VERIFY"
jr merge1
;And the merge routine
merge: ld a,3 ; Indidcate "MERGE"
merge1: ld (command_type),a
call rout32
loadud: call getdrv1 ; Get drives, enter with next char in a
call cksemi ; Look for a semi colon,comma,double quote
;0=save, 1=load,2=verify,3=merge
savetc: ld a,(command_type)
call settap ;??
ld ix,ufia
call exptex ; We want a string
call syntax ; Check if in syntax mode
jr z,sadata ; If we're in syntax don't touch variables
ld hl,flags
res 5,(hl)
call clufia ; clear ufia filename, hl = ufia+2
ld (ix+15),0 ; clear directory flags
call getstr ; Get the string into ufia+2
jr z,sadata ; Valid filename
ld hl,flags3 ; Filename is wild, check if in .TAP mode
bit 0,(hl)
jp z,error_filename ; Not in .TAP mode - bad filename
sadata: call rout24 ; Check for a '!'
cp '!'
jr nz,sadat0
ld hl,flags ; If so, then indicate headerless mode
set 5,(hl)
call rout32 ; Get next character
sadat0: cp 228 ; DATA
jr nz,sascr
ld a,(command_type) ; Check command, if MERGE then Nonsense in BASIC
cp 3
jp z,error_nonsense
call rout32
call rom3
defw 28B2h ; look vars
set 7,c
jr nc,savold
ld hl,0
ld a,(command_type)
dec a
jr z,savnew
call errorn
defb 1 ;var not found
savold: jp nz,error_nonsense
call syntax
jr z,sadat1
inc hl
;Copy the length...
call readbyte
ld (ix+16),a
inc hl
call readbyte
ld (ix+17),a
inc hl
;Variable name...
savnew: call syntax
jr z,sadat1
ld (ix+19),c
ld a,1
bit 6,c
jr z,savtyp
inc a
;Save the file type...
savtyp: ld (ix+15),a
sadat1: ex de,hl
call rout32
cp ')'
jp nz,error_nonsense ;error_nonsense
call rout32
call ckend
ex de,hl
jp saall
sascr: cp 170 ;SCREEN$
jr nz,sacod
ld a,(command_type) ; MERGE is not an appropriate type
cp 3
jp z,error_nonsense
call rout32
call ckend ; Check for end
ld (ix+16),0 ; Set up file length and start for SCREEN$
ld (ix+17),27
ld hl,16384
ld (ix+18),l
ld (ix+19),h
jr satyp3 ; hl = load address
sacod: cp 175 ;CODE
jr nz,saline
ld a,(command_type) ; Once more MERGE is not an appropriate command
cp 3
jp z,error_nonsense
call rout32
call ckenqu ; Check for end
jr nz,sacod1 ; Jump if more parameters
ld a,(command_type) ; SAVE with no parameters makes no sense
and a
jp z,error_nonsense
call usezer ; Stack 0 for first parameter
jr sacod2
sacod1: call expt1n ; Get a number (we already have 1 char)
call rout24 ; Check for comma
cp ','
jr z,sacod3
ld a,(command_type) ; If SAVE and only one parameter then nonsense
and a
jp z,error_nonsense
sacod2: call usezer ; Stack 0 for second parameter
jr sacod4
sacod3: call e32_1n ; Get second parameter
sacod4: call ckend ; End of line
call getnum ; Get second parameter
ld (ix+16),c ; Save length in ufia
ld (ix+17),b
call getnum ; Get first parameter
ld (ix+18),c ; Save load address in ufia
ld (ix+19),b
ld h,b ; hl = load address
ld l,c
;Code +scr$ types...
satyp3: ld (ix+15),3 ; Indicate filetype CODE expected
jr saall
; Snapshot handling
saline: and 223
cp 'S'
jr nz,salin1
call rout32 ; Get next character
ld b,48 ;value for 32765 (lock)
ld h,176 ;ldir
ld l,237
cp '!' ; '!' not supplied thus lock paging
jr nz,snap0
call rout32
ld b,16 ; Normal unlocked memory setup
ld hl,0 ; Don't copy the printer buffer
snap0: ld a,b
ld (lmode+1),a ; Save locked mode
ld (cpbuff),hl ; Save the printer buffer copying opcode
call ckend ; Check for end
ld a,(command_type) ; Anything apart from LOAD doesn't make sense
dec a
jp nz,error_nonsense
ld (ix+15),4 ; Indicate snapshot type
jr saall
; So, it must be BASIC then
salin1: cp 202 ;LINE
jr z,salin0 ; Jump if we had a LINE parameter
call ckend ; Otherwise check for end
ld (ix+18),0 ; Set up load address
ld (ix+19),80
jr satyp0
salin0: ld a,(command_type) ; We can't have a LINE without SAVE type
and a
jp nz,error_nonsense
call e32_1n ; Get number
call ckend ; Check for end of statemetn
call getnum ; Get line number off the stack
ld (ix+18),c ; And place it in the ufia
ld (ix+19),b
satyp0: ld (ix+15),0 ; Indicate BASIC type
ld hl,(23641) ; Calculate length of BASIC program
ld de,(23635)
scf
sbc hl,de
ld (ix+16),l ; And place in ufia
ld (ix+17),h
ld hl,(23627) ; Calculate length of variables
sbc hl,de
ld (ix+20),l ; And place in ufia
ld (ix+21),h
ex de,hl ; hl = (23635) = load address
saall: ld a,(command_type) ; If commmand type is SAVE, goto save routine
and a
jp z,sacntl
cp 2 ; If its verify, then silently ignore
ret z
ld (saall2+1),hl
call rdopen ; Open the file
saall0: ld a,(temphd) ; Check disc header versus our ufia
cp (ix+15)
jr z,saall1
call errorn
defb 29 ;Wrong file type
saall1: cp 4 ; If it's a snapshot, goto snapshot handler
jp z,snpcnt
saall2: ld hl,0 ; Modified by above, contains load address
cp 3 ; CODE filetype
jr z,vrcntl
ld a,(command_type) ; So it must be BASIC/DATA Check for command LOAD
dec a
jr z,ldcntl
cp 2 ; Check for MERGE
jp z,mecntl
; Handles loading CODE/SCREEN$
vrcntl: push hl ; Save load address
ld l,(ix+16) ; Get file length
ld h,(ix+17)
ld bc,(temphd+1) ; Disc length
ld a,l ; If specified file length == 0 then skip checks
or h
jr z,vrcnt1
sbc hl,bc
jr c,repotr ; Incorrect file length
jr z,vrcnt1
ld a,(ix+15) ; No check that we requested a CODE file
cp 3
jr nz,repotr
vrcnt1: pop hl ; Check load address, if 0 then use file address
ld a,h
or l
jr nz,vrcnt2
ld hl,(temphd+3) ; Pick up file load address
vrcnt2: ex de,hl ; de = load address, bc = length to load
ldblok: jp rdblok
repotr: call errorn
defb 79 ;code length
;For basic progs +arrays
ldcntl: ld de,(temphd+1) ; File length
push hl ; Store load address
ld a,h
or l
jr nz,ldcnt1
inc de
inc de
inc de
ex de,hl
jr ldcnt2
ldcnt1: ld l,(ix+16) ; Get BASIC program length
ld h,(ix+17)
ex de,hl
scf
sbc hl,de
jr c,lddata
ldcnt2: ld de,5
add hl,de
ld b,h
ld c,l
call rom3
defw $1F05 ; test room
lddata: pop hl
ld a,(ix+15) ; If file type is BASIC
and a
jr z,ldprog
ld a,h
or l
jr z,lddat1
dec hl
ld b,(hl)
dec hl
ld c,(hl)
dec hl
inc bc
inc bc
inc bc
ld (23647),ix ; xptr
call rom3
defw $19E8 ; reclaim 2
ld ix,(23647)
lddat1: ld hl,(23641)
dec hl
ld bc,(temphd+1)
push bc
inc bc
inc bc
inc bc
ld a,(ix+19) ;variable
push af
call rom3
defw $1655 ;make room
inc hl
pop af
ld (hl),a
pop de
inc hl
ld (hl),e
inc hl
ld (hl),d
inc hl
ex de,hl
push hl
pop bc
jp ldblok
ldprog: ex de,hl
ld hl,(23641)
dec hl
ld (23647),ix
ld bc,(temphd+1)
push bc
call rom3
defw $19E5 ; reclaim 1
pop bc
push hl
push bc
call rom3
defw $1655 ; make room
ld ix,(23647)
inc hl
ld bc,(temphd+5) ;n len
add hl,bc
ld (23627),hl
ld hl,(temphd+3) ;LINE
ld a,h
and 11000000b
jr nz,ldprg1
ld (23618),hl
ld (iy+10),0
ldprg1: pop bc
pop de
jp ldblok
;Loading 48k snapshots
;This bit of code will be rewritten
;To handle .sna
defc basreg = wrisec
snpcnt: ld a,23
ld (page),a
; ld de,wrisec+256
ld de,basreg
ld bc,27
call rdblok
; ld hl,basreg+1
; ld de,wrisec
; ld bc,18
; ldir
ld a,(basreg) ;a=i
ld (imval+1),a
;Do ei/di
ld b,243
ld a,(basreg+19)
bit 2,a
jr z,snpcn1
ld b,251
snpcn1: ld a,b
ld (snppa4),a
ld hl,(basreg+25) ;l=im 0/1/2,h=border colour
ld a,l
ld (immode+1),a
ld a,h
ld (bordcr+1),a
ld a,(basreg+20)
ld (valr+1),a
ld hl,(basreg+21) ;af
ld (snppa5),hl
ld hl,(basreg+23) ;sp
ld (snppa3+1),hl
ld de,16384 ; Read in the screen within the .sna file
ld bc,6912
call rdblok
bordcr: ld a,0 ; Change the border colour
out (254),a
ld a,23 ; Read the printer buffer to somewhere safe
ld (page),a
ld de,wrisec+256
ld bc,256
call rdblok
ld a,16 ; Now read the rest of the code
ld (page),a
ld de,23296+256
ld bc,41984
call rdblok
ld hl,wrisec+256 ; Copy the printer buffer
ld de,23296
ld bc,256
cpbuff: ldir ; Will either be ldir/nop-nop depending
di ; Restore some of the standard registers
im 1
ld sp,basreg+1
pop hl
pop de
pop bc
pop af
exx
ex af,af'
pop hl
pop de
pop bc
pop iy
pop ix
imval: ld a,0
ld i,a
immode: ld a,0
bit 2,a
jr z,noim2
im 2
noim2: ld (snppa1+1),bc
push hl
push de
ld hl,snppag
ld de,16384
ld bc,snpend-snppag
ldir
pop de
pop hl
ld sp,(snppa5-snppag+16384)
jp 16384
snppag: ld bc,32765
ld a,16
out (c),a
lmode: ld a,48
out (c),a
snppa1: ld bc,0
valr: ld a,0
ld r,a
pop af
snppa3: ld sp,0
snppa4: ei
ret
snppa5: defw 0 ; VARIABLE
snpend:
;Merge control routine
mecntl: ld bc,(temphd+1)
push bc
inc bc
call rom3
defw 48 ;bc spaces
ld (hl),128
pop bc
push de
call rdblok
pop hl
ld de,(23635)
call rom3
defw 08D2h ; me-new-lp
ret
; Save file routine
sacntl:
push hl ; hl = save address
sacntl1: call wropen ; Open the file
pop de ; Get the save address back
ld c,(ix+16) ; Pick up the length from the ufia
ld b,(ix+17)
call wrblok ; Write the block
jp wrclos ; And close
; Sector load routine
seclod: call rout32
call gdrive ; get the drive
call rout24 ; we need a comma
cp ','
jp nz,error_nonsense
call e32_1n ; get track
cp ','
jp nz,error_nonsense
call e32_1n ; get sector
cp ','
jp nz,error_nonsense
call e32_1n ; get load address
seclo0: call ckend ; check for end of statement
call getnum ; get address off stack
ld (lodadd),bc
call getnum ; get sector off stack
ld a,b ; Check for sector > 255
and a
jr z,seclo1
error_parameter:
call errorn
defb 45 ;parameter error
seclo1: ld a,c
ld (sect),a
call getnum ; get track off disc
ld a,b ; check for track > 255
and a
jr nz,error_parameter
ld a,c
ld (sect+1),a
seclo3: ld de,(sect)
ld hl,(lodadd)
ld a,(command_type) ; check command type
and a ; SAVE
jp z,wos
jp ros ; READ
lodadd: defw 0 ;VARIABLE
sect: defw 0 ;VARIABLE
;Routine to set bit 6,(flags) if bit 6,(flags2)..
;Entry: a=command_type - if not relevent set to <>0
settapn: xor a
settap: ld hl,flags2
bit 6,(hl)
ret z
inc hl ;hl=flags3
res 0,(hl)
and a
ret z
set 0,(hl) ;have marked that we're in there!!
ret