If you appreciate the work done within the wiki, please consider supporting The Cutting Room Floor on Patreon. Thanks for all your support!

Proto:Game Boy Camera

From The Cutting Room Floor
Jump to navigation Jump to search

This page details one or more prototype versions of Game Boy Camera.

For the unreleased Hello Kitty edition of the game, see Hello Kitty Pocket Camera
So very stubbly.
This page is rather stubbly and could use some expansion.
Are you a bad enough dude to rescue this article?
Notes: Describe the rest of the functionality of the cart
DebagameTesterSI-Title.png

The Debagame Tester: Second Impact is a cartridge used for testing the Game Boy Camera hardware. Debagame means peeping tom and is also likely a pun on debug.

Functionality

Hmmm...
To do:
A lot of this stuff still needs researched.
MENU

There are six options in the main menu.

SRAM TEST

SRAM TEST
  • VERIFY
  • WRITE
  • AGING
    • DECREMENT
    • 00,00,FF,FF
    • 55,55,AA,AA
    • ALL 00
    • ALL FF
  • DUMP: Press Left/Right to change displayed bank from 00 through 0F. Press Up/Down to scroll the selected bank.

BANK TEST

BANK TEST

PROTECT TEST

Elementary, my dear Cactus.
This needs some investigation.
Discuss ideas and findings on the talk page.
Specifically: What is this protecting...? It doesn't seem to be the photo data...
PROTECT TEST
  • PROTECT: Displays current "protect" status, either "OK" or "NG" (no good).
  • ON: Turn protect status ON.
  • OFF: Turn protect status OFF.

MOVIE TEST

MOVIE TEST

This is the mode for taking photos.

Controls:

  • A: Snap and save photo. You can choose which slot to save the photo to, from 00 to 29.
  • B: Cancel/return.
  • Left/Right: Adjust offset, 01 through 83.
  • Select: Change trick lens modes, 00 through 1F.
  • Start: Open settings screen.
MOVIE TEST Settings

Settings options:

  • ディザ (Dither): Set the dithering strength from 1 to 11, or OFF.
  • MODE: Set camera mode.
    • 二次元エッジ強調 (2D edge emphasis): With GAIN levels 04H, 08H, and 00H.
    • 二次元エッジ (2D edge)
    • 負画像 (Inverted)
    • 横エッジ強調 (Horizontal edge emphasis)
    • 縦エッジ強調 (Vertical edge emphasis)
  • EDGE: Set 50%, 75%, 100%, 125%, 200%, 300%, 400%, 500%.
  • パレット (Palette): Set color palette order from 0 to 5.

The following settings are for reference cannot be selected:

  • VREF: Always set to 1.5V.
  • ゼロ点 (Zero point): Generally set to 負画像ゼロ点補正 (inverted image zero point compensation), but will change to 無し (none) in 二次元エッジ (2D edge) MODE.
  • GAIN: Generally set to 04H, but can change to 08H or 00H in certain 二次元エッジ強調 (2D edge emphasis) MODEs.
  • オフセット (Offset)
  • CHG
(Example photos: Chris Graves)

GALLERY

GALLERY

A basic photo gallery viewer. Press Up/Down to scroll through photos 00 through 29. Photos cannot be deleted; they can simply be overwritten with new ones from the MOVIE TEST mode.

COM

COM

A basic link cable communication test. When two Testers are connected on this screen, pressing A on either Game Boy will cause the number to quickly "count" from 00 through FF in a loop on both screens.

Unused Graphics

DebagameTesterSI-Pictures.png

