📄 ps2code.lst
字号:
0033 3001 00187 movlw 0x01
0034 00B0 00188 movwf LENGTH
0035 2001 00189 call BATdelay
0036 1283 00190 bcf STATUS,RP0
0037 2860 00191 goto PacketOut ;Output 2-byte "completion-code, device ID" packet
00192
00193 ;---------------------------------------------------------------------------------------------
00194 ; Stream/Remote Mode:
00195 ;---------------------------------------------------------------------------------------------
0038 1D05 00196 MainLoop btfss DATA
0039 2870 00197 goto PacketIn
003A 1507 00198 bsf PORTC,2
003B 2085 00199 call ReadInputs
003C 0825 00200 movf OLDKEYCODE, w
003D 0626 00201 xorwf NEWKEYCODE ,w
003E 1903 00202 btfsc STATUS, Z
003F 2838 00203 goto MainLoop
0040 2841 00204 goto Report
00205
00206
00207 ;---------------------------------------------------------------------------------------------
00208 ; REPORT:
00209 ;---------------------------------------------------------------------------------------------
00210
0041 1407 00211 Report bsf PORTC,0
0042 0825 00212 movf OLDKEYCODE,w
0043 39FF 00213 andlw 0xff
0044 1D03 00214 btfss STATUS,Z
0045 2847 00215 goto KeyBreak
0046 2851 00216 goto KeyMake
0047 30F0 00217 KeyBreak movlw 0xf0
0048 00B1 00218 movwf SEND1
0049 0825 00219 movf OLDKEYCODE,w
004A 205D 00220 call Label
004B 00B2 00221 movwf SEND2
004C 3002 00222 movlw 0x02 ;Movement data report length
004D 00B0 00223 movwf LENGTH
004E 3000 00224 movlw 0x00
004F 00A5 00225 movwf OLDKEYCODE
0050 2860 00226 goto PacketOut
0051 0826 00227 KeyMake movf NEWKEYCODE,w
0052 39FF 00228 andlw 0xff
0053 1903 00229 btfsc STATUS,Z
0054 2838 00230 goto MainLoop
0055 0826 00231 movf NEWKEYCODE,w
0056 205D 00232 call Label
0057 00B1 00233 movwf SEND1
MPASM 03.20.02 Released PS2CODE.ASM 6-30-2004 14:27:07 PAGE 6
PS/2 Keyboard Emulator
Copyright 2001, Adam Chapweske
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
0058 3001 00234 movlw 0x01 ;Movement data report length
0059 00B0 00235 movwf LENGTH
005A 0826 00236 movf NEWKEYCODE,w
005B 00A5 00237 movwf OLDKEYCODE
005C 2860 00238 goto PacketOut
00239
005D 0782 00240 Label addwf PCL
005E 3445 00241 retlw 0x45
005F 3446 00242 retlw 0x46
00243
00244 ;---------------------------------------------------------------------------------------------
00245 ; OUTPUT PACKET
00246 ;---------------------------------------------------------------------------------------------
00247
0060 3031 00248 PacketOut movlw SEND1 ;First byte of packet
0061 0084 00249 movwf FSR
0062 0830 00250 movf LENGTH, w ;Length of packet
0063 00A1 00251 movwf TEMP1
0064 0800 00252 PacketOutLoop movf INDF, w ;Get data byte
0065 2099 00253 call ByteOut ; Output that byte
0066 3AFF 00254 xorlw 0xFF ;Test for RTS error
0067 1903 2870 00255 bz PacketIn
0069 3A01 00256 xorlw 0xFE ^ 0xFF ;Test for inhibit error
006A 1903 2860 00257 bz PacketOut
006C 0A84 00258 incf FSR, f ;Point to next byte
006D 0BA1 00259 decfsz TEMP1, f
006E 2864 00260 goto PacketOutLoop
006F 2838 00261 goto MainLoop
00262
00263 ;---------------------------------------------------------------------------------------------
00264 ; READ PACKET
00265 ;---------------------------------------------------------------------------------------------
00266
0070 00267 PacketIn
0070 20D8 00268 call ByteIn
0071 3AFF 00269 xorlw 0xFF ;Test for parity/framing error
0072 1903 288A 00270 bz KeyBd_ERR
0074 3A01 00271 xorlw 0xFE ^ 0xFF ;Test for inhibit error
0075 1903 2838 00272 bz MainLoop
0077 30FE 00273 movlw 0xFE ;Test for "Resend" command
0078 0622 00274 xorwf RECEIVE, w
0079 1903 2860 00275 bz PacketOut
007B 30EE 00276 movlw 0xEE
007C 0622 00277 xorwf RECEIVE,w
007D 1D03 00278 btfss STATUS,Z
007E 2882 00279 goto Acknowledge
007F 30EE 00280 movlw 0xEE
0080 2099 00281 call ByteOut
0081 2838 00282 goto MainLoop
0082 30FA 00283 Acknowledge movlw 0xFA ;Acknowledge
0083 2099 00284 call ByteOut
0084 280B 00285 goto Command
00286 ;---------------------------------------------------------------------------------------------
MPASM 03.20.02 Released PS2CODE.ASM 6-30-2004 14:27:07 PAGE 7
PS/2 Keyboard Emulator
Copyright 2001, Adam Chapweske
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
00287 ; READ INPUTS:
00288 ;---------------------------------------------------------------------------------------------
00289
0085 3000 00290 ReadInputs movlw 0x00
0086 1806 00291 btfsc KEY
0087 3001 00292 movlw 0x01
0088 00A6 00293 movwf NEWKEYCODE
0089 0008 00294 return
00295
00296 ;---------------------------------------------------------------------------------------------
00297 ; HANDLE COMMANDS:
00298 ;---------------------------------------------------------------------------------------------
00299
00300
00301 ;Invalid command
008A 30FE 00302 KeyBd_ERR movlw 0xFE
008B 2099 00303 call ByteOut
008C 1487 00304 bsf PORTC,1
008D 2838 00305 goto MainLoop
00306
008E 30EE 00307 KeyBd_EE movlw 0xEE
008F 2099 00308 call ByteOut
0090 2838 00309 goto MainLoop
00310
0091 30AB 00311 KeyBd_F2 movlw 0xAB
0092 00B1 00312 movwf SEND1
0093 3083 00313 movlw 0x83
0094 00B2 00314 movwf SEND2
0095 3002 00315 movlw 0x02
0096 00B0 00316 movwf LENGTH
0097 2860 00317 goto PacketOut
00318
0098 2838 00319 KeyBd_F4 goto MainLoop
00320
00321 ;---------------------------------------------------------------------------------------------
00322 ; OUTPUT ONE BYTE: - TIMING IS CRITICAL!!!
00323 ;---------------------------------------------------------------------------------------------
00324
0099 00A0 00325 ByteOut movwf TEMP0
009A 1D85 00326 InhibitLoop btfss CLOCK ;Test for inhibit
009B 289A 00327 goto InhibitLoop
00328 Delay 100 ;(50 microsec = 58 clock cycles, min)
M if (100==1)
M nop
M exitm
M endif
M if (100==2)
M goto $ + 1
M exitm
M endif
M if (100==3)
M nop
M goto $ + 1
MPASM 03.20.02 Released PS2CODE.ASM 6-30-2004 14:27:07 PAGE 8
PS/2 Keyboard Emulator
Copyright 2001, Adam Chapweske
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
M exitm
M endif
M if (100==4)
M goto $ + 1
M goto $ + 1
M exitm
M endif
M if (100==5)
M goto $ + 1
M goto $ + 1
M nop
M exitm
M endif
M if (100==6)
M goto $ + 1
M goto $ + 1
M goto $ + 1
M exitm
M endif
M if (100==7)
M goto $ + 1
M goto $ + 1
M goto $ + 1
M nop
M exitm
M endif
M if (100%4==0)
009C 3018 M movlw (100-4)/4
009D 2121 M call Delay_us
M exitm
009E 1D85 00329 btfss CLOCK
009F 289A 00330 goto InhibitLoop
00A0 1D05 00331 btfss DATA ;Check for request-to-send
00A1 34FF 00332 retlw 0xFF
00A2 01A3 00333 clrf PARITY
00A3 3008 00334 movlw 0x08
00A4 00A4 00335 movwf COUNTER
00A5 3000 00336 movlw 0x00
00A6 20C5 00337 call BitOut ;Start bit (0)
00A7 1D85 00338 btfss CLOCK ;Test for inhibit
00A8 28C0 00339 goto ByteOutEnd
00340 Delay 4
M if (4==1)
M nop
M exitm
M endif
M if (4==2)
M goto $ + 1
M exitm
M endif
M if (4==3)
M nop
M goto $ + 1
MPASM 03.20.02 Released PS2CODE.ASM 6-30-2004 14:27:07 PAGE 9
PS/2 Keyboard Emulator
Copyright 2001, Adam Chapweske
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
M exitm
M endif
M if (4==4)
00A9 28AA M goto $ + 1
00AA 28AB M goto $ + 1
M exitm
00AB 0820 00341 ByteOutLoop movf TEMP0, w
00AC 06A3 00342 xorwf PARITY, f
00AD 20C5 00343 call BitOut ;Data bits
00AE 1D85 00344 btfss CLOCK ;Test for inhibit
00AF 28C0 00345 goto ByteOutEnd
00B0 0CA0 00346 rrf TEMP0, f
00B1 0BA4 00347 decfsz COUNTER, f
00B2 28AB 00348 goto ByteOutLoop
00349 Delay 2
M if (2==1)
M nop
M exitm
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -