-
Notifications
You must be signed in to change notification settings - Fork 2
/
BlockMapping.cs
76 lines (74 loc) · 2.46 KB
/
BlockMapping.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using System;
using System.IO;
using System.Drawing;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace sth1edwv
{
public class BlockMapping
{
public uint address;
public uint blockCount;
public List<byte[]> blocks;
public List<Color[,]> imagedata;
public BlockMapping(uint _address, byte solidityIndex, TileSet tileSet)
{
address = _address;
switch (address)
{
case 0x10000:
blockCount = 184;
break;
case 0x10B80:
blockCount = 144;
break;
case 0x11480:
blockCount = 160;
break;
case 0x11E80:
blockCount = 176;
break;
case 0x12980:
blockCount = 192;
break;
case 0x13580:
blockCount = 216;
break;
case 0x14300:
blockCount = 104;
break;
case 0x14980:
blockCount = 132;
break;
}
MemoryStream m = new MemoryStream();
m.Write(Cartridge.memory, (int)address, (int)blockCount * 16);
m.Seek(0, 0);
MemoryStream m2 = new MemoryStream();
ushort offset = BitConverter.ToUInt16(Cartridge.memory, 0x3A65 + solidityIndex * 2);
m2.Write(Cartridge.memory, offset, (int)blockCount);
m2.Seek(0, 0);
blocks = new List<byte[]>();
for (int i = 0; i < blockCount; i++)
{
byte[] block = new byte[17];
m.Read(block, 0, 16);
block[16] = (byte)m2.ReadByte();
blocks.Add(block);
}
imagedata = new List<Color[,]>();
for (int i = 0; i < blockCount; i++)
{
Color[,] data = new Color[32, 32];
for(int by =0;by<4;by++)
for (int bx = 0; bx < 4; bx++)
for (int ty = 0; ty < 8; ty++)
for (int tx = 0; tx < 8; tx++)
data[bx * 8 + tx, by * 8 + ty] = tileSet.tiles[blocks[i][bx + by * 4]][tx, ty];
imagedata.Add(data);
}
}
}
}