Subversion Repositories Spectranet

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

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

Rev 371 Rev 372
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        "ctrlchars.inc"
 
.include        "spectranet.inc"
 
.include        "snapman.inc"
 
.include        "sysvars.inc"
 
 
;------------------------------------------------------------------------
;------------------------------------------------------------------------
; F_makeselection
; F_makeselection
; HL = start address of box
; HL = start address of box
; B = number of lines the box has
; B = number of lines the box has
; C = maximum column number (32 cols)
; C = maximum column number (32 cols)
; DE = address of first item to show
; DE = address of first item to show
F_makeselection
.globl F_makeselection
 
F_makeselection:
        ld (v_selstart), hl     ; initialize variables
        ld (v_selstart), hl     ; initialize variables
        ld (v_maxcolumn), bc
        ld (v_maxcolumn), bc
        ld (v_stringtable), de
        ld (v_stringtable), de
        ld (v_numitems), a
        ld (v_numitems), a
 
 
Line 47... Line 52...
        sra a                   ; divide by four
        sra a                   ; divide by four
        sra a
        sra a
        add a, b                ; and add to the number of 8 px columns
        add a, b                ; and add to the number of 8 px columns
        inc a
        inc a
        ld (v_42colsperln),a    ; then save.
        ld (v_42colsperln),a    ; then save.
F_reinitselection
.globl F_reinitselection
 
F_reinitselection:
        call F_clearattrs
        call F_clearattrs
        call F_cleararea        ; clear the box
        call F_cleararea        ; clear the box
        ld hl, (v_selstart)
        ld hl, (v_selstart)
        ld de, (v_stringtable)
        ld de, (v_stringtable)
        call F_puttext          ; Fill the box with text.
        call F_puttext          ; Fill the box with text.
Line 75... Line 81...
;------------------------------------------------------------------------
;------------------------------------------------------------------------
; F_cprint
; F_cprint
; Constrained print routine. Print from the start column to the maximum
; Constrained print routine. Print from the start column to the maximum
; column or until NULL, whichever is earliest.
; column or until NULL, whichever is earliest.
; HL = pointer to string
; HL = pointer to string
F_cprint
.globl F_cprint
 
F_cprint:
        xor a
        xor a
        ld (v_rowcount), a      ; prevent 42 col routine scroll
        ld (v_rowcount), a      ; prevent 42 col routine scroll
        ld a, (v_startcolumn)   ; get the 32 column position and
        ld a, (v_startcolumn)   ; get the 32 column position and
        ld b, a                 ; convert it to a 42 column start
        ld b, a                 ; convert it to a 42 column start
        sra a
        sra a
        sra a
        sra a
        inc a
        inc a
        add a, b
        add a, b
        ld (v_column), a        ; set Spectranet 42 col print routine col
        ld (v_column), a        ; set Spectranet 42 col print routine col
        ld b, 0
        ld b, 0
.loop
.loop3:
        ld a, (hl)
        ld a, (hl)
        and a
        and a
        jr z, .cr
        jr z,  .cr3
        call PUTCHAR42
        call PUTCHAR42
        inc hl
        inc hl
        inc b                   ; increment 'columns printed so far'
        inc b                   ; increment 'columns printed so far'
        ld a, (v_42colsperln)
        ld a, (v_42colsperln)
        cp b                    ; reached the limit?
        cp b                    ; reached the limit?
        jr nz, .loop
        jr nz,  .loop3
.cr
.cr3:
        ld a, '\n'
        ld a, NEWLINE
        call PUTCHAR42
        call PUTCHAR42
        ret
        ret
 
 
;------------------------------------------------------------------------
;------------------------------------------------------------------------
; F_bytesperline
; F_bytesperline
; Calculates bytes per line. HL = start address of the line.
; Calculates bytes per line. HL = start address of the line.
F_bytesperline
.globl F_bytesperline
 
F_bytesperline:
        push bc
        push bc
        ld a, l
        ld a, l
        and 0x1F
        and 0x1F
        ld b, a
        ld b, a
        ld a, (v_maxcolumn)
        ld a, (v_maxcolumn)
Line 123... Line 131...
; F_scrollarea
; F_scrollarea
; Scroll an area of the screen.
; Scroll an area of the screen.
; HL = pointer to first line to scroll
; HL = pointer to first line to scroll
; B = number of lines to scroll
; B = number of lines to scroll
; C = 0 = scroll normal way, nonzero scroll reverse
; C = 0 = scroll normal way, nonzero scroll reverse
F_scrollforward
.globl F_scrollforward
 
F_scrollforward:
        push bc                 ; save counter
        push bc                 ; save counter
        call .advance           ; advance one line (need to scroll
        call  .advance5         ; advance one line (need to scroll
        push hl                 ; box size minus 1)
        push hl                 ; box size minus 1)
        jr z, .moveloopthird
        jr z,  .moveloopthird5
.moveloop
.moveloop5:
        push bc                 ; save line counter
        push bc                 ; save line counter
        ld a, l
        ld a, l
        sub 32                  ; address of next line up
        sub 32                  ; address of next line up
        ld d, h
        ld d, h
        ld e, a
        ld e, a
