.if (0)

***************************************************

C128 Listbox Manager

Author: William C. Coleman

Start Date: 16 Sept 1988

Notice: Copyright (C) 1988, BlasterSoft, William C. Coleman

page 1 variables

page 2 InitFBox,FBoxPtrs

page 3 NBoxPtrs

page 4 FillBox

page 5 ScrollUp,ScrollDown,Invert

page 6 BotScroll,TopScroll,PageUp,PageDown,DoAgain

page 7 DoButton

page 8 CheckIcons

***************************************************

This version will not work under Geos64. If you need a version to

operate under both computers just print out both this file and ListBox.

You will find there are only a few areas that are different and it

should be fairly easy to code decision routines to make a single file

out of both versions

.endif

.if Pass1

.noeqin

.noglbl

.include geosSym

.include geos128Sym

.include geosMac

.eqin

.glbl

.endif

;FileBox Equates

BOXWITH = 124 ;Width of filebox

NAMEHITE = 10 ;Height of name region

MAX_IN_VIEW = 7 ;Number of files shown in box

BOXHITE = NAMEHITE*MAX_IN_VIEW+1

BOXTOP = DEF_DB_TOP+4

BOXBOTTOM = BOXTOP+BOXHITE

BOXLEFT = DEF_DB_LEFT+3

BOXRIGHT = BOXLEFT+BOXWITH

.psect

fBoxIcons:

fBox80Icons:

.ramsect

highest: .block 1 ;Highest entry # in buffer

ontop: .block 1 ;entry # on top of window

selected: .block 1 ;Currently selected entry #

nameWidth: .block 1 ;width of each entry

boxStyle: .block 1 ;style of box text

list: .block 2

.psect

;**************************************************

; InitFBox - pass: A - # of entries (zero if no files)

; Y - width of each entry

; r15 - buffer of names

;**************************************************

InitFBox:

sty nameWidth

sta highest

lda #15

jsr SetPattern

MoveW r15,list

jsr FBoxPtrs ;Set pointers to FileBox

LoadB r2L,BOXBOTTOM+1

LoadB r2H,BOXBOTTOM+16

jsr Rectangle

LoadB r2L,BOXTOP

lda #$ff

jsr FrameRectangle ;Outline box

lda highest

cmp #MAX_IN_VIEW+1

bcc 10$

lda graphMode

beq 05$

jsr i_BitmapUp

.word fBox80Icons

.byte BOXLEFT/4,BOXBOTTOM+1,32,16

bra 10$

05$:

jsr i_BitmapUp

.word fBoxIcons

.byte DOUBLE_Bö(BOXLEFT/8),BOXBOTTOM+1

.byte DOUBLE_Bö16,16

10$:

LoadW otherPressVec,DoButton

jmp TopScroll

;**************************************************

; FBoxPtrs -- sets up box pointers

;**************************************************

FBoxPtrs:

LoadW r3,DOUBLE_WöBOXLEFT

LoadW r4,DOUBLE_WöBOXRIGHT

LoadB r2L,BOXTOP

LoadB r2H,BOXBOTTOM

rts

;**************************************************

; NBoxPtrs -- Set pointers to a filename area in box

; pass: A = box # (0 to max_in_view-1)

;**************************************************

NBoxPtrs: sta r0L

LoadB r1L,NAMEHITE

ldy #r1

ldx #r0

jsr BBMult

jsr FBoxPtrs

inc r2L

lda r0L

add r2L

sta r2L

adc #NAMEHITE

sta r2H

ldx #r3

jsr NormalizeX

ldx #r4

jsr NormalizeX

inc r3L

bne 10$

inc r3H

10$: ldx #r4

jmp Ddec

;**************************************************

; FillBox - Fills the current box with names.

;**************************************************

FillBox:

lda highest

beq 05$ ;Nothing to fill with - exit

PushW rightMargin

jsr FBoxPtrs

MoveW r4,rightMargin ;Don't let text print out of box

dec rightMargin

LoadB temp,0

jsr SetPattern

lda boxStyle ;BOLDON,PLAINTEXT,etc

jsr PutChar

01$: lda temp ;Counter will count from 0 to max_in_view-1

jsr NBoxPtrs ;Get pointers to name box

jsr Rectangle ;Clear area

MoveW r3,r11 ;Set up Horiz. text

lda r2L ;Add pointsize to Vert text

add #8

sta r1H

lda temp

add ontop ;Top list entry

cmp highest ;Past last entry?

beq 02$ ;Nope, continue

bcs 04$ ;Yep, we're done!

02$:

tay

dey ;make relative to 0

sty r15

MoveB nameWidth,r0

ldx #r0

ldy #r15

jsr BBMult ;width * entry #

AddW list,r0 ;add address of list

jsr PutString ;Print name

inc temp

