Subversion Repositories Spectranet

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

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

Rev 371 Rev 372
Line 20... Line 20...
;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.
 
 
;------------------------------------------------------------------------
;------------------------------------------------------------------------
; Handle user interaction for the snapshot manager.
; Handle user interaction for the snapshot manager.
 
.include        "spectranet.inc"
 
.include        "snapman.inc"
 
.include        "sysvars.inc"
 
 
; Create the user interface and enter the input loop.
; Create the user interface and enter the input loop.
F_startui
.globl F_startui
 
F_startui:
        call F_fetchpage
        call F_fetchpage
        jp c, F_nopage
        jp c, F_nopage
        call CLEAR42
        call CLEAR42
        xor a
        xor a
        ld (v_viewflags), a     ; reset view flags
        ld (v_viewflags), a     ; reset view flags
Line 41... Line 45...
        ld de, v_snatable       ; start with the snapshot view
        ld de, v_snatable       ; start with the snapshot view
        call F_makeselection
        call F_makeselection
 
 
;----------------------------------------------------------------------
;----------------------------------------------------------------------
; Main UI loop
; Main UI loop
F_mainloop
.globl F_mainloop
 
F_mainloop:
        call F_inputloop        ; call UI control input loop, wait for a key
        call F_inputloop        ; call UI control input loop, wait for a key
        ld b, a                 ; save the keypress in B
        ld b, a                 ; save the keypress in B
        ld c, 0                 ; use C as a counter
        ld c, 0                 ; use C as a counter
        ld hl, INPUTTABLE
        ld hl, INPUTTABLE
.getactionloop
.getactionloop2:
        ld a, (hl)
        ld a, (hl)
        and a                   ; check for "end of list"
        and a                   ; check for "end of list"
        jr z, F_mainloop        ; invalid key, ignore it
        jr z, F_mainloop        ; invalid key, ignore it
        cp b                    ; See if the key press is recognised.
        cp b                    ; See if the key press is recognised.
        jr z, .handlekey
        jr z,  .handlekey2
        inc c                   ; inc. counter
        inc c                   ; inc. counter
        inc hl
        inc hl
        jr .getactionloop
        jr  .getactionloop2
.handlekey
.handlekey2:
        rlc c                   ; double the counter to form the offset
        rlc c                   ; double the counter to form the offset
        ld b, 0                 ; in BC
        ld b, 0                 ; in BC
        ld hl, INPUTADDRS       ; Calculate the address of the address
        ld hl, INPUTADDRS       ; Calculate the address of the address
        add hl, bc              ; that we need to find
        add hl, bc              ; that we need to find
        ld e, (hl)              ; and get its LSB
        ld e, (hl)              ; and get its LSB
        inc hl
        inc hl
        ld d, (hl)              ; and MSB
        ld d, (hl)              ; and MSB
        ex de, hl               ; put it in hl
        ex de, hl               ; put it in hl
        ld de, .return
        ld de,  .return2
        push de                 ; effectively, we want to CALL (HL)
        push de                 ; effectively, we want to CALL (HL)
        jp (hl)
        jp (hl)
.return
.return2:
        ld a, (v_inputflags)
        ld a, (v_inputflags)
        bit 0, a                ; signal to leave?
        bit 0, a                ; signal to leave?
        jr z, F_mainloop        ; ...no, so continue
        jr z, F_mainloop        ; ...no, so continue
        res 0, a
        res 0, a
        ld (v_inputflags), a    ; reset the flag
        ld (v_inputflags), a    ; reset the flag
        jp F_leave              ; restore memory and leave
        jp F_leave              ; restore memory and leave
 
 
;------------------------------------------------------------------------
;------------------------------------------------------------------------
; F_exit
; F_exit
; Leave the main input loop, by setting the 'done' flag.
; Leave the main input loop, by setting the 'done' flag.
F_exit
.globl F_exit
 
F_exit:
        ld a, (v_inputflags)
        ld a, (v_inputflags)
        set 0, a
        set 0, a
        ld (v_inputflags), a
        ld (v_inputflags), a
        ret
        ret
 
 
;------------------------------------------------------------------------
;------------------------------------------------------------------------
; F_enterpressed
; F_enterpressed
F_enterpressed
.globl F_enterpressed
 
