a2d/desk.acc/show_text_file.s

1490 lines
38 KiB
ArmAsm
Raw Normal View History

.setcpu "6502"
2017-08-29 03:58:09 +00:00
2017-09-06 05:19:45 +00:00
.include "apple2.inc"
2017-09-16 21:20:41 +00:00
.include "../inc/ascii.inc"
2017-09-04 19:56:41 +00:00
.include "../inc/prodos.inc"
.include "../inc/auxmem.inc"
.include "../a2d.inc"
.include "../desktop.inc" ; needed to get/clear DeskTop selection
.org $800
2017-08-29 03:58:09 +00:00
start: jmp copy2aux
2017-09-01 05:53:07 +00:00
save_stack:.byte 0
;;; Copy $800 through $13FF (the DA) to aux
2017-08-30 02:07:44 +00:00
.proc copy2aux
2017-08-29 03:58:09 +00:00
tsx
2017-09-01 05:53:07 +00:00
stx save_stack
2017-08-29 03:58:09 +00:00
sta RAMWRTON
2017-09-01 05:53:07 +00:00
ldy #0
src: lda start,y ; self-modified
dst: sta start,y ; self-modified
2017-08-29 03:58:09 +00:00
dey
2017-09-01 05:53:07 +00:00
bne src
2017-08-29 03:58:09 +00:00
sta RAMWRTOFF
2017-09-01 05:53:07 +00:00
inc src+2
inc dst+2
2017-08-29 03:58:09 +00:00
sta RAMWRTON
2017-09-01 05:53:07 +00:00
lda dst+2
2017-08-29 03:58:09 +00:00
cmp #$14
2017-09-01 05:53:07 +00:00
bne src
2017-08-30 02:07:44 +00:00
.endproc
2017-09-02 02:35:50 +00:00
call_main_trampoline := $20 ; installed on ZP, turns off auxmem and calls...
call_main_addr := call_main_trampoline+7 ; address patched in here
2017-09-02 02:06:14 +00:00
;;; Copy the following "call_main_template" routine to $20
2017-09-01 05:53:07 +00:00
.scope
2017-08-29 03:58:09 +00:00
sta RAMWRTON
sta RAMRDON
2017-09-15 08:02:38 +00:00
ldx #sizeof_call_main_template
2017-09-02 02:06:14 +00:00
loop: lda call_main_template,x
sta call_main_trampoline,x
2017-08-29 03:58:09 +00:00
dex
2017-09-01 05:53:07 +00:00
bpl loop
jmp call_init
.endscope
2017-08-29 03:58:09 +00:00
2017-09-02 02:06:14 +00:00
.proc call_main_template
2017-08-30 02:07:44 +00:00
sta RAMRDOFF
2017-08-29 03:58:09 +00:00
sta RAMWRTOFF
2017-09-02 02:06:14 +00:00
jsr $1000 ; overwritten (in zp version)
2017-08-29 03:58:09 +00:00
sta RAMRDON
sta RAMWRTON
rts
2017-08-30 02:07:44 +00:00
.endproc
2017-09-15 08:02:38 +00:00
sizeof_call_main_template := * - call_main_template
2017-08-29 03:58:09 +00:00
2017-09-01 05:53:07 +00:00
.proc call_init
;; run the DA
jsr init
;; tear down/exit
2017-08-29 03:58:09 +00:00
sta ALTZPON
lda LCBANK1
lda LCBANK1
sta RAMRDOFF
sta RAMWRTOFF
2017-09-01 05:53:07 +00:00
ldx save_stack
2017-08-29 03:58:09 +00:00
txs
2017-09-01 05:53:07 +00:00
rts
.endproc
;;; ==================================================
;;; ProDOS MLI calls
2017-08-29 03:58:09 +00:00
.proc open_file
2017-08-30 01:47:15 +00:00
jsr copy_params_aux_to_main
2017-08-29 03:58:09 +00:00
sta ALTZPOFF
2017-08-29 15:40:35 +00:00
MLI_CALL OPEN, open_params
2017-08-29 03:58:09 +00:00
sta ALTZPON
2017-08-29 16:08:46 +00:00
jsr copy_params_main_to_aux
2017-08-29 03:58:09 +00:00
rts
2017-08-30 01:47:15 +00:00
.endproc
2017-08-29 03:58:09 +00:00
.proc read_file
2017-08-30 01:47:15 +00:00
jsr copy_params_aux_to_main
2017-08-29 03:58:09 +00:00
sta ALTZPOFF
2017-08-29 15:40:35 +00:00
MLI_CALL READ, read_params
2017-08-29 03:58:09 +00:00
sta ALTZPON
2017-08-29 16:08:46 +00:00
jsr copy_params_main_to_aux
2017-08-29 03:58:09 +00:00
rts
2017-08-30 01:47:15 +00:00
.endproc
2017-08-29 03:58:09 +00:00
.proc get_file_eof
2017-08-30 01:47:15 +00:00
jsr copy_params_aux_to_main
2017-08-29 03:58:09 +00:00
sta ALTZPOFF
2017-08-29 15:45:32 +00:00
MLI_CALL GET_EOF, get_eof_params
2017-08-29 03:58:09 +00:00
sta ALTZPON
2017-08-29 16:08:46 +00:00
jsr copy_params_main_to_aux
2017-08-29 03:58:09 +00:00
rts
2017-08-30 01:47:15 +00:00
.endproc
2017-08-29 03:58:09 +00:00
2017-08-30 01:47:15 +00:00
.proc set_file_mark
jsr copy_params_aux_to_main
2017-08-29 03:58:09 +00:00
sta ALTZPOFF
2017-08-29 15:47:42 +00:00
MLI_CALL SET_MARK, set_mark_params
2017-08-29 03:58:09 +00:00
sta ALTZPON
2017-08-29 16:08:46 +00:00
jsr copy_params_main_to_aux
2017-08-29 03:58:09 +00:00
rts
2017-08-30 01:47:15 +00:00
.endproc
2017-08-29 03:58:09 +00:00
2017-08-30 01:47:15 +00:00
.proc close_file
jsr copy_params_aux_to_main
2017-08-29 03:58:09 +00:00
sta ALTZPOFF
2017-08-29 15:45:32 +00:00
MLI_CALL CLOSE, close_params
2017-08-29 03:58:09 +00:00
sta ALTZPON
2017-08-29 16:08:46 +00:00
jsr copy_params_main_to_aux
2017-08-29 03:58:09 +00:00
rts
2017-08-30 01:47:15 +00:00
.endproc
2017-08-29 03:58:09 +00:00
2017-09-01 05:53:07 +00:00
;;; ==================================================
2017-08-29 16:08:46 +00:00
;;; Copies param blocks from Aux to Main
.proc copy_params_aux_to_main
2017-08-29 16:08:46 +00:00
ldy #(params_end - params_start + 1)
2017-08-29 03:58:09 +00:00
sta RAMWRTOFF
2017-08-29 16:08:46 +00:00
loop: lda params_start - 1,y
sta params_start - 1,y
2017-08-29 03:58:09 +00:00
dey
2017-08-29 16:08:46 +00:00
bne loop
2017-08-29 03:58:09 +00:00
sta RAMRDOFF
rts
2017-08-29 16:08:46 +00:00
.endproc
2017-08-29 03:58:09 +00:00
2017-08-29 16:08:46 +00:00
;;; Copies param blocks from Main to Aux
.proc copy_params_main_to_aux
2017-08-29 16:08:46 +00:00
pha
2017-08-29 03:58:09 +00:00
php
sta RAMWRTON
2017-08-29 16:08:46 +00:00
ldy #(params_end - params_start + 1)
loop: lda params_start - 1,y
sta params_start - 1,y
2017-08-29 03:58:09 +00:00
dey
2017-08-29 16:08:46 +00:00
bne loop
2017-08-29 03:58:09 +00:00
sta RAMRDON
plp
pla
2017-08-29 16:08:46 +00:00
rts
.endproc
2017-08-29 03:58:09 +00:00
2017-08-29 16:08:46 +00:00
;;; ----------------------------------------
params_start:
;;; This block gets copied between main/aux
2017-08-29 15:40:35 +00:00
2017-09-01 05:53:07 +00:00
;;; ProDOS MLI param blocks
.proc open_params
2017-08-29 15:45:32 +00:00
.byte 3 ; param_count
2017-09-01 01:38:49 +00:00
.addr pathname ; pathname
2017-08-29 15:40:35 +00:00
.addr $0C00 ; io_buffer
ref_num:.byte 0 ; ref_num
.endproc
2017-08-29 15:40:35 +00:00
2017-09-01 05:39:06 +00:00
default_buffer := $1200
.proc read_params
2017-08-29 15:45:32 +00:00
.byte 4 ; param_count
ref_num:.byte 0 ; ref_num
2017-09-01 05:39:06 +00:00
buffer: .addr default_buffer ; data_buffer
2017-08-29 15:40:35 +00:00
.word $100 ; request_count
.word 0 ; trans_count
.endproc
2017-08-29 15:40:35 +00:00
.proc get_eof_params
2017-08-29 15:45:32 +00:00
.byte 2 ; param_count
ref_num:.byte 0 ; ref_num
2017-08-29 15:47:42 +00:00
.byte 0,0,0 ; EOF (lo, mid, hi)
.endproc
2017-08-29 15:40:35 +00:00
.proc set_mark_params
2017-08-29 15:47:42 +00:00
.byte 2 ; param_count
ref_num:.byte 0 ; ref_num
2018-01-05 08:26:13 +00:00
.faraddr 0 ; position (lo, mid, hi)
.endproc
2017-08-29 15:45:32 +00:00
.proc close_params
2017-08-29 15:45:32 +00:00
.byte 1 ; param_count
ref_num:.byte 0 ; ref_num
.endproc
2017-08-29 16:08:46 +00:00
2017-09-02 01:32:37 +00:00
.proc pathname ; 1st byte is length, rest is full path
length: .byte $00
data: .res 64, $00
2017-09-02 01:32:37 +00:00
.endproc
2017-09-01 01:38:49 +00:00
2017-08-29 03:58:09 +00:00
L0945: .byte $00
L0946: .byte $00
L0947: .byte $00
L0948: .byte $00
L0949: .byte $00
2017-09-02 03:10:21 +00:00
2017-09-03 03:23:14 +00:00
params_end := * + 4 ; bug in original? (harmless as this is static)
2017-08-29 16:08:46 +00:00
;;; ----------------------------------------
2017-09-03 03:23:14 +00:00
black_pattern:
.res 8, $00
2017-09-02 04:24:35 +00:00
2017-09-03 03:23:14 +00:00
white_pattern:
.res $8, $FF
2017-09-03 03:23:14 +00:00
window_id := 100
2017-09-01 15:15:05 +00:00
2017-08-29 03:58:09 +00:00
L095A: .byte $00
L095B: .byte $FA
L095C: .byte $01
2017-09-01 15:15:05 +00:00
.proc line_pos
left: .word 0
base: .word 0
.endproc
2017-09-01 15:48:46 +00:00
window_width: .word 0
window_height: .word 0
2017-08-29 03:58:09 +00:00
L0965: .byte $00
L0966: .byte $00,$00
L0968: .byte $00
L0969: .byte $00
L096A: .byte $00
L096B: .byte $00
L096C: .byte $00
L096D: .byte $00
2017-08-31 04:13:25 +00:00
track_scroll_delta:
.byte $00
fixed_mode_flag:
2017-09-02 03:30:55 +00:00
.byte $00 ; 0 = proportional, otherwise = fixed
2017-09-09 03:45:11 +00:00
.proc input_params
state: .byte 0
coords: ; spills into target query
2017-08-31 03:30:46 +00:00
xcoord: .word 0
ycoord: .word 0
2017-09-09 03:45:11 +00:00
.endproc
.proc target_params
2017-08-31 04:04:16 +00:00
elem: .byte 0
win: .byte 0
.endproc
2017-09-02 02:54:04 +00:00
.proc resize_drag_params
id: .byte window_id
xcoord: .word 0
ycoord: .word 0
2017-08-31 03:30:46 +00:00
.byte 0 ; ???
2017-09-02 02:54:04 +00:00
.endproc
2017-08-31 03:30:46 +00:00
2017-09-03 07:31:23 +00:00
.proc close_btn_params ; queried after close clicked to see if aborted/finished
2017-08-31 04:04:16 +00:00
state: .byte 0 ; 0 = aborted, 1 = clicked
2017-09-02 17:15:15 +00:00
.byte 0,0 ; ???
2017-08-31 03:30:46 +00:00
.endproc
2017-08-31 15:10:51 +00:00
.proc query_client_params ; queried after a client click to identify target
2017-08-31 03:30:46 +00:00
xcoord: .word 0
ycoord: .word 0
2017-09-02 17:15:15 +00:00
part: .byte 0 ; 0 = client, 1 = vscroll, 2 = hscroll
2017-08-31 03:30:46 +00:00
scroll: .byte 0 ; 1 = up, 2 = down, 3 = above, 4 = below, 5 = thumb
.endproc
2017-09-01 16:30:29 +00:00
;; param block used in dead code (resize?)
2017-09-02 02:54:04 +00:00
.proc resize_window_params
part: .byte 0
2017-09-02 03:30:55 +00:00
L0987: .byte 0
;; needs one more byte?
2017-09-02 02:54:04 +00:00
.endproc
2017-08-31 15:10:51 +00:00
.proc update_scroll_params ; called to update scroll bar position
2017-09-03 05:52:38 +00:00
type: .byte 0 ; 1 = vscroll, 2 = hscroll
pos: .byte 0 ; new position
2017-08-31 15:10:51 +00:00
.endproc
2017-08-31 05:13:41 +00:00
;;; Used when dragging vscroll thumb
2017-08-31 05:22:04 +00:00
.proc thumb_drag_params
2017-09-03 05:52:38 +00:00
type: .byte 0 ; 1 = vscroll, 2 = hscroll
2017-08-31 05:13:41 +00:00
xcoord: .word 0
ycoord: .word 0
2017-09-03 05:52:38 +00:00
pos: .byte 0 ; position
2017-09-01 05:12:02 +00:00
moved: .byte 0 ; 0 if not moved, 1 if moved
2017-08-31 05:13:41 +00:00
.endproc
2017-08-30 01:52:56 +00:00
2017-09-01 05:12:02 +00:00
.proc text_string
addr: .addr 0 ; address
len: .byte 0 ; length
.endproc
2017-08-30 01:52:56 +00:00
2017-09-03 01:51:03 +00:00
default_width := 512
default_height := 150
2017-09-04 04:47:45 +00:00
default_left := 10
default_top := 28
2017-09-03 01:51:03 +00:00
2017-09-01 02:05:41 +00:00
.proc window_params
id: .byte window_id ; window identifier
2017-09-03 03:49:28 +00:00
flags: .byte A2D_CWF_ADDCLOSE; window flags (2=include close box)
2017-09-02 05:08:43 +00:00
title: .addr $1000 ; overwritten to point at filename
2017-09-03 03:49:28 +00:00
hscroll:.byte A2D_CWS_NOSCROLL
vscroll:.byte A2D_CWS_SCROLL_NORMAL
hsmax: .byte 32
hspos: .byte 0
vsmax: .byte 255
vspos: .byte 0
2017-09-15 08:02:38 +00:00
.byte 0, 0 ; ???
w1: .word 200
h1: .word 51
w2: .word default_width
h2: .word default_height
2017-08-31 03:41:54 +00:00
2017-09-15 08:02:38 +00:00
.proc box
2017-09-04 04:47:45 +00:00
left: .word default_left
top: .word default_top
2017-10-08 03:22:39 +00:00
addr: .addr A2D_SCREEN_ADDR
stride: .word A2D_SCREEN_STRIDE
2017-10-08 03:22:39 +00:00
hoff: .word 0 ; Also used for A2D_FILL_RECT
voff: .word 0
2017-09-03 01:51:03 +00:00
width: .word default_width
height: .word default_height
2017-09-01 15:32:29 +00:00
.endproc
pattern:.res 8, $00
2017-09-15 08:02:38 +00:00
mskand: .byte A2D_DEFAULT_MSKAND
mskor: .byte A2D_DEFAULT_MSKOR
2017-10-07 20:59:25 +00:00
xpos: .word 0
ypos: .word 0
hthick: .byte 1
vthick: .byte 1
2017-10-08 03:22:39 +00:00
mode: .byte 0
tmask: .byte $7F
font: .addr A2D_DEFAULT_FONT
next: .addr 0
.endproc
2017-09-01 15:15:05 +00:00
;; gets copied over window_params::box after mode is drawn
2017-09-01 15:32:29 +00:00
.proc default_box
2017-09-04 04:47:45 +00:00
left: .word default_left
top: .word default_top
addr: .word A2D_SCREEN_ADDR
stride: .word A2D_SCREEN_STRIDE
2017-10-08 03:22:39 +00:00
hoff: .word 0
voff: .word 0
2017-09-03 01:51:03 +00:00
width: .word default_width
height: .word default_height
2017-09-01 15:32:29 +00:00
.endproc
2017-08-29 16:08:46 +00:00
2017-09-01 05:53:07 +00:00
.proc init
2017-09-02 03:30:55 +00:00
sta ALTZPON
2017-08-29 03:58:09 +00:00
lda LCBANK1
lda LCBANK1
2017-09-02 01:43:53 +00:00
2017-09-04 04:47:45 +00:00
;; Get filename by checking DeskTop selected window/icon
2017-09-02 01:43:53 +00:00
2017-09-04 04:47:45 +00:00
;; Check that an icon is selected
2017-09-02 01:32:37 +00:00
lda #0
sta pathname::length
2017-09-02 05:08:43 +00:00
lda file_selected
2017-09-02 01:32:37 +00:00
beq abort ; some file properties?
2017-09-02 01:43:53 +00:00
lda path_index ; prefix index in table
2017-09-02 02:39:29 +00:00
bne :+
2017-09-02 01:32:37 +00:00
abort: rts
2017-09-02 01:58:36 +00:00
;; Copy path (prefix) into pathname buffer.
2017-09-02 02:39:29 +00:00
: src := $06
2017-09-02 01:32:37 +00:00
dst := $08
2017-09-02 01:43:53 +00:00
asl a ; (since address table is 2 bytes wide)
2017-08-29 03:58:09 +00:00
tax
2017-09-02 01:43:53 +00:00
lda path_table,x ; pathname ???
2017-09-02 01:32:37 +00:00
sta src
2017-09-02 01:43:53 +00:00
lda path_table+1,x
2017-09-02 01:32:37 +00:00
sta src+1
ldy #0
lda (src),y
2017-08-29 03:58:09 +00:00
tax
2017-09-02 01:32:37 +00:00
inc src
bne :+
inc src+1
: lda #<(pathname::data)
sta dst
lda #>(pathname::data)
sta dst+1
2017-09-02 01:34:29 +00:00
jsr copy_pathname ; copy x bytes (src) to (dst)
2017-09-02 01:32:37 +00:00
2017-09-02 01:58:36 +00:00
;; Append separator.
lda #'/'
2017-09-02 01:32:37 +00:00
ldy #0
sta (dst),y
inc pathname::length
inc dst
bne :+
inc dst+1
2017-09-02 01:43:53 +00:00
2017-09-02 05:08:43 +00:00
;; Get file entry.
2017-09-02 01:58:36 +00:00
: lda file_index ; file index in table
2017-09-02 01:43:53 +00:00
asl a ; (since table is 2 bytes wide)
2017-08-29 03:58:09 +00:00
tax
2017-09-02 01:58:36 +00:00
lda file_table,x
2017-09-02 01:32:37 +00:00
sta src
2017-09-02 01:58:36 +00:00
lda file_table+1,x
2017-09-02 01:32:37 +00:00
sta src+1
2017-09-02 01:58:36 +00:00
2017-09-02 05:08:43 +00:00
;; Exit if a directory.
ldy #2 ; 2nd byte of entry
2017-09-02 01:32:37 +00:00
lda (src),y
2017-09-02 01:58:36 +00:00
and #$70 ; check that one of bits 4,5,6 is set ???
2017-09-02 05:08:43 +00:00
;; some vague patterns, but unclear
;; basic = $32,$33, text = $52, sys = $11,$14,??, bin = $23,$24,$33
;; dir = $01 (so not shown)
2017-09-02 01:32:37 +00:00
bne :+
rts ; abort ???
2017-09-02 01:58:36 +00:00
2017-09-02 05:08:43 +00:00
;; Set window title to point at filename (9th byte of entry)
;; (title includes the spaces before/after from the icon)
2017-09-02 01:32:37 +00:00
: clc
2017-09-02 05:08:43 +00:00
lda src ; name is 9 bytes into entry
2017-09-02 01:58:36 +00:00
adc #9
2017-09-02 01:32:37 +00:00
sta window_params::title
lda src+1
2017-09-02 01:58:36 +00:00
adc #0
2017-09-02 01:32:37 +00:00
sta window_params::title+1
2017-09-02 01:58:36 +00:00
2017-09-02 05:08:43 +00:00
;; Append filename to path.
2017-09-02 01:58:36 +00:00
ldy #9
2017-09-02 05:08:43 +00:00
lda (src),y ; grab length
tax ; name has spaces before/after
dex ; so subtract 2 to get actual length
2017-08-29 03:58:09 +00:00
dex
clc
2017-09-02 01:32:37 +00:00
lda src
2017-09-02 05:08:43 +00:00
adc #11 ; 9 = length, 10 = space, 11 = name
2017-09-02 01:32:37 +00:00
sta src
2017-09-02 01:58:36 +00:00
bcc :+
2017-09-02 01:32:37 +00:00
inc src+1
2017-09-02 01:58:36 +00:00
: jsr copy_pathname ; copy x bytes (src) to (dst)
2017-09-04 03:07:05 +00:00
;; Clear selection (why???)
lda #<JUMP_TABLE_CLEAR_SEL
2017-09-02 02:06:14 +00:00
sta call_main_addr
2017-09-04 03:07:05 +00:00
lda #>JUMP_TABLE_CLEAR_SEL
2017-09-02 02:06:14 +00:00
sta call_main_addr+1
jsr call_main_trampoline
2017-09-02 01:58:36 +00:00
2017-09-01 05:12:02 +00:00
jmp open_file_and_init_window
2017-08-29 03:58:09 +00:00
2017-09-02 01:32:37 +00:00
.proc copy_pathname ; copy x bytes from src to dst
ldy #0 ; incrementing path length and dst
loop: lda (src),y
sta (dst),y
2017-08-29 03:58:09 +00:00
iny
2017-09-02 01:32:37 +00:00
inc pathname::length
2017-08-29 03:58:09 +00:00
dex
2017-09-01 05:12:02 +00:00
bne loop
2017-08-29 03:58:09 +00:00
tya
clc
2017-09-02 01:32:37 +00:00
adc dst
sta dst
2017-09-01 05:12:02 +00:00
bcc end
2017-09-02 01:32:37 +00:00
inc dst+1
2017-09-01 05:12:02 +00:00
end: rts
.endproc
2017-08-29 03:58:09 +00:00
2017-09-02 01:32:37 +00:00
.endproc
2017-09-16 03:04:56 +00:00
font_width_backup := $1100
2017-09-01 05:12:02 +00:00
.proc open_file_and_init_window
lda #0
sta fixed_mode_flag
2017-09-01 05:12:02 +00:00
2017-09-16 03:04:56 +00:00
;; make backup of font width table; overwritten if fixed
ldx font_size_count
2017-08-29 03:58:09 +00:00
sta RAMWRTOFF
2017-09-16 03:04:56 +00:00
loop: lda font_width_table - 1,x
2017-09-18 15:10:19 +00:00
sta font_width_backup - 1,x
2017-08-29 03:58:09 +00:00
dex
2017-09-01 05:12:02 +00:00
bne loop
2017-08-29 03:58:09 +00:00
sta RAMWRTON
2017-09-01 05:12:02 +00:00
;; open file, get length
2017-08-30 01:47:15 +00:00
jsr open_file
lda open_params::ref_num
sta read_params::ref_num
sta set_mark_params::ref_num
sta get_eof_params::ref_num
sta close_params::ref_num
2017-08-30 01:47:15 +00:00
jsr get_file_eof
2017-09-01 05:12:02 +00:00
;; create window
2017-09-01 02:05:41 +00:00
A2D_CALL A2D_CREATE_WINDOW, window_params
2017-09-14 04:35:23 +00:00
A2D_CALL A2D_SET_STATE, window_params::box
2017-09-02 16:44:33 +00:00
jsr calc_window_size
jsr calc_and_draw_mode
2017-09-01 01:38:49 +00:00
jsr draw_content
A2D_CALL $2B ; ???
2017-09-02 03:10:21 +00:00
;; fall through
2017-09-01 05:12:02 +00:00
.endproc
2017-09-02 04:24:35 +00:00
;;; ==================================================
;;; Main Input Loop
input_loop:
2017-09-09 03:13:09 +00:00
A2D_CALL A2D_GET_INPUT, input_params
lda input_params
2017-09-01 02:05:41 +00:00
cmp #1 ; was clicked?
bne input_loop ; nope, keep waiting
2017-09-09 03:45:11 +00:00
A2D_CALL A2D_QUERY_TARGET, input_params::coords
lda target_params::win ; in our window?
2017-09-01 05:39:06 +00:00
cmp #window_id
bne input_loop
2017-09-01 05:39:06 +00:00
;; which part of the window?
2017-09-09 03:45:11 +00:00
lda target_params::elem
2017-09-01 05:39:06 +00:00
cmp #A2D_ELEM_CLOSE
2017-09-02 04:24:35 +00:00
beq on_close_click
2017-09-01 05:39:06 +00:00
2017-09-02 04:24:35 +00:00
;; title and resize clicks need mouse location
2017-09-09 03:45:11 +00:00
ldx input_params::xcoord
2017-09-02 02:54:04 +00:00
stx resize_drag_params::xcoord
2017-08-31 03:30:46 +00:00
stx query_client_params::xcoord
2017-09-09 03:45:11 +00:00
ldx input_params::xcoord+1
2017-09-02 02:54:04 +00:00
stx resize_drag_params::xcoord+1
2017-08-31 03:30:46 +00:00
stx query_client_params::xcoord+1
2017-09-09 03:45:11 +00:00
ldx input_params::ycoord
2017-09-02 02:54:04 +00:00
stx resize_drag_params::ycoord
2017-08-31 03:30:46 +00:00
stx query_client_params::ycoord
2017-09-01 05:39:06 +00:00
cmp #A2D_ELEM_TITLE
beq title
2017-09-02 04:24:35 +00:00
cmp #A2D_ELEM_RESIZE ; not enabled, so this will never match
beq input_loop
2017-08-31 03:30:46 +00:00
jsr on_client_click
jmp input_loop
2017-08-29 03:58:09 +00:00
2017-09-01 05:39:06 +00:00
title: jsr on_title_bar_click
jmp input_loop
2017-08-29 03:58:09 +00:00
2017-09-02 04:24:35 +00:00
;;; ==================================================
;;; Close Button
.proc on_close_click
A2D_CALL A2D_CLOSE_CLICK, close_btn_params ; wait to see if the click completes
2017-09-03 07:31:23 +00:00
lda close_btn_params::state ; did click complete?
2017-08-30 06:47:18 +00:00
beq input_loop ; nope
2017-08-30 01:47:15 +00:00
jsr close_file
2017-09-01 02:05:41 +00:00
A2D_CALL A2D_DESTROY_WINDOW, window_params
DESKTOP_CALL DESKTOP_REDRAW_ICONS
2017-08-30 06:47:18 +00:00
rts ; exits input loop
.endproc
2017-08-29 03:58:09 +00:00
2017-09-02 04:24:35 +00:00
;;; ==================================================
;;; Resize Handle
2017-09-02 02:54:04 +00:00
;;; This is dead code (no resize handle!) and may be buggy
.proc on_resize_click
A2D_CALL A2D_DRAG_RESIZE, resize_drag_params
2017-09-18 15:10:19 +00:00
jsr redraw_screen
2017-09-02 16:44:33 +00:00
jsr calc_window_size
2017-09-01 16:30:29 +00:00
2017-09-03 01:51:03 +00:00
max_width := default_width
2017-09-01 16:30:29 +00:00
lda #>max_width
cmp window_params::box::width+1
2017-09-02 02:39:29 +00:00
bne :+
2017-09-01 16:30:29 +00:00
lda #<max_width
cmp window_params::box::width
2017-09-02 02:39:29 +00:00
: bcs wider
2017-09-01 16:30:29 +00:00
lda #<max_width
sta window_params::box::width
2017-09-01 16:30:29 +00:00
lda #>max_width
sta window_params::box::width+1
2017-08-29 03:58:09 +00:00
sec
lda window_params::box::width
2017-09-01 15:48:46 +00:00
sbc window_width
2017-10-08 03:22:39 +00:00
sta window_params::box::hoff
lda window_params::box::width+1
2017-09-01 15:48:46 +00:00
sbc window_width+1
2017-10-08 03:22:39 +00:00
sta window_params::box::hoff+1
2017-09-03 03:49:28 +00:00
wider: lda window_params::hscroll
2017-09-01 15:48:46 +00:00
ldx window_width
2017-09-01 16:30:29 +00:00
cpx #<max_width
2017-09-04 03:07:05 +00:00
bne enable
2017-09-01 15:48:46 +00:00
ldx window_width+1
2017-09-01 16:30:29 +00:00
cpx #>max_width
2017-09-04 03:07:05 +00:00
bne enable
and #(<~A2D_CWS_SCROLL_TRACK) ; disable scroll
jmp :+
2017-08-29 03:58:09 +00:00
2017-09-04 03:07:05 +00:00
enable: ora #A2D_CWS_SCROLL_TRACK ; enable scroll
: sta window_params::hscroll
2017-08-29 03:58:09 +00:00
sec
2017-09-01 16:30:29 +00:00
lda #<max_width
2017-09-01 15:48:46 +00:00
sbc window_width
2017-08-29 03:58:09 +00:00
sta $06
2017-09-01 16:30:29 +00:00
lda #>max_width
2017-09-01 15:48:46 +00:00
sbc window_width+1
2017-08-29 03:58:09 +00:00
sta $07
2017-09-03 05:52:38 +00:00
jsr div_by_16
2017-09-02 02:54:04 +00:00
sta resize_window_params::L0987
lda #A2D_HSCROLL
sta resize_window_params::part
2017-09-02 02:54:04 +00:00
A2D_CALL A2D_RESIZE_WINDOW, resize_window_params ; change to clamped size ???
jsr calc_and_draw_mode
2017-09-02 03:30:55 +00:00
jmp finish_resize
2017-08-31 03:30:46 +00:00
.endproc
2017-08-29 03:58:09 +00:00
2017-09-02 04:24:35 +00:00
;;; ==================================================
;;; Client Area
2017-08-31 04:04:16 +00:00
;;; Non-title (client) area clicked
2017-08-31 03:30:46 +00:00
.proc on_client_click
2017-09-02 04:24:35 +00:00
;; On one of the scroll bars?
2017-08-31 03:30:46 +00:00
A2D_CALL A2D_QUERY_CLIENT, query_client_params
lda query_client_params::part
2017-09-01 05:39:06 +00:00
cmp #A2D_VSCROLL
2017-08-31 03:41:54 +00:00
beq on_vscroll_click
2017-09-01 05:39:06 +00:00
cmp #A2D_HSCROLL
bne end
2017-09-01 05:12:02 +00:00
jmp on_hscroll_click
2017-08-31 03:41:54 +00:00
end: rts
2017-08-31 03:30:46 +00:00
.endproc
2017-08-29 03:58:09 +00:00
2017-09-02 04:24:35 +00:00
;;; ==================================================
;;; Vertical Scroll Bar
2017-08-31 03:41:54 +00:00
.proc on_vscroll_click
2017-09-02 03:30:55 +00:00
lda #A2D_VSCROLL
2017-08-31 05:22:04 +00:00
sta thumb_drag_params::type
2017-08-31 15:10:51 +00:00
sta update_scroll_params::type
2017-08-31 03:30:46 +00:00
lda query_client_params::scroll
2017-09-01 05:39:06 +00:00
cmp #A2D_SCROLL_PART_THUMB
2017-08-31 03:41:54 +00:00
beq on_vscroll_thumb_click
2017-09-01 05:39:06 +00:00
cmp #A2D_SCROLL_PART_BELOW
2017-08-31 03:41:54 +00:00
beq on_vscroll_below_click
2017-09-01 05:39:06 +00:00
cmp #A2D_SCROLL_PART_ABOVE
2017-08-31 03:41:54 +00:00
beq on_vscroll_above_click
2017-09-01 05:39:06 +00:00
cmp #A2D_SCROLL_PART_UP
2017-08-31 03:41:54 +00:00
beq on_vscroll_up_click
2017-09-01 05:39:06 +00:00
cmp #A2D_SCROLL_PART_DOWN
2017-08-31 03:30:46 +00:00
bne end
2017-08-31 03:41:54 +00:00
jmp on_vscroll_down_click
end: rts
2017-08-31 03:30:46 +00:00
.endproc
2017-08-29 03:58:09 +00:00
2017-08-31 03:41:54 +00:00
.proc on_vscroll_thumb_click
2017-09-01 05:39:06 +00:00
jsr do_thumb_drag
2017-09-01 05:12:02 +00:00
lda thumb_drag_params::moved
2017-08-31 03:41:54 +00:00
beq end
2017-09-01 05:12:02 +00:00
lda thumb_drag_params::pos
2017-08-31 15:10:51 +00:00
sta update_scroll_params::pos
2017-09-02 16:44:33 +00:00
jsr update_voffset
2017-08-31 15:17:06 +00:00
jsr update_vscroll
2017-09-01 01:38:49 +00:00
jsr draw_content
2017-08-29 03:58:09 +00:00
lda L0947
2017-08-31 03:41:54 +00:00
beq end
2017-08-29 03:58:09 +00:00
lda L0949
2017-08-31 03:41:54 +00:00
bne end
2017-09-16 03:04:56 +00:00
jsr clear_window
2017-08-31 03:41:54 +00:00
end: rts
.endproc
2017-08-29 03:58:09 +00:00
2017-08-31 03:41:54 +00:00
.proc on_vscroll_above_click
loop: lda window_params::vspos
2017-08-31 03:41:54 +00:00
beq end
2017-08-31 04:13:25 +00:00
jsr calc_track_scroll_delta
2017-08-29 03:58:09 +00:00
sec
lda window_params::vspos
2017-08-31 04:13:25 +00:00
sbc track_scroll_delta
2017-08-31 15:17:06 +00:00
bcs store
2017-09-02 02:54:04 +00:00
lda #0 ; underflow
2017-08-31 15:17:06 +00:00
store: sta update_scroll_params::pos
2017-08-31 04:04:16 +00:00
jsr update_scroll_pos
bcc loop ; repeat while button down
2017-08-31 03:41:54 +00:00
end: rts
.endproc
2017-08-29 03:58:09 +00:00
2017-08-31 03:41:54 +00:00
.proc on_vscroll_up_click
loop : lda window_params::vspos
2017-08-31 03:41:54 +00:00
beq end
2017-08-29 03:58:09 +00:00
sec
2017-08-31 04:04:16 +00:00
sbc #1
2017-08-31 15:10:51 +00:00
sta update_scroll_params::pos
2017-08-31 04:04:16 +00:00
jsr update_scroll_pos
bcc loop ; repeat while button down
2017-08-31 03:41:54 +00:00
end: rts
.endproc
2017-08-29 03:58:09 +00:00
2017-08-31 04:04:16 +00:00
vscroll_max := $FA
2017-08-31 03:41:54 +00:00
.proc on_vscroll_below_click
loop: lda window_params::vspos
2017-08-31 04:04:16 +00:00
cmp #vscroll_max ; pos == max ?
2017-08-31 03:41:54 +00:00
beq end
2017-08-31 04:13:25 +00:00
jsr calc_track_scroll_delta
2017-08-29 03:58:09 +00:00
clc
lda window_params::vspos
2017-08-31 04:13:25 +00:00
adc track_scroll_delta ; pos + delta
2017-08-31 04:04:16 +00:00
bcs overflow
cmp #vscroll_max+1 ; > max ?
bcc store ; nope, it's good
overflow:
lda #vscroll_max ; set to max
2017-08-31 15:10:51 +00:00
store: sta update_scroll_params::pos
2017-08-31 04:04:16 +00:00
jsr update_scroll_pos
bcc loop ; repeat while button down
2017-08-31 03:41:54 +00:00
end: rts
.endproc
2017-08-29 03:58:09 +00:00
2017-08-31 03:41:54 +00:00
.proc on_vscroll_down_click
loop: lda window_params::vspos
2017-08-31 04:04:16 +00:00
cmp #vscroll_max
2017-08-31 03:41:54 +00:00
beq end
2017-08-29 03:58:09 +00:00
clc
2017-08-31 04:04:16 +00:00
adc #1
2017-08-31 15:10:51 +00:00
sta update_scroll_params::pos
2017-08-31 04:04:16 +00:00
jsr update_scroll_pos
bcc loop ; repeat while button down
2017-08-31 03:41:54 +00:00
end: rts
.endproc
2017-08-29 03:58:09 +00:00
2017-08-31 04:13:25 +00:00
.proc update_scroll_pos ; Returns with carry set if mouse released
2017-09-02 16:44:33 +00:00
jsr update_voffset
2017-08-31 15:17:06 +00:00
jsr update_vscroll
2017-09-01 01:38:49 +00:00
jsr draw_content
2017-08-31 04:04:16 +00:00
jsr was_button_released
2017-08-29 03:58:09 +00:00
clc
2017-08-31 04:04:16 +00:00
bne end
2017-08-29 03:58:09 +00:00
sec
2017-08-31 04:04:16 +00:00
end: rts
.endproc
2017-08-29 03:58:09 +00:00
2017-08-31 04:13:25 +00:00
.proc calc_track_scroll_delta
2017-09-02 16:44:33 +00:00
lda window_height ; ceil(??? / 50)
2017-08-31 04:13:25 +00:00
ldx #0
loop: inx
2017-08-29 03:58:09 +00:00
sec
2017-08-31 04:13:25 +00:00
sbc #50
cmp #50
bcs loop
stx track_scroll_delta
2017-08-29 03:58:09 +00:00
rts
2017-08-31 04:13:25 +00:00
.endproc
2017-08-29 03:58:09 +00:00
2017-09-02 04:24:35 +00:00
;;; ==================================================
;;; Horizontal Scroll Bar
;;; (Unused in STF DA, so most of this is speculation)
2017-09-01 05:12:02 +00:00
.proc on_hscroll_click
2017-09-01 05:39:06 +00:00
lda #A2D_HSCROLL
2017-08-31 05:22:04 +00:00
sta thumb_drag_params::type
2017-08-31 15:10:51 +00:00
sta update_scroll_params::type
2017-08-31 03:30:46 +00:00
lda query_client_params::scroll
2017-09-01 05:39:06 +00:00
cmp #A2D_SCROLL_PART_THUMB
2017-09-01 05:12:02 +00:00
beq on_hscroll_thumb_click
2017-09-01 05:39:06 +00:00
cmp #A2D_SCROLL_PART_AFTER
2017-09-01 05:12:02 +00:00
beq on_hscroll_after_click
2017-09-01 05:39:06 +00:00
cmp #A2D_SCROLL_PART_BEFORE
2017-09-01 05:12:02 +00:00
beq on_hscroll_before_click
2017-09-01 05:39:06 +00:00
cmp #A2D_SCROLL_PART_LEFT
2017-09-01 05:12:02 +00:00
beq on_hscroll_left_click
2017-09-01 05:39:06 +00:00
cmp #A2D_SCROLL_PART_RIGHT
2017-09-01 05:12:02 +00:00
beq on_hscroll_right_click
2017-08-29 03:58:09 +00:00
rts
2017-09-01 05:12:02 +00:00
.endproc
2017-08-29 03:58:09 +00:00
2017-09-01 05:12:02 +00:00
.proc on_hscroll_thumb_click
2017-09-01 05:39:06 +00:00
jsr do_thumb_drag
2017-09-01 05:12:02 +00:00
lda thumb_drag_params::moved
beq end
lda thumb_drag_params::pos
2017-09-03 05:52:38 +00:00
jsr mul_by_16
2017-08-29 03:58:09 +00:00
lda $06
2017-10-08 03:22:39 +00:00
sta window_params::box::hoff
2017-08-29 03:58:09 +00:00
lda $07
2017-10-08 03:22:39 +00:00
sta window_params::box::hoff+1
2017-08-29 03:58:09 +00:00
clc
2017-10-08 03:22:39 +00:00
lda window_params::box::hoff
2017-09-01 15:48:46 +00:00
adc window_width
sta window_params::box::width
2017-10-08 03:22:39 +00:00
lda window_params::box::hoff+1
2017-09-01 15:48:46 +00:00
adc window_width+1
sta window_params::box::width+1
2017-09-02 03:30:55 +00:00
jsr update_hscroll
2017-09-01 01:38:49 +00:00
jsr draw_content
2017-09-01 05:12:02 +00:00
end: rts
.endproc
2017-08-29 03:58:09 +00:00
2017-09-01 05:12:02 +00:00
.proc on_hscroll_after_click
ldx #2
lda window_params::hsmax
2017-09-01 05:12:02 +00:00
jmp hscroll_common
.endproc
2017-08-29 03:58:09 +00:00
2017-09-01 05:12:02 +00:00
.proc on_hscroll_before_click
ldx #254
lda #0
jmp hscroll_common
.endproc
2017-08-29 03:58:09 +00:00
2017-09-01 05:12:02 +00:00
.proc on_hscroll_right_click
ldx #1
lda window_params::hsmax
2017-09-01 05:12:02 +00:00
jmp hscroll_common
.endproc
2017-08-29 03:58:09 +00:00
2017-09-01 05:12:02 +00:00
.proc on_hscroll_left_click
ldx #255
lda #0
;; fall through
.endproc
.proc hscroll_common
sta compare+1
stx delta+1
loop: lda window_params::hspos
2017-09-01 05:12:02 +00:00
compare:cmp #$0A ; self-modified
bne continue
2017-08-29 03:58:09 +00:00
rts
2017-09-01 05:12:02 +00:00
continue:
clc
lda window_params::hspos
2017-09-01 05:12:02 +00:00
delta: adc #1 ; self-modified
bmi overflow
cmp window_params::hsmax
2017-09-01 05:12:02 +00:00
beq store
bcc store
lda window_params::hsmax
2017-09-01 05:12:02 +00:00
jmp store
overflow:
lda #0
store: sta window_params::hspos
2017-09-16 21:20:41 +00:00
jsr adjust_box_width
2017-09-02 03:30:55 +00:00
jsr update_hscroll
2017-09-01 01:38:49 +00:00
jsr draw_content
2017-08-31 04:04:16 +00:00
jsr was_button_released
2017-09-01 05:12:02 +00:00
bne loop
2017-08-29 03:58:09 +00:00
rts
2017-09-01 05:12:02 +00:00
.endproc
2017-08-29 03:58:09 +00:00
2017-09-02 04:24:35 +00:00
;;; ==================================================
;;; UI Helpers
2017-08-31 05:13:41 +00:00
;; Used at start of thumb drag
2017-09-01 05:39:06 +00:00
.proc do_thumb_drag
2017-09-09 03:45:11 +00:00
lda input_params::xcoord
2017-08-31 05:22:04 +00:00
sta thumb_drag_params::xcoord
2017-09-09 03:45:11 +00:00
lda input_params::xcoord+1
2017-08-31 05:22:04 +00:00
sta thumb_drag_params::xcoord+1
2017-09-09 03:45:11 +00:00
lda input_params::ycoord
2017-08-31 05:22:04 +00:00
sta thumb_drag_params::ycoord
2017-09-01 05:39:06 +00:00
A2D_CALL A2D_DRAG_SCROLL, thumb_drag_params
2017-08-29 03:58:09 +00:00
rts
2017-08-31 05:22:04 +00:00
.endproc
2017-08-29 03:58:09 +00:00
2017-09-01 02:05:41 +00:00
;;; Checks button state; z clear if button was released, set otherwise
2017-08-31 04:04:16 +00:00
.proc was_button_released
2017-09-09 03:13:09 +00:00
A2D_CALL A2D_GET_INPUT, input_params
lda input_params
2017-08-31 04:04:16 +00:00
cmp #2
2017-08-29 03:58:09 +00:00
rts
2017-08-31 04:04:16 +00:00
.endproc
2017-08-29 03:58:09 +00:00
2017-09-01 05:12:02 +00:00
;;; only used from hscroll code?
2017-09-16 21:20:41 +00:00
.proc adjust_box_width
lda window_params::hspos
2017-09-03 05:52:38 +00:00
jsr mul_by_16
2017-08-29 03:58:09 +00:00
clc
lda $06
2017-10-08 03:22:39 +00:00
sta window_params::box::hoff
2017-09-01 15:48:46 +00:00
adc window_width
sta window_params::box::width
2017-08-29 03:58:09 +00:00
lda $07
2017-10-08 03:22:39 +00:00
sta window_params::box::hoff+1
2017-09-01 15:48:46 +00:00
adc window_width+1
sta window_params::box::width+1
2017-08-29 03:58:09 +00:00
rts
2017-09-01 05:12:02 +00:00
.endproc
2017-08-29 03:58:09 +00:00
2017-09-02 16:44:33 +00:00
.proc update_voffset
2017-09-01 05:39:06 +00:00
lda #0
2017-10-08 03:22:39 +00:00
sta window_params::box::voff
sta window_params::box::voff+1
2017-08-31 15:10:51 +00:00
ldx update_scroll_params::pos
2017-09-16 04:44:41 +00:00
loop: beq adjust_box_height
2017-08-29 03:58:09 +00:00
clc
2017-10-08 03:22:39 +00:00
lda window_params::box::voff
2017-08-31 15:17:06 +00:00
adc #50
2017-10-08 03:22:39 +00:00
sta window_params::box::voff
2017-09-02 02:39:29 +00:00
bcc :+
2017-10-08 03:22:39 +00:00
inc window_params::box::voff+1
2017-09-02 02:39:29 +00:00
: dex
2017-09-01 05:39:06 +00:00
jmp loop
.endproc
2017-08-29 03:58:09 +00:00
2017-09-16 04:44:41 +00:00
.proc adjust_box_height
2017-09-01 05:39:06 +00:00
clc
2017-10-08 03:22:39 +00:00
lda window_params::box::voff
2017-09-01 15:48:46 +00:00
adc window_height
sta window_params::box::height
2017-10-08 03:22:39 +00:00
lda window_params::box::voff+1
2017-09-01 15:48:46 +00:00
adc window_height+1
sta window_params::box::height+1
2017-09-16 21:20:41 +00:00
jsr calc_line_position
2017-08-31 15:17:06 +00:00
lda #0
2017-08-29 03:58:09 +00:00
sta L096A
sta L096B
2017-08-31 15:10:51 +00:00
ldx update_scroll_params::pos
2017-09-01 05:39:06 +00:00
loop: beq end
2017-08-29 03:58:09 +00:00
clc
lda L096A
2017-08-31 15:17:06 +00:00
adc #5
2017-08-29 03:58:09 +00:00
sta L096A
2017-09-02 02:39:29 +00:00
bcc :+
2017-08-29 03:58:09 +00:00
inc L096B
2017-09-02 02:39:29 +00:00
: dex
2017-09-01 05:39:06 +00:00
jmp loop
end: rts
.endproc
2017-08-29 03:58:09 +00:00
2017-09-02 03:30:55 +00:00
.proc update_hscroll
lda #2
2017-08-31 15:10:51 +00:00
sta update_scroll_params::type
2017-10-08 03:22:39 +00:00
lda window_params::box::hoff
2017-08-29 03:58:09 +00:00
sta $06
2017-10-08 03:22:39 +00:00
lda window_params::box::hoff+1
2017-08-29 03:58:09 +00:00
sta $07
2017-09-03 05:52:38 +00:00
jsr div_by_16
2017-08-31 15:10:51 +00:00
sta update_scroll_params::pos
A2D_CALL A2D_UPDATE_SCROLL, update_scroll_params
2017-08-29 03:58:09 +00:00
rts
2017-09-02 03:30:55 +00:00
.endproc
2017-08-29 03:58:09 +00:00
2017-08-31 15:17:06 +00:00
.proc update_vscroll ; update_scroll_params::pos set by caller
lda #1
2017-08-31 15:10:51 +00:00
sta update_scroll_params::type
A2D_CALL A2D_UPDATE_SCROLL, update_scroll_params
2017-08-29 03:58:09 +00:00
rts
2017-08-31 15:17:06 +00:00
.endproc
2017-08-29 03:58:09 +00:00
2017-09-02 03:30:55 +00:00
.proc finish_resize ; only called from dead code
DESKTOP_CALL DESKTOP_REDRAW_ICONS
2017-09-14 04:35:23 +00:00
A2D_CALL A2D_SET_STATE, window_params::box
2017-09-03 03:49:28 +00:00
lda window_params::hscroll
ror a ; check if low bit (track enabled) is set
2017-09-02 02:39:29 +00:00
bcc :+
2017-09-02 03:30:55 +00:00
jsr update_hscroll
: lda window_params::vspos
2017-08-31 15:10:51 +00:00
sta update_scroll_params::pos
2017-08-31 15:17:06 +00:00
jsr update_vscroll
2017-09-01 01:38:49 +00:00
jsr draw_content
jmp input_loop
2017-09-01 05:39:06 +00:00
.endproc
2017-08-29 03:58:09 +00:00
2017-09-16 03:04:56 +00:00
.proc clear_window
A2D_CALL A2D_SET_PATTERN, white_pattern
2017-10-08 03:22:39 +00:00
A2D_CALL A2D_FILL_RECT, window_params::box::hoff
2017-09-03 03:23:14 +00:00
A2D_CALL A2D_SET_PATTERN, black_pattern
2017-08-29 03:58:09 +00:00
rts
2017-09-16 03:04:56 +00:00
.endproc
2017-08-29 03:58:09 +00:00
2017-09-02 04:24:35 +00:00
;;; ==================================================
;;; Content Rendering
2017-09-01 01:38:49 +00:00
.proc draw_content
2017-09-01 05:39:06 +00:00
lda #0
2017-08-29 03:58:09 +00:00
sta L0949
2017-09-16 04:44:41 +00:00
jsr assign_fixed_font_width_table_if_needed
2017-08-30 01:47:15 +00:00
jsr set_file_mark
2017-09-01 05:39:06 +00:00
lda #<default_buffer
2017-09-01 01:38:49 +00:00
sta read_params::buffer
2017-08-29 03:58:09 +00:00
sta $06
2017-09-01 05:39:06 +00:00
lda #>default_buffer
2017-09-01 01:38:49 +00:00
sta read_params::buffer+1
2017-08-29 03:58:09 +00:00
sta $07
2017-09-16 21:20:41 +00:00
lda #0
2017-08-29 03:58:09 +00:00
sta L0945
sta L0946
sta L0947
2017-09-01 15:15:05 +00:00
sta line_pos::base+1
2017-08-29 03:58:09 +00:00
sta L096C
sta L096D
sta L0948
2017-09-02 04:02:00 +00:00
lda #$0A ; line spacing = 10
2017-09-01 15:15:05 +00:00
sta line_pos::base
2017-08-29 03:58:09 +00:00
jsr L0EDB
2017-09-16 04:44:41 +00:00
do_line:
lda L096D
2017-08-29 03:58:09 +00:00
cmp L096B
2017-09-16 04:44:41 +00:00
bne :+
2017-08-29 03:58:09 +00:00
lda L096C
cmp L096A
2017-09-16 04:44:41 +00:00
bne :+
2017-09-16 03:04:56 +00:00
jsr clear_window
2017-08-29 03:58:09 +00:00
inc L0948
2017-09-16 04:44:41 +00:00
: A2D_CALL A2D_SET_POS, line_pos
2017-08-29 03:58:09 +00:00
sec
2017-09-02 03:10:21 +00:00
lda #250
2017-09-01 15:15:05 +00:00
sbc line_pos::left
2017-08-29 03:58:09 +00:00
sta L095B
2017-09-02 03:10:21 +00:00
lda #1
2017-09-01 15:15:05 +00:00
sbc line_pos::left+1
2017-08-29 03:58:09 +00:00
sta L095C
jsr find_text_run
2017-08-29 03:58:09 +00:00
bcs L0ED7
clc
2017-09-01 05:12:02 +00:00
lda text_string::len
2017-08-29 03:58:09 +00:00
adc $06
sta $06
2017-09-15 08:09:42 +00:00
bcc :+
2017-08-29 03:58:09 +00:00
inc $07
2017-09-15 08:09:42 +00:00
: lda L095A
2017-09-16 04:44:41 +00:00
bne do_line
2017-08-29 03:58:09 +00:00
clc
2017-09-01 15:15:05 +00:00
lda line_pos::base
2017-09-02 04:02:00 +00:00
adc #$0A ; line spacing = 10
2017-09-01 15:15:05 +00:00
sta line_pos::base
2017-09-15 08:09:42 +00:00
bcc :+
2017-09-01 15:15:05 +00:00
inc line_pos::base+1
2017-09-15 08:09:42 +00:00
: jsr L0EDB
2017-08-29 03:58:09 +00:00
lda L096C
cmp L0968
2017-09-15 08:09:42 +00:00
bne :+
2017-08-29 03:58:09 +00:00
lda L096D
cmp L0969
beq L0ED7
2017-09-15 08:09:42 +00:00
: inc L096C
bne :+
2017-08-29 03:58:09 +00:00
inc L096D
2017-09-16 04:44:41 +00:00
: jmp do_line
2017-08-29 03:58:09 +00:00
2017-09-16 04:44:41 +00:00
L0ED7: jsr restore_proportional_font_table_if_needed
2017-08-29 03:58:09 +00:00
rts
2017-09-01 01:38:49 +00:00
.endproc
2017-08-29 03:58:09 +00:00
2017-09-16 04:44:41 +00:00
;;; ==================================================
2017-09-01 01:38:49 +00:00
.proc L0EDB ; ???
2017-09-02 03:10:21 +00:00
lda #250
2017-08-29 03:58:09 +00:00
sta L095B
2017-09-02 03:10:21 +00:00
lda #1
2017-08-29 03:58:09 +00:00
sta L095C
2017-09-02 03:10:21 +00:00
lda #3
2017-09-01 15:15:05 +00:00
sta line_pos::left
2017-09-02 03:10:21 +00:00
lda #0
2017-09-01 15:15:05 +00:00
sta line_pos::left+1
2017-08-29 03:58:09 +00:00
sta L095A
rts
2017-09-01 01:38:49 +00:00
.endproc
2017-08-29 03:58:09 +00:00
2017-09-16 04:44:41 +00:00
;;; ==================================================
.proc find_text_run
lda #$FF
2017-08-29 03:58:09 +00:00
sta L0F9B
2017-09-16 05:05:41 +00:00
lda #0
sta run_width
sta run_width+1
2017-08-29 03:58:09 +00:00
sta L095A
2017-09-01 05:12:02 +00:00
sta text_string::len
2017-08-29 03:58:09 +00:00
lda $06
2017-09-01 05:12:02 +00:00
sta text_string::addr
2017-08-29 03:58:09 +00:00
lda $07
2017-09-01 05:12:02 +00:00
sta text_string::addr+1
loop: lda L0945
bne more
2017-08-29 03:58:09 +00:00
lda L0947
beq :+
2017-09-16 05:05:41 +00:00
jsr draw_text_run
2017-08-29 03:58:09 +00:00
sec
rts
: jsr ensure_page_buffered
more: ldy text_string::len
2017-08-29 03:58:09 +00:00
lda ($06),y
2017-08-30 02:07:44 +00:00
and #$7F ; clear high bit
2017-08-29 03:58:09 +00:00
sta ($06),y
inc L0945
2017-09-16 21:20:41 +00:00
cmp #ASCII_RETURN
beq finish_text_run
2017-09-02 03:10:21 +00:00
cmp #' ' ; space character
2017-09-15 08:09:42 +00:00
bne :+
2017-08-29 03:58:09 +00:00
sty L0F9B
pha
lda L0945
sta L0946
pla
2017-09-16 21:20:41 +00:00
: cmp #ASCII_TAB
2017-09-16 05:05:41 +00:00
bne :+
jmp handle_tab
2017-08-29 03:58:09 +00:00
2017-09-16 05:05:41 +00:00
: tay
2017-09-16 03:04:56 +00:00
lda font_width_table,y
2017-08-29 03:58:09 +00:00
clc
2017-09-16 05:05:41 +00:00
adc run_width
sta run_width
2017-09-15 08:09:42 +00:00
bcc :+
2017-09-16 05:05:41 +00:00
inc run_width+1
2017-09-15 08:09:42 +00:00
: lda L095C
2017-09-16 05:05:41 +00:00
cmp run_width+1
2017-09-15 08:09:42 +00:00
bne :+
2017-08-29 03:58:09 +00:00
lda L095B
2017-09-16 05:05:41 +00:00
cmp run_width
: bcc :+
2017-09-01 05:12:02 +00:00
inc text_string::len
jmp loop
2017-08-29 03:58:09 +00:00
2017-09-16 05:05:41 +00:00
: lda #0
2017-08-29 03:58:09 +00:00
sta L095A
lda L0F9B
cmp #$FF
2017-09-15 08:09:42 +00:00
beq :+
2017-09-01 05:12:02 +00:00
sta text_string::len
2017-08-29 03:58:09 +00:00
lda L0946
sta L0945
2017-09-15 08:09:42 +00:00
: inc text_string::len
;; fall through
.endproc
2017-09-16 05:05:41 +00:00
finish_text_run: jsr draw_text_run
2017-09-01 05:12:02 +00:00
ldy text_string::len
2017-08-29 03:58:09 +00:00
lda ($06),y
2017-09-16 21:20:41 +00:00
cmp #ASCII_TAB
2017-09-16 05:05:41 +00:00
beq tab
2017-09-16 21:20:41 +00:00
cmp #ASCII_RETURN
2017-09-16 05:05:41 +00:00
bne :+
tab: inc text_string::len
: clc
2017-08-29 03:58:09 +00:00
rts
2017-09-16 04:44:41 +00:00
;;; ==================================================
2017-08-29 16:08:46 +00:00
L0F9B: .byte 0
2017-09-16 05:05:41 +00:00
run_width: .word 0
.proc handle_tab
2017-09-01 02:05:41 +00:00
lda #1
2017-08-29 03:58:09 +00:00
sta L095A
clc
2017-09-16 05:05:41 +00:00
lda run_width
2017-09-01 15:15:05 +00:00
adc line_pos::left
sta line_pos::left
2017-09-16 05:05:41 +00:00
lda run_width+1
2017-09-01 15:15:05 +00:00
adc line_pos::left+1
sta line_pos::left+1
2017-09-01 02:05:41 +00:00
ldx #0
loop: lda times70+1,x
2017-09-01 15:15:05 +00:00
cmp line_pos::left+1
2017-09-15 08:09:42 +00:00
bne :+
2017-09-01 02:05:41 +00:00
lda times70,x
2017-09-01 15:15:05 +00:00
cmp line_pos::left
2017-09-15 08:09:42 +00:00
: bcs :+
2017-08-29 03:58:09 +00:00
inx
inx
2017-09-01 02:05:41 +00:00
cpx #14
beq done
jmp loop
2017-09-15 08:09:42 +00:00
: lda times70,x
2017-09-01 15:15:05 +00:00
sta line_pos::left
2017-09-01 02:05:41 +00:00
lda times70+1,x
2017-09-01 15:15:05 +00:00
sta line_pos::left+1
jmp finish_text_run
2017-09-01 02:05:41 +00:00
done: lda #0
2017-08-29 03:58:09 +00:00
sta L095A
jmp finish_text_run
2017-08-29 03:58:09 +00:00
2017-09-01 02:05:41 +00:00
times70:.word 70
.word 140
.word 210
.word 280
.word 350
.word 420
.word 490
.endproc
2017-09-16 04:44:41 +00:00
;;; ==================================================
;;; Draw a line of content
2017-09-16 05:05:41 +00:00
.proc draw_text_run
2017-09-16 03:04:56 +00:00
lda L0948
beq end
2017-09-01 05:12:02 +00:00
lda text_string::len
2017-09-16 03:04:56 +00:00
beq end
2017-09-02 02:06:14 +00:00
A2D_CALL A2D_DRAW_TEXT, text_string
2017-09-01 05:53:07 +00:00
lda #1
2017-08-29 03:58:09 +00:00
sta L0949
2017-09-16 03:04:56 +00:00
end: rts
.endproc
2017-08-29 03:58:09 +00:00
2017-09-16 04:44:41 +00:00
;;; ==================================================
.proc ensure_page_buffered
lda text_string::addr+1
2017-09-16 21:20:41 +00:00
cmp #>default_buffer
beq read
2017-09-02 03:10:21 +00:00
;; copy a page of characters from $1300 to the buffer
ldy #0
loop: lda $1300,y
2017-09-01 05:39:06 +00:00
sta default_buffer,y
2017-08-29 03:58:09 +00:00
iny
2017-09-02 03:10:21 +00:00
bne loop
2017-09-01 05:12:02 +00:00
dec text_string::addr+1
lda text_string::addr
2017-08-29 03:58:09 +00:00
sta $06
2017-09-01 05:12:02 +00:00
lda text_string::addr+1
2017-08-29 03:58:09 +00:00
sta $07
2017-09-16 21:20:41 +00:00
read: lda #0
2017-08-29 03:58:09 +00:00
sta L0945
jsr read_file_page
2017-09-01 01:38:49 +00:00
lda read_params::buffer+1
cmp #>default_buffer
bne :+
2017-09-01 01:38:49 +00:00
inc read_params::buffer+1
: rts
.endproc
2017-08-29 03:58:09 +00:00
2017-09-16 04:44:41 +00:00
;;; ==================================================
.proc read_file_page
2017-09-01 01:38:49 +00:00
lda read_params::buffer
2017-08-30 02:07:44 +00:00
sta store+1
2017-09-01 01:38:49 +00:00
lda read_params::buffer+1
2017-08-30 02:07:44 +00:00
sta store+2
lda #' ' ; fill buffer with spaces
ldx #0
2017-08-29 03:58:09 +00:00
sta RAMWRTOFF
2017-09-01 05:39:06 +00:00
store: sta default_buffer,x ; self-modified
2017-08-29 03:58:09 +00:00
inx
2017-08-30 02:07:44 +00:00
bne store
sta RAMWRTON ; read file chunk
2017-08-29 03:58:09 +00:00
lda #$00
sta L0947
2017-08-30 01:47:15 +00:00
jsr read_file
pha ; copy read buffer main>aux
2017-08-29 03:58:09 +00:00
lda #$00
2017-09-01 01:20:36 +00:00
sta STARTLO
sta DESTINATIONLO
2017-08-29 03:58:09 +00:00
lda #$FF
2017-09-01 01:20:36 +00:00
sta ENDLO
2017-09-01 01:38:49 +00:00
lda read_params::buffer+1
2017-09-01 01:20:36 +00:00
sta DESTINATIONHI
sta STARTHI
sta ENDHI
sec ; main>aux
2017-08-29 03:58:09 +00:00
jsr AUXMOVE
pla
2017-08-30 02:07:44 +00:00
beq end
cmp #$4C ; ???
2017-08-30 02:07:44 +00:00
beq done
brk ; ????
done: lda #$01
2017-08-29 03:58:09 +00:00
sta L0947
2017-08-30 02:07:44 +00:00
end: rts
2017-09-02 03:10:21 +00:00
.endproc
2017-08-29 03:58:09 +00:00
2017-09-02 16:44:33 +00:00
.proc calc_window_size
sec
lda window_params::box::width
2017-10-08 03:22:39 +00:00
sbc window_params::box::hoff
2017-09-01 15:48:46 +00:00
sta window_width
lda window_params::box::width+1
2017-10-08 03:22:39 +00:00
sbc window_params::box::hoff+1
2017-09-01 15:48:46 +00:00
sta window_width+1
2017-09-02 04:24:35 +00:00
2017-08-29 03:58:09 +00:00
sec
lda window_params::box::height
2017-10-08 03:22:39 +00:00
sbc window_params::box::voff
2017-09-01 15:48:46 +00:00
sta window_height
2017-09-02 16:44:33 +00:00
;; fall through
.endproc
2017-09-16 04:44:41 +00:00
;;; ==================================================
2017-09-16 21:20:41 +00:00
.proc calc_line_position
lda window_params::box::height
2017-08-29 03:58:09 +00:00
sta L0965
lda window_params::box::height+1
2017-08-29 03:58:09 +00:00
sta L0966
2017-09-02 04:24:35 +00:00
2017-09-02 16:44:33 +00:00
lda #0
2017-08-29 03:58:09 +00:00
sta L0968
sta L0969
2017-09-02 16:44:33 +00:00
loop: lda L0966
bne :+
2017-08-29 03:58:09 +00:00
lda L0965
2017-09-02 04:24:35 +00:00
cmp #$0A ; line spacing = 10
2017-09-02 16:44:33 +00:00
bcc end
: sec
2017-08-29 03:58:09 +00:00
lda L0965
2017-09-02 04:24:35 +00:00
sbc #$0A ; line spacing = 10
2017-08-29 03:58:09 +00:00
sta L0965
2017-09-02 16:44:33 +00:00
bcs :+
2017-08-29 03:58:09 +00:00
dec L0966
2017-09-02 16:44:33 +00:00
: inc L0968
bne loop
2017-08-29 03:58:09 +00:00
inc L0969
2017-09-02 16:44:33 +00:00
jmp loop
end: rts
.endproc
2017-08-29 03:58:09 +00:00
2017-09-16 04:44:41 +00:00
;;; ==================================================
2017-09-03 05:52:38 +00:00
.proc div_by_16 ; input in $06/$07, output in a
ldx #4
2017-09-02 03:10:21 +00:00
loop: clc
2017-08-29 03:58:09 +00:00
ror $07
ror $06
dex
2017-09-02 03:10:21 +00:00
bne loop
2017-08-29 03:58:09 +00:00
lda $06
rts
2017-09-02 03:10:21 +00:00
.endproc
2017-08-29 03:58:09 +00:00
2017-09-03 05:52:38 +00:00
.proc mul_by_16 ; input in a, output in $06/$07
2017-09-02 03:10:21 +00:00
sta $06
2017-09-03 05:52:38 +00:00
lda #0
2017-08-29 03:58:09 +00:00
sta $07
2017-09-03 05:52:38 +00:00
ldx #4
2017-09-02 03:10:21 +00:00
loop: clc
2017-08-29 03:58:09 +00:00
rol $06
rol $07
dex
2017-09-02 03:10:21 +00:00
bne loop
2017-08-29 03:58:09 +00:00
rts
2017-09-02 03:10:21 +00:00
.endproc
2017-08-29 03:58:09 +00:00
2017-09-18 15:10:19 +00:00
.proc redraw_screen
lda #<JUMP_TABLE_REDRAW_ALL
sta call_main_addr
lda #>JUMP_TABLE_REDRAW_ALL
2017-09-02 02:06:14 +00:00
sta call_main_addr+1
jsr call_main_trampoline
2017-08-29 03:58:09 +00:00
rts
2017-09-02 02:06:14 +00:00
.endproc
2017-08-29 03:58:09 +00:00
2017-09-16 04:44:41 +00:00
;;; ==================================================
;;; Restore the font glyph width table when switching
;;; back to proportional mode.
.proc restore_proportional_font_table_if_needed
2017-09-01 01:38:49 +00:00
lda fixed_mode_flag ; if not fixed (i.e. proportional)
beq done ; then exit
2017-09-16 03:04:56 +00:00
start := font_width_backup
end := font_width_backup + $7E
dest := font_width_table
2017-09-01 01:38:49 +00:00
lda #<start
2017-09-01 01:20:36 +00:00
sta STARTLO
lda #<end
sta ENDLO
lda #>start
2017-09-01 01:20:36 +00:00
sta STARTHI
sta ENDHI
2017-09-01 01:38:49 +00:00
lda #>dest
2017-09-01 01:20:36 +00:00
sta DESTINATIONHI
2017-09-01 01:38:49 +00:00
lda #<dest
2017-09-01 01:20:36 +00:00
sta DESTINATIONLO
sec ; main>aux
2017-08-29 03:58:09 +00:00
jsr AUXMOVE
done: rts
2017-09-01 01:38:49 +00:00
.endproc
2017-08-29 03:58:09 +00:00
2017-09-16 04:44:41 +00:00
;;; ==================================================
;;; Overwrite the font glyph width table (with 7s)
;;; when switching to fixed width mode.
.proc assign_fixed_font_width_table_if_needed
2017-09-01 02:05:41 +00:00
lda fixed_mode_flag ; if not fixed (i.e. proportional)
beq end ; then exit
2017-09-16 03:04:56 +00:00
ldx font_size_count
2017-09-02 02:35:50 +00:00
lda #7 ; 7 pixels/character
2017-09-16 03:04:56 +00:00
loop: sta font_width_table - 1,x
2017-08-29 03:58:09 +00:00
dex
2017-09-01 01:38:49 +00:00
bne loop
2017-09-01 02:05:41 +00:00
end: rts
2017-09-01 01:38:49 +00:00
.endproc
2017-08-29 03:58:09 +00:00
2017-09-02 04:24:35 +00:00
;;; ==================================================
;;; Title Bar (Proportional/Fixed mode button)
.proc on_title_bar_click
2017-09-09 03:45:11 +00:00
lda input_params::xcoord+1 ; mouse x high byte?
2017-09-01 15:15:05 +00:00
cmp mode_box_left+1
bne :+
2017-09-09 03:45:11 +00:00
lda input_params::xcoord
2017-09-01 15:15:05 +00:00
cmp mode_box_left
: bcc ignore
2017-09-02 04:24:35 +00:00
;; Toggle the state and redraw
lda fixed_mode_flag
beq set_flag
dec fixed_mode_flag ; clear flag (mode = proportional)
2017-09-16 04:44:41 +00:00
jsr restore_proportional_font_table_if_needed
jmp redraw
2017-08-29 03:58:09 +00:00
set_flag:
inc fixed_mode_flag ; set flag (mode = fixed)
redraw: jsr draw_mode
2017-09-01 01:38:49 +00:00
jsr draw_content
sec ; Click consumed
2017-08-29 03:58:09 +00:00
rts
ignore: clc ; Click ignored
2017-08-29 03:58:09 +00:00
rts
.endproc
2017-08-29 03:58:09 +00:00
fixed_str: A2D_DEFSTRING "Fixed "
prop_str: A2D_DEFSTRING "Proportional"
2017-09-01 15:48:46 +00:00
label_width := 50
title_bar_height := 12
2017-09-01 15:15:05 +00:00
.proc mode_box ; bounding box for mode label
left: .word 0
top: .word 0
addr: .word A2D_SCREEN_ADDR
stride: .word A2D_SCREEN_STRIDE
2017-10-08 03:22:39 +00:00
hoff: .word 0
voff: .word 0
2017-09-01 15:15:05 +00:00
width: .word 80
height: .word 10
.endproc
mode_box_left := mode_box::left ; forward refs to mode_box::left don't work?
2017-09-02 02:35:50 +00:00
;; https://github.com/cc65/cc65/issues/479
2017-09-01 15:15:05 +00:00
.proc mode_pos
left: .word 0 ; horizontal text offset
base: .word 10 ; vertical text offset (to baseline)
.endproc
.proc calc_and_draw_mode
sec
lda window_params::box::top
2017-09-01 15:48:46 +00:00
sbc #title_bar_height
sta mode_box::top
2017-08-29 03:58:09 +00:00
clc
lda window_params::box::left
2017-09-01 15:48:46 +00:00
adc window_width
2017-08-29 03:58:09 +00:00
pha
lda window_params::box::left+1
2017-09-01 15:48:46 +00:00
adc window_width+1
2017-08-29 03:58:09 +00:00
tax
sec
pla
2017-09-01 15:48:46 +00:00
sbc #<label_width
2017-09-01 15:15:05 +00:00
sta mode_box::left
2017-08-29 03:58:09 +00:00
txa
2017-09-01 15:48:46 +00:00
sbc #>label_width
2017-09-01 15:15:05 +00:00
sta mode_box::left+1
2017-09-01 02:05:41 +00:00
;; fall through...
.endproc
2017-09-01 02:05:41 +00:00
.proc draw_mode
2017-09-15 08:09:42 +00:00
A2D_CALL A2D_SET_BOX, mode_box
2017-09-09 19:18:06 +00:00
A2D_CALL A2D_SET_POS, mode_pos
lda fixed_mode_flag
beq else ; is proportional?
2017-08-31 03:30:46 +00:00
A2D_CALL A2D_DRAW_TEXT, fixed_str
jmp endif
2017-08-31 03:30:46 +00:00
else: A2D_CALL A2D_DRAW_TEXT, prop_str
2017-09-01 15:15:05 +00:00
2017-08-31 15:10:51 +00:00
endif: ldx #$0F
2017-09-01 15:32:29 +00:00
loop: lda default_box,x
sta window_params::box,x
2017-08-29 03:58:09 +00:00
dex
bpl loop
2017-09-14 04:35:23 +00:00
A2D_CALL A2D_SET_BOX, window_params::box
2017-08-29 03:58:09 +00:00
rts
.endproc