-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathys.lst
2233 lines (2181 loc) · 99.4 KB
/
ys.lst
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
; -------------------------------------------------------------------
; -------------------------------------------------------------------
; *** ys: send one or more files using YMODEM batch protocol
; ***
; *** Build #
; *** 1: Proof of concept version
; *** 2: First bug squashed: 256 & 512 byte files were sent
; *** as 0 bytes
; *** 3: Added file timestamp to block 0
; *** 4: Inlined some Tx/Rx code to make it fast enough to
; *** catch the ACK & CRC/NAK at the end of a block send
; *** 5: Dec/hex oops in "Couldn't open file:" message
; *** 6: missed a "pop rc" when O_READ didn't read any bytes
; *** 7: moved endrom to end of uninitialised data so that
; *** Elf/OS 0.4.x can tell if we're colliding with the heap.
; *** Make stack manipulation interrupt safe on entry and
; *** exit (even though soft UART code is unlikely to work
; *** if interrupted).
; *** 8: Add UART type detection & auto config. Both hard &
; *** soft UARTs supported.
; *** 9: Expand directory files on cmd line into their component
; *** data files for sending (NOT recursive)
; *******************************************************************
; *** This software is released to the public domain. ***
; *** You have permission to use, modify, copy, and distribute ***
; *** this software as you please. ***
; *******************************************************************
;
; Register usage:
;
; System:
; r0 - Resesrved for DMA
; r1 - Reserved for interrupts
; r2 - Stack pointer
; r3 - Program counter
; r4 - SCALL program counter
; r5 - SRET program counter
; r6 - SCALL return address
; re.0 - SCALL overwrites with D
; re.1 - Baud rate constant
;
; Main program :
;
; ra - Command line pointer (on exec)
;
; All other registers are available for subroutines.
;
include "bios.inc"
; *******************************************************************
; *** This software is copyright 2006 by Michael H Riley ***
; *** You have permission to use, modify, copy, and distribute ***
; *** this software so long as this copyright notice is retained. ***
; *** This software may not be used in commercial applications ***
; *** without express written permission from the author. ***
; *******************************************************************
; f_getdev bit values
b_devIDE equ 00000001b ; IDE
b_devFLPY equ 00000010b ; floppy
b_devBBSER equ 00000100b ; Bit-banged serial
b_devUART equ 00001000b ; UART
b_devRTC equ 00010000b ; RTC
b_devNVR equ 00100000b ; NVRAM
b_devNBREAD equ 00000001b ; NBREAD supported
#ifndef _IS_BIOS
; Define address for standard BIOS vectors
BIOS equ 0ff00h
; Define address for extended BIOS vectors
EBIOS equ 0f800h
scall equ r4 ; register for SCALL
sret equ r5 ; register for SRET
f_boot equ (BIOS+00h) ; boot from ide device
f_type equ (BIOS+03h) ; type 1 character to console
f_read equ (BIOS+06h) ; read 1 character from console
f_msg equ (BIOS+09h) ; type asciiz string to console
f_typex equ (BIOS+0ch) ; depricated, just returns now
f_input equ (BIOS+0fh) ; read asciiz from console
f_strcmp equ (BIOS+12h) ; compare 2 strings
f_ltrim equ (BIOS+15h) ; trim leading spaces
f_strcpy equ (BIOS+18h) ; copy an asciiz string
f_memcpy equ (BIOS+1bh) ; copy memory
f_wrtsec equ (BIOS+1eh) ; write floppy sector (depricated)
f_rdsec equ (BIOS+21h) ; read floppy sector (depricated)
f_seek0 equ (BIOS+24h) ; floppy seek to track 0 (depricated)
f_seek equ (BIOS+27h) ; floopy track seek (depricated)
f_drive equ (BIOS+2ah) ; select floppy drive (depricated)
f_setbd equ (BIOS+2dh) ; set console baud rate
f_mul16 equ (BIOS+30h) ; 16-bit multiply
f_div16 equ (BIOS+33h) ; 16-bit division
f_idereset equ (BIOS+36h) ; reset ide device
f_idewrite equ (BIOS+39h) ; write ide sector
f_ideread equ (BIOS+3ch) ; read ide sector
f_initcall equ (BIOS+3fh) ; initialize R4 and R5
f_bootide equ (BIOS+42h) ; boot from ide device
f_hexin equ (BIOS+45h) ; convert ascii number to hex
f_hexout2 equ (BIOS+48h) ; convert hex to 2-digit ascii
f_hexout4 equ (BIOS+4bh) ; convert hex to 4-digit ascii
f_tty equ (BIOS+4eh) ; type character to console
f_mover equ (BIOS+51h) ; program relocator
f_minimon equ (BIOS+54h) ; mini monitor
f_freemem equ (BIOS+57h) ; determine memory size
f_isnum equ (BIOS+5ah) ; determine if D is numeric
f_atoi equ (BIOS+5dh) ; convert ascii to integer
f_uintout equ (BIOS+60h) ; convert unsigned integer to ascii
f_intout equ (BIOS+63h) ; convert signed integer to ascii
f_inmsg equ (BIOS+66h) ; type in-line message
f_inputl equ (BIOS+69h) ; read limited line from console
f_brktest equ (BIOS+6ch) ; check for serial break
f_findtkn equ (BIOS+6fh) ; find token in a token table
f_isalpha equ (BIOS+72h) ; determine if D is alphabetic
f_ishex equ (BIOS+75h) ; determine if D is hexadecimal
f_isalnum equ (BIOS+78h) ; determine if D is alpha or numeric
f_idnum equ (BIOS+7bh) ; determine type of ascii number
f_isterm equ (BIOS+7eh) ; determine if D is a termination char
f_getdev equ (BIOS+81h) ; get supported devices
f_nbread equ (BIOS+84); ; read 1 char from console (non blocking)
f_version equ (BIOS+0f9h) ; 3 bytes holding bios version number
; "Extended" BIOS vectors
f_bread equ (EBIOS+00h) ; read from onboard serial port
f_btype equ (EBIOS+03h) ; write to onboard serial port
f_btest equ (EBIOS+06h) ; test onboard serial port
f_utype equ (EBIOS+09h) ; write to disk board UART
f_uread equ (EBIOS+0ch) ; read from disk board UART
f_utest equ (EBIOS+0fh) ; test disk board UART
f_usetbd equ (EBIOS+12h) ; set disk board UART baud rate and format
f_gettod equ (EBIOS+15h) ; read time of day clock
f_settod equ (EBIOS+18h) ; set time of day clock
f_rdnvr equ (EBIOS+1bh) ; read non volatile RAM
f_wrnvr equ (EBIOS+1eh) ; write non volatile RAM
f_idesize equ (EBIOS+21h) ; return size of attached IDE drive(s)
f_ideid equ (EBIOS+24h) ; return device data for IDE drive(s)
f_tmtoas equ (EBIOS+2ah) ; time to ASCII string
f_dttoas equ (EBIOS+27h) ; date to ASCII string
f_rtctest equ (EBIOS+2dh) ; test size and presence of RTC/NVR
f_astodt equ (EBIOS+30h) ; convert ASCII string to date
f_astotm equ (EBIOS+33h) ; convert ASCII string to time
f_nvrcchk equ (EBIOS+36h) ; compute NVR checksum
#endif
include "kernel.inc"
O_CREAT equ 00000001b
O_TRUNC equ 00000010b
O_APPND equ 00000100b
;
errexists equ 1
errnoffnd equ 2
errinvdir equ 3
errisdir equ 4
errdirnotempty equ 5
errnotexec equ 6
;
ff_dir equ 00000001b
ff_exec equ 00000010b
ff_write equ 00000100b
ff_hide equ 00001000b
ff_archive equ 00010000b
#ifndef _IS_KERNEL
O_CLDBOOT: equ 0300h ; jump to cold boot routine
O_WRMBOOT: equ 0303h ; jump to warm boot routine
O_OPEN: equ 0306h ; open a file
O_READ: equ 0309h ; read from file
O_WRITE: equ 030ch ; write to file
O_SEEK: equ 030fh ; seek to file position
O_CLOSE: equ 0312h ; close file
O_OPENDIR: equ 0315h ; open dir as a file
O_DELETE: equ 0318h ; delete a file
O_RENAME: equ 031bh ; rename a file
O_EXEC: equ 031eh ; execute an external program
O_MKDIR: equ 0321h ; make directory
O_CHDIR: equ 0324h ; change directory
O_RMDIR: equ 0327h ; remove directory
O_RDLUMP: equ 032Ah ; read LAT entry
O_WRLUMP: equ 032Dh ; write LAT entry
O_TYPE: equ 0330h ; passthrough for console output
O_MSG: equ 0333h ; passthrough for console output
O_READKEY: equ 0336h ; passthrough for console input
O_INPUT: equ 0339h ; passthrough for console input
O_PRTSTAT: equ 033ch ; printer status
O_PRINT: equ 033fh ; output to printer
O_EXECBIN: equ 0342h ; execute from default directory
O_SETDEF: equ 0345h ; set/get default directory
O_KINIT: equ 0348h ; reserved - do not use!!!
O_INMSG: equ 034bh ; passthrough for console output
O_GETDEV: equ 034eh ; passthrough to f_getdef
O_GETTOD: equ 0351h ; passthrough to f_gettod
O_SETTOD: equ 0354h ; passthrough to f_settod
O_INPUTL: equ 0357h ; passthrough to f_inputl
O_BOOT: equ 035ah ; passthrough to f_boot
O_SETBD: equ 0360h ; passthrough to f_setbd
O_INITCALL: equ 0363h ; passthrough to f_initcall
O_BRKTEST: equ 0366h ; passthrough to f_brktest
O_DEVCTRL: equ 0369h ; Hook for device control drivers
O_ALLOC: equ 036ch ; passthrough to alloc
O_DEALLOC: equ 036fh ; passthrough to dealloc
O_TERMCTRL: equ 0372h ; Hook for terminal control drivers
O_MEMCTRL: equ 0375h ; Hook for memory control drivers
I_SERVE: equ 03f6h ; address of interrupt chain head
V_IVEC: equ 03fdh ; interrupt head
V_DVEC: equ 036ah ; device head
K_VER: equ 0400h ; kernel version number
K_BUILD: equ 0403h ; kernel build number
K_BMONTH: equ 0405h ; kernel build month
K_BDAY: equ 0406h ; kernel build day
K_BYEAR: equ 0407h ; kernel build month
K_HIMEM: equ 0442h ; high memory pointer
K_LOWMEM: equ 0465h ; lowest memory heap can use
K_RETVAL: equ 0467h ; D on program exit
K_HEAP: equ 0468h ; heap pointer
K_CLKFREQ: equ 0470h ; system clock frequency
K_MONTH: equ 0475h ; date/time
K_DAY: equ 0476h
K_YEAR: equ 0477h
K_HOUR: equ 0478h
K_MINUTE: equ 0479h
K_SECOND: equ 047ah
K_SECDEN: equ 047bh
K_SECNUM: equ 047dh
;
;O_HIMEM: equ 0442h ; himem value
O_DATTIM: equ 0475h ; date/time block
;
#endif
;
debug equ 0
info equ 0
;
; ***************************************************
; ***** Constants *****
; ***************************************************
cr equ 'M'-'@'
lf equ 'J'-'@'
bs equ 'H'-'@'
;
soh equ 'A'-'@' ; 128 byte packet header
stx equ 'B'-'@' ; 1K byte packet header
eot equ 'D'-'@' ; end of file transfer marker
ack equ 'F'-'@' ; Acknowledge (good packet)
nak equ 'U'-'@' ; Negative acknowledge (bad packet)
can equ 'X'-'@' ; cancel transfer
crc equ 'C' ; use CRC rather than checksum
;
; ***************************************************
; ***** This block is the Execution header for *****
; ***** a stand-alone program. It begins 6 *****
; *****bytes before the program start. *****
; ***************************************************
LoadAdr equ 2000h
org LoadAdr-6 ; Header starts at 01ffah
1ffa 20 00 dw LoadAdr
1ffc 19 3e dw EndRom-LoadAdr
1ffe 20 00 dw LoadAdr
;
; ***************************************************
; ***** Code start *****
; ***************************************************
2000 30 52 br Start
;
; ***************************************************
; ***** Program header *****
; ***************************************************
2002 88 03 07 e5 date
2006 00 09 Build: dw 9 ; build number
2008 65 78 70 61 db 'expand dirs in cmd tail',0
200c 6e 64 20 64
2010 69 72 73 20
2014 69 6e 20 63
2018 6d 64 20 74
201c 61 69 6c 00
;
monthDays:
2020 1f 1c 1f 1e db 31,28,31,30,31,30,31,31,30,31,30,31
2024 1f 1e 1f 1f
2028 1e 1f 1e 1f
;
CmdFilDes:
202c 00 00 00 00 db 0,0,0,0 ; current file offset
2030 2d 00 dw CmdDta ; DTA
2032 00 00 dw 0 ; eof
2034 00 db 0 ; flags
CmdDirSec:
2035 00 00 00 00 db 0,0,0,0 ; dir sector
CmdDirOfs:
2039 00 00 dw 0 ; dir offset
203b 00 00 00 00 db 0,0,0,0 ; current sector in DTA
;
SndFilDes:
203f 00 00 00 00 db 0,0,0,0 ; current file offset
2043 2f 00 dw SndDta ; DTA
2045 00 00 dw 0 ; eof
2047 00 db 0 ; flags
SndDirSec:
2048 00 00 00 00 db 0,0,0,0 ; dir sector
SndDirOfs:
204c 00 00 dw 0 ; dir offset
204e 00 00 00 00 db 0,0,0,0 ; current sector in DTA
;
; ***************************************************
; ***** Main program *****
; ***************************************************
start:
2052 86 73 96 73 push r6 ; save Elf/OS's return address on its stack
2056 f8 01 ldi 1 ; assume interrupts are enabled
2058 cc lsie ; skip if they are
2059 f8 00 ldi 0 ; mark interrupts disabled
205b ae plo re ; save IE flag
205c f8 23 ldi 023h ; setup for DIS (X=2, P=3)
205e 52 str r2
205f 71 dis ; disable interrupts
2060 22 dec r2
2061 f8 31 bf f8 load rf,saveStack ; save Elf/OS's stack
2065 8c af
2067 92 ghi r2
2068 5f str rf
2069 1f inc rf
206a 82 glo r2
206b 5f str rf
206c f8 31 b2 f8 load r2,localStack ; use our own stack
2070 8b a2
2072 8e glo re ; recover IE flag
2073 c2 20 7b lbz start2 ; jump if interrupts were disabled
2076 f8 23 ldi 023h ; setup for RET (X=2, P=3)
2078 52 str r2
2079 70 ret ; re-enable interrupts
207a 22 dec r2
start2:
207b 9e ghi re ; turn off console echo
207c fa fe ani 11111110b
207e be phi re
207f d4 28 82 call UARTsetup ; auto detect/config UART
;
2082 d4 20 f4 call NextFileName ; point to first file name
2085 ca 20 b1 lbnz NextFile ; and go send it
2088 d4 03 4b call O_INMSG ; otherwise display usage message
208b 55 73 61 67 db 'Usage: ys filename [filename...]',cr,lf,0
208f 65 3a 09 79
2093 73 20 66 69
2097 6c 65 6e 61
209b 6d 65 20 5b
209f 66 69 6c 65
20a3 6e 61 6d 65
20a7 2e 2e 2e 5d
20ab 0d 0a 00
20ae c0 20 fd lbr Exit ; and return to os
NextFile:
20b1 d4 21 25 call ProcFile ; process next file (either send or expand)
20b4 d4 20 f4 call NextFileName ; point to next file name in cmd tail
20b7 ca 20 b1 lbnz NextFile ; loop for next file
20ba d4 25 c3 call WaitNAKorCRC
20bd f8 34 bf f8 load rf,blknum
20c1 b8 af
20c3 f8 00 ldi 0
20c5 5f str rf
20c6 d4 25 8e call ZeroBlock0 ; send zero filled block 0 to finish up
if debug=0
20c9 f8 27 bf f8 load rf,SoftAckedAction
20cd 44 af
20cf f8 81 ldi low nextBlock
20d1 5f str rf
20d2 f8 26 bf f8 load rf,HardAckedAction
20d6 83 af
20d8 f8 27 ldi high nextBlock
20da 5f str rf
20db 1f inc rf
20dc f8 81 ldi low nextBlock
20de 5f str rf
endi
20df f8 34 bf f8 load rf,block0
20e3 be af
20e5 f8 00 bc f8 load rc,128
20e9 80 ac
20eb f8 0a ldi 10
20ed a8 plo r8
20ee d4 26 09 call SendBlock
20f1 c0 20 fd lbr Exit ; and return to os
;
; ***************************************************
; ***** NextFilename: advance RA to the next *****
; ***** non space character *****
; ***************************************************
NextFileName:
20f4 4a lda ra ; move past any spaces
20f5 ff 20 smi ' '
20f7 c2 20 f4 lbz NextFileName
20fa 2a dec ra ; move back to non-space character
20fb 0a ldn ra ; get byte
20fc d5 retn
;
; ***************************************************
; ***** Exit: return to Elf/OS, restoring OS *****
; ***** stack and R6 contents *****
; ***************************************************
Exit:
20fd 9e ghi re ; restore console echo
20fe f9 01 ori 00000001b
2100 be phi re
2101 f8 01 ldi 1 ; assume interrupts are enabled
2103 cc lsie ; skip if they are
2104 f8 00 ldi 0 ; mark interrupts disabled
2106 ae plo re ; save IE flag
2107 f8 23 ldi 023h ; setup for DIS (X=2, P=3)
2109 52 str r2
210a 71 dis ; disable interrupts
210b 22 dec r2
210c f8 31 bf f8 load rf,saveStack ; restore Elf/OS's stack
2110 8c af
2112 4f lda rf
2113 b2 phi r2
2114 0f ldn rf
2115 a2 plo r2
2116 8e glo re ; recover IE flag
2117 c2 21 1f lbz Exit2 ; jump if interrupts were disabled
211a f8 23 ldi 023h ; setup for RET (X=2, P=3)
211c 52 str r2
211d 70 ret ; re-enable interrupts
211e 22 dec r2
Exit2:
211f 60 72 b6 f0 pop r6 ; restore Elf/OS's return address
2123 a6
2124 d5 retn ; return to Elf/OS
;
; ***************************************************
; ***** Process file: if a directory file, *****
; ***** send each ordinary file contained in it *****
; ***** If an ordinary file, just send it *****
; ***** RA: points to file name *****
; ***************************************************
ProcFile:
2125 f8 31 bd f8 load rd,cmdFilename ; copy filename from cmd tail
2129 8e ad
212b f8 32 bc f8 load rc,sndFilename
212f 0e ac
ProcCopyName:
2131 4a lda ra ; look for first less <= space
2132 5d str rd
2133 1d inc rd
2134 5c str rc
2135 1c inc rc
2136 ff 21 smi ' '+1
2138 c3 21 31 lbdf ProcCopyName
213b 2a dec ra
213c 2d dec rd
213d f8 00 ldi 0 ; zero terminate filename
213f 5d str rd
2140 1d inc rd
2141 2c dec rc
2142 5c str rc
2143 8d 73 9d 73 push rd ; save block ptr
2147 f8 20 bd f8 load rd,CmdFilDes ; get file descriptor
214b 2c ad
214d f8 31 bf f8 load rf,cmdFilename
2151 8e af
2153 f8 00 ldi 0 ; flags for open, append
2155 a7 plo r7
2156 d4 03 06 call O_OPEN ; attempt to open file to determine size
2159 cb 21 86 lbnf CmdFileOpened ; jump if file was opened
215c d4 25 9f call Cancel
215f d4 03 4b call O_INMSG
2162 43 6f 75 6c db 'Couldn',27h,'t open file: ',0
2166 64 6e 27 74
216a 20 6f 70 65
216e 6e 20 66 69
2172 6c 65 3a 20
2176 00
2177 f8 31 bf f8 load rf,cmdFilename
217b 8e af
217d d4 03 33 call O_MSG ; display it
2180 d4 27 a8 call crlf
2183 c0 20 fd lbr Exit ; and return to os
CmdFileOpened:
2186 f8 20 bd f8 load rd,CmdFilDes
218a 2c ad
;
218c 8f 73 9f 73 push rf
2190 f8 e0 ldi 0e0h ; lba mode
2192 b8 phi r8
2193 f8 20 bf f8 load rf,CmdDirSec+1 ; point to dir sector in CmdFilDes
2197 36 af
2199 4f lda rf ; retrieve sector
219a a8 plo r8
219b 4f lda rf
219c b7 phi r7
219d 4f lda rf
219e a7 plo r7
219f f8 32 bf f8 load rf,DirBuffer ; where to load sector
21a3 8e af
21a5 d4 ff 3c call f_ideread ; call bios to read the sector
;
21a8 f8 20 bf f8 load rf,CmdDirOfs+1 ; need dirent offset
21ac 3a af
21ae 0f ldn rf
21af fc 06 adi 6 ; point to flags
21b1 ad plo rd
21b2 2f dec rf
21b3 0f ldn rf
21b4 7c 00 adci 0 ; propagate carry
21b6 bd phi rd ; r7 now points to flags
21b7 8d glo rd ; now point to correct spot in sector buffer
21b8 fc 8e adi low DirBuffer
21ba ad plo rd
21bb 9d ghi rd
21bc 7c 32 adci high Dirbuffer
21be bd phi rd
;
21bf 0d ldn rd ; get flags
21c0 73 pushd
21c1 fa 01 ani ff_dir
21c3 3a e1 bnz isDirFile
;
21c5 f8 20 bd f8 load rd,CmdFilDes
21c9 2c ad
21cb d4 03 12 call O_CLOSE
21ce 8a 73 9a 73 push ra ; save cmd tail ptr
21d2 f8 31 ba f8 load ra,cmdFilename
21d6 8e aa
21d8 d4 22 63 call SendFile ; ordinary file, just send it
21db 60 72 ba f0 pop ra
21df aa
21e0 d5 retn
isDirFile:
21e1 f8 00 bc f8 load rc,32 ; read next directory entry
21e5 20 ac
21e7 f8 34 bf f8 load rf,dirEntBuffer
21eb 8e af
21ed f8 20 bd f8 load rd,CmdFilDes
21f1 2c ad
21f3 d4 03 09 call O_READ
21f6 8c glo rc
21f7 c2 22 59 lbz eofdir ; no more
21fa f8 34 bf f8 load rf,dirEntBuffer
21fe 8e af
2200 4f lda rf ; see if it has a non zero sector
2201 ca 22 10 lbnz occupied ; (indicates in-use file)
2204 4f lda rf
2205 ca 22 10 lbnz occupied
2208 4f lda rf
2209 ca 22 10 lbnz occupied
220c 4f lda rf
220d c2 21 e1 lbz isDirFile
occupied:
2210 f8 34 bf f8 load rf,dirEntBuffer+6
2214 94 af
2216 0f ldn rf ; make sure it's not a sub directory
2217 fa 01 ani ff_dir
2219 ca 21 e1 lbnz isDirFile
221c 8a 73 9a 73 push ra ; save cmd tail ptr
2220 f8 31 bf f8 load rf,cmdFilename
2224 8e af
2226 f8 32 ba f8 load ra,sndFilename
222a 0e aa
copyDir:
222c 4f lda rf
222d 5a str ra
222e 1a inc ra
222f 3a 2c bnz copyDir
2231 2a dec ra ; point back to terminator
2232 2a dec ra ; point back to last char of dir
2233 0a ldn ra
2234 ff 2f smi '/'
2236 32 3c bz hasTrailingSlash
2238 1a inc ra
2239 f8 2f ldi '/'
223b 5a str ra
hasTrailingSlash:
223c 1a inc ra
223d f8 34 bf f8 load rf,dirEntBuffer+12
2241 9a af
copyFileName:
2243 4f lda rf
2244 5a str ra
2245 1a inc ra
2246 3a 43 bnz copyFileName
2248 f8 32 ba f8 load ra,sndFilename
224c 0e aa
224e d4 22 63 call SendFile ; send file from directory entry
2251 60 72 ba f0 pop ra ; restore cmd tail ptr
2255 aa
2256 c0 21 e1 lbr isDirFile
eofdir:
2259 f8 20 bd f8 load rd,CmdFilDes
225d 2c ad
225f d4 03 12 call O_CLOSE
2262 d5 retn
;
; ***************************************************
; ***** Send file: send a single file *****
; ***** RA: points to file name *****
; ***************************************************
SendFile:
2263 d4 25 8e call ZeroBlock0
2266 f8 34 bd f8 load rd,block0 ; copy filename to block
226a be ad
226c 0a ldn ra ; don't allow leading /
226d ff 2f smi '/'
226f 3a 72 bnz B0loop1 ; jump if not an absolute path
2271 1a inc ra ; make it a relative path
B0loop1:
2272 4a lda ra ; look for first less <= space
2273 5d str rd
2274 1d inc rd
2275 ff 21 smi ' '+1
2277 c3 22 72 lbdf B0loop1
227a 2a dec ra
227b 2d dec rd
227c 1d inc rd ; skip over 0 terminator
227d 8d 73 9d 73 push rd ; save block ptr
2281 f8 20 bd f8 load rd,SndFilDes ; get file descriptor
2285 3f ad
2287 f8 32 bf f8 load rf,sndFilename
228b 0e af
228d f8 04 ldi O_APPND ; flags for open, append
228f a7 plo r7
2290 d4 03 06 call O_OPEN ; attempt to open file to determine size
2293 cb 22 c0 lbnf SndFileOpened ; jump if file was opened
2296 d4 25 9f call Cancel
2299 d4 03 4b call O_INMSG
229c 43 6f 75 6c db 'Couldn',27h,'t open file: ',0
22a0 64 6e 27 74
22a4 20 6f 70 65
22a8 6e 20 66 69
22ac 6c 65 3a 20
22b0 00
22b1 f8 32 bf f8 load rf,sndFilename
22b5 0e af
22b7 d4 03 33 call O_MSG ; display it
22ba d4 27 a8 call crlf
22bd c0 20 fd lbr Exit ; and return to os
SndFileOpened:
22c0 f8 20 bd f8 load rd,SndFilDes
22c4 3f ad
22c6 f8 34 bf f8 load rf,fileSize
22ca ba af
22cc 4d lda rd ; put 32 bit offset into
22cd b7 phi r7 ; R7:R8 and fileSize
22ce 5f str rf
22cf 1f inc rf
;
22d0 4d lda rd
22d1 a7 plo r7
22d2 5f str rf
22d3 1f inc rf
;
22d4 4d lda rd
22d5 b8 phi r8
22d6 5f str rf
22d7 1f inc rf
;
22d8 0d ldn rd
22d9 a8 plo r8
22da 5f str rf
;
22db 2d dec rd ; restore descriptor
22dc 2d dec rd
22dd 2d dec rd
;
22de 87 73 97 73 push r7
22e2 88 73 98 73 push r8
;
22e6 f8 00 b8 f8 load r8,0
22ea 00 a8
22ec f8 00 b7 f8 load r7,0
22f0 00 a7
22f2 f8 20 bd f8 load rd,SndFilDes
22f6 3f ad
22f8 f8 00 bc f8 load rc,0 ; rewind file to start
22fc 00 ac
22fe d4 03 0f call O_SEEK
;
2301 60 72 b8 f0 pop r8
2305 a8
2306 60 72 b7 f0 pop r7
230a a7
230b 60 72 bf f0 pop rf ; restore block ptr
230f af
2310 d4 27 af call uint32_out ; convert number to ascii
2313 f8 20 ldi ' ' ; finish file size with space
2315 5f str rf
2316 1f inc rf
;
2317 8a 73 9a 73 push ra
231b 8f 73 9f 73 push rf
231f f8 e0 ldi 0e0h ; lba mode
2321 b8 phi r8
2322 f8 20 bf f8 load rf,SndDirSec+1 ; point to dir sector in SndFilDes
2326 49 af
2328 4f lda rf ; retrieve sector
2329 a8 plo r8
232a 4f lda rf
232b b7 phi r7
232c 4f lda rf
232d a7 plo r7
232e f8 32 bf f8 load rf,DirBuffer ; where to load sector
2332 8e af
2334 d4 ff 3c call f_ideread ; call bios to read the sector
;
2337 f8 20 bf f8 load rf,SndDirOfs+1 ; need dirent offset
233b 4d af
233d 0f ldn rf
233e fc 07 adi 7 ; point to date block
2340 aa plo ra
2341 2f dec rf
2342 0f ldn rf
2343 7c 00 adci 0 ; propagate carry
2345 ba phi ra ; r7 now points to date block
2346 8a glo ra ; now point to correct spot in sector buffer
2347 fc 8e adi low DirBuffer
2349 aa plo ra
234a 9a ghi ra
234b 7c 32 adci high DirBuffer
234d ba phi ra
;
234e f8 34 bf f8 load rf,year
2352 ae af
2354 4a lda ra ; get year/month
2355 f6 shr ; shift high month bit into DF
2356 0a ldn ra ; get low bits of month
2357 76 shrc ; shift high bit in
2358 f6 shr ; then shift into position
2359 f6 shr
235a f6 shr
235b f6 shr
235c 1f inc rf
235d 5f str rf ; store month
235e 1f inc rf ; point to day storage
235f 0a ldn ra ; recover day
2360 fa 1f ani 31 ; mask for day
2362 5f str rf ; store day
2363 2f dec rf
2364 2f dec rf ; point back to year offset storage
2365 2a dec ra ; point back to year
2366 4a lda ra ; get year
2367 f6 shr ; shift out high bit of month
2368 5f str rf ; store year offset from 1972
2369 1f inc rf
236a 1f inc rf
236b 1f inc rf ; point to hours storage
236c 1a inc ra ; point to time
236d 0a ldn ra ; retrieve hours
236e f6 shr ; shift to proper position
236f f6 shr
2370 f6 shr
2371 5f str rf ; store hours
2372 1f inc rf ; point to minutes storage
2373 4a lda ra ; get minutes
2374 fa 07 ani 07h ; strip out hours
2376 fe shl ; shift to needed spot
2377 fe shl
2378 fe shl
2379 52 str r2 ; save for combination
237a 0a ldn ra ; get low bits of minutes
237b f6 shr ; shift into position
237c f6 shr
237d f6 shr
237e f6 shr
237f f6 shr
2380 f1 or ; combine with high bites
2381 5f str rf ; store minutes
2382 1f inc rf ; point to seconds storage
2383 0a ldn ra ; get seconds
2384 fa 1f ani 1fh ; strip minutes out
2386 fe shl ; multiply by 2
2387 5f str rf ; store seconds
;
2388 f8 34 bf f8 load rf,year ; point back to year
238c ae af
238e f8 03 b7 f8 load r7,03c2h ; number of seconds
2392 c2 a7
2394 f8 67 b8 f8 load r8,6700h ; from Jan 1 1970 to Jan 1 1972
2398 00 a8
239a 0f ldn rf ; year offset from 1972
239b a9 plo r9
239c f8 00 ldi 0
239e b9 phi r9 ; leap year counter
yearLoop:
239f 89 glo r9
23a0 32 cd bz yearsDone
23a2 f8 01 ba f8 load ra,01e1h ; seconds in a year
23a6 e1 aa
23a8 f8 33 bb f8 load rb,3380h
23ac 80 ab
23ae d4 28 6d call add32bits
23b1 99 ghi r9
23b2 fa 03 ani 00000011b
23b4 3a c5 bnz notLeapYear
23b6 f8 00 ba f8 load ra,0001h ; seconds in the leap day
23ba 01 aa
23bc f8 51 bb f8 load rb,5180h ; (86400)
23c0 80 ab
23c2 d4 28 6d call add32bits
notLeapYear:
23c5 99 ghi r9
23c6 29 dec r9
23c7 fc 01 adi 1
23c9 b9 phi r9
23ca c0 23 9f lbr yearLoop
yearsDone:
23cd f8 00 ba f8 load ra,0001h ; seconds in a day
23d1 01 aa
23d3 f8 51 bb f8 load rb,5180h ; (86400)
23d7 80 ab
23d9 4f lda rf ; re-get year
23da fa 03 ani 00000011b ; rc.1 will be 0 if leap year
23dc bc phi rc ;
23dd 4f lda rf ; month # (1-12)
23de ff 01 smi 1
23e0 c2 24 06 lbz monthsDone
23e3 ac plo rc ; rc.0 is month # -1
23e4 f8 20 bd f8 load rd,monthDays
23e8 20 ad
monthsLoop:
23ea 4d lda rd
23eb a9 plo r9 ; rb.0 is # days in month
monthLoop:
23ec d4 28 6d call add32bits ; add a day's worth of seconds
23ef 29 dec r9 ; decrement days left in month
23f0 89 glo r9
23f1 ca 23 ec lbnz monthLoop
23f4 9c ghi rc ; leap year?
23f5 3a ff bnz noLeapYearChk
23f7 8d glo rd ; test for February
23f8 ff 22 smi low monthDays+2
23fa 3a ff bnz notFebruary
23fc d4 28 6d call add32bits ; add in another day in Feb in leap year
noLeapYearChk:
notFebruary:
23ff 8c glo rc
2400 ff 01 smi 1
2402 ac plo rc
2403 ca 23 ea lbnz monthsLoop
monthsDone:
2406 4f lda rf ; day of month
2407 ff 01 smi 1
2409 c2 24 15 lbz domDone
240c a9 plo r9
domLoop:
240d d4 28 6d call add32bits
2410 29 dec r9
2411 89 glo r9
2412 ca 24 0d lbnz domLoop
domDone:
2415 f8 00 ba f8 load ra,0
2419 00 aa
241b f8 0e bb f8 load rb,3600 ; seconds in an hour
241f 10 ab
2421 4f lda rf
2422 32 2c bz hoursDone
2424 a9 plo r9
hoursLoop:
2425 d4 28 6d call add32bits
2428 29 dec r9
2429 89 glo r9
242a 3a 25 bnz hoursLoop
hoursDone:
242c f8 00 bb f8 load rb,60 ; seconds in a minute
2430 3c ab
2432 4f lda rf
2433 c2 24 3f lbz minutesDone
2436 a9 plo r9
minutesLoop:
2437 d4 28 6d call add32bits
243a 29 dec r9
243b 89 glo r9
243c ca 24 37 lbnz minutesLoop
minutesDone:
243f 0f ldn rf ; get seconds
2440 ab plo rb
2441 d4 28 6d call add32bits
;
2444 60 72 bf f0 pop rf ; restore block 0 ptr
2448 af
2449 f8 0c ldi '0' shr 2 ; convert r7:r8 to octal number
244b b9 phi r9 ; and add to block 0 string
244c f8 02 ldi 2 ; 2 bits on first digit
244e a9 plo r9
244f f8 0b ldi 11 ; 11 digits in a 32 bit number
2451 aa plo ra
bitLoop:
2452 88 glo r8
2453 fe shl
2454 a8 plo r8
2455 98 ghi r8
2456 7e shlc
2457 b8 phi r8
2458 87 glo r7
2459 7e shlc
245a a7 plo r7
245b 97 ghi r7
245c 7e shlc
245d b7 phi r7
245e 99 ghi r9
245f 7e shlc
2460 29 dec r9
2461 b9 phi r9
2462 89 glo r9
2463 ca 24 52 lbnz bitLoop
2466 99 ghi r9
2467 5f str rf
2468 1f inc rf
2469 f8 06 ldi '0' shr 3 ; next octal digit setup
246b b9 phi r9
246c f8 03 ldi 3 ; 3 bits for remaining digits
246e a9 plo r9
246f 2a dec ra
2470 8a glo ra
2471 ca 24 52 lbnz bitLoop
;
2474 60 72 ba f0 pop ra
2478 aa
;
2479 f8 20 ldi ' ' ; finish timestamp with space
247b 5f str rf
247c 1f inc rf
247d f8 30 ldi '0' ; default file mode to '0'
247f 5f str rf ; no trailing nul needed: already 0'd
;
2480 d4 25 c3 call WaitNAKorCRC
2483 ff 43 smi crc
2485 c2 24 99 lbz CrcMode
2488 ff d2 smi nak-crc
248a c2 24 9b lbz SaveMode
SendFileError:
248d f8 20 bd f8 load rd,SndFilDes
2491 3f ad
2493 d4 03 12 call O_CLOSE
2496 ff 00 smi 0 ; DF=1, error
2498 d5 retn
CrcMode:
2499 f8 01 ldi 1
SaveMode:
249b a7 plo r7
249c f8 34 bf f8 load rf,blkMode
24a0 b9 af
24a2 87 glo r7
24a3 5f str rf
;
if debug=0
24a4 f8 27 bf f8 load rf,SoftAckedAction
24a8 44 af
24aa f8 5c ldi low SoftReadne2
24ac 5f str rf
24ad f8 26 bf f8 load rf,HardAckedAction
24b1 83 af
24b3 f8 26 ldi high HardAcked
24b5 5f str rf
24b6 1f inc rf
24b7 f8 92 ldi low HardAcked
24b9 5f str rf
endi
24ba f8 34 bf f8 load rf,blkNum
24be b8 af
24c0 f8 00 ldi 0
24c2 5f str rf
24c3 f8 34 bf f8 load rf,block0
24c7 be af
24c9 f8 00 bc f8 load rc,128
24cd 80 ac
24cf f8 0a ldi 10
24d1 a8 plo r8
24d2 d4 26 09 call SendBlock ; send file block 0
24d5 c3 24 8d lbdf SendFileError
;
if debug
pushd
call crlf
load rf,hexcount
ldi 0
str rf
popd
endif
;
24d8 ff 43 smi crc
24da 32 e0 bz fileSendLoop
24dc ff d2 smi nak-crc
24de 3a 8d bnz SendFileError
;
FileSendLoop:
24e0 f8 34 bf f8 load rf,fileSize
24e4 ba af
24e6 f8 04 bc f8 load rc,1024 ; assume we've got at least 1K
24ea 00 ac
24ec 4f lda rf ; left to send
24ed ca 25 08 lbnz MoreToGo
24f0 4f lda rf
24f1 ca 25 08 lbnz MoreToGo
24f4 0f ldn rf
24f5 ff 04 smi high 1024
24f7 c3 25 08 lbdf MoreToGo ; jump if >= 1K left to go