a2d/desk.acc/show.text.file.s

1406 lines
36 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"
2018-02-27 04:13:18 +00:00
.include "../inc/apple2.inc"
2017-09-04 19:56:41 +00:00
.include "../inc/prodos.inc"
2018-01-29 05:18:00 +00:00
.include "../mgtk.inc"
.include "../desktop.inc" ; get/clear selection, font
2018-02-07 02:42:00 +00:00
.include "../macros.inc"
.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
2018-03-05 05:36:00 +00:00
;;; ============================================================
2017-09-01 05:53:07 +00:00
;;; 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
2018-03-05 05:36:00 +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
2018-02-27 04:51:23 +00:00
DEFINE_OPEN_PARAMS open_params, pathbuff, $C00
2017-08-29 15:40:35 +00:00
2017-09-01 05:39:06 +00:00
default_buffer := $1200
2018-02-27 04:51:23 +00:00
DEFINE_READ_PARAMS read_params, default_buffer, $100
DEFINE_GET_EOF_PARAMS get_eof_params
DEFINE_SET_MARK_PARAMS set_mark_params, 0
DEFINE_CLOSE_PARAMS close_params
2017-08-29 16:08:46 +00:00
2018-02-27 04:51:23 +00:00
.proc pathbuff ; 1st byte is length, rest is full path
2017-09-02 01:32:37 +00:00
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
2018-01-31 08:05:54 +00:00
da_window_id := 100
2017-09-01 15:15:05 +00:00
2017-08-29 03:58:09 +00:00
L095A: .byte $00
2018-02-07 02:42:00 +00:00
L095B: .word $1FA
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
2018-02-07 02:42:00 +00:00
L0965: .byte 0
L0966: .word 0
L0968: .word 0
L096A: .word 0
L096C: .word 0
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
2018-01-30 04:14:34 +00:00
.proc event_params
2018-01-30 05:11:32 +00:00
kind: .byte 0
2017-09-09 03:45:11 +00:00
coords: ; spills into target query
2018-01-31 08:05:54 +00:00
mousex: .word 0
mousey: .word 0
2017-09-09 03:45:11 +00:00
.endproc
2018-01-31 08:05:54 +00:00
2018-01-30 04:14:34 +00:00
.proc findwindow_params
2018-01-31 08:05:54 +00:00
which_area: .byte 0
window_id: .byte 0
.endproc
2018-01-30 04:14:34 +00:00
.proc growwindow_params
2018-01-31 08:05:54 +00:00
window_id: .byte da_window_id
mousex: .word 0
mousey: .word 0
it_grew: .byte 0
2017-09-02 02:54:04 +00:00
.endproc
2017-08-31 03:30:46 +00:00
2018-01-30 04:14:34 +00:00
.proc trackgoaway_params ; queried after close clicked to see if aborted/finished
2018-01-30 05:11:32 +00:00
goaway: .byte 0 ; 0 = aborted, 1 = clicked
2017-08-31 03:30:46 +00:00
.endproc
2018-01-31 08:05:54 +00:00
.byte 0,0 ; ???
2018-01-30 04:14:34 +00:00
.proc findcontrol_params ; queried after a client click to identify target
2018-01-31 08:05:54 +00:00
mousex: .word 0
mousey: .word 0
which_ctl: .byte 0 ; 0 = client, 1 = vscroll, 2 = hscroll
which_part: .byte 0 ; 1 = up, 2 = down, 3 = above, 4 = below, 5 = thumb
2017-08-31 03:30:46 +00:00
.endproc
2017-09-01 16:30:29 +00:00
;; param block used in dead code (resize?)
2018-01-31 08:05:54 +00:00
.proc setctlmax_params
which_ctl: .byte 0
ctlmax: .byte 0
;; needs one more byte?
2017-09-02 02:54:04 +00:00
.endproc
2017-08-31 15:10:51 +00:00
2018-01-30 04:14:34 +00:00
.proc updatethumb_params ; called to update scroll bar position
2018-01-31 08:05:54 +00:00
which_ctl: .byte 0 ; 1 = vscroll, 2 = hscroll
thumbpos: .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
2018-01-31 08:05:54 +00:00
.proc trackthumb_params
which_ctl: .byte 0 ; 1 = vscroll, 2 = hscroll
mousex: .word 0
mousey: .word 0
thumbpos: .byte 0 ; position
thumbmoved: .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
2018-01-31 08:05:54 +00:00
.proc drawtext_params
textptr: .addr 0 ; address
textlen: .byte 0 ; length
2017-09-01 05:12:02 +00:00
.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
2018-01-30 05:11:32 +00:00
.proc winfo
2018-01-31 08:05:54 +00:00
window_id: .byte da_window_id ; window identifier
2018-01-30 05:11:32 +00:00
options: .byte MGTK::option_go_away_box; window flags (2=include close port)
2017-09-02 05:08:43 +00:00
title: .addr $1000 ; overwritten to point at filename
2018-01-29 05:18:00 +00:00
hscroll:.byte MGTK::scroll_option_none
vscroll:.byte MGTK::scroll_option_normal
2018-01-30 04:49:42 +00:00
hthumbmax: .byte 32
hthumbpos: .byte 0
vthumbmax: .byte 255
vthumbpos: .byte 0
2018-01-30 05:11:32 +00:00
status: .byte 0
reserved: .byte 0
2018-01-30 04:49:42 +00:00
mincontwidth: .word 200
mincontlength: .word 51
maxcontwidth: .word default_width
maxcontlength: .word default_height
2017-08-31 03:41:54 +00:00
2018-01-31 08:05:54 +00:00
port:
DEFINE_POINT default_left, default_top, viewloc
2018-01-30 04:49:42 +00:00
mapbits: .addr MGTK::screen_mapbits
mapwidth: .word MGTK::screen_mapwidth
2018-01-31 08:05:54 +00:00
DEFINE_RECT 0, 0, default_width, default_height, maprect
2017-09-01 15:32:29 +00:00
pattern:.res 8, $00
2018-01-30 05:11:32 +00:00
colormasks: .byte MGTK::colormask_and, MGTK::colormask_or
2018-01-31 08:05:54 +00:00
penloc: DEFINE_POINT 0, 0
2018-01-30 05:11:32 +00:00
penwidth: .byte 1
penheight: .byte 1
penmode: .byte 0
textback: .byte $7F
textfont: .addr DEFAULT_FONT
2018-01-31 08:05:54 +00:00
2018-01-30 05:11:32 +00:00
nextwinfo: .addr 0
.endproc
2017-09-01 15:15:05 +00:00
2018-01-30 05:11:32 +00:00
;; gets copied over winfo::port after mode is drawn
2018-01-31 08:05:54 +00:00
.proc default_port
viewloc: DEFINE_POINT default_left, default_top
2018-01-30 04:49:42 +00:00
mapbits: .word MGTK::screen_mapbits
mapwidth: .word MGTK::screen_mapwidth
2018-01-31 08:05:54 +00:00
maprect: DEFINE_RECT 0, 0, default_width, 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
2018-02-27 04:51:23 +00:00
sta pathbuff::length
2018-02-19 19:33:13 +00:00
lda selected_file_count
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
2018-02-27 04:51:23 +00:00
;; Copy path (prefix) into pathbuff 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
2018-02-07 02:42:00 +00:00
copy16 path_table,x, src
2017-09-02 01:32:37 +00:00
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
2018-02-27 04:51:23 +00:00
: copy16 #(pathbuff::data), dst
jsr copy_pathbuff ; 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
2018-02-27 04:51:23 +00:00
inc pathbuff::length
2017-09-02 01:32:37 +00:00
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.
2018-02-19 19:33:13 +00:00
: lda selected_file_list ; 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
2018-02-07 02:42:00 +00:00
copy16 file_table,x, src
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
2018-01-30 05:11:32 +00:00
sta winfo::title
2017-09-02 01:32:37 +00:00
lda src+1
2017-09-02 01:58:36 +00:00
adc #0
2018-01-30 05:11:32 +00:00
sta winfo::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
2018-02-27 04:51:23 +00:00
: jsr copy_pathbuff ; copy x bytes (src) to (dst)
2017-09-02 01:58:36 +00:00
2017-09-04 03:07:05 +00:00
;; Clear selection (why???)
2018-02-07 02:42:00 +00:00
copy16 #JUMP_TABLE_CLEAR_SEL, call_main_addr
2017-09-02 02:06:14 +00:00
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
2018-02-27 04:51:23 +00:00
.proc copy_pathbuff ; copy x bytes from src to dst
2017-09-02 01:32:37 +00:00
ldy #0 ; incrementing path length and dst
loop: lda (src),y
sta (dst),y
2017-08-29 03:58:09 +00:00
iny
2018-02-27 04:51:23 +00:00
inc pathbuff::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
2018-02-18 20:49:59 +00:00
ldx font_last_char
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
2018-01-30 05:11:32 +00:00
MGTK_CALL MGTK::OpenWindow, winfo
MGTK_CALL MGTK::SetPort, winfo::port
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
2018-01-29 16:38:23 +00:00
MGTK_CALL MGTK::FlushEvents
2017-09-02 03:10:21 +00:00
;; fall through
2017-09-01 05:12:02 +00:00
.endproc
2018-03-05 05:36:00 +00:00
;;; ============================================================
2017-09-02 04:24:35 +00:00
;;; Main Input Loop
input_loop:
2018-01-30 04:14:34 +00:00
MGTK_CALL MGTK::GetEvent, event_params
lda event_params
2017-09-01 02:05:41 +00:00
cmp #1 ; was clicked?
bne input_loop ; nope, keep waiting
2018-01-30 04:14:34 +00:00
MGTK_CALL MGTK::FindWindow, event_params::coords
2018-01-31 08:05:54 +00:00
lda findwindow_params::window_id ; in our window?
cmp #da_window_id
bne input_loop
2017-09-01 05:39:06 +00:00
;; which part of the window?
2018-01-31 08:05:54 +00:00
lda findwindow_params::which_area
2018-01-29 05:18:00 +00:00
cmp #MGTK::area_close_box
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
2018-01-31 08:05:54 +00:00
ldx event_params::mousex
stx growwindow_params::mousex
stx findcontrol_params::mousex
ldx event_params::mousex+1
stx growwindow_params::mousex+1
stx findcontrol_params::mousex+1
ldx event_params::mousey
stx growwindow_params::mousey
stx findcontrol_params::mousey
2017-09-01 05:39:06 +00:00
2018-01-29 05:18:00 +00:00
cmp #MGTK::area_dragbar
2017-09-01 05:39:06 +00:00
beq title
2018-01-29 05:18:00 +00:00
cmp #MGTK::area_grow_box ; 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
2018-03-05 05:36:00 +00:00
;;; ============================================================
2017-09-02 04:24:35 +00:00
;;; Close Button
.proc on_close_click
2018-01-30 04:14:34 +00:00
MGTK_CALL MGTK::TrackGoAway, trackgoaway_params
2018-01-30 05:11:32 +00:00
lda trackgoaway_params::goaway ; 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
2018-01-30 05:11:32 +00:00
MGTK_CALL MGTK::CloseWindow, winfo
2018-02-05 03:13:21 +00:00
DESKTOP_CALL DT_REDRAW_ICONS
2017-08-30 06:47:18 +00:00
rts ; exits input loop
.endproc
2017-08-29 03:58:09 +00:00
2018-03-05 05:36:00 +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
2018-01-30 04:14:34 +00:00
MGTK_CALL MGTK::GrowWindow, growwindow_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
2018-01-31 08:05:54 +00:00
cmp winfo::maprect::x2+1
2017-09-02 02:39:29 +00:00
bne :+
2017-09-01 16:30:29 +00:00
lda #<max_width
2018-01-31 08:05:54 +00:00
cmp winfo::maprect::x2
2017-09-02 02:39:29 +00:00
: bcs wider
2017-09-01 16:30:29 +00:00
2018-02-07 02:42:00 +00:00
copy16 #max_width, winfo::maprect::x2
2017-08-29 03:58:09 +00:00
sec
2018-01-31 08:05:54 +00:00
lda winfo::maprect::x2
2017-09-01 15:48:46 +00:00
sbc window_width
2018-01-31 08:05:54 +00:00
sta winfo::maprect::x1
lda winfo::maprect::x2+1
2017-09-01 15:48:46 +00:00
sbc window_width+1
2018-01-31 08:05:54 +00:00
sta winfo::maprect::x1+1
2018-01-30 05:11:32 +00:00
wider: lda winfo::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
2018-01-29 05:18:00 +00:00
and #(<~MGTK::scroll_option_active) ; disable scroll
jmp :+
2017-08-29 03:58:09 +00:00
2018-01-29 05:18:00 +00:00
enable: ora #MGTK::scroll_option_active ; enable scroll
2018-01-30 05:11:32 +00:00
: sta winfo::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
2018-02-07 02:42:00 +00:00
sta $06+1
2017-09-03 05:52:38 +00:00
jsr div_by_16
2018-01-31 08:05:54 +00:00
sta setctlmax_params::ctlmax
2018-01-29 05:18:00 +00:00
lda #MGTK::ctl_horizontal_scroll_bar
2018-01-31 08:05:54 +00:00
sta setctlmax_params::which_ctl
MGTK_CALL MGTK::SetCtlMax, setctlmax_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
2018-03-05 05:36:00 +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?
2018-01-30 04:14:34 +00:00
MGTK_CALL MGTK::FindControl, findcontrol_params
2018-01-31 08:05:54 +00:00
lda findcontrol_params::which_ctl
2018-01-29 05:18:00 +00:00
cmp #MGTK::ctl_vertical_scroll_bar
2017-08-31 03:41:54 +00:00
beq on_vscroll_click
2018-01-29 05:18:00 +00:00
cmp #MGTK::ctl_horizontal_scroll_bar
2017-09-01 05:39:06 +00:00
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
2018-03-05 05:36:00 +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
2018-01-29 05:18:00 +00:00
lda #MGTK::ctl_vertical_scroll_bar
2018-01-31 08:05:54 +00:00
sta trackthumb_params::which_ctl
sta updatethumb_params::which_ctl
lda findcontrol_params::which_part
2018-01-29 05:18:00 +00:00
cmp #MGTK::part_thumb
2017-08-31 03:41:54 +00:00
beq on_vscroll_thumb_click
2018-01-29 05:18:00 +00:00
cmp #MGTK::part_page_down
2017-08-31 03:41:54 +00:00
beq on_vscroll_below_click
2018-01-29 05:18:00 +00:00
cmp #MGTK::part_page_up
2017-08-31 03:41:54 +00:00
beq on_vscroll_above_click
2018-01-29 05:18:00 +00:00
cmp #MGTK::part_up_arrow
2017-08-31 03:41:54 +00:00
beq on_vscroll_up_click
2018-01-29 05:18:00 +00:00
cmp #MGTK::part_down_arrow
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
2018-01-31 08:05:54 +00:00
jsr do_trackthumb
lda trackthumb_params::thumbmoved
2017-08-31 03:41:54 +00:00
beq end
2018-01-31 08:05:54 +00:00
lda trackthumb_params::thumbpos
sta updatethumb_params::thumbpos
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
2018-01-30 05:11:32 +00:00
loop: lda winfo::vthumbpos
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
2018-01-30 05:11:32 +00:00
lda winfo::vthumbpos
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
2018-01-31 08:05:54 +00:00
store: sta updatethumb_params::thumbpos
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
2018-01-30 05:11:32 +00:00
loop : lda winfo::vthumbpos
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
2018-01-31 08:05:54 +00:00
sta updatethumb_params::thumbpos
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
2018-01-30 05:11:32 +00:00
loop: lda winfo::vthumbpos
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
2018-01-30 05:11:32 +00:00
lda winfo::vthumbpos
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
2018-01-31 08:05:54 +00:00
store: sta updatethumb_params::thumbpos
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
2018-01-30 05:11:32 +00:00
loop: lda winfo::vthumbpos
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
2018-01-31 08:05:54 +00:00
sta updatethumb_params::thumbpos
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
2018-03-05 05:36:00 +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
2018-01-29 05:18:00 +00:00
lda #MGTK::ctl_horizontal_scroll_bar
2018-01-31 08:05:54 +00:00
sta trackthumb_params::which_ctl
sta updatethumb_params::which_ctl
lda findcontrol_params::which_part
2018-01-29 05:18:00 +00:00
cmp #MGTK::part_thumb
2017-09-01 05:12:02 +00:00
beq on_hscroll_thumb_click
2018-01-29 05:18:00 +00:00
cmp #MGTK::part_page_right
2017-09-01 05:12:02 +00:00
beq on_hscroll_after_click
2018-01-29 05:18:00 +00:00
cmp #MGTK::part_page_left
2017-09-01 05:12:02 +00:00
beq on_hscroll_before_click
2018-01-29 05:18:00 +00:00
cmp #MGTK::part_left_arrow
2017-09-01 05:12:02 +00:00
beq on_hscroll_left_click
2018-01-29 05:18:00 +00:00
cmp #MGTK::part_right_arrow
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
2018-01-31 08:05:54 +00:00
jsr do_trackthumb
lda trackthumb_params::thumbmoved
2017-09-01 05:12:02 +00:00
beq end
2018-01-31 08:05:54 +00:00
lda trackthumb_params::thumbpos
2017-09-03 05:52:38 +00:00
jsr mul_by_16
2018-02-07 02:42:00 +00:00
copy16 $06, winfo::maprect::x1
2017-08-29 03:58:09 +00:00
clc
2018-01-31 08:05:54 +00:00
lda winfo::maprect::x1
2017-09-01 15:48:46 +00:00
adc window_width
2018-01-31 08:05:54 +00:00
sta winfo::maprect::x2
lda winfo::maprect::x1+1
2017-09-01 15:48:46 +00:00
adc window_width+1
2018-01-31 08:05:54 +00:00
sta winfo::maprect::x2+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
2018-01-30 05:11:32 +00:00
lda winfo::hthumbmax
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
2018-01-30 05:11:32 +00:00
lda winfo::hthumbmax
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
2018-01-30 05:11:32 +00:00
loop: lda winfo::hthumbpos
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
2018-01-30 05:11:32 +00:00
lda winfo::hthumbpos
2017-09-01 05:12:02 +00:00
delta: adc #1 ; self-modified
bmi overflow
2018-01-30 05:11:32 +00:00
cmp winfo::hthumbmax
2017-09-01 05:12:02 +00:00
beq store
bcc store
2018-01-30 05:11:32 +00:00
lda winfo::hthumbmax
2017-09-01 05:12:02 +00:00
jmp store
overflow:
lda #0
2018-01-30 05:11:32 +00:00
store: sta winfo::hthumbpos
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
2018-03-05 05:36:00 +00:00
;;; ============================================================
2017-09-02 04:24:35 +00:00
;;; UI Helpers
2018-02-03 04:10:19 +00:00
;; Used at start of thumb event_kind_drag
2018-01-31 08:05:54 +00:00
.proc do_trackthumb
2018-02-07 02:42:00 +00:00
copy16 event_params::mousex, trackthumb_params::mousex
2018-01-31 08:05:54 +00:00
lda event_params::mousey
sta trackthumb_params::mousey
MGTK_CALL MGTK::TrackThumb, trackthumb_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
2018-01-30 04:14:34 +00:00
MGTK_CALL MGTK::GetEvent, event_params
lda event_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
2018-01-30 05:11:32 +00:00
lda winfo::hthumbpos
2017-09-03 05:52:38 +00:00
jsr mul_by_16
2017-08-29 03:58:09 +00:00
clc
lda $06
2018-01-31 08:05:54 +00:00
sta winfo::maprect::x1
2017-09-01 15:48:46 +00:00
adc window_width
2018-01-31 08:05:54 +00:00
sta winfo::maprect::x2
2017-08-29 03:58:09 +00:00
lda $07
2018-01-31 08:05:54 +00:00
sta winfo::maprect::x1+1
2017-09-01 15:48:46 +00:00
adc window_width+1
2018-01-31 08:05:54 +00:00
sta winfo::maprect::x2+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
2018-01-31 08:05:54 +00:00
sta winfo::maprect::y1
sta winfo::maprect::y1+1
ldx updatethumb_params::thumbpos
2017-09-16 04:44:41 +00:00
loop: beq adjust_box_height
2017-08-29 03:58:09 +00:00
clc
2018-01-31 08:05:54 +00:00
lda winfo::maprect::y1
2017-08-31 15:17:06 +00:00
adc #50
2018-01-31 08:05:54 +00:00
sta winfo::maprect::y1
2017-09-02 02:39:29 +00:00
bcc :+
2018-01-31 08:05:54 +00:00
inc winfo::maprect::y1+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
2018-01-31 08:05:54 +00:00
lda winfo::maprect::y1
2017-09-01 15:48:46 +00:00
adc window_height
2018-01-31 08:05:54 +00:00
sta winfo::maprect::y2
lda winfo::maprect::y1+1
2017-09-01 15:48:46 +00:00
adc window_height+1
2018-01-31 08:05:54 +00:00
sta winfo::maprect::y2+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
2018-02-07 02:42:00 +00:00
sta L096A+1
2018-01-31 08:05:54 +00:00
ldx updatethumb_params::thumbpos
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 :+
2018-02-07 02:42:00 +00:00
inc L096A+1
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
2018-01-31 08:05:54 +00:00
sta updatethumb_params::which_ctl
2018-02-07 02:42:00 +00:00
copy16 winfo::maprect::x1, $06
2017-09-03 05:52:38 +00:00
jsr div_by_16
2018-01-31 08:05:54 +00:00
sta updatethumb_params::thumbpos
2018-01-30 04:14:34 +00:00
MGTK_CALL MGTK::UpdateThumb, updatethumb_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
2018-01-31 08:05:54 +00:00
.proc update_vscroll ; updatethumb_params::thumbpos set by caller
2017-08-31 15:17:06 +00:00
lda #1
2018-01-31 08:05:54 +00:00
sta updatethumb_params::which_ctl
2018-01-30 04:14:34 +00:00
MGTK_CALL MGTK::UpdateThumb, updatethumb_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
2018-02-05 03:13:21 +00:00
DESKTOP_CALL DT_REDRAW_ICONS
2018-01-30 05:11:32 +00:00
MGTK_CALL MGTK::SetPort, winfo::port
lda winfo::hscroll
2017-09-03 03:49:28 +00:00
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
2018-01-30 05:11:32 +00:00
: lda winfo::vthumbpos
2018-01-31 08:05:54 +00:00
sta updatethumb_params::thumbpos
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
2018-01-29 05:18:00 +00:00
MGTK_CALL MGTK::SetPattern, white_pattern
2018-01-31 08:05:54 +00:00
MGTK_CALL MGTK::PaintRect, winfo::maprect::x1
2018-01-29 05:18:00 +00:00
MGTK_CALL MGTK::SetPattern, 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
2018-03-05 05:36:00 +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
2018-02-27 04:51:23 +00:00
sta read_params::data_buffer
2017-08-29 03:58:09 +00:00
sta $06
2017-09-01 05:39:06 +00:00
lda #>default_buffer
2018-02-27 04:51:23 +00:00
sta read_params::data_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
2018-02-07 02:42:00 +00:00
sta L096C+1
2017-08-29 03:58:09 +00:00
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:
2018-02-07 02:42:00 +00:00
lda L096C+1
cmp L096A+1
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
2018-01-29 05:18:00 +00:00
: MGTK_CALL MGTK::MoveTo, 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
2018-02-07 02:42:00 +00:00
sta L095B+1
jsr find_text_run
2017-08-29 03:58:09 +00:00
bcs L0ED7
clc
2018-01-31 08:05:54 +00:00
lda drawtext_params::textlen
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 :+
2018-02-07 02:42:00 +00:00
lda L096C+1
cmp L0968+1
2017-08-29 03:58:09 +00:00
beq L0ED7
2017-09-15 08:09:42 +00:00
: inc L096C
bne :+
2018-02-07 02:42:00 +00:00
inc L096C+1
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
2018-03-05 05:36:00 +00:00
;;; ============================================================
2017-09-16 04:44:41 +00:00
2017-09-01 01:38:49 +00:00
.proc L0EDB ; ???
2018-02-07 02:42:00 +00:00
copy16 #506, L095B
copy16 #3, line_pos::left
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
2018-03-05 05:36:00 +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
2018-01-31 08:05:54 +00:00
sta drawtext_params::textlen
2018-02-07 02:42:00 +00:00
copy16 $06, drawtext_params::textptr
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
2018-01-31 08:05:54 +00:00
more: ldy drawtext_params::textlen
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
2018-02-27 04:13:18 +00:00
cmp #CHAR_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
2018-02-27 04:13:18 +00:00
: cmp #CHAR_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
2018-02-07 02:42:00 +00:00
: lda L095B+1
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 :+
2018-01-31 08:05:54 +00:00
inc drawtext_params::textlen
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 :+
2018-01-31 08:05:54 +00:00
sta drawtext_params::textlen
2017-08-29 03:58:09 +00:00
lda L0946
sta L0945
2018-01-31 08:05:54 +00:00
: inc drawtext_params::textlen
;; fall through
.endproc
2017-09-16 05:05:41 +00:00
finish_text_run: jsr draw_text_run
2018-01-31 08:05:54 +00:00
ldy drawtext_params::textlen
2017-08-29 03:58:09 +00:00
lda ($06),y
2018-02-27 04:13:18 +00:00
cmp #CHAR_TAB
2017-09-16 05:05:41 +00:00
beq tab
2018-02-27 04:13:18 +00:00
cmp #CHAR_RETURN
2017-09-16 05:05:41 +00:00
bne :+
2018-01-31 08:05:54 +00:00
tab: inc drawtext_params::textlen
2017-09-16 05:05:41 +00:00
: clc
2017-08-29 03:58:09 +00:00
rts
2018-03-05 05:36:00 +00:00
;;; ============================================================
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
2018-02-07 02:42:00 +00:00
: copy16 times70,x, line_pos::left
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
2018-03-05 05:36:00 +00:00
;;; ============================================================
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
2018-01-31 08:05:54 +00:00
lda drawtext_params::textlen
2017-09-16 03:04:56 +00:00
beq end
2018-01-31 08:05:54 +00:00
MGTK_CALL MGTK::DrawText, drawtext_params
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
2018-03-05 05:36:00 +00:00
;;; ============================================================
2017-09-16 04:44:41 +00:00
.proc ensure_page_buffered
2018-01-31 08:05:54 +00:00
lda drawtext_params::textptr+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
2018-01-31 08:05:54 +00:00
dec drawtext_params::textptr+1
2018-02-07 02:42:00 +00:00
copy16 drawtext_params::textptr, $06
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
2018-02-27 04:51:23 +00:00
lda read_params::data_buffer+1
cmp #>default_buffer
bne :+
2018-02-27 04:51:23 +00:00
inc read_params::data_buffer+1
: rts
.endproc
2017-08-29 03:58:09 +00:00
2018-03-05 05:36:00 +00:00
;;; ============================================================
2017-09-16 04:44:41 +00:00
.proc read_file_page
2018-02-27 04:51:23 +00:00
copy16 read_params::data_buffer, store+1
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
2018-02-27 04:51:23 +00:00
lda read_params::data_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
2018-01-31 08:05:54 +00:00
lda winfo::maprect::x2
sbc winfo::maprect::x1
2017-09-01 15:48:46 +00:00
sta window_width
2018-01-31 08:05:54 +00:00
lda winfo::maprect::x2+1
sbc winfo::maprect::x1+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
2018-01-31 08:05:54 +00:00
lda winfo::maprect::y2
sbc winfo::maprect::y1
2017-09-01 15:48:46 +00:00
sta window_height
2017-09-02 16:44:33 +00:00
;; fall through
.endproc
2018-03-05 05:36:00 +00:00
;;; ============================================================
2017-09-16 04:44:41 +00:00
2017-09-16 21:20:41 +00:00
.proc calc_line_position
2018-02-07 02:42:00 +00:00
copy16 winfo::maprect::y2, L0965
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
2018-02-07 02:42:00 +00:00
sta L0968+1
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
2018-02-07 02:42:00 +00:00
inc L0968+1
2017-09-02 16:44:33 +00:00
jmp loop
end: rts
.endproc
2017-08-29 03:58:09 +00:00
2018-03-05 05:36:00 +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
2018-02-07 02:42:00 +00:00
copy16 #JUMP_TABLE_REDRAW_ALL, call_main_addr
2017-09-02 02:06:14 +00:00
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
2018-03-05 05:36:00 +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
2018-03-05 05:36:00 +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
2018-02-18 20:49:59 +00:00
ldx font_last_char
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
2018-03-05 05:36:00 +00:00
;;; ============================================================
2017-09-02 04:24:35 +00:00
;;; Title Bar (Proportional/Fixed mode button)
.proc on_title_bar_click
2018-01-31 08:05:54 +00:00
lda event_params::mousex+1 ; mouse x high byte?
2017-09-01 15:15:05 +00:00
cmp mode_box_left+1
bne :+
2018-01-31 08:05:54 +00:00
lda event_params::mousex
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
2018-01-29 05:18:00 +00:00
fixed_str: DEFINE_STRING "Fixed "
prop_str: DEFINE_STRING "Proportional"
2017-09-01 15:48:46 +00:00
label_width := 50
title_bar_height := 12
2018-01-30 04:49:42 +00:00
.proc mode_box ; bounding port for mode label
2017-09-01 15:15:05 +00:00
left: .word 0
top: .word 0
2018-01-30 04:49:42 +00:00
mapbits: .word MGTK::screen_mapbits
mapwidth: .word MGTK::screen_mapwidth
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
2018-01-31 08:05:54 +00:00
lda winfo::viewloc::ycoord
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
2018-01-31 08:05:54 +00:00
lda winfo::viewloc::xcoord
2017-09-01 15:48:46 +00:00
adc window_width
2017-08-29 03:58:09 +00:00
pha
2018-01-31 08:05:54 +00:00
lda winfo::viewloc::xcoord+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
2018-01-29 08:57:55 +00:00
MGTK_CALL MGTK::SetPortBits, mode_box
2018-01-29 05:18:00 +00:00
MGTK_CALL MGTK::MoveTo, mode_pos
lda fixed_mode_flag
beq else ; is proportional?
2018-01-29 05:18:00 +00:00
MGTK_CALL MGTK::DrawText, fixed_str
jmp endif
2018-01-29 05:18:00 +00:00
else: MGTK_CALL MGTK::DrawText, prop_str
2017-09-01 15:15:05 +00:00
2017-08-31 15:10:51 +00:00
endif: ldx #$0F
2018-01-31 08:05:54 +00:00
loop: lda default_port,x
2018-01-30 05:11:32 +00:00
sta winfo::port,x
2017-08-29 03:58:09 +00:00
dex
bpl loop
2018-01-30 05:11:32 +00:00
MGTK_CALL MGTK::SetPortBits, winfo::port
2017-08-29 03:58:09 +00:00
rts
.endproc