	NAM	HEXLDR	VER 2.0

* COPYRIGHT (C) 1978 PERCOM DATA CO. INC.
* ALL RIGHTS RESERVED
* WRITTEN BY H.A. MAUCH
* MODIFIED FOR MINIDOS 1.4 AUG 20, 1978
*************************************************
* THIS PROGRAM READS AND CONVERTS THE ASCII-HEX
* OBJECT FILE CREATED BY THE ASSEMBLER TO BINARY.
* THE BINARY CODE IS THEN STORED IN MEMORY FOR
* PROGRAM EXECUTION. REQUIRES MINIDOS VERSION 1.4.
*
* ALTHOUGH THIS LISTING WAS ASSEMBLED TO START AT
* ADDRESS $2000, 'HEXLDR' IS RELOCATABLE AND MAY
* BE PLACED ANYWERE IN MEMORY. 'HEXLDR' AND ITS
* BUFFER REQUIRE 470 BYTES OF CONTIGUOUS MEMPORY.
* 'HEXLDR' ALSO USED 14 BYTES OF THE MONITOR RAM
* ($A040-$A057) FOR TEMPORARY POINTER STORAGE.
**************************************************
*
* KEYED IN FROM THE LFD-400 SYSTEMS MANUAL BY
* MIKE DOUGLAS 1/10/2020
*
TRKSEC	EQU	$01
FWDLNK	EQU	$05
BYTCNT	EQU	$07
TW	EQU	$16
EOF	EQU	$FF		END OF FILE FLAG
RDSEC	EQU	$C00C
TYPERR	EQU	$C01E
PCRLF	EQU	$C363
CVTDTS	EQU	$C003
PDATA	EQU	$E07E
BADDR	EQU	$E047

	ORG	$A04A
DSKFIL	RMB	2
DSKPTR	RMB	2
BYTECT	RMB	1
BUFCNT	RMB	1
BUFADD	RMB	2
BUFPTR	RMB	2
ADDRES	RMB	2
XTEMP1	RMB	2	

	ORG	$2000
LOAD	LDS	#$A07F		SET STACK
	BSR	HERE		THIS SEQUENCE PERMITS THIS
HERE	TSX			TO BE LOCATED ANYWHERE
	NOP
	LDAA	1,X
	ADDA	#PROMPT-HERE
	STAA	BUFADD+1
	LDAA	0,X
	ADCA	#0
	STAA	BUFADD
	JSR	PCRLF
	LDX	BUFADD
	JSR	PDATA
	INX
	STX	BUFADD
	JSR	BADDR		GET FILE
	JSR	CVTDTS
	BCS	ERR
	LDX	TRKSEC
	STX	DSKFIL
	STX	DSKPTR
	LDAA	#1
	STAA	BUFCNT

LOAD3	BSR	GETCHR
	BEQ	LOAD
	CMPA	#'S
	BNE	LOAD3
	BSR	GETCHR
	BEQ	LOAD
	CMPA	#'9
	BEQ	LOAD
	CMPA	#'1
	BNE	LOAD3
	BSR	ONEBYT		GET BYTE COUNT
	SUBA	#2
	STAA	BYTECT
	BSR	TWOBYT
LOAD11	BSR	ONEBYT
	DEC	BYTECT
	BEQ	LOAD3
	STAA	0,X
	INX
	BRA	LOAD11

ERRE	LDAA	#$E		WHAT?
ERR	JSR	TYPERR		ERROR TRAP
	BRA	LOAD		UNSTRUCTURED RETURN

TWOBYT	BSR	ONEBYT
	STAA	ADDRES
	BSR	ONEBYT
	STAA	ADDRES+1
	LDX	ADDRES
	RTS
ONEBYT	BSR	GETHEX
	ASLA
	ASLA
	ASLA
	ASLA
	TAB
	BSR	GETHEX
	ABA
	RTS
GETHEX	BSR	GETCHR
	BEQ	ERRE
	SUBA	#$30		REMOVE ASCII OFFSET
	CMPA	#9
	BLE	GH1
	SUBA	#7
GH1	RTS

GETCHR	STX	XTEMP1		SAVE INDEX
	PSHB			SAVE B
	DEC	BUFCNT		BUMP DISK BUFFER COUNTER
	BNE	GETC1		BRANCH IF NOT EMPTY
	LDAA	#EOF		END OF FILE DEFAULT
	LDX	DSKPTR
	BEQ	GETC2		BRANCH IF END OF FILE
	BSR	GTSCTR		GET NEXT SECTOR
	BCS	ERR		BRANCH IF ERROR
	LDX	BUFADD		POINT TO DISK BUFFER
	STX	BUFPTR
	LDAA	BYTCNT		GET BYTE COUNT
	STAA	BUFCNT
GETC1	LDX	BUFPTR		GET DISK BUF PTR
	LDAA	0,X		GET CHARACTER
	INX
	STX	BUFPTR
GETC2	LDX	XTEMP1
	PULB			RESTORE B
	CMPA	#EOF
	CLC
	RTS

* GET A SECTOR OF DATA FROM DISK
* ON ENTRY, X CONTAINS TRK-SEC
GTSCTR	STX	TRKSEC		SET UP DISK HEADER
	LDX	BUFADD		SET UP TARGET ADDRESS
	STX	TW
	JSR	RDSEC		READ THE SECTOR
	BCS	GTS1		BRANCH IF ERROR
	LDX	FWDLNK
	STX	DSKPTR		PUT IN DISK PTR
GTS1	RTS

PROMPT	FCC	'FILE?'
	FCB	$04
BUFF	RMB	256
	END

