;==============================================================================
; SIF patch for ISOROM
;==============================================================================
;
; SIF		= Serial InterFace for ZX Spectrum (http://sif.itherm.cz)
;
; ISOROM	= Modified ZX Spectrum ROM, fully compatible with original Sinclair
;		BASIC with some very important features, many are related to TRDOS
;
; ASL		= Best compiler for Z80 assembler http://john.ccac.rwth-aachen.de:8000/as/
;		This code was developed with this compiler.
;
; This code cannot work standalone. But when will writen to ROM then you will able use
; standard ROM commands SAVE/LOAD/MERGE/VERIFY for transfer data to/from PC trought
; RS232 at speed 115200 bps.

		cpu	z80undoc
		org	32768

INSTALL_START	; test if ISOROM (other ROM) is writeable
		; message and stop installer if not
		; if it is ok, check checksum of ROM
		; warning message if checksum different
		; wait for key

		; set ISOROM 128 writeable
		ld	a,1
		out	(239),a

		; write patches to ROM
		ld	hl,SIF_SAVE_PATCH
		ld	de,1218			; 0x04c2 = 1218		SA-BYTES
		ld	bc,SIF_SAVE_PATCH_LN
		ldir

		ld	hl,SIF_INIT_PATCH
		ld	de,1294			; RANDOMIZE USR 1294	INITIALIZE SIF
		ld	bc,SIF_INIT_PATCH_LN
		ldir

		ld	hl,SIF_LOAD_PATCH
		ld	de,1366			; 0x0556 = 1366		LD-BYTES
		ld	bc,SIF_LOAD_PATCH_LN
		ldir

		ld	hl,SIF_CLR_PATCH
		ld	de,1494			; RANDOMIZE USR 1494	CLEAR BUFFERS
		ld	bc,SIF_CLR_PATCH_LN
		ldir

		; set ISOROM 128 readonly
		xor	a
		out	(239),a

		; call init in ROM
		; return to BASIC

		ret

SIF_SAVE_PATCH
		include		"save.za"
SIF_SAVE_PATCH_LN = $ - SIF_SAVE_PATCH

SIF_INIT_PATCH					; init po SAVE, protože tam na něj zbyde místo
		include		"init.za"
SIF_INIT_PATCH_LN = $ - SIF_INIT_PATCH

SIF_LOAD_PATCH
		include		"load.za"
SIF_LOAD_PATCH_LN = $ - SIF_LOAD_PATCH

SIF_CLR_PATCH
		include		"clear.za"
SIF_CLR_PATCH_LN = $ - SIF_CLR_PATCH