Identify kbd/mouse pos, menu state

This commit is contained in:
Joshua Bell 2018-03-23 19:43:22 -07:00
parent d8de51ac59
commit ee0472f55f
2 changed files with 177 additions and 123 deletions

View File

@ -66,7 +66,7 @@ cases, e.g. `HideCursor`, `HideCursorImpl`, etc.
* Define local variables (e.g. `ptr := $06`) * Define local variables (e.g. `ptr := $06`)
* Define offsets, constants, etc. * Define offsets, constants, etc.
* Use math where necessary (e.g. `ldy #offset2 - offset1`) * Use math where necessary (e.g. `ldy #offset2 - offset1`)
* Use `.sizeof()` (or math if needed) rather than hardcoding sizes
## Structure ## Structure
@ -140,3 +140,24 @@ result: .word 0
Currently, only MGTK constants are wrapped in a `.scope` to provide Currently, only MGTK constants are wrapped in a `.scope` to provide
a namespace. We may want to do that for ProDOS and DeskTop stuff as a namespace. We may want to do that for ProDOS and DeskTop stuff as
well in the future. well in the future.
## Self-modifying code
* Add a label for the value being modified (byte or address)
```
sta jump_addr
stx jump_addr+1
jump_addr := *+1
jmp $0000
```
```
sty count
ldy #0
: sta table,y
iny
count := *+1
cpy #count
bne :-
```

View File

