/* BWSideView */

#import <Cocoa/Cocoa.h>

@interface BWSideView : NSMatrix
{
	IBOutlet id menuSet;
	IBOutlet id fieldArea;
	IBOutlet id fieldData;
	IBOutlet id fieldEnemySet;
	IBOutlet id fieldObjects;
	IBOutlet id fieldObjectPosition;
	IBOutlet id fieldObjectType;
	IBOutlet id fieldObjectItem;
	IBOutlet id fieldEnemies;
	IBOutlet id fieldEnemyPosition;
	IBOutlet id fieldEnemyScreen;
	IBOutlet id fieldEnemyType;
	IBOutlet id radioObjectSet;
	
	IBOutlet id matrixEnemies;
	
	NSMutableData *rom;
	NSMutableArray *tiles;
	NSMutableArray *tilesItems;
	NSMutableArray *tilesEnemies;
	
	unsigned char currentTool;
	unsigned char mapScale;
	unsigned char cw;		// Current World
	unsigned char ca;		// Current Area
	unsigned char cd;		// Current Area Data
	unsigned char co;		// Current Object
	unsigned char ceg;		// Current Enemy Group
	unsigned char ce;		// Current Enemy
	unsigned char objSet;   // Object Set (0-1)
	
	unsigned char areaWidth;		// Width of the area, in screens (0-3)
	unsigned char objx,objy,length,type;
	
	unsigned char areaData[8][0x3F][0x80];
	unsigned char bgAreaData[8][8][0x80];
	unsigned char enemyData[8][0x80][0x40];
	
	unsigned char areaAssoc[8][0x3F];
	unsigned char enemyAssoc[8][0x3F];
	
	unsigned char palettes[8][0xE0];
	unsigned char tileMappings[8][0x400];
	unsigned char tileCodes[8][2][0x20];
	unsigned char tileLayers[8][8][9];
	
	unsigned const char *ptr;
}

- (void)open:(NSMutableData *)theRom;

- (void)loadTiles;
- (void)loadTilesItems;
- (void)loadTilesEnemies;

- (NSImage *)graphicWithBlocks:(NSArray *)blocks type:(unsigned char)size;
- (NSImage *)tileBlockWithTiles:(NSArray *)tsa;
- (NSImage *)tileWithOffset:(int)os palette:(struct sCol *)pal;
- (NSImage *)emptyTile;
- (void)flipTile:(NSImage *)tile type:(int)flip;

- (void)loadPalettes;
- (void)loadTileMappings;
- (void)loadTileCodes;

- (IBAction)changeWorld:(id)sender;

- (void)loadArea;
- (void)loadAreaData;
- (void)loadEnemyData;
- (void)loadAssociations;

- (IBAction)changeArea:(id)sender;
- (IBAction)changeData:(id)sender;
- (IBAction)changeEnemySet:(id)sender;

- (IBAction)nextObject:(id)sender;
- (IBAction)prevObject:(id)sender;
- (void)changeObject;
- (IBAction)changeObjectData:(id)sender;
- (unsigned char)totalObjects;
- (unsigned char)offsetForObject:(unsigned char)obj;

- (IBAction)nextEnemy:(id)sender;
- (IBAction)prevEnemy:(id)sender;
- (void)changeEnemy;
- (IBAction)changeEnemyData:(id)sender;

- (IBAction)changeBushesGrass:(id)sender;
- (IBAction)changeNoCeiling:(id)sender;
- (IBAction)changeObjectSet:(id)sender;

//- (NSString *)nameForObject:(unsigned char)objectCode world:(unsigned char)worldCode;
//- (NSString *)nameForEnemy:(unsigned char)enemyCode world:(unsigned char)worldCode;
- (void)displayEnemyName:(unsigned char)enemyCode world:(unsigned char)worldCode;
- (void)displayObjectName:(unsigned char)objectCode position:(unsigned char)positionCode world:(unsigned char)worldCode;

- (void)changeSize:(int)newSize;
- (void)redraw;
- (void)redrawAreaData;
- (void)drawCF:(int)x code:(unsigned char)h;

- (void)setSingle:(int)code;
- (void)setHorizontalTwo:(int)code;
- (void)setVerticalTwo:(int)code;
- (void)setHorizontalSingle:(int)code;
- (void)setHorizontalDouble:(int)code;
- (void)setVerticalUp:(int)code;
- (void)setVerticalSingle:(int)code;
- (void)setVerticalDouble:(int)code;
- (void)setOther:(int)code;
- (void)setItem:(int)code;

- (unsigned int)stringToHex:(NSString *)str;
- (NSString *)hexToString:(unsigned int)hex;

@end
