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

📄 main.s

📁 实现2个ps/2接口转到1个USB接口功能
💻 S
📖 第 1 页 / 共 3 页
字号:
	.module main.c
	.area text(rom, con, rel)
	.dbfile ./main.c
	.dbfunc e main _main fV
_main::
	.dbline -1
	.dbline 61
; //----------------------------------------------------------------------------
; // C main line
; //----------------------------------------------------------------------------
; 
; #include <m8c.h>        // part specific constants and macros
; #include "PSoCAPI.h"    // PSoC API definitions for all User Modules
; 
; #include "main.h"
; #include "timer.h"
; #include "USB_mk.h"
; #include "port.h"
; #include "int_func.h"
; #include "debug.h"
; 
; #define PORT0_UNUSED_PINS	0xFF	//@@all pins of port0 is unused
; #define RED_LED				0x8
; #define PORT1_UNUSED_PINS	0x84	// Pins 2,and 7
; 
; BOOL shouldSuspend;//@@a flag indicated suspend
; BOOL shouldprotect;//@@a flag indicated protect is necessary or not
; UINT16	protect_counter;//inorder to send a broke code and clear USB keyboard's first byte to protect the system
; 
; APP_TX_PACKET      report_packet;
; APP_TX_PACKET_KB   report_packet_kb;
; 
; INT8            get_int1_new;
; INT8            reg_int1_new;
; BOOL			shouldstartms;//@@a flag indicated mouse timer start is necessary or not
; INT8            ms_timer;
;     UINT8           get_ms0;
;     UINT8           get_ms1;   
;     UINT8           get_ms2;
;     UINT8           get_ms3;
;     UINT8           get_ms4;
;     
; 
; INT8            get_int0_new;
; INT8            reg_int0_new; 
; BOOL			shouldstartkb;//@@a flag indicated keyboard timer start is necessary or not
; INT8            kb_timer;
;     UINT8           get_kb0;
;     UINT8           get_kb1;
;     UINT8           get_kb2;
;     UINT8           get_kb3;
;     UINT8           get_kb4;
;     UINT8           get_kb5;
;     UINT8           get_kb6;
;     UINT8           get_kb7;
; 		BOOL	R_GUI;
; 		BOOL	R_ALT;
; 		BOOL	R_SHIFT;
; 		BOOL	R_CTRL;
; 		BOOL	L_GUI;
; 		BOOL	L_ALT;
; 		BOOL	L_SHIFT;
; 		BOOL	L_CTRL;
; 
; static void	mk_init( void );//local function,can't be got out this file 
; void mk_report_init( void );
; void main()
; {
	.dbline 62
; 		debug_turn_on_led();
	push X
	xcall _debug_turn_on_led
	pop X
	.dbline 63
; 	M8C_ClearWDT;// Clear Watchdog
	mov REG[0xe3],0
	.dbline 64
;     shouldSuspend = FALSE;
	mov [_shouldSuspend],0
	.dbline 65
;     OSC_CR0 = 0x1B;//24MHZ CPU
	or F,0x10  ; iopage = 1
	mov REG[0xe0],27
	and F,0xEF ; iopage = 0
	.dbline 66
;     M8C_EnableGInt;    
		or  F, 01h

	.dbline 67
; 	M8C_EnableWatchDog;//Enable WDT
	and REG[0xff],-17
	.dbline 68
;     MSTIMER_EnableInt();// Enable timer interrupt
	push X
	xcall _MSTIMER_EnableInt
	pop X
	.dbline 69
; 	mk_init();
	xcall _mk_init
	.dbline 71
; 
; 	int0_initialize();
	push X
	xcall _int0_initialize
	.dbline 72
; 	int1_initialize();	
	xcall _int1_initialize
	pop X
	.dbline 73
; 	P02CR = 0x30;//0011 0000,INT0 is occur on falling edge
	mov REG[0x7],48
	.dbline 74
; 	P03CR = 0x30;//0011 0000,INT1 is occur on falling edge	
	mov REG[0x8],48
	.dbline 75
; 	INT_MSK0 = 0x22;//0010 0010,INT0 and INT1 is enabled
	mov REG[0xe0],34
	.dbline 76
; 	    debug_turn_off_led();    
	xcall _debug_turn_off_led
	.dbline 79
;  
;  	// Main loop
;     for ( ;; )
L3:
	.dbline 80
	.dbline 82
	mov REG[0xe3],0
	.dbline 84
	xcall _usb_idle
	.dbline 85
	.dbline 79
	.dbline 79
	xjmp L3
X0:
	.dbline -2
L2:
	.dbline 0 ; func end
	jmp .
	.dbend
	.dbfunc s mk_init _mk_init fV
_mk_init:
	.dbline -1
	.dbline 100
;     {
; 		// Clear Watchdog
; 		M8C_ClearWDT;
; 		//Execute USB idle routine
; 		usb_idle();//this function transmit USB signals
;  	}   // end for (;;)
; }
; 
; //--------------------------------------------------------------------------
; //
; // Function: mk_init
; //
; //  Description:
; ///     This function initializes all components of the mouse and keyboard application.
; ///
; /// Returns:
; ///     void
; //
; //--------------------------------------------------------------------------
; static void mk_init( void )
; {
	.dbline 101
;     port_init();
	xcall _port_init
	.dbline 102
; 	port_drive_off( PORT0_UNUSED_PINS );// Drive all the unused pins to outputs for power savings.	
	mov A,-1
	push A
	xcall _port_drive_off
	add SP,-1
	.dbline 103
;     P1DATA &= ~PORT1_UNUSED_PINS;
	and REG[0x1],123
	.dbline 104
;    	usb_init();// Initialized the USB UM
	xcall _usb_init
	.dbline 105
;     timer_init();
	xcall _timer_init
	.dbline 106
;     mk_report_init();
	xcall _mk_report_init
	.dbline -2
	.dbline 107
; }
L7:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e mk_report_init _mk_report_init fV
_mk_report_init::
	.dbline -1
	.dbline 113