Line 140... Line 149...
        ld bc, (v_movebytes)
        ld bc, (v_movebytes)
        ldir
        ldir
        pop hl
        pop hl
        inc h
        inc h
        pop bc
        pop bc
        djnz .moveloop
        djnz  .moveloop5
.nextline
.nextline5:
        pop hl
        pop hl
        pop af                  ; get counter
        pop af                  ; get counter
        dec a
        dec a
        ret z                   ; all lines scrolled
        ret z                   ; all lines scrolled
 
 
        push af                 ; save counter
        push af                 ; save counter
        call .advance
        call  .advance5
        push hl
        push hl
        jr nz, .moveloop
        jr nz,  .moveloop5
 
 
.moveloopthird
.moveloopthird5:
        push bc
        push bc
        ld a, l
        ld a, l
        or 0xE0                 ; set top 3 bits of LSB
        or 0xE0                 ; set top 3 bits of LSB
        ld e, a
        ld e, a
        ld a, h
        ld a, h
Line 166... Line 175...
        ld bc, (v_movebytes)
        ld bc, (v_movebytes)
        ldir
        ldir
        pop hl
        pop hl
        inc h
        inc h
        pop bc
        pop bc
        djnz .moveloopthird
        djnz  .moveloopthird5
        jr .nextline
        jr  .nextline5
 
 
.advance
.advance5:
        ld a, l
        ld a, l
        and 0xE0
        and 0xE0
        cp 0xE0                 ; about to go into the next third?
        cp 0xE0                 ; about to go into the next third?
        jr z, .nnextthird
        jr z,  .nnextthird5
        ld a, 32
        ld a, 32
        add a, l                ; next line
        add a, l                ; next line
        ld l, a
        ld l, a
        ld b, 8                 ; number of iterations per line
        ld b, 8                 ; number of iterations per line
        ret
        ret
.nnextthird
.nnextthird5:
        ld a, l
        ld a, l
        and 0x1F                ; clear 3 most significant bits
        and 0x1F                ; clear 3 most significant bits
        ld l, a                 ; set LSB of pointer
        ld l, a                 ; set LSB of pointer
        ld a, h
        ld a, h
        add 8
        add a, 8
        ld h, a                 ; set MSB of pointer
        ld h, a                 ; set MSB of pointer
        ld b, 8                 ; move 8 lines
        ld b, 8                 ; move 8 lines
        xor a
        xor a
        ret
        ret
 
 
F_scrollreverse
.globl F_scrollreverse
 
F_scrollreverse:
        dec b
        dec b
        push bc
        push bc
        call .retreat           ; up one line, scroll box size - 1
        call  .retreat6         ; up one line, scroll box size - 1
        push hl
        push hl
        jr z, .nextthird
        jr z,  .nextthird6
.moveloop
.moveloop6:
        push bc
        push bc
        ld a, 32
        ld a, 32
        add a, l                ; calculate next line
        add a, l                ; calculate next line
        ld e, a
        ld e, a
        ld d, h                 ; de is now pointer to next line
        ld d, h                 ; de is now pointer to next line
Line 208... Line 218...
        ld bc, (v_movebytes)
        ld bc, (v_movebytes)
        ldir
        ldir
        pop hl
        pop hl
        inc h
        inc h
        pop bc
        pop bc
        djnz .moveloop
        djnz  .moveloop6
.nextline
.nextline6:
        pop hl
        pop hl
        pop af
        pop af
        dec a                   ; decrement line counter
        dec a                   ; decrement line counter
        ret z                   ; and leave if we've finished all lines
        ret z                   ; and leave if we've finished all lines
 
 
        push af                 ; store counter
        push af                 ; store counter
        call .retreat
        call  .retreat6
        push hl
        push hl
        jr nz, .moveloop
        jr nz,  .moveloop6
 
 
.moveloopthird
.moveloopthird6:
        push bc
        push bc
        ld a, l
        ld a, l
        and 0x1F                ; clear 3 bits of LSB
        and 0x1F                ; clear 3 bits of LSB
        ld e, a
        ld e, a
        ld a, h
        ld a, h
        add 0x08                ; add 0x08 to the MSB of copy to pointer
        add a, 0x08             ; add 0x08 to the MSB of copy to pointer
        ld d, a                 ; DE now equals address of next row
        ld d, a                 ; DE now equals address of next row
        push hl
        push hl
        ld bc, (v_movebytes)
        ld bc, (v_movebytes)
        ldir
        ldir
        pop hl
        pop hl
        inc h
        inc h
        pop bc
        pop bc
        djnz .moveloopthird
        djnz  .moveloopthird6
        jr .nextline
        jr  .nextline6
 
 
.retreat
.retreat6:
        ld a, l                 ; about to cross a third boundary?
        ld a, l                 ; about to cross a third boundary?
        and 0xE0
        and 0xE0
        jr z, .nextthird
        jr z,  .nextthird6
        ld a, l
        ld a, l
        sub 32                  ; move up a line
        sub 32                  ; move up a line
        ld l, a
        ld l, a
        ld b, 8
        ld b, 8
        ret
        ret
