; AMPATCH.ASM   PATCH FOR AUTOMITE.COM VERSION 1.61   6/6/86 GSD
;
; THIS PATCH:
;
;	1. ENSURES THAT THE 25th LINE ON THE SCREEN IS ERASED
;	2. ASSEMBLES WITH DRI'S MAC ASSEMBLER
;
; USE DDT TO PATCH AUTOMITE.COM:
;
; A>DDT AUTOMITE.COM
; NEXT PC
; 7600 0100
; #IAMPATCH.HEX
; #R
; #G0
; A>SAVE 117 AUTOMITE.COM
;
;
BDOS	equ	0005H	; BDOS ENTRY
ESC	equ	01BH	; ASCII ESCAPE CHARACTER
CTRLX	equ	'X'-40H	; CONTROL X (ERASE TO END OF LINE)
CTRLZ	equ	'Z'-40H ; CONTROL Z (HOME CURSOR, THEN ERASE SCREEN)
;
djnz	macro addr	; Z80 djnz macro
	db 10h
	db low addr-($+1)
	endm
;
	org	011bh	; id string
	db	'1.61'
;
	ORG 	100H	; start of TPA
;
	JMP	PATCH	; branch to patch code
;
	org	7206H	; end of program pointer

	DW	ENDPRG	; change pointer to protect patch

	ORG 	759dH	; start of patch area
;
patch:	lxi	sp,endprg
	call 	swap		; exchange BIOS Warm Boot vector
	lxi	h,line25	; turn off status line
	call	prnstr
	jmp	7208H		; execute AUTOMITE

;
;	This code intercepts the Warm Boot following the exit
;	from Automite.  This code:
;
;	    1.  Resotres the orginal Warm Boot vector at the BIOS
;		jump table level.
;	    2.  Ensures that the 25th line is cleared
;	    3.  Exits to the orginal Warm Boot routine
;
WBPATCH:
	lxi	sp,endprg
	call	swap		; restore BIOS Warm Boot vector
	lxi	h,line24	; restore status line
	call	prnstr
	rst	0		; Warm Boot
;
;	This code exchanges the BIOS jump table Warm Boot vector
;	for the vector stored locally.  This code is used to 
;	insert a Warm Boot patch into Automite and then restore
;	the orginal Warm Boot vector.
;
swap:	lhld	0001		; get BIOS Warm BootJMP ADDR
	push	h		; save jmp addr
	lxi	d,0ch-3 	; offset to conout routine
	dad	d
	shld	conout+1
	pop	h		; restore jmp addr
	inx	h		; hl --> BIOS Warm Boot vector
	lxi	d,table		; de --> local Warm Boot handler
	mvi	b,2		; vector size in bytes
;
;	exchange the contents pointed to by hl with those
;	pointed to by de.
;
loop:				; repeat
	mov	c,m		;   swap *hl,*de
	ldax	d
	mov	m,a
	mov	a,c
	stax	d
	inx	h		;   hl++, de++
	inx	d
	djnz	loop		; unitl bytes swaped
        ret
;
prnstr: mov	a,m		; while character is not 0
	ora	a		; 
	rz
	mov	c,a		;   set up to pass char in c
	push	h		;   save pointer 
	call	conout		;   output to screen 
	pop	h		;   restore pointer
	inx	h		;   and advance to next char
	jmp 	prnstr		; end while

conout:	jmp	0		; dummy jump to BIOS CONOUT routine
;
table:	DW	wbpatch		; replacement Warm Boot Vector
;
line25:	DB	ESC,'C7',0
line24:	DB	ESC,'B7',0
;
	ds	16		; temp stack area
;
ENDPRG	equ	$		; end marker
;
	END
 
