;*** Spectrum Tape Header Reader ***
;by Steve Smith - www.ProjectSPECCY.com - V1.01 circa. 1991
;
;Licence: Public Domain
;
;Pasmo 0.5.3 source
;
;Clear 25499, load code at 25500 and RANDOMIZE USR 25500
;to read tape header
;

ORG	25500

START:
PR_STRING:		EQU		8252	;ROM Print a string routine
LD_BYTES:		EQU		1366	;ROM Load data routine
CHAN_OPEN		EQU		5633	;ROM Prepare screen for printing

BEGIN:	
		CALL	PRNTIT
		CALL	LDHEADR
		CALL	PRNFN
		LD		A,(HEADER)
		CP		0
		JP		Z,BASIC
		CP		1
		JP		Z,NUMARRAY
		CP		2
		JP		Z,STRARRAY
		CP		3
		JP		Z,CODE
UNNOWN:
		JP		UNKNOWN
LDHEADR:
		LD		DE,17
		LD		IX,HEADER
		XOR		A
		SCF
		CALL	LD_BYTES
		JP		NC,LDHEADR
		RET
HEADER:
		DS		17
PRNTIT:
		LD		A,2
		CALL	CHAN_OPEN
		LD		DE,TITLE
		LD		BC,38
		CALL	PR_STRING
		RET
TITLE:
		DB		19,1,"****** TAPE HEADER READER ******",19,0,13,13
PRNFN:
		LD		DE,FILEMSG
		LD		BC,10
		CALL	PR_STRING
		LD		DE,HEADER+1
		LD		BC,10
		CALL	PR_STRING
		CALL	ENT2
		RET
FILEMSG:
		DB		"Filename:  "
BASIC:
		LD		DE,BASMSG
		LD		BC,9
		CALL	PR_STRING
		CALL	ENT2
		LD		DE,STMSG
		LD		BC,6
		CALL	PR_STRING
		LD		HL,(HEADER+13)
		CALL	PRNNUM
		CALL	ENT2
		LD		A,13
		RST		16
		LD		A,13
		RST		16
		LD		DE,PLENMSG
		LD		BC,16
		CALL	PR_STRING
		LD		HL,(HEADER+15)
		CALL	PRNNUM
		CALL	ENT2
		LD		DE,BLENMSG
		LD		BC,14
		CALL	PR_STRING
		LD		HL,(HEADER+11)
		CALL	PRNNUM
		CALL	ENT2
		RET
STMSG:
		DB		"Line:  "
PLENMSG:
		DB		"Program Length:  "
BLENMSG:
		DB		"Block Length:  "
BASMSG:
		DB		19,1,"BASIC", 19,0
NUMARRAY:
		LD		DE,NAMMSG
		LD		BC,17
		CALL	PR_STRING
		CALL	ENT2
		LD		DE,NMMSG
		LD		BC,12
		CALL	PR_STRING
		LD		A,(HEADER+14)
		SUB		32
		RST		16
		CALL	ENT2
		LD		DE,BLENMSG
		LD		BC,14
		CALL	PR_STRING
		LD		HL,(HEADER+11)
		CALL	PRNNUM
		CALL	ENT2
		RET
NAMMSG:
		DB		19,1,"Numeric Array",19,0
NMMSG:
		DB		"Array Name:  "
STRARRAY:
		LD		DE,STRMSG
		LD		BC,16
		CALL	PR_STRING
		CALL	ENT2
		LD		DE,STRGMSG
		LD		BC,12
		CALL	PR_STRING
		LD		A,(HEADER+14)
		SUB		128
		RST		16
		LD		A,"$"
		RST		16
		CALL	ENT2
		LD		DE,BLENMSG
		LD		BC,14
		CALL	PR_STRING
		LD		HL,(HEADER+11)
		CALL	PRNNUM
		CALL	ENT2
		RET
STRMSG:
		DB		19,0,"String Array",19,0
STRGMSG:
		DB		"Array Name:  "
CODE:
		LD		DE,CDMSG
		LD		BC,8
		CALL	PR_STRING
		CALL	ENT2
		LD		DE,CDSMSG
		LD		BC,7
		CALL	PR_STRING
		LD		HL,(HEADER+13)
		CALL	PRNNUM
		CALL	ENT2
		LD		DE,BLENMSG
		LD		BC,14
		CALL	PR_STRING
		LD		HL,(HEADER+11)
		CALL	PRNNUM
		CALL	ENT2
		RET
CDMSG:
		DB		19,1,"Code",19,0
CDSMSG:
		DB		"Start:  "
UNKNOWN:
		LD		DE,UKMSG
		LD		BC,11
		CALL	PR_STRING
		CALL	ENT2
		LD		DE,TPMSG
		LD		BC,6
		CALL	PR_STRING
		LD		A,(HEADER)
		LD		L,A
		LD		H,0
		CALL	PRNNUM
		CALL	ENT2
		RET
UKMSG:
		DB		19,1,"UNKNOWN",19,0
TPMSG:
		DB		"Type:  "
DIV10:
		LD		DE,0
		LD		BC,10
		XOR		A
DVLP:
		INC		DE
		SBC		HL,BC
		JR		NC,DVLP
		ADC		HL,BC
		DEC		DE
		DEC		HL
		EX		DE,HL
		LD		A,E
		RET
PRNNUM:					;Print 16-Bit Number
		XOR		A
		PUSH	AF
LOOP:
		CALL	DIV10
		ADD		A,"0"
		PUSH	AF
		LD		A,H
		OR		L
		JR		NZ,LOOP
LOOPB:
		POP		AF
		OR		A
		RET		Z
		RST		16
		JR		LOOPB
ENT2:
		LD		A,13
		RST		16
		LD		A,13
		RST		16
		RET
END		START