.nextthird
.nextthird6:
        ld a, l
        ld a, l
        or 0xE0                 ; set top 3 bits of the pointer
        or 0xE0                 ; set top 3 bits of the pointer
        ld l, a                 ; set LSB of pointer
        ld l, a                 ; set LSB of pointer
        ld a, h
        ld a, h
        sub 8
        sub 8
Line 261... Line 271...
 
 
;--------------------------------------------------------------------------
;--------------------------------------------------------------------------
; F_cleararea: Clears a defined area.
; F_cleararea: Clears a defined area.
; HL = Start address
; HL = Start address
; B = Number of lines to clear
; B = Number of lines to clear
F_cleararea
.globl F_cleararea
 
F_cleararea:
        ld hl, (v_selstart)     ; start of area
        ld hl, (v_selstart)     ; start of area
        ld bc, (v_maxcolumn)    ; counter into B
        ld bc, (v_maxcolumn)    ; counter into B
        push bc                 ; save counter
        push bc                 ; save counter
        push hl
        push hl
        ld b, 8                 ; clear 8 scanlines
        ld b, 8                 ; clear 8 scanlines
.clearloop
.clearloop7:
        push bc                 ; save line counter
        push bc                 ; save line counter
        ld d, h
        ld d, h
        ld e, l
        ld e, l
        inc e
        inc e
        push hl
        push hl
Line 281... Line 292...
        ld (hl), a
        ld (hl), a
        ldir
        ldir
        pop hl
        pop hl
        inc h
        inc h
        pop bc                  ; retrieve counter
        pop bc                  ; retrieve counter
        djnz .clearloop
        djnz  .clearloop7
.nextline
.nextline7:
        pop hl
        pop hl
        pop af                  ; get counter
        pop af                  ; get counter
        dec a
        dec a
        jr z, .savelastline     ; all lines cleared
        jr z,  .savelastline7   ; all lines cleared
 
 
        push af                 ; save counter
        push af                 ; save counter
        ld a, l
        ld a, l
        and 0xE0
        and 0xE0
        cp 0xE0                 ; about to go into the next third?
        cp 0xE0                 ; about to go into the next third?
        jr z, .nextthird
        jr z,  .nextthird7
        ld a, 32
        ld a, 32
        add a, l                ; next line
        add a, l                ; next line
        ld l, a
        ld l, a
        push hl
        push hl
        ld b, 8                 ; number of iterations per line
        ld b, 8                 ; number of iterations per line
        jr .clearloop
        jr  .clearloop7
 
 
.nextthird
.nextthird7:
        ld a, l
        ld a, l
        and 0x1F                ; clear 3 most significant bits
        and 0x1F                ; clear 3 most significant bits
        ld l, a                 ; set LSB of pointer
        ld l, a                 ; set LSB of pointer
        ld a, h
        ld a, h
        add 8
        add a, 8
        ld h, a                 ; set MSB of pointer
        ld h, a                 ; set MSB of pointer
        push hl                 ; save HL
        push hl                 ; save HL
        ld b, 8                 ; move 8 lines
        ld b, 8                 ; move 8 lines
        jr .clearloop
        jr  .clearloop7
 
 
.savelastline
.savelastline7:
        ld (v_selend), hl       ; save the bottom row address
        ld (v_selend), hl       ; save the bottom row address
        ret
        ret
 
 
;------------------------------------------------------------------------
;------------------------------------------------------------------------
; F_clearline
; F_clearline
; Clears a line. HL = start address.
; Clears a line. HL = start address.
F_clearline
.globl F_clearline
 
F_clearline:
        ld bc, (v_movebytes)    ; put current box width in
        ld bc, (v_movebytes)    ; put current box width in
 
 
; ...clears a line BC bytes long.
; ...clears a line BC bytes long.
F_clearline2
.globl F_clearline2
 
F_clearline2:
        ld (v_clearbytes), bc   ; our "how much to clear" var.
        ld (v_clearbytes), bc   ; our "how much to clear" var.
        ld b, 8
        ld b, 8
.clearloop
.clearloop9:
        push bc
        push bc
        ld d, h
        ld d, h
        ld e, l
        ld e, l
        inc e
        inc e
        push hl
        push hl
Line 339... Line 352...
        ld (hl), a
        ld (hl), a
        ldir
        ldir
        pop hl
        pop hl
        inc h
        inc h
        pop bc
        pop bc
        djnz .clearloop
        djnz  .clearloop9
        ret
        ret
 
 
;------------------------------------------------------------------------
;------------------------------------------------------------------------
; F_movebar
; F_movebar
; Moves selection bar down.
; Moves selection bar down.
; A = 0 - move bar down
; A = 0 - move bar down
; Otherwise, it moves up.
; Otherwise, it moves up.
F_movebar
.globl F_movebar
 
