
		onbankgroup

;==============	僶儞僋侽 ================================================
BANK0		GROUP	0
;-------------<	ZCO >-------------
		EXTERN	DATA_MOV,RAMCLR,RAMCL2,BGMSET,RNDSUB,OBJBG,RAMCL3
		EXTERN	SOUNDCLR,DJITRV,SVOPEN
;
;-------------<	ZES >-------------
		EXTERN	ENEMY,BGDTST,ENDTST,BDCHT1,BDCHT2,KTFLSTL,ECACH
		EXTERN	EMOVE,EFAIL,ENIDSHL
;
;-------------<	ZMA >-------------
		EXTERN	PBSET,PBRETN,VRMCL,VRMBT,BKCHG,BKCH2,BKCH3,WINDBGS
		EXTERN	RBGST,PSLBGS,NSLBGS,DJBST,GRBST,GOVBG,BLVRDS,BNKTR
		EXTERN	TLCHG,GMAPCL,GVCHG,VRMB2
		EXTERN	Char_bank_set
;
;-------------<	ZBS >-------------
		EXTERN	BGCRRD
		EXTERN	Unit_bank_set
;
;==============	僶儞僋侾 ================================================
BANK1		GROUP	1
;-------------<	ZTI >-------------
		EXTERN	PLSLCTS,NMREGIS,NMCLERS,DMAPSUB,GRMAPSB,GPSUB
		EXTERN	NMCOPYS,GMSTART,DTSAVE,TSAVESB,PLOVERS,DAMPFGD
;
;-------------<	ZS1 >-------------
		EXTERN	OPENING,MSGTEST,PEACHSB,LOVEDEMO,KABE1SB
		EXTERN	ARIMOTO,OPA,DJMSCK
;
;==============	僶儞僋俀 ================================================
BANK2		GROUP	2
;-------------<	ZEX >-------------
		EXTERN	EXSTRA,TAKARST,PLBELT,COINIT,HARTIT,ITEMDP,WINDOW
		EXTERN	ITEMDP2,WUPSET,WUPSET2,DOORSUB,FUCKSST,PLYKMV
		EXTERN	PLYKBC,PRTBMSTS,PLROTCS,PLTOBIS,PLOBORS,KNPWUPS
		EXTERN	PLFOLES,KURDORS,SCROLLS,ANAHORIS,BG1CHS,PLCTBC
		EXTERN	ITEMUP,PWDRUP,PLJUMP,ANBGSB,OKARINA,PLBOXER
		EXTERN	OKARST,DEFUP,DJMPST,PLMOVES,PLIDBC,FLSH,PLBGCK
		EXTERN	PLBGC0,PLCUT,PLCUT2,PLCUT3,PCUTED,PLSWIMS,KPWF
		EXTERN	DSZN,SMK1,PLIDBC2,PMVXD,PMVYD,PLCMDT,PLCHPD,PLCHP2
		EXTERN	PLCHP28,PLCHP3,PLCHP38,PLCHPO,PLCHPC,PLCHSW,PLCHDB
                EXTERN  PLCHYSW
;
;==============	僶儞僋俁 ================================================
BANK3		GROUP	3
;-------------<	ZEN >-------------
		EXTERN	ENCAPS,BOMBR,BUMER,KTOBJ,PYAAA,BLOCK,FUCKS,KEYSM
		EXTERN	POWDR,RUPY1,HART1,PRTBM,FUKURO,YOSSI,KENBM
;
;==============	僶儞僋係 ================================================
BANK4		GROUP	4
;-------------<	ZE2 >-------------
		EXTERN	SHOPGET
;
;==============	僶儞僋俉 ================================================
BANK8		GROUP	8
;-------------<	ZBD >-------------
;(CGB)		EXTERN	GRBGCR,DJBGCR,BGUNCH,DJUNCH,GBBKDT,DBBKDT,GREBDT
;(CGB)		EXTERN	DJEBDT,GEBANKD,DEBANKD
;(CGB)		EXTERN	DBBKDT2,DJEBDT2,DJUNCH2
		EXTERN	GRBGCR,DJBGCR,DJUNCH,DJUNCH2,DJUNCH_CGB
;
;==============	僶儞僋侾係 ==============================================
BANK14		GROUP	$14
;-------------<	ZDB >-------------
		EXTERN	DJRMDT,D7DAT2,DJTKDT
		EXTERN	NEWDJDAT
;
;-------------<	ZEX >-------------
		EXTERN	MSOKCKL,TUBOITEM,TILTCK,KNBNMSD,EXSEST,FADECK
		EXTERN	BG1CHGSB,WPDJPT,WPDJPTN,WTUP2
		EXTERN	WPDJPT2,TRC_SUB
;
;==============	僶儞僋侾俈 ==============================================
BANK17		GROUP	$17
;-------------<	ZEND >-------------
		EXTERN	ENDING,YAOBJSTS,MSCURST,YMCLER
;
;==============	僶儞僋侾俋 ==============================================
BANK19		GROUP	$19
;-------------<	ZE7 >-------------
		EXTERN	PLWARP,BELTCK
;
;==============	僶儞僋侾俙 ==============================================
BANK1A		GROUP	$1A
;-------------<	ZBDATR >-------------
		EXTERN	BgAtrAddress
;
;-------------<	ZMAP >-------------
		EXTERN	BGUNCH,BGUNCH_CGB
;
;==============	僶儞僋侾俠 ==============================================
BANK1C          GROUP   $1C
;-------------<	ZMS >-------------
		EXTERN	MSCANC,MSCHNO,MSCHN2,USA,MSGEAD,MJ2DT,MJ2DTH,MJ2DTL
		EXTERN	MJ1DTL,MJ1DTH,XX,WED,WE2,NM,GPMA,KAI,C02
		EXTERN	MJBI10_SUB
		EXTERN	MSMASKS_SUB,MSRETN_SUB
;
;==============	僶儞僋俀侽 ==============================================
BANK20		GROUP	$20
;-------------<	ZFADE >-------------
		EXTERN	WhiteOut,WhiteIn
;-------------<	ZPLSUB >-------------
		EXTERN	TLCRST_SUB,SCRL_SUB,SCROLL_INIT
		EXTERN	KNCSET_SUB,PLY100_SUB,BOMBRST_SUB
		EXTERN	BYTM,TATEST2_SUB,BUMERST_SUB,NEWDJ_BGCRS,NEWDJ_CHR
		EXTERN	MGICPW_SUB,PLTROK_SUB
;-------------<	ZWIN >------------
		EXTERN	ITEM_SELECT,ITSEL_SUB
;-------------<	ZMAP >------------
		EXTERN	GBBKDT,DBBKDT,GREBDT
		EXTERN	DJEBDT,GEBANKD,DEBANKD
		EXTERN	DBBKDT2,DJEBDT2
		EXTERN	CCC
;
;==============	僶儞僋俀侾 ==============================================
BANK21		GROUP	$21
;-------------<	ZCOL >------------
		EXTERN	MORI_COL_CHANGE
;
;==============	僶儞僋俀俉 ==============================================
BANK28		GROUP	$28
;-------------<	ZPR >------------
		EXTERN	PRINTER_MAIN
;
;==============	僶儞僋俁俈 ==============================================
BANK37		GROUP	$37
;-------------<	ZGEKI >----------
		EXTERN	GEKI04_MODE
;
;========================================================================
	PUBALL
;
BANK0	GROUP	0
	LIB	ZRAM
	LIB	ZBN
;
	KANJI
	isdmg
;
	LIST
;(CGB)	ORG	$087C
;;CGB;;	ORG	$0890
;-----------------------------------------------------
;========================================
PLPTSTL
	LD	A,$02
	LD	($2100),A
	CALL	PLPTST
	JP	PBRETN
;========================================
LDTIM3 
	LD	HL,ENTIM3
	JR	LDTSUB
;========================================
LDTIM1 
	LD	HL,ENTIM1
	JR	LDTSUB
;========================================
LDTIM0
	LD	HL,ENTIM0
LDTSUB
	ADD	HL,BC
	LD	A,(HL)
	AND	A
	RET
;-----------------------------------------------------
;-----------------------------------------------------
YOSSISET
	LD	A,YOSSI
	CALL	ENIDSHL
;
	LD	A,(PLXPSL)
	LD	HL,ENXPSL
	ADD	HL,DE
	LD	(HL),A
;
	LD	A,(PLYPSL)
	LD	HL,ENYPSL
	ADD	HL,DE
	LD	(HL),A
;
	RET
;
;-----------------------------------------------------
;-----------------------------------------------------
;-----------------------------------------------------
NOSDST	;巆擮壒両
	LD	A,$1D
	LD	(SOUND1),A	;(S)
	RET
;-----------------------------------------------------
MSCHNOR
	LD	HL,MSCHNO
	JR	MSCHN2RS
;-----------------------------------------------------
MSCHN2R
	LD	HL,MSCHN2
MSCHN2RS
	LD	A,$1C
	LD	($2100),A
	ADD	HL,BC
	LD	A,(HL)
	LD	HL,$2100
	LD	(HL),$01
	RET
;-----------------------------------------------------
GKCHRV	; 妝婍僉儍儔僋僞乕 RETURN SUB!
	LD	A,$0C
	LD	($2100),A
;
	LD	BC,$0040	; 屄悢 
	CALL	DATA_MOV	; 僉儍儔僋僞 揮憲
;
	LD	A,$01
	LD	($2100),A
	RET
;-----------------------------------------------------
BBSDST
	LD	HL,SOUND3
	LD	(HL),$0C	;(S)
;
OTOSET
	LD	HL,OTOFLG
	LD	(HL),$04
	RET
;-----------------------------------------------------
ENHNCL
	LD	HL,ENHNFG
	ADD	HL,BC
	LD	A,(HL)
	AND	A
	JR	Z,EHNC10
;
	DEC	(HL)
EHNC10
	RET
;-----------------------------------------------------
NAZOCLR
	PUSH	AF
;
	LD	A,(NAZOCL)
	AND	A
	JR	NZ,NZCLR10
;
	LD	(DJSDON),A	;拞儃僗梡僒僂儞僪僙僢僩僋儕傾乕
	INC	A
	LD	(NAZOCL),A
	LD	(IWAMSFG),A	;僸儞僩儊僢僙乕僕両僋儕傾乕
;
	LD	A,(WARPFG)
	AND	A
	JR	NZ,NZCLR10
;
	LD	A,$02
	LD	(SOUND1),A	;(S)
NZCLR10
	POP	AF
	RET
;-----------------------------------------------------
;===============================================
NXGOTO
	LD	A,$30
	LD	(SDOUTFG),A	; BGM Fade OUT 
	JR	NXG010
;===============================================
NXGOTO4
	LD	A,$30
	LD	(SDOUTFG),A	; BGM Fade OUT 
	JR	NXG011
;- - - - - - - - - - - - - - - -
NXGOTO2
	LD	A,(NXRMMD)
	CP	DNJ
	JR	NZ,NXGOTO
;
	LD	A,(DJFLAG)
	AND	A
	JR	Z,NXGOTO
;
	LD	A,$01
	LD	(BGMNOT),A
NXG010
	LD	A,$06
	LD	(SOUND3),A	;(S)
NXG011
;
NXGOTO3
	LD	A,PINDR1
	LD	(PLMODE),A	; Goto next room !
;
	XOR	A
	LD	(SBHR),A
	LD	(SBCNT),A
	LD	(BIRDFG),A
;
	AND	A	; CLC
	RET
;===========================================
DUSHCL
	XOR	A
	LD	(SPCTTM),A
	LD	(SPCTWT),A
DUSHCL2
	XOR	A
	LD	(DUSHCT),A
	LD	(DUSHFG),A
	RET
;=========================================
PLPSRV
	LD	A,(PLSVXL)
	LD	(PLXPSL),A
	LD	A,(PLSVYL)
	LD	(PLYPSL),A
	RET
;=============================
EXIDSH
	PUSH	AF
;
	LD	E,EXNO-1
	LD	D,$00
WUS010
	LD	HL,EXMODE
	ADD	HL,DE
	LD	A,(HL)
	AND	A
	JR	Z,WUS020
	DEC	E
	LD	A,E
	CP	$FF
	JR	NZ,WUS010
;
	LD	HL,EXSTCT
	DEC	(HL)
	LD	A,(HL)
	CP	$FF
	JR	NZ,WUS018
;
	LD	A,EXNO-1
	LD	(EXSTCT),A
WUS018
	LD	A,(EXSTCT)
	LD	E,A
WUS020
	POP	AF
EXSET
	LD	HL,EXMODE
	ADD	HL,DE
	LD	(HL),A
;
	LD	A,(WORK1)   ;PLYPSL)
	LD	HL,EXYPSL
	ADD	HL,DE
	LD	(HL),A
;
	LD	A,(WORK0)  ;PLXPSL)
	LD	HL,EXXPSL
	ADD	HL,DE
	LD	(HL),A
;
	LD	HL,EXTIM0
	ADD	HL,DE
	LD	(HL),$0F ;A
	RET
;===================================
KNFLSH
	LD	A,(PKCRX1)
	SUB	$08
	LD	(WORK0),A
	LD	A,(PKCRY1)
	SUB	$08
	LD	(WORK1),A
FLASHST
	LD	A,$07
	LD	(SOUND1),A	;(S)
;
	LD	A,FLSH
	JP	EXIDSH
;
;================================
BGBKST	; BG bank set 
;(CGB)	LD	A,$8
	LD	A,$20		; 僨乕僞傪 ZMAP 偵堏摦
	LD	($2100),A
;
	LD	A,(DJFLAG)
	AND	A
	JR	Z,BKS011
;
	LD	A,(GRNDPT)
	LD	E,A
	LD	D,$0
;
	LD	HL,DBBKDT
;
		LD	A,(DNJNNO)
		CP	NEWDJ
		JR	NZ,DBS990_PASS
		LD	HL,DBBKDT2
		JR	DBS990
DBS990_PASS
;
;;;KK;;;	LD	A,(DNJNNO)
	CP	DJROOM2
	JR	NC,DBS990
;
	CP	DJROOM ;$20
	JR	C,DBS990
;
	INC	H
DBS990
	ADD	HL,DE
	LD	A,(BKCHNO)
	LD	E,A
	LD	A,(HL)
	CP	E
	JR	Z,BKS008	; bank change ?
	LD	(BKCHNO),A
	CP	$FF
	JR	Z,BKS008	; bank change ?
;
	LD	A,$1
	LD	(BKCHFG),A
BKS008
	JR	BKST09
;
;
;
BKS011
	LD	A,(GRNDPT)
	CP	$07
	JR	NZ,BKS01122
	INC	A
BKS01122
	LD	D,A
	SRL	A
	SRL	A
	AND	%11111000
	LD	E,A
	LD	A,D ;(GRNDPT)
	SRL	A
	AND	%00000111
	OR	E
;
	LD	E,A
	LD	D,$0
;
	LD	HL,GBBKDT
	ADD	HL,DE
	LD	A,(BKCHNO)
	LD	E,A
	LD	A,(HL)
	CP	E
	JR	Z,BKST09	; bank change ?
	CP	$0F		; yes !
	JR	Z,BKST09	; set ? (F):Not set
;				; yes !

		CP	CCC		; 26,27,36,37 僄儕傾丠
		JR	NZ,BKST08	; 俶俷

		LD	A,(GRNDPT)
		CP	$37		; 37(僇儊儔壆偝傫)丠
		JR	NZ,BKST09	; 俶俷

		LD	A,(HL)
BKST08
	LD	(BKCHNO),A
	LD	A,$1
	LD	(BKCHFG),A
BKST09
;- - Enemy bank check - - 
	XOR	A
	LD	(WORK0),A
;
	LD	A,(GRNDPT)
	LD	E,A
	LD	D,$00
	LD	HL,GREBDT
;
;;;KK;;;		LD	A,(DNJNNO)
;;;KK;;;		CP	NEWDJ
;;;KK;;;		JR	NZ,EBK010_PASS	;	NO --> EBK010_PASS
;;;KK;;;		LD	HL,DJEBDT2
;;;KK;;;		ADD	HL,DE
;;;KK;;;		LD	E,(HL)
;;;KK;;;		JP	EBK0211	;抧忋丠
EBK010_PASS
;
	LD	A,(DJFLAG)
	LD	D,A
	LD	A,(DNJNNO)
	CP	DJROOM2 ;$20
	JR	NC,EBK010
	CP	DJROOM ;$20
	JR	C,EBK010
	INC	D
EBK010
	ADD	HL,DE
	LD	E,(HL)
;
	LD	A,D
	AND	A
	JR	NZ,EBK0211	;抧忋丠
;				;YES !
	LD	A,E
	CP	$23
	JR	NZ,EBK0111	;恖嫑丠
;				;YES ! $71
	LD	A,(GRRMSV+$C9)
	AND	%00100000
	JR	Z,EBK0111	;僀儀儞僩屻丠
;				;YES!
	INC	E
EBK0111
	LD	A,E
	CP	$21
	JR	NZ,EBK0211	;僩僢僪丠
;				;YES ! $71
	LD	A,(GRRMSV+$FD)
	AND	%00100000
	JR	Z,EBK0211	;僀儀儞僩屻丠
;				;YES!
	INC	E
EBK0211
	LD	D,$00
	SLA	E
	RL	D
	SLA	E
	RL	D
;
		LD	A,(DNJNNO)
		CP	NEWDJ		;怴僟儞僕儑儞丠
		JR	NZ,EBK022_PASS	;	NO --> EBK022_PASS
		LD	A,$001
		LD	(BKCHF2),A
		JR	EBCH30
EBK022_PASS
	LD	HL,GEBANKD
	LD	A,(DJFLAG)
	AND	A
	JR	Z,EBK022
	LD	HL,DEBANKD
EBK022
	ADD	HL,DE
;
	LD	D,$00
	LD	BC,EBANK0
EBCH10
	LD	E,(HL)
	LD	A,(BC)
	CP	E
	JR	Z,EBCH20	; Bank chenge ?
;				; yes !
	LD	A,E
	CP	$FF
	JR	Z,EBCH20
;
	LD	(BC),A
;
	LD	A,(WORK0)
	AND	A
	JR	Z,EBCH11	; Second set ?
;				; yes !
	LD	A,D
	LD	(EBCHF2),A	; Port 2
	LD	A,$1
	LD	(BKCHF3),A
	JR	EBCH20
EBCH11
	INC	A
	LD	(WORK0),A
;
	LD	A,D
	LD	(EBCHFG),A	; Port 1
	LD	A,$1
	LD	(BKCHF2),A
EBCH20
	INC	HL
	INC	BC
	INC	D
	LD	A,D
	CP	$4
	JR	NZ,EBCH10
EBCH30
;
	JP  	PBRETN
;
;
CARITMD	EQU	$0C	; Ken chari time
;================================================================
;= 偡傋偰偺巒傑傝両						=
;================================================================
PLAY
;
PLAY001
	LD	A,(GMMODE)
	CP	GMAP
	JR	C,GPM900	; 僎乕儉拞丠
;
	CP	GPLAY	
	JR	NZ,PLAY005
;
	LD	A,(ITMODE)
	CP	GPMA
	JR	NZ,GPM900
;
PLAY005
	LD	A,(SBHR)
	CP	$04
	JR	NZ,GPM900
;				; YES !
	LD	A,(MSGEFG)
	LD	HL,ITEMNOT
	OR	(HL)
	LD	HL,SCRLFG
	OR	(HL)
	JR	NZ,GPM900
;				; YES !
		LD	A,(GMMODE)	;傾僀僥儉僙儗僋僩儌乕僪
		CP	ITSEL		;	埲崀偺儌乕僪僫儞僶乕丠
		JR	NC,GPM900	;	YES --> GPM900
;
	LD	A,(KEYA1)
	CP	%11110000
	JR	NZ,GPM900	;嫮惂僙乕僽儌乕僪?
;
	XOR	A		;YES !
	LD	(SBHR),A
	LD	(SBCNT),A
	LD	(MSGEFG),A
;
	LD	(ITMODE),A
	LD	A,TSVE
	LD	(GMMODE),A
;
;---------------------------------
GPM900
	LD	A,(GMMODE)
;
	RST	0
	DW	OPNING	; (0) 僆乕僾僯儞僌
	DW	ENDINGS ; (1) TITLE
	DW	PLSLCT	; (2) 僾儗僀儎乕僙儗僋僩
	DW	NMREGI	; (3) 柤慜搊榐
	DW	NMCLER	; (4) 僨乕僞徚嫀
	DW	NMCOPY	; (5) 僨乕僞僐僺乕
	DW	TSAVE	; (6) Hot save mode !
	DW	GRMAP	; (7) Ground map mode !
	DW	PEACHS	; (8) 僺乕僠幨恀 !
	DW	LOVEDM	; (9) 奀娸僨儌 !
	DW	KABE1S	; (A) 僋僕儔暻夋!
	DW	GMPLAY  ; (B) GAME MAIN !!
;( for CGB )
	DW	ITEMSEL	; (C) 傾僀僥儉僙儗僋僩
	DW	PRINTER	; (D) 億働僢僩僾儕儞僞
	DW	0000000	; 0E 俶倧.侽侾丂悺寑
	DW	0000000	; 0F 俶倧.侽俀丂悺寑
	DW	0000000	; 10 俶倧.侽俁丂悺寑
	DW	GEKI04_MD	; 10 俶倧.侽係丂悺寑
	DW	0000000	; 10 俶倧.侽俆丂悺寑
	DW	0000000	; 10 俶倧.侽俇丂悺寑
	DW	0000000	; 10 俶倧.侽俈丂悺寑
	DW	0000000	; 10 俶倧.侽俉丂悺寑
	DW	0000000	; 10 俶倧.侽俋丂悺寑
	DW	0000000	; 10 俶倧.侾侽丂悺寑
	DW	0000000	; 10 俶倧.侾侾丂悺寑
	DW	0000000	; 10 俶倧.侾俀丂悺寑
