Subversion Repositories Spectranet

[/] [branches/] [gnubinutils/] [modules/] [basext/] [commands.asm] - Diff between revs 371 and 380

Show entire file | Details | Blame | View Log

Rev 371 Rev 380
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.
 
 
; TNFS BASIC extensions
; TNFS BASIC extensions
        include "../../rom/zxromdefs.asm"
.include        "zxrom.inc"
 
.include        "spectranet.inc"
 
.include        "defs.inc"
 
.include        "fcntl.inc"
 
.include        "sysvars.inc"
 
.include        "zxsysvars.inc"
 
.text
;---------------------------------------------------------------------------
;---------------------------------------------------------------------------
; F_tbas_mount
; F_tbas_mount
; BASIC interpreter for "mount"
; BASIC interpreter for "mount"
; Syntax: %mount mountpoint, "url"
; Syntax: %mount mountpoint, "url"
F_tbas_mount
.globl F_tbas_mount
 
F_tbas_mount:
        ; Syntax and runtime
        ; Syntax and runtime
        rst CALLBAS
        rst CALLBAS
        defw ZX_EXPT1_NUM
        defw ZX_EXPT1_NUM
        cp ','                          ; comma
        cp ','                          ; comma
        jp nz, PARSE_ERROR
        jp nz, PARSE_ERROR
Line 53... Line 59...
        ld hl, INTERPWKSPC+10
        ld hl, INTERPWKSPC+10
        call F_basstrcpy                ; copy string from BASIC
        call F_basstrcpy                ; copy string from BASIC
        ld ix, INTERPWKSPC              ; where to place the mount struct
        ld ix, INTERPWKSPC              ; where to place the mount struct
        ld hl, INTERPWKSPC+10           ; location of the string to parse
        ld hl, INTERPWKSPC+10           ; location of the string to parse
        call F_parseurl
        call F_parseurl
        jr c, .badurl
        jr c, .badurl1
 
 
        rst CALLBAS                     ; fetch the mount point
        rst CALLBAS                     ; fetch the mount point
        defw ZX_FIND_INT2
        defw ZX_FIND_INT2
 
 
.mount
.mount1:
        ld a, c                         ; mount point in BC
        ld a, c                         ; mount point in BC
        call MOUNT
        call MOUNT
        jp c, J_tbas_error              ; display the error message
        jp c, J_tbas_error              ; display the error message
 
 
        jp EXIT_SUCCESS
        jp EXIT_SUCCESS
 
 
.badurl
.badurl1:
        ld a, EBADURL
        ld a, EBADURL
        jp J_tbas_error
        jp J_tbas_error
 
 
        ; Copy a BASIC string to a C string.
        ; Copy a BASIC string to a C string.
        ; BASIC string in DE, C string (dest) in HL
        ; BASIC string in DE, C string (dest) in HL
F_basstrcpy
.globl F_basstrcpy
 
F_basstrcpy:
        ld a, b                         ; end of string?
        ld a, b                         ; end of string?
        or c
        or c
        jr z, .terminate
        jr z, .terminate2
        ld a, (de)
        ld a, (de)
        ld (hl), a
        ld (hl), a
        inc hl
        inc hl
        inc de
        inc de
        dec bc
        dec bc
        jr F_basstrcpy
        jr F_basstrcpy
.terminate
.terminate2:
        xor a                           ; put the null on the end
        xor a                           ; put the null on the end
        ld (hl), a
        ld (hl), a
        inc hl
        inc hl
        ret
        ret
 
 
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
; F_tbas_umount
; F_tbas_umount
; Umount the mounted filesystem.
; Umount the mounted filesystem.
F_tbas_umount
.globl F_tbas_umount
 
F_tbas_umount:
        rst CALLBAS
        rst CALLBAS
        defw ZX_EXPT1_NUM               ; 1 parameter - mount point number
        defw ZX_EXPT1_NUM               ; 1 parameter - mount point number
        call STATEMENT_END
        call STATEMENT_END
 
 
        ;--------- runtime ---------
        ;--------- runtime ---------
