Skip to content

Commit

Permalink
Added mapper and map selector to name table
Browse files Browse the repository at this point in the history
  • Loading branch information
YusukeLab committed Aug 28, 2022
1 parent 35f3159 commit c4faef7
Show file tree
Hide file tree
Showing 17 changed files with 527 additions and 95 deletions.
5 changes: 5 additions & 0 deletions 99x8Edit/Clipboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ internal class ClipNametable : ClipBase
internal List<List<int>> pcgID = new List<List<int>>();
}
[Serializable]
internal class ClipNametableBanks : ClipBase
{
internal List<List<byte[]>> banks = new List<List<byte[]>>();
}
[Serializable]
internal class ClipMapPtn : ClipBase
{
internal int index;
Expand Down
4 changes: 4 additions & 0 deletions 99x8Edit/EditorControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public void SetEditingDot(Brush b, int col, int row)
{
// Set brush to not to be created every time
_brush ??= new Brush[ColumnNum, RowNum];
if ((_brush.GetLength(0) < _columnNum) || (_brush.GetLength(1) < _rowNum))
{
_brush = new Brush[_columnNum, _rowNum];
}
_brush[col, row] = b;
_updated = true;
}
Expand Down
44 changes: 24 additions & 20 deletions 99x8Edit/Machine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class Machine : IMementoTarget, IExportable, IImportable
private readonly Brush[] _brushOf = new Brush[16];
// Consts
internal readonly int NameTableMapWMax = 16;
internal readonly int NameTableMapHMax = 12;
internal readonly int NameTableMapHMax = 16;
// For TMS9918 view, we need higher resolution than RGB8)
private static readonly int[] _palette9918 = { 0x000000, 0x000000, 0x3eb849, 0x74d07d,
0x5955e0, 0x8076f1, 0xb95e51, 0x65dbef,
Expand Down Expand Up @@ -401,7 +401,7 @@ internal void LoadPCGAdd(BinaryReader br)
{
_nameTableMapW = width;
_nameTableMapH = br.ReadByte();
_nameTableMapped = br.ReadBytes(_nameTableMapW * _nameTableMapH);
_nameTableMapped = br.ReadBytes(_nameTableMapW * _nameTableMapH * 768);
}
}
catch (EndOfStreamException)
Expand Down Expand Up @@ -649,27 +649,12 @@ internal void SetPCGColor(int pcg, int line, int color_code, bool isForeGround,
}
//------------------------------------------------
// Name table
internal int GetNameTable(int addr)
{
// Will be discontinued
return _nameTable[addr];
}
internal void SetNameTable(int addr, int data, bool push)
{
// Will be discontinued
addr = Math.Clamp(addr, 0, 767);
data = Math.Clamp(data, 0, 255);
if (push)
{
MementoCaretaker.Instance.Push();
}
_nameTable[addr] = (byte)data;
}
internal int NameTableMapW
{
get => _nameTableMapW;
set
{
MementoCaretaker.Instance.Push();
value = Math.Clamp(value, 1, NameTableMapHMax);
byte[] new_buf = new byte[value * _nameTableMapH * 768];
for (int row = 0; row < _nameTableMapH; ++row)
Expand All @@ -691,6 +676,7 @@ internal int NameTableMapH
get => _nameTableMapH;
set
{
MementoCaretaker.Instance.Push();
value = Math.Clamp(value, 1, NameTableMapWMax);
byte[] new_buf = new byte[_nameTableMapW * value * 768];
for (int row = 0; (row < value) && (row < _nameTableMapH); ++row)
Expand All @@ -706,7 +692,7 @@ internal int NameTableMapH
_nameTableMapped = new_buf;
}
}
internal int GetNameTableMapped(int mapx, int mapy, int x, int y)
internal int GetNameTable(int mapx, int mapy, int x, int y)
{
mapx = Math.Clamp(mapx, 0, _nameTableMapW - 1);
mapy = Math.Clamp(mapy, 0, _nameTableMapH - 1);
Expand All @@ -716,17 +702,35 @@ internal int GetNameTableMapped(int mapx, int mapy, int x, int y)
int addr = mapy * stride + mapx * 768 + y * 32 + x;
return _nameTableMapped[addr];
}
internal void SetNameTableMapped(int mapx, int mapy, int x, int y, int value)
internal void SetNameTable(int mapx, int mapy, int x, int y, int value, bool push)
{
mapx = Math.Clamp(mapx, 0, _nameTableMapW - 1);
mapy = Math.Clamp(mapy, 0, _nameTableMapH - 1);
x = Math.Clamp(x, 0, 31);
y = Math.Clamp(y, 0, 23);
value = Math.Clamp(value, 0, 255);
if (push) MementoCaretaker.Instance.Push();
int stride = _nameTableMapW * 768;
int addr = mapy * stride + mapx * 768 + y * 32 + x;
_nameTableMapped[addr] = (byte)value;
}
internal IEnumerable<byte> GetNameTableBank(int mapx, int mapy)
{
int addr = (mapy * _nameTableMapW + mapx) * 768;
for (int i = 0; i < 768; ++i)
{
yield return _nameTableMapped[addr + i];
}
}
internal void SetNameTableBank(int mapx, int mapy, byte[] data, bool push)
{
if(push) MementoCaretaker.Instance.Push();
int addr = (mapy * _nameTableMapW + mapx) * 768;
foreach (byte datum in data)
{
_nameTableMapped[addr++] = datum;
}
}
//------------------------------------------------
// Map pattern (4 pcg in each 256 patterns)
internal int GetPCGInPattern(int ptn, int index)
Expand Down
164 changes: 164 additions & 0 deletions 99x8Edit/MapSelector.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c4faef7

Please sign in to comment.