-
Notifications
You must be signed in to change notification settings - Fork 3
/
M4ROM.s
5907 lines (5258 loc) · 100 KB
/
M4ROM.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
; M4 Board cpc z80 rom
; Written by Duke, 2016/2017/2018
; www.spinpoint.org
.module cpc
.area _HEADER (ABS)
.org 0xC000
.include "ff.i"
.include "firmware.i"
.include "m4cmds.i"
rom_response .equ 0xE800
m4_workspace .equ rom_response+0xA00
snamem .equ rom_response+0xB00
rom_config .equ rom_response+0xC00
sock_status .equ 0xFE00
rom_table .equ 0xFF00
UDIR_RAM_Address .equ 0xBEA3
DATAPORT .equ 0xFE00
ACKPORT .equ 0xFC00
.db 0x01
.db 2, 0, 0
.dw rsx_commands
; RSX jump block
jp init_rom ; 0xC006
jp set_SDdrive ; |SD 0xC009
jp disc ; |DISC 0xC00C
jp change_dir ; |CD 0xC00F
jp copy_file ; |COPYF 0xC012
jp tape ; |TAPE 0xC015
jp httpget ; |HTTPGET 0xC018
jp httpgetmem ; |HTTPMEM 0xC01B
jp drvA ; |A 0xC01E
jp drvB ; |B 0xC021
jp drive ; |DRIVE 0xC024
jp user ; |USER 0xC027
jp directory ; |DIR 0xC02A
jp erase_file ; |ERA 0xC02D
jp rename_file ; |REN 0xC030
jp set_message ; 0x81 0xC033
jp setup_disc ; 0x82 0xC036
jp select_format ; 0x83 0xC039
jp read_sector ; 0x84 0xC03C
jp write_sector ; 0x85 0xC03F
jp format_track ; 0x86 0xC042
jp move_track ; 0x87 0xC045
jp get_dr_status ; 0x88 0xC048
jp set_retry_cnt ; 0x89 0xC04B
jp m4off ; |M4ROMOFF 0xC04E
jp makedir ; |MKDIR 0xC051
jp setnetwork ; |NETSET 0xC054
jp netstat ; |NETSTAT 0xC057
jp gettime ; |TIME 0xC05A
jp upgrade ; |UPGRADE 0xC05D
jp version ; |VERSION 0xC060
jp rom_upload ; |ROMUP 0xC063
jp rom_set ; |ROMSET 0xC066
jp rom_update ; |ROMUPD 0xC069
jp ls ; |ls 0xC06C
jp UDIR ; |UDIR 0xC06F
jp init_plus ; 0xC072
jp GETPATH ; |UDIR 0xC075
jp LongName ; |UDIR 0xC078
jp wifi_power
jp fcp
jp m4help
jp snaload
jp ctrboot
jp ctrupload
jp dsk_extract
jp romsoff
rsx_commands:
.ascis "M4 BOARD"
.ascis "SD"
.ascis "DISC"
.ascis "CD"
.ascis "COPYF"
.ascis "TAPE"
.ascis "HTTPGET"
.ascis "HTTPMEM"
.ascis "A"
.ascis "B"
.ascis "DRIVE"
.ascis "USER"
.ascis "DIR"
.ascis "ERA"
.ascis "REN"
.db 0x81 ; Set message
.db 0x82 ; Drive speed
.db 0x83 ; Disc type
.db 0x84 ; Read sector
.db 0x85 ; Write sector
.db 0x86 ; Format track
.db 0x87 ; Seek track
.db 0x88 ; Test drive
.db 0x89 ; Set retry count
.ascis "M4ROMOFF"
.ascis "MKDIR"
.ascis "NETSET"
.ascis "NETSTAT"
.ascis "TIME"
.ascis "UPGRADE"
.ascis "VERSION"
.ascis "ROMUP"
.ascis "ROMSET"
.ascis "ROMUPD"
.ascis "LS"
.ascis "UDIR"
.db 0x8A ; plus init
.ascis "GETPATH"
.ascis "LONGNAME"
.ascis "WIFI"
.ascis "FCP"
.ascis "M4HELP"
.ascis "SNA"
.ascis "CTR"
.ascis "CTRUP"
.ascis "DSKX"
.ascis "ROMSOFF"
.db 0
; work space map
; 000-073 : Amsdos openin header (if amsdos not present, otherwise use amsdos cas_in_header)
; 074-143 : Amsdos openout header (if amsdos not present, otherwise use amsdos cas_out_header)
; 144-272 : actual work buffer
cas_out_isdirect .equ -5
cas_buf_l .equ -4
cas_buf_h .equ -3
cas_idx_l .equ -2
cas_idx_h .equ -1
cas_filetype .equ 18
cas_size_l .equ 19 ; data len
cas_size_h .equ 20
cas_in_next_byte .equ 0x23
cas_in_eof .equ 0x24
init_rom: push de
push hl
pop iy
; detect if amsdos present?
ld a,(0xBC77)
cp #0xDF
jr z, use_amsdos
ld bc,#-276 ; 144+128
add iy,bc
jr init_cnt
use_amsdos:
ld bc,#-128 ; 128
add iy,bc
init_cnt: push iy ; workspace start
ld de, #fio_jvec
init_cont:
ld (iy),#19+3 ; config size+3 (to increase)
ld 1(iy),#C_CONFIG
ld 2(iy),#C_CONFIG>>8
ld 3(iy),#0 ; config offset (0..251)
ld 6(iy),e ; 02 patch jump vector l
ld 7(iy),d ; 03 patch jump vector h
call #kl_curr_selection ; get M4 rom number
ld 8(iy),a ; 04 current rom
ld 9(iy),#0 ; 05 init count.
ld a,#0x80
cp c ; was 0x80 substracted, then we are using amsdos buffer
jr z,amsdos_buffers
push iy
pop hl
ld bc,#5
add hl,bc ; point to amsdos in header
ld 4(iy),l ; 00 amsdos in header l
ld 5(iy),h ; 01 amsdos in header h
ld bc,#74
add hl,bc
ld 10(iy),l ; 06 amsdos out header l
ld 11(iy),h ; 07 amsdos out header h
ld bc,#74-5
add hl,bc
ld 20(iy),#0
ld 21(iy),#0
; set BE7D for compatiblity with loaders that read and use the pointer to ie. restore drive num.
ld a,l
ld (#0xBE7D),a
ld a,h
ld (#0xBE7E),a
jr no_amsdos_buffers
amsdos_buffers:
ld hl,(0xBE7D)
ld bc,#0x55
add hl,bc ; point to amsdos in header
ld 4(iy),l ; 00 amsdos in header l
ld 5(iy),h ; 01 amsdos in header h
ld bc,#74
add hl,bc
ld 10(iy),l ; 06 amsdos out header l
ld 11(iy),h ; 07 amsdos out header h
ld hl,(0xBE7D)
dec hl
dec hl
ld a,(hl) ; amsdos rom number
ld c,a
ld 21(iy),c
call #0xB915 ; probe rom
ld 20(iy),h ; amsdos version
push iy
pop hl
inc hl
no_amsdos_buffers:
ld 12(iy),l ; 08 regular workspace for rom l
ld 13(iy),h ; 09 regular workspace for rom h
push iy
pop hl
ld de,#14
add hl,de
ex de,hl
ld hl,#txt_output
ldi
ldi
ldi
ld hl,#0xbc6e
ldi
ldi
ldi
ld c,#0 ; check basic rom ver
call #0xB915
ld 22(iy),h
call send_command_iy
; save amsdos or tape functions
; BCA7-BC77 = 48
ld (iy),#48+3 ; config size+3
ld 1(iy),#C_CONFIG
ld 2(iy),#C_CONFIG>>8
ld 3(iy),#22 ; config offset
push iy
pop de
inc de
inc de
inc de
inc de
ld hl,#0xBC77
ld bc,#48
ldir
call send_command_iy
call set_SDdrive
; detect if AZERTY or QWERTY keyboard
ld hl,#0xB502
ld a,(#0xBB5B)
cp #0
jr nz, basic11
ld hl,#0xB3B8
basic11:
ld de,#1 ; dest offset
ld bc,#DATAPORT ; data out port
out (c),c
ld a, #C_ROMWRITE ;
out (c),a ; command lo
ld a, #C_ROMWRITE>>8 ;
out (c),a ; command hi
out (c),e ; rom dest addr
out (c),d ; rom dest addr
out (c),e ; size 1
out (c),d ; size 0001
dec d
out (c),d ; (0 = M4 ROM, 255 = nmi rom)
ld a,(hl)
out (c),a ; keyb val
ld b,#ACKPORT>>8 ; kick command
out (c),c
pop hl
pop de
and a
scf
ret
init_plus: ;ld hl,#0
;jp mc_start_program
call kl_l_rom_enable
ld hl,#0
jp 0x77
init_msg:
.ascii " M4 Board v2.0.6"
.db 10, 13, 10, 13, 0
; ------------------------- strncmp
; -- parameters:
; -- HL = string 1
; -- DE = string 2
; -- b = len
; -- return:
; -- A = 0 == match
strncmp: ld a,(de)
xor (hl)
ret nz
inc hl
inc de
djnz strncmp
ret
; ------------------------- strlen
; -- parameters:
; -- HL = zero terminated string
; -- return:
; -- A = length
strlen:
push bc
push hl
ld b,#0
strlen_loop:
ld a,(hl)
cp #0
jr z, term
inc hl
inc b
jr strlen_loop
term:
ld a,b
pop hl
pop bc
ret
temp:
scf
sbc a,a
ret
; ------------------------- strcpy
; -- parameters:
; -- HL = string
; -- DE = dest.
; -- B = string len
; -- return:
; -- A = length
strcpy:
push bc
push hl
push de
strcpy_loop:
ld a,(hl)
ld (de),a
inc hl
inc de
djnz strcpy_loop
xor a
ld (de),a
pop de
pop hl
pop bc
ld a,b
inc a
ret
; same but remove spaces
strcpynz:
push bc
push hl
push de
ld c,#0
strcpy_loopnz:
ld a,(hl)
cp #32
jr z,skip_space
ld (de),a
inc de
inc c
skip_space:
inc hl
djnz strcpy_loopnz
xor a
ld (de),a
pop de
pop hl
ld a,c
pop bc
inc a
ret
upper_case:
cp #'a'
ret c
cp #'z'+1
ret nc
and #0xDF
ret
; ------------------------- strcpy83
; -- parameters:
; -- HL = string
; -- DE = dest.
; -- B = string len
; -- return:
; -- A = length
strcpy83:
push bc
push hl
push de
; loop through first 8 characters, if we encounter '.' pad with spaces.
ld c,b ; in length
ld b,#8
copy8:
ld a,c
cp #0
jr z,space_pad
ld a,(hl)
cp #0x2E ; are we at extension yet?
jr z,space_pad
dec c ; decrease inlength
inc hl
call upper_case
jr cont_strcpy83
space_pad:
ld a,#32
cont_strcpy83:
ld (de),a
inc de
djnz copy8
ld b,#3
ld a,(hl)
cp #0x2E ; are we at extension yet?
jr z, has_ext
ld c,#1 ; no (valid) extension
has_ext:
inc hl
dec c
copy3: ld a,c
cp #0
jr z,space_pad2
ld a,(hl)
inc hl
dec c
call upper_case
jr cont_strcpy83_2
space_pad2:
ld a,#32
cont_strcpy83_2:
ld (de),a
inc de
djnz copy3
ld a,#0
ld (de),a
pop de
pop hl
pop bc
ret
; ------------------------- fio jump vector
; AMSDOS 0xCD30
fio_jvec: di
ex af,af'
exx
ld a,c
pop de ; return address
pop bc ; workspace?
pop hl ; 0x85 10000101 (disable upperrom)
ex (sp),hl ; get jump entry from stack
push bc ;
push de ;
ld c,a ;
ld b,#0x7f
ld de,#cas_hook_table-0xbc77-3; offset from bc77
add hl,de ; add offset to jump table
push hl ; save it on stack
exx ; restore
ex af,af'
ei
ret
cas_hook_table:
jp _cas_in_open ; BC77
jp _cas_in_close ; BC7A
jp _cas_in_abandon ; BC7D
jp _cas_in_char ; BC80
jp _cas_in_direct ; BC83
jp _cas_return ; BC86
jp _cas_test_eof ; BC89
jp _cas_out_open ; BC8C
jp _cas_out_close ; BC8F
jp _cas_out_abandon ; BC92
jp _cas_out_char ; BC95
jp _cas_out_direct ; BC98
jp _cas_catalog ; BC9B
; ------------------------- cas_in_open replacement BC77
; -- parameters
; -- HL = filename
; -- DE = 0 or 2Kbuffer
; -- B = filename len
; -- returns
; -- carry true if valid
; -- HL ptr to AMSDOS header
; -- DE load address
; -- BC filesize (-header)
; -- A file type
_cas_in_open: push iy
push hl
push de
push bc
ld a,b
cp #0
jr z, failopen
ld a,#FA_READ ; read mode
call fopen
cp #0xFF
jr nz, open_ok
ld a,b
cp #0x92 ; file not found? set Z flag.
jr nz,other_open_error
failopen:
pop bc ; len
pop de
pop hl ; filename
push hl
push de
push bc
push af
ld iy,(#rom_workspace)
push iy
pop de ; dest
call strcpy83 ; hl = filename, de =workspace, b = len
ld hl,#11
add hl,de
ld e,l
ld d,h
push de
dec hl
ldd
ldd
ldd
ld a,#0x2E
ld (de),a
pop de
inc de
; de = workspace
ld hl,#text_not_found
ld bc,#13
ldir
push iy
pop hl
call disp_msg
pop af
other_open_error:
pop bc
pop de
pop hl
pop iy
scf
ccf
ret
open_ok:
; read first 128 bytes and check if its using AMSDOS header
ld de,(#amsdos_inheader)
ld a,(amsdos_ver)
cp #0
jr z, no_amsdos_rom
; read to "buffer area"
ld hl,#0xE4-0x55
add hl,de
ex de,hl
ld hl,#128 ; size of header
ld a,#1 ; fd
call fread
; copy to real location
ld hl,(#amsdos_inheader)
ex de,hl
ld bc,#69
push de
ldir
pop de
jr check_head
no_amsdos_rom:
ld hl,#69 ; size of header
ld a,#1 ; fd
call fread
check_head:
; DE still amsdos header ptr
push de
; check checksum
ld b,#66
ld hl,#0
checksum_loop:
push bc
ld a,(de)
ld c,a
ld b,#0
inc de
add hl,bc
pop bc
djnz checksum_loop
ld iy,(#amsdos_inheader)
ld e,cas_size_l(iy)
ld c,cas_size_h(iy)
ld d,#0
ld b,#0
ld cas_size_l(iy),#0 ;
ld cas_size_h(iy),#0 ; size
; clear internal vars
ld cas_in_eof(iy),#0
ld cas_in_next_byte(iy),#0 ; next char for test eof
; compare with header checksum
ld a,l
cp 67(iy)
jr nz, checksum_mismatch
ld a,h
cp 68(iy)
jr z, checksum_ok
; deal with headerless file
checksum_mismatch:
; build "fake" header
ld hl,#0
ld a,#1
call fseek
; clear header
pop hl ; header
ld b,#69
clear_loop:
ld (hl),#0
inc hl
djnz clear_loop
; copy filename into "fake" header
pop bc ; b = filename len
pop de ; 2k buffer or 0
ld 21(iy),e
ld 22(iy),d
ld cas_buf_l(iy),e
ld cas_buf_h(iy),d
ld cas_idx_l(iy),e
ld cas_idx_h(iy),d
pop hl ; filename
push iy
pop de
inc de
call strcpy83
ld 18(iy),#0x16; set as ascii?
ld 23(iy),#0xFF ; first block 0xFF
ld 66(iy),#0x80
;ld de,#0; x170 ; load adr
;ld e,19(iy)
;ld d,20(iy)
;ld iy,(#rom_workspace)
;ld 1(iy),#C_FSIZE
;ld 2(iy),#C_FSIZE>>8
;ld 3(iy),#1
;ld (iy),#3
;call send_command_iy
ld bc,#0 ;(#rom_response+3) ; size
;ld iy,(#amsdos_inheader)
ld e,cas_buf_l(iy)
ld d,cas_buf_h(iy)
push iy
pop hl
;or a ; z = 0
scf ; c = 1
sbc a,a
ld a,#0x16 ; x2
pop iy
ret
checksum_ok: or a
sbc hl,bc
or a
sbc hl,de
ld 67(iy),l
ld 68(iy),h
ld hl,#128 ; ignore rest of header (unused)
ld a,#1
call fseek
; get protection flag
; ld l,#0
; ld a,18(iy)
; and #1
; cp #0
; jr z,no_prot
; inc l
;no_prot:
; ld a,(basic_ver) ; version
; cp #0 ; is basic 1.0
; ld a,l
; jr nz,notpbasic10
; ld (#0xAE45),a
; jr pflag_set
;notpbasic10:
; ld (#0xAE2C),a
;pflag_set:
pop hl
pop de ; b =filename len
pop de ; 2k buffer or 0
ld cas_buf_l(iy),e
ld cas_buf_h(iy),d
ld cas_idx_l(iy),e
ld cas_idx_h(iy),d
pop de ; filename
; DE = load address
ld e,21(iy)
ld d,22(iy)
; BC = file size
ld c,24(iy)
ld b,25(iy)
; A= file type
scf ; set carry flag
sbc a,a ; clear z
ld a,18(iy)
pop iy
ret
open_fail:
pop de
pop iy
call _cas_in_close
or a
ret
; ------------------------- cas_in_close replacement BC7A
_cas_in_close:
; detect
ld a,#1
call fclose
cp #0
scf
jr nz,close_fail
sbc a,a
ret
close_fail:
ccf
ret
; ------------------------- cas_in_abandon replacement BC7D
_cas_in_abandon:
ld a,#1
call fclose
scf
sbc a,a
ret
; ------------------------- cas_in_char replacment BC80
_cas_in_char:
push hl
push bc
push de
push iy
ld iy,(#amsdos_inheader)
; size > 0
ld e,cas_size_l(iy) ; size
ld d,cas_size_h(iy) ;
xor a
cp e
jr nz, no_buffer_fill
cp d
jr nz, no_buffer_fill
; EOF flag set ?
ld b,#0xF ; set hard EOF
ld a,cas_in_eof(iy) ; EOF yet?
cp #0
jp nz, char_in_eof
; re-fill buffer
ld bc,#DATAPORT ; data out port
out (c),c
ld a,#C_READ2
out (c),a ; command lo
ld a,#C_READ2>>8
out (c),a ; command hi
ld a,#1
out (c),a ; output char
xor a
out (c),a
ld a,#8
out (c),a
ld bc,#ACKPORT
out (c),c ; tell M4 that command has been send
; check rom response
ld a,(#rom_response+3)
cp #20 ; eof ?
jr nz, not_eof_yet
; Set EOF flag
ld a,#1
ld cas_in_eof(iy),a ; this is end of file
; check if read size == 0
ld hl,(#rom_response+4) ; read size
xor a
cp h
jr nz, not_eof_yet
cp l
jr nz, not_eof_yet
ld b,#0xF ; set hard end
jr char_in_eof
not_eof_yet:
ld hl,(#rom_response+4) ; read size
ld cas_size_l(iy),l ; size
ld cas_size_h(iy),h ;
;ld hl,(#rom_response+6)
ld c,l
ld b,h
ld hl,#rom_response+8
ld e, cas_buf_l(iy)
ld d, cas_buf_h(iy)
ld cas_idx_l(iy),e ; index
ld cas_idx_h(iy),d ; index
xor a
cp e
jr nz, buf_is_set
cp d
jr z, no_buffer_fill
buf_is_set:
ldir
no_buffer_fill:
;ld hl,#rom_response+8
ld l,cas_idx_l(iy) ; index
ld h,cas_idx_h(iy) ;
rst #0x20
ld b,a
inc hl
ld cas_idx_l(iy),l ; index
ld cas_idx_h(iy),h ;
rst #0x20
ld l, cas_size_l(iy) ; size
ld h, cas_size_h(iy)
dec hl
ld cas_size_l(iy),l ; size
ld cas_size_h(iy),h ;
ld cas_in_next_byte(iy),a
ld a,#26
cp b
jr z, char_in_eof
or a ; z = 0
scf ; c = 1
ld a,b
pop iy
pop de
pop bc
pop hl
ret
char_in_eof: or a ; z = 0
scf
ccf ; c = 0
ld a,b ; get either 0xF or 0x1A
pop iy
pop de
pop bc
pop hl
ret
; ------------------------- cas_in_direct replacement BC83
; -- parameters
; -- HL = load address
; -- returns
; -- HL = exec addr
_cas_in_direct:
push iy
ld iy,(#amsdos_inheader)
push bc
; DE = address
ex de,hl
; HL = size
xor a
ld l,24(iy)
ld h,25(iy)
cp h
jr nz, head_not_zero
cp l
jr nz, head_not_zero
; get dsk record size instead
ld 1(iy),#C_FSIZE
ld 2(iy),#C_FSIZE>>8
ld 3(iy),#1 ; fd
ld (iy),#3
call send_command_iy
ld hl,(#rom_response+3)
head_not_zero:
; A = fd
ld a,#1
call fread
cp #0
jr nz,in_direct_error
; get exec addr
ld l,26(iy)
ld h,27(iy)
pop bc
pop iy
scf
sbc a,a
ret
in_direct_error:
pop bc
pop iy
or a ; clear carry
ret
; ------------------------- cas_return replacement BC86
_cas_return:
push hl
push de
push bc
push af
ld hl,#ftell_cmd
call send_command
ld hl,(#rom_response+3)
dec hl
ld a,#1
call fseek
pop af
pop bc
pop de
pop hl
ret
; ------------------------- cas_test_eof replacement BC89
_cas_test_eof: push hl