a2d/desk.acc/calculator.s

1760 lines
48 KiB
ArmAsm
Raw Normal View History

.setcpu "6502"
2017-09-06 05:19:45 +00:00
.include "apple2.inc"
2017-09-15 04:13:54 +00:00
.include "../inc/apple2.inc"
.include "../inc/auxmem.inc"
.include "../inc/applesoft.inc"
2017-09-06 05:19:45 +00:00
.include "../a2d.inc"
.include "../desktop.inc" ; needed to redraw DeskTop icons after window mode
.org $800
adjust_txtptr := $B1
2017-09-09 01:34:34 +00:00
;;; ==================================================
;;; Start of the code
2017-09-06 05:19:45 +00:00
start: jmp copy2aux
2017-09-06 05:19:45 +00:00
save_stack: .byte 0
2017-09-09 01:34:34 +00:00
;;; ==================================================
;;; Duplicate the DA (code and data) to AUX memory,
;;; then invoke the code in AUX.
2017-09-06 05:19:45 +00:00
.proc copy2aux
tsx
stx save_stack
start := call_init
end := da_end
dest := start
2017-09-09 01:34:34 +00:00
;; Copy the DA to AUX memory.
2017-09-06 05:19:45 +00:00
lda ROMIN2
lda #<start
sta STARTLO
lda #>start
sta STARTHI
lda #<end
sta ENDLO
lda #>end
sta ENDHI
lda #<dest
sta DESTINATIONLO
lda #>dest
sta DESTINATIONHI
sec ; main>aux
jsr AUXMOVE
2017-09-06 02:08:11 +00:00
2017-09-09 01:34:34 +00:00
;; Invoke it.
2017-09-06 05:19:45 +00:00
lda #<start
sta XFERSTARTLO
lda #>start
sta XFERSTARTHI
php
pla
2017-09-06 05:19:45 +00:00
ora #$40 ; set overflow: use aux zp/stack
pha
plp
2017-09-06 05:19:45 +00:00
sec ; control main>aux
jmp XFER
2017-09-06 05:19:45 +00:00
.endproc
2017-09-08 08:00:58 +00:00
;;; ==================================================
2017-09-06 05:19:45 +00:00
.proc exit_da
lda LCBANK1
2017-09-06 05:19:45 +00:00
lda LCBANK1
ldx save_stack
txs
rts
2017-09-06 05:19:45 +00:00
.endproc
2017-09-08 08:00:58 +00:00
;;; ==================================================
2017-09-06 05:19:45 +00:00
call_init:
lda ROMIN2
2017-09-15 04:22:27 +00:00
jmp init
2017-09-09 04:10:56 +00:00
;; Used after a drag-and-drop is completed;
;; redraws the window.
2017-09-18 15:10:19 +00:00
.proc redraw_screen_and_window
2017-09-08 06:40:01 +00:00
;; Redraw the desktop (by copying trampoline to ZP)
2017-09-08 06:40:01 +00:00
zp_stash := $20
lda LCBANK1
lda LCBANK1
2017-09-19 00:17:30 +00:00
ldx #sizeof_routine
2017-09-08 15:41:51 +00:00
: lda routine,x
2017-09-08 06:40:01 +00:00
sta zp_stash,x
dex
2017-09-08 15:41:51 +00:00
bpl :-
2017-09-08 06:40:01 +00:00
jsr zp_stash
2017-09-08 15:41:51 +00:00
2017-09-09 04:10:56 +00:00
;; Redraw window after drag
2017-09-06 05:19:45 +00:00
lda ROMIN2
2017-09-08 06:40:01 +00:00
lda #window_id
jsr check_visibility_and_draw_window
2017-09-08 15:41:51 +00:00
2017-09-09 01:34:34 +00:00
;; ???
lda LCBANK1
lda LCBANK1
2017-09-15 04:22:27 +00:00
bit offscreen_flag ; BUG: https://github.com/inexorabletash/a2d/issues/33
2017-09-08 15:41:51 +00:00
bmi skip
DESKTOP_CALL DESKTOP_REDRAW_ICONS
2017-09-06 05:19:45 +00:00
2017-09-09 01:34:34 +00:00
;; ???
2017-09-08 15:41:51 +00:00
skip: lda #0
sta offscreen_flag
2017-09-06 05:19:45 +00:00
lda ROMIN2
2017-09-14 04:35:23 +00:00
A2D_CALL A2D_QUERY_STATE, query_state_params
A2D_CALL A2D_SET_STATE, state_params
rts
2017-09-08 06:40:01 +00:00
.proc routine
sta RAMRDOFF
sta RAMWRTOFF
2017-09-18 15:10:19 +00:00
jsr JUMP_TABLE_REDRAW_ALL
sta RAMRDON
sta RAMWRTON
rts
2017-09-08 06:40:01 +00:00
.endproc
2017-09-19 00:17:30 +00:00
sizeof_routine := * - routine
2017-09-08 06:40:01 +00:00
.endproc
2017-09-08 08:00:58 +00:00
;;; ==================================================
;; Set when the client area is offscreen and
;; should not be painted.
offscreen_flag:
.byte 0
2017-09-09 01:34:34 +00:00
2017-09-09 04:10:56 +00:00
;; Called after window drag is complete
2017-09-10 02:11:05 +00:00
;; (called with window_id in A)
.proc check_visibility_and_draw_window
2017-09-14 04:35:23 +00:00
sta query_state_params_id
lda create_window_params_top
2017-09-10 01:11:01 +00:00
cmp #screen_height - 1
2017-09-08 06:40:01 +00:00
bcc :+
lda #$80
sta offscreen_flag
rts
;; Is skipping this responsible for display redraw bug?
;; https://github.com/inexorabletash/a2d/issues/34
2017-09-14 04:35:23 +00:00
: A2D_CALL A2D_QUERY_STATE, query_state_params
A2D_CALL A2D_SET_STATE, state_params
lda query_state_params_id
2017-09-08 06:40:01 +00:00
cmp #window_id
2017-09-10 01:11:01 +00:00
bne :+
2017-09-10 04:15:01 +00:00
jmp draw_background
2017-09-10 01:11:01 +00:00
: rts
2017-09-10 04:15:01 +00:00
.endproc
2017-09-08 08:00:58 +00:00
;;; ==================================================
;;; Call Params (and other data)
2017-09-09 04:10:56 +00:00
;; The following params blocks overlap for data re-use
2017-09-09 03:13:09 +00:00
.proc map_coords_params
id := *
screen := * + 1
2017-09-09 04:10:56 +00:00
screenx := * + 1 ; aligns with input_state::xcoord
screeny := * + 3 ; aligns with input_state::ycoord
2017-09-09 03:13:09 +00:00
client := * + 5
clientx := * + 5
clienty := * + 7
.endproc
2017-09-09 04:10:56 +00:00
.proc drag_params
id := *
xcoord := * + 1 ; aligns with input_state::xcoord
ycoord := * + 3 ; aligns with input_state::ycoord
2017-09-25 04:02:13 +00:00
moved := * + 5 ; ignored
2017-09-09 04:10:56 +00:00
.endproc
2017-09-09 03:13:09 +00:00
.proc input_state_params
2017-09-08 04:42:58 +00:00
state: .byte 0
2017-09-09 03:45:11 +00:00
xcoord := * ; if state is 0,1,2,4
ycoord := * + 2 ; "
key := * ; if state is 3
modifiers := * + 1 ; "
2017-09-06 06:24:21 +00:00
.endproc
2017-09-06 05:59:02 +00:00
2017-09-09 03:45:11 +00:00
.proc target_params
queryx: .word 0 ; aligns with input_state_params::xcoord
queryy: .word 0 ; aligns with input_state_params::ycoord
2017-09-08 03:59:38 +00:00
elem: .byte 0
id: .byte 0
2017-09-06 05:59:02 +00:00
.endproc
2017-09-09 03:45:11 +00:00
.byte 0, 0 ; fills out space for map_coords_params
.byte 0, 0 ; ???
2017-09-06 06:24:21 +00:00
.proc close_click_params
2017-09-08 04:42:58 +00:00
state: .byte 0
2017-09-06 06:24:21 +00:00
.endproc
2017-09-14 04:35:23 +00:00
.proc query_state_params
2017-09-10 01:11:01 +00:00
id: .byte 0
2017-09-14 04:35:23 +00:00
.addr state_params
2017-09-10 01:11:01 +00:00
.endproc
2017-09-14 04:35:23 +00:00
query_state_params_id := query_state_params::id
2017-09-08 04:42:58 +00:00
2017-09-21 15:09:11 +00:00
.proc preserve_zp_params
flag: .byte A2D_CZP_PRESERVE
.endproc
2017-09-08 04:42:58 +00:00
2017-09-21 15:09:11 +00:00
.proc overwrite_zp_params
flag: .byte A2D_CZP_OVERWRITE
.endproc
2017-09-10 02:11:05 +00:00
;;; ==================================================
;;; Button Definitions
2017-09-06 15:42:33 +00:00
button_width := 17
button_height := 9
col1_left := 13
2017-09-07 02:05:49 +00:00
col1_right := col1_left+button_width ; 30
2017-09-06 15:42:33 +00:00
col2_left := 42
2017-09-07 02:05:49 +00:00
col2_right := col2_left+button_width ; 59
2017-09-06 15:42:33 +00:00
col3_left := 70
2017-09-07 02:05:49 +00:00
col3_right := col3_left+button_width ; 87
2017-09-06 15:42:33 +00:00
col4_left := 98
2017-09-07 02:05:49 +00:00
col4_right := col4_left+button_width ; 115
2017-09-06 15:42:33 +00:00
row1_top := 22
2017-09-07 02:05:49 +00:00
row1_bot := row1_top+button_height ; 31
2017-09-06 15:42:33 +00:00
row2_top := 38
2017-09-07 02:05:49 +00:00
row2_bot := row2_top+button_height ; 47
2017-09-06 15:42:33 +00:00
row3_top := 53
2017-09-07 02:05:49 +00:00
row3_bot := row3_top+button_height ; 62
2017-09-06 15:42:33 +00:00
row4_top := 68
2017-09-07 02:05:49 +00:00
row4_bot := row4_top+button_height ; 77
2017-09-06 15:42:33 +00:00
row5_top := 83
2017-09-07 02:05:49 +00:00
row5_bot := row5_top+button_height ; 92
2017-09-06 15:42:33 +00:00
2017-09-08 08:00:58 +00:00
border_lt := 1 ; border width pixels (left/top)
border_br := 2 ; (bottom/right)
2017-09-06 15:42:33 +00:00
2017-09-08 04:42:58 +00:00
.proc btn_c
2017-09-25 00:57:57 +00:00
left: .word col1_left - border_lt
top: .word row1_top - border_lt
bitmap: .addr button_bitmap
stride: .byte bitmap_stride
.byte 0 ; ???
2017-10-08 03:22:39 +00:00
hoff: .word 0
voff: .word 0
2017-09-25 00:57:57 +00:00
width: .word button_width + border_lt + border_br
height: .word button_height + border_lt + border_br
2017-09-08 04:42:58 +00:00
label: .byte 'c'
2017-09-08 07:42:45 +00:00
pos: .word col1_left + 6, row1_bot
2017-09-08 04:42:58 +00:00
box: .word col1_left,row1_top,col1_right,row1_bot
.endproc
2017-09-06 15:23:23 +00:00
2017-09-08 04:42:58 +00:00
.proc btn_e
2017-09-25 00:57:57 +00:00
left: .word col2_left - border_lt
top: .word row1_top - border_lt
bitmap: .addr button_bitmap
stride: .byte bitmap_stride
.byte 0 ; ???
2017-10-08 03:22:39 +00:00
hoff: .word 0
voff: .word 0
2017-09-25 00:57:57 +00:00
width: .word button_width + border_lt + border_br
height: .word button_height + border_lt + border_br
2017-09-08 07:10:54 +00:00
label: .byte 'e'
2017-09-25 00:57:57 +00:00
pos: .word col2_left + 6, row1_bot
2017-09-08 04:42:58 +00:00
box: .word col2_left,row1_top,col2_right,row1_bot
.endproc
2017-09-06 15:23:23 +00:00
2017-09-08 04:42:58 +00:00
.proc btn_eq
2017-09-25 00:57:57 +00:00
left: .word col3_left - border_lt
top: .word row1_top - border_lt
bitmap: .addr button_bitmap
stride: .byte bitmap_stride
.byte 0 ; ???
2017-10-08 03:22:39 +00:00
hoff: .word 0
voff: .word 0
2017-09-25 00:57:57 +00:00
width: .word button_width + border_lt + border_br
height: .word button_height + border_lt + border_br
2017-09-08 07:10:54 +00:00
label: .byte '='
2017-09-25 00:57:57 +00:00
pos: .word col3_left + 6, row1_bot
2017-09-08 04:42:58 +00:00
box: .word col3_left,row1_top,col3_right,row1_bot
.endproc
2017-09-06 15:23:23 +00:00
2017-09-08 04:42:58 +00:00
.proc btn_mul
2017-09-25 00:57:57 +00:00
left: .word col4_left - border_lt
top: .word row1_top - border_lt
bitmap: .addr button_bitmap
stride: .byte bitmap_stride
.byte 0 ; ???
2017-10-08 03:22:39 +00:00
hoff: .word 0
voff: .word 0
2017-09-25 00:57:57 +00:00
width: .word button_width + border_lt + border_br
height: .word button_height + border_lt + border_br
2017-09-08 07:10:54 +00:00
label: .byte '*'
2017-09-25 00:57:57 +00:00
pos: .word col4_left + 6, row1_bot
2017-09-08 04:42:58 +00:00
box: .word col4_left,row1_top,col4_right,row1_bot
.endproc
2017-09-06 15:23:23 +00:00
2017-09-08 04:42:58 +00:00
.proc btn_7
2017-09-25 00:57:57 +00:00
left: .word col1_left - border_lt
top: .word row2_top - border_lt
bitmap: .addr button_bitmap
stride: .byte bitmap_stride
.byte 0 ; ???
2017-10-08 03:22:39 +00:00
hoff: .word 0
voff: .word 0
2017-09-25 00:57:57 +00:00
width: .word button_width + border_lt + border_br
height: .word button_height + border_lt + border_br
2017-09-08 07:10:54 +00:00
label: .byte '7'
2017-09-25 00:57:57 +00:00
pos: .word col1_left + 6, row2_bot
2017-09-08 04:42:58 +00:00
box: .word col1_left,row2_top,col1_right,row2_bot
.endproc
2017-09-06 15:23:23 +00:00
2017-09-08 04:42:58 +00:00
.proc btn_8
2017-09-25 00:57:57 +00:00
left: .word col2_left - border_lt
top: .word row2_top - border_lt
bitmap: .addr button_bitmap
stride: .byte bitmap_stride
.byte 0 ; ???
2017-10-08 03:22:39 +00:00
hoff: .word 0
voff: .word 0
2017-09-25 00:57:57 +00:00
width: .word button_width + border_lt + border_br
height: .word button_height + border_lt + border_br
2017-09-08 07:10:54 +00:00
label: .byte '8'
2017-09-25 00:57:57 +00:00
pos: .word col2_left + 6, row2_bot
2017-09-08 04:42:58 +00:00
box: .word col2_left,row2_top,col2_right,row2_bot
.endproc
2017-09-06 15:23:23 +00:00
2017-09-08 04:42:58 +00:00
.proc btn_9
2017-09-25 00:57:57 +00:00
left: .word col3_left - border_lt
top: .word row2_top - border_lt
bitmap: .addr button_bitmap
stride: .byte bitmap_stride
.byte 0 ; ???
2017-10-08 03:22:39 +00:00
hoff: .word 0
voff: .word 0
2017-09-25 00:57:57 +00:00
width: .word button_width + border_lt + border_br
height: .word button_height + border_lt + border_br
2017-09-08 07:10:54 +00:00
label: .byte '9'
2017-09-25 00:57:57 +00:00
pos: .word col3_left + 6, row2_bot
2017-09-08 04:42:58 +00:00
box: .word col3_left,row2_top,col3_right,row2_bot
.endproc
2017-09-06 15:23:23 +00:00
2017-09-08 04:42:58 +00:00
.proc btn_div
2017-09-25 00:57:57 +00:00
left: .word col4_left - border_lt
top: .word row2_top - border_lt
bitmap: .addr button_bitmap
stride: .byte bitmap_stride
.byte 0 ; ???
2017-10-08 03:22:39 +00:00
hoff: .word 0
voff: .word 0
2017-09-25 00:57:57 +00:00
width: .word button_width + border_lt + border_br
height: .word button_height + border_lt + border_br
2017-09-08 07:10:54 +00:00
label: .byte '/'
2017-09-25 00:57:57 +00:00
pos: .word col4_left + 6, row2_bot
2017-09-08 04:42:58 +00:00
box: .word col4_left,row2_top,col4_right,row2_bot
.endproc
2017-09-06 15:23:23 +00:00
2017-09-08 04:42:58 +00:00
.proc btn_4
2017-09-25 00:57:57 +00:00
left: .word col1_left - border_lt
top: .word row3_top - border_lt
bitmap: .addr button_bitmap
stride: .byte bitmap_stride
.byte 0 ; ???
2017-10-08 03:22:39 +00:00
hoff: .word 0
voff: .word 0
2017-09-25 00:57:57 +00:00
width: .word button_width + border_lt + border_br
height: .word button_height + border_lt + border_br
2017-09-08 07:10:54 +00:00
label: .byte '4'
2017-09-25 00:57:57 +00:00
pos: .word col1_left + 6, row3_bot
2017-09-08 04:42:58 +00:00
box: .word col1_left,row3_top,col1_right,row3_bot
.endproc
2017-09-06 15:23:23 +00:00
2017-09-08 04:42:58 +00:00
.proc btn_5
2017-09-25 00:57:57 +00:00
left: .word col2_left - border_lt
top: .word row3_top - border_lt
bitmap: .addr button_bitmap
stride: .byte bitmap_stride
.byte 0 ; ???
2017-10-08 03:22:39 +00:00
hoff: .word 0
voff: .word 0
2017-09-25 00:57:57 +00:00
width: .word button_width + border_lt + border_br
height: .word button_height + border_lt + border_br
2017-09-08 07:10:54 +00:00
label: .byte '5'
2017-09-25 00:57:57 +00:00
pos: .word col2_left + 6, row3_bot
2017-09-08 04:42:58 +00:00
box: .word col2_left,row3_top,col2_right,row3_bot
.endproc
2017-09-06 15:23:23 +00:00
2017-09-08 04:42:58 +00:00
.proc btn_6
2017-09-25 00:57:57 +00:00
left: .word col3_left - border_lt
top: .word row3_top - border_lt
bitmap: .addr button_bitmap
stride: .byte bitmap_stride
.byte 0 ; ???
2017-10-08 03:22:39 +00:00
hoff: .word 0
voff: .word 0
2017-09-25 00:57:57 +00:00
width: .word button_width + border_lt + border_br
height: .word button_height + border_lt + border_br
2017-09-08 07:10:54 +00:00
label: .byte '6'
2017-09-25 00:57:57 +00:00
pos: .word col3_left + 6, row3_bot
2017-09-08 04:42:58 +00:00
box: .word col3_left,row3_top,col3_right,row3_bot
.endproc
2017-09-06 15:23:23 +00:00
2017-09-08 04:42:58 +00:00
.proc btn_sub
2017-09-25 00:57:57 +00:00
left: .word col4_left - border_lt
top: .word row3_top - border_lt
bitmap: .addr button_bitmap
stride: .byte bitmap_stride
.byte 0 ; ???
2017-10-08 03:22:39 +00:00
hoff: .word 0
voff: .word 0
2017-09-25 00:57:57 +00:00
width: .word button_width + border_lt + border_br
height: .word button_height + border_lt + border_br
2017-09-08 07:10:54 +00:00
label: .byte '-'
2017-09-25 00:57:57 +00:00
pos: .word col4_left + 6, row3_bot
2017-09-08 04:42:58 +00:00
box: .word col4_left,row3_top,col4_right,row3_bot
.endproc
2017-09-06 15:23:23 +00:00
2017-09-08 04:42:58 +00:00
.proc btn_1
2017-09-25 00:57:57 +00:00
left: .word col1_left - border_lt
top: .word row4_top - border_lt
bitmap: .addr button_bitmap
stride: .byte bitmap_stride
.byte 0 ; ???
2017-10-08 03:22:39 +00:00
hoff: .word 0
voff: .word 0
2017-09-25 00:57:57 +00:00
width: .word button_width + border_lt + border_br
height: .word button_height + border_lt + border_br
2017-09-08 07:10:54 +00:00
label: .byte '1'
2017-09-25 00:57:57 +00:00
pos: .word col1_left + 6, row4_bot
2017-09-08 04:42:58 +00:00
box: .word col1_left,row4_top,col1_right,row4_bot
.endproc
2017-09-06 15:23:23 +00:00
2017-09-08 04:42:58 +00:00
.proc btn_2
2017-09-25 00:57:57 +00:00
left: .word col2_left - border_lt
top: .word row4_top - border_lt
bitmap: .addr button_bitmap
stride: .byte bitmap_stride
.byte 0 ; ???
2017-10-08 03:22:39 +00:00
hoff: .word 0
voff: .word 0
2017-09-25 00:57:57 +00:00
width: .word button_width + border_lt + border_br
height: .word button_height + border_lt + border_br
2017-09-08 07:10:54 +00:00
label: .byte '2'
2017-09-25 00:57:57 +00:00
pos: .word col2_left + 6, row4_bot
2017-09-08 04:42:58 +00:00
box: .word col2_left,row4_top,col2_right,row4_bot
.endproc
2017-09-06 15:23:23 +00:00
2017-09-08 04:42:58 +00:00
.proc btn_3
2017-09-25 00:57:57 +00:00
left: .word col3_left - border_lt
top: .word row4_top - border_lt
bitmap: .addr button_bitmap
stride: .byte bitmap_stride
.byte 0 ; ???
2017-10-08 03:22:39 +00:00
hoff: .word 0
voff: .word 0
2017-09-25 00:57:57 +00:00
width: .word button_width + border_lt + border_br
height: .word button_height + border_lt + border_br
2017-09-08 07:10:54 +00:00
label: .byte '3'
2017-09-25 00:57:57 +00:00
pos: .word col3_left + 6, row4_bot
2017-09-08 04:42:58 +00:00
box: .word col3_left,row4_top,col3_right,row4_bot
.endproc
2017-09-06 15:23:23 +00:00
2017-09-08 04:42:58 +00:00
.proc btn_0
2017-09-25 00:57:57 +00:00
left: .word col1_left - border_lt
top: .word row5_top - border_lt
bitmap: .addr wide_button_bitmap
stride: .byte 8 ; bitmap_stride (bytes)
.byte 0 ; ???
2017-10-08 03:22:39 +00:00
hoff: .word 0
voff: .word 0
2017-09-25 00:57:57 +00:00
width: .word 49 ; 0 is extra wide
height: .word button_height + border_lt + border_br
label: .byte '0'
pos: .word col1_left + 6, row5_bot
2017-09-08 04:42:58 +00:00
box: .word col1_left,row5_top,col2_right,row5_bot
.endproc
2017-09-06 15:23:23 +00:00
2017-09-08 04:42:58 +00:00
.proc btn_dec
2017-09-25 00:57:57 +00:00
left: .word col3_left - border_lt
top: .word row5_top - border_lt
bitmap: .addr button_bitmap
stride: .byte bitmap_stride
.byte 0 ; ???
2017-10-08 03:22:39 +00:00
hoff: .word 0
voff: .word 0
2017-09-25 00:57:57 +00:00
width: .word button_width + border_lt + border_br
height: .word button_height + border_lt + border_br
label: .byte '.'
pos: .word col3_left + 6 + 2, row5_bot ; + 2 to center the label
2017-09-08 04:42:58 +00:00
box: .word col3_left,row5_top,col3_right,row5_bot
.endproc
2017-09-06 15:23:23 +00:00
2017-09-08 04:42:58 +00:00
.proc btn_add
2017-09-25 00:57:57 +00:00
left: .word col4_left - border_lt
top: .word row4_top - border_lt
bitmap: .addr tall_button_bitmap
stride: .byte bitmap_stride
.byte 0 ; ???
2017-10-08 03:22:39 +00:00
hoff: .word 0
voff: .word 0
2017-09-25 00:57:57 +00:00
width: .word button_width + border_lt + border_br
height: .word 27 ; + is extra tall
label: .byte '+'
pos: .word col4_left + 6, row5_bot
2017-09-08 04:42:58 +00:00
box: .word col4_left,row4_top,col4_right,row5_bot
.endproc
2017-09-08 04:47:27 +00:00
.byte 0 ; sentinel
2017-09-06 15:23:23 +00:00
2017-09-15 04:22:27 +00:00
;; Button bitmaps. These are used as bitmaps for
2017-09-10 02:11:05 +00:00
;; drawing the shadowed buttons.
2017-09-10 00:43:37 +00:00
2017-09-15 04:22:27 +00:00
;; bitmaps are low 7 bits, 0=black 1=white
bitmap_stride := 3 ; bytes
2017-09-25 00:57:57 +00:00
button_bitmap: ; bitmap for normal buttons
2017-09-10 00:43:37 +00:00
.byte px(%0000000),px(%0000000),px(%0000001)
.byte px(%0111111),px(%1111111),px(%1111100)
.byte px(%0111111),px(%1111111),px(%1111100)
.byte px(%0111111),px(%1111111),px(%1111100)
.byte px(%0111111),px(%1111111),px(%1111100)
.byte px(%0111111),px(%1111111),px(%1111100)
.byte px(%0111111),px(%1111111),px(%1111100)
.byte px(%0111111),px(%1111111),px(%1111100)
.byte px(%0111111),px(%1111111),px(%1111100)
.byte px(%0111111),px(%1111111),px(%1111100)
.byte px(%0111111),px(%1111111),px(%1111100)
.byte px(%0000000),px(%0000000),px(%0000000)
.byte px(%1000000),px(%0000000),px(%0000000)
2017-09-15 04:22:27 +00:00
wide_bitmap_stride := 8
2017-09-25 00:57:57 +00:00
wide_button_bitmap: ; bitmap for '0' button
2017-09-10 00:43:37 +00:00
.byte px(%0000000),px(%0000000),px(%0000000),px(%0000000),px(%0000000),px(%0000000),px(%0000000),px(%1111111)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111111),px(%1111111),px(%1111111),px(%1111110),px(%0111111)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111111),px(%1111111),px(%1111111),px(%1111110),px(%0111111)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111111),px(%1111111),px(%1111111),px(%1111110),px(%0111111)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111111),px(%1111111),px(%1111111),px(%1111110),px(%0111111)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111111),px(%1111111),px(%1111111),px(%1111110),px(%0111111)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111111),px(%1111111),px(%1111111),px(%1111110),px(%0111111)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111111),px(%1111111),px(%1111111),px(%1111110),px(%0111111)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111111),px(%1111111),px(%1111111),px(%1111110),px(%0111111)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111111),px(%1111111),px(%1111111),px(%1111110),px(%0111111)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111111),px(%1111111),px(%1111111),px(%1111110),px(%0111111)
.byte px(%0000000),px(%0000000),px(%0000000),px(%0000000),px(%0000000),px(%0000000),px(%0000000),px(%0111111)
.byte px(%1000000),px(%0000000),px(%0000000),px(%0000000),px(%0000000),px(%0000000),px(%0000000),px(%0111111)
2017-09-25 00:57:57 +00:00
tall_button_bitmap: ; bitmap for '+' button
2017-09-10 00:43:37 +00:00
.byte px(%0000000),px(%0000000),px(%0000001)
.byte px(%0111111),px(%1111111),px(%1111100)
.byte px(%0111111),px(%1111111),px(%1111100)
.byte px(%0111111),px(%1111111),px(%1111100)
.byte px(%0111111),px(%1111111),px(%1111100)
.byte px(%0111111),px(%1111111),px(%1111100)
.byte px(%0111111),px(%1111111),px(%1111100)
.byte px(%0111111),px(%1111111),px(%1111100)
.byte px(%0111111),px(%1111111),px(%1111100)
.byte px(%0111111),px(%1111111),px(%1111100)
.byte px(%0111111),px(%1111111),px(%1111100)
.byte px(%0111111),px(%1111111),px(%1111100)
.byte px(%0111111),px(%1111111),px(%1111100)
.byte px(%0111111),px(%1111111),px(%1111100)
.byte px(%0111111),px(%1111111),px(%1111100)
.byte px(%0111111),px(%1111111),px(%1111100)
.byte px(%0111111),px(%1111111),px(%1111100)
.byte px(%0111111),px(%1111111),px(%1111100)
.byte px(%0111111),px(%1111111),px(%1111100)
.byte px(%0111111),px(%1111111),px(%1111100)
.byte px(%0111111),px(%1111111),px(%1111100)
.byte px(%0111111),px(%1111111),px(%1111100)
.byte px(%0111111),px(%1111111),px(%1111100)
.byte px(%0111111),px(%1111111),px(%1111100)
.byte px(%0111111),px(%1111111),px(%1111100)
.byte px(%0111111),px(%1111111),px(%1111100)
.byte px(%0000000),px(%0000000),px(%0000000)
.byte px(%1000000),px(%0000000),px(%0000000)
2017-09-08 07:10:54 +00:00
2017-09-06 15:55:53 +00:00
2017-09-10 02:11:05 +00:00
;;; ==================================================
;;; Calculation state
saved_stack:
.byte $00 ; restored after error
2017-09-15 07:53:45 +00:00
calc_p: .byte $00 ; high bit set if pending op?
2017-09-08 07:42:45 +00:00
calc_op:.byte $00
2017-09-10 00:43:37 +00:00
calc_d: .byte $00 ; '.' if decimal present, 0 otherwise
calc_e: .byte $00 ; exponential?
calc_n: .byte $00 ; negative?
2017-09-15 07:53:45 +00:00
calc_g: .byte $00 ; high bit set if last input digit
2017-09-10 00:43:37 +00:00
calc_l: .byte $00 ; input length
2017-09-06 05:59:02 +00:00
2017-09-10 02:11:05 +00:00
;;; ==================================================
;;; Miscellaneous param blocks
2017-09-07 06:43:40 +00:00
.proc background_box_params
left: .word 1
top: .word 0
right: .word 129
bottom: .word 96
2017-09-06 05:59:02 +00:00
.endproc
2017-09-06 05:19:45 +00:00
background_pattern:
.byte $77,$DD,$77,$DD,$77,$DD,$77,$DD
.byte $00
2017-09-06 05:19:45 +00:00
black_pattern:
.res 8, $00
.byte $00
2017-09-06 05:19:45 +00:00
white_pattern:
.res 8, $FF
.byte $00
2017-09-06 05:19:45 +00:00
2017-09-19 05:51:24 +00:00
.proc text_mask_params
mask: .byte $7F
.endproc
2017-09-06 05:59:02 +00:00
display_left := 10
display_top := 5
display_width := 120
display_height := 17
2017-09-07 06:43:40 +00:00
.proc frame_display_params
left: .word display_left
top: .word display_top
width: .word display_width
height: .word display_height
2017-09-07 06:43:40 +00:00
.endproc
.proc clear_display_params
left: .word display_left+1
top: .word display_top+1
width: .word display_width-1
height: .word display_height-1
2017-09-06 05:59:02 +00:00
.endproc
2017-09-06 06:37:05 +00:00
;; For drawing 1-character strings (button labels)
.proc draw_text_params_label
.addr label
.byte 1
.endproc
label: .byte 0 ; modified with char to draw
2017-09-06 06:24:21 +00:00
.proc draw_text_params1
2017-09-06 06:37:05 +00:00
addr: .addr text_buffer1
2017-09-06 06:24:21 +00:00
length: .byte 15
.endproc
2017-09-06 06:55:44 +00:00
text_buffer_size := 14
2017-09-06 06:24:21 +00:00
text_buffer1:
.res text_buffer_size+2, 0
2017-09-06 06:37:05 +00:00
.proc draw_text_params2
addr: .addr text_buffer2
length: .byte 15
.endproc
text_buffer2:
.res text_buffer_size+2, 0
2017-09-06 06:37:05 +00:00
spaces_string:
A2D_DEFSTRING " "
error_string:
A2D_DEFSTRING "Error "
2017-09-06 06:24:21 +00:00
;; used when clearing display; params to a $18 call
.proc measure_text_params
addr: .addr text_buffer1
len: .byte 15 ; ???
width: .word 0
.endproc
2017-09-06 06:24:21 +00:00
window_id = 52
2017-09-07 02:38:06 +00:00
2017-09-06 06:24:21 +00:00
.proc destroy_window_params
2017-09-07 02:38:06 +00:00
id: .byte window_id
2017-09-06 06:24:21 +00:00
.endproc
2017-09-06 05:59:02 +00:00
.proc text_pos_params3
left: .word 0
base: .word 16
.endproc
.proc text_pos_params2
left: .word 15
base: .word 16
.endproc
2017-09-10 02:11:05 +00:00
.proc error_pos
left: .word 69
base: .word 16
.endproc
2017-09-07 03:43:12 +00:00
farg: .byte $00,$00,$00,$00,$00,$00
2017-09-08 04:42:58 +00:00
2017-09-14 04:58:37 +00:00
.proc title_bar_decoration ; Params for A2D_DRAW_BITMAP
2017-09-10 00:43:37 +00:00
left: .word 115 ; overwritten
top: .word $FFF7 ; overwritten
2017-09-15 04:22:27 +00:00
bitmap:.addr pixels
2017-09-10 00:43:37 +00:00
stride: .byte 1
2017-09-25 00:57:57 +00:00
.byte 0 ; ???
2017-10-08 03:22:39 +00:00
hoff: .word 0
voff: .word 0
2017-09-10 00:43:37 +00:00
width: .word 6
height: .word 5
;; (not part of struct, but not referenced outside)
pixels: .byte px(%1000001)
.byte px(%1010110)
.byte px(%1110001)
.byte px(%1110110)
.byte px(%0110110)
.byte px(%1001001)
.endproc
2017-09-14 04:35:23 +00:00
;; param block for a QUERY_SCREEN and SET_STATE calls, and ref'd in QUERY_STATE call
.proc state_params
2017-09-10 00:43:37 +00:00
left: .word 0
top: .word 0
2017-10-08 03:22:39 +00:00
addr: .word 0
stride: .word 0
2017-10-08 03:22:39 +00:00
hoff: .word 0
voff: .word 0
width: .word 0
height: .word 0
pattern:.res 8, 0
2017-09-14 04:35:23 +00:00
mskand: .byte 0
mskor: .byte 0
2017-10-07 20:59:25 +00:00
xpos: .word 0
ypos: .word 0
hthick: .byte 0
vthick: .byte 0
2017-10-08 03:22:39 +00:00
mode: .byte 0
tmask: .byte 0
font: .addr 0
2017-09-10 00:43:37 +00:00
.endproc
.assert * - state_params = 36, error
.byte 0 ; ???
2017-09-08 04:42:58 +00:00
2017-09-10 01:11:01 +00:00
menu_bar_height := 13
screen_width := 560
screen_height := 192
2017-09-14 04:35:23 +00:00
;; params for A2D_SET_BOX when decorating title bar
2017-09-10 01:11:01 +00:00
.proc screen_box
2017-10-08 03:22:39 +00:00
left: .word 0
top: .word menu_bar_height
addr: .word A2D_SCREEN_ADDR
stride: .word A2D_SCREEN_STRIDE
hoff: .word 0
voff: .word 0
width: .word screen_width - 1
height: .word screen_height - menu_bar_height - 2
2017-09-10 01:11:01 +00:00
.endproc
2017-09-08 04:42:58 +00:00
2017-09-10 17:40:08 +00:00
.proc fill_mode_normal
mode: .byte A2D_SFM_NORMAL
.endproc
2017-09-10 00:43:37 +00:00
.byte $01,$02 ; ??
2017-09-10 17:40:08 +00:00
.proc fill_mode_xor
mode: .byte A2D_SFM_XOR
.endproc
2017-09-06 05:59:02 +00:00
window_width := 130
window_height := 96
default_left := 210
default_top := 60
.proc create_window_params
id: .byte window_id
flags: .byte A2D_CWF_ADDCLOSE
title: .addr window_title
hscroll:.byte A2D_CWS_NOSCROLL
vscroll:.byte A2D_CWS_NOSCROLL
hs_max: .byte 0
hs_pos: .byte 0
vs_max: .byte 0
vs_pos: .byte 0
.byte 0,0 ; ???
w1: .word window_width
h1: .word window_height
w2: .word window_width
h2: .word window_height
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
voff: .word 0
width: .word window_width
height: .word window_height
pattern:.res 8, $FF
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
create_window_params_top := create_window_params::top
2017-09-06 06:24:21 +00:00
window_title:
PASCAL_STRING "Calc"
2017-09-19 04:32:46 +00:00
cursor: .byte px(%0000000),px(%0000000) ; cursor
.byte px(%0100000),px(%0000000)
.byte px(%0110000),px(%0000000)
.byte px(%0111000),px(%0000000)
.byte px(%0111100),px(%0000000)
.byte px(%0111110),px(%0000000)
.byte px(%0111111),px(%0000000)
.byte px(%0101100),px(%0000000)
.byte px(%0000110),px(%0000000)
.byte px(%0000110),px(%0000000)
.byte px(%0000011),px(%0000000)
.byte px(%0000000),px(%0000000)
.byte px(%1100000),px(%0000000) ; mask
.byte px(%1110000),px(%0000000)
.byte px(%1111000),px(%0000000)
.byte px(%1111100),px(%0000000)
.byte px(%1111110),px(%0000000)
.byte px(%1111111),px(%0000000)
.byte px(%1111111),px(%1000000)
.byte px(%1111111),px(%0000000)
.byte px(%0001111),px(%0000000)
.byte px(%0001111),px(%0000000)
.byte px(%0000111),px(%1000000)
.byte px(%0000111),px(%1000000)
.byte 1, 1 ; hotspot
2017-09-06 05:19:45 +00:00
2017-09-08 08:00:58 +00:00
;;; ==================================================
;;; DA Init
2017-09-15 04:22:27 +00:00
init: sta ALTZPON
lda LCBANK1
lda LCBANK1
2017-09-21 15:09:11 +00:00
A2D_CALL A2D_CONFIGURE_ZP_USE, preserve_zp_params
2017-09-06 05:59:02 +00:00
A2D_CALL A2D_CREATE_WINDOW, create_window_params
2017-09-14 04:35:23 +00:00
A2D_CALL A2D_QUERY_SCREEN, state_params
A2D_CALL A2D_SET_STATE, state_params ; set clipping bounds?
2017-09-10 17:40:08 +00:00
A2D_CALL $2B ; reset drawing state?
lda #$01
2017-09-09 03:13:09 +00:00
sta input_state_params::state
2017-09-19 14:58:17 +00:00
A2D_CALL A2D_SET_INPUT, input_state_params
A2D_CALL A2D_GET_INPUT, input_state_params
2017-09-06 05:19:45 +00:00
lda ROMIN2
2017-09-08 07:42:45 +00:00
jsr reset_buffer2
2017-09-07 02:38:06 +00:00
lda #window_id
jsr check_visibility_and_draw_window
jsr reset_buffers_and_display
2017-09-08 07:42:45 +00:00
lda #'=' ; last operation
sta calc_op
lda #0 ; clear registers
2017-09-15 07:53:45 +00:00
sta calc_p
2017-09-10 00:43:37 +00:00
sta calc_d
sta calc_e
sta calc_n
2017-09-15 07:53:45 +00:00
sta calc_g
2017-09-10 00:43:37 +00:00
sta calc_l
2017-09-08 07:42:45 +00:00
.proc copy_to_b1
ldx #sizeof_adjust_txtptr_copied + 4 ; should be just + 1 ?
loop: lda adjust_txtptr_copied-1,x
sta adjust_txtptr-1,x
dex
2017-09-08 07:42:45 +00:00
bne loop
.endproc
lda #0 ; Turn off errors
sta ERRFLG
2017-09-09 18:27:35 +00:00
lda #<error_hook ; set up FP error handler
sta COUT_HOOK
lda #>error_hook
sta COUT_HOOK+1
lda #1
jsr FLOAT
2017-09-07 03:43:12 +00:00
ldx #<farg
ldy #>farg
jsr ROUND
lda #0 ; set FAC to 0
jsr FLOAT
jsr FADD
jsr FOUT
lda #$07
jsr FMULT
lda #$00
jsr FLOAT
2017-09-07 03:43:12 +00:00
ldx #<farg
ldy #>farg
jsr ROUND
2017-09-09 18:27:35 +00:00
tsx
stx saved_stack
2017-09-09 18:27:35 +00:00
2017-09-07 03:43:12 +00:00
lda #'='
jsr process_key
lda #'C'
jsr process_key
2017-09-09 18:27:35 +00:00
2017-09-19 04:32:46 +00:00
;; previous draws mangle the cursor (why???)
A2D_CALL A2D_SET_CURSOR, cursor ; Why not use JUMP_TABLE_CUR_POINTER ?
2017-09-08 08:00:58 +00:00
;; fall through
;;; ==================================================
;;; Input Loop
2017-09-08 07:42:45 +00:00
input_loop:
2017-09-09 03:13:09 +00:00
A2D_CALL A2D_GET_INPUT, input_state_params
lda input_state_params::state
cmp #A2D_INPUT_DOWN
2017-09-09 01:34:34 +00:00
bne :+
2017-09-08 03:59:38 +00:00
jsr on_click
2017-09-08 07:42:45 +00:00
jmp input_loop
2017-09-09 03:13:09 +00:00
: cmp #A2D_INPUT_KEY
2017-09-08 07:42:45 +00:00
bne input_loop
2017-09-09 03:13:09 +00:00
jsr on_key_press
2017-09-08 07:42:45 +00:00
jmp input_loop
2017-09-08 08:00:58 +00:00
;;; ==================================================
;;; On Click
2017-09-08 03:59:38 +00:00
on_click:
lda LCBANK1
lda LCBANK1
2017-09-09 03:45:11 +00:00
A2D_CALL A2D_QUERY_TARGET, target_params
2017-09-06 05:19:45 +00:00
lda ROMIN2
2017-09-09 03:45:11 +00:00
lda target_params::elem
2017-09-08 03:59:38 +00:00
cmp #A2D_ELEM_CLIENT ; Less than CLIENT is MENU or DESKTOP
bcc ignore_click
2017-09-09 03:45:11 +00:00
lda target_params::id
2017-09-08 03:59:38 +00:00
cmp #window_id ; This window?
beq :+
ignore_click:
rts
2017-09-09 03:45:11 +00:00
: lda target_params::elem
2017-09-08 03:59:38 +00:00
cmp #A2D_ELEM_CLIENT ; Client area?
bne :+
2017-09-08 08:00:58 +00:00
jsr map_click_to_button ; try to translate click into key
2017-09-08 03:59:38 +00:00
bcc ignore_click
2017-09-07 03:43:12 +00:00
jmp process_key
2017-09-08 03:59:38 +00:00
: cmp #A2D_ELEM_CLOSE ; Close box?
bne :+
A2D_CALL A2D_CLOSE_CLICK, close_click_params
lda close_click_params::state
2017-09-08 03:59:38 +00:00
beq ignore_click
2017-09-07 06:43:40 +00:00
exit: lda LCBANK1
lda LCBANK1
2017-09-06 06:24:21 +00:00
A2D_CALL A2D_DESTROY_WINDOW, destroy_window_params
DESKTOP_CALL DESKTOP_REDRAW_ICONS
2017-09-06 05:19:45 +00:00
lda ROMIN2
2017-09-21 15:09:11 +00:00
A2D_CALL A2D_CONFIGURE_ZP_USE, overwrite_zp_params
2017-09-08 03:59:38 +00:00
.proc do_close
;; Copy following routine to ZP and invoke it
zp_stash := $20
2017-09-19 00:17:30 +00:00
ldx #sizeof_routine
2017-09-08 03:59:38 +00:00
loop: lda routine,x
sta zp_stash,x
dex
2017-09-08 03:59:38 +00:00
bpl loop
jmp zp_stash
2017-09-08 03:59:38 +00:00
.proc routine
2017-09-08 08:00:58 +00:00
sta RAMRDOFF
sta RAMWRTOFF
2017-09-06 05:19:45 +00:00
jmp exit_da
2017-09-08 03:59:38 +00:00
.endproc
2017-09-19 00:17:30 +00:00
sizeof_routine := * - routine ; Can't use .sizeof before the .proc definition
2017-09-08 03:59:38 +00:00
.endproc
2017-09-08 03:59:38 +00:00
: cmp #A2D_ELEM_TITLE ; Title bar?
bne ignore_click
2017-09-07 02:38:06 +00:00
lda #window_id
2017-09-09 04:10:56 +00:00
sta drag_params::id
lda LCBANK1
lda LCBANK1
2017-09-09 04:10:56 +00:00
A2D_CALL A2D_DRAG_WINDOW, drag_params
2017-09-06 05:19:45 +00:00
lda ROMIN2
2017-09-18 15:10:19 +00:00
jsr redraw_screen_and_window
rts
2017-09-08 08:00:58 +00:00
;;; ==================================================
;;; On Key Press
2017-09-09 03:13:09 +00:00
.proc on_key_press
lda input_state_params::modifiers
2017-09-07 03:43:12 +00:00
bne bail
2017-09-09 03:13:09 +00:00
lda input_state_params::key
2017-09-15 04:13:54 +00:00
cmp #KEY_ESCAPE
2017-09-07 03:43:12 +00:00
bne trydel
2017-09-15 07:53:45 +00:00
lda calc_p
2017-09-07 06:43:40 +00:00
bne clear ; empty state?
2017-09-10 00:43:37 +00:00
lda calc_l
2017-09-07 06:43:40 +00:00
beq exit ; if so, exit DA
clear: lda #'C' ; otherwise turn Escape into Clear
2017-09-07 03:43:12 +00:00
trydel: cmp #$7F ; Delete?
beq :+
cmp #$60 ; lowercase range?
bcc :+
and #$5F ; convert to uppercase
: jmp process_key
bail:
.endproc
2017-09-15 04:22:27 +00:00
rts1: rts ; used by next proc
2017-09-08 08:00:58 +00:00
;;; ==================================================
;;; Try to map a click to a button
;;; If a button was clicked, carry is set and accum has key char
.proc map_click_to_button
lda #window_id
2017-09-09 03:13:09 +00:00
sta map_coords_params::id
A2D_CALL A2D_MAP_COORDS, map_coords_params
lda map_coords_params::clientx+1 ; ensure high bits of coords are 0
ora map_coords_params::clienty+1
2017-09-15 04:22:27 +00:00
bne rts1
2017-09-09 03:13:09 +00:00
lda map_coords_params::clienty
ldx map_coords_params::clientx
2017-09-07 02:05:49 +00:00
.proc find_button_row
2017-09-07 02:38:06 +00:00
cmp #row1_top+border_lt - 1 ; row 1 ? (- 1 is bug in original?)
2017-09-07 02:05:49 +00:00
bcc miss
2017-09-07 02:38:06 +00:00
cmp #row1_bot+border_br + 1 ; (+ 1 is bug in original?)
2017-09-06 06:55:44 +00:00
bcs :+
2017-09-07 02:05:49 +00:00
jsr find_button_col
bcc miss
lda row1_lookup,x
rts
2017-09-07 02:38:06 +00:00
: cmp #row2_top-border_lt ; row 2?
2017-09-07 02:05:49 +00:00
bcc miss
2017-09-07 02:38:06 +00:00
cmp #row2_bot+border_br
2017-09-06 06:55:44 +00:00
bcs :+
2017-09-07 02:05:49 +00:00
jsr find_button_col
bcc miss
lda row2_lookup,x
rts
2017-09-07 02:38:06 +00:00
: cmp #row3_top-border_lt ; row 3?
2017-09-07 02:05:49 +00:00
bcc miss
2017-09-07 02:38:06 +00:00
cmp #row3_bot+border_br
2017-09-06 06:55:44 +00:00
bcs :+
2017-09-07 02:05:49 +00:00
jsr find_button_col
bcc miss
lda row3_lookup,x
rts
2017-09-07 02:38:06 +00:00
: cmp #row4_top-border_lt ; row 4?
2017-09-07 02:05:49 +00:00
bcc miss
2017-09-07 02:38:06 +00:00
cmp #row4_bot+border_br
2017-09-06 06:55:44 +00:00
bcs :+
2017-09-07 02:05:49 +00:00
jsr find_button_col
bcc miss
sec
2017-09-07 02:05:49 +00:00
lda row4_lookup,x
rts
: cmp #row5_top-border_lt ; special case for tall + button
2017-09-06 06:55:44 +00:00
bcs :+
2017-09-09 03:13:09 +00:00
lda map_coords_params::clientx
cmp #col4_left-border_lt
2017-09-07 02:05:49 +00:00
bcc miss
cmp #col4_right+border_br-1 ; is -1 bug in original?
2017-09-07 02:05:49 +00:00
bcs miss
lda #'+'
sec
rts
2017-09-07 02:38:06 +00:00
: cmp #row5_bot+border_br ; row 5?
2017-09-07 02:05:49 +00:00
bcs miss
jsr find_button_col
2017-09-06 06:55:44 +00:00
bcc :+
2017-09-07 02:05:49 +00:00
lda row5_lookup,x
rts
2017-09-09 03:13:09 +00:00
: lda map_coords_params::clientx ; special case for wide 0 button
cmp #col1_left-border_lt
2017-09-07 02:05:49 +00:00
bcc miss
cmp #col2_right+border_br
2017-09-07 02:05:49 +00:00
bcs miss
lda #'0'
sec
rts
2017-09-07 02:05:49 +00:00
miss: clc
rts
.endproc
2017-09-06 02:08:11 +00:00
2017-09-07 02:05:49 +00:00
row1_lookup := *-1
.byte 'C', 'E', '=', '*'
row2_lookup := *-1
.byte '7', '8', '9', '/'
row3_lookup := *-1
.byte '4', '5', '6', '-'
row4_lookup := *-1
.byte '1', '2', '3', '+'
row5_lookup := *-1
.byte '0', '0', '.', '+'
2017-09-07 03:43:12 +00:00
.proc find_button_col
2017-09-07 02:38:06 +00:00
cpx #col1_left-border_lt ; col 1?
2017-09-07 03:43:12 +00:00
bcc miss
2017-09-07 02:38:06 +00:00
cpx #col1_right+border_br
2017-09-06 06:55:44 +00:00
bcs :+
2017-09-07 02:05:49 +00:00
ldx #1
sec
rts
2017-09-07 02:38:06 +00:00
: cpx #col2_left-border_lt ; col 2?
2017-09-07 03:43:12 +00:00
bcc miss
2017-09-07 02:38:06 +00:00
cpx #col2_right+border_br
2017-09-06 06:55:44 +00:00
bcs :+
2017-09-07 02:05:49 +00:00
ldx #2
sec
rts
2017-09-07 02:38:06 +00:00
: cpx #col3_left-border_lt ; col 3?
2017-09-07 03:43:12 +00:00
bcc miss
2017-09-07 02:38:06 +00:00
cpx #col3_right+border_br
2017-09-06 06:55:44 +00:00
bcs :+
2017-09-07 02:05:49 +00:00
ldx #3
sec
rts
2017-09-07 02:38:06 +00:00
: cpx #col4_left-border_lt ; col 4?
2017-09-07 03:43:12 +00:00
bcc miss
2017-09-07 02:38:06 +00:00
cpx #col4_right+border_br - 1 ; bug in original?
2017-09-07 03:43:12 +00:00
bcs miss
2017-09-07 02:05:49 +00:00
ldx #4
sec
rts
2017-09-07 03:43:12 +00:00
miss: clc
rts
2017-09-07 03:43:12 +00:00
.endproc
2017-09-08 08:00:58 +00:00
.endproc
;;; ==================================================
;;; Handle Key
;;; Accumulator is set to key char. Also used by
;;; click handlers (button is mapped to key char)
;;; and during initialization (by sending 'C', etc)
2017-09-07 03:43:12 +00:00
.proc process_key
cmp #'C' ; Clear?
2017-09-06 06:55:44 +00:00
bne :+
2017-09-08 04:42:58 +00:00
ldx #<btn_c::box
ldy #>btn_c::box
2017-09-09 19:18:06 +00:00
lda #'c'
2017-09-07 06:43:40 +00:00
jsr depress_button
lda #$00
jsr FLOAT
2017-09-07 03:43:12 +00:00
ldx #<farg
ldy #>farg
jsr ROUND
2017-09-07 03:43:12 +00:00
lda #'='
2017-09-08 07:42:45 +00:00
sta calc_op
2017-09-07 03:43:12 +00:00
lda #0
2017-09-15 07:53:45 +00:00
sta calc_p
2017-09-10 00:43:37 +00:00
sta calc_l
sta calc_d
sta calc_e
sta calc_n
jmp reset_buffers_and_display
2017-09-07 03:43:12 +00:00
: cmp #'E' ; Exponential?
2017-09-15 07:53:45 +00:00
bne try_eq
2017-09-08 04:42:58 +00:00
ldx #<btn_e::box
ldy #>btn_e::box
2017-09-09 19:18:06 +00:00
lda #'e'
2017-09-07 06:43:40 +00:00
jsr depress_button
2017-09-10 00:43:37 +00:00
ldy calc_e
2017-09-15 07:53:45 +00:00
bne rts1
2017-09-10 00:43:37 +00:00
ldy calc_l
2017-09-06 06:55:44 +00:00
bne :+
2017-09-10 00:43:37 +00:00
inc calc_l
2017-09-06 06:37:05 +00:00
lda #'1'
2017-09-06 07:00:46 +00:00
sta text_buffer1 + text_buffer_size
sta text_buffer2 + text_buffer_size
2017-09-06 06:55:44 +00:00
: lda #'E'
2017-09-10 00:43:37 +00:00
sta calc_e
2017-09-15 07:53:45 +00:00
jmp update
2017-09-15 07:53:45 +00:00
rts1: rts
2017-09-15 07:53:45 +00:00
try_eq: cmp #'=' ; Equals?
2017-09-06 06:55:44 +00:00
bne :+
pha
2017-09-08 04:42:58 +00:00
ldx #<btn_eq::box
ldy #>btn_eq::box
2017-09-15 04:22:27 +00:00
jmp do_op_click
2017-09-07 03:43:12 +00:00
: cmp #'*' ; Multiply?
2017-09-06 06:55:44 +00:00
bne :+
pha
2017-09-08 04:42:58 +00:00
ldx #<btn_mul::box
ldy #>btn_mul::box
2017-09-15 04:22:27 +00:00
jmp do_op_click
2017-09-07 03:43:12 +00:00
: cmp #'.' ; Decimal?
2017-09-15 04:22:27 +00:00
bne try_add
2017-09-08 04:42:58 +00:00
ldx #<btn_dec::box
ldy #>btn_dec::box
2017-09-07 06:43:40 +00:00
jsr depress_button
2017-09-10 00:43:37 +00:00
lda calc_d
ora calc_e
2017-09-15 04:22:27 +00:00
bne rts2
2017-09-10 00:43:37 +00:00
lda calc_l
2017-09-06 06:55:44 +00:00
bne :+
2017-09-10 00:43:37 +00:00
inc calc_l
2017-09-06 15:55:53 +00:00
: lda #'.'
2017-09-10 00:43:37 +00:00
sta calc_d
2017-09-15 07:53:45 +00:00
jmp update
2017-09-15 04:22:27 +00:00
rts2: rts
2017-09-15 04:22:27 +00:00
try_add:cmp #'+' ; Add?
2017-09-06 06:55:44 +00:00
bne :+
pha
2017-09-08 04:42:58 +00:00
ldx #<btn_add::box
ldy #>btn_add::box
2017-09-15 04:22:27 +00:00
jmp do_op_click
2017-09-07 03:43:12 +00:00
: cmp #'-' ; Subtract?
bne trydiv
pha
2017-09-08 04:42:58 +00:00
ldx #<btn_sub::box
ldy #>btn_sub::box
2017-09-10 00:43:37 +00:00
lda calc_e ; negate vs. subtract
2017-09-07 03:43:12 +00:00
beq :+
2017-09-10 00:43:37 +00:00
lda calc_n
2017-09-07 03:43:12 +00:00
bne :+
sec
2017-09-10 00:43:37 +00:00
ror calc_n
pla
pha
2017-09-15 04:22:27 +00:00
jmp do_digit_click
2017-09-07 03:43:12 +00:00
: pla
pha
2017-09-15 04:22:27 +00:00
jmp do_op_click
2017-09-07 03:43:12 +00:00
trydiv: cmp #'/' ; Divide?
2017-09-06 06:55:44 +00:00
bne :+
pha
2017-09-08 04:42:58 +00:00
ldx #<btn_div::box
ldy #>btn_div::box
2017-09-15 04:22:27 +00:00
jmp do_op_click
2017-09-07 03:43:12 +00:00
: cmp #'0' ; Digit 0?
2017-09-06 06:55:44 +00:00
bne :+
pha
2017-09-08 04:42:58 +00:00
ldx #<btn_0::box
ldy #>btn_0::box
2017-09-15 04:22:27 +00:00
jmp do_digit_click
2017-09-07 03:43:12 +00:00
: cmp #'1' ; Digit 1?
2017-09-06 06:55:44 +00:00
bne :+
pha
2017-09-08 04:42:58 +00:00
ldx #<btn_1::box
ldy #>btn_1::box
2017-09-15 04:22:27 +00:00
jmp do_digit_click
2017-09-07 03:43:12 +00:00
: cmp #'2' ; Digit 2?
2017-09-06 06:55:44 +00:00
bne :+
pha
2017-09-08 04:42:58 +00:00
ldx #<btn_2::box
ldy #>btn_2::box
2017-09-15 04:22:27 +00:00
jmp do_digit_click
2017-09-07 03:43:12 +00:00
: cmp #'3' ; Digit 3?
2017-09-06 06:55:44 +00:00
bne :+
pha
2017-09-08 04:42:58 +00:00
ldx #<btn_3::box
ldy #>btn_3::box
2017-09-15 04:22:27 +00:00
jmp do_digit_click
2017-09-07 03:43:12 +00:00
: cmp #'4' ; Digit 4?
2017-09-06 06:55:44 +00:00
bne :+
pha
2017-09-08 04:42:58 +00:00
ldx #<btn_4::box
ldy #>btn_4::box
2017-09-15 04:22:27 +00:00
jmp do_digit_click
2017-09-07 03:43:12 +00:00
: cmp #'5' ; Digit 5?
2017-09-06 06:55:44 +00:00
bne :+
pha
2017-09-08 04:42:58 +00:00
ldx #<btn_5::box
ldy #>btn_5::box
2017-09-15 04:22:27 +00:00
jmp do_digit_click
2017-09-07 03:43:12 +00:00
: cmp #'6' ; Digit 6?
2017-09-06 06:55:44 +00:00
bne :+
pha
2017-09-08 04:42:58 +00:00
ldx #<btn_6::box
ldy #>btn_6::box
2017-09-15 04:22:27 +00:00
jmp do_digit_click
2017-09-07 03:43:12 +00:00
: cmp #'7' ; Digit 7?
2017-09-06 06:55:44 +00:00
bne :+
pha
2017-09-08 04:42:58 +00:00
ldx #<btn_7::box
ldy #>btn_7::box
2017-09-15 04:22:27 +00:00
jmp do_digit_click
2017-09-07 03:43:12 +00:00
: cmp #'8' ; Digit 8?
2017-09-06 06:55:44 +00:00
bne :+
pha
2017-09-08 04:42:58 +00:00
ldx #<btn_8::box
ldy #>btn_8::box
2017-09-15 04:22:27 +00:00
jmp do_digit_click
2017-09-07 03:43:12 +00:00
: cmp #'9' ; Digit 9?
2017-09-06 06:55:44 +00:00
bne :+
pha
2017-09-08 04:42:58 +00:00
ldx #<btn_9::box
ldy #>btn_9::box
2017-09-15 04:22:27 +00:00
jmp do_digit_click
2017-09-07 03:43:12 +00:00
: cmp #$7F ; Delete?
bne end
2017-09-10 00:43:37 +00:00
ldy calc_l
2017-09-07 03:43:12 +00:00
beq end
2017-09-06 15:55:53 +00:00
cpy #1
2017-09-06 06:55:44 +00:00
bne :+
jsr reset_buffer1_and_state
jmp display_buffer1
2017-09-10 00:43:37 +00:00
: dec calc_l
2017-09-06 05:59:02 +00:00
ldx #0
2017-09-06 07:00:46 +00:00
lda text_buffer1 + text_buffer_size
2017-09-06 05:59:02 +00:00
cmp #'.'
2017-09-07 04:33:22 +00:00
bne :+
2017-09-10 00:43:37 +00:00
stx calc_d
2017-09-07 04:33:22 +00:00
: cmp #'E'
2017-09-06 06:55:44 +00:00
bne :+
2017-09-10 00:43:37 +00:00
stx calc_e
2017-09-06 06:55:44 +00:00
: cmp #'-'
bne :+
2017-09-10 00:43:37 +00:00
stx calc_n
2017-09-07 04:33:22 +00:00
: ldx #text_buffer_size-1
loop: lda text_buffer1,x
2017-09-06 06:24:21 +00:00
sta text_buffer1+1,x
2017-09-06 06:37:05 +00:00
sta text_buffer2+1,x
dex
dey
2017-09-07 04:33:22 +00:00
bne loop
2017-09-06 06:55:44 +00:00
lda #' '
2017-09-06 06:24:21 +00:00
sta text_buffer1+1,x
2017-09-06 06:37:05 +00:00
sta text_buffer2+1,x
jmp display_buffer1
2017-09-07 03:43:12 +00:00
end: rts
.endproc
2017-09-15 04:22:27 +00:00
do_digit_click:
jsr depress_button
2017-09-15 07:53:45 +00:00
bne :+
pla
rts
2017-09-15 07:53:45 +00:00
: pla
update: sec
ror calc_g
2017-09-10 00:43:37 +00:00
ldy calc_l
2017-09-15 07:53:45 +00:00
bne :+
pha
2017-09-08 07:42:45 +00:00
jsr reset_buffer2
pla
2017-09-15 07:53:45 +00:00
cmp #'0'
bne :+
jmp display_buffer1
2017-09-15 07:53:45 +00:00
: sec
ror calc_p
cpy #$0A
2017-09-15 07:53:45 +00:00
bcs rts3
pha
2017-09-10 00:43:37 +00:00
ldy calc_l
2017-09-15 07:53:45 +00:00
beq empty
lda #$0F
sec
2017-09-10 00:43:37 +00:00
sbc calc_l
tax
2017-09-15 07:53:45 +00:00
: lda text_buffer1,x
2017-09-06 06:24:21 +00:00
sta text_buffer1-1,x
2017-09-06 06:37:05 +00:00
sta text_buffer2-1,x
inx
dey
2017-09-15 07:53:45 +00:00
bne :-
empty: inc calc_l
pla
2017-09-06 07:00:46 +00:00
sta text_buffer1 + text_buffer_size
sta text_buffer2 + text_buffer_size
jmp display_buffer1
2017-09-15 07:53:45 +00:00
rts3: rts
2017-09-15 07:53:45 +00:00
.proc do_op_click
2017-09-15 04:22:27 +00:00
jsr depress_button
2017-09-15 07:53:45 +00:00
bne :+
pla
rts
2017-09-15 07:53:45 +00:00
: lda calc_op
2017-09-06 05:59:02 +00:00
cmp #'='
2017-09-06 06:55:44 +00:00
bne :+
2017-09-15 07:53:45 +00:00
lda calc_g
bne reparse
lda #$00
jsr FLOAT
2017-09-15 07:53:45 +00:00
jmp do_op
2017-09-15 07:53:45 +00:00
: lda calc_g
bne reparse
pla
2017-09-08 07:42:45 +00:00
sta calc_op
jmp reset_buffer1_and_state
2017-09-15 07:53:45 +00:00
reparse:lda #<text_buffer1
sta TXTPTR
lda #>text_buffer1
sta TXTPTR+1
jsr adjust_txtptr
jsr FIN
2017-09-15 07:53:45 +00:00
do_op: pla
2017-09-08 07:42:45 +00:00
ldx calc_op
2017-09-15 07:53:45 +00:00
sta calc_op
2017-09-07 03:43:12 +00:00
lda #<farg
ldy #>farg
2017-09-06 05:59:02 +00:00
cpx #'+'
2017-09-06 06:55:44 +00:00
bne :+
jsr FADD
jmp post_op
2017-09-06 06:55:44 +00:00
: cpx #'-'
bne :+
jsr FSUB
jmp post_op
2017-09-06 06:55:44 +00:00
: cpx #'*'
bne :+
jsr FMULT
jmp post_op
2017-09-06 06:55:44 +00:00
: cpx #'/'
bne :+
jsr FDIV
jmp post_op
2017-09-06 06:55:44 +00:00
: cpx #'='
bne post_op
2017-09-15 07:53:45 +00:00
ldy calc_g
bne post_op
jmp reset_buffer1_and_state
2017-09-15 07:53:45 +00:00
.endproc
.proc post_op
ldx #<farg ; after the FP operation is done
2017-09-07 03:43:12 +00:00
ldy #>farg
jsr ROUND
jsr FOUT ; output as null-terminated string to FBUFFR
ldy #0 ; count the eize
sloop: lda FBUFFR,y
beq :+
iny
bne sloop
: ldx #text_buffer_size ; copy to text buffers
cloop: lda FBUFFR-1,y
2017-09-06 06:24:21 +00:00
sta text_buffer1,x
2017-09-06 06:37:05 +00:00
sta text_buffer2,x
dex
dey
bne cloop
cpx #0 ; pad out with spaces if needed
bmi end
pad: lda #' '
2017-09-06 06:24:21 +00:00
sta text_buffer1,x
2017-09-06 06:37:05 +00:00
sta text_buffer2,x
dex
bpl pad
end: jsr display_buffer1
; fall through
.endproc
.proc reset_buffer1_and_state
jsr reset_buffer1
2017-09-06 06:55:44 +00:00
lda #0
2017-09-10 00:43:37 +00:00
sta calc_l
sta calc_d
sta calc_e
sta calc_n
2017-09-15 07:53:45 +00:00
sta calc_g
rts
.endproc
2017-09-07 06:43:40 +00:00
.proc depress_button
2017-09-09 18:27:35 +00:00
button_state := $FC
2017-09-07 06:43:40 +00:00
stx invert_addr
2017-09-07 04:33:22 +00:00
stx c13_addr
2017-09-07 06:43:40 +00:00
stx restore_addr
sty invert_addr+1
2017-09-07 04:33:22 +00:00
sty c13_addr+1
2017-09-07 06:43:40 +00:00
sty restore_addr+1
2017-09-06 05:19:45 +00:00
A2D_CALL A2D_SET_PATTERN, black_pattern
2017-09-10 17:40:08 +00:00
A2D_CALL A2D_SET_FILL_MODE, fill_mode_xor
sec
2017-09-09 18:27:35 +00:00
ror button_state
invert: A2D_CALL A2D_FILL_RECT, 0, invert_addr ; Inverts box
2017-09-07 04:33:22 +00:00
check_button:
2017-09-09 03:13:09 +00:00
A2D_CALL A2D_GET_INPUT, input_state_params
lda input_state_params::state
cmp #A2D_INPUT_HELD ; Button down?
2017-09-07 04:33:22 +00:00
bne done ; Nope, done immediately
2017-09-07 02:38:06 +00:00
lda #window_id
2017-09-09 03:13:09 +00:00
sta map_coords_params::id
2017-09-09 18:27:35 +00:00
2017-09-09 03:13:09 +00:00
A2D_CALL A2D_MAP_COORDS, map_coords_params
2017-09-09 19:18:06 +00:00
A2D_CALL A2D_SET_POS, map_coords_params::client
A2D_CALL A2D_TEST_BOX, 0, c13_addr
bne inside
2017-09-09 18:27:35 +00:00
lda button_state ; outside, not down
beq check_button ; so keep looping
lda #0 ; outside, was down
sta button_state ; so set up
beq invert ; and show it
inside: lda button_state ; inside, and down
bne check_button ; so keep looking
sec ; inside, was not down
ror button_state ; so set down
jmp invert ; and show it
2017-09-09 18:27:35 +00:00
done: lda button_state ; high bit set if button down
2017-09-07 06:43:40 +00:00
beq :+
A2D_CALL A2D_FILL_RECT, 0, restore_addr ; Inverts back to normal
2017-09-10 17:40:08 +00:00
: A2D_CALL A2D_SET_FILL_MODE, fill_mode_normal ; Normal draw mode??
2017-09-09 18:27:35 +00:00
lda button_state
rts
2017-09-07 04:33:22 +00:00
.endproc
;;; ==================================================
;;; Value Display
2017-09-08 07:42:45 +00:00
.proc reset_buffer1
ldy #text_buffer_size
loop: lda #' '
2017-09-06 06:24:21 +00:00
sta text_buffer1-1,y
dey
2017-09-08 07:42:45 +00:00
bne loop
lda #'0'
2017-09-06 07:00:46 +00:00
sta text_buffer1 + text_buffer_size
rts
2017-09-08 07:42:45 +00:00
.endproc
2017-09-08 07:42:45 +00:00
.proc reset_buffer2
ldy #text_buffer_size
loop: lda #' '
2017-09-06 06:37:05 +00:00
sta text_buffer2-1,y
dey
2017-09-08 07:42:45 +00:00
bne loop
2017-09-06 07:00:46 +00:00
lda #'0'
sta text_buffer2 + text_buffer_size
rts
2017-09-08 07:42:45 +00:00
.endproc
.proc reset_buffers_and_display
jsr reset_buffer1
2017-09-08 07:42:45 +00:00
jsr reset_buffer2
; fall through
.endproc
.proc display_buffer1
ldx #<text_buffer1
2017-09-08 07:42:45 +00:00
ldy #>text_buffer1
jsr pre_display_buffer
2017-09-06 06:24:21 +00:00
A2D_CALL A2D_DRAW_TEXT, draw_text_params1
rts
.endproc
.proc display_buffer2
ldx #<text_buffer2
ldy #>text_buffer2
jsr pre_display_buffer
2017-09-06 06:37:05 +00:00
A2D_CALL A2D_DRAW_TEXT, draw_text_params2
rts
2017-09-08 07:42:45 +00:00
.endproc
.proc pre_display_buffer
stx measure_text_params::addr ; text buffer address in x,y
sty measure_text_params::addr+1
A2D_CALL A2D_MEASURE_TEXT, measure_text_params
lda #display_width-15 ; ???
sec
sbc measure_text_params::width
2017-09-06 05:59:02 +00:00
sta text_pos_params3::left
2017-09-09 19:18:06 +00:00
A2D_CALL A2D_SET_POS, text_pos_params2 ; clear with spaces
2017-09-06 06:37:05 +00:00
A2D_CALL A2D_DRAW_TEXT, spaces_string
2017-09-09 19:18:06 +00:00
A2D_CALL A2D_SET_POS, text_pos_params3 ; set up for display
rts
2017-09-08 07:42:45 +00:00
.endproc
2017-09-08 08:00:58 +00:00
;;; ==================================================
;;; Draw the window contents (background, buttons)
2017-09-10 04:15:01 +00:00
.proc draw_background
2017-09-07 06:43:40 +00:00
;; Frame
A2D_CALL A2D_HIDE_CURSOR
2017-09-06 05:19:45 +00:00
A2D_CALL A2D_SET_PATTERN, background_pattern
2017-09-07 06:43:40 +00:00
A2D_CALL A2D_FILL_RECT, background_box_params
2017-09-06 05:19:45 +00:00
A2D_CALL A2D_SET_PATTERN, black_pattern
2017-09-07 06:43:40 +00:00
A2D_CALL A2D_DRAW_RECT, frame_display_params
2017-09-06 05:19:45 +00:00
A2D_CALL A2D_SET_PATTERN, white_pattern
2017-09-07 06:43:40 +00:00
A2D_CALL A2D_FILL_RECT, clear_display_params
2017-09-19 05:51:24 +00:00
A2D_CALL A2D_SET_TEXT_MASK, text_mask_params
2017-09-10 04:15:01 +00:00
;; fall through
.endproc
2017-09-07 06:43:40 +00:00
2017-09-10 04:15:01 +00:00
.proc draw_buttons
2017-09-07 06:43:40 +00:00
;; Buttons
ptr := $FA
2017-09-08 04:42:58 +00:00
lda #<btn_c
2017-09-07 06:43:40 +00:00
sta ptr
2017-09-08 04:42:58 +00:00
lda #>btn_c
2017-09-07 06:43:40 +00:00
sta ptr+1
loop: ldy #0
lda (ptr),y
2017-09-08 04:42:58 +00:00
beq draw_title_bar ; done!
2017-09-08 07:42:45 +00:00
lda ptr ; address for shadowed rect params
2017-09-14 04:58:37 +00:00
sta bitmap_addr
2017-09-07 06:43:40 +00:00
ldy ptr+1
2017-09-14 04:58:37 +00:00
sty bitmap_addr+1
2017-09-08 07:42:45 +00:00
clc ; address for label pos
adc #(btn_c::pos - btn_c)
2017-09-07 06:43:40 +00:00
sta text_addr
bcc :+
iny
2017-09-07 06:43:40 +00:00
: sty text_addr+1
2017-09-08 07:42:45 +00:00
ldy #(btn_c::label - btn_c) ; label
2017-09-08 04:42:58 +00:00
lda (ptr),y
2017-09-06 06:37:05 +00:00
sta label
2017-09-08 07:42:45 +00:00
2017-09-14 04:58:37 +00:00
A2D_CALL A2D_DRAW_BITMAP, 0, bitmap_addr ; draw shadowed rect
2017-09-09 19:18:06 +00:00
A2D_CALL A2D_SET_POS, 0, text_addr ; button label pos
2017-09-07 06:43:40 +00:00
A2D_CALL A2D_DRAW_TEXT, draw_text_params_label ; button label text
2017-09-08 07:42:45 +00:00
lda ptr ; advance to next record
clc
2017-09-08 04:42:58 +00:00
adc #.sizeof(btn_c)
sta ptr
2017-09-07 06:43:40 +00:00
bcc loop
2017-09-08 04:42:58 +00:00
inc ptr+1
2017-09-07 06:43:40 +00:00
jmp loop
.endproc
2017-09-08 08:00:58 +00:00
;;; ==================================================
2017-09-10 00:43:37 +00:00
;;; Draw the title bar decoration
2017-09-08 08:00:58 +00:00
2017-09-08 04:42:58 +00:00
draw_title_bar:
2017-09-10 00:43:37 +00:00
offset_left := 115 ; pixels from left of client area
offset_top := 22 ; pixels from top of client area (up!)
ldx create_window_params::left+1
lda create_window_params::left
clc
2017-09-10 00:43:37 +00:00
adc #offset_left
sta title_bar_decoration::left
2017-09-08 04:42:58 +00:00
bcc :+
inx
2017-09-10 00:43:37 +00:00
: stx title_bar_decoration::left+1
ldx create_window_params::top+1
lda create_window_params::top
sec
2017-09-10 00:43:37 +00:00
sbc #offset_top
sta title_bar_decoration::top
2017-09-08 04:42:58 +00:00
bcs :+
dex
2017-09-10 00:43:37 +00:00
: stx title_bar_decoration::top+1
2017-09-14 04:35:23 +00:00
A2D_CALL A2D_SET_BOX, screen_box ; set clipping rect to whole screen
2017-09-14 04:58:37 +00:00
A2D_CALL A2D_DRAW_BITMAP, title_bar_decoration ; Draws decoration in title bar
2017-09-07 02:38:06 +00:00
lda #window_id
2017-09-14 04:35:23 +00:00
sta query_state_params::id
A2D_CALL A2D_QUERY_STATE, query_state_params
A2D_CALL A2D_SET_STATE, state_params
2017-09-07 06:43:40 +00:00
A2D_CALL A2D_SHOW_CURSOR
jsr display_buffer2
rts
;; Traps FP error via call to $36 from MON.COUT, resets stack
;; and returns to the input loop.
.proc error_hook
jsr reset_buffers_and_display
2017-09-10 02:11:05 +00:00
A2D_CALL A2D_SET_POS, error_pos
2017-09-06 06:37:05 +00:00
A2D_CALL A2D_DRAW_TEXT, error_string
jsr reset_buffer1_and_state
2017-09-08 07:42:45 +00:00
lda #'='
sta calc_op
ldx saved_stack
txs
2017-09-08 07:42:45 +00:00
jmp input_loop
.endproc
;; Following proc is copied to $B1
.proc adjust_txtptr_copied
loop: inc TXTPTR
2017-09-08 07:42:45 +00:00
bne :+
inc TXTPTR+1
: lda $EA60 ; this ends up being aligned on TXTPTR
cmp #'9'+1 ; after digits?
2017-09-08 07:42:45 +00:00
bcs end
cmp #' ' ; space? keep going
2017-09-08 07:42:45 +00:00
beq loop
sec
sbc #'0' ; convert to digit...
sec
sbc #$D0 ; carry set if successful
2017-09-08 07:42:45 +00:00
end: rts
.endproc
sizeof_adjust_txtptr_copied := * - adjust_txtptr_copied
2017-09-06 05:19:45 +00:00
da_end := *