home *** CD-ROM | disk | FTP | other *** search
File List | 1978-03-06 | 17.3 KB | 409 lines |
- ===== Parallax PIC16C5x Assembler v2.3 =====
-
-
- 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 000- DEVICE PIC16C54,HS_OSC,WDT_OFF,PROTECT_OFF
- 46
- 47 1FF- A00 RESET start
- 48
- 49
- 50
- 51 =0008 trycnt = 08h ;synctrys, which format?
- 52 =0009 loopcnt = 09h ;loop counter
- 53
- 54 =000A bitcnt = 0ah ;bit counter
- 55 =000B serbuf = 0bh ;serial buffer
- 56
- 57 =000C RBbuf = 0ch ;Port buffer
- 58
- 59 =0025 RXD = RA.1 ;RXD input, bit 1 from Port A
- 60
- 61 =0010 byte0 = 10h ;first received byte
- 62 =0011 byte1 = 11h ;second received byte and byte 4 (mouse system)
- 63 =0012 byte2 = 12h ;third received byte and byte 5 (mouse system)
- 64
- 65
- 66
- 67 =004C r_b = RBbuf.2 ;right mouse button
- 68 =008C m_b = RBbuf.4 ;middle mouse button
- 69 =00CC l_b = RBbuf.6 ;left mouse button
- 70
- 71 =000C H = RBbuf.0 ;Horizontal Pulses
- 72 =00AC HQ = RBbuf.5 ;Horizontal Quadrature Pulses
- 73 =002C V = RBbuf.1 ;Vertical Pulses
- 74 =00EC VQ = RBbuf.7 ;Vertical Quadrature Pulses
- 75
- 76
- 77 000- C00 006 start mov !RB,#00h
- 78 002- CFF 005 mov !RA,#0FFh
- 79
- 80 004- 06C clr RBbuf ;make butoons unpressed
- 81 005- 0EC dec RBbuf
- 82
- 83 006- 20C 026 mov RB,RBbuf ;use Port buffer to prevent read from Port
- 84
- 85 008- 068 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 009- 068 micro clr trycnt
- 102 00A- C04 088 603 mic csb trycnt,#4
- 103 00D- A48 jmp mouse ;more than 3 trys? jump!
- 104
- 105 00E- 971 call rcb ;receive the first byte
- 106 00F- 2A8 inc trycnt
- 107
- 108 010- 20B mov w,serbuf
- 109 011- FC0 xor w,#11000000b ;invert bit 6 and 7 from working register
- 110 012- EC0 and w,#11000000b ;clr bit 0 to 5 (buttons and coord.)
- 111 013- 743 sz ;skip if w is zero
- 112 014- A0A jmp mic ;if not zero -> no match
- 113
- 114 015- 20B 030 mov byte0,serbuf ;this is the first received byte
- 115
- 116
- 117 017- 58C setb m_b ;middle button not supported
- 118 018- 68B 44C 78B 54C movb r_b,/serbuf.4 ;mov buttons
- 119 01C- 6AB 4CC 7AB 5CC movb l_b,/serbuf.5
- 120
- 121 020- 971 call rcb ;receive second byte
- 122
- 123
- 124 021- C80 1AB xor serbuf,#10000000b ;invert bit 7 from buffer
- 125 023- 20B mov w,serbuf
- 126 024- EC0 and w,#11000000b ;clr bit 0 to 5 (coord.)
- 127 025- 743 sz ;skip if w is zero
- 128 026- A48 jmp mouse ;if not zero -> no match -> mouse format
- 129
- 130
- 131 027- 071 clr byte1
- 132
- 133 028- 710 4D1 610 5D1 movb byte1.6,byte0.0 ;mov x6 and x7 coord. to byte1
- 134 02C- 730 4F1 630 5F1 movb byte1.7,byte0.1
- 135
- 136 030- 20B 131 or byte1,serbuf ;set rest of x coord.
- 137
- 138
- 139
- 140
- 141
- 142 032- 971 call rcb ;receive third byte
- 143
- 144
- 145 033- C80 1AB xor serbuf,#10000000b ;invert bit 7 from buffer
- 146 035- 20B mov w,serbuf
- 147 036- EC0 and w,#11000000b ;clr bit 0 to 5 (coord.)
- 148 037- 743 sz ;skip if w is zero
- 149 038- A48 jmp mouse ;if not zero -> no match -> mouse format
- 150
- 151 039- 072 clr byte2
- 152
- 153 03A- 750 4D2 650 5D2 movb byte2.6,byte0.2 ;mov y6 and y7 coord. to byte2
- 154 03E- 770 4F2 670 5F2 movb byte2.7,byte0.3
- 155
- 156 042- 20B 132 or byte2,serbuf ;set rest of y coord.
- 157 044- 272 2B2 neg byte2 ;fix microsoft to mouse protokoll
- 158 ;(up and down exchanged)
- 159 046- 068 clr trycnt
- 160 047- A09 jmp micro
- 161
- 162
- 163
- 164 ;this is the routine for the mouse system format (5 bytes with 3 buttons)
- 165
- 166
- 167 048- C06 088 603 mouse csb trycnt,#6
- 168 04B- A09 jmp micro ;more than 5 trys? jump micro!
- 169
- 170 04C- 971 call rcb ;get first of five bytes from serial mouse
- 171
- 172 04D- 2A8 inc trycnt ;one more try
- 173
- 174 ;test format #10000lmr (left, middle, right)
- 175
- 176 04E- 20B mov w,serbuf
- 177 04F- F80 xor w,#10000000b ;invert bit 7 from working register
- 178 050- EF8 and w,#11111000b ;clr bit 0 to 2 (buttons)
- 179 051- 743 sz ;skip if w is zero
- 180 052- A48 jmp mouse ;if not zero -> no match
- 181
- 182 053- 20B 030 mov byte0,serbuf
- 183
- 184
- 185
- 186 055- 971 call rcb ;byte1, X-Axis movement data
- 187 056- 20B 031 mov byte1,serbuf
- 188
- 189 058- 971 call rcb ;byte2, Y-Axis movement data
- 190 059- 20B 032 mov byte2,serbuf
- 191
- 192 05B- 971 call rcb ;byte3, X-Axis movement data
- 193 05C- 20B 031 mov byte1,serbuf
- 194
- 195 05E- 971 call rcb ;byte4, Y-Axis movement data
- 196 05F- 20B 032 mov byte2,serbuf
- 197
- 198 061- 710 44C 610 54C movb r_b,byte0.0 ;convert to Amiga
- 199 065- 730 48C 630 58C movb m_b,byte0.1
- 200 069- 750 4CC 650 5CC movb l_b,byte0.2
- 201 06D- 20C 026 mov RB,RBbuf ;use Port buffer to prevent read from Port
- 202
- 203 06F- 068 clr trycnt
- 204
- 205 070- A48 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 071- 625 A74 rcb jb RXD,rcshift ;startbit ?
- 220 073- A71 jmp rcb
- 221 074- C08 02A rcshift mov bitcnt,#8
- 222 076- 982 call whbit ;wait half bit (middle bit position)
- 223
- 224 077- 98E r_it call wbit ;wait bit delay
- 225 078- 725 403 625 503 movb c,RXD ;move RXD into c
- 226 07C- 32B rr serbuf ;rotate c in serbuf
- 227 07D- 2EA A77 djnz bitcnt,r_it ;decrement bit counter (8 bits)
- 228 07F- 26B not serbuf ;invert serbuf (RS232 -> TTL)
- 229 080- 982 call whbit ;wait a half bit to get out from data area
- 230 081- 800 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 082- C7D 029 whbit mov loopcnt,#125 ;1200
- 243 084- 000 do_hbit nop
- 244 085- 000 nop
- 245 086- 000 nop
- 246 087- 000 nop
- 247 088- 000 nop
- 248 089- 000 nop
- 249 08A- 000 nop
- 250 08B- 2E9 A84 djnz loopcnt,do_hbit
- 251 08D- 800 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 08E- C2D 029 wbit mov loopcnt,#45 ;quad mod is done while bit waiting
- 262 090- 211 x_axe mov w,byte1
- 263 091- 643 snz
- 264 092- AA8 jmp x_axe0 ;byte1 = 0, nothing to do
- 265 093- 6F1 ABB jb byte1.7,_right ;jump if bit
- 266 095- 000 nop
- 267 096- 000 nop
- 268 097- 000 nop
- 269 098- 000 nop
- 270 099- 000 nop
- 271 09A- 0F1 left dec byte1 ;decrement byte 1
- 272 09B- 60C snb H
- 273 09C- AA1 jmp leftx1 ;jmp to x1 if H set
- 274 09D- 6AC snb HQ
- 275 09E- AA6 jmp left10
- 276 09F- 50C setb H ;set H if H and HQ clear
- 277 0A0- AB6 jmp lback1
- 278 0A1- 6AC leftx1 snb HQ
- 279 0A2- 40C clrb H ;clr H if H set and HQ set
- 280 0A3- 7AC sb HQ
- 281 0A4- 5AC setb HQ ;set HQ if H set and HQ clear
- 282 0A5- AB8 jmp lback3
- 283 0A6- 4AC left10 clrb HQ ;clear HQ if H clear and HQ set
- 284 0A7- AB7 jmp lback2
- 285 0A8- 000 x_axe0 nop
- 286 0A9- 000 nop
- 287 0AA- 000 nop
- 288 0AB- 000 nop
- 289 0AC- 000 nop
- 290 0AD- 000 nop
- 291 0AE- 000 nop
- 292 0AF- 000 nop
- 293 0B0- 000 nop
- 294 0B1- 000 nop
- 295 0B2- 000 nop
- 296 0B3- 000 nop
- 297 0B4- 000 nop
- 298 0B5- 000 nop
- 299 0B6- 000 lback1 nop
- 300 0B7- 000 lback2 nop
- 301 0B8- 20C 026 lback3 mov RB,RBbuf ;use Port buffer to prevent read from Port
- 302 0BA- AD3 jmp y_axe
- 303
- 304 0BB- 271 2B1 _right neg byte1
- 305
- 306 0BD- 000 nop
- 307 0BE- 000 nop
- 308
- 309 0BF- 0F1 right dec byte1
- 310 0C0- 6AC snb HQ
- 311 0C1- AC6 jmp right1x ;jmp to 1x if HQ set
- 312 0C2- 60C snb H
- 313 0C3- ACB jmp right01
- 314 0C4- 5AC setb HQ ;set HQ if H and HQ clear
- 315 0C5- ACD jmp rback1
- 316 0C6- 60C right1x snb H
- 317 0C7- 4AC clrb HQ ;clrb H if H and HQ set
- 318 0C8- 70C sb H
- 319 0C9- 50C setb H ;setb H if H clear and HQ set
- 320 0CA- ACF jmp rback3
- 321 0CB- 40C right01 clrb H ;clr H if HQ clear and H set
- 322 0CC- ACE jmp rback2
- 323
- 324 0CD- 000 rback1 nop
- 325 0CE- 000 rback2 nop
- 326 0CF- 20C 026 rback3 mov RB,RBbuf ;use Port buffer to prevent read from Port
- 327 0D1- 271 2B1 neg byte1
- 328
- 329
- 330
- 331
- 332 0D3- 212 y_axe mov w,byte2
- 333 0D4- 643 snz
- 334 0D5- AEB jmp y_axe0 ;byte2 = 0, nothing to do
- 335 0D6- 6F2 AFE jb byte2.7,_up ;jump if bit
- 336 0D8- 000 nop
- 337 0D9- 000 nop
- 338 0DA- 000 nop
- 339 0DB- 000 nop
- 340 0DC- 000 nop
- 341 0DD- 0F2 down dec byte2
- 342 0DE- 6EC snb VQ
- 343 0DF- AE4 jmp down1x ;jmp to 1x if VQ set
- 344 0E0- 62C snb V
- 345 0E1- AE9 jmp down01
- 346 0E2- 5EC setb VQ ;set VQ if V and VQ clear
- 347 0E3- AF9 jmp dback1
- 348 0E4- 62C down1x snb V
- 349 0E5- 4EC clrb VQ ;clrb V if V and VQ set
- 350 0E6- 72C sb V
- 351 0E7- 52C setb V ;setb V if V clear and VQ set
- 352 0E8- AFB jmp dback3
- 353 0E9- 42C down01 clrb V ;clr V if VQ clear and V set
- 354 0EA- AFA jmp dback2
- 355 0EB- 000 y_axe0 nop
- 356 0EC- 000 nop
- 357 0ED- 000 nop
- 358 0EE- 000 nop
- 359 0EF- 000 nop
- 360 0F0- 000 nop
- 361 0F1- 000 nop
- 362 0F2- 000 nop
- 363 0F3- 000 nop
- 364 0F4- 000 nop
- 365 0F5- 000 nop
- 366 0F6- 000 nop
- 367 0F7- 000 nop
- 368 0F8- 000 nop
- 369 0F9- 000 dback1 nop
- 370 0FA- 000 dback2 nop
- 371 0FB- 20C 026 dback3 mov RB,RBbuf ;use Port buffer to prevent read from Port
- 372 0FD- B16 jmp done
- 373
- 374 0FE- 272 2B2 _up neg byte2
- 375
- 376 100- 000 nop
- 377 101- 000 nop
- 378
- 379 102- 0F2 up dec byte2
- 380 103- 62C snb V
- 381 104- B09 jmp up_x1 ;jmp to x1 if V set
- 382 105- 6EC snb VQ
- 383 106- B0E jmp up_10
- 384 107- 52C setb V ;set V if V and VQ clear
- 385 108- B10 jmp uback1
- 386 109- 6EC up_x1 snb VQ
- 387 10A- 42C clrb V ;clr V if V set and VQ set
- 388 10B- 7EC sb VQ
- 389 10C- 5EC setb VQ ;set VQ if V set and VQ clear
- 390 10D- B12 jmp uback3
- 391 10E- 4EC up_10 clrb VQ ;clear VQ if V clear and VQ set
- 392 10F- B11 jmp uback2
- 393 110- 000 uback1 nop
- 394 111- 000 uback2 nop
- 395 112- 20C 026 uback3 mov RB,RBbuf ;use Port buffer to prevent read from Port
- 396 114- 272 2B2 neg byte2
- 397
- 398
- 399
- 400 116- 2E9 A90 done djnz loopcnt,x_axe
- 401 118- 800 ret
-
-
- ===== Errors: 0 =====
-