;   GETSYS.COM
;	CP/M Reader for my 8080 microcomputer
;	JWD - v1.0   11/21/2025   
;
;   Run from working CP/M OS
;
;
	CPU 8080        ; Specify architecture
	PAGE 0
;
;
cpmstart	equ	2000h	;Initial memory location of CP/M memory image
cpmsize		equ 36h		;Size of CP/M image in sectors
secsize		equ	80h		;Disk logical sector size
;
; Deblocking parameters
;
wrall	equ	0		;write to allocated
wrdir	equ	1		;write to directory
wrual	equ	2		;write to unallocated
;
; BIOS entry points
;
warm    equ 0f403h  ;Warm restart
conout  equ 0f40ch  ;Console output
seldsk	equ	0f41bh	;Select disk
settrk	equ	0f41eh	;Set track
setsec	equ	0f421h	;Set sector
setdma  equ	0f424h	;Set transfer address
read	equ	0f427h	;Read sector
;
	org	0100h		;origin of this program
;
start:
	lxi d, gsstart	;Point to end message
	call biosprint	;Print it
;
	mvi a, cpmsize	;Sector transfer count
	sta seccnt		;Save it
    mvi a, 4		;Starting sector
    sta secpos      ;Save it
    mov c, a		;Transfer it to C
	call setsec		;Select sector 4
	mvi c, 0  		;Set drive 0
	call seldsk		;Select drive 0
	mvi c, 0  		;Set track 0
	call settrk		;Select track 0
	lxi h, cpmstart	;Starting DMA position
	shld dmapos		;Save it
start01:
	mov b, h
	mov c, l
	call setdma		;Select dma position
;
	call read		;Read the first track
;
    lda secpos		;Get current sector position
	inr a			;Point to next sector
	sta secpos		;Save it
    mov c, a		;Transfer it to c register
	call setsec		;Set next sector
;
    lda seccnt		;Get sector counter
	dcr a			;Decrement the sector count
	sta seccnt		;Save sector counter
	lhld dmapos		;Get current DMA address
	lxi b, secsize	;Get sector size
	dad b			;Add byte increment
    shld dmapos		;Save DMA address
	jnz start01		;If not zero, do next sector
;
	lxi d, gsend	;Point to end message
	call biosprint	;Print it
exit:
	jmp warm		;Restart CP/M
;
biosprint:			;Print a message on the console
	ldax d			;Get char pointed to by D into A
	cpi 0			;End of string?
	jz biospend		;Exit if end of string
	mov c, a		;Move shar into C for console out
	call conout		;Print it
	inx d			;Point to next character
	jmp biosprint	;Repeat
biospend:
	ret				;And exit
;
;   GETSYS variables
;
dmapos:
	dw 0
secpos:
	db 0
seccnt:
	db 0
;
;   GETSYS messages
;
gsstart:
    db 'Reading CP/M from ATA drive'
    dw 0d0ah
	db 0
gsend:
    db 'CP/M read completed'
    dw 0d0ah
	db 0
;
;
	end