F_movebar:
        call F_clearbar
        call F_clearbar
        ld de, 32               ; Next row
        ld de, 32               ; Next row
        and a                   ; Is A = 0?
        and a                   ; Is A = 0?
        jr z, .down
        jr z,  .down10
        sbc hl, de
        sbc hl, de
        jr .move
        jr  .move10
.down
.down10:
        add hl, de
        add hl, de
.move
.move10:
        ld (v_baraddr), hl      ; Save the new row pointer
        ld (v_baraddr), hl      ; Save the new row pointer
F_putbar_impl
.globl F_putbar_impl
 
F_putbar_impl:
        ld d, h
        ld d, h
        ld e, l
        ld e, l
        inc e
        inc e
        ld a, (v_barlen)
        ld a, (v_barlen)
        ld c, a
        ld c, a
        ld b, 0
        ld b, 0
        ld (hl), SELECTED_ATTR  ; Colour to draw
        ld (hl), SELECTED_ATTR  ; Colour to draw
        ldir
        ldir
        ret
        ret
F_clearbar
.globl F_clearbar
 
F_clearbar:
        ld hl, (v_baraddr)      ; current start address of bar
        ld hl, (v_baraddr)      ; current start address of bar
F_clearbar2
.globl F_clearbar2
 
F_clearbar2:
        push af
        push af
        ld a, (v_barlen)        ; how long the bar is
        ld a, (v_barlen)        ; how long the bar is
        ld b, 0
        ld b, 0
        ld c, a
        ld c, a
        ld d, h
        ld d, h
Line 388... Line 405...
        ret
        ret
 
 
;------------------------------------------------------------------------
;------------------------------------------------------------------------
; F_putbar
; F_putbar
; Draws the bar at the current start address.
; Draws the bar at the current start address.
F_putbar
.globl F_putbar
 
F_putbar:
        ld hl, (v_baraddr)
        ld hl, (v_baraddr)
        ld a, (v_barlen)
        ld a, (v_barlen)
        jp F_putbar_impl
        jp F_putbar_impl
 
 
;------------------------------------------------------------------------
;------------------------------------------------------------------------
; F_fbuf2attr
; F_fbuf2attr
; Convert pixel buffer addresses to attribute addresses
; Convert pixel buffer addresses to attribute addresses
F_fbuf2attr
.globl F_fbuf2attr
 
F_fbuf2attr:
        ld a, l                 ; get LSB of frame buffer address
        ld a, l                 ; get LSB of frame buffer address
        and 0xE0                ; mask out bottom bits
        and 0xE0                ; mask out bottom bits
        rlca                    ; and move to lowest 3 bits
        rlca                    ; and move to lowest 3 bits
        rlca
        rlca
        rlca
        rlca
Line 425... Line 444...
        ret
        ret
 
 
;------------------------------------------------------------------------
;------------------------------------------------------------------------
; F_clearattrs
; F_clearattrs
; Clears the entire background area
; Clears the entire background area
F_clearattrs
.globl F_clearattrs
 
F_clearattrs:
        ld hl, (v_selstart)
        ld hl, (v_selstart)
        call F_fbuf2attr
        call F_fbuf2attr
        ld a, (v_sellines)
        ld a, (v_sellines)
.clearloop
.clearloop16:
        push hl
        push hl
        call F_clearbar2
        call F_clearbar2
        ld bc, 32
        ld bc, 32
        pop hl
        pop hl
        add hl, bc
        add hl, bc
        dec a
        dec a
        and a
        and a
        jr nz, .clearloop
        jr nz,  .clearloop16
        ret
        ret
 
 
;------------------------------------------------------------------------
;------------------------------------------------------------------------
; F_inputloop
; F_inputloop
; Deal with keyboard input.
; Deal with keyboard input.
F_inputloop
.globl F_inputloop
.inputloop
F_inputloop:
 
.inputloop17:
        call GETKEY             ; get the actual key
        call GETKEY             ; get the actual key
        ld hl, 0x1000           ; wait some more time so that
        ld hl, 0x1000           ; wait some more time so that
.loop                           ; multi key contacts on Spectrum + / 128
.loop17:                           ; multi key contacts on Spectrum + / 128
        dec hl                  ; membranes all make. Use a delay loop
        dec hl                  ; membranes all make. Use a delay loop
        ld a, h                 ; rather than halt so this routine works
        ld a, h                 ; rather than halt so this routine works
        or l                    ; with interrupts disabled.
        or l                    ; with interrupts disabled.
        jr nz, .loop
        jr nz,  .loop17
 
 
        call GETKEY             ; to close all the contacts...
        call GETKEY             ; to close all the contacts...
        push af                 ; save it
        push af                 ; save it
        call KEYUP              ; and wait for keyup
        call KEYUP              ; and wait for keyup
        pop af
        pop af
        cp 0x0A                 ; KEY_DOWN
        cp 0x0A                 ; KEY_DOWN
        jr z, .bardown
        jr z,  .bardown17
        cp 0x0B                 ; KEY_UP
        cp 0x0B                 ; KEY_UP
        jr z, .barup
        jr z,  .barup17
        ret
        ret
