-
Notifications
You must be signed in to change notification settings - Fork 2
/
GameText.cs
129 lines (124 loc) · 3.58 KB
/
GameText.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace sth1edwv
{
public class GameText
{
public bool isLower;
public byte[] raw;
public byte X;
public byte Y;
public string text;
public GameText(byte[] data, bool isLowerMap)
{
raw = data;
isLower = isLowerMap;
X = data[0];
Y = data[1];
text = "";
for (int i = 2; i < data.Length - 1; i++)
{
if (isLower && lowChars.ContainsKey(data[i]))
text += lowChars[data[i]];
if (!isLower && highChars.ContainsKey(data[i]))
text += highChars[data[i]];
}
}
public void WriteToMemory(int pos, byte x, byte y, string s, int fillSize = 12)
{
Cartridge.memory[pos] = x;
Cartridge.memory[pos + 1] = y;
for (int i = 0; i < fillSize; i++)
{
if (i < s.Length)
{
if (isLower)
{
foreach (KeyValuePair<byte, char> pair in lowChars)
if (pair.Value == s[i])
{
Cartridge.memory[pos + 2 + i] = pair.Key;
break;
}
}
else
{
foreach (KeyValuePair<byte, char> pair in highChars)
if (pair.Value == s[i])
{
Cartridge.memory[pos + 2 + i] = pair.Key;
break;
}
}
}
else
Cartridge.memory[pos + 2 + i] = 0xEB;
}
}
public static Dictionary<byte, char> lowChars = new Dictionary<byte, char>()
{
{0x34, 'A'},
{0x35, 'B'},
{0x36, 'C'},
{0x37, 'D'},
{0x44, 'E'},
{0x45, 'F'},
{0x46, 'G'},
{0x47, 'H'},
{0x40, 'I'},
{0x41, 'J'},
{0x42, 'K'},
{0x43, 'L'},
{0x50, 'M'},
{0x51, 'N'},
{0x52, 'O'},
{0x60, 'P'},
{0x61, 'Q'},
{0x62, 'R'},
{0x70, 'S'},
{0x80, 'T'},
{0x81, 'U'},
{0x54, 'V'},
{0x3C, 'W'},
{0x3D, 'X'},
{0x3E, 'Y'},
{0x3F, 'Z'},
{0xCF, '©'},
{0xEB, ' '}
};
public static Dictionary<byte, char> highChars = new Dictionary<byte, char>()
{
{0x1E, 'A'},
{0x1F, 'B'},
{0x2E, 'C'},
{0x2F, 'D'},
{0x3E, 'E'},
{0x3F, 'F'},
{0x4E, 'G'},
{0x4F, 'H'},
{0x5E, 'I'},
{0x5F, 'J'},
{0x6E, 'K'},
{0x6F, 'L'},
{0x7E, 'M'},
{0x7F, 'N'},
{0x8E, 'O'},
{0x8F, 'P'},
{0x9E, 'Q'},
{0x9F, 'R'},
{0xAE, 'S'},
{0xAF, 'T'},
{0xBE, 'U'},
{0xBF, 'V'},
{0xCE, 'W'},
{0xCF, 'X'},
{0xDE, 'Y'},
{0xDF, 'Z'},
{0xAB, '©'},
{0xEB, ' '}
};
}
}