;
OPING	EQU	0
ENDG	EQU	1 
TITL	EQU	1 ;(偄傑偼傕偆側偄乯
PSLCT	EQU	2
NMREG	EQU	3
NMCLR	EQU	4
NMCPY	EQU	5
TSVE	EQU	6
GMAP	EQU	7
PEACH	EQU	8
LOVED	EQU	9
KABE1	EQU	$0A
GPLAY	EQU	$0B
;( for CGB )
ITSEL	EQU	$0C
PRN	EQU	$0D
GEKI01	EQU	$0E
GEKI02	EQU	$0F
GEKI03	EQU	$10
GEKI04	EQU	$11
GEKI05	EQU	$12
GEKI06	EQU	$13
GEKI07	EQU	$14
GEKI08	EQU	$15
GEKI09	EQU	$16
GEKI10	EQU	$17
GEKI11	EQU	$18
GEKI12	EQU	$19
;
;************************************************
;*	僋僕儔暻夋				*
;************************************************
KABE1S
	CALL	KABE1SB
;
	JP  	MSSUBS
;
;************************************************
;*	僺乕僠幨恀				*
;************************************************
PEACHS
	CALL	PEACHSB
;
	JP  	MSSUBS
;
;************************************************
;*	奀娸僨儌				*
;************************************************
LOVEDM
	CALL	LOVEDEMO
;
	JP  	MSSUBS
;
;************************************************
;*	抧忋儅僢僾昞帵				*
;************************************************
GRMAP
	CALL	GRMAPSB
;
	JP  	MSSUBS
;
;************************************************
;*						*
;************************************************
TSAVE
	JP  	TSAVESB
;
;************************************************
;*	僆乕僾僯儞僌				*
;************************************************
OPNING
	JP  	OPENING
;
;************************************************
;*	僄儞僨傿儞僌				*
;************************************************
ENDINGS
	LD	A,$17
	CALL	PBSET
;
	CALL  	ENDING
;
	JP  	MSSUBS
;=============================
ENEMYL
	LD	A,$03
	LD	($2100),A
	LD	A,$17
ENL10
	PUSH	AF
	CALL	ENEMY
	POP	AF
	JP  	PBSET
;=============================
ENEMYL1
	LD	A,$03
	LD	($2100),A
	LD	A,$01
	JR	ENL10
;=============================
ENEMYL2
	LD	A,$03
	LD	($2100),A
	LD	A,$02
	JR	ENL10
;
;************************************************
;*	僾儗僀儎乕僙儗僋僩			*
;************************************************
PLSLCT
	JP  	PLSLCTS
;
;************************************************
;*	NAME REGIST 柤慜搊榐			*
;************************************************
NMREGI
	JP  	NMREGIS
;
;************************************************
;*	NAME CLEAR 僨乕僞徚嫀			*
;************************************************
NMCLER
	JP  	NMCLERS
;
;************************************************
;*	NAME COPY 僨乕僞僐僺乕			*
;************************************************
NMCOPY
	JP  	NMCOPYS
;
;****************************************
;*       GAME Play      	        *
;****************************************
GMPLAY ;PLINIT
	LD	A,$14
	LD	($2100),A
	CALL	FADECK
	CALL	EXSEST	;摿庩抧宍SE set
;
	LD	A,$01
	CALL	PBSET
	JP  	GPSUB

;****************************************
;*	傾僀僥儉僙儗僋僩 (CGB)		*
;****************************************
ITEMSEL
	LD	A,$20
	CALL	PBSET

	JP	ITEM_SELECT

;****************************************
;*	億働僢僩僾儕儞僞 (CGB)		*
;****************************************
PRINTER
	LD	A,:PRINTER_MAIN
	CALL	PBSET

	CALL	PRINTER_MAIN

	JP	MSSUBS

;****************************************
;*	俶倧.侽係丂悺寑			*
;****************************************
GEKI04_MD
	LD	A,:GEKI04_MODE
	CALL	PBSET

	JP	GEKI04_MODE

;****************************************
;*       GAME Play  Main                *
;****************************************
GPMAIN   ;PLAY00
	LD	A,$02
	CALL	PBSET	;For exstra sub!
;
	LD	A,(MSGEFG)
	AND	A
	JR	NZ,PLY0F0
;
	LD	HL,DJMSTM
	LD	A,(HL)
	AND	A
	JR	Z,PLYD00
;
	LD	A,(WNDYPS)
	CP	$80
	JR	NZ,PLYD00
;
	LD	A,(WNDFLG)
	AND	A
	JR	NZ,PLYD00
;
	DEC	(HL)
	JR	NZ,PLYD00
;
	LD	A,$01
	LD	($2100),A
	CALL	DJMSCK	;僟儞僕儑儞埬撪儊僢僙乕僕僙僢僩!
	CALL	PBRETN
PLYD00
	LD	A,(MSGEFG)
	AND	A
	JR	NZ,PLY0F0
;
	LD	A,(DJCLTM)
	AND	A
	JR	Z,PLY0F0
;
	LD	HL,PLSTOP
	LD	(HL),$02
;
	DEC	A
	LD	(DJCLTM),A
	JR	NZ,PLY0F0
;
	JP	NXGOTO
;
PLY0F0
	LD	HL,PLFLSH
	LD	A,(HL)
	AND	A
	JR	Z,PLY000
	DEC	(HL)
PLY000
	LD	A,(PLXPSL)
	LD	(PLSVXL),A
	LD	A,(PLYPSL)
	LD	(PLSVYL),A
	LD	HL,PLZPSL
	SUB	(HL)
	LD	(PLDSYP),A
;
	CALL	WINDOW	; Item window 
;
	XOR	A
	LD	(PKCRX1),A
	LD	(PLDSXD),A
	LD	(PLDSYD),A
;
	LD	HL,PLFLPL
	RES	7,(HL)
	LD	HL,PLFLPR
	RES	7,(HL)
;
	CALL	DOORSUB	; Dandyon door open sub !
;
	LD	A,$2
	CALL	PBSET
	CALL	SCROLL	; BG write & scroll
;
	CALL	PLAYER	; Player
;
	LD	A,(PLCAMD)
	LD	(WPLCAMD),A
;
	LD	A,$20
	LD	($2100),A
	CALL	PLY100_SUB
;
;;;KK;;;	XOR	A
;;;KK;;;	LD	(BOMBFG),A	; Bomber  shot falg clear !
;;;KK;;;	LD	(BUMEFG),A	; Bomber  shot falg clear !
;;;KK;;;	LD	(PFUCKFG),A	; Bomber  shot falg clear !
;;;KK;;;	LD	(PLCAMD),A	; Player cach flag 
;;;KK;;;	LD	(SLIMCNT),A	; Boss small slime set count
;;;KK;;;;
;;;KK;;;	LD	A,(PLOSHI)
;;;KK;;;	AND	A
;;;KK;;;	JR	Z,PLY100
;;;KK;;;	DEC	A
;;;KK;;;	LD	(PLOSHI),A	; Player oshi flag 
;;;KK;;;PLY100
	LD	A,$19
	CALL	PBSET
;
	CALL	BELTCK	; 儀儖僩僐儞儀傾乕揮憲寁嶼両(IN ENMY7)
;
	CALL	ENEMY	; Enemy
;
	LD	A,$2
	CALL	PBSET
;
	CALL	EXSTRA	; Exstra 
;
	LD	HL,VRAMD+1
	LD	A,(FRCNT)
	AND	$3
	OR	(HL)
	JR	NZ,LFU030
;
	LD	A,(PLMODE)
	CP	PMOVE+2
	JR	NC,LFU030
;
	LD	C,$01
	LD	B,$00
	LD	E,$00
;
	LD	A,(FRCNT)
	AND	%00000100
	JR	Z,LFU020
;
	DEC	C
	DEC	E
LFU020
		LD	A,$20
		LD	($2100),A
		CALL	ITSEL_SUB	; BG chenge
;;;CGB;;;	CALL	ITEMDP2		; BG chenge
;
LFU030
	LD	A,$14
	CALL	PBSET
	CALL	TILTCK
MSSUBS
	LD	A,$0F
	CALL	PBSET	; 暥帤僉儍儔僋僞乕僶儞僋
;
	CALL	MESEGE	; 儊僢僙乕僕

;------------------------------------------
	LD	A,$21
	CALL	PBSET
	CALL	MORI_COL_CHANGE	; (CGB) 柪偄偺怷僇儔乕僠僃儞僕
;------------------------------------------

	RET
;****************************************
;*       PLAYER		                *
;****************************************
DMMSDT
	DB	$08,$0E,$99,$28,$EC  ;,$8E
;
PLAYER	
	LD	A,(PLYPSL)
	LD	HL,PLZPSL
	SUB	(HL)
	LD	(PLYPS2),A
;
	LD	A,(DEMOFG)
	AND	A
	JR	Z,PY1080
;
	LD	A,(MSGEFG)
	AND	A
	JR	NZ,PY1010
;
	LD	HL,DEMOTM
	DEC	(HL)
	LD	A,(HL)
	CP	$02
	JR	NZ,PY100E
;
	LD	A,(DEMOFG)
	LD	E,A
	LD	D,$00
	LD	HL,DMMSDT-1
	ADD	HL,DE
	LD	A,(HL)
	CALL	MSGCHK
;
	LD	A,$01
PY100E
	AND	A
	JR	NZ,PY1010
;
	XOR	A
	LD	(DEMOFG),A
	LD	(ENSTFG),A
;
	JR	PY1080
PY1010
	LD	A,(DEMOFG)
	LD	(ENSTFG),A
	DEC	A
	RST	0
	DW	KNPWUPS ;1 寱僷儚乕傾僢僾僨儌
	DW	ITEMUP	;2 壗偵巊偆偐傢偐傜傫傾僀僥儉僨儌(偒偺偙乯
	DW	PWDRUP	;3 杺朄偺暡帩偪忋偘僨儌両 
	DW	ITEMUP	;4 壗偵巊偆偐傢偐傜傫傾僀僥儉僨儌乮偐偄偑傜乯
	DW	DEFUP	;5 栘偺傒庣傝傾僢僾両
;========================================
PY1080
	LD	A,(KEYA1)
	AND	%10110000
	JR	NZ,GMP0000
;
	LD	A,(KEYA1)
	AND	%01000000
	JR	Z,GMP0000
;
	LD	A,(GMPTIM)
	INC	A
	LD	(GMPTIM),A
	CP	$04
	JR	C,GMP00001
;
	LD	A,(PLSTOP)
	CP	$02
	JR	Z,GMP0000
;
	LD	A,(PLCHPT)
	CP	$FF
	JR	Z,GMP0000
;
	LD	A,(PLMODE)
	CP	PMOVE+2
	JR	NC,GMP0000
;
	LD	A,(MSGEFG)
	LD	HL,ITEMNOT
	OR	(HL)
	LD	HL,SCRLFG 
	OR	(HL)
	JR	NZ,GMP0000
;
	XOR	A
	LD	(SBHR),A
	LD	(SBCNT),A
;
	LD	(ITMODE),A
	LD	A,GMAP
	LD	(GMMODE),A
;
	LD	A,$02
	LD	($2100),A
	CALL	PLIDBC2
	CALL	PLCSET
	CALL	ENEMY
;
	POP	AF
;==============================
	RET
GMP0000
	XOR	A
	LD	(GMPTIM),A
GMP00001
;=================================
	LD	A,(PLTIM0)
	AND	A
	JR	Z,PLAYER00
;
	DEC	A
	LD	(PLTIM0),A
PLAYER00
	LD	A,(KNKNTM)
	AND	A
	JR	Z,PLAYER01
;
	DEC	A
	LD	(KNKNTM),A
PLAYER01
	LD	A,(MSGEFG)
	AND	A
	JP	NZ,PLWPCS
;
	LD	A,(SCRLFG)
	AND	A
	JP	NZ,PL0B0
;
	LD	A,(PLMODE)
	CP	POVER
	JR	Z,PLAYER10
;
	LD	A,(HARTCT)
	LD	HL,SHOPFG
	OR	(HL)
	LD	HL,WNDFLG
	OR	(HL)
	JR	NZ,PLAYER08
;
	LD	A,POVER
	LD	(PLMODE),A
	LD	A,$7F+$40
	LD	(PLTIM0),A
	LD	A,$10
	LD	(FADECT),A
;
	XOR	A
	LD	(PLFLSH),A
	LD	(PLSTAT),A
;
	CALL	SOUNDCLR	;(S)
;
	LD	A,$08
	LD	(SOUND2),A	;(S)
PLAYER08
	LD	A,(PLMODE)
PLAYER10
	RST	0
	DW	PLMOVE
	DW	PLSWIMS	; Swiming !
	DW	PLTOBIS	; Tobiori 
	DW	PLINDR1 ; In room  1
	DW	PLINDR2 ;          2
	DW	KURDORS	; Kurukuru door !
	DW	PLFOLES	; Fole fall !
	DW	PLOVER	; Game over
	DW	PLOBORS	; Mizu obore
	DW	PLWARPS	; 屌掕儚乕僾
	DW	PLBOXER	; 儃僋僒乕僷儞僠傇偭旘傃両
;
;- - - - - - - - - - - - - - - - - - -
PMOVE	EQU	$0
PSWIM	EQU	$1
PTOBI	EQU	$2
PINDR1	EQU	$3
PINDR2	EQU	$4
POTDR1	EQU	3  ;$5
POTDR2	EQU	4  ;$6
KURUD	EQU	5  ;$7
PFOLE	EQU	6  ;$8
POVER	EQU	7  ;$8
POBOR	EQU	8
PWARP	EQU	9
PBOXER	EQU	$A
; - - - In scroll - - - - - -
PL0B0
;========================================
	CALL	PLWPCS		; Wepon character set
	JP   	PLCSET
;=============================
PLWARPS
	LD	A,$19
	CALL	PBSET
;
	JP	PLWARP
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;%	Game over  			     %
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
PLOVER
	LD	A,$01
	CALL	PBSET
	JP	PLOVERS
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;%	曕偔				     %
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
PLMOVE
	LD	A,$02
	CALL	PBSET
;
	CALL	PLMOVES
	RET
;
;---------------------------------
PKEN	EQU	$01
PBOMB	EQU	$02
PBULE	EQU	$03
PTATE	EQU	$04
PYAST	EQU	$05
PFUCK	EQU	$06
PROD	EQU	$07
PSHSE	EQU	$08
POKAR	EQU	$09
PHANE	EQU	$0A
PSKOP	EQU	$0B
PMGIC	EQU	$0C
PBUME	EQU	$0D
;- - - - - - - - - - - - - - - - - 
PLTOOL
	LD	A,(SHOPFG)
	LD	HL,ITEMNOT
	OR	(HL)
	LD	HL,PFUCKFG
	OR	(HL)
	RET	NZ
;
	LD	A,(DUSHFG)
	AND	A
	JR	Z,TOL158
;
	LD	A,(ITEMA)
	CP	PKEN
	JR	Z,TOL120
	LD	A,(ITEMB)
	CP	PKEN
	JR	Z,TOL120
;
	LD	A,(ITEMA)
	CP	PTATE
	JR	Z,TOL110
	LD	A,(ITEMB)
	CP	PTATE
	JR	NZ,TOL150
;
TOL110
	CALL	TATEST
	JR	TOL150
TOL120
	LD	A,(PCUTFG)
	DEC	A
	CP	$04
	JR	C,TOL150
;
	LD	A,$4+1
	LD	(PCUTFG),A
	LD	(WCUTFG),A	; Ken kamae set !
TOL150
	JR	TOL160
;=============================================
TOL158
	XOR	A
	LD	(TATEON),A
	LD	(TATEFG),A
;
TOL160
	LD	A,(SLIMFG)
	AND	A
	JP	NZ,PLTL20	;僗儔僀儉傂偭偮偄偨丠
;				;NO.
	LD	A,(PLCAMD)
	AND	A ;OR	(HL) ;AND	A
	JP	NZ,PLTL20
;
	LD	A,(PCUTFG)
	AND	A
	JR	Z,PLTL1A
;
	CP	$03
	JR	NZ,PLTL1A
;
	LD	A,(PCUTTM)	; yes !
	CP	$03
	JR	NC,PLTL1B
;
PLTL1A
	LD	A,(PLSTOP)
	AND	A
	JP	NZ,PLTL20
PLTL1B
;===Level input====
	LD	A,(ITEMB)
	CP	PSHSE
	JR	NZ,PLTL015
;
	LD	A,(KEYA1)
	AND	%00100000
	JR	Z,PLTL01
;
	CALL	DUSHST
	JR	PLTL015
;-- - - - - - - - - - - - - -
PLTL01
	XOR	A
	LD	(DUSHCT),A
PLTL015
	LD	A,(ITEMA)
	CP	PSHSE
	JR	NZ,PLTL0C
;
	LD	A,(KEYA1)
	AND	%00010000
	JR	Z,PLTL08
;
	CALL	DUSHST
	JR	PLTL0C
PLTL08
	XOR	A
	LD	(DUSHCT),A
PLTL0C
	LD	A,(ITEMA)
	CP	PTATE
	JR	NZ,PLTL0E
;
	LD	A,(TATLEV)
	LD	(TATEFG),A
;
	LD	A,(KEYA1)
	AND	%00010000
	JR	Z,PLTL0E
;
	LD	A,(MSCRFG)
	CP	$01
	JR	Z,PLTL0E
	CP	$02
	JR	Z,PLTL0E
;
	CALL	TATEST
PLTL0E
	LD	A,(ITEMB)
	CP	PTATE
	JR	NZ,PLTL0F
;
	LD	A,(TATLEV)
	LD	(TATEFG),A
;
	LD	A,(KEYA1)
	AND	%00100000
	JR	Z,PLTL0F
;
	CALL	TATEST
PLTL0F
;===Triger input====
	LD	A,(KEYA2)
	AND	%00100000
	JR	Z,PLTL10
;
	LD	A,(MSCRFG)
	CP	$02
	JR	Z,PLTL10	; 僞僇儔仌僇儞僶儞 ?
;				; no !
	LD	A,(ITEMB)
	CALL	TLCHEK
;-- - - - - - - - - - - - - -
PLTL10
	LD	A,(KEYA2)
	AND	%00010000
	JR	Z,PLTL201
;
	LD	A,(MSCRFG)
	CP	$01
	JR	Z,PLTL201	; Peaple cros ?
	CP	$02
	JR	Z,PLTL201	; Peaple cros ?
;				; no !
	LD	A,(ITEMA)
	CALL	TLCHEK
;
PLTL201
	LD	A,(KEYA1)
	AND	%00100000
	JR	Z,PLTL110
;
	LD	A,(ITEMB)
	CALL	TLCHEK2
PLTL110
	LD	A,(KEYA1)
	AND	%00010000
	JR	Z,PLTL120
;
	LD	A,(ITEMA)
	CALL	TLCHEK2
PLTL120
;
		LD	A,$020
		LD	($2100),A
		CALL	NEWDJ_BGCRS
		LD	A,(PBANK)
		LD	($2100),A
;
	RET
;=========================================
;-- For triger input check - -
TLCHEK
	LD	C,A
;
	CP	PKEN
	JP	Z,PCUTST
	CP	PTATE
	JP	Z,TATESDS
	CP	PBOMB
	JP	Z,BOMBRST
	CP	PBULE
	JP	Z,BULESST
	CP	PYAST
	JP	Z,PYAAAST
	CP	PBUME
	JP	Z,BUMERST
	CP	PFUCK
	JP	Z,PFUCKST
	CP	PHANE
	JP	Z,JUMPST
	CP	POKAR
	JP	Z,OKARST
	CP	PMGIC
	JP	Z,MGICPW
	CP	PSKOP  ;MEMO
	JP	Z,ANAHST ;MEMOOK
	CP	PROD
	JR	NZ,PLTL20
;
	LD	HL,PCUTFG	; Yes ! Rod start !
	LD	A,(POWDRTM)
	OR	(HL)
	JR	NZ,PLTL20
;
	LD	A,(BUMEFG)
	CP	$02
	JR	NC,PLTL20
;
	LD	A,$0E+$80
	LD	(POWDRTM),A
PLTL20
	RET
;=========================================
TATESDS
	LD	A,(PLOSHI)
	AND	A
	RET	NZ
;
	LD	A,$16
	LD	(SOUND3),A	;(S)
;
	RET
;=========================================
ANAHST  ;MEMOOK
	LD	A,(ANAHFG)
	LD	HL,PLJPFG
	OR	(HL)
	RET	NZ
;
	CALL	ANBGSB		;孈傞慜BG僠僃僢僋両
	JR	NC,ANAHS08	;孈傟側偄丠
;				;YES !
	LD	A,$07		
	LD	(SOUND1),A	;(S) 僇僢僉乕儞!
	JR	ANAHS0C
;
ANAHS08
	LD	A,$0E
	LD	(SOUND3),A	;(S)
ANAHS0C
	LD	A,$01
	LD	(ANAHFG),A
;
	XOR	A
	LD	(ANAHTM),A
ANAHS10
	RET
;=========================================
PFUCKST
	LD	A,(PFUCKFG)
	AND	A
	RET	NZ
	CALL	FUCKSST
;
PFS900
	RET
;=========================================
;-- For revel input check - -
TLCHEK2
	CP	PKEN
	RET	NZ
;------------------------------
PCUTST2
	LD	HL,PCUTFG
	LD	A,(MSCRFG)
	AND	$03
	OR	(HL)
	RET	NZ
;
	LD	A,(PCUTOF)
	AND	A
	RET	NZ
;
	XOR	A
	LD	(KENOFF),A
;
	LD	A,$4+1
	LD	(PCUTFG),A
	LD	(KENTAT),A
PCS230
	RET
;
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;%	儕儞僋偑弬傪偐傑偊傞					%
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;;;KK;;;TTCRX1
;;;KK;;;	DB	$10,$00,$08,$08
;;;KK;;;TTCRX2
;;;KK;;;	DB	$03,$03,$08,$08
;;;KK;;;TTCRY1
;;;KK;;;	DB	$08,$08,$00,$0D
;;;KK;;;TTCRY2
;;;KK;;;	DB	$08,$08,$03,$04
;---------------------------------------
TATEST
	LD	A,$1
	LD	(TATEON),A
;
	LD	A,(TATLEV)
	LD	(TATEFG),A
TATEST2
;
		LD	A,$20
		LD	($2100),A
		CALL	TATEST2_SUB
		LD	A,(PBANK)
		LD	($2100),A
		RET
;
;;;KK;;;	LD	A,(PLCMKI)
;;;KK;;;	LD	E,A
;;;KK;;;	LD	D,$0
;;;KK;;;;
;;;KK;;;	LD	HL,TTCRX1
;;;KK;;;	ADD	HL,DE
;;;KK;;;;
;;;KK;;;	LD	A,(PLXPSL)
;;;KK;;;	ADD	A,(HL)
;;;KK;;;	LD	(PKCRX1),A
;;;KK;;;;
;;;KK;;;	LD	HL,TTCRX2
;;;KK;;;	ADD	HL,DE
;;;KK;;;	LD	A,(HL)
;;;KK;;;	LD	(PKCRX2),A
;;;KK;;;;
;;;KK;;;	LD	HL,TTCRY1
;;;KK;;;	ADD	HL,DE
;;;KK;;;;
;;;KK;;;	LD	A,(PLYPS2)
;;;KK;;;	ADD	A,(HL)
;;;KK;;;	LD	(PKCRY1),A
;;;KK;;;;
;;;KK;;;	LD	HL,TTCRY2
;;;KK;;;	ADD	HL,DE
;;;KK;;;	LD	A,(HL)
;;;KK;;;	LD	(PKCRY2),A
;;;KK;;;;
;;;KK;;;	XOR	A
;;;KK;;;	LD	(KENTAT),A
;;;KK;;;;
;;;KK;;;	RET
;
;################################################################
;#	儕儞僋偑敋抏傪僙僢僩偡傞				#
;################################################################
;;;KK;;;BBSTXP	
;;;KK;;;	DB	$08,$F8,$00,$00	
;;;KK;;;BBSTYP	
;;;KK;;;	DB	$00,$00,$FD,$04	
;- - - - - - - - - - - - - - - - - - - -
BOMBRST
	LD	A,(BOMBFG)
	CP	$1  ;2
	RET	NC
;
	LD	A,(BOMBCT)
	AND	A
	JP	Z,NOSDST
;
	SUB	$1
	DAA
	LD	(BOMBCT),A
;
	LD	A,BOMBR
	CALL	PLSHST
	RET	C
;
		LD	A,$20
		LD	($2100),A
		CALL	BOMBRST_SUB
		LD	A,(PBANK)
		LD	($2100),A
		RET
;
;;;KK;;;	LD	HL,ENTIM1
;;;KK;;;	ADD	HL,DE
;;;KK;;;	LD	(HL),$10	; CACH protect !!
;;;KK;;;;
;;;KK;;;	LD	A,(BMYATM)
;;;KK;;;	AND	A
;;;KK;;;	JP	Z,BBST001	; Bomb alow chance ?
;;;KK;;;;				; Yes !
;;;KK;;;	XOR	A
;;;KK;;;	LD	(BMYATM),A
;;;KK;;;;
;;;KK;;;	LD	A,(YAINDX)	; Old alow -> Bomb alow chenge !
;;;KK;;;	LD	C,A
;;;KK;;;	LD	B,D
;;;KK;;;	LD	HL,ENSTAT
;;;KK;;;	ADD	HL,BC
;;;KK;;;	LD	(HL),$01
;;;KK;;;	RET
;;;KK;;;;
;;;KK;;;BYTM	EQU	$06	; Bomb alow chance time !
;;;KK;;;;
;;;KK;;;BBST001
;;;KK;;;	LD	A,BYTM ;$06
;;;KK;;;	LD	(BMYATM),A
;;;KK;;;;
;;;KK;;;	LD	A,E
;;;KK;;;	LD	(BMINDX),A
;;;KK;;;;
;;;KK;;;	LD	A,$0C
;;;KK;;;	LD	(POWDRTM),A
;;;KK;;;;
;;;KK;;;	LD	HL,ENTIM0
;;;KK;;;	ADD	HL,DE
;;;KK;;;	LD	(HL),$A0  ;$FF  ;A
;;;KK;;;;
;;;KK;;;	LD	HL,ENCHPT
;;;KK;;;	ADD	HL,DE
;;;KK;;;	LD	(HL),D ;$00 ;A
;;;KK;;;;
;;;KK;;;	LD	HL,ENTIM4
;;;KK;;;	ADD	HL,DE
;;;KK;;;	LD	(HL),$3 ; Water up protect
;;;KK;;;;
;;;KK;;;	LD	A,(YKFLAG)
;;;KK;;;	AND	A
;;;KK;;;	JR	NZ,BBS089
;;;KK;;;;
;;;KK;;;	LD	A,$09
;;;KK;;;	LD	(SOUND1),A	;(S) Bomb set !
;;;KK;;;	JR	BBS08C
;;;KK;;;;
;;;KK;;;BBS089
;;;KK;;;	LD	HL,ENZPSL
;;;KK;;;	ADD	HL,DE
;;;KK;;;	LD	(HL),D
;;;KK;;;BBS08C
;;;KK;;;	LD	HL,ENXSPD
;;;KK;;;	ADD	HL,DE
;;;KK;;;	LD	(HL),D
;;;KK;;;	LD	HL,ENYSPD
;;;KK;;;	ADD	HL,DE
;;;KK;;;	LD	(HL),D	
;;;KK;;;;
;;;KK;;;	LD	HL,ENZSPD
;;;KK;;;	ADD	HL,DE
;;;KK;;;	LD	(HL),D
;;;KK;;;;
;;;KK;;;	LD	A,(PLCMKI)
;;;KK;;;	LD	C,A
;;;KK;;;	LD	B,D
;;;KK;;;	LD	HL,BBSTXP
;;;KK;;;	ADD	HL,BC
;;;KK;;;	LD	A,(PLXPSL)
;;;KK;;;	ADD	A,(HL)
;;;KK;;;	LD	HL,ENXPSL
;;;KK;;;	ADD	HL,DE
;;;KK;;;	LD	(HL),A
;;;KK;;;;
;;;KK;;;	LD	HL,BBSTYP
;;;KK;;;	ADD	HL,BC
;;;KK;;;	LD	A,(PLYPSL)
;;;KK;;;	ADD	A,(HL)
;;;KK;;;	LD	HL,ENYPSL
;;;KK;;;	ADD	HL,DE
;;;KK;;;	LD	(HL),A
;;;KK;;;;
;;;KK;;;	RET
;
;###############################################
;#					       #
;###############################################
BULESST
	RET
;
;################################################################
;#	儕儞僋偑僽乕儊儔儞傪搳偘傞				#
;################################################################
;;;KK;;;BRSXSD
;;;KK;;;	DB	$18,$E8,$00
;;;KK;;;BRSYSD
;;;KK;;;	DB	$E8,$18,$00
;
BUMERST
	LD	A,(BUMEFG)
	AND	A
	RET	NZ
;
	LD	A,BUMER
	CALL	PLSHST
	RET	C
;
		LD	A,$20
		LD	($2100),A
		CALL	BUMERST_SUB
		LD	A,(PBANK)
		LD	($2100),A
		RET
;
;;;KK;;;	LD	HL,ENTIM0
;;;KK;;;	ADD	HL,DE
;;;KK;;;	LD	(HL),$28  ;A
;;;KK;;;;
;;;KK;;;	LD	C,$4
;;;KK;;;	LD	B,$0
;;;KK;;;	LD	A,(KEYA1)
;;;KK;;;BRS080
;;;KK;;;	SRL	A
;;;KK;;;	JR	NC,BRS070
;;;KK;;;;
;;;KK;;;	INC	B
;;;KK;;;BRS070
;;;KK;;;	DEC	C
;;;KK;;;	JR	NZ,BRS080
;;;KK;;;;
;;;KK;;;	LD	A,B
;;;KK;;;	CP	$2
;;;KK;;;	JR	C,BRS090
;;;KK;;;;
;;;KK;;;	LD	A,(KEYA1)
;;;KK;;;	AND	%00000011
;;;KK;;;	LD	C,A
;;;KK;;;	LD	B,$0
;;;KK;;;	LD	HL,BRSXSD-1
;;;KK;;;	ADD	HL,BC
;;;KK;;;	LD	A,(HL)
;;;KK;;;	LD	HL,ENXSPD
;;;KK;;;	ADD	HL,DE
;;;KK;;;	LD	(HL),A
;;;KK;;;;
;;;KK;;;	LD	A,(KEYA1)
;;;KK;;;	SRL	A
;;;KK;;;	SRL	A
;;;KK;;;	AND	%00000011
;;;KK;;;	LD	C,A
;;;KK;;;	LD	B,$0
;;;KK;;;	LD	HL,BRSYSD-1
;;;KK;;;	ADD	HL,BC
;;;KK;;;	LD	A,(HL)
;;;KK;;;	LD	HL,ENYSPD
;;;KK;;;	ADD	HL,DE
;;;KK;;;	LD	(HL),A
;;;KK;;;BRS090
;;;KK;;;	RET
;
;###############################################
;#					       #
;###############################################
PYSXAD
	DB	$00,$00,$00,$00
PYSYAD
	DB	$00,$00,$00,$00
PYSXSD
	DB	$20,$E0,$00,$00
PYSYSD
	DB	$00,$00,$E0,$20
PYSXS2
	DB	$30,$D0,$00,$00
	DB	$40,$C0,$00,$00
PYSYS2
	DB	$00,$00,$D0,$30
	DB	$00,$00,$C0,$40
;- - - - - - - - - - - - - - - - -
PYAAAST
	LD	A,(PYAATM)
	AND	A
	RET	NZ
;
	LD	A,(BUMEFG)
	CP	$02
	JR	NC,PYST900
;
	LD	A,$10
	LD	(PYAATM),A
;
	LD	A,(YAAACT)
	AND	A
	JP	Z,NOSDST
;
	SUB	$1
	DAA
	LD	(YAAACT),A
;
	CALL	PLCMST	;PLCMKI set
;
	LD	A,PYAAA
	CALL	PLSHST
	RET	C
;
	LD	A,E
	LD	(YAINDX),A
;
	LD	A,(BMYATM)
	AND	A
	JR	Z,PYST001	; Bom alow chance ?
;				; Yes !
	LD	A,(BMINDX)
	LD	C,A
	LD	B,D
	LD	HL,ENMODE
	ADD	HL,BC
	LD	(HL),B		; Old bomb clear !
;
	LD	HL,ENSTAT
	ADD	HL,DE
	LD	(HL),$01
;
	XOR	A
	JR	PYST002
;- - - - - - - - - - - - - - -
PYST001
	LD	A,$0A
	LD	(SOUND3),A	;(S)
;
	LD	A,BYTM ;$04
PYST002
	LD	(BMYATM),A
;
	LD	A,(PLCMKI)
	LD	C,A
	LD	B,$00
;-------------------------------
TLSDST
	LD	A,(POWRFG)
	CP	$01
	JR	NZ,PYST800
;
	LD	A,C
	ADD	A,$4
	LD	C,A
PYST800
	LD	HL,PYSXS2
	ADD	HL,BC
;
	LD 	A,(HL)
	LD	HL,ENXSPD
	ADD	HL,DE
	LD	(HL),A
;
	LD	HL,PYSYS2
	ADD	HL,BC
;
	LD 	A,(HL)
	LD	HL,ENYSPD
	ADD	HL,DE
	LD	(HL),A
PYST900
	RET
;===================================
PLSHST
	CALL	ENIDSHL
	RET	C
;
	LD	A,$0C
	LD	(POWDRTM),A
;
	PUSH	BC
;
	LD	A,(PLCMKI)
	LD	C,A
	LD	B,$00
;
	LD	HL,PYSXAD
	ADD	HL,BC
;
	LD	A,(PLXPSL)
	ADD	A,(HL)
	LD	HL,ENXPSL
	ADD	HL,DE
	LD	(HL),A
;
	LD	HL,PYSYAD
	ADD	HL,BC
;
	LD	A,(PLYPSL)
	ADD	A,(HL)
	LD	HL,ENYPSL
	ADD	HL,DE
	LD	(HL),A
;
	LD	A,(PLZPSL)
	INC	A
	LD	HL,ENZPSL
	ADD	HL,DE
	LD	(HL),A
;
	LD	HL,PYSXSD
	ADD	HL,BC
;
	LD 	A,(HL)
	LD	HL,ENXSPD
	ADD	HL,DE
	LD	(HL),A
;
	LD	HL,PYSYSD
	ADD	HL,BC
;
	LD 	A,(HL)
	LD	HL,ENYSPD
	ADD	HL,DE
	LD	(HL),A
;
	LD 	A,(PLCMKI)
	LD	HL,ENCHPT
	ADD	HL,DE
	LD	(HL),A
;
	LD	HL,ENMUKI
	ADD	HL,DE
	LD	(HL),A
;
	LD	HL,ENSHMK
	ADD	HL,DE
	LD	(HL),A
;
	LD	HL,ENBCOF
	ADD	HL,DE
	LD	(HL),$01
;
	POP	BC
;
	SCF
	CCF	; CLC
PYS090
	RET
;
;################################################################
;#	儕儞僋偑杺朄偺暡傪巊偆					#
;################################################################
;;;KK;;;PWSXAD
;;;KK;;;	DB	$0E,$F2,$00,$00
;;;KK;;;PWSYAD
;;;KK;;;	DB	$00,$00,$F4,$0C
;
MGICPW
	LD	A,(POWDRTM)
	AND	A
	RET	NZ
;
	LD	A,(KINOKFG)
	AND	A
	JR	Z,MGP100	; 偒偺偙帩偭偰偄傞丠
;-----------------------------------------
	LD	A,(PLZPSL)
	AND	A
	RET	NZ
;
	LD	A,$02
CACHDMS
	LD	(DEMOFG),A
;				; Yes !
	LD	A,$2A
	LD	(DEMOTM),A	; 側傫偵傕偮偐偊側偄僨儌
	RET
;
MGP100
	LD	A,(TUBOCT)
	AND	A
	JP	Z,NOSDST
;
	LD	A,POWDR
	CALL	ENIDSHL
	RET	C
;
		LD	A,$20
		LD	($2100),A
		CALL	MGICPW_SUB
		LD	A,(PBANK)
		LD	($2100),A
		RET
;
;;;KK;;;	LD	A,$05
;;;KK;;;	LD	(SOUND1),A	;(S)
;;;KK;;;;
;;;KK;;;	LD	A,$0E
;;;KK;;;	LD	(POWDRTM),A
;;;KK;;;;
;;;KK;;;	LD	A,(TUBOCT)
;;;KK;;;	SUB	$01
;;;KK;;;	DAA
;;;KK;;;	LD	(TUBOCT),A
;;;KK;;;	JR	NZ,MGCL20	;側偔側偭偨丠
;;;KK;;;;
;;;KK;;;	LD	HL,ITEMB	;傾僀僥儉榞偐傜徚嫀両
;;;KK;;;;
;;;KK;;;	LD	A,(HL)
;;;KK;;;	CP	PMGIC
;;;KK;;;	JR	NZ,MGCL10
;;;KK;;;	LD	(HL),$00
;;;KK;;;MGCL10
;;;KK;;;	INC	HL
;;;KK;;;	LD	A,(HL)
;;;KK;;;	CP	PMGIC
;;;KK;;;	JR	NZ,MGCL20
;;;KK;;;	LD	(HL),$00
;;;KK;;;MGCL20
;;;KK;;;	PUSH	BC
;;;KK;;;;
;;;KK;;;	LD	A,(PLCMKI)
;;;KK;;;	LD	C,A
;;;KK;;;;
;;;KK;;;	LD	HL,PWSXAD
;;;KK;;;	ADD	HL,BC
;;;KK;;;;
;;;KK;;;	LD	A,(PLXPSL)
;;;KK;;;	ADD	A,(HL)
;;;KK;;;	LD	HL,ENXPSL
;;;KK;;;	ADD	HL,DE
;;;KK;;;	LD	(HL),A
;;;KK;;;;
;;;KK;;;	LD	HL,PWSYAD
;;;KK;;;	ADD	HL,BC
;;;KK;;;;
;;;KK;;;	LD	A,(PLYPSL)
;;;KK;;;	ADD	A,(HL)
;;;KK;;;	LD	HL,ENYPSL
;;;KK;;;	ADD	HL,DE
;;;KK;;;	LD	(HL),A
;;;KK;;;;
;;;KK;;;	LD	A,(PLZPSL)
;;;KK;;;	LD	HL,ENZPSL
;;;KK;;;	ADD	HL,DE
;;;KK;;;	LD	(HL),A
;;;KK;;;;
;;;KK;;;	LD	HL,ENTIM0
;;;KK;;;	ADD	HL,DE
;;;KK;;;	LD	(HL),$17
;;;KK;;;;
;;;KK;;;	POP	BC
;;;KK;;;	RET
;===========================================
;
;################################################################
;#	儕儞僋偑僕儍儞僾偡傞					#
;################################################################
PLDSJX
	DB	$1C,$E4,$00,$00	;僟僢僔儏僕儍儞僾僗僺乕僪
PLDSJY
	DB	$00,$00,$E4,$1C
;
JUMPST
	LD	A,(WHASGFG)
	CP	$07
	RET	Z
;
	LD	A,(PLJPFG)
	AND	A
	RET	NZ
;
	LD	A,$1
	LD	(PLJPFG),A
;
	XOR	A
	LD	(PLJCPT),A
	LD	(PLJCCT),A
;
	LD	A,$0D
	LD	(SOUND1),A	;(S)
;
	LD	A,(YKFLAG)
	AND	A
	JR	Z,JS0010
;
	CALL	JS0010
	LD	A,(KEYA1)
	AND	$03
	LD	A,$EA
	JR	Z,YJS010
	LD	A,$E8
YJS010
	LD	(PLYSPD),A
;
	XOR	A
	LD	(PLZSPD),A
;
	CALL	MVCALC
	LD	A,$02
	CALL	PBSET
	CALL	PLBGCK
;
	RET
JS0010
	LD	A,$20
	LD	(PLZSPD),A
;
	LD	A,(DUSHFG)
	AND	A
	RET	Z
;
	LD	A,(PLCMKI)
	LD	E,A
	LD	D,B
	LD	HL,PLDSJX
	ADD	HL,DE
	LD	A,(HL)
	LD	(PLXSPD),A
;	
	LD	HL,PLDSJY
	ADD	HL,DE
	LD	A,(HL)
	LD	(PLYSPD),A
JPS010
	RET
;=====================================================
KENSDD	;寱怳傝僒僂儞僪 儔儞僟儉 僙僢僩両
	DB	$02,$14,$15,$18
;
PCUTST
	LD	A,(CARITM)
	LD	HL,SPCTTM
	OR	(HL)
	RET	NZ
;
	LD	A,$03  ;(PCTTMD)
	LD	(PCUTTM),A
;
	LD	A,$01
	LD	(PCUTFG),A
	LD	(KENTAT),A
;
	XOR	A
	LD	(PCUTOF),A	; Oshippanashi reset
	LD	(KENOFF),A
;
	CALL	RNDSUB
	AND	$03
	LD	E,A
	LD	D,$00
	LD	HL,KENSDD
	ADD	HL,DE
	LD	A,(HL)
	LD	(SOUND3),A	;(S)
;
	CALL	PLCMST
;
	LD	A,(PLJPFG)
	AND	A
	JR	NZ,PCUT10
;
	CALL	DUSHCL
	CALL	PLSDCL
PCUT10
	LD	A,(BUMEFG)
	AND	A
	RET	NZ
;
	LD	A,(HARTFUL)
	AND	A
	RET	Z
;
	LD	A,(KENLEV)
	CP	$02
	RET	NZ
;
	LD	A,KENBM
	CALL	PLSHST	
;
	XOR	A
	LD	(POWDRTM),A
	RET
;=====================================================
;=================================
PLCMST
	LD	A,(KEYA1)
	AND	$0F
	LD	E,A
	LD	D,$00
;
	LD	HL,PLCMDT
	ADD	HL,DE
	LD	A,(HL)
	CP	$0F
	JR	Z,PCSST00
;
	LD	(PLCMKI),A
PCSST00
	RET
;=======================================
;============================================
;=					    =
;============================================
KNBGXD
	DB	$16,$FA,$08,$08	; For normal cut
;;;		  0   1   2   3   4   5   6   7
	DB	$16,$16,$08,$FA,$FA,$FA,$08,$16	; For spin cut !
KNBGYD
	DB	$08,$08,$FA,$16
	DB	$08,$16,$16,$16,$08,$FA,$FA,$FA
;
KNBGCK
	CALL	KNBGCKL
	LD	A,$02
	JP	PBSET
;=====================================
KNBGCKL
	LD	A,(KNBGTM)
	AND	A
	RET	NZ
;
	LD	A,(DUSHFG)
	AND	A
	JR	NZ,KBCKF0
;
	LD	A,(WCUTFG)
	CP	$4+1
	RET	Z   ;JR	Z,PCED10	; ken kamae ?
;
KBCKF0
	LD	A,(SPCTTM)
	AND	A
	JR	Z,KBCK02	; spin cut ?
;				; yes !
	LD	A,(PKENPT)
	ADD	A,$4
	JR	KBCK03
KBCK02
	LD	A,(PLCMKI)
KBCK03
	LD	E,A
	LD	D,$00
;
	LD	HL,KNBGXD
	ADD	HL,DE
	LD	A,(PLXPSL)
	ADD	A,(HL)
	SUB	$08
	AND	$F0
	LD	(OBJXP),A
;
	SWAP	A
	LD	C,A
;
	LD	HL,KNBGYD
	ADD	HL,DE
	LD	A,(PLYPSL)
	ADD	A,(HL)
	SUB	$10
	AND	$F0
	LD	(OBJYP),A
;
	OR	C
	LD	E,A
	LD	HL,BGUNDT+$11
	ADD	HL,DE
	LD	A,H
	CP	$D7
	RET	NZ
	PUSH	DE
	LD	A,(HL)
	LD	(UNITNO),A
	LD	E,A
	LD	A,(DJFLAG)
	LD	D,A
	CALL	BGCRRD
	POP	DE
	CP	$D0
	JP	C,KBGFL10
	CP	$D3+1
	JP	C,KBGFLS
;
KBGFL10
	CP	$90
	JP	NC,KBGFLS
	CP	$01
	JP	Z,KBGFLS	;偐偨偄偲偙偱壩壴偑弌傞両
;
	LD	C,$00
;
	LD	A,(DJFLAG)
	AND	A
	LD	A,(UNITNO)
	JR	Z,KBCK033
	CP	DSKEB
	JR	Z,KBCK05
	RET
;
KBCK033
	INC	C
	CP	ANFLW
	JR	Z,KBCK05
	CP	FLW00
	JR	Z,KBCK05
	CP	KUSA2
	RET	NZ
;
	LD	C,$FF
KBCK05
	LD	A,C
	LD	(ENCHPT2),A	; Kusa or ishi !!
;
	CALL	BG1CHG
;
	LD	A,(DUSHFG)
	AND	A
	JR	NZ,KBCK08
;
	LD	A,(WCUTFG)
	CP	$4+1
	JR	NZ,KBCK08
;
	XOR	A
	LD	(SPCTWT),A	; Spin cut wait time reset
;
	LD	A,CARITMD
KBCK06
	LD	(CARITM),A
KBCK08
;-- Kusa break --
	LD	A,KTOBJ
	CALL	PLSHST
	JR	C,KBCK80
;
	XOR	A
	LD	(POWDRTM),A	
;
	LD	HL,ENXPSL
	ADD	HL,DE
	LD	A,(OBJXP)
	ADD	A,$8
	LD	(HL),A
;
	LD	HL,ENYPSL
	ADD	HL,DE
	LD	A,(OBJYP)
	ADD	A,$10
	LD	(HL),A
;
	LD	HL,ENCHPT
	ADD	HL,DE
	LD	A,(ENCHPT2)
	LD	(HL),A ;$01  ;A
;
	PUSH	DE
	POP	BC
	CALL	KTFLSTL	
KBCK80
	CALL	RNDSUB
	AND	$07
	RET	NZ
;
	LD	A,(UNITNO)
	CP	ANFLW
	RET	Z
;
	CALL	RNDSUB
	RRA
	LD	A,RUPY1
	JR	NC,KBCK88
	LD	A,HART1
KBCK88
	CALL	ENIDSHL  ;PLSHST
	RET	C
;
	LD	HL,ENXPSL
	ADD	HL,DE
	LD	A,(OBJXP)
	ADD	A,$8
	LD	(HL),A
;
	LD	HL,ENYPSL
	ADD	HL,DE
	LD	A,(OBJYP)
	ADD	A,$10
	LD	(HL),A
;
	LD	HL,ENTIM3
	ADD	HL,DE
	LD	(HL),$80 ;A
;
	LD	HL,ENTIM1
	ADD	HL,DE
	LD	(HL),$18  ;A
;
	LD	HL,ENZSPD
	ADD	HL,DE
	LD	(HL),$10
;
KBCK90
	RET
;
;================================
;----------------------------------------
PKFLXD
	DB	$12,$EE,$FC,$04
PKFLYD
	DB	$04,$04,$EE,$12
;---------------------------------
KBGFLS
	LD	C,A
;
	LD	A,(CARITM)
	AND	A
	RET	Z
;
	LD	A,(PLCMKI)
	LD	E,A
	LD	D,$00
	LD	HL,PKFLXD
	ADD	HL,DE
	LD	A,(PLXPSL)
	ADD	A,(HL)
	LD	(WORK0),A
	LD	HL,PKFLYD
	ADD	HL,DE
	LD	A,(PLYPSL)
	ADD	A,(HL)
	LD	(WORK1),A
;
	LD	A,$4
	LD	(OTOFLG),A
;
	CALL	FLASHST
;
	LD	A,$10
	LD	(KNBGTM),A	; Protect !!
;
	LD	A,C
	AND	$F0
	CP	$90
	JR	Z,KBFS08
;
	LD	A,$07
	LD	(SOUND1),A	;(S)
KBFS10
	RET
KBFS08
	LD	A,$17
	LD	(SOUND3),A	;(S)
	RET
;============================================
;=					    =
;============================================
DUSXSD
	DB	$20,$E0,$00,$00
DUSYSD
	DB	$00,$00,$E0,$20
;- - - - - - - - - - - - - - - - - 
DUSHST
	LD	A,(YKFLAG)
	AND	A
	JR	Z,DUSS08	
;
	LD	A,(PLSTAT)
	AND	A
	RET	NZ
;
	LD	A,(PLCMKI)
	AND	%00000010
	RET	NZ
;
DUSS08
	LD	A,(DUSHFG)
	AND	A
	RET	NZ
;
	LD	A,(PLZPSL)
	LD	HL,PLJPFG
	OR	(HL)
	RET	NZ
;
	LD	A,(PLWKCT)
	ADD	A,$2
	LD	(PLWKCT),A	; Move count clear !
;
	CALL	DSSDST
;
	LD	A,(DUSHCT)
	INC	A
	LD	(DUSHCT),A
	CP	$20
	RET	NZ
;
	LD	(DUSHFG),A
;
	XOR	A
	LD	(SPCTTM),A
	LD	(SPCTWT),A
;
	LD	A,(PLCMKI)
	LD	E,A
	LD	D,$0
	LD	HL,DUSXSD
	ADD	HL,DE
	LD	A,(HL)
	LD	(PLXSPD),A
;
	LD	HL,DUSYSD
	ADD	HL,DE
	LD	A,(HL)
	LD	(PLYSPD),A
;
	XOR	A
	LD	(KENOFF),A
DUSS10
	RET
;----------------------
DSSDST
	LD	A,(FRCNT)
	AND	$07
	LD	HL,PLZPSL
	OR	(HL)
	LD	HL,PLSTOP
	OR	(HL) ;AND	A
	LD	HL,PLJPFG
	OR	(HL) ;AND	A
	RET	NZ
;
	LD	A,(PLXPSL)
	LD	(WORK0),A
;
	LD	A,(FTBGNO)
	CP	$05
	JR	Z,DSSS20	
;
	LD	A,$07
	LD	(SOUND3),A	;(S)
;
	LD	A,(PLYPSL)
	ADD	A,$06
	LD	(WORK1),A
;
	LD	A,DSZN
	JP  	EXIDSH
;
DSSS20
	LD	A,(PLYPSL)
	LD	(WORK1),A
;
	LD	A,$0E
	LD	(SOUND1),A	;(S)
;
	LD	A,WTUP2
	JP  	EXIDSH
;------------------------
PLSDCL
	XOR	A
	LD	(PLXSPD),A
	LD	(PLYSPD),A
	RET
;===================================
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;%	Sword C set				 %
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;
PLWPCS
	CALL	PLCTBC	; Center BG check (Sadow etc set)
;
PLWPCS2
	LD	A,(PLMODE)
	CP	PSWIM
	RET	Z
;
	LD	A,(WCUTFG)
	AND	A
	JR	Z,PWPC90
;
	LD	BC,OAM+$10
;
	LD	A,(PLYPS2)
	LD	HL,PLDSYD
	ADD	A,(HL)
	LD	(WORK0),A
	LD	A,(PLXPSL)
	LD	(WORK1),A
;
	LD	HL,WORK3
	LD	(HL),$00
;
	LD	A,(SPCTWT)
	CP	$28
	JR	C,PWPC8A	; Spin cut chance ?
;				; yes !
	LD	A,(FRCNT)
	RLA
	RLA
	AND	%00010000
	LD	(HL),A
PWPC8A
	LD	A,(PKENYD)
	LD	H,A
	LD	A,(PKENXD)
	LD	L,A
;
	LD	A,(PKENPT)
	LD	(WORK2),A
;
	LD	A,(PLYPSL)
	CP	$88
	RET	NC
;
	JP	KNCSET
PWPC90
	LD	A,(POWDRTM)
	PUSH	AF
	BIT	7,A
	JP	Z,PWPC92	; Rot ?
;				; yes !
	LD	A,$02
	CALL	PBSET
	CALL	PLROTCS
;
	LD	A,(POWDRTM)
	AND	$7F
	CP	$0C
	JR	NZ,PWPC92
;
	LD	HL,MSGEFG
	LD	A,(SCRLFG)
	OR	(HL)
	JR	NZ,PWPC92
;
	CALL	PLCMST	;PLCMKI set
;
	LD	A,PRTBM
	CALL	PLSHST
	JR	C,PWPC92
;
	LD	A,$0D
	LD	(SOUND3),A	;(S)
;
	LD	A,$02
	CALL	PBSET
	CALL	PRTBMSTS
PWPC92
	POP	AF
	LD	(POWDRTM),A	
	RET
;
;--------------------------------------------------------
;							 |
;	俲俶俠俽俤俿	丟丂寱 僉儍儔僙僢僩		 |
;							 |
;	Input						 |
;	BC   :Set OAM start addres			 |
;	WORK0:Main X pos				 |
;	WORK1:Main Y pos				 |
;	H    :Y add value				 |
;	L    :X add value				 |
;	WORK2:Ken. paturn 0-7				 |
;							 |
;--------------------------------------------------------
KNCSET
		LD	A,$20
		LD	($2100),A
		CALL	KNCSET_SUB
		LD	A,(PBANK)
		LD	($2100),A
		RET
;
;;;CGB;;;KNCSCD
;;;CGB;;;	DB	$08,$06	;0
;;;CGB;;;	DB	$0C,$0A	;1
;;;CGB;;;	DB	$FF,$04	;2
;;;CGB;;;	DB	$0A,$0C	;3
;;;CGB;;;	DB	$06,$08	;4
;;;CGB;;;	DB	$0A,$0C	;5
;;;CGB;;;	DB	$FF,$04	;6
;;;CGB;;;	DB	$0C,$0A	;7
;;;CGB;;;KNCSAD
;;;CGB;;;	DB	$20,$20	;0
;;;CGB;;;	DB	$60,$60	;1
;;;CGB;;;	DB	$00,$00	;2
;;;CGB;;;	DB	$40,$40	;3
;;;CGB;;;	DB	$00,$00	;4
;;;CGB;;;	DB	$00,$00	;5
;;;CGB;;;	DB	$40,$40	;6
;;;CGB;;;	DB	$20,$20	;7
;;;CGB;;;;===========================================
;;;CGB;;;KNCSET
;;;CGB;;;	PUSH	HL
;;;CGB;;;;
;;;CGB;;;	LD	A,(WORK0)
;;;CGB;;;	ADD	A,H
;;;CGB;;;	LD	(BC),A		; Y left
;;;CGB;;;	INC	BC
;;;CGB;;;	LD	A,(WORK1)
;;;CGB;;;	ADD	A,L
;;;CGB;;;	LD	(BC),A		; X left
;;;CGB;;;	INC	BC
;;;CGB;;;;
;;;CGB;;;	LD	HL,KNCSCD
;;;CGB;;;	LD	A,(WORK2)
;;;CGB;;;	SLA	A
;;;CGB;;;	LD	E,A
;;;CGB;;;	LD	D,$0
;;;CGB;;;	ADD	HL,DE
;;;CGB;;;	LD	A,(HL)
;;;CGB;;;	LD	(BC),A		; Chr left
;;;CGB;;;	CP	$FF
;;;CGB;;;	JR	NZ,KNC010	; Not chr ?
;;;CGB;;;;				; yes ! clear
;;;CGB;;;	DEC	BC
;;;CGB;;;	LD	A,$F0
;;;CGB;;;	LD	(BC),A
;;;CGB;;;	INC	BC
;;;CGB;;;KNC010
;;;CGB;;;	INC	BC
;;;CGB;;;	LD	HL,KNCSAD
;;;CGB;;;	ADD	HL,DE
;;;CGB;;;	LD	A,(HL)
;;;CGB;;;	LD	HL,WORK3	; Color
;;;CGB;;;	OR	(HL)
;;;CGB;;;	LD	(BC),A		; Atr left
;;;CGB;;;	INC	BC
;;;CGB;;;;
;;;CGB;;;	POP	HL
;;;CGB;;;;
;;;CGB;;;	LD	A,(WORK0)
;;;CGB;;;	ADD	A,H
;;;CGB;;;	LD	(BC),A		; Y pos right
;;;CGB;;;	INC	BC
;;;CGB;;;	LD	A,(WORK1)
;;;CGB;;;	ADD	A,L
;;;CGB;;;	ADD	A,$08
;;;CGB;;;	LD	(BC),A		; X pos right
;;;CGB;;;	INC	BC
;;;CGB;;;;
;;;CGB;;;	LD	HL,KNCSCD+1
;;;CGB;;;	ADD	HL,DE
;;;CGB;;;	LD	A,(HL)
;;;CGB;;;	LD	(BC),A		; Chr right
;;;CGB;;;	INC	BC
;;;CGB;;;	LD	HL,KNCSAD+1
;;;CGB;;;	ADD	HL,DE
;;;CGB;;;	LD	A,(HL)
;;;CGB;;;	LD	HL,WORK3	; Color
;;;CGB;;;	OR	(HL)
;;;CGB;;;	LD	(BC),A		; Atr right
;;;CGB;;;	RET
;
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;%	Item cros check size set	%
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
TLCRST
		LD	A,$20
		LD	($2100),A
		CALL	TLCRST_SUB
		LD	A,(PBANK)
		LD	($2100),A
		RET
;
;;;;;;;;TLCRXD
;;;;;;;;	DB	$10,$F0,$08,$08
;;;;;;;;TLCRYD
;;;;;;;;	DB	$0C,$0C,$F0,$10
;;;;;;;;;- - - - - - - - - - - - - - - - - - - - - -
;;;;;;;;TLCRST
;;;;;;;;	LD	A,(PLCMKI)
;;;;;;;;	LD	E,A
;;;;;;;;	LD	D,$0
;;;;;;;;;
;;;;;;;;	LD	HL,TLCRXD
;;;;;;;;	ADD	HL,DE
;;;;;;;;	LD	A,(PLXPSL)
;;;;;;;;	ADD	A,(HL)
;;;;;;;;	LD	(TLCRXL),A
;;;;;;;;;
;;;;;;;;	LD	HL,TLCRYD
;;;;;;;;	ADD	HL,DE
;;;;;;;;	LD	A,(PLYPSL)
;;;;;;;;	ADD	A,(HL)
;;;;;;;;	LD	(TLCRYL),A
;;;;;;;;;
;;;;;;;;	LD	A,$02
;;;;;;;;	LD	(TLCRTM),A
;;;;;;;;	RET
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;%	Player in door & window close		 %
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
PLINDR1
	CALL	PLIDBC
;
	LD	A,(PIMODE)
	AND	A
	JR	Z,PIDR0A0
;
	XOR	A
	LD	(PIMODE),A
;
	JP	NXGOTO
PIDR0A0
	CALL	FDIN
;
	XOR	A
	LD	(TILTCT),A
;
	INC	A
	LD	(ENSTFG),A
;
	LD	A,(SBHR)
	CP	$4
	JP	NZ,PLID1F0
;
	XOR	A
	LD	(SCCH),A
	LD	(SCCV),A
	LD	(DJMSTM),A	;僟儞僕儑儞埬撪儊僢僙乕僕両
;
	LD	E,ENNO
	LD	HL,ENMODE	;揋慡晹僋儕傾乕
PID1020
	LD	(HLI),A
	DEC	E
	JR	NZ,PID1020
;
	LD	A,(SHOHFG)
	AND	A
	JR	Z,PID009	; Shop manbiki ?
;			; yes !
	PUSH	AF
;
	LD	A,$4
	CALL	PBSET
;
	POP	AF
	CALL	SHOPGET	; Seiko
;
	LD	HL,MANBICT
	INC	(HL)
	LD	HL,MANBIKI
	INC	(HL)
;
	LD	A,$01
	LD	(MANBIKIF),A
	XOR	A
	LD	(PLCHPT),A
PID009
	LD	A,(YKFLAG)
	LD	(WORKD),A
;
	LD	A,GPLAY  ;INIT
	LD	(GMMODE),A
;
	XOR	A
	LD	(ITMODE),A
	LD	(FADEON),A
;
	LD	(YKFLAG),A
;- - - - - - - - - - - - - - - - -
	LD	HL,NXRMMD
	LD	A,(DJFLAG)
	LD	(WORKF),A
	AND	A
	JR	NZ,PID00C	; Many door ?
;
	LD	HL,DRPSBF
;
	LD	C,$00
SSS3
	LD	A,(PLXPSL)
	SWAP	A
	AND	$0F
	LD	E,A
	LD	A,(PLYPSL)
	SUB	$08
	AND	$F0
	OR	E
	CP	(HL)
	JR	Z,SSSW
;
	INC	HL
	INC	C
	LD	A,C
	CP	$04
	JR	NZ,SSS3
;
SSSW
	LD	A,C
	SLA	A
	SLA	A
	ADD	A,C	;*5
	LD	E,A
	LD	D,$00
;
	LD	HL,NXRMMD
	ADD	HL,DE		; Yes !
;
PID00C
	PUSH	HL
;
	LD	A,(HLI)
	LD	(DJFLAG),A
	CP	$02
	JR	NZ,PID010
;
	LD	(YKFLAG),A
	DEC	A	;(A)
	LD	(DJFLAG),A
;
	LD	A,$01
	LD	(PLSTAT),A	;僴僔僑搊傝両
PID010
	LD	A,(HLI)
	LD	(DNJNNO),A
;
	LD	A,(DJFLAG)
	AND	A
	LD	A,(HLI)
	LD	(GRNDPT),A
	JR	NZ,PLID180
;
	LD	A,(WORKF)
	AND	A
	JR	Z,PID012	;僟儞僕儑儞偐傜抧忋丠
;				;YES !
	XOR	A
	LD	(POWRFG),A
PID012
	JR	PLID1A0
;-----------------------------
PLID180
	LD	C,A
;
	LD	A,$14
	CALL	PBSET
;
	PUSH	HL
;
	LD	A,(DNJNNO)
	SWAP	A
	LD	E,A
	LD	D,$00
	SLA	E
	RL	D
	SLA	E
	RL	D
	LD	HL,DJRMDT
	ADD	HL,DE
;
		LD	A,(DNJNNO)
		CP	NEWDJ		;怴僟儞僕儑儞僫儞僶乕丠
		JR	NZ,PLID180_PASS	;	NO --> PLID180_PASS
		LD	HL,NEWDJDAT
		JR	DICK10
PLID180_PASS
;
;;;KK;;;	LD	A,(DNJNNO)
	CP	$06
	JR	NZ,DICK10	;儗儀儖俈丠
;				;YES!
	LD	A,(WARPSV+$06)
	AND	%00000100
	JR	Z,DICK10	;偼偟傜棊偪偨丠
;
	LD	HL,D7DAT2	;YES !
DICK10
	LD	E,$00
PLID188
	LD	A,(HLI)
	CP	C
	JR	Z,PLID190
	INC	E
	LD	A,E
	CP	$40
	JR	NZ,PLID188
PLID190
	LD	A,E
	LD	(DNJNPT),A
;
	LD	A,(WORKF)
	AND	A
	JR	NZ,PLID19F	;抧忋偐傜僟儞僕儑儞丠
;				;YES !
	XOR	A
	LD	(POWRFG),A
;
	LD	A,(DNJNNO)
	CP	DJMAX
	JR	NC,PLID19F
;
	LD	A,$02
	CALL	PBSET
	CALL	DJMPST	;儅僢僾僶僢僼傾乕僙僢僩
;
	LD	A,$30
	LD	(DJMSTM),A	;僟儞僕儑儞埬撪儊僢僙乕僕僙僢僩両
;
	XOR	A
	LD	(ONOFFG),A
	LD	(ONOFTM),A	; On off block time reset !
PLID19F
	POP	HL
PLID1A0
	LD	A,(HLI)
	LD	(WPLXPSL),A
	LD	A,(HL)
	LD	(WPLYPSL),A
;
	POP	HL
;
	LD	A,(YKFLAG)
	AND	A
	JR	NZ,PLID1F00
	LD	A,(WORKD)
	AND	A
	JR	NZ,PLID1F0	; Yoko gamen not save !
;
	LD	A,(DJFLAG)
	AND	A
	JR	Z,DID010
;				;YES !
	LD	A,(DNJNNO)
;
		CP	NEWDJ		;怴僟儞僕儑儞丠
		JR	NZ,PLID_PASS	;	NO --> PLID_PASS
		LD	HL,WPDJPT2
		JR	PLID_SET
PLID_PASS
;
	CP	DJMAX
	JR	NC,DID010	;寛摤僟儞僕儑儞丠
;				;YES !
	LD	E,A	;擖傝岥両
	SLA	A
	SLA	A
	ADD	A,E
	LD	E,A
	LD	D,$00
	LD	HL,WPDJPT
	ADD	HL,DE
;
PLID_SET
	LD	A,$14
	LD	($2100),A
;
	CALL	DID010
;
	PUSH	DE
	LD	A,(DNJNNO)
;
		CP	NEWDJ		;怴僟儞僕儑儞丠
		JR	NZ,PLID1_PASS	;	NO --> PLID1_PASS
		LD	A,$3A
		JR	PLID1_SET
PLID1_PASS
;
	LD	E,A
	LD	D,$00
	LD	HL,WPDJPTN	;擖傝岥僟儞僕儑儞億僀儞僩両
	ADD	HL,DE
	LD	A,(HL)
PLID1_SET
	POP	DE
	LD	(DE),A	;DNJNPT
	RET
;-------------------------------------
DID010
	LD	A,$00
;
	LD	(WORK0),A
	LD	DE,CONTBF	; Continue start pos save buffer
PID00D
	LD	A,(HLI)
	LD	(DE),A
	INC	DE
	LD	A,(WORK0)
	INC	A
	LD	(WORK0),A
	CP	$05
	JR	NZ,PID00D
;
	LD	A,(DNJNPT)
	LD	(DE),A
PLID1F0
	RET
PLID1F00
	XOR	A
	LD	(PLCMKI),A
	RET
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;%				         %
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
PLINDR2
	CALL	PLIDBC
;
	LD	A,(OKWARPF)
	AND	A
	JR	Z,PLID210
;
	XOR	A
	LD	(OKWARPF),A
;
	LD	A,$30
	LD	(WAVTIM),A
	LD	A,$03
	LD	(WAVFLG),A
;
	LD	A,$04
	LD	(SBHR),A
	JR	PLID220
;
PLID210
	CALL	FDOUT
;
	LD	A,(SBHR)
	CP	$04
	JR	NZ,PLID290
;
PLID220
	LD	A,(WPLMODE)
	CP	PSWIM
	JR	Z,PLID221
;
	LD	A,PMOVE
PLID221
	LD	(PLMODE),A
;
	LD	A,(MANBIKIF)
	AND	A
	JR	Z,PLID270
;
	XOR	A
	LD	(MANBIKIF),A
;
	LD	A,$36
	CALL	MSGCHK
PLID270
PLID290
	RET
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;%	"FDIN"偵側偭偰傞偗偳僼僃乕僪傾僂僩	%
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FDIN
		LD	A,$20
		LD	($2100),A
		CALL	WhiteOut
		LD	A,(PBANK)
		LD	($2100),A
;
	LD	HL,SBCNT
	INC	(HL)
;;;CGB;;;	LD	A,(SBCNT)
	LD	A,(HL)
	AND	$03
	JR	NZ,N3
;
	LD	HL,SBHR
	LD	A,(HL)
	CP	$04
	JR	Z,PIDEND2
	INC	(HL)
;
	XOR	A
	LD	(WORK0),A
SNUTS	
	LD	A,(WORK0)
	CP	$03
	JR	Z,N3		
;
	LD	HL,BGPFG
	LD	E,A
	LD	D,$0
	ADD	HL,DE
	LD	A,(HL)
	LD	C,A
	LD	B,$0
LOPN
	LD	A,C
	AND	$03
	JR	Z,N2
	DEC	C
N2
	RRC	C
	RRC	C
	INC	B
	LD	A,B
	CP	$04
	JR	NZ,LOPN
;
	LD	A,C
	LD	(HL),A
;
	LD	HL,WORK0
	INC	(HL)
	JR	SNUTS
;
N3
PIDEND
PIDEND2
	RET
;====================================================
SBHRDT
	DB	%00000000
	DB	%00000001
	DB	%00000010
	DB	%00000011
;
	DB	%00000000
	DB	%00000011
	DB	%00000001
	DB	%00000000
;
	DB	%00000000
	DB	%00000001
	DB	%00000010
	DB	%00000011
;------------------------------------------
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;%	"FDOUT"偵側偭偰傞偗偳僼僃乕僪僀儞	%
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FDOUT
		LD	A,$20
		LD	($2100),A
		CALL	WhiteIn
		LD	A,(PBANK)
		LD	($2100),A
;
	LD	HL,SBCNT
	INC	(HL)
	LD	A,(SBCNT)
	AND	$03
	JR	NZ,N23
;
	LD	HL,SBHR
	LD	A,(HL)
	INC	(HL)
	CP	$04
;;;CGB;;;	JR	Z,PIDEND
	JR	Z,N23
;
	XOR	A
	LD	(WORK0),A
SNUTS2	
	LD	A,(WORK0)
	CP	$03
	JR	Z,N23		
;
	LD	HL,BGPFG
	LD	E,A
	LD	D,$0
	ADD	HL,DE
	LD	A,(HL)
	PUSH	HL
	LD	C,A
	LD	B,$0
LOPN2
	LD	A,(WORK0)
	SLA	A
	SLA	A
	OR	B
	LD	E,A
	LD	HL,SBHRDT
	ADD	HL,DE
	LD	A,C
	AND	$03
	CP	(HL)    ;$03
	JR	Z,N22
	INC	C
N22
	RRC	C
	RRC	C
	INC	B
	LD	A,B
	CP	$04
	JR	NZ,LOPN2
;
	LD	A,C
	POP	HL
	LD	(HL),A
;
	LD	HL,WORK0
	INC	(HL)
	JR	SNUTS2
N23
	RET
;--------------------------------
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;%	Player charactert tr. 			 %
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;(CGB);=============================================
;(CGB)PLCHNO	; Character data !!
;(CGB);		; L   R
;(CGB)	DB	$00,$02	;0
;(CGB)	DB	$02,$00	;1
;(CGB)	DB	$10,$02	;2
;(CGB)	DB	$12,$00	;3
;(CGB)	DB	$04,$06	;4
;(CGB)	DB	$06,$04	;5
;(CGB)	DB	$08,$0A	;6
;(CGB)	DB	$0C,$0E	;7
;(CGB)	DB	$18,$0A	;8
;(CGB)	DB	$1C,$0E	;9
;(CGB)	DB	$0A,$08	;A
;(CGB)	DB	$0E,$0C	;B
;(CGB)	DB	$0A,$18	;C
;(CGB)	DB	$0E,$1C	;D
;(CGB);
;(CGB)	DB	$20,$22	;E
;(CGB)	DB	$24,$26	;F
;(CGB)	DB	$28,$2A	;10
;(CGB)	DB	$2A,$28	;1
;(CGB)	DB	$30,$32	;2
;(CGB)	DB	$20,$22	;3
;(CGB)	DB	$34,$36	;4
;(CGB)	DB	$24,$26	;5
;(CGB)	DB	$38,$3A	;6
;(CGB)	DB	$28,$2A	;7
;(CGB)	DB	$3A,$38	;8
;(CGB)	DB	$2A,$28	;9
;(CGB)	DB	$40,$40	;A
;(CGB)	DB	$42,$42	;B
;(CGB)	DB	$44,$46	;C
;(CGB)	DB	$48,$4A	;D
;(CGB)	DB	$4C,$4E	;E
;(CGB)	DB	$50,$52	;F
;(CGB)	DB	$4E,$4C	;20
;(CGB)	DB	$52,$50	;21
;(CGB);-
;(CGB)	DB	$80,$02	;22
;(CGB)	DB	$82,$00	;23
;(CGB)	DB	$84,$86	;24
;(CGB)	DB	$88,$8A	;25
;(CGB)	DB	$8C,$8E	;26
;(CGB)	DB	$90,$92	;27
;(CGB)	DB	$94,$96	;28
;(CGB)	DB	$98,$9A	;29
;(CGB)	DB	$9C,$9E	;2A
;(CGB)	DB	$9A,$A2	;2B
;(CGB)	DB	$A4,$08	;2C
;(CGB)	DB	$A6,$0C	;2D
;(CGB)	DB	$A8,$AA	;2E
;(CGB)	DB	$AC,$AE	;2F
;(CGB)	DB	$B0,$B2	;30
;(CGB)	DB	$B4,$B6	;31
;(CGB)	DB	$B0,$B2	;32
;(CGB)	DB	$B4,$B6	;33
;(CGB)	DB	$04,$C0	;34
;(CGB)	DB	$06,$C2	;35
;(CGB);
;(CGB)	DB	$5A,$58	;36
;(CGB)	DB	$5E,$5C	;37
;(CGB)	DB	$58,$5A	;38
;(CGB)	DB	$5C,$5E	;39
;(CGB)	DB	$44,$46	;3A
;(CGB)	DB	$6E,$6E	;3B
;(CGB)	DB	$40,$40	;3C
;(CGB)	DB	$56,$56	;3D
;(CGB);
;(CGB)	DB	$7A,$78	;3E
;(CGB)	DB	$7E,$7C	;3F
;(CGB)	DB	$78,$7A	;40
;(CGB)	DB	$7C,$7E	;41
;(CGB)	DB	$74,$76	;42
;(CGB)	DB	$76,$74	;43
;(CGB)	DB	$70,$72	;44
;(CGB)	DB	$72,$70	;45
;(CGB);
;(CGB)	DB	$CA,$C8	;46
;(CGB)	DB	$D6,$D4	;47
;(CGB)	DB	$C8,$CA	;48
;(CGB)	DB	$D4,$D6	;49
;(CGB)	DB	$CC,$CE	;4A
;(CGB)	DB	$D8,$DA	;4B
;(CGB)	DB	$C4,$C4	;4C
;(CGB)	DB	$C6,$C6	;4D
;(CGB)	DB	$DC,$DC	;4E ;愽傝侾
;(CGB)	DB	$DE,$DE	;4F ;愽傝俀
;(CGB);- Kurukuru door - -
;(CGB)	DB	$EA,$EC ;50
;(CGB)	DB	$EE,$F0 ;51
;(CGB)	DB	$F2,$F4 ;52
;(CGB)	DB	$F6,$F6 ;53
;(CGB)	DB	$F8,$FA ;54
;(CGB);- -Fall down --
;(CGB)	DB	$E0,$E2	;55
;(CGB)	DB	$E4,$E6	;56
;(CGB)	DB	$E8,$E8	;57
;(CGB);- Yoko swim --
;(CGB)	DB	$10,$12	;58
;(CGB)	DB	$14,$16	;59
;(CGB)	DB	$18,$1C	;5A
;(CGB)	DB	$12,$10	;5B
;(CGB)	DB	$16,$14	;5C
;(CGB)	DB	$1C,$18	;5D
;(CGB);- -Kaiten jump - -
;(CGB)	DB	$66,$68 ;5E
;(CGB)	DB	$6A,$6C ;5F
;(CGB)	DB	$68,$66 ;60
;(CGB)	DB	$68,$66 ;61
;(CGB)	DB	$6C,$6A ;62
;(CGB)	DB	$66,$68 ;63
;(CGB)	DB	$60,$60 ;64
;(CGB)	DB	$62,$62 ;65
;(CGB)	DB	$64,$64 ;66
;(CGB)	DB	$62,$62 ;67
;(CGB)	DB	$64,$64 ;68
;(CGB)	DB	$60,$60 ;69
;(CGB);- Fail - -
;(CGB)	DB	$54,$54 ;6A
;(CGB);- Ken power up demo - -
;(CGB)	DB	$3C,$3E ;6B
;(CGB);- Item chach ---
;(CGB)	DB	$FE,$FE ;6C
;(CGB);- Ana hori ---
;(CGB)	DB	$18,$1A	;6D	
;(CGB)	DB	$1C,$1E	;6E	
;(CGB)	DB	$2C,$2E	;6F	
;(CGB)	DB	$B8,$BA	;70	
;(CGB)	DB	$2E,$2C	;71	
;(CGB)	DB	$BA,$B8	;72	
;(CGB)	DB	$BC,$BE	;73	
;(CGB)	DB	$D0,$D2	;74	
;(CGB);- -僆僇儕僫 傆偒
;(CGB)	DB	$A0,$FC	;75
;(CGB)	DB	$FC,$A0	;76
;(CGB);=====================================
;(CGB)PLFLPD	; Flip data
;(CGB)	DB	$00,$00	;0
;(CGB)	DB	$20,$20	;1
;(CGB)	DB	$00,$00	;2
;(CGB)	DB	$00,$20	;3
;(CGB)	DB	$00,$00	;4
;(CGB)	DB	$20,$20	;5
;(CGB)	DB	$00,$00	;6
;(CGB)	DB	$00,$00	;7
;(CGB)	DB	$00,$00	;8
;(CGB)	DB	$00,$00	;9
;(CGB)	DB	$20,$20	;A
;(CGB)	DB	$20,$20	;B
;(CGB)	DB	$20,$20	;C
;(CGB)	DB	$20,$20	;D
;(CGB);
;(CGB)	DB	$00,$00	;E
;(CGB)	DB	$00,$00 ;F
;(CGB)	DB	$00,$00	;10
;(CGB)	DB	$20,$20	;11
;(CGB)	DB	$00,$00	;12
;(CGB)	DB	$00,$00	;13
;(CGB)	DB	$00,$00	;14
;(CGB)	DB	$00,$00	;15
;(CGB)	DB	$00,$00	;16
;(CGB)	DB	$00,$00	;17
;(CGB)	DB	$20,$20	;18
;(CGB)	DB	$20,$20	;19
;(CGB)	DB	$00,$20	;1A
;(CGB)	DB	$00,$20	;1B
;(CGB)	DB	$00,$00	;1C
;(CGB)	DB	$00,$00	;1D
;(CGB)	DB	$00,$00	;1E
;(CGB)	DB	$00,$00	;1F
;(CGB)	DB	$20,$20	;20
;(CGB)	DB	$20,$20	;21
;(CGB);
;(CGB)	DB	$00,$00	;22
;(CGB)	DB	$00,$20	;23
;(CGB)	DB	$00,$00	;24
;(CGB)	DB	$00,$00	;25
;(CGB)	DB	$00,$00	;26
;(CGB)	DB	$00,$00	;27
;(CGB)	DB	$00,$00	;28
;(CGB)	DB	$00,$00	;29
;(CGB)	DB	$00,$00	;2A
;(CGB)	DB	$20,$00	;2B
;(CGB)	DB	$00,$20	;2C
;(CGB)	DB	$00,$20	;2D
;(CGB)	DB	$00,$00	;2E
;(CGB)	DB	$00,$00	;2F
;(CGB)	DB	$00,$00	;30
;(CGB)	DB	$00,$00	;31
;(CGB)	DB	$00,$00	;32
;(CGB)	DB	$00,$00	;33
;(CGB)	DB	$00,$00	;34
;(CGB)	DB	$20,$00	;35
;(CGB);
;(CGB)	DB	$20,$20	;36
;(CGB)	DB	$20,$20	;37
;(CGB)	DB	$00,$00	;38
;(CGB)	DB	$00,$00	;39
;(CGB)	DB	$00,$00	;3A
;(CGB)	DB	$00,$20	;3B
;(CGB)	DB	$00,$20	;3C
;(CGB)	DB	$00,$20	;3D
;(CGB);
;(CGB)	DB	$20,$20	;3E
;(CGB)	DB	$20,$20	;3F
;(CGB)	DB	$00,$00	;40
;(CGB)	DB	$00,$00	;41
;(CGB)	DB	$00,$00	;42
;(CGB)	DB	$20,$20	;43
;(CGB)	DB	$00,$00	;44
;(CGB)	DB	$20,$20	;45
;(CGB);
;(CGB)	DB	$20,$20	;46
;(CGB)	DB	$20,$20	;47
;(CGB)	DB	$00,$00	;48
;(CGB)	DB	$00,$00	;49
;(CGB)	DB	$00,$00	;4A
;(CGB)	DB	$00,$00	;4B
;(CGB)	DB	$00,$20	;4C
;(CGB)	DB	$00,$20	;4D
;(CGB)	DB	$00,$20	;4E
;(CGB)	DB	$00,$20	;4F
;(CGB);- - Kuru kuru door - -
;(CGB)	DB	$00,$00	;50
;(CGB)	DB	$00,$00	;51
;(CGB)	DB	$00,$00	;52
;(CGB)	DB	$00,$20	;53
;(CGB)	DB	$00,$00	;54
;(CGB);- -Fall down --
;(CGB)	DB	$00,$00	;55
;(CGB)	DB	$00,$00	;56
;(CGB)	DB	$00,$20	;57
;(CGB);- -Yoko swim --
;(CGB)	DB	$00,$00	;58
;(CGB)	DB	$00,$00	;59
;(CGB)	DB	$00,$00	;5A
;(CGB)	DB	$20,$20	;5B
;(CGB)	DB	$20,$20	;5C
;(CGB)	DB	$20,$20	;5D
;(CGB);- -Kaiten jump - -
;(CGB)	DB	$00,$00 ;5E
;(CGB)	DB	$00,$00 ;5F
;(CGB)	DB	$60,$60 ;60
;(CGB)	DB	$20,$20 ;61
;(CGB)	DB	$20,$20 ;62
;(CGB)	DB	$40,$40 ;63
;(CGB)	DB	$00,$20 ;64
;(CGB)	DB	$00,$20 ;65
;(CGB)	DB	$00,$20 ;66
;(CGB)	DB	$40,$60 ;67
;(CGB)	DB	$40,$60 ;68
;(CGB)	DB	$40,$60 ;69
;(CGB);- Fail - -
;(CGB)	DB	$00,$20 ;6A
;(CGB);- Ken power up demo - -
;(CGB)	DB	$00,$00 ;6B
;(CGB);- Item chach ---
;(CGB)	DB	$00,$20 ;6C
;(CGB);- Ana hori ---
;(CGB)	DB	$00,$00	;6D	
;(CGB)	DB	$00,$00	;6E	
;(CGB)	DB	$00,$00	;6F	
;(CGB)	DB	$00,$00	;70	
;(CGB)	DB	$20,$20	;71	
;(CGB)	DB	$20,$20	;72	
;(CGB)	DB	$00,$00	;73	
;(CGB)	DB	$00,$00	;74	
;(CGB);- - Okarina - -
;(CGB)	DB	$00,$00	;75
;(CGB)	DB	$20,$20	;76
;------------------------------------------
;- Character paturn set ---
PLPTST
	LD	A,(PLWKCT)
	SRA	A
	SRA	A
	SRA	A
	AND	$1
	LD	D,A
	LD	A,(PLCMKI)
	SLA	A
	OR	D
	LD	C,A
	LD	B,$0
;
	LD	HL,PLCHSW
	LD	A,(PLMODE)
	CP	PSWIM		;儕儞僋塲偖丠
	JR	NZ,PLMAF0	;	NO --> PLMAF0
;
	LD	A,(PLSTAT)
	AND	A
	JR	Z,PLMAE8
;
	LD	HL,PLCHDB
PLMAE8
	JR	PLMA10
;--------------------------------
PLMAF0
	LD	A,(YKFLAG)
	AND	A		;墶夋柺丠
	JR	Z,PLMAF1	;	NO --> PLMAF1
;
	LD	A,(PLSTAT)
	CP	$02
	JR	NZ,PLMAF1
;
	LD	HL,PLCHYSW
	JR	PLMA10
PLMAF1
	LD	A,(PLCAMD)
	CP	$1
	JR	Z,PLMA0C
;
	LD	A,(IKADAON)
	AND	A		;僀僇僟偵忔偭偰傞丠
	JR	NZ,PLMAF2	;	YES --> PLMAF2
;
	LD	A,(PLOSHI)
	AND	A		;墴偟億乕僘丠
	JR	NZ,PLMA08	;	YES --> PLMA08
;
PLMAF2
	LD	A,(TATEFG)
	AND	A		;弬峔偊丠
	JR	NZ,PLMA00	;	YES --> PLMA00
;
	LD	HL,PLCHPD
	JR	PLMA10
PLMA00
	LD	HL,PLCHP2
	CP	$2
	JR	NZ,PLMA02	;Big tate ?
;				;yes !
	LD	HL,PLCHP3
PLMA02
	LD	A,(TATEON)
	AND	A
	JR	Z,PLMA03	; Tate using ?
;				; yes !
	LD	A,L
	ADD	A,$8
	LD	L,A
;
	LD	A,H
	ADC	A,$0
	LD	H,A
PLMA03
	JR	PLMA10
PLMA08
	LD	HL,PLCHPO
	JR	PLMA10
PLMA0C
	LD	HL,PLCHPC
PLMA10
	ADD	HL,BC
	LD	A,(HL)
	LD	(PLCHPT),A
	RET
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;%				      %
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;-----------------------------------------------
LOVETR
	LD	A,(VRAMD+1)
	AND	A
	RET	NZ
;
	LD	A,$10
	CALL	Char_bank_set	; (CGB) 僉儍儔僋僞乕僶儞僋僙僢僩
	LD	($2100),A
;
	LD	HL,CHRDAT+$2500
	LD	DE,CHRRAM+$1500
;
	LD	A,(FRCNT)
	AND	%00001111
	JR	Z,LVTR10	
	CP	$08
	RET	NZ
;
	LD	L,$40
	LD	E,L
LVTR10
	LD	A,(FRCNT)
	AND	%00110000
	LD	C,A
	LD	B,$0
	SLA	C
	RL	B
	SLA	C
	RL	B
	SLA	C
	RL	B
;
	ADD	HL,BC
;
	LD	BC,$0040
	JP	DATA_MOV

ROUSAD
TAKIAD
	DB	$20,$60,$A0,$E0
	DB	$E0,$E0,$A0,$60
;
PLCHTR
	LD	A,(GMMODE)
	CP	LOVED
	JR	Z,LOVETR
	CP	OPING
	JR	NZ,PT8000	; Opening Demo?
;
	LD	A,(VRAMD+1)
	AND	A
	JP	NZ,PT7000
;
	LD	A,(FRCNT)
	AND	$0F
	CP	$04
	JR	C,PT7000
;
	LD	A,$10
	CALL	Char_bank_set	; (CGB) 僉儍儔僋僞乕僶儞僋僙僢僩
	LD	($2100),A
;
	LD	A,(NMCH0L)
	LD	L,A
	LD	A,(NMCH0H)
	LD	H,A
	LD	A,(NMCH1L)
	LD	E,A
	LD	A,(NMCH1H)
	LD	D,A
;
	LD	BC,$0020
	CALL	DATA_MOV
PT7000
	RET
;
PT8000
	LD	A,(GMMODE)
	CP	ENDG
	JR	NZ,PCTR558
;
	LD	A,(CHTRF2)
	AND	A
	JR	NZ,PCTR561
;
	RET
PCTR558
	CP	GPLAY
	JP	C,PLCSNOT
;
	LD	A,(WNDYPS)
	CP	$80
	JP	NZ,PLCSNOT
;
	LD	A,(WNDFLG)
	AND	A
	JP	NZ,PLTRNOT
;
	LD	HL,SCRLFG
	LD	A,(VRAMD+1)
	OR	(HL)
	JP	NZ,PLTRNOT  ;088 ;30
;
	LD	A,(ONOFTM)
	AND	A
	JR	Z,PCTR560	; 墯撌僽儘僢僋嶌摦 ?
;				; Yes !
	CALL	ONOFSUB
	JP	PCTR30
;
PCTR560
	LD	A,(CHTRF2)
	AND	A
	JR	Z,PCTR088
;
PCTR561
	CP	$01 ;F0
	JP	Z,BDCHT1	; 戝捁偺恖娫僉儍儔僋僞乕揮憲!
	CP	$02 ;F1
	JP	Z,BDCHT2
	CP	$03 ;F2
	JP	Z,SWCHTR1	; 忔傞僗僀僢僠 ON !
	CP	$04 ;F3
	JP	Z,SWCHTR2	;      "       RETURN !
	CP	$08
	JP	Z,EGAKKIRV 	;F ;僄儞僨傿儞僌妝婍傕偳偡揮憲
	CP	$09
	JP	Z,GRKEY5TR	; Key "E" colect !!
	CP	$0A
	JP	Z,KINOKOTR	; 偒偺偙 !!
	CP	$0B
	JP	Z,MGPWDRTR	; 杺朄偺暡
	CP	$0C
	JP	Z,EGAKKITR 	;F ;僄儞僨傿儞僌妝婍揮憲
	CP	$0D
	JP	Z,MEGANETR	; 傢傜偟傋傾僀僥儉両
	CP	$0E
	JR	Z,YMCLERS	;僄儞僨傿儞僌嶳徚偡両
	CP	$0F
	JP	Z,MARINTR1
	CP	$10
	JP	Z,MARINTR2
;
	JP	PCTR30
;
YMCLERS
	LD	A,$17
	LD	($2100),A
	JP	YMCLER
;================================
PCTR088
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;%   偄傠偄傠 僉儍儔僋僞乕揮憲		 %
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
CHRTR
;===========================================
CTR010
	LD	A,(CHTRCT)
	INC	A
	LD	(CHTRCT),A	; Timing counter !
;=================================================
CHRTRSB
	LD	A,(CHTRFG)
	RST	0
	DW	PLTROK 	;0
	DW	MESTEST	;1 Message TEST No. display !
	DW	GRSER2	;2 ;抧忋 攇偓傢
	DW	GRSER1	;3 ;抧忋 戧亄怺悈亄愺悈
	DW	DJTOUR	;4 ;僟儞僕儑儞 摃楿亄儘僂僜僋亄恓
	DW	YKTOUR	;5 ;墶夋柺梡
	DW	BSYOUG	;6 ;梟娾儃僗
	DW	BELTTR	;7 ;儀儖僩僐儞儀傾乕亄儘僂僜僋
	DW	RYUSATR	;8 ;棳嵒
	DW	JYANTR	;9 ;僕儍儞僌儖 悈棳
	DW	JYANTR2	;A ;僕儍儞僌儖 悈棳亄戧
	DW	YAMASEA	;B ;嶳 墦宨悈
	DW	DMIZUTR	;C ;僟儞僕儑儞悈
	DW	GAGETR	;D ;寱俀傕傜偆晹壆
	DW	HIMITR 	;E ;昘
	DW	YYOGTR 	;F ;墶梟娾両
	DW	KAZATR 	;10 ;晽尒捁!
;-----------------------------------------------------
;-----------------------------------------------------
MESTEST
	LD	A,(CHTRCT)
	AND	$07
	JP	NZ,PLTROK
;
	LD	A,$01
	LD	($2100),A
	CALL	MSGTEST
	LD	A,$0C
	CALL	Char_bank_set	; (CGB) 僉儍儔僋僞乕僶儞僋僙僢僩
	LD	($2100),A
	JP	PLTRNOT
;=======================================
CH4TR1
	LD	L,A
	JR	CH4TR
;-----------------------------------------------------
GRSER2
	LD	H,$6B
	JR	CHTRF
;-----------------------------------------------------
GRSER1
	LD	H,$6C
	JR	CHTRF
;=====================================
DMIZUTR
	LD	H,$73
	JR	CHTRF
;=====================================
YAMASEA
	LD	H,$6A
CHTRF
	LD	A,(CHTRCT)
	AND	$0F
	JP	NZ,PLTROK
;
	CALL	CC2INC
;
	JP	CH4TR1
;-----------------------------------------------------
DTTRTRD
	DB	$00,$40,$80,$C0
	DB	$C0,$C0,$80,$40
;
DJTOUR
	LD	A,(CHTRCT)
	AND	$07
	JP	NZ,PLTROK
;
	LD	A,(CHTRCT)
	RRA
	RRA
	RRA
	AND	$07
	LD	E,A
	LD	D,$00
	LD	HL,DTTRTRD
	ADD	HL,DE
;
	LD	L,(HL)
	LD	H,$6D
;- - - - - - - - - - - - - -
CH4TR
	LD	DE,CHRRAM+$16C0
CH4TR2
	LD	BC,$0040
	CALL	DATA_MOV
;
		LD	A,(DNJNNO)
		CP	NEWDJ		;怴僟儞僕儑儞丠
		JR	NZ,DJTOUR_PASS	;	NO --> DJTOUR_PASS
		LD	A,$20
		LD	($2100),A
		LD	B,$001
		CALL	NEWDJ_CHR
		JR	Z,DJTOUR_100
		LD	($2100),A
		CALL	DATA_MOV
DJTOUR_100
		LD	A,$20
		LD	($2100),A
		LD	B,$000
		CALL	NEWDJ_CHR
		JR	Z,DJTOUR_PASS
		LD	($2100),A
		LD	DE,CHRRAM+$16C0
		CALL	DATA_MOV
DJTOUR_PASS
;
	JP	PLTRNOT
;=====================================
YKTOUR
	LD	H,$6E
	JR	CHTRF
;=====================================
BSYOUG
	LD	A,(CHTRCT)
	AND	$07
	JP	NZ,PLTROK
;
	LD	A,(CHTRCT)
	RRA
	RRA
	RRA
	AND	$07
	LD	E,A
	LD	D,$00
	LD	HL,DTTRTRD
	ADD	HL,DE
;
	LD	L,(HL)
	LD	H,$6F
	JP	CH4TR
;=====================================
BELTTR
		LD	HL,BELTBF
		LD	A,(DNJNNO)
		CP	NEWDJ		;怴僟儞僕儑儞丠
		JR	NZ,BELTTR_PASS	;	NO --> BELTTR_PASS
		LD	DE,$8400	; 僉儍儔僋僞 俼俙俵
		JP	CH4TR2
BELTTR_PASS
;
	LD	A,(CHTRCT)
	INC	A
	AND	$03
	JP	NZ,DJTOUR
;
	LD	DE,$90C0	; 僉儍儔僋僞 俼俙俵 ($8000 - $97FF)
	JP	CH4TR2
;
;-----------------------------------------------------
;===================================
RYUSATR
	LD	H,$70
;
CHTR7
	LD	A,(CHTRCT)
	AND	$07
	JP	NZ,PLTROK
;
	CALL	CC2INC
;
	JP	CH4TR1
;===================================
JYANTR
	LD	H,$71
CHTR3
	LD	A,(CHTRCT)
	AND	$03
	JP	NZ,PLTROK
;
	CALL	CC2INC
;
	JP	CH4TR1
;===================================
JYANTR2
	LD	H,$72
	JR	CHTR3
;=====================================
CC2INC
	LD	A,(CHTRC2)	; A bus adress chenge !
	ADD	A,$40
	LD	(CHTRC2),A
	RET	
;=====================================
GAGETR
	LD	H,$75
	JR	CHTR3
;=====================================
YYOGTR
	LD	H,$74
	JR	CHTR7
;=====================================
KAZATR
	LD	H,$77
	JR	CHTR7
;=====================================
HIMITR
	LD	H,$76
	JR	CHTR7
;-----------------------------------------------------
PCTR09

;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
;x	 僾儗僀儎乕僉儍儔僋僞乕倁俼俙俵揮憲				x
;x----------------------------------------------------------------------x
;x	    俤俶俿俼倄							x
;x		俛         丗 僨乕僞傾僪儗僗 俫俬俧俫乮揮憲尦乯		x
;x		俠         丗 僨乕僞傾僪儗僗 俴俷倂  乮  乭  乯		x
;x		俢         丗 揮憲屄悢					x
;x		俫         丗 倁俼俙俵傾僪儗僗 俫俬俧俫乮揮憲愭乯	x
;x		俴         丗 倁俼俙俵傾僪儗僗 俴俷倂  乮  乭  乯	x
;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
PLCHR_TRAN
		LD	A,$0C
		CALL	Char_bank_set	; (CGB) 僉儍儔僋僞乕僶儞僋僙僢僩
		LD	($2100),A
PLCHR_TRAN_100	
		LD	A,(BC)
		INC	BC
		LD	(HLI),A
		DEC	D
		JR	NZ,PLCHR_TRAN_100

		LD	A,:PLTROK_SUB
		LD	($2100),A
		RET

;================================================
;=	僾儗僀儎乕僉儍儔僋僞乕揮憲		=
;================================================
PLTROK
;- - Player Character TR. - -

		LD	A,:PLTROK_SUB
		LD	($2100),A
		CALL	PLTROK_SUB
		LD	A,$0C
		CALL	Char_bank_set	; (CGB) 僉儍儔僋僞乕僶儞僋僙僢僩
		LD	($2100),A

;(CGB);- - Left - -
;(CGB)	LD	A,(PLCHPT)
;(CGB)	CP	$FF
;(CGB)	JP	Z,PCTR30
;(CGB);
;(CGB)	LD	HL,PLCHNO
;(CGB)	SLA	A
;(CGB)	LD	C,A
;(CGB)	LD	B,$0
;(CGB)	ADD	HL,BC
;(CGB)	LD	E,(HL)
;(CGB);
;(CGB)	PUSH	HL
;(CGB);
;(CGB)	LD	HL,PLFLPD
;(CGB)	ADD	HL,BC
;(CGB)	LD	A,(PLFLPL)
;(CGB);;;CGB;;;	AND	%10011111
;(CGB)	AND	%10011000
;(CGB)	OR	(HL)
;(CGB)	LD	(PLFLPL),A
;(CGB);
;(CGB)	INC	HL
;(CGB);
;(CGB)	LD	A,(PLFLPR)
;(CGB);;;CGB;;;	AND	%10011111
;(CGB)	AND	%10011000
;(CGB)	OR	(HL)
;(CGB)	LD	(PLFLPR),A
;(CGB);
;(CGB)	LD	D,$0
;(CGB)	SLA	E
;(CGB)	RL	D
;(CGB)	SLA	E
;(CGB)	RL	D
;(CGB)	SLA	E
;(CGB)	RL	D
;(CGB)	SLA	E
;(CGB)	RL	D
;(CGB)	LD	HL,PLCHDT
;(CGB)	ADD	HL,DE
;(CGB)	PUSH	HL
;(CGB)	POP	BC
;(CGB);
;(CGB)	LD	HL,$8000
;(CGB);
;(CGB)	LD	D,$20
;(CGB)PCTR10
;(CGB)	LD	A,(BC)
;(CGB)	INC	BC
;(CGB)	LD	(HLI),A
;(CGB)	DEC	D
;(CGB)	JR	NZ,PCTR10
;(CGB);- - Right - -
;(CGB)	POP	HL
;(CGB)	INC	HL
;(CGB)	LD	E,(HL)
;(CGB);
;(CGB)	LD	D,$0
;(CGB)	SLA	E
;(CGB)	RL	D
;(CGB)	SLA	E
;(CGB)	RL	D
;(CGB)	SLA	E
;(CGB)	RL	D
;(CGB)	SLA	E
;(CGB)	RL	D
;(CGB)	LD	HL,PLCHDT
;(CGB)	ADD	HL,DE
;(CGB)	PUSH	HL
;(CGB)	POP	BC
;(CGB);
;(CGB)	LD	HL,$8020
;(CGB);
;(CGB)	LD	D,$20
;(CGB)PCTR20
;(CGB)	LD	A,(BC)
;(CGB)	INC	BC
;(CGB)	LD	(HLI),A
;(CGB)	DEC	D
;(CGB)	JR	NZ,PCTR20

PCTR30
PLTRNOT
;
;****************************************
;*       PLAYER	Character OAM set       *
;****************************************
PLCSET
	LD	A,(PLCHPT)
	INC	A
	JP	Z,PLCS70
;
		LD	A,(CGBFLG)
		AND	A
		JR	Z,PLCSET_100
		LD	A,(PLFLSH)
		AND	$04
		JR	Z,PLCSET_300
		LD	A,$04
		JR	PLCSET_300
;
PLCSET_100
		LD	A,(PLFLSH)
		RLA
		RLA
		AND	$10
PLCSET_300
		LD	(PLPRIO),A
;
;- LEFT -
	LD	HL,POAM
;
	LD	A,(PLDSYD)
	LD	C,A
;
	LD	A,(PLYPS2)
	ADD	A,C
	CP	$88
	JR	NC,PLCS70
	PUSH	AF
	LD	(HLI),A		; YPOS
;
	LD	A,(PLDSXD)
	LD	C,A
;
	LD	A,(PLXPSL)
	ADD	A,C
	LD	(HLI),A		; XPOS
;
	LD	A,$00
	LD	(HLI),A		; CHR NO.
;
	LD	A,(PLPRIO)
	LD	D,A
	LD	A,(PLFLPL)
	OR	D
;;;KK;;;	LD	(HLI),A		; ATR.
	LD	(HL),A		; ATR.
;
		LD	A,(CLOTHFG)
		AND	A
		JR	Z,PLCSET_400
		OR	%00000010
		OR	(HL)
		LD	(HL),A
PLCSET_400
		LD	A,(PLCHPT)	;儕儞僋愽悈偟偰傞丠
		CP	$04E		;	YES --> PLCSET_450
		JR	Z,PLCSET_450	;	NO ---> PLCSET_500
		CP	$04F		;
		JR	NZ,PLCSET_500	;
PLCSET_450
		LD	(HL),$003
PLCSET_500
		INC	HL
;
;- - - RIGHT - -
	POP 	AF
	LD	(HLI),A		; YPOS
;
	LD	A,(PLXPSL)
	ADD	A,C
	ADD	A,$08  ;10
	LD	(HLI),A		; XPOS
;
	LD	A,$02
	LD	(HLI),A		; CHR NO.
;
	LD	A,(PLPRIO)
	LD	D,A
	LD	A,(PLFLPR)
	OR	D
;;;KK;;;	LD	(HLI),A		; ATR.
	LD	(HL),A		; ATR.
;
		LD	A,(CLOTHFG)
		AND	A
		JR	Z,PLCSET_800
		OR	%00000010
		OR	(HL)
		LD	(HL),A
PLCSET_800
		LD	A,(PLCHPT)	;儕儞僋愽悈偟偰傞丠
		CP	$04E		;	YES --> PLCSET_850
		JR	Z,PLCSET_850	;	NO ---> PLCSET_900
		CP	$04F		;
		JR	NZ,PLCSET_900	;
PLCSET_850
		LD	(HL),$023
PLCSET_900
		INC	HL
;
PLCS70
PLCSNOT
	RET
;
;======================================================
MARINTR2
	LD	HL,CHRDAT+$0F00       
	LD	A,$0E
	JR	MARINTRS
;======================================================
MARINTR1
	LD	A,$12
	LD	HL,CHRDAT+$2080       
MARINTRS
	LD	($2100),A
	LD	DE,CHRRAM+$0400
	LD	BC,$0040
	JP	DTMOVS
;======================================================
; 傢傜偟傋傾僀僥儉梡
;======================================================
MEGANETR
	LD	A,(MEGAF)
	CP	$02
	JP	C,DTMOVS2 ;PLCSNOTS	;0:側偟 1:儓僢僔乕(偼偠傔偐傜帩偭偰傞両乯
;
	SUB	$02
	LD	D,A
	LD	E,$00
;
	SRA	D
	RR	E	
	SRA	D
	RR	E	
;
	LD	HL,CHRDAT+$0400
	ADD	HL,DE
	LD	DE,CHRRAM+$09A0
	LD	BC,$0040
;
	LD	A,$0C
	LD	($2100),A
;
	JP	DTMOVS
;======================================================
; 杺朄偺暡偑偒偺偙偵曄傢傞彂偒姺偊
;======================================================
KINOKOTR
	LD	HL,CHRDAT+$28C0	; 
;
	LD	DE,CHRRAM+$08E0
	JR	IRANSUB
;======================================================
;       OBJ 妝婍 彂偒姺偊			      :
;======================================================
EGAKKITR
	LD	A,$11
	LD	($2100),A
;
	LD	A,(EDWRK0)
	SWAP	A
	AND	$F0
	LD	E,A
	LD	D,$00
	SLA	E
	RL	D
	SLA	E
	RL	D
;
	LD	HL,CHRRAM+$0D00
	ADD	HL,DE
	PUSH	HL
;
	LD	HL,CHRDAT+$1000
EGAKSUB
	ADD	HL,DE
	POP	DE

	LD	BC,$0040
	CALL	DATA_MOV
;
	XOR	A
	LD	(CHTRF2),A
;
	LD	A,$0C
	LD	($2100),A
	RET
;
;======================================================
;       OBJ 妝婍 彂偒姺偊			      :
;======================================================
EGAKKIRV
	LD	A,$13
	LD	($2100),A
;
	LD	A,(EDWRK0)
	SWAP	A
	AND	$F0
	LD	E,A
	LD	D,$00
	SLA	E
	RL	D
	SLA	E
	RL	D
;
	LD	HL,CHRRAM+$0D00
	ADD	HL,DE
	PUSH	HL
;
	LD	HL,CHRDAT+$0D00
	JR	EGAKSUB
;
;======================================================
; 偒偺偙偑杺朄偺暡偵曄傢傞彂偒姺偊
;======================================================
MGPWDRTR
	LD	HL,CHRDAT+$08E0	; 
;
	LD	DE,CHRRAM+$08E0
;
	LD	A,$0C
	LD	($2100),A
;
	LD	BC,$0020
	JP	DTMOVS
;======================================================
; 尞俆斣傪傕傜偆偨傔偵廤傔傞傗偮偑尞俆斣偵彂偒姺偊
;======================================================
GRKEY5TR
	LD	HL,CHRDAT+$28E0	; Kagi E
	LD	DE,CHRRAM+$0CA0
;
IRANSUB
	LD	A,$0C
	LD	($2100),A
;
	LD	BC,$0020
	JP	DTMOVS
;======================================================
; 忔傞僗僀僢僠彂偒姺偊
;======================================================
SWCHTR1		; ON !
	LD	HL,CHRDAT+$3F00
	LD	A,$12
	JR	SWTR10
SWCHTR2		; Return !
	LD	HL,CHRDAT+$0C40
	LD	A,$0D
SWTR10
	CALL	Char_bank_set	; (CGB) 僉儍儔僋僞乕僶儞僋僙僢僩
	LD	($2100),A
;
	LD	DE,CHRRAM+$1140
;
	JP	CHR4TR
;======================================================
ONOFA11
ONOFA21
	DW	$6840
	DW	$6840
ONOFA12
	DW	$6800
ONOFA22
	DW	$6880
	DW	$6800
;- - - - - - - - - - - - - - - - - - - - - -
;	悈徎僗僀僢僠 僽儘僢僋墯撌
;- - - - - - - - - - - - - - - - - - - - - -
ONOFSUB		; On off block character chenge !
;(CGB)	LD	HL,$2100
;(CGB)	LD	(HL),$0C
		PUSH	AF
		LD	A,$0C
		CALL	Char_bank_set	; (CGB) 僉儍儔僋僞乕僶儞僋僙僢僩
		LD	($2100),A
		POP	AF
;
	LD	HL,PLSTOP
	LD	(HL),$01
;
	LD	HL,ONOFFG
	LD	E,(HL)
	LD	D,$00
;
	INC	A
	CP	$03
	JR	NZ,ONOFS10
;
	PUSH	AF
	LD	A,(ONOFFG)
	XOR	%00000010
	LD	(ONOFFG),A
	POP	AF
;
ONOFS10
	LD	(ONOFTM),A
;
	CP	$04
	JR	NZ,ONOFS20
;
	LD	HL,ONOFA11
	JR	OFSUB1
ONOFS20
	CP	$08
	JR	NZ,ONOFS30
;
	LD	HL,ONOFA12
OFSUB1
	ADD	HL,DE
	LD	DE,$9040
;
	JR	OFSUB3
;
ONOFS30
	CP	$06
	JR	NZ,ONOFS40
;
	LD	HL,ONOFA21
	JR	OFSUB2
ONOFS40
	CP	$0A
	JR	NZ,ONOFS50
;
	XOR	A
	LD	(ONOFTM),A
;
	LD	HL,ONOFA22
OFSUB2
	ADD	HL,DE
	LD	DE,$9080
OFSUB3
	LD	BC,$0040
	LD	A,(HLI)
	LD	H,(HL)
	LD	L,A
	JP  	DATA_MOV
ONOFS50
	JP	PLCSET
;
;======================================================
CHR4TR
	LD	BC,$0040
DTMOVS
	CALL	DATA_MOV
;
DTMOVS2
	XOR	A
	LD	(CHTRF2),A
;
	LD	A,$0C
	LD	($2100),A
;
	JP	PLCSET
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;%	1 Unit BG chenge  		     %
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
BGCAXD
	DB	$0C,$03,$08,$08
BGCAYD
	DB	$0A,$0A,$05,$10
PLHKC0
	DB	$36,$38,$3A,$3C
PLHKCK
	DB	%00000010
	DB	%00000001
	DB	%00001000
	DB	%00000100
PLHKXD
	DB	$FC,$04,0,0
PLHKYD
	DB	$00,$00,$04,$00
;----------------------------------
BGCACH
	CALL	BGCACHS
;
	LD	A,$02
	JP	PBSET
;
BGCACHS
	LD	HL,DUSHFG
	LD	A,(PLCAMD)
	OR	(HL)
	LD	HL,PLZPSL
	OR	(HL)
	LD	HL,PLMODE
	OR	(HL)
	JP	NZ,UNCG90
;
	LD	A,(PLCMKI)
	LD	E,A
	LD	D,$00
;
	LD	HL,BGCAXD
	ADD	HL,DE
	LD	A,(PLXPSL)
	ADD	A,(HL)
	SUB	$08
	AND	$F0
	LD	(OBJXP),A
;
	SWAP	A
	LD	C,A
;
	LD	HL,BGCAYD
	ADD	HL,DE
	LD	A,(PLYPSL)
	ADD	A,(HL)
	SUB	$10
	AND	$F0
	LD	(OBJYP),A
;
	OR	C
	LD	E,A
	LD	(WORK1),A
	LD	HL,BGUNDT+$11
	ADD	HL,DE
	LD	A,H
	CP	$D7
	JP	NZ,PLHK20
	LD	A,(HL)
	LD	(WORK0),A
	LD	E,A
;
	LD	A,(DJFLAG)
	LD	D,A
;
	CALL	BGCRRD
	LD	(WORK5),A
;
	LD	A,(WORK0)
	CP	DHTN1		; 僞儞僗丠
	JR	Z,PLHK211
;
	LD	A,(WORK5) ;HL)
	CP	$00  
	JP	Z,PLHK20	; door etc
	CP	$01
	JR	Z,PLHK11
	CP	$50
	JP	Z,PLHK20
	CP	$51
	JP	Z,PLHK20
	CP	$10+1  ;GAK2D+1
	JP	C,PLHK20	; Tobiori
	CP	$D3+1
	JP	NC,PLHK20
	CP	$D0
	JR	NC,PLHK11
	CP	$7C
	JP	NC,PLHK20
;
PLHK11
	LD	A,(WORK0)
	LD	E,A
	CP	FUKRO		; 傆偔傠偆憸
	JR	Z,PLHK211T
	CP	KAZA1		; 晽尒捁両
	JR	Z,PLHK211T
	CP	KNBAN		; 娕斅丠
	JP	NZ,PLHK222
;
PLHK211T
	LD	A,(DJFLAG)
	AND	A
	LD	A,E
	JP	NZ,PLHK222
;
PLHK211
	LD	E,A
	LD	A,(PLCMKI)
	CP	02
	JP	NZ,UNR510
;
	LD	A,$02
	LD	(MSCRFG),A	; Not item set !
;
	LD	A,(KEYA2)
	AND	%00110000
	JP	Z,UNR510
;
	LD	A,E
	CP	KAZA1
	LD	A,$8E
	JR	Z,PLHK2321
	LD	A,E
	CP	FUKRO
	JR	Z,PLHK212	;
	CP	KNBAN
	JR	Z,PLHK212	;僞儞僗 儊僢僙乕僕 ?
;				; YES !
	LD	A,(MARINFG)
	AND	A
	JR	Z,PLTANS
;
	LD	A,$78
	CALL	MSGCH3
	JP	UNR510
;
PLTANS
	LD	A,(KENLEV)
	AND	A
	LD	A,(GRNDPT)
	JR	NZ,PLHK216
;
	LD	E,$FF	;偰偄両偦傫側偙偲丄偳偙偱偍傏偊偨丠
;
	CP	$A3	;僞儕儞偺壠丠
	JR	Z,PLHK2322
PLHK216
	LD	E,$FC	
	CP	$FA	;恾彂娰丠
	JR	Z,PLHK2322	
;
	LD	E,$FD	;偁偁偁偁偁偼丄僞儞僗傪偟傜傋偨丄丄丄
PLHK2322
	LD	A,E
	JR	PLHK232
PLHK212
	LD	A,(GRNDPT)
	LD	E,A
	LD	D,$00
	LD	A,$14 ;$01
	LD	($2100),A
	LD	HL,KNBNMSD
	ADD	HL,DE
	LD	A,(ONPUFG)
	LD	E,A
	LD	A,(HL)
	CP	$A9
	JR	NZ,PLHK123
;
	BIT	0,E
	JR	Z,PLHK123	;僇僄儖偺塖傪妎偊偨丠
;				; YES !
	LD	A,$AF
PLHK123
	CP	$AF
	JR	NZ,HKKN10	;旈枾娕斅丠
;
	BIT	0,E
	JR	NZ,HKKN10	;僇僄儖偺塖傪妎偊偨丠
;				; YES !
	LD	A,(OBJXP)
	SWAP	A
	AND	$0F
	LD	E,A
	LD	A,(OBJYP)
	AND	$F0
	OR	E				;YES !
	LD	(KHIMIFG),A	;僠僃僢僋両
	JP	UNR510
HKKN10
	CP	$83
	JR	Z,PLHK232

		CP	$2D		; 侾亅俤 傆偔傠偆丠
		JR	Z,PLHK233	; 倄俤俽
PLHK2321
	CALL	MSGCH2
	JP	UNR510
PLHK232
	CALL	MSGCHK
	JR	UNR510
PLHK233
		CALL	MSGCH3
		JR	UNR510
PLHK222
	CP	DTRE0
	JR	NZ,UNR510	; Takara box ?
;				; yes !
	LD	A,(NAZOFG)
	AND	%00011111
	CP	$0D
	JR	Z,UNR510
;
	LD	A,(PLCMKI)
	CP	$02
	JR	NZ,UNR510
;
	LD	(MSCRFG),A	; Not item set !
;
	LD	A,(KEYA2)
	AND	%00110000
	JR	Z,UNR510
;
	LD	A,(YKFLAG)
	AND	A
	JR	NZ,PLHK13
;
	LD	A,(PLCMKI)
	CP	$2
	JR	NZ,UNR510	; Ue muki ?
;
PLHK13
	LD	A,$14
	LD	($2100),A
;
		CALL	TRC_SUB
;
;;;KK;;;	LD	A,(GRNDPT)
;;;KK;;;	LD	E,A
;;;KK;;;;
;;;KK;;;	LD	A,(DJFLAG)
;;;KK;;;	LD	D,A
;;;KK;;;;
;;;KK;;;	LD	A,(DNJNNO)
;;;KK;;;	CP	DJROOM2 ;$20
;;;KK;;;	JR	NC,TRC010
;;;KK;;;	CP	DJROOM ;$20
;;;KK;;;	JR	C,TRC010
;;;KK;;;	INC	D
;;;KK;;;TRC010
;;;KK;;;	LD	HL,DJTKDT
;;;KK;;;	ADD	HL,DE
;;;KK;;;	LD	A,(HL)
;;;KK;;;	CP	KAI
;;;KK;;;	JR	NZ,TRC011
;;;KK;;;;
;;;KK;;;	LD	A,(KENLEV)
;;;KK;;;	CP	$02
;;;KK;;;	LD	A,KAI
;;;KK;;;	JR	C,TRC011	;寱俀庢偭偨傜奓妅偼偄傜傫両
;;;KK;;;;
;;;KK;;;	LD	A,C02
;;;KK;;;TRC011
;;;KK;;;	LD	(WORK8),A	; Takara No. !
;
	LD	A,$2
	LD	($2100),A
;
	CALL	TAKARST		; open set !
UNR510
	LD	A,(ITEMB)
	CP	PBULE
	JR	NZ,BCA900	; Bulesret check !
;
	LD	A,(KEYA1)
	AND	%00100000
	JR	NZ,BCA910
	RET
BCA900
	LD	A,(ITEMA)
	CP	PBULE
	JP	NZ,UNCG90
;
	LD	A,(KEYA1)
	AND	%00010000
	JP	Z,UNCG90
;
BCA910
	LD	A,$02
	LD	($2100),A
	CALL	PCUTED		; cutting clear !
;
	LD	A,$01
	LD	(PLSTOP),A
;
	LD	A,(PLCMKI)
	LD	E,A
	LD	D,$0
	LD	HL,PLHKC0
	ADD	HL,DE
	LD	A,(HL)
	LD	(PLCHPT),A
;
	LD	HL,PLHKCK
	ADD	HL,DE
	LD	A,(KEYA1)
	AND	(HL) ;C
	JR	Z,PLHK20
;
	LD	HL,PLHKXD
	ADD	HL,DE
	LD	A,(HL)
	LD	(PLDSXD),A
;
	LD	HL,PLHKYD
	ADD	HL,DE
	LD	A,(HL)
	LD	(PLDSYD),A
;
	LD	HL,PLCHPT
	INC	(HL)
;
	LD	E,$08
	LD	A,(POWRFG)
	CP	$01
	JR	NZ,PLHK09
;
	LD	E,$03
PLHK09
	LD	HL,PLHKCT
	INC	(HL)
	LD	A,(HL)
	CP	E  ;$08
	JR	C,PLHK10
;
	XOR	A
	LD	(WORKE),A
;
	LD	A,(WORK0)
	CP	STUBO
	JR	Z,PLHKTBO ;50
	CP	IWA00
	JR	Z,PLHKTBO ;50
;
	LD	A,(DJFLAG)
	AND	A
	JR	NZ,PLHK10
;
	LD	A,(WORK0)
	CP	FLW00
	JR	Z,PLHK58
PLHK10
	RET
PLHK20
	XOR	A
	LD	(PLHKCT),A
	RET
;
PLHKTBO
	CALL	PLHK50
;
	LD	A,$14
	LD	($2100),A
;
	CALL	TUBOITEM ;捹撪晹傾僀僥儉僙僢僩僠僃僢僋
;
	JP  	PBRETN
;
PLHK58
	LD	A,$01
	LD	(WORKE),A
PLHK50
	LD	A,(WORK1)
	LD	E,A
	LD	A,(WORK0)
	LD	(UNITNO),A
	CALL	BG1CHG
;
	LD	A,(PLCMKI)
	LD	(PLCAMK),A
;
	CALL	KTOSET
UNCG90
	RET
;=============================
BG1CHG
	LD	A,$14
	LD	($2100),A
;
	CALL	BG1CHGSB
;
	JP	PBRETN
;========================================
KTOSET
	LD	A,KTOBJ
	CALL	PLSHST
	JR	C,KOS090
;
	LD	A,$02
	LD	(SOUND2),A	;(S)
;
	LD	HL,ENMODE
	ADD	HL,DE
	LD	(HL),ECACH  ;A
;
	LD	HL,ENCHPT
	ADD	HL,DE
	LD	A,(WORKE)
	LD	(HL),A
;
	PUSH	DE
	POP	BC
	LD	E,$1
	LD	A,$03
	CALL	PBSET
;
	CALL	ENCAPS
KOS090
	RET
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;%	Move calc			     %
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
MVCALC
	LD	A,(WNDFLG)
	AND	A
	RET	NZ
;
	LD	C,$1
	CALL	XCALC
PLXCLC
	LD	C,$0
	LD	(WORK0),A
;-----------------------------------------
XCALC	
	LD	B,$0		;INDEX (H)
;
	LD	HL,PLXSPD
	ADD	HL,BC 
;
	LD	A,(HL)
	PUSH	AF
	SWAP	A
	AND	$F0
	LD	HL,PLXSDR
	ADD	HL,BC 
	ADD	A,(HL)
	LD	(HL),A
	RL	D
;
	LD	HL,PLXPSL
	ADD	HL,BC 
;
	POP	AF
;
	LD	E,$0
	BIT	7,A
	JR	Z,XC00
	LD	E,$F0
XC00
	SWAP	A
	AND	$0F
	OR	E
	RR	D
	ADC	A,(HL)
	LD	(HL),A
	RET
;-----------------------------------------
;-----------------------------------------
PLZCLC	
	LD	A,(PLZSPD)
	PUSH	AF
	SWAP	A
	AND	$F0
	LD	HL,PLZSDR
	ADD	A,(HL)
	LD	(HL),A
	RL	D
;
	LD	HL,PLZPSL
;
	POP	AF
;
	LD	E,$0
	BIT	7,A
	JR	Z,ZC00
	LD	E,$F0
ZC00
	SWAP	A
	AND	$0F
	OR	E
	RR	D
	ADC	A,(HL)
	LD	(HL),A
	RET
;
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;%				       %
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
MESEGE
	LD	A,(MSGEFG)
	AND	A
	RET	Z
;
	LD	E,A
;
	LD	A,(GMMODE)
	CP	ENDG
	LD	A,$7E
	JR	NZ,MJBI010
;
	LD	A,$7F
MJBI010
	LD	(ENHELP),A	;傋偨 No.
;
	LD	A,(MJSTCTH)
	AND	A
	LD	A,(MJSTCT)
	JR	NZ,MJBI18
;
	CP	$20
	JR	C,MJBI20
MJBI18
	AND	$0F
	OR	$10
MJBI20
	LD	(MJSTCT2),A
;
	LD	A,E
	AND	%01111111
	DEC	A
	RST	0
	DW	MSOKCK	; Vram check !S
;
	DW	MSVRSV2	;Vram save 1
	DW	MSVRSV2 ;2
	DW	MSVRSV2 ;3
	DW	MSMASKS ;Window BG set
;
MJSA	DW	MJBGIT
	DW	MJBGST
	DW	MJCHST
;
MSCC1	DW	MSSCR1	; Mesege scroll 1
MSCC2	DW	MSSCR2	;
MSCC3	DW	MSSCR3	;
;
MSK	DW	MSRWIT	; Return key in check (TEST)
MQE	DW	MSQUES	; Question check 
;
MBR	DW	MSRETN	;BG return
	DW	MSGEND
;
MJST	EQU	$5+1
MSSC1	EQU	$8+1
MSSC2	EQU	$9+1
MSSC3	EQU	$A+1
MSKYW	EQU	$B+1
MSQUE	EQU	$C+1
MSBGR	EQU	$D+1
;--------------------------------------------------
MSOKCK
	LD	A,$14
	LD	($2100),A
;
	JP  	MSOKCKL
;---儊僢僙乕僕僫儞僶乕偑侾侽侽傪偙偊傞応崌---------------
MSGCH2
	CALL	MSGCHK
	LD	A,$01
	LD	(MSGENOH),A
	RET
;---儊僢僙乕僕僫儞僶乕偑俀侽侽傪偙偊傞応崌---------------
MSGCH3
	CALL	MSGCHK
	LD	A,$02
	LD	(MSGENOH),A
	RET
;------------------------------------
MSGCHK
	PUSH	AF
;
	XOR	A
	LD	(MSANSR),A
;
	POP	AF
MSGCHK2
	LD	(MSGENO),A
;
	XOR	A
	LD	(MSSTCT),A
	LD	(MJSTCT),A
	LD	(MJSTCTH),A
	LD	(NMSTCT),A
	LD	(MSGENOH),A	; MSXX or M1XX
;
	LD	A,$0F
	LD	(FKMSFG),A	;榖 壒両
;
	LD	A,(PLYPSL)
	CP	$48
	RRA
	AND	%10000000
	OR	$1
	LD	(MSGEFG),A
	RET
;=====================================================
MSVRSV2
	RET	
;=====================================================
MSGEND
	XOR	A
	LD	(MSGEFG),A
;
	LD	A,$18
	LD	(MSOFTM),A	;儊僢僙乕僕楢懕杊巭僞僀儉両
	RET


;劕劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劖
;劔	zms.s 偵僾儘僌儔儉傪堏摦					 劔
;劦劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劮
;劔	偙傔傫偲丗 倁亅俛俴俙俶俲拞偺張棟偩偗偵丄侽僶儞僋埲奜偵		 劔 
;劔		   旘偽偝側偄傎偆偑偄偄偺偐側丒丒丒丒丒			 劔
;劔		   儊僢僙乕僕偑偍偐偟偔側偭偨傜丄偡偖栠偡傋偟丅		 劔
;劘劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劗
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;%	幠尨 僒僽傞偆偪傫丂俀	    %
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
MSBGAD
	DB	00,36,72
	DB	00,36,72
MSVRAH
	DB	$98,$98,$98
	DB	$99,$99,$99
MSVRAL
	DB	$21,$61,$A1
	DB	$41,$81,$C1
;--------------------------------------
MSVRSV
	LD	A,(MSGEFG)
	BIT	7,A
	JR	Z,MVS010
;
	AND	%01111111
	ADD	A,$3
MVS010
	LD	E,A
	LD	D,$0
;
	LD	HL,MSBGAD-1-1
	ADD	HL,DE
;;;;;;;;	LD	A,(HL)
;;;;;;;;	LD	C,A
;;;;;;;;	LD	B,$0
;;;;;;;;	LD	HL,MSBGBF
;;;;;;;;	ADD	HL,BC
;;;;;;;;	PUSH	HL
;;;;;;;;	POP	BC
	LD	A,(HL)		; (CGB)彂偒捈偟 
	ADD	A,<MSBGBF	;
	LD	C,A		;
	LD	A,>MSBGBF	;
	ADC	A,$0		;
	LD	B,A		;
;
	LD	HL,MSVRAL-1-1
	ADD	HL,DE
	LD	A,(SCVRML)
	ADD	A,(HL)
	LD	L,A
	LD	(WORK0),A
;
	LD	HL,MSVRAH-1-1
	ADD	HL,DE
	LD	A,(SCVRMH)
	ADD	A,(HL)
	LD	H,A
	LD	A,(WORK0)
	LD	L,A
;
	XOR	A
	LD	E,A
	LD	D,A
MSV02
	LD	A,(HL)
	LD	(BC),A

;-------------------------------------------------------------
;	傾僩儕價儏乕僩懸旔
;-------------------------------------------------------------
		LD	A,(CGBFLG)
		AND	A
		JR	Z,MSV02_100

		LD	A,$01
		LD	(VBK),A		; 倁亅俼俙俵僶儞僋乮侾乯僙僢僩
		LD	A,$02
		LD	(SVBK),A	; 俼俙俵僶儞僋乮俀乯僙僢僩
		LD	A,(HL)		; 傾僩儕價儏乕僩俧俤俿
		LD	(BC),A		; 傾僩儕價儏乕僩懸旔
		XOR	A
		LD	(VBK),A		; 倁亅俼俙俵僶儞僋乮侽乯僙僢僩
		LD	(SVBK),A	; 俼俙俵僶儞僋乮侽乯僙僢僩
MSV02_100
;-------------------------------------------------------------

	INC	BC
;
	LD	A,L
	ADD	A,$01
	AND	$1F
	JR	NZ,LSTA
;
	LD	A,L
	AND	$E0
	LD	L,A
	JR	RSTA
;
LSTA
	INC	L
RSTA
	INC	E
	LD	A,E
	CP	$12
	JR	NZ,MSV02
;
	LD	E,$00
	LD	A,(WORK0)
	ADD	A,$20
	LD	(WORK0),A
	JR	NC,HSORT
;
	INC	H
HSORT
	LD	L,A
	INC	D
	LD	A,D
	CP	$02  ;05
	JR	NZ,MSV02
;
	RET
;=====================================================
;=====================================================
;-----------------------------------------------------
;=====================================================
;劕劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劖
;劔	zms.s 偵僾儘僌儔儉傪堏摦					 劔
;劘劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劗
;(CGB)KWDTL
;(CGB)	DB	$61,$41,$81,$21,$A1	;忋偺恖
;(CGB)	DB	$81,$61,$A1,$41,$C1	;壓偺恖
;(CGB)KWDTH
;(CGB)	DB	$98,$98,$98,$98,$98	;
;(CGB)	DB	$99,$99,$99,$99,$99	;
;
MSMASKS
		LD	A,:MSMASKS_SUB
		LD	($2100),A
		JP	MSMASKS_SUB


;(CGB)	LD	A,(MSGEFG)
;(CGB)	LD	C,A
;(CGB);
;(CGB)	LD	A,(MSSTCT)
;(CGB)	CP	$05
;(CGB)	JR	Z,MSFIN
;(CGB);
;(CGB)	BIT	7,C
;(CGB)	JR	Z,MSUP
;(CGB);
;(CGB)	ADD	A,$05
;(CGB)MSUP
;(CGB)	LD	C,A
;(CGB)	LD	B,$0
;(CGB);
;(CGB)	LD	E,$01
;(CGB)	LD	D,$00
;(CGB);
;(CGB)	LD	A,(SCVRMH)
;(CGB)	LD	HL,KWDTH
;(CGB)	ADD	HL,BC
;(CGB)	ADD	A,(HL)
;(CGB)	LD	HL,VRAMD
;(CGB)	ADD	HL,DE	
;(CGB)	LD	(HLI),A
;(CGB)	PUSH	HL
;(CGB);
;(CGB)	LD	A,(SCVRML)
;(CGB)	LD	HL,KWDTL
;(CGB)	ADD	HL,BC
;(CGB)	ADD	A,(HL)
;(CGB)	POP	HL
;(CGB);
;(CGB)	LD	(HLI),A
;(CGB);
;(CGB)	LD	A,$51
;(CGB)	LD	(HLI),A
;(CGB);
;(CGB)	LD	A,(ENHELP) ;$7E
;(CGB)	LD	(HLI),A
;(CGB);
;(CGB)	LD	(HL),$00 ;A
;(CGB);
;(CGB)	LD	HL,MSSTCT
;(CGB)	INC	(HL)
;(CGB)	RET
;(CGB);---------------------
;(CGB)MSFIN
;
MSNEXT
	LD	HL,MSGEFG
	INC	(HL)
MSRET
	RET
;=====================================================
MSRWIT
	LD	A,(MSKYOF)
	AND	A
	JR	NZ,MSRW10	; Key check ok ?
;				; yes !
	LD	A,(KEYA2)
	AND	%00110000
	JR	Z,MSRW10
;
BGRSET
	XOR	A
	LD	(MSSTCT),A
;
	LD	A,(MSGEFG)
	AND	$F0
	OR	MSBGR	; Game BG return
	LD	(MSGEFG),A
MSRW10
	RET
;=====================================================
;=====================================================
;=====================================================
;劕劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劖
;劔	zms.s 偵僾儘僌儔儉傪堏摦					 劔
;劘劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劗
;(CGB)REDL
;(CGB)	DB	$A1,$21,$81,$41,$61	;忋偺恖
;(CGB)	DB	$C1,$41,$A1,$61,$81	;壓偺恖
;(CGB)REDH
;(CGB)	DB	$98,$98,$98,$98,$98	;
;(CGB)	DB	$99,$99,$99,$99,$99	;
;(CGB)MSGZDT
;(CGB)	DB	$48,$00,$36,$12,$24
;(CGB)	DB	$48,$00,$36,$12,$24
;
;
MSRETN
		LD	A,:MSRETN_SUB
		LD	($2100),A
		JP	MSRETN_SUB


;(CGB)	LD	A,(MSGEFG)
;(CGB)	LD	C,A
;(CGB);
;(CGB)	LD	A,(MSSTCT)
;(CGB)	CP	$05
;(CGB)	JR	Z,MSFIN
;(CGB);
;(CGB)	BIT	7,C
;(CGB)	JR	Z,MSRUP
;(CGB);
;(CGB)	ADD	A,$05
;(CGB)MSRUP
;(CGB)	LD	C,A
;(CGB)	LD	B,$0
;(CGB);
;(CGB)	LD	E,$01
;(CGB)	LD	D,$00
;(CGB);
;(CGB)	LD	A,(SCVRMH)
;(CGB)	LD	HL,REDH
;(CGB)	ADD	HL,BC
;(CGB)	ADD	A,(HL)
;(CGB)	LD	HL,VRAMD
;(CGB)	ADD	HL,DE	
;(CGB)	LD	(HLI),A
;(CGB)	PUSH	HL
;(CGB);
;(CGB)	LD	A,(SCVRML)
;(CGB)	LD	HL,REDL
;(CGB)	ADD	HL,BC
;(CGB)	ADD	A,(HL)
;(CGB)	POP	HL
;(CGB);
;(CGB)	LD	(HLI),A
;(CGB);
;(CGB)	LD	A,$11
;(CGB)	LD	(HLI),A
;(CGB);
;(CGB)	PUSH	HL
;(CGB);
;(CGB)	LD	HL,MSGZDT
;(CGB)	ADD	HL,BC
;(CGB)	LD	A,(HL)
;(CGB)	LD	C,A
;(CGB)	LD	B,$00
;(CGB)	LD	HL,MSBGBF
;(CGB)	ADD	HL,BC
;(CGB)	PUSH	HL
;(CGB)	POP	BC
;(CGB);
;(CGB)	POP	HL
;(CGB)	LD	E,$12	
;(CGB);
;(CGB)MRITA
;(CGB)	LD	A,(BC)
;(CGB)	INC	BC
;(CGB)	LD	(HLI),A
;(CGB)	DEC	E
;(CGB)	JR	NZ,MRITA
;(CGB);
;(CGB)	LD	(HL),$00 ;A
;(CGB);
;(CGB)		LD	A,:MSRETN_ATR
;(CGB)		LD	($2100),A
;(CGB)		CALL	MSRETN_ATR	; (CGB)儊僢僙乕僕傾僩儕價儏乕僩暅婣
;(CGB);
;(CGB)	LD	HL,MSSTCT
;(CGB)	INC	(HL)
;(CGB)	RET
;=====================================================
;-----------------------------------------------------	
MJBGIT
	LD	A,$1C
	LD	($2100),A
;
	LD	A,(MJSTTM)
	AND	A
	JR	Z,MJBI10
;
	DEC	A
	LD	(MJSTTM),A
	RET
MJBI10
	CALL	MJBI10_SUB
;
;;;KK;;;	LD	A,(MJSTCT)
;;;KK;;;	AND	$1F
;;;KK;;;	LD	E,A
;;;KK;;;	LD	D,0
;;;KK;;;;
;;;KK;;;	LD	C,$01
;;;KK;;;	LD	B,$00
;;;KK;;;;
;;;KK;;;	LD	HL,MJ1DTH
;;;KK;;;	ADD	HL,DE
;;;KK;;;	LD	A,(HL)
;;;KK;;;	LD	HL,VRAMD
;;;KK;;;	ADD	HL,BC
;;;KK;;;	LD	(HLI),A
;;;KK;;;;
;;;KK;;;	PUSH	HL
;;;KK;;;	LD	HL,MJ1DTL
;;;KK;;;	ADD	HL,DE
;;;KK;;;	LD	A,(HL)
;;;KK;;;	POP	HL
;;;KK;;;;
;;;KK;;;	LD	(HLI),A
;;;KK;;;;
;;;KK;;;	LD	A,$4F
;;;KK;;;	LD	(HLI),A	
;;;KK;;;;
;;;KK;;;	LD	A,$FF	; Beta 3
;;;KK;;;	LD	(HLI),A
;;;KK;;;;
;;;KK;;;	LD	(HL),$00 ;A
;
	JP  	MSNEXT
;=====================================================
MJBGST
	LD	A,$1C
	LD	($2100),A
;
	LD	A,(MSGEFG)
	LD	C,A
;
	LD	A,(MJSTCT2)
	BIT	7,C
	JR	Z,MJ2UP
;
	ADD	A,$20
MJ2UP
	LD	C,A
	LD	B,$0
;
	LD	E,$01
	LD	D,$00
;
	LD	A,(SCVRMH)
	LD	HL,MJ2DTH
	ADD	HL,BC
	ADD	A,(HL)
	LD	HL,VRAMD
	ADD	HL,DE
	LD	(HLI),A
	LD	(MSVRMH),A
;
	PUSH	HL
;
	LD	HL,MJ2DTL
	ADD	HL,BC
	LD	A,(HL)
	AND	$E0
	ADD	A,$20
	LD	E,A
;
	LD	A,(SCVRML)
	ADD	A,(HL)
	LD	D,A
	CP	E
	JR	C,MJ2010
;
	LD	A,D
	SUB	$20
	LD	D,A
MJ2010
	LD	A,D
	LD	(MSVRML),A
	POP	HL
;
	LD	(HLI),A
	XOR	A
	LD	(HLI),A
;
	PUSH	HL
;
	LD	A,(MJSTCT)
	AND	$1F
	LD	C,A
	LD	HL,MJ2DT
	ADD	HL,BC
	LD	A,(HL)
;
	POP	HL
;
	LD	(HLI),A
	CALL	MSNEXT
	JP	MJCHST
;=====================================================
MJCHST
	LD	A,$1C
	LD	($2100),A
;
	LD	A,(MJSTCT) ;3)
	AND	$1F
;
	LD	C,A
	LD	B,0
;
	LD	E,$05  ;1
	LD	D,$00
;
	LD	HL,MJ1DTH
	ADD	HL,BC
	LD	A,(HL)
	LD	HL,VRAMD
	ADD	HL,DE
	LD	(HLI),A
;
	PUSH	HL
	LD	HL,MJ1DTL
	ADD	HL,BC
	LD	A,(HL)
;
	POP	HL
	LD	(HLI),A
;
	LD	A,$0F
	LD	(HLI),A
;
	PUSH	HL
;
	LD	A,(MSGENOH)
	LD	D,A
;
	LD	A,(MSGENO)
	LD	E,A
	SLA	E
	RL	D
;
	LD	HL,MSGEAD
	ADD	HL,DE
	LD	A,(HLI)
	LD	E,A
	LD	D,(HL)
	PUSH	DE
	POP	HL
;
	LD	E,$1C
	LD	A,(MSGENOH)
	AND	A
	JR	Z,MSBKSSS
;
	LD	E,$1D
	CP	$01
	JR	Z,MSBKSSS
;
	LD	E,$14
MSBKSSS
	LD	A,E
	LD	($2100),A
;
	LD	A,(MJSTCT) ;3)
	LD	E,A
	LD	A,(MJSTCTH)
	LD	D,A  ;$0
	ADD	HL,DE
	LD	A,(HLI)
