Subttl -Firmware I/O Routines (Rev_20 12_Jan_84) ; ; Copyright 1983, 1984 ; Morrow Designs, Inc. ; San Leandro, Ca. ; David Block, John Zalabak, Bill Smith ; .z80 ; switch set to assemble z80 nemonics include HD20DEF.MAC ; Include Global Equates aseg org o_io ;See the hd*def.mac module for definition ; Index: I/O Routines ;-------------------- ; ; inturt initialize the darts ; intctc setu counter/time chi for proper baud rate ; ; sp1sts read port 1 status (the default console) ; sp2sts read port 2 status ; sp3sts read port 3 status ; ; sp3in input from serial port 3 ; sp2in input from serial port 2 ; sp1in input from serial port 1 (the default console) ; spin common serial input routine ; ; sp3out output to serial port 3 ; sp2out output to serial port 2 ; sp1out output to serial port 1 (the default console) ; spout common serial output routine ; ; cinIY input from the current serial input device ; coutIY Ouput a character to the current console device ; cstsIY Get the status of the current console input device ; ; cntout centronics port driver ; ; clrmsg clear the console screen ; mesg output a message string ; outbyt this will print the hex value of the accumulator. ; outasc output lower nibble of accumulator as hex digit. page 64 ;---------------------------------------------------------------------- ; Linkage Definitions ;-------------------- ; public inturt ;initialize the serial I/O public intct ;setu counter/time chi baud rates public sp1sts ;read port 1 status (the default console) public sp2sts ;read port 2 status public sp3sts ;read port 3 status publi sp1in ;inpu fro seria por (defaul console) public sp2in ;input from serial port 2 public sp3in ;input from serial port 3 publi sp1out ;outpu t seria por (defaul console) public sp2out ;output to serial port 2 public sp3out ;output to serial port 3 public cinIY ;Input from the current console device public coutIY ;Ouput to the current console device public cstsIY ;Status input from the current console device public cntout ;output to the centronics port public cntsts ;centronics status public clrmsg ;clear the console screen public mesg ;output a message string public outbyt ;print the hex value of accumulator. public outasc ;output lo-nibble of accum as hex digit ; In the Main Module external wrtbnk ;Write to the bank strobe register ;---------------------------------------------------------------------- ; Local Equates (12_Jan_84) ;-------------------------- ; ;Baud Rate Definitions for CTC initialization (see IntCtc) B300 equ 342h ;300 Baud B1200 equ 0D0h ;1200 Baud B9600 equ 01Ah ;9600 Baud B19200 equ 00Dh ;19200 Baud page ;---------------------------------------------------------------------- ; INTURT - Initialize the Serial I/O Devices (12_Nov_83) ;------------------------------------------------------- ; function: this routine initializes both channels of the darts. ; they are set for 8 bits, no parity, x16 clock rate, and ; 2 stop bits. in addition, dtr, and rts, are programmed ; to be on. ; inturt: ld a,18h ; send channel reset commands out (s1stat),a out (s2stat),a out (s3stat),a ld a,10h ;reset ext/status interrupts out (s1stat),a out (s2stat),a out (s3stat),a ;end of reset sequence ld a,04h ;select register 4 out (s1stat),a out (s2stat),a out (s3stat),a ld a,04ch ;no par, x16, 2 stops out (s1stat),a out (s2stat),a out (s3stat),a ld a,03h ;select register 3 out (s1stat),a out (s2stat),a out (s3stat),a ld a,0c1h ;rx 8 bits, auto off, rx enabled out (s1stat),a out (s2stat),a out (s3stat),a ld a,05h ;select register 5 out (s1stat),a out (s2stat),a out (s3stat),a ld a,0EAh ;tx 8 bits, dtr/rts on tx enabled out (s1stat),a out (s2stat),a out (s3stat),a ld a,10h ;reset ext/status interupts again out (s1stat),a out (s2stat),a out (s3stat),a ld a,01h ;select register 1 out (s1stat),a out (s2stat),a out (s3stat),a ld a,0h ;disable all interrupts here out (s1stat),a out (s2stat),a out (s3stat),a page ;---------------------------------------------------------------------- ; INTCTC - Initialize the Counter Timer Chip Baud Rates (12_Jan_84) ;------------------------------------------------------------------ ; 1) This routine intializes the counter timer chip that serves as ; a baud rate generator for the serial ports. ; 2) Notice that the Console Device (channel_2) has its baud rate ; set as a function of a jumper (bit_5 of drvsts). If the jumper ; IS NOT present then the console will be set to 9600 baud. If the ; jumper IS present then the console will be set to 19200 baud. ; 3) Baud rate definitions (B...) are defined in the Local Equates ; section at the beginning of this module (following the index). ; ; Device Baud Rate CTC Channel ; Con 9600/19200 2 ; Lst 1200 1 ; Aux 1200 0 ; IntCTC: ld a,0BEh ;Console:= Mode 3 (Channel 2) out (baudset),a in a,(drvsts) ;If (Baud Rate Jumper is IN) and $JBAUD jr z,IcSk1 ld a,LOW B19200 out (baud0),a ld a,HIGH B19200 out (baud0),a ; Console_Baud_Rate:= 19200 Baud jr IcSk2 IcSk1: ld a,LOW B9600 ;Else out (baud0),a ld a,HIGH B9600 out (baud0),a ; Console_Baud_Rate:= 9600 Baud IcSk2: ld a,7Eh ;List:= Mode 3 (Channel 1) out (baudset),a ld a,LOW B1200 out (baud1),a ld a,HIGH B1200 out (baud1),a ;List_Baud_Rate:= 1200 Baud ld a,3Eh ;Aux:= Mode 3 (Channel 0) out (baudset),a ld a,LOW B1200 out (baud2),a ld a,HIGH B1200 out (baud2),a ;Aux_Baud_Rate:= 1200 Baud ret page ;---------------------------------------------------------------------- ; SP*STS - Serial device input status routines (26_Sept_83) ;---------------------------------------------------------- ; sp1sts: in a,(s1stat) ;read port 1 (default console) status bit 0,a ;If (No key has been hit) ld a,0 ; Accm:= 0 ret z ; Return ld a,0FFh ;Else Accm:= 0FFh ret ; Return sp2sts: in a,(s2stat) ;read port 2 status bit 0,a ;If (No key has been hit) ld a,0 ; Accm:= 0 ret z ; Return ld a,0FFh ;Else Accm:= 0FFh ret ; Return sp3sts: in a,(s3stat) ;read port 3 status bit 0,a ;If (No key has been hit) ld a,0 ; Accm:= 0 ret z ; Return ld a,0FFh ;Else Accm:= 0FFh ret ; Return ;---------------------------------------------------------------------- ; SP*IN - serial device input routines ;------------------------------------- ; 1) Register Usage: ; A -> Input Character ; C -> Port Address ; sp3in: ld c,s3stat ;B:= port 3 status jr spin sp2in: ld c,s2stat ;B:= port 2 status jr spin sp1in: ld c,s1stat ;B:= port 1 status spin: in a,(c) ;While (serial port is NOT ready) bit 0,a ; (bit_0 = ready) jr z,spin ; Wait dec c ;Adjust pointer to data port in a,(c) ;Input Character and 01111111b ;mask off parity ret page ;---------------------------------------------------------------------- ; SP*OUT - serial device output routines ;--------------------------------------- ; 1) These are the character output routines for the serial ports. ; 2) Note that the BC register pair is preserved ; 3) Register Usage: ; A -> General Purpose ; B -> Port Address ; C -> Character to be output ; sp3out: push bc ld b,s3stat ;B:= port 3 status jr spout sp2out: push bc ld b,s2stat ;B:= port 2 status jr spout sp1out: push bc ld b,s1stat ;B:= port 1 status (default console port) spout: ld a,b ;(switch port and character registers) ld b,c ;B:= Character to Output ld c,a ;C:= Status Port Address outlp: in a,(c) ;While (console is NOT ready) bit 2,a ; (bit_2 = ready) jr z,outlp ; Wait ld a,b ;A:= Character dec c ;(Move pointer to data port) out (c),a ;Output the character pop bc ret page ;---------------------------------------------------------------------- ; C*IY - Current Console Status, Input and Output Routines (13_Oct_83) ;--------------------------------------------------------------------- ; ; Get the Status of the Current console device ;--------------------------------------------- ; 1) The current console input device's status is checked ; 2) The status is returned in the accm (0=Not Ready, FF=Ready) ; cstsIY: push hl ld l,(iy+cnsts) ;hl:= vector to current console Status ld h,(iy+cnsts+1) call cIYjp pop hl ret ; Input a character from the current console device ;-------------------------------------------------- ; 1) This routine inputs one character from the current output device. ; 2) All Registers are preserved (Note that the DE pair is NOT used ; by and of the serial I/O routines or the Centronics Driver). ; cinIY: push bc push hl ld l,(iy+cnin) ;HL:= vector to current console output ld h,(iy+cnin+1) call cIYjp pop hl pop bc ret ; Ouput a character to the current console device ;------------------------------------------------ ; 1) This routine outputs one character to the current output device. ; 2) The character to be output is passed in the C reg. ; 3) All Registers are preserved (Note that the DE pair is NOT used ; by and of the serial I/O routines or the Centronics Driver). ; coutIY: push bc push hl ld l,(iy+cnout) ;HL:= vector to current console output ld h,(iy+cnout+1) call cIYjp pop hl pop bc ret ;Indirect Jump (This jump is only used by cinIY and coutIY) cIYjp: jp (hl) ;vector to the current console driver page ;---------------------------------------------------------------------- ; CNTOUT - centronics port driver (12_Nov_83) ;-------------------------------------------- ; 1) This routine outputs the character sent in the C register to the ; centronics port. ; 2) Notice that the routine will hang until the centronics port ; becomes ready. ; 3) Register Usage: ; A -> General Purpose ; B -> Mask byte (see wrtbnk) ; C -> Character to be output and Mask Byte (see wrtbnk) ; cntout: call cntsts ;While (print is NOT ready) jr z,cntout ; wait ld a,c out (cdata),a ;Output character to centronics port push bc ld b,11111111b xor ($CNTSTB) ld c,00000000b or ($CNTSTB) call wrtbnk ;Set the strobe bit ld c,00000000b or (0000000) call wrtbnk ;Clear the strobe bit pop bc ret ; Get the centronics ready status ;-------------------------------- ; 1) This routine samples the ready line of the centronics port. ; 2) Register Usage: ; A -> Returned status (0FFh=ready, 0=Not-ready) ; cntsts: in a,(cstat) ;Read the Centronics Status port and $CNTRDY ;If (the printer is NOT ready) ret z ; Return (accm=0) ld a,0FFh ;Else accm:= FFh (Not ready) ret ;Return (accm=0 for ready) page ;---------------------------------------------------------------------- ; --- General Purpose Output Routines ;------------------------------------ ; 1) Notice that all of these routines use the current console ; as the output device. This means that the IY area have been ; setup with the proper console vectors before these routines ; are used. ;Clear the console screen and output a prompt clrmsg: ld b,50 ;For (B:=50; B ne 0; B:= B - 1) clrlp: ld c,lf call coutIY ; Output a Line Feed djnz clrlp ; <== Fall through to output a message ; Print the message pointed to by the DE pair (terminated by a 0) mesg: ld a,(de) ;While (character ne 0) or a ret z ; (return if 0) ld c,a call coutIY ; Output the character inc de ; Pointer:= Pointer + 1 jr mesg ;Print the hex value of the accumulator. outbyt: push af ; save value rrca ; get upper nibble rrca rrca rrca and 0Fh ; mask off the rest call outasc ; print ascii hex digit pop af ; get value back and 0Fh ; mask call outasc ; print ascii hex digit ret ;Output the lower nibble of the accumulator as a hex digit. outasc: cp 0Ah ; see if digit or alpha jp m,num ; jump if digit add a,07h ; adjust for alpha num: add a,30h ; convert to ascii ld c,a call coutIY ; print it ret if ($ lt o_bios - 1) ;If (we haven't overwritten hd*bios) e_io: ds (o_bios - $) - 1, 0 ; Zero Fill to the bios module else ;Else if2 ; print an error message on pass2 .printx "The io module has overflowed into the bios module" endif endif end