forked from ChnuckiErdbeer/Super-Mario-Land-Editor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForm1.cs
More file actions
303 lines (182 loc) · 11.1 KB
/
Form1.cs
File metadata and controls
303 lines (182 loc) · 11.1 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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SMLEdit
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public Form1(RomHeader romHeader)
{
this.romHeader = romHeader;
InitializeComponent();
}
public RomHeader romHeader = new RomHeader();
public Level[] levels = new Level[32];
public int lvlInFocus = 26;
//Functions:
private int calcRomAdr(int level, int address)
{
return 0x4000 * (level + 5) + address - 0x4000;
}
//Resizes a bitmap with nearest neighbour interpolation mode. (Thanks to Richard Knop and Michael for this code: http://stackoverflow.com/questions/4120339/resize-a-bitmap-like-ms-paint-no-antialiasing)
private Bitmap ResizeBitmap(Bitmap b, int nWidth, int nHeight)
{
Bitmap result = new Bitmap(nWidth, nHeight);
using (Graphics g = Graphics.FromImage((Image)result))
{
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
g.DrawImage(b, 0, 0, nWidth, nHeight);
}
return result;
}
private void openSMLROMToolStripMenuItem_Click(object sender, EventArgs e)
{
String filename = string.Empty;
OpenFileDialog ofdialog = new OpenFileDialog();
ofdialog.Filter = "Prepared SML-ROM (*.gb)|*.gb|All files (*.*) |*.*";
ofdialog.InitialDirectory = "D:\\In Arbeit\\SML\\rom backup";
ofdialog.Title = "Yea und Yea!";
if (ofdialog.ShowDialog() == DialogResult.OK)
filename = ofdialog.FileName;
//Open the stream and read it back.
try
{
using (FileStream fs = new FileStream (filename,FileMode.Open, FileAccess.Read))
{
//Read the supposedly prepared ROM-file into a byte array:
bool romCorrect = true; // To check for problems.
if (fs.Length != 1048611) // Check if ROM has the right size.
{
romCorrect = false;
MessageBox.Show("Sorry. The ROM's filesize has to be exactly 1MB. Did you pick a rom prepared for SMLED? If not try \"file->import ROM\" to prepare and open your ROM.");
}
byte[] rom = new byte[fs.Length]; //Create a byte array to contain the rom.
int spareBytes = (int)fs.Length; //Number of byes yet to be read.
int readBytes = 0; //Number of bytes read.
// Byte-step through the romfile and copy each byte to the byte-array "rom".
while (spareBytes > 0)
{
int n = fs.Read(rom, readBytes, spareBytes);
if (n == 0)
break;
readBytes += n;
spareBytes -= n;
}
// The ROM is now in memory! Lets fill the romHeader-object:
if (romCorrect) romCorrect = romHeader.set_entryPoint(rom); //Set entry-point.
if (romCorrect) romCorrect = romHeader.set_title(rom); //Set title.
if (romCorrect) romCorrect = romHeader.set_cardridgeType(rom); //Set cardridge type.
if (romCorrect) romCorrect = romHeader.set_romSize(rom); //Set rom size
if (romCorrect) romCorrect = romHeader.set_ramSize(rom); //Set ram size
if (romCorrect) romCorrect = romHeader.set_destinationCode(rom); //Set destination code
if (romCorrect) romCorrect = romHeader.set_oldLicenseeCode(rom); //Set old licensee code
if (romCorrect) romHeader.set_romVersionNuber(rom[0x14C]); //Set rom version number (Blank space intended for readability.)
if (romCorrect) romCorrect = romHeader.set_headerChecksum(rom); //Set header checksum
if (romCorrect) romHeader.set_globalChecksum(rom); //Set global checksum
// Set level objects:
for (int curLevNum = 0; curLevNum < 27; curLevNum++) //do this for all 27 possible levels.
{
Level cur_level = new Level(); //Create a new temp-level to fill it and add it to the list.
// Set variables from the level header:
if (romCorrect) romCorrect = cur_level.set_type (rom[calcRomAdr(curLevNum, 0x4040)]); //Set Level-Type (located at 0x4040 in current bank).
if (romCorrect) romCorrect = cur_level.set_music (rom[calcRomAdr(curLevNum, 0x4041)]); //Set Level-Music.
if (romCorrect) romCorrect = cur_level.set_musicBonus(rom[calcRomAdr(curLevNum, 0x4042)]); //Set Coinroom-Music.
if (romCorrect) romCorrect = cur_level.set_countdown (rom[calcRomAdr(curLevNum, 0x4043)]); //Set Level-Music.
// Set more complex level values:
if (romCorrect) cur_level.set_bonusScreenList(rom, curLevNum); //Set levels BonusScreenList.
if (romCorrect) cur_level.set_screenOrderList(rom, curLevNum); //Set levels ScreenOrderList.
if (romCorrect) cur_level.set_checkpointList (rom, curLevNum); //Set levels CheckpointList.
if (romCorrect) cur_level.set_bonuspipeList (rom, curLevNum); //Set levels BonusPipeList.
if (romCorrect) cur_level.set_entityList (rom, curLevNum); //Set levels EntityList.
if (romCorrect) cur_level.set_itemList (rom, curLevNum); //Set levels ItemList.
if (romCorrect) cur_level.set_tileMatrix (rom, curLevNum); //Set levels ItemList.
if (romCorrect) cur_level.set_TilePalette (rom, curLevNum); //Set levels TilePalette.
// FEHLT: Fill the remaining screens with 0xFF!!
levels[curLevNum] = cur_level;
}
}
MessageBox.Show("SPIELWIESE:");
/// Spielwiese >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><
Bitmap citrus = new Bitmap("d:\\citrus.bmp");
Point pnt = new Point(100, 100);
Size tile_on_screen_size = new Size(17,17);
Size screen_on_screen_size = new Size(340, 272);
// ENDE >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><
MessageBox.Show("ENDE SPIELWIESE");
// ENDE >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><
PictureBox[] tilepal = new PictureBox[256];
for (ushort i = 0; i < 256; i++)
{
System.Windows.Forms.PictureBox testbox = new System.Windows.Forms.PictureBox();
testbox.Size = tile_on_screen_size;
testbox.Margin = new Padding (1);
testbox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
testbox.BackgroundImage = levels[lvlInFocus].tilePal.getTile(i);
tilepal[i] = testbox;
}
TilePaletteDisplay.Controls.AddRange(tilepal); //
int numOfScreens = 32;
PictureBox[] levelLayout = new PictureBox[numOfScreens];
levels[lvlInFocus].tileMatrix.update_all_screens(levels[lvlInFocus].tilePal);
for (int i = 0; i < numOfScreens; i++) //Put each screen into a single picture box.
{
System.Windows.Forms.PictureBox tmpPicBox = new System.Windows.Forms.PictureBox(); //Create temporary picture box.
tmpPicBox.Size = screen_on_screen_size; //Configure the picture box.
tmpPicBox.Margin = new Padding(1);
Bitmap tmpScreen = levels[lvlInFocus].tileMatrix.screens[i];
tmpPicBox.BackgroundImage = tmpScreen;
levelLayout[i] = tmpPicBox;
}
LevelDisplay.Controls.AddRange(levelLayout);
}
catch (FileNotFoundException ioEx)
{
Console.WriteLine(ioEx.Message);
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void flowLayoutPanel1_Paint(object sender, PaintEventArgs e)
{
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
lvlInFocus = Convert.ToInt16(comboBox1.Text);
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
}
private void TileMatrix_Paint(object sender, PaintEventArgs e)
{
}
private void testpanel_Paint(object sender, PaintEventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
Bitmap citrus = new Bitmap("d:\\citrus.bmp");
Size tile_on_screen_size = new Size(16, 16);
System.Windows.Forms.PictureBox testbox = new System.Windows.Forms.PictureBox();
testbox.Size = tile_on_screen_size;
testbox.Margin = new Padding(1);
testbox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
testbox.Image = ResizeBitmap(citrus, 16, 16);
TilePaletteDisplay.Controls[41].BackgroundImage = citrus;
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
}
}