public void SetGraphicsState(GraphicsState state, int offsetStart, int offsetEnd, int width = -1, int scale = 2)
{
GraphicsState.TileModifiedHandler tileModifiedHandler = delegate(int bank, int tile)
{
if (bank == -1 && tile == -1) // Full invalidation
{
redrawAll();
}
else
{
draw(tile + bank * 0x180);
}
};
if (graphicsState != null)
{
graphicsState.RemoveTileModifiedHandler(tileModifiedHandler);
}
if (state != null)
{
state.AddTileModifiedHandler(tileModifiedHandler);
}
graphicsState = state;
int size = (offsetEnd - offsetStart) / 16;
if (width == -1)
{
width = (int)Math.Sqrt(size);
}
int height = size / width;
this.offsetStart = offsetStart;
this.offsetEnd = offsetEnd;
Width = width;
Height = height;
TileWidth = 8;
TileHeight = 8;
Scale = scale;
image = new Bitmap(Width * TileWidth, Height * TileHeight);
redrawAll();
}