[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: I'm an idiot - this code is prolly broken in 6502 different ways



On Monday, December 10, 2012 5:47:31 AM UTC-6, Steve Nickolas wrote:
> Trying to figure out how to use the mouse driver, I wrote this code, but I 
> 
> screwed up, prolly in several places.
> 
> 
> 
> I attempted to map the firmware to & commands - something with which I am 
> 
> not exactly familiar - and could have probably screwed up there as well. 
> 
> I had in mind to implement USR() to get the X and Y values and couldn't 
> 
> figure that out either.
> 
> 
> 
> -uso.
> 
> 
> 
> intwrd     =        $06
> 
> postab     =        $FA
> 
> 
> 
> chrget     =        $B1
> 
> 
> 
>            .org      $9000
> 
> entry:    jmp       entry2
> 
> amp:      bne       proc
> 
>            rts
> 
> getwrd:   jsr       $DD67     ; create integer word at $50
> 
>            jsr       $E752
> 
>            lda       $51
> 
>            cmp       #$04
> 
>            bcs       funerr
> 
>            rts
> 
> proc:     cmp       #$87      ; &READ
> 
>            beq       b_read
> 
>            cmp       #$97      ; &HOME
> 
>            beq       v_home
> 
>            cmp       #$AA      ; &LET mode
> 
>            beq       b_set
> 
>            cmp       #$AB      ; &GOTO
> 
>            beq       b_pos
> 
>            cmp       #$AC      ; &RUN
> 
>            beq       b_serve
> 
>            cmp       #$B3      ; &STOP {X | Y}=start,end
> 
>            beq       v_clamp
> 
>            cmp       #$B8      ; &DEF
> 
>            beq       v_init
> 
>            cmp       #$BD      ; &CLEAR
> 
>            beq       b_clear
> 
> synerr:   jmp       $DEC9     ; ?SYNTAX ERROR
> 
> funerr:   jmp       $E199     ; ?ILLEGAL QUANTITY ERROR
> 
> v_home:   jmp       b_home
> 
> v_clamp:  beq       b_clamp
> 
> v_init:   jmp       b_init
> 
> b_set:    jsr       chrget
> 
>            jsr       $DD67
> 
>            jsr       $E752
> 
>            lda       $50
> 
>            and       #$F0
> 
>            bne       funerr
> 
>            lda       $51
> 
>            bne       funerr
> 
>            lda       $50
> 
>            and       #$0F
> 
>            pha
> 
>            jsr       setmos
> 
>            pla
> 
>            jsr       dojmp
> 
>            bcs       funerr
> 
>            rts
> 
> b_serve:  jsr       srvmos
> 
>            jsr       dojmp
> 
>            bcc       @1
> 
>            lda       #$FF
> 
>            .byte     $2C
> 
> @1:       lda       #$00
> 
>            sta       intwrd+2
> 
>            rts
> 
> b_read:   jsr       rdmos
> 
>            jmp       b_cmn
> 
> b_clear:  jsr       clrmos
> 
> b_cmn:    jsr       dojmp
> 
>            jmp       getvars
> 
> b_pos:    jsr       chrget
> 
>            jsr       getwrd
> 
>            sta       postab+1
> 
>            lda       $50
> 
>            sta       postab
> 
>            jsr       chrget
> 
>            cmp       #','
> 
>            bne       synerr
> 
>            jsr       chrget
> 
>            jsr       getwrd
> 
>            sta       postab+3
> 
>            lda       $50
> 
>            sta       postab+2
> 
>            jsr       putvars
> 
>            jsr       posmos
> 
>            jmp       dojmp
> 
> synerr2:  jmp       synerr
> 
> b_clamp:  jsr       chrget
> 
>            cmp       #'X'
> 
>            beq       @1
> 
>            cmp       #'Y'
> 
>            bne       synerr2
> 
>            lda       #$01
> 
>            .byte     $2C
> 
> @1:       lda       #$00
> 
>            sta       postab
> 
>            jsr       chrget
> 
>            cmp       #$D0      ; = token
> 
>            bne       synerr2
> 
>            jsr       chrget
> 
>            jsr       getwrd
> 
>            sta       $04F8
> 
>            lda       $50
> 
>            sta       $0478
> 
>            jsr       chrget
> 
>            cmp       #','
> 
>            bne       synerr2
> 
>            jsr       chrget
> 
>            jsr       getwrd
> 
>            sta       $05F8
> 
>            lda       $50
> 
>            sta       $0578
> 
>            jsr       clmpmos
> 
>            jmp       dojmp
> 
> b_home:   jsr       chrget
> 
>            bne       synerr2
> 
>            jsr       homemos
> 
>            jsr       dojmp
> 
>            jmp       getvars
> 
> b_init:   jsr       chrget
> 
>            bne       synerr2
> 
>            jsr       mosinit
> 
>            jsr       dojmp
> 
>            jmp       getvars
> 
> 
> 
> entry2:   lda       #<$C700
> 
>            sta       intwrd
> 
>            lda       #>$C700
> 
>            sta       intwrd+1
> 
> @1:       ldy       #$05
> 
>            lda       ($06), y
> 
>            cmp       #$38
> 
>            bne       @2
> 
>            ldy       #$07
> 
>            lda       ($06), y
> 
>            cmp       #$18
> 
>            bne       @2
> 
>            ldy       #$0B
> 
>            lda       ($06), y
> 
>            cmp       #$01
> 
>            bne       @2
> 
>            iny
> 
>            lda       ($06), y
> 
>            cmp       #$20
> 
>            bne       @2
> 
>            ldy       #$FB
> 
>            lda       ($06), y
> 
>            cmp       #$D6
> 
>            beq       entry3
> 
> @2:       dec       intwrd+1
> 
>            lda       intwrd+1
> 
>            cmp       #$C1
> 
>            bcs       @1
> 
>            ldy       #$00
> 
>            jsr       prtmsg
> 
>            jmp       $03D0
> 
> errmos:   .byte     13, 7, "NO MOUSE FOUND", 13, 0
> 
> mosok:    .byte     13, "&MOUSE V0.0", 13, 0
> 
> entry3:   lda       #$4C
> 
>            sta       $03F5
> 
>            lda       #<amp
> 
>            sta       $03F6
> 
>            lda       #>amp
> 
>            sta       $03F7
> 
>            ldy       #mosok-errmos
> 
> prtmsg:   lda       errmos, y
> 
>            beq       @1
> 
>            eor       #$80
> 
>            jsr       $FDED
> 
>            iny
> 
>            bne       prtmsg
> 
> @1:       rts
> 
> 
> 
> dojmp:    .byte     $4C
> 
>            .word     $FF59
> 
> 
> 
> setmos:   lda       #$12
> 
>            .byte     $2C
> 
> srvmos:   lda       #$13
> 
>            .byte     $2C
> 
> rdmos:    lda       #$14
> 
>            .byte     $2C
> 
> clrmos:   lda       #$15
> 
>            .byte     $2C
> 
> posmos:   lda       #$16
> 
>            .byte     $2C
> 
> clmpmos:  lda       #$17
> 
>            .byte     $2C
> 
> homemos:  lda       #$18
> 
>            .byte     $2C
> 
> mosinit:  lda       #$19
> 
>            .byte     $2C
> 
> moscmn:   sta       intwrd
> 
>            ldy       #$00
> 
>            lda       (intwrd), y
> 
>            sta       dojmp+1
> 
>            lda       intwrd+1
> 
>            sta       dojmp+2
> 
>            rts
> 
> 
> 
> getvars:  lda       intwrd+1
> 
>            and       #$07
> 
>            tay
> 
>            lda       $0478, y
> 
>            sta       postab
> 
>            lda       $0578, y
> 
>            sta       postab+1
> 
>            lda       $04F8, y
> 
>            sta       postab+2
> 
>            lda       $05F8, y
> 
>            sta       postab+3
> 
>            lda       $0778, y
> 
>            sta       postab+4
> 
>            lda       $07F8, y
> 
>            sta       postab+5
> 
>            rts
> 
> 
> 
> putvars:  lda       intwrd+1
> 
>            and       #$07
> 
>            tay
> 
>            lda       postab
> 
>            sta       $0478, y
> 
>            lda       postab+1
> 
>            sta       $0578, y
> 
>            lda       postab+2
> 
>            sta       $04F8, y
> 
>            lda       postab+3
> 
>            sta       $05F8, y
> 
>            lda       postab+4
> 
>            sta       $0778, y
> 
>            lda       postab+5
> 
>            sta       $07F8, y
> 
>            rts

I implemented the Jace mouse interface against the information here:
http://stason.org/TULARC/pc/apple2/programmer/012-How-do-I-write-programs-which-use-the-mouse.html

Note that Jace doesn't use the actual mouse interface firmware from the original card because I wanted something to synchronize the host machine mouse pointer to the emulated mouse pointer instead of emulate the wire protocol of the old mouse guts.  Because of this, Jace acts a little differently.  If you touch the screen holes directly (instead of using the firmware calls) then you can expect to fall out of sync with the emulated mouse somewhat in Jace.

If you read the comments of the mouse interface class, you can see a decent summary of what each firmware call returns (accumulator, carry bit) as well as the values stored in screen holes.  Hopefully it can serve as a decent summary of the mouse interface functionality.
https://sourceforge.net/p/java-ace/code/285/tree/jace/src/jace/hardware/CardAppleMouse.java

-B