	cpu LMM
	.module menu.c
	.area text(rom, con, rel)
	.dbfile ./menu.c
	.dbfunc e menu _menu fC
;      menuitems -> X+2
;              b -> X+1
;              i -> X+0
;       selected -> X-8
;           menu -> X-7
;      menuname1 -> X-5
_menu::
	.dbline -1
	push X
	mov X,SP
	add SP,3
	.dbline 12
; #include "menu.h"
; #include "main.h"
; #include "pad.h"
; #include "ed_host_int.h"
; #include "ed_pad_int.h"
; #include "ed_slave_int.h"
; 
; #include "PSoCAPI.h"    // PSoC API definitions for all User Modules
; 
; signed char menu(const char *menuname1, const char **menu, 
; 				 signed char selected)
; {
	.dbline 17
; 	unsigned char i;
; 	unsigned char menuitems;
; 	unsigned char b;
; 		
; 	menuitems=0;
	mov [X+2],0
	xjmp L3
L2:
	.dbline 19
	inc [X+2]
L3:
	.dbline 18
; 	while (menu[menuitems][0]!=0)
	mov REG[0xd0],>__r0
	mov A,[X+2]
	mov [__r1],A
	mov [__r0],0
	asl [__r1]
	rlc [__r0]
	mov A,[X-6]
	add [__r1],A
	mov A,[X-7]
	adc [__r0],A
	mov A,[__r0]
	mov REG[0xd4],A
	mvi A,[__r1]
	mov [__r0],A
	mvi A,[__r1]
	mov [__r1],A
	mov A,[__r0]
	push X
	mov X,[__r1]
	romx
	pop X
	cmp A,0
	jnz L2
	.dbline 21
; 		menuitems++;
; 			
; 	pad_LcdClear();
	xcall _pad_LcdClear
L5:
	.dbline 25
; 		
; 	redraw:
; 	
; 	pad_LcdPrintC(0x00, 0x08, 'D', menuname1);
	mov A,[X-5]
	push A
	mov A,[X-4]
	push A
	mov A,68
	push A
	mov A,8
	push A
	mov A,0
	push A
	xcall _pad_LcdPrintC
	add SP,-5
	.dbline 27
; 
; 	for (i=0;i<menuitems;i+=2)
	mov [X+0],0
	xjmp L9
L6:
	.dbline 28
; 		{
	.dbline 29
; 		if (i==selected)
	mov A,[X+0]
	cmp A,[X-8]
	jnz L10
	.dbline 30
; 			pad_LcdPrintC(0x04, 24+i*4, 'b', menu[i]);
	mov REG[0xd0],>__r0
	mov A,[X+0]
	mov [__r1],A
	mov [__r0],0
	asl [__r1]
	rlc [__r0]
	mov A,[X-6]
	add [__r1],A
	mov A,[X-7]
	adc [__r0],A
	mov A,[__r0]
	mov REG[0xd4],A
	mvi A,[__r1]
	mov [__r0],A
	mvi A,[__r1]
	mov [__r1],A
	mov A,[__r0]
	push A
	mov A,[__r1]
	push A
	mov A,98
	push A
	mov A,[X+0]
	mov [__r0],A
	asl [__r0]
	asl [__r0]
	add [__r0],24
	mov A,[__r0]
	push A
	mov A,4
	push A
	xcall _pad_LcdPrintC
	add SP,-5
	xjmp L11
L10:
	.dbline 32
; 		else
; 			pad_LcdPrintC(0x04, 24+i*4, 'B', menu[i]);
	mov REG[0xd0],>__r0
	mov A,[X+0]
	mov [__r1],A
	mov [__r0],0
	asl [__r1]
	rlc [__r0]
	mov A,[X-6]
	add [__r1],A
	mov A,[X-7]
	adc [__r0],A
	mov A,[__r0]
	mov REG[0xd4],A
	mvi A,[__r1]
	mov [__r0],A
	mvi A,[__r1]
	mov [__r1],A
	mov A,[__r0]
	push A
	mov A,[__r1]
	push A
	mov A,66
	push A
	mov A,[X+0]
	mov [__r0],A
	asl [__r0]
	asl [__r0]
	add [__r0],24
	mov A,[__r0]
	push A
	mov A,4
	push A
	xcall _pad_LcdPrintC
	add SP,-5
L11:
	.dbline 34
; 		
; 		if (i+1==menuitems)
	mov REG[0xd0],>__r0
	mov A,[X+0]
	add A,1
	cmp A,[X+2]
	jnz L12
	.dbline 35
; 			break;
	xjmp L17
L12:
	.dbline 37
; 		
; 		if (i+1==selected)
	mov REG[0xd0],>__r0
	mov A,[X+0]
	add A,1
	cmp A,[X-8]
	jnz L14
	.dbline 38
; 			pad_LcdPrintC(0x40, 24+i*4, 'b', menu[i+1]);
	mov A,[X+0]
	mov [__r1],A
	mov [__r0],0
	add [__r1],1
	adc [__r0],0
	asl [__r1]
	rlc [__r0]
	mov A,[X-6]
	add [__r1],A
	mov A,[X-7]
	adc [__r0],A
	mov A,[__r0]
	mov REG[0xd4],A
	mvi A,[__r1]
	mov [__r0],A
	mvi A,[__r1]
	mov [__r1],A
	mov A,[__r0]
	push A
	mov A,[__r1]
	push A
	mov A,98
	push A
	mov A,[X+0]
	mov [__r0],A
	asl [__r0]
	asl [__r0]
	add [__r0],24
	mov A,[__r0]
	push A
	mov A,64
	push A
	xcall _pad_LcdPrintC
	add SP,-5
	xjmp L15
L14:
	.dbline 40
; 		else
; 			pad_LcdPrintC(0x40, 24+i*4, 'B', menu[i+1]);
	mov REG[0xd0],>__r0
	mov A,[X+0]
	mov [__r1],A
	mov [__r0],0
	add [__r1],1
	adc [__r0],0
	asl [__r1]
	rlc [__r0]
	mov A,[X-6]
	add [__r1],A
	mov A,[X-7]
	adc [__r0],A
	mov A,[__r0]
	mov REG[0xd4],A
	mvi A,[__r1]
	mov [__r0],A
	mvi A,[__r1]
	mov [__r1],A
	mov A,[__r0]
	push A
	mov A,[__r1]
	push A
	mov A,66
	push A
	mov A,[X+0]
	mov [__r0],A
	asl [__r0]
	asl [__r0]
	add [__r0],24
	mov A,[__r0]
	push A
	mov A,64
	push A
	xcall _pad_LcdPrintC
	add SP,-5
L15:
	.dbline 41
L7:
	.dbline 27
	add [X+0],2
L9:
	.dbline 27
	mov A,[X+0]
	cmp A,[X+2]
	jc L6
X1:
	xjmp L17
L16:
	.dbline 44
; 		}
; 	
; 	while(1)
; 		{
	.dbline 45
; 		b=pad_gets();
	xcall _pad_gets
	mov REG[0xd0],>__r0
	mov [X+1],A
	.dbline 47
; 	
; 		if ((b&PAD_MOVEMASK)==PAD_UP && selected>1) //up
	mov A,[X+1]
	and A,15
	cmp A,1
	jnz L19
	mov A,1
	cmp A,[X-8]
	rrc A
	xor A,[X-8]
	xor A,1
	rlc A
	jnc L19
X2:
	.dbline 48
; 			{
	.dbline 49
; 			selected-=2;
	sub [X-8],2
	.dbline 50
; 			if (selected<0)
	tst [X-8],-128
	jz L5
	.dbline 51
; 				selected=menuitems-1;
	mov A,[X+2]
	sub A,1
	mov [X-8],A
	.dbline 52
; 			goto redraw;
	xjmp L5
L19:
	.dbline 54
; 			}
; 		if ((b&PAD_MOVEMASK)==PAD_DOWN && selected<(menuitems-2)) //down
	mov REG[0xd0],>__r0
	mov A,[X+1]
	and A,15
	cmp A,2
	jnz L23
	mov A,[X+2]
	mov [__r1],A
	mov [__r0],0
	sub [__r1],2
	sbb [__r0],0
	mov A,[X-8]
	mov [__r3],A
	mov [__r2],0
	tst [__r3],-128
	jz X3
	mov [__r2],-1
X3:
	mov REG[0xd0],>__r0
	mov A,[__r3]
	sub A,[__r1]
	mov A,[__r0]
	xor A,-128
	mov [__rX],A
	mov A,[__r2]
	xor A,-128
	sbb A,[__rX]
	jnc L23
X4:
	.dbline 55
; 			{
	.dbline 56
; 			selected+=2;
	add [X-8],2
	.dbline 57
; 			if (selected>(menuitems-1))
	mov REG[0xd0],>__r0
	mov A,[X+2]
	mov [__r1],A
	mov [__r0],0
	sub [__r1],1
	sbb [__r0],0
	mov A,[X-8]
	mov [__r3],A
	mov [__r2],0
	tst [__r3],-128
	jz X5
	mov [__r2],-1
X5:
	mov REG[0xd0],>__r0
	mov A,[__r1]
	sub A,[__r3]
	mov A,[__r2]
	xor A,-128
	mov [__rX],A
	mov A,[__r0]
	xor A,-128
	sbb A,[__rX]
	jnc L5
X6:
	.dbline 58
; 				selected=0;
	mov [X-8],0
	.dbline 60
; 				
; 			goto redraw;
	xjmp L5
L23:
	.dbline 63
; 			}
; 		
; 		if ((b&PAD_MOVEMASK)==PAD_LEFT && (selected&1)==1) //left
	mov REG[0xd0],>__r0
	mov A,[X+1]
	and A,15
	cmp A,4
	jnz L27
	mov A,[X-8]
	and A,1
	cmp A,1
	jnz L27
	.dbline 64
; 			{
	.dbline 65
; 			selected-=1;
	dec [X-8]
	.dbline 66
; 			if (selected<0)
	tst [X-8],-128
	jz L5
	.dbline 67
; 				selected=menuitems-1;
	mov A,[X+2]
	sub A,1
	mov [X-8],A
	.dbline 68
; 			goto redraw;	
	xjmp L5
L27:
	.dbline 71
; 			}
; 
; 		if ((b&PAD_MOVEMASK)==PAD_RIGHT && (selected&1)==0) //right
	mov REG[0xd0],>__r0
	mov A,[X+1]
	and A,15
	cmp A,3
	jnz L31
	tst [X-8],1
	jnz L31
	.dbline 72
; 			{
	.dbline 73
; 			selected+=1;
	inc [X-8]
	.dbline 74
; 			if (selected>(menuitems-1))
	mov A,[X+2]
	mov [__r1],A
	mov [__r0],0
	sub [__r1],1
	sbb [__r0],0
	mov A,[X-8]
	mov [__r3],A
	mov [__r2],0
	tst [__r3],-128
	jz X7
	mov [__r2],-1
X7:
	mov REG[0xd0],>__r0
	mov A,[__r1]
	sub A,[__r3]
	mov A,[__r2]
	xor A,-128
	mov [__rX],A
	mov A,[__r0]
	xor A,-128
	sbb A,[__rX]
	jnc L5
X8:
	.dbline 75
; 				selected=0;
	mov [X-8],0
	.dbline 76
; 			goto redraw;	
	xjmp L5
L31:
	.dbline 79
; 			}
; 			
; 		if (b&(PAD_STICK|PAD_MENU))
	tst [X+1],48
	jz L35
	.dbline 80
; 			{
	.dbline 81
; 			return selected;
	mov A,[X-8]
	mov REG[0xd0],>__r0
	xjmp L1
L35:
	.dbline 83
; 			}
; 		if (b&(PAD_STOP))
	tst [X+1],64
	jz L37
	.dbline 84
; 			{
	.dbline 85
; 			return -1;
	mov REG[0xd0],>__r0
	mov A,-1
	xjmp L1
L37:
	.dbline 87
L17:
	.dbline 43
	xjmp L16
X0:
	.dbline 88
; 			}
; 		}
; 	return 0;
	mov REG[0xd0],>__r0
	mov A,0
	.dbline -2
L1:
	add SP,-3
	pop X
	.dbline 0 ; func end
	ret
	.dbsym l menuitems 2 c
	.dbsym l b 1 c
	.dbsym l i 0 c
	.dbsym l selected -8 C
	.dbsym l menu -7 ppc
	.dbsym l menuname1 -5 pc
	.dbend