;
	LD	E,A
	LD	A,(HL)
	LD	(MSNXMJ),A	;師偺暥帤 No. 
;
	CALL	PBRETN
	LD	A,E
;
	LD	(WORK0),A
	CP	WE2
	JR	NZ,MJCS06	; Question check ?
;				; yes !
	POP	HL
	XOR	A
	LD	(VRAMD+1),A
;
MSQUESS
	LD	A,(MSGEFG)
	AND	$F0
	OR	MSQUE
	LD	(MSGEFG),A
;---------------------------------------
YASDST
	LD	A,$15
	LD	(SOUND1),A	;(S)栴報壒
	RET
;-------------------------------------
MJCS06
	CP	WED
	JR	NZ,MJCS08
;
	POP	HL
;
	XOR	A
	LD	(VRAMD+1),A
;
MSENDS
	LD	A,(MSGEFG)
	AND	$F0
	OR	MSKYW
	LD	(MSGEFG),A
	RET
;========================================
DOROBOU
	DB	$3D,$2B,$42,$A3,$00
;
MJCS08
	CP	XX
	JR	Z,MJCS081
;
	PUSH	AF
;
	LD	A,(FKMSFG)
	LD	D,A
	LD	E,$01
	CP	$0F
	JR	Z,MJCS0808
