
;**************************************************************************
;**
;** booter.asm 
;** Copyright (c) 1995,1996 Daniel Kahlin <tlr@stacken.kth.se>
;**
;******

	PROCESSOR 6502

;zeropage definitions
currzp	EQU	$ae
destzp	EQU	$fb

	org	$1800
booter_start:

;**************************************************************************
;**
;** unstuffer (will fall through booter)
;** machine independant code.
;**
;******
unstuffer:

;*** do unstuffing of code
;*** may not contain any zeroes

	IF	[<booter_stuff]==0
	ECHO	"WARNING! zero byte in unstuffer."
	ENDIF
	IF	[>booter_stuff]==0
	ECHO	"WARNING! zero byte in unstuffer."
	ENDIF
	sei
	lda	#<booter_stuff
	ldx	#>booter_stuff
	sta	currzp
	stx	currzp+1
	sta	destzp
	stx	destzp+1

	ldx	#2	;number of pages

	ldy	#1	;y=0
	dey

;* unstuff loop
us_lp1:
	lda	(currzp),y
	cmp	#$11
	bne	us_skp2

	inc	currzp
	bne	us_skp1
	inc	currzp+1
us_skp1:

	lda	(currzp),y
	bpl	us_skp2
	tya

us_skp2:
	sta	(destzp),y

	inc	currzp
	bne	us_skp3
	inc	currzp+1
us_skp3:

	inc	destzp
	bne	us_lp1
	inc	destzp+1
	dex
	bpl	us_lp1
	
;*** stuff tag
	nop
	nop

;**************************************************************************
;**
;** booter
;** machine independant code.
;**
;******
booter_stuff:
	lda	#<start_MSG
	ldy	#>start_MSG
	jsr	$ab1e
	rts

start_MSG:
	dc.b	13,"IT WORKS LIKE HELL!",13,0
	ds.b	[booter_start+$200]-.,$ea
booter_end:
