Skip to content

Commit d76f179

Browse files
authored
Merge pull request #659 from boriel/fix/esxdos.bas
fix: fixes esxdos.bas library
2 parents caea830 + c158fa0 commit d76f179

2 files changed

Lines changed: 108 additions & 164 deletions

File tree

src/arch/zx48k/library/esxdos.bas

Lines changed: 54 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
' Copyleft (k) 2017
55
' by Miguel Angel Rodriguez Jodar (mcleod_ideafix)
66
' and Jose Rodriguez-Rosa (a.k.a. Boriel) <http://www.boriel.com>
7-
'
7+
' Revised and fixed by Duefectu
88
' ESXDOS file access usage
99
' ----------------------------------------------------------------
1010

@@ -65,7 +65,7 @@ REM Avoid recursive / multiple inclusion
6565
'
6666
' Returns:
6767
' File stream ID (ubyte)
68-
' it can be -1 on error (variable ERR_NR will contain
68+
' it can be -1 on error (variable ERR_NR will contain
6969
' another value with extra information)
7070
' ----------------------------------------------------------------
7171
Function ESXDosOpen(ByVal fname as String, ByVal mode as Ubyte) as Byte
@@ -119,7 +119,7 @@ End Sub
119119

120120
' ----------------------------------------------------------------
121121
' Function ESXDosWrite
122-
'
122+
'
123123
' Parameters:
124124
' handle: file handle (returned by ESXDOSOpen
125125
' buffer: memory address for the buffer
@@ -131,8 +131,6 @@ End Sub
131131
Function FASTCALL ESXDosWrite(ByVal handle as Byte, _
132132
ByVal buffer as UInteger, _
133133
ByVal nbytes as UInteger) as Uinteger
134-
poke EDOS_ERR_NR,255
135-
136134
Asm
137135
;FASTCALL implies handle is already in A register
138136
ld hl, EDOS_ERR_NR
@@ -207,6 +205,8 @@ Sub FASTCALL ESXDosSeek(ByVal handle as byte, _
207205
ByVal offset as Long, _
208206
ByVal position as UByte)
209207
Asm
208+
ld hl, EDOS_ERR_NR
209+
ld (hl), 255 ; sets 255 = OK
210210
;FASTCALL implies handle is already in A register
211211
pop hl ; ret address
212212
pop de ; low (word) offset part
@@ -232,9 +232,10 @@ End Sub
232232
' Returns:
233233
' the current file position
234234
' ----------------------------------------------------------------
235-
Function ESXDosGetPos (ByVal handle as byte) as long
235+
Function FASTCALL ESXDosGetPos (ByVal handle as byte) as long
236236
Asm
237-
ld a,(ix+5)
237+
ld hl, EDOS_ERR_NR
238+
ld (hl), 255 ; sets 255 = OK
238239
rst 8
239240
db F_GETPOS
240241
ld h,d
@@ -420,18 +421,14 @@ End Sub
420421
' new entry was retrieved
421422
'
422423
' ----------------------------------------------------------------
423-
Function ESXDosReadDentry (ByVal handle as UInteger) as Byte
424-
poke EDOS_ERR_NR,255
425-
if handle = 0 then
426-
return 0
427-
end if
428-
424+
Function FASTCALL ESXDosReadDentry (ByVal handle as UInteger) as Byte
429425
Asm
430426
Proc
427+
ld a, 0xFF
428+
ld (EDOS_ERR_NR), a
429+
431430
local read_ok
432431

433-
ld l,(ix+4) ;
434-
ld h,(ix+5) ; HL = block of memory where OpenDir stored handle
435432
ld a,(hl)
436433
inc hl
437434

@@ -513,17 +510,13 @@ End Function
513510
' entry retrieved in the last call to ESXDosReadDentry
514511
'
515512
' ----------------------------------------------------------------
516-
Function ESXDosGetDentryFilesize (ByVal handle as UInteger) as ULong
517-
if handle = 0 then
518-
return 0
519-
end if
520-
513+
Function FASTCALL ESXDosGetDentryFilesize (ByVal handle as UInteger) as ULong
521514
Asm
522515
Proc
523516
Local ParseString
524517

525-
ld l,(ix+4)
526-
ld h,(ix+5)
518+
ld a, 0xFF
519+
ld (EDOS_ERR_NR), a
527520
inc hl ;skip over ESXDOS directory handle
528521

529522
ParseString:
@@ -625,19 +618,18 @@ End Sub
625618
' on the next call to ESXDosReadDentry
626619
'
627620
' ----------------------------------------------------------------
628-
Function ESXDosTellDir (ByVal handle as UInteger) as ULong
629-
630-
poke EDOS_ERR_NR,255
631-
if handle = 0 then
632-
return 0
633-
end if
634-
621+
Function FASTCALL ESXDosTellDir (ByVal handle as UInteger) as ULong
635622
Asm
636623
Proc
624+
ld a, 0xFF
625+
ld (EDOS_ERR_NR), a
626+
637627
local read_ok,divide_by_32
638628