;
	LD	E,$07
	CP	$19	;僼僋儘僂両
	JR	Z,MJCS0808
	LD	E,$03
;
MJCS0808
	LD	A,(MJSTCT)
	ADD	A,$04
	AND	E
	JR	NZ,MJCS080A
;
	LD	A,D
	LD	(SOUND2),A	;(S)
MJCS080A
	POP	AF
MJCS081
	LD	D,$00
	CP	NM   ;E   ;NM1
	JR	NZ,NMCK10	; Name ?
;				; yes !
	LD	A,(NMSTCT)
	LD	E,A
	INC	A
	CP	$05
	JR	NZ,NMCK0D
;
	XOR	A
NMCK0D
	LD	(NMSTCT),A
;
	LD	HL,NAME
	LD	A,(MANBICT)
	AND	A
	JR	Z,NMCK0E
;
	LD	HL,DOROBOU
NMCK0E
	ADD	HL,DE
	LD	A,(HL)
	DEC	A
	CP	$FF
	JR	NZ,NMCK10
;
	LD	A,XX
NMCK10
	LD	(WORK1),A
	LD	E,A
;
	LD	A,$1C
	LD	($2100),A
;
	LD	HL,MSCHNO
	ADD	HL,DE
	LD	E,(HL)
	LD	D,$00
