-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCharacterDisplayer.cs
More file actions
209 lines (172 loc) · 6.65 KB
/
CharacterDisplayer.cs
File metadata and controls
209 lines (172 loc) · 6.65 KB
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
using RetroDevStudio;
using System;
using System.Collections.Generic;
using System.Text;
namespace RetroDevStudio.Displayer
{
public class CharacterDisplayer
{
public static void DisplayHiResChar( GR.Memory.ByteBuffer Data, Palette Palette, int BGColor, int CharColor, GR.Image.IImage TargetImage, int X, int Y )
{
// single color
int colorIndex = 0;
for ( int j = 0; j < 8; ++j )
{
for ( int i = 0; i < 8; ++i )
{
if ( ( Data.ByteAt( j ) & ( 1 << ( 7 - i ) ) ) != 0 )
{
colorIndex = CharColor;
}
else
{
colorIndex = BGColor;
}
uint color = Palette.ColorValues[colorIndex];
TargetImage.SetPixel( X + i, Y + j, color );
}
}
}
public static void DisplayMultiColorChar( GR.Memory.ByteBuffer Data, Palette Palette, int BGColor, int MColor1, int MColor2, int CharColor, GR.Image.IImage TargetImage, int X, int Y )
{
// multicolor
if ( CharColor < 8 )
{
DisplayHiResChar( Data, Palette, BGColor, CharColor, TargetImage, X, Y );
return;
}
int charColor = CharColor - 8;
for ( int j = 0; j < 8; ++j )
{
for ( int i = 0; i < 4; ++i )
{
int pixelValue = ( Data.ByteAt( j ) & ( 3 << ( ( 3 - i ) * 2 ) ) ) >> ( ( 3 - i ) * 2 );
switch ( pixelValue )
{
case 0:
pixelValue = BGColor;
break;
case 1:
pixelValue = MColor1;
break;
case 2:
pixelValue = MColor2;
break;
case 3:
pixelValue = charColor;
break;
}
uint color = Palette.ColorValues[pixelValue];
TargetImage.SetPixel( X + i * 2, Y + j, color );
TargetImage.SetPixel( X + i * 2 + 1, Y + j, color );
}
}
}
public static void DisplayVC20Char( GR.Memory.ByteBuffer Data, Palette Palette, int BGColor, int MColor1, int MColor2, int CharColor, GR.Image.IImage TargetImage, int X, int Y )
{
// multicolor
if ( CharColor < 8 )
{
DisplayHiResChar( Data, Palette, BGColor, CharColor, TargetImage, X, Y );
return;
}
int charColor = CharColor - 8;
for ( int j = 0; j < 8; ++j )
{
for ( int i = 0; i < 4; ++i )
{
int pixelValue = ( Data.ByteAt( j ) & ( 3 << ( ( 3 - i ) * 2 ) ) ) >> ( ( 3 - i ) * 2 );
switch ( pixelValue )
{
case 0:
pixelValue = BGColor;
break;
case 1:
// border color(!)
pixelValue = MColor1;
break;
case 2:
pixelValue = charColor;
break;
case 3:
pixelValue = MColor2;
break;
}
uint color = Palette.ColorValues[pixelValue];
TargetImage.SetPixel( X + i * 2, Y + j, color );
TargetImage.SetPixel( X + i * 2 + 1, Y + j, color );
}
}
}
public static void DisplayMega65FCMChar( GR.Memory.ByteBuffer Data, Palette Palette, int BGColor, int CharColor, GR.Image.IImage TargetImage, int X, int Y )
{
for ( int j = 0; j < 8; ++j )
{
for ( int i = 0; i < 8; ++i )
{
int colorIndex = Data.ByteAt( i + j * 8 );
uint color = Palette.ColorValues[colorIndex];
TargetImage.SetPixel( X + i, Y + j, color );
}
}
}
public static void DisplayChar( Formats.CharsetProject Charset, int CharIndex, GR.Image.IImage TargetImage, int X, int Y )
{
Formats.CharData Char = Charset.Characters[CharIndex];
DisplayChar( Charset, CharIndex, TargetImage, X, Y, Char.Tile.CustomColor );
}
public static void DisplayChar( Formats.CharsetProject Charset, int CharIndex, GR.Image.IImage TargetImage, int X, int Y, int AlternativeColor )
{
DisplayChar( Charset, CharIndex, TargetImage, X, Y, AlternativeColor, Charset.Colors.BackgroundColor, Charset.Colors.MultiColor1, Charset.Colors.MultiColor2, Charset.Colors.BGColor4 );
}
public static void DisplayChar( Formats.CharsetProject Charset, int CharIndex, GR.Image.IImage TargetImage, int X, int Y, int AlternativeColor, int AltBGColor, int AltMColor1, int AltMColor2, int AltBGColor4 )
{
Formats.CharData Char = Charset.Characters[CharIndex];
DisplayChar( Charset, CharIndex, TargetImage, X, Y, AlternativeColor, AltBGColor, AltMColor1, AltMColor2, AltBGColor4, Charset.Mode );
}
public static void DisplayChar( Formats.CharsetProject Charset, int CharIndex, GR.Image.IImage TargetImage, int X, int Y, int AlternativeColor, int AltBGColor, int AltMColor1, int AltMColor2, int AltBGColor4, TextCharMode AlternativeMode )
{
Formats.CharData Char = Charset.Characters[CharIndex];
if ( AlternativeMode == TextCharMode.COMMODORE_ECM )
{
// ECM
Formats.CharData origChar = Charset.Characters[CharIndex % 64];
int bgColor = AltBGColor;
switch ( CharIndex / 64 )
{
case 1:
bgColor = AltMColor1;
break;
case 2:
bgColor = AltMColor2;
break;
case 3:
bgColor = AltBGColor4;
break;
}
DisplayHiResChar( origChar.Tile.Data, Charset.Colors.Palette, bgColor, AlternativeColor, TargetImage, X, Y );
}
else if ( AlternativeMode == TextCharMode.COMMODORE_MULTICOLOR )
{
DisplayMultiColorChar( Char.Tile.Data, Charset.Colors.Palette, AltBGColor, AltMColor1, AltMColor2, AlternativeColor, TargetImage, X, Y );
}
else if ( AlternativeMode == TextCharMode.COMMODORE_HIRES )
{
DisplayHiResChar( Char.Tile.Data, Charset.Colors.Palette, AltBGColor, AlternativeColor, TargetImage, X, Y );
}
else if ( ( AlternativeMode == TextCharMode.MEGA65_FCM )
|| ( AlternativeMode == TextCharMode.MEGA65_FCM_16BIT ) )
{
DisplayMega65FCMChar( Char.Tile.Data, Charset.Colors.Palette, AltBGColor, AlternativeColor, TargetImage, X, Y );
}
else if ( AlternativeMode == TextCharMode.VIC20 )
{
DisplayVC20Char( Char.Tile.Data, Charset.Colors.Palette, AltBGColor, AltMColor1, AltMColor2, AlternativeColor, TargetImage, X, Y );
}
else
{
Debug.Log( "DisplayChar #2 unsupported mode " + AlternativeMode );
}
}
}
}