Advertisement
Guest User

dunemouse.asm

a guest
Jun 26th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.         org 0
  2.         incbin  dune2.bin
  3.  
  4.         org $d54
  5.         nop
  6.         nop
  7.         nop
  8.  
  9.         org $28DDE
  10.         move.w  #$D8,-(sp)
  11.         move.w  #$138,-(sp)
  12.         moveq   #$10,d0
  13.  
  14.         org $28708
  15.         move.w  #$D8,(sp)
  16.         move.w  #$138,-(sp)
  17.         moveq   #$10,d0
  18.  
  19.         org $2867C
  20.         move.w  #$D8,(sp)
  21.         move.w  #$138,-(sp)
  22.         moveq   #$10,d0
  23.  
  24.         org $1615E
  25.         move.w  #$D8,(sp)
  26.         move.w  #$138,-(sp)
  27.         moveq   #$10,d0
  28.  
  29.  
  30.  
  31.         org $28DD6
  32.         bra.s   $28DDE
  33.  
  34.         org $28620
  35.         nop
  36.         nop
  37.         nop
  38.  
  39.         org $6522
  40.         subi.w  #$48,d4
  41.  
  42.         org $652C
  43.         addi.w  #$80,d4
  44.  
  45.  
  46.         org $660A
  47.         subi.w  #$42,d5
  48.  
  49.         org $6614
  50.         addi.w  #$4C,d5
  51.  
  52.  
  53.         org $6FFC
  54.         nop
  55.         nop
  56.         nop
  57.  
  58.  
  59.         org $6e36
  60.         nop
  61.  
  62.         org $6ec6
  63.         bra.w   $6EE4
  64.  
  65.         org     $6e3c
  66.         bra.s   $6E46
  67.  
  68.         org $6e4a
  69.         nop
  70.  
  71.         org $6eec
  72.         nop
  73.         nop
  74.  
  75.         org $6F90
  76.         nop
  77.         nop
  78.  
  79.         org $706A
  80. ;       bra.w   $71F6
  81.  
  82.         org $7088
  83.         bra.w   $7128
  84.  
  85.         org $713C
  86.         bra.w   $71F6
  87.  
  88.         org $707A
  89.         cmpi.w  #$18,d0
  90.         blt.s   $708C
  91.         cmpi.w  #$128,d0
  92.  
  93.  
  94.         org $708C
  95.         subi.w  #$18,d0
  96.         blt.s   $7096
  97.         subi.w  #$128,d0
  98.  
  99.         org $712E
  100.         cmpi.w  #$18,d0
  101.         blt.s   $7140
  102.         cmpi.w  #$c8,d0
  103.  
  104.         org $7140
  105.         subi.w  #$18,d0
  106.         bra.s   $714A
  107.         subi.w  #$c8,d0
  108.  
  109.  
  110.         org $7098
  111.         asr.l   #1,d0
  112.  
  113.         org $714c
  114.         asr.l   #1,d0
  115.  
  116.         org $EC4
  117.         bne.w   joy_drv_sub
  118.  
  119.         org $ED4
  120.         bra.w   $EE2
  121.  
  122.         org $F36
  123.         or.b    ($FFFFE41C).w,d0
  124.         move.b  d0,1(a1)
  125.         and.b   d2,d0
  126.         move.b  d0,(a1)
  127.         move.l  (sp)+,d2
  128.         rts
  129. joy_drv_sub:
  130.         move.l  ($FFFFE422).w,d0
  131.         beq.s   locret_F52
  132.         movea.l d0,a0
  133.         jsr     (a0)
  134.         move.l  d0,($FFFFE41A).w
  135. locret_F52:
  136.         rts
  137.  
  138.         org $1856
  139.         clr.l   ($FFFFF800).w
  140.         jsr     mouse_read.w
  141.         movem.l (sp)+,d0-a6
  142.         rte
  143.  
  144. ; ---------------------------------------------------------------------------
  145.  
  146.         org $2460
  147. mouse_read:
  148. ; halt z80
  149.         move.w  #$100,($A11100).l
  150.         move.w  #$100,($A11200).l
  151. wait_z80:
  152.         btst    #0,($A11100).l
  153.         bne.s   wait_z80
  154.  
  155.         movea.l #$A10005,a0
  156.         move.b  #$60,6(a0)          ; set port direction for TLH
  157.         nop
  158.         nop
  159.         move.b  #$60,(a0)           ; set port for TLH
  160.         nop
  161.         nop
  162. wait_hs0:
  163.         btst    #4,(a0)
  164.         beq.s   wait_hs0
  165.  
  166.         move.w  #254,d1             ; # retries
  167. ; get header
  168.         moveq   #1,d2               ; two bytes (four nibbles) in header
  169.         bsr.w   do_tlh
  170. ; check header
  171.         cmpi.w  #$0BFF,d0           ; check for mouse
  172.         bne.w   mouse_err
  173.  
  174. ; get mouse packet
  175.         moveq   #2,d2               ; three bytes (six nibbles) in packet
  176.         bsr.w   do_tlh
  177.         move.b  #$60,(a0)           ; TLH done
  178.         move.w  #0,($A11100).l      ; release z80
  179.  
  180. ; process mouse packet
  181. ;   d0 = YO XO YS XS S M R L X7 X6 X5 X4 X3 X2 X1 X0 Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0
  182.         btst    #23,d0              ; YO
  183.         beq.s   chkys               ; no overflow
  184.         move.w  #$0100,d2
  185.         btst    #21,d0              ; YS
  186.         beq.s   calcy               ; positive
  187.         neg.w   d2
  188.         bra.s   calcy
  189. chkys:
  190.         moveq   #0,d2
  191.         move.b  d0,d2
  192.         btst    #21,d0              ; YS
  193.         beq.s   calcy               ; positive
  194.         or.w    #$FF00,d2           ; sign-extend Y
  195.         tst.b   d2
  196.         bne.s   calcy
  197.         seq     d2                  ; handle -0 case
  198. calcy:
  199.         asr.w   #1,d2
  200.         move.w  ($FFFFBF14).w,d1    ; screen Y coord
  201.         sub.w   d2,d1
  202.         cmpi.w  #$D0,d1
  203.         ble.s   chkymin
  204.         move.w  #$D0,d1
  205. chkymin:
  206.         cmpi.w  #$10,d1
  207.         bge.s   updsy
  208.         move.w  #$10,d1
  209. updsy:
  210.         move.w  d1,($FFFFBF14).w    ; update Y coord
  211.  
  212.         btst    #22,d0              ; XO
  213.         beq.s   chkxs               ; no overflow
  214.         move.w  #$0100,d0
  215.         btst    #20,d0              ; XS
  216.         beq.s   calcx               ; positive
  217.         neg.w   d0
  218.         bra.s   calcx
  219. chkxs:
  220.         lsr.w   #8,d0
  221.         btst    #20,d0              ; XS
  222.         beq.s   calcx               ; positive
  223.         or.w    #$FF00,d0           ; sign-extend X
  224.         tst.b   d0
  225.         bne.s   calcx
  226.         seq     d0                  ; handle -0 case
  227. calcx:
  228.         asr.w   #1,d0
  229.         move.w  ($FFFFBF12).w,d1    ; screen X coord
  230.         add.w   d0,d1
  231.         cmpi.w  #$130,d1
  232.         ble.s   chkxmin
  233.         move.w  #$130,d1
  234. chkxmin:
  235.         cmpi.w  #$10,d1
  236.         bge.s   updsx
  237.         move.w  #$10,d1
  238. updsx:
  239.         move.w  d1,($FFFFBF12).w    ; update X coord
  240.  
  241.         clr.b   d1
  242.         btst    #16,d0              ; LMB
  243.         beq.s   chkrmb
  244.         bset    #6,d1
  245. chkrmb:
  246.         btst    #17,d0              ; RMB
  247.         beq.s   do_btns
  248.         bset    #4,d1
  249. do_btns:
  250.         move.b  d1,d0
  251.         move.b  ($FFFFE41C).w,d1    ; save current button state
  252.         move.b  d0,($FFFFE41C).w    ; set current button state
  253.         eor.b   d0,d1
  254.         move.b  d1,($FFFFE41D).w    ; change in button state
  255.  
  256.         rts
  257.  
  258. do_tlh:
  259.         move.b  (a0),d0
  260.         move.b  #$20,(a0)   ; next phase
  261.         lsl.b   #4,d0
  262.         lsl.l   #4,d0       ; save nibble
  263. wait_hs1:
  264.         btst    #4,(a0)
  265.         bne.s   pkt_phase2
  266.         dbra    d1,wait_hs1
  267.         addq.l  #4,sp       ; pop return address
  268.         bra.s   mouse_err
  269.  
  270. pkt_phase2:
  271.         move.b  (a0),d0
  272.         move.b  #0,(a0)     ; next phase
  273.         lsl.b   #4,d0
  274.         lsl.l   #4,d0       ; save nibble
  275. wait_hs2:
  276.         btst    #4,(a0)
  277.         beq.s   pkt_chklp
  278.         dbra    d1,wait_hs2
  279.         addq.l  #4,sp       ; pop return address
  280.         bra.s   mouse_err
  281.  
  282. pkt_chklp:
  283.         dbra    d2,do_tlh
  284.         lsr.l   #8,d0
  285.         rts
  286.  
  287. ; ---------------------------------------------------------------------------
  288.  
  289. mouse_err:
  290.         move.b  #$60,(a0)           ; TLH done
  291.         move.w  #0,($A11100).l      ; release z80
  292.         moveq   #-1,d0
  293.         rts
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement