;======================================================================= ; ; XMHB.Z80 - XMODEMXX PATCH FILE FOR ROMWBW HBIOS ; ; Wayne Warthen - wwarthen@gmail.com ; Updated: 2018-06-06 ; ; 2018-06-06 WBW Added support for RC2014 w/ Z180 ; ;======================================================================= ; ; Overlay file is Z80, build with M80: ; M80 =XMHB ; L80 XMHB,XMHB/N/X/E ; .Z80 ASEG ; NO EQU 0 YES EQU NOT NO ; ERRDET EQU NO ; detect parity/framing/overrun errs ; BASE EQU 100H ; start of cp/m normal program area ; BDOS EQU 00005H ; BDOS function dispatch vector ; ;======================================================================= ; ; Jump table: The jump table must be in exactly the same sequence as the ; one in XMODEM. Note the ORG of 103H - This jump table has no jump to ; 'BEGIN'. ; ORG BASE + 3 ;start after 'JMP BEGIN' ; JP CONOUT ;must be 00000h if not used, see below JP MINIT ;initialization routine (if needed) JP UNINIT ;undo whatever 'MINIT' did (or return) JPTBL: JP SENDR ;send character (via pop psw) JP CAROK ;test for carrier JP MDIN ;receive data byte JP GETCHR ;get character from modem JP RCVRDY ;check receive ready JP SNDRDY ;check send ready JP SPEED ;get speed value for file transfer time JP EXTRA1 ;extra for custom routine JP EXTRA2 ;extra for custom routine JP EXTRA3 ;extra for custom routine ; ;----------------------------------------------------------------------- ; ; Output character to console ; CONOUT EQU 0 ; not used ; ;----------------------------------------------------------------------- ; ; Initialize modem ; ; This procedure has been usurped to dynamically detect the type ; of system we are running on and install the *real* jump table ; entries as appropriate. ; MINIT: ; ; Announce LD DE,RBC ; RetroBrew Computers LD C,9 ; BDOS string display function CALL BDOS ; Do it ; ; Identify BIOS (RomWBW HBIOS or UNA UBIOS) CALL IDBIO ; 1=HBIOS, 2=UBIOS LD (BIOID),A ; Save it DEC A ; Test for HBIOS JR Z,HINIT ; Do HBIOS setup DEC A ; Test for UBIOS JR Z,UINIT ; Do UBIOS setup ; ; Neither UNA nor RomWBW LD DE,BIOERR ; BIOS error message LD C,9 ; BDOS string display function CALL BDOS ; Do it JP 0 ; Bail out! ; HINIT: ; ; Display RomWBW notification string LD DE,HBTAG ; BIOS notification string LD C,9 ; BDOS string display function CALL BDOS ; Do it ; ; Get platform id from RomWBW HBIOS and save it LD B,0F1H ; HBIOS VER function 0xF1 LD C,0 ; Required reserved value RST 08 ; Do it, L := Platform ID LD A,L ; Move to A LD (PLTID),A ; Save it ; ; Get CPU speed from RomWBW HBIOS and save it LD B,0F8H ; HBIOS SYSGET function 0xF8 LD C,0F0H ; CPUINFO subfunction 0xF0 RST 08 ; Do it, L := CPU speed in MHz LD A,L ; Move it to A LD (CPUSPD),A ; Save it JR MINIT1 ; Continue general initialization ; UINIT: ; ; Display UNA notification string LD DE,UBTAG ; BIOS notification string LD C,9 ; BDOS string display function CALL BDOS ; Do it ; ; Get CPU speed from UNA and save it LD C,0F8H ; UNA BIOS Get PHI function RST 08 ; Returns speed in Hz in DE:HL LD B,4 ; Divide MHz in DE:HL by 100000H UINIT1: SRL D ; ... to get approx CPU speed in RR E ; ...MHz. Throw away HL, and DJNZ UINIT1 ; ...right shift DE by 4. INC E ; Fix up for value truncation LD A,E ; Put in A LD (CPUSPD),A ; Save it JR MINIT1 ; Continue general initialization ; MINIT1: ; NOTE: PLTID is only set if RomWBW HBIOS is active. This is OK ; because RC2014 is only supported by RomWBW HBIOS at this point. LD A,(PLTID) ; Get the platform id CP 7 ; Check for RC2014 JR Z,RCINIT ; Handle RC2014 special CP 8 ; Check for RC2014 w/ Z180 JR Z,ARCINIT ; Handle RC2014 w/ Z180 ; ; Check for Z180 which implies ASCI serial port LD DE,00202H ; D := 2, E := 2 MLT DE ; DE := D * E == 4 BIT 2,E ; Bit 2 wil be set if mlt happend JR Z,MINIT2 ; Not Z180 (ASCI), look for others LD HL,ASCI_JPTBL ; Point to Z180 (ASCI) jump table LD DE,ASCI ; ASCI port notification string JR MINIT3 ; Complete the initialization ; MINIT2: ; Not a Z180, so assume RBC standard UART serial port LD HL,UART_JPTBL ; Assume Z80 (UART) LD DE,UART ; UART port notification string JR MINIT3 ; Complete the initialization ; RCINIT: ; RC2014, use HBIOS calls LD HL,1250 ; Smaller receive loop tiemout scalar LD (RCVSCL),HL ; ... to compensate for BIOS overhead LD HL,HBIOS_JPTBL ; HBIOS jump table address LD DE,COMX ; HBIOS console notification string JR MINIT3 ; Complete the initialization ; ARCINIT: ; RC2014 running Z180 LD HL,ARC_JPTBL ; ASCI RC2014 jump table address LD DE,ASCIRC ; ASCI RC2014 console notification string JR MINIT3 ; Complete the initialization ; MINIT3: PUSH HL ; Save HL ; Display port notification string LD C,9 ; BDOS string display function CALL BDOS ; Do it ; ; Newline LD C,9 ; BDOS string display function LD DE,CRLF ; Newline CALL BDOS ; Do it ; ; Copy real vectors into active jump table POP HL ; Recover HL LD DE,JPTBL ; Real jump table is destination LD BC,7 * 3 ; Copy 7 3-byte entries LDIR ; Do the copy ; ; Return with CPU speed in A LD A,(CPUSPD) ; A := CPU speed in MHz LD HL,(RCVSCL) ; HL := receive scalar RET ; and return ; ; Identify active BIOS. RomWBW HBIOS=1, UNA UBIOS=2, else 0 ; IDBIO: ; ; Check for UNA (UBIOS) LD A,(0FFFDH) ; fixed location of UNA API vector CP 0C3H ; jp instruction? JR NZ,IDBIO1 ; if not, not UNA LD HL,(0FFFEH) ; get jp address LD A,(HL) ; get byte at target address CP 0FDH ; first byte of UNA push ix instruction JR NZ,IDBIO1 ; if not, not UNA INC HL ; point to next byte LD A,(HL) ; get next byte CP 0E5H ; second byte of UNA push ix instruction JR NZ,IDBIO1 ; if not, not UNA, check others LD A,2 ; UNA BIOS id = 2 RET ; and done ; IDBIO1: ; Check for RomWBW (HBIOS) LD HL,(0FFFEH) ; HL := HBIOS ident location LD A,'W' ; First byte of ident CP (HL) ; Compare JR NZ,IDBIO2 ; Not HBIOS INC HL ; Next byte of ident LD A,~'W' ; Second byte of ident CP (HL) ; Compare JR NZ,IDBIO2 ; Not HBIOS LD A,1 ; HBIOS BIOS id = 1 RET ; and done ; IDBIO2: ; No idea what this is XOR A ; Setup return value of 0 RET ; and done ; ; ; BIOID DB 0 ; BIOS ID, 1=HBIOS, 2=UBIOS PLTID DB 0 ; Platform ID CPUSPD DB 10 ; CPU speed in MHz RCVSCL DW 2800 ; RECV loop timeout scalar ; RBC DB "RBC, 06-Jun-2018$" ; UART DB ", UART0$" ASCI DB ", ASCI0$" ASCIRC DB ", ASCI0 (RC2014)$" COMX DB ", COM0$" ; UBTAG DB " [UNA]$" HBTAG DB " [WBW]$" ; CRLF DB 13, 10, "$" ; BIOERR DB 13, 10, 13, 10, "++ Unknown BIOS ++", 13, 10, "$" ; ;----------------------------------------------------------------------- ; ; Uninitialize modem ; UNINIT: RET ; not initialized, so no 'UN-INITIALIZE' ; ;----------------------------------------------------------------------- ; ; The following are all dummy routines that are unused because MINIT ; dynamically installs the real jump table. ; SENDR: CAROK: MDIN: GETCHR: RCVRDY: SNDRDY: SPEED: EXTRA1: EXTRA2: EXTRA3: RET ; ;======================================================================= ;======================================================================= ; ; Standard RBC Projects 8250-like UART port @ 68H ; ; Will be used for all RBC Z80 systems. ; ;======================================================================= ;======================================================================= ; ; UART port constants ; U_BASE EQU 68H ; UART base port U_DATP EQU U_BASE + 0 ; data in port U_DATO EQU U_BASE + 0 ; data out port U_CTLP EQU U_BASE + 5 ; control/status port U_SNDB EQU 20H ; bit to test for send ready U_SNDR EQU 20H ; value when ready to send U_RCVB EQU 01H ; bit to test for receive ready U_RCVR EQU 01H ; value when ready to receive U_PARE EQU 04H ; bit for parity error U_OVRE EQU 02H ; bit for overrun error U_FRME EQU 08H ; bit for framing error ; ; Following jump table is dynamically patched into real jump ; table at program startup. See MINIT above. Note that only a ; subset of the jump table is overlaid (SENDR to SPEED). ; UART_JPTBL: JP U_SENDR ; send character (via pop psw) JP U_CAROK ; test for carrier JP U_MDIN ; receive data byte JP U_GETCHR ; get character from modem JP U_RCVRDY ; check receive ready JP U_SNDRDY ; check send ready JP U_SPEED ; get speed value for file transfer time ; ;----------------------------------------------------------------------- ; ; Send character on top of stack ; U_SENDR: POP AF ; get character to send from stack OUT (U_DATO),A ; send to port RET ; ;----------------------------------------------------------------------- ; ; Test and rep;ort carrier status, Z set if carrier present ; U_CAROK: XOR A ; not used, always indicate present RET ; ;----------------------------------------------------------------------- ; ; Get a character (assume character ready has already been tested) ; U_MDIN: U_GETCHR: IN A,(U_DATP) ; read character from port RET ; ;----------------------------------------------------------------------- ; ; Test for character ready to receive, Z = ready ; Error code returned in A register ; *** Error code does not seem to be used *** ; U_RCVRDY: IN A,(U_CTLP) ; get modem status ; IF ERRDET ; ; With error detection (slower) PUSH BC ; save scratch register PUSH AF ; save full status on stack AND U_FRME | U_OVRE | U_PARE ; isolate line err bits LD B,A ; save err status in B POP AF ; get full status back AND U_RCVB ; isolate ready bit CP U_RCVR ; test it (set flags) LD A,B ; get the error code back POP BC ; restore scratch register ; ELSE ; ; No error detection (faster) AND U_RCVB ; isolate ready bit CP U_RCVR ; test it (set flags) LD A,0 ; report no line errors ; ENDIF ; RET ; ;----------------------------------------------------------------------- ; ; Test for ready to send a character, Z = ready ; U_SNDRDY: IN A,(U_CTLP) ; get status AND U_SNDB ; isolate transmit ready bit CP U_SNDR ; test for ready value RET ; ;----------------------------------------------------------------------- ; ; Report baud rate (index into SPTBL returned in register A) ; U_SPEED: LD A,8 ; arbitrarily return 9600 baud RET ; ;======================================================================= ;======================================================================= ; ; Standard RBC Projects Z180 primary ASCI port ; ; Will be used for all RBC Z180 systems. ; ;======================================================================= ;======================================================================= ; ; ASCI port constants ; A_DATP EQU 48H ;Z180 TSR - ASCI receive data port A_DATO EQU 46H ;Z180 TDR - ASCI transmit data port A_CTLP EQU 44H ;Z180 STAT - ASCI status port A_CTL2 EQU 40H ;Z180 CNTLA - ASCI control port ; A_SNDB EQU 02H ;Z180 STAT:TDRE - xmit data reg empty bit A_SNDR EQU 02H ;Z180 STAT:TDRE - xmit data reg empty value A_RCVB EQU 80H ;Z180 STAT:RDRF - rcv data reg full bit A_RCVR EQU 80H ;Z180 STAT:RDRF - rcv data reg full value A_PARE EQU 20H ;Z180 STAT:PE - parity error bit A_OVRE EQU 40H ;Z180 STAT:OVRN - overrun error bit A_FRME EQU 10H ;Z180 STAT:FE - framing error bit ; ; Following jump table is dynamically patched over initial jump ; table at program startup. See MINIT above. Note that only a ; subset of the jump table is overlaid (SENDR to SPEED). ; ASCI_JPTBL: JP A_SENDR ;send character (via pop psw) JP A_CAROK ;test for carrier JP A_MDIN ;receive data byte JP A_GETCHR ;get character from modem JP A_RCVRDY ;check receive ready JP A_SNDRDY ;check send ready JP A_SPEED ;get speed value for file transfer time ; ;----------------------------------------------------------------------- ; ; Send character on top of stack ; A_SENDR: POP AF ; get character to send from stack OUT0 (A_DATO),A ; send to port RET ; ;----------------------------------------------------------------------- ; ; Test and rep;ort carrier status, Z set if carrier present ; A_CAROK: XOR A ; not used, always indicate present RET ; ;----------------------------------------------------------------------- ; ; Get a character (assume character ready has already been tested) ; A_MDIN: A_GETCHR: IN0 A,(A_DATP) ; read character from port RET ; ;----------------------------------------------------------------------- ; ; Test for character ready to receive, Z = ready ; Error code returned in A register ; *** Error code does not seem to be used *** ; A_RCVRDY: IN0 A,(A_CTLP) ; get modem status PUSH BC ; save scratch register PUSH AF ; save full status on stack AND A_FRME | A_OVRE | A_PARE ; isolate line err bits LD B,A ; save err status in B ; Z180 ASCI ports will stall if there are errors. ; Error bits are NOT cleared by merely reading ; the status register. Below, bit 3 of ASCI ; control register is written with a zero to ; clear error(s) if needed. JP Z,A_RCVRDY2 ; if no errs, continue IN0 A,(A_CTL2) ; get current control register AND 0F7H ; force err reset bit to zero OUT0 (A_CTL2),A ; write control register A_RCVRDY2: POP AF ; get full status back AND A_RCVB ; isolate ready bit CP A_RCVR ; test it (set flags) LD A,B ; get the error code back POP BC ; restore scratch register RET ; ;----------------------------------------------------------------------- ; ; Test for ready to send a character, Z = ready ; A_SNDRDY: IN A,(A_CTLP) ; get status AND A_SNDB ; isolate transmit ready bit CP A_SNDR ; test for ready value RET ; ;----------------------------------------------------------------------- ; ; Report baud rate (index into SPTBL returned in register A) ; A_SPEED: LD A,8 ; arbitrarily return 9600 baud RET ; ;======================================================================= ;======================================================================= ; ; RC2014 Z180 primary ASCI port ; ; Will be used for all RC2014 Z180 systems. ; ;======================================================================= ;======================================================================= ; ; ASCI port constants for RC2014 ; AR_DATP EQU 0C8H ;Z180 TSR - ASCI receive data port AR_DATO EQU 0C6H ;Z180 TDR - ASCI transmit data port AR_CTLP EQU 0C4H ;Z180 STAT - ASCI status port AR_CTL2 EQU 0C0H ;Z180 CNTLA - ASCI control port ; ; Following jump table is dynamically patched over initial jump ; table at program startup. See MINIT above. Note that only a ; subset of the jump table is overlaid (SENDR to SPEED). ; ARC_JPTBL: JP AR_SENDR ;send character (via pop psw) JP AR_CAROK ;test for carrier JP AR_MDIN ;receive data byte JP AR_GETCHR ;get character from modem JP AR_RCVRDY ;check receive ready JP AR_SNDRDY ;check send ready JP AR_SPEED ;get speed value for file transfer time ; ;----------------------------------------------------------------------- ; ; Send character on top of stack ; AR_SENDR: POP AF ; get character to send from stack OUT0 (AR_DATO),A ; send to port RET ; ;----------------------------------------------------------------------- ; ; Test and rep;ort carrier status, Z set if carrier present ; AR_CAROK: XOR A ; not used, always indicate present RET ; ;----------------------------------------------------------------------- ; ; Get a character (assume character ready has already been tested) ; AR_MDIN: AR_GETCHR: IN0 A,(AR_DATP) ; read character from port RET ; ;----------------------------------------------------------------------- ; ; Test for character ready to receive, Z = ready ; Error code returned in A register ; *** Error code does not seem to be used *** ; AR_RCVRDY: IN0 A,(AR_CTLP) ; get modem status PUSH BC ; save scratch register PUSH AF ; save full status on stack AND A_FRME | A_OVRE | A_PARE ; isolate line err bits LD B,A ; save err status in B ; Z180 ASCI ports will stall if there are errors. ; Error bits are NOT cleared by merely reading ; the status register. Below, bit 3 of ASCI ; control register is written with a zero to ; clear error(s) if needed. JP Z,A_RCVRDY2 ; if no errs, continue IN0 A,(AR_CTL2) ; get current control register AND 0F7H ; force err reset bit to zero OUT0 (AR_CTL2),A ; write control register AR_RCVRDY2: POP AF ; get full status back AND A_RCVB ; isolate ready bit CP A_RCVR ; test it (set flags) LD A,B ; get the error code back POP BC ; restore scratch register RET ; ;----------------------------------------------------------------------- ; ; Test for ready to send a character, Z = ready ; AR_SNDRDY: IN A,(AR_CTLP) ; get status AND A_SNDB ; isolate transmit ready bit CP A_SNDR ; test for ready value RET ; ;----------------------------------------------------------------------- ; ; Report baud rate (index into SPTBL returned in register A) ; AR_SPEED: LD A,8 ; arbitrarily return 9600 baud RET ; ;======================================================================= ;======================================================================= ; ; HBIOS CONSOLE (COM0:) ; ; Will be used for all RC2014 systems ; ;======================================================================= ;======================================================================= ; ; Following jump table is dynamically patched over initial jump ; table at program startup. See MINIT above. Note that only a ; subset of the jump table is overlaid (SENDR to SPEED). ; HBIOS_JPTBL: JP HB_SENDR ;send character (via pop psw) JP HB_CAROK ;test for carrier JP HB_MDIN ;receive data byte JP HB_GETCHR ;get character from modem JP HB_RCVRDY ;check receive ready JP HB_SNDRDY ;check send ready JP HB_SPEED ;get speed value for file transfer time ; ;----------------------------------------------------------------------- ; ; Send character on top of stack ; HB_SENDR: POP AF ; get character to send from stack PUSH BC PUSH DE PUSH HL LD B,01H ; HBIOS OUT function LD C,0 ; console is unit 0 by fiat LD E,A ; character to E RST 08 ; HBIOS call POP HL POP DE POP BC RET ; ;----------------------------------------------------------------------- ; ; Test and rep;ort carrier status, Z set if carrier present ; HB_CAROK: XOR A ; not used, always indicate present RET ; ;----------------------------------------------------------------------- ; ; Get a character (assume character ready has already been tested) ; ; This routine must NOT block. ; HB_MDIN: HB_GETCHR: PUSH BC PUSH DE PUSH HL LD B,02H ; HBIOS IST function LD C,0 ; console is unit 0 by fiat RST 08 ; HBIOS call, A := bytes pending JR NZ,HB_MDIN1 ; If char(s) waiting, go get it XOR A ; otherwise, return null JR HB_MDIN2 ; and done HB_MDIN1: LD B,00H ; HBIOS IN function LD C,0 ; console is unit 0 by fiat RST 08 ; HBIOS call LD A,E ; byte received to A HB_MDIN2: POP HL POP DE POP BC RET ; ;----------------------------------------------------------------------- ; ; Test for character ready to receive, Z = ready ; Error code returned in A register ; *** Error code does not seem to be used *** ; HB_RCVRDY: PUSH BC PUSH DE PUSH HL LD B,02H ; HBIOS IST function LD C,0 ; console is unit 0 by fiat RST 08 ; HBIOS call, A := bytes pending SUB 1 ; CF set IFF zero RL A ; CF to bit 0 of A AND 01H ; set Z flag as needed LD A,0 ; report no line errors POP HL POP DE POP BC RET ; ;----------------------------------------------------------------------- ; ; Test for ready to send a character, Z = ready ; HB_SNDRDY: PUSH BC PUSH DE PUSH HL LD B,03H ; HBIOS OST function LD C,0 ; console is unit 0 by fiat RST 08 ; HBIOS call, A := xmit buf bytes avail SUB 1 ; CF set IFF zero RL A ; CF to bit 0 of A AND 01H ; set Z flag as needed POP HL POP DE POP BC RET ; ;----------------------------------------------------------------------- ; ; Report baud rate (index into SPTBL returned in register A) ; HB_SPEED: LD A,8 ; arbitrarily return 9600 baud RET ; END