Fourteen full size pictures are found throughout the ROM data. Ten of them are photos of an unknown Nintendo employee. The last four are drawings of a face which appear in the final game (however, they're slightly less refined here).

DebagameTesterSI-Edit.png

UI elements for some sort of editor.

DebagameTesterSI-Logo.png

An alternate, probably earlier, logo for the title screen. It reads "Debagame Tester NEO".

DebagameTesterSI-Arrow.png

An arrow hanging from a string. Probably an earlier menu cursor graphic, before it was replaced with the spinning face.

Source Code

Hmmm...
To do:
Other bits?

Large chunks of commented source code are also found throughout the ROM. The two largest chunks are as follows:

	LD	(AKARUSA),A		;目標値をワークに
	
	LD	A,$00
	LD	($4000),A		;RAMバンクの変更
	
	
;-------------現在のチャージタイムの表示---------------

	IFE	OOE

	LD	A,(B_CNTR2)
	LD	(TEST1),A
	LD	A,(B_CNTR3)
	LD	(TEST2),A

	ENDIF
	
;-------------黒点数え(真ん中)-----------------------
	IFE	ZENTAI
	LD	BC,$00		;真ん中8×7キャラの1の数を数える
				; 市松模様(448バイトをチェック)
	LD	de,BUF_ADR+$340
	CALL	LINE_CHECK
	LD	de,BUF_ADR+$440
	CALL	LINE_CHECK
	LD	de,BUF_ADR+$540
	CALL	LINE_CHECK
	LD	de,BUF_ADR+$640
	CALL	LINE_CHECK
	LD	de,BUF_ADR+$740
	CALL	LINE_CHECK
	LD	de,BUF_ADR+$840
	CALL	LINE_CHECK
	LD	de,BUF_ADR+$940
	CALL	LINE_CHECK
	ENDIF

;------------黒点数え(画面全体)----------------------
	ifn	ZENTAI
	LD	BC,$00
	
	LD	DE,BUF_ADR
	CALL	SCREEN_CHECK

	endif

;********この時点で、BCに黒点の個数が入っている***********
;********    BCのとりうる値は 0000~1500H      ***********

_COUNT_END

	LD	A,(AKARUSA)
	LD	D,A		; AKARUSAが、黒点の数の目標値(0~A8)

	SLA	C	; BCを3BIT左にシフト
	RL	B		
	SLA	C
	RL	B
	SLA	C	; 黒点の数の上位8BITがBレジスタに入る
	RL	B	; Bの値は 0~A8


;--------------------------------------------
;   ここで現在の黒点の数と目標値を比較する
;--------------------------------------------
	LD	A,B
	SUB	D	; B(黒点の数)からC(AKARUSA:目標値)を引く
	JR	NC,_UP

;===========================================
; 現在の黒点の数が、目標値よりも少なかった時
;  チャージタイムを短くする
;===========================================
_DOWN
	CPL			; BIT反転
	INC	A		; これで2の補数
	LD	B,A
	LD	(TEST),A
;------------------------------------	
	LD	A,(B_CNTR2)	;現在のチャージタイムをHL,DEに入れる
	LD	H,A
	LD	D,A
	LD	A,(B_CNTR3)
	LD	L,A
	LD	E,A
;------------------------------------
	LD	A,B		; チャージタイム増加分の計算
	LD	BC,CHG_TIME_TBL_D	;テーブルからシフトする回数を得る
	ADD	A,C
	LD	C,A
	JR	NC,_NO_CARRY
	INC	B
_NO_CARRY
	LD	A,(BC)		;ループカウンタ(シフトする回数)
				;この数が、何分の1を引くかを決める
;------------------------------------
_DOWN_LP
	CP	$00
	JR	Z,_D_LP_E
	SRL	D		;DEを右シフト
	RR	E		;ループするごとに減少分が減る
	DEC	A
	JR	_DOWN_LP
_D_LP_E

;--------DEの2の補数の計算-----------
	LD	A,D
	CPL
	LD	D,A
	LD	A,E
	CPL
	LD	E,A
	INC	DE
;------------------------------------
	ADD	HL,DE
	JR	_SET



;===========================================
; 現在の黒点の数が、目標値よりも多かった時
;  チャージタイムを長くする
;===========================================
_UP
	LD	B,A		;引き算結果をBに入れる
	LD	(TEST),A

;------------------------------------
	LD	A,(B_CNTR2)	;現在のチャージタイムを、HL,DEに入れる
	LD	H,A
	LD	D,A
	LD	A,(B_CNTR3)
	LD	L,A
	LD	E,A
;------------------------------------
	LD	A,B		; チャージタイム増加分の計算

;------------------------------------
	CP	$00		;00なら変更の必要無し。戻る。
	RET	Z
;------------------------------------

	LD	BC,CHG_TIME_TBL_U	;テーブルからシフトする回数を得る
	ADD	A,C
	LD	C,A
	JR	NC,_NO_CARRY_U
	INC	B
_NO_CARRY_U
	LD	A,(BC)		;ループカウンタ(シフトする回数)

;------------------------------------
_UP_LP	
	CP	$00
	JR	Z,_U_LP_E
	SRL	D
	RR	E
	DEC	A
	JR	_UP_LP
_U_LP_E
	ADD	HL,DE
	JR	NC,_SET
	LD	HL,$FFFF	; MAX値(FFFFH)超えた場合はMAXに
;------------------------------------

;======================================================
;  実際にチャージタイムを変更する(チップへの転送も)
;======================================================
_SET
	LD	A,H
	LD	(B_CNTR2),A
	LD	A,L
	LD	(B_CNTR3),A

	LD	DE,$FFDF		; 21Hより下は使えないので
	ADD	HL,DE
	JR	C,_SET_OK

	LD	A,$00
	LD	(B_CNTR2),A		; 強制的に21Hにする
	LD	A,$21
	LD	(B_CNTR3),A

_SET_OK
	LD	A,$10
	LD	($4000),A		; RAM BANKの変更
	
	LD	A,(B_CNTR2)
	LD	(CNTR2),A		;実際に変更する
	LD	A,(B_CNTR3)
	LD	(CNTR3),A

	RET





;=================================================
; 1の数を数えるサブルーチン 1行分
;=================================================
LINE_CHECK
	ld	a,$4
	ld	(r0),a	; loop counter
_lp
	call	BIT_COUNT
	inc	de
	inc	de
	
	call	BIT_COUNT
	inc	de
	inc	de

	call	BIT_COUNT
	inc	de
	inc	de

	call	BIT_COUNT
	inc	de
	inc	de
	
	inc	de
	inc	de
	
	call	BIT_COUNT
	inc	de
	inc	de

	call	BIT_COUNT
	inc	de
	inc	de

	call	BIT_COUNT
	inc	de
	inc	de

	call	BIT_COUNT

	ld	a,(r0)
	dec	a
	ret	z
	ld	(r0),a
	jr	_lp


;************************************************
;*   SCREEN_CHECK		画面全体	*
;************************************************

SCREEN_CHECK
	ld	a,$1C
	ld	(r0),a	; loop counter
_lp
	CALL	BIT_COUNT	;最初のキャラクタの1行目
	LD	HL,$14		
	ADD	HL,DE
	LD	D,H
	LD	E,L

	CALL	BIT_COUNT	;次のキャラクタの4行目
	LD	HL,$14
	ADD	HL,DE
	LD	D,H
	LD	E,L
	
	CALL	BIT_COUNT	;次のキャラクタの7行目
	LD	HL,$4
	ADD	HL,DE
	LD	D,H
	LD	E,L
	
	CALL	BIT_COUNT	;次のキャラクタの1行目
	LD	HL,$14
	ADD	HL,DE
	LD	D,H
	LD	E,L
	
	CALL	BIT_COUNT
	LD	HL,$14
	ADD	HL,DE
	LD	D,H
	LD	E,L
	
	CALL	BIT_COUNT
	LD	HL,$4
	ADD	HL,DE
	LD	D,H
	LD	E,L
	
	CALL	BIT_COUNT
	LD	HL,$14
	ADD	HL,DE
	LD	D,H
	LD	E,L
	
	CALL	BIT_COUNT
	LD	HL,$4
	ADD	HL,DE
	LD	D,H
	LD	E,L	
	
	ld	a,(r0)
	dec	a
	ret	z
	ld	(r0),a
	jr	_lp


;==================================================
; 色の濃度を計算する  色データ00、01、10、11を0,1,2,3
;                     として足しあわせる。
;	bc : bit counter
;	de : チェックする画像データのアドレス
;==================================================
BIT_COUNT
	LD	H,$3E		; テーブルのアドレス$3E00
	LD	A,(DE)
	INC	DE
	LD	L,A
	LD	L,(HL)
	LD	H,$00
	ADD	HL,BC
	LD	B,H
	LD	C,L
	
	LD	H,$3E
	LD	A,(DE)
	INC	DE
	LD	L,A
	LD	L,(HL)
	SLA	L		; 1BIT左シフト
	LD	H,$00
	ADD	HL,BC
	LD	B,H
	LD	C,L

	RET




;//////////////////////////////////////////////////////////////////////
;//////////////////////////////////////////////////////////////////////


;*******************************************************
;* SET DITH MATRIX                                     *
;*     B : ディザパターン                              *
;*     C : コントラスト                                *
;*******************************************************
SET_DITH_MATRIX
;++++++コントラストからS0,S1,S2,W0,W1,W2を決定する+++++++
	LD	HL,CONT_PATTERN
	LD	DE,$6
_LP0
	DEC	C		;コントラスト1~21H
	JR	Z,_GET_PAT
	ADD	HL,DE
	JR	_LP0


_GET_PAT
	LD	DE,S0		; DEにS0のアドレスをセット
	LD	A,(HLI)
	LD	(DE),A
	INC	DE
	LD	A,(HLI)
	LD	(DE),A
	INC	DE
	LD	A,(HLI)
	LD	(DE),A
	INC	DE
	LD	A,(HLI)
	LD	(DE),A
	INC	DE
	LD	A,(HLI)
	LD	(DE),A
	INC	DE
	LD	A,(HLI)
	LD	(DE),A

;++++++ディザパターンの先頭アドレスをHLに入れる++++++++
	LD	HL,NO_DITHER_PAT
	LD	DE,$10
	LD	A,B
	OR	A
	JR	Z,_LP_START
_LP1
	ADD	HL,DE
	DEC	B
	JR	NZ,_LP1

;++++++閾値バッファに書き込んでいく+++++++++++
_LP_START

	LD	DE,B_TH000	; 書き込み先バッファ(48バイト)の先頭

	LD	A,$10
	LD	(LOOP_COUNT),A
_LP2
	LD	A,(W0)
	LD	C,A

	LD	A,(HLI)
	LD	B,A
	XOR	A
_LP21
	DEC	C
	JR	Z,_LP22
	ADD	A,B
	JR	_LP21
_LP22
	LD	B,A
	LD	A,(S0)
	ADD	A,B

	LD	(DE),A
	INC	DE
	LD	A,(LOOP_COUNT)
	DEC	A
	LD	(LOOP_COUNT),A
	JR	NZ,_LP2

;------------------------------
	LD	BC,$FFF0
	ADD	HL,BC

	LD	A,$10
	LD	(LOOP_COUNT),A
_LP3
	LD	A,(W1)
	LD	C,A

	LD	A,(HLI)
	LD	B,A
	XOR	A
_LP31
	DEC	C
	JR	Z,_LP32
	ADD	A,B
	JR	_LP31
_LP32
	LD	B,A
	LD	A,(S1)
	ADD	A,B

	LD	(DE),A
	INC	DE
	LD	A,(LOOP_COUNT)
	DEC	A
	LD	(LOOP_COUNT),A
	JR	NZ,_LP3

;-------------------------------
	LD	BC,$FFF0
	ADD	HL,BC

	LD	A,$10
	LD	(LOOP_COUNT),A
_LP4
	LD	A,(W2)
	LD	C,A

	LD	A,(HLI)
	LD	B,A
	XOR	A
_LP41
	DEC	C
	JR	Z,_LP42
	ADD	A,B
	JR	_LP41
_LP42
	LD	B,A
	LD	A,(S2)
	ADD	A,B

	LD	(DE),A
	INC	DE
	LD	A,(LOOP_COUNT)
	DEC	A
	LD	(LOOP_COUNT),A
	JR	NZ,_LP4


;=======閾値をバッファから網膜チップに書き込む=========

	C_RAMBK	$10

	LD	HL,$A006
	
	LD	A,(B_TH000)
	LD	(HLI),A
	LD	A,(B_TH001)
	LD	(HLI),A
	LD	A,(B_TH002)
	LD	(HLI),A
	LD	A,(B_TH010)
	LD	(HLI),A
	LD	A,(B_TH011)
	LD	(HLI),A
	LD	A,(B_TH012)
	LD	(HLI),A
	LD	A,(B_TH020)
	LD	(HLI),A
	LD	A,(B_TH021)
	LD	(HLI),A
	LD	A,(B_TH022)
	LD	(HLI),A
	LD	A,(B_TH030)
	LD	(HLI),A
	LD	A,(B_TH031)
	LD	(HLI),A
	LD	A,(B_TH032)
	LD	(HLI),A

	LD	A,(B_TH100)
	LD	(HLI),A
	LD	A,(B_TH101)
	LD	(HLI),A
	LD	A,(B_TH102)
	LD	(HLI),A
	LD	A,(B_TH110)
	LD	(HLI),A
	LD	A,(B_TH111)
	LD	(HLI),A
	LD	A,(B_TH112)
	LD	(HLI),A
	LD	A,(B_TH120)
	LD	(HLI),A
	LD	A,(B_TH121)
	LD	(HLI),A
	LD	A,(B_TH122)
	LD	(HLI),A
	LD	A,(B_TH130)
	LD	(HLI),A
	LD	A,(B_TH131)
	LD	(HLI),A
	LD	A,(B_TH132)
	LD	(HLI),A

	LD	A,(B_TH200)
	LD	(HLI),A
	LD	A,(B_TH201)
	LD	(HLI),A
	LD	A,(B_TH202)
	LD	(HLI),A
	LD	A,(B_TH210)
	LD	(HLI),A
	LD	A,(B_TH211)
	LD	(HLI),A
	LD	A,(B_TH212)
	LD	(HLI),A
	LD	A,(B_TH220)
	LD	(HLI),A
	LD	A,(B_TH221)
	LD	(HLI),A
	LD	A,(B_TH222)
	LD	(HLI),A
	LD	A,(B_TH230)
	LD	(HLI),A
	LD	A,(B_TH231)
	LD	(HLI),A
	LD	A,(B_TH232)
	LD	(HLI),A

	LD	A,(B_TH300)
	LD	(HLI),A
	LD	A,(B_TH301)
	LD	(HLI),A
	LD	A,(B_TH302)
	LD	(HLI),A
	LD	A,(B_TH310)
	LD	(HLI),A
	LD	A,(B_TH311)
	LD	(HLI),A
	LD	A,(B_TH312)
	LD	(HLI),A
	LD	A,(B_TH320)
	LD	(HLI),A
	LD	A,(B_TH321)
	LD	(HLI),A
	LD	A,(B_TH322)
	LD	(HLI),A
	LD	A,(B_TH330)
	LD	(HLI),A
	LD	A,(B_TH331)
	LD	(HLI),A
	LD	A,(B_TH332)
	LD	(HLI),A
	
	R_RAMBK

	RET



;=========================================================
;  REGISTER_SETTING
;
;   人工網膜チップのレジスタの設定
;
;   Aレジスタ : 上位4ビット エッジの強さ 0~7
;		下位4ビット モード 0:負画像
;				   1:横エッジ強調
;				   2:縦エッジ強調
;				   3:二次元エッジ強調
;				   4:横エッジ
;				   5:縦エッジ
;				   6:二次元エッジ
;==========================================================
REGISTER_SETTING
	LD	B,A	;モードとエッジの強さ
	
	AND	$0F
	CP	$00
	JR	Z,_FUGAZOU
	CP	$01
	JR	Z,_YOKO_KYOUTYOU
	CP	$02
	JR	Z,_TATE_KYOUTYOU
	CP	$03
	JR	Z,_NIJIGEN_KYOUTYOU
	CP	$04
	JP	Z,_YOKO_EDGE
	CP	$05
	JP	Z,_TATE_EDGE
	JP	_NIJIGEN_EDGE
	RET

;--------------負画像------------------
_FUGAZOU
	LD	A,$02
	LD	(B_CNTR0),A
	LD	A,$02
	LD	(CNTR1),A
	LD	(B_CNTR1),A
	LD	A,$02
	LD	(CNTR4),A
	LD	(B_CNTR4),A
;	LD	A,$80
;	LD	(B_CNTR5),A
	RET

;-----------横エッジ強調--------------
_YOKO_KYOUTYOU
	LD	A,$02
	LD	(B_CNTR0),A
	LD	A,$22
	LD	(B_CNTR1),A
	LD	(CNTR1),A
	
	LD	A,B
	AND	$F0
	CP	$00
	JR	Z,_EDGE_YOWAI1
	CP	$10
	JR	Z,_EDGE_YOWAI1
	CP	$20
	JR	Z,_EDGE_YOWAI1
	ADD	A,$6
	JR	_V_SET_YK
_EDGE_YOWAI1
	ADD	A,$03
_V_SET_YK
	LD	(CNTR4),A
	LD	(B_CNTR4),A
;	LD	A,$80
;	LD	(B_CNTR5),A
	
	RET
	
;-----------縦エッジ強調--------------
_TATE_KYOUTYOU
	LD	A,$00
	LD	(B_CNTR0),A
	LD	A,$C2
	LD	(CNTR1),A
	LD	(B_CNTR1),A
	
	LD	A,B
	AND	$F0
	ADD	A,$03
	LD	(CNTR4),A
	LD	(B_CNTR4),A
	RET
	
;---------二次元エッジ強調------------

_NIJIGEN_KYOUTYOU
	LD	A,$00
	LD	(B_CNTR0),A
	LD	A,$E2
	LD	(B_CNTR1),A
	LD	(CNTR1),A

	LD	A,B
	AND	$F0
	CP	$00
	JR	Z,_EDGE_YOWAI
	CP	$10
	JR	Z,_EDGE_YOWAI
	CP	$20
	JR	Z,_EDGE_YOWAI
	CP	$30
	JR	Z,_EDGE_TYUU
	ADD	A,$6
	JR	_V_SET
_EDGE_YOWAI
	ADD	A,$03
	JR	_V_SET
_EDGE_TYUU
	ADD	A,$04
	
_V_SET
	LD	(CNTR4),A
	LD	(B_CNTR4),A
;	LD	A,$80
;	LD	(B_CNTR5),A
	RET

;--------------横エッジ-----------------
_YOKO_EDGE

	RET
	
;--------------縦エッジ-----------------
_TATE_EDGE

	RET
	
;------------二次元エッジ---------------
_NIJIGEN_EDGE
	LD	A,$00
	LD	(B_CNTR0),A
	LD	A,$E2
	LD	(CNTR1),A
	LD	(B_CNTR1),A
	
	LD	A,B
	AND	$F0
	ADD	A,$03
	SET	7,A
	LD	(CNTR4),A
	LD	(B_CNTR4),A
	
	RET
	

;///////////////////////////////////////////////////////////////////
;///////////////////////////////////////////////////////////////////


;=====================================================
;
;   オフセット調整
;
;  閾値が変更されるので、この後ディザの設定をすること
;=====================================================
GET_OFFSET

;-------------------------
	LD	A,$10		; RAMBK $10
	LD	($4000),A

	LD	B,$70
	LD	A,(B_MODE)
	CP	$06
	JR	NZ,_SET_TH

	LD	B,$55		;閾値を55H(1V)に設定する
_SET_TH
	LD	HL,TH000
	LD	DE,$30
_TH_LOOP
	LD	(HL),B
	DEC	DE
	LD	A,D
	OR	E
	JR	NZ,_TH_LOOP


;--------------------------

	XOR	A		;チャージタイムを0021Hに設定する
	LD	(CNTR2),A
	LD	A,$21
	LD	(CNTR3),A

;---------------------------

	LD	A,(B_CNTR5)
	AND	$C0
	LD	B,$3F		;オフセットの初期値は3FH(+1FH)
	OR	B
	LD	(B_CNTR5),A
	LD	(CNTR5),A


;-------------------------------------


	LD	A,$10
	LD	($4000),A
	
	LD	A,(B_CNTR0)	;スタートビットを立てる
	SET	0,A
	LD	(CNTR0),A

_POLL1				;画像取得ポーリング
	LD	A,(CNTR0)
	BIT	0,A
	JR	NZ,_POLL1
		
	LD	A,(B_CNTR0)	;スタートビットを立てる
	SET	0,A
	LD	(CNTR0),A

_POLL2				;画像取得ポーリング
	LD	A,(CNTR0)
	BIT	0,A
	JR	NZ,_POLL2


;-------------------------------------------------------
_LOOP
	LD	A,$10
	LD	($4000),A
	
	LD	A,(B_CNTR0)	;スタートビットを立てる
	SET	0,A
	LD	(CNTR0),A

_POLL				;画像取得ポーリング
	LD	A,(CNTR0)
	BIT	0,A
	JR	NZ,_POLL

	CALL	CHECK_BLACK	;黒レベルに到達したか?
	OR	A		;Aレジスタが1のとき終了
	JR	NZ,_LOOP_END

	CALL	OFFSET_DOWN	;オフセットを下げて繰り返し
	OR	A		;Aレジスタが1のとき終了
	JR	Z,_LOOP

;--------------------------------------------------------
_LOOP_END

	LD	A,(B_CNTR2)	;チャージタイムを元に戻す
	LD	(CNTR2),A
	LD	A,(B_CNTR3)
	LD	(CNTR3),A

	RET


;=================
;CHECK_BLACK
;=================
CHECK_BLACK
	XOR	A
	LD	($4000),A	;RAM BANK 0
	
;	LD	HL,$AD0A
	LD	HL,$A770
	LD	E,$10
_LOOP
	LD	A,(HLI)
	CP	$FF
	JR	NZ,_RET

;	LD	A,(HLI)
;	CP	$FF
;	JR	NZ,_RET
;	LD	A,L
;	ADD	A,$0E
;	LD	L,A

	DEC	E
	JR	NZ,_LOOP

;---黒レベルがでた!
	LD	A,$10
	LD	($4000),A	;RAM BANK 10H
	LD	A,$01		;黒レベルが出たよフラグセット!
	RET

;---黒レベルは出なかった。オフセットを下げて出直そう
_RET
	LD	A,$10
	LD	($4000),A	;RAM BANK 10H
	XOR	A
	RET


;=================
;OFFSET_DOWN
;=================
OFFSET_DOWN
	LD	A,(B_CNTR5)

	BIT	5,A		;符号チェック
	JR	Z,_MINUS

;------------------------------
_PLUS
	AND	$3F		;下位6BITをみて
	CP	$20
	JR	Z,_PLUS_END	;現在+0の時は・・・_PLUS_END
	
	DEC	A		;減らす
;	SET	5,A		;符号ビットをたてる
	LD	B,$00
	JR	_DOWN_END
	
_PLUS_END			;-1にする
	LD	A,$01
	LD	B,$00
	JR	_DOWN_END

;------------------------------
_MINUS
	AND	$1F
	CP	$1F
	JR	NZ,_MINUS_DOWN
	LD	B,$01		;終了フラグ
	JR	_DOWN_END

_MINUS_DOWN
	INC	A		;へらす
	LD	B,$00

;-----------------------------
_DOWN_END
	LD	C,A
	LD	A,(B_CNTR5)
	AND	$C0
	OR	C
	LD	(B_CNTR5),A
	LD	(CNTR5),A

	LD	A,B		;一番下までいったかフラグ

	
	RET


;///////////////////////////////////////////////////////////////////////
;///////////////////////////////////////////////////////////////////////

;=======================================================
;
;   TRANSFER_TO_BUF
;
;     画像をバッファに転送する
;     Aレジスタ : パレットとモード
;=======================================================
TRANSFER_TO_BUF

	AND	$1F	; 下位5BITがモード
_TENSOU1
	CP	13
	JR	NZ,_TENSOU2
	CALL	TENSOU_TATE
	JP	_TENSOU_END

_TENSOU2
	CP	16
	JR	NZ,_TENSOU3
	CALL	TENSOU_YOKO
	JP	_TENSOU_END

_TENSOU3
	CP	2
	JR	NZ,_TENSOU4
	CALL	MIRROR_MODE
	JP	_TENSOU_END
_TENSOU4
	CP	8
	JR	NZ,_TENSOU5
	CALL	MABIKI_MODE
	JP	_TENSOU_END
_TENSOU5
	CP	9
	JR	NZ,_TENSOU6
	CALL	MABIKI_MODE2
	JP	_TENSOU_END
_TENSOU6
	CP	5
	JR	NZ,_TENSOU7
	CALL	TATE_NOBASI_MODE
	JP	_TENSOU_END
_TENSOU7
	CP	6
	JR	NZ,_TENSOU8
	CALL	YOKO_NOBASI_MODE
	JP	_TENSOU_END
_TENSOU8
	CP	7
	JR	NZ,_TENSOU0
	CALL	KAKUDAI_MODE
	JP	_TENSOU_END
_TENSOU0
	XOR	A
	LD	($4000),A
	
	LD	HL,$A100	
	LD	DE,$D000
	LD	B,$0E
	CALL	DATA_MOV_F
	JR	_TENSOU_END

_TENSOU_END

	RET

;=====================
AA,$AA,$AA,$AA,$AA,$AA,$AA
	
	DEFB	$AA,$AA,$AA,$B6,$1D,$A0,$A0,$A0,$A0
	DEFB	$A0,$A0,$A0,$A0,$A0,$A0,$A0,$1F
	DEFB	$AA,$AA,$AA,$AA,$AA,$AA,$AA,$AA
	DEFB	$AA,$AA,$AA,$AA,$AA,$AA,$AA

	DEFB	$AA,$AA,$AA,$AA,$1D,$A0,$A0,$A0,$A0
	DEFB	$A0,$A0,$A0,$A0,$␀タ�ツA0,$A0,$1F
	DEFB	$AA,$AA,$AA,$AA,$AA,$AA,$AA,$AA
	DEFB	$AA,$AA,$AA,$AA,$AA,$AA,$AA

	DEFB	$AA,$AA,$AA,$AA,$1D,$A0,$A0,$A0,$A0
	DEFB	$A0,$A0,$A0,$A0,$A0,$A0,$A0,$1F
	DEFB	$AA,$AA,$AA,$AA,$AA,$AA,$AA,$AA
	DEFB	$AA,$AA,$AA,$AA,$AA,$AA,$AA
	
	DEFB04
	DB	$59,$70,$87,$03,$03,$04
	DB	$5A,$70,$86,$03,$03,$04
	DB	$5B,$70,$85,$03,$03,$04
	DB	$5C,$70,$84,$03,$03,$04
	DB	$5D,$70,$83,$03,$03,$04
	DB	$5E,$70,$82,$03,$03,$04
	DB	$5F,$70,$81,$03,$03,$04
	DB	$60,$70,$80,$02,$02,$03
	DB	$61,$70,$7F,$02,$02,$03
	DB	$62,$70,$7E,$02,$02,$03
	DB	$63,$70,$7D,$02,$02,$03
	DB	$64,$70,$7C,$02,$02,$03
	DB	$65,$70,$7B,$02,$02,$03
	DB	$66,$70,$7A,$02,$02,$03
	DB	$67,$70,$79,$02,$02,$03
	DB	$68,$70,$78,$02,$02,$03
	DB	$69,$70,$77,$02,$02,$03
	DB	$6A,$70,$76,$02,$02,$03
	DB	$6B,$70,$75,$02,$02,$03
	DB	$6C,$70,$74,$02,$02,$03
	DB	$6D,$70,$73,$02,$02,$03
	DB	$6E,$70,$72,$02,$02,$03
	DB	$6F,$70,$71,$02,$02,$03
	DB	$70,$70,$70,$03,$03,$03

	
	
	
	DB	$60,$78,$A0,$03,$04,$04
	DB	$60,$74,$98,$03,$04,$04
	DB	$60,$70,$90,$02,$03,$04
	DB	$60,$6C,$84,$02,$03,$04
	DB	$60,$68,$78,$02,$02,$03
	
	
	
	
	DB	$68,$78,$98,$02,$03,$04
	DB	$70,$80,$A0,$02,$03,$04
	DB	$78,$88,$A8,$02,$03,$04
	DB	$80,$90,$B0,$02,$03,$04

	DB	$40,$60,$A0,$03,$05,$05	
	DB	$41,$60,$9E,$03,$05,$05
	DB	$42,$60,$9C,$03,$05,$05
	DB	$43,$60,$9A,$03,$05,$05

	DB	$44,$60,$98,$03,$05,$05
	DB	$45,$60,$96,$03,$05,$05
	DB	$46,$60,$94,$03,$05,$05
	DB	$47,$60,$92,$03,$05,$05

	DB	$48,$60,$90,$03,$04,$05
	DB	$49,$60,$8E,$03,$04,$05
	DB	$4A,$60,$8C,$03,$04,$05
	DB	$4B,$60,$8A,$03,$04,$05

	DB	$4C,$60,$88,$03,$04,$05
	DB	$4D,$60,$86,$03,$04,$05
	DB	$4E,$60,$84,$03,$04,$05
	DB	$4F,$60,$82,$03,$04,$05

	DB	$50,$60,$80,$03,$04,$05
	DB	$51,$60,$7E,$03,$04,$05
	DB	$52,$60,$7C,$03,$04,$05
	DB	$53,$60,$7A,$03,$04,$05

	DB	$54,$60,$78,$03,$04,$05
	DB	$55,$60,$76,$03,$04,$05
	DB	$56,$60,$74,$03,$04,$05
	DB	$57,$60,$72,$03,$04,$05

	DB	$58,$60,$70,$03,$04,$05
	DB	$59,$60,$6E,$03,$04,$05
	DB	$5A,$60,$6C,$03,$04,$05
	DB	$5B,$60,$6A,$03,$04,$05

	DB	$5C,$60,$68,$03,$04,$05
	DB	$5D,$60,$66,$03,$04,$05
	DB	$5E,$60,$64,$03,$04,$05
	DB	$5F,$60,$62,$03,$04,$05
	DB	$60,$60,$60,$04,$04,$04



	DB	$40,$58,$88,$03,$04,$05
	DB	$41,$58,$86,$03,$04,$05
	DB	$42,$58,$84,$03,$04,$05
	DB	$43,$58,$82,$03,$04,$05

	DB	$44,$58,$80,$03,$04,$05
	DB	$45,$58,$8E,$03,$04,$05
	DB	$46,$58,$7C,$03,$04,$05
	DB	$47,$58,$7A,$03,$04,$05

	DB	$48,$58,$78,$02,$03,$05
	DB	$49,$58,$76,$02,$03,$05
	DB	$4A,$58,$74,$02,$03,$05
	DB	$4B,$58,$72,$02,$03,$05

	DB	$4C,$58,$70,$02,$03,$05
	DB	$4D,$58,$6E,$02,$03,$05
	DB	$4E,$58,$6C,$02,$03,$05
	DB	$4F,$58,$6A,$02,$03,$05

	DB	$50,$58,$68,$02,$02,$04
	DB	$51,$58,$66,$02,$02,$04
	DB	$52,$58,$64,$02,$02,$04
	DB	$53,$58,$62,$02,$02,$04

	DB	$54,$58,$60,$02,$02,$04
	DB	$55,$58,$5E,$02,$02,$04
	DB	$56,$58,$5C,$02,$02,$04
	DB	$57,$58,$5A,$02,$02,$04
	DB	$58,$58,$58,$04,$04,$04



	DB	$40,$58,$A0,$03,$06,$05
	DB	$41,$58,$9D,$03,$06,$05
	DB	$42,$58,$9A,$03,$06,$05
	DB	$43,$58,$97,$03,$05,$05

	DB	$44,$58,$94,$03,$05,$05
	DB	$45,$58,$91,$03,$05,$05
	DB	$46,$58,$8E,$03,$05,$05
	DB	$47,$58,$8B,$03,$05,$05

	DB	$48,$58,$88,$02,$04,$05
	DB	$49,$58,$85,$02,$04,$05
	DB	$4A,$58,$82,$02,$04,$05
	DB	$4B,$58,$7F,$02,$04,$05

	DB	$4C,$58,$7C,$02,$04,$05
	DB	$4D,$58,$79,$02,$04,$05
	DB	$4E,$58,$76,$02,$03,$05
	DB	$4F,$58,$73,$02,$03,$05

	DB	$50,$58,$70,$02,$03,$04
	DB	$51,$58,$6D,$02,$03,$04
	DB	$52,$58,$6A,$02,$03,$04
	DB	$53,$58,$67,$02,$02,$04

	DB	$54,$58,$64,$02,$02,$04
	DB	$55,$58,$61,$02,$02,$04
	DB	$56,$58,$5E,$02,$02,$04
	DB	$57,$58,$5B,$02,$02,$04
	DB	$58,$58,$58,$04,$04,$04

	

NO_DITHER_PAT
	DB	$8,$8,$8,$8
	DB	$8,$8,$8,$8
	DB	$8,$8,$8,$8
	DB	$8,$8,$8,$8

BAYER_PAT
	DB	$0,$8,$2,$A
	DB	$C,$4,$E,$6
	DB	$3,$B,$1,$9
	DB	$F,$7,$D,$5
HARF_PAT
	DB	$A,$4,$6,$8
	DB	$C,$0,$1,$E
	DB	$7,$9,$B,$5
	DB	$3,$F,$D,$1
SCREW_PAT
	DB	$D,$7,$6,$C
	DB	$8,$1,$0,$5
	DB	$9,$2,$3,$4
	DB	$E,$A,$B,$F
SCREW2_PAT
	DB	$F,$4,$8,$C
	DB	$B,$0,$1,$5
	DB	$7,$3,$2,$9
	DB	$E,$A,$6,$D
TYUUKAN_PAT
	DB	$C,$4,$8,$E
	DB	$B,$0,$2,$6
	DB	$7,$3,$1,$A
	DB	$F,$9,$5,$D
CONCENT_PAT
	DB	$D,$4,$8,$E
	DB	$A,$0,$1,$7
	DB	$6,$3,$2,$B
	DB	$F,$9,$5,$C

	DB	$F,$0,$F,$0	;H
	DB	$F,$F,$F,$0
	DB	$F,$0,$F,$0
	DB	$0,$0,$0,$0
	
	DB	$8,$0,$8,$F	;斜線
	DB	$0,$8,$F,$8
	DB	$8,$F,$8,$0
	DB	$F,$8,$0,$8

	DB	$F,$0,$0,$0	;ばってん
	DB	$0,$F,$0,$F
	DB	$0,$0,$F,$0
	DB	$0,$F,$0,$F

	DB	$7,$3,$7,$B	;白丸
	DB	$3,$0,$3,$7
	DB	$7,$3,$7,$B
	DB	$B,$7,$B,$F

	DB	$8,$8,$8,$0	;■
	DB	$8,$F,$8,$0
	DB	$8,$8,$8,$0
	DB	$0,$0,$0,$0
	
	
;*******************************************
;* チャージタイム決定時に使用するテーブル  *
;*******************************************
CHG_TIME_TBL_U
	DB	$10,$07,$06,$06,$06,$05,$05,$05
	DB	$05,$05,$04,$04,$04,$04,$04,$04
	DB	$03,$03,$03,$03,$03,$03,$03,$03
	DB	$02,$02,$02,$02,$02,$02,$02,$02
	DB	$02,$02,$02,$02,$02,$02,$02,$02
	DB	$01,$01,$01,$01,$01,$01,$01,$01
	DB	$01,$01,$01,$01,$01,$01,$01,$01
	DB	$01,$01,$01,$01,$01,$01,$01,$01
	DB	$01,$01,$01,$01,$01,$01,$01,$01
	DB	$01,$01,$01,$01,$01,$01,$01,$01
	DB	$01,$01,$01,$01,$01,$01,$01,$01
	DB	$01,$01,$01,$01,$01,$01,$01,$01
	DB	$01,$01,$01,$01,$01,$01,$01,$01
	DB	$00,$00,$00,$00,$00,$00,$00,$00
	DB	$00,$00,$00,$00,$00,$00,$00,$00
	DB	$00,$00,$00,$00,$00,$00,$00,$00
	DB	$00,$00,$00,$00,$00,$00,$00,$00
	DB	$00,$00,$00,$00,$00,$00,$00,$00
	DB	$00,$00,$00,$00,$00,$00,$00,$00
	DB	$00,$00,$00,$00,$00,$00,$00,$00
	DB	$00,$00,$00,$00,$00,$00,$00,$00
	DB	$00

CHG_TIME_TBL_D
	DB	$10,$07,$06,$06,$06,$05,$05,$05
	DB	$05,$05,$04,$04,$04,$04,$04,$04
	DB	$03,$03,$03,$03,$03,$03,$03,$03
	DB	$02,$02,$02,$02,$02,$02,$02,$02
	DB	$02,$02,$02,$02,$02,$02,$02,$02
	DB	$01,$01,$01,$01,$01,$01,$01,$01
	DB	$01,$01,$01,$01,$01,$01,$01,$01
	DB	$01,$01,$01,$01,$01,$01,$01,$01
	DB	$01,$01,$01,$01,$01,$01,$01,$01
	DB	$01,$01,$01,$01,$01,$01,$01,$01
	DB	$01,$01,$01,$01,$01,$01,$01,$01
	DB	$01,$01,$01,$01,$01,$01,$01,$01
	DB	$01,$01,$01,$01,$01,$01,$01,$01
	DB	$01,$01,$01,$01,$01,$01,$01,$01
	DB	$01,$01,$01,$01,$01,$01,$01,$01
	DB	$01,$01,$01,$01,$01,$01,$01,$01
	DB	$01,$01,$01,$01,$01,$01,$01,$01
	DB	$01,$01,$01,$01,$01,$01,$01,$01
	DB	$01,$01,$01,$01,$01,$01,$01,$01
	DB	$01,$01,$01,$01,$01,$01,$01,$01
	DB	$01,$01,$01,$01,$01,$01,$01,$01
	DB	$01


;*********************************
;* ミラーモード用のテーブル      *
;*********************************
	ORG	$3D00
MIRROR_TABLE
	DB	$00,$80,$40,$C0,$20,$A0,$60,$E0
	DB	$10,$90,$50,$D0,$30,$B0,$70,$F0
	DB	$08,$88,$48,$C8,$28,$A8,$68,$E8
	DB	$18,$98,$58,$D8,$38,$B8,$78,$F8
	DB	$04,$84,$44,$C4,$24,$A4,$64,$E4
	DB	$14,$94,$54,$D4,$34,$B4,$74,$F4
	DB	$0C,$8C,$4C,$CC,$2C,$AC,$6C,$EC
	DB	$1C,$9C,$5C,$DC,$3C,$BC,$7C,$FC
	DB	$02,$82,$42,$C2,$22,$A2,$62,$E2
	DB	$12,$92,$52,$D2,$32,$B2,$72,$F2
	DB	$0A,$8A,$4A,$CA,$2A,$AA,$6A,$EA
	DB	$1A,$9A,$5A,$DA,$3A,$BA,$7A,$FA
	DB	$06,$86,$46,$C6,$26,$A6,$66,$E6
	DB	$16,$96,$56,$D6,$36,$B6,$76,$F6
	DB	$0E,$8E,$4E,$CE,$2E,$AE,$6E,$EE
	DB	$1E,$9E,$5E,$DE,$3E,$BE,$7E,$FE
	DB	$01,$81,$41,$C1,$21,$A1,$61,$E1
	DB	$11,$91,$51,$D1,$31,$B1,$71,$F1
	DB	$09,$89,$49,$C9,$29,$A9,$69,$E9
	DB	$19,$99,$59,$D9,$39,$B9,$79,$F9
	DB	$05,$85,$45,$C5,$25,$A5,$65,$E5
	DB	$15,$95,$55,$D5,$35,$B5,$75,$F5
	DB	$0D,$8D,$4D,$CD,$2D,$AD,$6D,$ED
	DB	$1D,$9D,$5D,$DD,$3D,$BD,$7D,$FD
	DB	$03,$83,$43,$C3,$23,$A3,$63,$E3
	DB	$13,$93,$53,$D3,$33,$B3,$73,$F3
	DB	$0B,$8B,$4B,$CB,$2B,$AB,$6B,$EB
	DB	$1B,$9B,$5B,$DB,$3B,$BB,$7B,$FB
	DB	$07,$87,$47,$C7,$27,$A7,$67,$E7
	DB	$17,$97,$57,$D7,$37,$B7,$77,$F7
	DB	$0F,$8F,$4F,$CF,$2F,$AF,$6F,$EF
	DB	$1F,$9F,$5F,$DF,$3F,$BF,$7F,$FF


;********************************************
;* バイト中のビットの数を数える為のテーブル *
;********************************************
	ORG	$3E00
COUNT_TABLE
	DB	$00,$01,$01,$02,$01,$02,$02,$03
	DB	$01,$02,$02,$03,$02,$03,$03,$04
	DB	$01,$02,$02,$03,$02,$03,$03,$04
	DB	$02,$03,$03,$04,$03,$04,$04,$05
	DB	$01,$02,$02,$03,$02,$03,$03,$04
	DB	$02,$03,$03,$04,$03,$04,$04,$05
	DB	$02,$03,$03,$04,$03,$04,$04,$05
	DB	$03,$04,$04,$05,$04,$05,$05,$06
	DB	$01,$02,$02,$03,$02,$03,$03,$04
	DB	$02,$03,$03,$04,$03,$04,$04,$05
	DB	$02,$03,$03,$04,$03,$04,$04,$05
	DB	$03,$04,$04,$05,$04,$05,$05,$06
	DB	$02,$03,$03,$04,$03,$04,$04,$05
	DB	$03,$04,$04,$05,$04,$05,$05,$06
	DB	$03,$04,$04,$05,$04,$05,$05,$06
	DB	$04,$05,$05,$06,$05,$06,$06,$07
	DB	$01,$02,$02,$03,$02,$03,$03,$04
	DB	$02,$03,$03,$04,$03,$04,$04,$05
	DB	$02,$03,$03,$04,$03,$04,$04,$05
	DB	$03,$04,$04,$05,$04,$05,$05,$06
	DB	$02,$03,$03,$04,$03,$04,$04,$05
	DB	$03,$04,$04,$05,$04,$05,$05,$06
	DB	$03,$04,$04,$05,$04,$05,$05,$06
	DB	$04,$05,$05,$06,$05,$06,$06,$07
	DB	$02,$03,$03,$04,$03,$04,$04,$05
	DB	$03,$04,$04,$05,$04,$05,$05,$06
	DB	$03,$04,$04,$05,$04,$05,$05,$06
	DB	$04,$05,$05,$06,$05,$06,$06,$07
	DB	$03,$04,$04,$05,$04,$05,$05,$06
	DB	$04,$05,$05,$06,$05,$06,$06,$07
	DB	$04,$05,$05,$06,$05,$06,$06,$07
	DB	$05,$06,$06,$07,$06,$07,$07,$08

CK
	LD	de,BUF_ADR+$940
	CALL	LINE_CHECK
	ENDIF

;------------黒点数え(画面全体)----------------------
	ifn	ZENTAI
	LD	BC,$00
	
	LD	DE,BUF_ADR
	CALL	SCREEN_CHECK

	endif

;********この時点で、BCに黒点の個数が入っている***********
;********    BCのとりうる値は 0000~1500H      ***********

_COUNT_END

	LD	A,(AKARUSA)
	LD	D,A		; AKARUSAが、黒点の数の目標値(0~A8)

	SLA	C	B_TH320)
	LD	(HLI),A
	LD	A,(B_TH321)
	LD	(HLI),A
	LD	A,(B_TH322)
	LD	(HLI),A
	LD	A,(B_TH330)
	LD	(HLI),A
	LD	A,(B_TH331)
	LD	(HLI),A
	LD	A,(B_TH332)
	LD	(HLI),A
	
	R_RAMBK

	RET



