⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ap_message2.s01

📁 5807收音机模块用于炬力平台
💻 S01
📖 第 1 页 / 共 2 页
字号:
	NAME	ap_message2(17)
	RSEG	COM_MSG(0)
	RSEG	UDATA0(0)
	RSEG	IDATA0(0)
	RSEG	CDATA0(0)
	PUBLIC	EarProtectThreshold
	EXTERN	ap_get_message
	PUBLIC	ap_get_message_core
	EXTERN	ap_handle_hotkey
	PUBLIC	ap_handle_hotkey_core
	PUBLIC	ap_message_init
	PUBLIC	ap_sleep
	PUBLIC	g_EarProtect_flag
	PUBLIC	g_charge_counter
	EXTERN	g_comval
	PUBLIC	g_decrease_time
	PUBLIC	g_half_hour_counter
	PUBLIC	g_light_time
	PUBLIC	g_rtc_counter
	PUBLIC	g_sleep_time
	PUBLIC	g_standby_time
	EXTERN	sKY_Beep
	EXTERN	sKY_ChargeGetandSet
	EXTERN	sKY_CloseBacklight
	EXTERN	sKY_OpenBacklight
	EXTERN	ui_run_realtime
	EXTERN	ui_show_lock
	EXTERN	?CLZ80B_4_04_L00
	EXTERN	?S_MUL_L02
	EXTERN	?C_V_SWITCH_L06
	EXTERN	?BANK_CALL_DIRECT_L08
	EXTERN	?BANK_FAST_LEAVE_L08
	RSEG	COM_MSG
ap_message_init:
; 1.	/*
; 2.	*******************************************************************************
; 3.	*                ACTOS AP
; 4.	*        ap common lib message file
; 5.	*
; 6.	*        (c) Copyright, Actions Co,Ld.
; 7.	*             All Right Reserved
; 8.	*
; 9.	*******************************************************************************
; 10.	*/
; 11.	#pragma codeseg(COM_MSG)
; 12.	
; 13.	#include "ap_common.h"
; 14.	#define DEBUG
; 15.	
; 16.	#ifdef EAR_PROTECT
; 17.	    #define     EarProctetTimeTick     60    //30 seconds
; 18.	    byte g_decrease_time = 0;
; 19.	    int g_half_hour_counter = 0;
; 20.	    //int g_autoswitch_counter = 0;
; 21.	    byte g_EarProtect_flag;
; 22.	    byte EarProtectThreshold;
; 23.	    //int g_autoswitch_time;
; 24.	#endif
; 25.	BYTE g_light_time=0;    //关背光时间,0.5秒为单位
; 26.	WORD g_sleep_time=0;    //睡眠时间,0.5秒为单位
; 27.	WORD g_standby_time=0;    //自动关机时间,0.5秒为单位
; 28.	WORD g_rtc_counter=0;    //rtc 消息计数
; 29.	BYTE g_charge_counter = 0; //检测充电状态的计数器,插上USB就开始检测第一次
; 30.	extern comval_t g_comval; 
; 31.	//WORD g_ap_event=0;    //事件标志
; 32.	/*
; 33.	char g_ap_message[4]={0, 0, 0, 0};    //ap 消息队列
; 34.	char g_ap_message_index=0;        //ap 消息队列的读写指针
; 35.	*/
; 36.	
; 37.	/*
; 38.	  * 对于普通按键的处理存在隐患,如果os把普通按键的值定义到0x20 以上,
; 39.	  * ap_get_message() 将不能正确处理, 正确的做法是用9个case, 不用default
; 40.	  */
; 41.	#if  Msg_KeyEQ > 0x20  || Msg_KeyMenu > 0x20 || \
; 42.	    Msg_KeyNext > 0x20 || Msg_KeyLast > 0x20 || \
; 43.	    Msg_KeyVolAdd > 0x20 || Msg_KeyVolSub > 0x20 || \
; 44.	    Msg_KeyPlayPause > 0x20 || Msg_KeyREC > 0x20 || Msg_KeyLoop > 0x20
; 45.	
; 46.	#error os define key greater than 0x20
; 47.	#endif
; 48.	
; 49.	/*
; 50.	********************************************************************************
; 51.	* Description : 初始化消息处理
; 52.	*
; 53.	* Arguments   : comval, 系统设定值, =null 表示只初始化内部计数器
; 54.	*
; 55.	* Returns     :
; 56.	*                           
; 57.	* Notes       :
; 58.	*
; 59.	********************************************************************************
; 60.	*/
; 61.	void ap_message_init(const comval_t *comval)
; 62.	{
	PUSH	BC
	PUSH	IX
	PUSH	DE
	POP	IX
; 63.	
; 64.	    if(comval != NULL)
	LD	A,E
	OR	D
	JR	Z,?0005
?0004:
; 65.	    {
; 66.	        g_light_time = comval->LightTime * 2;
	LD	A,(IX+9)
	ADD	A,A
	LD	(g_light_time),A
; 67.	
; 68.	        g_sleep_time = comval->SleepTime * 60 * 2;
	LD	C,(IX+11)
	LD	B,0
	LD	DE,60
	CALL	LWRD ?S_MUL_L02
	EX	DE,HL
	ADD	HL,HL
	LD	(g_sleep_time),HL
; 69.	
; 70.	        g_standby_time = comval->StandbyTime * 2;
	LD	L,(IX+10)
	LD	H,B
	ADD	HL,HL
	LD	(g_standby_time),HL
; 71.	        #ifdef EAR_PROTECT
; 72.	        g_EarProtect_flag = comval->EarProtect_flag;
	LD	A,(IX+24)
	LD	(g_EarProtect_flag),A
; 73.	        EarProtectThreshold = comval->EarProtectThreshold;
	LD	A,(IX+25)
	LD	(EarProtectThreshold),A
?0005:
; 74.	        //g_autoswitch_time = comval->auto_switchoff_time * 60 * 2;
; 75.	        #endif
; 76.	    }
; 77.	
; 78.	    g_rtc_counter = 0;
	LD	HL,0
	LD	(g_rtc_counter),HL
; 79.	}
	POP	IX
	POP	BC
	JP	LWRD ?BANK_FAST_LEAVE_L08
