home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Oakland CPM Archive
/
oakcpm.iso
/
cpmug
/
cpmug015.ark
/
MDGCBIOS.ASM
< prev
next >
Wrap
Assembly Source File
|
1984-04-29
|
7KB
|
378 lines
.TITLE /CPM-CBIOS FOR Z80 CPU MDG 12-26-77/
;BASIC IO OPERATING SYSTEM (CBIOS) FOR CPM
;WRITTEN BY M. D. GRAY 12/26/77
;SUPPORTS:
; Z80 CPU
; DUAL PERSCI 270 (277 MODIFIED)
; AT LEAST 17K OF RAM
; 2-SIO MITS DUAL SERIAL ADDRESSED AT 0,1,2,3
; VDM-3A VIDEO CONSOLE @2,3
; SILENT 700 @0,1
;
.PABS
.PHEX
.XLINK
.SALL
MSIZE =\ "INPUT MEMORY SIZE IN K="
DADR == 0F8H ;DISK ADDRESS
DCOM == DADR ;DISK COMMAND PORT
DSTAT == DADR ;DISK STATUS PORT
TRACK == DADR+1 ;DISK TRACK REGISTER
SECTP == DADR+2 ;DISK SECTOR REGISTER
DDATA == DADR+3 ;DISK DATA REGISTER
WAIT == DADR+4 ;WAIT FOR DATA-INTERRUPT
ERCNT == 10 ;ERROR RETRY COUNT
.LOC MSIZE*400H-600H ;CBIOS SPOT
CBASE == (MSIZE-17)*1024 ;BIAS FOR CPM
CPMB == CBASE+2900H ;START OF CP/M
BDOS == CBASE+3206H ;START OF BDOS
CPML == .-CPMB ;LENGTH OF CP/M
NSECTS == CPML/128 ;NUMBER OF SECTORS
;
;MACRO DEFINITIONS
;
.DEFINE PRINT$[MESLOC]=[
CALL MESS
.WORD MESLOC]
.DEFINE WAIT$ = [
XTHL
XTHL]
;
;JUMP TABLE
;
JMP BOOT ;FROM COLD START
WBOOTE: JMP WBOOT ;WARM START
JMP CONST ;CONSOLE STATUS
JMP CONIN ;READ A CHARACTER FROM CONSOLE
JMP CONOUT ;WRITE A CHARACTER TO CONSOLE
JMP LIST ;WRITE A CHAR TO LIST DEVICE
JMP PUNCH ;WRITE A CHAR TO PUNCH DEVICE
JMP READER ;READ A CHAR FROM READER
JMP HOME ;SEEK TRACK 0
JMP SELDSK ;SELECT DISK
JMP SETTRK ;SELECT TRACK
JMP SETSEC ;SET SECTOR (1-26)
JMP SETDMA ;SET START OF 128 BYTE TRANSFER
JMP READ ;READ A SECTOR
JMP WRITE ;WRITE A SECTOR
JMP . ;RESERVED
JMP . ;RESERVED
;
;MISC CBIOS VARIABLES
;
DISKSL: .BYTE 0 ;DISK SELECTED
DMAADD: .WORD CPMB ;DMA ADDRESS
TESTM: .BYTE 0 ;TEST MODE
ERRORS: .BYTE 0,0,0,0 ;ERROR COUNTERS-
;CRC,SEEK,-,-
;
;STACK SWAP ROUTINE WITH REGISTER SAVE
;
SSWAP: XTHL ;GET RETURN ADDRESS
SHLD ..RET ;AND SAVE IT FOR EXIT
POP H ;RECOVER (HL)
SSPD USTACK ;SAVE USER STACK
LXI SP,CBSTAK ;LOAD LOCAL STACK
PUSH B ;SAVE WORKING REGISTERS
PUSH D
PUSH H
LXI H,EXITRT ;SAVE RETURN EXIT IS STACK
PUSH H
JMP . ;DUMMY EXIT TO BE STUFFED
..RET == .-2
EXIT: LXI SP,CBSTAK-6 ;DIRTY STACK EXIT
EXITRT: POP H ;CLEAN STACK EXIT
POP D ;RESTORE REGISTERS
POP B
ANA A
LSPD USTACK ;GET ORIG STACK
RET ;EXIT CBIOS
;
;BOOT - COLD START CP/M LOAD ROUTINE
;
BOOT: MVI A,3 ;RESET AND INITALIZE TI-700
OUT 0 ;AND VDM
OUT 2
MVI A,9
OUT 0
OUT 2
MVI A,0FFH
OUT 0FFH ;CLEAR TYE DISPLAY LIGHTS
LXI SP,80H
PRINT$ SIGNON ;SIGN ON MESSAGE
MVI A,1 ;DEFINE CONSOLE = CRT
STA 3 ;CLEAR IOBYTE
;
;WARM BOOT
;
WBOOT: LXI SP,80H ;SET BOOT STACK
MVI B,ERRORS-DISKSL
LXI H,DISKSL ;ZERO DISK PARAM TABLE
..L: MVI M,0
INX H
DJNZ ..L
MVI A,0F2H
OUT WAIT
CALL HOME
MVI C,2
CALL SETSEC ;LOAD FROM SECTOR 2
MVI B,NSECTS ;LOOP UNTIL ALL CP/M SCTRS RD
LXI H,CPMB ;LOAD AT CP/M BASE
LXI D,80H ;SECTOR SIZE
..LOOP: SHLD DMAADD ;CURRENT LOAD ADDRESS
DAD D ;PREPARE FOR NEXT SECTOR ADR
CALL READ ;READ A SECTOR
CPI 1 ;SECTOR IN ERROR ?
CZ BOOTER ;GO DO ERROR THING
INR C ;INCREMENT SECTOR COUNT
MOV A,C
CPI 27 ;SEE IF WE NEED A NEW TRACK
JRC ..U ;NO, STILL OK
MVI C,1 ;IF NEW TRACK THEN TRK AND SEC=1
CALL SETTRK
..U: CALL SETSEC
DJNZ ..LOOP ;LOOP UNTIL ALL READ
MVI A,0C3H ;INIT JMP LOC IN PAGE 0
STA 0
LXI H,WBOOTE
SHLD 1
STA 5
LXI H,BDOS
SHLD 6
LXI H,80H
SHLD DMAADD ;INIT DMA ADDRESS TO 80H
MVI C,0 ;SELECT DRIVE 0 FOR SYSTEM
JMP CPMB ;EXIT AFTER SUCCESSFUL BOOT
;
;CHECK CONSOLE STATUS
;
CONST: IN 2 ;CONSOLE STATUS
ANI 1 ;CHECK DATA READY
MVI A,255
RNZ
CMA
RET
;
;READ A CHARACTER FROM THE CONSOLE
;
CONIN: IN 2
ANI 1
JRZ CONIN ;WAIT FOR CHARACTER
IN 3
ANI 7FH
RET
;
;CHARACTER OUT TO CONSOLE
;
CONOUT: IN 2
ANI 2
JRZ CONOUT
MOV A,C
OUT 3
RET
LIST: MOV A,C ;STRIP MSB
ANI 7FH ;AND CHECK FOR (CR)
CPI 13
JRZ ..CR ;GO INSERT NULLS
..L: IN 0 ;TEST STATUS
ANI 2
JRZ ..L
MOV A,C
OUT 1
RET
..CR: CALL ..L ;OUTPUT THE (CR)
PUSH B
MVI B,6
MVI C,0 ;OUTPUT NULLS
..L1: CALL ..L ;SIX TIMES
DJNZ ..L1
POP B
MOV A,C
RET
;
READER: CALL 0F006H ;JUMP TO TDL READER
JRC ..EOF ;CONVERT CARRY TO 1AH
ANI 7FH
RET
..EOF: MVI A,1AH
RET
;
;PUNCH DEVICE
;
PUNCH: JMP 0F00CH ;JMP TO TDL MONITOR PUNCH DEVICE
;
;HOME - RESTORE TO TRACK 0 WITH HEAD LOADED
;
HOME: MVI A,0EH ;RESTORE,HDLD,VERIFY
CALL EXECC ;EXECUTE COMMAND
RET
;
;SELDSK - SELECT DISK 0 OR 1 (A OR B)
;ALWAYS DONE PRIOR TO SETTRK,SETSEC
;
SELDSK: LDA DISKSL ;TEST TO SEE IF NOT SELCTED
CMP C
RZ ;RETURN IF ALREADY SELECTED
CPI 2 ;CHECK PARAMETERS
CNC SELERR
MOV A,C
STA DISKSL ;SAVE NEW SELECTED DISK
IN TRACK ;SEEK TO SAME PLACE
OUT DDATA ;BUT UNLOAD HEAD
MVI A,12H
CALL EXECC
BIT 0,C ;TEST DISK SELECTED
MVI A,0F2H ;DISK 0
JRZ ..L
MVI A,0C2H ;DISK 1
..L: OUT WAIT
XRA A
RET
;
;SETTRK - SELECT TRACK 0 - 76
;
SETTRK: MOV A,C ;CHECK PARAMETERS
CPI 77
CNC TRKERR ;RANGE ERROR
IN TRACK
CMP C ;IF NO CHANGE TO TRACK - EXIT
RZ
MOV A,C
OUT DDATA ;DO A SEEK WITH VERIFY
MVI A,1EH
CALL EXECC
RET
;
;SETSEC - SET SECTOR FROM 1-26
;
SETSEC: MOV A,C ;CHECK PARAMETERS
CPI 27
CNC SECERR
ANA A ;0 NOT ALLOWED
CZ SECERR
OUT SECTP
RET
;
;SETDMA - SET DMA ADDRESS FROM BC
;
SETDMA: SBCD DMAADD ;BC TO DMAADD
RET
;
;READ - READ A SECTOR
;
READ: CALL SSWAP ;SAVE STACK AND REGISTERS
MVI B,ERCNT ;INITIALIZE ERROR COUNT
..RTRY: MVI A,0D0H ;INTERRUPT TO TEST HDLD
OUT DCOM
WAIT$
LHLD DMAADD ;READ BUFFER START
IN DSTAT
ANI 20H ;CHECK HEAD LOAD
MVI A,88H
JRNZ ..L
ORI 4 ;HEAD NEEDS LOADING
..L: OUT DCOM
WAIT$
..LOOP: IN WAIT
RLC
JRNC ..DONE ;EXIT IF FINISHED
IN DDATA
MOV M,A
INX H
JMP ..LOOP
..DONE: IN DSTAT
ANI 9DH
RZ ;RETURN ON GOOD READ
CMA
OUT 0FFH ;DISPLAY ERROR
DJNZ ..RTRY
PRINT$ RDERR ;READ ERROR MESSAGE
MVI A,1
RET
;
;WRITE - WRITE A SECTOR FROM DMAADD
;
WRITE: CALL SSWAP ;SAVE STACK,REGS
MVI B,ERCNT ;ERROR RETRY COUNT
..WTRY: LHLD DMAADD
MVI A,0D0H ;INTERRUPT
OUT DCOM
WAIT$
IN DSTAT ;TEST FOR HEAD LOAD
ANI 20H
MVI A,0A8H
JRNZ ..L
ORI 4 ;HEAD NEEDS LOADING
..L: OUT DCOM
WAIT$
..LOOP: IN WAIT ;WRITE 128 BYTES
RLC
JRNC ..DONE
MOV A,M
OUT DDATA
INX H
JMP ..LOOP
..DONE: IN DSTAT ;CHECK FOR ERRORS
ANI 0FDH
RZ ;RETURN ON GOOD WRITE
CMA
OUT 0FFH
DJNZ ..WTRY ;RETRY ON ERROR
PRINT$ WERR
MVI A,1
RET
EXECC: OUT DCOM ;OUTPUT DISK COMMAND
WAIT$
..L: IN DSTAT
ANI 1 ;WAIT TILL COMMAND DONE
JRNZ ..L
IN DSTAT ;CHECK FOR ERRORS
ANI 10011000B
RZ
CMA
OUT 0FFH
PRINT$ COMERR
HLT
;
;MESS - PRINT MESSAGE AT LOC FOLLOWING CALL
; UNTIL BIT 7 IS TRUE
;
MESS: XTHL ;GET PARAMETER IN (DE)
MOV E,M
INX H
MOV D,M
INX H
XTHL
XCHG ;ADDRESS OF MESSAGE IS IN HL
..L: MOV C,M
CALL CONOUT
BIT 7,C
RNZ
INX H
JMPR ..L
;DATA TABLES
;
BOOTER:
SELERR:
TRKERR:
SECERR:
PRINT$ G1ERR
HLT
G1ERR: .ASCIS [13][10]/PARAMETER ERROR/
RDERR: .ASCIS [13][10]/READ ERROR/
WERR: .ASCIS [13][10]/WRITE ERROR/
COMERR: .ASCIS [13][10]/COMMAND ERROR/
SIGNON: .ASCII [1AH][13][10]/Z-80 CBIOS/
.ASCII [13][10]/WRITTEN BY M. D. GRAY 12-28-77/
.ASCIS [13][10]/REVISION 1.00/[13][10]
.BLKB 32
CBSTAK: .BLKB 4
USTACK: .BLKB 2
.END