rlm@1
|
1 // GBMapView.cpp : implementation file
|
rlm@1
|
2 //
|
rlm@1
|
3
|
rlm@1
|
4 #include "stdafx.h"
|
rlm@1
|
5 #include "resource.h"
|
rlm@1
|
6 #include "GBMapView.h"
|
rlm@1
|
7 #include "FileDlg.h"
|
rlm@1
|
8 #include "Reg.h"
|
rlm@1
|
9 #include "WinResUtil.h"
|
rlm@1
|
10 #include "VBA.h"
|
rlm@1
|
11
|
rlm@1
|
12 //#include "../common/System.h"
|
rlm@1
|
13 #include "../gb/gbGlobals.h"
|
rlm@1
|
14 #include "../NLS.h"
|
rlm@1
|
15 #include "../common/Util.h"
|
rlm@1
|
16
|
rlm@1
|
17 extern "C" {
|
rlm@1
|
18 #include <png.h>
|
rlm@1
|
19 }
|
rlm@1
|
20
|
rlm@1
|
21 extern u8 gbInvertTab[256];
|
rlm@1
|
22
|
rlm@1
|
23 /////////////////////////////////////////////////////////////////////////////
|
rlm@1
|
24 // GBMapView dialog
|
rlm@1
|
25
|
rlm@1
|
26 GBMapView::GBMapView(CWnd*pParent /*=NULL*/)
|
rlm@1
|
27 : ResizeDlg(GBMapView::IDD, pParent)
|
rlm@1
|
28 {
|
rlm@1
|
29 //{{AFX_DATA_INIT(GBMapView)
|
rlm@1
|
30 // NOTE: the ClassWizard will add member initialization here
|
rlm@1
|
31 //}}AFX_DATA_INIT
|
rlm@1
|
32 autoUpdate = false;
|
rlm@1
|
33
|
rlm@1
|
34 memset(&bmpInfo.bmiHeader, 0, sizeof(bmpInfo.bmiHeader));
|
rlm@1
|
35
|
rlm@1
|
36 bmpInfo.bmiHeader.biSize = sizeof(bmpInfo.bmiHeader);
|
rlm@1
|
37 bmpInfo.bmiHeader.biWidth = 1024;
|
rlm@1
|
38 bmpInfo.bmiHeader.biHeight = -1024;
|
rlm@1
|
39 bmpInfo.bmiHeader.biPlanes = 1;
|
rlm@1
|
40 bmpInfo.bmiHeader.biBitCount = 24;
|
rlm@1
|
41 bmpInfo.bmiHeader.biCompression = BI_RGB;
|
rlm@1
|
42 data = (u8 *)calloc(1, 3 * 1024 * 1024);
|
rlm@1
|
43
|
rlm@1
|
44 mapView.setData(data);
|
rlm@1
|
45 mapView.setBmpInfo(&bmpInfo);
|
rlm@1
|
46
|
rlm@1
|
47 bg = 0;
|
rlm@1
|
48 bank = 0;
|
rlm@1
|
49 }
|
rlm@1
|
50
|
rlm@1
|
51 void GBMapView::DoDataExchange(CDataExchange*pDX)
|
rlm@1
|
52 {
|
rlm@1
|
53 CDialog::DoDataExchange(pDX);
|
rlm@1
|
54 //{{AFX_DATA_MAP(GBMapView)
|
rlm@1
|
55 // NOTE: the ClassWizard will add DDX and DDV calls here
|
rlm@1
|
56 //}}AFX_DATA_MAP
|
rlm@1
|
57 DDX_Control(pDX, IDC_MAP_VIEW, mapView);
|
rlm@1
|
58 DDX_Control(pDX, IDC_MAP_VIEW_ZOOM, mapViewZoom);
|
rlm@1
|
59 DDX_Control(pDX, IDC_COLOR, color);
|
rlm@1
|
60 }
|
rlm@1
|
61
|
rlm@1
|
62 BEGIN_MESSAGE_MAP(GBMapView, CDialog)
|
rlm@1
|
63 //{{AFX_MSG_MAP(GBMapView)
|
rlm@1
|
64 ON_BN_CLICKED(IDC_SAVE, OnSave)
|
rlm@1
|
65 ON_BN_CLICKED(IDC_REFRESH, OnRefresh)
|
rlm@1
|
66 ON_BN_CLICKED(IDC_BG0, OnBg0)
|
rlm@1
|
67 ON_BN_CLICKED(IDC_BG1, OnBg1)
|
rlm@1
|
68 ON_BN_CLICKED(IDC_BANK_0, OnBank0)
|
rlm@1
|
69 ON_BN_CLICKED(IDC_BANK_1, OnBank1)
|
rlm@1
|
70 ON_BN_CLICKED(IDC_STRETCH, OnStretch)
|
rlm@1
|
71 ON_BN_CLICKED(IDC_AUTO_UPDATE, OnAutoUpdate)
|
rlm@1
|
72 ON_BN_CLICKED(IDC_CLOSE, OnClose)
|
rlm@1
|
73 //}}AFX_MSG_MAP
|
rlm@1
|
74 ON_MESSAGE(WM_MAPINFO, OnMapInfo)
|
rlm@1
|
75 ON_MESSAGE(WM_COLINFO, OnColInfo)
|
rlm@1
|
76 END_MESSAGE_MAP()
|
rlm@1
|
77
|
rlm@1
|
78 /////////////////////////////////////////////////////////////////////////////
|
rlm@1
|
79 // GBMapView message handlers
|
rlm@1
|
80
|
rlm@1
|
81 GBMapView::~GBMapView()
|
rlm@1
|
82 {
|
rlm@1
|
83 free(data);
|
rlm@1
|
84 data = NULL;
|
rlm@1
|
85 }
|
rlm@1
|
86
|
rlm@1
|
87 void GBMapView::saveBMP(const char *name)
|
rlm@1
|
88 {
|
rlm@1
|
89 u8 writeBuffer[1024 * 3];
|
rlm@1
|
90
|
rlm@1
|
91 FILE *fp = fopen(name, "wb");
|
rlm@1
|
92
|
rlm@1
|
93 if (!fp)
|
rlm@1
|
94 {
|
rlm@1
|
95 systemMessage(MSG_ERROR_CREATING_FILE, "Error creating file %s", name);
|
rlm@1
|
96 return;
|
rlm@1
|
97 }
|
rlm@1
|
98
|
rlm@1
|
99 struct
|
rlm@1
|
100 {
|
rlm@1
|
101 u8 ident[2];
|
rlm@1
|
102 u8 filesize[4];
|
rlm@1
|
103 u8 reserved[4];
|
rlm@1
|
104 u8 dataoffset[4];
|
rlm@1
|
105 u8 headersize[4];
|
rlm@1
|
106 u8 width[4];
|
rlm@1
|
107 u8 height[4];
|
rlm@1
|
108 u8 planes[2];
|
rlm@1
|
109 u8 bitsperpixel[2];
|
rlm@1
|
110 u8 compression[4];
|
rlm@1
|
111 u8 datasize[4];
|
rlm@1
|
112 u8 hres[4];
|
rlm@1
|
113 u8 vres[4];
|
rlm@1
|
114 u8 colors[4];
|
rlm@1
|
115 u8 importantcolors[4];
|
rlm@1
|
116 u8 pad[2];
|
rlm@1
|
117 } bmpheader;
|
rlm@1
|
118 memset(&bmpheader, 0, sizeof(bmpheader));
|
rlm@1
|
119
|
rlm@1
|
120 bmpheader.ident[0] = 'B';
|
rlm@1
|
121 bmpheader.ident[1] = 'M';
|
rlm@1
|
122
|
rlm@1
|
123 u32 fsz = sizeof(bmpheader) + w*h*3;
|
rlm@1
|
124 utilPutDword(bmpheader.filesize, fsz);
|
rlm@1
|
125 utilPutDword(bmpheader.dataoffset, 0x38);
|
rlm@1
|
126 utilPutDword(bmpheader.headersize, 0x28);
|
rlm@1
|
127 utilPutDword(bmpheader.width, w);
|
rlm@1
|
128 utilPutDword(bmpheader.height, h);
|
rlm@1
|
129 utilPutDword(bmpheader.planes, 1);
|
rlm@1
|
130 utilPutDword(bmpheader.bitsperpixel, 24);
|
rlm@1
|
131 utilPutDword(bmpheader.datasize, 3*w*h);
|
rlm@1
|
132
|
rlm@1
|
133 fwrite(&bmpheader, 1, sizeof(bmpheader), fp);
|
rlm@1
|
134
|
rlm@1
|
135 u8 *b = writeBuffer;
|
rlm@1
|
136
|
rlm@1
|
137 int sizeX = w;
|
rlm@1
|
138 int sizeY = h;
|
rlm@1
|
139
|
rlm@1
|
140 u8 *pixU8 = (u8 *)data+3*w*(h-1);
|
rlm@1
|
141 for (int y = 0; y < sizeY; y++)
|
rlm@1
|
142 {
|
rlm@1
|
143 for (int x = 0; x < sizeX; x++)
|
rlm@1
|
144 {
|
rlm@1
|
145 *b++ = *pixU8++; // B
|
rlm@1
|
146 *b++ = *pixU8++; // G
|
rlm@1
|
147 *b++ = *pixU8++; // R
|
rlm@1
|
148 }
|
rlm@1
|
149 pixU8 -= 2*3*w;
|
rlm@1
|
150 fwrite(writeBuffer, 1, 3*w, fp);
|
rlm@1
|
151
|
rlm@1
|
152 b = writeBuffer;
|
rlm@1
|
153 }
|
rlm@1
|
154
|
rlm@1
|
155 fclose(fp);
|
rlm@1
|
156 }
|
rlm@1
|
157
|
rlm@1
|
158 void GBMapView::savePNG(const char *name)
|
rlm@1
|
159 {
|
rlm@1
|
160 u8 writeBuffer[1024 * 3];
|
rlm@1
|
161
|
rlm@1
|
162 FILE *fp = fopen(name, "wb");
|
rlm@1
|
163
|
rlm@1
|
164 if (!fp)
|
rlm@1
|
165 {
|
rlm@1
|
166 systemMessage(MSG_ERROR_CREATING_FILE, "Error creating file %s", name);
|
rlm@1
|
167 return;
|
rlm@1
|
168 }
|
rlm@1
|
169
|
rlm@1
|
170 png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,
|
rlm@1
|
171 NULL,
|
rlm@1
|
172 NULL,
|
rlm@1
|
173 NULL);
|
rlm@1
|
174 if (!png_ptr)
|
rlm@1
|
175 {
|
rlm@1
|
176 fclose(fp);
|
rlm@1
|
177 return;
|
rlm@1
|
178 }
|
rlm@1
|
179
|
rlm@1
|
180 png_infop info_ptr = png_create_info_struct(png_ptr);
|
rlm@1
|
181
|
rlm@1
|
182 if (!info_ptr)
|
rlm@1
|
183 {
|
rlm@1
|
184 png_destroy_write_struct(&png_ptr, NULL);
|
rlm@1
|
185 fclose(fp);
|
rlm@1
|
186 return;
|
rlm@1
|
187 }
|
rlm@1
|
188
|
rlm@1
|
189 if (setjmp(png_ptr->jmpbuf))
|
rlm@1
|
190 {
|
rlm@1
|
191 png_destroy_write_struct(&png_ptr, NULL);
|
rlm@1
|
192 fclose(fp);
|
rlm@1
|
193 return;
|
rlm@1
|
194 }
|
rlm@1
|
195
|
rlm@1
|
196 png_init_io(png_ptr, fp);
|
rlm@1
|
197
|
rlm@1
|
198 png_set_IHDR(png_ptr,
|
rlm@1
|
199 info_ptr,
|
rlm@1
|
200 w,
|
rlm@1
|
201 h,
|
rlm@1
|
202 8,
|
rlm@1
|
203 PNG_COLOR_TYPE_RGB,
|
rlm@1
|
204 PNG_INTERLACE_NONE,
|
rlm@1
|
205 PNG_COMPRESSION_TYPE_DEFAULT,
|
rlm@1
|
206 PNG_FILTER_TYPE_DEFAULT);
|
rlm@1
|
207
|
rlm@1
|
208 png_write_info(png_ptr, info_ptr);
|
rlm@1
|
209
|
rlm@1
|
210 u8 *b = writeBuffer;
|
rlm@1
|
211
|
rlm@1
|
212 int sizeX = w;
|
rlm@1
|
213 int sizeY = h;
|
rlm@1
|
214
|
rlm@1
|
215 u8 *pixU8 = (u8 *)data;
|
rlm@1
|
216 for (int y = 0; y < sizeY; y++)
|
rlm@1
|
217 {
|
rlm@1
|
218 for (int x = 0; x < sizeX; x++)
|
rlm@1
|
219 {
|
rlm@1
|
220 int blue = *pixU8++;
|
rlm@1
|
221 int green = *pixU8++;
|
rlm@1
|
222 int red = *pixU8++;
|
rlm@1
|
223
|
rlm@1
|
224 *b++ = red;
|
rlm@1
|
225 *b++ = green;
|
rlm@1
|
226 *b++ = blue;
|
rlm@1
|
227 }
|
rlm@1
|
228 png_write_row(png_ptr, writeBuffer);
|
rlm@1
|
229
|
rlm@1
|
230 b = writeBuffer;
|
rlm@1
|
231 }
|
rlm@1
|
232
|
rlm@1
|
233 png_write_end(png_ptr, info_ptr);
|
rlm@1
|
234
|
rlm@1
|
235 png_destroy_write_struct(&png_ptr, &info_ptr);
|
rlm@1
|
236
|
rlm@1
|
237 fclose(fp);
|
rlm@1
|
238 }
|
rlm@1
|
239
|
rlm@1
|
240 void GBMapView::OnSave()
|
rlm@1
|
241 {
|
rlm@1
|
242 CString filename;
|
rlm@1
|
243
|
rlm@1
|
244 if (theApp.captureFormat == 0)
|
rlm@1
|
245 filename = "map.png";
|
rlm@1
|
246 else
|
rlm@1
|
247 filename = "map.bmp";
|
rlm@1
|
248
|
rlm@1
|
249 LPCTSTR exts[] = {".png", ".bmp", NULL };
|
rlm@1
|
250 CString filter = winResLoadFilter(IDS_FILTER_PNG);
|
rlm@1
|
251 CString title = winResLoadString(IDS_SELECT_CAPTURE_NAME);
|
rlm@1
|
252
|
rlm@1
|
253 FileDlg dlg(this,
|
rlm@1
|
254 filename,
|
rlm@1
|
255 filter,
|
rlm@1
|
256 theApp.captureFormat ? 2 : 1,
|
rlm@1
|
257 theApp.captureFormat ? "BMP" : "PNG",
|
rlm@1
|
258 exts,
|
rlm@1
|
259 "",
|
rlm@1
|
260 title,
|
rlm@1
|
261 true);
|
rlm@1
|
262
|
rlm@1
|
263 if (dlg.DoModal() == IDCANCEL)
|
rlm@1
|
264 {
|
rlm@1
|
265 return;
|
rlm@1
|
266 }
|
rlm@1
|
267
|
rlm@1
|
268 if (dlg.getFilterIndex() == 2)
|
rlm@1
|
269 saveBMP(dlg.GetPathName());
|
rlm@1
|
270 else
|
rlm@1
|
271 savePNG(dlg.GetPathName());
|
rlm@1
|
272 }
|
rlm@1
|
273
|
rlm@1
|
274 void GBMapView::render()
|
rlm@1
|
275 {
|
rlm@1
|
276 u8 *bank0;
|
rlm@1
|
277 u8 *bank1;
|
rlm@1
|
278 if (gbCgbMode)
|
rlm@1
|
279 {
|
rlm@1
|
280 bank0 = &gbVram[0x0000];
|
rlm@1
|
281 bank1 = &gbVram[0x2000];
|
rlm@1
|
282 }
|
rlm@1
|
283 else
|
rlm@1
|
284 {
|
rlm@1
|
285 bank0 = &gbMemory[0x8000];
|
rlm@1
|
286 bank1 = NULL;
|
rlm@1
|
287 }
|
rlm@1
|
288
|
rlm@1
|
289 int tile_map_address = 0x1800;
|
rlm@1
|
290 if (bg == 1)
|
rlm@1
|
291 tile_map_address = 0x1c00;
|
rlm@1
|
292
|
rlm@1
|
293 int tile_pattern = 0x0000;
|
rlm@1
|
294 if (bank == 1)
|
rlm@1
|
295 tile_pattern = 0x0800;
|
rlm@1
|
296
|
rlm@1
|
297 w = 256;
|
rlm@1
|
298 h = 256;
|
rlm@1
|
299
|
rlm@1
|
300 int tile = 0;
|
rlm@1
|
301 for (int y = 0; y < 32; y++)
|
rlm@1
|
302 {
|
rlm@1
|
303 for (int x = 0; x < 32; x++)
|
rlm@1
|
304 {
|
rlm@1
|
305 u8 *bmp = &data[y * 8 * 32 * 24 + x*24];
|
rlm@1
|
306 u8 attrs = 0;
|
rlm@1
|
307 if (bank1 != NULL)
|
rlm@1
|
308 attrs = bank1[tile_map_address];
|
rlm@1
|
309 u8 tile = bank0[tile_map_address];
|
rlm@1
|
310 tile_map_address++;
|
rlm@1
|
311
|
rlm@1
|
312 if (bank == 1)
|
rlm@1
|
313 {
|
rlm@1
|
314 if (tile < 128)
|
rlm@1
|
315 tile += 128;
|
rlm@1
|
316 else
|
rlm@1
|
317 tile -= 128;
|
rlm@1
|
318 }
|
rlm@1
|
319 for (int j = 0; j < 8; j++)
|
rlm@1
|
320 {
|
rlm@1
|
321 int tile_pattern_address = attrs & 0x40 ?
|
rlm@1
|
322 tile_pattern + tile*16 + (7-j)*2 :
|
rlm@1
|
323 tile_pattern + tile*16+j*2;
|
rlm@1
|
324
|
rlm@1
|
325 u8 tile_a = 0;
|
rlm@1
|
326 u8 tile_b = 0;
|
rlm@1
|
327
|
rlm@1
|
328 if (attrs & 0x08)
|
rlm@1
|
329 {
|
rlm@1
|
330 tile_a = bank1[tile_pattern_address++];
|
rlm@1
|
331 tile_b = bank1[tile_pattern_address];
|
rlm@1
|
332 }
|
rlm@1
|
333 else
|
rlm@1
|
334 {
|
rlm@1
|
335 tile_a = bank0[tile_pattern_address++];
|
rlm@1
|
336 tile_b = bank0[tile_pattern_address];
|
rlm@1
|
337 }
|
rlm@1
|
338
|
rlm@1
|
339 if (attrs & 0x20)
|
rlm@1
|
340 {
|
rlm@1
|
341 tile_a = gbInvertTab[tile_a];
|
rlm@1
|
342 tile_b = gbInvertTab[tile_b];
|
rlm@1
|
343 }
|
rlm@1
|
344
|
rlm@1
|
345 u8 mask = 0x80;
|
rlm@1
|
346
|
rlm@1
|
347 while (mask > 0)
|
rlm@1
|
348 {
|
rlm@1
|
349 u8 c = (tile_a & mask) ? 1 : 0;
|
rlm@1
|
350 c += (tile_b & mask) ? 2 : 0;
|
rlm@1
|
351
|
rlm@1
|
352 if (gbCgbMode)
|
rlm@1
|
353 c = c + (attrs & 7)*4;
|
rlm@1
|
354
|
rlm@1
|
355 u16 color = gbPalette[c];
|
rlm@1
|
356
|
rlm@1
|
357 *bmp++ = ((color >> 10) & 0x1f) << 3;
|
rlm@1
|
358 *bmp++ = ((color >> 5) & 0x1f) << 3;
|
rlm@1
|
359 *bmp++ = (color & 0x1f) << 3;
|
rlm@1
|
360
|
rlm@1
|
361 mask >>= 1;
|
rlm@1
|
362 }
|
rlm@1
|
363 bmp += 31*24;
|
rlm@1
|
364 }
|
rlm@1
|
365 }
|
rlm@1
|
366 }
|
rlm@1
|
367 }
|
rlm@1
|
368
|
rlm@1
|
369 void GBMapView::paint()
|
rlm@1
|
370 {
|
rlm@1
|
371 if (gbRom == NULL)
|
rlm@1
|
372 return;
|
rlm@1
|
373 render();
|
rlm@1
|
374
|
rlm@1
|
375 SIZE s;
|
rlm@1
|
376 if (mapView.getStretch())
|
rlm@1
|
377 {
|
rlm@1
|
378 mapView.setSize(w, h);
|
rlm@1
|
379 s.cx = s.cy = 1;
|
rlm@1
|
380 mapView.SetScrollSizes(MM_TEXT, s);
|
rlm@1
|
381 }
|
rlm@1
|
382 else
|
rlm@1
|
383 {
|
rlm@1
|
384 mapView.setSize(w, h);
|
rlm@1
|
385 s.cx = w;
|
rlm@1
|
386 s.cy = h;
|
rlm@1
|
387 mapView.SetScrollSizes(MM_TEXT, s);
|
rlm@1
|
388 }
|
rlm@1
|
389
|
rlm@1
|
390 mapView.refresh();
|
rlm@1
|
391 }
|
rlm@1
|
392
|
rlm@1
|
393 void GBMapView::OnRefresh()
|
rlm@1
|
394 {
|
rlm@1
|
395 paint();
|
rlm@1
|
396 }
|
rlm@1
|
397
|
rlm@1
|
398 void GBMapView::update()
|
rlm@1
|
399 {
|
rlm@1
|
400 paint();
|
rlm@1
|
401 }
|
rlm@1
|
402
|
rlm@1
|
403 BOOL GBMapView::OnInitDialog()
|
rlm@1
|
404 {
|
rlm@1
|
405 CDialog::OnInitDialog();
|
rlm@1
|
406
|
rlm@1
|
407 DIALOG_SIZER_START(sz)
|
rlm@1
|
408 DIALOG_SIZER_ENTRY(IDC_MAP_VIEW, DS_SizeX | DS_SizeY)
|
rlm@1
|
409 DIALOG_SIZER_ENTRY(IDC_REFRESH, DS_MoveY)
|
rlm@1
|
410 DIALOG_SIZER_ENTRY(IDC_CLOSE, DS_MoveY)
|
rlm@1
|
411 DIALOG_SIZER_ENTRY(IDC_SAVE, DS_MoveY)
|
rlm@1
|
412 DIALOG_SIZER_ENTRY(IDC_COLOR, DS_MoveY)
|
rlm@1
|
413 DIALOG_SIZER_ENTRY(IDC_R, DS_MoveY)
|
rlm@1
|
414 DIALOG_SIZER_ENTRY(IDC_G, DS_MoveY)
|
rlm@1
|
415 DIALOG_SIZER_ENTRY(IDC_B, DS_MoveY)
|
rlm@1
|
416 DIALOG_SIZER_END()
|
rlm@1
|
417 SetData(sz,
|
rlm@1
|
418 TRUE,
|
rlm@1
|
419 HKEY_CURRENT_USER,
|
rlm@1
|
420 "Software\\Emulators\\VisualBoyAdvance\\Viewer\\GBMapView",
|
rlm@1
|
421 NULL);
|
rlm@1
|
422
|
rlm@1
|
423 int s = regQueryDwordValue("mapViewStretch", 0);
|
rlm@1
|
424 if (s)
|
rlm@1
|
425 mapView.setStretch(true);
|
rlm@1
|
426 ((CButton *)GetDlgItem(IDC_STRETCH))->SetCheck(s);
|
rlm@1
|
427
|
rlm@1
|
428 UINT id = IDC_BANK_0;
|
rlm@1
|
429 if (bank == 1)
|
rlm@1
|
430 id = IDC_BANK_1;
|
rlm@1
|
431 CheckRadioButton(IDC_BANK_0, IDC_BANK_1, id);
|
rlm@1
|
432 id = IDC_BG0;
|
rlm@1
|
433 if (bg == 1)
|
rlm@1
|
434 id = IDC_BG1;
|
rlm@1
|
435 CheckRadioButton(IDC_BG0, IDC_BG1, id);
|
rlm@1
|
436 paint();
|
rlm@1
|
437
|
rlm@1
|
438 return TRUE; // return TRUE unless you set the focus to a control
|
rlm@1
|
439 // EXCEPTION: OCX Property Pages should return FALSE
|
rlm@1
|
440 }
|
rlm@1
|
441
|
rlm@1
|
442 void GBMapView::OnBg0()
|
rlm@1
|
443 {
|
rlm@1
|
444 bg = 0;
|
rlm@1
|
445 paint();
|
rlm@1
|
446 }
|
rlm@1
|
447
|
rlm@1
|
448 void GBMapView::OnBg1()
|
rlm@1
|
449 {
|
rlm@1
|
450 bg = 1;
|
rlm@1
|
451 paint();
|
rlm@1
|
452 }
|
rlm@1
|
453
|
rlm@1
|
454 void GBMapView::OnBank0()
|
rlm@1
|
455 {
|
rlm@1
|
456 bank = 0;
|
rlm@1
|
457 paint();
|
rlm@1
|
458 }
|
rlm@1
|
459
|
rlm@1
|
460 void GBMapView::OnBank1()
|
rlm@1
|
461 {
|
rlm@1
|
462 bank = 1;
|
rlm@1
|
463 paint();
|
rlm@1
|
464 }
|
rlm@1
|
465
|
rlm@1
|
466 void GBMapView::OnStretch()
|
rlm@1
|
467 {
|
rlm@1
|
468 mapView.setStretch(!mapView.getStretch());
|
rlm@1
|
469 paint();
|
rlm@1
|
470 regSetDwordValue("mapViewStretch", mapView.getStretch());
|
rlm@1
|
471 }
|
rlm@1
|
472
|
rlm@1
|
473 void GBMapView::OnAutoUpdate()
|
rlm@1
|
474 {
|
rlm@1
|
475 autoUpdate = !autoUpdate;
|
rlm@1
|
476 if (autoUpdate)
|
rlm@1
|
477 {
|
rlm@1
|
478 theApp.winAddUpdateListener(this);
|
rlm@1
|
479 }
|
rlm@1
|
480 else
|
rlm@1
|
481 {
|
rlm@1
|
482 theApp.winRemoveUpdateListener(this);
|
rlm@1
|
483 }
|
rlm@1
|
484 }
|
rlm@1
|
485
|
rlm@1
|
486 void GBMapView::OnClose()
|
rlm@1
|
487 {
|
rlm@1
|
488 theApp.winRemoveUpdateListener(this);
|
rlm@1
|
489
|
rlm@1
|
490 DestroyWindow();
|
rlm@1
|
491 }
|
rlm@1
|
492
|
rlm@1
|
493 u32 GBMapView::GetClickAddress(int x, int y)
|
rlm@1
|
494 {
|
rlm@1
|
495 u32 base = 0x9800;
|
rlm@1
|
496 if (bg == 1)
|
rlm@1
|
497 base = 0x9c00;
|
rlm@1
|
498
|
rlm@1
|
499 return base + (y >> 3)*32 + (x >> 3);
|
rlm@1
|
500 }
|
rlm@1
|
501
|
rlm@1
|
502 LRESULT GBMapView::OnMapInfo(WPARAM wParam, LPARAM lParam)
|
rlm@1
|
503 {
|
rlm@1
|
504 u8 *colors = (u8 *)lParam;
|
rlm@1
|
505 mapViewZoom.setColors(colors);
|
rlm@1
|
506
|
rlm@1
|
507 int x = wParam & 0xffff;
|
rlm@1
|
508 int y = (wParam >> 16);
|
rlm@1
|
509
|
rlm@1
|
510 CString buffer;
|
rlm@1
|
511 buffer.Format("(%d,%d)", x, y);
|
rlm@1
|
512 GetDlgItem(IDC_XY)->SetWindowText(buffer);
|
rlm@1
|
513
|
rlm@1
|
514 u32 address = GetClickAddress(x, y);
|
rlm@1
|
515 buffer.Format("0x%08X", address);
|
rlm@1
|
516 GetDlgItem(IDC_ADDRESS)->SetWindowText(buffer);
|
rlm@1
|
517
|
rlm@1
|
518 u8 attrs = 0;
|
rlm@1
|
519
|
rlm@1
|
520 u8 tile = gbReadMemoryQuick(0x9000 | (address & 0xfff));
|
rlm@1
|
521 if (gbCgbMode)
|
rlm@1
|
522 {
|
rlm@1
|
523 attrs = gbVram[0x2000 + address - 0x8000];
|
rlm@1
|
524 tile = gbVram[address & 0x1fff];
|
rlm@1
|
525 }
|
rlm@1
|
526
|
rlm@1
|
527 if (bank == 1)
|
rlm@1
|
528 {
|
rlm@1
|
529 if (tile > 128)
|
rlm@1
|
530 tile -= 128;
|
rlm@1
|
531 else
|
rlm@1
|
532 tile += 128;
|
rlm@1
|
533 }
|
rlm@1
|
534
|
rlm@1
|
535 buffer.Format("%d", tile);
|
rlm@1
|
536 GetDlgItem(IDC_TILE_NUM)->SetWindowText(buffer);
|
rlm@1
|
537
|
rlm@1
|
538 buffer.Empty();
|
rlm@1
|
539 buffer += attrs & 0x20 ? 'H' : '-';
|
rlm@1
|
540 buffer += attrs & 0x40 ? 'V' : '-';
|
rlm@1
|
541 GetDlgItem(IDC_FLIP)->SetWindowText(buffer);
|
rlm@1
|
542
|
rlm@1
|
543 if (gbCgbMode)
|
rlm@1
|
544 {
|
rlm@1
|
545 buffer.Format("%d", (attrs & 7));
|
rlm@1
|
546 }
|
rlm@1
|
547 else
|
rlm@1
|
548 buffer = "---";
|
rlm@1
|
549 GetDlgItem(IDC_PALETTE_NUM)->SetWindowText(buffer);
|
rlm@1
|
550
|
rlm@1
|
551 buffer.Empty();
|
rlm@1
|
552 if (gbCgbMode)
|
rlm@1
|
553 buffer += attrs & 0x80 ? 'P' : '-';
|
rlm@1
|
554 else
|
rlm@1
|
555 buffer += '-';
|
rlm@1
|
556 GetDlgItem(IDC_PRIORITY)->SetWindowText(buffer);
|
rlm@1
|
557
|
rlm@1
|
558 return TRUE;
|
rlm@1
|
559 }
|
rlm@1
|
560
|
rlm@1
|
561 LRESULT GBMapView::OnColInfo(WPARAM wParam, LPARAM)
|
rlm@1
|
562 {
|
rlm@1
|
563 u16 c = (u16)wParam;
|
rlm@1
|
564
|
rlm@1
|
565 color.setColor(c);
|
rlm@1
|
566
|
rlm@1
|
567 int r = (c & 0x1f);
|
rlm@1
|
568 int g = (c & 0x3e0) >> 5;
|
rlm@1
|
569 int b = (c & 0x7c00) >> 10;
|
rlm@1
|
570
|
rlm@1
|
571 CString buffer;
|
rlm@1
|
572 buffer.Format("R: %d", r);
|
rlm@1
|
573 GetDlgItem(IDC_R)->SetWindowText(buffer);
|
rlm@1
|
574
|
rlm@1
|
575 buffer.Format("G: %d", g);
|
rlm@1
|
576 GetDlgItem(IDC_G)->SetWindowText(buffer);
|
rlm@1
|
577
|
rlm@1
|
578 buffer.Format("B: %d", b);
|
rlm@1
|
579 GetDlgItem(IDC_B)->SetWindowText(buffer);
|
rlm@1
|
580
|
rlm@1
|
581 return TRUE;
|
rlm@1
|
582 }
|
rlm@1
|
583
|
rlm@1
|
584 void GBMapView::PostNcDestroy()
|
rlm@1
|
585 {
|
rlm@1
|
586 delete this;
|
rlm@1
|
587 CDialog::PostNcDestroy();
|
rlm@1
|
588 }
|
rlm@1
|
589
|