F_enterpressed:
        call F_getselected
        call F_getselected
        ret z                   ; nothing to do - no entries
        ret z                   ; nothing to do - no entries
        ld a, (v_viewflags)
        ld a, (v_viewflags)
        and 1                   ; bit 1 set - directory mode
        and 1                   ; bit 1 set - directory mode
        jr z, .loadsnap
        jr z,  .loadsnap4
        ld de, WORKSPACE        ; copy directory name to where the
        ld de, WORKSPACE        ; copy directory name to where the
        call F_strcpy           ; FS module will be able to see it
        call F_strcpy           ; FS module will be able to see it
        ld hl, WORKSPACE
        ld hl, WORKSPACE
        call CHDIR
        call CHDIR
        jp c, F_error
        jp c, F_error
Line 104... Line 111...
        ld hl, BOXSTARTADDR     ; start address of the box
        ld hl, BOXSTARTADDR     ; start address of the box
        ld bc, BOXDIMENSIONS    ; box dimensions
        ld bc, BOXDIMENSIONS    ; box dimensions
        ld de, v_dirtable
        ld de, v_dirtable
        ld a, (v_numdirs)
        ld a, (v_numdirs)
        jp F_makeselection      ; make the selection and return.
        jp F_makeselection      ; make the selection and return.
.loadsnap
.loadsnap4:
        ld de, WORKSPACE
        ld de, WORKSPACE
        push hl
        push hl
        call F_strcpy           ; copy the filename into common workspace
        call F_strcpy           ; copy the filename into common workspace
        pop hl
        pop hl
        ld de, v_curfilename    ; copy the filename to our "current file"
        ld de, v_curfilename    ; copy the filename to our "current file"
        call F_strcpy
        call F_strcpy
        ld hl, WORKSPACE        ; filename pointed to by HL
        ld hl, WORKSPACE        ; filename pointed to by HL
        call F_loadsnap         ; load the snapshot
        call F_loadsnap         ; load the snapshot
F_error                         ; ends up here if there is an error
.globl F_error
 
F_error:                        ; ends up here if there is an error
        ld a, 2
        ld a, 2
        out (254), a
        out (254), a
        ret
        ret
 
 
;------------------------------------------------------------------------
;------------------------------------------------------------------------
; F_saveas
; F_saveas
F_saveas
.globl F_saveas
 
F_saveas:
        ld hl, STR_filename
        ld hl, STR_filename
        ld de, v_strbuf
        ld de, v_strbuf
        ld c, FNAMESZ
        ld c, FNAMESZ
        call F_userinput
        call F_userinput
        ret z                   ; nothing entered, continue
        ret z                   ; nothing entered, continue
 
 
        ld de, v_curfilename    ; copy the string entered to the current
        ld de, v_curfilename    ; copy the string entered to the current
        ld hl, v_strbuf
        ld hl, v_strbuf
        call F_strcpy           ; filename.
        call F_strcpy           ; filename.
        ld hl, v_strbuf
        ld hl, v_strbuf
F_saveas2
.globl F_saveas2
 
F_saveas2:
        ld de, WORKSPACE        ; and copy it to the workspace
        ld de, WORKSPACE        ; and copy it to the workspace
        call F_strcpy           ; so the FS module can see it too
        call F_strcpy           ; so the FS module can see it too
        ld hl, WORKSPACE
        ld hl, WORKSPACE
        call F_savesna
        call F_savesna
        jp c, F_error
        jp c, F_error
Line 143... Line 153...
 
 
        ret
        ret
 
 
;------------------------------------------------------------------------
;------------------------------------------------------------------------
; F_save
; F_save
F_save
.globl F_save
 
F_save:
        ld a, (v_viewflags)     ; directory view or file view?
        ld a, (v_viewflags)     ; directory view or file view?
        and 1
        and 1
        jr nz, .needfilename
        jr nz,  .needfilename8
        call F_getselected
        call F_getselected
        jr z, F_saveas
        jr z, F_saveas
        ld (v_hlsave), hl       ; save the pointer but don't disturb stack
        ld (v_hlsave), hl       ; save the pointer but don't disturb stack
        ld de, v_curfilename
        ld de, v_curfilename
        call F_strcmp           ; selected = current?
        call F_strcmp           ; selected = current?
        jr nz, .confirm
        jr nz,  .confirm8
.save
.save8:
        ld hl, (v_hlsave)
        ld hl, (v_hlsave)
        jp F_saveas2
        jp F_saveas2
.confirm
.confirm8:
        ld hl, STR_cfoverwrite
        ld hl, STR_cfoverwrite
        ld de, v_strbuf
        ld de, v_strbuf
        ld c, 2
        ld c, 2
        call F_userinput
        call F_userinput
        ret z                   ; nothing entered, nothing to do
        ret z                   ; nothing entered, nothing to do
