-
Notifications
You must be signed in to change notification settings - Fork 1
/
atasys.s
1016 lines (984 loc) · 16.1 KB
/
atasys.s
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
XDEF find_file ;,save_file2
XDEF get_drive,get_path,set_path,open_dta,close_dta,get_wd,find_first,find_next
XDEF open_file,create_file,write_file,read_file,seek_file,rel_seek_file,close_file
XDEF DoEnd,PrtLine,OutChar,PrtChar,PrtNChar,GetShifts,StrtTime,StopTime
XDEF GetIncBin,LoadSrc,LoadBin,IsFPU,GetMPU,LstOpen,LstClose,TestFile,IsAbsFname
XDEF FreeEditBlocks
XREF OutMsg,NoPrtEnd,MyMalloc,MyMfree
XREF TopStack
XREF LstCnt,LstName,LstHand,LstPgFlg,LstMttl,LstSttl,LstLnNb,LstPgNb,LstLnLen,LstPgLen
XREF IEnvFlg,IEnvPtr,HeadEditBlock,CurEditBlock
XREF FstTime,TotTime,LstErr
XREF CurLNb,CurModPtr,CurLPtr
include "comequ.s"
section TEXT
TSTIENV EQU 0
EDIT_BLK_SIZE EQU 16384
DTA_TYPE EQU 21
DTA_SIZE EQU 26
DTA_NAME EQU 30
; #[ cd: change directory
_cd: move.l a0,a3
cmpi.b #':',1(a3)
bne.s .nodrive
move.b (a3),d0
cmpi.b #'A',d0
blt.s .rpath
cmpi.b #'P',d0
ble.s .maj
cmpi.b #'a',d0
blt.s .rpath
cmpi.b #'p',d0
bgt.s .rpath
subi.b #'a',d0
bra.s .set_drv
.maj: subi.b #'A',d0
.set_drv: bsr set_drive
bmi.s .rpath
.nodrive: move.l a3,a0
bsr set_path
bmi.s .rpath
moveq #0,d0
rts
.rpath: move #setpath_errno,d0
bra filepfatal
; #] cd:
; #[ LoadSrc:
;GERER CLOSE ERROR
;--- IN ---
;a0=ptr sur nom de fichier
;d0=offset
;d1=taille si d0!=0
;--- INTERNAL ---
;d3=taille
;d4=handle
;a3=@ de chargement
;d7 sert en fin
;a3=new dta
;a4=olddta
;a6=nom de fichier
;--- OUT ---
;a0=@ de chargement
;a1=@ nom de fichier
;d0=taille chargee
LoadSrc: movem.l d3-d7/a2-a6,-(sp)
move.l d0,d7
move.l d1,d3
move.l a0,a6
move.l a1,a4
lea MyDta,a3
; IFEQ TSTIENV
; tst.b IEnvFlg
; beq.s .noenv
; move.l CurEditBlock,a1
; move.l TXT_text(a1),a4
; move.l TXT_size(a1),d3
; bra .end
;.noenv:
; ENDC :TSTIENV
move.l a6,a0
bsr find_file
bmi.s .rfind
.ffound: tst.l d7
bne.s .sizeset
move.l DTA_SIZE(a3),d3
.sizeset: move.l a6,a0
bsr open_file
bmi.s .ropen
move.l d0,d4
; IFNE TSTIENV
; tst.b IEnvFlg
; beq.s .ttp
; bsr get_edit_file
; bra.s .end
;.ttp:
; ENDC
move.l d3,d0
addq.l #4,d0
sf d1
jsr MyMalloc
beq.s .rmem
move.l d0,a4
move.l d7,d0
beq.s .read
move.l d4,d1
bsr seek_file
bmi.s .rseek
.read: move.l a4,a0
move.l d3,d0
move.l d4,d1
bsr read_file
cmp.l d0,d3
bne.s .rread
move.l d4,d0
bsr close_file
bne.s .rclose
lea 0(a4,d3.l),a0
clr.b (a0)+
clr.b (a0)+
clr.b (a0)+
clr.b (a0)+
.end: move.l d3,d0
move.l a6,a1
move.l a4,a0
movem.l (sp)+,d3-d7/a2-a6
rts
.rmem: move #fileram_errno,d7
bra.s .print
.rfind:
.ropen: move #open_errno,d7
bra.s .print
.rclose: move #close_errno,d7
bra.s .print
.rread: move #read_errno,d7
bra.s .close
.rseek: move #seek_errno,d7
.close: move.l d4,d0
bsr close_file
.print: move.w d7,d0
bra filepfatal
;.incdir: lea InclDir,a0
; tst.b (a0)
; beq.s .erropen
; lea SrcNameBuf,a2
; move.l a2,a1
; STRCPY
; subq.w #1,a1
; move.l a6,a0
; STRCPY
; lea MyDta,a3
; move.l a2,a0
; bsr find_file
; bmi.s .erropen
; move.l a2,a6
; bra .ffound
IFNE TSTIENV
;Input: d4:file handle,d3:size
get_edit_file:
clr.l HeadEditBlock
clr.l CurEditBlock
movem.l d3/a6,-(sp)
.read: bsr.s .alloc
move.l a0,a2
move.l TXT_text(a2),a0
move.l d4,d1
move.l #EDIT_BLK_SIZE,d0
bsr read_file
tst.l d0
beq.s .end
cmp.l #EDIT_BLK_SIZE,d0
bne.s .notfull
bsr .cut
move.l d0,-(sp)
sub.l #EDIT_BLK_SIZE,d0
move.l d4,d1
bsr rel_seek_file
move.l (sp)+,d0
.notfull: move.l d0,TXT_size(a2)
move.l TXT_text(a2),a0
adda.l d0,a0
REPT 4
clr.b (a0)+
ENDR
bra.s .read
.end: move.l HeadEditBlock,a0
move.l a0,CurEditBlock
move.l TXT_text(a0),a4
movem.l (sp)+,d3/a6
rts ;attention dernier block de taille 0
.alloc: move.l CurEditBlock,d1
move.l #TXT_SIZEOF,d0
jsr MyMalloc
beq.s .errmem
move.l d0,a0
move.l #EDIT_BLK_SIZE+4,d0
jsr MyMalloc
move.l d0,TXT_text(a0)
beq.s .errmem
move.l d1,TXT_prev(a0)
beq.s .first
move.l d1,a1
move.l a0,TXT_next(a1)
.link: clr.l TXT_next(a0)
clr.l TXT_size(a0)
move.l a0,CurEditBlock
rts
.first: move.l a0,HeadEditBlock
bra.s .link
.errmem: move #fileram_errno,d0
bra filepfatal
;d0=taille lue
.cut: move.l TXT_text(a2),a0
lea 0(a0,d0.l),a1
moveq #13,d1
moveq #10,d2
.l1: cmp.b -(a1),d1
bhs.s .line
.tst: cmp.l a0,a1
bgt.s .l1
IFNE BLINDOS
_Debugger
ENDC
bra.s .ok
.line: cmp.b (a1),d2
beq.s .ok
cmp.b (a1),d1
bne.s .tst
.ok: addq.w #1,a1
move.l a1,d0
sub.l a0,d0
rts
ENDC ;TSTIENV
FreeEditBlocks:
IFNE TSTIENV
move.l d1,-(sp)
move.l HeadEditBlock,d1
beq.s .end
.nx: move.l d1,a0
move.l TXT_next(a0),d1
jsr MyMfree
tst.l d1
bne.s .nx
.end: move.l (sp)+,d1
ENDC
rts
; #] LoadSrc:
; #[ GetIncBin:
;Out: a0=@nom avec chemin eventuel
GetIncBin:
movem.l d6-d7/a4-a6,-(sp)
move.l a0,a6
bsr open_dta
move.l a6,a0
moveq #$22,d0
bsr find_first
move.l d0,d6
bsr close_dta
move.l d6,d0
bne.s .rfnf
move.l a6,a0
.found: move.l MyDta+DTA_SIZE,d0
.end: movem.l (sp)+,d6-d7/a4-a6
rts
.rfnf: move #open_errno,d0
bra filepfatal
; #] GetIncBin:
; #[ LoadBin:
;GERER CLOSE ERROR
;--- IN ---
;a0=ptr sur nom de fichier
;a1=ptr sur @ de chargement (nul ou negatif=pas d'@)
;d0=taille a charger (<0 if none)
;d1=offset par rapport au debut du fichier a charger (0 if none)
;--- INTERNAL ---
;d3=taille
;d4=handle
;d6=@ de chargement
;d7 sert en fin
;a3=new dta
;a4=olddta
;a6=nom de fichier
;--- OUT ---
;a0=@ de chargement
;a1=@ nom de fichier
;d0=taille chargee
LoadBin: movem.l d3-d7/a2-a6,-(sp)
move.l a0,a6
move.l a1,d6
move.l d0,d3
move.l d1,d5
lea MyDta,a3
move.l a6,a0
bsr find_file
bmi.s .rfind
.ffound: tst.l d3
bpl.s .sizeset
move.l DTA_SIZE(a3),d3
.sizeset: move.l a6,a0 ;lea DTA_NAME(a3),a6
bsr open_file
bmi.s .ropen
move.l d0,d4
move.l d6,a3
tst.l d6
bgt.s .nores
move.l d3,d0
sf d1
jsr MyMalloc
beq.s .rmem
move.l d0,a3
.nores: move.l d5,d0 ;seeker au besoin
beq.s .no_seek
move.l d4,d1
bsr seek_file
bmi.s .rseek
.no_seek: move.l a3,a0
move.l d3,d0
move.l d4,d1
bsr read_file
cmp.l d0,d3
bne.s .rread
move.l d0,d7
move.l d4,d0
bsr close_file
.end: move.l d7,d0
move.l a6,a1
move.l a3,a0
movem.l (sp)+,d3-d7/a2-a6
rts
.rmem: move #fileram_errno,d7
bra.s .print
.rfind:
.ropen: move #open_errno,d7
bra.s .print
.rclos: move #close_errno,d7
bra.s .print
.rseek: move #seek_errno,d7
bra.s .close
.rread: move #read_errno,d7
.close: move.l d4,d0
bsr close_file
.print: move.l d7,d0
bra filepfatal
;.incdir?: lea InclDir,a0
; tst.b (a0)
; beq.s .erropen
; lea SrcNameBuf,a2
; move.l a2,a1
; STRCPY
; subq.w #1,a1
; move.l a6,a0
; STRCPY
; lea MyDta,a3
; move.l a2,a0
; bsr.s find_file
; bmi.s .erropen
; move.l a2,a6
; bra .ffound
; #] LoadBin:
; #[ Save file:
;--- IN ---
;a0=nom de fichier
;a1=@ d'ou sauver
;d0=taille
;--- INTERNAL ---
;d3=taille
;d7=@ sauvegarde
;a6=nom de fichier
;save_file2:
; movem.l d3/d7/a3-a6,-(sp)
; move.l d0,d3 ;taille
; move.l a1,d7 ;@ sauvegarde
; move.l a0,a6 ;@ nom de fichier
;; move.l a6,a0
; bsr create_file
; bmi.s .open_error
; move.l d0,d4 ;handle
; move.l d7,a0
; move.l d3,d0
; move.w d4,d1
; bsr write_file
;; cmp.l d0,d3
; bne.s .write_error
; move.l d0,d7
;.end: move.w d4,d0
; bsr close_file
;.fin: move.l d7,d0
; movem.l (sp)+,d3/d7/a3-a6
; rts
;.memory_error
; move #fileram_errno,d7
; bra.s .print
;.open_error
; move #create_errno,d7
; bra.s .print
;.write_error
; move #write_errno,d7
;.print: bra filepfatal
; #] Save file:
; #[ Disk functions:
; #[ Find file:
;a0=nom de fichier
TestFile:
find_file:
movem.l d6-d7/a3-a4,-(sp)
move.l a0,a3
bsr.s open_dta
move.l a3,a0
moveq #$22,d0
bsr.s find_first
move.l d0,d6
bsr close_dta
tst.w d6
bne.s .end
move.l a3,a0
STRLEN
beq.s .error
lea 0(a3,d0.w),a4
subq.w #1,d0
.l1: move.b -(a4),d1
cmp.b #DIRSEP,d1
beq.s .cd
cmp.b #':',d1
beq.s .cd
dbf d0,.l1
bra.s .end
.cd: move.b 1(a4),d7
clr.b 1(a4)
move.l a3,a0
bsr _cd
bmi.s .end
move.b d7,1(a4)
bra.s .end
.error: moveq #-1,d6
.end: move.l d6,d0
movem.l (sp)+,d6-d7/a3-a4
rts
; #] Find file:
; #[ Disk operation:
get_wd: pea _get_drivepath(pc)
bra.s disk_operation
get_drive:
pea _get_drive(pc)
bra.s disk_operation
get_path:
pea _get_path(pc)
bra.s disk_operation
;set_drive:
; pea _set_drive(pc)
; bra.s disk_operation
set_path:
pea _set_path(pc)
bra.s disk_operation
open_dta:
pea _open_dta(pc)
bra.s disk_operation
find_first:
pea _find_first(pc)
bra.s disk_operation
find_next:
pea _find_next(pc)
bra.s disk_operation
open_file:
pea _open_file(pc)
bra.s disk_operation
create_file:
pea _create_file(pc)
bra.s disk_operation
write_file:
pea _write_file(pc)
bra.s disk_operation
read_file:
pea _read_file(pc)
bra.s disk_operation
seek_file:
pea _seek_file(pc)
bra.s disk_operation
rel_seek_file:
pea _rel_seek_file(pc)
bra.s disk_operation
close_dta:
pea _close_dta(pc)
bra.s disk_operation
close_file:
pea _close_file(pc)
; bra.s disk_operation
disk_operation:
move.l (sp)+,a1
move.l a2,-(sp)
jsr (a1)
move.l (sp)+,a2
rts
; #] Disk operation:
; #[ Get drive:
_get_drive:
move.w #$19,-(sp)
trap #1
addq.w #2,sp
rts
; #] Get drive:
; #[ Get drivepath:
;a0=ptr sur buffer devant contenir le path
_get_drivepath:
move.l a0,-(sp)
bsr.s _get_drive
move.l (sp)+,a0
add.b #'A',d0
move.b d0,(a0)+
move.b #':',(a0)+
; bra _get_path
; #] Get drivepath:
; #[ Get path:
;a0=ptr sur buffer devant contenir le path
_get_path:
move.l a0,-(sp)
clr.w -(sp)
move.l a0,-(sp)
move.w #$47,-(sp)
trap #1
addq.w #8,sp
move.l (sp)+,a0
tst.b (a0)
bne.s .end
move.b #DIRSEP,(a0)+
clr.b (a0)
.end: ;tst.l d0
rts
; #] Get path:
; #[ Set drive:
;d0=nouveau numero de drive
set_drive:
;_set_drive:
move.w d0,-(sp)
move.w #$e,-(sp)
trap #1
addq.w #4,sp
rts
; #] Set drive:
; #[ Set path:
;a0=ptr sur nouveau path
_set_path:
move.l a0,-(sp)
move.w #$3b,-(sp)
trap #1
addq.w #6,sp
rts
; #] Set path:
; #[ Open dta:
_open_dta:
moveq #0,d0
tst.l OldDta
bne.s .no_setdta
move.w #$2f,-(sp)
trap #1
addq.w #2,sp
move.l d0,OldDta
pea MyDta
move.w #$1a,-(sp)
trap #1
addq.w #6,sp
.no_setdta:
rts
; #] Open dta:
; #[ Find first:
_find_first:
move.w d0,-(sp)
move.l a0,-(sp)
move.w #$4e,-(sp)
trap #1
addq.w #8,sp
rts
; #] Find first:
; #[ Find next:
_find_next:
move.w #$4f,-(sp)
trap #1
addq.w #2,sp
rts
; #] Find next:
; #[ Open file:
;a0=nom de fichier
_open_file:
clr.w -(sp)
move.l a0,-(sp)
move.w #$3d,-(sp)
trap #1
addq.w #8,sp
tst.l d0
rts
; #] Open file:
; #[ Create file:
;a0=nom de fichier
_create_file:
; move.l a0,-(sp)
clr.w -(sp)
move.l a0,-(sp)
move.w #$3c,-(sp)
trap #1
addq.w #8,sp
tst.l d0
; move.l (sp)+,a0
; tst.l d0
; bne.s .end
; bsr find_file
;.end:
rts
; #] Create file:
; #[ Write file:
;a0=nom de fichier
;d0=taille
;d1.w=handle
_write_file:
move.l d0,-(sp)
move.l a0,-(sp)
move.l d0,-(sp)
move.w d1,-(sp)
move.w #$40,-(sp)
trap #1
lea 12(sp),sp
move.l (sp)+,d1
cmp.l d0,d1
rts
; #] Write file:
; #[ Read file:
;a0=ptr
;d0=taille
;d1.w=handle
_read_file:
move.l d0,-(sp)
move.l a0,-(sp)
move.l d0,-(sp)
move.w d1,-(sp)
move.w #$3f,-(sp)
trap #1
lea 12(sp),sp
move.l (sp)+,d1
cmp.l d0,d1
rts
; #] Read file:
; #[ Seek file:
;d0=offset
;d1.w=handle
_seek_file:
clr.w -(sp)
move.w d1,-(sp)
move.l d0,-(sp)
move.w #$42,-(sp)
trap #1
lea 10(sp),sp
tst.l d0
rts
;d0=offset
;d1.w=handle
_rel_seek_file:
move.w #1,-(sp)
move.w d1,-(sp)
move.l d0,-(sp)
move.w #$42,-(sp)
trap #1
lea 10(sp),sp
tst.l d0
rts
; #] Seek file:
; #[ Close dta:
_close_dta:
tst.l OldDta
beq.s .end
move.l OldDta,-(sp)
move.w #$1a,-(sp)
trap #1
addq.w #6,sp
clr.l OldDta
.end:
rts
; #] Close dta:
; #[ Close file:
;handle ds d0
_close_file:
move.w d0,-(sp)
move.w #$3e,-(sp)
trap #1
addq.w #4,sp
tst.l d0
rts
; #] Close file:
; #[ IsAbsFname:
;In: a0=@filename/directory name
IsAbsFname:
movem.l d1-d2/a0-a1,-(sp)
move.l a0,a1
moveq #':',d1
moveq #DIRSEP,d2
.l2: move.b (a0)+,d0
beq.s .no
cmp.b d1,d0
bne.s .l1
move.l a0,d0
sub.l a1,d0
subq.l #1,d0
bne.s .yes
bra.s .no
.l1: cmp.b d2,d0
bne.s .l2
.no: moveq #-1,d0
.end: movem.l (sp)+,d1-d2/a0-a1
rts
.yes: moveq #0,d0
bra.s .end
; #] IsAbsFname:
; #] Disk functions:
; #[ filepfatal:
filepfatal:
neg.w d0
lea filemsg,a0
move.w #MSG_FATL,MSG_flags(a0)
move.w d0,MSG_no(a0)
move.l CurModPtr,MSG_mod(a0)
move.l CurLNb,MSG_lnb(a0)
move.l CurLPtr,MSG_ln(a0)
jmp OutMsg
; #] filepfatal:
; #[ Out functions:
;Input:
;d0 char to print
;Output:
;ccr+d0: <0:error
;WritePrt: move.w d0,-(sp)
; move.w #5,-(sp)
; trap #1
; addq.w #4,sp
; not.l d0
; rts
LstOpen: move.l a0,-(sp)
lea LstName,a0
bsr create_file
move.l (sp)+,a0
bmi.s .rcreate
move.l d0,LstHand
rts
.rcreate: move #create_errno,d0
bra filepfatal
LstClose: move.l LstHand,d0
beq.s .noclose
move.l a0,-(sp)
bsr close_file
move.l (sp)+,a0
clr.l LstHand
.noclose: rts
;Input:
;d0.l=strlen
;a0=src @
;a1=dst @
expttl: move.w LstLnLen,d1
sub.w d0,d1
lsr.w #1,d1
subq.w #1,d1
bmi.s .cpy
moveq #' ',d0
.l1: move.b d0,(a1)+
dbf d1,.l1
.l2: move.b (a0)+,(a1)+
bne.s .l2
.crlf: subq.w #1,a1
move.b #13,(a1)+
move.b #10,(a1)+
clr.b (a1)
rts
.cpy: STRCPY
bra.s .crlf
;In:a0=string
PrtLine: tst.w LstCnt
bne .nolst
tst.l LstHand
beq .nolst
tst.b LstPgFlg
beq.s .nohead
movem.l a0-a2,-(sp)
lea -256(sp),sp
lea LstLnNb,a0
move.l (a0),d0
move.w LstPgLen,d1
divu d1,d0
swap d0
tst.w d0
bne.s .nopage
moveq #$c,d0 ;form feed
bsr PrtChar
addq.l #1,LstPgNb ;pnb++
lea LstMttl,a0
PSTRLEN
beq.s .nottl
move.l sp,a1
bsr expttl
move.l sp,a0
bsr.s .nohead
.nottl: lea LstSttl,a0
PSTRLEN
beq.s .nopage
move.l sp,a1
bsr expttl
move.l sp,a0
bsr.s .nohead
.nopage: addq.l #1,LstLnNb ;lnb++
lea 256(sp),sp
movem.l (sp)+,a0-a2
.nohead: PSTRLEN
move.l LstHand,d1
bsr write_file
bne.s .rwrite
rts
.nolst: tst.b IEnvFlg
beq.s .noenv
move.l IEnvPtr,a1
move.l IENV_print(a1),a1
jsr (a1)
tst.w d0
bne.s .ok
jmp NoPrtEnd
.ok: rts
.noenv: move.l a2,-(sp)
move.l a0,-(sp)
move.w #9,-(sp)
trap #1
addq.w #6,sp
move.l (sp)+,a2
rts
.rwrite: bsr LstClose
move #write_errno,d0
bra filepfatal
; move.l a2,-(sp)
;.l1: move.b (a0)+,d0
; beq.s .end
; cmp.b #10,d0
; beq.s .print
; cmp.b #13,d0
; beq.s .print
; cmp.b #9,d0
; beq.s .print
; cmp.b #31,d0
; bgt.s .print
; move.l a0,-(sp)
; bsr out_char
; move.l (sp)+,a0
; bra.s .l1
;.print: move.l a0,-(sp)
; bsr print_char
; move.l (sp)+,a0
; bra.s .l1
;.end: move.l (sp)+,a2
; rts
OutChar: move.w d0,-(sp)
move.l #$30005,-(sp)
trap #13 ;print 'raw'
addq.w #6,sp
rts
PrtChar: tst.w LstCnt
bne.s .nolst
move.l LstHand,d1
beq.s .nolst
move.b d0,-(sp)
move.l sp,a0
moveq #1,d0
bsr write_file
addq.w #2,sp
bne.s .rwrite
rts
.rwrite: bsr LstClose
move #write_errno,d0
bra filepfatal
.nolst: tst.b IEnvFlg
bne.s .end
move.w d0,-(sp)
move.w #2,-(sp)
trap #1 ;print VT52
addq.w #4,sp
.end: rts
PrtNChar: move.w d0,-(sp)
move.l #$30002,-(sp)
trap #13
addq #6,sp
rts
; #] Out functions:
; #[ Kbd functions:
GetShifts:
move.l #$affff,-(sp)
trap #13
addq.w #4,sp
rts
; #] Kbd functions:
; #[ Time functions:
StrtTime: pea .rout(pc)
move.w #$26,-(sp)
trap #14
addq.w #6,sp
rts
.rout: move.l $4ba.w,d0
.wait cmp.l $4ba.w,d0
beq.s .wait
move.l d0,FstTime
rts
StopTime: pea .rout(pc)
move.w #$26,-(sp)
trap #14
addq.w #6,sp
sub.l FstTime,d0
lsr.l #1,d0 ;200Hz->100Hz
divu #100,d0
move.l d0,TotTime
rts
.rout: move.l $4ba.w,d0
.wait cmp.l $4ba.w,d0
beq.s .wait
rts
; #] Time functions:
; #[ IsFPU:
;Out:
;d0.b=-1:no fpu -> bmi error
;d0.b=1:fpu present
IsFPU: move.b fpuflg,d0
bne.s .ok
pea .getfpu(pc)
move.w #$26,-(sp)
trap #14
addq.w #6,sp
move.b d0,fpuflg
.ok: rts
.getfpu: move.l $5a0.w,d0
beq.s .no
move.l d0,a0
.l1: move.l (a0)+,d0
beq.s .no
cmp.l #'_FPU',d0
beq.s .chk
addq.w #4,a0
bra.s .l1
.chk: move.w (a0),d0
lsr.w #1,d0
beq.s .no
rts
.no: moveq #-1,d0
rts
; #] IsFPU:
; #[ GetMPU:
;Out:
;d0.w=MPU #
GetMPU: pea .getmpu(pc)
move.w #$26,-(sp)
trap #14
addq.w #6,sp
rts
.getmpu: move.l $5a0.w,d0
beq.s .no
move.l d0,a0
.l1: move.l (a0)+,d0
beq.s .no
cmp.l #'_CPU',d0
beq.s .chk
addq.w #4,a0
bra.s .l1
.chk: move.l (a0),d0
divu #10,d0
rts
.no: moveq #0,d0
rts
; #] GetMPU:
; #[ End function:
DoEnd: move.l LstHand,d0
beq.s .nolst
bsr close_file
.nolst: move.w LstErr,d0