; PORTSCAN.ASM - finds which input port a parallel keyboard is on. ; ; Reads all 256 input ports, lists the ones that answer (read something other ; than FF) and the ones that change by themselves (they are ignored after ; that), then prints every change on the others while you press keys. A ; keyboard's data port shows the key codes; its status port the bit that ; flips. Any key on the serial terminal ends it. ; ; It only reads ports. On a UART, reading the data port can drop a received ; character, so don't type on the serial terminal while it starts up. ; ; Assemble with: python tools\asm8080\asm8080.py tools\vti\PORTSCAN.ASM BDOS EQU 5 CONOUT EQU 2 PRINT EQU 9 CONST EQU 11 LAST EQU 1000H ; last value read from each port NEW EQU 1100H ; a second reading, while calibrating NOISY EQU 1200H ; 1 = changes by itself, ignored PASSES EQU 200 ; calibration passes (about a second at 2 MHz) ORG 100H START: LXI D,HELLO CALL PSTR LXI H,NOISY ; nothing is noisy yet XRA A CLR: MOV M,A INR L JNZ CLR MVI H,HIGH LAST CALL SNAP MVI B,PASSES ; watch for ports that change by themselves CAL: PUSH B MVI H,HIGH NEW CALL SNAP MVI C,0 CAL1: MOV L,C MVI H,HIGH LAST MOV A,M MVI H,HIGH NEW CMP M JZ CAL2 MVI H,HIGH NOISY MVI M,1 CAL2: INR C JNZ CAL1 POP B DCR B JNZ CAL LXI D,ANSWER ; ports that answer CALL PSTR MVI C,0 REP1: MOV L,C MVI H,HIGH NOISY MOV A,M ORA A JNZ REP2 MVI H,HIGH LAST MOV A,M CPI 0FFH JZ REP2 CALL PAIR REP2: INR C JNZ REP1 LXI D,NOISE ; ports that change by themselves CALL PSTR MVI C,0 REP3: MOV L,C MVI H,HIGH NOISY MOV A,M ORA A JZ REP4 MVI H,HIGH LAST CALL PAIR REP4: INR C JNZ REP3 LXI D,GO CALL PSTR WATCH: MVI C,CONST ; a serial key ends it CALL BDOS ORA A JNZ QUIT MVI C,0 W1: MOV L,C MVI H,HIGH NOISY MOV A,M ORA A JNZ W2 MOV A,C CALL INPORT MOV L,C MVI H,HIGH LAST CMP M JZ W2 MOV B,M ; B = old value, A = new MOV M,A STA NEWV MOV A,B STA OLDV MOV A,C STA PORTV LXI D,PORT1 ; "port xx: aa -> bb" CALL PSTR LDA PORTV CALL PHEX LXI D,PORT2 CALL PSTR LDA OLDV CALL PHEX LXI D,PORT3 CALL PSTR LDA NEWV CALL PHEX LXI D,CRLF CALL PSTR LDA PORTV MOV C,A W2: INR C JNZ W1 JMP WATCH QUIT: MVI C,1 ; take the key that ended it CALL BDOS LXI D,BYE CALL PSTR JMP 0 ; SNAP: reads every port into the table at page H. SNAP: MVI L,0 SN1: MOV A,L CALL INPORT MOV M,A INR L JNZ SN1 RET ; INPORT: A = IN (port A). The IN instruction is patched with the port. INPORT: STA INP+1 INP: IN 0 RET ; PAIR: prints "xx=yy " for port C, value M; keeps C. PAIR: MOV A,M STA NEWV MOV A,C STA PORTV CALL PHEX MVI E,'=' MVI C,CONOUT CALL BDOS LDA NEWV CALL PHEX MVI E,' ' MVI C,CONOUT CALL BDOS LDA PORTV MOV C,A RET PSTR: MVI C,PRINT JMP BDOS ; PHEX: prints A as two hex digits. PHEX: PUSH PSW RRC RRC RRC RRC CALL PNIB POP PSW PNIB: ANI 0FH ADI 90H DAA ACI 40H DAA MOV E,A MVI C,CONOUT JMP BDOS PORTV: DB 0 OLDV: DB 0 NEWV: DB 0 HELLO: DB 'PORTSCAN: reading all input ports; leave the keyboards alone for a second...',13,10,'$' ANSWER: DB 'Ports that answer (port=value, FF not shown):',13,10,'$' NOISE: DB 13,10,'Ports that change by themselves (ignored):',13,10,'$' GO: DB 13,10,'Now press keys on the VTI keyboard; any serial key ends it.',13,10,'$' PORT1: DB 'port $' PORT2: DB ': $' PORT3: DB ' -> $' CRLF: DB 13,10,'$' BYE: DB 'PORTSCAN done.',13,10,'$' END