; 
; //--------------------------------------------------------------------------
; //@@mouse_report_init
; //--------------------------------------------------------------------------
; void mk_report_init( void )
; {
	.dbline 114
; 	get_int1_new=0x00;
	mov [_get_int1_new],0
	.dbline 115
; 	reg_int1_new=0x01;
	mov [_reg_int1_new],1
	.dbline 116
; 	get_int0_new=0x00;
	mov [_get_int0_new],0
	.dbline 117
; 	reg_int0_new=0x01;
	mov [_reg_int0_new],1
	.dbline 118
; 	ms_timer=0x00;
	mov [_ms_timer],0
	.dbline 119
; 	kb_timer=0x00;
	mov [_kb_timer],0
	.dbline 120
; 		R_GUI = FALSE;
	mov [_R_GUI],0
	.dbline 121
; 		R_ALT = FALSE;
	mov [_R_ALT],0
	.dbline 122
; 		R_SHIFT = FALSE;
	mov [_R_SHIFT],0
	.dbline 123
; 		R_CTRL = FALSE;
	mov [_R_CTRL],0
	.dbline 124
; 		L_GUI = FALSE;
	mov [_L_GUI],0
	.dbline 125
; 		L_ALT = FALSE;
	mov [_L_ALT],0
	.dbline 126
; 		L_SHIFT = FALSE;
	mov [_L_SHIFT],0
	.dbline 127
; 		L_CTRL = FALSE;
	mov [_L_CTRL],0
	.dbline 128
; 	protect_counter=0x0000;	
	mov [_protect_counter+1],0
	mov [_protect_counter],0
	.dbline 129
; 	shouldprotect = FALSE;
	mov [_shouldprotect],0
	.dbline -2
	.dbline 130
; }
L8:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e mouse_get_report _mouse_get_report fc
;       check_ms -> X+5
;       regy_ms0 -> X+4
;       regx_ms0 -> X+3
;          ysign -> X+2
;          xsign -> X+1
; mouse_report_valid -> X+0
_mouse_get_report::
	.dbline -1
	push X
	mov X,SP
	add SP,8
	.dbline 139