Line 106... Line 114...
        jp EXIT_SUCCESS
        jp EXIT_SUCCESS
 
 
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
; F_tbas_chdir
; F_tbas_chdir
; Handle changing directory
; Handle changing directory
F_tbas_chdir
.globl F_tbas_chdir
 
F_tbas_chdir:
        rst CALLBAS
        rst CALLBAS
        defw ZX_EXPT_EXP                ; expect a string expression
        defw ZX_EXPT_EXP                ; expect a string expression
        call STATEMENT_END
        call STATEMENT_END
 
 
        ;-------- runtime --------
        ;-------- runtime --------
Line 125... Line 134...
 
 
;---------------------------------------------------------------------------
;---------------------------------------------------------------------------
; F_tbas_aload: Loads an arbitary file from the TNFS filesystem.
; F_tbas_aload: Loads an arbitary file from the TNFS filesystem.
; The syntax is %aload "filename" CODE address. This allows the user
; The syntax is %aload "filename" CODE address. This allows the user
; to load an arbitrary file with no ZX formatting into memory.
; to load an arbitrary file with no ZX formatting into memory.
F_tbas_aload
.globl F_tbas_aload
 
F_tbas_aload:
        rst CALLBAS
        rst CALLBAS
        defw ZX_EXPT_EXP                ; expect a string expression
        defw ZX_EXPT_EXP                ; expect a string expression
        cp TOKEN_CODE                   ; expect CODE
        cp TOKEN_CODE                   ; expect CODE
        jp nz, PARSE_ERROR
        jp nz, PARSE_ERROR
        rst CALLBAS                     ; fetch the next bit
        rst CALLBAS                     ; fetch the next bit
Line 156... Line 166...
 
 
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
; F_tbas_load: Loads a ZX file (BASIC, CODE etc.)
; F_tbas_load: Loads a ZX file (BASIC, CODE etc.)
; The syntax is as for ZX BASIC LOAD, except %load.
; The syntax is as for ZX BASIC LOAD, except %load.
; TODO: CODE et al.
; TODO: CODE et al.
F_tbas_load
.globl F_tbas_load
 
F_tbas_load:
        rst CALLBAS
        rst CALLBAS
        defw ZX_EXPT_EXP                ; expect a string expression
        defw ZX_EXPT_EXP                ; expect a string expression
        cp TOKEN_CODE                   ; Check for CODE...
        cp TOKEN_CODE                   ; Check for CODE...
        jr z, .loadcode
        jr z, .loadcode6
        call STATEMENT_END              ; If not, statment end for BASIC.
        call STATEMENT_END              ; If not, statment end for BASIC.
 
 
        ;------ runtime for BASIC ------
        ;------ runtime for BASIC ------
        xor a                           ; type 0x00 is BASIC
        xor a                           ; type 0x00 is BASIC
.loader
.loader6:
        push af                         ; save type
        push af                         ; save type
        rst CALLBAS
        rst CALLBAS
        defw ZX_STK_FETCH               ; fetch the filename
        defw ZX_STK_FETCH               ; fetch the filename
        ld a, b                         ; check for empty string
        ld a, b                         ; check for empty string
        or c
        or c
        jr nz, .havefilename
        jr nz, .havefilename6
        ld hl, STR_BOOTDOTZX
        ld hl, STR_BOOTDOTZX
        ld de, INTERPWKSPC
        ld de, INTERPWKSPC
        ld bc, STR_BOOTDOTZXLEN
        ld bc, STR_BOOTDOTZXLEN
        ldir
        ldir
        jr .loadbasic
        jr .loadbasic6
.havefilename
.havefilename6:
        ld hl, INTERPWKSPC
        ld hl, INTERPWKSPC
        call F_basstrcpy                ; copy + convert to C string
        call F_basstrcpy                ; copy + convert to C string
