a2d/desk.acc/calculator.s

1656 lines
45 KiB
ArmAsm
Raw Normal View History

.setcpu "65C02"
.org $800
2017-09-06 05:19:45 +00:00
.include "apple2.inc"
.include "../inc/prodos.inc"
.include "../inc/auxmem.inc"
.include "../inc/applesoft.inc"
2017-09-06 05:19:45 +00:00
.include "a2d.inc"
L0020 := $0020
adjust_txtptr := $B1
2017-09-06 05:19:45 +00:00
ROMIN2 := $C082
COUT_HOOK := $36
2017-09-06 02:08:11 +00:00
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
jmp L0D18
2017-09-09 04:10:56 +00:00
;; Used after a drag-and-drop is completed;
;; redraws the window.
2017-09-09 01:34:34 +00:00
.proc call_4015_main
2017-09-08 06:40:01 +00:00
zp_stash := $20
2017-09-09 01:34:34 +00:00
;; Call jump table entry $4015 in main memory, by
;; copying a trampoline routine to the ZP.
2017-09-08 06:40:01 +00:00
lda LCBANK1
lda LCBANK1
2017-09-08 06:40:01 +00:00
ldx #(routine_end - 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 L089E
2017-09-08 15:41:51 +00:00
2017-09-09 01:34:34 +00:00
;; ???
lda LCBANK1
lda LCBANK1
bit L089D
2017-09-08 15:41:51 +00:00
bmi skip
jsr UNKNOWN_CALL
.byte $0C
.addr 0
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 L089D
2017-09-06 05:19:45 +00:00
lda ROMIN2
2017-09-06 02:08:11 +00:00
A2D_CALL $3C, L08D1
A2D_CALL A2D_TEXT_BOX1, L0C6E
rts
2017-09-08 06:40:01 +00:00
.proc routine
sta RAMRDOFF
sta RAMWRTOFF
2017-09-06 05:19:45 +00:00
jsr JUMP_TABLE_15
sta RAMRDON
sta RAMWRTON
rts
2017-09-08 06:40:01 +00:00
.endproc
routine_end := *
.endproc
2017-09-08 08:00:58 +00:00
;;; ==================================================
2017-09-08 04:42:58 +00:00
L089D: .byte 0
2017-09-09 01:34:34 +00:00
2017-09-09 04:10:56 +00:00
;; Called after window drag is complete
L089E: sta L08D1
lda create_window_params_top
cmp #$BF
2017-09-08 06:40:01 +00:00
bcc :+
lda #$80
sta L089D
rts
2017-09-09 04:10:56 +00:00
: A2D_CALL $3C, L08D1
2017-09-06 02:08:11 +00:00
A2D_CALL A2D_TEXT_BOX1, L0C6E
lda L08D1
2017-09-08 06:40:01 +00:00
cmp #window_id
bne L08C4
2017-09-07 06:43:40 +00:00
jmp draw_window
L08C4: rts
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
.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 button_click_params
2017-09-08 04:42:58 +00:00
state: .byte 0
2017-09-06 06:24:21 +00:00
.endproc
;; param block for a 3C call
L08D1: .byte $00 ; set to window_id
2017-09-08 15:41:51 +00:00
.addr L0C6E
2017-09-08 04:42:58 +00:00
;; param block for a 1A call
L08D4: .byte $80
2017-09-08 04:42:58 +00:00
;; param block for a 1A call
L08D5: .byte $00
2017-09-06 15:23:23 +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-10 00:43:37 +00:00
pattern_width := 3 ; bytes
2017-09-08 04:42:58 +00:00
.proc btn_c
2017-09-08 05:13:24 +00:00
.word col1_left - border_lt
.word row1_top - border_lt
2017-09-10 00:43:37 +00:00
.addr button_pattern
.byte pattern_width
.byte $00,$00,$00,$00,$00 ; ???
2017-09-08 05:13:24 +00:00
.word button_width + border_lt + border_br
.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-08 07:10:54 +00:00
.word col2_left - border_lt
.word row1_top - border_lt
2017-09-10 00:43:37 +00:00
.addr button_pattern
.byte pattern_width
.byte $00,$00,$00,$00,$00
2017-09-08 07:10:54 +00:00
.word button_width + border_lt + border_br
.word button_height + border_lt + border_br
label: .byte 'e'
2017-09-08 07:42:45 +00:00
.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-08 07:10:54 +00:00
.word col3_left - border_lt
.word row1_top - border_lt
2017-09-10 00:43:37 +00:00
.addr button_pattern
.byte pattern_width
.byte $00,$00,$00,$00,$00
2017-09-08 07:10:54 +00:00
.word button_width + border_lt + border_br
.word button_height + border_lt + border_br
label: .byte '='
2017-09-08 07:42:45 +00:00
.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-08 07:10:54 +00:00
.word col4_left - border_lt
.word row1_top - border_lt
2017-09-10 00:43:37 +00:00
.addr button_pattern
.byte pattern_width
.byte $00,$00,$00,$00,$00
2017-09-08 07:10:54 +00:00
.word button_width + border_lt + border_br
.word button_height + border_lt + border_br
label: .byte '*'
2017-09-08 07:42:45 +00:00
.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-08 07:10:54 +00:00
.word col1_left - border_lt
.word row2_top - border_lt
2017-09-10 00:43:37 +00:00
.addr button_pattern
.byte pattern_width
.byte $00,$00,$00,$00,$00
2017-09-08 07:10:54 +00:00
.word button_width + border_lt + border_br
.word button_height + border_lt + border_br
label: .byte '7'
2017-09-08 07:42:45 +00:00
.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-08 07:10:54 +00:00
.word col2_left - border_lt
.word row2_top - border_lt
2017-09-10 00:43:37 +00:00
.addr button_pattern
.byte pattern_width
.byte $00,$00,$00,$00,$00
2017-09-08 07:10:54 +00:00
.word button_width + border_lt + border_br
.word button_height + border_lt + border_br
label: .byte '8'
2017-09-08 07:42:45 +00:00
.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-08 07:10:54 +00:00
.word col3_left - border_lt
.word row2_top - border_lt
2017-09-10 00:43:37 +00:00
.addr button_pattern
.byte pattern_width
.byte $00,$00,$00,$00,$00
2017-09-08 07:10:54 +00:00
.word button_width + border_lt + border_br
.word button_height + border_lt + border_br
label: .byte '9'
2017-09-08 07:42:45 +00:00
.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-08 07:10:54 +00:00
.word col4_left - border_lt
.word row2_top - border_lt
2017-09-10 00:43:37 +00:00
.addr button_pattern
.byte pattern_width
.byte $00,$00,$00,$00,$00
2017-09-08 07:10:54 +00:00
.word button_width + border_lt + border_br
.word button_height + border_lt + border_br
label: .byte '/'
2017-09-08 07:42:45 +00:00
.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-08 07:10:54 +00:00
.word col1_left - border_lt
.word row3_top - border_lt
2017-09-10 00:43:37 +00:00
.addr button_pattern
.byte pattern_width
.byte $00,$00,$00,$00,$00
2017-09-08 07:10:54 +00:00
.word button_width + border_lt + border_br
.word button_height + border_lt + border_br
label: .byte '4'
2017-09-08 07:42:45 +00:00
.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-08 07:10:54 +00:00
.word col2_left - border_lt
.word row3_top - border_lt
2017-09-10 00:43:37 +00:00
.addr button_pattern
.byte pattern_width
.byte $00,$00,$00,$00,$00
2017-09-08 07:10:54 +00:00
.word button_width + border_lt + border_br
.word button_height + border_lt + border_br
label: .byte '5'
2017-09-08 07:42:45 +00:00
.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-08 07:10:54 +00:00
.word col3_left - border_lt
.word row3_top - border_lt
2017-09-10 00:43:37 +00:00
.addr button_pattern
.byte pattern_width
.byte $00,$00,$00,$00,$00
2017-09-08 07:10:54 +00:00
.word button_width + border_lt + border_br
.word button_height + border_lt + border_br
label: .byte '6'
2017-09-08 07:42:45 +00:00
.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-08 07:10:54 +00:00
.word col4_left - border_lt
.word row3_top - border_lt
2017-09-10 00:43:37 +00:00
.addr button_pattern
.byte pattern_width
.byte $00,$00,$00,$00,$00
2017-09-08 07:10:54 +00:00
.word button_width + border_lt + border_br
.word button_height + border_lt + border_br
label: .byte '-'
2017-09-08 07:42:45 +00:00
.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-08 07:10:54 +00:00
.word col1_left - border_lt
.word row4_top - border_lt
2017-09-10 00:43:37 +00:00
.addr button_pattern
.byte pattern_width
.byte $00,$00,$00,$00,$00
2017-09-08 07:10:54 +00:00
.word button_width + border_lt + border_br
.word button_height + border_lt + border_br
label: .byte '1'
2017-09-08 07:42:45 +00:00
.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-08 07:10:54 +00:00
.word col2_left - border_lt
.word row4_top - border_lt
2017-09-10 00:43:37 +00:00
.addr button_pattern
.byte pattern_width
.byte $00,$00,$00,$00,$00
2017-09-08 07:10:54 +00:00
.word button_width + border_lt + border_br
.word button_height + border_lt + border_br
label: .byte '2'
2017-09-08 07:42:45 +00:00
.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-08 07:10:54 +00:00
.word col3_left - border_lt
.word row4_top - border_lt
2017-09-10 00:43:37 +00:00
.addr button_pattern
.byte pattern_width
.byte $00,$00,$00,$00,$00
2017-09-08 07:10:54 +00:00
.word button_width + border_lt + border_br
.word button_height + border_lt + border_br
label: .byte '3'
2017-09-08 07:42:45 +00:00
.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-08 07:10:54 +00:00
.word col1_left - border_lt
.word row5_top - border_lt
2017-09-10 00:43:37 +00:00
.addr wide_button_pattern
.byte 8 ; pattern_width (bytes)
.byte $00,$00,$00,$00,$00
2017-09-08 07:10:54 +00:00
.word 49 ; 0 is extra wide
.word button_height + border_lt + border_br
.byte '0'
2017-09-08 07:42:45 +00:00
.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-08 07:10:54 +00:00
.word col3_left - border_lt
.word row5_top - border_lt
2017-09-10 00:43:37 +00:00
.addr button_pattern
.byte pattern_width
.byte $00,$00,$00,$00,$00
2017-09-08 07:10:54 +00:00
.word button_width + border_lt + border_br
.word button_height + border_lt + border_br
.byte '.'
2017-09-08 07:42:45 +00:00
.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-08 07:10:54 +00:00
.word col4_left - border_lt
.word row4_top - border_lt
2017-09-10 00:43:37 +00:00
.addr tall_button_pattern
.byte pattern_width,$00,$00,$00,$00,$00
2017-09-08 07:10:54 +00:00
.word button_width + border_lt + border_br
.word 27 ; + is extra tall
.byte '+'
2017-09-08 07:42:45 +00:00
.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-10 00:43:37 +00:00
;; patterns are low 7 bits, 0=black 1=white
button_pattern: ; pattern for normal buttons
.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)
wide_button_pattern: ; pattern for '0' button
.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)
tall_button_pattern: ; pattern for '+' button
.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-08 07:42:45 +00:00
;; Calculation state
saved_stack:
.byte $00 ; restored after error
L0BC5: .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?
L0BCA: .byte $00 ; related to = key
2017-09-10 00:43:37 +00:00
calc_l: .byte $00 ; input length
2017-09-06 05:59:02 +00:00
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:
.byte $00,$00,$00,$00,$00,$00,$00,$00
.byte $00
2017-09-06 05:19:45 +00:00
white_pattern:
.byte $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
.byte $00
2017-09-06 05:19:45 +00:00
L0BEF: .byte $7F
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:
2017-09-06 07:00:46 +00:00
.byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
2017-09-06 06:37:05 +00:00
.proc draw_text_params2
addr: .addr text_buffer2
length: .byte 15
.endproc
text_buffer2:
2017-09-06 07:00:46 +00:00
.byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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
2017-09-07 02:38:06 +00:00
window_id = $34
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-07 03:43:12 +00:00
L0C4E: .byte $45,$00,$10,$00
farg:
.byte $00,$00,$00,$00,$00,$00
2017-09-08 04:42:58 +00:00
2017-09-10 00:43:37 +00:00
.proc title_bar_decoration ; Params for A2D_DRAW_PATTERN
left: .word 115 ; overwritten
top: .word $FFF7 ; overwritten
pattern:.addr pixels
stride: .byte 1
.byte 0,0,0,0,0 ; ???
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
;; param block for a $03 and TEXT_BOX1 calls, and ref'd in $3C call
.proc L0C6E
left: .word 0
top: .word 0
.word 0 ; ??? $03 call sets to $2000 (hires)
.word 0 ; ??? $03 call sets to $80
hoffset:.word 0
voffset:.word 0
width: .word 0 ; $03 call sets to 559
height: .word 0 ; $03 call sets to 191
;; unknown from here
.byte $00,$00,$00,$00,$00,$00,$00,$00,$00 ; filled with $FF by $03 call
.byte $00,$00,$00,$00 ; left $00 by $03
.word 0 ; $03 call sets to $100
.word 0 ; $03 call sets to $1
.word 0 ; $03 call sets to $7F (127)
.word 0 ; $03 call sets to $88 (136)
.endproc
2017-09-08 04:42:58 +00:00
L0C93: .byte $00,$00,$0D,$00,$00,$20,$80,$00
.byte $00,$00,$00,$00,$2F,$02,$B1,$00
2017-09-08 04:42:58 +00:00
2017-09-10 00:43:37 +00:00
L0CA3: .byte $00 ; arg for "normal" fill mode?
.byte $01,$02 ; ??
L0CA6: .byte $06 ; arg for "xor" fill mode?
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 $02
2017-09-06 06:24:21 +00:00
.addr title
hscroll:.byte 0
vscroll:.byte 0
hs_max: .byte 0
hs_pos: .byte 0
vs_max: .byte 0
vs_pos: .byte 0
.byte 0,0 ; ???
width_a: .word window_width
height_a:.word window_height
width_b: .word window_width
height_b:.word window_height
left: .word default_left
top: .word default_top
2017-09-10 00:43:37 +00:00
.word $2000 ;hires?
.word $80
hoffset:.word 0
voffset:.word 0
width: .word window_width
height: .word window_height
.endproc
create_window_params_top := create_window_params::top
;; ???
2017-09-10 00:43:37 +00:00
;; Same as latter part of L0C6E block after $03 call fills it in
.byte $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
.byte $00,$00
.byte $00,$00,$00,$01,$01,$00,$7F,$00
2017-09-10 00:43:37 +00:00
.byte $88,$00
.byte $00
2017-09-06 06:24:21 +00:00
title: PASCAL_STRING "Calc"
;; param block for $24 call (just before entering input loop)
L0CE6: .byte $00,$00,$02,$00,$06,$00,$0E,$00
.byte $1E,$00,$3E,$00,$7E,$00,$1A,$00
.byte $30,$00,$30,$00,$60,$00,$00,$00
.byte $03,$00,$07,$00,$0F,$00,$1F,$00
.byte $3F,$00,$7F,$00,$7F,$01,$7F,$00
.byte $78,$00,$78,$00,$70,$01,$70,$01
.byte $01,$01
2017-09-06 05:19:45 +00:00
2017-09-08 08:00:58 +00:00
;;; ==================================================
;;; DA Init
L0D18: sta ALTZPON
lda LCBANK1
lda LCBANK1
2017-09-06 02:08:11 +00:00
A2D_CALL $1A, L08D4
2017-09-06 05:59:02 +00:00
A2D_CALL A2D_CREATE_WINDOW, create_window_params
2017-09-10 00:43:37 +00:00
A2D_CALL $03, L0C6E ; get display state?
A2D_CALL A2D_TEXT_BOX1, L0C6E ; set clipping bounds?
2017-09-06 02:08:11 +00:00
A2D_CALL $2B, 0
lda #$01
2017-09-09 03:13:09 +00:00
sta input_state_params::state
A2D_CALL $2D, 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 L089E
jsr reset_buffers_and_display
2017-09-08 07:42:45 +00:00
lda #'=' ; last operation
sta calc_op
lda #0 ; clear registers
sta L0BC5
2017-09-10 00:43:37 +00:00
sta calc_d
sta calc_e
sta calc_n
sta L0BCA
2017-09-10 00:43:37 +00:00
sta calc_l
2017-09-08 07:42:45 +00:00
.proc copy_to_b1
ldx #(end_adjust_txtptr_copied - 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-06 02:08:11 +00:00
A2D_CALL $24, L0CE6
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 :+
2017-09-06 06:24:21 +00:00
A2D_CALL A2D_BTN_CLICK, button_click_params
lda button_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
jsr UNKNOWN_CALL
.byte $0C
.addr 0
2017-09-06 05:19:45 +00:00
lda ROMIN2
2017-09-06 02:08:11 +00:00
A2D_CALL $1A, L08D5
2017-09-08 03:59:38 +00:00
.proc do_close
;; Copy following routine to ZP and invoke it
zp_stash := $20
ldx #(routine_end - routine)
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
routine_end := * ; Can't use .sizeof before the .proc definition
.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-09 04:10:56 +00:00
jsr call_4015_main ; redraws 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-07 03:43:12 +00:00
cmp #$1B ; Escape?
bne trydel
2017-09-07 06:43:40 +00:00
lda L0BC5
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
L0E94: rts ; used by prev/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
bne L0E94
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
sta L0BC5
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?
bne L0FC7
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
bne L0FC6
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
jmp L1107
L0FC6: rts
2017-09-07 03:43:12 +00:00
L0FC7: 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
jmp L114C
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
jmp L114C
2017-09-07 03:43:12 +00:00
: cmp #'.' ; Decimal?
bne L1003
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
bne L1002
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
jmp L1107
L1002: rts
2017-09-07 03:43:12 +00:00
L1003: 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
jmp L114C
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
jmp L10FF
2017-09-07 03:43:12 +00:00
: pla
pha
jmp L114C
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
jmp L114C
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
jmp L10FF
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
jmp L10FF
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
jmp L10FF
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
jmp L10FF
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
jmp L10FF
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
jmp L10FF
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
jmp L10FF
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
jmp L10FF
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
jmp L10FF
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
jmp L10FF
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-07 06:43:40 +00:00
L10FF: jsr depress_button
bne L1106
pla
rts
L1106: pla
L1107: sec
ror L0BCA
2017-09-10 00:43:37 +00:00
ldy calc_l
bne L111C
pha
2017-09-08 07:42:45 +00:00
jsr reset_buffer2
pla
cmp #$30
bne L111C
jmp display_buffer1
L111C: sec
ror L0BC5
cpy #$0A
bcs L114B
pha
2017-09-10 00:43:37 +00:00
ldy calc_l
beq L113E
lda #$0F
sec
2017-09-10 00:43:37 +00:00
sbc calc_l
tax
2017-09-06 06:24:21 +00:00
L1131: lda text_buffer1,x
sta text_buffer1-1,x
2017-09-06 06:37:05 +00:00
sta text_buffer2-1,x
inx
dey
bne L1131
2017-09-10 00:43:37 +00:00
L113E: 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
L114B: rts
2017-09-07 06:43:40 +00:00
L114C: jsr depress_button
bne L1153
pla
rts
2017-09-08 07:42:45 +00:00
L1153: lda calc_op
2017-09-06 05:59:02 +00:00
cmp #'='
2017-09-06 06:55:44 +00:00
bne :+
lda L0BCA
bne L1173
lda #$00
jsr FLOAT
jmp L1181
2017-09-06 06:55:44 +00:00
: lda L0BCA
bne L1173
pla
2017-09-08 07:42:45 +00:00
sta calc_op
jmp reset_buffer1_and_state
2017-09-08 07:42:45 +00:00
L1173: lda #<text_buffer1
sta TXTPTR
lda #>text_buffer1
sta TXTPTR+1
jsr adjust_txtptr
jsr FIN
L1181: pla
2017-09-08 07:42:45 +00:00
ldx calc_op
sta calc_op ; Operation
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
ldy L0BCA
bne post_op
jmp reset_buffer1_and_state
.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
sta L0BCA
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-07 06:43:40 +00:00
A2D_CALL $07, L0CA6 ; set 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
: A2D_CALL $07, L0CA3 ; 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-07 06:43:40 +00:00
.proc draw_window
;; 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
A2D_CALL $0C, L0BEF ; ???
;; 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-10 00:43:37 +00:00
sta pattern_addr
2017-09-07 06:43:40 +00:00
ldy ptr+1
2017-09-10 00:43:37 +00:00
sty pattern_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-10 00:43:37 +00:00
A2D_CALL A2D_DRAW_PATTERN, 0, pattern_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-06 02:08:11 +00:00
A2D_CALL A2D_TEXT_BOX2, L0C93
2017-09-10 00:43:37 +00:00
A2D_CALL A2D_DRAW_PATTERN, title_bar_decoration ; Draws decoration in title bar
2017-09-07 02:38:06 +00:00
lda #window_id
sta L08D1
2017-09-06 02:08:11 +00:00
A2D_CALL $3C, L08D1
A2D_CALL A2D_TEXT_BOX1, L0C6E
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-09 19:18:06 +00:00
A2D_CALL A2D_SET_POS, L0C4E
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
end_adjust_txtptr_copied := *
2017-09-06 05:19:45 +00:00
da_end := *