;=========================================================
;  REGISTER_SETTING
;
;   人工網膜チップのレジスタの設定
;
;   Aレジスタ : 上位4ビット エッジの強さ 0~7
;		下位4ビット モード 0:負画像
;				   1:横エッジ強調
;				   2:縦エッジ強調
;				   3:二次元エッジ強調
;				   4:横エッジ
;				   5:縦エッジ
;				   6:二次元エッジ
;==========================================================
REGISTER_SETTING
	LD	B,A	;モードとエッジの強さ
	
	AND	$0F
	CP	$00
	JR	Z,_FUGAZOU
	CP	$01
	JR	Z,_YOKO_KYOUTYOU
	CP	$02
	JR	Z,_TATE_KYOUTYOU
	CP	$03
	JR	Z,_NIJIGEN_KYOUTYOU
	CP	$04
	JR	Z,_YOKO_EDGE
	CP	$05
	JR	Z,_TATE_EDGE
	JR	_NIJIGEN_EDGE


;--------------負画像------------------
_FUGAZOU
	LD	A,$02
	LD	(B_CNTR0),A
	LD	A,$02
	LD	(CNTR1),A
	LD	(B_CNTR1),A
	LD	A,$02
	LD	(CNTR4),A
	LD	(B_CNTR4),A
;	LD	A,$80
;	LD	(B_CNTR5),A
	JR	_REGI_SET_END