.loadbasic
.loadbasic6:
        ; Now call the loader routine with the filename in HL
        ; Now call the loader routine with the filename in HL
        ld hl, INTERPWKSPC
        ld hl, INTERPWKSPC
        pop af                          ; get type id
        pop af                          ; get type id
        call F_tbas_loader
        call F_tbas_loader
        jp c, J_tbas_error
        jp c, J_tbas_error
        jp EXIT_SUCCESS
        jp EXIT_SUCCESS
 
 
.loadcode
.loadcode6:
        ; TODO - code to a specific address.
        ; TODO - code to a specific address.
        rst CALLBAS
        rst CALLBAS
        defw ZX_NEXT_CHAR
        defw ZX_NEXT_CHAR
        call STATEMENT_END
        call STATEMENT_END
 
 
        ;------ runtime for CODE with no addr -------
        ;------ runtime for CODE with no addr -------
        ld a, 3                         ; type=CODE
        ld a, 3                         ; type=CODE
        jr .loader                      ; get the filename then load.
        jr .loader6                     ; get the filename then load.
 
 
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
; F_tbas_save: Save a ZX file (BASIC, CODE etc.)
; F_tbas_save: Save a ZX file (BASIC, CODE etc.)
; The syntax is as for ZX BASIC SAVE.
; The syntax is as for ZX BASIC SAVE.
; TODO: CODE et al.
; TODO: CODE et al.
F_tbas_save
.globl F_tbas_save
 
F_tbas_save:
        rst CALLBAS
        rst CALLBAS
        defw ZX_EXPT_EXP                ; fetch the file name
        defw ZX_EXPT_EXP                ; fetch the file name
        cp TOKEN_CODE                   ; for CODE
        cp TOKEN_CODE                   ; for CODE
        jr z, .savecode
        jr z, .savecode7
        cp TOKEN_SCREEN                 ; for SCREEN$
        cp TOKEN_SCREEN                 ; for SCREEN$
        jr z, .savescreen
        jr z, .savescreen7
        cp TOKEN_LINE                   ; then for LINE
        cp TOKEN_LINE                   ; then for LINE
        jr z, .savebasline
        jr z, .savebasline7
 
 
        call STATEMENT_END              ; a basic BASIC save.
        call STATEMENT_END              ; a basic BASIC save.
 
 
        ;------- runtime for simple BASIC save -------
        ;------- runtime for simple BASIC save -------
        rst CALLBAS
        rst CALLBAS
Line 223... Line 235...
        push bc
        push bc
        xor a
        xor a
        call F_tbas_mktapheader
        call F_tbas_mktapheader
        ld hl, 0xFFFF                   ; set param1 to >32767
        ld hl, 0xFFFF                   ; set param1 to >32767
        ld (INTERPWKSPC+OFFSET_PARAM1), hl
        ld (INTERPWKSPC+OFFSET_PARAM1), hl
        jr .makebasicblock
        jr .makebasicblock7
 
 
        ; Deal with SAVE "filename" CODE
        ; Deal with SAVE "filename" CODE
.savecode
.savecode7:
        rst CALLBAS
        rst CALLBAS
        defw ZX_NEXT2_NUM               ; check for 2 numbers
        defw ZX_NEXT2_NUM               ; check for 2 numbers
        call STATEMENT_END              ; then end of command.
        call STATEMENT_END              ; then end of command.
 
 
        ; Runtime
        ; Runtime
Line 238... Line 250...
        defw ZX_FIND_INT2               ; Get the length
        defw ZX_FIND_INT2               ; Get the length
        push bc                         ; into BC and save it
        push bc                         ; into BC and save it
        rst CALLBAS
        rst CALLBAS
        defw ZX_FIND_INT2               ; and the start
        defw ZX_FIND_INT2               ; and the start
        push bc                         ; and save that, too
        push bc                         ; and save that, too