.bardown
.bardown17:
        ld a, (v_sellines)      ; hit the bottom?
        ld a, (v_sellines)      ; hit the bottom?
        dec a                   ; convert to 'index'
        dec a                   ; convert to 'index'
        ld b, a
        ld b, a
        ld a, (v_barpos)
        ld a, (v_barpos)
        cp b
        cp b
        jr z, .scrolldown
        jr z,  .scrolldown17
        ld a, (v_numitems)      ; check we're not at the end
        ld a, (v_numitems)      ; check we're not at the end
        and a
        and a
        jr z, .inputloop        ; no items
        jr z,  .inputloop17     ; no items
        dec a
        dec a
        ld b, a
        ld b, a
        ld a, (v_selecteditem)
        ld a, (v_selecteditem)
        cp b
        cp b
        jr z, .inputloop        ; selection is at the end
        jr z,  .inputloop17     ; selection is at the end
        inc a                   ; increment selection
        inc a                   ; increment selection
        ld (v_selecteditem), a
        ld (v_selecteditem), a
        ld a, (v_barpos)
        ld a, (v_barpos)
        inc a
        inc a
        ld (v_barpos), a        ; update position
        ld (v_barpos), a        ; update position
        xor a
        xor a
        call F_movebar
        call F_movebar
        jr .inputloop
        jr  .inputloop17
.barup
.barup17:
        ld a, (v_barpos)
        ld a, (v_barpos)
        and a
        and a
        jr z, .scrollup
        jr z,  .scrollup17
        dec a
        dec a
        ld (v_barpos), a
        ld (v_barpos), a
        ld a, (v_selecteditem)  ; decrement the selected item index
        ld a, (v_selecteditem)  ; decrement the selected item index
        dec a
        dec a
        ld (v_selecteditem), a
        ld (v_selecteditem), a
        inc a                   ; ensure A is nonzero
        inc a                   ; ensure A is nonzero
        call F_movebar
        call F_movebar
        jr .inputloop
        jr  .inputloop17
 
 
 
 
.scrolldown
.scrolldown17:
        ld a, (v_numitems)
        ld a, (v_numitems)
        and a
        and a
        jr z, .inputloop        ; no items
        jr z,  .inputloop17     ; no items
        dec a
        dec a
        ld b, a                 ; compare the last item index
        ld b, a                 ; compare the last item index
        ld a, (v_selecteditem)  ; with the current
        ld a, (v_selecteditem)  ; with the current
        cp b
        cp b
        jr z, .inputloop        ; already at the last item
        jr z,  .inputloop17     ; already at the last item
        ld a, (v_selecteditem)  ; Increment the selected item index.
        ld a, (v_selecteditem)  ; Increment the selected item index.
        inc a
        inc a
        ld (v_selecteditem), a
        ld (v_selecteditem), a
        rlca                    ; double it to calculate
        rlca                    ; double it to calculate
        ld d, 0                 ; the pointer table address
        ld d, 0                 ; the pointer table address
Line 534... Line 555...
        and 0xE0                ; mask out bottom bits
        and 0xE0                ; mask out bottom bits
        ld l, a
        ld l, a
        ld (v_row), hl          ; set print routine to bottom line row
        ld (v_row), hl          ; set print routine to bottom line row
        pop hl                  ; now get the string back
        pop hl                  ; now get the string back
        call F_cprint
        call F_cprint
        jp .inputloop
        jp  .inputloop17
 
 
.scrollup
.scrollup17:
        ld a, (v_selecteditem)  ; check we've not hit zero
        ld a, (v_selecteditem)  ; check we've not hit zero
        and a
        and a
        jp z, .inputloop
        jp z,  .inputloop17
        dec a
        dec a
        ld (v_selecteditem), a  ; update the selected item
        ld (v_selecteditem), a  ; update the selected item
        ld hl, (v_stringtable)  ; string table start address
        ld hl, (v_stringtable)  ; string table start address
        rlca                    ; double A
        rlca                    ; double A
        ld d, 0
        ld d, 0
Line 565... Line 586...
        and 0xE0                ; mask out bottom 5 bits
        and 0xE0                ; mask out bottom 5 bits
        ld l, a
        ld l, a
        ld (v_row), hl          ; set the print routine's row address
        ld (v_row), hl          ; set the print routine's row address
        pop hl                  ; get the string pointer
        pop hl                  ; get the string pointer
        call F_cprint
        call F_cprint
        jp .inputloop
        jp  .inputloop17
 
 
;--------------------------------------------------------------------------
;--------------------------------------------------------------------------
; F_setbarloc
; F_setbarloc
; Sets the bar location to a determined point in the list (which must
; Sets the bar location to a determined point in the list (which must
; already be initialized, along with the selection box)
; already be initialized, along with the selection box)
; A = index of string to select
; A = index of string to select
F_setbarloc
.globl F_setbarloc
 
