; TARBELL CP/M COLD START LOADER
; STANDARD VERSION OF 10-11-77
;
; THIS PROGRAM IS LOADED AT LOCATION
; 0 BY THE BOOTSTRAP PROGRAM, AND RUN.
; IT'S PURPOSE IS TO LOAD AND RUN THE MAIN
; CP/M DISK OPERATING SYSTEM AT THE TOP OF
; THE MEMORY IN USE.
;
MSIZE	EQU  47		;MEMORY SIZE (minus 1)
DCOM    EQU  0F8H
DSTAT   EQU  0F8H
TRACK   EQU  0F9H
SECT    EQU  0FAH
DDATA   EQU  0FBH
WAIT    EQU  0FCH
CBASE   EQU  (MSIZE-16)*1024
CPMB    EQU  CBASE+2900H
BOOTE   EQU  CBASE+3E00H
NSECTS  EQU  51		;NUMBER OF SECTORS.
	ORG  0
BOOT:   LXI  SP,100H
BOOT1:  LXI  B,2
	MVI  D,NSECTS
	LXI  H,CPMB
RBLK    MOV  A,B
	OUT  DDATA
	IN   DSTAT
	RRC
	MVI  A,1
	JC   ERROR
	MVI  A,13H
	OUT  DCOM
	IN   WAIT
	ORA  A
	MVI  A,1
	JM   ERROR
	IN   DSTAT
	ANI  91H
	JNZ  ERROR
	MOV  A,C
	CALL READ
RBLK1:  JNZ  ERROR
	DCR  D
	JZ   BOOTE
	INR  C
	MOV  A,C
	CPI  27
	JC   RBLK2
	MVI  C,1
	INR  B
	JMP  RBLK
;
RBLK2:  MOV  A,C
	CALL READ1
	JMP  RBLK1
;
;
READ1:  OUT  SECT
	IN   DSTAT
	RRC
	MVI  A,1
	JC   RERR
	MVI  A,88H
	JMP  READE
;
READ:   OUT  SECT
	IN   DSTAT
	RRC
	MVI  A,1
	JC   RERR
	MVI  A,8CH
READE:  OUT  DCOM
RLOOP:  IN   WAIT
	ORA  A
	JP   RDONE
	IN   DDATA
	MOV  M,A
	INX  H
	JMP  RLOOP
;
RDONE:  IN   DSTAT
RERR:   ANI  9DH
	RET
;
;
ERROR:  CMA
	OUT  0FFH
	HLT
;
;
	ORG  7DH
	JMP  0
	END
