; CP/M for M100, T102, M200 ; ; CONIN Console In for M100, T102 ver 1.0 ; ; By Philip Avery 19-Nov-07 ; ; A CONIN routine for initial testing of CP/M M100. ; Essentially the required M100 ROM routines & tables have been extracted ; into this stand-alone routine. Uses no external memory locations, ; eg references to FFF#H are changed to locations at the end of this program. ; ; This is a 'polled' version whereas the ROM is interrupt driven. ; ROM code disassembly source: Steve Adolph. Assembled by: TASM ; ; Waits for keyboard input, then returns with the character in reg A. ; ; ; Version History: ; ; -------------------------------------------------------------- ; .org 55000 ; d6d8h Conin di call Scan ei lda 0FFAAH ora a jz Conin xra a sta 0FFAAH ; Zero buffer count lda 0FFABH ; Get char ret ; To BIOS Scan LXI H,RFF99H ; Keyboard scan column storage #1 Key detection -- Determine which keys are pressed LXI D,RFFA2H ; Keyboard scan column storage @2 CALL R72B1H ; Scan BREAK,CAPS,NUM,CODE,GRAPH,CTRL,SHIFT & set bits in A CMA CMP M MOV M,A CZ R7101H ; call if no soecial keys (GET COL) XRA A ; invert OUT 0B9H ; IN 0E8H INR A MVI A,0FFH OUT 0B9H ; No cols selected JZ R71FDH ; jmp if not key detected MVI A,7FH MVI C,07H R7080H DCX H ; DCX D ; MOV B,A ; OUT 0B9H ; get left most col IN 0E8H ; get keys CMA ; invert CMP M ; compair with (m) (dont know) MOV M,A ; save JNZ R7092H ; jmp if A was zero LDAX D ; A = (DE) CMP M ; compair with (m) (dont know) CNZ R70C5H ; call if not the same R7092H MVI A,0FFH ; OUT 0B9H ; no cols MOV A,B ; A = 7F RRC ; A = FE + C DCR C JP R7080H DCX H MVI M,02H LXI H,RFFA5H DCR M JZ R711AH INR M RM LDA RFFA7H LHLD RFFA8H ; Pointer to entry in 2nd Storage Buffer for key ANA M RZ ;============================================ ============================================ ;============================================ ============================================ LDA RFFAAH ; Keyboard buffer count Key repeat detection CPI 02H RNC LXI H,RFFA4H ; Key repeat start delay counter DCR M RNZ MVI M,06H MVI A,01H STA RFFF3H JMP R7122H ; Key decoding R70C5H PUSH B PUSH H PUSH D MOV B,A MVI A,80H MVI E,07H R70CDH MOV D,A ANA M JZ R70D6H ANA B JZ R70E2H R70D6H MOV A,D RRC DCR E JP R70CDH POP D R70DDH POP H MOV A,M STAX D POP B RET R70E2H LXI H,RFFA5H INR A CMP M JNZ R70EEH POP D POP H POP B RET R70EEH MOV M,A MOV A,C RLC RLC RLC ORA E INX H MOV M,A INX H MOV M,D POP D XCHG SHLD RFFA8H ; Pointer to entry in 2nd Storage Buffer for key XCHG JMP R70DDH R7101H LDAX D MOV B,A MOV A,M STAX D RLC RNC MOV A,B RLC RC XTHL LXI H,R71C4H XTHL MVI B,00H MOV D,B MOV A,M RRC MVI A,03H RC MVI A,13H RET R711AH DCX H MVI M,54H DCX H LDA RFFA2H ; Keyboard scan column storage @2 MOV M,A ;============================================ ============================================ ;============================================ ============================================ R7122H LDA RFFA6H ; Key position storage Key decoding MOV C,A LXI D,002CH MOV B,D CPI 33H JC R7133H LXI H,RFFA7H MOV M,B R7133H LDA RFFA3H ; Shift key status storage RRC PUSH PSW MOV A,C CMP E JC R7184H CPI 30H JNC R7148H POP PSW PUSH PSW RRC JC R7184H R7148H LXI H,R7CEFH POP PSW JNC R7152H LXI H,R7CDBH R7152H DAD B MOV A,M RLC ORA A RAR MOV C,A JNC R71E4H ; Keyboard buffer management - place subsequent key in buffer CPI 08H JNC R7180H LDA RF650H ANI 0E0H JNZ R7180H LHLD RF67AH ; Current executing line number MOV A,H ANA L INR A JZ R7180H LXI H,RF630H ; Function key status table (1 = on) DAD B MOV A,M ORA A JZ R7180H MOV A,C ORI 80H JMP R71D5H ; Keyboard buffer management - place key in new buffer R7180H DCR B JMP R71E4H ; Keyboard buffer management - place subsequent key in buffer R7184H POP PSW JC R7189H MOV E,B R7189H RRC PUSH PSW JC R720AH ; Handle unshifted & non-CTRL key during key decoding R718EH LXI H,R7C49H RRC JC R71B5H LXI H,R7CA1H RRC JC R71B5H RRC JNC R71AEH LXI H,R7BF1H DAD B PUSH D MOV D,A CALL R7233H ; Handle NUM key during key decoding MOV A,D POP D JZ R71B7H R71AEH RRC CC R722CH ; Handle CAPS LOCK key during key decoding LXI H,R7BF1H R71B5H DAD D R71B6H DAD B R71B7H POP PSW MOV A,M JNC R71C2H CPI 60H RNC ANI 3FH JNC R71C4H ; Expanded ROM's 'tricky' code R71C2H ORA A ; Expanded ROM's 'tricky' code RZ ; Expanded ROM's 'tricky' code R71C4H ret ; Got key - polled keyboard MOV C,A ANI 0EFH CPI 03H JNZ R71E4H ; Keyboard buffer management - place subsequent key in buffer LDA RF650H ANI 0C0H JNZ R71E4H ; Keyboard buffer management - place subsequent key in buffer MOV A,C ;============================================ ============================================ ;============================================ ============================================ R71D5H STA RFFEBH ; Keyboard buffer management - place key in new buffer CPI 03H RNZ LXI H,RFFAAH ; Keyboard buffer count MVI M,01H INX H JMP R71F0H ;============================================ ============================================ ;============================================ ============================================ R71E4H LXI H,RFFAAH ; Keyboard buffer count Keyboard buffer management - place subsequent key in buffer MOV A,M ; Adds a character to the keyboard buffer. CPI 20H RZ INR M RLC INX H MOV E,A DAD D R71F0H MOV M,C INX H MOV M,B ;============================================ ============================================ ;============================================ ============================================ R71F4H RET ;============================================ ============================================ ;============================================ ============================================ R71FDH LXI H,RFF90H DCR M RNZ LXI H,RFF91H MVI B,11H JMP R4F0AH ; Zero B bytes at M ;============================================ ============================================ ;============================================ ============================================ R720AH MOV A,C ; Handle unshifted & non-CTRL key during key decoding CPI 1AH LXI H,R7C1DH JC R71B6H CPI 2CH JC R721DH CPI 30H JC R7222H ; Handle Arrow keys during key decoding R721DH POP PSW PUSH PSW JMP R718EH ;============================================ ============================================ ;============================================ ============================================ R7222H SUI 2CH ; Handle Arrow keys during key decoding LXI H,R7D2FH MOV C,A DAD B JMP R71B7H ;============================================ ============================================ ;============================================ ============================================ R722CH MOV A,C ; Handle CAPS LOCK key during key decoding CPI 1AH RNC MVI E,2CH RET ;============================================ ============================================ ;============================================ ============================================ R7233H MOV A,M ; Handle NUM key during key decoding MVI E,06H LXI H,R7CF9H R7239H CMP M INX H RZ INX H DCR E JP R7239H RET ;============================================ ============================================ ;============================================ ============================================ ; CALL R765CH ; Set interrupt to 1DH Scan keyboard for character (CTRL-BREAK ==> CTRL-C) LDA RFFAAH ; Keyboard buffer count Gets key if any. Returns ASCII or 0. ORA A JZ R726AH ; Enable interrupts as normal LXI H,RFFACH MOV A,M ADI 02H DCX H MOV A,M PUSH PSW DCX H DCR M MOV A,M RLC MOV C,A INX H LXI D,RFFADH R725EH DCR C JM R7269H LDAX D MOV M,A INX H INX D JMP R725EH R7269H POP PSW ;============================================ ============================================ ;============================================ ============================================ R726AH PUSH PSW ; Enable interrupts as normal MVI A,09H SIM POP PSW RET ;============================================ ============================================ ;============================================ ============================================ CALL R7283H ; Check for break or wait (CTRL-S). Check keyboard queue for pending characters JZ R727EH CPI 03H JNZ R727EH ORA A STC RET R727EH LDA RFFAAH ; Keyboard buffer count ORA A RET ;============================================ ============================================ ;============================================ ============================================ R7283H PUSH H ; Check for break or wait (CTRL-S) LXI H,RFFEBH MOV A,M MVI M,00H POP H ORA A RP PUSH H PUSH B LXI H,RF7CAH MOV C,A MVI B,00H DAD B DAD B DAD B ; CALL R3FD2H ; Trigger interrupt. HL points to interrupt table POP B POP H XRA A RET ;============================================ ============================================ ;============================================ ============================================ PUSH B ; Check if SHIFT-BREAK is being pressed IN 0B9H MOV C,A CALL R72B1H ; Scan BREAK,CAPS,NUM,CODE,GRAPH,CTRL,SHIFT & set bits in A PUSH PSW MOV A,C OUT 0B9H POP PSW POP B ANI 81H RNZ STC RET ;============================================ ============================================ ;============================================ ============================================ R72B1H MVI A,0FFH ; Scan BREAK,CAPS,NUM,CODE,GRAPH,CTRL,SHIFT & set bits in A OUT 0B9H IN 0BAH ANI 0FEH MOV B,A OUT 0BAH IN 0E8H PUSH PSW MOV A,B INR A OUT 0BAH POP PSW RET ; -------------------------------------------------- ; Relocated routines & tables R4F0AH XRA A ; Zero bytes at M R4F0BH MOV M,A ; Load bytes at M with A INX H DCR B JNZ R4F0BH ; Load B bytes at M with A RET R7BF1H .DB 7AH,78H,63H,76H,62H,6EH,6DH,6CH ; Keyboard conversion matrix .DB 61H,73H,64H,66H,67H,68H,6AH,6BH .DB 71H,77H,65H,72H,74H,79H,75H,69H .DB 6FH,70H,5BH,3BH,27H,2CH,2EH,2FH .DB 31H,32H,33H,34H,35H,36H,37H,38H .DB 39H,30H,2DH,3DH R7C1DH .DB 5AH,58H,43H,56H .DB 42H,4EH,4DH,4CH,41H,53H,44H,46H .DB 47H,48H,4AH,4BH,51H,57H,45H,52H .DB 54H,59H,55H,49H,4FH,50H,5DH,3AH .DB 22H,3CH,3EH,3FH,21H,40H,23H,24H .DB 25H,5EH,26H,2AH,28H,29H,5FH,2BH R7C49H .DB 00H,83H,84H,00H,95H,96H,81H,9AH .DB 85H,8BH,00H,82H,00H,86H,00H,9BH .DB 93H,94H,8FH,89H,87H,90H,91H,8EH .DB 98H,80H,60H,92H,8CH,99H,97H,8AH .DB 88H,9CH,9DH,9EH,9FH,0B4H,0B0H,0A3H .DB 7BH,7DH,5CH,8DH,0E0H,0EFH,0FFH,00H .DB 00H,00H,0F6H,0F9H,0EBH,0ECH,0EDH,0EEH .DB 0FDH,0FBH,0F4H,0FAH,0E7H,0E8H,0E9H,0EAH .DB 0FCH,0FEH,0F0H,0F3H,0F2H,0F1H,7EH,0F5H .DB 00H,0F8H,0F7H,00H,0E1H,0E2H,0E3H,0E4H .DB 0E5H,0E6H,00H,00H,00H,00H,7CH,00H R7CA1H .DB 0CEH,0A1H,0A2H,0BDH,00H,0CDH,00H,0CAH .DB 0B6H,0A9H,0BBH,00H,00H,00H,0CBH,0C9H .DB 0C8H,00H,0C6H,00H,00H,0CCH,0B8H,0C7H .DB 0B7H,0ACH,0B5H,0ADH,0A0H,0BCH,0CFH,0AEH .DB 0C0H,00H,0C1H,00H,00H,00H,0C4H,0C2H .DB 0C3H,0AFH,0C5H,0BEH,00H,0DFH,0ABH,0DEH .DB 00H,00H,0A5H,0DAH,0B1H,0B9H,0D7H,0BFH .DB 00H,00H R7CDBH .DB 0DBH,0D9H,0D8H,00H,0D6H,0AAH .DB 0BAH,0DCH,0B3H,0D5H,0B2H,00H,00H,00H .DB 0A4H,0DDH,00H,00H,0D0H,00H R7CEFH .DB 0D1H,00H .DB 00H,00H,0D4H,0D2H,0D3H,0A6H,0A7H,0A8H R7CF9H .DB 6DH,30H,6AH,31H,6BH,32H,6CH,33H .DB 75H,34H,69H,35H,6FH,36H,01H,06H .DB 14H,02H,20H,7FH,09H,1BH,8BH,88H .DB 8AH,0DH,80H,81H,82H,83H,84H,85H .DB 86H,87H,1DH,1CH,1EH,1FH,20H,08H .DB 09H,1BH,8BH,88H,89H,0DH,80H,81H .DB 82H,83H,84H,85H,86H,87H R7D2FH .DB 51H,52H .DB 57H,5AH RF630H .DB 00H,00H,00H,00H,00H,00H,00H,00H RF650H .DB 00H RF654H .DB 00H RF67AH .DB 00H,00H RF7CAH .DB 00H ; Function key Def area? RFF8FH .DB 03H ; Counter (3-1) RFF90H .DB 00H RFF91H .DB 00H,00H,00H,00H,00H,00H,00H,00H RFF99H .DB 00H,00H,00H,00H,00H,00H,00H,00H,00H RFFA2H .DB 00H RFFA3H .DB 00H RFFA4H .DB 00H RFFA5H .DB 00H RFFA6H .DB 00H RFFA7H .DB 00H RFFA8H .DB 00H,00H RFFAAH .DB 00H RFFABH .DB 00H RFFACH .DB 00H RFFADH .DB 00H RFFEBH .DB 00H,00H,00H,00H,00H RFFF3H .DB 00 ; .END