;
	SLA	E
	RL	D
	SLA	E
	RL	D
	SLA	E
	RL	D
	SLA	E
	RL	D
;
	CALL	PBRETN
;
	LD	HL,$5000
	ADD	HL,DE
	PUSH	HL
	POP	BC
;
	POP	HL
;
	LD	E,$10
MJCS0C
	LD	A,(BC)
	LD	(HLI),A
;
	INC	BC
;
	DEC	E
	JR	NZ,MJCS0C
;
	LD	(HL),$00 ;A
;
	PUSH	HL
;
	LD	A,$1C
	LD	($2100),A
;
	LD	A,(WORK1)
	LD	E,A
	LD	D,$00
	LD	HL,MSCHN2
	ADD	HL,DE
;
	LD	A,(HL)
	POP	HL
	AND	A
;
;
	JR	Z,MJCS88	; Dakuten ?
;				; yes !
	LD	E,A
;
	LD	A,(MSVRMH)
	LD	(HLI),A
	LD	A,(MSVRML)
	SUB	$20
	LD	(HLI),A
	LD	A,$00
	LD	(HLI),A
	LD	A,$C9	; Tenten
	RR	E
	JR	C,MJCS80
	DEC	A	; Maru
MJCS80
	LD	(HLI),A
	LD	(HL),$00 ;A