;-----------横エッジ強調--------------
_YOKO_KYOUTYOU
	LD	A,$02
	LD	(B_CNTR0),A
	LD	A,$22
	LD	(B_CNTR1),A
	LD	(CNTR1),A
	
	LD	A,B
	AND	$F0
	CP	$00
	JR	Z,_EDGE_YOWAI1
	CP	$10
	JR	Z,_EDGE_YOWAI1
	CP	$20
	JR	Z,_EDGE_YOWAI1
	ADD	A,$6
	JR	_V_SET_YK
_EDGE_YOWAI1
	ADD	A,$03
_V_SET_YK
	LD	(CNTR4),A
	LD	(B_CNTR4),A
;	LD	A,$80
;	LD	(B_CNTR5),A
	
	JR	_REGI_SET_END
	
;-----------縦エッジ強調--------------
_TATE_KYOUTYOU

	JR	_REGI_SET_END
	
;---------二次元エッジ強調------------

_NIJIGEN_KYOUTYOU
	LD	A,$00
	LD	(B_CNTR0),A
	LD	A,$E2
	LD	(B_CNTR1),A
	LD	(CNTR1),A

	LD	A,B
	AND	$F0
	CP	$00
	JR	Z,_EDGE_YOWAI
	CP	$10
	JR	Z,_EDGE_YOWAI
	CP	$20
	JR	Z,_EDGE_YOWAI
	CP	$30
	JR	Z,_EDGE_TYUU
	ADD	A,$6
	JR	_V_SET