Line 168... Line 179...
        cp CHAR_YES
        cp CHAR_YES
        ret nz                  ; user didn't answer "yes"
        ret nz                  ; user didn't answer "yes"
        ld hl, (v_hlsave)
        ld hl, (v_hlsave)
        ld de, v_curfilename
        ld de, v_curfilename
        call F_strcpy           ; set this as the current file
        call F_strcpy           ; set this as the current file
        jr .save
        jr  .save8
.needfilename
.needfilename8:
        ld a, (v_curfilename)   ; Already have a filename?
        ld a, (v_curfilename)   ; Already have a filename?
        and a                   ; if zero, no
        and a                   ; if zero, no
        jr z, F_saveas
        jr z, F_saveas
 
 
;------------------------------------------------------------------------
;------------------------------------------------------------------------
; F_userinput
; F_userinput
; HL = pointer to prompt string
; HL = pointer to prompt string
; DE = pointer to buffer in which to return the data
; DE = pointer to buffer in which to return the data
;  C = size of input buffer
;  C = size of input buffer
F_userinput
.globl F_userinput
 
F_userinput:
        push bc
        push bc
        push hl
        push hl
        ld bc, 0x1600           ; line 24, col 0
        ld bc, 0x1600           ; line 24, col 0
        call F_printat          ; HL now is the address of the line
        call F_printat          ; HL now is the address of the line
        pop hl                  ; prompt to print
        pop hl                  ; prompt to print
Line 201... Line 213...
        ret
        ret
 
 
;----------------------------------------------------------------------
;----------------------------------------------------------------------
; F_rename
; F_rename
; Renames a snapshot file.
; Renames a snapshot file.
F_rename
.globl F_rename
 
F_rename:
        ld a, (v_viewflags)     ; check we are in snapshot view
        ld a, (v_viewflags)     ; check we are in snapshot view
        rra                     ; if LSB = 1 we are in directory view
        rra                     ; if LSB = 1 we are in directory view
        ret c                   ; so leave.
        ret c                   ; so leave.
 
 
        call F_getselected
        call F_getselected
Line 239... Line 252...
        jp F_snapview           ; and update the window
        jp F_snapview           ; and update the window
 
 
;----------------------------------------------------------------------
;----------------------------------------------------------------------
; F_erase
; F_erase
; Erases a snapshot file.
; Erases a snapshot file.
F_erase
.globl F_erase
 
F_erase:
        ld a, (v_viewflags)     ; check we are in snapshot view
        ld a, (v_viewflags)     ; check we are in snapshot view
        rra                     ; if LSB = 1 we are in directory view
        rra                     ; if LSB = 1 we are in directory view
        ret c                   ; so leave.
        ret c                   ; so leave.
 
 
        call F_getselected
        call F_getselected
Line 275... Line 289...
        jp F_snapview           ; update the UI
        jp F_snapview           ; update the UI
 
 
;----------------------------------------------------------------------
;----------------------------------------------------------------------
; F_switchdirview
; F_switchdirview
; Switch between directory and file views.
; Switch between directory and file views.
F_switchdirview
.globl F_switchdirview
 
F_switchdirview:
        ld a, (v_viewflags)
        ld a, (v_viewflags)
        xor 1                   ; flip "dir view" bit
        xor 1                   ; flip "dir view" bit
        ld (v_viewflags), a     ; and save
        ld (v_viewflags), a     ; and save
        rra                     ; push lsb into the carry flag
        rra                     ; push lsb into the carry flag
        jr c, showdir           ; switch from file to dir view
        jr c, showdir           ; switch from file to dir view
F_snapview
.globl F_snapview
 
F_snapview:
        ld de, v_snatable
        ld de, v_snatable
        ld a, (v_numsnas)
        ld a, (v_numsnas)
makesel
makesel:
        ld hl, BOXSTARTADDR     ; start address of the box
        ld hl, BOXSTARTADDR     ; start address of the box
        ld bc, BOXDIMENSIONS    ; box dimensions
        ld bc, BOXDIMENSIONS    ; box dimensions
        jp F_makeselection      ; make the selection and return.
        jp F_makeselection      ; make the selection and return.
showdir
showdir:
        ld de, v_dirtable
        ld de, v_dirtable
        ld a, (v_numdirs)
        ld a, (v_numdirs)
        jr makesel
        jr makesel
 
 
; We end up here if the allocated page wasn't found.
; We end up here if the allocated page wasn't found.
F_nopage
.globl F_nopage
 
F_nopage:
        ld hl, STR_nomempage
        ld hl, STR_nomempage
        call PRINT42
        call PRINT42
        ret
        ret