F_setbarloc:
        ld b, a                 ; save 'goto' location
        ld b, a                 ; save 'goto' location
 
 
        ; first find out whether the bar is going to remain within
        ; first find out whether the bar is going to remain within
        ; what can be seen already.
        ; what can be seen already.
        ld hl, v_sellines
        ld hl, v_sellines
Line 586... Line 608...
        sub c                   ; subtract the current bar position
        sub c                   ; subtract the current bar position
        ld c, a                 ; save this value
        ld c, a                 ; save this value
        ld a, (v_selecteditem)  ; get the selected item index
        ld a, (v_selecteditem)  ; get the selected item index
        add a, c                ; and calculate the index of the bottom item
        add a, c                ; and calculate the index of the bottom item
        cp b                    ; Is the request for an item past what
        cp b                    ; Is the request for an item past what
        jr c, .newselection     ; we can see on the screen?
        jr c,  .newselection18  ; we can see on the screen?
        jr z, .newselection
        jr z,  .newselection18
        ld c, (hl)              ; get the number of lines in the box
        ld c, (hl)              ; get the number of lines in the box
        sub c                   ; and calculate index of top item
        sub c                   ; and calculate index of top item
        cp b                    ; is out of bounds low.
        cp b                    ; is out of bounds low.
        jr c, .movebar
        jr c,  .movebar18
 
 
.newselection
.newselection18:
        push bc                 ; save desired index
        push bc                 ; save desired index
        call F_cleararea        ; clear the box ready to repaint it
        call F_cleararea        ; clear the box ready to repaint it
        ld hl, (v_stringtable)  ; calculate new position in the string
        ld hl, (v_stringtable)  ; calculate new position in the string
        pop bc
        pop bc
        ld a, b
        ld a, b
Line 610... Line 632...
        ld hl, (v_selstart)     ; first line of selection box
        ld hl, (v_selstart)     ; first line of selection box
        call F_puttext
        call F_puttext
        xor a                   ; move bar to the top
        xor a                   ; move bar to the top
        jp F_putbarat           ; (only need this if putbarat is moved)
        jp F_putbarat           ; (only need this if putbarat is moved)
 
 
.movebar
.movebar18:
        ; The item is actually visible already - select it.
        ; The item is actually visible already - select it.
        ld c, a                 ; then calculate where the bar actually
        ld c, a                 ; then calculate where the bar actually
        ld a, b                 ; should be relative to the top
        ld a, b                 ; should be relative to the top
        sub c                   ; of the box.
        sub c                   ; of the box.
        ld hl, v_selecteditem   ; save the selected item
        ld hl, v_selecteditem   ; save the selected item
        ld (hl), b
        ld (hl), b
;       jp F_putbarat           ; and move the bar to its proper place.
;       jp F_putbarat           ; and move the bar to its proper place.
 
 
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
; F_putbarat: Draws the bar at the specified relative location in A
; F_putbarat: Draws the bar at the specified relative location in A
F_putbarat
.globl F_putbarat
 
F_putbarat:
        call F_clearbar         ; clear the existing bar
        call F_clearbar         ; clear the existing bar
 
 
        ld (v_barpos), a        ; save the bar position
        ld (v_barpos), a        ; save the bar position
        ld l, a                 ; get the offset by
        ld l, a                 ; get the offset by
        ld h, 0
        ld h, 0
Line 643... Line 666...
;--------------------------------------------------------------------------
;--------------------------------------------------------------------------
; F_puttext
; F_puttext
; Puts the text in the selection box.
; Puts the text in the selection box.
; HL = address of first character cell
; HL = address of first character cell
; DE = pointer to the first item in the string table to print
; DE = pointer to the first item in the string table to print
F_puttext
.globl F_puttext
 
F_puttext:
        ld a, l                 ; Initialize the position of the 42 col
        ld a, l                 ; Initialize the position of the 42 col
        and 0xE0                ; print routine to the top of the box.
        and 0xE0                ; print routine to the top of the box.
        ld l, a
        ld l, a
        ld (v_row), hl          ; Spectranet sysvar
        ld (v_row), hl          ; Spectranet sysvar
 
 
        ex de, hl               ; get first item to print
        ex de, hl               ; get first item to print
        ld a, (v_sellines)      ; number of lines we can fit
        ld a, (v_sellines)      ; number of lines we can fit
        ld b, a
        ld b, a
.printloop
.printloop20:
        ld e, (hl)              ; low order of string lookup
        ld e, (hl)              ; low order of string lookup
        inc hl
        inc hl
        ld d, (hl)              ; high order of string lookup
        ld d, (hl)              ; high order of string lookup
        inc hl
        inc hl
        ld a, d
        ld a, d
Line 667... Line 691...
        push bc                 ; save counter
        push bc                 ; save counter
        call F_cprint           ; print the string
        call F_cprint           ; print the string
        pop bc
        pop bc
        pop de
        pop de
        ex de, hl
        ex de, hl
        djnz .printloop
        djnz  .printloop20
        ret
        ret
 
 
;--------------------------------------------------------------------------
;--------------------------------------------------------------------------
; F_getselected
; F_getselected
; Returns a pointer to the selected item in HL
; Returns a pointer to the selected item in HL
F_getselected
.globl F_getselected
 