_EDGE_YOWAI
	ADD	A,$03
	JR	_V_SET
_EDGE_TYUU
	ADD	A,$04
	
_V_SET
	LD	(CNTR4),A
	LD	(B_CNTR4),A
;	LD	A,$80
;	LD	(B_CNTR5),A
	JR	_REGI_SET_END

;--------------横エッジ-----------------
_YOKO_EDGE

	JR	_REGI_SET_END
	
;--------------縦エッジ-----------------
_TATE_EDGE

	JR	_REGI_SET_END
	
;------------二次元エッジ---------------
_NIJIGEN_EDGE
	JR	_REGI_SET_END
	
_REGI_SET_END

	RET


;///////////////////////////////////////////////////////////////////
;///////////////////////////////////////////////////////////////////


;=====================================================
;
;   オフセット調整
;
;  閾値が変更されるので、この後ディザの設定をすること
;=====================================================
GET_OFFSET

;-------------------------
	LD	A,$10		; RAMBK $10
	LD	($4000),A

	LD	B,$55		;閾値を55H(1V)に設定する
	LD	HL,TH000
	LD	DE,$30
_TH_LOOP
	LD	(HL),B
	DEC	DE
	LD	A,D
	OR	E
	JR	NZ,_TH_LOOP


;--------------------------

	XOR	A		;チャージタイムを0000Hに設定する
	LD	(CNTR2),A
	LD	(CNTR3),A

