	TITLE	'DBBOOT secondary coldstart loader  4-8-81'
;
; tarbell electronics cp/m coldstart loader
; version of 3-21-81.
; for deblocked operating system only
; modified for tarbell cpu card  -  7-3-80.
; modified for deblock   3-21-81
; modified for head loaded check -  4-8-81
; removed dma code (never worked) - 6-9-81
; added code to clear extended latch 6-26-81
; g.w.mulchin
; tarbell electronics
;-------------------------------------------------
; copyright (c) 1980 tarbell electronics
;
; this program is loaded at location zero by the
; bootstrap program, and executed. its purpose
; is to load and execute the cp/m disk
; operating system at the top of the memory in use.
;
FALSE	EQU  0000H
TRUE	EQU  NOT FALSE	;define value of true.
;
;********* this is the area to make changes in ***********
;********* for different system configurations ***********
;							**
MSIZE	EQU  63		;memory size in decimal kbytes.	**
MAC	EQU  FALSE	;true if using macro assembler	**
TARBELL	EQU  TRUE	;true if using tarbell cpu.	**
DUBSID	EQU  FALSE	;true for double sided systems.	**
DELTA	EQU  FALSE	;true if using delta cpu card	**
BASE	EQU  0		;tarbell i/o ports (00 or10 hex)**
SPT	EQU  26		;number of sectors per track.	**
DDS	EQU  08		;sectors trk 1 (rng = 8 to 16)	**
DISK	EQU  0F8H	;disk port base address.	**
;							**
;*********************************************************
;
	IF	MAC
	MACLIB	Z80
	ENDIF
;
	IF   TARBELL
IO	EQU  BASE	;i/o ports on tarbell cpu.
MMENB	EQU  IO+10	;memory management enable port.
MEMMAG	EQU  BASE+32	;memory management port.
	ENDIF

DCOM	EQU  DISK	;command port.
DSTAT	EQU  DISK	;status port.
TRACK	EQU  DISK+1	;track port.
SECT	EQU  DISK+2	;sector port.
DATA	EQU  DISK+3	;data port.
WAIT	EQU  DISK+4	;wait port.
DCONT	EQU  DISK+4	;control port.
EXTMEM	EQU  DISK+5	;extended latch port
PANEL	EQU  0FFH	;front panel machines.
CBASE	EQU  (MSIZE-20)*1024
CPMB	EQU  CBASE+3400H;start of cp/m.
BOOTE	EQU  CPMB+1600H	;cold boot entry point.
SDS	EQU  25		;always 25 sectors to read in trk 1.
NSECTS	EQU  SDS + DDS	;sectors of cp/m.
RTCNT	EQU  10		;number of retrys.
;
	ORG  0		;start of loader.
;
BOOT:
	IF   TARBELL	;if using tarbell cpu
	LXI  B,16 SHL 8 OR MEMMAG
	MVI  A,0FFH
MLOOP:	OUTP A		;send a by way of port c
	DCR  A		;next init byte
	INR  C		;bump port
	DJNZ MLOOP	;decrease count and loop
	OUT  MMENB	;enable memory management.
	ENDIF
;
	IF   DELTA	;if using delta cpu.
	MVI  A,1	;get a 1 in reg a.
	OUT  9		; and disable cpu rom slot.
	ENDIF
;
	XRA  A		;get a zero
	OUT  EXTMEM	;clear the latch on disk board
	MVI  E,RTCNT	;get retry count.
BLOOP:	LXI  SP,100H	;set stack pointer.
	LXI  H,CPMB	;cp/m starts here.
	MVI  D,NSECTS	;number of sectors to read.
	MVI  C,2	;sector number.
RNTRK:	MVI  B,4	;for head load.
RNSEC:	CALL READ	;read first sector.
	DCR  D		;if done,
	JZ   BOOTE	;go to cp/m.
	MVI  B,0	;for no head load.
	INR  C		;increment sector count.
	MOV  A,C	;done with
SECCMP:	CPI  SPT+1	;this track?
	JRC  RNSEC	;if not, read next sector.
;
	IF   NOT DUBSID
	MVI  A,8H	;set doub dens code
	OUT  WAIT	;set latch for d.density
	MVI  A,5BH	;step command.
	OUT  DCOM	;issue it.
	IN   WAIT	;wait until done.
	ENDIF
;
	IF   DUBSID	;if double sided system.
	MVI  A,48H	;set doub dens & side select command.
	OUT  WAIT	;issue it.
	ENDIF
;
	MVI  C,1	;sector number.
	JMPR RNTRK	;read next track.
;
READ:	MOV  A,C	;sector in a.
	OUT  SECT	;set sector register.
	MVI  B,80H	;command for read.
	IN   DSTAT	;check head loaded
	ANI  20H	;mask for head bit
	MVI  A,0
	JRZ  HDLD	;head not loaded
	MVI  A,4
HDLD:	ORA  B		;get head load bit.
	OUT  DCOM	;issue command.
RLOOP:	IN   WAIT	;wait for drq.
	ORA  A		;set flags.
	JP   CHECK	;jump if done.
	IN   DATA	;read data.
	MOV  M,A	;put in memory.
	INX  H		;increment pointer.
	JMPR RLOOP	;loop until done.
;
CHECK:	IN   DSTAT	;read status.
	ANI  9DH	;look at error bits.
	RZ		;ok if zero.
	DCR  E		;decrement retry count.
	JRNZ BLOOP	;try again if not zero.
HERE:	JMPR HERE	;loop.
;
	ORG  7DH	;put jump here.
	RST  0		;jump to loc. 0
;
	IF   NOT DUBSID
	DB   0DEH
	DB   0
	ENDIF

	IF   DUBSID
	DB   0DCH
	DB   0
	ENDIF

	END   BOOT	;end of boot.