ap_get_message_core:
; 80.	
; 81.	
; 82.	/*
; 83.	********************************************************************************
; 84.	* Description : 处理系统消息, 返回按键消息, 同时负责开/关背光
; 85.	*
; 86.	* Arguments   : key, 系统消息
; 87.	*
; 88.	* Returns     : 返回ap能够识别的消息, 如果没有系统消息, 返回 AP_KEY_NULL
; 89.	*
; 90.	* Notes       :
; 91.	
; 92.	* 按键时序:
; 93.	 *  0.....1.2....1.5........... (s)
; 94.	 *  key    long   hold    up    (>1.2s)
; 95.	 *  key  up            (<1.2s)
; 96.	 *
; 97.	 * key rate: 0.3s
; 98.	*
; 99.	********************************************************************************
; 100.	*/
; 101.	char ap_get_message_core(char key)
; 102.	{
	PUSH	BC
	PUSH	IX
	LD	IX,0
	ADD	IX,SP
	PUSH	DE
	PUSH	AF
; 103.	    static WORD key_count=0;        //当前按键消息发生的次数
; 104.	    static char key_value=Msg_KeyNull;        //当前按键的值
; 105.	    #ifdef EAR_PROTECT
; 106.	        char tempVolume;
; 107.	        bool counter_flag = FALSE;
; 108.	        
; 109.	        tempVolume = input8(0x99)&0x1f;
	IN	A,(153)
	AND	31
	LD	(IX-4),A
; 110.	        if (tempVolume > EarProtectThreshold)
	LD	B,A
	LD	A,(EarProtectThreshold)
	CP	B
	JR	NC,?0009
?0008:
; 111.	        {              
; 112.	               counter_flag = TRUE;
	LD	(IX-3),1
; 113.	        }
; 114.	        else
	JR	?0010
?0009:
; 115.	        {
; 116.	            counter_flag = FALSE;
	LD	(IX-3),0
?0010:
; 117.	        }
; 118.	            
; 119.	        if ( g_EarProtect_flag && (tempVolume > EarProtectThreshold) && (g_decrease_time == EarProctetTimeTick) )
	LD	A,(g_EarProtect_flag)
	OR	A
	JR	Z,?0012
	LD	A,(EarProtectThreshold)
	CP	B
	JR	NC,?0012
	LD	A,(g_decrease_time)
	CP	60
	JR	NZ,?0012
?0014:
?0013:
?0011:
; 120.	        {
; 121.	            output8(0x99, input(0x99)&0xe0|(tempVolume-1));
	LD	BC,153
	IN	D,(C)
	LD	A,D
	AND	224
	PUSH	AF
	LD	A,(IX-4)
	ADD	A,255
	LD	B,A
	POP	AF
	OR	B
	OUT	(153),A
; 122.	            g_decrease_time = 0;
	XOR	A
	LD	(g_decrease_time),A
?0012:
; 123.	        }
; 124.	        if ( g_EarProtect_flag && (g_half_hour_counter == 7200) )
	LD	A,(g_EarProtect_flag)
	OR	A
	JR	Z,?0016
	LD	HL,7200
	LD	BC,(g_half_hour_counter)
	SBC	HL,BC
	JR	NZ,?0016
?0018:
?0017:
?0015:
; 125.	        {
; 126.	              if (tempVolume > 10)
	LD	A,10
	CP	(IX-4)
	JR	NC,?0020
?0019:
; 127.	              {
; 128.	                output8(0x99, input(0x99)&0xe0|(tempVolume-1));
	LD	BC,153
	IN	D,(C)
	LD	A,D
	AND	224
	PUSH	AF
	LD	A,(IX-4)
	ADD	A,255
	LD	B,A
	POP	AF
	OR	B
	OUT	(153),A
?0020:
; 129.	            }
; 130.	            g_half_hour_counter = 0;
	LD	(g_half_hour_counter),HL
?0016:
; 131.	        }
; 132.	    #endif
; 133.	
; 134.	    //和上次的一样
; 135.	    if(key == key_value)
	LD	A,(?0007)
	LD	B,A
	LD	A,E
	CP	B
	JR	NZ,?0022
?0021:
; 136.	    {
; 137.	//          if(g_comval.KeyTone)        //key tone add by mzh 2007.3.14
; 138.	//                  sKY_Beep(g_comval.KeyTone); 
; 139.	        //开背光
; 140.	        if(g_light_time != 0) sKY_OpenBacklight();
	LD	A,(g_light_time)
	OR	A
	JR	Z,?0024
?0023:
	CALL	LWRD sKY_OpenBacklight
?0024:
; 141.	
; 142.	        g_rtc_counter = 0;
	LD	HL,0
	LD	(g_rtc_counter),HL
; 143.	        key_count++;
	LD	HL,(?0006)
	INC	HL
	LD	(?0006),HL
; 144.	        //key rate: ...0.3...0.3...0.3...0.3
; 145.	        if(key_count == 4) key |= AP_KEY_LONG;    //=1.2s
	LD	A,4
	XOR	L
	OR	H
	JR	NZ,?0026
?0025:
	SET	7,(IX-2)
	JP	LWRD ?0089
?0026:
; 146.	        else if(key_count > 4) key |= AP_KEY_HOLD;
	LD	C,L
	LD	B,H
	LD	HL,4
	SBC	HL,BC
	JP	NC,?0089
?0028:
	SET	6,(IX-2)
?0029:
?0027:
; 147.	        return key;
	JP	LWRD ?0089
; 148.	    }
?0022:
; 149.	
; 150.	    switch( key )
	CALL	LWRD ?C_V_SWITCH_L06
	DEFW	12
	DEFB	0
	DEFB	48
	DEFB	49
	DEFB	50
	DEFB	52
	DEFB	128
	DEFB	129
	DEFB	130
	DEFB	145
	DEFB	146
	DEFB	176
	DEFB	177
	DEFW	?0085
	DEFW	?0084
	DEFW	?0083
	DEFW	?0078
	DEFW	?0069
	DEFW	?0075
	DEFW	?0032
	DEFW	?0032
	DEFW	?0080
	DEFW	?0082
	DEFW	?0031
	DEFW	?0031
	DEFW	?0080
?0031:
; 151.	    {
; 152.	    case Msg_KeyLongUp:
; 153.	    case Msg_KeyShortUp:
; 154.	        key_count = 0;
	LD	HL,0
	LD	(?0006),HL
; 155.	        g_rtc_counter = 0;
	LD	(g_rtc_counter),HL
; 156.	        key = key_value | AP_KEY_UP;
	LD	A,B
	SET	5,A
	LD	(IX-2),A
; 157.	        key_value=key;                                //add by mzh 2007.3.14
	LD	(?0007),A
; 158.	        break;
	JP	LWRD ?0089
?0032:
; 159.	
; 160.	
; 161.	    case MSG_RTC2HZ:        //rtc
; 162.	    case MSG_BAT_V_CHG:        //charging & rtc
; 163.	        g_rtc_counter++;
	LD	HL,(g_rtc_counter)
	INC	HL
	LD	(g_rtc_counter),HL
; 164.	
; 165.	 
; 166.	      if(g_comval.BatteryType != BATT_TYPE_LITHIUM)
	LD	A,(g_comval+15)
	DEC	A
	DEC	A
	IN	A,(142)
	JR	Z,?0034
?0033:
; 167.	      { 
; 168.	        if(((input8(0x8e)&0x80)==0)&&((input8(0x8f)&0x3f)<= 0x09))         //check low battery
	BIT	7,A
	JR	NZ,?0041
	IN	A,(143)
	AND	63
	LD	B,A
	LD	A,9
	CP	B
	JR	C,?0041
?0038:
?0037:
?0035:
; 169.	        {
; 170.	            return AP_MSG_LOW_POWER;
	JR	?0118
; 171.	        }
?0036:
; 172.	      }
; 173.	      else     
?0034:
; 174.	      { 
; 175.	        if(((input8(0x8e)&0x80)==0)&&((input8(0x8f)&0x3f)<= 0x12))         //check low battery
	BIT	7,A
	JR	NZ,?0041
	IN	A,(143)
	AND	63
	LD	B,A
	LD	A,18
	CP	B
	JR	NC,?0118
?0043:
?0042:
?0040:
; 176.	        {
; 177.	            return AP_MSG_LOW_POWER;
; 178.	        }
?0041:
?0039:
; 179.	      }          
; 180.	
; 181.	        #ifdef EAR_PROTECT
; 182.	            if (counter_flag)
	XOR	A
	OR	(IX-3)
	JR	Z,?0045
?0044:
; 183.	            {
; 184.	                g_decrease_time++;
	LD	HL,g_decrease_time
	INC	(HL)
?0045:
; 185.	            }
; 186.	            g_half_hour_counter++;
	LD	HL,(g_half_hour_counter)
	INC	HL
	LD	(g_half_hour_counter),HL
; 187.	            //g_autoswitch_counter++;
; 188.	        #endif
; 189.	        if((g_light_time != 0) && (g_rtc_counter >= g_light_time))    //自动关背光
	LD	A,(g_light_time)
	OR	A
	JR	Z,?0047
	LD	C,A
	LD	B,0
	LD	HL,(g_rtc_counter)
	SBC	HL,BC
	JR	C,?0047
?0049:
?0048:
?0046:
; 190.	        {
; 191.	            //关背光
; 192.	            sKY_CloseBacklight();
	CALL	LWRD sKY_CloseBacklight
?0047:
; 193.	        }
; 194.	
; 195.	        if(g_sleep_time != 0 && g_rtc_counter == g_sleep_time) //睡眠
	LD	HL,(g_sleep_time)
	LD	A,L
	OR	H
	JR	Z,?0051
	LD	BC,(g_rtc_counter)
	SBC	HL,BC
	JR	NZ,?0051
?0053:
?0052:
?0050:
; 196.	        {
; 197.	            return AP_MSG_SLEEP;
?0118:
	LD	L,31
; 198.	        }
	JP	LWRD ?0090
?0051:
; 199.	
; 200.	        if(g_standby_time != 0 && g_rtc_counter == g_standby_time) //自动关机
	LD	HL,(g_standby_time)
	LD	A,L
	OR	H
	JR	Z,?0055
	LD	BC,(g_rtc_counter)
	SBC	HL,BC
	JR	NZ,?0055
?0057:
?0056:
?0054:
; 201.	        {
; 202.	            return AP_MSG_STANDBY;
	LD	L,29
; 203.	        }
	JP	LWRD ?0090
?0055:
; 204.	        #ifdef EAR_PROTECT
; 205.	        //    if(g_autoswitch_time != 0 && g_autoswitch_counter == g_autoswitch_time) //自动关机
; 206.	        //    {
; 207.	        //        return AP_MSG_FORCE_STANDBY;
; 208.	        //    }
; 209.	        #endif
; 210.	
; 211.	        if( (g_rtc_counter % 16) == 0 )
	LD	HL,(g_rtc_counter)
	LD	A,L
	AND	15
	JR	NZ,?0059
?0058:
; 212.	        {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -