Mail has been fixed; you should now be able to confirm your e-mail address, watch pages, and the like.
Please report any issues on Discord.

Spirou (Game Gear)

From The Cutting Room Floor
Jump to navigation Jump to search

Title Screen

Spirou

Developer: Bit Managers
Platform: Game Gear


SourceIcon.png This game has uncompiled source code.
LevelSelectIcon.png This game has a hidden level select.


We could only wish we were playing this right now... maybe...
This game was never completed and/or given a public release.
As a result of this, keep in mind that the developers might have used or deleted some of the content featured here, had the game actually reached store shelves.
Hmmm...
To do:
Document any source code fragments that were missed and other development-related stuff that made its way into the ROM.

Level Select

Spirou GG Level Select.png

Pause the game and press Down, Down, 1, Left, Right, 2, Down, Up, 2.

Source Code Fragments

Cacti speak Japanese.
...But what does it mean?
This game has text or audio that needs to be translated. If you are fluent with this language, please read our translation guidelines and then submit a translation!

Present throughout much of the bottom third of the ROM space, alongside messages from the compiler used.

0x63E81

	and	#0f
	PRTA	1,0,3

	ldal	PersoJump
	PRTA	2,0,3
	ENDIF

	ldal	vargen2
	inc	a
	stal	vargen2
	PRTA	3,4,3
	is60	jr,$GUdiff_chdes	; Origin is not a 60
	ldal	vargen2
	inc	a
	stal	vargen2
	PRTA	3,4,3
+\2*8
	ldhll	var1
	PRTHL	3,4,5


	ldhll	var1
	PRTHL	3,4,5
	ldal	vargen2
	inc	a
	stal	vargen2
	PRTA	3,4,3
	ldhll	var1
	PRTHL	3,0,5

	ldhll	var1
	PRTHL	3,0,5
 
	ldal	vargen2
	inc	a
	stal	vargen2
	PRTA	3,4,3
	ldal	vargen2
	inc	a
	stal	vargen2
	PRTA	3,4,3


$GUdiff_chdes
;	MARCA
	call	GetHigh60\1	; X

	ld	c,a
	cmp	#80

	if	narg=3
	\3	z
	else
	\3	z,\4
	endif

	bit	7,a
	jnz	$\@yes

	ldal	Perso\2	; Y
	and	#0f
	cmp	c

	if	narg=3
	\3	c
	else
	\3	c,\4
	endif
\1	; 
$GUdiff_chdes
;	MARCA
	;is60	jr,$GUdiff_chdes	; Origin is not a 60
	jp	c,$GUdiff_chdes
	jp	$

;	jp	z,$GUdiff_chdes
;	jp	c,$GUdiff_chdes
;	MARCA
$adjwhenmovex
;	MARCA
	if	1
	endif
	lda	vargen
	inc	a
	sta	vargen
	;PRTA	3,0,3


	lda	vargen
	inc	a
	sta	vargen
	;PRTA	3,0,3
	lda	vargen
	inc	a
	sta	vargen
	PRTA	3,0,3
	lda	vargen
	inc	a
	sta	vargen
	PRTA	3,0,3
	;Dani arreglo start

	;ldal	WORLD
	;cpx	AEREO
	;jz          $GUdiff_in

	;Dani arreglo end




	IF	0

	ENDIF
	IF	0

$GUadjAnt
	jz	$GUadjAnt
	jc          $GUadjAnt
	jz	$GUadjAnt
	jc          $GUadjAnt
;	MARCA START
;	MARCA END
	ld	a,(hl)
	cmp	MAXSLOPE
	bcs	$\@si
	ldhll
	ld	a,(hl)
	cmp	MAXSLOPE
	bcs	$\@si
	cp
;	MARCA END

	IF	0
;	MARCA START

	; Origen en una inclinada

	call	GetHigh60XAnt
	ld	c,a
	cmp	#80
	jp	z,$GUdiff_chdes
	bit	7,a
	jnz	$yes

	ldal	PersoY
	and	#0f
	cmp	c
	jp	nc,$GUdiff_chdes
$yes

;	isin	XAnt,Y,jp,$GUdiff_chdes

;	MARCA END
	ENDIF




	cp	MAXSLOPE
	jnc
	cp	MAXSLOPE
	jc	$GUdiff_chdes
	jr	$ok
	jc	$GUdiff_chdes

	push	af
	pop	af
	ld	a,c
pop	af
	IF	0
diff_chdes
diff_chdes
	ld	c,a

	ld	a,c
ld	a,c
ldhll	HOTY
	ld	a,(hl)
	

	IF	1
	ENDIF
AEREO
PANTANO	;AEREO
512+40
	;5/2
	;4/2
	stal	CachoMuro

$cont
CUEVA
FABRICA
	IF	MASRNC

0x6587A

$=S_TxtMenu
	dw	AL_TxtMenu

IdiomaOptions:
	dw	IN_TxtOptions
	dw	FR_TxtOptions
	dw	ES_TxtOptions
	dw	AL_TxtOptions

;	Rutina de menu

MenuMain:

$Whitechar		=	128	  ; Codigo pieza blanco
$Codecursor		=	0	  ; Codigo pieza spr.cursor
	IF	GB
$InitPosYM		=	68+16	  ; Pos.inicial Y cursor menu
$InitPosXM		=	36+8	  ; Pos.inicial X cursor menu
$InitPosYO		=           68+16	  ; Pos.inicial Y cursor opt.
$InitPosXO		=	36+8	  ; Pos.inicial X cursor opt.
	ELSE
$InitPosYM		=	68+#17	  ; Pos.inicial Y cursor menu
$InitPosXM		=	36+#30	  ; Pos.inicial X cursor menu
$InitPosYO		=           68+#17	  ; Pos.inicial Y cursor opt.
$InitPosXO		=	36+#30	  ; Pos.inicial X cursor opt.
	ENDIF

$IncYMovCursor	=	16	  ; Incr.mov.Y cursor menu
$IncYMovCursor2	=	48	  ; Incr.mov.Y cursor opciones
$LimDownYCursor	=	$IncYMovCursor*3 ; Lim.down Y cursor menu
$LimDownYCursor2	=	$IncYMovCursor2*2 ; Lim.down Y cursor opc.
$OptStart		=	0
$OptOptions		=	$IncYMovCursor
$OptPassword	=           $IncYMovCursor*2

	if	GB
	ldal	IE
	push	af
	and	00000001b
	stal	IE
	endif

	xor	a
	stal	PosCursorP	; Init. posicion del cursor password
	dec	a
	stal	NextWorld

	call	MakeClears

	IF	GB
	EI
	CallMusic	INIT_GBS
	HALT_
	DI
	ENDIF

	ldal	OkPassword
	and	a
;	call	nz,CheckPasswordBnk

$ReturnFromPass:
	DI

	IF	GB
	EI
	xor	a
	stal	SGB_FlagMarkers
	ld	hl,PAL_TIT
	SGB	SetPalette
	DI
	ENDIF

	ld	hl,IdiomaOptions
	ldal	Langua
	add	a,a
	ld	c,a
	ADDHLA
	LDHLHL
	STHLL	ST_ALL2		; Dir.texto idioma opciones

	xref	IdiomaLevels
	ld	hl,IdiomaLevels
	ld	a,c
	ADDHLA
	LDHLHL
	STHLL	ST_ALL3		; Dir.texto idioma opciones

	IF	GB
	ld	hl,#8800
	callx	DumpWhite
	ENDIF

	callx	DumpChapeau		; Vuelca gorrito
	callx	DumpCharsBig2	; Vuelca graficos set gordo
	callx	DumpTitulo

$InitMenu	xor	a
	stal	PosCursorM	; Init. posicion del cursor menu

	IF	GB
	ld	a,$Whitechar
	sta	ST_ALL
	callx	BG1
	ELSE

	call	SetPalSt

	ld	a,FIRSTCHARBIGPIECE
	sta	ST_ALL
	callx	BG1
	ENDIF

	call	PrintTitulo

	ld	hl,IdiomaMenu
	ldal	Langua
	add	a,a
	ADDHLA
	LDHLHL

	IF	GB
	ld	de,#9800+8*32+6
	ELSE
	ld	de,#7800+8*64+6*2
	ENDIF

	call	DumpTxtBig

	IF	GB
	ldal	LCDC
	or	LCDC_OBJ
	stal	LCDC

	ld	hl,OBJRAM
	ldal	PosCursorM
	add	$InitPosYM
	ldhlia
	ld	a,$InitPosXM
	ldhlia
	ld	a,$Codecursor
	ldhlia
	xor	a
	ld	(hl),a

	ELSE

	ldal	PosCursorM
	add	$InitPosYM
	stal	OBJRAM2
	ld	a,#d0
	stal	OBJRAM2+1

	ld	a,$InitPosXM
	stal	OBJRAM
	ld	a,$Codecursor
	stal	OBJRAM+1

	ENDIF

	ldal	MusicOn
	and	a
	jnz	$nomusic

	IF	GB
	ld	a,4
	CallMusic	FADE_IN
	HALT_
	ENDIF

	xref	MAIN
	LD	HL,MAIN
	callx	DoCallMusic

$nomusic	callx	LCDC_ON

;----------	Control de menu principal --------

$w	HALT_
	callx	CONT
	ldal	TRG1
	bit	UP,a
	jp	nz,$Upcursor
	bit	DOWN,a
	jp	nz,$Downcursor
	bit	SELECT,a
	jp	nz,$Downcursor
	and	BIT_START+BIT_FIREA+BIT_FIREB
	jz	$w

;	Decide que opcion de ha elegido

	ldal	PosCursorM
	cp	$OptStart
	jz	$StartGame
	cp	$OptPassword
	jz	$MenuPassword
	cp	$OptOptions
	jz	$MenuOptions

$MenuPassword
	InitFx	SELOP
	HALT_
	callx	LCDC_OFF
;	call	PassWordsFromMenu

	ldal	OkPassword
	and	a
	jz	$error

	InitFx	OK
	jr	$retpass

$error	InitFx	ERROR
$retpass	callx	LCDC_OFF
	jp	$ReturnFromPass

;	Start game

$StartGame	InitFx	OK
	HALT_

	callx	LCDC_OFF

	IF	GB
	pop	af
	or	00000010b
	stal	IE
	ENDIF

	ret

$TabIncCursorY
	if	GB

	db	$InitPosYO,$InitPosYO+40,$InitPosYO+40+16
$MaxTabInc	equ	$-$TabIncCursorY
	db	#ff

	ELSE

	db	$In

0x6687C

ENDIF

	call	PrintTitulo

	LDHL	ST_ALL2		; texto opciones
	IF	GB
	ld	de,#9800+8*32+6
	ELSE
	ld	de,#7800+8*64+6*2
	ENDIF

	call	DumpTxtBig

	ld	a,1
	stal	PrtOptions

	EI
	CallMusic	TURNOFF
	HALT_
	callx	LCDC_ON

;	Control de menu de opciones

$w2	HALT_
	callx	CONT

	ldal	TRG1
	bit	UP,a
	jp	nz,$UpCursorOpt
	bit	DOWN,a
	jp	nz,$DownCursorOpt

	IF	GB
	bit	SELECT,a
	jp	nz,$DownCursorOpt
	ENDIF

	bit	LEFT,a
	jnz	$izq
	bit	RIGHT,a
	jp	nz,$der
	bit	FIREB,a
	jnz	$izq
	bit	FIREA,a
	jp	nz,$der
	and	BIT_START
	jz	$w2

	callx	LCDC_OFF
	xor	a
	stal	PrtOptions
	ldal	OptMusic
	stal	MusicOn
	jp	$InitMenu

;	Mueve izquierda nivel

$izq        xor	a
	stal	FxPnt
	InitFx	SELOP

	ldal	PosCursorO
	and	a
	jz	$levizq
	dec	a
	jp	nz,$nofxc

	ldal	OptFX
	sub	1
	stal	OptFX
	jp	nc,$w2
	ld	a,1
	stal	OptFX
	jp	$w2

$nofxc	ldal	OptMusic
	sub	1
	stal	OptMusic
	jp	nc,$w2
	ld	a,1
	stal	OptMusic
	jp	$w2

$levizq     xor	a
	stal	CaraPos0
	stal	CaraPos1
	stal	CaraPos2

	xref	CALLES
	ld	a,CALLES
	stal	WORLD

	ldal	OptLevel
	sub	1
	stal	OptLevel
	jp	nc,$w2
	ld	a,2
	stal	OptLevel
	jp	$w2

;	Mueve derecha nivel

$der	xor	a
	stal	FxPnt
	InitFx	SELOP

$no1	ldal	PosCursorO
	and	a
	jz	$levder
	dec	a
	jnz	$nofx2

	ldal	OptFX
	inc	a
	stal	OptFX
	cp	2
	jp	c,$w2
	xor	a
	stal	OptFX
	jp	$w2

$nofx2	ldal	OptMusic
	inc	a
	stal	OptMusic
	cp	2
	jp	c,$w2
	xor	a
	stal	OptMusic
	jp	$w2

$levder     xor	a
	stal	CaraPos0
	stal	CaraPos1
	stal	CaraPos2

	ld	a,CALLES
	stal	WORLD

	ldal	OptLevel
	inc	a
	stal	OptLevel
	cp	3
	jp	c,$w2
	xor	a
	stal	OptLevel
	jp	$w2

;	Cursor abajo opciones

$DownCursorOpt
	InitFx	MOVOP
	ld	hl,$TabIncCursorY
	ldal	PosCursorO
	inc	a
	stal	PosCursorO
	cp	$MaxTabInc
	jnz	$noend

	xor	a
	stal	PosCursorO

$noend	ld	e,a
	ld	d,0
	add	hl,de

	;ldal	PosCursorO
	;add	$IncYMovCursor2
	;stal	PosCursorO

	ld	a,(hl)

$baja2	;add	$InitPosYO
	IF	GB
	stal	OBJRAM
	ELSE
	stal	OBJRAM2
	ENDIF
	jp	$w2

;	Cursor arriba opciones

$UpCursorOpt
	InitFx	MOVOP
	ld	hl,$TabIncCursorY
	ldal	PosCursorO
	sub	1
	stal	PosCursorO
	jnc	$ok
	ld	a,$MaxTabInc-1
	stal	PosCursorO

$ok	ld	e,a
	ld	d,0
	add	hl,de

	;ldal	PosCursorO
	;sub	$IncYMovCursor2
	;stal	PosCursorO
	;jnc	$sube2

	;ld	a,$LimDownYCursor2-$IncYMovCursor2
	;stal	PosCursorO

$sube2	;add	$InitPosYO
	ld	a,(hl)
	IF	GB
	stal	OBJRAM
	ELSE
	stal	OBJRAM2
	ENDIF
	jp	$w2

;	Cursor abajo menu principal

$Downcursor	InitFx	MOVOP

	ldal	PosCursorM
	add	$IncYMovCursor
	stal	PosCursorM
	cp	$LimDownYCursor
	jnz	$baja

	xor	a
	stal	PosCursorM

$baja       add	$InitPosYM
	IF	GB
	stal	OBJRAM
	ELSE
	stal	OBJRAM2
	ENDIF

	jp	$w

;	Cursor arriba menu principal

$Upcursor   InitFx	MOVOP

	ldal	PosCursorM
	sub	$IncYMovCursor
	stal	PosCursorM
	jnc	$sube

	ld	a,$LimDownYCursor-$IncYMovCursor
	stal	PosCursorM

$sube	add	$InitPosYM
	IF	GB
	stal	OBJRAM
	ELSE
	stal	OBJRAM2
	ENDIF

	jp	$w

;	Imprime titulo

DoPrintTitulo:
	ld	de,MAP_BUFF
	ld	hl,TITULOM
	sthll	DirMapPan
	ld	a,TITULOMBNK
	stal	BnkMapPan

	IF	GB
	ld	hl,#9800+2
	ELSE
	ld	hl,#7800+3*2
	ENDIF

	sthl	ST_ALL7

	IF	GB
	ld	a,16
	sta	ST_ALL8
	ld	a,7
	sta	ST_ALL9
	ELSE
	ld	a,14
	sta	ST_ALL8
	ld	a,6
	sta	ST_ALL9
	ENDIF

	call	DumpPantMap
	ret

;	Rutina que visualiza secuencias
;	de presentacion,fases intermedias y final

CineMain:	xor	a
	stal	CNTGEN2
	stal	WaitScrCine

	DI
	IF	GB
	ldal	IE
	push	af
	and	00000001b
TER=OFF
	if	0
	endif
	WAITB	11b,$set
	ldal	ProgramCounter
	and	11b
	jz	$reset

GenEnemy	RVOL
CALLGEN	macro
	xref	\1

	sta	var3
	xor	a
	sta	var4

	ld	de,#100*(\2)+\3
	ld	bc,#100*(\1)+#ff
	callx	GenEneOff
	endm
CALLGEN	macro
	xref	\1

	sta	var3
	xor	a
	sta	var4

	ld	de,#100*(\2)+\3
	ld	bc,#100*(\1)+#ff
	callx	GenEneOff
	endm



	GenEnemy	RVOL
	stal	NumEneDeath
	xor	a
	xor	a
GenEnemy	KAMIK
	jnc	$nomuere
	jp	GestFuel
;COLBALA	1
	;jnc	$nomuere
	
;ldal	WORLD
	;cp	AEREO
	;jp	nz,$noaereo
	;DIRHERO	AN_RVOL
;	Tratamiento robot volante fase aerea.
	jnc	$nomuere
	jp	GestFuel
ESP_ORDEN




	sta	Pollo
PersoSpeedY	DS	1           ;>
PersoPixY	DS	1           ;>
CONT_MOV	DS	2	;>
FMUERTO	DS	1           ;>
CNTENER	DS	1           ;>
Pollo1	ds	1	;>
Pollo2	ds	1	;>
	DS	1           ;>
	DS	1           ;>
	DS	2	;>
	DS	1           ;>
	DS	1           ;>
	ds	1	;>
	ds	1	;>
FASANIM	DS	1           ;> SON DE ENETAB
FPOLLO	DS	1           ;>
	sta	FASANIM	DS	1           ;> SON DE ENETAB
	sta	FPOLLO	DS	1           ;>
	if	1
	CALLGEN	BFUMEE,0,0
	xref	BFUEL
	ld	a,BFUEL
	stal	NOMBRE
	xor	a
	sta	FASANIM
	sta	FPOLLO
	if	1
	sta	PersoSpeedY
	sta	PersoPixY
	sta	CONT_MOV
	sta	FMUERTO
	sta	CNTENER
	sta	Pollo1
	sta	Pollo2
	endif

	endif

	ldal	NumEneDeath
	PRTA	3,0,3

	GenEnemy	RVOL
APARYDOWNBASE EQU	5*8*2	; RANGO "Y" DESAPARICION INFERIOR ENE.
APARYJUMPBASE EQU	8*8         ; RANGO "Y" APARICION EN BASE SI JUMP
AEREO
APARYDOWNBASE EQU	5*8*2	; RANGO "Y" DESAPARICION INFERIOR ENE.
APARYJUMPBASE EQU	8*8         ; RANGO "Y" APARICION EN BASE SI JUMP


+6*8
	jr	$normal

	ld	a,2

	; ¨Porque con HeroY y no con PersoY?
BASE
	ldal	HeroAgarra
	and	a
	jnz	$nost
	ldhll	HeroYLast
	PRTHL	0,0,5

	;28
FABRICA
	ld	a,2

C	A
	STAL	CNTGEN
	PRTA	1,0,3
	LDAL	CNTGEN2
	INC	A
	STAL	CNTGEN2
	PRTA	1,0,3

	ret
	ret	nz
	jz	$set
	ADDWL	PersoX,1
	ret	nz
	jnc	$set
$check	cp	4
	if	0
	ldal	X_SCR
	ld	l,a
	ldal	PersoX
	sub	l
	ret	c
	cp	4
	ret	c
	endif
	ret	c
	jr	$set
	ret	c
AEREO
JUGUETES
	a,(hl)
	ld	a,(hl)
	ldhll	HeroX
	ld	a,l
	ldhll	HeroY
	ld	a,l
C_
	ldal	CNTGEN2
	inc	a
	stal	CNTGEN2
	PRTA	2,0,3

	ADDWL	PersoX,2

AEREO
	jz	$GENERA
	ret
	ret	z
	and	a
	ret
	;cp	1
	;ret	nz
JUGUETES
APARYFAB	EQU	0*8	; RANGO "Y" APARICION DE ENEMIGOS
APARYFAB	EQU	-1	; RANGO "Y" APARICION DE ENEMIGOS
DESAYFAB	EQU	3*8	; RANGO "Y" DESAPARICION DE ENEMIGOS
DESAYFAB	EQU	0	; RANGO "Y" DESAPARICION DE ENEMIGOS
	LD	DE,ANCHOP+DESAYFAB
	STDEL	ST_ALL8