F_getselected:
        ld a, (v_numitems)      ; check there's something there
        ld a, (v_numitems)      ; check there's something there
        and a
        and a
        ret z                   ; if nothing return with Z set
        ret z                   ; if nothing return with Z set
        ld hl, (v_stringtable)  ; start address of the current string table
        ld hl, (v_stringtable)  ; start address of the current string table
        ld a, (v_selecteditem)  ; get what's under the selection
        ld a, (v_selecteditem)  ; get what's under the selection
Line 692... Line 717...
        ret
        ret
 
 
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
; F_addstring
; F_addstring
; Adds a string to the selection
; Adds a string to the selection
F_addstring
.globl F_addstring
 
F_addstring:
        push hl                 ; save pointer
        push hl                 ; save pointer
        ld a, (v_numitems)      ; Make room in the string table
        ld a, (v_numitems)      ; Make room in the string table
        cp 0x7F                 ; but make sure there is room.
        cp 0x7F                 ; but make sure there is room.
        jr z, .noroom
        jr z,  .noroom22
        rlca                    ; - find the last entry
        rlca                    ; - find the last entry
 
 
        ld hl, (v_stringtable)
        ld hl, (v_stringtable)
        ld d, 0
        ld d, 0
        ld e, a
        ld e, a
Line 726... Line 752...
        ld (hl), a              ; put the null on the end
        ld (hl), a              ; put the null on the end
        inc hl
        inc hl
        ld (hl), a
        ld (hl), a
 
 
        pop hl                  ; get string pointer
        pop hl                  ; get string pointer
.strcpy
.strcpy22:
        ld a, (hl)
        ld a, (hl)
        ld (de), a
        ld (de), a
        and a
        and a
        jr z, .redraw
        jr z,  .redraw22
        inc hl
        inc hl
        inc de
        inc de
        jr .strcpy
        jr  .strcpy22
.redraw
.redraw22:
        ld a, (v_numitems)
        ld a, (v_numitems)
        inc a
        inc a
        ld (v_numitems), a      ; update last item index
        ld (v_numitems), a      ; update last item index
        call F_reinitselection  ; TODO - just repaint the end
        call F_reinitselection  ; TODO - just repaint the end
        ld a, (v_numitems)
        ld a, (v_numitems)
        dec a
        dec a
        call F_setbarloc
        call F_setbarloc
        ret
        ret
 
 
.noroom
.noroom22:
        pop hl
        pop hl
        scf
        scf
        ret
        ret
 
 
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
; F_printat: Move PRINT42 location.
; F_printat: Move PRINT42 location.
; B = row
; B = row
; C = column
; C = column
F_printat
.globl F_printat
 
F_printat:
        ld a, b
        ld a, b
        and 0x18                ; find the third of the screen
        and 0x18                ; find the third of the screen
        add 0x40                ; add MSB of the screen address
        add a, 0x40             ; add MSB of the screen address
        ld h, a
        ld h, a
        ld a, b
        ld a, b
        and 0x07                ; find where we are within that 1/3rd
        and 0x07                ; find where we are within that 1/3rd
        rlca                    ; multiply by 32
        rlca                    ; multiply by 32
        rlca
        rlca
Line 774... Line 801...
        ret
        ret
 
 
;------------------------------------------------------------------------
;------------------------------------------------------------------------
; F_loading
; F_loading
; Show "Loading..."
; Show "Loading..."
F_loading
.globl F_loading
 
F_loading:
        ld bc, 0x1600
        ld bc, 0x1600
        call F_printat
        call F_printat
        ld hl, STR_loading
        ld hl, STR_loading
        call PRINT42
        call PRINT42
        ret
        ret
F_clearloading
.globl F_clearloading
 
F_clearloading:
        ld bc, 0x1600
        ld bc, 0x1600
        call F_printat
        call F_printat
        ld bc, 32
        ld bc, 32
        call F_clearline2
        call F_clearline2
        ret
        ret
F_saving
.globl F_saving
 
F_saving:
        ld bc, 0x1600
        ld bc, 0x1600
        call F_printat
        call F_printat
        ld hl, STR_saving
        ld hl, STR_saving
        call PRINT42
        call PRINT42
        ret
        ret
 
 
;-----------------------------------------------------------------------
;-----------------------------------------------------------------------
; F_putcurfile
; F_putcurfile
; Prints the currently file name.
; Prints the currently file name.
F_printcurfile
.globl F_printcurfile
 
F_printcurfile:
        ld bc, 0x1500
        ld bc, 0x1500
        call F_printat
        call F_printat
        ld bc, 32
        ld bc, 32
        call F_clearline2
        call F_clearline2
        ld hl, STR_curfile
        ld hl, STR_curfile
        call PRINT42
        call PRINT42
        ld hl, v_curfilename
        ld hl, v_curfilename
        ld a, (hl)
        ld a, (hl)
        and a
        and a
        jr z, .none
        jr z,  .none27
        call PRINT42
        call PRINT42
        ret
        ret