lda temp

cmp #MAX_IN_VIEW

bne 01$

04$:

jsr Invert ;Invert selected name

PopW rightMargin

05$:

rts

;***************************************************

; Scroll -- scroll designated box based on mouse's position

; (which half of icon the mouse is in). These

; routines are called by an icon press.

;***************************************************

ScrollUp:

ldx ontop ;x holds top item #

dex ;Scroll back

bne Scroll_ ;don't back up to zero!

beq ScrollErr

ScrollDown:

ldx ontop ;x holds top item #

inx ;Scroll forwards

lda highest

sub ontop ;Check if more names...

cmp #MAX_IN_VIEW ;...past bottom of box

bcc ScrollErr ;Nope, so beep

Scroll_:

txa

pha ;Save new top-of-box

jsr Invert ;Clear selected name

pla

sta ontop

cmp selected ;Check if selected before top of box

bcs 10$ ;Branch if selected out of box

add #MAX_IN_VIEW-1

cmp selected ;Check if selected after bottom

bcs 20$ ;Branch if selected in box

10$:

sta selected

20$:

jmp DoAgain

ScrollErr:

jmp HiBeep

;**************************************************

; Invert -- inverts name box whos # in stored in selected

;**************************************************

Invert:

lda selected ;Get name box #

sub ontop ;Offset from top box #

jsr NBoxPtrs ;Set pointers

jmp InvertRectangle

;***************************************************

; Far Scrolling - Scroll box to the very top or bottom or

; up or down a page.

; These routines are called by CheckIcons

;***************************************************

BotScroll:

MoveB highest,selected

sub #MAX_IN_VIEW-1

bcs 10$ ;ensure ontop > 0

bne 10$ ;ensure ontop not 0

lda #1

10$:

sta ontop

jmp FillBox

TopScroll:

lda #1

sta ontop

sta selected

jmp FillBox

PageUp:

lda ontop

cmp #1

beq ScrollErr

cmp #MAX_IN_VIEW

bcc TopScroll

sub #MAX_IN_VIEW-1

sta ontop

sta selected

jmp DoAgain

PageDown:

lda highest

sub #MAX_IN_VIEW

sta temp

cmp ontop

bcc ScrollErr

lda ontop

add #MAX_IN_VIEW-1

cmp temp

bcs BotScroll

sta ontop

sta selected

DoAgain:

jsr FillBox ;redraw box

lda mouseData

bmi 10$

jmp CheckIcons ;Do again if pressed

10$:

rts

;***************************************************

; DoButton - Mouse button handler. Wedged into otherPressVector

;***************************************************

DoButton:

lda mouseData

bmi 20$ ;Ignore releases

lda highest

beq 20$ ;Box empty - exit

jsr FBoxPtrs ;check if mouse in filebox

LoadB r2H,BOXBOTTOM-2

jsr IsMseInRegion

cmp #0

beq CheckIcons ;nope

jsr Invert ;Restore current selection

jsr FBoxPtrs

lda mouseYPos

sub #BOXTOP

sta r0L ;Convert mouseY to 0 offset

lda #0

sta r0H

sta r1H

LoadB r1L,NAMEHITE

ldx #r0

ldy #r1

jsr Ddiv ;mouseY/nameHite = name #

lda r0L

add ontop ;Result = selection #

cmp highest

bcc 10$ ;Branch if not passed last name

lda highest

10$:

sta selected

jsr Invert

20$:

rts

;***************************************************

; CheckIcons - Checks if icon clicked on and executes the

; the appropriate dispatch routine.

;***************************************************

CheckIcons:

lda highest

cmp #MAX_IN_VIEW+1

bcc 40$

LoadB temp,5

10$:

LoadB r2L,BOXBOTTOM+1

LoadB r2H,BOXBOTTOM+16

ldy temp

lda iconXLTab,y

sta r4L

sub #15

sta r3L

lda #0

sta r3H

sta r4H

lda graphMode

beq 15$

asl r4L

rol r4H

asl r3L

rol r3H

15$

jsr IsMseInRegion ;check if on icon

cmp #0

beq 30$ ;nope - branch

jsr InvertRectangle ;flash icon

ldy #40

ldx #0 ;now waste some time

20$:

inx

bne 20$

dey

bne 20$

jsr InvertRectangle ;back to normal

lda temp ;get execution address

asl a ;from table

tay

lda iconExecTab+1,y ;push it on the stack

pha

lda iconExecTab,y

pha

rts ;and 'jump' to it

30$:

dec temp

bpl 10$

40$:

rts

iconXLTab: .byte BOXRIGHT,BOXRIGHT-16,BOXRIGHT-(16*2)

.byte BOXRIGHT-(16*3),BOXRIGHT-(16*4)

.byte BOXRIGHT-(16*5)

iconExecTab: