-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcpmemu.mac
1686 lines (1420 loc) · 36.9 KB
/
cpmemu.mac
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
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;----------------------------------------------------------
; CP/M 2.2 emulator for UZI180
; extended from AS.C by Doug Braun
; Copyright (C) 1998 by Harold F. Bower
;----------------------------------------------------------
; This module may begin on any arbitrary Page (mod 256)
; boundary to ensure that the BIOS jump table is so aligned.
; It provides a minimal CP/M 2.2 functional subset to allow
; applications to execute in an UZI process. The only
; requirement on CP/M executables is that the first byte in
; the .COM file be a Far Jump (0C3H opcode). The Bdos code
; originated with AS.C by Doug Braun, but has been converted
; to assembly and extensively modified. H.F.Bower
;----------------------------------------------------------
.Z80
ASEG
ORG 100H
UZIX EQU 1
FCN10V1 EQU 0
IF UZIX
; functions for UZIX
ExitFcn EQU 11 ; Exit process
OpenFcn EQU 20 ; Open File
CloseFcn EQU 6 ; Close File
CreatFcn EQU 20 ; Create File through OpenFile
LinkFcn EQU 17 ; Rename?
Unlink EQU 33 ; unlink (delete) file
ReadFcn EQU 23 ; Read File
WriteFcn EQU 36 ; WriteFile at Position
SeekFcn EQU 25 ; Seek file (lseek in UZIX !!!)
SyncFcn EQU 29 ; Sync IObuffers
StatFcn EQU 27 ; Stat file
IoctlFcn EQU 15 ; IOctl
ELSE
; functions for UZI
ExitFcn EQU 0 ; Exit process
OpenFcn EQU 1 ; Open File
CloseFcn EQU 2 ; Close File
CreatFcn EQU 3 ; Create File
LinkFcn EQU 5 ; Rename?
Unlink EQU 6 ; unlink (delete) file
ReadFcn EQU 7 ; Read File
WriteFcn EQU 8 ; WriteFile at Position
SeekFcn EQU 9 ; Seek file
SyncFcn EQU 11 ; Sync IObuffers
StatFcn EQU 15 ; Stat file
IoctlFcn EQU 29 ; IOctl
ENDIF
; from FCNTL.H
O_CREAT EQU 0100h ; create and open file
O_TRUNC EQU 0200h ; open with truncation
O_NEW EQU 0400h ; create only if not exist
O_RDONLY EQU 0
O_WRONLY EQU 1
O_RDWR EQU 2
SEEK_SET EQU 0
SEEK_CUR EQU 1
SEEK_END EQU 2
; A couple of CP/M-specific values used in EMU.
fcb EQU 005CH ; Default CP/M FCB
buff EQU 0080H ; Default CP/M Buffer
; General-Purpose Ascii Character Equates.
BS EQU 08H ; Ascii BackSpace
TAB EQU 09H ; Ascii Horizontal Tab
LF EQU 0AH ; Ascii Line Feed
CR EQU 0DH ; Ascii Carriage Return
ESC EQU 1BH ; Ascii ESCape Char
; TTY Ioctl Functions for UZI180. Used by EMU and TTYASM.
; !!!!!-- Ensure definitions match those in unix.h --!!!!!
TIOCGETP EQU 0 ; UZI ioctl Return tty Parms
TIOCSETP EQU 1 ; UZI ioctl Set tty Parms
TIOCSETN EQU 2 ; UZI ioctl Return buffer count
TIOCTLSET EQU 9 ; UZI ioctl Unique - Disable Ctl Char Proc
TIOCTLRES EQU 10 ; UZI ioctl Unique - Enable Ctl Char Proc
; TTY Ioctl Functions for UZIX
TTY_COOKED EQU 0 ; buffered
TTY_RAW EQU 1 ; unbuffered, wait
TTY_RAW_UNBUFF EQU 2 ; unbuffered, no wait
TTY_RAWCHAR EQU 3 ; unbuffered, no wait, one char
; File Descriptors needed by EMU for Console IO.
STDIN EQU 0 ; file descriptor value of keyboard
STDOUT EQU 1 ; file descriptor value of display
.phase 0E300h
; Initialize both FCB entries to blank values
EStart: LD HL,fcbDat ; Move initial FCB
PUSH HL
LD DE,fcb ; into
LD BC,16 ; position
LDIR
POP HL
LD C,16 ; init 2nd entry
LDIR
; Catenate argv[] elements into default buffer
POP IX ; Skip argc
POP IX ; Get Ptr to argv[]
LD DE,buff+1 ; Pt to CP/M Dflt Buffer
LD C,0 ; Cnt to 0
INC IX ; Skip Argv[0]
INC IX
Cold0: LD L,(IX+0) ; Get Ptr to Arg element
INC IX
LD H,(IX+0)
INC IX
LD A,H
OR L ; End?
JR Z,Cold2 ; ..exit if Yes
LD A,' ' ; Add space separator for args
LD (DE),A
INC DE
INC C ; bump count
Cold1: LD A,(HL)
OR A ; End of string?
JR Z,Cold0 ; ..try next if Yes
CP 'a' ; ensure
JR C,NoCap ; it
CP 'z'+1 ; is
JR NC,NoCap ; UCase
AND 5FH
NoCap: LD (DE),A ; Move a byte
INC HL
INC C ; bump count
INC E ; bump ptr
JR NZ,Cold1 ; ..get next byte if no bfr ovfl
;..else 0FF->100H, terminate
DEC E ; (back up for Null-termination)
Cold2: XOR A
LD (DE),A ; Null-terminate for safety
LD HL,buff ; Pt to count loc'n in buff
LD (HL),C ; save total arg count
INC HL ; advance to 1st char
LD DE,fcb+1
CALL FilNm ; Get Name/Typ in 1st FCB
OR A ; (set End flag)
LD DE,fcb+17 ; (prepare)
CALL NZ,FilNm ; Get Tame/Typ in 2nd FCB if present
LD DE,dir
LD B,128
CALL ZeroDE ; Clear Directory Buffer
LD HL,0
LD (0003H),HL ; Clear IOBYTE and Default Drive/User
JP __bios ; Go to Cold Start setup
; Fill FCB Name.Typ fields with any present data
FilNm: LD A,(HL) ; Get char
INC HL ; bump
OR A ; End of String?
RET Z
CP ' ' ; "Whitespace"?
JR Z,FilNm0 ; ..jump if Yes
CP TAB
JR NZ,FilNm1 ; ..jump if No
FilNm0: DEC C ; Count down total length
LD A,C ; (prepare)
JR NZ,FilNm ; ..loop if Not End
RET ; ..else Exit showing EOL
FilNm1: LD B,8 ; Set length of Name field
PUSH DE ; save Ptr to Name[0]
CALL FilFl0 ; Get Name
POP DE ; restore Ptr to Name
OR A
RET Z ; ..return if End-of-Line
CP ' '
RET Z ; ..return if separator
CP '.'
JR Z,FilNm2 ; ..bypass char skip
FilNm3: LD A,(HL)
INC HL
OR A
RET Z ; Exit if End of Line
CP ' '
RET Z ; or End of Field
CP '.'
JR NZ,FilNm3 ; ..loop til End or period
FilNm2: LD A,E
ADD A,8 ; Adjust FCB ptr to type field
LD E,A
LD B,3
;..fall thru to get next char..
; Move bytes from (HL) to (DE) for Count in C, Count in B or Ch in {' ','.',0}
FilFld: LD A,(HL) ; Get Char
INC HL ; bump ptr
OR A ; End of String?
RET Z ; ..return if Yes
FilFl0: CP '.' ; Period?
RET Z
CP ' ' ; Space?
RET Z
LD (DE),A ; Else Store byte
INC DE ; bump dest ptr
DEC C ; End of Input String?
LD A,C ; (prepare)
RET Z ; .return End if Yes
DJNZ FilFld ; ..loop til field counter ends
OR 0FFH ; Return flag
RET
fcbDat: DEFB 0
DEFM ' '
DEFB 0,0,0,0
;==========================================================
; Resident Portion of Basic Disk Operating System
;==========================================================
; bdos()
; {
__bdos: JP _bdos0
; }
;.....
; BDOS Function Dispatch Table
fcnTbl: defw Fcn0 ; Warm Boot
defw Fcn1 ; ConIn
defw Fcn2 ; ConOut
defw Fcn3 ; Reader In
defw Fcn4 ; Punch Out
defw Fcn5 ; List Output
defw Fcn6 ; Direct Console IO
defw Fcn7 ; Get IOBYTE
defw Fcn8 ; Set IOBYTE
defw Fcn9 ; WrBuf
defw Fcn10 ; RdBuf
defw Fcn11 ; Get Console Status
defw Fcn12 ; Return Version #
defw Fcn13 ; Reset Disk Drive
defw Fcn14 ; Select Disk
defw Fcn15 ; Open File
defw Fcn16 ; Close File
defw Fcn17 ; Search First Occurance
defw Fcn18 ; Search Next Occurance
defw Fcn19 ; Delete File
defw Fcn20 ; Read File
defw Fcn21 ; Write File
defw Fcn22 ; Create File
defw Fcn23 ; Rename File
defw Fcn24 ; Return Disk Login Vector
defw Fcn25 ; Return Current Disk
defw Fcn26 ; Set DMA
defw Fcn27 ; Get Allocation Map
defw Fcn28 ; Write Protect Disk
defw Fcn29 ; Get R/O Vector Address
defw Fcn30 ; Set File Attributes
defw Fcn31 ; Get Disk Parameter Table Address
defw Fcn32 ; Set/Get User Code
defw Fcn33 ; Read Random
defw Fcn34 ; Write Random
defw Fcn35 ; Compute File Size
defw Fcn36 ; Set Random Record Field in FCB
; defw Fcn37 ; Reset Multiple Drives
; defw null ; (Fcn38 not implemented)
; defw Fcn39 ; Get Fixed Disk Vector
; defw Fcn40 ; Write Random
TBLSZ EQU $-fcnTbl
MAXFCN EQU TBLSZ/2
;------------------------------------------------
; bdos0()
; {
_bdos0: LD (_arg),DE
LD A,C
LD (_call),A
CP MAXFCN ; Legal Function?
LD A,0FFH ; Prepare Error code
LD L,A
RET NC ; ..return if Illegal
LD (_userSP),SP
LD SP,_Bstack
PUSH IX
PUSH IY
LD B,0 ; Fcn # to Word
LD HL,_bdosX
PUSH HL ; (ret Addr to Stack)
LD HL,fcnTbl
ADD HL,BC
ADD HL,BC ; Pt to Fcn entry in Table
LD A,(HL)
INC HL
LD H,(HL)
LD L,A
JP (HL) ; "Call" Function #
_bdosX: POP IY
POP IX
LD SP,(_userSP)
LD DE,(_arg) ; Return Orig contents of DE
LD A,(_call)
LD C,A ; Return Orig contents of C
LD A,L
LD B,H ; Strict compatibility
OR A
RET
; }
;------------------------------------------------
; case 0: _exit(); /* Warm Boot */
Fcn0: JP WBoot
;------------------------------------------------
; case 6: if (arg < 0xfe) /* Direct Console I/O */
; goto conout;
; else if (arg == 0xfe)
; return (ConSt);
; else if (ConSt) /* 0xff */
; goto conout;
; else return (0);
Fcn6: LD A,E ; _arg in DE
CP 0FEH ; < 0FE ?
JR C,Fcn2 ; ..jump if Write if Yes
PUSH AF
CALL BConSt ; Else get Console Status
POP AF
INC A
RET NZ ; ..exit with 0ffh if 0feh
LD A,H
OR L ; Any char ready?
RET Z ; ..exit if Nothing available
;..else fall thru to Fcn1..
;------------------------------------------------
; case 1: /* Console Input */
; conin: read (0, &c, 1);
; if (c == '\n')
; c = '\r';
; return (c);
Fcn1: CALL BConIn ; Get Char from Bios
Fcn1A: LD H,0
CP 0AH ; \n?
LD L,A ; (prepare for return
RET NZ ; ..return if Not
LD L,0DH ; Else return CR
RET
;------------------------------------------------
; case 3: /* Reader (Aux) Input */
; conin: read (0, &c, 1);
; if (c == '\n')
; c = '\r';
; return (c);
Fcn3: CALL AuxIn ; Get Char from Bios
JR Fcn1A ; ..exit via common code
;------------------------------------------------
; case 2: /* Console Output */
; conout: if (arg == '\r')
; return (0);
; c = arg;
; write (1, &c, 1);
; break;
Fcn2: LD C,E ; _arg in DE, need char in C
JP BConOu
;------------------------------------------------
; case 4: /* Punch (Aux) Output */
; conout: if (arg == '\r')
; return (0);
; c = arg;
; write (1, &c, 1);
; break;
Fcn4: LD C,E ; _arg in DE, need char in C
JP AuxOut
;------------------------------------------------
; case 5: if (arg == '\r') /* List (Prntr) Output */
; return (0);
; c = arg;
; write (2, &c, 1);
; break;
Fcn5: LD A,E ; _arg in DE
CP 13 ; \r?
RET Z
JP List ; ..go to Bios
;------------------------------------------------
; case 9: ptr = (char *)arg; /* Print '$'-term String */
; while (*ptr != '$')
; {
; if (*ptr != '\r')
; write (1, ptr, 1);
; ++ptr;
; }
; break;
; Enter: DE -> String (arg)
Fcn9: LD A,(DE) ; Get char
INC DE ; pt to Next
CP '$' ; End?
RET Z ; ..quit if Yes
LD C,A
PUSH DE
CALL BConOu
POP DE
JR Fcn9 ; ..loop Til done
;------------------------------------------------
; case 10: rdbuf (arg);
; break;
; rdbuf (arg)
; char *arg;
; {
; int nread;
; nread = read (0, arg+2, *arg & 0xff);
IF FCN10V1
Fcn10: PUSH DE ; (save ptr to buffer)
LD A,(DE) ; Enter DE -> Buffer
LD C,A
LD B,0
PUSH BC ; cnt (*arg & 0xff)
INC DE
INC DE
PUSH DE ; arg+2
LD C,STDIN
PUSH BC ; 0 (stdin)
LD HL,ReadFcn ; UZI Read Fcn #
PUSH HL
RST 8H ; Execute!
POP BC ; Clean Stack
POP BC
POP BC
POP BC
POP DE ; Restore Ptr to Buff
; --nread; /* Forget about newline */
DEC HL
LD A,L
; arg[nread+2] = '\0'; /* Remove newline */
ADD HL,DE
INC HL
INC HL
LD (HL),0
; arg[1] = nread;
INC DE
LD (DE),A
; }
RET
ELSE
Fcn10:
push de
ex de,hl ; hl - buffer
ld e,(hl) ; e - max chars
inc hl
inc hl
ld d,0 ; d - char cnt
get: push hl
push de
call BConIn
pop de
pop hl
cp 8
jr z,del
cp 7Fh
jr z,del
cp 3
jp z,0
push hl
push de
push af
ld c,a
call BConOu
pop af
pop de
pop hl
ld (hl),a
cp CR
jr z,eol
ld a,e
cp d
jr z,eol1
inc hl
inc d
jr get
del: ld a,d
or a
jr z,get
push hl
push de
ld c,8
call BConOu
ld c,' '
call BConOu
ld c,8
call BConOu
pop de
pop hl
dec hl
dec d
jr get
eol: ld (hl),0
eol1: ld a,d
pop de
inc de
ld (de),a
ld hl,0
ret
ENDIF
;------------------------------------------------
; case 11: return (ConSt); /* Get Console Status */
Fcn11: JP BConSt
;------------------------------------------------
; case 12: /* Return Version # */
Fcn12: LD HL,0022H ; Say this is CP/M 2.2
RET
;------------------------------------------------
; case 13: /* Reset Disk Drive */
; SDma(0x80);
; break;
Fcn13:
LD BC,80h
JP BSDma
;------------------------------------------------
; case 7: /* Get IO Byte */
; case 8: break; /* Set IO Byte */
; case 14: break; /* Select Disk
; case 25: break; /* Return Current Disk */
; case 28: break; /* Write Protect Disk */
; case 30: break; /* Set File Attribytes */
; case 32: break; /* Get/Set User Code */
Fcn7:
Fcn8:
Fcn14:
Fcn25: ; 0 = Drive A
Fcn28:
Fcn30:
Fcn32: ; Return User 0
; default: break;
; }
; return (0);
Exit0: LD HL,0
RET
;------------------------------------------------
; case 15: return (openfile (arg)); /* Open File */
; openfile (blk)
; {
; desc = open (getname (arg), 2);
; DE -> arg
Fcn15: CALL Fcn17 ; Does this file exist?
LD A,H
AND L
INC A ; File Not Found (-1)?
RET Z ; ..return -1 if File doesn't exist
Open1: CALL CkSrch ; (Close Search File)
; arg.recno = 0;
CALL ZeroCR
LD (IY+13),80h ; use S1 as file open flag
JR Exit0 ; Return Dir Code for Entry
;.....
; Common File Open Routine. Used by Read, Write and Search First.
; Enter: DE = File Mode
; HL = Ptr to Null-terminated Path String
; Exit : A = 0 if Error, HL = -1
; File Descriptor, A <> 0 if Ok
OpenF:
IF UZIX
ld bc,438 ; 0666 in octal
push BC
ENDIF
PUSH DE ; Mode
PUSH HL ; Path
LD HL,OpenFcn ; UZI Open Fcn #
PUSH HL
RST 8H ; _open (Path, Mode);
POP BC ; Clean Stack
POP BC
POP BC
LD A,H
AND L
INC A ; FF -> 0?
RET ; ..return (HL=-1/A=0 if Err, HL=fd/A<>0 of Ok)
;------------------------------------------------
; case 16: return (closefile (arg)); /* Close File */
; if (close (arg->desc) == -1)
Fcn16: LD IY,(_arg)
LD (IY+13),0 ; clear file open flag
LD HL, SyncFcn ; UZI sync function #
PUSH HL
RST 8H ; Execute!
POP BC ; Clean Stack
JP Exit0 ; Return OK
;....
; Close file descriptor
CloseV: PUSH DE
LD HL,CloseFcn ; UZI Close Fcn #
PUSH HL
RST 8H ; Execute!
POP BC ; Clean Stack
POP BC
RET
;------------------------------------------------
; case 17: /* Search First */
Fcn17: CALL CkSrch ; Ensure Search File closed
LD HL,'.' ; Open current directory
LD (RName),HL ; store name in Secondary work string
LD DE,O_RDONLY ; Open Read-Only
LD HL,RName
CALL OpenF ; _open ('.', 0);
RET Z ; HL = -1, A = 0 if Can't Open
LD (srchFD),HL ; Else Ok, Save File Descriptor
LD (curFil),HL ; Duplicate for Reading
;..fall thru to read one entry..
;------------------------------------------------
; case 18: return (255); /* Search Next */
Fcn18: LD HL,(dmaadr)
LD (dmaSav),HL ; Save "real" DMA
Fcn18A: LD HL,dir+16
LD (dmaadr),HL ; Set DMA for Dir Op'n
LD A,ReadFcn ; UZI Read Function #
LD DE,16 ; Len of Dir entries
CALL RdWrt0 ; Read an Entry
JR C,Fcn18E ; Error if Carry Set
OR A ; Read Ok?
JR Z,Fcn18E ; ..Return HL=-1 if EOF
CALL ChkDir ; Else Set Dir to CP/M, Check Match
OR A
JR NZ,Fcn18A ; ..loop if No Match
LD A,(_call)
CP 15 ; Is this a File Open internal Call?
LD HL,0 ; (set Success, Index 0)
JR Z,Fcn18X ; ..exit now if Yes
LD HL,dir ; Else
LD DE,(dmaSav) ; Move Dir Buffer to "real" DMA
LD BC,128
LDIR
LD L,B ; Use 0 in BC
LD H,C ; to show Index 0 (success)
JR Fcn18X ; ..exit
Fcn18E: LD HL,-1
Fcn18X: LD DE,(dmaSav)
LD (dmaadr),DE ; Restore "real" DMA Addr
RET
;------------------------------------------------
; case 19: return (delete (arg)); /* Delete File */
Fcn19: CALL CkSrch ; Ensure Search file closed
; if (unlink (getname (arg)) == -1)
; DE -> arg
CALL GetNam ; Parse to String
PUSH HL ; String
LD HL,Unlink ; UZI Unlink Fcn #
PUSH HL
RST 8H ; Execute!
POP BC ; Clean Stack
POP BC
; return (255);
; return (0);
LD A,H
AND L
INC A ; FF->0?
JP NZ,Exit0 ; return Ok if No
ExitM1: LD HL,-1
RET
;------------------------------------------------
; case 33: /* Read File Random */
; readrandom (fcb)
; {
; /* CAUTION the seek calls MUST be in this order */
; _seek (f, (int)(fcb+33) % 128, 0); /* byte seek */
; _seek (f, (int)(fcb+33) / 128, 3); /* block seek */
Fcn33: CALL RWprep ; Prepare File for access
JP Z,Exit1
LD IY,(_arg)
LD A,(IY+33) ; Set Record Count from
LD (IY+32),A ; Random Record number
LD A,(IY+34) ;
LD (IY+12),A ;
CALL DoRead
JR RWEx
;....
DoRead:
CALL SkOff ; Seek to Offset (128-byte rec in Block)
CALL SkBlk ; Seek to 512-byte Block
CALL BRead ; Read 1 Sector
PUSH AF
LD DE,(curFil)
;;;; CALL CloseV ; Close the file
LD DE,0
LD (curFil),DE
POP AF
RET
;------------------------------------------------
; case 20: return (readfile (arg)); /* Read File */
; readfile (arg)
; {
; nread = read (blk->desc, dmaadr, 128);
; DE -> arg (FCB)
Fcn20: CALL RWprep ; Prepare file for access
JP Z,Exit1
CALL DoRead ; Read 1 Sector
; arg.recno++;
PUSH AF
CALL IncCR ; Bump Current Record #
POP AF
RWEx: JP C,Exit1 ; ..Error if Carry Set
; if (nread == 0)
; return (0);
OR A ; Good Read?
JP Z,Exit0 ; exit w/0 if Yes
; else return (1)
JP Exit1
;------------------------------------------------
; case 34: /* Write File Random */
; writerandom (fcb)
; {
; /* CAUTION the seek calls MUST be in this order */
; _seek (f, (int)(fcb+33) % 128, 0); /* byte seek */
; _seek (f, (int)(fcb+33) / 128, 3); /* block seek */
Fcn34: CALL RWprep ; Prepare file for access
JP Z,Exit1
LD IY,(_arg)
LD A,(IY+33) ; Set Record Count from
LD (IY+32),A ; Random Record number
LD A,(IY+34) ;
LD (IY+12),A ;
CALL DoWrite
JR RWEx
;....
DoWrite:
CALL SkOff ; Seek to Offset (128-byte rec in Block)
CALL SkBlk ; Seek to 512-byte Block
CALL BWrit ; Write 1 Sector
PUSH AF
LD DE,(curFil)
;;;; CALL CloseV ; Close the file
LD DE,0
LD (curFil),DE
POP AF
RET
;------------------------------------------------
; case 21: return (writefile (arg)); /* Write File */
; writefile (arg)
; {
; if (write (blk->desc, dmaadr, 128) != 128)
; DE -> arg (FCB)
Fcn21: CALL RWprep ; Prepare file for access
JP Z,Exit1
Fcn21A: CALL DoWrite ; Write
; arg.recno++;
PUSH AF
CALL IncCR ; Bump Current Record #
POP AF
; return (255);
; return (0);
JR RWEx ; ..exit via Common R/W Code
; }
;------------------------------------------------
; case 22: return (makefile (arg)); /* Create File */
; makefile (arg)
; {
; desc = creat (getname (blk), 0666);
Fcn22: CALL CkSrch ; Ensure Search file closed
LD HL,0666Q ; Own/Grp/Oth are Read/Execute
PUSH HL ; DE -> arg
IF UZIX
ld hl, O_CREAT+O_WRONLY+O_TRUNC
push hl ; /* flag */
ENDIF
CALL GetNam ; This name string
PUSH HL
LD HL,CreatFcn ; UZI Creat Fcn #
PUSH HL
RST 8H ; Execute!
POP BC ; Clean Stack
POP BC
POP BC
; if (desc == -1)
LD A,H
AND L
INC A ; FF -> 0?
; return (255);
RET Z ; ..return -1 if Yes
; arg.recno = 0;
EX DE,HL
CALL CloseV
JP Open1
;------------------------------------------------
; case 23: return (rename (arg)); /* Rename File */
; rename (arg)
; {
; RName = getname (arg);
Fcn23: CALL CkSrch ; Ensure Search file closed
PUSH DE ; Save FCB Ptr
CALL GetNam ; parse to UZI String
LD HL,FName
LD DE,RName
LD BC,12
LDIR ; Copy to Rename string
; FName = getname (arg+16);
POP DE ; DE -> _arg
LD HL,16
ADD HL,DE ; Offset to New Name
EX DE,HL
CALL GetNam ; parse it returning HL -> FName
; if (link (RName, FName) < 0) {
PUSH HL ; New Name
LD HL,RName ; Old Name
PUSH HL
LD HL,LinkFcn ; UZI link Fcn #
PUSH HL
RST 8H ; Execute!
POP BC ; Clean Stack
POP BC
POP BC
; return (-1);
JP C,ExitM1 ; Exit w/Err if Bad
; }
; if (unlink (RName) < 0) {
LD HL,RName ; Old Name
PUSH HL
LD HL,Unlink ; UZI unlink Fcn #
PUSH HL
RST 8H ; Execute!
POP BC ; Clean Stack
POP BC
JP NC,Exit0 ; exit w/0 if Ok
; unlink (FName);
; Else remove the new iNode
LD HL,FName ; New Name
PUSH HL
LD HL,Unlink ; UZI unlink Fcn #
PUSH HL
RST 8H ; Execute!
POP BC ; Clean Stack
POP BC
; return (-1);
JP C,ExitM1 ; return -1 if Bad
; }
; return (0);
JP Exit0 ; else return Ok
; }
;------------------------------------------------
; case 24: return (1); /* Return Disk Login Vector */
Fcn24:
Exit1: LD HL,1
RET
;------------------------------------------------
; case 26: dmaadr = (char *)arg; /* Set DMA Address */
; break;
; Enter DE = DMA Address
Fcn26: LD C,E
LD B,D ; Move to Bios Regs
JP BSDma ; Set in Bios & return
;------------------------------------------------
; case 27: return (-1) /* Get Allocation Map */
; case 29: return (-1) /* Get R/O Vector Address */
Fcn27:
Fcn29: LD HL,-1
RET
;------------------------------------------------
; case 31: return (&dpb); /* Get Disk Param Table Addr */
Fcn31: LD HL,dpb
RET
; }
;------------------------------------------------
; case 35: /* Return File Size in FCB */