639-
ld l,(ix+4) ;
640-
ld h,(ix+5) ; HL = block of memory where OpenDir stored handle
629+
ld a, h
630+
or l
631+
ret z
632+
641633
ld a,(hl)
642634

643635
push ix
@@ -646,7 +638,10 @@ Function ESXDosTellDir (ByVal handle as UInteger) as ULong
646638
pop ix
647639
jr nc,read_ok
648640
ld (EDOS_ERR_NR),a
649-
ld hl,0
641+
ld hl, 0
642+
ld d, h
643+
ld e, l
644+
ret
650645
read_ok:
651646
ld h,d ;
652647
ld l,e ; BCDE -> DEHL for ZX Basic
@@ -674,43 +669,40 @@ End Function
674669
' entry: ULong containing the directory entry # to seek to.
675670
'
676671
' ----------------------------------------------------------------
677-
Sub ESXDosSeekDir (ByVal handle as UInteger, ByVal entry as ULong)
678-
poke EDOS_ERR_NR,255
679-
if handle = 0 then
680-
return
681-
end if
682-
672+
Sub FASTCALL ESXDosSeekDir (ByVal handle as UInteger, ByVal entry as ULong)
683673
Asm
684674
Proc
685-
local read_ok
675+
local multiply_by_32
676+
677+
ld a, 0xFF
678+
ld (EDOS_ERR_NR), a
686679

687-
ld l,(ix+4) ;
688-
ld h,(ix+5) ; HL = block of memory where OpenDir stored handle
680+
ld a, h
681+
or l
689682
ld a,(hl)
690683

691-
ld e,(ix+6)
692-
ld d,(ix+7)
693-
ld l,(ix+8)
694-
ld h,(ix+9)
684+
pop hl
685+
pop de
686+
ex (sp),hl
687+
ret z
695688

696689
ld b,5
697690
multiply_by_32:
698-
sla l ;
699-
rl h ; Multiply DEHL by 32
700-
rl e ;
701-
rl d ;
691+
sla e ;
692+
rl d ; Multiply HLDE by 32
693+
rl l ;
694+
rl h ;
702695
djnz multiply_by_32
703-
ld b,h ;
704-
ld c,l ; Offset is now at BCDE
696+
ld b, h ;
697+
ld c, l ; Offset is now at BCDE
705698

706699
ld l,0 ; Just in case this is using L as in F_SEEK (to-do)
707700
push ix
708701
rst 8
709702
db F_SEEKDIR
710703
pop ix
711-
jr nc,read_ok
704+
ret nc
712705
ld (EDOS_ERR_NR),a
713-
read_ok:
714706
Endp
715707
End Asm
716708

@@ -727,25 +719,25 @@ End Sub
727719
' Functionally equivalent to ESXDosSeekDir (handle, 0)
728720
'
729721
' ----------------------------------------------------------------
730-
Sub ESXDosRewindDir (ByVal handle as UInteger)
731-
poke EDOS_ERR_NR,255
732-
if handle = 0 then
733-
return
734-
end if
735-
722+
Sub FASTCALL ESXDosRewindDir (ByVal handle as UInteger)
736723
Asm
737724
Proc
738725
local read_ok
739726

740-
ld l,(ix+4) ;
741-
ld h,(ix+5) ; HL = block of memory where OpenDir stored handle
727+
ld a,0xFF
728+
ld (EDOS_ERR_NR),a
729+
730+
ld a, h
731+
or l
732+
ret z
733+
742734
ld a,(hl)
743735

744736
push ix
745737
rst 8
746738
db F_REWINDDIR
747739
pop ix
748-
jr nc,read_ok
740+
ret nc
749741
ld (EDOS_ERR_NR),a
750742
read_ok:
751743
Endp
@@ -774,24 +766,4 @@ End Sub
774766
#undef F_MKDIR
775767
#undef F_RMDIR
776768

777-
#undef EDOS_FMODE_READ
778-
#undef EDOS_FMODE_WRITE
779-
#undef EDOS_FMODE_OPEN_EX
780-
#undef EDOS_FMODE_OPEN_AL
781-
#undef EDOS_FMODE_CREATE_NEW
782-
#undef EDOS_FMODE_CREATE_AL
783-
784-
#undef SEEK_START
785-
#undef SEEK_CUR
786-
#undef SEEK_BKCUR
787-
788-
#undef FATTR_RDONLY
789-
#undef FATTR_HIDDEN
790-
#undef FATTR_SYSTEM
791-
#undef FATTR_VOLUME
792-
#undef FATTR_DIR
793-
#undef FATTR_ARCHIVE
794-
795-
#undef EDOS_ERR_NR
796-
797769
#endif

0 commit comments

Comments
 (0)