ALTOP+DESAYFAB
ALTOP
	LD	DE,ALTOP+DESAYFAB
	STDEL	ST_ALL8
	LD	DE,ALTOP
	STDEL	ST_ALL8
	LD	DE,ALTOP+DESAYFAB
	STDEL	ST_ALL8
	LD	DE,-DESAYFAB
	STDEL	ST_ALL7
	LD	DE,-DESAYFAB
	STDEL	ST_ALL7
-DESAYFAB
FABRICA
BASE
+16*2
+16*2
APARYJUMPBASE
RANGO "Y" APARICION EN BASE SI JUMP
+2*8
DESAYFABDOWN
 DE ENE
RANGO "Y" DESAPARICION ABAJO
APARYDOWNBASE
	EQU	16*2	; RANGO "Y" DESAPARICION INFERIOR ENE.
APARYJUMPBASE
	EQU	8*8	; RANGO "Y" APARICION EN BASE SI JUMP
APARYBASE	EQU	0	; RANGO "Y" APARICION EN BASE SI NO JUMP
DESAXFAB	EQU	3*8	; RANGO "X" DESAPARICION DE ENEMIGOS
DESAYFABUP	EQU	0	; RANGO "Y" DESAPARICION ARRIBA
DESAYFABDOWN
	EQU	16*2	; RANGO "Y" DESAPARICION INFERIOR ENE.
	EQU	8*8	; RANGO "Y" APARICION EN BASE SI JUMP
	EQU	0	; RANGO "Y" APARICION EN BASE SI NO JUMP
	EQU	3*8	; RANGO "X" DESAPARICION DE ENEMIGOS
	EQU	0	; RANGO "Y" DESAPARICION ARRIBA


	;ld	de,-APARYFAB+8*8
;ld	de,-APARYFAB
RANGO "Y" DESAPARICION ABAJO
-DESAYBASE
DESAYBASE	  EQU	3*8	; RANGO "Y" DESAPARICION
 EQU	3*8	; RANGO "Y" DESAPARICION
FABRICA
BASE
	;D_Pos	16*140,16*10		;Original
AEREO
	jr	$NOAEREO



	ret


jp	CMP_SCRY
	ldal	HeroXAnt
	and	#0f
	PRTA	4,0,3
	LDHL	DIRCENTROA
	ld	a,(hl)
	cp	SL_IZQ45_A
	ret	c
	cp	SL_IZQ45_A+4
	ret	nc
	ret	nc
	cp


	ldal	PersoXAnt
	and	#f0
	ld	c,a
	ldal	PersoX
	and	#f0
	cp	c
	jnc	$read
	lda	PersoXAnt
	lda	PersoXAnt


	ldhll	PersoXAnt
	lda	PersoX
	sub	l
	lda	PersoX+1
	sbc	h
	jnc	$read


	ld	a,l
PersoXAnt
	lda	PersoXAnt
Ant
;	Solo para fase aerea

0x686E2

 ;
