
unsigned short areas[46] =
{
	0x462F , 0x4663 , 0x4664 , 0x4665 ,
	0x465C , 0x465E , 0x4661 , 0x4660 , 0x465F , 0x4662 , 0x465B ,
	0x4639 , 0x463A , 0x463B , 0x463C , 0x4640 , 0x4641 , 0x4630 , 0x4632 , 0x4634 , 0x463F , 0x463E , 0x463D ,
	0x4631 , 0x4633 , 0x4646 , 0x4635 , 0x4649 , 0x464A , 0x464B , 0x464C , 0x4648 ,
	0x4637 , 0x4647 , 0x464D ,
	0x4638 ,
	0x4642 , 0x4643 , 0x4644 , 0x4645 ,
	0x4636 , 0x464E , 0x464F , 0x4658 , 0x4659 , 0x465A
};

unsigned short ka[55] =
{
	0 , 52 , 53 , 54 ,
	45 , 47 , 50 , 49 , 48 , 51 , 44 ,
	10 , 11 , 12 , 13 , 17 , 18 , 1 , 3 , 5 , 16 , 15 , 14 ,
	2 , 4 , 23 , 6 , 26 , 27 , 28 , 29 , 25 ,
	8 , 24 , 30 ,
	9 ,
	19 , 20 , 21 , 22 ,
	7 , 31 , 32 , 41 , 42 , 43 ,
	33 , 34 , 35 , 36 , 37 , 38 , 39 , 40 , 46
};

- (IBAction)changeRegion:(id)sender
{
	cr = [sender indexOfSelectedItem];
	if (cr == 0) { maxGroups = 801; maxAreas = 55; }
	if (cr == 1) { maxGroups = 794; maxAreas = 55; }
	if (cr == 2) { maxGroups = 1024; maxAreas = 62; }
	
	NSLog(@"maxGroups = %d",maxGroups);
	
	[self renewRows:1 columns:64];
	
	unsigned char b1,b2;	// b1 : High Byte   b2 : Low Byte
	
	int c = 0;
	int r = 0;
	int i,j;
	
	for (i=0; i<maxGroups; i++) {
		
		b1 = b[cr][i] >> 4;
		b2 = b[cr][i] & 0x0F;
		
		for (j=0; j<=b1; j++) {
			
			[[self cellAtRow:r column:c] setImage:[tiles objectAtIndex:b2]];
			c++;
			
			if (c == [self numberOfColumns] && (i < (maxGroups-1))) {
				c = 0; r++;
				[self addRow];
			}
		}
	}
	
	NSLog(@"Making Areas Menu");
	[menuArea removeAllItems];
	NSString *str = [[NSBundle mainBundle] pathForResource:@"KeyAreas" ofType:@"plist"];
	if (areas) [areas release];
	areas = [[NSMutableDictionary alloc] initWithContentsOfFile:str];
	
	NSMutableArray *items = [NSMutableArray arrayWithCapacity:64];
	NSArray *sub = [areas objectForKey:[menuRegion titleOfSelectedItem]];
	
	[items addObject:@"Show All"];
	for (i=0; i<[sub count]; i++) {
		[items addObjectsFromArray:[[sub objectAtIndex:i] objectForKey:@"Items"]];
	}
	
	[menuArea addItemsWithTitles:items];
	
	[self sizeToCells];
	[self calc];
	[self setNeedsDisplay:YES];
}

- (IBAction)changeArea:(id)sender
{
	int d = [sender indexOfSelectedItem];
	NSLog(@"Area Selected : %d (%@)",[sender indexOfSelectedItem],[sender titleOfSelectedItem]);
	if (d == 0) {
		[[matrixTools cellWithTag:0] setBordered:YES];
		currentTool = 0;
		sel = -1;
	} else {
		[[matrixTools cellWithTag:currentTool] setBordered:NO];
		currentTool = 17;
		sel = ka[d-1];
		NSLog(@"sel : %d",sel);
	}
	[self setNeedsDisplay:YES];
}

