home *** CD-ROM | disk | FTP | other *** search
/ MACD 4 / MACD4.iso / Emulatory / PicSim / examples / parallax / mouse54.SRC < prev    next >
Encoding:
Text File  |  1978-03-06  |  7.2 KB  |  402 lines

  1. ;PC mouse adapter for Amiga computers
  2. ;
  3. ; use serial Pc mouse on Amiga Computers without Software driver !!
  4. ;
  5. ; 03.01.96
  6. ;
  7. ;This Program converts the microsoft and the mouse system format to amiga ones,
  8. ;three mouse buttons are supported (mouse system).
  9. ;Only hardware, it`s like an original Amiga mouse
  10. ;The Xtal frequenzy is 11.0592 Mhz, the TXD line from mouse is with a 20K
  11. ;resistor directly with the PIC 16C54 Port connected. Only three other components
  12. ;are needed for the voltage conversion: ICL7660 (voltage converter from Harris 
  13. ;semiconductor,INTERSIL) and two capacitors with 10µF. The PCB is about 3*4.5cm.
  14. ;My PC mouse needs -5V on TXD,5V on RTS and ground. 
  15. ;The adapter recognizes mouse protocoll changes automatic. I think it`s easy
  16. ;to include the Logitech protokoll but I don`t know it.
  17. ;
  18. ; see our Amiga Pic Tools Home Page:
  19. ;
  20. ; http://linux.rz.fh-hannover.de/~duesterb/
  21. ; (Pic Simulator, Pic Progger)
  22. ;
  23. ;Dirk Düsterberg, duesterb@unixserv.rz.fh-hannover.de
  24. ;
  25. ;Jahnstr.9
  26. ;31860 Emmerthal
  27. ;Germany
  28. ;
  29. ;
  30. ;thanks to Ioannes Petroglou, who made this with his wonderful Tools possibel!
  31.  
  32.  
  33.  
  34. ; Microsoft is a registered trademark of Microsoft Corp.
  35. ; Mouse Systems is  registered trademark of MSC Technologies, Inc.
  36. ; Microchip is a registered trademark of Microchip Technology
  37. ; Logitech is a registered trademark too
  38. ; This source is copyrighted to Dirk Düsterberg, no trademark
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.     DEVICE PIC16C54,HS_OSC,WDT_OFF,PROTECT_OFF
  46.  
  47.     RESET    start
  48.  
  49.  
  50.  
  51. trycnt    =    08h            ;synctrys, which format?
  52. loopcnt    =    09h            ;loop counter
  53.  
  54. bitcnt    =    0ah            ;bit counter
  55. serbuf    =    0bh            ;serial buffer
  56.  
  57. RBbuf    =    0ch            ;Port buffer
  58.  
  59. RXD    =    RA.1            ;RXD input, bit 1 from Port A
  60.  
  61. byte0    =    10h            ;first received byte
  62. byte1    =    11h            ;second received byte and byte 4 (mouse system)
  63. byte2    =    12h            ;third received byte and byte 5 (mouse system)
  64.  
  65.  
  66.  
  67. r_b    =    RBbuf.2            ;right mouse button
  68. m_b    =    RBbuf.4            ;middle mouse button
  69. l_b    =    RBbuf.6            ;left mouse button
  70.  
  71. H    =    RBbuf.0            ;Horizontal Pulses
  72. HQ    =    RBbuf.5            ;Horizontal Quadrature Pulses
  73. V    =    RBbuf.1            ;Vertical Pulses
  74. VQ    =    RBbuf.7            ;Vertical Quadrature Pulses
  75.  
  76.  
  77. start    mov    !RB,#00h
  78.     mov    !RA,#0FFh
  79.  
  80.     clr    RBbuf            ;make butoons unpressed
  81.     dec    RBbuf
  82.  
  83.     mov    RB,RBbuf        ;use Port buffer to prevent read from Port
  84.     
  85.     clr    trycnt
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97. ;this is the routine for the microsoft format (3 bytes with 2 buttons)
  98.  
  99.  
  100.  
  101. micro    clr    trycnt
  102. mic    csb    trycnt,#4
  103.     jmp    mouse            ;more than 3 trys? jump!
  104.     
  105.     call    rcb            ;receive the first byte
  106.     inc    trycnt
  107.     
  108.     mov    w,serbuf
  109.     xor    w,#11000000b        ;invert bit 6 and 7 from working register
  110.     and    w,#11000000b        ;clr bit 0 to 5 (buttons and coord.)
  111.     sz                ;skip if w is zero
  112.     jmp    mic            ;if not zero -> no match
  113.  
  114.     mov    byte0,serbuf        ;this is the first received byte
  115.  
  116.  
  117.     setb    m_b            ;middle button not supported
  118.     movb    r_b,/serbuf.4        ;mov buttons
  119.     movb    l_b,/serbuf.5
  120.  
  121.     call    rcb            ;receive second byte
  122.  
  123.     
  124.     xor    serbuf,#10000000b    ;invert bit 7 from buffer
  125.     mov    w,serbuf
  126.     and    w,#11000000b        ;clr bit 0 to 5 (coord.)
  127.     sz                ;skip if w is zero
  128.     jmp    mouse            ;if not zero -> no match -> mouse format
  129.         
  130.     
  131.     clr    byte1
  132.  
  133.     movb    byte1.6,byte0.0        ;mov x6 and x7 coord. to byte1
  134.     movb    byte1.7,byte0.1
  135.  
  136.     or    byte1,serbuf        ;set rest of x coord.
  137.  
  138.  
  139.  
  140.  
  141.  
  142.     call    rcb            ;receive third byte
  143.  
  144.     
  145.     xor    serbuf,#10000000b    ;invert bit 7 from buffer
  146.     mov    w,serbuf
  147.     and    w,#11000000b        ;clr bit 0 to 5 (coord.)
  148.     sz                ;skip if w is zero
  149.     jmp    mouse            ;if not zero -> no match -> mouse format
  150.  
  151.     clr    byte2
  152.  
  153.     movb    byte2.6,byte0.2        ;mov y6 and y7 coord. to byte2
  154.     movb    byte2.7,byte0.3
  155.  
  156.     or    byte2,serbuf        ;set rest of y coord.
  157.     neg    byte2            ;fix microsoft to mouse protokoll
  158.                     ;(up and down exchanged)
  159.     clr    trycnt
  160.     jmp    micro
  161.  
  162.  
  163.  
  164. ;this is the routine for the mouse system format (5 bytes with 3 buttons)
  165.  
  166.  
  167. mouse    csb    trycnt,#6
  168.     jmp    micro            ;more than 5 trys? jump micro!
  169.  
  170.     call    rcb            ;get first of five bytes from serial mouse
  171.  
  172.     inc    trycnt            ;one more try
  173.  
  174. ;test format #10000lmr (left, middle, right) 
  175.  
  176.     mov    w,serbuf
  177.     xor    w,#10000000b        ;invert bit 7 from working register
  178.     and    w,#11111000b        ;clr bit 0 to 2 (buttons)
  179.     sz                ;skip if w is zero
  180.     jmp    mouse            ;if not zero -> no match
  181.     
  182.     mov    byte0,serbuf
  183.  
  184.  
  185.  
  186.     call    rcb            ;byte1, X-Axis movement data
  187.     mov    byte1,serbuf
  188.  
  189.     call    rcb            ;byte2, Y-Axis movement data
  190.     mov    byte2,serbuf
  191.     
  192.     call    rcb            ;byte3, X-Axis movement data    
  193.     mov    byte1,serbuf
  194.  
  195.     call    rcb            ;byte4, Y-Axis movement data
  196.     mov    byte2,serbuf
  197.  
  198.     movb    r_b,byte0.0        ;convert to Amiga
  199.     movb    m_b,byte0.1
  200.     movb    l_b,byte0.2
  201.     mov    RB,RBbuf        ;use Port buffer to prevent read from Port
  202.  
  203.     clr    trycnt            
  204.  
  205.     jmp    mouse
  206.  
  207.  
  208.  
  209.  
  210.  
  211.  
  212.  
  213. ;receive routine, receive 8bits
  214. ;loop is done until byte is received
  215.  
  216.  
  217.  
  218.  
  219. rcb    jb    RXD,rcshift        ;startbit ?
  220.     jmp    rcb
  221. rcshift    mov    bitcnt,#8
  222.     call    whbit            ;wait half bit (middle bit position)
  223.  
  224. r_it    call    wbit            ;wait bit delay
  225.     movb    c,RXD            ;move RXD into c
  226.     rr    serbuf            ;rotate c in serbuf
  227.     djnz    bitcnt,r_it        ;decrement bit counter (8 bits)
  228.     not    serbuf            ;invert serbuf (RS232 -> TTL)
  229.     call    whbit            ;wait a half bit to get out from data area
  230.     ret                ;back
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239. ;wait routine for one and one half bit for 1200 baud
  240.  
  241.  
  242. whbit    mov    loopcnt,#125        ;1200
  243. do_hbit    nop
  244.     nop
  245.     nop
  246.     nop
  247.     nop
  248.     nop
  249.     nop
  250.     djnz    loopcnt,do_hbit
  251.     ret
  252.  
  253.  
  254.  
  255.  
  256.  
  257. ;this routine is one bit long, it converts the axe counter to a quadrature
  258. ;modulation, every change on V,VQ,H or HQ means a mouse move
  259.  
  260.  
  261. wbit    mov    loopcnt,#45        ;quad mod is done while bit waiting
  262. x_axe    mov    w,byte1
  263.     snz
  264.     jmp    x_axe0            ;byte1 = 0, nothing to do
  265.     jb    byte1.7,_right        ;jump if bit
  266.     nop
  267.     nop
  268.     nop
  269.     nop
  270.     nop
  271. left    dec    byte1            ;decrement byte 1
  272.     snb    H
  273.     jmp    leftx1            ;jmp to x1 if H set
  274.     snb    HQ
  275.     jmp    left10
  276.     setb    H            ;set H if H and HQ clear
  277.     jmp    lback1
  278. leftx1    snb    HQ            
  279.     clrb    H            ;clr H if H set and HQ set
  280.     sb    HQ
  281.     setb    HQ            ;set HQ if H set and HQ clear
  282.     jmp    lback3
  283. left10    clrb    HQ            ;clear HQ if H clear and HQ set
  284.     jmp    lback2
  285. x_axe0    nop
  286.     nop
  287.     nop
  288.     nop
  289.     nop
  290.     nop
  291.     nop
  292.     nop
  293.     nop
  294.     nop
  295.     nop
  296.     nop
  297.     nop
  298.     nop
  299. lback1    nop
  300. lback2    nop
  301. lback3    mov    RB,RBbuf        ;use Port buffer to prevent read from Port
  302.     jmp    y_axe
  303.  
  304. _right    neg    byte1
  305.  
  306.     nop
  307.     nop
  308.  
  309. right    dec    byte1
  310.     snb    HQ
  311.     jmp    right1x            ;jmp to 1x if HQ set
  312.     snb    H
  313.     jmp    right01
  314.     setb    HQ            ;set HQ if H and HQ clear
  315.     jmp    rback1
  316. right1x    snb    H            
  317.     clrb    HQ            ;clrb H if H and HQ set
  318.     sb    H
  319.     setb    H            ;setb H if H clear and HQ set
  320.     jmp    rback3
  321. right01    clrb    H            ;clr H if HQ clear and H set
  322.     jmp    rback2
  323.  
  324. rback1    nop
  325. rback2    nop
  326. rback3    mov    RB,RBbuf        ;use Port buffer to prevent read from Port
  327.     neg    byte1
  328.  
  329.     
  330.  
  331.  
  332. y_axe    mov    w,byte2
  333.     snz
  334.     jmp    y_axe0            ;byte2 = 0, nothing to do
  335.     jb    byte2.7,_up        ;jump if bit
  336.     nop
  337.     nop
  338.     nop
  339.     nop
  340.     nop
  341. down    dec    byte2
  342.     snb    VQ
  343.     jmp    down1x            ;jmp to 1x if VQ set
  344.     snb    V
  345.     jmp    down01
  346.     setb    VQ            ;set VQ if V and VQ clear
  347.     jmp    dback1
  348. down1x    snb    V            
  349.     clrb    VQ            ;clrb V if V and VQ set
  350.     sb    V
  351.     setb    V            ;setb V if V clear and VQ set
  352.     jmp    dback3
  353. down01    clrb    V            ;clr V if VQ clear and V set
  354.     jmp    dback2
  355. y_axe0    nop
  356.     nop
  357.     nop
  358.     nop
  359.     nop
  360.     nop
  361.     nop
  362.     nop
  363.     nop
  364.     nop
  365.     nop
  366.     nop
  367.     nop
  368.     nop
  369. dback1    nop
  370. dback2    nop
  371. dback3    mov    RB,RBbuf        ;use Port buffer to prevent read from Port
  372.     jmp    done
  373.  
  374. _up    neg    byte2
  375.  
  376.     nop
  377.     nop
  378.  
  379. up    dec    byte2
  380.     snb    V
  381.     jmp    up_x1            ;jmp to x1 if V set
  382.     snb    VQ
  383.     jmp    up_10
  384.     setb    V            ;set V if V and VQ clear
  385.     jmp    uback1
  386. up_x1    snb    VQ            
  387.     clrb    V            ;clr V if V set and VQ set
  388.     sb    VQ
  389.     setb    VQ            ;set VQ if V set and VQ clear
  390.     jmp    uback3
  391. up_10    clrb    VQ            ;clear VQ if V clear and VQ set
  392.     jmp    uback2
  393. uback1    nop
  394. uback2    nop
  395. uback3    mov    RB,RBbuf        ;use Port buffer to prevent read from Port
  396.     neg    byte2
  397.     
  398.     
  399.  
  400. done    djnz    loopcnt,x_axe
  401.     ret
  402.