Line 17... |
Line 17... |
;FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
;FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
;AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
;AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
;LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
;LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
;OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
;OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
;THE SOFTWARE.
|
;THE SOFTWARE.
|
|
.include "stat.inc"
|
|
.include "fcntl.inc"
|
|
.include "spectranet.inc"
|
|
.include "defs.inc"
|
|
.include "zxrom.inc"
|
|
.include "ctrlchars.inc"
|
|
.include "sysvars.inc"
|
|
.text
|
|
|
; Routine that lists directories.
|
|
include "../../rom/fs_statdefs.asm"
|
|
; Show the directory listing. HL = directory to open.
|
; Show the directory listing. HL = directory to open.
|
F_listdir
|
.globl F_listdir
|
|
F_listdir:
|
call OPENDIR ; open the directory
|
call OPENDIR ; open the directory
|
jp c, J_tbas_error
|
jp c, J_tbas_error
|
ld (v_vfs_dirhandle), a ; save the directory handle
|
ld (v_vfs_dirhandle), a ; save the directory handle
|
ld a, 2
|
ld a, 2
|
rst CALLBAS ; set channel to 2
|
rst CALLBAS ; set channel to 2
|
defw 0x1601
|
defw 0x1601
|
.catloop
|
.catloop1:
|
ld a, (v_vfs_dirhandle) ; get the dir handle back
|
ld a, (v_vfs_dirhandle) ; get the dir handle back
|
ld de, INTERPWKSPC ; location for result
|
ld de, INTERPWKSPC ; location for result
|
call READDIR ; read dir
|
call READDIR ; read dir
|
jr c, .readdone ; read is probably at EOF
|
jr c, .readdone1 ; read is probably at EOF
|
call F_statentry ; show some information about it
|
call F_statentry ; show some information about it
|
ld hl, INTERPWKSPC
|
ld hl, INTERPWKSPC
|
call F_tbas_zxprint ; print a C string to #2
|
call F_tbas_zxprint ; print a C string to #2
|
ld a, '\r' ; newline
|
ld a, NEWLINE ; newline
|
rst CALLBAS
|
rst CALLBAS
|
defw 0x10
|
defw 0x10
|
jr .catloop
|
jr .catloop1
|
.readdone
|
.readdone1:
|
push af ; save error code while
|
push af ; save error code while
|
ld a, (v_vfs_dirhandle) ; we close the dir handle
|
ld a, (v_vfs_dirhandle) ; we close the dir handle
|
call CLOSEDIR
|
call CLOSEDIR
|
pop hl ; pop into hl to not disturb flags
|
pop hl ; pop into hl to not disturb flags
|
jp c, J_tbas_error ; report any error
|
jp c, J_tbas_error ; report any error
|
Line 52... |
Line 59... |
cp EOF ; EOF is good
|
cp EOF ; EOF is good
|
jp nz, J_tbas_error ; everything else is bad, report it
|
jp nz, J_tbas_error ; everything else is bad, report it
|
jp EXIT_SUCCESS
|
jp EXIT_SUCCESS
|
|
|
; Expects the filename to be in INTERPWKSPC
|
; Expects the filename to be in INTERPWKSPC
|
F_statentry
|
.globl F_statentry
|
|
F_statentry:
|
ld hl, INTERPWKSPC
|
ld hl, INTERPWKSPC
|
ld de, INTERPWKSPC+256 ; where to put the data
|
ld de, INTERPWKSPC+256 ; where to put the data
|
call STAT
|
call STAT
|
jr c, .staterr
|
jr c, .staterr2
|
ld ix, INTERPWKSPC+256
|
ld ix, INTERPWKSPC+256
|
ld a, (ix+(STAT_MODE+1)) ; Check file mode MSB
|
ld a, (ix+(STAT_MODE+1)) ; Check file mode MSB
|
and S_IFDIR / 256 ; check directory flag
|
and S_IFDIR / 256 ; check directory flag
|
jr z, .isfile
|
jr z, .isfile2
|
ld hl, STR_dir
|
ld hl, STR_dir
|
call F_tbas_zxprint
|
call F_tbas_zxprint
|
jr .continue
|
jr .continue2
|
.isfile
|
.isfile2:
|
call F_showsize
|
call F_showsize
|
ld a, ' '
|
ld a, ' '
|
rst CALLBAS
|
rst CALLBAS
|
defw 0x0010
|
defw 0x0010
|
.continue
|
.continue2:
|
ret
|
ret
|
|
|
.staterr
|
.staterr2:
|
ld hl, STR_staterr
|
ld hl, STR_staterr
|
jp F_tbas_zxprint ; print it and return.
|
jp F_tbas_zxprint ; print it and return.
|
|
|
STR_staterr defb " Err ",0
|
STR_staterr: defb " Err ",0
|
STR_dir defb " Dir ",0
|
STR_dir: defb " Dir ",0
|
|
|
;----------------------------------------------------------------------
|
;----------------------------------------------------------------------
|
; F_showsize
|
; F_showsize
|
; Create a 4 digit decimal with the correct ending (b, k, M or G)
|
; Create a 4 digit decimal with the correct ending (b, k, M or G)
|
; TODO: This routine is particularly naive and hardly optimized
|
; TODO: This routine is particularly naive and hardly optimized
|
; for space (or anything else). (Low priority TODO).
|
; for space (or anything else). (Low priority TODO).
|
F_showsize
|
.globl F_showsize
|
|
F_showsize:
|
ld a, (ix+(STAT_SIZE+3)) ; MSB of size
|
ld a, (ix+(STAT_SIZE+3)) ; MSB of size
|
ld b, a
|
ld b, a
|
and 0xC0 ; >= 2^30
|
and 0xC0 ; >= 2^30
|
jr nz, .gigs
|
jr nz, .gigs3
|
cpl ; check lower half
|
cpl ; check lower half
|
and b ; of 4th stat byte for megs
|
and b ; of 4th stat byte for megs
|
jr nz, .megs
|
jr nz, .megs3
|
ld a, (ix+(STAT_SIZE+2))
|
ld a, (ix+(STAT_SIZE+2))
|
ld b, a
|
ld b, a
|
and 0xF0 ; >= 2^20
|
and 0xF0 ; >= 2^20
|
jr nz, .megs
|
jr nz, .megs3
|
cpl ; check lower half of
|
cpl ; check lower half of
|
and b ; 3rd stat byte for kilos
|
and b ; 3rd stat byte for kilos
|
jr nz, .kilos
|
jr nz, .kilos3
|
ld a, (ix+(STAT_SIZE+1))
|
ld a, (ix+(STAT_SIZE+1))
|
and 0xFC ; >= 2^10
|
and 0xFC ; >= 2^10
|
jr nz, .kilos
|
jr nz, .kilos3
|
ld l, (ix+STAT_SIZE) ; less than 1K
|
ld l, (ix+STAT_SIZE) ; less than 1K
|
ld h, (ix+(STAT_SIZE+1))
|
ld h, (ix+(STAT_SIZE+1))
|
call F_decimal
|
call F_decimal
|
ld a, 'b'
|
ld a, 'b'
|
rst CALLBAS
|
rst CALLBAS
|
defw 0x0010
|
defw 0x0010
|
ret
|
ret
|
.kilos
|
.kilos3:
|
ld l, (ix+(STAT_SIZE+1)) ; 1K to 1023K
|
ld l, (ix+(STAT_SIZE+1)) ; 1K to 1023K
|
ld h, (ix+(STAT_SIZE+2))
|
ld h, (ix+(STAT_SIZE+2))
|
srl h
|
srl h
|
rr l
|
rr l
|
srl h
|
srl h
|
Line 121... |
Line 130... |
call F_decimal
|
call F_decimal
|
ld a, 'k'
|
ld a, 'k'
|
rst CALLBAS
|
rst CALLBAS
|
defw 0x0010
|
defw 0x0010
|
ret
|
ret
|
.megs
|
.megs3:
|
ld l, (ix+(STAT_SIZE+2)) ; 1M to 1023M
|
ld l, (ix+(STAT_SIZE+2)) ; 1M to 1023M
|
ld h, (ix+(STAT_SIZE+3))
|
ld h, (ix+(STAT_SIZE+3))
|
ld b, 4
|
ld b, 4
|
.megloop
|
.megloop3:
|
srl h
|
srl h
|
rr l
|
rr l
|
djnz .megloop
|
djnz .megloop3
|
call F_decimal
|
call F_decimal
|
ld a, 'M'
|
ld a, 'M'
|
rst CALLBAS
|
rst CALLBAS
|
defw 0x0010
|
defw 0x0010
|
ret
|
ret
|
.gigs
|
.gigs3:
|
ld l, (ix+(STAT_SIZE+4)) ; 1G to 4G
|
ld l, (ix+(STAT_SIZE+4)) ; 1G to 4G
|
ld h, 0
|
ld h, 0
|
ld b, 6
|
ld b, 6
|
.gigloop
|
.gigloop3:
|
srl l
|
srl l
|
djnz .gigloop
|
djnz .gigloop3
|
call F_decimal
|
call F_decimal
|
ld a, 'G'
|
ld a, 'G'
|
rst CALLBAS
|
rst CALLBAS
|
defw 0x0010
|
defw 0x0010
|
ret
|
ret
|
|
|
;----------------------------------------------------------------------
|
;----------------------------------------------------------------------
|
; F_decimal
|
; F_decimal
|
; Modified version of http://baze.au.com/misc/z80bits.html#5.1
|
; Modified version of http://baze.au3.com3/misc/z80bits.html3#5.13
|
; by baze.
|
; by baze.
|
; HL = number to convert
|
; HL = number to convert
|
F_decimal
|
.globl F_decimal
|
|
F_decimal:
|
ld e, 0
|
ld e, 0
|
ld bc, -1000 ; maximum value passed will be 9999
|
ld bc, -1000 ; maximum value passed will be 9999
|
call .num1
|
call .num14
|
ld bc, -100
|
ld bc, -100
|
call .num1
|
call .num14
|
ld c, -10
|
ld c, -10
|
call .num1
|
call .num14
|
ld c, b
|
ld c, b
|
ld e, 1 ; print a zero if it's the last digit
|
ld e, 1 ; print a zero if it's the last digit
|
.num1
|
.num14:
|
ld a, '0'-1
|
ld a, '0'-1
|
.num2
|
.num24:
|
inc a
|
inc a
|
add hl, bc
|
add hl, bc
|
jr c, .num2
|
jr c, .num24
|
sbc hl, bc
|
sbc hl, bc
|
|
|
bit 0, e
|
bit 0, e
|
jr nz, .zerocont
|
jr nz, .zerocont4
|
cp '0'
|
cp '0'
|
jr nz, .nonz
|
jr nz, .nonz4
|
ld a, ' '
|
ld a, ' '
|
jr .zerocont
|
jr .zerocont4
|
.nonz
|
.nonz4:
|
ld e, 1
|
ld e, 1
|
.zerocont
|
.zerocont4:
|
rst CALLBAS
|
rst CALLBAS
|
defw 0x0010
|
defw 0x0010
|
ret
|
ret
|
|
|