.savecodemain
.savecodemain7:
        rst CALLBAS
        rst CALLBAS
        defw ZX_STK_FETCH               ; and get the filename
        defw ZX_STK_FETCH               ; and get the filename
        ld a, 3                         ; type = 3 - CODE
        ld a, 3                         ; type = 3 - CODE
        call F_tbas_mktapheader         ; create the header template
        call F_tbas_mktapheader         ; create the header template
        pop hl                          ; retrieve the start address
        pop hl                          ; retrieve the start address
Line 251... Line 263...
        ld (INTERPWKSPC+OFFSET_LENGTH), hl      ; and put it in the header
        ld (INTERPWKSPC+OFFSET_LENGTH), hl      ; and put it in the header
        call F_tbas_writefile           ; finally write it out
        call F_tbas_writefile           ; finally write it out
        jp c, J_tbas_error
        jp c, J_tbas_error
        jp EXIT_SUCCESS
        jp EXIT_SUCCESS
 
 
.savescreen
.savescreen7:
        rst CALLBAS
        rst CALLBAS
        defw ZX_NEXT_CHAR               ; advance to the end of the line
        defw ZX_NEXT_CHAR               ; advance to the end of the line
        call STATEMENT_END
        call STATEMENT_END
 
 
        ; Runtime
        ; Runtime
        ld hl, 6912                     ; Put the length of a SCREEN$
        ld hl, 6912                     ; Put the length of a SCREEN$
        push hl                         ; on the stack
        push hl                         ; on the stack
        ld hl, 16384                    ; followed by the start address
        ld hl, 16384                    ; followed by the start address
        push hl
        push hl
        jr .savecodemain                ; and do as for CODE
        jr .savecodemain7               ; and do as for CODE
 
 
.savebasline
.savebasline7:
        rst CALLBAS
        rst CALLBAS
        defw ZX_NEXT_CHAR
        defw ZX_NEXT_CHAR
        rst CALLBAS
        rst CALLBAS
        defw ZX_EXPT1_NUM               ; 1 number - the line number
        defw ZX_EXPT1_NUM               ; 1 number - the line number
        call STATEMENT_END
        call STATEMENT_END
Line 282... Line 294...
        push bc
        push bc
        xor a                           ; type = 0
        xor a                           ; type = 0
        call F_tbas_mktapheader         ; Create the header
        call F_tbas_mktapheader         ; Create the header
        ld hl, (v_bcsave)               ; get LINE parameter
        ld hl, (v_bcsave)               ; get LINE parameter
        ld (INTERPWKSPC+OFFSET_PARAM1), hl ; Put it into parameter 1
        ld (INTERPWKSPC+OFFSET_PARAM1), hl ; Put it into parameter 1
.makebasicblock
.makebasicblock7:
 
 
        ; Fill in the header, length and length without vars
        ; Fill in the header, length and length without vars
        ld hl, (ZX_E_LINE)              ; get the length of the BASIC prog
        ld hl, (ZX_E_LINE)              ; get the length of the BASIC prog
        ld de, (ZX_PROG)                ; by calculating it
        ld de, (ZX_PROG)                ; by calculating it
        scf
        scf
Line 303... Line 315...
 
 
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
; F_tbas_ls
; F_tbas_ls
; List a directory
; List a directory
; Two forms - either %cat or %cat "directory"
; Two forms - either %cat or %cat "directory"
F_tbas_ls
.globl F_tbas_ls
 
F_tbas_ls:
        cp 0x0d
        cp 0x0d
        jr z, .noargs
        jr z, .noargs8
        cp ':'
        cp ':'
        jr z, .noargs
        jr z, .noargs8
 
 
        ; we have an argument supplied.
        ; we have an argument supplied.
        rst CALLBAS
        rst CALLBAS
        defw ZX_EXPT_EXP                ; expect a string
        defw ZX_EXPT_EXP                ; expect a string
        call STATEMENT_END
        call STATEMENT_END