; 
; //--------------------------------------------------------------------------
; // mouse_get_report
; //
; /// This function polls the optics, wheel and buttons for potential events to 
; /// send over the radio.  It also builds the packet payload.
; //--------------------------------------------------------------------------
; BOOL mouse_get_report( void )
; {
	.dbline 140
;     BOOL            mouse_report_valid = FALSE;
	mov [X+0],0
	.dbline 149
;     UINT8 			xsign;
;     UINT8			ysign;
;     
;     UINT8           regx_ms0;
;     UINT8           regy_ms0;  
; 
;     UINT8           check_ms;        
; 
; 	get_int1_new = GET_INT1_NEW();
	push X
	xcall _GET_INT1_NEW
	pop X
	mov [_get_int1_new],A
	.dbline 151
; 	
; 	if(get_int1_new==reg_int1_new && get_int1_new!=0x00)	
	mov A,[_get_int1_new]
	cmp A,[_reg_int1_new]
	jnz L10
	cmp [_get_int1_new],0
	jz L10
	.dbline 152
; 	{
	.dbline 153
; 		shouldstartms=TRUE;
	mov [_shouldstartms],1
	.dbline 154
; 	}
	xjmp L11
L10:
	.dbline 156
; 	else
; 	{
	.dbline 157
; 		shouldstartms=FALSE;		
	mov [_shouldstartms],0
	.dbline 158
; 		reg_int1_new=get_int1_new;
	mov [_reg_int1_new],[_get_int1_new]
	.dbline 159
; 		ms_timer=0x00;
	mov [_ms_timer],0
	.dbline 160
; 	}
L11:
	.dbline 162
; //MOUSE	
; 	if(ms_timer==0x0A)
	cmp [_ms_timer],10
	jnz L12
	.dbline 163
; 	{
	.dbline 164
; 		get_ms0=INT1_GET_BUTT();
	push X
	xcall _INT1_GET_BUTT
	pop X
	mov [_get_ms0],A
	.dbline 165
; 		get_ms1=INT1_GET_X();
	push X
	xcall _INT1_GET_X
	pop X
	mov [_get_ms1],A
	.dbline 166
; 		get_ms2=INT1_GET_Y();
	push X
	xcall _INT1_GET_Y
	pop X
	mov [_get_ms2],A
	.dbline 167
; 		get_ms3=INT1_GET_Z();
	push X
	xcall _INT1_GET_Z
	pop X
	mov [_get_ms3],A
	.dbline 171
; 				
; //		if(check_ms==get_ms4)//check sum end 
; //		{
; 			regx_ms0=get_ms0;
	mov A,[_get_ms0]
	mov [X+3],A
	.dbline 172
; 			regy_ms0=get_ms0;
	mov A,[_get_ms0]
	mov [X+4],A
	.dbline 174
; 		
; 			report_packet.buttons = get_ms0 & 0x07;//0x07="0000 0111"
	mov A,[_get_ms0]
	and A,7
	mov [_report_packet],A
	.dbline 176
; 			
; 			xsign=regx_ms0 & 0x10;
	mov A,[X+3]
	and A,16
	mov [X+1],A
	.dbline 177
; 			if(xsign == 0x10)
	cmp [X+1],16
	jnz L14
	.dbline 178
; 			{
	.dbline 179
; 				if((get_ms1==0x01) || (get_ms1==0x02))
	cmp [_get_ms1],1
	jz L18
	cmp [_get_ms1],2
	jnz L16
L18:
	.dbline 180
; 				{
	.dbline 181
; 					report_packet.x=0xff;	
	mov [_report_packet+1],-1
	.dbline 182
; 				}
	xjmp L15
L16:
	.dbline 188
; //				else if(get_ms1==0x02)
; //				{
; //					report_packet.x=0xff;		
; //				}
; 				else
; 				{
	.dbline 189
; 					get_ms1=get_ms1-1;
	dec [_get_ms1]
	.dbline 190
; 					get_ms1=get_ms1>>1;
	and F,-5
	rrc [_get_ms1]
	.dbline 191
; 					get_ms1=get_ms1|0x80;
	or [_get_ms1],-128
	.dbline 194
; //					if((get_ms1>=0xf0) && (get_ms1<=0xff))
; //					{
; 						report_packet.x=get_ms1;			
	mov [_report_packet+1],[_get_ms1]
	.dbline 200
; //					}
; //					else
; //					{
; //						report_packet.x=0xf0;									
; //					}
; 				}
	.dbline 201
; 			}
	xjmp L15
L14:
	.dbline 203
; 			else// xsign!=0x10
; 			{	//clear the high bit start 
	.dbline 204
; 				get_ms1 = get_ms1 >>1;//cut the first bit
	and F,-5
	rrc [_get_ms1]
	.dbline 205
; 				get_ms1 = get_ms1 <<1;//
	asl [_get_ms1]
	.dbline 206
; 				get_ms1 = get_ms1 >>1;//cut the last bit
	and F,-5
	rrc [_get_ms1]
	.dbline 211
; 				//clear the high bit end 		
; 				
; //				if((get_ms1>=0x00) && (get_ms1<=0x1f))
; //				{
; 					report_packet.x=get_ms1;			
	mov [_report_packet+1],[_get_ms1]
	.dbline 217
; //				}
; //				else
; //				{	
; //					report_packet.x=0x1f;									
; //				}
; 			}// xsign
L15:
	.dbline 219
; 
; 			ysign=regy_ms0 & 0x20;
	mov A,[X+4]
	and A,32
	mov [X+2],A
	.dbline 220
; 			if(ysign != 0x20)
	cmp [X+2],32
	jz L22
	.dbline 221
; 			{
	.dbline 222
; 				if(get_ms2==0x00)
	cmp [_get_ms2],0
	jnz L24
	.dbline 223
; 				{
	.dbline 224
; 					report_packet.y=get_ms2;
	mov [_report_packet+2],[_get_ms2]
	.dbline 225
; 				}
	xjmp L23
L24:
	.dbline 227
; 				else
; 				{
	.dbline 228
; 					get_ms2=get_ms2-1;
	dec [_get_ms2]
	.dbline 229
; 					get_ms2=~get_ms2;
	mov A,[_get_ms2]
	cpl A
	mov [_get_ms2],A
	.dbline 230
; 					get_ms2=get_ms2>>1;
	and F,-5
	rrc [_get_ms2]
	.dbline 231
; 					get_ms2=get_ms2 | 0x80;
	or [_get_ms2],-128
	.dbline 235
; 					
; //					if((get_ms2>=0xf0) && (get_ms2<=0xff))
; //					{
; 						report_packet.y=get_ms2;			
	mov [_report_packet+2],[_get_ms2]
	.dbline 241
; //					}
; //					else
; //					{
; //						report_packet.y=0xf0;
; //					}				
; 				}
	.dbline 242
; 			}
	xjmp L23
L22:
	.dbline 244
; 			else //ysign == 0x20
; 			{//clear the high bit start 
	.dbline 245
; 				if((get_ms2==0xff) || (get_ms2==0xfe))
	cmp [_get_ms2],-1
	jz L30
	cmp [_get_ms2],-2
	jnz L28
L30:
	.dbline 246
; 				{
	.dbline 247
; 					report_packet.y=0x01;	
	mov [_report_packet+2],1
	.dbline 248
; 				}
	xjmp L29
L28:
	.dbline 250
; 				else
; 				{		
	.dbline 251
; 					get_ms2 = get_ms2 >>1;//cut the first bit
	and F,-5
	rrc [_get_ms2]
	.dbline 252
; 					get_ms2 = get_ms2 <<1;//
	asl [_get_ms2]
	.dbline 253
; 					get_ms2=~get_ms2;
	mov A,[_get_ms2]
	cpl A
	mov [_get_ms2],A
	.dbline 256
; 					
; 					
; 					get_ms2 = get_ms2 >>1;//cut the last bit
	and F,-5
	rrc [_get_ms2]
	.dbline 260
; 					//clear the high bit end 	
; //					if((get_ms2>=0x01) && (get_ms2<=0x0f))
; //					{
; 						report_packet.y=get_ms2;			
	mov [_report_packet+2],[_get_ms2]
	.dbline 266
; //					}
; //					else
; //					{
; //						report_packet.y=0x0f;									
; //					}	
; 				}		
L29:
	.dbline 267
; 			}// ysign
L23:
	.dbline 269
; 
; 			switch(get_ms3)
	mov A,[_get_ms3]
	mov [X+7],A
	mov [X+6],0
	cmp [X+6],0
	jnz X2
	cmp [X+7],0
	jz L36
X2:
	cmp [X+6],0
	jnz X3
	cmp [X+7],1
	jz L38
X3:
	cmp [X+6],0
	jnz X4
	cmp [X+7],2
	jz L40
X4:
	cmp [X+6],0
	jnz X5
	cmp [X+7],3
	jz L42
X5:
	cmp [X+6],0
	jnz X6
	cmp [X+7],4
	jz L44
X6:
	cmp [X+6],0
	jnz X7
	cmp [X+7],5
	jz L46
X7:
	cmp [X+6],0
	jnz X8
	cmp [X+7],6
	jz L48
X8:
	cmp [X+6],0
	jnz X9
	cmp [X+7],7
	jz L50
X9:
	mov A,[X+7]
	sub A,0
	mov A,[X+6]
	xor A,-128
	sbb A,(0 ^ 0x80)
	jc L33
X10:
L69:
	cmp [X+6],0
	jnz X11
	cmp [X+7],-8
	jz L66
X11:
	cmp [X+6],0
	jnz X12
	cmp [X+7],-7
	jz L64
X12:
	cmp [X+6],0
	jnz X13
	cmp [X+7],-6
	jz L62
X13:
	cmp [X+6],0
	jnz X14
	cmp [X+7],-5
	jz L60
X14:
	cmp [X+6],0
	jnz X15
	cmp [X+7],-4
	jz L58
X15:
	cmp [X+6],0
	jnz X16
	cmp [X+7],-3
	jz L56
X16:
	cmp [X+6],0
	jnz X17
	cmp [X+7],-2
	jz L54
X17:
	cmp [X+6],0
	jnz X18
	cmp [X+7],-1
	jz L52
X18:
	xjmp L33
X1:
	.dbline 270
; 			{
L36:
	.dbline 271
; 			case 0x00: report_packet.z =0x00;break;
	mov [_report_packet+3],0
	.dbline 271
	xjmp L34
L38:
	.dbline 272
; 			case 0x01: report_packet.z =0xff;break;
	mov [_report_packet+3],-1
	.dbline 272
	xjmp L34
L40:
	.dbline 273
; 			case 0x02: report_packet.z =0xfe;break;
	mov [_report_packet+3],-2
	.dbline 273
	xjmp L34
L42:
	.dbline 274
; 			case 0x03: report_packet.z =0xfd;break;
	mov [_report_packet+3],-3
	.dbline 274
	xjmp L34
L44:
	.dbline 275
; 			case 0x04: report_packet.z =0xfc;break;
	mov [_report_packet+3],-4
	.dbline 275
	xjmp L34
L46:
	.dbline 276
; 			case 0x05: report_packet.z =0xfb;break;
	mov [_report_packet+3],-5
	.dbline 276
	xjmp L34
L48:
	.dbline 277

⌨️ 快捷键说明

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