;----------------------------------------------------------
;Option ROM Header must be ORGed at 0 by the assembler
;or linked at 0 by the linker.
;----------------------------------------------------------

;Routine to turn on the Option ROM

OPON:	EQU	0FAA4H

;Globals on the Telcom Back Page to temporarily hold HL and
;DE registers during a CALL to Standard ROM, or during an
;Interrupt.

HOLDH:	EQU	0FCC0H
HOLDD:	EQU	0FCC2H
INTH:	EQU	0FCC4H
INTD:	EQU	0FCC6H


;Entry point arrived at by CALL 63012

RST0?:
;Optional for linking versions
;	EXTRN	PROGRAM
	INX	SP
	INX	SP
	JMP	PROGRAM
	DB	0,0,0

RST1?:				;Not used
	RET
	DB	0,0,0,0,0,0,0

RST2?:				;Not used
	RET
	DB	0,0,0,0,0,0,0

RST3?:				;Not Used
	RET
	DB	0,0,0,0,0,0,0

RST4?:				;Not Used
	RET
	DB	0,0,0

TRAP?:
	DI
	JMP	INTRAP

RST5?:				;Not Used
	RET
	DB	0,0,0

RST55?:
	DI
	JMP	INT55

;RST 6 used as short call to a Standard ROM routine.

RST6?:
	JMP	STDCALL
	DB	0

;Replaces the 6.5 interrupt and sets up a call to 6.5 in
;Standard ROM

RST65?:
	DI
	JMP	INT65

RST7?:				;Not Used
	RET
	DB	0,0,0

;Replaces the 7.5 interrupt and sets up a call to 7.5 in
;Standard ROM

RST75?:
	DI
	JMP	INT75

;An image of the OPON routine copied to FAA4H by the
;Model 100 power up logic.

OPONIMG:
	PUSH	PSW
	MVI	A,1
	OUT	0E0H
	POP	PSW
	RET
	DB	0

;---------------------------------------------------------
;The STDCALL routine allows a program running in the
;the Option ROM to call and return to an address in the
;Option ROM.
;Syntax is to use a RST 6 plus the address to be called.
;
;	RST	6
;	DW	04B44H
;---------------------------------------------------------

STDCALL:
	DI
	SHLD	HOLDH		;Caller's HL
	XCHG
	SHLD	HOLDD		;Caller's DE
	POP	H		;(HL)=Routine to Call
	MOV	E,M
	INX	H
	MOV	D,M		;DE=Routine to Call
	INX	H		;HL=Return Address
	PUSH	H
	LXI	H,OPON		;return through OPON
	PUSH	H
	PUSH	D		;Return Address
	LHLD	HOLDD		;Caller's DE
	XCHG
	LHLD	HOLDH		;Caller's HL
	EI
	JMP	STDON


;Routines for each of the hardware traps.
INTRAP:
	CALL	INTCALL
	DW	0024H
	RET

INT55:
	CALL	INTCALL
	DW	002CH
	RET

INT65:
	CALL	INTCALL
	DW	0034H
	RET

INT75:
	CALL	INTCALL
	DW	003CH
	RET

OPX:
;Turns off the Option ROM (or turns on Standard ROM)
;Depending on your viewpoint.
;This routine must be ORGed at 85H. Ensure the the previous
;Code does not overlap into 85H

	ORG	85H
;Optional for linking versions
;	PUBLIC	STDON
STDON:
	PUSH	PSW
	PUSH	H
	LXI	H,26C8H
	XTHL
	XRA	A
OPEXIT:
	OUT	0E0H
	RET

;---------------------------------------------------------
;The INTCALL routine allows a program running in the Option
;ROM to call an interrupt routine.
;Syntax: CALL INTCALL plus the address to be called.
;
;	CALL	INTCALL
;	DW	24H
;---------------------------------------------------------
INTCALL:
	SHLD	INTH		;Caller's HL
	XCHG
	SHLD	INTD		;Caller's DE
	POP	H		;(HL)=Routine to Call
	MOV	E,M
	INX	H
	MOV	D,M		;DE=Routine to Call
	INX	H		;HL=Return Address
	PUSH	H
	LXI	H,OPON		;return through OPON
	PUSH	H
	PUSH	D		;Return Address
	LHLD	INTD		;Caller's DE
	XCHG
	LHLD	INTH		;Caller's HL
	JMP	STDON

;For Non linking versions your Code begins here
;For linking versions delete the label below, and
;use it for the entry point to your program after
;declaring it PUBLIC.

PROGRAM:

	END
