a2d/desk.acc/calculator.s

1643 lines
45 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"
2018-01-29 05:18:00 +00:00
.include "../mgtk.inc"
2018-05-03 03:04:56 +00:00
.include "../desktop.inc"
2018-02-07 02:42:00 +00:00
.include "../macros.inc"
2018-05-03 03:04:56 +00:00
;;; ============================================================
.org $800
adjust_txtptr := $B1
2018-03-05 05:36:00 +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
2018-03-05 05:36:00 +00:00
;;; ============================================================
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
2018-02-07 02:42:00 +00:00
copy16 #start, STARTLO
copy16 #end, ENDLO
copy16 #dest, DESTINATIONLO
2017-09-06 05:19:45 +00:00
sec ; main>aux
jsr AUXMOVE
2017-09-06 02:08:11 +00:00
2017-09-09 01:34:34 +00:00
;; Invoke it.
2018-02-07 02:42:00 +00:00
copy16 #start, XFERSTARTLO
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
2018-03-05 05:36:00 +00:00
;;; ============================================================
2017-09-08 08:00:58 +00:00
2018-01-30 04:49:42 +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
2018-03-05 05:36:00 +00:00
;;; ============================================================
2017-09-08 08:00:58 +00:00
2017-09-06 05:19:45 +00:00
call_init:
2017-09-15 04:22:27 +00:00
jmp init
2018-02-03 04:10:19 +00:00
;; Used after a event_kind_drag-and-drop is completed;
2017-09-09 04:10:56 +00:00
;; 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)
2018-04-07 07:33:15 +00:00
zp_routine := $20
COPY_BYTES sizeof_routine+1, routine, zp_routine
jsr zp_routine
2018-02-05 03:13:21 +00:00
DESKTOP_CALL DT_REDRAW_ICONS
2017-09-06 05:19:45 +00:00
2018-02-19 18:48:21 +00:00
;; Redraw window after event_kind_drag
2018-04-07 07:33:15 +00:00
jsr draw_content
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
2018-03-05 05:36:00 +00:00
;;; ============================================================
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
2018-01-30 04:14:34 +00:00
.proc screentowindow_params
2018-01-30 04:49:42 +00:00
window_id := *
2017-09-09 03:13:09 +00:00
screen := * + 1
2018-01-30 05:11:32 +00:00
screenx := * + 1 ; aligns with event_params::xcoord
screeny := * + 3 ; aligns with event_params::ycoord
2018-01-30 04:49:42 +00:00
window := * + 5
windowx := * + 5
windowy := * + 7
2017-09-09 03:13:09 +00:00
.endproc
2018-01-30 04:49:42 +00:00
.proc dragwindow_params
window_id := *
2018-01-30 05:11:32 +00:00
xcoord := * + 1 ; aligns with event_params::xcoord
ycoord := * + 3 ; aligns with event_params::ycoord
2017-09-25 04:02:13 +00:00
moved := * + 5 ; ignored
2017-09-09 04:10:56 +00:00
.endproc
2018-01-30 04:14:34 +00:00
.proc event_params
kind: .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
2018-01-30 04:14:34 +00:00
.proc findwindow_params
2018-01-30 04:49:42 +00:00
mousex: .word 0 ; aligns with event_params::xcoord
mousey: .word 0 ; aligns with event_params::ycoord
2018-01-30 04:14:34 +00:00
which_area: .byte 0
2018-01-30 04:49:42 +00:00
window_id: .byte 0
2017-09-06 05:59:02 +00:00
.endproc
2018-01-30 04:14:34 +00:00
.byte 0, 0 ; fills out space for screentowindow_params
2017-09-09 03:45:11 +00:00
.byte 0, 0 ; ???
2017-09-06 06:24:21 +00:00
2018-01-30 04:14:34 +00:00
.proc trackgoaway_params
goaway: .byte 0
2017-09-06 06:24:21 +00:00
.endproc
2018-01-30 04:14:34 +00:00
.proc getwinport_params
2018-04-07 07:33:15 +00:00
window_id: .byte da_window_id
2018-02-27 04:51:23 +00:00
.addr grafport
2017-09-10 01:11:01 +00:00
.endproc
2018-01-30 04:49:42 +00:00
getwinport_params_window_id := getwinport_params::window_id
2017-09-08 04:42:58 +00:00
2017-09-21 15:09:11 +00:00
.proc preserve_zp_params
2018-01-29 05:18:00 +00:00
flag: .byte MGTK::zp_preserve
2017-09-21 15:09:11 +00:00
.endproc
2017-09-08 04:42:58 +00:00
2017-09-21 15:09:11 +00:00
.proc overwrite_zp_params
2018-01-29 05:18:00 +00:00
flag: .byte MGTK::zp_overwrite
2017-09-21 15:09:11 +00:00
.endproc
2018-03-05 05:36:00 +00:00
;;; ============================================================
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
2018-01-31 08:18:07 +00:00
viewloc: DEFINE_POINT col1_left - border_lt, row1_top - border_lt
2018-01-30 05:11:32 +00:00
mapbits: .addr button_bitmap
2018-01-30 04:49:42 +00:00
mapwidth: .byte bitmap_stride
2018-01-31 08:18:07 +00:00
reserved: .byte 0
maprect: DEFINE_RECT 0, 0, button_width + border_lt + border_br, 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
2018-01-30 04:49:42 +00:00
port: .word col1_left,row1_top,col1_right,row1_bot
2017-09-08 04:42:58 +00:00
.endproc
2017-09-06 15:23:23 +00:00
2017-09-08 04:42:58 +00:00
.proc btn_e
2018-01-31 08:18:07 +00:00
viewloc: DEFINE_POINT col2_left - border_lt, row1_top - border_lt
2018-01-30 05:11:32 +00:00
mapbits: .addr button_bitmap
2018-01-30 04:49:42 +00:00
mapwidth: .byte bitmap_stride
2018-01-31 08:18:07 +00:00
reserved: .byte 0
maprect: DEFINE_RECT 0, 0, button_width + border_lt + border_br, 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
2018-01-30 04:49:42 +00:00
port: .word col2_left,row1_top,col2_right,row1_bot
2017-09-08 04:42:58 +00:00
.endproc
2017-09-06 15:23:23 +00:00
2017-09-08 04:42:58 +00:00
.proc btn_eq
2018-01-31 08:18:07 +00:00
viewloc: DEFINE_POINT col3_left - border_lt, row1_top - border_lt
2018-01-30 05:11:32 +00:00
mapbits: .addr button_bitmap
2018-01-30 04:49:42 +00:00
mapwidth: .byte bitmap_stride
2018-01-31 08:18:07 +00:00
reserved: .byte 0
maprect: DEFINE_RECT 0, 0, button_width + border_lt + border_br, 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
2018-01-30 04:49:42 +00:00
port: .word col3_left,row1_top,col3_right,row1_bot
2017-09-08 04:42:58 +00:00
.endproc
2017-09-06 15:23:23 +00:00
2017-09-08 04:42:58 +00:00
.proc btn_mul
2018-01-31 08:18:07 +00:00
viewloc: DEFINE_POINT col4_left - border_lt, row1_top - border_lt
2018-01-30 05:11:32 +00:00
mapbits: .addr button_bitmap
2018-01-30 04:49:42 +00:00
mapwidth: .byte bitmap_stride
2018-01-31 08:18:07 +00:00
reserved: .byte 0
maprect: DEFINE_RECT 0, 0, button_width + border_lt + border_br, 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
2018-01-30 04:49:42 +00:00
port: .word col4_left,row1_top,col4_right,row1_bot
2017-09-08 04:42:58 +00:00
.endproc
2017-09-06 15:23:23 +00:00
2017-09-08 04:42:58 +00:00
.proc btn_7
2018-01-31 08:18:07 +00:00
viewloc: DEFINE_POINT col1_left - border_lt, row2_top - border_lt
2018-01-30 05:11:32 +00:00
mapbits: .addr button_bitmap
2018-01-30 04:49:42 +00:00
mapwidth: .byte bitmap_stride
2018-01-31 08:18:07 +00:00
reserved: .byte 0
maprect: DEFINE_RECT 0, 0, button_width + border_lt + border_br, 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
2018-01-30 04:49:42 +00:00
port: .word col1_left,row2_top,col1_right,row2_bot
2017-09-08 04:42:58 +00:00
.endproc
2017-09-06 15:23:23 +00:00
2017-09-08 04:42:58 +00:00
.proc btn_8
2018-01-31 08:18:07 +00:00
viewloc: DEFINE_POINT col2_left - border_lt, row2_top - border_lt
2018-01-30 05:11:32 +00:00
mapbits: .addr button_bitmap
2018-01-30 04:49:42 +00:00
mapwidth: .byte bitmap_stride
2018-01-31 08:18:07 +00:00
reserved: .byte 0
maprect: DEFINE_RECT 0, 0, button_width + border_lt + border_br, 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
2018-01-30 04:49:42 +00:00
port: .word col2_left,row2_top,col2_right,row2_bot
2017-09-08 04:42:58 +00:00
.endproc
2017-09-06 15:23:23 +00:00
2017-09-08 04:42:58 +00:00
.proc btn_9
2018-01-31 08:18:07 +00:00
viewloc: DEFINE_POINT col3_left - border_lt, row2_top - border_lt
2018-01-30 05:11:32 +00:00
mapbits: .addr button_bitmap
2018-01-30 04:49:42 +00:00
mapwidth: .byte bitmap_stride
2018-01-31 08:18:07 +00:00
reserved: .byte 0
maprect: DEFINE_RECT 0, 0, button_width + border_lt + border_br, 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
2018-01-30 04:49:42 +00:00
port: .word col3_left,row2_top,col3_right,row2_bot
2017-09-08 04:42:58 +00:00
.endproc
2017-09-06 15:23:23 +00:00
2017-09-08 04:42:58 +00:00
.proc btn_div
2018-01-31 08:18:07 +00:00
viewloc: DEFINE_POINT col4_left - border_lt, row2_top - border_lt
2018-01-30 05:11:32 +00:00
mapbits: .addr button_bitmap
2018-01-30 04:49:42 +00:00
mapwidth: .byte bitmap_stride
2018-01-31 08:18:07 +00:00
reserved: .byte 0
maprect: DEFINE_RECT 0, 0, button_width + border_lt + border_br, 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
2018-01-30 04:49:42 +00:00
port: .word col4_left,row2_top,col4_right,row2_bot
2017-09-08 04:42:58 +00:00
.endproc
2017-09-06 15:23:23 +00:00
2017-09-08 04:42:58 +00:00
.proc btn_4
2018-01-31 08:18:07 +00:00
viewloc: DEFINE_POINT col1_left - border_lt, row3_top - border_lt
2018-01-30 05:11:32 +00:00
mapbits: .addr button_bitmap
2018-01-30 04:49:42 +00:00
mapwidth: .byte bitmap_stride
2018-01-31 08:18:07 +00:00
reserved: .byte 0
maprect: DEFINE_RECT 0, 0, button_width + border_lt + border_br, 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
2018-01-30 04:49:42 +00:00
port: .word col1_left,row3_top,col1_right,row3_bot
2017-09-08 04:42:58 +00:00
.endproc
2017-09-06 15:23:23 +00:00
2017-09-08 04:42:58 +00:00
.proc btn_5
2018-01-31 08:18:07 +00:00
viewloc: DEFINE_POINT col2_left - border_lt, row3_top - border_lt
2018-01-30 05:11:32 +00:00
mapbits: .addr button_bitmap
2018-01-30 04:49:42 +00:00
mapwidth: .byte bitmap_stride
2018-01-31 08:18:07 +00:00
reserved: .byte 0
maprect: DEFINE_RECT 0, 0, button_width + border_lt + border_br, 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
2018-01-30 04:49:42 +00:00
port: .word col2_left,row3_top,col2_right,row3_bot
2017-09-08 04:42:58 +00:00
.endproc
2017-09-06 15:23:23 +00:00
2017-09-08 04:42:58 +00:00
.proc btn_6
2018-01-31 08:18:07 +00:00
viewloc: DEFINE_POINT col3_left - border_lt, row3_top - border_lt
2018-01-30 05:11:32 +00:00
mapbits: .addr button_bitmap
2018-01-30 04:49:42 +00:00
mapwidth: .byte bitmap_stride
2018-01-31 08:18:07 +00:00
reserved: .byte 0
maprect: DEFINE_RECT 0, 0, button_width + border_lt + border_br, 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
2018-01-30 04:49:42 +00:00
port: .word col3_left,row3_top,col3_right,row3_bot
2017-09-08 04:42:58 +00:00
.endproc
2017-09-06 15:23:23 +00:00
2017-09-08 04:42:58 +00:00
.proc btn_sub
2018-01-31 08:18:07 +00:00
viewloc: DEFINE_POINT col4_left - border_lt, row3_top - border_lt
2018-01-30 05:11:32 +00:00
mapbits: .addr button_bitmap
2018-01-30 04:49:42 +00:00
mapwidth: .byte bitmap_stride
2018-01-31 08:18:07 +00:00
reserved: .byte 0
maprect: DEFINE_RECT 0, 0, button_width + border_lt + border_br, 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
2018-01-30 04:49:42 +00:00
port: .word col4_left,row3_top,col4_right,row3_bot
2017-09-08 04:42:58 +00:00
.endproc
2017-09-06 15:23:23 +00:00
2017-09-08 04:42:58 +00:00
.proc btn_1
2018-01-31 08:18:07 +00:00
viewloc: DEFINE_POINT col1_left - border_lt, row4_top - border_lt
2018-01-30 05:11:32 +00:00
mapbits: .addr button_bitmap
2018-01-30 04:49:42 +00:00
mapwidth: .byte bitmap_stride
2018-01-31 08:18:07 +00:00
reserved: .byte 0
maprect: DEFINE_RECT 0, 0, button_width + border_lt + border_br, 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
2018-01-30 04:49:42 +00:00
port: .word col1_left,row4_top,col1_right,row4_bot
2017-09-08 04:42:58 +00:00
.endproc
2017-09-06 15:23:23 +00:00
2017-09-08 04:42:58 +00:00
.proc btn_2
2018-01-31 08:18:07 +00:00
viewloc: DEFINE_POINT col2_left - border_lt, row4_top - border_lt
2018-01-30 05:11:32 +00:00
mapbits: .addr button_bitmap
2018-01-30 04:49:42 +00:00
mapwidth: .byte bitmap_stride
2018-01-31 08:18:07 +00:00
reserved: .byte 0
maprect: DEFINE_RECT 0, 0, button_width + border_lt + border_br, 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
2018-01-30 04:49:42 +00:00
port: .word col2_left,row4_top,col2_right,row4_bot
2017-09-08 04:42:58 +00:00
.endproc
2017-09-06 15:23:23 +00:00
2017-09-08 04:42:58 +00:00
.proc btn_3
2018-01-31 08:18:07 +00:00
viewloc: DEFINE_POINT col3_left - border_lt, row4_top - border_lt
2018-01-30 05:11:32 +00:00
mapbits: .addr button_bitmap
2018-01-30 04:49:42 +00:00
mapwidth: .byte bitmap_stride
2018-01-31 08:18:07 +00:00
reserved: .byte 0
maprect: DEFINE_RECT 0, 0, button_width + border_lt + border_br, 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
2018-01-30 04:49:42 +00:00
port: .word col3_left,row4_top,col3_right,row4_bot
2017-09-08 04:42:58 +00:00
.endproc
2017-09-06 15:23:23 +00:00
2017-09-08 04:42:58 +00:00
.proc btn_0
2018-01-31 08:18:07 +00:00
viewloc: DEFINE_POINT col1_left - border_lt, row5_top - border_lt
2018-01-30 05:11:32 +00:00
mapbits: .addr wide_button_bitmap
2018-01-30 04:49:42 +00:00
mapwidth: .byte 8 ; bitmap_stride (bytes)
2018-01-31 08:18:07 +00:00
reserved: .byte 0
maprect: DEFINE_RECT 0, 0, 49, button_height + border_lt + border_br ; 0 is extra wide
2017-09-25 00:57:57 +00:00
label: .byte '0'
pos: .word col1_left + 6, row5_bot
2018-01-30 04:49:42 +00:00
port: .word col1_left,row5_top,col2_right,row5_bot
2017-09-08 04:42:58 +00:00
.endproc
2017-09-06 15:23:23 +00:00
2017-09-08 04:42:58 +00:00
.proc btn_dec
2018-01-31 08:18:07 +00:00
viewloc: DEFINE_POINT col3_left - border_lt, row5_top - border_lt
2018-01-30 05:11:32 +00:00
mapbits: .addr button_bitmap
2018-01-30 04:49:42 +00:00
mapwidth: .byte bitmap_stride
2018-01-31 08:18:07 +00:00
reserved: .byte 0
maprect: DEFINE_RECT 0, 0, button_width + border_lt + border_br, button_height + border_lt + border_br
2017-09-25 00:57:57 +00:00
label: .byte '.'
pos: .word col3_left + 6 + 2, row5_bot ; + 2 to center the label
2018-01-30 04:49:42 +00:00
port: .word col3_left,row5_top,col3_right,row5_bot
2017-09-08 04:42:58 +00:00
.endproc
2017-09-06 15:23:23 +00:00
2017-09-08 04:42:58 +00:00
.proc btn_add
2018-01-31 08:18:07 +00:00
viewloc: DEFINE_POINT col4_left - border_lt, row4_top - border_lt
2018-01-30 05:11:32 +00:00
mapbits: .addr tall_button_bitmap
2018-01-30 04:49:42 +00:00
mapwidth: .byte bitmap_stride
2018-01-31 08:18:07 +00:00
reserved: .byte 0
maprect: DEFINE_RECT 0, 0, button_width + border_lt + border_br, 27 ; + is extra tall
2017-09-25 00:57:57 +00:00
label: .byte '+'
pos: .word col4_left + 6, row5_bot
2018-01-30 04:49:42 +00:00
port: .word col4_left,row4_top,col4_right,row5_bot
2017-09-08 04:42:58 +00:00
.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
2018-03-05 05:36:00 +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
2018-03-05 05:36:00 +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
2018-01-30 04:14:34 +00:00
.proc settextbg_params
2018-01-30 05:11:32 +00:00
backcolor: .byte $7F
2017-09-19 05:51:24 +00:00
.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)
2018-01-30 04:14:34 +00:00
.proc drawtext_params_label
2017-09-06 06:37:05 +00:00
.addr label
.byte 1
.endproc
label: .byte 0 ; modified with char to draw
2017-09-06 06:24:21 +00:00
2018-01-30 04:14:34 +00:00
.proc drawtext_params1
2018-01-30 04:49:42 +00:00
textptr: .addr text_buffer1
textlen: .byte 15
2017-09-06 06:24:21 +00:00
.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
2018-01-30 04:14:34 +00:00
.proc drawtext_params2
2018-01-30 04:49:42 +00:00
textptr: .addr text_buffer2
textlen: .byte 15
2017-09-06 06:37:05 +00:00
.endproc
text_buffer2:
.res text_buffer_size+2, 0
2017-09-06 06:37:05 +00:00
spaces_string:
2018-01-29 05:18:00 +00:00
DEFINE_STRING " "
2017-09-06 06:37:05 +00:00
error_string:
2018-01-29 05:18:00 +00:00
DEFINE_STRING "Error "
2017-09-06 06:24:21 +00:00
;; used when clearing display; params to a $18 call
2018-01-30 04:14:34 +00:00
.proc textwidth_params
2018-01-30 04:49:42 +00:00
textptr: .addr text_buffer1
textlen: .byte 15 ; ???
result: .word 0
.endproc
2017-09-06 06:24:21 +00:00
2018-01-30 04:49:42 +00:00
da_window_id = 52
2017-09-07 02:38:06 +00:00
2018-01-30 04:14:34 +00:00
.proc closewindow_params
2018-01-30 04:49:42 +00:00
window_id: .byte da_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
2018-02-27 04:51:23 +00:00
.proc title_bar_bitmap ; Params for MGTK::PaintBits
2018-03-07 18:39:36 +00:00
viewloc: DEFINE_POINT 115, AS_WORD -9, viewloc
mapbits: .addr pixels
mapwidth: .byte 1
2018-01-31 08:18:07 +00:00
reserved: .byte 0
maprect: DEFINE_RECT 0, 0, 6, 5
2017-09-10 00:43:37 +00:00
;; (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
2018-02-27 04:51:23 +00:00
.proc grafport
2018-01-31 08:18:07 +00:00
viewloc: DEFINE_POINT 0, 0
2018-03-07 18:39:36 +00:00
mapbits: .word 0
mapwidth: .word 0
2018-01-31 08:18:07 +00:00
cliprect: DEFINE_RECT 0, 0, 0, 0
2018-03-07 18:39:36 +00:00
pattern: .res 8, 0
colormasks: .byte 0, 0
penloc: DEFINE_POINT 0, 0
penwidth: .byte 0
penheight: .byte 0
penmode: .byte 0
textback: .byte 0
textfont: .addr 0
2017-09-10 00:43:37 +00:00
.endproc
2018-02-27 04:51:23 +00:00
.assert * - grafport = 36, error
.byte 0 ; ???
2017-09-08 04:42:58 +00:00
2017-09-10 01:11:01 +00:00
menu_bar_height := 13
2018-01-29 08:57:55 +00:00
;; params for MGTK::SetPortBits when decorating title bar
2018-01-30 04:14:34 +00:00
.proc screen_port
2018-03-07 18:39:36 +00:00
left: .word 0
top: .word menu_bar_height
mapbits: .word MGTK::screen_mapbits
mapwidth: .word MGTK::screen_mapwidth
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
2018-01-30 04:14:34 +00:00
.proc penmode_normal
2018-01-30 05:11:32 +00:00
penmode: .byte MGTK::pencopy
2017-09-10 17:40:08 +00:00
.endproc
2017-09-10 00:43:37 +00:00
.byte $01,$02 ; ??
2018-01-30 04:14:34 +00:00
.proc penmode_xor
2018-01-30 05:11:32 +00:00
penmode: .byte MGTK::notpenXOR
2017-09-10 17:40:08 +00:00
.endproc
2017-09-06 05:59:02 +00:00
window_width := 130
window_height := 96
default_left := 210
default_top := 60
2018-01-30 04:49:42 +00:00
.proc winfo
2018-03-07 18:39:36 +00:00
window_id: .byte da_window_id
2018-11-18 04:34:17 +00:00
options: .byte MGTK::Option::go_away_box
2018-03-07 18:39:36 +00:00
title: .addr window_title
2018-11-18 04:34:17 +00:00
hscroll: .byte MGTK::Scroll::option_none
vscroll: .byte MGTK::Scroll::option_none
2018-03-07 18:39:36 +00:00
hthumbmax: .byte 0
hthumbpos: .byte 0
vthumbmax: .byte 0
vthumbpos: .byte 0
status: .byte 0
reserved: .byte 0
mincontwidth: .word window_width
mincontlength: .word window_height
maxcontwidth: .word window_width
maxcontlength: .word window_height
left: .word default_left
top: .word default_top
mapbits: .addr MGTK::screen_mapbits
mapwidth: .word MGTK::screen_mapwidth
2018-01-31 08:18:07 +00:00
cliprect: DEFINE_RECT 0, 0, window_width, window_height
2018-03-07 18:39:36 +00:00
pattern: .res 8, $FF
2018-01-30 05:11:32 +00:00
colormasks: .byte MGTK::colormask_and, MGTK::colormask_or
2018-03-07 18:39:36 +00:00
penloc: DEFINE_POINT 0, 0
penwidth: .byte 1
penheight: .byte 1
penmode: .byte 0
textback: .byte $7f
textfont: .addr DEFAULT_FONT
nextwinfo: .addr 0
.endproc
2018-01-30 04:49:42 +00:00
openwindow_params_top := winfo::top
2017-09-06 06:24:21 +00:00
window_title:
PASCAL_STRING "Calc"
2018-02-19 18:48:21 +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
2018-01-29 05:18:00 +00:00
MGTK_CALL MGTK::SetZP1, preserve_zp_params
2018-01-30 04:49:42 +00:00
MGTK_CALL MGTK::OpenWindow, winfo
2018-02-27 04:51:23 +00:00
MGTK_CALL MGTK::InitPort, grafport
2018-04-07 07:33:15 +00:00
MGTK_CALL MGTK::SetPort, grafport
2018-01-29 16:38:23 +00:00
MGTK_CALL MGTK::FlushEvents
2018-02-19 18:48:21 +00:00
2017-09-08 07:42:45 +00:00
jsr reset_buffer2
2018-02-19 18:48:21 +00:00
2018-04-07 07:33:15 +00:00
jsr draw_content
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
2018-02-07 02:42:00 +00:00
copy16 #error_hook, COUT_HOOK ; set up FP error handler
lda #1
2018-02-19 18:48:21 +00:00
jsr CALL_FLOAT
2018-02-07 02:42:00 +00:00
ldxy #farg
2018-02-19 18:48:21 +00:00
jsr CALL_ROUND
lda #0 ; set FAC to 0
2018-02-19 18:48:21 +00:00
jsr CALL_FLOAT
jsr CALL_FADD
jsr CALL_FOUT
lda #$07
2018-02-19 18:48:21 +00:00
jsr CALL_FMULT
lda #$00
2018-02-19 18:48:21 +00:00
jsr CALL_FLOAT
2018-02-07 02:42:00 +00:00
ldxy #farg
2018-02-19 18:48:21 +00:00
jsr CALL_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-08 08:00:58 +00:00
2018-03-05 05:36:00 +00:00
;;; ============================================================
2017-09-08 08:00:58 +00:00
;;; Input Loop
2017-09-08 07:42:45 +00:00
input_loop:
2018-01-30 04:14:34 +00:00
MGTK_CALL MGTK::GetEvent, event_params
lda event_params::kind
2018-11-18 04:34:17 +00:00
cmp #MGTK::EventKind::button_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
2018-11-18 04:34:17 +00:00
: cmp #MGTK::EventKind::key_down
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
2018-03-05 05:36:00 +00:00
;;; ============================================================
2017-09-08 08:00:58 +00:00
;;; On Click
2017-09-08 03:59:38 +00:00
on_click:
2018-01-30 04:14:34 +00:00
MGTK_CALL MGTK::FindWindow, findwindow_params
lda findwindow_params::which_area
2018-11-18 04:34:17 +00:00
cmp #MGTK::Area::content
2017-09-08 03:59:38 +00:00
bcc ignore_click
2018-01-30 04:49:42 +00:00
lda findwindow_params::window_id
cmp #da_window_id ; This window?
2017-09-08 03:59:38 +00:00
beq :+
ignore_click:
rts
2018-01-30 04:14:34 +00:00
: lda findwindow_params::which_area
2018-04-07 07:33:15 +00:00
cmp #MGTK::Area::content ; Content area?
2017-09-08 03:59:38 +00:00
bne :+
2018-04-07 07:33:15 +00:00
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
2018-11-18 04:34:17 +00:00
: cmp #MGTK::Area::close_box ; Close box?
2017-09-08 03:59:38 +00:00
bne :+
2018-01-30 04:14:34 +00:00
MGTK_CALL MGTK::TrackGoAway, trackgoaway_params
lda trackgoaway_params::goaway
2017-09-08 03:59:38 +00:00
beq ignore_click
2018-02-19 18:48:21 +00:00
exit: MGTK_CALL MGTK::CloseWindow, closewindow_params
2018-02-05 03:13:21 +00:00
DESKTOP_CALL DT_REDRAW_ICONS
2017-09-06 05:19:45 +00:00
lda ROMIN2
2018-01-29 05:18:00 +00:00
MGTK_CALL MGTK::SetZP1, overwrite_zp_params
2017-09-08 03:59:38 +00:00
.proc do_close
;; Copy following routine to ZP and invoke it
2018-04-07 07:33:15 +00:00
zp_routine := $20
2017-09-08 03:59:38 +00:00
2018-04-07 07:33:15 +00:00
COPY_BYTES sizeof_routine+1, routine, zp_routine
jmp zp_routine
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
2018-11-18 04:34:17 +00:00
: cmp #MGTK::Area::dragbar ; Title bar?
2017-09-08 03:59:38 +00:00
bne ignore_click
2018-01-30 04:49:42 +00:00
lda #da_window_id
sta dragwindow_params::window_id
MGTK_CALL MGTK::DragWindow, dragwindow_params
2017-09-18 15:10:19 +00:00
jsr redraw_screen_and_window
rts
2018-03-05 05:36:00 +00:00
;;; ============================================================
2017-09-08 08:00:58 +00:00
;;; On Key Press
2017-09-09 03:13:09 +00:00
.proc on_key_press
2018-01-30 04:14:34 +00:00
lda event_params::modifiers
2017-09-07 03:43:12 +00:00
bne bail
2018-01-30 04:14:34 +00:00
lda event_params::key
2018-02-27 04:13:18 +00:00
cmp #CHAR_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
2018-02-27 04:51:23 +00:00
trydel: cmp #CHAR_DELETE ; Delete?
2017-09-07 03:43:12 +00:00
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
2018-03-05 05:36:00 +00:00
;;; ============================================================
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
2018-01-30 04:49:42 +00:00
lda #da_window_id
sta screentowindow_params::window_id
2018-01-30 04:14:34 +00:00
MGTK_CALL MGTK::ScreenToWindow, screentowindow_params
2018-01-30 04:49:42 +00:00
lda screentowindow_params::windowx+1 ; ensure high bits of coords are 0
ora screentowindow_params::windowy+1
2017-09-15 04:22:27 +00:00
bne rts1
2018-01-30 04:49:42 +00:00
lda screentowindow_params::windowy
ldx screentowindow_params::windowx
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 :+
2018-01-30 04:49:42 +00:00
lda screentowindow_params::windowx
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
2018-01-30 04:49:42 +00:00
: lda screentowindow_params::windowx ; 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
2018-02-19 18:48:21 +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
2018-03-05 05:36:00 +00:00
;;; ============================================================
2017-09-08 08:00:58 +00:00
;;; 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 :+
2018-02-07 02:42:00 +00:00
ldxy #btn_c::port
2017-09-09 19:18:06 +00:00
lda #'c'
2017-09-07 06:43:40 +00:00
jsr depress_button
lda #$00
2018-02-19 18:48:21 +00:00
jsr CALL_FLOAT
2018-02-07 02:42:00 +00:00
ldxy #farg
2018-02-19 18:48:21 +00:00
jsr CALL_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
2018-02-07 02:42:00 +00:00
ldxy #btn_e::port
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
2018-02-07 02:42:00 +00:00
ldxy #btn_eq::port
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
2018-02-07 02:42:00 +00:00
ldxy #btn_mul::port
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
2018-02-07 02:42:00 +00:00
ldxy #btn_dec::port
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
2018-02-07 02:42:00 +00:00
ldxy #btn_add::port
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
2018-02-07 02:42:00 +00:00
ldxy #btn_sub::port
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
2018-02-07 02:42:00 +00:00
ldxy #btn_div::port
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
2018-02-07 02:42:00 +00:00
ldxy #btn_0::port
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
2018-02-07 02:42:00 +00:00
ldxy #btn_1::port
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
2018-02-07 02:42:00 +00:00
ldxy #btn_2::port
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
2018-02-07 02:42:00 +00:00
ldxy #btn_3::port
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
2018-02-07 02:42:00 +00:00
ldxy #btn_4::port
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
2018-02-07 02:42:00 +00:00
ldxy #btn_5::port
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
2018-02-07 02:42:00 +00:00
ldxy #btn_6::port
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
2018-02-07 02:42:00 +00:00
ldxy #btn_7::port
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
2018-02-07 02:42:00 +00:00
ldxy #btn_8::port
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
2018-02-07 02:42:00 +00:00
ldxy #btn_9::port
2017-09-15 04:22:27 +00:00
jmp do_digit_click
: cmp #CHAR_DELETE ; Delete?
2017-09-07 03:43:12 +00:00
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
2018-02-19 18:48:21 +00:00
jsr CALL_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
2018-02-07 02:42:00 +00:00
reparse:copy16 #text_buffer1, TXTPTR
jsr adjust_txtptr
2018-02-19 18:48:21 +00:00
jsr CALL_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 :+
2018-02-19 18:48:21 +00:00
jsr CALL_FADD
jmp post_op
2017-09-06 06:55:44 +00:00
: cpx #'-'
bne :+
2018-02-19 18:48:21 +00:00
jsr CALL_FSUB
jmp post_op
2017-09-06 06:55:44 +00:00
: cpx #'*'
bne :+
2018-02-19 18:48:21 +00:00
jsr CALL_FMULT
jmp post_op
2017-09-06 06:55:44 +00:00
: cpx #'/'
bne :+
2018-02-19 18:48:21 +00:00
jsr CALL_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
2018-02-19 18:48:21 +00:00
ldxy #farg ; after the FP operation is done
jsr CALL_ROUND
jsr CALL_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
2018-04-07 07:33:15 +00:00
stxy invert_addr
stxy inrect_params
stxy restore_addr
MGTK_CALL MGTK::GetWinPort, getwinport_params
2018-11-18 04:37:19 +00:00
cmp #MGTK::Error::window_obscured
2018-04-07 07:33:15 +00:00
bne :+
rts
: MGTK_CALL MGTK::SetPort, grafport
2017-09-09 18:27:35 +00:00
button_state := $FC
2018-01-29 05:18:00 +00:00
MGTK_CALL MGTK::SetPattern, black_pattern
2018-01-30 04:14:34 +00:00
MGTK_CALL MGTK::SetPenMode, penmode_xor
sec
2017-09-09 18:27:35 +00:00
ror button_state
2018-01-30 04:49:42 +00:00
invert: MGTK_CALL MGTK::PaintRect, 0, invert_addr ; Inverts port
2017-09-09 18:27:35 +00:00
2017-09-07 04:33:22 +00:00
check_button:
2018-01-30 04:14:34 +00:00
MGTK_CALL MGTK::GetEvent, event_params
lda event_params::kind
2018-11-18 04:34:17 +00:00
cmp #MGTK::EventKind::drag ; Button down?
2017-09-07 04:33:22 +00:00
bne done ; Nope, done immediately
2018-01-30 04:49:42 +00:00
lda #da_window_id
sta screentowindow_params::window_id
2017-09-09 18:27:35 +00:00
2018-01-30 04:14:34 +00:00
MGTK_CALL MGTK::ScreenToWindow, screentowindow_params
2018-01-30 04:49:42 +00:00
MGTK_CALL MGTK::MoveTo, screentowindow_params::window
2018-01-30 04:14:34 +00:00
MGTK_CALL MGTK::InRect, 0, inrect_params
2017-09-09 19:18:06 +00:00
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 :+
2018-01-29 05:18:00 +00:00
MGTK_CALL MGTK::PaintRect, 0, restore_addr ; Inverts back to normal
2018-01-30 04:14:34 +00:00
: MGTK_CALL MGTK::SetPenMode, penmode_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
2018-03-05 05:36:00 +00:00
;;; ============================================================
;;; 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
2018-04-07 07:33:15 +00:00
MGTK_CALL MGTK::GetWinPort, getwinport_params
2018-11-18 04:37:19 +00:00
cmp #MGTK::Error::window_obscured
2018-04-07 07:33:15 +00:00
beq end
MGTK_CALL MGTK::SetPort, grafport
2018-02-07 02:42:00 +00:00
ldxy #text_buffer1
jsr pre_display_buffer
2018-01-30 04:14:34 +00:00
MGTK_CALL MGTK::DrawText, drawtext_params1
2018-02-19 18:48:21 +00:00
end: rts
.endproc
.proc display_buffer2
2018-04-07 07:33:15 +00:00
MGTK_CALL MGTK::GetWinPort, getwinport_params
2018-11-18 04:37:19 +00:00
cmp #MGTK::Error::window_obscured
2018-04-07 07:33:15 +00:00
beq end
MGTK_CALL MGTK::SetPort, grafport
2018-02-07 02:42:00 +00:00
ldxy #text_buffer2
jsr pre_display_buffer
2018-01-30 04:14:34 +00:00
MGTK_CALL MGTK::DrawText, drawtext_params2
2018-02-19 18:48:21 +00:00
end: rts
2017-09-08 07:42:45 +00:00
.endproc
.proc pre_display_buffer
2018-01-30 04:49:42 +00:00
stx textwidth_params::textptr ; text buffer address in x,y
sty textwidth_params::textptr+1
2018-01-30 04:14:34 +00:00
MGTK_CALL MGTK::TextWidth, textwidth_params
lda #display_width-15 ; ???
sec
2018-01-30 04:49:42 +00:00
sbc textwidth_params::result
2017-09-06 05:59:02 +00:00
sta text_pos_params3::left
2018-01-29 05:18:00 +00:00
MGTK_CALL MGTK::MoveTo, text_pos_params2 ; clear with spaces
MGTK_CALL MGTK::DrawText, spaces_string
MGTK_CALL MGTK::MoveTo, text_pos_params3 ; set up for display
rts
2017-09-08 07:42:45 +00:00
.endproc
2018-03-05 05:36:00 +00:00
;;; ============================================================
2017-09-08 08:00:58 +00:00
;;; Draw the window contents (background, buttons)
2018-04-07 07:33:15 +00:00
.proc draw_content
MGTK_CALL MGTK::GetWinPort, getwinport_params
2018-11-18 04:37:19 +00:00
cmp #MGTK::Error::window_obscured
2018-04-07 07:33:15 +00:00
bne :+
rts
: MGTK_CALL MGTK::SetPort, grafport
2017-09-07 06:43:40 +00:00
;; Frame
2018-01-29 05:18:00 +00:00
MGTK_CALL MGTK::HideCursor
MGTK_CALL MGTK::SetPattern, background_pattern
MGTK_CALL MGTK::PaintRect, background_box_params
MGTK_CALL MGTK::SetPattern, black_pattern
MGTK_CALL MGTK::FrameRect, frame_display_params
MGTK_CALL MGTK::SetPattern, white_pattern
MGTK_CALL MGTK::PaintRect, clear_display_params
2018-01-30 04:14:34 +00:00
MGTK_CALL MGTK::SetTextBG, settextbg_params
2017-09-07 06:43:40 +00:00
;; Buttons
ptr := $FA
2017-09-08 04:42:58 +00:00
2018-02-07 02:42:00 +00:00
copy16 #btn_c, ptr
2017-09-07 06:43:40 +00:00
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
2018-01-29 05:18:00 +00:00
MGTK_CALL MGTK::PaintBits, 0, bitmap_addr ; draw shadowed rect
MGTK_CALL MGTK::MoveTo, 0, text_addr ; button label pos
2018-01-30 04:14:34 +00:00
MGTK_CALL MGTK::DrawText, drawtext_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
2018-03-05 05:36:00 +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!)
2018-01-30 04:49:42 +00:00
ldx winfo::left+1
lda winfo::left
clc
2017-09-10 00:43:37 +00:00
adc #offset_left
2018-02-27 04:51:23 +00:00
sta title_bar_bitmap::viewloc::xcoord
2017-09-08 04:42:58 +00:00
bcc :+
inx
2018-02-27 04:51:23 +00:00
: stx title_bar_bitmap::viewloc::xcoord+1
2018-01-30 04:49:42 +00:00
ldx winfo::top+1
lda winfo::top
sec
2017-09-10 00:43:37 +00:00
sbc #offset_top
2018-02-27 04:51:23 +00:00
sta title_bar_bitmap::viewloc::ycoord
2017-09-08 04:42:58 +00:00
bcs :+
dex
2018-02-27 04:51:23 +00:00
: stx title_bar_bitmap::viewloc::ycoord+1
2018-01-30 04:14:34 +00:00
MGTK_CALL MGTK::SetPortBits, screen_port ; set clipping rect to whole screen
2018-02-27 04:51:23 +00:00
MGTK_CALL MGTK::PaintBits, title_bar_bitmap ; Draws decoration in title bar
2018-01-29 05:18:00 +00:00
MGTK_CALL MGTK::ShowCursor
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
2018-02-19 18:48:21 +00:00
lda LCBANK1
lda LCBANK1
jsr reset_buffers_and_display
2018-04-07 07:33:15 +00:00
MGTK_CALL MGTK::GetWinPort, getwinport_params
2018-11-18 04:37:19 +00:00
cmp #MGTK::Error::window_obscured
2018-04-07 07:33:15 +00:00
beq :+
MGTK_CALL MGTK::SetPort, grafport
2018-01-29 05:18:00 +00:00
MGTK_CALL MGTK::MoveTo, error_pos
MGTK_CALL MGTK::DrawText, error_string
2018-04-07 07:33:15 +00:00
2018-02-19 18:48:21 +00:00
: 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
2018-03-07 18:39:36 +00:00
save_org := *
.proc adjust_txtptr_copied
2018-03-07 18:39:36 +00:00
.org $B1
dummy_addr := $EA60
loop: inc TXTPTR
2017-09-08 07:42:45 +00:00
bne :+
inc TXTPTR+1
2018-03-07 18:39:36 +00:00
.assert * + 1 = TXTPTR, error, "misaligned routine"
: lda dummy_addr ; 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
2018-03-07 18:39:36 +00:00
.org save_org + .sizeof(adjust_txtptr_copied)
sizeof_adjust_txtptr_copied := .sizeof(adjust_txtptr_copied)
2017-09-06 05:19:45 +00:00
2018-02-19 18:48:21 +00:00
CALL_FLOAT:
pha
lda ROMIN2
pla
jsr FLOAT
pha
lda LCBANK1
lda LCBANK1
pla
rts
CALL_FADD:
pha
lda ROMIN2
pla
jsr FADD
pha
lda LCBANK1
lda LCBANK1
pla
rts
CALL_FSUB:
pha
lda ROMIN2
jsr FSUB
pha
lda LCBANK1
lda LCBANK1
pla
rts
CALL_FMULT:
pha
lda ROMIN2
pla
jsr FMULT
pha
lda LCBANK1
lda LCBANK1
pla
rts
CALL_FDIV:
pha
lda ROMIN2
pla
jsr FDIV
pha
lda LCBANK1
lda LCBANK1
pla
rts
CALL_FIN:
pha
lda ROMIN2
pla
jsr FIN
pha
lda LCBANK1
lda LCBANK1
pla
rts
CALL_FOUT:
pha
lda ROMIN2
pla
jsr FOUT
pha
lda LCBANK1
lda LCBANK1
pla
rts
CALL_ROUND:
pha
lda ROMIN2
pla
jsr ROUND
pha
lda LCBANK1
lda LCBANK1
pla
rts
2017-09-06 05:19:45 +00:00
da_end := *