@ -82,8 +82,7 @@
port_offset_in_window_params := $14 port_offset_in_window_params := $14
next_offset_in_window_params := $38 next_offset_in_window_params := $38
active := $F4 active_port := $F4 ; address of live port block
active_port := $F4 ; address of live port block
fill_eor_mask := $F6 fill_eor_mask := $F6
x_offset := $F7 x_offset := $F7
@ -114,7 +113,7 @@
bpl :- bpl :-
ldx #$0B ldx #$0B
: lda active_saved,x : lda active_saved,x
sta active,x sta active_port,x
dex dex
bpl :- bpl :-
jsr apply_active_port_to_port jsr apply_active_port_to_port
@ -139,10 +138,7 @@ adjust_stack: ; Adjust stack to account for params
lda (params_addr),y lda (params_addr),y
asl a asl a
tax tax
lda jump_table,x copy16 jump_table,x, jump_addr
sta jump+1
lda jump_table+1,x
sta jump+2
iny ; Point params_addr at params iny ; Point params_addr at params
lda (params_addr),y lda (params_addr),y
@ -192,6 +188,7 @@ store: sta $FF,y ; self modified
dey dey
bpl :- bpl :-
jump_addr := *+1
jump: jsr $FFFF ; the actual call jump: jsr $FFFF ; the actual call
;; Exposed for routines to call directly ;; Exposed for routines to call directly
@ -204,7 +201,7 @@ cleanup:
bpl exit_with_0 bpl exit_with_0
jsr apply_port_to_active_port jsr apply_port_to_active_port
ldx #$0B ldx #$0B
: lda active,x : lda active_port,x
sta active_saved,x sta active_saved,x
dex dex
bpl :- bpl :-
@ -395,8 +392,10 @@ jump_table:
.addr TrackThumbImpl ; $4A TrackThumb .addr TrackThumbImpl ; $4A TrackThumb
.addr UpdateThumbImpl ; $4B UpdateThumb .addr UpdateThumbImpl ; $4B UpdateThumb
.addr ActivateCtlImpl ; $4C ActivateCtl .addr ActivateCtlImpl ; $4C ActivateCtl
;; Extra Calls
.addr L51B3 ; $4D ??? .addr L51B3 ; $4D ???
.addr L7D69 ; $4E ??? .addr SetMenuSelection ; $4E SetMenuSelection
;; Entry point param lengths ;; Entry point param lengths
;; (length, ZP destination, hide cursor flag) ;; (length, ZP destination, hide cursor flag)
@ -4194,7 +4193,7 @@ L6263: rts
L6264: .byte 0 L6264: .byte 0
L6265: bit L6339 L6265: bit L6339
bpl L627C bpl L627C
lda L7D74 lda kbd_mouse_state
bne L627C bne L627C
dec L6264 dec L6264
lda L6264 lda L6264
@ -4223,7 +4222,7 @@ L62A7: bit no_mouse_flag
bpl L62B1 bpl L62B1
lda #$00 lda #$00
sta mouse_status sta mouse_status
L62B1: lda L7D74 L62B1: lda kbd_mouse_state
beq rts4 beq rts4
jsr L7EF5 jsr L7EF5
rts4: rts rts4: rts
@ -4699,7 +4698,7 @@ PostEventImpl:
ldx $83 ldx $83
ldy $84 ldy $84
lda $85 lda $85
jsr L7E19 jsr set_mouse_pos
L6626: jsr L67E4 L6626: jsr L67E4
bcs L663F bcs L663F
tax tax
@ -4779,7 +4778,7 @@ L666D:
bmi end ; minus = is down bmi end ; minus = is down
bit check_kbd_flag bit check_kbd_flag
bpl L66B9 bpl L66B9
lda L7D74 lda kbd_mouse_state
bne L66B9 bne L66B9
lda KBD lda KBD
@ -5260,9 +5259,9 @@ L6A24: stax $B9
beq L6A3C beq L6A3C
jmp L6957 jmp L6957
L6A3C: lda #$00 L6A3C: lda #0
sta L7D7A sta menu_index
sta L7D7B sta menu_item_index
jsr L6553 jsr L6553
sec sec
lda L633B lda L633B
@ -5499,7 +5498,7 @@ MenuSelectImpl:
jsr get_menu_count jsr get_menu_count
jsr L653F jsr L653F
jsr L657E jsr L657E
bit L7D74 bit kbd_mouse_state
bpl L6BF2 bpl L6BF2
jsr L7FE1 jsr L7FE1
jmp L6C23 jmp L6C23
@ -5537,9 +5536,9 @@ L6C40: jsr L6556
ldx L6BDA ldx L6BDA
beq L6C55 beq L6C55
lda L6BD9 lda L6BD9
ldy $A7 ldy $A7 ; ???
sty L7D7A sty menu_index
stx L7D7B stx menu_item_index
L6C55: jmp store_xa_at_params L6C55: jmp store_xa_at_params
L6C58: jsr L6EA1 L6C58: jsr L6EA1
@ -6895,7 +6894,7 @@ L76B6: lda $83,x
dex dex
bpl L76B6 bpl L76B6
jsr window_by_id_or_exit jsr window_by_id_or_exit
bit L7D74 bit kbd_mouse_state
bpl L76D1 bpl L76D1
jsr L817C jsr L817C
L76D1: jsr L653C L76D1: jsr L653C
@ -7776,7 +7775,7 @@ check_win:
KeyboardMouse: KeyboardMouse:
lda #$80 lda #$80
sta L7D74 sta kbd_mouse_state
jmp FlushEventsImpl jmp FlushEventsImpl
;;; ============================================================ ;;; ============================================================
@ -7785,24 +7784,45 @@ KeyboardMouse:
;;; 2 bytes of params, copied to $82 ;;; 2 bytes of params, copied to $82
L7D69: .proc SetMenuSelection
copy16 $82, L7D7A params := $82
rts
lda params+0
sta menu_index
lda params+1
sta menu_item_index
rts
.endproc
;;; ============================================================
;; Set to $80 by KeyboardMouse call; also set to $04,
;; $01 elsewhere.
kbd_mouse_state:
.byte 0
kbd_mouse_x: .word 0
kbd_mouse_y: .word 0
L7D74: .byte $00
L7D75: .byte $00
L7D76: .byte $00
L7D77: .byte $00,$00
L7D79: .byte $00 L7D79: .byte $00
L7D7A: .byte $00
L7D7B: .byte $00 ;; Currently selected menu/menu item. Note that menu is index,
L7D7C: .byte $00 ;; not ID from menu definition.
L7D7D: .byte $00 menu_index:
L7D7E: .byte $00 .byte 0
menu_item_index:
.byte 0
other_mouse_x: .word 0
other_mouse_y: .byte 0
L7D7F: .byte $00 L7D7F: .byte $00
L7D80: .byte $00 L7D80: .byte $00
L7D81: .byte $00 L7D81: .byte $00
L7D82: .byte $00 L7D82: .byte $00
L7D83: ldx #$7F L7D83: ldx #$7F
L7D85: lda $80,x L7D85: lda $80,x
sta L7D99,x sta L7D99,x
@ -7819,10 +7839,15 @@ L7D90: lda L7D99,x
L7D99: .res 128, 0 L7D99: .res 128, 0
L7E19: bit mouse_hooked_flag ;;; ============================================================
bmi L7E49 ;;; X = xlo, Y = xhi, A = y
.proc set_mouse_pos
bit mouse_hooked_flag
bmi no_firmware
bit no_mouse_flag bit no_mouse_flag
bmi L7E49 bmi no_firmware
pha pha
txa txa
sec sec
@ -7842,25 +7867,31 @@ L7E19: bit mouse_hooked_flag
ldy #POSMOUSE ldy #POSMOUSE
jmp call_mouse jmp call_mouse
L7E49: stx mouse_x no_firmware:
stx mouse_x
sty mouse_x+1 sty mouse_x+1
sta mouse_y sta mouse_y
bit mouse_hooked_flag bit mouse_hooked_flag
bpl L7E5C bpl not_hooked
ldy #POSMOUSE ldy #POSMOUSE
jmp call_mouse jmp call_mouse
L7E5C: rts not_hooked:
rts
.endproc
L7E5D: ldx L7D7C ;;; ============================================================
ldy L7D7D
lda L7D7E
jmp L7E19
L7E69: ldx L7D75 L7E5D: ldx other_mouse_x
ldy L7D76 ldy other_mouse_x+1
lda L7D77 lda other_mouse_y
jmp L7E19 jmp set_mouse_pos
set_mouse_pos_from_kbd_mouse:
ldx kbd_mouse_x
ldy kbd_mouse_x+1
lda kbd_mouse_y
jmp set_mouse_pos
L7E75: bcc L7E7D L7E75: bcc L7E7D
ldx L5FFD ldx L5FFD
@ -7880,19 +7911,19 @@ L7E82: pha
rts rts
L7E8C: ldx #$02 L7E8C: ldx #$02
L7E8E: lda L7D75,x L7E8E: lda kbd_mouse_x,x
sta mouse_x,x sta mouse_x,x
dex dex
bpl L7E8E bpl L7E8E
rts rts
L7E98: jsr L7E8C L7E98: jsr L7E8C
jmp L7E69 jmp set_mouse_pos_from_kbd_mouse
L7E9E: jsr L62BA L7E9E: jsr L62BA
ldx #$02 ldx #$02
L7EA3: lda mouse_x,x L7EA3: lda mouse_x,x
sta L7D7C,x sta other_mouse_x,x
dex dex
bpl L7EA3 bpl L7EA3
rts rts
@ -7905,7 +7936,7 @@ L7EAD: jsr stash_addr
jsr SetCursorImpl jsr SetCursorImpl
jsr restore_addr jsr restore_addr
lda #$00 lda #$00
sta L7D74 sta kbd_mouse_state
lda #$40 lda #$40
sta mouse_status sta mouse_status
jmp L7E5D jmp L7E5D
@ -7937,14 +7968,14 @@ L7EE8: clc
sec sec
L7EF4: rts L7EF4: rts
L7EF5: lda L7D74 L7EF5: lda kbd_mouse_state
bne L7EFB bne L7EFB
rts rts
L7EFB: cmp #$04 L7EFB: cmp #$04
beq L7F48 beq L7F48
jsr L7FB4 jsr L7FB4
lda L7D74 lda kbd_mouse_state
cmp #$01 cmp #$01
bne L7F0C bne L7F0C
jmp L804D jmp L804D
@ -7997,7 +8028,7 @@ L7F48: jsr compute_modifiers
L7F63: jmp L7E98 L7F63: jmp L7E98
L7F66: pha L7F66: pha
lda L7D74 lda kbd_mouse_state
bne L7FA3 bne L7FA3
pla pla
cmp #$03 cmp #$03
@ -8005,7 +8036,7 @@ L7F66: pha
bit mouse_status bit mouse_status
bmi L7FA2 bmi L7FA2
lda #$04 lda #$04
sta L7D74 sta kbd_mouse_state
ldx #$0A ldx #$0A
L7F7D: lda SPKR ; Beep? L7F7D: lda SPKR ; Beep?
ldy #$00 ldy #$00
@ -8021,7 +8052,7 @@ L7F88: jsr compute_modifiers
sta L7D82 sta L7D82
ldx #$02 ldx #$02
L7F99: lda set_pos_params,x L7F99: lda set_pos_params,x
sta L7D75,x sta kbd_mouse_x,x
dex dex
bpl L7F99 bpl L7F99
L7FA2: rts L7FA2: rts
@ -8032,7 +8063,7 @@ L7FA3: cmp #$04
and #$01 and #$01
bne L7FB1 bne L7FB1
lda #$00 lda #$00
sta L7D74 sta kbd_mouse_state
L7FB1: rts L7FB1: rts
L7FB2: pla L7FB2: pla
@ -8040,9 +8071,9 @@ L7FB2: pla
L7FB4: bit mouse_status L7FB4: bit mouse_status
bpl L7FC1 bpl L7FC1
lda #$00 lda #0
sta L7D74 sta kbd_mouse_state
jmp L7E69 jmp set_mouse_pos_from_kbd_mouse
L7FC1: lda mouse_status L7FC1: lda mouse_status
pha pha
@ -8053,7 +8084,7 @@ L7FC1: lda mouse_status
beq L7FDE beq L7FDE
ldx #$02 ldx #$02
L7FD1: lda mouse_x,x L7FD1: lda mouse_x,x
sta L7D75,x sta kbd_mouse_x,x
dex dex
bpl L7FD1 bpl L7FD1
stx L7D79 stx L7D79
@ -8065,34 +8096,36 @@ L7FE1: php
sei sei
jsr L7E9E jsr L7E9E
lda #$01 lda #$01
sta L7D74 sta kbd_mouse_state
jsr L800F jsr L800F
lda #$80 lda #$80
sta mouse_status sta mouse_status
jsr L7F0F jsr L7F0F
ldx L7D7A ldx menu_index
jsr L6878 jsr L6878
lda $AF lda $AF
sta L6BD9 sta L6BD9
jsr L6D26 jsr L6D26
lda L7D7B lda menu_item_index
sta L6BDA sta L6BDA
jsr L6EAA jsr L6EAA
plp plp
rts rts
L800F: ldx L7D7A L800F: ldx menu_index
jsr L6878 jsr L6878
clc clc
lda $B7 lda $B7
adc #$05 adc #$05
sta L7D75 sta kbd_mouse_x
lda $B8 lda $B8
adc #$00 adc #$00
sta L7D76 sta kbd_mouse_x+1
ldy L7D7B
ldy menu_item_index
lda menu_item_y_table,y lda menu_item_y_table,y
sta L7D77 sta kbd_mouse_y
lda #$C0 lda #$C0
sta mouse_status sta mouse_status
jmp L7E98 jmp L7E98
@ -8100,10 +8133,10 @@ L800F: ldx L7D7A
L8035: bit L7D79 L8035: bit L7D79
bpl L804C bpl L804C
lda L6BDA lda L6BDA
sta L7D7B sta menu_item_index
ldx L6BD9 ldx L6BD9
dex dex
stx L7D7A stx menu_index
lda #$00 lda #$00
sta L7D79 sta L7D79
L804C: rts L804C: rts
@ -8140,13 +8173,13 @@ try_return:
try_up: try_up:
cmp #CHAR_UP cmp #CHAR_UP
bne try_down bne try_down
L8081: dec L7D7B L8081: dec menu_item_index
bpl L8091 bpl L8091
ldx L7D7A ldx menu_index
jsr L6878 jsr L6878
ldx $AA ldx $AA
stx L7D7B stx menu_item_index
L8091: ldx L7D7B L8091: ldx menu_item_index
beq L80A0 beq L80A0
dex dex
jsr L68BE jsr L68BE
@ -8158,16 +8191,16 @@ L80A0: jmp L800F
try_down: try_down:
cmp #CHAR_DOWN cmp #CHAR_DOWN
bne try_right bne try_right
L80A7: inc L7D7B L80A7: inc menu_item_index
ldx L7D7A ldx menu_index
jsr L6878 jsr L6878
lda L7D7B lda menu_item_index
cmp $AA cmp $AA
bcc L80BE bcc L80BE
beq L80BE beq L80BE
lda #0 lda #0
sta L7D7B sta menu_item_index
L80BE: ldx L7D7B L80BE: ldx menu_item_index
beq L80CD beq L80CD
dex dex
jsr L68BE jsr L68BE
@ -8180,27 +8213,27 @@ try_right:
cmp #CHAR_RIGHT cmp #CHAR_RIGHT
bne try_left bne try_left
lda #0 lda #0
sta L7D7B sta menu_item_index
inc L7D7A inc menu_index
lda L7D7A lda menu_index
cmp $A8 cmp $A8
bcc L80E8 bcc L80E8
lda #$00 lda #$00
sta L7D7A sta menu_index
L80E8: jmp L800F L80E8: jmp L800F
try_left: try_left:
cmp #CHAR_LEFT cmp #CHAR_LEFT
bne nope bne nope
lda #0 lda #0
sta L7D7B sta menu_item_index
dec L7D7A dec menu_index
bmi L80FC bmi L80FC
jmp L800F jmp L800F
L80FC: ldx $A8 L80FC: ldx $A8
dex dex
stx L7D7A stx menu_index
jmp L800F jmp L800F
nope: jsr L8110 nope: jsr L8110
@ -8275,12 +8308,12 @@ L817C: php
L8196: sec L8196: sec
lda $CB,x lda $CB,x
sbc #$04 sbc #$04
sta L7D75,x sta kbd_mouse_x,x
sta L769B,x sta L769B,x
sta L769F,x sta L769F,x
lda $CC,x lda $CC,x
sbc #$00 sbc #$00
sta L7D76,x sta kbd_mouse_x+1,x
sta L769C,x sta L769C,x
sta L76A0,x sta L76A0,x
inx inx
@ -8305,7 +8338,7 @@ L8196: sec
rts rts
L81D9: lda #$00 L81D9: lda #$00
sta L7D74 sta kbd_mouse_state
lda #$A2 lda #$A2
plp plp
jmp exit_with_a jmp exit_with_a
@ -8314,7 +8347,7 @@ L81E4: lda $AC
and #$01 and #$01
beq L81F4 beq L81F4
lda #$00 lda #$00
sta L7D74 sta kbd_mouse_state
exit_call $A1 exit_call $A1
L81F4: ldx #$00 L81F4: ldx #$00
@ -8326,23 +8359,23 @@ L81F6: clc
jmp L8204 jmp L8204
L8202: adc #$05 L8202: adc #$05
L8204: sta L7D75,x L8204: sta kbd_mouse_x,x
sta L769B,x sta L769B,x
sta L769F,x sta L769F,x
lda $C8,x lda $C8,x
adc #$00 adc #$00
sta L7D76,x sta kbd_mouse_x+1,x
sta L769C,x sta L769C,x
sta L76A0,x sta L76A0,x
inx inx
inx inx
cpx #$04 cpx #$04
bcc L81F6 bcc L81F6
bit L7D76 bit kbd_mouse_x+1
bpl L8235 bpl L8235
ldx #$01 ldx #$01
lda #$00 lda #$00
L8229: sta L7D75,x L8229: sta kbd_mouse_x,x
sta L769B,x sta L769B,x
sta L769F,x sta L769F,x
dex dex
@ -8354,20 +8387,20 @@ L8235: jsr L7E98
L823D: php L823D: php
clc clc
adc L7D77 adc kbd_mouse_y
sta L7D77 sta kbd_mouse_y
plp plp
bpl L8254 bpl L8254
cmp #$C0 cmp #$C0
bcc L8251 bcc L8251
lda #$00 lda #$00
sta L7D77 sta kbd_mouse_y
L8251: jmp L7E98 L8251: jmp L7E98
L8254: cmp #$C0 L8254: cmp #$C0
bcc L8251 bcc L8251
lda #$BF lda #$BF
sta L7D77 sta kbd_mouse_y
bne L8251 bne L8251
L825F: jsr L7D83 L825F: jsr L7D83
jsr L8268 jsr L8268
@ -8420,42 +8453,42 @@ L82B2: cmp #$15
bit set_input_modifiers bit set_input_modifiers
bpl L82C5 bpl L82C5
lda #$40 lda #$40
L82C5: adc L7D75 L82C5: adc kbd_mouse_x
sta L7D75 sta kbd_mouse_x
lda L7D76 lda kbd_mouse_x+1
adc #$00 adc #$00
sta L7D76 sta kbd_mouse_x+1
sec sec
lda L7D75 lda kbd_mouse_x
sbc #$2F sbc #$2F
lda L7D76 lda kbd_mouse_x+1
sbc #$02 sbc #$02
bmi L82EA bmi L82EA
lda #$02 lda #$02
sta L7D76 sta kbd_mouse_x+1
lda #$2F lda #$2F
sta L7D75 sta kbd_mouse_x
L82EA: jmp L7E98 L82EA: jmp L7E98
L82ED: cmp #$08 L82ED: cmp #$08
bne L831D bne L831D
jsr L8352 jsr L8352
bcc L831A bcc L831A
lda L7D75 lda kbd_mouse_x
bit set_input_modifiers bit set_input_modifiers
bpl L8303 bpl L8303
sbc #$40 sbc #$40
jmp L8305 jmp L8305
L8303: sbc #$08 L8303: sbc #$08
L8305: sta L7D75 L8305: sta kbd_mouse_x
lda L7D76 lda kbd_mouse_x+1
sbc #$00 sbc #$00
sta L7D76 sta kbd_mouse_x+1
bpl L831A bpl L831A
lda #$00 lda #$00
sta L7D75 sta kbd_mouse_x
sta L7D76 sta kbd_mouse_x+1
L831A: jmp L7E98 L831A: jmp L7E98
L831D: sta set_input_key L831D: sta set_input_key
@ -8494,12 +8527,12 @@ unk: .byte 0
set_input_modifiers := set_input_params::modifiers set_input_modifiers := set_input_params::modifiers
set_input_unk := set_input_params::unk set_input_unk := set_input_params::unk
L8352: lda L7D74 L8352: lda kbd_mouse_state
cmp #$04 cmp #$04
beq L8368 beq L8368
lda L7D75 lda kbd_mouse_x
bne L8368 bne L8368
lda L7D76 lda kbd_mouse_x+1
bne L8368 bne L8368
bit drag_resize_flag bit drag_resize_flag
bpl L836A bpl L836A
@ -8531,14 +8564,14 @@ L838D: adc L769B
L8398: clc L8398: clc
rts rts
L839A: lda L7D74 L839A: lda kbd_mouse_state
cmp #$04 cmp #$04
beq L83B3 beq L83B3
bit drag_resize_flag bit drag_resize_flag
.byte $30 ; bmi ... .byte $30 ; bmi ...
ora $75AD ora $75AD
adc $2FE9,x adc $2FE9,x
lda L7D76 lda kbd_mouse_x+1
sbc #$02 sbc #$02
beq L83B5 beq L83B5
sec sec
@ -8585,7 +8618,7 @@ L83F6: lda #$80
sta L83F5 sta L83F5
L83FB: rts L83FB: rts
L83FC: bit L7D74 L83FC: bit kbd_mouse_state
bpl L83FB bpl L83FB
bit L83F5 bit L83F5
bpl L83FB bpl L83FB
@ -8596,10 +8629,10 @@ L83FC: bit L7D74
L840D: sec L840D: sec
lda $CB,x lda $CB,x
sbc #$04 sbc #$04
sta L7D75,x sta kbd_mouse_x,x
lda $CC,x lda $CC,x
sbc #$00 sbc #$00
sta L7D76,x sta kbd_mouse_x+1,x
inx inx
inx inx
cpx #$04 cpx #$04