;---------------------------

	LD	A,(B_CNTR5)
	AND	$C0
	LD	B,$3F		;オフセットの初期値は3FH(+1FH)
	OR	B
	LD	(B_CNTR5),A
	LD	(CNTR5),A


;-------------------------------------


	LD	A,$10
	LD	($4000),A
	
	LD	A,(B_CNTR0)	;スタートビットを立てる
	SET	0,A
	LD	(CNTR0),A

_POLL1				;画像取得ポーリング
	LD	A,(CNTR0)
	BIT	0,A
	JR	NZ,_POLL1
		
	LD	A,(B_CNTR0)	;スタートビットを立てる
	SET	0,A
	LD	(CNTR0),A

_POLL2				;画像取得ポーリング
	LD	A,(CNTR0)
	BIT	0,A
	JR	NZ,_POLL2


;-------------------------------------------------------
_LOOP
	LD	A,$10
	LD	($4000),A
	
	LD	A,(B_CNTR0)	;スタートビットを立てる
	SET	0,A
	LD	(CNTR0),A

_POLL				;画像取得ポーリング
	LD	A,(CNTR0)
	BIT	0,A
	JR	NZ,_POLL

	CALL	CHECK_BLACK	;黒レベルに到達したか?
	OR	A		;Aレジスタが1のとき終了
	JR	NZ,_LOOP_END

	CALL	OFFSET_DOWN	;オフセットを下げて繰り返し
	OR	A		;Aレジスタが1のとき終了
	JR	Z,_LOOP

