;****************************************
;sets escape event $0E upon entering room.
;set the desired 'endgame trigger room'
;main ASM pointer to FF00

;****************************************
;after entering a room, a brief delay passes and then a
;message appears that instructs player to return to ship
;note - you can't have over 29 enemies in the room since
;this patch bootlegs an enemy variable for a delay timer.


LOROM
;bootleg enemy RAM - don't change this unless you know
;what you are doing!!!
!eRAM = $16FA


;add main ASM to run handling of event and message
ORG $8FFF00
;if timer high enough, skip
LDA !eRAM : CMP #$0100 : BMI + : RTS
+
;if event is set already just return
LDA #$000E : JSL $808233 : BCC +
	LDA #$0100 : !eRAM : RTS
+
;if timer equal, display message box
LDA !eRAM : CMP #$00FF : BNE +
	;set escape event
	LDA #$000E : JSL $8081FA
	;play song A
	LDA #$0001 : JSL $808FC1
	;Play room music track after 6 seconds, display message
	LDA #$0168 : JSL $82E118 : LDA #$001E : JSL $858080
+
INC !eRAM : RTS


;move the button array to freespace to make room for more messages
ORG $858412
LDA $96C0,x


;add these messages to end of list of message tilemap pointers:
ORG $858749
dw $8436, $8289, $9700 ;new mission clear message
dw $8436, $8289, $9740 ;terminator message - is not used


;new button ASM array
ORG $8596C0
db $00,$00,$2A,$01,$2A,$01,$2C,$01,$FF,$FF,$2C,$01,$00,$00,$00,$00
db $00,$00,$00,$00,$00,$00,$00,$00,$20,$01,$00,$00,$00,$00,$00,$00
db $00,$00,$00,$00,$2A,$01,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
db $00,$00,$00,$00,$00,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF


ORG $859700
;endgame message, message 1E
db $0E,$00,$0E,$00,$0E,$00,$0E,$00,$0E,$00,$0E,$00,$4E,$28,$4E,$28
db $F1,$28,$E4,$28,$F3,$28,$F4,$28,$F1,$28,$ED,$28,$4E,$28,$F3,$28
db $EE,$28,$0F,$28,$F2,$28,$E7,$28,$E8,$28,$EF,$28,$4E,$28,$4E,$28
db $4E,$28,$0E,$00,$0E,$00,$0E,$00,$0E,$00,$0E,$00,$0E,$00,$0E,$00
;endgame terminator, message 1F, dup of endgame message, unuseable
db $0E,$00,$0E,$00,$0E,$00,$0E,$00,$0E,$00,$0E,$00,$4E,$28,$4E,$28
db $F1,$28,$E4,$28,$F3,$28,$F4,$28,$F1,$28,$ED,$28,$4E,$28,$F3,$28
db $EE,$28,$0F,$28,$F2,$28,$E7,$28,$E8,$28,$EF,$28,$4E,$28,$4E,$28
db $4E,$28,$0E,$00,$0E,$00,$0E,$00,$0E,$00,$0E,$00,$0E,$00,$0E,$00
