DeskTop Seg 1: mouse hookup

This commit is contained in:
Joshua Bell 2017-10-07 15:07:12 -07:00
parent e681879ede
commit 31aa3ec57b
2 changed files with 197 additions and 124 deletions

View File

@ -134,6 +134,11 @@ A2D_DRAW_LINE := $0F ; Draw line (from SET_POS)
;; .word xdelta signed, delta in pixels ;; .word xdelta signed, delta in pixels
;; .word ydelta ;; .word ydelta
A2D_DRAW_LINE_ABS := $10 ; Draw line (from SET_POS)
;; (input length 4 bytes)
;; .word xcoord end coords in pixels
;; .word ycoord
A2D_FILL_RECT := $11 ; Fill rectangle with selected simple pattern/thickness A2D_FILL_RECT := $11 ; Fill rectangle with selected simple pattern/thickness
;; (input length 8 bytes) ;; (input length 8 bytes)
;; .word left (includes scroll pos) ;; .word left (includes scroll pos)

View File

@ -61,6 +61,7 @@ LD2D0 := $D2D0
state_tmask := $F1 state_tmask := $F1
state_font := $F2 state_font := $F2
sizeof_state := 36
;;; ================================================== ;;; ==================================================
;;; A2D ;;; A2D
@ -202,10 +203,10 @@ a2d_exit_with_a:
rts2: rts rts2: rts
;;; ================================================== ;;; ==================================================
;;; Copy params (35 bytes) to/from ($F4) to $D0 ;;; Copy params (36 bytes) to/from ($F4) to $D0
.proc copy_params_to_zp .proc copy_params_to_zp
ldy #$23 ldy #sizeof_state-1
: lda ($F4),y : lda ($F4),y
sta $D0,y sta $D0,y
dey dey
@ -214,7 +215,7 @@ rts2: rts
.endproc .endproc
.proc copy_params_from_zp .proc copy_params_from_zp
ldy #$23 ldy #sizeof_state-1
: lda $D0,y : lda $D0,y
sta ($F4),y sta ($F4),y
dey dey
@ -266,7 +267,7 @@ a2d_jump_table:
.addr L5742 ; $0D .addr L5742 ; $0D
.addr jt_rts ; $0E SET_POS .addr jt_rts ; $0E SET_POS
.addr DRAW_LINE_IMPL ; $0F DRAW_LINE .addr DRAW_LINE_IMPL ; $0F DRAW_LINE
.addr L5776 ; $10 .addr DRAW_LINE_ABS_IMPL ; $10 DRAW_LINE_ABS
.addr FILL_RECT_IMPL ; $11 FILL_RECT .addr FILL_RECT_IMPL ; $11 FILL_RECT
.addr DRAW_RECT_IMPL ; $12 DRAW_RECT .addr DRAW_RECT_IMPL ; $12 DRAW_RECT
.addr TEST_BOX_IMPL ; $13 TEST_BOX .addr TEST_BOX_IMPL ; $13 TEST_BOX
@ -354,7 +355,7 @@ param_lengths:
PARAM_DEFN 4, $A1, 0 ; $0D PARAM_DEFN 4, $A1, 0 ; $0D
PARAM_DEFN 4, state_pos, 0 ; $0E SET_POS PARAM_DEFN 4, state_pos, 0 ; $0E SET_POS
PARAM_DEFN 4, $A1, 1 ; $0F DRAW_LINE PARAM_DEFN 4, $A1, 1 ; $0F DRAW_LINE
PARAM_DEFN 4, $92, 1 ; $10 PARAM_DEFN 4, $92, 1 ; $10 DRAW_LINE_ABS
PARAM_DEFN 8, $92, 1 ; $11 FILL_RECT PARAM_DEFN 8, $92, 1 ; $11 FILL_RECT
PARAM_DEFN 8, $9F, 1 ; $12 DRAW_RECT PARAM_DEFN 8, $9F, 1 ; $12 DRAW_RECT
PARAM_DEFN 8, $92, 0 ; $13 TEST_BOX PARAM_DEFN 8, $92, 0 ; $13 TEST_BOX
@ -1345,6 +1346,12 @@ L4FDD: dex
L4FE4: .byte 0 L4FE4: .byte 0
DRAW_RECT_IMPL: DRAW_RECT_IMPL:
left := $9F
top := $A1
right := $A3
bottom := $A5
ldy #$03 ldy #$03
L4FE7: ldx #$07 L4FE7: ldx #$07
L4FE9: lda $9F,x L4FE9: lda $9F,x
@ -1373,18 +1380,20 @@ L5015: rts
L5016: .byte $00,$02,$04,$06 L5016: .byte $00,$02,$04,$06
L501A: .byte $04,$06,$00,$02 L501A: .byte $04,$06,$00,$02
L501E: lda state_hthick L501E: lda state_hthick
sec sec
sbc #$01 sbc #1
cmp #$FF cmp #$FF
beq L5015 beq L5015
adc $96 adc $96
sta $96 sta $96
bcc L502F bcc L502F
inc $97 inc $97
L502F: lda state_vthick L502F: lda state_vthick
sec sec
sbc #$01 sbc #1
cmp #$FF cmp #$FF
beq L5015 beq L5015
adc $98 adc $98
@ -1410,31 +1419,37 @@ L5043: jsr L50A9
;;; 4 bytes of params, copied to $92 ;;; 4 bytes of params, copied to $92
.proc TEST_BOX_IMPL .proc TEST_BOX_IMPL
left := $92
top := $94
right := $96
bottom := $98
jsr L514C jsr L514C
lda state_xpos lda state_xpos
ldx state_xpos+1 ldx state_xpos+1
cpx $93 cpx left+1
bmi fail bmi fail
bne :+ bne :+
cmp $92 cmp left
bcc fail bcc fail
: cpx $97 : cpx right+1
bmi :+ bmi :+
bne fail bne fail
cmp $96 cmp right
bcc :+ bcc :+
bne fail bne fail
: lda state_ypos : lda state_ypos
ldx state_ypos+1 ldx state_ypos+1
cpx $95 cpx top+1
bmi fail bmi fail
bne :+ bne :+
cmp $94 cmp top
bcc fail bcc fail
: cpx $99 : cpx bottom+1
bmi :+ bmi :+
bne fail bne fail
cmp $98 cmp bottom
bcc :+ bcc :+
bne fail bne fail
: lda #$80 ; success! : lda #$80 ; success!
@ -1580,45 +1595,62 @@ L5168: .byte 0
L5169: .byte 0 L5169: .byte 0
DRAW_BITMAP_IMPL: DRAW_BITMAP_IMPL:
ldx #$03
L516C: lda $8A,x dbi_left := $8A
sta $9B,x dbi_top := $8C
lda $92,x dbi_bitmap := $8E
sta $8A,x dbi_stride := $90
dbi_hoff := $92
dbi_voff := $94
dbi_width := $96
dbi_height := $98
dbi_x := $9B
dbi_y := $9D
ldx #3 ; copy left/top to $9B/$9D
: lda dbi_left,x ; and hoff/voff to $8A/$8C (overwriting left/top)
sta dbi_x,x
lda dbi_hoff,x
sta dbi_left,x
dex dex
bpl L516C bpl :-
lda $96
lda dbi_width
sec sec
sbc $92 sbc dbi_hoff
sta $82 sta $82
lda $97 lda dbi_width+1
sbc $93 sbc dbi_hoff+1
sta $83 sta $83
lda $9B lda dbi_x
sta $92 sta dbi_hoff
clc clc
adc $82 adc $82
sta $96 sta dbi_width
lda $9C lda dbi_x+1
sta $93 sta dbi_hoff+1
adc $83 adc $83
sta $97 sta dbi_width+1
lda $98
lda dbi_height
sec sec
sbc $94 sbc dbi_voff
sta $82 sta $82
lda $99 lda dbi_height+1
sbc $95 sbc dbi_voff+1
sta $83 sta $83
lda $9D lda dbi_y
sta $94 sta dbi_voff
clc clc
adc $82 adc $82
sta $98 sta dbi_height
lda $9E lda dbi_y+1
sta $95 sta dbi_voff+1
adc $83 adc $83
sta $99 sta dbi_height+1
;; fall through
;;; ================================================== ;;; ==================================================
@ -2369,26 +2401,30 @@ L5758: clc
;;; 4 bytes of params, copied to $A1 ;;; 4 bytes of params, copied to $A1
DRAW_LINE_IMPL: .proc DRAW_LINE_IMPL
ldx #$02
L5765: lda $A1,x xdelta := $A1
ydelta := $A2
ldx #2 ; Convert relative x/y to absolute x/y at $92,$94
loop: lda xdelta,x
clc clc
adc state_xpos,x adc state_xpos,x
sta $92,x sta $92,x
lda $A2,x lda xdelta+1,x
adc state_xpos+1,x adc state_xpos+1,x
sta $93,x sta $93,x
dex dex
dex dex
bpl L5765 bpl loop
;; fall through
.endproc
;;; ================================================== ;;; ==================================================
;;; $10 IMPL
;;; 4 bytes of params, copied to $92 ;;; 4 bytes of params, copied to $92
L5776: DRAW_LINE_ABS_IMPL:
ldx #$03 ldx #$03
L5778: lda state_pos,x L5778: lda state_pos,x
sta $96,x sta $96,x
@ -3213,7 +3249,7 @@ L5E42: .byte $00,$00,$00,$00,$00,$00,$00,$00
L5E51: lda #$71 L5E51: lda #$71
sta $82 sta $82
jsr L5E7B jsr L5E7B
ldx #$23 ldx #sizeof_state-1
L5E5A: lda L5F1E,x L5E5A: lda L5F1E,x
sta $8A,x sta $8A,x
sta $D0,x sta $D0,x
@ -3285,25 +3321,29 @@ L5EBD: sta (params_addr),y
;;; ================================================== ;;; ==================================================
QUERY_SCREEN_IMPL: .proc QUERY_SCREEN_IMPL
ldy #35 ; Store 36 bytes at params ldy #sizeof_state-1 ; Store 36 bytes at params
L5EC6: lda L5F1E,y loop: lda L5F1E,y
sta (params_addr),y sta (params_addr),y
dey dey
bpl L5EC6 bpl loop
L5ECE: rts .endproc
rts3: rts
;;; ================================================== ;;; ==================================================
;;; 1 byte of params, copied to $82 ;;; 1 byte of params, copied to $82
CONFIGURE_ZP_IMPL: .proc CONFIGURE_ZP_IMPL
lda $82 param := $82
lda param
cmp preserve_zp_flag cmp preserve_zp_flag
beq L5ECE beq rts3
sta preserve_zp_flag sta preserve_zp_flag
bcc L5ECE bcc rts3
jmp a2d_dispatch::cleanup jmp a2d_dispatch::cleanup
.endproc
;;; ================================================== ;;; ==================================================
@ -3314,7 +3354,7 @@ CONFIGURE_ZP_IMPL:
L5EDE: L5EDE:
lda $82 lda $82
cmp L5F1C cmp L5F1C
beq L5ECE beq rts3
sta L5F1C sta L5F1C
bcc L5EFF bcc L5EFF
L5EEA: bit L5F1C L5EEA: bit L5F1C
@ -3732,23 +3772,23 @@ L6293: lda L5FF8,x
dex dex
bpl L6293 bpl L6293
jsr L60A8 jsr L60A8
L629F: bit L851C L629F: bit no_mouse_flag
bmi L62A7 bmi L62A7
jsr L62BA jsr L62BA
L62A7: bit L851C L62A7: bit no_mouse_flag
bpl L62B1 bpl L62B1
lda #$00 lda #$00
sta L5FFC sta L5FFC
L62B1: lda L7D74 L62B1: lda L7D74
beq L62B9 beq rts4
jsr L7EF5 jsr L7EF5
L62B9: rts rts4: rts
L62BA: ldy #$14 L62BA: ldy #$14
jsr L6313 jsr call_mouse
bit L5FFF bit L5FFF
bmi L62D9 bmi L62D9
ldx L851D ldx mouse_firmware_hi
lda $03B8,x lda $03B8,x
sta L5FF8 sta L5FF8
lda $04B8,x lda $04B8,x
@ -3787,19 +3827,22 @@ L630A:
ldx L6143 ldx L6143
jmp L5EBB jmp L5EBB
L6313: bit L851C ;; Call mouse firmware, operation in Y, param in A
bmi L62B9 call_mouse:
bit no_mouse_flag
bmi rts4
bit L5FFF bit L5FFF
bmi L6332 bmi L6332
pha pha
ldx L851D ldx mouse_firmware_hi
stx $89 stx $89
lda #$00 lda #$00
sta $88 sta $88
lda ($88),y lda ($88),y
sta $88 sta $88
pla pla
ldy L851E ldy mouse_operand
jmp ($88) jmp ($88)
L6332: jmp (L6000) L6332: jmp (L6000)
@ -3892,7 +3935,7 @@ L63AC: txa
lda #$01 lda #$01
sta L5FFE sta L5FFE
L63D1: ldx L6338 L63D1: ldx L6338
jsr L84BD jsr find_mouse
bit L6338 bit L6338
bpl L63F6 bpl L63F6
cpx #$00 cpx #$00
@ -3938,7 +3981,7 @@ L642A: lda $FBB3
bpl L643F bpl L643F
cli cli
ora #$08 ora #$08
L643F: jsr L6313 L643F: jsr call_mouse
pla pla
sta $FBB3 sta $FBB3
jsr L5E51 jsr L5E51
@ -4000,9 +4043,9 @@ L64A4: rts
L64A5: L64A5:
ldy #$12 ldy #$12
lda #$00 lda #$00
jsr L6313 jsr call_mouse
ldy #$13 ldy #$13
jsr L6313 jsr call_mouse
bit L6339 bit L6339
bpl L64C7 bpl L64C7
bit L6337 bit L6337
@ -4109,7 +4152,7 @@ L6567: sta $82
stx $83 stx $83
lda L653B lda L653B
sta stack_ptr_stash sta stack_ptr_stash
ldy #$23 ldy #sizeof_state-1
L6573: lda ($82),y L6573: lda ($82),y
sta $D0,y sta $D0,y
dey dey
@ -4362,7 +4405,7 @@ sloop: lda $82,x
bpl sloop bpl sloop
ldy #$13 ldy #$13
jsr L6313 jsr call_mouse
bcs :+ bcs :+
jsr L666D jsr L666D
clc clc
@ -5592,7 +5635,7 @@ L704A: lda ($A9),y
sta $AB,y sta $AB,y
dey dey
bpl L704A bpl L704A
ldy #$23 ldy #sizeof_state-1
L7054: lda ($A9),y L7054: lda ($A9),y
sta $A3,y sta $A3,y
dey dey
@ -6309,7 +6352,7 @@ L75AC: lda fill_rect_params,x
bpl L75AC bpl L75AC
jsr L75C6 jsr L75C6
bcc L7585 bcc L7585
ldy #$23 ldy #sizeof_state-1
L75BB: lda $D0,y L75BB: lda $D0,y
sta (params_addr),y sta (params_addr),y
dey dey
@ -6380,7 +6423,7 @@ L761F:
sta $A9 sta $A9
bcc L762D bcc L762D
inc $AA inc $AA
L762D: ldy #$23 L762D: ldy #sizeof_state-1
L762F: lda ($82),y L762F: lda ($82),y
sta ($A9),y sta ($A9),y
dey dey
@ -6405,6 +6448,7 @@ L7644: ldy #$00
;;; ================================================== ;;; ==================================================
L7649: .byte 0 L7649: .byte 0
CLOSE_CLICK_IMPL: CLOSE_CLICK_IMPL:
jsr L7013 jsr L7013
beq L7697 beq L7697
@ -7414,13 +7458,13 @@ L7D99: .res 128, 0
L7E19: bit L5FFF L7E19: bit L5FFF
bmi L7E49 bmi L7E49
bit L851C bit no_mouse_flag
bmi L7E49 bmi L7E49
pha pha
txa txa
sec sec
jsr L7E75 jsr L7E75
ldx L851D ldx mouse_firmware_hi
sta $03B8,x sta $03B8,x
tya tya
sta $04B8,x sta $04B8,x
@ -7428,12 +7472,12 @@ L7E19: bit L5FFF
ldy #$00 ldy #$00
clc clc
jsr L7E75 jsr L7E75
ldx L851D ldx mouse_firmware_hi
sta $0438,x sta $0438,x
tya tya
sta $0538,x sta $0538,x
ldy #$16 ldy #$16
jmp L6313 jmp call_mouse
L7E49: stx L5FF8 L7E49: stx L5FF8
sty L5FF9 sty L5FF9
@ -7441,7 +7485,7 @@ L7E49: stx L5FF8
bit L5FFF bit L5FFF
bpl L7E5C bpl L7E5C
ldy #$16 ldy #$16
jmp L6313 jmp call_mouse
L7E5C: rts L7E5C: rts
@ -8040,7 +8084,7 @@ L8305: sta L7D75
L831A: jmp L7E98 L831A: jmp L7E98
L831D: sta set_input_params_key L831D: sta set_input_params_key
ldx #$23 ldx #sizeof_state-1
L8322: lda $A7,x L8322: lda $A7,x
sta $0600,x sta $0600,x
dex dex
@ -8048,7 +8092,7 @@ L8322: lda $A7,x
lda set_input_params_key lda set_input_params_key
jsr L8110 jsr L8110
php php
ldx #$23 ldx #sizeof_state-1
L8333: lda $0600,x L8333: lda $0600,x
sta $A7,x sta $A7,x
dex dex
@ -8201,7 +8245,7 @@ L8427:
sta L5FFD sta L5FFD
lda $83 lda $83
sta L5FFE sta L5FFE
L8431: bit L851C L8431: bit no_mouse_flag
bmi L84AC bmi L84AC
lda L5FFD lda L5FFD
asl a asl a
@ -8225,7 +8269,7 @@ L845C: lda L84AD+1,y
sta $05F8 sta $05F8
L846A: lda #$00 L846A: lda #$00
ldy #$17 ldy #$17
jsr L6313 jsr call_mouse
lda L5FFE lda L5FFE
asl a asl a
tay tay
@ -8248,69 +8292,93 @@ L8497: lda L84B5+1,y
sta $05F8 sta $05F8
L84A5: lda #$01 L84A5: lda #$01
ldy #$17 ldy #$17
jsr L6313 jsr call_mouse
L84AC: rts L84AC: rts
L84AD: .word 560-1, 560/2-1, 560/4-1, 560/8-1 L84AD: .word 560-1, 560/2-1, 560/4-1, 560/8-1
L84B5: .word 192-1, 192/2-1, 192/4-1, 192/8-1 L84B5: .word 192-1, 192/2-1, 192/4-1, 192/8-1
L84BD: txa ;;; ==================================================
;;; Locate Mouse Slot
;; If X's high bit is set, only slot in low bits is tested.
;; Otherwise all slots are scanned.
.proc find_mouse
txa
and #$7F and #$7F
beq L84CD beq scan
jsr L84F2 jsr check_mouse_in_a
sta L851C sta no_mouse_flag
beq L84DE beq found
ldx #$00 ldx #0
rts rts
L84CD: ldx #$07 ;; Scan for mouse starting at slot 7
L84CF: txa scan: ldx #7
jsr L84F2 loop: txa
sta L851C jsr check_mouse_in_a
beq L84DE sta no_mouse_flag
beq found
dex dex
bpl L84CF bpl loop
ldx #$00 ldx #0 ; no mouse found
rts rts
L84DE: ldy #$19 found: ldy #$19
jsr L6313 jsr call_mouse
jsr L8431 jsr L8431
ldy #$18 ldy #$18
jsr L6313 jsr call_mouse
lda L851D lda mouse_firmware_hi
and #$0F and #$0F
tax tax ; return with mouse slot in X
rts rts
L84F2: ora #$C0 ;; Check for mouse in slot A
sta $89 .proc check_mouse_in_a
lda #$00 ptr := $88
sta $88
ldy #$0C ora #>$C000
lda ($88),y sta ptr+1
lda #<$0000
sta ptr
ldy #$0C ; $Cn0C = $20
lda (ptr),y
cmp #$20 cmp #$20
bne L8519 bne nope
ldy #$FB
lda ($88),y ldy #$FB ; $CnFB = $D6
lda (ptr),y
cmp #$D6 cmp #$D6
bne L8519 bne nope
lda $89
sta L851D lda ptr+1 ; yay, found it!
sta mouse_firmware_hi
asl a asl a
asl a asl a
asl a asl a
asl a asl a
sta L851E sta mouse_operand
lda #$00 lda #$00
rts rts
L8519: lda #$80 nope: lda #$80
rts rts
.endproc
.endproc
no_mouse_flag: ; high bit set if no mouse present
.byte 0
mouse_firmware_hi: ; e.g. if mouse is in slot 4, this is $C4
.byte 0
mouse_operand: ; e.g. if mouse is in slot 4, this is $40
.byte 0
;;; ==================================================
L851C: .byte 0
L851D: .byte 0
L851E: .byte 0
.byte $03 .byte $03
sbc #$85 sbc #$85
php php