*
* FastMem adder for ZKick'ing Kickstarts greater than 1.3.  If you are using
* a RAM expansion card in other than the rightmost slot, ZKick will not
* enable your FastRam.  This fix will enable it... it fixes my GVP ok!
*
* (w)18-May-92 02:45 BSI
*

beg	equ $200000	    ; Pointer to start of ram board...
fin	equ $a00000	    ; End of RAM+1

KICKSIZE equ $80000	    ; kickstart image is 512k long...
base	 equ beg+KICKSIZE+8 ; fix base of ram board so that it reflects
			    ; where the memchunk struct should be created!

*
* Detect KS version...
*
start:	move.l 4,a6
	lea dosname(pc),a1
	moveq #36,d0
	jsr -552(a6)
	tst.l d0	; if library 36+ not found, d0 is already zero
	bne kickfix	; so quit... this allows 1.3 scripts to run
	rts		; fine...

dosname:dc.b "dos.library",0
	even
dbase:	dc.l 0


*
* Add ram then print notice to screen...
*
kickfix:move.l d0,dbase

	moveq #4,d1
	jsr -216(a6)
	tst.l d0
	bne fastpres

	bsr kickadd

	move.l dbase(pc),a6
	jsr -60(a6)
	tst.l d0		; output() failed?
	bne prtxt		; if so, it may be the wb in action...
	rts	

prtxt:	move.l d0,d1		; print text to notify user ZEMA is active...
	move.l #notice,d2
	move.l #(notend-notice),d3
writer:	jsr -48(a6)
	
	move.l a6,a1		; close up shop on dos.library
	move.l 4,a6
	jsr -414(a6)
	moveq #0,d0		; scripts ok...
	rts

fastpres:
	move.l dbase(pc),a6
	jsr -60(a6)
	tst.l d0		; output() failed?
	bne prtxt2		; if so, it may be the wb in action...
	rts	

prtxt2:	move.l d0,d1		; print text to notify user ZEMA is
	move.l #warning,d2	; already active...
	move.l #(warnend-warning),d3
	bra writer

notice:	dc.b 10,13
	dc.b "ZEMA: ZKick Expansion Memory Adder",13,10
	dc.b "----------------------------------",13,10
	dc.b "Expansion Memory Added for use with configurations that do not",13,10
	dc.b "allow ZKick to enable fast memory such as in GVP cards or on",13,10
	dc.b "cards that are not in slot zero.",13,10
	dc.b "(W)1992 Bansai/BSI",13,10,10
notend	equ *

warning:dc.b 10,13
	dc.b "ZEMA WARNING: FAST MEMORY ALREADY PRESENT!",13,10,10
warnend	equ *
	even

*
* The actual expansion ram adder...
*
kickadd:move.l 4,a6	; alloc mem for our memheader in chipram...
	moveq #listlen,d0
	move.w d0,d7
	moveq #$2,d1
	jsr -198(a6)
	lea memh(pc),a1
	move.l d0,a0
	move.l d0,a2	

	subq.w #1,d7	; copy memheader over...
cpybyte:move.b (a1)+,(a2)+
	dbra d7,cpybyte

	move.l a0,d0	; relocate name ptr in struct...
	add.l d0,skiplen(a0)

	clr.l base-8	; construct memchunk...
	move.l #(fin-base),base-4

	move.l a0,a1
	lea 322(a6),a0	; add to system memory list...
	jsr -240(A6)
	rts


*
* MemHeader structure...
*
memh:	dc.l 0		; successor...
	dc.l 0		; predecessor...
	dc.b 10		; nodetype is memory...
	dc.b 0		; pri
name:	dc.l exp-memh	; name	

	dc.w (1<<0)+(1<<2) ; attributes...
	dc.l base-8
	dc.l base-8
	dc.l fin
	dc.l fin-base
	
exp:	dc.b "expansion ram",0

EOMH	equ *

listlen	equ EOMH-memh
skiplen	equ name-memh