Line 322... Line 335...
        ld hl, INTERPWKSPC
        ld hl, INTERPWKSPC
        call F_basstrcpy                ; convert it to a C string
        call F_basstrcpy                ; convert it to a C string
        ld hl, INTERPWKSPC
        ld hl, INTERPWKSPC
        jp F_listdir
        jp F_listdir
 
 
.noargs
.noargs8:
        call STATEMENT_END
        call STATEMENT_END
 
 
        ; --------- runtime ----------
        ; --------- runtime ----------
        ld a, '.'
        ld a, '.'
        ld (INTERPWKSPC), a             ; default directory is CWD
        ld (INTERPWKSPC), a             ; default directory is CWD
        xor a
        xor a
        ld (INTERPWKSPC+1), a
        ld (INTERPWKSPC+1), a
        ld hl, INTERPWKSPC
        ld hl, INTERPWKSPC
.makecat
.makecat8:
        jp F_listdir
        jp F_listdir
 
 
;---------------------------------------------------------------------------
;---------------------------------------------------------------------------
; F_tbas_tapein
; F_tbas_tapein
; Handle the %tapein command, which takes a filename as a parameter.
; Handle the %tapein command, which takes a filename as a parameter.
F_tbas_tapein
.globl F_tbas_tapein
 
F_tbas_tapein:
        rst CALLBAS
        rst CALLBAS
        defw ZX_EXPT_EXP                ; expect a string expression
        defw ZX_EXPT_EXP                ; expect a string expression
        call STATEMENT_END
        call STATEMENT_END
 
 
        ;-------- runtime --------
        ;-------- runtime --------
Line 352... Line 366...
        jp EXIT_SUCCESS
        jp EXIT_SUCCESS
 
 
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
; F_tbas_info
; F_tbas_info
; Handle the %info command
; Handle the %info command
F_tbas_info
.globl F_tbas_info
 
F_tbas_info:
        rst CALLBAS
        rst CALLBAS
        defw ZX_EXPT_EXP                ; expect a string
        defw ZX_EXPT_EXP                ; expect a string
        call STATEMENT_END
        call STATEMENT_END
 
 
        ;-------- runtime ----------
        ;-------- runtime ----------
Line 367... Line 382...
        jp EXIT_SUCCESS
        jp EXIT_SUCCESS
 
 
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
; F_tbas_fs
; F_tbas_fs
; Sets the current filesystem.
; Sets the current filesystem.
F_tbas_fs
.globl F_tbas_fs
 
F_tbas_fs:
        rst CALLBAS
        rst CALLBAS
        defw ZX_EXPT1_NUM               ; expect one number - the FS number
        defw ZX_EXPT1_NUM               ; expect one number - the FS number
        call STATEMENT_END
        call STATEMENT_END
 
 
        ;-------- runtime ----------
        ;-------- runtime ----------
Line 384... Line 400...
        jp J_tbas_error
        jp J_tbas_error
 
 
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
; F_loadsnap
; F_loadsnap
; Loads a snapshot file.
; Loads a snapshot file.
F_loadsnap
.globl F_loadsnap
 
F_loadsnap:
        rst CALLBAS
        rst CALLBAS
        defw ZX_EXPT_EXP                ; filename string
        defw ZX_EXPT_EXP                ; filename string
        call STATEMENT_END
        call STATEMENT_END
 
 
        ;---------- runtime -----------
        ;---------- runtime -----------
Line 402... Line 419...
        jp J_tbas_error                 ; If we get here, an error occurred
        jp J_tbas_error                 ; If we get here, an error occurred
 
 
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
; F_tbas_mv
; F_tbas_mv
; Moves (renames) a file.
; Moves (renames) a file.
F_tbas_mv
.globl F_tbas_mv
 
