Static Trainer Menu Source

The following source code was written on an Amiga 4000/040 computer using

CygnusEd (text editor), SASM (snes assembler), IFF2SNES (gfx converter).

This music was written by The Doctor using CuBase (I think..)

This is a horrible piece of code and shows very sloppy work (too).

This time I mixed equates and direct addresses together. I think it's

because I borrowed code from my older source codes. I have a bad habit

of re-using old stuff and never fixing them. :(







	heap	O=512k			;max 128k object buffer                
	size	8			;4 32kblocks                          
                                                                                  
	SMC+				;yes, we want a smc header            
	lrom				;yes, please split in 32k hunks       

planeflip	equ	$400
joydata		equ	planeflip+2
set2133		equ	joydata+2
random1		equ	set2133+2
random2		equ	random1+2
verthtime	equ	random2+2
logox		equ	verthtime+2
logomove	equ	logox+2
fadetimer	equ	logomove+2
fadeoffset	equ	fadetimer+2
menuscroll	equ	fadeoffset+2
menutimer	equ	menuscroll+2
menumotion	equ	menutimer+2
menudirection	equ	menumotion+2
menuoffset	equ	menudirection+2
currentline	equ	menuoffset+2
numconv		equ	currentline+2
low2		equ	numconv+2
low1		equ	low2+2
low0		equ	low1+2
high6		equ	low0+2
high5		equ	high6+2
high4		equ	high5+2
hundreds	equ	high4+2
ones		equ	hundreds+2
tens		equ	ones+2
numbertimer	equ	tens+2
bottomtimer	equ	numbertimer+2
bottomfadeon	equ	bottomtimer+2
bottomoffset	equ	bottomfadeon+2
csh0		equ	bottomoffset+2
ssh4		equ	csh0+2
cst2		equ	ssh4+2
sst6		equ	cst2+2
sms8		equ	sst6+2
ssa		equ	sms8+2
scs		equ	ssa+2
sinedir		equ	scs+2
scrpal		equ	sinedir+2
scrolldrop	equ	scrpal+2
endflag		equ	scrolldrop+2
endtimer	equ	endflag+2
endhoriz	equ	endtimer+2
toggle		equ	endhoriz+2
storage		equ	toggle+2

UnpackBuffr     EQU     $7f0000
Buff2	EQU	$000200	; 24-bit address of $1A0 byte buffer
in	EQU	$65
out	EQU	$68
wrkbuf	EQU	$6a
counts	EQU	$6d
blocks	EQU	$4f
bitbufl	EQU	$51
bitbufh	EQU	$43
bufbits	EQU	$55
bitlen	EQU	$57
hufcde	EQU	$59
hufbse	EQU	$5b
temp1	EQU	$5d
temp2	EQU	$5f
temp3	EQU	$61
temp4	EQU	$63
tmptab	EQU	0	; indexed from Buff2
rawtab	EQU	$20	; indexed from Buff2
postab	EQU	$a0	; indexed from Buff2
slntab	EQU	$120	; indexed from Buff2

;==========================================================================
;      Code (c) 1995 -Pan-/ANTHROX   All code can be used at will!
;==========================================================================                     

	;jmp	Slow
	;jmp	Cheat
	jmp	IRQ  
	;jmp	LEVEL

Start:
	

	phk			; Put current bank on stack
	plb			; make it current programming bank
				; if this program were used as an intro
				; and it was located at bank $20 then an
				; LDA $8000 would actually read from
				; $008000 if it were not changed!
				; JSRs and JMPs work fine, but LDAs do not! 
	clc			; Clear Carry flag
	xce			; Native 16 bit mode  (no 6502 Emulation!) 
;==========================================================================

	jsr	Snes_Init





	rep	#$10
	sep	#$20
	ldx	#music		; CRUNCHED FILE
	stx	$65
	phk
	pla
	;lda	#^Picture1		; CRUNCHED FILE BANK
	sta	$67
	ldx	#UnpackBuffr		; LOW WORD UNPACK BUFFER
	stx	$68
	lda	#^UnpackBuffr		; UNPACK BUFFER BANK
	pha
	plb
	jsr	UNPACK				;Requires A[8] XY[16]

	phk
	plb

	jsr	musique

	rep	#$30
	sep	#$20

	jsr	Copy_Gfx
	jsr	Make_tiles
	jsr	Copy_colors
	jsr	HDMA
	jsr	Sprite_setup

	jsr	Option_Setup

	lda	#$01
	sta	$2105
	
	lda	#$03
	sta	$212c

	;lda	#$02
	;sta	$212d

	lda	#$79
	sta	$2107
	
	lda	#$10
	sta	$2108

	lda	#$03
	sta	$210b



	ldx	#$0000
	stx	set2133

	ldx	#$0000
	stx	random1
	stx	random2

	ldx	#$01a0
	stx	verthtime

	ldx	#$0100
	stx	logox
	
	ldx	#$0000
	stx	logomove

	ldx	#$0000
	stx	fadetimer 
	stx	fadeoffset

	ldx	#$0000
	stx	menuscroll
	stx	menutimer
	stx	menumotion   
	stx	menudirection
	stx	menuoffset

	ldx	#$0001		; menu's starting currentline
	stx	currentline

	ldx	#$0000
	stx	numbertimer

	ldx	#$0000
	stx	bottomtimer
	stx	bottomfadeon
	stx	bottomoffset
	ldx	#$0001
	stx	csh0
	dex
	stx	ssh4
	stx	cst2
	stx	sst6
	stx	sms8
	stx	ssa 
	stx	scs
	
	ldx	#$0002
	stx	sinedir

	ldx	#%0000
	stx	scrpal

	ldx	#$0000
	stx	scrolldrop
	stx	endflag
	stx	endtimer
	stx	endhoriz


	lda	#$c3		; planes 1 uses Window 1 plane 2 uses Window 2
	sta	$2123
	lda	#$00
	sta	$2124

	lda	#$c0		; Color window uses window 2
	sta	$2125		; Obj window uses window 1
	
	lda	#$00		; window 1 start
	sta	$2126
	lda	#$ff		; window 1 end
	sta	$2127

	lda	#$00		; window 2 start
	sta	$2128
	lda	#$00		; Window 2 end
	sta	$2129

	lda	#$04		; Color Window Logic 0 = or
	sta	$212b		; 4 =and , 8 = xor, c = xnor

	lda	#$01		; Main screen mask belongs to obj, and planes
	sta	$212e		; same with subscreen
	lda	#$02
	sta	$212f

	lda	#$22;22		; sub screen window, effect happens INSIDE
	sta	$2130		; window	; 30 = turn effect OFF
						; 20 = turn effect on in window
						; 00 = on ALWAYS
	lda	#%10000010 	; ; 10000010 Color addition
 	sta	$2131		; not 1/2 bright, back, no obj, bg0-3

	lda	#%11100100	; blue off, green on, red off
	;sta	$2132		; lowest 5 bits = brightness

	lda	#$00
	sta	$210d
	lda	#$01
	sta	$210d

	lda	#$0f
	sta	$2100

	lda	#$01
	sta	$4200

	jsr	tune


Waitlooper:
	jsr	WaitVb

	stz	$212c
	stz	$2133
	ldx	verthtime
	beq	novhold

	lda	set2133
	sta	$2133
	eor	#$04
	sta	set2133

	dex
	stx	verthtime


novhold:

	lda	#$13
	sta	$212c



	ldx	random1
	lda	randomnumbers,x
	sta	$210f
	stz	$210f
	
	ldx	random2
	lda	randomnumbers,x
	sta	$2110
	stz	$2110
	ldx	verthtime
	beq	okforintro
	jmp	endofintrovbi


okforintro:

	lda	logomove		; beginning of intro routine
	bne	dontmovelogo		; bring logo and other features
	jsr	movelogo		; together on the screen
	jsr	fadeline
	jmp	endofintrovbi
dontmovelogo:
	lda	endflag
	bne	skipallroutines
	jsr	joypad
	jsr	buttselect
	jsr	Sprscroll
	jsr	fadeline
	jsr	movemenu
	jsr	bottomchanger
	jsr	Movescroll

	rep	#$30
	lda	menuscroll
	clc
	adc	#$0088
	sta	$1e28
	sep	#$20
	jsr	teststart







endofintrovbi:
	inc	random1

	lda	random2
	clc
	adc	#$03
	adc	random1
	sta	random2
	jmp	Waitlooper

skipallroutines:
	jsr	endmove
	jsr	Sprscroll
	jsr	fadeline
	jsr	bottomchanger
	jsr	Movescroll

	bra	endofintrovbi

;==========================================================================
;                   Move Screen At End Of Intro
;==========================================================================

endmove:


	rep	#$30
	lda	logox
	inc a
	sta	logox
	and	#$00ff
	beq	stoplogomove2
	sep	#$20
returnmovelogo2:
	lda	logox		; move logo in HDMA list
	eor	#$ff
	sta	$1e21
	sta	$1e2b
	sta	$1e30
	lda	logox+1
	eor	#$ff
	sta	$1e22
	sta	$1e2c
	sta	$1e31

	lda	logox
	sta	$1e26		; move menu in HDMA list
	lda	logox+1
	sta	$1e27

	lda	logox		; shade the static
	eor	#$ff
	sta	$1e03		; dark static window left

	lda	logox
	lsr a
	lsr a
	inc a
	inc a
	sta	scrolldrop

	rts


stoplogomove2:

	jsr	tuneoff
	rep	#$30
	sep	#$20
	ldx	#$0000
	stx	endtimer
	stx	endhoriz

	lda	#$00
	sta	$2126
	lda	#$ff
	sta	$2127

	lda	#$02
	sta	$212e
	lda	#$30
	sta	$2123

	
	;stz 	$2123   ; BG1 & BG2 Window mask setting register
	stz 	$2124   ; BG3 & BG4 Window mask setting register
	stz 	$2125   ; OBJ & Color Window mask setting register
	stz 	$2126   ; Window 1 left position register
	stz 	$2127   ; Window 2 left position register
	stz 	$2128   ; Window 3 left position register
	stz 	$2129   ; Window 4 left position register
	stz 	$212A   ; BG1, BG2, BG3, BG4 Window Logic register
	stz 	$212B   ; OBJ, Color Window Logic Register (or,and,xor,xnor)
	sta 	$212C   ; Main Screen designation (planes, sprites enable)
	stz 	$212D   ; Sub Screen designation

	stz 	$212F   ; Window mask for Sub Screen
	lda 	#$30
	sta 	$2130   ; Color addition & screen addition init setting
	stz 	$2131   ; Add/Sub sub designation for screen, sprite, color
	lda 	#$E0
	sta 	$2132   ; color data for addition/subtraction




	jsr	WaitVb
	stz	$420c
	stz	$420b

	ldx	#$0000
copy212clist:
	lda	list212c,x
	sta	$1e00,x
	inx
	cpx	#$0020
	bne	copy212clist


	lda     #$00          
	sta     $4300         
	lda     #$2c         
	sta     $4301         
	ldx     #$1e00  
	stx     $4302         
	lda	#$7e          
	sta     $4304
	lda	#$01
	sta	$420c




	bra	Waitcont


Waitblank:
	jsr	WaitVb


Waitcont:


	ldx	random1
	lda	randomnumbers,x
	sta	$210f
	stz	$210f
	
	ldx	random2
	lda	randomnumbers,x
	sta	$2110
	stz	$2110

	inc	random1

	lda	random2
	clc
	adc	#$03
	adc	random1
	sta	random2


	lda	$1e02
	sec
	sbc	#$05
	sta	$1e02

	lda	$1e04
	sec
	sbc	#$05
	sta	$1e04

	lda	$1e00
	clc
	adc	#$05
	sta	$1e00

	lda	endhoriz
	clc
	adc	#$05
	sta	endhoriz
	sta	$2126

	eor	#$ff
	sta	$2127

	ldx	endtimer
	inx
	inx
	inx
	inx
	inx
	stx	endtimer
	cpx	#$007d
	beq	endagain
	bra	Waitblank
endagain:

	ldx	#$0f00
	stx	fadetimer






Waitblank2:
	jsr	WaitVb

	
	ldx	random1
	lda	randomnumbers,x
	sta	$210f
	stz	$210f
	
	ldx	random2
	lda	randomnumbers,x
	sta	$2110
	stz	$2110

	inc	random1

	lda	random2
	clc
	adc	#$03
	adc	random1
	sta	random2

	lda	fadetimer
	dec a
	and	#$03
	sta	fadetimer
	bne	Waitblank2

	dec	fadetimer+1
	lda	fadetimer+1
	sta	$2100
	beq	Waitblank3

	bra	Waitblank2


Waitblank3:
	jsr	WaitVb
	jsr	Snes_Init
Watblank4:
	jmp	gameover


list212c:
	dc.b	1,0
	dc.b	$7f,$2
	dc.b	$7f,$2
	dc.b	1,0
	dc.b	0,0



;==========================================================================
;                  Test If Start Button Was Pressed
;==========================================================================

teststart:
	lda	joydata+1
	cmp	#$10
	beq	startpressed
	rts
startpressed:
	lda	#$01
	sta	endflag
	ldx	#$0000
	stx	joydata
	rts

;==========================================================================
;                      Sprite Scroll Routine
;==========================================================================

Sprscroll:
	rep	#$10	; x,y = 16 bit
	sep	#$20	; a = 8 bit
			; start of General DMA graphics copy routine!
	lda	#$00
	sta	$4370		; 0= 1 byte per register (not a word!)
	lda	#$04
	sta	$4371		; 21xx   this is 2118 (VRAM)
	lda	#$00
	sta	$4372
	lda	#$05		; address = $7e0500
	sta	$4373
	lda	#$7e
	sta	$4374		; bank address of data in ram
	ldx	#$0044
	stx	$4375		; # of bytes to be transferred

	ldx	#$0000
	stx	$2102

	lda	#$80		; turn on bit 8 (%1000=8) of G-DMA channel
	sta	$420b
	ldx	#$0100
	stx	$2102
	lda	sms8
	sta	$2104
	rts




Movescroll:



	stz	sms8
	lda	csh0
	sta	scs
	sec
	sbc	#$11
	sta	ssh4

	and	#$80
	asl a
	rol	sms8
	

	ldx	#$0000
	stx	sst6


	ldx	#$0000
	txy
				; csh0 = current scroll H pos
				; ssh4 = storage scroll h pos
				; cst2 = current scroll text pos
				; sst6	= storage scroll text pos
				; sms8 = storage of MSB

scrollwriter:
	lda	ssh4	
	sta	$0500,x
	inx
	phx
	rep	#$30
	lda	scs
	clc
	adc	ssa
	and	#$00ff
	tax
	rep	#$30
	lda	vertsine,x		; vert pos
	and	#$00ff
	clc
	adc	#$9f
	clc
	adc	scrolldrop
	cmp	#$00e0
	bcc	noyposset	
	lda	#$00e0

noyposset:
	sep	#$20
	plx
	sta	$0500,x
	inx
	rep	#$30

	

	phy
	ldy	sst6

	lda	$0550,y
	
	and	#$0ff
	sec
	sbc	#$20
	phx
	tax
	sep	#$20
	lda	fontpos,x	
	plx
	sta	$0500,x
	inx	    ;;	
	
	lda	$0570,y
	asl a
	ora	#%00110000

	;lda	#%00110000
	sta	$0500,x
	ply

	inx

	phx
	ldx	sst6
	inx
	stx	sst6
	plx


	lda	scs
	clc
	adc	#$10
	sta	scs


	lda	ssh4
	clc
	adc	#$10
	sta	ssh4
	iny
	cpy	#$0011
	bne	scrollwriter

	lda	ssa
	sec
	sbc	sinedir
	sta	ssa

	dec	csh0
	lda	csh0
	beq	movescrolltext
	rts
movescrolltext:
	lda	#$10
	sta	csh0

	inc	$1102
	inc	$1106


	ldx	#$0000
	sep	#$20
copyscrolltext:
	lda	$0551,x
	sta	$0550,x

	lda	$0571,x		; palette type/palette
	sta	$0570,x

	inx
	cpx	#$0010
	bne	copyscrolltext


readtext:


	ldx	cst2
	lda	scrolltext,x
	cmp	#"#"
	beq	leftright
	cmp	#"$"
	beq	rightleft
	cmp	#"%"
	beq	paleffect
	cmp	#$00
	beq	endscroll
	cmp	#$60
	bcc	noand5f
	and	#$5f
noand5f:
	sta	$0560
	lda	scrpal
	sta	$0580

	ldx	cst2
	inx
	stx	cst2
	rts


endscroll:
	ldx	#$0000
	stx	cst2
	bra	readtext

leftright:
	lda	#$02
	sta	sinedir
	ldx	cst2
	inx
	stx	cst2
	bra	readtext

rightleft:
	lda	#$fc
	sta	sinedir
	ldx	cst2
	inx
	stx	cst2
	bra	readtext

paleffect:
	ldx	cst2
	inx
	stx	cst2
	lda	scrolltext,x
	sec
	sbc	#$30
	and	#$07
	sta	scrpal
	ldx	cst2
	inx
	stx	cst2
	bra	readtext

;==========================================================================
;                       Bottom Text Changer Routine
;==========================================================================

bottomchanger:
	lda	bottomfadeon
	cmp	#$01
	beq	bottomfadein
	cmp	#$02
	beq	bottomfadeout

	lda	bottomtimer
	dec a
	and	#$ff
	sta	bottomtimer
	beq	changebottom
	rts
changebottom:
	lda	#$01
	sta	bottomfadeon
	ldx	#$0000
	stx	bottomoffset

bottomfadein:
	ldx	bottomoffset
	lda	bottommosaic,x
	sta	$1e4a
	inx
	stx	bottomoffset
	cpx	#$000f
	beq	enablefadeout
	rts

enablefadeout:
	lda	#$02
	sta	bottomfadeon
	lda	$1e32
	clc
	adc	#$10
	sta	$1e32
	rts

bottomfadeout:
	ldx	bottomoffset
	lda	bottommosaic,x
	sta	$1e4a
	inx
	stx	bottomoffset
	cpx	#$001e
	beq	stopfading
	rts
stopfading:
	ldx	#$00
	stx	bottomfadeon
	stx	bottomoffset
	rts

bottommosaic:
	dc.b	$11,$21,$31,$41,$51,$61,$71,$81,$91,$a1,$b1,$c1,$d1
	dc.b	$e1,$f1
	dc.b	$e1,$d1,$c1,$b1,$a1,$91,$81,$71,$61,$51,$41,$31,$21,$11,$01



;==========================================================================
;                   Change Trainer Value And Print Yes/No/#
;==========================================================================

buttselect:
	lda	joydata+1
	bit	#$80
	bne	OptB
	bit	#$02
	bne	OptB
	bit	#$01
	bne	OptA
	lda	joydata
	bit	#$80
	bne	OptA
	stz	numbertimer
	rts

OptA:
	jmp	Incopt
OptB:
	jmp	Decopt

Incopt:
	ldx	currentline		; get current option line
	dex
	lda	Type,x
	beq	Textopt
	jmp	Numberopt
Textopt:
	lda	#$01
	sta	$1c00,x
	jmp	displayyn	

Numberopt:
	lda	numbertimer
	inc a
	and	#$03
	sta	numbertimer
	beq	Numberoptinc
	rts
Numberoptinc:
	lda	$1c00,x
	cmp	Max,x
	bne	Incnumber
	rts
Incnumber:
	inc	$1c00,x
	lda	$1c00,x
PrintDec:
	sta	numconv
	jsr	Hex2Dec

	rep	#$30
	lda	currentline
	dec a
	asl a
	asl a
	asl a
	asl a
	asl a
	clc
	adc	#$7019
	sta	$2116
	sep	#$20
	lda	hundreds
	clc
	adc	#$10
	adc	#$7f
	sta	$2118
	lda	#$04
	sta	$2119
	lda	tens
	clc
	adc	#$10
	adc	#$7f
	sta	$2118
	lda	#$04
	sta	$2119
	lda	ones
	clc
	adc	#$10
	adc	#$7f
	sta	$2118
	lda	#$04
	sta	$2119
	rts




Decopt:
	ldx	currentline		; get current option line
	dex
	lda	Type,x
	beq	Textopt1
	jmp	Numberopt1
Textopt1:
	lda	#$00
	sta	$1c00,x
	jmp	displayyn	

Numberopt1:
	lda	numbertimer
	inc a
	and	#$03
	sta	numbertimer
	beq	Numberoptdec
	rts

Numberoptdec:
	lda	$1c00,x
	cmp	Min,x
	bne	Decnumber
	rts
Decnumber:
	dec	$1c00,x
	lda	$1c00,x
	sta	numconv
	jsr	Hex2Dec

	rep	#$30
	lda	currentline
	dec a
	asl a
	asl a
	asl a
	asl a
	asl a
	clc
	adc	#$7019
	sta	$2116
	sep	#$20
	lda	hundreds
	clc
	adc	#$10
	adc	#$7f
	sta	$2118
	lda	#$04
	sta	$2119
	lda	tens
	clc
	adc	#$10
	adc	#$7f
	sta	$2118
	lda	#$04
	sta	$2119
	lda	ones
	clc
	adc	#$10
	adc	#$7f
	sta	$2118
	lda	#$04
	sta	$2119
	rts




displayyn:
	rep	#$30
	lda	currentline
	dec a
	asl a
	asl a
	asl a
	asl a
	asl a
	clc
	adc	#$7019
	sta	$2116
	sep	#$20
	lda	$1c00,x
	beq	TxtNo
	ldx	#$0000
copyyes:
	lda	YES,x
	sec
	sbc	#$20
	clc
	adc	#$7f
	sta	$2118
	lda	#$04
	sta	$2119
	inx
	cpx	#$03
	bne	copyyes
	rts
TxtNo:
	ldx	#$0000
copyno:
	lda	NO,x
	sec
	sbc	#$20
	clc
	adc	#$7f
	sta	$2118
	lda	#$04
	sta	$2119
	inx
	cpx	#$03
	bne	copyno
	rts


	

;==========================================================================
;                          Move Menu Up/Down
;==========================================================================

movemenu:
	lda	menumotion
	beq	menucheckpad
	lda	menudirection
	beq	md3
	bne	mu3

menucheckpad:
	lda	joydata+1
	;and	#$0c
	bit	#$08
	bne	movedown
	bit	#$04
	bne	moveup
	rts

movedown:
	jmp	movedown2
moveup:
	jmp	moveup2

movedown2:
	lda	currentline
	cmp	#$01
	beq	md4
	dec	currentline
	lda	#$01
	sta	menumotion	; turn on menu motor!

	stz	menudirection	; 0 = moving down
	stz	menuoffset	; set to 0
	;rts
md3:
	dec	menuscroll
	lda	menuoffset
	inc a
	sta	menuoffset
	cmp	#$08
	beq	md4
	rts
md4:
	stz	menumotion
	rts


moveup2:
	lda	currentline
	cmp	options
	beq	mu4
	inc	currentline
	lda	#$01
	sta	menumotion
	lda	#$01
	sta	menudirection
	stz	menuoffset
	;rts

mu3:
	inc	menuscroll
	lda	menuoffset
	inc a
	sta	menuoffset
	cmp	#$08
	beq	mu4
	rts
mu4:
	stz	menumotion
	rts


	
	

;==========================================================================
;                          Joypad Routine
;==========================================================================

joypad:
	lda	$4212
	and	#$01
	beq	joypad
joypad2:
	lda	$4212
	and	#$01
	bne	joypad2

	ldx	$4218
	stx	joydata
	rts


;==========================================================================
;                     Fading Selection Bar Routine
;==========================================================================

fadeline:
	lda	fadetimer
	dec a
	and	#$03
	sta	fadetimer
	beq	fadelineok
	rts
fadelineok:
	ldx	fadeoffset
	lda	fadingcolors,x
	ora	#%01100000
	sta	$1e13
	
	lda	fadeoffset
	inc a
	cmp	#$01e
	bne	writefadeoffset
	lda	#$00
writefadeoffset:
	sta	fadeoffset
	rts

fadingcolors:
	dc.b	4,5,6,7,8,9,$a,$b,$c,$d,$e,$f,$e,$d,$c,$b,$a,9,8,7,6,5,4,3
	dc.b	2,1,0,1,2,3



;==========================================================================
;                   Move Logo Left After Vertical Hold Routine
;==========================================================================

movelogo:
	rep	#$30
	lda	logox
	dec a
	sta	logox
	beq	stoplogomove
	sep	#$20
returnmovelogo:
	lda	logox		; move logo in HDMA list
	eor	#$ff
	sta	$1e21
	sta	$1e2b
	sta	$1e30
	lda	logox+1
	eor	#$ff
	sta	$1e22
	sta	$1e2c
	sta	$1e31

	lda	logox
	sta	$1e26		; move menu in HDMA list
	lda	logox+1
	sta	$1e27

	lda	logox		; shade the static
	eor	#$ff
	sta	$1e03		; dark static window left
	rts
stoplogomove:
	sep	#$20
	lda	#$01
	sta	logomove
	bra	returnmovelogo

;==========================================================================
;                              Vertical Blank
;==========================================================================

WaitVb:
	lda	$4210
	bpl	WaitVb
WaitVb2:
	lda	$4210
	bmi	WaitVb2
	rts


;==========================================================================
;       	     SETUP ROUTINES FOR PROGRAM
;==========================================================================

;==========================================================================
;                         Copy graf-x data
;==========================================================================

Copy_Gfx:
	ldx	#$0000		; Vram address $0000 
	stx	$2116		; 
	ldx	#$0000
Clearvr:
	stz	$2118		; clear entire Vram
	stz	$2119
	inx
	bne	Clearvr

	rep	#$30


	ldx	#$0000
	stx	$2116


	ldx	#$0000
	
copystaticgfx:
	lda	staticgfx,x
	sta	$2118
	inx
	inx
	cpx	#$1000
	bne	copystaticgfx




	rep	#$10
	sep	#$20
	ldx	#atxgfx		; CRUNCHED FILE
	stx	$65
	phk
	pla
	;lda	#^Picture1		; CRUNCHED FILE BANK
	sta	$67
	ldx	#UnpackBuffr		; LOW WORD UNPACK BUFFER
	stx	$68
	lda	#^UnpackBuffr		; UNPACK BUFFER BANK
	pha
	plb
	jsr	UNPACK				;Requires A[8] XY[16]

	phk
	plb

	rep	#$30
	;sep	#$20



	ldx	#$3000
	stx	$2116

	ldx	#$0000
copyatxgfx:
	lda	>$7f0000,x
	sta	$2118
	inx
	inx
	cpx	#$1be0
	bne	copyatxgfx




	rep	#$10
	sep	#$20
	ldx	#sprtgfx		; CRUNCHED FILE
	stx	$65
	phk
	pla
	;lda	#^Picture1		; CRUNCHED FILE BANK
	sta	$67
	ldx	#UnpackBuffr		; LOW WORD UNPACK BUFFER
	stx	$68
	lda	#^UnpackBuffr		; UNPACK BUFFER BANK
	pha
	plb
	jsr	UNPACK				;Requires A[8] XY[16]

	phk
	plb

	rep	#$30
	;sep	#$20




	ldx	#$4000
	stx	$2116

	ldx	#$0000
copysprtgfx:
	lda	$7f0000,x
	sta	$2118
	inx
	inx
	cpx	#$1c00
	bne	copysprtgfx


	sep	#$20

	rts

;==========================================================================
;                      Copy Colors
;==========================================================================
Copy_colors:
	stz	$2121		; Select Color Register 1
	ldx	#$0000
CopCol:	
	lda	Colors,X
	sta	$2122
	inx
	cpx	#$0200 		; copy 32 colors ($20*2)
	bne	CopCol
	rts
;==========================================================================
;                      Make Tiles
;==========================================================================

Make_tiles:

	rep	#$30

	ldx	#$1000
	stx	$2116
	ldx	#$0000
	ldy	#$0000
	lda	#$0000
	sta	planeflip
copystatictile:
	lda	randomnumbers,y
	and	#$c000
	ora	planeflip
	sta	$2118

	lda	planeflip
	clc
	adc	#$05	; 9
	and	#$007f	; ff
	sta	planeflip

	tya
	inc a
	and	#$00ff
	tay

	inx
	inx
	cpx	#$0800
	bne	copystatictile




	rep	#$10
	sep	#$20
	ldx	#atxtile		; CRUNCHED FILE
	stx	$65
	phk
	pla
	;lda	#^Picture1		; CRUNCHED FILE BANK
	sta	$67
	ldx	#UnpackBuffr		; LOW WORD UNPACK BUFFER
	stx	$68
	lda	#^UnpackBuffr		; UNPACK BUFFER BANK
	pha
	plb
	jsr	UNPACK				;Requires A[8] XY[16]

	phk
	plb

	rep	#$30
	;sep	#$20


	ldx	#$7840
	stx	$2116
	ldx	#$0000
copyatxtile:
	lda	$7f0000,x
	sta	$2118
	inx
	inx
	cpx	#$0200
	bne	copyatxtile

	ldx	#$6800
	stx	$2116

	ldx	#$0000
drawfont:
	lda	bottext,x
	clc
	adc	#$7f
	sta	$2118
	inx
	inx
	cpx	#64*32		;(rows*number of lines)
	bne	drawfont	

	ldx	#$7c00
	stx	$2116
	ldx	#$0000
	lda	#$0000
copyatxtile2:
	sta	$2118
	inx
	cpx	#$0400
	bne	copyatxtile2

	ldx	#$7000
	stx	$2116
	
	ldx	#$0000
copymenutxt:
	lda	menutxt,x
	and	#$00ff
	sec
	sbc	#$20
	clc
	adc	#$7f
	ora	#$0800
	sta	$2118
	inx
	cpx	#$0400-128
	bne	copymenutxt
copymenutxt2:
	lda	menutxt,x
	and	#$00ff
	sec
	sbc	#$20
	clc
	adc	#$7f
	ora	#$0c00
	sta	$2118
	inx
	cpx	#$0400
	bne	copymenutxt2
	


	sep	#$20


	rts


;=========================================================================
;                         Hex to Decimal Conversion
;=========================================================================

Hex2Dec:

	;lda	#$8f
	;sta	$1f28		; number to be converted

	rep	#$30
	lda	numconv
	and	#$000f
	asl a
	asl a
	tax
	sep	#$20
	inx
	inx
	inx
	lda	LOW,x
	sta	low2
	dex
	lda	LOW,x
	sta	low1
	dex
	lda	LOW,x
	sta	low0

	rep	#$30
	lda	numconv
	and	#$00f0
	lsr a
	lsr a
	lsr a
	lsr a
	asl a
	asl a
	tax
	sep	#$20
	inx
	inx
	inx
	lda	HIGH,x
	sta	high6
	dex	
	lda	HIGH,x
	sta	high5
	dex
	lda	HIGH,x
	sta	high4

oneadd:
	lda	high6
	clc
	adc	low2
	cmp	#$0a
	bcs	onehigh
	stz	hundreds
	sta	ones
	bra	tenadd
onehigh:
	sec
	sbc	#$0a
	sta	ones
	lda	#$01
	sta	hundreds

tenadd:
	lda	high5
	clc
	adc	low1
	clc
	adc	hundreds

	cmp	#$0a
	bcs	tenhigh
	stz	hundreds
	sta	tens
	bra	hundadd
tenhigh:
	sec	
	sbc	#$0a
	sta	tens
	lda	#$01
	sta	hundreds
	
hundadd:
	lda	high4
	clc
	adc	low0
	clc
	adc	hundreds
	sta	hundreds
	rts


;==========================================================================
;                            Option Setup Routine
;==========================================================================

Option_Setup:

	
	ldx	#$0000
clearopts:
	stz	$1c00,x
	inx
	cpx	#$0100
	bne	clearopts

	ldx	#$0000
SetOptRam:
	lda	Type,x
	bne	Numberthing
SetRamOpt:
	inx
	cpx	options
	bne	SetOptRam
	jmp	thisthat

Numberthing:
	lda	Begin,x
	sta	$1c00,x
	bra	SetRamOpt


thisthat:

	
	ldx	#$0001
	stx	currentline
	
printopt:
	ldx	currentline
	dex
	lda	Type,x
	bne	numbtype
	jsr	displayyn
contOptram:
	ldx	currentline
	inx
	stx	currentline
	ldx	currentline
	dex 
	cpx	options
	bne	printopt
	rts
numbtype:
	
	ldx	currentline
	dex
	lda	$1c00,x
	jsr	PrintDec
	bra	contOptram

	

;==========================================================================
;                        Start of HDMA routine
;==========================================================================

HDMA:
	rep	#$10
	sep	#$20

	ldx	#$0000
copy2129list:
	lda	list2129,x
	sta	$1e00,x
	inx
	cpx	#$0008
	bne	copy2129list

	ldx	#$0000
copy2132list:
	lda	list2132,x
	sta	$1e10,x
	inx
	cpx	#$0010
	bne	copy2132list


	ldx	#$0000
copy210dlist:
	lda	list210d,x
	sta	$1e20,x
	inx
	cpx	#$0020
	bne	copy210dlist

	ldx	#$0000
copy2106list:
	lda	list2106,x
	sta	$1e40,x
	inx
	cpx	#$0020
	bne	copy2106list


	lda     #$00          
	sta     $4300         
	lda     #$29         
	sta     $4301         
	ldx     #$1e00  
	stx     $4302         
	lda	#$7e          
	sta     $4304

	lda	#$00
	sta	$4310
	lda	#$32
	sta	$4311
	ldx	#$1e10
	stx	$4312
	lda	#$7e
	sta	$4314

	lda	#$03
	sta	$4320
	lda	#$0d
	sta	$4321
	ldx	#$1e20
	stx	$4322
	lda	#$7e
	sta	$4324
	
	lda	#$01
	sta	$4330
	lda	#$06
	sta	$4331
	ldx	#$1e40
	stx	$4332
	lda	#$7e
	sta	$4334
	


	jsr	WaitVb
	lda	#%00001111
	sta	$420c
	rts

list2129:	
	dc.b	$57,0,$48,$00,$1,$0,$0,$0

list2132:
	dc.b	$77,%11100111
	dc.b	$8,$0		;%11100111
	dc.b	$8,%11100111
	dc.b	$0,0,0,$0,$0

list210d:
	dc.b	$57,$00,$01,$00,$01
	dc.b	$48,$00,$01,$88,$00	; yay
	dc.b	$8,$00,$01,$00,$01
	dc.b	$10,$00,$01,$d8,0		:<-bot text
	dc.b	$01,$00,$01,$00,$01,0,0,0,0

list2106:
	dc.b	$57,$00,$79
	dc.b	$48,$00,$71
	dc.b	$08,$00,$79
	dc.b	$10,$00,$69		;x1<mosaic line 
	dc.b	$01,$00,$79
	dc.b	$0,$0,$0






;==========================================================================
;                           Sprite Setup routine
;==========================================================================

Sprite_setup:
	lda	#$62
	sta	$2101
	stz	$2102
	stz	$2103
	ldx	#$0000
sprtclear:
	stz	$2104		; Horizontal position
	lda	#$f0
	sta	$2104		; Vertical position
	stz	$2104		; sprite object = 0
	lda	#%00110000
	sta	$2104		; pallete = 0, priority = 0, h;v flip = 0
	inx
	cpx	#$0080		; (128 sprites)
	bne	sprtclear
	ldx	#$0000
sprtdataclear:
	stz	$2104		; clear H-position MSB
	stz	$2104		; and make size small
	inx
	cpx	#$0020		; 32 extra bytes for sprite data
				; info
	bne	sprtdataclear

	ldx	#$0000
clearspritememory:
	lda	#$20
	sta	$0500,x
	inx
	cpx	#$0220
	bne	clearspritememory

	rts


;==========================================================================
;                   SNES Register Initialization routine
;==========================================================================
Snes_Init:
	sep 	#$30    ; X,Y,A are 8 bit numbers
	lda 	#$8F    ; screen off, full brightness
	sta 	$2100   ; brightness + screen enable register 
	stz 	$2101   ; Sprite register (size + address in VRAM)
	stz 	$2102   ; Sprite registers (address of sprite memory [OAM])
	stz 	$2103   ;    ""                       ""
	stz 	$2105   ; Mode 0, = Graphic mode register
	stz 	$2106   ; noplanes, no mosaic, = Mosaic register
	stz 	$2107   ; Plane 0 map VRAM location
	stz 	$2108   ; Plane 1 map VRAM location
	stz 	$2109   ; Plane 2 map VRAM location
	stz 	$210A   ; Plane 3 map VRAM location
	stz 	$210B   ; Plane 0+1 Tile data location
	stz 	$210C   ; Plane 2+3 Tile data location
	stz 	$210D   ; Plane 0 scroll x (first 8 bits)
	stz 	$210D   ; Plane 0 scroll x (last 3 bits) #$0 - #$07ff
	stz 	$210E   ; Plane 0 scroll y (first 8 bits)
	stz 	$210E   ; Plane 0 scroll y (last 3 bits) #$0 - #$07ff
	stz 	$210F   ; Plane 1 scroll x (first 8 bits)
	stz 	$210F   ; Plane 1 scroll x (last 3 bits) #$0 - #$07ff
	stz 	$2110   ; Plane 1 scroll y (first 8 bits)
	stz 	$2110   ; Plane 1 scroll y (last 3 bits) #$0 - #$07ff
	stz 	$2111   ; Plane 2 scroll x (first 8 bits)
	stz 	$2111   ; Plane 2 scroll x (last 3 bits) #$0 - #$07ff
	stz 	$2112   ; Plane 2 scroll y (first 8 bits)
	stz 	$2112   ; Plane 2 scroll y (last 3 bits) #$0 - #$07ff
	stz 	$2113   ; Plane 3 scroll x (first 8 bits)
	stz 	$2113   ; Plane 3 scroll x (last 3 bits) #$0 - #$07ff
	stz 	$2114   ; Plane 3 scroll y (first 8 bits)
	stz 	$2114   ; Plane 3 scroll y (last 3 bits) #$0 - #$07ff
	lda 	#$80    ; increase VRAM address after writing to $2119
	sta 	$2115   ; VRAM address increment register
	stz 	$2116   ; VRAM address low
	stz 	$2117   ; VRAM address high
	stz 	$211A   ; Initial Mode 7 setting register
	stz 	$211B   ; Mode 7 matrix parameter A register (low)
	lda 	#$01
	sta 	$211B   ; Mode 7 matrix parameter A register (high)
	stz 	$211C   ; Mode 7 matrix parameter B register (low)
	stz 	$211C   ; Mode 7 matrix parameter B register (high)
	stz 	$211D   ; Mode 7 matrix parameter C register (low)
	stz 	$211D   ; Mode 7 matrix parameter C register (high)
	stz 	$211E   ; Mode 7 matrix parameter D register (low)
	sta 	$211E   ; Mode 7 matrix parameter D register (high)
	stz 	$211F   ; Mode 7 center position X register (low)
	stz 	$211F   ; Mode 7 center position X register (high)
	stz 	$2120   ; Mode 7 center position Y register (low)
	stz 	$2120   ; Mode 7 center position Y register (high)
	stz 	$2121   ; Color number register ($0-ff)
	stz 	$2123   ; BG1 & BG2 Window mask setting register
	stz 	$2124   ; BG3 & BG4 Window mask setting register
	stz 	$2125   ; OBJ & Color Window mask setting register
	stz 	$2126   ; Window 1 left position register
	stz 	$2127   ; Window 2 left position register
	stz 	$2128   ; Window 3 left position register
	stz 	$2129   ; Window 4 left position register
	stz 	$212A   ; BG1, BG2, BG3, BG4 Window Logic register
	stz 	$212B   ; OBJ, Color Window Logic Register (or,and,xor,xnor)
	sta 	$212C   ; Main Screen designation (planes, sprites enable)
	stz 	$212D   ; Sub Screen designation
	stz 	$212E   ; Window mask for Main Screen
	stz 	$212F   ; Window mask for Sub Screen
	lda 	#$30
	sta 	$2130   ; Color addition & screen addition init setting
	stz 	$2131   ; Add/Sub sub designation for screen, sprite, color
	lda 	#$E0
	sta 	$2132   ; color data for addition/subtraction
	stz 	$2133   ; Screen setting (interlace x,y/enable SFXdata)
	stz 	$4200   ; Enable V-blank, interrupt, Joypad register
	lda 	#$FF
	sta 	$4201   ; Programmable I/O port
	stz 	$4202   ; Multiplicand A
	stz 	$4203   ; Multiplier B
	stz 	$4204   ; Multiplier C
	stz 	$4205   ; Multiplicand C
	stz 	$4206   ; Divisor B
	stz 	$4207   ; Horizontal Count Timer
	stz 	$4208   ; Horizontal Count Timer MSB (most significant bit)
	stz 	$4209   ; Vertical Count Timer
	stz 	$420A   ; Vertical Count Timer MSB
	stz 	$420B   ; General DMA enable (bits 0-7)
	stz 	$420C   ; Horizontal DMA (HDMA) enable (bits 0-7)
	stz 	$420D	; Access cycle designation (slow/fast rom)
	rts




;===========================================================================
;                         Start Of Unpack Routine
;===========================================================================

;---------------------------------------------------------
; PRO-PACK Unpack Source Code - Super NES, Method 1
;
; Copyright (c) 1992 Rob Northen Computing
;
; File: RNC_1.S
;
; Date: 9.03.92
;---------------------------------------------------------
;---------------------------------------------------------
; Unpack Routine - Super NES, Method 1
;
; To unpack a packed file (in any data bank) to an output
; buffer (in any data bank) Note: the packed and unpacked
; files are limited to 65536 bytes in length.
;
; To call (assumes 16-bit accumulator)
;
;
; On exit,
;
; A, X, Y undefined, M=0, X=0
;---------------------------------------------------------
;---------------------------------------------------------
; Equates
;---------------------------------------------------------


;---------------------------------------------------------
UNPACK	rep	#$39	; 16-bit AXY, clear D and C
	lda	#Buff2
	sta	wrkbuf
	lda	#^Buff2
	sta	wrkbuf+2
	lda	#17
	adc	in
	sta	in
	lda	[in]
	and	#$00ff
	sta	blocks
	inc	in
	lda	[in]
	sta	bitbufl
	stz	bufbits
	lda	#2
	jsr	gtbits
unpack2	ldy	#rawtab
	jsr	makehuff
	ldy	#postab
	jsr	makehuff
	ldy	#slntab
	jsr	makehuff
	lda	#16
	jsr	gtbits
	sta	counts
	jmp	unpack8
unpack3	ldy	#postab
	jsr	gtval
	sta	temp2
	lda	out
	clc
	sbc	temp2
	sta	temp3
	ldy	#slntab
	jsr	gtval
	inc	a
	inc	a
	lsr	a
	tax
	ldy	#0
	lda	temp2
	bne	unpack5
	sep	#$20	; 8-bit accumulator
	lda	(temp3),y
	xba
	lda	(temp3),y
	rep	#$20	; 16-bit accumulator
unpack4	sta	(out),y
	iny
	iny
	dex
	bne	unpack4
	bra	unpack6
unpack5	lda	(temp3),y
	sta	(out),y
	iny
	iny
	dex
	bne	unpack5
unpack6	bcc	unpack7
	sep	#$20	; 8-bit accumulator
	lda	(temp3),y
	sta	(out),y
	iny
	rep	#$21	; 16-bit accumulator, clear carry
unpack7	tya
	adc	out
	sta	out
unpack8	ldy	#rawtab
	jsr	gtval
	tax
	beq	unpack14
	ldy	#0
	lsr	a
	beq	unpack10
	tax
unpack9	lda	[in],y
	sta	(out),y
	iny
	iny
	dex
	bne	unpack9
unpack10	bcc	unpack11
	sep	#$20	; 8-bit accumulator
	lda	[in],y
	sta	(out),y
	rep	#$21	; 16-bit accumulator, clear carry
	iny
unpack11	tya
	adc	in
	sta	in
	tya
	adc	out
	sta	out
	stz	bitbufh
	lda	bufbits
	tay
	asl	a
	tax
	lda	[in]
	cpy	#0
	beq	unpack13
unpack12	asl	a
	rol	bitbufh
	dey
	bne	unpack12
unpack13	sta	temp1
	phb
	phk
	plb
	lda	msktab,x		;>
	plb
	and	bitbufl
	ora	temp1
	sta	bitbufl
unpack14	dec	counts
	beq	.Mark1
	jmp	unpack3
.Mark1	dec	blocks
	beq	.Mark2
	jmp	unpack2
.Mark2	rts
;-----------------------------------------------------------
gtval	ldx	bitbufl
	bra	gtval3
gtval2	iny
	iny
gtval3	txa
	and	[wrkbuf],y
	iny
	iny
	cmp	[wrkbuf],y
	bne	gtval2
	tya
	adc	#(15*4+1)
	tay
	lda	[wrkbuf],y
	pha
	xba
	and	#$ff
	jsr	gtbits
	pla
	and	#$ff
	cmp	#2
	bcc	gtval4
	dec	a
	asl	a
	pha
	lsr	a
	jsr	gtbits
	plx
	phb
	phk
	plb
	ora	bittab,x		;>
	plb
gtval4	rts
bittab	dcr.w	1
	dcr.w	2
	dcr.w	4
	dcr.w	8
	dcr.w	$10
	dcr.w	$20
	dcr.w	$40
	dcr.w	$80
	dcr.w	$100
	dcr.w	$200
	dcr.w	$400
	dcr.w	$800
	dcr.w	$1000
	dcr.w	$2000
	dcr.w	$4000
	dcr.w	$8000
;-----------------------------------------------------------
gtbits	tay
	asl	a
	tax
	phb
	phk
	plb
	lda	msktab,x		;>
	plb
	and	bitbufl
	pha
	lda	bitbufh
	ldx	bufbits
	beq	gtbits3
gtbits2	lsr	a
	ror	bitbufl
	dey
	beq	gtbits4
	dex
	beq	gtbits3
	lsr	a
	ror	bitbufl
	dey
	beq	gtbits4
	dex
	bne	gtbits2
gtbits3	inc	in
	inc	in
	lda	[in]
	ldx	#16
	bra	gtbits2
gtbits4	dex
	stx	bufbits
	sta	bitbufh
	pla
gtbits5	rts
msktab	dcr.w	0
	dcr.w	1
	dcr.w	3
	dcr.w	7
	dcr.w	$f
	dcr.w	$1f
	dcr.w	$3f
	dcr.w	$7f
	dcr.w	$ff
	dcr.w	$1ff
	dcr.w	$3ff
	dcr.w	$7ff
	dcr.w	$fff
	dcr.w	$1fff
	dcr.w	$3fff
	dcr.w	$7fff
	dcr.w	$ffff
;-----------------------------------------------------------
makehuff	sty	temp4
	lda	#5
	jsr	gtbits
	beq	gtbits5
	sta	temp1
	sta	temp2
	ldy	#0
makehuff2	phy
	lda	#4
	jsr	gtbits
	ply
	sta	[wrkbuf],y
	iny
	iny
	dec	temp2
	bne	makehuff2
	stz	hufcde
	lda	#$8000
	sta	hufbse
	lda	#1
	sta	bitlen
makehuff3	lda	bitlen
	ldx	temp1
	ldy	#0
makehuff4	cmp	[wrkbuf],y
	bne	makehuff8
	phx
	sty	temp3
	asl	a
	tax
	phb
	phk
	plb
	lda	msktab,x		;>
	plb
	ldy	temp4
	sta	[wrkbuf],y
	iny
	iny
	lda	#16
	sec
	sbc	bitlen
	pha
	lda	hufcde
	sta	temp2
	ldx	bitlen
makehuff5	asl	temp2
	ror	a
	dex
	bne	makehuff5
	plx
	beq	makehuff7
makehuff6	lsr	a
	dex
	bne	makehuff6
makehuff7	sta	[wrkbuf],y
	iny
	iny
	sty	temp4
	tya
	clc
	adc	#(15*4)
	tay
	lda	bitlen
	xba
	sep	#$20	; 8-bit accumulator
	lda	temp3
	lsr	a
	rep	#$21	; 16-bit accumulator, clear carry
	sta	[wrkbuf],y
	lda	hufbse
	adc	hufcde
	sta	hufcde
	lda	bitlen
	ldy	temp3
	plx
makehuff8	iny
	iny
	dex
	bne	makehuff4
	lsr	hufbse
	inc	bitlen
	cmp	#16
	bne	makehuff3
	rts





MOFF	equ	$0200	;stop music 
MBONUS	equ	$0201	;timer bonus countdown
MCHEAT	equ	$0202	;cheat mode enabled
MCLICK	equ	$0203	;button click
MOVER	equ	$0204	;game over/time up
MTRING	equ	$0205	;tring for startup of the wildcard
MSOLVED	equ	$0206	;puzzle solved tune
MTUNE	equ	$0207	;New tune....
MWINDOW	equ	$0208	;Open selection window
MSELECT	equ	$0209	;Move cursor up and down
MRESET	equ	$0400	; reset the music controller

tune	rep #$30
	;lda #MTUNE
	lda	#MBONUS
	jsr NewSound_l
	sep #$20
 	rts

tuneoff:
	rep	#$30
	lda	#MRESET
	jsr	NewSound_l
	sep	#$20
	rts


	rep 	#$30
NewSound_l 	
	ora	toggle 
	sta	$2140 
	lda	toggle 
	eor	#$0100 
	sta	toggle 
	rts


musique:
	
	rep	#$30
	stz	toggle

 	sep	#$20
	lda	#$7f
	sta $a5 
	lda #00 
	sta $a4 
	sta $a3 
 

	php       
	rep     #$30  
	ldy     #$0000  
	lda     #$bbaa  
L00f7b6 cmp     $2140 
	bne     L00f7b6  
	sep     #$20  
	lda     #$cc  
	bra     L00f7f5 
L00f7c1 lda     [$a3],y  
	iny       
	bpl     L00f7cb		; check for bank overflow 
	ldy     #$0000 		; if so, zero y 
	inc     $a5		; and inc work reg bank 
L00f7cb xba       
	lda     #$00  
	bra     L00f7e2 
L00f7d0 xba       
	lda     [$a3],y  
	iny       
	bpl     L00f7db    	; check for bank overflow 
	ldy     #$0000		; if so, zero y 
	inc     $a5 		; and inc work reg bank 
L00f7db xba       
L00f7dc cmp     $2140 
	bne     L00f7dc  
	inc     a  
L00f7e2 rep     #$20  
	sta     $2140 
	sep     #$20  
	dex       
	bne     L00f7d0  
L00f7ec cmp     $2140 
	bne     L00f7ec  
L00f7f1 adc     #$03  
	beq     L00f7f1  
L00f7f5 pha       
	rep     #$20  
	lda     [$a3],y  
	iny       
	iny       
	tax       
	lda     [$a3],y  
	iny       
	iny       
	sta     $2142 
	sep     #$20  
	cpx     #$0001  
	lda     #$00  
	rol     a  
	sta     $2141 
	adc     #$7f  
	pla       
	sta     $2140 
L00f815 cmp     $2140 
	bne     L00f815  
	bvs     L00f7c1  
	plp       
	sep     #$30  
	rts     





Colors:

	; static colors (grey)

	dc.w	$0000,$4208,$8410,$C618,$0821,$4A29,$8C31,$CE39
	dc.w	$1042,$524A,$9452,$D65A,$1863,$5A6B,$9C73,$FF7F 
 

	; atx colors (greys/blues..)

	dcr.w	$4631,$1888,$739C,$6B58,$6316,$5AD4,$5A92,$5250
	dcr.w	$4A0E,$420C,$41CC,$39CA,$398A,$2988,$2946,$20C4 

	; font colors 
	;                   orange
	dcr.w	$4210,$739C,$675C,$5F1B,$52DB,$4ABA,$3E79,$3639
	dcr.w	$2DF8,$25D8,$1D97,$1577,$0D36,$0515,$00F5,$18c6
	;                   blue
	dcr.w	$4210,$739C,$737A,$6F38,$6EF6,$6AD3,$6691,$664F
	dcr.w	$622D,$61EB,$5DA8,$5D86,$5944,$5902,$54E0,$0000
	;                   cyan
	dcr.w	$4210,$739C,$6F7A,$6758,$5F36,$5B14,$52F1,$4ACF
	dcr.w	$468D,$3E6B,$3648,$3226,$2A04,$21E2,$1DC0,$0000
	;		    red
	dcr.w	$4210,$7FFF,$7BBF,$737E,$6F1E,$66DD,$627C,$5A3C
	dcr.w	$55DB,$4D9B,$493A,$40F9,$3C99,$3458,$3018,$0000 
	;		    yellow
	dcr.w	$4210,$7FFF,$77DF,$6FBE,$637D,$5B5C,$533B,$4AFA
	dcr.w	$3ED9,$36B8,$2E77,$2656,$1A15,$11F5,$09D4,$0000 
	;			; green
	dcr.w	$4210,$6BFF,$63DE,$5BBC,$539B,$4B79,$4358,$3B36
	dcr.w	$3314,$2AF3,$22B1,$1A90,$126E,$0A4D,$022B,$0000 
	;		sprite colors
	;                   yellow
	dcr.w	$0000,$0193,$7FFF,$6739,$033F,$02FF,$02BD,$027B
	dcr.w	$0239,$01D7,$0195,$0153,$0111,$00CE,$008C,$000A 
	;	
	dcr.w	$0000,$02EF,$7FFF,$6739,$03FF,$03BD,$037A,$0337
	dcr.w	$02D4,$0291,$024E,$020B,$01A8,$0165,$0123,$00E0 
	;
	dcr.w	$0000,$5A40,$7FFF,$6739,$7FE0,$77A0,$6F40,$66E0
	dcr.w	$5EA0,$5240,$49E0,$41A0,$3940,$2CE0,$24A0,$1C40 
	;
	dcr.w	$0000,$01DB,$7FFF,$6739,$3B3F,$36DE,$329D,$2A5B
	dcr.w	$261A,$21B9,$1977,$1536,$10D5,$0893,$0452,$0010 
	;
	dcr.w	$0000,$4AFB,$7FFF,$6739,$3B3F,$3ADE,$3E9D,$3E5B
	dcr.w	$3E1A,$3DB9,$3D77,$4136,$40D5,$4093,$4052,$4010 
	;
	dcr.w	$0000,$6718,$7FFF,$6739,$739C,$6F5A,$6718,$5ED5
	dcr.w	$5693,$5251,$4A0F,$41CD,$3D8A,$3548,$2D06,$28C4 
	;
	dcr.w	$0000,$6718,$7FFF,$6739,$6B7C,$631C,$5EDC,$5A7C
	dcr.w	$563C,$51DB,$4D9B,$493B,$44FB,$3CBB,$385B,$341B 
	;
	dcr.w	$0000,$4E99,$7FFF,$6739,$6B7C,$5F3B,$56FA,$4E99
	dcr.w	$4258,$3A18,$2DD7,$2596,$1D55,$1114,$08D3,$0092 

 

fontpos:
	dc.b	0	;SP
	dc.b	$a	;!
	dc.b	$c	;"
	dc.b	0	;#
	dc.b	0 	;$
	dc.b	0 	;%
	dc.b	$2a	;&
	dc.b	$2	;'
	dc.b	$4	;(
	dc.b	$6	;)
	dc.b	$28	;* HE
	dc.b	$2a	;+
	dc.b	$2c	;,
	dc.b	$2e	;-
	dc.b	$0e	;.
	dc.b	$00	;/
	dc.b	$20	;0
	dc.b	$22	;1
	dc.b	$24	;2
	dc.b	$26	;3
	dc.b	$48	;4
	dc.b	$4a	;5
	dc.b	$4c	;6
	dc.b	$4e	;7
	dc.b	$60	;8
	dc.b	$62	;9
	dc.b	$40	;:
	dc.b	$40	;;
	dc.b	$4	;<
	dc.b	$46	;=
	dc.b	$6	;>
	dc.b	$6c	;?
	dc.b	$00	;@
	dc.b	$80	;A
	dc.b	$82	;B
	dc.b	$84	;C
	dc.b	$64	;D
	dc.b	$66	;E
	dc.b	$68	;F
	dc.b	$6a	;G
	dc.b	$8e	;H
	dc.b	$a0	;I
	dc.b	$a2	;J
	dc.b	$a4	;k
	dc.b	$a6	;l
	dc.b	$a8	;m
	dc.b	$86	;n
	dc.b	$88	;o
	dc.b	$8a	;p
	dc.b	$8c	;q
	dc.b	$c0	;r
	dc.b	$c2	;s
	dc.b	$c4	;t
	dc.b	$c6	;u
	dc.b	$c8	;v
	dc.b	$ca	;w
	dc.b	$aa	;x
	dc.b	$ac	;y
	dc.b	$ae	;z
 

YES:	dc.b	"YES"

NO:
	dc.b	"NO "

LOW:
	dc.b	0,0,0,0
	dc.b	0,0,0,1
	dc.b	0,0,0,2
	dc.b	0,0,0,3
	dc.b	0,0,0,4
	dc.b	0,0,0,5
	dc.b	0,0,0,6
	dc.b	0,0,0,7
	dc.b	0,0,0,8
	dc.b	0,0,0,9
	dc.b	0,0,1,0
	dc.b	0,0,1,1
	dc.b	0,0,1,2
	dc.b	0,0,1,3
	dc.b	0,0,1,4
	dc.b	0,0,1,5
	
HIGH:
	dc.b	0,0,0,0
	dc.b	0,0,1,6
	dc.b	0,0,3,2
	dc.b	0,0,4,8
	dc.b	0,0,6,4
	dc.b	0,0,8,0
	dc.b	0,0,9,6
	dc.b	0,1,1,2
	dc.b	0,1,2,8
	dc.b	0,1,4,4
	dc.b	0,1,6,0
	dc.b	0,1,7,6
	dc.b	0,1,9,2
	dc.b	0,2,0,8
	dc.b	0,2,2,4
	dc.b	0,2,4,0


vertsine:

 dc.b  24,25,25,26,26,27,28,28,29,29,30,30,31,32,32,33,33,34,34,35
 dc.b  35,36,36,37,37,38,38,39,39,40,40,41,41,41,42,42,43,43,43,44
 dc.b  44,44,45,45,45,45,46,46,46,46,47,47,47,47,47,47,48,48,48,48
 dc.b  48,48,48,48,48,48,48,48,48,48,48,48,48,47,47,47,47,47,47,46
 dc.b  46,46,46,45,45,45,45,44,44,44,43,43,43,42,42,41,41,41,40,40
 dc.b  39,39,38,38,37,37,36,36,35,35,34,34,33,33,32,32,31,30,30,29
 dc.b  29,28,28,27,26,26,25,25,24,23,23,22,22,21,20,20,19,19,18,18
 dc.b  17,16,16,15,15,14,14,13,13,12,12,11,11,10,10,9,9,8,8,7,7,7
 dc.b  6,6,5,5,5,4,4,4,3,3,3,3,2,2,2,2,1,1,1,1,1,1,0,0,0,0,0,0,0,0
 dc.b  0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,5,5,5,6
 dc.b  6,7,7,7,8,8,9,9,10,10,11,11,12,12,13,13,14,14,15,15,16,16,17
 dc.b  18,18,19,19,20,20,21,22,22,23,23


 


randomnumbers:
	dc.w	$3AA7,$3ECB,$3A50,$9684,$6807,$6DBA,$0FA0
	dc.w	$C455,$722F,$3280,$630A,$A402,$244E,$3FF7,$FBB5
	dc.w	$83F4,$7210,$0165,$6688,$1248,$516B,$43BB,$E401
	dc.w	$656A,$7144,$7525,$C2AE,$E455,$B7A9,$9087,$5E33
	dc.w	$8C23,$002A,$33B1,$A61E,$1989,$E1AA,$FC54,$8A0B
	dc.w	$1722,$1FEE,$9226,$079B,$68D5,$1090,$FEC8,$3B4C
	dc.w	$10DA,$EF06,$A471,$46B7,$4D47,$1984,$3F3F,$FC58
	dc.w	$D0E2,$B601,$ECF3,$5647,$4113,$738B,$305F,$914A
	dc.w	$8665,$420B,$D45B,$8825,$F3B6,$F2C1,$ABEF,$96CA
	dc.w	$4BD7,$A1D4,$8D0C,$A6B1,$EF4C,$033E,$8FAF,$CE49
	dc.w	$4975,$72FD,$9552,$1366,$3FBE,$67F9,$61BF,$307C
	dc.w	$2B57,$0FBF,$05C1,$FAA3,$0E8E,$DA0D,$6BDA,$E101
	dc.w	$DF3D,$CBF2,$8C3A,$0D97,$BED5,$FAD5,$30D9,$361D
	dc.w	$9C81,$3C27,$5BBD,$45EE,$2C62,$8B21,$5424,$1976
	dc.w	$3D5B,$3778,$7599,$3EB8,$6A92,$3C30,$BF88,$2F27
	dc.w	$ABE4,$C50F,$256F,$15AF,$FB7C,$BF5C,$3407,$DCCE
	dc.w	$361A


staticgfx:
	.bin	static2.dat
atxgfx:
	;.bin	atx_logo.rnc
	;.bin	font.rnc
	.bin	logofont.rnc	; both files packed into one
atxtile:
	;.bin	atx_logo.char
	.bin	atxchar.rnc
sprtgfx:
	.bin	scroll.rnc

music:
	;.bin	atxchip3.rnc
	.bin	atxchip4.rnc
bottext:

		;********************************
	text	$10,"     Intro Coded By: -Pan-      "
	text	$10," Music Composed By: The Doctor  "

	text	$14,"       U.S.S. Enterprise        "
	text	$14,"  412-233-2611  Sysop: Picard   "

	text	$18,"     Intro Coded By: -Pan-      "
	text	$18," Music Composed By: The Doctor  "

	text	$1c,"           Trade Line           "
	text	$1c," 514-966-9569 Sysop: Wild Fire  "

	text	$10,"     Intro Coded By: -Pan-      "
	text	$10," Music Composed By: The Doctor  "

	text	$14,"            Dial Hard           "
	text	$14,"  +41-7350-0155   Sysop: Fury   "

	text	$18,"     Intro Coded By: -Pan-      "
	text	$18," Music Composed By: The Doctor  "

	text	$1c,"              Synergy           "
	text	$1c," +49-PRIVATE Sysop: Sigma Seven "

	text	$10,"     Intro Coded By: -Pan-      "
	text	$10," Music Composed By: The Doctor  "

	text	$14,"       U.S.S. Enterprise        "
	text	$14,"  412-233-2611  Sysop: Picard   "

	text	$18,"     Intro Coded By: -Pan-      "
	text	$18," Music Composed By: The Doctor  "

	text	$1c,"           Trade Line           "
	text	$1c," 514-966-9569 Sysop: Wild Fire  "

	text	$10,"     Intro Coded By: -Pan-      "
	text	$10," Music Composed By: The Doctor  "

	text	$14,"            Dial Hard           "
	text	$14,"  +41-7350-0155   Sysop: Fury   "

	text	$18,"     Intro Coded By: -Pan-      "
	text	$18," Music Composed By: The Doctor  "

	text	$1c,"              Synergy           "
	text	$1c," +49-PRIVATE Sysop: Sigma Seven "


gameover:
	rep	#$30
	sep	#$20
	ldx	#$0000
copycheatdata:
	lda	$1c00,x
	sta	>$700000,x
	inx
	cpx	#$0020
	bne	copycheatdata

	sep	#$30
	lda	#$00
	phk
	plb
	dc.b	$5c,$00,$80,$00		: <- jump to game!!



menutxt:
	
	dc.b	"   Unlimited Lives:      Yes    "
	dc.b	"   Unlimited Health:     Yes    "
	dc.b	"   In-Game Buttons:      Yes    "
	dc.b	"      Read Scroll Text For      "
	dc.b	"         In-Game Buttons        "
	dc.b	"                                "
	dc.b	"                                "
	dc.b	"                                "
	dc.b	"                                "
	dc.b	"                                "
	dc.b	"                                "
	dc.b	"                                "
	dc.b	"                                "
	dc.b	"                                "
	dc.b	"                                "
	dc.b	"                                "
	dc.b	"                                "
	dc.b	"                                "
	dc.b	"                                "
	dc.b	"                                "
	dc.b	"                                "
	dc.b	"                                "
	dc.b	"                                "
	dc.b	"                                "
	dc.b	"                                "
	dc.b	"                                "
	dc.b	"                                "
	dc.b	"                                "
	dc.b	"         Putty Squad +3         "
	dc.b	"     Original by Mad Turnip     "
	dc.b    "     Trained By -Pan- + TWK     "
	dc.b    "                                "

	; 0 = yellow
	; 1 = yellow/green
	; 2 = sky blue
	; 3 = red/orange
	; 4 = purple/pink
	; 5 = silver
	; 6 = pink
	; 7 = brown

scrolltext:
	dc.b	" #%1-putty squad- %0was released and trained by %7anthrox%0 on %54-30-95%0  "
	dc.b	"  $we greet these fine groups: #Censor   Cyberforce   Elite   Nightfall "
	dc.b	"and others that TWK forgot!         $the in game butts be: "
	dc.b	"sel+top left = level skip    sel+top right = open all doors  sel+a = select item 1  "
	dc.b	"     # %4 see ya!!      %1-pan-     "
	dc.b	"                           ",0



options:
	dc.b	3		;<- # of options
Type:                              
        dc.b    0,0,0,0,0,0,0,0,0,0,0,0,1  
                                   
Min:                               
        dc.b    1,0,1,1,0,1,1,1,3,0,0,0,1
                                   
Max:                               
        dc.b    9,5,5,5,5,6,1,1,1,1,1,1,12 
                                   
Begin:                             
        dc.b    2,4,4,1,0,1,1,1,3,0,0,0,1  



Slow:
	php
	sep	#$30
	dc.b	$af,$00,$00,$70
	and	#$01
	eor	#$01
	sta	$420d
	plp
	rtl




Cheat:
	dc.b	$ad,$18,$42
	dc.b	$85,$7a
	pha
	php
	sep	#$30
	dc.b	$af,$01,$80,$70
	beq	Livesoff
	lda	#$09
	sta	$1da1
	sta	$1da3
Livesoff:
	dc.b	$af,$02,$80,$70
	beq	Damage
	lda	#$0a
	sta	$1d09
	sta	$1d0b

Damage:
	;dc.b	$af,$03,$80,$70
	;beq	noammo
	;lda	#$99
	;sta	$1096
noammo:
	dc.b	$af,$03,$80,$70
	beq	nohyper
	lda	#$01
	sta	$1db1
	sta	$1db3

nohyper:
	dc.b	$af,$04,$80,$70
	beq	nothingy
	lda	#$01
	dc.b	$8f,$e0,$65,$7e
nothingy:
	;dc.b	$af,$05,$80,$70
	;beq	nojumpy
	;rep	#$30
	;dc.b	$a5,$7a
	;cmp	#$2020
	;bne	nojumpy
	;stz	$7a
	;sep	#$20
	;stz	$1e05

nojumpy:
	sep	#$20
	
	plp
	pla
	rtl
Time1:

	php
	sep	#$20
	dc.b	$af,$03,$80,$70
	beq	timeoff
	plp
	dc.b	$5c,$ab,$89,$01
	rtl
timeoff:
	plp
	dc.b	$a9,$e5,$04
	dc.b	$85,$e9
	dc.b	$5c,$9f,$89,$01
	;rtl
LEVEL:

	lda	$1a03
	bne	levelhere2
	bra	levelhere
levelthing:
	dc.b	$5c,$7d,$9e,$1d


levelhere:
	php
	rep	#$30
	dc.b	$af,$0c,$00,$70
	and	#$00ff
	dec a
	asl a
	asl a
	asl a
	sta	>$7e1a03
	plp
	lda	>$7e1a03
	beq	levelthing
	dc.b	$5c,$95,$9e,$1d

levelhere2:
	lda	$7e1a03
	dc.b	$5c,$95,$9e,$1d
	rtl

leveljunk:
	dcr.w	$8,$b,$14,$1d,$29,$33

IRQ:
	;dc.b	$ee,$c6,$ec
	;dc.b	$af,$10,$42,$00
	pha
	php
	sep	#$20
	dc.b	$af,$00,$00,$70
	beq	IRQnrg
	lda	#$03
	sta	>$7e0035
	sta	>$7e0037
IRQnrg:
	dc.b	$af,$01,$00,$70
	beq	IRQtime

	lda	#$4e
	sta	>$7e0026
	sta	>$7e0028
IRQtime:
	dc.b	$af,$02,$00,$70
	bne	IRQinvul



IRQend:
	plp
	pla
	rtl

IRQinvul:

	lda	>$7e1776
	ora	>$7e1778
	cmp	#$20
	beq	selectison
	plp
	pla
	rtl
selectison:

	lda	>$7e1775
	ora	>$7e1777
	and	#$20
	cmp	#$20
	bne	nolevelskippy
	sep	#$30
	;lda	>$7e0039
	lda	>$7e003a
	cmp	#$ff
	bne	nolevelskippy

	phx
	ldx	#$fe
levelloop:
	inx
	inx
	cpx	#$4c
	beq	forgetitall
	lda	>$0084f2,x
	cmp	>$7e003b
	bne	levelloop
	inx
	inx
	lda	>$0084f2,x
	sta	>$7e0039
	lda	#$00
	sta	>$7e003a
	plx	
	plp
	pla
	rtl

forgetitall:
	ldx	#$4e
	lda	>$0084f2,x
	sta	>$7e0039
	lda	#$00
	sta	>$7e003a
	plx
	plp
	pla
	rtl

nolevelskippy:
	lda	>$7e1775
	ora	>$7e1777
	and	#$10		; 10
	cmp	#$10
	bne	nodooropen
	lda	#$00
	sta	>$7e0024
	plp
	pla
	rtl

nodooropen:
	lda	>$7e1775	; 6
	and	#$80		; 80
	cmp	#$80
	bne	noitemsel1
	
	lda	>$70000f
	inc a
	and	#$07
	sta	>$70000f
	bne	noitemsel1


	lda	>$7e006d
	inc a
	inc a
	cmp	#$0c
	bcs	item1over
	sta	>$7e006d
	plp
	pla
	rtl

item1over:
	lda	#$00
	sta	>$7e006d
	plp
	pla
	rtl

noitemsel1:

	lda	>$7e1777
	and	#$80
	cmp	#$80
	bne	noitemsel2

	lda     >$70000f  
	inc a             
	and     #$07      
	sta     >$70000f  
	bne     noitemsel2


	lda	>$7e006f
	inc a
	inc a
	cmp	#$0c
	bcs	item2over
	sta	>$7e006f
	plp
	pla
	rtl

item2over:
	lda	#$00
	sta	>$7e006f
noitemsel2:
	plp
	pla
	rtl





	org	$fffc	;reset vector in 6502 mode
	dcr.w	Start
	.pad
