;	DMPSCRX.ASM
;	Written by Robert J. King, Pittsburgh, PA
;	for the Osborne Executive
;	Based on DMPSCR.BAS on 
;
;
CR	EQU	0DH
LF	EQU	0AH
ML	EQU	128
NSVCH	EQU	80
BASE	EQU	0C000H
XEND	EQU	0CBCFH
NDBS	EQU	XEND-BASE+1
;
	ORG	100H
	LXI	H,STACK
	SPHL
	LXI	H,80H
	SHLD	SAVEHL
	MVI	A,80H
	STA	NCH
	LXI	H,BASE
	LXI	B,NDBS
	MVI	A,65
	OUT	0
LP1	MOV	A,M
	CPI	128
	JNC	MN2
	INX	H
	DCX	B
	MOV	A,C
	ORA	B
	JNZ	LP1
MN2	SHLD	CRSIN
;
;	STA	08000H
;	SHLD	8002H
;	JMP	0
;
	SHLD	SCRPTR
	PUSH	H
	CALL	SETDMA
	CALL	DELFILE
	CALL	MAKFILE
	POP	H
	MOV	A,M
	SUI	128
	CALL	PUTCH
	MVI	A,1
	STA	COLPTR
	LHLD	CRSIN
	INX	H
	SHLD	JHL
;
;	STA	8000H
;	SHLD	8002H
;	LXI	H,XEND
;	SHLD	8004H
;	JMP	0
;
	LXI	H,XEND
	CALL	SR1
;	CALL	PART1
	LXI	H,BASE
	SHLD	JHL
	LHLD	CRSIN
	DCX	H
	MVI	A,1
	STA	COLPTR
	CALL	SR1
	CALL	WEOF
	LXI	D,MSG1
	MVI	C,9
	CALL	5
	MVI	A,1
	OUT	0
	JMP	0
;
SETDMA	LXI	D,80H
	MVI	C,1AH
	JMP	5
;
DELFILE	LXI	D,FCB
	MVI	C,13H
	JMP	5
;
MAKFILE	LXI	D,FCB
	MVI	C,16H
	JMP	5
;
PUTCH	PUSH	H
	PUSH	D
	LHLD	SAVEHL
	MOV	M,A
	INX	H
	SHLD	SAVEHL
	LDA	NCH
	DCR	A
	STA	NCH
	JNZ	PT2
;	CALL	PXX
	CALL	WRSEQ
	ORA	A
	JNZ	ERROR
PT2	POP	D
	POP	H
	RET
;
SR1	SHLD	LIMIT
LP2	LDA	COLPTR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