Subttl -Firmware I/O Routines (16_Jul_84) ; ; Copyright 1983, 1984 ; Morrow Designs, Inc. ; San Leandro, Ca. ; David Block, John Zalabak, Bill Smith ; .z80 ; switch set to assemble z80 nemonics Include HD22DEF.MAC ; Include Global Equates ASeg Org O_IO ;See the hd*def.mac module for definition ; Index: I/O Routines ;-------------------- ; ; 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. ; ; IntCtc setu counter/time chi for proper baud rate ; IntUrt initialize the Darts and the Sio page 64 ;---------------------------------------------------------------------- ; Linkage Definitions ;-------------------- ; 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 public IntCt ;setu counter/time chi baud rates public IntUrt ;initialize the serial I/O ; 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 ;---------------------------------------------------------------------- ; SP*STS - Serial Device Input Status Routines (16_Jul_84) ;--------------------------------------------------------- ; sp3sts: in a,(s3stat) ;read port 3 status jr SpSts sp2sts: in a,(s2stat) ;read port 2 status jr SpSts sp1sts: in a,(s1stat) ;read port 1 (default console) status ;Common Part of Serial Input Status Routines SpSts: and $RcvRdy ;If (No key has been hit) ret z ; Return (Accm:= 0) xor a ;Else (Accm:= 0FFh) ret ; Return ;---------------------------------------------------------------------- ; SP*IN - Serial Device Input Routines (16_Jul_84) ;------------------------------------------------- ; 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 ;Common Part of Serial Input Routines SpIn: in a,(c) ;While (serial port is NOT ready) and $RcvRdy ; (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 (16_Jul_84) ;--------------------------------------------------- ; 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 pus bc ld b,s2stat ;B:= port 2 status jr spout sp1out: push bc ld b,s1stat ;B:= port 1 status (default console) ;Common Part of Serial Output Routines 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) and $TxRdy ; (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 (16_Jul_84) ;--------------------------------------------------------------------- ; ; 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) ; 3) All Register Pairs are Preserved. ; CStsIY: push bc push de push hl ld l,(iy+cnsts) ;HL:= vector to current console Status ld h,(iy+cnsts+1) call cIYjp pop hl pop de pop bc ret ; Input a character from the current console device ;-------------------------------------------------- ; 1) This routine inputs one character from the current output device. ; 2) All Registers Pairs are Preserved. ; CInIY: push bc push de push hl ld l,(iy+cnin) ;HL:= vector to current console output ld h,(iy+cnin+1) call cIYjp pop hl pop de 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 Pairs are Preserved. ; COutIY: push bc push de push hl ld l,(iy+cnout) ;HL:= vector to current console output ld h,(iy+cnout+1) call cIYjp pop hl pop de 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 page ;---------------------------------------------------------------------- ; INTCTC - Initialize the Counter Timer Chip Baud Rates (16_Jul_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 9600 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 B9600 out (baud2),a ld a,HIGH B9600 out (baud2),a ;Aux_Baud_Rate:= 9600 Baud ret page ;---------------------------------------------------------------------- ; Initialize the Serial I/O Ports (16_Jul_84) ;-------------------------------------------- ; 1) This routine initializes both channels of the darts and the ; Sio. 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 hl,Init_Tbl ;HL:= Pointer to Initialization Table ld b,Init_Tbl_Length ;B:= Initialization Table Length IuLp1: ld a,(hl) ;Repeat out (s1stat),a ; Init Dart Chan1 out (s2stat),a ; Init Dart Chan2 out (s3stat),a ; Init Sio inc hl ; Increment Table Pointer djnz IuLp1 ;Unitl (whole table has been used) ret ;Return ; Initialization Table ;--------------------- ; Init_Tbl: db 00011000b ;sen channe rese commands db 00010000b ;reset ext/status interrupts db 4 ;select register 4 db 01001100b ; no par, x16, 2 stops db 3 ;select register 3 db 11000001b ; rx 8 bits, auto off, rx enabled db 5 ;select register 5 db 11101010b ; tx 8 bits, dtr/rts on tx enabled db 00010000b ;reset ext/status interupts again db 1 ;select register 1 db 00000000b ; disable all interrupts here End_Init_Tbl: Init_Tbl_Length equ (End_Init_Tbl - Init_Tbl) If ($ lt O_Bios - 1) ;If (we haven't overwritten hd*bios) E_IO: ds (O_Bios - $) - 1, 0FFh ; 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