Safely tests a real IMSAI MIO's serial port and finds the settings MIO.COM needs.
Written by Sarah Craswell while writing and debugging Zimul80r
MIOTEST watches the MIO's ports without disturbing the console, shows which status bits change as characters come and go, scans wider for ready bits the defaults miss, and sweeps the control port to find TRDY. It was used to track down a fault on a real IMSAI, which turned out to be a memory card answering I/O reads.
Using it
A>MIOTEST watch the MIO at 40H-43H
A>MIOTEST 10 watch 10H-13H
MIOTEST.ASM
996 LINES
; MIOTEST.ASM - safely test an IMSAI MIO serial port and find the settings; MIO.COM needs on a real board.;; MIOTEST watches the MIO at ports 40H-43H; MIOTEST 10 watches 10H-13H, and so on;; Run it from the normal console, without MIO installed. It never reads the; serial data port by itself except once each time the chosen RRDY bit becomes; active: an unconditional read clears RRDY and pulses the UART's receive; enable, which hides the very bit being looked for.;; It watches the other three ports of the group and prints them whenever any of; them changes. Type one character on the terminal at the MIO's serial; connector: the bit that changes and STAYS changed is RRDY (the UART keeps it; until the data port is read; press X to read it). If no port changes, the; Input Jumper Area doesn't carry RRDY to the control port.;; Keys on the normal console:; 0-3 write "M" to port base+0..3 again and again for about 20 ms,; reading the other ports between writes, and show them before, at; once and 20 ms after, with every bit that changed at any time: the; bit that drops or rises while characters go out is TRDY. One; character alone would show TBMT for only a bit time, until it moves; into the shift register; writing faster than the line keeps the; holding register full. A few Ms appear on the MIO terminal. Use it; only on the serial data port: the others are the cassette, parallel; and control ports.; S choose the status port for RRDY (default base+3); D choose the serial data port (default base+2); R choose the RRDY bit and polarity (default bit 1, active high); X read the serial data port once now; W wide receive scan: read every port 00-FF (except the data port),; ask for one character on the MIO terminal, read them all again and; list each bit that changed. Bits that change by themselves are left; out. This finds RRDY wherever it reaches the bus.; T wide transmit scan: the same, comparing every port while idle with; every port while Ms are written to the data port faster than they; can go out (so TBMT stays low). This finds TRDY.; K control-port sweep: write each value 00-FF to the status (control); port, then compare the status port idle with the status port while; Ms are sent, in case a control bit has to be set before TRDY and; RRDY reach the status port. Lists each value that shows a change,; and the status port with each single control bit set. Writes 00; to the control port at the end.; C for a scope: write "M" to the data port about every 2 ms, and read; the status port after each write, until another key is pressed; any other key ends the test.;; Then: MIO S=status D=data T=bit R=bit, with a - after a bit that is low; when ready (e.g. MIO S=43 D=42 T=0 R=1, or T=7- R=6-).;; Assemble with: python tools\asm8080\asm8080.py tools\mio\MIOTEST.ASMBDOS EQU 5CONOUT EQU 2PRINT EQU 9CONST EQU 11CONIN EQU 1 ORG 100HSTART: CALL GETBASE LXI D,USAGE JC SAY STA PBASE ADI 2 STA DATAP INR A STA STATP LXI D,HELLO CALL PSTR CALL REFRESHWATCH: MVI C,CONST ; a key on the normal console? CALL BDOS ORA A JNZ KEY CALL READ4 ; the non-data ports; never the data port CALL SAME4 JZ WCHK CALL SHOW4 LXI H,NEWV LXI D,LASTV CALL COPY4WCHK: CALL RXACT ; read the data port once when RRDY becomes ORA A ; active, not while it stays active JZ WIDLE LDA PREV ORA A JNZ WATCH CALL GETRX CALL SETPREV JMP WATCHWIDLE: STA PREV JMP WATCHKEY: MVI C,CONIN CALL BDOS SUI '0' ; 0-3 send a test character CPI 4 JC KSEND ADI '0' ANI 5FH ; upper case CPI 'S' JZ SETST CPI 'D' JZ SETDT CPI 'R' JZ SETRDY CPI 'X' JZ READX CPI 'C' JZ SCOPE CPI 'W' JZ WIDERX CPI 'T' JZ WIDETX CPI 'K' JZ KSWEEP JMP DONEKSEND: CALL SENDTST JMP WATCHDONE: LXI D,BYESAY: MVI C,PRINT JMP BDOSREADX: LXI D,CRLF CALL PSTR CALL GETRX CALL SETPREV JMP WATCH; Write M to the data port about every 2 ms and read the status port after; each write, until a key: a steady signal to trigger a scope on.SCOPE: LXI D,SCOPEMSG CALL PSTR LDA DATAP STA SCOUT+1 LDA STATP STA SCIN+1SCLOOP: MVI A,'M'SCOUT: OUT 0SCIN: IN 0 LXI B,160 ; about 2 ms at 2 MHz with the BDOS callSCDLY: DCX B MOV A,B ORA C JNZ SCDLY MVI C,CONST CALL BDOS ORA A JZ SCLOOP MVI C,CONIN ; swallow the key that stopped it CALL BDOS CALL REFRESH JMP WATCH; Wide receive scan: every port before and after one character arrives.WIDERX: LXI D,WRXMSG1 CALL PSTR CALL CLRUNS LXI D,SNA CALL SNAP CALL IDLECHK LXI D,WRXMSG2 CALL PSTR MVI C,CONIN CALL BDOS LXI D,SNB CALL SNAP LXI D,WRXMSG3 CALL REPORT CALL REFRESH JMP WATCH; Wide transmit scan: every port while idle, then while Ms keep the UART busy.WIDETX: LXI D,WTXMSG1 CALL PSTR CALL CLRUNS LXI D,SNA CALL SNAP CALL IDLECHK LDA DATAP STA WOUT+1 MVI A,'M' ; the first M goes straight into the shift CALL WOUT ; register; the next ones keep the holding LXI B,40 ; register fullWTDLY: DCX B MOV A,B ORA C JNZ WTDLY LXI D,SNB MVI C,0WTLOOP: LDA DATAP CMP C MVI A,0 JZ WTSAVE MVI A,'M' CALL WOUT MOV A,C STA SNIN+1 CALL SNINWTSAVE: STAX D INX D INR C JNZ WTLOOP LXI D,WTXMSG2 CALL REPORT CALL REFRESH JMP WATCHWOUT: OUT 0 RET; Control-port sweep: for each value written to the control port, the status; port idle (ANDed into IAND, ORed into IOR) and while sending (BAND, BOR).KSWEEP: LXI D,KMSG1 CALL PSTR LDA STATP STA KOUT+1 STA KIN+1 LDA DATAP STA KDOUT+1 XRA A STA CTLVKLOOP: LDA CTLV CALL KOUT LXI B,200 ; about 2 ms to settle CALL DELAYBC CALL KIN STA IAND STA IOR MVI A,8 STA COUNTKI1: CALL KIN MOV B,A LDA IAND ANA B STA IAND LDA IOR ORA B STA IOR LDA COUNT DCR A STA COUNT JNZ KI1 MVI A,'M' ; into the shift register... CALL KDOUT LXI B,40 CALL DELAYBC MVI A,'M' ; ...and keep the holding register full CALL KDOUT CALL KIN STA BAND STA BOR MVI A,16 STA COUNTKB1: MVI A,'M' CALL KDOUT CALL KIN MOV B,A LDA BAND ANA B STA BAND LDA BOR ORA B STA BOR LDA COUNT DCR A STA COUNT JNZ KB1 LDA IOR ; bits steady while idle that differ MOV B,A ; while sending LDA BOR XRA B MOV C,A LDA IAND MOV B,A LDA BAND XRA B ORA C MOV C,A LDA IAND MOV B,A LDA IOR XRA B CMA ANA C STA CURV JNZ KPRINT LDA CTLV ; also show 00 and each single bit MOV B,A DCR A ANA B JNZ KNEXTKPRINT: LXI D,KMSG2 CALL PSTR LDA CTLV CALL PHEX LXI D,KMSG3 CALL PSTR LDA IAND CALL PBIN LDA CURV ORA A JZ KPEND LXI D,KMSG4 CALL PSTR LDA CURV CALL PBIN LXI D,KMSG5 CALL PSTRKPEND: LXI D,CRLF CALL PSTRKNEXT: LXI B,1700 ; about 20 ms for the Ms to go out CALL DELAYBC LDA CTLV INR A STA CTLV JNZ KLOOP XRA A CALL KOUT LXI D,KMSG6 CALL PSTR CALL REFRESH JMP WATCHKOUT: OUT 0 RETKDOUT: OUT 0 RETKIN: IN 0 RET; Wait BC x 24 cycles (12 us at 2 MHz).DELAYBC:DCX B MOV A,B ORA C JNZ DELAYBC RETSNIN: IN 0 RET; Read every port again five times over about half a second, against SNA,; to find the bits that change by themselves.IDLECHK:MVI A,5 STA COUNTIC1: LXI B,8000 ; about 0.1 s at 2 MHzIC2: DCX B MOV A,B ORA C JNZ IC2 LXI D,SNA CALL SNAPCHK LDA COUNT DCR A STA COUNT JNZ IC1 RET; Clear the "changes by itself" bits.CLRUNS: LXI H,UNS MVI B,0CU1: MVI M,0 INX H DCR B JNZ CU1 RET; Read every port but the data port four times into the 256 bytes at DE,; adding any bit that differs between the readings to UNS.SNAP: MVI C,0SNLOOP: LDA DATAP CMP C JZ SNDATA MOV A,C STA SNIN+1 CALL SNIN MOV B,A MVI L,0 MVI H,3SNR: CALL SNIN XRA B ORA L MOV L,A DCR H JNZ SNR MOV A,B STAX D CALL ADDUNS JMP SNNEXTSNDATA: XRA A STAX DSNNEXT: INX D INR C JNZ SNLOOP RET; Read every port but the data port once more and add any bit that differs; from the 256 bytes at DE to UNS.SNAPCHK:MVI C,0SCLOOP: LDA DATAP CMP C JZ SCNEXT MOV A,C STA SNIN+1 CALL SNIN XCHG XRA M XCHG MOV L,A CALL ADDUNSSCNEXT: INX D INR C JNZ SCLOOP RET; UNS[C] = UNS[C] OR L. Keeps C and DE.ADDUNS: PUSH D MOV E,C MVI D,0 MOV A,L LXI H,UNS DAD D ORA M MOV M,A POP D RET; Print the heading at DE, then each port with bits that differ between SNA; and SNB (leaving out UNS), or that none did.REPORT: CALL PSTR XRA A STA PORTN STA FOUNDRPLOOP: LXI H,SNA CALL GETP MOV B,A LXI H,SNB CALL GETP XRA B MOV B,A LXI H,UNS CALL GETP CMA ANA B JZ RPNEXT STA CURV STA FOUND LXI D,SP2 CALL PSTR LDA PORTN CALL PHEX LXI D,RPMSG1 CALL PSTR LXI H,SNA CALL GETP CALL PBIN LXI D,RPMSG2 CALL PSTR LXI H,SNB CALL GETP CALL PBIN LXI D,RPMSG3 CALL PSTR LDA CURV CALL PBIN LXI D,CRLF CALL PSTRRPNEXT: LDA PORTN INR A STA PORTN JNZ RPLOOP LDA FOUND ORA A RNZ LXI D,RPNONE JMP PSTR; A = the byte at HL + PORTN.GETP: LDA PORTN MOV E,A MVI D,0 DAD D MOV A,M RET; Ask which port number (0-3 within the group) is the status port.SETST: LXI D,ASKST CALL ASKPORT JNC WATCH STA STATP CALL REFRESH JMP WATCH; Ask which port number (0-3 within the group) is the UART data port.SETDT: LXI D,ASKDT CALL ASKPORT JNC WATCH STA DATAP CALL REFRESH JMP WATCH; Print the question at DE and read 0-3: carry set and A = the port, or carry; clear if the answer wasn't 0-3.ASKPORT:CALL PSTR MVI C,CONIN CALL BDOS SUI '0' CPI 4 RNC MOV B,A LDA PBASE ADD B STC RET; Ask for the RRDY bit and whether it is active high (+) or active low (-).SETRDY: LXI D,ASKRB CALL PSTR MVI C,CONIN CALL BDOS SUI '0' CPI 8 JNC WATCH STA RBIT MOV B,A ORA A MVI A,1 JZ SRMASKSRLOOP: RLC DCR B JNZ SRLOOPSRMASK: STA RMASK LXI D,ASKRP CALL PSTR MVI C,CONIN CALL BDOS MVI B,0 CPI '-' JNZ SRPOL DCR B ; FF means invert status before testing itSRPOL: MOV A,B STA RINV CALL REFRESH JMP WATCH; Show the settings and the ports as they are now. A bit that is already; active doesn't count as a new character (X reads one that is waiting).REFRESH:LXI D,CRLF CALL PSTR CALL SHOWCFG CALL READ4 CALL SHOW4 LXI H,NEWV LXI D,LASTV CALL COPY4SETPREV:CALL READ4 CALL RXACT STA PREV RET; Read the four ports into NEWV, leaving out the data port (it reads as 0).READ4: LXI H,NEWV LDA PBASE MOV C,A MVI B,4R4LOOP: LDA DATAP CMP C MVI A,0 JZ R4SAVE MOV A,C STA R4IN+1R4IN: IN 0R4SAVE: MOV M,A INX H INR C DCR B JNZ R4LOOP RET; Zero flag set if NEWV and LASTV are the same.SAME4: LXI H,NEWV LXI D,LASTV MVI B,4SM1: LDAX D CMP M RNZ INX H INX D DCR B JNZ SM1 RET; Copy four bytes from HL to DE.COPY4: MVI B,4CP1: MOV A,M STAX D INX H INX D DCR B JNZ CP1 RET; A = nonzero if the chosen RRDY bit is active in NEWV.RXACT: LDA PBASE MOV B,A LDA STATP SUB B MOV E,A MVI D,0 LXI H,NEWV DAD D LDA RINV XRA M MOV B,A LDA RMASK ANA B RET; Read the data port once and show what it held.GETRX: LDA DATAP STA GRIN+1GRIN: IN 0 STA RXBYTE LXI D,RXMSG1 CALL PSTR LDA DATAP CALL PHEX LXI D,RXMSG2 CALL PSTR LDA RXBYTE CALL PHEX MVI E,'H' CALL PCHR LDA RXBYTE CPI ' ' JC GREND CPI 7FH JNC GREND LXI D,QUOTE CALL PSTR LDA RXBYTE MOV E,A CALL PCHR MVI E,27H CALL PCHRGREND: LXI D,CRLF JMP PSTR; IDX = 0-3: CURP = that port, and zero flag set if it is the data port.ISDATA: LDA IDX MOV B,A LDA PBASE ADD B STA CURP MOV B,A LDA DATAP CMP B RET; A = the byte at HL + IDX.GETIDX: LDA IDX MOV E,A MVI D,0 DAD D MOV A,M RET; Print the non-data ports in NEWV: "40=EE/11101110 41=00/00000000 ..."SHOW4: XRA A STA IDXS4LOOP: CALL ISDATA JZ S4NEXT LDA CURP CALL PHEX MVI E,'=' CALL PCHR LXI H,NEWV CALL GETIDX STA CURV CALL PHEX MVI E,'/' CALL PCHR LDA CURV CALL PBIN LXI D,SP2 CALL PSTRS4NEXT: LDA IDX INR A STA IDX CPI 4 JNZ S4LOOP LXI D,CRLF JMP PSTRSHOWCFG:LXI D,CFG1 CALL PSTR LDA DATAP CALL PHEX LXI D,CFG2 CALL PSTR LDA STATP CALL PHEX LXI D,CFG3 CALL PSTR LDA RBIT ADI '0' MOV E,A CALL PCHR LDA RINV ORA A LXI D,CFGHIGH JZ CFGEND LXI D,CFGLOWCFGEND: JMP PSTR; A = port offset 0-3: send Ms there for 20 ms and show the other ports.SENDTST:MOV B,A LDA PBASE ADD B STA OUTP+1 STA OUTP2+1 CALL READ4 LXI H,NEWV LXI D,BEFV CALL COPY4 LXI H,NEWV LXI D,ORV CALL COPY4 LXI H,NEWV LXI D,ANDV CALL COPY4 MVI A,'M'OUTP: OUT 0 CALL READ4 CALL ACCUM LXI H,NEWV LXI D,DURV CALL COPY4 MVI A,50 ; about 20 ms of writes and readings at 2 MHz STA COUNTSLOOP: MVI A,'M'OUTP2: OUT 0 CALL READ4 CALL ACCUM LDA COUNT DCR A STA COUNT JNZ SLOOP LXI B,2000 ; about 20 ms more, then the last readingDLY: DCX B MOV A,B ORA C JNZ DLY CALL READ4 CALL ACCUM LXI H,NEWV LXI D,AFTV CALL COPY4 LXI D,SENT1 CALL PSTR LDA OUTP+1 CALL PHEX LXI D,SENT2 CALL PSTR XRA A STA IDXSTLOOP: CALL ISDATA JZ STNEXT LXI D,SP2 CALL PSTR LDA CURP CALL PHEX LXI D,SENT3 CALL PSTR LXI H,BEFV CALL GETIDX CALL PBIN LXI D,SP2 CALL PSTR LXI H,DURV CALL GETIDX CALL PBIN LXI D,SP2 CALL PSTR LXI H,AFTV CALL GETIDX CALL PBIN LXI D,SP2 CALL PSTR LXI H,ORV ; the bits that were 1 and 0 at some point CALL GETIDX MOV B,A LXI H,ANDV CALL GETIDX XRA B CALL PBIN LXI D,CRLF CALL PSTRSTNEXT: LDA IDX INR A STA IDX CPI 4 JNZ STLOOP RET; OR NEWV into ORV and AND it into ANDV.ACCUM: LXI H,NEWV LXI D,ORV MVI B,4AC1: LDAX D ORA M STAX D INX H INX D DCR B JNZ AC1 LXI H,NEWV LXI D,ANDV MVI B,4AC2: LDAX D ANA M STAX D INX H INX D DCR B JNZ AC2 RET; Print A as eight binary digits, bit 7 first.PBIN: MVI B,8PB1: RLC PUSH PSW PUSH B MVI E,'0' JNC PB2 MVI E,'1'PB2: CALL PCHR POP B POP PSW DCR B JNZ PB1 RETPCHR: MVI C,CONOUT JMP BDOSPSTR: MVI C,PRINT JMP BDOSPHEX: PUSH PSW RRC RRC RRC RRC CALL PNIB POP PSWPNIB: ANI 0FH ADI 90H DAA ACI 40H DAA MOV E,A JMP PCHR; The base port from the command tail ("40", "40H"), or 40H if there is none.; It is rounded down to a multiple of 4. Carry set if it isn't hex.GETBASE:LXI H,80H MOV B,M INX H LXI D,0 ; D = the number, E = 1 once a digit is seenGB1: MOV A,B ORA A JZ GBEND MOV A,M INX H DCR B CPI ' ' JZ GB1 CPI 'H' JZ GBEND SUI '0' RC CPI 10 JC GB2 SUI 'A'-'0'-10 CPI 10 RC CPI 16 CMC RCGB2: MOV C,A MOV A,D RLC RLC RLC RLC ANI 0F0H ORA C MOV D,A MVI E,1 ; a digit was seen JMP GB1GBEND: MOV A,E CPI 1 MOV A,D JZ GB3 MVI A,40H ; none givenGB3: ANI 0FCH ORA A ; clear carry RETPBASE: DB 40HDATAP: DB 42HSTATP: DB 43HRMASK: DB 2RINV: DB 0RBIT: DB 1PREV: DB 0RXBYTE: DB 0IDX: DB 0CURP: DB 0CURV: DB 0NEWV: DB 0,0,0,0LASTV: DB 0,0,0,0BEFV: DB 0,0,0,0DURV: DB 0,0,0,0AFTV: DB 0,0,0,0ORV: DB 0,0,0,0ANDV: DB 0,0,0,0COUNT: DB 0PORTN: DB 0FOUND: DB 0CTLV: DB 0IAND: DB 0IOR: DB 0BAND: DB 0BOR: DB 0HELLO: DB 'MIOTEST: safe IMSAI MIO UART receive and transmit test.',13,10 DB 'Type on the terminal at the MIO serial connector. Sarah',13,10 DB 'messed this up first time.',13,10 DB 'The other ports print when they change; a bit that changes',13,10 DB 'and stays changed when you type is RRDY.',13,10 DB 'Keys: 0-3 send Ms; S=status port; D=data port; R=RRDY bit;',13,10 DB 'X=read data port; W/T=scan all ports for RRDY/TRDY;',13,10 DB 'K=try every control port value; C=Ms for a scope;',13,10 DB 'any other key ends.',13,10,'$'ASKST: DB 13,10,'Status port is base + (0-3)? $'ASKDT: DB 13,10,'Serial data port is base + (0-3)? $'ASKRB: DB 13,10,'RRDY bit (0-7)? $'ASKRP: DB ' Ready polarity (+ high, - low)? $'CFG1: DB 'Data port $'CFG2: DB 'H, status $'CFG3: DB 'H, RRDY bit $'CFGHIGH:DB ' high.',13,10,'$'CFGLOW: DB ' low.',13,10,'$'RXMSG1: DB 'Data port $'RXMSG2: DB 'H read $'QUOTE: DB ' ',27H,'$'SENT1: DB 13,10,'Sent Ms to $'SENT2: DB 'H:',13,10,' before at once 20 ms on ever changed',13,10,'$'SENT3: DB 'H: $'SP2: DB ' $'SCOPEMSG:DB 13,10,'Writing M to the data port about every 2 ms; a key stops it.',13,10,'$'WRXMSG1:DB 13,10,'Wide receive scan: reading ports 00-FF.',13,10,'$'WRXMSG2:DB 'Type ONE character on the MIO terminal, then press a key here.',13,10,'$'WRXMSG3:DB 'Bits that changed when the character arrived:',13,10,'$'WTXMSG1:DB 13,10,'Wide transmit scan: reading ports 00-FF idle, then while sending.',13,10,'$'WTXMSG2:DB 'Bits that changed while sending:',13,10,'$'KMSG1: DB 13,10,'Control-port sweep: writing 00-FF to the status port.',13,10,'$'KMSG2: DB ' control $'KMSG3: DB 'H: status $'KMSG4: DB ' changes $'KMSG5: DB ' while sending$'KMSG6: DB 'Control port set back to 00.',13,10,'$'RPMSG1: DB 'H: before $'RPMSG2: DB ' after $'RPMSG3: DB ' changed $'RPNONE: DB ' none (outside bits that change by themselves).',13,10,'$'USAGE: DB 'Usage: MIOTEST [base port], e.g. MIOTEST 40',13,10,'$'BYE: DB 13,10,'MIOTEST done.',13,10,'$'CRLF: DB 13,10,'$'; Three 256-byte tables past the end of the program (not in the file). The; EQUs follow the label: asm8080 keeps an EQU's first-pass value.BUFFERS:SNA EQU BUFFERS ; every port: beforeSNB EQU BUFFERS+256 ; every port: afterUNS EQU BUFFERS+512 ; bits that changed by themselves END