; PROGRAM: ZMO-MH05.Z80 ; AUTHOR: Lindsay Allen ; VERSION: 1.5 ; DATE: 19 Sept, 1988 ;----------------------------------------------------------------------- ; This overlay is set up for a Morrow MD11. ; Uses a Z80SIO and an 8253 CTC ;----------------------------------------------------------------------- ; 89/04/12 - Modified to ZMP v1.5 - George Conover ; 89/03/15 - Removed the beginning remarks to make the file ; smaller. If you need the remarks there are in the ; file ZMP-BLNK.Z80 - George Conover ; 89/03/14 - Modified to ZMP v1.4 - George Conover ; 88/10/12 - Modified to ZMP v1.3 - Ron Murray ; 88/09/15 - Modified to ZMP v1.2 - Ron Murray ; 88/09/14 - First version of this file - Lindsay Allen ; ; Written by - ; Ron Murray, c/o Z-Node 62, 061-9-450-0200, Perth, Western Australia. ;----------------------------------------------------------------------- NO EQU 0 YES EQU NOT NO ; ; User-set variables ; CLKSPD EQU 4 ; Processor clock speed in MHz ; DEBUG EQU NO ;Set the following two equates to the drive and user area which will contain ; ZMP's .OVR files, .CFG file, .FON file and .HLP file. Set both to zero ; (null) to locate them on the drive from which ZMP was invoked. OVERDRIVE EQU 'A' ; Drive to find overlay files on ('A'-'P') OVERUSER EQU 0 ; User area to find files ;------------------------------------------------------------------------------ ; ; NOT user-set variables ; USERDEF EQU 0145H ; Origin of this overlay. This address ; ; may change with subsequent revisions MSPEED EQU 05CH ; Location of current baud rate. OVSIZE EQU 0400H ; Max size of this overlay ; .Z80 ; Use z80 code ASEG ; Absolute ; IF DEBUG ORG 100H ; So you can debug it with CEBUG, ZSID, ; ; etc. ELSE ORG USERDEF ENDIF ; DEBUG ; ESC EQU 1BH CTRLQ EQU 11H CR EQU 0DH LF EQU 0AH BDOS EQU 5 ; ; Ports: ; Console data 60 ; stat 61 ; ; Modem data 62 ; Rx bit 2 ; stat 63 ; Tx 0 ; ; SIO data 70 ; stat 71 ; ; mode 3 BNKBIOS3 ; CTC SIO 50 CH 0 3E PORT 3 (BAUD2) ; MODEM 51 CH 1 7E PORT 2 (BAUD1) ; CONSOLE 52 CH 2 BE PORT 1 (BAUD0) ; SELECT 53 ; ; ; MDII specific equates ; SIO EQU YES ; YES to use the SIO, NO to use the DART ; IF SIO MDATA EQU 070H ; Use RS232 socket at other end from ; ; Terminal MSTAT EQU MDATA+1 CTC EQU 50H MODE EQU 3EH ; ELSE MDATA EQU 62H ; Use RSs232 socket adjacent to Terminal MSTAT EQU MDATA+1 CTC EQU 51H MODE EQU 7EH ENDIF ; SIO ; RDA EQU 0 TBE EQU 2 CTCSEL EQU 53H ONHOOK EQU 7FH ONLINE EQU 80H ERROR EQU 70H BREAK EQU 0F8H RESET EQU 30H ; ;----------------------------------------------------------------------- ; ; Main code starts here ; ; Jump table for the overlay: do NOT change this ; CODEBGN EQU $ ; JUMPTAB: JP SCRNPR ; Screen print JP MRD ; Modem read with timeout JP MCHIN ; Get a character from modem JP MCHOUT ; Send a character to the modem JP MORDY ; Test for tx buffer empty JP MIRDY ; Test for character received JP SNDBRK ; Send break JP CURSADD ; Cursor addressing JP CLS ; Clear screen JP INVON ; Inverse video on JP INVOFF ; Inverse video off JP HIDE ; Hide cursor JP SHOW ; Show cursor JP SAVECU ; Save cursor position JP RESCU ; Restore cursor position JP MINT ; Service modem interrupt JP INVEC ; Initialise interrupt vectors JP DINVEC ; De-initialise interrupt vectors JP MDMERR ; Test uart flags for error JP DTRON ; Turn DTR on JP DTROFF ; Turn DTR OFF JP INIT ; Initialise uart JP WAIT ; Wait seconds JP MSWAIT ; Wait milliseconds JP USERIN ; User-defined entry routine JP USEROUT ; User-defined exit routine JP GETVARS ; get system variables JP SETPORT ; Set port (0 or 1) ; ; Spare jumps for compatibility with future versions ; JP SPARE ; Spares for later use JP SPARE ; Spares for later use JP SPARE ; Spares for later use JP SPARE ; Spares for later use JP SPARE ; Spares for later use JP SPARE ; Spares for later use ; SPARE: RET ; ;----------------------------------------------------------------------- ; ; Screen print function ; SCRNPR: DS 0 ; ; <== Insert your own code here ; CALL PRINT DB 'This function not supported.',CR,LF,0 ; ; <== End of your own code ; RET ; ; ; Get a character from the modem: return in HL ; MCHIN: PUSH BC ; ; <== Insert your own code here ; MCHIN2: IN A,(MSTAT) ; Check for char waiting BIT RDA,A JR Z,MCHIN2 IN A,(MDATA) ; Read the char ; ; <== End of your own code ; LD L,A ; Put in HL LD H,0 OR A ; Set/clear Z POP BC RET ; ; Send a character to the modem ; MCHOUT: LD HL,2 ; Get the character ADD HL,SP LD A,(HL) ; ; <== Insert your own code here ; PUSH BC LD B,A ; Save the character ; MCHOUT2:IN A,(MSTAT) ; Check for uart ready BIT TBE,A JR Z,MCHOUT2 LD A,B ; Char in a OUT (MDATA),A ; Send it POP BC ; ; <== End of your own code ; RET ; Done ; ; Test for output ready: return TRUE (1) in HL if ok ; MORDY: DS 0 ;' ; <== Insert your own code here ; LD HL,0 IN A,(MSTAT) BIT TBE,A ; Transmit buffer empty JR Z,MORDY1 INC HL ; MORDY1: DS 0 ; ; <== End of your own code ; LD A,L ; Set/clear Z OR A RET ; ; Test for character at modem: return TRUE (1) in HL if so MIRDY: DS 0 ; ; <== Insert your own code here ; LD HL,0 IN A,(MSTAT) BIT RDA,A ; Received data available JR Z,MIRDY1 INC HL ; MIRDY1: DS 0 ; ; <== End of your own code ; LD A,L ; Set/clear Z OR A RET ; ; Send a break to the modem: leave empty if your system can't do it ; SNDBRK: DS 0 ; ; <== Insert your own code here ; LD A,5 OUT (MSTAT),A LD A,BREAK ; F8 OUT (MSTAT),A LD HL,300 ; A 300 mS break CALL WAITHLMS LD A,5 OUT (MSTAT),A LD A,ONLINE ; 68 OUT (MSTAT),A LD A,3 OUT (MSTAT),A LD A,0E1H OUT (MSTAT),A ; E1 ; ; <== End of your own code ; RET ; ; Test UART flags for error: return TRUE (1) in HL if error ; MDMERR: DS 0 ; ; <== Insert your own code here ; LD HL,0 IN A,(MSTAT) AND ERROR JR Z,MDMER2 INC HL ; MDMER2: DS 0 ; ; <== End of your own code ; LD A,L ; Set/clear Z OR A RET ; ; Turn DTR ON ; DTRON: DS 0 ; ; <== Insert your own code here ; LD A,5 OUT (MSTAT),A LD A,(COMBYT) ; Get the one we used last time OR ONLINE ; 80h - set bit 7 high LD (COMBYT),A ; Save it for next time OUT (MSTAT),A ; Go ; ; <== End of your own code ; RET ; ; Turn DTR OFF ; DTROFF: DS 0 ; ; <== Insert your own code here ; LD A,5 OUT (MSTAT),A LD A,(COMBYT) ; Get the one we used last time AND ONHOOK ; 7Fh - clear bit 7 LD (COMBYT),A ; Save it for next time OUT (MSTAT),A ; Go ; ; <== End of your own code ; RET ; ; Initialise the SIO +++ ; The SIO is set up in four steps: ; 1) Reset ; 2) Reg 4 - clock, stop bits, parity ; 3) Reg 5 - dtr, Tx bits, Brk, TxEn, rts ; 4) Reg 3 - Rx bits, RxEn ; INIT: LD HL,2 ; Get parameters ADD HL,SP EX DE,HL CALL GETPARM ; In HL LD (BRATE),HL ; Baud rate LD A,L LD (003CH),A ; Save the baud rate in 3C for later ; ; as per IMP CALL GETPARM LD (PARITY),HL ; Parity CALL GETPARM LD (DATA),HL ; Data bits CALL GETPARM LD (STOP),HL ; Stop bits ; ; <== Insert your own code here, using values below ; PUSH BC LD A,0 OUT (MSTAT),A ; Point to reg 0 LD A,18H ; Reset OUT (MSTAT),A ; *** step 1 LD A,4 ; Point to wrt reg 4 OUT (MSTAT),A LD E,44H ; Assume x16, 1 stop, No parity LD A,(STOP) ; Set stop bits CP 2 ; Set 2 if required JR NZ,SETPAR SET 3,E ; SETPAR: LD A,(PARITY) ; Set parity bits CP 'O' JR NZ,SETPA2 SET 0,E ; ODD JR SETPA3 ; SETPA2: CP 'E' JR NZ,SETPA3 SET 0,E SET 1,E ; EVEN ; SETPA3: LD A,E OUT (MSTAT),A ; *** step 2 LD A,5 ; Point to wrt reg 5 - dtr, Tx bits, etc OUT (MSTAT),A LD E,0EAH ; Assume dtr, TX 8 bits, TxEn, rts LD A,(DATA) CP 7 JR NZ,SETBI2 RES 6,E ; 7 bits ; SETBI2: LD A,E OUT (MSTAT),A ; *** step 3 LD A,3 ; Point to wrt reg 3 OUT (MSTAT),A LD E,0C1H ; Assume 8 bits LD A,(DATA) CP 7 JR NZ,SETBI3 RES 7,E ; 7 bits ; SETBI3: LD A,E OUT (MSTAT),A ; *** step 4 ; SETBRATE: PUSH IX LD DE,(BRATE) ; Get baud rate value (0-10) LD HL,BRVAL ADD HL,DE ADD HL,DE ; Hl now points to the divisor dw PUSH HL ; Look at it POP IX LD A,(IX) OR (IX+1) JR Z,SETBRX ; Zero = invalid LD C,CTCSEL ; 053h LD A,MODE ; 03Eh or 7Eh OUT (C),A ; Select the correct timer and mode ; ; of the 8253 LD C,CTC ; 050h or 51h OUTI ; Lo byte OUTI ; Hi byte LD A,(BRATE) ; Tell zmp it's ok LD (MSPEED),A ; SETBRX: POP IX POP BC ; ; <== End of your own code ; RET ; ;----------------------------------------------------------------------- ; STOP: DW 1 ; Stop bits PARITY: DW 'N' ; Parity DATA: DW 8 ; Data bits BRATE: DW 7 ; Baud rate: COMBYT: DB 0EAH ; For now ; ;----------------------------------------------------------------------- ; ;Values for 8253 control reg for each baud rate ; BRVAL: DW 2273 ; 110 0 DW 833 ; 300 1 DW 555 ; 450 2 DW 417 ; 600 3 DW 352 ; 710 4 DW 208 ; 1200 5 DW 104 ; 2400 6 DW 52 ; 4800 7 DW 26 ; 9600 8 DW 13 ; 19200 9 DW 0 ; 38400 10 DW 0 ; 57600 11 DW 0 ; 76800 12 DW 0 ; 115200 13 ; ; Set the port. ZMP supplies either 0 or 1 as a parameter. ; setport: ld hl,2 ; get port number add hl,sp ex de,hl call getparm ; in HL (values are 0 and 1) ; <== Insert your own code here ; <== End of your own code ret ; ;----------------------------------------------------------------------- ; ; Video terminal sequences: these are for ADM-3A: Modify as you wish ; ; Cursor addressing ; CURSADD:LD HL,2 ; Get parameters ADD HL,SP EX DE,HL CALL GETPARM ; In HL LD (ROW),HL ; Row CALL GETPARM LD (COL),HL ; Column ; ; <== Insert your own code here, using values in row and column ; CALL PRINT DB ESC,'=',0 ; ADM-3A leadin LD A,(ROW) ; Row first ADD A,' ' ; Add offset CALL COUT LD A,(COL) ; Sane for column ADD A,' ' CALL COUT ; ; <== end of your own code ; RET ; ROW: DS 2 ; Row COL: DS 2 ; Column ; ; Clear screen ; CLS: CALL PRINT DB ESC,'*',0 RET ; ; Inverse video on ; INVON: CALL PRINT DB ESC,'G4',0 RET ; ; Inverse video off ; INVOFF: CALL PRINT DB ESC,'G0',0 RET ; ; Turn off cursor ; HIDE: CALL PRINT DB ESC,'.1',0 RET ; ; Turn on cursor ; SHOW: CALL PRINT DB ESC,'.3',0 RET ; ; Save cursor position ; SAVECU: RET ; ; Restore cursor position ; RESCU: RET ; ;----------------------------------------------------------------------- ; ; Service modem interrupt ; MINT: RET ; My system doesn't need this ; ; Initialise interrupt vectors ; INVEC: RET ; Ditto ; ; De-initialise interrupt vectors ; DINVEC: RET ; Ditto ; ; User-defined entry routine: leave empty if not used ; USERIN: RET ; ; User-defined exit routine: leave empty if not used ; USEROUT:RET ; ;------------------- End of user-defined code -------------------------- ; Do not change anything below here ; ; Modem character test for 100 ms ; MRD: PUSH BC ; Save BC LD BC,100 ; Set limit ; MRD1: CALL MIRDY ; Char at modem? JR NZ,MRD2 ; Yes, exit LD HL,1 ; Else wait 1 ms CALL WAITHLMS DEC BC ; Loop till done LD A,B OR C JR NZ,MRD1 LD HL,0 ; None there, result=0 XOR A ; MRD2: POP BC RET ; ; Inline print routine: destroys A and HL ; PRINT: EX (SP),HL ; Get address of string ; PLOOP: LD A,(HL) ; Get next INC HL ; Bump pointer OR A ; Done if zero JR Z,PDONE CALL COUT ; Else print JR PLOOP ; And loop ; PDONE: EX (SP),HL ; Restore return address RET ; And quit ; ; Output a character in A to the console ; COUT: PUSH BC ; Save registers PUSH DE PUSH HL LD E,A ; Character to E LD C,2 CALL BDOS ; Print it POP HL POP DE POP BC RET ; ; Wait(seconds) ; WAIT: LD HL,2 ADD HL,SP EX DE,HL ; Get delay size CALL GETPARM ; ; Fall thru to... ; Wait seconds in HL ; WAITHLS:PUSH BC ; Save BC PUSH DE ; DE PUSH IX ; And IX LD IX,0 ; Then point IX to 0 ; ; so we don't upset memory-mapped I/O ; ; Calculate values for loop constants. Need to have two loops to avoid ; 16-bit overflow with clock speeds above 9 MHz. ; OUTERVAL EQU (CLKSPD / 10) + 1 ; INNERVAL EQU (6667 / OUTERVAL) * CLKSPD ; WAIT10: LD B,OUTERVAL ; WAIT11: LD DE,INNERVAL ; WAIT12: BIT 0,(IX) ; Time-wasters BIT 0,(IX) BIT 0,(IX) ; 20 T-states each BIT 0,(IX) BIT 0,(IX) BIT 0,(IX) DEC DE LD A,E LD A,D OR E JR NZ,WAIT12 ; 150 T-states per inner loop DJNZ WAIT11 ; Decrement outer loop DEC HL ; Ok, decrement count in HL LD A,H OR L JR NZ,WAIT10 POP IX ; Done -- restore IX POP DE ; DE POP BC ; And BC RET ; ; Wait milliseconds ; MSWAIT: LD HL,2 ADD HL,SP EX DE,HL ; Get delay size CALL GETPARM ; ; Wait milliseconds in HL ; WAITHLMS: PUSH DE ; W1MS0: LD DE,39 * CLKSPD ; W1MS1: DEC DE LD A,D OR E JR NZ,W1MS1 DEC HL LD A,H OR L JR NZ,W1MS0 POP DE RET ; ; Get next parameter from (DE) into HL ; GETPARM:EX DE,HL ; Get address into HL LD E,(HL) ; Get low INC HL LD D,(HL) ; Then hihi INC HL ; Bump for next EX DE,HL ; Result in HL, address still in DE RET ; ;Get address of user-defined variables ; GETVARS: LD HL,USERVARS RET USERVARS: DW OVERDRIVE ; .OVR etc. drive/user DW OVERUSER ; IF ($ - CODEBGN) GT OVSIZE TOOBIG: JP ERRVAL ; Overlay is too large ENDIF ; END