Subversion Repositories Spectranet

[/] [branches/] [gnubinutils/] [modules/] [snapman/] [directory.asm] - Diff between revs 371 and 372

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 371 Rev 372
Line 19... Line 19...
;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.
 
 
; Read the current directory and filter files found.
; Read the current directory and filter files found.
        include "../../rom/fs_statdefs.asm"
.include        "stat.inc"
 
.include        "spectranet.inc"
 
.include        "snapman.inc"
 
 
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
; F_loaddir
; F_loaddir
; Load the contents of a directory into memory.
; Load the contents of a directory into memory.
F_loaddir
.globl F_loaddir
 
F_loaddir:
        call F_loading
        call F_loading
        xor a                   ; initialize vars
        xor a                   ; initialize vars
        ld (v_numdirs), a
        ld (v_numdirs), a
        ld (v_numsnas), a
        ld (v_numsnas), a
        ld hl, v_dirtable
        ld hl, v_dirtable
Line 42... Line 45...
 
 
        ld hl, 0x002E           ; "." followed by a NULL terminator
        ld hl, 0x002E           ; "." followed by a NULL terminator
        ld (WORKSPACE), hl      ; put it somewhere the FS module can see
        ld (WORKSPACE), hl      ; put it somewhere the FS module can see
        ld hl, WORKSPACE        ; and set this as the param to OPENDIR
        ld hl, WORKSPACE        ; and set this as the param to OPENDIR
        call OPENDIR
        call OPENDIR
        jr c, .err
        jr c,  .err1
        ld (v_dhnd), a          ; save the directory handle
        ld (v_dhnd), a          ; save the directory handle
.readloop
.readloop1:
        ld de, v_dirwkspc
        ld de, v_dirwkspc
        call READDIR            ; Get the next directory entry
        call READDIR            ; Get the next directory entry
        jr c, .readdone         ; Probably EOF
        jr c,  .readdone1               ; Probably EOF
        call F_filterdir        ; Decide whether to store or discard
        call F_filterdir        ; Decide whether to store or discard
        ld a, (v_dhnd)          ; Restore dirhandle
        ld a, (v_dhnd)          ; Restore dirhandle
        jr .readloop
        jr  .readloop1
.readdone
.readdone1:
        ld a, (v_dhnd)
        ld a, (v_dhnd)
        call CLOSEDIR
        call CLOSEDIR
        ld hl, (v_snaptr)       ; terminate lists
        ld hl, (v_snaptr)       ; terminate lists
        ld (hl), 0
        ld (hl), 0
        inc hl
        inc hl
Line 64... Line 67...
        ld (hl), 0
        ld (hl), 0
        inc hl
        inc hl
        ld (hl), 0
        ld (hl), 0
        call F_clearloading
        call F_clearloading
        ret
        ret
.err
.err1:
        call F_clearloading
        call F_clearloading
        ret                     ; TODO - report errors
        ret                     ; TODO - report errors
 
 
;------------------------------------------------------------------------
;------------------------------------------------------------------------
; F_filterdir
; F_filterdir
; Looks at the directory entry in v_dirwkspc, stats it, and adds it to the
; Looks at the directory entry in v_dirwkspc, stats it, and adds it to the
; appropriate list.
; appropriate list.
F_filterdir
.globl F_filterdir
 
F_filterdir:
        ld hl, v_dirwkspc
        ld hl, v_dirwkspc
        ld de, v_statinfo
        ld de, v_statinfo
        call STAT
        call STAT
        ret c                   ; TODO - error handling
        ret c                   ; TODO - error handling
        ld a, (v_statinfo+STAT_MODE+1)  ; Get high order of MODE bits
        ld a, (v_statinfo+STAT_MODE+1)  ; Get high order of MODE bits
        and S_IFDIR / 256       ; compare with high order mask for isdir
        and S_IFDIR / 256       ; compare with high order mask for isdir
        jr nz, .directory
        jr nz,  .directory2
.file
.file2:
        ld hl, v_statinfo+STAT_SIZE
        ld hl, v_statinfo+STAT_SIZE
        ld de, c_48ksnap
        ld de, c_48ksnap
        call F_cp32             ; Look for a file the size of a 48k snap
        call F_cp32             ; Look for a file the size of a 48k snap
        jr z, .checkfilename
        jr z,  .checkfilename2
 
 
        ; TODO - check whether machine is 128K
        ; TODO - check whether machine is 128K
        ld hl, v_statinfo+STAT_SIZE
        ld hl, v_statinfo+STAT_SIZE
        ld de, c_128ksnap1
        ld de, c_128ksnap1
        call F_cp32
        call F_cp32
        jr z, .checkfilename
        jr z,  .checkfilename2
        ld hl, v_statinfo+STAT_SIZE
        ld hl, v_statinfo+STAT_SIZE
        ld de, c_128ksnap2
        ld de, c_128ksnap2
        call F_cp32
        call F_cp32
        ret nz
        ret nz
.checkfilename
.checkfilename2:
        ld hl, (v_snaptr)
        ld hl, (v_snaptr)
        ld de, (v_snanextentry)
        ld de, (v_snanextentry)
        call F_addentry
        call F_addentry
        ld (v_snaptr), hl
        ld (v_snaptr), hl
        ld (v_snanextentry), de
        ld (v_snanextentry), de
        ld a, (v_numsnas)
        ld a, (v_numsnas)
        inc a
        inc a
        ld (v_numsnas), a
        ld (v_numsnas), a
        ret
        ret
 
 
.directory
.directory2:
        ld hl, (v_dirptr)       ; current end of directory table
        ld hl, (v_dirptr)       ; current end of directory table
        ld de, (v_dirnextentry)
        ld de, (v_dirnextentry)
        call F_addentry
        call F_addentry
        ld (v_dirptr), hl
        ld (v_dirptr), hl
        ld (v_dirnextentry), de
        ld (v_dirnextentry), de
        ld a, (v_numdirs)
        ld a, (v_numdirs)
        inc a
        inc a
        ld (v_numdirs), a
        ld (v_numdirs), a
        ret
        ret
c_48ksnap       defw    0xC01B,0x0000
c_48ksnap:      defw    0xC01B,0x0000
c_128ksnap1     defw    0x001F,0x0002
c_128ksnap1:    defw    0x001F,0x0002
c_128ksnap2     defw    0x401F,0x0002
c_128ksnap2:    defw    0x401F,0x0002
 
 
;-----------------------------------------------------------------------
;-----------------------------------------------------------------------
; F_addentry
; F_addentry
; Adds an entry to a string table
; Adds an entry to a string table
F_addentry
.globl F_addentry
 
F_addentry:
        push hl
        push hl
        push de
        push de
        ld hl, v_dirwkspc       ; point at filename to copy
        ld hl, v_dirwkspc       ; point at filename to copy
        call F_strcpy
        call F_strcpy
        pop bc
        pop bc
Line 142... Line 147...
;-----------------------------------------------------------------------
;-----------------------------------------------------------------------
; F_cp32
; F_cp32
; 32 bit compare between two memory locations
; 32 bit compare between two memory locations
; HL = pointer to location 1
; HL = pointer to location 1
; DE = pointer to location 2
; DE = pointer to location 2
F_cp32
.globl F_cp32
 
F_cp32:
        ld b, 4                 ; number of iterations
        ld b, 4                 ; number of iterations
.loop
.loop4:
        ld a, (de)
        ld a, (de)
        cp (hl)
        cp (hl)
        ret nz                  ; no compare
        ret nz                  ; no compare
        inc de
        inc de
        inc hl
        inc hl
        djnz .loop
        djnz  .loop4
        ret
        ret