-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcal.lst
1031 lines (1010 loc) · 50.1 KB
/
cal.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
; -------------------------------------------------------------------
; *** cal: displays a simple calendar in traditional format.
; *** If arguments are not specified, the current month is displayed.
; ***
; *** Assembled with a modified version of the A18 assembler (includes
; *** DC pseudo-op).
; ***
; *** Build #
; *** 6: Changed highlighting from bold to reverse video.
; *** 7: Expanded year limits to 1582-9999.
; *** 8: Send VT1802 style highlight/normal sequences when
; *** that video card is in use
; *** 9: Didn't read the VT1802 doc closely enough; 2nd try.
; *** 10: Thought about VT1802 some more, came up with something more
; *** likely to work. (Such are the perils of writing code for h/w
; *** you don't have to test on!)
; *** Use local stack and f_getdev
; *** 12: Use Elf/OS for terminal output (I remember changing this
; *** TO the kernel calls for older Elf/OS support...)
; *** Use interrupt proof stack maniuplation
; *******************************************************************
; *** This software is copyleft 2021 by Wayne Hortensius ***
; *** All wrongs reserved. ***
; *******************************************************************
;
incl "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
incl "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
;
#endif
;
; ************************************************************
; This block generates the Execution header for a stand-alone
; program. It begins 6 bytes before the program start.
; ************************************************************
;
org 02000h-6 ; Header starts at 01ffah
1ffa 20 00 dw 2000h
1ffc 05 90 dw endrom-2000h
1ffe 20 00 dw 2000h
;
2000 30 2d br Start
; **************************************************
; Build date format:
; 80h+month, day, four digit year
; **************************************************
; 80h month offset indicates extended
; build information, with build number and text.
; **************************************************
;
2002 88 03 07 e5 date: date
;
2006 00 0c build: dw 12 ; build number
2008 75 73 65 20 db 'use Elf/OS calls for terminal output',0
200c 45 6c 66 2f
2010 4f 53 20 63
2014 61 6c 6c 73
2018 20 66 6f 72
201c 20 74 65 72
2020 6d 69 6e 61
2024 6c 20 6f 75
2028 74 70 75 74
202c 00
;
cr equ 13
lf equ 10
tab equ 9
bell equ 7
esc equ 27
bs equ 8
;
Start:
202d c0 21 15 lbr Main
Help:
2030 d4 03 4b call O_INMSG
2033 43 61 6c 65 db 'Calendar, version 1.0',cr,lf
2037 6e 64 61 72
203b 2c 20 76 65
203f 72 73 69 6f
2043 6e 20 31 2e
2047 30 0d 0a
204a 20 20 53 79 db ' Syntax:',cr,lf
204e 6e 74 61 78
2052 3a 0d 0a
2055 09 63 61 6c db tab,'cal -h',tab,tab,'- Help',cr,lf,0
2059 20 2d 68 09
205d 09 2d 20 48
2061 65 6c 70 0d
2065 0a 00
;
2067 f8 24 bf f8 load rf,HasClock
206b f3 af
206d 0f ldn rf
206e 32 90 bz Help2
2070 d4 03 4b call O_INMSG
2073 09 63 61 6c db tab,'cal',tab,tab,'- Show current month',cr,lf,0
2077 09 09 2d 20
207b 53 68 6f 77
207f 20 63 75 72
2083 72 65 6e 74
2087 20 6d 6f 6e
208b 74 68 0d 0a
208f 00
Help2:
2090 d4 03 4b call O_INMSG
2093 09 63 61 6c db tab,'cal month year',tab,'- Show specified month',cr,lf
2097 20 6d 6f 6e
209b 74 68 20 79
209f 65 61 72 09
20a3 2d 20 53 68
20a7 6f 77 20 73
20ab 70 65 63 69
20af 66 69 65 64
20b3 20 6d 6f 6e
20b7 74 68 0d 0a
20bb 09 09 6d 6f db tab,tab,'month',tab,'= 1-12 or Jan-Dec',cr,lf
20bf 6e 74 68 09
20c3 3d 20 31 2d
20c7 31 32 20 6f
20cb 72 20 4a 61
20cf 6e 2d 44 65
20d3 63 0d 0a
20d6 09 09 79 65 db tab,tab,'year',tab,'= 1-99 or 1582-9999',0
20da 61 72 09 3d
20de 20 31 2d 39
20e2 39 20 6f 72
20e6 20 31 35 38
20ea 32 2d 39 39
20ee 39 39 00
Exit:
20f1 f8 01 ldi 1 ; assume interrupts are enabled
20f3 cc lsie ; skip if they are
20f4 f8 00 ldi 0 ; mark interrupts disabled
20f6 ae plo re ; save IE flag
20f7 f8 23 ldi 023h ; setup for DIS (X=2, P=3)
20f9 52 str r2
20fa 71 dis ; disable interrupts
20fb 22 dec r2
20fc f8 25 bf f8 load rf,saveStack ; restore Elf/OS's stack
2100 3e af
2102 4f lda rf
2103 b2 phi r2
2104 0f ldn rf
2105 a2 plo r2
2106 8e glo re ; recover IE flag
2107 c2 21 0f lbz Exit2 ; jump if interrupts were disabled
210a f8 23 ldi 023h ; setup for RET (X=2, P=3)
210c 52 str r2
210d 70 ret ; re-enable interrupts
210e 22 dec r2
Exit2:
210f 60 72 b6 f0 pop r6 ; restore Elf/OS's return address
2113 a6
2114 d5 retn ; return to Elf/OS
;-----------------------
Main:
2115 86 73 96 73 push r6 ; save Elf/OS's return address on its stack
2119 f8 01 ldi 1 ; assume interrupts are enabled
211b cc lsie ; skip if they are
211c f8 00 ldi 0 ; mark interrupts disabled
211e ae plo re ; save IE flag
211f f8 23 ldi 023h ; setup for DIS (X=2, P=3)
2121 52 str r2
2122 71 dis ; disable interrupts
2123 22 dec r2
2124 f8 25 bf f8 load rf,saveStack ; save Elf/OS's stack
2128 3e af
212a 92 ghi r2
212b 5f str rf
212c 1f inc rf
212d 82 glo r2
212e 5f str rf
212f f8 25 b2 f8 load r2,localStack ; use our own stack
2133 3d a2
2135 8e glo re ; recover IE flag
2136 c2 21 3e lbz Main2 ; jump if interrupts were disabled
2139 f8 23 ldi 023h ; setup for RET (X=2, P=3)
213b 52 str r2
213c 70 ret ; re-enable interrupts
213d 22 dec r2
Main2:
213e d4 24 e5 call HasRTC
2141 f8 24 bf f8 load rf,HasClock
2145 f3 af
2147 f8 00 ldi 0 ; D = 0x00 (doesn't have RTC)
2149 cb 21 4e lbnf NoClk
214c ff 01 smi 1 ; D = 0xFF (has RTC)
214e 5f NoClk: str rf
214f f8 24 bf f8 load rf,Day
2153 f6 af
2155 f8 00 ldi 0 ; zero out day
2157 5f str rf ; (so no day hilited if command tail)
2158 d4 23 9e call crlf
SkipSpaces:
215b 4a lda ra ; skip over any spaces
215c ff 20 smi ' '
215e c2 21 5b lbz SkipSpaces
2161 2a dec ra ; move back to non-space character
2162 0a ldn ra ; get byte
2163 ca 21 a1 lbnz DoTail ; there was a cmd tail, process it
;
2166 f8 24 bf f8 load rf,HasClock
216a f3 af
216c 0f ldn rf ; no cmd tail, get system time if we can
216d c2 21 7c lbz NoClkMsg ; no system clock to check, aww!
;
2170 f8 24 bf f8 load rf,DateBlk ; point to kernel date/time
2174 f5 af
2176 d4 03 51 call O_GETTOD ; call BIOS to get current date/time from RTC
2179 cb 21 8d lbnf GotTime
NoClkMsg:
217c d4 03 4b call O_INMSG
217f 07 4e 6f 20 db bell,'No RTC',cr,lf,lf,0
2183 52 54 43 0d
2187 0a 0a 00
218a c0 20 30 lbr Help
;
GotTime:
218d f8 24 bf f8 load rf,Year
2191 f7 af
2193 0f ldn rf ; convert offset year to absolute
2194 fc b4 adi low 1972 ; binary year
2196 1f inc rf
2197 5f str rf ; store low byte of absolute year
2198 2f dec rf
2199 f8 00 ldi 0
219b 7c 07 adci high 1972
219d 5f str rf ; store high byte of absolute year
219e c0 22 30 lbr ShowCal ; show the current month calendar
DoTail:
21a1 ff 2d smi '-'
21a3 0a ldn ra
21a4 ca 21 af lbnz DoTailX
21a7 1a inc ra
21a8 0a ldn ra
21a9 ff 68 smi 'h'
21ab 0a ldn ra
21ac c2 20 30 lbz Help
DoTailX:
21af d4 ff 5a call f_isnum ; 1st non blank char: is it 0..9?
21b2 8a glo ra
21b3 af plo rf
21b4 9a ghi ra
21b5 bf phi rf
21b6 cb 21 cf lbnf MonName ; nope, try a month name
21b9 d4 ff 5d call f_atoi ; get month #
21bc 0f ldn rf
21bd ff 20 smi ' '
21bf ca 20 30 lbnz Help
21c2 9d ghi rd
21c3 ca 20 30 lbnz Help ; out of range [1..12]
21c6 8d glo rd
21c7 ff 0d smi 12+1
21c9 c3 20 30 lbdf Help ; out of range [1..12]
21cc c0 21 de lbr DoYear
MonName:
21cf d4 24 0a call MatchMonthName
21d2 c2 20 30 lbz Help
21d5 ad plo rd
SkipRest:
21d6 4f lda rf
21d7 d4 ff 72 call f_isalpha
21da c3 21 d6 lbdf SkipRest
21dd 2f dec rf ; back up to first non alpha char
DoYear:
21de f8 24 ba f8 load ra,Month
21e2 f5 aa
21e4 8d glo rd
21e5 5a str ra ; save month #
SkipYearSpaces:
21e6 4f lda rf ; skip over any spaces
21e7 ff 20 smi ' '
21e9 c2 21 e6 lbz SkipYearSpaces
21ec 2f dec rf ; move back to non-space character
21ed 0f ldn rf
21ee c2 20 30 lbz Help ; needed a year, we're done
21f1 d4 ff 5a call f_isnum ; is it a digit?
21f4 cb 20 30 lbnf Help ; nope, we're done
21f7 d4 ff 5d call f_atoi ; get year
21fa 0f ldn rf ; end of command tail?
21fb ca 20 30 lbnz Help ; jump if not
21fe 9d ghi rd
21ff ca 22 15 lbnz FullYear
2202 8d glo rd
2203 c2 20 30 lbz Help ; year 0's no good
DoYear1:
2206 8d glo rd
2207 ff 64 smi 100
2209 c3 22 15 lbdf FullYear
220c 8d glo rd
220d fc d0 adi low 2000 ; 2 digit years assumed 20xx
220f ad plo rd
2210 f8 00 ldi 0
2212 7c 07 adci high 2000
2214 bd phi rd
FullYear:
2215 f8 24 bf f8 load rf,Year+1
2219 f8 af
221b 8d glo rd
221c 5f str rf
221d ff 2e smi low 1582 ; ZCAL limited the calendar
221f 2f dec rf ; to 1766..2499, though I'm
2220 9d ghi rd ; not away of any such
2221 5f str rf ; limitation in Zeller's
2222 7f 06 smbi high 1582 ; congruence
2224 cb 20 30 lbnf Help
;
2227 8d glo rd
2228 ff 10 smi low (9999+1)
222a 9d ghi rd
222b 7f 27 smbi high (9999+1)
222d c3 20 30 lbdf Help
;
ShowCal:
2230 f8 20 ldi ' '
2232 d4 03 30 call O_TYPE
2235 f8 24 bf f8 load rf,MonthNames
2239 66 af
223b f8 24 bd f8 load rd,DateBlk
223f f5 ad
2241 0d ldn rd ; month #
2242 fd 0c sdi 12 ; D = 12-month #
2244 d4 24 b2 call prtTblStr ; print month name
;
2247 f8 24 bf f8 load rf,Year
224b f7 af
224d 4f lda rf ; high byte of year
224e bd phi rd
224f 0f ldn rf ; low byte of year
2250 ad plo rd
2251 f8 25 bf f8 load rf,buffer
2255 40 af
2257 d4 ff 60 call f_uintout
225a f8 00 ldi 0
225c 5f str rf
225d f8 25 bf f8 load rf,buffer
2261 40 af
2263 d4 03 33 call O_MSG ; print year
;
2266 d4 03 4b call O_INMSG
2269 0d 0a db cr,lf
226b 20 53 75 6e db ' Sun Mon Tue Wed Thu Fri Sat'
226f 20 4d 6f 6e
2273 20 54 75 65
2277 20 57 65 64
227b 20 54 68 75
227f 20 46 72 69
2283 20 53 61 74
2287 0d 0a 00 db cr,lf,0
;
228a f8 24 b7 f8 load r7,DateBlk
228e f5 a7
2290 d4 23 a5 call GetDOW ; get the DOW of the 1st of the month
2293 27 dec r7 ; r7 -> DOW1st
2294 57 str r7 ; store DOW of 1st day of month
2295 17 inc r7 ; r7 -> Month
2296 87 glo r7
2297 af plo rf
2298 97 ghi r7
2299 bf phi rf
229a f8 24 bd f8 load rd,Date2Blk
229e f9 ad
22a0 f8 04 ldi 4
22a2 ac plo rc
22a3 f8 00 ldi 0
22a5 bc phi rc
22a6 d4 ff 1b call f_memcpy ; copy DateBlk to Date2Blk
22a9 2d dec rd
22aa 2d dec rd
22ab 2d dec rd
22ac 2d dec rd ; rd -> Date2Blk
22ad 0d ldn rd
22ae fc 01 adi 1
22b0 5d str rd ; store next month
22b1 ff 0d smi 13
22b3 ca 22 c7 lbnz NextMonth
22b6 f8 01 ldi 1
22b8 5d str rd
22b9 1d inc rd
22ba 1d inc rd ; rd -> high byte of year
22bb 4d lda rd ; rf.1 = m(rd), rf.0 = m(rd+1)
22bc bf phi rf
22bd 0d ldn rd
22be af plo rf
22bf 1f inc rf ; rf = next year
22c0 8f glo rf
22c1 5d str rd
22c2 2d dec rd
22c3 9f ghi rf
22c4 5d str rd
22c5 2d dec rd
22c6 2d dec rd ; rd -> Date2Blk
NextMonth:
22c7 8d glo rd
22c8 a7 plo r7
22c9 9d ghi rd
22ca b7 phi r7
22cb d4 23 a5 call GetDOW ; get the DOW of 1st of the next month
22ce 27 dec r7
22cf 27 dec r7
22d0 27 dec r7
22d1 27 dec r7
22d2 27 dec r7 ; r7 -> DOW1st
22d3 fc 07 adi 7
22d5 e7 sex r7
22d6 f7 sm
22d7 e2 sex r2
DaysInMonth:
22d8 fc 07 adi 7 ; figure out how many days in the month
22da bb phi rb ; (all months have at least 28 days)
22db ff 1c smi 28
22dd 9b ghi rb
22de cb 22 d8 lbnf DaysInMonth
22e1 ac plo rc ; rc = # of days in the month
22e2 f8 01 ldi 1 ; start with 1st day of month
22e4 a9 plo r9
22e5 f8 00 ldi 0
22e7 a8 plo r8 ; reset "VT1802 esc seq used space" flag
22e8 07 ldn r7 ; fetch DOW1st
22e9 17 inc r7
22ea 17 inc r7 ; r7 -> day of month
22eb c2 23 03 lbz FullWeek ; month starts on Sunday, so full week
22ee aa plo ra
22ef f8 07 ldi 7
22f1 ab plo rb ; # days remaining in first week
MoveFirst:
22f2 d4 03 4b call O_INMSG ; space over to 1st of month
22f5 20 20 20 20 db ' ',0
22f9 00
22fa 2b dec rb
22fb 2a dec ra
22fc 8a glo ra
22fd ca 22 f2 lbnz MoveFirst
2300 c0 23 06 lbr WeekLoop
FullWeek:
2303 f8 07 ldi 7
2305 ab plo rb ; # of days in this week to print
WeekLoop:
2306 88 glo r8 ; only print 1 leading space after
2307 ca 23 0f lbnz LeadingSpace ; highlighting the current day on the
230a f8 20 ldi ' ' ; VT1802 board (reverse/normal video
230c d4 03 30 call O_TYPE ; occupies a character spot afaict)
LeadingSpace:
230f f8 20 ldi ' '
2311 d4 03 30 call O_TYPE
2314 f8 00 ldi 0 ; reset VT1802 flag
2316 a8 plo r8
;
2317 89 glo r9
2318 e7 sex r7
2319 f7 sm
231a e2 sex r2
231b ca 23 35 lbnz NotToday1
231e f8 23 bf f8 load rf,ansi_hilite
2322 8c af
2324 9e ghi re ; check to see if the VT1802
2325 fa fe ani 0feh ; video card is active, and if
2327 fb fe xri 0feh ; so, use a VT52 video hilite
2329 ca 23 32 lbnz hilite_day
232c f8 23 bf f8 load rf,vt52_hilite
2330 95 af
hilite_day:
2332 d4 03 33 call O_MSG
NotToday1:
2335 89 glo r9 ; day of month < 10 ?
2336 ff 0a smi 10
2338 c3 23 40 lbdf Gt10
233b f8 20 ldi ' '
233d d4 03 30 call O_TYPE ; yes, print a leading blank
2340 89 Gt10: glo r9
2341 ad plo rd
2342 f8 00 ldi 0
2344 bd phi rd
2345 f8 25 bf f8 load rf,buffer
2349 40 af
234b d4 ff 60 call f_uintout
234e f8 00 ldi 0
2350 5f str rf
2351 f8 25 bf f8 load rf,buffer
2355 40 af
2357 d4 03 33 call O_MSG ; print day of month
235a 89 glo r9
235b e7 sex r7
235c f7 sm
235d e2 sex r2
235e ca 23 7b lbnz NotToday2
2361 f8 23 bf f8 load rf,ansi_normal
2365 91 af
2367 9e ghi re ; check to see if the VT1802
2368 fa fe ani 0feh ; video card is active, and if
236a fb fe xri 0feh ; so, use a VT52 video normal string
236c ca 23 78 lbnz normal_day
236f f8 01 ldi 1 ; set "only one space" flag after VT1802
2371 a8 plo r8 ; escape sequence
2372 f8 23 bf f8 load rf,vt52_normal
2376 9a af
normal_day:
2378 d4 03 33 call O_MSG
NotToday2:
237b 19 inc r9 ; next day of month
237c 2c dec rc
237d 8c glo rc
237e c2 20 f1 lbz Exit
2381 2b dec rb
2382 8b glo rb
2383 ca 23 06 lbnz WeekLoop
2386 d4 23 9e call crlf
2389 c0 23 03 lbr FullWeek
;
238c 1b 5b 37 6d ansi_hilite: db esc,'[7m',0 ; ANSI hilight today
2390 00
2391 1b 5b 6d 00 ansi_normal: db esc,'[m',0 ; ANSI end hilight of today
2395 08 1b 4e 50 vt52_hilite: db bs,esc,'NP',0 ; VT1802 hilight today
2399 00
239a 1b 4e 40 00 vt52_normal: db esc,'N@',0 ; VT1802 end hilight of today
;------------------------
239e d4 03 4b crlf: call O_INMSG
23a1 0d 0a 00 db cr,lf,0
23a4 d5 retn
;------------------------
;
; Zeller's Congruence algorithm for determining
; the day of the week of the 1st of a month
;
; IN: r7 = address of date/time block m/d/yy
; OUT D = day of week (0-6, Sunday-Saturday)
;
; ALTERS r8,r9,ra,rb,rc,rd
;
23a5 07 GetDOW: ldn r7 ; month
23a6 ff 03 smi 3 ; march - december?
23a8 17 inc r7
23a9 17 inc r7 ; R7 -> high byte of year word
23aa 47 lda r7
23ab bf phi rf
23ac 07 ldn r7 ; fetch low byte of year word
23ad af plo rf
23ae c3 23 b2 lbdf GetDOW1 ; DF=1 if month >= 3
23b1 2f dec rf ; --year for january & february
GetDOW1:
23b2 f8 00 bd f8 load rd,100
23b6 64 ad
23b8 d4 ff 33 call f_div16 ; RB=year DIV 100 (century), RF=year MOD 100
23bb 8b glo rb
23bc aa plo ra ; save century
23bd f8 05 ldi low 5
23bf ad plo rd
23c0 f8 00 ldi low 0
23c2 bd phi rd
23c3 d4 ff 30 call f_mul16 ; RB = 5 * (year MOD 100)
23c6 9b ghi rb
23c7 f6 shr
23c8 bb phi rb
23c9 8b glo rb
23ca 76 shrc
23cb ab plo rb
23cc 9b ghi rb
23cd f6 shr
23ce bb phi rb
23cf 8b glo rb
23d0 76 shrc
23d1 ab plo rb ; RB = 5 * (year mod 100) DIV 4
23d2 27 dec r7 ; R7 -> high byte of year word
23d3 27 dec r7 ; R7 -> day
23d4 27 dec r7 ; R7 -> month
23d5 f8 fd ldi low (valtab-1)
23d7 e7 sex r7
23d8 f4 add
23d9 e2 sex r2
23da ac plo rc
23db f8 23 ldi high (valtab-1)
23dd 7c 00 adci 0
23df bc phi rc ; index into valtab
23e0 8b glo rb
23e1 ec sex rc
23e2 f4 add ; result = (13 * month - 1 ) DIV 5 + 5 * year MOD 100) DIV 4
23e3 e2 sex r2
23e4 52 str r2 ; save result
23e5 8a glo ra
23e6 f6 shr
23e7 f6 shr ; century DIV 4
23e8 f4 add ; result += century DIV 4
23e9 52 str r2
23ea 8a glo ra
23eb fe shl ; century * 2
23ec f5 sd ; D = century * 2 - result
23ed 52 str r2
23ee c3 23 f6 lbdf GetDOW3 ; branch if result >= 0
GetDOW2:
23f1 fc 07 adi 7
23f3 cb 23 f1 lbnf GetDOW2 ; loop until result >= 0
GetDOW3:
23f6 ff 07 smi 7 ; do MOD 7
23f8 c3 23 f6 lbdf GetDOW3 ; loop until result < 0
23fb fc 07 adi 7 ; MOD 7 done
23fd d5 retn
;
; Precomputed (13 * month) DIV 5 values
;
23fe 1d 20 03 06 valtab: db 29,32,3,6,8,11,13,16,19,21,24,26
2402 08 0b 0d 10
2406 13 15 18 1a
;------------------------
;
; MatchMonthName: find a unique prefix match for a NUL terminated string
; in a table of strings
; IN: rf -> space terminated string to match
; OUT: D -> 1 based string index (0 if not found)
;
; ALTERS: r7, r8, r9, ra, rb, rc, rd
;
MatchMonthName:
240a f8 24 bd f8 load rd,MonthNames
240e 66 ad
2410 f8 00 ldi 0
2412 a7 plo r7 ; R7 is longest substring matched so far
2413 a8 plo r8 ; R8 is match # (0 means no match)
2414 f8 0c ldi 12 ; # month names to search
2416 ab plo rb ; RB is loop counter
MonthLoop:
2417 8f glo rf
2418 a9 plo r9
2419 9f ghi rf
241a b9 phi r9 ; r9 is working cmd tail ptr
241b f8 ff ldi 0ffh
241d ac plo rc ; rc is working matched substring length
ChkNextChr:
241e 1d inc rd ; next byte in table
241f 1c inc rc ; # chars matched
2420 09 ldn r9 ; char from cmd tail
2421 ff 61 smi 'a'
2423 49 lda r9
2424 cb 24 29 lbnf NotLower
2427 fa df ani not 20h ; make upper case
NotLower:
2429 ed sex rd
242a f3 xor ; compare to month char
242b fa df ani not 20h ; make it case insensitive
242d e2 sex r2
242e c2 24 1e lbz ChkNextChr
2431 fb 80 xri 80h
2433 ca 24 3f lbnz FindEoS ; jump if wasn't last char in table entry
2436 1c inc rc ; matched a complete table entry
2437 09 ldn r9
2438 ff 20 smi ' '
243a ca 24 3f lbnz FindEoS ; end of month name?
243d 8b glo rb ; complete cmd tail string matched
243e d5 retn
FindEoS:
243f 4d lda rd
2440 fe shl
2441 cb 24 3f lbnf FindEoS ; find end of string (hi bit set)
2444 2d dec rd
2445 29 dec r9
2446 09 ldn r9 ; did we get to the end of the
2447 ff 20 smi ' ' ; cmd tail word?
2449 ca 24 5f lbnz DoNextMonth
244c 8c glo rc ; substr length
244d 52 str r2 ; store it for a moment
244e 87 glo r7
244f f5 sd
2450 cb 24 5f lbnf DoNextMonth ; jump if substr lng < longest substr lng
2453 52 str r2
2454 f8 00 ldi 0
2456 a8 plo r8 ; no month name matched
2457 02 ldn r2
2458 c2 24 5f lbz DoNextMonth ; jump if substr lng = longest substr lng
245b 8b glo rb
245c a8 plo r8 ; save month name index matched
245d 8c glo rc
245e a7 plo r7 ; save longest length matched
DoNextMonth:
245f 2b dec rb
2460 8b glo rb
2461 ca 24 17 lbnz MonthLoop
2464 88 glo r8
2465 d5 retn
;------------------------
MonthNames:
2466 0c db 12
2467 44 65 63 65 dc 'December'
246b 6d 62 65 f2
246f 4e 6f 76 65 dc 'November'
2473 6d 62 65 f2
2477 4f 63 74 6f dc 'October'
247b 62 65 f2
247e 53 65 70 74 dc 'September'
2482 65 6d 62 65
2486 f2
2487 41 75 67 75 dc 'August'
248b 73 f4
248d 4a 75 6c f9 dc 'July'
2491 4a 75 6e e5 dc 'June'
2495 4d 61 f9 dc 'May'
2498 41 70 72 69 dc 'April'
249c ec
249d 4d 61 72 63 dc 'March'
24a1 e8
24a2 46 65 62 72 dc 'February'
24a6 75 61 72 f9
24aa 4a 61 6e 75 dc 'January'
24ae 61 72 f9
24b1 ff db 0ffh
;------------------------
; prtTblStr: print n'th string in a table (end of string marked with hi bit set)
; IN: D = string number (0..N-1)
; RF = table (N strings with last char MSb set)
; (table terminated by 0FFH)
;
prtTblStr:
24b2 ad plo rd
24b3 ef sex rf
24b4 f7 sm ; exceeds # of strings in table?
24b5 e2 sex r2
24b6 cb 24 ba lbnf prtts1
24b9 d5 retn ; yep, we are done
prtts1:
24ba 8d glo rd
24bb c2 24 ca lbz FirstStr
NextStr:
24be 1f inc rf
24bf 0f ldn rf
24c0 fa 80 ani 80h
24c2 c2 24 be lbz NextStr ; not end of this string
24c5 2d dec rd
24c6 8d glo rd
24c7 ca 24 be lbnz NextStr ; got to the string we want yet?
FirstStr:
24ca f8 17 ldi 23 ; total spaces
24cc ad plo rd
StrLoop:
24cd 1f inc rf
24ce 0f ldn rf
24cf fa 7f ani 7fh ; mask off hi bit
24d1 d4 03 30 call O_TYPE
24d4 2d dec rd ; decr # spaces required
24d5 0f ldn rf
24d6 fe shl ; put msb in DF
24d7 cb 24 cd lbnf StrLoop ; loop until last char (hi bit set)
StrSpaces:
24da f8 20 ldi ' ' ; fill out to 23 chars with spaces
24dc d4 03 30 call O_TYPE
24df 2d dec rd
24e0 8d glo rd
24e1 ca 24 da lbnz StrSpaces
24e4 d5 retn
;------------------------
24e5 d4 ff 81 HasRTC: call f_getdev ; check that the BIOS thinks
24e8 8f glo rf
24e9 fa 10 ani b_devRTC ; we have an RTC
24eb 32 f0 bz NoRTC
24ed 7f 00 smbi 0 ; signal RTC present (DF=1)
24ef d5 retn ; and return
24f0 fc 00 NoRTC: adi 0 ; clear DF
24f2 d5 retn ; and return
;------------------------
;
HasClock: ds 1
;
DOW1st: ds 1 ;\.
DateBlk: ; \.
Month: ds 1 ; \.
Day: ds 1 ; NB: these variables must
Year: ds 2 ; remain together in this
Date2Blk: ; order!
Month2: ds 1 ; /.
Day2: ds 1 ; /.
Year2: ds 2 ;/.
;
ds 64
localStack: ds 1
saveStack: ds 2
;
buffer: ds 80
;
endrom equ $
;
;------------------------
;
end
238c ansi_hilite 2391 ansi_normal 0004 b_devBBSER 0002 b_devFLPY
0001 b_devIDE 0001 b_devNBREAD 0020 b_devNVR 0010 b_devRTC
0008 b_devUART 0007 bell ff00 BIOS 0008 bs
2540 buffer 2006 build 241e ChkNextChr 000d cr
239e crlf 2002 date 24f9 Date2Blk 24f5 DateBlk
24f6 Day 24fa Day2 22d8 DaysInMonth 245f DoNextMonth
21a1 DoTail 21af DoTailX 24f4 DOW1st 21de DoYear
2206 DoYear1 f800 EBIOS 2590 endrom 0005 errdirnotempty
0001 errexists 0003 errinvdir 0004 errisdir 0002 errnoffnd
0006 errnotexec 001b esc 20f1 Exit 210f Exit2
f830 f_astodt f833 f_astotm ff5d f_atoi ff00 f_boot
ff42 f_bootide f800 f_bread ff6c f_brktest f806 f_btest
f803 f_btype ff33 f_div16 ff2a f_drive f827 f_dttoas
ff6f f_findtkn ff57 f_freemem ff81 f_getdev f815 f_gettod
ff45 f_hexin ff48 f_hexout2 ff4b f_hexout4 f824 f_ideid
ff3c f_ideread ff36 f_idereset f821 f_idesize ff39 f_idewrite
ff7b f_idnum ff3f f_initcall ff66 f_inmsg ff0f f_input
ff69 f_inputl ff63 f_intout ff78 f_isalnum ff72 f_isalpha
ff75 f_ishex ff5a f_isnum ff7e f_isterm ff15 f_ltrim
ff1b f_memcpy ff54 f_minimon ff51 f_mover ff09 f_msg
ff30 f_mul16 ff54 f_nbread f836 f_nvrcchk f81b f_rdnvr
ff21 f_rdsec ff06 f_read f82d f_rtctest ff27 f_seek
ff24 f_seek0 ff2d f_setbd f818 f_settod ff12 f_strcmp
ff18 f_strcpy f82a f_tmtoas ff4e f_tty ff03 f_type
ff0c f_typex ff60 f_uintout f80c f_uread f812 f_usetbd
f80f f_utest f809 f_utype fff9 f_version f81e f_wrnvr
ff1e f_wrtsec 0010 ff_archive 0001 ff_dir 0002 ff_exec
0008 ff_hide 0004 ff_write 243f FindEoS 24ca FirstStr
2303 FullWeek 2215 FullYear 23a5 GetDOW 23b2 GetDOW1
23f1 GetDOW2 23f6 GetDOW3 218d GotTime 2340 Gt10
24f3 HasClock 24e5 HasRTC 2030 Help 2090 Help2
2332 hilite_day 03f6 I_SERVE 0406 K_BDAY 0405 K_BMONTH
0403 K_BUILD 0407 K_BYEAR 0470 K_CLKFREQ 0476 K_DAY