MJCS88
	LD	A,(MJSTCT)
	ADD	A,$01 ;	INC	A
	LD	(MJSTCT),A
	LD	A,(MJSTCTH)
	ADC	A,$00
	LD	(MJSTCTH),A
;
	XOR	A
	LD	(MJSDON),A
;
	LD	A,(MJSTCT2)
	CP	$1F
	JR	Z,MJCS10
;
MJAGAN
	LD	A,(MSGEFG)
	AND	$F0
	OR	MJST
	LD	(MSGEFG),A
;
	LD	A,$0
	LD	(MJSTTM),A
	RET
;
MJCS10
	JP  	MSNEXT
;=====================================================
MSSC1L
	DB	$22,$42
MSSC1H
	DB	$98,$99
MSSCR1
	LD	A,(MJSTCT)
	AND	$1F
	JR	NZ,MSCR080	; 1 page end ?
;				; yes ! key wait !
	LD	A,(MSNXMJ)  ;WORK2)
	CP	WED
	JP	Z,MSENDS	;愭撉傒両
	CP	WE2
	JP	Z,MSQUESS
;
	LD	A,(MJSDON)
	AND	A
	JR	NZ,MSSCR101
;
	INC	A
	LD	(MJSDON),A
;
	CALL	YASDST	;(S)