.none
.none27:
        ld hl, STR_nofile
        ld hl, STR_nofile
        call PRINT42
        call PRINT42
        ret
        ret
 
 
;------------------------------------------------------------------------
;------------------------------------------------------------------------
; F_printcwd
; F_printcwd
; Prints the current working directory
; Prints the current working directory
F_printcwd
.globl F_printcwd
 
F_printcwd:
        ld bc, 0x1404
        ld bc, 0x1404
        call F_printat
        call F_printat
        ld bc,  MAXDIRSTR
        ld bc,  MAXDIRSTR
        inc l
        inc l
        inc l
        inc l
Line 830... Line 862...
        ld de, WORKSPACE
        ld de, WORKSPACE
        call GETCWD             ; ask the filesystem where we are
        call GETCWD             ; ask the filesystem where we are
        ld hl, WORKSPACE
        ld hl, WORKSPACE
        call F_strlen
        call F_strlen
        cp MAXDIRSTR            ; too long to fit in the bit of screen?
        cp MAXDIRSTR            ; too long to fit in the bit of screen?
        jr nc, .truncstr
        jr nc,  .truncstr28
        call PRINT42            ; no, so just print it
        call PRINT42            ; no, so just print it
        ret
        ret
.truncstr
.truncstr28:
        sub MAXDIRSTR
        sub MAXDIRSTR
        ld c, a                 ; should be starting form.
        ld c, a                 ; should be starting form.
        ld b, 0
        ld b, 0
        add hl, bc
        add hl, bc
        add a, 3
        add a, 3
        cp MAXDIRSTR            ; still too long with the ... added?
        cp MAXDIRSTR            ; still too long with the ... added?
        call nc, .truncmore
        call nc,  .truncmore28
        push hl
        push hl
        ld hl, STR_dotdotdot
        ld hl, STR_dotdotdot
        call PRINT42
        call PRINT42
        pop hl
        pop hl
        call PRINT42
        call PRINT42
        ret
        ret
.truncmore
.truncmore28:
        sub MAXDIRSTR
        sub MAXDIRSTR
        ld c, a
        ld c, a
        add hl, bc
        add hl, bc
        ret
        ret
STR_dotdotdot   defb "...",0
.data
 
STR_dotdotdot: .asciz "..."
 
.text
 
 
;------------------------------------------------------------------------
;------------------------------------------------------------------------
; F_strlen
; F_strlen
; String length returned in A for the string at HL
; String length returned in A for the string at HL
F_strlen
.globl F_strlen
 
F_strlen:
        push hl
        push hl
        xor a
        xor a
        ld bc, 0x100
        ld bc, 0x100
.loop
.loop29:
        cpir
        cpir
        ld a, c
        ld a, c
        cpl
        cpl
        pop hl
        pop hl
        ret
        ret
 
 
;------------------------------------------------------------------------
;------------------------------------------------------------------------
; F_makestaticUI
; F_makestaticUI
F_makestaticui
.globl F_makestaticui
 
F_makestaticui:
        ld hl, UI_STRINGS
        ld hl, UI_STRINGS
.loop
.loop30:
        ld b, (hl)              ; get screen position to print at
        ld b, (hl)              ; get screen position to print at
        inc hl
        inc hl
        ld c, (hl)
        ld c, (hl)
        inc hl
        inc hl
        ld a, c
        ld a, c
Line 887... Line 923...
        push hl
        push hl
        call F_printat          ; position the 42 col print routine
        call F_printat          ; position the 42 col print routine
        pop hl
        pop hl
        call PRINT42            ; print the string
        call PRINT42            ; print the string
        inc hl                  ; point HL at the start of the next item
        inc hl                  ; point HL at the start of the next item
        jr .loop
        jr  .loop30
 
 
;-----------------------------------------------------------------------
;-----------------------------------------------------------------------
; F_findstring
; F_findstring
; Finds the index of a string in the box, returns it in A.
; Finds the index of a string in the box, returns it in A.
; Carry flag set if the string was found.
; Carry flag set if the string was found.
F_findstr
.globl F_findstr
 
F_findstr:
        ld hl, (v_stringtable)
        ld hl, (v_stringtable)
        ld c, 0                 ; counter
        ld c, 0                 ; counter
.findloop
.findloop31:
        ld e, (hl)
        ld e, (hl)
        inc hl
        inc hl
        ld d, (hl)
        ld d, (hl)
        inc hl
        inc hl
        ld (v_hlsave), hl
        ld (v_hlsave), hl
Line 912... Line 949...
        and a
        and a
        ret z
        ret z
        push bc
        push bc
        call F_strcmp           ; is this the string?
        call F_strcmp           ; is this the string?
        pop bc
        pop bc
        jr z, .found
        jr z,  .found31
        inc c
        inc c
        ld hl, (v_hlsave)
        ld hl, (v_hlsave)
        jr .findloop
        jr  .findloop31
.found
.found31:
        ld a, c
        ld a, c
        scf
        scf
        ret
        ret