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

  1.                     ===== Parallax PIC16C5x Assembler v2.3 =====
  2.  
  3.  
  4.      1                              ;PC mouse adapter for Amiga computers
  5.      2                              ;
  6.      3                              ; use serial Pc mouse on Amiga Computers without Software driver !!
  7.      4                              ;
  8.      5                              ; 03.01.96
  9.      6                              ;
  10.      7                              ;This Program converts the microsoft and the mouse system format to amiga ones,
  11.      8                              ;three mouse buttons are supported (mouse system).
  12.      9                              ;Only hardware, it`s like an original Amiga mouse
  13.     10                              ;The Xtal frequenzy is 11.0592 Mhz, the TXD line from mouse is with a 20K
  14.     11                              ;resistor directly with the PIC 16C54 Port connected. Only three other components
  15.     12                              ;are needed for the voltage conversion: ICL7660 (voltage converter from Harris 
  16.     13                              ;semiconductor,INTERSIL) and two capacitors with 10µF. The PCB is about 3*4.5cm.
  17.     14                              ;My PC mouse needs -5V on TXD,5V on RTS and ground. 
  18.     15                              ;The adapter recognizes mouse protocoll changes automatic. I think it`s easy
  19.     16                              ;to include the Logitech protokoll but I don`t know it.
  20.     17                              ;
  21.     18                              ; see our Amiga Pic Tools Home Page:
  22.     19                              ;
  23.     20                              ; http://linux.rz.fh-hannover.de/~duesterb/
  24.     21                              ; (Pic Simulator, Pic Progger)
  25.     22                              ;
  26.     23                              ;Dirk Düsterberg, duesterb@unixserv.rz.fh-hannover.de
  27.     24                              ;
  28.     25                              ;Jahnstr.9
  29.     26                              ;31860 Emmerthal
  30.     27                              ;Germany
  31.     28                              ;
  32.     29                              ;
  33.     30                              ;thanks to Ioannes Petroglou, who made this with his wonderful Tools possibel!
  34.     31
  35.     32
  36.     33
  37.     34                              ; Microsoft is a registered trademark of Microsoft Corp.
  38.     35                              ; Mouse Systems is  registered trademark of MSC Technologies, Inc.
  39.     36                              ; Microchip is a registered trademark of Microchip Technology
  40.     37                              ; Logitech is a registered trademark too
  41.     38                              ; This source is copyrighted to Dirk Düsterberg, no trademark
  42.     39
  43.     40
  44.     41
  45.     42
  46.     43
  47.     44
  48.     45     000-                         DEVICE PIC16C54,HS_OSC,WDT_OFF,PROTECT_OFF
  49.     46
  50.     47     1FF- A00                     RESET    start
  51.     48
  52.     49
  53.     50
  54.     51     =0008                    trycnt    =    08h            ;synctrys, which format?
  55.     52     =0009                    loopcnt    =    09h            ;loop counter
  56.     53
  57.     54     =000A                    bitcnt    =    0ah            ;bit counter
  58.     55     =000B                    serbuf    =    0bh            ;serial buffer
  59.     56
  60.     57     =000C                    RBbuf    =    0ch            ;Port buffer
  61.     58
  62.     59     =0025                    RXD    =    RA.1            ;RXD input, bit 1 from Port A
  63.     60
  64.     61     =0010                    byte0    =    10h            ;first received byte
  65.     62     =0011                    byte1    =    11h            ;second received byte and byte 4 (mouse system)
  66.     63     =0012                    byte2    =    12h            ;third received byte and byte 5 (mouse system)
  67.     64
  68.     65
  69.     66
  70.     67     =004C                    r_b    =    RBbuf.2            ;right mouse button
  71.     68     =008C                    m_b    =    RBbuf.4            ;middle mouse button
  72.     69     =00CC                    l_b    =    RBbuf.6            ;left mouse button
  73.     70
  74.     71     =000C                    H    =    RBbuf.0            ;Horizontal Pulses
  75.     72     =00AC                    HQ    =    RBbuf.5            ;Horizontal Quadrature Pulses
  76.     73     =002C                    V    =    RBbuf.1            ;Vertical Pulses
  77.     74     =00EC                    VQ    =    RBbuf.7            ;Vertical Quadrature Pulses
  78.     75
  79.     76
  80.     77     000- C00 006             start    mov    !RB,#00h
  81.     78     002- CFF 005                 mov    !RA,#0FFh
  82.     79
  83.     80     004- 06C                     clr    RBbuf            ;make butoons unpressed
  84.     81     005- 0EC                     dec    RBbuf
  85.     82
  86.     83     006- 20C 026                 mov    RB,RBbuf        ;use Port buffer to prevent read from Port
  87.     84                                  
  88.     85     008- 068                     clr    trycnt
  89.     86
  90.     87
  91.     88
  92.     89
  93.     90
  94.     91
  95.     92
  96.     93
  97.     94
  98.     95
  99.     96
  100.     97                              ;this is the routine for the microsoft format (3 bytes with 2 buttons)
  101.     98
  102.     99
  103.    100
  104.    101     009- 068                 micro    clr    trycnt
  105.    102     00A- C04 088 603         mic    csb    trycnt,#4
  106.    103     00D- A48                     jmp    mouse            ;more than 3 trys? jump!
  107.    104                                  
  108.    105     00E- 971                     call    rcb            ;receive the first byte
  109.    106     00F- 2A8                     inc    trycnt
  110.    107                                  
  111.    108     010- 20B                     mov    w,serbuf
  112.    109     011- FC0                     xor    w,#11000000b        ;invert bit 6 and 7 from working register
  113.    110     012- EC0                     and    w,#11000000b        ;clr bit 0 to 5 (buttons and coord.)
  114.    111     013- 743                     sz                ;skip if w is zero
  115.    112     014- A0A                     jmp    mic            ;if not zero -> no match
  116.    113
  117.    114     015- 20B 030                 mov    byte0,serbuf        ;this is the first received byte
  118.    115
  119.    116
  120.    117     017- 58C                     setb    m_b            ;middle button not supported
  121.    118     018- 68B 44C 78B 54C         movb    r_b,/serbuf.4        ;mov buttons
  122.    119     01C- 6AB 4CC 7AB 5CC         movb    l_b,/serbuf.5
  123.    120
  124.    121     020- 971                     call    rcb            ;receive second byte
  125.    122
  126.    123                                  
  127.    124     021- C80 1AB                 xor    serbuf,#10000000b    ;invert bit 7 from buffer
  128.    125     023- 20B                     mov    w,serbuf
  129.    126     024- EC0                     and    w,#11000000b        ;clr bit 0 to 5 (coord.)
  130.    127     025- 743                     sz                ;skip if w is zero
  131.    128     026- A48                     jmp    mouse            ;if not zero -> no match -> mouse format
  132.    129                                      
  133.    130                                  
  134.    131     027- 071                     clr    byte1
  135.    132
  136.    133     028- 710 4D1 610 5D1         movb    byte1.6,byte0.0        ;mov x6 and x7 coord. to byte1
  137.    134     02C- 730 4F1 630 5F1         movb    byte1.7,byte0.1
  138.    135
  139.    136     030- 20B 131                 or    byte1,serbuf        ;set rest of x coord.
  140.    137
  141.    138
  142.    139
  143.    140
  144.    141
  145.    142     032- 971                     call    rcb            ;receive third byte
  146.    143
  147.    144                                  
  148.    145     033- C80 1AB                 xor    serbuf,#10000000b    ;invert bit 7 from buffer
  149.    146     035- 20B                     mov    w,serbuf
  150.    147     036- EC0                     and    w,#11000000b        ;clr bit 0 to 5 (coord.)
  151.    148     037- 743                     sz                ;skip if w is zero
  152.    149     038- A48                     jmp    mouse            ;if not zero -> no match -> mouse format
  153.    150
  154.    151     039- 072                     clr    byte2
  155.    152
  156.    153     03A- 750 4D2 650 5D2         movb    byte2.6,byte0.2        ;mov y6 and y7 coord. to byte2
  157.    154     03E- 770 4F2 670 5F2         movb    byte2.7,byte0.3
  158.    155
  159.    156     042- 20B 132                 or    byte2,serbuf        ;set rest of y coord.
  160.    157     044- 272 2B2                 neg    byte2            ;fix microsoft to mouse protokoll
  161.    158                                                  ;(up and down exchanged)
  162.    159     046- 068                     clr    trycnt
  163.    160     047- A09                     jmp    micro
  164.    161
  165.    162
  166.    163
  167.    164                              ;this is the routine for the mouse system format (5 bytes with 3 buttons)
  168.    165
  169.    166
  170.    167     048- C06 088 603         mouse    csb    trycnt,#6
  171.    168     04B- A09                     jmp    micro            ;more than 5 trys? jump micro!
  172.    169
  173.    170     04C- 971                     call    rcb            ;get first of five bytes from serial mouse
  174.    171
  175.    172     04D- 2A8                     inc    trycnt            ;one more try
  176.    173
  177.    174                              ;test format #10000lmr (left, middle, right) 
  178.    175
  179.    176     04E- 20B                     mov    w,serbuf
  180.    177     04F- F80                     xor    w,#10000000b        ;invert bit 7 from working register
  181.    178     050- EF8                     and    w,#11111000b        ;clr bit 0 to 2 (buttons)
  182.    179     051- 743                     sz                ;skip if w is zero
  183.    180     052- A48                     jmp    mouse            ;if not zero -> no match
  184.    181                                  
  185.    182     053- 20B 030                 mov    byte0,serbuf
  186.    183
  187.    184
  188.    185
  189.    186     055- 971                     call    rcb            ;byte1, X-Axis movement data
  190.    187     056- 20B 031                 mov    byte1,serbuf
  191.    188
  192.    189     058- 971                     call    rcb            ;byte2, Y-Axis movement data
  193.    190     059- 20B 032                 mov    byte2,serbuf
  194.    191                                  
  195.    192     05B- 971                     call    rcb            ;byte3, X-Axis movement data    
  196.    193     05C- 20B 031                 mov    byte1,serbuf
  197.    194
  198.    195     05E- 971                     call    rcb            ;byte4, Y-Axis movement data
  199.    196     05F- 20B 032                 mov    byte2,serbuf
  200.    197
  201.    198     061- 710 44C 610 54C         movb    r_b,byte0.0        ;convert to Amiga
  202.    199     065- 730 48C 630 58C         movb    m_b,byte0.1
  203.    200     069- 750 4CC 650 5CC         movb    l_b,byte0.2
  204.    201     06D- 20C 026                 mov    RB,RBbuf        ;use Port buffer to prevent read from Port
  205.    202
  206.    203     06F- 068                     clr    trycnt            
  207.    204
  208.    205     070- A48                     jmp    mouse
  209.    206
  210.    207
  211.    208
  212.    209
  213.    210
  214.    211
  215.    212
  216.    213                              ;receive routine, receive 8bits
  217.    214                              ;loop is done until byte is received
  218.    215
  219.    216
  220.    217
  221.    218
  222.    219     071- 625 A74             rcb    jb    RXD,rcshift        ;startbit ?
  223.    220     073- A71                     jmp    rcb
  224.    221     074- C08 02A             rcshift    mov    bitcnt,#8
  225.    222     076- 982                     call    whbit            ;wait half bit (middle bit position)
  226.    223
  227.    224     077- 98E                 r_it    call    wbit            ;wait bit delay
  228.    225     078- 725 403 625 503         movb    c,RXD            ;move RXD into c
  229.    226     07C- 32B                     rr    serbuf            ;rotate c in serbuf
  230.    227     07D- 2EA A77                 djnz    bitcnt,r_it        ;decrement bit counter (8 bits)
  231.    228     07F- 26B                     not    serbuf            ;invert serbuf (RS232 -> TTL)
  232.    229     080- 982                     call    whbit            ;wait a half bit to get out from data area
  233.    230     081- 800                     ret                ;back
  234.    231
  235.    232
  236.    233
  237.    234
  238.    235
  239.    236
  240.    237
  241.    238
  242.    239                              ;wait routine for one and one half bit for 1200 baud
  243.    240
  244.    241
  245.    242     082- C7D 029             whbit    mov    loopcnt,#125        ;1200
  246.    243     084- 000                 do_hbit    nop
  247.    244     085- 000                     nop
  248.    245     086- 000                     nop
  249.    246     087- 000                     nop
  250.    247     088- 000                     nop
  251.    248     089- 000                     nop
  252.    249     08A- 000                     nop
  253.    250     08B- 2E9 A84                 djnz    loopcnt,do_hbit
  254.    251     08D- 800                     ret
  255.    252
  256.    253
  257.    254
  258.    255
  259.    256
  260.    257                              ;this routine is one bit long, it converts the axe counter to a quadrature
  261.    258                              ;modulation, every change on V,VQ,H or HQ means a mouse move
  262.    259
  263.    260
  264.    261     08E- C2D 029             wbit    mov    loopcnt,#45        ;quad mod is done while bit waiting
  265.    262     090- 211                 x_axe    mov    w,byte1
  266.    263     091- 643                     snz
  267.    264     092- AA8                     jmp    x_axe0            ;byte1 = 0, nothing to do
  268.    265     093- 6F1 ABB                 jb    byte1.7,_right        ;jump if bit
  269.    266     095- 000                     nop
  270.    267     096- 000                     nop
  271.    268     097- 000                     nop
  272.    269     098- 000                     nop
  273.    270     099- 000                     nop
  274.    271     09A- 0F1                 left    dec    byte1            ;decrement byte 1
  275.    272     09B- 60C                     snb    H
  276.    273     09C- AA1                     jmp    leftx1            ;jmp to x1 if H set
  277.    274     09D- 6AC                     snb    HQ
  278.    275     09E- AA6                     jmp    left10
  279.    276     09F- 50C                     setb    H            ;set H if H and HQ clear
  280.    277     0A0- AB6                     jmp    lback1
  281.    278     0A1- 6AC                 leftx1    snb    HQ            
  282.    279     0A2- 40C                     clrb    H            ;clr H if H set and HQ set
  283.    280     0A3- 7AC                     sb    HQ
  284.    281     0A4- 5AC                     setb    HQ            ;set HQ if H set and HQ clear
  285.    282     0A5- AB8                     jmp    lback3
  286.    283     0A6- 4AC                 left10    clrb    HQ            ;clear HQ if H clear and HQ set
  287.    284     0A7- AB7                     jmp    lback2
  288.    285     0A8- 000                 x_axe0    nop
  289.    286     0A9- 000                     nop
  290.    287     0AA- 000                     nop
  291.    288     0AB- 000                     nop
  292.    289     0AC- 000                     nop
  293.    290     0AD- 000                     nop
  294.    291     0AE- 000                     nop
  295.    292     0AF- 000                     nop
  296.    293     0B0- 000                     nop
  297.    294     0B1- 000                     nop
  298.    295     0B2- 000                     nop
  299.    296     0B3- 000                     nop
  300.    297     0B4- 000                     nop
  301.    298     0B5- 000                     nop
  302.    299     0B6- 000                 lback1    nop
  303.    300     0B7- 000                 lback2    nop
  304.    301     0B8- 20C 026             lback3    mov    RB,RBbuf        ;use Port buffer to prevent read from Port
  305.    302     0BA- AD3                     jmp    y_axe
  306.    303
  307.    304     0BB- 271 2B1             _right    neg    byte1
  308.    305
  309.    306     0BD- 000                     nop
  310.    307     0BE- 000                     nop
  311.    308
  312.    309     0BF- 0F1                 right    dec    byte1
  313.    310     0C0- 6AC                     snb    HQ
  314.    311     0C1- AC6                     jmp    right1x            ;jmp to 1x if HQ set
  315.    312     0C2- 60C                     snb    H
  316.    313     0C3- ACB                     jmp    right01
  317.    314     0C4- 5AC                     setb    HQ            ;set HQ if H and HQ clear
  318.    315     0C5- ACD                     jmp    rback1
  319.    316     0C6- 60C                 right1x    snb    H            
  320.    317     0C7- 4AC                     clrb    HQ            ;clrb H if H and HQ set
  321.    318     0C8- 70C                     sb    H
  322.    319     0C9- 50C                     setb    H            ;setb H if H clear and HQ set
  323.    320     0CA- ACF                     jmp    rback3
  324.    321     0CB- 40C                 right01    clrb    H            ;clr H if HQ clear and H set
  325.    322     0CC- ACE                     jmp    rback2
  326.    323
  327.    324     0CD- 000                 rback1    nop
  328.    325     0CE- 000                 rback2    nop
  329.    326     0CF- 20C 026             rback3    mov    RB,RBbuf        ;use Port buffer to prevent read from Port
  330.    327     0D1- 271 2B1                 neg    byte1
  331.    328
  332.    329                                  
  333.    330
  334.    331
  335.    332     0D3- 212                 y_axe    mov    w,byte2
  336.    333     0D4- 643                     snz
  337.    334     0D5- AEB                     jmp    y_axe0            ;byte2 = 0, nothing to do
  338.    335     0D6- 6F2 AFE                 jb    byte2.7,_up        ;jump if bit
  339.    336     0D8- 000                     nop
  340.    337     0D9- 000                     nop
  341.    338     0DA- 000                     nop
  342.    339     0DB- 000                     nop
  343.    340     0DC- 000                     nop
  344.    341     0DD- 0F2                 down    dec    byte2
  345.    342     0DE- 6EC                     snb    VQ
  346.    343     0DF- AE4                     jmp    down1x            ;jmp to 1x if VQ set
  347.    344     0E0- 62C                     snb    V
  348.    345     0E1- AE9                     jmp    down01
  349.    346     0E2- 5EC                     setb    VQ            ;set VQ if V and VQ clear
  350.    347     0E3- AF9                     jmp    dback1
  351.    348     0E4- 62C                 down1x    snb    V            
  352.    349     0E5- 4EC                     clrb    VQ            ;clrb V if V and VQ set
  353.    350     0E6- 72C                     sb    V
  354.    351     0E7- 52C                     setb    V            ;setb V if V clear and VQ set
  355.    352     0E8- AFB                     jmp    dback3
  356.    353     0E9- 42C                 down01    clrb    V            ;clr V if VQ clear and V set
  357.    354     0EA- AFA                     jmp    dback2
  358.    355     0EB- 000                 y_axe0    nop
  359.    356     0EC- 000                     nop
  360.    357     0ED- 000                     nop
  361.    358     0EE- 000                     nop
  362.    359     0EF- 000                     nop
  363.    360     0F0- 000                     nop
  364.    361     0F1- 000                     nop
  365.    362     0F2- 000                     nop
  366.    363     0F3- 000                     nop
  367.    364     0F4- 000                     nop
  368.    365     0F5- 000                     nop
  369.    366     0F6- 000                     nop
  370.    367     0F7- 000                     nop
  371.    368     0F8- 000                     nop
  372.    369     0F9- 000                 dback1    nop
  373.    370     0FA- 000                 dback2    nop
  374.    371     0FB- 20C 026             dback3    mov    RB,RBbuf        ;use Port buffer to prevent read from Port
  375.    372     0FD- B16                     jmp    done
  376.    373
  377.    374     0FE- 272 2B2             _up    neg    byte2
  378.    375
  379.    376     100- 000                     nop
  380.    377     101- 000                     nop
  381.    378
  382.    379     102- 0F2                 up    dec    byte2
  383.    380     103- 62C                     snb    V
  384.    381     104- B09                     jmp    up_x1            ;jmp to x1 if V set
  385.    382     105- 6EC                     snb    VQ
  386.    383     106- B0E                     jmp    up_10
  387.    384     107- 52C                     setb    V            ;set V if V and VQ clear
  388.    385     108- B10                     jmp    uback1
  389.    386     109- 6EC                 up_x1    snb    VQ            
  390.    387     10A- 42C                     clrb    V            ;clr V if V set and VQ set
  391.    388     10B- 7EC                     sb    VQ
  392.    389     10C- 5EC                     setb    VQ            ;set VQ if V set and VQ clear
  393.    390     10D- B12                     jmp    uback3
  394.    391     10E- 4EC                 up_10    clrb    VQ            ;clear VQ if V clear and VQ set
  395.    392     10F- B11                     jmp    uback2
  396.    393     110- 000                 uback1    nop
  397.    394     111- 000                 uback2    nop
  398.    395     112- 20C 026             uback3    mov    RB,RBbuf        ;use Port buffer to prevent read from Port
  399.    396     114- 272 2B2                 neg    byte2
  400.    397                                  
  401.    398                                  
  402.    399
  403.    400     116- 2E9 A90             done    djnz    loopcnt,x_axe
  404.    401     118- 800                     ret
  405.  
  406.  
  407.                             ===== Errors: 0 =====
  408. 
  409.