MSSCR101
	CALL	YAOBJST
;
	LD	A,(KEYA2)
	BIT	4,A  ;	AND	%00100000
	JR	NZ,MSSCST
;
	BIT	5,A
	JR	Z,MSCR150
;
	LD	A,$1C
	LD	($2100),A
;
	LD	A,(GMMODE)
	CP	GMAP
	JP	Z,QBGRSET	;儅僢僾忋偼僉儍儞僙儖弌棃傞両
;
	LD	A,(MSGENO)
	LD	E,A
	LD	A,(MSGENOH)
	LD	D,A
	LD	HL,MSCANC
	ADD	HL,DE
	LD	A,(HL)
	AND	A
	JP	Z,QBGRSET	; Cansel Not ?
;				; yes !
;-------------------------------------
MSSCST
MSCR080
	LD	E,$00
	LD	A,(MSGEFG)
	AND	%10000000
	JR	Z,MSCR100
	INC	E
MSCR100
	LD	D,$00
;
	LD	HL,MSSC1H
	ADD	HL,DE
	LD	A,(SCVRMH)
	ADD	A,(HL)
	LD	(VRAMD+1),A
;
	LD	HL,MSSC1L
	ADD	HL,DE
	LD	A,(SCVRML)
	ADD	A,(HL)
	LD	(VRAMD+2),A