;--------------------------------------------------------
_LOOP_END

	LD	A,(B_CNTR2)	;チャージタイムを元に戻す
	LD	(CNTR2),A
	LD	A,(B_CNTR3)
	LD	(CNTR3),A

	RET


;=================
;CHECK_BLACK
;=================
CHECK_BLACK
	XOR	A
	LD	($4000),A	;RAM BANK 0
	
	LD	HL,$AD0A
	LD	E,$10
_LOOP
	LD	A,(HLI)
	CP	$FF
	JR	NZ,_RET

	LD	A,(HLI)
	CP	$FF
	JR	NZ,_RET

	LD	A,L
	ADD	A,$0E
	LD	L,A

	DEC	E
	JR	NZ,_LOOP

;---黒レベルがでた!
	LD	A,$10
	LD	($4000),A	;RAM BANK 10H
	LD	A,$01		;黒レベルが出たよフラグセット!
	RET

;---黒レベルは出なかった。オフセットを下げて出直そう
_RET
	LD	A,$10
	LD	($4000),A	;RAM BANK 10H
	XOR	A
	RET


;=================
;OFFSET_DOWN
;=================
OFFSET_DOWN
	LD	A,(B_CNTR5)

	BIT	5,A		;符号チェック
	JR	Z,_MINUS

