lorom


!up = $09AA
!down = $09AC
!left = $09AE
!right = $09B0
!shoot = $09B2
!jump = $09B4
!run = $09B6
!cancel = $09B8
!select = $09BA
!L = $09BC
!R = $09BE
!icon = $09D2

!libpos = #$0094			;x positions for the number displays
!sfxpos = #$009C
!quepos = #$00A2
!typepos = #$00A8

org $809B44

	JSR MainHUDRoutine
	RTL
	
	
org $80CD93

CURSORPOS:
	DW !libpos-2
	DW !sfxpos-2
	DW !quepos-2
	DW !typepos-2



MainHUDRoutine:
        PHP : PHB : PHK : PLB : REP #$30
		
		PEA $8000
		PLB
		PLB

INIT:

		LDX #$0000
-
		LDA #$280F
		STA $7EC608,x				;clear HUD
		INX
		INX
		CPX #$0120
		BNE -
print " START 1 ",pc				;testing print command for xkas
		LDA $072D					;Used as a timer in the pause screen for selection flashing
									;7E:072F - 7E:0730    Used as a timer in the pause screen for reserve tank flashing
		CMP #$7777
		BEQ +
		LDA #$7777
		STA $072D
		STZ !icon

		LDX #$0000
-
		STZ $09C6,x
		INX
		INX
		CPX #$0020
		BNE -
		LDA #$0005
		STA $09CC
		LDA #$0080
		JSL $808FC1
+	
		LDA #$8000 : STA $0A78
		STA $05F7												;place new game state here, disable automap, set game state
		JSL $86800B : JSL $8483B8 : JSL $87800B : JSL $8DC4CD	;disables e/r projectiles, PLMS, animations, cascade fx
		JSL $90F084	
		LDA #$0005 : STA $0CD2	: STA $0CCE						;max out projectile and bomb counter
																;disable charge
		
		LDA $8F
		BIT !left
		BEQ +
		DEC !icon
+
		BIT !right
		BEQ +
		INC !icon
+
		LDA !icon
		BPL +
		LDA #$0003
		STA !icon
		BRA ++
+
		CMP #$0004
		BCC ++
		STZ !icon
++		
		LDA !icon
		ASL
		TAX
		PHX
		LDA CURSORPOS,x
		TAX
		LDA #$3833
		STA $7EC608,x
		PLX
		LDA $8F
		BIT !up
		BEQ +
		INC $09C6,x
		
		BRA ++
+
		BIT !down
		BEQ ++
		DEC $09C6,x
++
		LDA #NUMBERS
		STA $00
		SEP #$20
		STZ $02
		REP #$20
		LDA $09C6		;defines library	

		LDX !libpos
		JSR DISPLAY		;display library
		; JSR $9D98
+
		LDA $09C8
		LDX !sfxpos
		JSR DISPLAY		;display sound
		; JSR $9D98
+
		LDA $09CA
		LDX !quepos
		JSR DISPLAY		;display queue
		; JSR $9D98
+
		LDA $09CC
		LDX !typepos
		JSR DISPLAY		;display song version
		; JSR $9D98
+
		LDA $09C6
		BPL +
		LDA #$0003
		BRA ++
+
		AND #$0003
		CMP #$0003
		BCC ++
		LDA #$0000
++
		STA $09C6
		ASL
		TAX
		LDA $09C8
		BPL +
		LDA MAXLIBSFX,x
		DEC
		STA $09C8
		BRA ++
+
		CMP MAXLIBSFX,x
		BCC ++
		STZ $09C8
++
		LDA $8F
		BIT !jump
		BEQ +
		LDA $09C8
		JSR (WHATLIB,x)
+
		LDA $8F
		BIT !shoot
		BEQ +++
		LDA $09CA
		AND #$00FF
		ORA #$FF00
		JSL $808FC1
		
		LDA $09CC
		BPL +
		LDA #$0007
		STA $09CC
		BRA ++
+
		CMP #$0008
		BCC ++
		LDA #$0005
		STA $09CC
++
		JSL $808FC1
+++
        LDX $0330 : LDA #$00C0 : STA $D0,X : INX : INX
        LDA #$C608 : STA $D0,X : INX : INX
        LDA #$007E : STA $D0,X : INX
        LDA #$5820 : STA $D0,X : INX : INX 
        STX $0330 : PLB : PLP : RTS	
		
LIB1:
	JSL $80903F
	RTS
	
LIB2:
	JSL $8090C1
	RTS
	
LIB3:
	JSL $809143
	RTS
	
	
DISPLAY:
print " display ",pc
	PHA
	AND #$00F0
	LSR
	LSR
	LSR
	TAY
	LDA [$00],y
	STA $7EC608,x
	PLA
	AND #$000F
	ASL
	TAY
	LDA [$00],y
	STA $7EC60A,x
	RTS
	
	
WHATLIB:
	DW LIB1
	DW LIB2
	DW LIB3
	
MAXLIBSFX:
	DW $0043		;maximum amount of sounds available for the current library + 1
	DW $0080
	DW $002F

NUMBERS:
	DW $0C00
	DW $0C01
	DW $0C02
	DW $0C03
	DW $0C04
	DW $0C05
	DW $0C06
	DW $0C07
	DW $0C08
	DW $0C09
	DW $0C40
	DW $0C41
	DW $0C42
	DW $0C43
	DW $0C44
	DW $0C45