;/* -------------------------------------------------------------------------- ;

MainLoop:	ldal	CNT2
	stal	CNT1OLD

	InitBuffNum

	IF	MARCA=OFF
	;ldhl	DIRCENTRO
	;ld	a,(hl)
	;PRTA	0,0,3
	;ldhll	HeroY
	;PRTHL	0,0,5
	;ldal	HeroJump
	;PRTA	1,0,3
	;PRTCOORDS
	ENDIF

	ldal	ProgramCounter
	inc	a
	stal	ProgramCounter

	xor	a
	stal	HeroHidden	; Usually can be seen
	stal	ObjFlag

;	calL

	ld	a,BYTE&(METRO_SPL)
	STAL	PAL
	ld	a,METRO_SPL/256
	STAL	PAL+1
	ld	a,METRO_SPLBNK
	callx	SET_PAL2

	pop	hl

	ENDIF

	ldahli
	ld	e,a
	stal	DirGrfPan
	ldahli
	stal	DirGrfPan+1		;Direccion Grafico

	ldahli
	stal	DirMapPan
	ldahli
	stal	DirMapPan+1		;Direccion Mapa

	ldahli
	stal	BnkGrfPan		;Banco Grafico
	ldahli
	stal	BnkMapPan		;Banco Mapa

	push	hl

	ldal	Langua
	add	a,a
	ADDHLA

	ldahli
	sta	ST_ALL5
	ldahli
	sta	ST_ALL5+1		;Direccion Texto

	call	LoadCine

	IF	GG
	ld	hl,MAP_BUFF
	ld	de,MAP_BUFF+1
	ld	bc,20*60
	ld	a,FIRSTCHARPIECE
	ld	(hl),a
	zldir

	xor	a
	stal	POSYLINE
	stal	POSXCHAR
	ENDIF

	ld	hl,MAP_BUFF	;COLBUFV
	lda	ST_ALL5
	ld	e,a
	lda	ST_ALL5+1
	ld	d,a
	ld	c,FIRSTCHARPIECE	;BYTE&(FIRSTCHARPIECE_AZ-("A"-" "))
	ld	b,0
	call	CallGenerateText    ; llamar aqui si esta en banco

	lda	var1
	add	7

	IF	GB
	add	a,a
	add	a,a
	add	a,a
	ENDIF

	sta	var4

	IF	GB
	call	DumpTxt
	ENDIF

	pop	hl

	ld	a,l
	add	MaxLangua*2
	ld	l,a
	ld	a,h
	adc	0
	ld	h,a
	STHLL	DirCineTab	;ST_ALL	;Puntero de tabla

	IF	GB
	LDlo	a,LYC_SCRTXT
	stal	LCRUT+1
	LDhi	a,LYC_SCRTXT
	stal	LCRUT+2

	LD	A,96-1
	STA	LYC		;Pos.Y scroll texto

	xor	a
	stal	CNTGEN2

	ENDIF

	ldal	MusicOn
	and	a
	jnz	$nomusic

	xref	MAIN
	LD	HL,MAIN
	callx	DoCallMusic

$nomusic	IF	GG

	ld	hl,#7B00
	ld	a,l
	stal	VRAMCHAR
	ld	a,h
	stal	VRAMCHAR+1

	ld	a,BYTE&(MAP_BUFF)
	stal	RAMCHAR
	ld	a,MAP_BUFF/256
	stal	RAMCHAR+1

	ENDIF

	callx	LCDC_ON

	IF	GG
	ld	a,1
	stal	FlgCinemati
	ENDIF

;	Bucle de scroll e impresion

$wait	HALT_

	IF	GG

	ldal	ProgramCounter
	inc	a
	stal	ProgramCounter
	and	11b
	jnz	$wait

	ldal	RAMCHAR
	add	1
	stal	RAMCHAR
	ldal	RAMCHAR+1
	adc	0
	stal	RAMCHAR+1

	ldal	POSXCHAR
	inc	a
	stal	POSXCHAR
	cp	20
	jnz	$noendl

	lda	var4
	dec	a
	sta	var4
	jz	Endscr

	ldal	POSYLINE
	inc	a
	stal	POSYLINE
	cp	6
	jnz	$noendline
	dec	a
	stal	POSYLINE

	ld	a,2
	stal	FlgCinemati

$noendline	xor	a
	stal	POSXCHAR

$noendl     add	a,a
	ld	c,a
	ldal	POSYLINE
	ld	l,a
	ld	h,0

	rept	6
	add	hl,hl
	endr

	ld	de,#7B00
	add	hl,de

	ld	e,c
	ld	d,0
	add	hl,de
	ld	a,l
	stal	VRAMCHAR
	ld	a,h
	stal	VRAMCHAR+1

	ENDIF

	IF	GB
	ldal	CNTGEN2
	cp	2
	jz	Endscr
	ld	a,1
	stal	CNTGEN2
	ENDIF

	callx	CONT

	ldal	CNT1
	and	a
	jz	$wait

	ld	c,a

	IF	GB
	and	BIT_FIREA+BIT_FIREB+BIT_SELECT
	ELSE
	and	BIT_FIREA+BIT_FIREB
	ENDIF
	jnz	Endscr

	ld	a,c
	and	BIT_START
	jp	z,$wait

	callx	LCDC_OFF
	jr	FinCine

Endscr	callx	LCDC_OFF

	IF	GB
	xor	a
;	stal	CNTGEN2
	stal	DIRSCRX
	stal	DIRSCRY
	stal	DIRSCRX_Old
	stal	DIRSCRY_Old
	stal	WaitScrCine
	ELSE
	xor	a
	stal	FlgCinemati
	ENDIF

	jp	NextCine

FinCine	CallMusic	TURNOFF

	IF	GB
	xor	a
	stal	CNTGEN2
	ELSE
	xor	a
	stal	FlgCinemati
	ENDIF

	IF	GB
	pop	af
	stal	IE
	ENDIF

	ret

	IF	GB
;	Rutina interrupcion de scan
;	Solamente para Game Boy

LYC_SCRTXT	push	bc,de,hl

	ldal	CNTGEN2
	and	a
	jz	$exitscan

	LDA	STAT
	AND	10B
	JR	NZ,LYC_SCRTXT

	ldal	ProgramCounter
	inc	a
	stal	ProgramCounter
	and	111b
	jnz	$setscr

	ldal	DIRSCRY
	inc	a
	stal	DIRSCRY
	sta	SCY

	ldal	WaitScrCine
	inc	a
	stal	WaitScrCine
	ld	c,a

	lda	var4
	cp	c
	jnz	$setbg2
	ld	a,2
	stal	CNTGEN2
	jr	$setbg2

$setscr	ldal	DIRSCRY
	stal	SCY

$setbg2     ldal	LCDC
	or	LCDC_BG_Bnk
	stal	LCDC

$exitscan	pop	hl,de,bc
	ei
	ret
	ENDIF

;	Vuelca texto letra a letra de buffer a VRAM
;	Solamente para Game Gear.

0x696A6

#ff

	IF	SPIROU

;	Efectua decremento de vida
;	y repone la energia

DoDecLife:	ldal	Life
	and	a
	jp	nz,$cont

	EI
	callx	LCDC_OFF

	IF	GB
	ldal	IE
	and	00000001b
	stal	IE
	ENDIF

	callx	MakeClears

	IF	GB
	xref	PAL_PAS
	xor	a
	stal	SGB_FlagMarkers
	ld	hl,PAL_PAS
	SGB	SetPalette
	DI
	ENDIF

	if	GG

	callx	SetPalSt

	endif

;	Imprime GAME OVER en pantalla

	PushBank

	ld	a,MUSICDATABNK
	SetBank	NoUpdate
	callx	STURNOFF

	P
	xor	a
	out	(VDP_DATA),a
	dec	c
	jnz	$dumpline

	dec	b
	jp	nz,$newline

	ld	a,1
	stal	FlgCinemati

	ld	a,e
	add	64
	out	(VDP_COMM),a
	ld	a,d
	adc	0
	out	(VDP_COMM),a

	ld	c,20

$lineblack	ld	a,FIRSTCHARPIECE
	out	(VDP_DATA),a
	xor	a
	out	(VDP_DATA),a
	dec	c
	jnz	$lineblack
	ret

	ENDIF

	IF	GB

;	Vuelca texto de buffer descomprimido a VRAM
;	Solamente para Game Boy.

DumpTxt:	ld	hl,MAP_BUFF	;COLBUFV
	ld	de,#9C00+0+19*32

$nextline	push	de
	ld	b,20
$prt	ldahli
	LDDEIA

	dec	b
	jnz	$prt
	pop	de

	ldal	var1
	dec	a
	stal	var1	; Dec.numero lineas
	ret	z

	ld	a,e
	add	32
	ld	e,a
	ld	a,d
	adc	0
	ld	d,a
	cp	#a0
	jnz	$nextline
	ld	d,#9c
	jr	$nextline

	ENDIF

TxtPass:	db	"PASSWORD",#FF
TxtPassAL:	db	"PASSWORT",#FF

;	Texto seleccion de lenguajes

;	SPC,A-Z,x,:,¥,š,',0-9

TxtLenguajes:
	db	"ENGLISH",0
	db	0,0
	db	"FRANCAIS",0
	db	0,0
	db	"ESPA",29+"@","OL",0
	db	0,0
	db	"DEUTSCH",0
	db	#ff

;	Vuelca texto big en pantalla
;	In:
;	HL=Direccion texto
;	DE=Direccion VRAM

DumpTxtBig:
$enter	push	de

$nextletter	if	GG
	ld	a,e
	out	(VDP_COMM),a
	ld	a,d
	out	(VDP_COMM),a
	endif

	ldahli
	and	a
	jz	$nextline
	cp	#ff
	jz	$endprt

	sub	"@"
	jnc	$normal
	xor	a
$normal	add	a,a
	add	FIRSTCHARBIGPIECE

	IF	GB

	LDDEIA
	inc	a
	ld	c,a

	ELSE

	out	(VDP_DATA),a
	inc	a
	ld	c,a
	xor	a
	out	(VDP_DATA),a

	ENDIF

	push	de

	IF	GB

	ld	a,e
	add	31
	ld	e,a
	ld	a,d
	adc	0
	ld	d,a
	ld	a,c
	LDDEIA

	pop	de
	jr	$nextletter

	ELSE

	ld	a,e
	add	64
	out	(VDP_COMM),a
	ld	a,d
	adc	0
	out	(VDP_COMM),a

	ld	a,c
	out	(VDP_DATA),a
	xor	a
	out	(VDP_DATA),a

	pop	de
	ld	a,e
	add	2
	ld	e,a
	ld	a,d
	adc	0
	ld	d,a
	jr	$nextletter

	ENDIF


$nextline	pop	de

	IF	GB

	ld	a,e
	add	32	;32*2
	ld	e,a
	ld	a,d
	adc	0
	ld	d,a

	ELSE

	ld	a,e
	add	64
	ld	e,a
	ld	a,d
	adc	0
	ld	d,a

	ENDIF

	jr	$enter

$endprt	pop	de
	ret

DefCine	macro
	dwx	\1
	dwx	\2
	dbx	\3
	dbx	\4
	dwx	IN_\5
	dwx	FR_\5
	dwx	ES_\5
	dwx	AL_\5
	endm

SetCine	MACRO
	xdef	\2
\2	EQU	Cine_C
	DW	\1
Cine_C	=	Cine_C+2
	ENDM

Cine_C	=	0
CineTabla   SetCine	CineEscen0,Escene_00
	SetCine	CineEscen1,Escene_01
	SetCine	CineEscen2,Escene_02
	SetCine	CineEscen3,Escene_03
	SetCine	CineEscen4,Escene_04
	SetCine	CineEscenEnd,EsceneEnd

CineEscen0  dwx	PAL_PR1
	DefCine	PRESEN1G,PRESEN1M,PRESEN1GBNK,PRESEN1MBNK,TXT00A

	IF	GB
	dwx	PAL_PR2
	DefCine	PRESEN3G,PRESEN2M,PRESEN3GBNK,PRESEN2MBNK,TXT00B
	ELSE
	dwx	PAL_PR2
	DefCine	PRESEN2G,PRESEN2M,PRESEN2GBNK,PRESEN2MBNK,TXT00B
	ENDIF

	dwx	PAL_PR3
	DefCine	PRESEN3G,PRESEN3M,PRESEN3GBNK,PRESEN3MBNK,TXT00C
	dw	#ffff

CineEscen1  IF	GB
	dwx	PAL_RED
	DefCine	REDUCEG,REDUCEM,REDUCEGBNK,REDUCEMBNK,TXT01
	dw	#ffff
	ELSE
	dwx	PAL_RED
	DefCine	CINE1G,REDUCEM,CINE1GBNK,REDUCEMBNK,TXT01
	dw	#ffff
	ENDIF

CineEscen2  IF	GB
	dwx	PAL_CN1
	DefCine	REDUCEG,CINE1M,REDUCEGBNK,CINE1MBNK,TXT02
	dw	#ffff
	ELSE
	dwx	PAL_CN1
	DefCine	CINE1G,CINE1M,CINE1GBNK,CINE1MBNK,TXT02
	dw	#ffff
	ENDIF

CineEscen3	IF	GB
	dwx	PAL_C2A
	DefCine	CINE2CG,CINE2AM,CINE2CGBNK,CINE2AMBNK,TXT03
	dwx	PAL_C2B
	DefCine	CINE2CG,CINE2BM,CINE2CGBNK,CINE2BMBNK,TXT04
	ELSE
	dwx	PAL_C2A
	DefCine	CINE2AG,CINE2AM,CINE2AGBNK,CINE2AMBNK,TXT03
	dwx	PAL_C2B
	DefCine	CINE2BG,CINE2BM,CINE2BGBNK,CINE2BMBNK,TXT04
	ENDIF

	dwx	PAL_C2C
	DefCine	CINE2CG,CINE2CM,CINE2CGBNK,CINE2CMBNK,TXT05
	dw	#ffff

CineEscen4	dwx	PAL_MON
	DefCine	NAVEROTAG,NAVEROTAM,NAVEROTAGBNK,NAVEROTAMBNK,TXT06

0x6A880

	ld	de,#8000
	ld	bc,16
	zldir

	ELSE

	ld	hl,GORRET_G
	xor	a
	out	(VDP_COMM),a
	ld	a,#40
	out	(VDP_COMM),a

	ld	b,32

$repe	ldahli
	out	(VDP_DATA),a
	djnz	$repe

	ENDIF

	PopBank
	ret


;	Menu de seleccion de lenguajes

Lenguajes:	PushBank

	ld	a,LengBNK
	SetBank

	call	DoLenguajes

	PopBank
	ret

;	Llama a GenerateText

CallGenerateText
	PushBank

	xref	BNKWindow
	ld	a,BNKWindow
	SetBank

	xor	a
	callx	GenerateText

	PopBank
	ret

	IF	GG

SetPalSt	ld	a,BYTE&(CHARSBIGPAL)
	STAL	PAL
	ld	a,CHARSBIGPAL/256
	STAL	PAL+1
	ld	a,CHARSBIGPALBNK
	callx	SET_PAL

	ld	a,BYTE&(METRO_SPL)
	STAL	PAL
	ld	a,METRO_SPL/256
	STAL	PAL+1
	ld	a,METRO_SPLBNK
	callx	SET_PAL2
	ret

	ENDIF

;	Llama a Cine

Cine	ldal	LastWorld
	ld	c,a
	ldal	WORLD
	cp	c
	ret	z	;No hay Cine si mismo WORLD

	lda	ActiveBank
	push	af

	ld	a,CineBNK
	SetBank
	call	CineMain

	pop	af
	SetBank
	ret

;	Carga pantallas

LoadCine	lda	ActiveBank
	push	af

	ldal	BnkGrfPan	;Banco Grafico
	SetBank
	LDHLL	DirGrfPan	;Direccion del grafico
	;ld	de,MAP_BUFF
	ld	de,OBJRAM
	callx	UNPACK

$unpack	if	GB

	ld	hl,OBJRAM	;MAP_BUFF
	ld	de,#9000
	ld	bc,128*16
	zldir
	ld	de,#8800
	ld	bc,128*16
	zldir

	ELSE

	ld	hl,OBJRAM	;MAP_BUFF
	ld	de,#2000+#4000
	ld	a,e
	out	(VDP_COMM),a
	ld	a,d
	out	(VDP_COMM),a
	ld	bc,192*32

$dump2	ldahli
	out	(VDP_DATA),a
	dec	bc
	ld	a,b
	or	c
	jnz	$dump2

	ENDIF

	callx	DumpChars

	IF	GB

	ld	hl,#9800
	ld	de,#9801
	ld	bc,1023
	ld	(hl),l
	zldir

	ld	hl,#9C00
	ld	de,#9C01
	ld	bc,1023
	ld	(hl),l
	zldir

	ELSE

	ld	a,FIRSTCHARPIECE
	sta	ST_ALL
	callx	BG1

	ENDIF

	LD	DE,MAP_BUFF

	IF	GB

	LDlo	a,#9800+32*2+2
	sta	ST_ALL7
	LDhi	a,#9800+32*2+2
	sta	ST_ALL7+1

	ELSE

	LDlo	a,#7800+64*2+2*2
	sta	ST_ALL7
	LDhi	a,#7800+64*2+2*2
	sta	ST_ALL7+1

	ENDIF

	ld	a,16
	stal        ST_ALL8
	ld	a,10
	stal	ST_ALL9

	call	DumpPantMap

	pop	af
	SetBank
	ret

;	Vuelca mapeado en pantalla
;	In:
;	DE=Buffer descompresion mapeado
;	DirMapPan=Direccion mapa
;	BnkMapPan=Banco mapa
;	ST_ALL7=Destino VRAM Map.
;	ST_ALL8=Ancho caracteres
;	ST_ALL9=Alto caracteres

DumpPantMap:
	PushBank
	ldal	BnkMapPan	;ST_ALL4+1	;Banco Mapa
	SetBank

	LDHLL	DirMapPan	;ST_ALL3
	ldahli
	cmp	"R"
	bne	$nornc
	ldahli
	cmp	"N"
	bne	$nornc
	ld	a,(hl)
	cmp	"C"
	bne	$nornc

	LDHLL	DirMapPan	;ST_ALL3	;Direccion Mapa
	callx	UNPACK
	bra	$rnced

$nornc      push	de,hl

	ldal	ST_ALL8
	if	GB
	ELSE
	add	a,a
	ENDIF

	ld	e,a
	ld	d,0
	ld	l,d
	ld	h,d
	ldal	ST_ALL9
	ld	b,a

$mult	add	hl,de       ; multiplica ancho*alto
	dec	b
	jnz	$mult
	ld	c,l
	ld	b,h

	pop	hl,de
	LDHLL	DirMapPan	;ST_ALL3	;Direccion Mapa
	zldir

$rnced      LD	HL,MAP_BUFF
	LDDEL	ST_ALL7

	lda	ST_ALL9
	ld	c,a	; Alto car.

$Alto	lda	ST_ALL8
	ld	b,a	; Ancho car.

	IF	GG
	ld	a,e
	out	(VDP_COMM),a
	ld	a,d
	or	#40
	out	(VDP_COMM),a
	ENDIF

	push	de
$Ancho	ldahli

	IF	GB
	ld	(de),a
	inc	de
	ELSE
	out	(VDP_DATA),a
	ldahli
	set	0,a
	out	(VDP_DATA),a
	ENDIF

	dec	b
	jr	nz,$Ancho
	pop	de

	ld	a,e
	add	32*(DIMCOD+1)
	ld	e,a
	ld	a,d
	adc	0
	ld	d,a

	dec	c
	jr	nz,$Alto

	PopBank
	ret

;	Imprime texto gordo

DumpTxtBigBNK
	PushBank
	ld	a,1
	SetBank
	call	DumpTxtBig
	PopBank
	ret

;	Desconecta sprites numeros

	IF	GG

ClearNums:  xor	a
	OUT	(VDP_COMM),A
	ld	a,#3f+#40
	OUT	(VDP_COMM),A

	ld	b,32
	xor	a
$repe	out	(VDP_DATA),a
	djnz	$repe
	ret

	ENDIF

;	Convierte digitos a texra fase aerea

	LDHL	DIRCENTROA
	ld	a,(hl)
	cp	SL_IZQ45_A
	jc	$read
	cp	SL_IZQ45_A+4
	jnc	$read

	ldal	DIRCENTRO
	sub	l
	ldal	DIRCENTRO+1
	sbc	h
	jnc	$read

	lda	PersoXAnt
	and	#0f
	jz	$read
	lda	PersoX
	and	#f0
	sta	PersoX
	ret

	ldal	CNT1
	PRTA	3,0,3


	ld	a,1
	PRTA	3,0,3


	ld	a,1
	PRTA	3,0,3
	ld	a,1
	PRTA	3,0,3
	ld	a,1
	PRTA	3,0,3
	ld	a,1
	PRTA	3,0,3
	ld	a,1
	PRTA	3,4,3

	ld	a,1
	PRTA	2,0,3

	ldal	HeroJump
	PRTA	2,0,3
	ldal	HeroJump
	PRTA	2,4,3
	ld	a,1
	PRTA	3,4,3

	ld	a,1
	PRTA	3,4,3

	ldal	HeroJump
	PRTA	2,0,3
$noprt
$noprt
	ldal	ProgramCounter
	and	1b
	jnz	$noprt

	ldal	HeroJump
	PRTA	2,4,3


	ld	a,1
	PRTA	3,4,3
	ld	a,1
	PRTA	3,8,3


	ld	a,1
	PRTA	3,8,3

	ld	a,1
	PRTA	3,8,3

	xor	a
	PRTA	3,0,3

	PRTA	3,0,3


	ld	a,1
	PRTA	3,0,3


	ld	a,1
	PRTA	3,4,3

	ld	a,1
	ld	a,1
	PRTA	3,4,3




	ld	a,1
	PRTA	3,4,3








	xor	a
	PRTA	3,0,3

$noprt
$noprt
	ldal	ProgramCounter
	and	1b
	jnz	$noprt

	ld	a,1
	PRTA	3,0,3


	ld	a,1
	PRTA	3,0,3


	ldal	ProgramCounter
	and	1b
	jnz	$noprt
	ldal	ProgramCounter
	and	1b
	jnz	$noprt



$noprt

	;ldal	HeroJump
	;PRTA	2,0,3
$noprt
ProgramCounter
$noprt
	ldal	ProgramCounter
	PRTA	3,0,3

	ldal	ProgramCounter
	bit	0,a
	jnz	$noprt

	ldal	ProgramCounter
	bit	0,a
	jnz	$noprt

vargen	ds	1
	ds	1
	xor	a
	PRTA	3,4,3
	xor	a
	xor	a
vargen2	ds	1
	ds	1
	ldal	vargen2
	inc	a
	stal	vargen2
	PRTA	3,4,3
	ldal	vargen2
	inc	a
	stal	vargen2
	PRTA	3,4,3
	ldal	vargen2
	inc	a
	stal	vargen2
	PRTA	3,4,3
	ldal	HeroX
	and	#0f
	PRTA	0,0,3

	ldal	HeroY
	and	#0f
	PRTA	1,0,3

	ldal	HeroJump
	PRTA	2,0,3
	IF	MASTER=OFF
	ldal	HeroX
	and	#0f
	PRTA	0,0,3

	ldal	HeroY
	and	#0f
	PRTA	1,0,3

	ldal	HeroJump
	PRTA	2,0,3
	ENDIF
HeroX
HeroY
	IF	MASTER=OFF
	ldal	PersoX
	and	#0f
	PRTA	0,0,3

	ldal	PersoY
	and	#0f
	PRTA	1,0,3

	ldal	PersoJump
	PRTA	2,0,3
	ENDIF
	IF	MASTER=OFF
	ldal	PersoX
	and	#0f
	PRTA	0,0,3

0x6D07D

stal	WORLD
	;jr	$fadeout

$nada       ldal	WORLD
	stal	LastWorld

$fadeout	call	FadeOut
	;ret
	jp	InitWorld

;	Offsets para generacion explosiones

;	Formato:
;	dw	Offsx,Offsy

OffsExplo	dw	-17,0
	dw	-10,-10
	dw	17,-20
	dw	15,-20
	dw	-8,-10
	dw	10,-20
	dw	8,0
	dw	-17,-10
	dw	10,0
	dw	-15,0
	dw	-8,-20
	dw	15,-10
	dw	#8080		; Codigo final

;	Formato:
;	dw	Cx,Cy
;	Posiciones x/y de mapeado de las puertas.
;	Hot point en centro inferior.

CoordDoorsMonte
	;dw	333,544
	dw	333+6*8,544
	dw	1229,80

	if	0
CoordDoorsBase
	dw	337,272
	dw	637,128
	endif

;	Genera explosiones puerta en monte

ESP_Monte	ldal	FlgDumpDoor
	and	a
	jp	z,$ret2

$repe	ldal	ProgramCounter
	and	11b
	jp	nz,$ret2

	xref	MONTE

	if	0
	ldal	WORLD
	cp	MONTE
	jz	$monte

	ld	hl,CoordDoorsBase
	jr	$dirmap
	endif

$monte	ld	hl,CoordDoorsMonte

$dirmap	;ldal	ContAuto
	;dec	a

	ldal	ContVramDump
	dec	a

	add	a,a
	add	a,a
	ld	e,a
	ld	d,0
	add	hl,de
	ld	c,l
	ld	b,h

	ld	hl,OffsExplo

	ldal	ContTablaExplo	;CONT_MOV
	inc	a
	stal	ContTablaExplo	;CONT_MOV
	add	a,a
	add	a,a
	ld	e,a
	ld	d,0
	add	hl,de

	ld	a,(hl)
	cp	#80
	jnz	$noend

	xor	a
	stal	ContTablaExplo	;CONT_MOV
	jr	$ret2

;	Pone explosiones en ENETAB

$noend      LDABCI
	add	(hl)
	inc	hl
	sta	var1

	LDABCI
	adc	(hl)
	inc	hl
	sta	var1+1	; Store Perso_X

	LDABCI
	add	(hl)
	inc	hl
	sta	var2

	LDABCI
	adc	(hl)
	sta	var2+1	; Store Perso_Y

	xor	a
	sta	var3
	sta	var4

	xref	BEXPLO1

	ld

0x7D9DD

P15 Low P14 Hi
	LDCA
	LD	A,B

	AND	0FH
	SWAP	A
	LD	B,A

	LDAC	; DUMMY(WAITE)
	LDAC	; DUMMY(WAITE)
	LDAC	; DUMMY(WAITE)
	LDAC	; DUMMY(WAITE)
	LDAC	;

0x7EA9B

                                                                *
;*                    TRATAMIENTO FASE AEREO		        *
;*                                                                  *
;********************************************************************

TabFall:
$num	=	8

;	Velocidad caida,Empuje subida

	db	#30-$num,#12-$num
	db	#30-$num,#38-$num
	db	#38-$num,#2A-$num
	db	#20-$num,#10-$num
	db	#30-$num,#12-$num
	db	#30-$num,#38-$num
	db	#38-$num,#2A-$num
	db	#20-$num,#10-$num
	db	#FF

TreatAereo:

$Limx_scr		=	3200
$ProfCaida		=	144+100
$FrecApa		=	1
$LimitTimeFuel	=	220	;160

;	Rutina tratamiento de nave

	IF	GB
	ldal	Fuel
	add	NUMS
	stal	MARC_BUFF+11+20
	ldal	Fuel+1
	add	NUMS
	stal	MARC_BUFF+10+20
	ENDIF

	ldal	StatusAereo
	and	a
	jz	$checkgen
	cp	ChecklimAereo
	jp	z,$checklim2
	cp	CaeNave
	jp	z,$cae
	cp	SubeNave
	jp	z,$sube
	cp	CaeSinCntr
	jp	z,$sincntr
	cp	TemblorAereo
	jp	z,$ret
	cp	EndAereo
	jp	z,$endaereo
	cp	DestruccionNave
	jp	nz,$ret

;	Nave destruida

	ldal	CNTGEN
	sub	1
	stal	CNTGEN
	jnc	$next0

	call	$setcoords
	GenEnemy	BEXPLO1

	ld	a,10
	stal	CNTGEN

$next0	call	$NaveCaeVacio
	jp	nc,$ret

	ld	a,DIE_DECLIFE
	stal	HeroDie
	ret

$checkgen	ldal	CntFuel
	inc	a
	stal	CntFuel
	cp	$LimitTimeFuel
	jnz	$checklim

	xor	a
	stal	CntFuel

	ldal	Fuel
	dec	a
	stal	Fuel
	and	#0f
	cp	10
	jc	$checklim

	ldal	Fuel+1
	dec	a
	stal	Fuel+1
	and	#0f
	cp	10
	jnc	$nofuel

	ld	a,9
	stal	Fuel
	jr	$checklim

$nofuel	xor	a
	stal	Fuel
	stal	Fuel+1

	ld	a,DestruccionNave	; Empty fuel
	stal	StatusAereo

	xor	a
	sta	PersoSpeedY
	sta	PersoPixY
	jp	$ret

$checklim	ldal	X_SCR
	sub	BYTE&($Limx_scr)
	ldal	X_SCR+1
	sbc	$Limx_scr/256
	jp	c,$efecdisp

$okclear	ld	a,ChecklimAereo
	stal	StatusAereo

$checklim2	call	$ChecklimX
	jnc	$checky
	call	$ChecklimY
	jc	$centro
	jp	$ret

$checky	call	$ChecklimY
	jp	$ret

$centro	call	$setcoords
	GenEnemy	BEXPLO1

	ld	a,CaeNave
	stal	StatusAereo

	xor	a
	stal	CNTGEN

	ldal	CNTGEN
	ld	e,a
	ld          d,0
	inc	a
	stal	CNTGEN

	ld	hl,TabFall
	add	hl,de
	ld	a,(hl)
	cp	#ff
	jnz	$cont

	ld	a,CaeSinCntr
	stal	StatusAereo
	jp	$ret

$cont	sta	PersoSpeedY
	xor	a
	sta	PersoPixY

;	Nave pierde el control y cae

$cae	PushY	2,down
	jnc	$noend

	ld	a,SubeNave
	stal	StatusAereo

	ldal	CNTGEN
	ld	e,a
	ld          d,0
	inc	a
	stal	CNTGEN

	ld	hl,TabFall
	add	hl,de
	ld	a,(hl)
	sta	PersoSpeedY
	xor	a
	sta	PersoPixY
	jp	$ret

$noend	lda	PersoY
	add	c
	sta	PersoY
	lda	PersoY+1
	adc	0
	sta	PersoY+1
	jp	$ret

;	Empuje ascendente

$sube	PushY	2,down
	jnc	$noend2

	call	$setcoords
	GenEnemy	BEXPLO2

	ld	a,CaeNave
	stal	StatusAereo

	ldal	CNTGEN
	ld	e,a
	ld          d,0
	inc	a
	stal	CNTGEN

	ld	hl,TabFall
	add	hl,de
	ld	a,(hl)
	cp	#ff
	jnz	$cont2

	ld	a,CaeSinCntr
	stal	StatusAereo
	jp	$ret

$cont2	sta	PersoSpeedY
	xor	a
	sta	PersoPixY
	jp	$ret

$noend2	lda	PersoY
	sub	c
	sta	PersoY
	lda	PersoY+1
	sbc	0
	sta	PersoY+1
	jp	$ret
(Source: Original TCRF research)