F_tbas_mv:
        rst CALLBAS
        rst CALLBAS
        defw ZX_EXPT_EXP                ; source filename
        defw ZX_EXPT_EXP                ; source filename
        cp ','                          ; and a comma
        cp ','                          ; and a comma
        jp nz, PARSE_ERROR
        jp nz, PARSE_ERROR
        rst CALLBAS
        rst CALLBAS
Line 431... Line 449...
        jp nc, EXIT_SUCCESS
        jp nc, EXIT_SUCCESS
        jp J_tbas_error
        jp J_tbas_error
 
 
;---------------------------------------------------------------------------
;---------------------------------------------------------------------------
; F_tbas_rm: Removes a file
; F_tbas_rm: Removes a file
F_tbas_rm
.globl F_tbas_rm
 
F_tbas_rm:
        rst CALLBAS
        rst CALLBAS
        defw ZX_EXPT_EXP                ; file to remove
        defw ZX_EXPT_EXP                ; file to remove
        call STATEMENT_END
        call STATEMENT_END
 
 
        ;-------- runtime ---------
        ;-------- runtime ---------
Line 450... Line 469...
 
 
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
; F_tbas_zxprint
; F_tbas_zxprint
; Prints a C string to the current ZX channel
; Prints a C string to the current ZX channel
; HL = pointer to string
; HL = pointer to string
F_tbas_zxprint
.globl F_tbas_zxprint
 
F_tbas_zxprint:
        ld a, (hl)
        ld a, (hl)
        and a
        and a
        ret z
        ret z
        rst CALLBAS
        rst CALLBAS
        defw 0x10
        defw 0x10
Line 462... Line 482...
        jr F_tbas_zxprint
        jr F_tbas_zxprint
 
 
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
; handle errors and return control to BASIC.
; handle errors and return control to BASIC.
; A=tnfs error number
; A=tnfs error number
J_tbas_error
.globl J_tbas_error
 
J_tbas_error:
        push af                         ; save error number
        push af                         ; save error number
        call F_geterrstr                ; get the error string
        call F_geterrstr                ; get the error string
        pop af
        pop af
        jp REPORTERR                    ; exit to BASIC with error string
        jp REPORTERR                    ; exit to BASIC with error string
 
 
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
; F_tnfs_geterrstr
; F_tnfs_geterrstr
; Enter with A=error number
; Enter with A=error number
; Exits with HL=pointer to null terminated error string
; Exits with HL=pointer to null terminated error string
F_geterrstr
.globl F_geterrstr
 
F_geterrstr:
        ld h, 0xFC              ; ID of messages module
        ld h, 0xFC              ; ID of messages module
        ld l, a                 ; Set the message ID to fetch
        ld l, a                 ; Set the message ID to fetch
        ld de, 0x3000           ; buffer
        ld de, 0x3000           ; buffer
        xor a
        xor a
        ld (de), a              ; initialize with a NULL
        ld (de), a              ; initialize with a NULL
        rst MODULECALL_NOPAGE
        rst MODULECALL_NOPAGE
        ld hl, 0x3000           ; address of the message
        ld hl, 0x3000           ; address of the message
        ret
        ret
 
.data
 
.globl STR_BOOTDOTZX
 
.globl STR_BOOTDOTZXLEN
 
STR_proto:      defb    "tnfs",0
 
STR_BOOTDOTZX:  defb    "boot.zx",0
 
STR_BOOTDOTZXEND:
 
 
STR_proto       defb    "tnfs",0
STR_BOOTDOTZXLEN equ    STR_BOOTDOTZXEND-STR_BOOTDOTZX
STR_BOOTDOTZX   defb    "boot.zx",0
 
STR_BOOTDOTZXLEN equ    $-STR_BOOTDOTZX
 
 
 
EBADURL         equ     0x28
EBADURL:                equ     0x28
EBADFS          equ     0x29
EBADFS:         equ     0x29