/*
Nuclear Disco version 2 For X100 Mobile Phone By NeO_2kX(c)
*/

.include "NuclearDiscoUnit.h"

.start 0x00129616
	BL		Call_lk_InvertDisplayBackLight
	B		0x00129620

Call_lk_InvertDisplayBackLight:
	LDR		R0, Data
	BX		R0

.start 0x00129658
Data:
	DCD		hen_MyMelodyLedOn+1


NuclearDiscoStart:
hen_MyMelodyLedOn:
PUSH	{LR}
	LDR		R0, =0x142A070
	LDRB	R0, [R0]
	CMP		R0, #1
	BEQ		hen_MMLedOn_StopLight

	BL		IsJavaState
	CMP		R0, #0
	BNE		hen_MMLedOn_Continue
	
	BL		check_low_info
	CMP		R0, #0
	BNE		hen_MMLedOn_Continue
	
	BL		CheckInCallState
	CMP		R0, #0
	BEQ		hen_MyMelodyLedOn_Start
	
	ADR		R0, =EnableInCall
	LDRB	R0, [R0]
	
	CMP		R0, #0
	BEQ		hen_MMLedOn_Continue
	
hen_MyMelodyLedOn_Start:	
	BL		lk_InvertDisplayBackLight

hen_MMLedOn_Continue:	
	LDR		R0, =0x00081066
	BL		Call_RtkStopTimer
	
	LDR		R0, =v_hen_PA_TypeSource2
	LDRB	R1, [R0, #0x18]
	
POP		{PC}
.data
hen_MMLedOn_StopLight:
	LDR		R0, =N2X_BackLightFlag
	LDRB	R0, [R0]
	
	CMP		R0, #0
	BEQ		hen_MMLedOn_Continue
	
	BL		Hw_DisplayBackLightDisable
	BL		Hard_KeypadBacklightOff
	B		hen_MMLedOn_Continue
.data

.align 1
lk_InvertDisplayBackLight:
PUSH	{R0-R1, LR}
	LDR		R0, =N2X_BackLightFlag
	LDRB	R1, [R0]
	CMP		R1, #1
	BEQ		lk_IDBL_Off
	
	ADD		R1, #1
	STRB	R1, [R0]
	BL		Hw_DisplayBackLightEnable
	BL		Hard_KeypadBacklightOn
	B		lk_InvertDisplayBackLight_Exit

lk_IDBL_Off:
	SUB		R1, #1
	STRB	R1, [R0]
	BL		Hw_DisplayBackLightDisable
	BL		Hard_KeypadBacklightOff
	
lk_InvertDisplayBackLight_Exit:
POP		{R0-R1, PC}
.align 2
EnableInCall:
.hex 01
.data

@Включает подсветку дисплея
Hw_DisplayBackLightEnable:
PUSH	{R0-R2, LR}
	LDR		R0, =0xFFFF8400
	LDRH	R1, [R0, #10]
	MOV		R2, #0x10
	ORR		R1, R2
	STRH	R1, [R0, #10]
POP		{R0-R2, PC}

@Выключает подсветку дисплея
Hw_DisplayBackLightDisable:
PUSH	{R0-R2, LR}
	LDR		R0, =0xFFFF8400
	LDRH	R1, [R0, #10]
	MOV		R2, #0x10
	BIC		R1, R2
	STRH	R1, [R0, #10]
POP		{R0-R2, PC}

@Выключение подсветки клавиатуры
@void Hard_KeypadBacklightOff(void)
Hard_KeypadBacklightOff:
PUSH	{R0-R1, R3, LR}
	LDR		R0, =0xFFFF8400
	LDRH	R1, [R0, #10]
	MOV		R3, #0xFF
	ADD		R3, #0x1
	BIC		R1, R3
	STRH	R1, [R0, #10]
POP		{R0-R1, R3, PC}

@Включение подсветки клавиатуры
@void Hard_KeypadBacklightOn(void)
Hard_KeypadBacklightOn:
PUSH	{R0-R1, R3, LR}
	LDR		R0, =0xFFFF8400
	LDRH	R1, [R0, #10]
	MOV		R3, #0xFF
	ADD		R3, #0x1
	ORR		R1, R3
	STRH	R1, [R0, #10]
POP		{R0-R1, R3, PC}
.data

Call_RtkStopTimer:
	LDR		R2, =_RtkStopTimer
	BX		R2
.data