;
	LD	A,$4F
	LD	(VRAMD+3),A
	LD	A,(ENHELP) ;$7E
	LD	(VRAMD+4),A
	XOR	A
	LD	(VRAMD+5),A
;
	CALL	MSNEXT
MSCR150
;=====================================================
MSSCR2
;;;	IN V BLANKING !!!
	RET
;=====================================================
MSSC2L
	DB	$62,$82
MSSC2H
	DB	$98,$99
MSSCR2S
	LD	E,$00
	LD	A,(MSGEFG)
	AND	%10000000
	JR	Z,MSCR200
	INC	E
MSCR200
	LD	D,$00
;
	LD	HL,MSSC2H
	ADD	HL,DE
	LD	A,(SCVRMH)
	ADD	A,(HL)
	LD	B,A
	LD	HL,MSSC2L
;----------------------------------
MSCRSUB
	ADD	HL,DE
	LD	A,(SCVRML)
	ADD	A,(HL)
	LD	C,A
;
	LD	E,$10
MSCR210
	LD	A,C
	SUB	$20
	LD	L,A
	LD	H,B
;
	LD	A,(BC)
	LD	(HL),A
	PUSH	BC
;
	LD	A,C
	ADD	A,$20
	LD	C,A
	LD	A,L
	ADD	A,$20
	LD	L,A
;
	LD	A,(BC)
	LD	(HL),A
;
	LD	A,L
	ADD	A,$20
	LD	L,A
;
	LD	A,(ENHELP)
	LD	(HL),A  ;$7E ;A
;
	POP	BC
;
	INC	BC
	LD	A,C
	AND	$1F
	JR	NZ,MSCR220
	LD	A,C
	SUB	$20
	LD	C,A
MSCR220
	DEC	E
	JR	NZ,MSCR210
;
	LD	A,$08
	LD	(MJSTTM),A
;
	JP  	MSNEXT
;=====================================================
MSSCR3
;;;	IN V BLANKING !!!
	RET
;=====================================================
MSSC3L
	DB	$42,$62
MSSC3H
	DB	$98,$99
MSSCR3S
	LD	E,$00
	LD	A,(MSGEFG)
	AND	%10000000
	JR	Z,MSCR300
	INC	E
MSCR300
	LD	D,$00
;
	LD	HL,MSSC3H
	ADD	HL,DE
	LD	A,(SCVRMH)
	ADD	A,(HL)
	LD	B,A
	LD	HL,MSSC3L
;
	CALL	MSCRSUB
	JP	MJAGAN
;=====================================================
QBGRSET
	LD	A,$2
	LD	(MSANSR),A
	JP	BGRSET
;
MSQUES
	LD	A,(KEYA2)
	BIT	5,A
	JR	NZ,QBGRSET
;
	AND	%00010000
	JP	NZ,MSQ080
;
	LD	A,(KEYA2)
	AND	%01000011
	JR	Z,MSQ008
;
	LD	HL,MSANSR
	LD	A,(HL)
	INC	A
	AND	$1
	LD	(HL),A
;
	LD	A,$0A
	LD	(SOUND1),A	;(S)
MSQ008
	LD	A,(FRCNT)
	AND	$10
	RET	Z
;
	LD	A,$17
	LD	($2100),A
	JP	MSCURST
;
MSQ080
	CALL	BGRSET
;
	RET
;
;=====================================================
YAOBJST
	LD	A,$17
	LD	($2100),A
	JP  	YAOBJSTS
;	
;=====================================================
;=====================================================
;=====================================================
;****************************************
;*      Scroll                          *
;****************************************
SCROLL
	LD	A,$02
	CALL	PBSET
;
	CALL	SCROLLS
;
	RET
;
;========================================
;;;CGB;;;SCVRAL
;;;CGB;;;	DB	$01,$01,$20,$20
;;;CGB;;;SCVRAT
;;;CGB;;;	DB	$93,$93,$13,$13
SCNXUN
	DB	$10,$10,$01,$01
SCRCD11
	DB	$08,$08,$0A,$0A		; Set unit count 
SCNLUN
	DB	$01,$FF,$F0,$10
SCNLAH
	DB	$00,$00,$03,$00
SCNLAL
	DB	$02,$1E,$C0,$40
;- - - - - - - - - - - - - - - - - - - - - - - - 
SCRMV1S
	LD	A,$8
	LD	($2100),A
;
	CALL	SCRMV1SS
	CALL	PBRETN
	RET
;
;--Tate scroll-------------------------------
TATE_SET
	LD	A,(HLI)		; Unit NO -> 4x4 Character
	LD	(BC),A
	INC	BC
	LD	A,(HLI)
	LD	(BC),A
	INC	BC
;
	LD	A,(HLI)		; Unit NO -> 4x4 Character
	LD	(DE),A
	INC	DE
	LD	A,(HL)
	LD	(DE),A
	INC	DE
	RET
;
;--Yoko scroll-------------------------------
YOKO_SET
	LD	A,(HLI)		; Unit NO -> 4x4 Character
	LD	(BC),A
	LD	A,(HLI)
	LD	(DE),A
;
	INC	BC
	INC	DE
;
	LD	A,(HLI)		; Unit NO -> 4x4 Character
	LD	(BC),A
	LD	A,(HL)
	LD	(DE),A
;
	INC	BC
	INC	DE
	RET
;
;===============================
SCRMV1SS
	LD	A,(SCRLTM)
	CP	$0
	JR	Z,SCM100	; Scroll speed wait !
;
	DEC	A
	LD	(SCRLTM),A
	RET
;
;-- CGB --
SCM100
		LD	A,$20
		LD	($2100),A
		CALL	SCROLL_INIT
		LD	A,$8
		LD	($2100),A
;-- CGB --
;
;;;CGB;;;SCM100
;;;CGB;;;	LD	A,(SCRLMK)
;;;CGB;;;	LD	C,A
;;;CGB;;;	LD	B,$00
;;;CGB;;;;
;;;CGB;;;	LD	A,$01
;;;CGB;;;	LD	(SCRLTM),A
;;;CGB;;;;
;;;CGB;;;	LD	A,(SCUNTA)
;;;CGB;;;	LD	(WORK2),A
;;;CGB;;;;
;;;CGB;;;	LD	HL,SCVRAL
;;;CGB;;;	ADD	HL,BC
;;;CGB;;;;
;;;CGB;;;	LD	A,(SCRADL)
;;;CGB;;;	LD	(VRAMD+2),A
;;;CGB;;;	ADD	A,(HL) ;E
;;;CGB;;;	RL	D		; PUSH CY
;;;CGB;;;	LD	(VRAMD+$19),A
;;;CGB;;;;
;;;CGB;;;	LD	A,(SCRADH)
;;;CGB;;;	OR	$98
;;;CGB;;;	LD	(VRAMD+1),A
;;;CGB;;;	RR	D		; POP CY
;;;CGB;;;	ADC	A,$00
;;;CGB;;;	LD	(VRAMD+$18),A
;;;CGB;;;;
;;;CGB;;;	LD	HL,SCVRAT
;;;CGB;;;	ADD	HL,BC
;;;CGB;;;	LD	A,(HL)
;;;CGB;;;	LD	(VRAMD+3),A
;;;CGB;;;	LD	(VRAMD+$1A),A
;;;CGB;;;;
;;;CGB;;;;
;;;CGB;;;	LD	A,$00
;;;CGB;;;	LD	(VRAMD+$2F),A
;;;CGB;;;;
;;;CGB;;;	LD	A,$EE		; FE:Not write  for yoko scroll !
;;;CGB;;;	LD	(VRAMD+$14),A
;;;CGB;;;	LD	(VRAMD+$15),A
;;;CGB;;;	LD	(VRAMD+$16),A
;;;CGB;;;	LD	(VRAMD+$17),A
;;;CGB;;;	LD	(VRAMD+$2B),A
;;;CGB;;;	LD	(VRAMD+$2C),A
;;;CGB;;;	LD	(VRAMD+$2D),A
;;;CGB;;;	LD	(VRAMD+$2E),A
;;;CGB;;;;
;;;CGB;;;	LD	B,>VRAMD
;;;CGB;;;	LD	C,<VRAMD+4
;;;CGB;;;	LD	D,>VRAMD
;;;CGB;;;	LD	E,<VRAMD+$1B
;;;CGB;;;;
SI2100
	PUSH	BC
	PUSH	DE
;
	LD	A,(WORK2)
	LD	C,A
	LD	B,$0
	LD	HL,BGUNDT+$11
	ADD	HL,BC
	LD	B,$0

;--------------------------------------
;	抧忋怴俵俙俹梡
;--------------------------------------
	LD	C,(HL)		; Unit NO.

		LD	A,(CGBFLG)
		AND	A		; 俠俧俛儌乕僪丠
		JR	Z,SI2100_100	; 俶俷
		LD	A,(DJFLAG)
		AND	A		; 僟儞僕儑儞丠
		JR	NZ,SI2100_100	; 倄俤俽

		LD	A,$02
		LD	(SVBK),A	; 俼俙俵僶儞僋乮俀乯僙僢僩
		LD	C,(HL)		; Unit NO.
		XOR	A
		LD	(SVBK),A	; 俼俙俵僶儞僋乮侽乯僙僢僩
SI2100_100
;--------------------------------------

	SLA	C
	RL	B
	SLA	C
	RL	B
;
		LD	A,(DJFLAG)
		AND	A		; 抧忋丠
		JR	Z,SI2100_200	; 倄俤俽

;亙 僟儞僕儑儞 亜
		LD	HL,DJUNCH
		LD	A,(CGBFLG)
		AND	A		; 俠俧俛儌乕僪丠
		JR	Z,SI2101_PASS	; 俶俷

		LD	HL,DJUNCH_CGB
		LD	A,(DNJNNO)
		CP	NEWDJ		;怴僟儞僕儑儞丠
		JR	NZ,SI2100_PASS	;	NO --> SI2100_PASS
		LD	HL,DJUNCH2
		JR	SI2100_PASS
;亙 抧忋 亜
SI2100_200
		LD	HL,BGUNCH
		LD	A,(CGBFLG)
		AND	A		; 俠俧俛儌乕僪丠
		JR	Z,SI2101_PASS	; 俶俷

		LD	HL,BGUNCH_CGB
SI2100_PASS
;
;-- CGB --
;;;;;		LD	A,(CGBFLG)
;;;;;		AND	A		;俠俧俛儌乕僪丠
;;;;;		JR	Z,SI2101_PASS	;	no --> SI2101_PASS
		LD	A,:BgAtrAddress
		LD	($2100),A
		CALL	BgAtrAddress
;NOT;		LD	A,$08
;NOT;		LD	($2100),A
SI2101_PASS
		CALL	Unit_bank_set	; 儐僯僢僩僶儞僋僙僢僩
;-- CGB --
;
	ADD	HL,BC
;
	POP	DE
	POP	BC
;
	LD	A,(SCRLMK)
	AND	%00000010
	JR	Z,SI2118
;--Tate scroll-------------------------------
		CALL	TATE_SET
;
;-- CGB --
		LD	A,(CGBFLG)
		AND	A		;俠俧俛儌乕僪丠
		JR	Z,TATE_ATR_PASS	;	no --> TATE_ATR_PASS
		PUSH	BC
		PUSH	DE
		LD	A,$20
		LD	($2100),A
		CALL	SCRL_SUB
		LD	A,(WORK8)
		LD	($2100),A
		CALL	TATE_SET
		LD	A,B
		LD	(WORKB),A
		LD	A,C
		LD	(WORKC),A
		LD	A,D
		LD	(WORKD),A
		LD	A,E
		LD	(WORKE),A
;NOT;		LD	A,$8
;NOT;		LD	($2100),A
		CALL	Unit_bank_set	; 儐僯僢僩僶儞僋僙僢僩
		POP	DE
		POP	BC
TATE_ATR_PASS
;-- CGB --
;
	JR	SI2130
;--Yoko scroll-------------------------------
SI2118
		CALL	YOKO_SET
;
;-- CGB --
		LD	A,(CGBFLG)
		AND	A		;俠俧俛儌乕僪丠
		JR	Z,YOKO_ATR_PASS	;	no --> YOKO_ATR_PASS
		PUSH	BC
		PUSH	DE
		LD	A,$20
		LD	($2100),A
		CALL	SCRL_SUB
		LD	A,(WORK8)
		LD	($2100),A
		CALL	YOKO_SET
		LD	A,B
		LD	(WORKB),A
		LD	A,C
		LD	(WORKC),A
		LD	A,D
		LD	(WORKD),A
		LD	A,E
		LD	(WORKE),A
;NOT;		LD	A,$8
;NOT;		LD	($2100),A
		CALL	Unit_bank_set	; 儐僯僢僩僶儞僋僙僢僩
		POP	DE
		POP	BC
YOKO_ATR_PASS
;-- CGB --
;
SI2130
;- - Next unit adress set - - 
	PUSH	BC
;
	LD	A,(SCRLMK)
	LD	C,A
	LD	B,$00
;
	LD	HL,SCNXUN
	ADD	HL,BC
	LD	A,(WORK2)
	ADD	A,(HL)  ;E
	LD	(WORK2),A	; Next load address set !
;
	POP	BC
;
	LD	A,(SCRLC1)
	DEC	A
	LD	(SCRLC1),A
	JP	NZ,SI2100	; 1 line end ?
;				; yes !
	LD	A,(SCRLMK)
	LD	C,A
	LD	B,$00
;
	LD	HL,SCRCD11	; Next count set !
	ADD	HL,BC
	LD	A,(HL)
	LD	(SCRLC1),A
;- - Next Line adress set - - 
	LD	HL,SCNLUN
	ADD	HL,BC
	LD	A,(SCUNTA)
	ADD	A,(HL)  ;E
	LD	(SCUNTA),A	; Next load address set !
;
	LD	HL,SCNLAL
	ADD	HL,BC
	LD	A,(SCRADL)
	ADD	A,(HL)  ;E
	RR	D		; PUSH C
	AND	%11011111
	LD	(SCRADL),A
;
	LD	HL,SCNLAH
	ADD	HL,BC
	LD	A,(SCRADH)
	RL	D		; POP C
	ADC	A,(HL)  ;E
	AND	$03
	LD	(SCRADH),A
;
	LD	A,(SCRLC2)
	DEC	A
	LD	(SCRLC2),A
	JR	NZ,SI2120	; All clear ?
;				; yes !
	JP	SCRNXT2
SI2120
	RET
SCRNXT2
	LD	A,(SCRLFG)
	INC	A
	LD	(SCRLFG),A
	RET
;=====================================================
;=====================================================
;=====================================================
;=====================================================
;=====================================================
	END
;=====================================================