;------------------------------
_PLUS
	AND	$3F		;下位6BITをみて
	CP	$20
	JR	Z,_PLUS_END	;現在+0の時は・・・_PLUS_END
	
	DEC	A		;減らす
;	SET	5,A		;符号ビットをたてる
	LD	B,$00
	JR	_DOWN_END
	
_PLUS_END			;-1にする
	LD	A,$01
	LD	B,$00
	JR	_DOWN_END

;------------------------------
_MINUS
	AND	$1F
	CP	$1F
	JR	NZ,_MINUS_DOWN
	LD	B,$01		;終了フラグ
	JR	_DOWN_END

_MINUS_DOWN
	INC	A		;へらす
	LD	B,$00

;-----------------------------
_DOWN_END
	LD	C,A
	LD	A,(B_CNTR5)
	AND	$C0
	OR	C
	LD	(B_CNTR5),A
	LD	(CNTR5),A

	LD	A,B		;一番下までいったかフラグ

	
	RET


;///////////////////////////////////////////////////////////////////////
;///////////////////////////////////////////////////////////////////////

;=======================================================
;
;   TRANSFER_TO_BUF
;
;     画像をバッファに転送する
;     Aレジスタ : パレットとモード
;=======================================================
TRANSFER_TO_BUF

	AND	$1F	; 下位5BITがモード
_TENSOU1
	CP	13
	JR	NZ,_TENSOU2
	CALL	TENSOU_TATE
	JP	_TENSOU_END

_TENSOU2
	CP	16
	JR	NZ,_TENSOU3
	CALL	TENSOU_YOKO
	JP	_TENSOU_END

_TENSOU3
	CP	2
	JR	NZ,_TENSOU4
	CALL	MIRROR_MODE
	JP	_TENSOU_END
_TENSOU4
	CP	8
	JR	NZ,_TENSOU5
	CALL	MABIKI_MODE
	JP	_TENSOU_END
_TENSOU5
	CP	9
	JR	NZ,_TENSOU6
	CALL	MABIKI_MODE2
	JP	_TENSOU_END
_TENSOU6
	CP	5
	JR	NZ,_TENSOU7
	CALL	TATE_NOBASI_MODE
	JP	_TENSOU_END
_TENSOU7
	CP	6
	JR	NZ,_TENSOU8
	CALL	YOKO_NOBASI_MODE
	JP	_TENSOU_END
_TENSOU8
	CP	7
	JR	NZ,_TENSOU0
	CALL	KAKUDAI_MODE
	JP	_TENSOU_END
_TENSOU0
	XOR	A
	LD	($4000),A
	
	LD	HL,$A100	
	LD	DE,$D000
	LD	B,$0E
	CALL	DATA_MOV_F
	JR	_TENSOU_END

_TENSOU_END

	RET

;============================================


;--  DDDD   AAA  TTTTT  AAA  ---------------
;--  D   D A   A   T   A   A ---------------
;--  D   D AAAAA   T   AAAAA ---------------
;--  D   D A   A   T   A   A ---------------
;--  DDDD  A   A   T   A   A ---------------

;****'(,$5C,$5C	;0155
	DEFB	$98,$98,$18,$18,$1E,$1E,$00,$00
	DEFB	$1B,$18,$1B,$18,$1C,$18,$1C,$18	;0156
	DEFB	$1B,$18,$1B,$18,$1C,$18,$1C,$18
	DEFB	$FF,$09,$FF,$0F,$FF,$09,$FF,$00	;0157
	DEFB	$FF,$00,$FF,$00,$FF,$00,$FF,$00
	DEFB	$FF,$1F,$FF,$04,$FF,$04,$F␀ミ�ツ0	;0158
	DEFB	$FF,$00,$FF,$00,$FF,$00,$FF,$00
	DEFB	$E0,$1F,$FC,$03,$FC,$03,$FC,$03	;0159
	DEFB	$FF,$00,$FF,$00,$FF,$00,$FF,$00
	DEFB	$1F,$E0,$FF,$00,$FF,$00,$FF,$00	;015A
	DEFB	$FF,$00,$FF,$00,$FF,$00,$FF,$00
	DEFB	$FF,$A8,$FF,$00,$FF,$00,$FF,$0