| 1 |
/* NDS Firmware tools |
| 2 |
|
| 3 |
Copyright 2009 DeSmuME team |
| 4 |
|
| 5 |
This file is part of DeSmuME |
| 6 |
|
| 7 |
DeSmuME is free software; you can redistribute it and/or modify |
| 8 |
it under the terms of the GNU General Public License as published by |
| 9 |
the Free Software Foundation; either version 2 of the License, or |
| 10 |
(at your option) any later version. |
| 11 |
|
| 12 |
DeSmuME is distributed in the hope that it will be useful, |
| 13 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
GNU General Public License for more details. |
| 16 |
|
| 17 |
You should have received a copy of the GNU General Public License |
| 18 |
along with DeSmuME; if not, write to the Free Software |
| 19 |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 |
*/ |
| 21 |
// first release: 17/12/2009 |
| 22 |
|
| 23 |
#include <windows.h> |
| 24 |
#include <strsafe.h> |
| 25 |
#include <commctrl.h> |
| 26 |
#include "main.h" |
| 27 |
#include "templates.h" |
| 28 |
|
| 29 |
const char months[12][10] = { "January", "February", "March", "April", "May", "June", "July", |
| 30 |
"August", "September", "October", "November", "December"}; |
| 31 |
|
| 32 |
const COLORREF firmColor[16] = {RGB( 96,128,152), // 0 - Gray |
| 33 |
RGB(184, 72, 0), // 1 - Brown |
| 34 |
RGB(248, 0, 24), // 2 - Red |
| 35 |
RGB(248,136,248), // 3 - Pink |
| 36 |
RGB(248,144, 0), // 4 - Orange |
| 37 |
RGB(240,224, 0), // 5 - Yellow |
| 38 |
RGB(168,248, 0), // 6 - Lime Green |
| 39 |
RGB( 0,248, 0), // 7 - Green |
| 40 |
RGB( 0,160, 56), // 8 - Dark Green |
| 41 |
RGB( 72,216,136), // 9 - Sea Green |
| 42 |
RGB( 48,184,240), // 10 - Turquoise |
| 43 |
RGB( 0, 80,240), // 11 - Blue |
| 44 |
RGB( 0, 0,144), // 12 - Dark Blue |
| 45 |
RGB(136, 0,208), // 13 - Dark Purple |
| 46 |
RGB(208, 0,232), // 14 - Violet |
| 47 |
RGB(248, 0,144) // 15 - Magenta |
| 48 |
}; |
| 49 |
|
| 50 |
const char firmColorNames[16][16] = {"Gray","Brown","Red","Pink","Orange","Yellow","Lime Green", |
| 51 |
"Green","Dark Green","Sea Green","Turquoise","Blue", |
| 52 |
"Dark Blue","Dark Purple","Violet","Magenta"}; |
| 53 |
|
| 54 |
HEADER header = {0}; |
| 55 |
u8 *gFirmwareData = NULL; |
| 56 |
u32 gFFsize = 0; |
| 57 |
u8 currColor = 0; |
| 58 |
|
| 59 |
HINSTANCE gInstance = NULL; |
| 60 |
HWND gMainWnd = NULL; |
| 61 |
RECT gMainWndPos = { CW_USEDEFAULT, CW_USEDEFAULT, 700, 555 }; |
| 62 |
HBRUSH hbBackground = NULL; |
| 63 |
HBRUSH hbEditBackground = NULL; |
| 64 |
HBRUSH hbColors[16] = { NULL }; |
| 65 |
|
| 66 |
char firmware_path[MAX_PATH] = { 0 }; |
| 67 |
|
| 68 |
//=============================================================================================== |
| 69 |
char *getType(const u8 type) |
| 70 |
{ |
| 71 |
char buf[30] = {0}; |
| 72 |
|
| 73 |
switch (type) |
| 74 |
{ |
| 75 |
case 0xFF: |
| 76 |
strcpy(buf, "NDS"); |
| 77 |
break; |
| 78 |
|
| 79 |
case 0x20: |
| 80 |
strcpy(buf, "NDS-Lite"); |
| 81 |
break; |
| 82 |
|
| 83 |
case 0x43: |
| 84 |
strcpy(buf, "iQueDS"); |
| 85 |
break; |
| 86 |
|
| 87 |
case 0x63: |
| 88 |
strcpy(buf, "iQueDS-Lite"); |
| 89 |
break; |
| 90 |
|
| 91 |
default: |
| 92 |
strcpy(buf, "Unknown"); |
| 93 |
break; |
| 94 |
} |
| 95 |
return strdup(buf); |
| 96 |
} |
| 97 |
|
| 98 |
char *getTimeStamp(const u8 tm[]) |
| 99 |
{ |
| 100 |
char buf[30] = {0}; |
| 101 |
if ((tm[2]>31)| (tm[3]>12)| (tm[1]>24)| (tm[0]>59)) |
| 102 |
{ |
| 103 |
strcpy(buf, "ERROR"); |
| 104 |
INFO("Error in timestamp: %02i/%02i/%02i %02i:%02i\n", tm[2], tm[3], tm[4], tm[1], tm[0]); |
| 105 |
} |
| 106 |
else |
| 107 |
sprintf(buf, "%02i/%02i/%02i %02i:%02i", tm[2], tm[3], tm[4], tm[1], tm[0]); |
| 108 |
return strdup(buf); |
| 109 |
} |
| 110 |
|
| 111 |
char *getVersion(const u8 ver[]) |
| 112 |
{ |
| 113 |
char buf[30] = {0}; |
| 114 |
sprintf(buf, "%c%c%c%c", ver[0], ver[1], ver[2], ver[3]); |
| 115 |
return strdup(buf); |
| 116 |
} |
| 117 |
|
| 118 |
char *getFlashMEversion(u8 vers, u16 vers_ex) |
| 119 |
{ |
| 120 |
char buf[10] = {0}; |
| 121 |
if (vers == 1) |
| 122 |
strcpy(buf, "1..4"); |
| 123 |
else |
| 124 |
sprintf(buf, "%i", vers_ex + 3); |
| 125 |
|
| 126 |
return strdup(buf); |
| 127 |
} |
| 128 |
//=============================================================================================== |
| 129 |
void clearMainDataWnd() |
| 130 |
{ |
| 131 |
for (int i = IDC_H_EDIT_START; i < IDC_H_EDIT_LAST; i++) |
| 132 |
SetDlgItemText(gMainWnd, i, ""); |
| 133 |
} |
| 134 |
|
| 135 |
void refreshMainData() |
| 136 |
{ |
| 137 |
u16 shift1 = 0, shift2 = 0, shift3 = 0, shift4 = 0; |
| 138 |
u32 size_header = ((header.shift_amounts >> 12) & 0xF) * 128 * 1024; |
| 139 |
|
| 140 |
shift1 = ((header.shift_amounts >> 0) & 0x07); |
| 141 |
shift2 = ((header.shift_amounts >> 3) & 0x07); |
| 142 |
shift3 = ((header.shift_amounts >> 6) & 0x07); |
| 143 |
shift4 = ((header.shift_amounts >> 9) & 0x07); |
| 144 |
|
| 145 |
clearMainDataWnd(); |
| 146 |
SetDlgItemText(gMainWnd, IDC_H1_TYPE, getType(header.console_type)); |
| 147 |
SetDlgItemText(gMainWnd, IDC_H1_VERSION, getVersion(header.fw_identifier)); |
| 148 |
SetDlgItemText(gMainWnd, IDC_H1_TIMESTAMP, getTimeStamp(header.fw_timestamp)); |
| 149 |
if (size_header != gFFsize) |
| 150 |
SetDlgItemText(gMainWnd, IDC_H1_SIZE, "ERROR"); |
| 151 |
else |
| 152 |
SetDlgItemInt(gMainWnd, IDC_H1_SIZE, size_header, false); |
| 153 |
SetDlgItemText(gMainWnd, IDC_H1_CRC, hex4(header.part12_boot_crc16)); |
| 154 |
SetDlgItemText(gMainWnd, IDC_H1_ARM9_ROM, hex8(header.part1_rom_boot9_addr << (2 + shift1))); |
| 155 |
SetDlgItemText(gMainWnd, IDC_H1_ARM9_RAM, hex8((0x02800000 - (header.part1_ram_boot9_addr << (2+shift2))))); |
| 156 |
SetDlgItemText(gMainWnd, IDC_H1_ARM9_GUI, hex8((header.part2_rom_boot7_addr << (2+shift3)))); |
| 157 |
SetDlgItemText(gMainWnd, IDC_H1_ARM7_ROM, hex8((0x03810000 - (header.part2_ram_boot7_addr << (2+shift4))))); |
| 158 |
SetDlgItemText(gMainWnd, IDC_H1_ARM7_RAM, hex8((header.part3_rom_gui9_addr << 3))); |
| 159 |
SetDlgItemText(gMainWnd, IDC_H1_ARM7_WIFI, hex8((header.part4_rom_wifi7_addr << 3))); |
| 160 |
//SetDlgItemText(gMainWnd, IDC_H1_ARM9_ROM, hex8((header.part5_gFirmwareData_gfx_addr << 3))); |
| 161 |
|
| 162 |
if (gFirmwareData[0x17C] != 0xFF) |
| 163 |
{ |
| 164 |
INFO("FlashME founded\n"); |
| 165 |
u32 patch_offset = 0x3FC80; |
| 166 |
if (gFirmwareData[0x17C] > 1) |
| 167 |
patch_offset = 0x3F680; |
| 168 |
|
| 169 |
memcpy(&header, gFirmwareData + patch_offset, sizeof(header)); |
| 170 |
|
| 171 |
shift1 = ((header.shift_amounts >> 0) & 0x07); |
| 172 |
shift2 = ((header.shift_amounts >> 3) & 0x07); |
| 173 |
shift3 = ((header.shift_amounts >> 6) & 0x07); |
| 174 |
shift4 = ((header.shift_amounts >> 9) & 0x07); |
| 175 |
|
| 176 |
size_header = ((header.shift_amounts >> 12) & 0xF) * 128 * 1024; |
| 177 |
|
| 178 |
SetDlgItemText(gMainWnd, IDC_H2_VERSION, getFlashMEversion(gFirmwareData[0x17C], (u16)gFirmwareData[0x3F7FC])); |
| 179 |
if (size_header != gFFsize) |
| 180 |
SetDlgItemText(gMainWnd, IDC_H2_SIZE, "ERROR"); |
| 181 |
else |
| 182 |
SetDlgItemInt(gMainWnd, IDC_H2_SIZE, size_header, false); |
| 183 |
SetDlgItemText(gMainWnd, IDC_H2_CRC, hex4(header.part12_boot_crc16)); |
| 184 |
SetDlgItemText(gMainWnd, IDC_H2_ARM9_ROM, hex8(header.part1_rom_boot9_addr << (2 + shift1))); |
| 185 |
SetDlgItemText(gMainWnd, IDC_H2_ARM9_RAM, hex8((0x02800000 - (header.part1_ram_boot9_addr << (2+shift2))))); |
| 186 |
SetDlgItemText(gMainWnd, IDC_H2_ARM9_GUI, hex8((header.part2_rom_boot7_addr << (2+shift3)))); |
| 187 |
SetDlgItemText(gMainWnd, IDC_H2_ARM7_ROM, hex8((0x03810000 - (header.part2_ram_boot7_addr << (2+shift4))))); |
| 188 |
SetDlgItemText(gMainWnd, IDC_H2_ARM7_RAM, hex8((header.part3_rom_gui9_addr << 3))); |
| 189 |
SetDlgItemText(gMainWnd, IDC_H2_ARM7_WIFI, hex8((header.part4_rom_wifi7_addr << 3))); |
| 190 |
//SetDlgItemText(gMainWnd, IDC_H2_ARM9_ROM, hex8((header.part5_gFirmwareData_gfx_addr << 3))); |
| 191 |
} |
| 192 |
else |
| 193 |
SetDlgItemText(gMainWnd, IDC_H2_VERSION, "not present "); |
| 194 |
} |
| 195 |
|
| 196 |
bool loadFirmware() |
| 197 |
{ |
| 198 |
FILE *fp = fopen(firmware_path, "rb"); |
| 199 |
u8 *data = NULL; |
| 200 |
|
| 201 |
if (fp) |
| 202 |
{ |
| 203 |
fseek(fp, 0, SEEK_END); |
| 204 |
gFFsize = ftell(fp); |
| 205 |
fseek(fp, 0, SEEK_SET); |
| 206 |
if( (gFFsize != 256*1024) && (gFFsize != 512*1024) ) |
| 207 |
{ |
| 208 |
INFO("Firmware: error size %i\n", gFFsize); |
| 209 |
fclose(fp); |
| 210 |
return false; |
| 211 |
} |
| 212 |
|
| 213 |
data = new u8 [gFFsize]; |
| 214 |
if (!data) |
| 215 |
{ |
| 216 |
INFO("Firmware: error memory allocate\n"); |
| 217 |
fclose(fp); |
| 218 |
return false; |
| 219 |
} |
| 220 |
memset(data, 0, gFFsize); |
| 221 |
|
| 222 |
if (fread(data, 1, gFFsize, fp) != gFFsize) |
| 223 |
{ |
| 224 |
INFO("Firmware: error reading\n"); |
| 225 |
delete [] data; |
| 226 |
fclose(fp); |
| 227 |
return false; |
| 228 |
} |
| 229 |
fclose(fp); |
| 230 |
|
| 231 |
|
| 232 |
if ((data[0x08] != 'M') || |
| 233 |
(data[0x09] != 'A') || |
| 234 |
(data[0x0A] != 'C')) |
| 235 |
{ |
| 236 |
INFO("Firmware: error ID string\n"); |
| 237 |
delete [] data; |
| 238 |
fclose(fp); |
| 239 |
return false; |
| 240 |
} |
| 241 |
|
| 242 |
SetWindowText(GetDlgItem(gMainWnd, IDC_BPATH), firmware_path); |
| 243 |
memcpy(&header, data, sizeof(header)); |
| 244 |
memcpy(gFirmwareData, data, gFFsize); |
| 245 |
refreshMainData(); |
| 246 |
delete [] data; |
| 247 |
return true; |
| 248 |
} |
| 249 |
INFO("Error opening %s\n", firmware_path); |
| 250 |
return false; |
| 251 |
} |
| 252 |
|
| 253 |
void refreshWiFiAPDlg(HWND hwnd) |
| 254 |
{ |
| 255 |
u8 *data = (u8*)(gFirmwareData + (header.user_settings_offset * 8 - 0x400)); |
| 256 |
char buf[256] = {0}; |
| 257 |
|
| 258 |
for (int i =0; i < 3; i++) |
| 259 |
{ |
| 260 |
u16 ofsID = (i * 30); |
| 261 |
u32 ofsMem = (i * 0x100); |
| 262 |
|
| 263 |
strncpy(buf, (char*)(data+ofsMem+0x40), 32); |
| 264 |
SetDlgItemText(hwnd, IDC_WIFI_AP_SSID + ofsID, buf); |
| 265 |
|
| 266 |
strncpy(buf, (char*)(data+ofsMem+0x60), 32); |
| 267 |
SetDlgItemText(hwnd, IDC_WIFI_AP_SSID2 + ofsID, buf); |
| 268 |
|
| 269 |
sprintf(buf, "%X", read64(data, ofsMem+0xF0)); |
| 270 |
SetDlgItemText(hwnd, IDC_WIFI_AP_USER_ID + ofsID, buf); |
| 271 |
|
| 272 |
strncpy(buf, (char*)(data+ofsMem+0x80), 16); |
| 273 |
SetDlgItemText(hwnd, IDC_WIFI_AP_KEY1 + ofsID, buf); |
| 274 |
strncpy(buf, (char*)(data+ofsMem+0x90), 16); |
| 275 |
SetDlgItemText(hwnd, IDC_WIFI_AP_KEY2 + ofsID, buf); |
| 276 |
strncpy(buf, (char*)(data+ofsMem+0xA0), 16); |
| 277 |
SetDlgItemText(hwnd, IDC_WIFI_AP_KEY3 + ofsID, buf); |
| 278 |
strncpy(buf, (char*)(data+ofsMem+0xB0), 16); |
| 279 |
SetDlgItemText(hwnd, IDC_WIFI_AP_KEY4 + ofsID, buf); |
| 280 |
|
| 281 |
u8 tmp8 = read8(data, ofsMem+0xE6); |
| 282 |
if (tmp8 == 0) |
| 283 |
{ |
| 284 |
SendMessage(GetDlgItem(hwnd, IDC_WIFI_AP_WEP_SIZE + ofsID), CB_SETCURSEL, 0, 0); |
| 285 |
SendMessage(GetDlgItem(hwnd, IDC_WIFI_AP_WEP_EMETHOD + ofsID), CB_SETCURSEL, 0, 0); |
| 286 |
EnableWindow(GetDlgItem(hwnd, IDC_WIFI_AP_WEP_EMETHOD + ofsID), false); |
| 287 |
} |
| 288 |
else |
| 289 |
{ |
| 290 |
u8 tmp = 0; |
| 291 |
if (tmp8 > 3) |
| 292 |
{ |
| 293 |
tmp = tmp8 - 4; |
| 294 |
SendMessage(GetDlgItem(hwnd, IDC_WIFI_AP_WEP_EMETHOD + ofsID), CB_SETCURSEL, 0, 0); |
| 295 |
} |
| 296 |
else |
| 297 |
{ |
| 298 |
tmp = tmp8; |
| 299 |
SendMessage(GetDlgItem(hwnd, IDC_WIFI_AP_WEP_EMETHOD + ofsID), CB_SETCURSEL, 1, 0); |
| 300 |
} |
| 301 |
SendMessage(GetDlgItem(hwnd, IDC_WIFI_AP_WEP_SIZE + ofsID), CB_SETCURSEL, tmp, 0); |
| 302 |
} |
| 303 |
|
| 304 |
if (read32(data, ofsMem+0xC0) == 0) |
| 305 |
{ |
| 306 |
SetDlgItemText(hwnd, IDC_WIFI_AP_IP + ofsID, "DHCP"); |
| 307 |
SetDlgItemText(hwnd, IDC_WIFI_AP_IPMASK + ofsID, "DHCP"); |
| 308 |
SetDlgItemText(hwnd, IDC_WIFI_AP_GATEWAY + ofsID, "DHCP"); |
| 309 |
} |
| 310 |
else |
| 311 |
{ |
| 312 |
sprintf(buf, "%i.%i.%i.%i", read8(data, ofsMem+0xC0), read8(data, ofsMem+0xC1), read8(data, ofsMem+0xC2), read8(data, ofsMem+0xC3)); |
| 313 |
SetDlgItemText(hwnd, IDC_WIFI_AP_IP + ofsID, buf); |
| 314 |
sprintf(buf, "%i.%i.%i.%i", read8(data, ofsMem+0xD0), read8(data, ofsMem+0xD1), read8(data, ofsMem+0xD2), read8(data, ofsMem+0xD3)); |
| 315 |
SetDlgItemText(hwnd, IDC_WIFI_AP_IPMASK + ofsID, buf); |
| 316 |
sprintf(buf, "%i.%i.%i.%i", read8(data, ofsMem+0xC4), read8(data, ofsMem+0xC5), read8(data, ofsMem+0xC6), read8(data, ofsMem+0xC7)); |
| 317 |
SetDlgItemText(hwnd, IDC_WIFI_AP_GATEWAY + ofsID, buf); |
| 318 |
} |
| 319 |
|
| 320 |
if (read32(data, ofsMem+0xC8) == 0) |
| 321 |
{ |
| 322 |
SetDlgItemText(hwnd, IDC_WIFI_AP_DNS1 + ofsID, "DHCP"); |
| 323 |
} |
| 324 |
else |
| 325 |
{ |
| 326 |
sprintf(buf, "%i.%i.%i.%i", read8(data, ofsMem+0xC8), read8(data, ofsMem+0xC9), read8(data, ofsMem+0xCA), read8(data, ofsMem+0xCB)); |
| 327 |
SetDlgItemText(hwnd, IDC_WIFI_AP_DNS1 + ofsID, buf); |
| 328 |
} |
| 329 |
|
| 330 |
if (read32(data, ofsMem+0xCC) == 0) |
| 331 |
{ |
| 332 |
SetDlgItemText(hwnd, IDC_WIFI_AP_DNS2 + ofsID, "DHCP"); |
| 333 |
} |
| 334 |
else |
| 335 |
{ |
| 336 |
sprintf(buf, "%i.%i.%i.%i", read8(data, ofsMem+0xC8), read8(data, ofsMem+0xC9), read8(data, ofsMem+0xCA), read8(data, ofsMem+0xCB)); |
| 337 |
SetDlgItemText(hwnd, IDC_WIFI_AP_DNS2 + ofsID, buf); |
| 338 |
} |
| 339 |
|
| 340 |
if (read8(data, ofsMem+0xE7) == 0) |
| 341 |
SetDlgItemText(hwnd, IDC_WIFI_AP_STATUS + ofsID, "Normal"); |
| 342 |
else |
| 343 |
if (read8(data, ofsMem+0xE7) == 0x01) |
| 344 |
SetDlgItemText(hwnd, IDC_WIFI_AP_STATUS + ofsID, "AOSS"); |
| 345 |
else |
| 346 |
if (read8(data, ofsMem+0xE7) == 0xFF) |
| 347 |
SetDlgItemText(hwnd, IDC_WIFI_AP_STATUS + ofsID, "not configured"); |
| 348 |
|
| 349 |
SetDlgItemText(hwnd, IDC_WIFI_AP_CRC16 + ofsID, hex4(read16(data, ofsMem+0xFE))); |
| 350 |
} |
| 351 |
} |
| 352 |
|
| 353 |
BOOL CALLBACK wifiAPDlgProc(HWND hdlg,UINT msg, WPARAM wParam,LPARAM lParam) |
| 354 |
{ |
| 355 |
switch (msg) |
| 356 |
{ |
| 357 |
case WM_INITDIALOG: |
| 358 |
{ |
| 359 |
HWND tmp_wnd = NULL; |
| 360 |
|
| 361 |
SetWindowText(hdlg, "WiFi Access Points Settings"); |
| 362 |
u16 size = sizeof(TwifiAPDlg1)/sizeof(TwifiAPDlg1[0]); |
| 363 |
for (int t = 0; t < 3; t++) |
| 364 |
{ |
| 365 |
u32 tmp_id = NULL; |
| 366 |
|
| 367 |
for (int i = 0; i < size; i++) |
| 368 |
{ |
| 369 |
tmp_id = TwifiAPDlg1[i].id; |
| 370 |
|
| 371 |
if (tmp_id != NULL) |
| 372 |
tmp_id += (t*30); |
| 373 |
|
| 374 |
CreateWindow(TwifiAPDlg1[i].wclass, TwifiAPDlg1[i].wtitle, WS_CHILD | WS_VISIBLE | TwifiAPDlg1[i].style, |
| 375 |
TwifiAPDlg1[i].x, TwifiAPDlg1[i].y-10+t*220, TwifiAPDlg1[i].w, TwifiAPDlg1[i].h, hdlg, (HMENU)tmp_id, gInstance, NULL); |
| 376 |
} |
| 377 |
|
| 378 |
tmp_wnd = GetDlgItem(hdlg, IDC_WIFI_AP_WEP_SIZE + (t*30)); |
| 379 |
SendMessage(tmp_wnd, CB_ADDSTRING, 0, (LPARAM)"None"); |
| 380 |
SendMessage(tmp_wnd, CB_ADDSTRING, 0, (LPARAM)"5 bytes"); |
| 381 |
SendMessage(tmp_wnd, CB_ADDSTRING, 0, (LPARAM)"13 bytes"); |
| 382 |
SendMessage(tmp_wnd, CB_ADDSTRING, 0, (LPARAM)"16 bytes"); |
| 383 |
SendMessage(tmp_wnd, CB_SETCURSEL, 0, 0); |
| 384 |
|
| 385 |
tmp_wnd = GetDlgItem(hdlg, IDC_WIFI_AP_WEP_EMETHOD + (t*30)); |
| 386 |
SendMessage(tmp_wnd, CB_ADDSTRING, 0, (LPARAM)"ASCII"); |
| 387 |
SendMessage(tmp_wnd, CB_ADDSTRING, 0, (LPARAM)"Hex"); |
| 388 |
SendMessage(tmp_wnd, CB_SETCURSEL, 0, 0); |
| 389 |
} |
| 390 |
|
| 391 |
size = sizeof(TwifiAPDlg2)/sizeof(TwifiAPDlg2[0]); |
| 392 |
for (int i = 0; i < size; i++) |
| 393 |
{ |
| 394 |
CreateWindow(TwifiAPDlg2[i].wclass, TwifiAPDlg2[i].wtitle, WS_CHILD | WS_VISIBLE | TwifiAPDlg2[i].style, |
| 395 |
TwifiAPDlg2[i].x, TwifiAPDlg2[i].y, TwifiAPDlg2[i].w, TwifiAPDlg2[i].h, hdlg, (HMENU)TwifiAPDlg2[i].id, gInstance, NULL); |
| 396 |
} |
| 397 |
|
| 398 |
refreshWiFiAPDlg(hdlg); |
| 399 |
break; |
| 400 |
} |
| 401 |
case WM_CTLCOLORDLG: |
| 402 |
{ |
| 403 |
HDC hdc = (HDC)wParam; |
| 404 |
SetTextColor(hdc,RGB(200,200,200)); |
| 405 |
SetBkColor(hdc,RGB(60,60,60)); |
| 406 |
return (BOOL)hbBackground; |
| 407 |
} |
| 408 |
|
| 409 |
case WM_CTLCOLORBTN: |
| 410 |
return (BOOL)hbBackground; |
| 411 |
|
| 412 |
case WM_CTLCOLOREDIT: |
| 413 |
{ |
| 414 |
HDC hdc = (HDC)wParam; |
| 415 |
SetTextColor(hdc,RGB(200,200,200)); |
| 416 |
SetBkColor(hdc,RGB(60,60,60)); |
| 417 |
return (BOOL)hbEditBackground; |
| 418 |
} |
| 419 |
|
| 420 |
case WM_CTLCOLORSTATIC: |
| 421 |
{ |
| 422 |
HDC hdc = (HDC)wParam; |
| 423 |
u32 id = GetWindowLong((HWND)lParam, GWL_ID); |
| 424 |
if (id >= IDC_WIFI_AP_STATUS) |
| 425 |
{ |
| 426 |
SetTextColor(hdc,RGB(200,200,200)); |
| 427 |
SetBkColor(hdc,RGB(60,60,60)); |
| 428 |
return (LRESULT)hbEditBackground; |
| 429 |
} |
| 430 |
SetTextColor(hdc,RGB(0xFF,0xFF,0xFF)); |
| 431 |
SetBkColor(hdc,RGB(0x6D,0x70, 0xA0)); |
| 432 |
return (LRESULT)hbBackground; |
| 433 |
} |
| 434 |
|
| 435 |
case WM_COMMAND: |
| 436 |
switch (LOWORD(wParam)) |
| 437 |
{ |
| 438 |
case IDOK: |
| 439 |
EndDialog(hdlg, 1); |
| 440 |
break; |
| 441 |
|
| 442 |
case IDCANCEL: |
| 443 |
EndDialog(hdlg, 0); |
| 444 |
break; |
| 445 |
|
| 446 |
} |
| 447 |
break; |
| 448 |
} |
| 449 |
|
| 450 |
return FALSE; |
| 451 |
} |
| 452 |
|
| 453 |
//==================================================================================================== |
| 454 |
bool refreshWiFiDlg(HWND hwnd) |
| 455 |
{ |
| 456 |
u8 *data = (u8*)gFirmwareData; |
| 457 |
u16 tmp16 = 0; |
| 458 |
char buf[256] = {0}; |
| 459 |
|
| 460 |
SetDlgItemText(hwnd, IDC_WIFI_CRC16, hex4(read16(data, 0x2A))); |
| 461 |
SetDlgItemInt(hwnd, IDC_WIFI_VERSION, read8(data, 0x2F), false); |
| 462 |
|
| 463 |
if (read8(data, 0x2F) > 5) |
| 464 |
strcpy(buf, "001656"); |
| 465 |
else |
| 466 |
strcpy(buf, "0009BF"); |
| 467 |
sprintf(buf, "%s%02X%02X%02X", buf, read8(data, 0x36), read8(data, 0x37), read8(data, 0x38)); |
| 468 |
SetDlgItemText(hwnd, IDC_WIFI_MACID, buf); |
| 469 |
SetDlgItemInt(hwnd, IDC_WIFI_RFTYPE, read8(data, 0x40), false); |
| 470 |
|
| 471 |
|
| 472 |
tmp16 = read16(data, 0x3C) & 0x7FFE; |
| 473 |
SendMessage(GetDlgItem(hwnd, IDC_WIFI_ECHANNEL_01), BM_SETCHECK, (tmp16 & (1<<1))?BST_CHECKED:BST_UNCHECKED, 0); |
| 474 |
SendMessage(GetDlgItem(hwnd, IDC_WIFI_ECHANNEL_02), BM_SETCHECK, (tmp16 & (1<<2))?BST_CHECKED:BST_UNCHECKED, 0); |
| 475 |
SendMessage(GetDlgItem(hwnd, IDC_WIFI_ECHANNEL_03), BM_SETCHECK, (tmp16 & (1<<3))?BST_CHECKED:BST_UNCHECKED, 0); |
| 476 |
SendMessage(GetDlgItem(hwnd, IDC_WIFI_ECHANNEL_04), BM_SETCHECK, (tmp16 & (1<<4))?BST_CHECKED:BST_UNCHECKED, 0); |
| 477 |
SendMessage(GetDlgItem(hwnd, IDC_WIFI_ECHANNEL_05), BM_SETCHECK, (tmp16 & (1<<5))?BST_CHECKED:BST_UNCHECKED, 0); |
| 478 |
SendMessage(GetDlgItem(hwnd, IDC_WIFI_ECHANNEL_06), BM_SETCHECK, (tmp16 & (1<<6))?BST_CHECKED:BST_UNCHECKED, 0); |
| 479 |
SendMessage(GetDlgItem(hwnd, IDC_WIFI_ECHANNEL_07), BM_SETCHECK, (tmp16 & (1<<7))?BST_CHECKED:BST_UNCHECKED, 0); |
| 480 |
SendMessage(GetDlgItem(hwnd, IDC_WIFI_ECHANNEL_08), BM_SETCHECK, (tmp16 & (1<<8))?BST_CHECKED:BST_UNCHECKED, 0); |
| 481 |
SendMessage(GetDlgItem(hwnd, IDC_WIFI_ECHANNEL_09), BM_SETCHECK, (tmp16 & (1<<9))?BST_CHECKED:BST_UNCHECKED, 0); |
| 482 |
SendMessage(GetDlgItem(hwnd, IDC_WIFI_ECHANNEL_10), BM_SETCHECK, (tmp16 & (1<<10))?BST_CHECKED:BST_UNCHECKED, 0); |
| 483 |
SendMessage(GetDlgItem(hwnd, IDC_WIFI_ECHANNEL_11), BM_SETCHECK, (tmp16 & (1<<11))?BST_CHECKED:BST_UNCHECKED, 0); |
| 484 |
SendMessage(GetDlgItem(hwnd, IDC_WIFI_ECHANNEL_12), BM_SETCHECK, (tmp16 & (1<<12))?BST_CHECKED:BST_UNCHECKED, 0); |
| 485 |
SendMessage(GetDlgItem(hwnd, IDC_WIFI_ECHANNEL_13), BM_SETCHECK, (tmp16 & (1<<13))?BST_CHECKED:BST_UNCHECKED, 0); |
| 486 |
SendMessage(GetDlgItem(hwnd, IDC_WIFI_ECHANNEL_14), BM_SETCHECK, (tmp16 & (1<<14))?BST_CHECKED:BST_UNCHECKED, 0); |
| 487 |
|
| 488 |
SetDlgItemText(hwnd, IDC_WIFI_044, hex4w(read16(data, 0x44))); |
| 489 |
SetDlgItemText(hwnd, IDC_WIFI_046, hex4w(read16(data, 0x46))); |
| 490 |
SetDlgItemText(hwnd, IDC_WIFI_048, hex4w(read16(data, 0x48))); |
| 491 |
SetDlgItemText(hwnd, IDC_WIFI_04A, hex4w(read16(data, 0x4A))); |
| 492 |
SetDlgItemText(hwnd, IDC_WIFI_04C, hex4w(read16(data, 0x4C))); |
| 493 |
SetDlgItemText(hwnd, IDC_WIFI_04E, hex4w(read16(data, 0x4E))); |
| 494 |
SetDlgItemText(hwnd, IDC_WIFI_050, hex4w(read16(data, 0x50))); |
| 495 |
SetDlgItemText(hwnd, IDC_WIFI_052, hex4w(read16(data, 0x52))); |
| 496 |
SetDlgItemText(hwnd, IDC_WIFI_054, hex4w(read16(data, 0x54))); |
| 497 |
SetDlgItemText(hwnd, IDC_WIFI_056, hex4w(read16(data, 0x56))); |
| 498 |
SetDlgItemText(hwnd, IDC_WIFI_058, hex4w(read16(data, 0x58))); |
| 499 |
SetDlgItemText(hwnd, IDC_WIFI_05A, hex4w(read16(data, 0x5A))); |
| 500 |
SetDlgItemText(hwnd, IDC_WIFI_05C, hex4w(read16(data, 0x5C))); |
| 501 |
SetDlgItemText(hwnd, IDC_WIFI_05E, hex4w(read16(data, 0x5E))); |
| 502 |
SetDlgItemText(hwnd, IDC_WIFI_060, hex4w(read16(data, 0x60))); |
| 503 |
SetDlgItemText(hwnd, IDC_WIFI_062, hex4w(read16(data, 0x62))); |
| 504 |
|
| 505 |
for (int i = 0; i < 0x69; i++) |
| 506 |
SetDlgItemText(hwnd, IDC_WIFI_BB + i, hex2w(read8(data, 0x64+i))); |
| 507 |
|
| 508 |
if (read8(data, 0x44) == 2) |
| 509 |
{ |
| 510 |
for (int i = 0; i < (0x24 / 3); i++) |
| 511 |
SetDlgItemText(hwnd, IDC_WIFI_RF2_INIT + i, hex6w(read24(data, 0xCE+(i*3)))); |
| 512 |
|
| 513 |
for (int i = 0; i < (0x54 / 3 / 2); i++) |
| 514 |
{ |
| 515 |
// check |
| 516 |
SetDlgItemText(hwnd, IDC_WIFI_RF2_56_CH + i, hex6w(read24(data, 0xF2+(i*3)))); |
| 517 |
SetDlgItemText(hwnd, IDC_WIFI_RF2_56_CH + i + 14, hex6w(read24(data, (0xF2+3*14)+(i*3)))); |
| 518 |
} |
| 519 |
|
| 520 |
for (int i = 0; i < 0x0E; i++) |
| 521 |
{ |
| 522 |
SetDlgItemText(hwnd, IDC_WIFI_RF2_BB_RF_CH + i, hex2w(read8(data, 0x146+i))); |
| 523 |
SetDlgItemText(hwnd, IDC_WIFI_RF2_BB_RF_CH + i + 14, hex2w(read8(data, 0x154+i))); |
| 524 |
} |
| 525 |
} |
| 526 |
else |
| 527 |
if (read8(gFirmwareData, 0x44) == 3) |
| 528 |
{ |
| 529 |
// TODO |
| 530 |
} |
| 531 |
|
| 532 |
return true; |
| 533 |
} |
| 534 |
|
| 535 |
BOOL CALLBACK wifiDlgProc(HWND hdlg,UINT msg, WPARAM wParam,LPARAM lParam) |
| 536 |
{ |
| 537 |
switch (msg) |
| 538 |
{ |
| 539 |
case WM_INITDIALOG: |
| 540 |
{ |
| 541 |
SetWindowText(hdlg, "WiFi Settings"); |
| 542 |
u16 size = sizeof(TwifiDlg1)/sizeof(TwifiDlg1[0]); |
| 543 |
for (int i = 0; i < size; i++) |
| 544 |
{ |
| 545 |
CreateWindow(TwifiDlg1[i].wclass, TwifiDlg1[i].wtitle, WS_CHILD | WS_VISIBLE | TwifiDlg1[i].style, |
| 546 |
TwifiDlg1[i].x, TwifiDlg1[i].y, TwifiDlg1[i].w, TwifiDlg1[i].h, hdlg, (HMENU)TwifiDlg1[i].id, gInstance, NULL); |
| 547 |
} |
| 548 |
|
| 549 |
u32 x = 40, y = Y_WIFI_BB+15; |
| 550 |
//========================================================= |
| 551 |
for (int i = 0; i < 0x69; i++) |
| 552 |
{ |
| 553 |
CreateWindow("EDIT", "", WS_CHILD | WS_VISIBLE | WS_TABSTOP | ES_CENTER, |
| 554 |
x, y, 20, 20, hdlg, (HMENU)(IDC_WIFI_BB + i), gInstance, NULL); |
| 555 |
x += 25; |
| 556 |
if ((i > 20) && ((i % 26) == 0)) |
| 557 |
{ |
| 558 |
x = 40; |
| 559 |
y +=25; |
| 560 |
} |
| 561 |
} |
| 562 |
|
| 563 |
if (read8(gFirmwareData, 0x44) == 2) |
| 564 |
{ |
| 565 |
u8 rfIndexes[] = {0, 4, 5, 6, 7, 8, 9, 0xA, 0xB, 1, 2, 3}; |
| 566 |
CreateWindow("BUTTON", "RF chip Type 2", WS_CHILD | WS_VISIBLE | BS_GROUPBOX, |
| 567 |
5, Y_WIFI_RF, 720, 290, hdlg, (HMENU)NULL, gInstance, NULL); |
| 568 |
CreateWindow("BUTTON", "RFx Initial values...", WS_CHILD | WS_VISIBLE | BS_GROUPBOX, |
| 569 |
15, Y_WIFI_RF+15, 700, 75, hdlg, (HMENU)NULL, gInstance, NULL); |
| 570 |
y = 0; x = 60; |
| 571 |
for (int i = 0; i < (0x24 / 3); i++) |
| 572 |
{ |
| 573 |
char buf[10] = { 0 }; |
| 574 |
sprintf(buf, "%02X", rfIndexes[i]); |
| 575 |
CreateWindow("STATIC", buf, WS_CHILD | WS_VISIBLE, |
| 576 |
x, Y_WIFI_RF + 35 + y, 30, 18, hdlg, (HMENU)NULL, gInstance, NULL); |
| 577 |
CreateWindow("EDIT", "", WS_CHILD | WS_VISIBLE | WS_TABSTOP | ES_CENTER, |
| 578 |
x + 18, Y_WIFI_RF + 35 + y, 65, 18, hdlg, (HMENU)(IDC_WIFI_RF2_INIT + i), gInstance, NULL); |
| 579 |
x += 105; |
| 580 |
if (i == 5) |
| 581 |
{ |
| 582 |
y = 25; |
| 583 |
x = 60; |
| 584 |
} |
| 585 |
} |
| 586 |
|
| 587 |
CreateWindow("BUTTON", "RF values (channel 1..14)", WS_CHILD | WS_VISIBLE | BS_GROUPBOX, |
| 588 |
15, Y_WIFI_RF+95, 700, 115, hdlg, (HMENU)NULL, gInstance, NULL); |
| 589 |
CreateWindow("STATIC", "RF5", WS_CHILD | WS_VISIBLE, 25, Y_WIFI_RF + 115, 30, 18, hdlg, (HMENU)NULL, gInstance, NULL); |
| 590 |
CreateWindow("STATIC", "RF6", WS_CHILD | WS_VISIBLE, 25, Y_WIFI_RF + 160, 30, 18, hdlg, (HMENU)NULL, gInstance, NULL); |
| 591 |
y = 0; x = 60; |
| 592 |
for (int i = 0; i < 14; i++) |
| 593 |
{ |
| 594 |
CreateWindow("EDIT", "", WS_CHILD | WS_VISIBLE | WS_TABSTOP | ES_CENTER, |
| 595 |
x, Y_WIFI_RF + 115 + y, 65, 18, hdlg, (HMENU)(IDC_WIFI_RF2_56_CH + i), gInstance, NULL); |
| 596 |
x += 95; |
| 597 |
if (i == 6) |
| 598 |
{ |
| 599 |
y = 22; |
| 600 |
x = 60; |
| 601 |
} |
| 602 |
} |
| 603 |
|
| 604 |
y = 0; x = 60; |
| 605 |
for (int i = 0; i < 14; i++) |
| 606 |
{ |
| 607 |
CreateWindow("EDIT", "", WS_CHILD | WS_VISIBLE | WS_TABSTOP | ES_CENTER, |
| 608 |
x, Y_WIFI_RF + 160 + y, 65, 18, hdlg, (HMENU)(IDC_WIFI_RF2_56_CH + i + 14), gInstance, NULL); |
| 609 |
x += 95; |
| 610 |
if (i == 6) |
| 611 |
{ |
| 612 |
y = 22; |
| 613 |
x = 60; |
| 614 |
} |
| 615 |
} |
| 616 |
|
| 617 |
CreateWindow("BUTTON", "BB/RF 8bit values (channel 1..14)", WS_CHILD | WS_VISIBLE | BS_GROUPBOX, |
| 618 |
15, Y_WIFI_RF+210, 700, 70, hdlg, (HMENU)NULL, gInstance, NULL); |
| 619 |
CreateWindow("STATIC", "BB", WS_CHILD | WS_VISIBLE, 25, Y_WIFI_RF + 230, 30, 18, hdlg, (HMENU)NULL, gInstance, NULL); |
| 620 |
CreateWindow("STATIC", "RF9", WS_CHILD | WS_VISIBLE, 25, Y_WIFI_RF + 250, 30, 18, hdlg, (HMENU)NULL, gInstance, NULL); |
| 621 |
for (int i = 0; i < 14; i++) |
| 622 |
{ |
| 623 |
CreateWindow("EDIT", "", WS_CHILD | WS_VISIBLE | WS_TABSTOP | ES_CENTER, |
| 624 |
60+ (i*45), Y_WIFI_RF + 230, 35, 18, hdlg, (HMENU)(IDC_WIFI_RF2_BB_RF_CH + i), gInstance, NULL); |
| 625 |
} |
| 626 |
for (int i = 0; i < 14; i++) |
| 627 |
{ |
| 628 |
CreateWindow("EDIT", "", WS_CHILD | WS_VISIBLE | WS_TABSTOP | ES_CENTER, |
| 629 |
60+ (i*45), Y_WIFI_RF + 250, 35, 18, hdlg, (HMENU)(IDC_WIFI_RF2_BB_RF_CH + i + 14), gInstance, NULL); |
| 630 |
} |
| 631 |
} |
| 632 |
else |
| 633 |
if (read8(gFirmwareData, 0x44) == 3) |
| 634 |
{ |
| 635 |
// TODO |
| 636 |
} |
| 637 |
|
| 638 |
size = sizeof(TwifiDlg2)/sizeof(TwifiDlg2[0]); |
| 639 |
for (int i = 0; i < size; i++) |
| 640 |
{ |
| 641 |
CreateWindow(TwifiDlg2[i].wclass, TwifiDlg2[i].wtitle, WS_CHILD | WS_VISIBLE | TwifiDlg2[i].style, |
| 642 |
TwifiDlg2[i].x, TwifiDlg2[i].y, TwifiDlg2[i].w, TwifiDlg2[i].h, hdlg, (HMENU)TwifiDlg2[i].id, gInstance, NULL); |
| 643 |
} |
| 644 |
refreshWiFiDlg(hdlg); |
| 645 |
break; |
| 646 |
} |
| 647 |
case WM_CTLCOLORDLG: |
| 648 |
{ |
| 649 |
HDC hdc = (HDC)wParam; |
| 650 |
SetTextColor(hdc,RGB(200,200,200)); |
| 651 |
SetBkColor(hdc,RGB(60,60,60)); |
| 652 |
return (BOOL)hbBackground; |
| 653 |
} |
| 654 |
|
| 655 |
case WM_CTLCOLORBTN: |
| 656 |
return (BOOL)hbBackground; |
| 657 |
|
| 658 |
case WM_CTLCOLOREDIT: |
| 659 |
{ |
| 660 |
HDC hdc = (HDC)wParam; |
| 661 |
SetTextColor(hdc,RGB(200,200,200)); |
| 662 |
SetBkColor(hdc,RGB(60,60,60)); |
| 663 |
return (BOOL)hbEditBackground; |
| 664 |
} |
| 665 |
|
| 666 |
case WM_CTLCOLORSTATIC: |
| 667 |
{ |
| 668 |
HDC hdc = (HDC)wParam; |
| 669 |
u32 id = GetWindowLong((HWND)lParam, GWL_ID); |
| 670 |
if ((id > IDC_WIFI_EDIT_STATIC) && (id < IDC_WIFI_EDIT_STATIC + 100)) |
| 671 |
{ |
| 672 |
SetTextColor(hdc,RGB(200,200,200)); |
| 673 |
SetBkColor(hdc,RGB(60,60,60)); |
| 674 |
return (LRESULT)hbEditBackground; |
| 675 |
} |
| 676 |
SetTextColor(hdc,RGB(0xFF,0xFF,0xFF)); |
| 677 |
SetBkColor(hdc,RGB(0x6D,0x70, 0xA0)); |
| 678 |
return (LRESULT)hbBackground; |
| 679 |
} |
| 680 |
|
| 681 |
case WM_COMMAND: |
| 682 |
switch (LOWORD(wParam)) |
| 683 |
{ |
| 684 |
case IDOK: |
| 685 |
EndDialog(hdlg, 1); |
| 686 |
break; |
| 687 |
|
| 688 |
case IDCANCEL: |
| 689 |
EndDialog(hdlg, 0); |
| 690 |
break; |
| 691 |
|
| 692 |
} |
| 693 |
break; |
| 694 |
} |
| 695 |
|
| 696 |
return FALSE; |
| 697 |
} |
| 698 |
|
| 699 |
bool refreshUserDlg(HWND hwnd) |
| 700 |
{ |
| 701 |
u8 *data = (u8*)(gFirmwareData + (header.user_settings_offset * 8)); |
| 702 |
char buf[256] = { 0 }; |
| 703 |
|
| 704 |
wcstombs(buf, (wchar_t *)(data+0x06), read16(data,0x1A)); |
| 705 |
SetDlgItemText(hwnd, IDC_NICKNAME, buf); |
| 706 |
|
| 707 |
memset(buf, 0, sizeof(buf)); |
| 708 |
wcstombs(buf, (wchar_t *)(data+0x1C), read16(data,0x50)); |
| 709 |
SetDlgItemText(hwnd, IDC_MESSAGE, buf); |
| 710 |
|
| 711 |
SendMessage(GetDlgItem(hwnd, IDC_BIRTH_DAY), CB_SETCURSEL, data[0x04]-1, 0); |
| 712 |
SendMessage(GetDlgItem(hwnd, IDC_BIRTH_MONTH), CB_SETCURSEL, data[0x03]-1, 0); |
| 713 |
|
| 714 |
// lang |
| 715 |
if ((header.console_type == 0x43) || (header.console_type == 0x63)) |
| 716 |
{ |
| 717 |
SendMessage(GetDlgItem(hwnd, IDC_LANGUAGE), CB_SETCURSEL, read16(data,0x75)&0x07, 0); |
| 718 |
} |
| 719 |
else |
| 720 |
{ |
| 721 |
SendMessage(GetDlgItem(hwnd, IDC_LANGUAGE), CB_SETCURSEL, read16(data,0x64)&0x07, 0); |
| 722 |
} |
| 723 |
|
| 724 |
SendMessage(GetDlgItem(hwnd, IDC_ALARM_ON), BM_SETCHECK, data[0x56]?BST_CHECKED:BST_UNCHECKED, 0); |
| 725 |
SendMessage(GetDlgItem(hwnd, IDC_ALARM_HOUR), CB_SETCURSEL, data[0x52], 0); |
| 726 |
SendMessage(GetDlgItem(hwnd, IDC_ALARM_MIN), CB_SETCURSEL, data[0x53], 0); |
| 727 |
|
| 728 |
currColor = read8(data, 0x02); |
| 729 |
|
| 730 |
SendMessage(GetDlgItem(hwnd, IDC_GBA_MODE_SCREENS), CB_SETCURSEL, (read16(data,0x64) >> 3)&0x01, 0); |
| 731 |
SendMessage(GetDlgItem(hwnd, IDC_BRIGHTLIGHT_LEVEL), CB_SETCURSEL, (read16(data,0x64) >> 4)&0x03, 0); |
| 732 |
SendMessage(GetDlgItem(hwnd, IDC_BOOTMENU), CB_SETCURSEL, (read16(data,0x64) >> 6)&0x01, 0); |
| 733 |
|
| 734 |
SetDlgItemText(hwnd, IDC_TADC_X1, hex2w(read16(data,0x58)&0xFFF)); |
| 735 |
SetDlgItemText(hwnd, IDC_TADC_Y1, hex2w(read16(data,0x5A)&0xFFF)); |
| 736 |
SetDlgItemText(hwnd, IDC_TADC_X2, hex2w(read16(data,0x5E)&0xFFF)); |
| 737 |
SetDlgItemText(hwnd, IDC_TADC_Y2, hex2w(read16(data,0x60)&0xFFF)); |
| 738 |
|
| 739 |
SetDlgItemText(hwnd, IDC_TSCR_X1, hex2w(read16(data,0x5C)&0xFF)); |
| 740 |
SetDlgItemText(hwnd, IDC_TSCR_Y1, hex2w(read16(data,0x5F)&0xFF)); |
| 741 |
SetDlgItemText(hwnd, IDC_TSCR_X2, hex2w(read16(data,0x62)&0xFF)); |
| 742 |
SetDlgItemText(hwnd, IDC_TSCR_Y2, hex2w(read16(data,0x64)&0xFF)); |
| 743 |
|
| 744 |
SetDlgItemInt(hwnd, IDC_RTC_OFFSET, read32(data,0x68), true); |
| 745 |
SetDlgItemInt(hwnd, IDC_YEAR_BOOT, 2000+read8(data,0x66), false); |
| 746 |
SetDlgItemInt(hwnd, IDC_UPDATE_COUNTER, read16(data,0x70), false); |
| 747 |
SetDlgItemText(hwnd, IDC_USER_CRC16, hex4(read16(data,0x72))); |
| 748 |
|
| 749 |
return true; |
| 750 |
} |
| 751 |
|
| 752 |
BOOL CALLBACK userDlgProc(HWND hdlg,UINT msg, WPARAM wParam,LPARAM lParam) |
| 753 |
{ |
| 754 |
switch (msg) |
| 755 |
{ |
| 756 |
case WM_INITDIALOG: |
| 757 |
{ |
| 758 |
SetWindowText(hdlg, "User settings"); |
| 759 |
u16 size = sizeof(TuserDlg1)/sizeof(TuserDlg1[0]); |
| 760 |
for (int i = 0; i < size; i++) |
| 761 |
{ |
| 762 |
CreateWindow(TuserDlg1[i].wclass, TuserDlg1[i].wtitle, WS_CHILD | WS_VISIBLE | TuserDlg1[i].style, |
| 763 |
TuserDlg1[i].x, TuserDlg1[i].y, TuserDlg1[i].w, TuserDlg1[i].h, hdlg, (HMENU)TuserDlg1[i].id, gInstance, NULL); |
| 764 |
} |
| 765 |
|
| 766 |
u32 y_ofs = Y_FAV_COLOR + 15, x_ofs = 0; |
| 767 |
for (int i = 0; i < 16; i++) |
| 768 |
{ |
| 769 |
char buf[22] = { 0 }; |
| 770 |
sprintf(buf,"%02i",i); |
| 771 |
CreateWindow("BUTTON", buf, WS_CHILD | WS_TABSTOP | WS_VISIBLE | BS_OWNERDRAW, 25 + x_ofs, 5 + y_ofs, 40, 40, hdlg, (HMENU)(IDC_COLOR+i), gInstance, NULL); |
| 772 |
x_ofs += 45; |
| 773 |
if (i == 7) |
| 774 |
{ |
| 775 |
x_ofs = 0; |
| 776 |
y_ofs += 45; |
| 777 |
} |
| 778 |
} |
| 779 |
|
| 780 |
size = sizeof(TuserDlg2)/sizeof(TuserDlg2[0]); |
| 781 |
for (int i = 0; i < size; i++) |
| 782 |
{ |
| 783 |
CreateWindow(TuserDlg2[i].wclass, TuserDlg2[i].wtitle, WS_CHILD | WS_VISIBLE | TuserDlg2[i].style, |
| 784 |
TuserDlg2[i].x, TuserDlg2[i].y, TuserDlg2[i].w, TuserDlg2[i].h, hdlg, (HMENU)TuserDlg2[i].id, gInstance, NULL); |
| 785 |
} |
| 786 |
|
| 787 |
HWND tmp_wnd = GetDlgItem(hdlg, IDC_BIRTH_DAY); |
| 788 |
for (int i = 1; i < 32; i++) |
| 789 |
{ |
| 790 |
char bf[10] = {0}; |
| 791 |
_itoa(i, bf, 10); |
| 792 |
SendMessage(tmp_wnd, CB_ADDSTRING, 0, (LPARAM)bf); |
| 793 |
} |
| 794 |
|
| 795 |
tmp_wnd = GetDlgItem(hdlg, IDC_BIRTH_MONTH); |
| 796 |
for (int i = 1; i < 13; i++) |
| 797 |
{ |
| 798 |
SendMessage(tmp_wnd, CB_ADDSTRING, 0, (LPARAM)months[i-1]); |
| 799 |
} |
| 800 |
|
| 801 |
tmp_wnd = GetDlgItem(hdlg, IDC_ALARM_HOUR); |
| 802 |
for (int i = 0; i < 24; i++) |
| 803 |
{ |
| 804 |
char bf[10] = {0}; |
| 805 |
itoa(i, bf, 10); |
| 806 |
SendMessage(tmp_wnd, CB_ADDSTRING, 0, (LPARAM)bf); |
| 807 |
} |
| 808 |
|
| 809 |
tmp_wnd = GetDlgItem(hdlg, IDC_ALARM_MIN); |
| 810 |
for (int i = 0; i < 60; i++) |
| 811 |
{ |
| 812 |
char bf[10] = {0}; |
| 813 |
itoa(i, bf, 10); |
| 814 |
SendMessage(tmp_wnd, CB_ADDSTRING, 0, (LPARAM)bf); |
| 815 |
} |
| 816 |
|
| 817 |
tmp_wnd = GetDlgItem(hdlg, IDC_LANGUAGE); |
| 818 |
SendMessage(tmp_wnd, CB_ADDSTRING, 0, (LPARAM)"Japanese"); |
| 819 |
SendMessage(tmp_wnd, CB_ADDSTRING, 0, (LPARAM)"English"); |
| 820 |
SendMessage(tmp_wnd, CB_ADDSTRING, 0, (LPARAM)"French"); |
| 821 |
SendMessage(tmp_wnd, CB_ADDSTRING, 0, (LPARAM)"German"); |
| 822 |
SendMessage(tmp_wnd, CB_ADDSTRING, 0, (LPARAM)"Italian"); |
| 823 |
SendMessage(tmp_wnd, CB_ADDSTRING, 0, (LPARAM)"Spanish"); |
| 824 |
if ((header.console_type == 0x43) || (header.console_type == 0x63)) |
| 825 |
SendMessage(tmp_wnd, CB_ADDSTRING, 0, (LPARAM)"Chinese"); |
| 826 |
|
| 827 |
tmp_wnd = GetDlgItem(hdlg, IDC_GBA_MODE_SCREENS); |
| 828 |
SendMessage(tmp_wnd, CB_ADDSTRING, 0, (LPARAM)"Upper"); |
| 829 |
SendMessage(tmp_wnd, CB_ADDSTRING, 0, (LPARAM)"Lower"); |
| 830 |
|
| 831 |
tmp_wnd = GetDlgItem(hdlg, IDC_BRIGHTLIGHT_LEVEL); |
| 832 |
SendMessage(tmp_wnd, CB_ADDSTRING, 0, (LPARAM)"Low"); |
| 833 |
SendMessage(tmp_wnd, CB_ADDSTRING, 0, (LPARAM)"Med"); |
| 834 |
SendMessage(tmp_wnd, CB_ADDSTRING, 0, (LPARAM)"High"); |
| 835 |
SendMessage(tmp_wnd, CB_ADDSTRING, 0, (LPARAM)"Max"); |
| 836 |
|
| 837 |
tmp_wnd = GetDlgItem(hdlg, IDC_BOOTMENU); |
| 838 |
SendMessage(tmp_wnd, CB_ADDSTRING, 0, (LPARAM)"Manual/bootmenu"); |
| 839 |
SendMessage(tmp_wnd, CB_ADDSTRING, 0, (LPARAM)"Autostart Cartridge"); |
| 840 |
|
| 841 |
refreshUserDlg(hdlg); |
| 842 |
return TRUE; |
| 843 |
} |
| 844 |
|
| 845 |
case WM_DRAWITEM: |
| 846 |
{ |
| 847 |
if ((wParam >= IDC_COLOR) && (wParam <= (IDC_COLOR + 15))) |
| 848 |
{ |
| 849 |
LPDRAWITEMSTRUCT di = (LPDRAWITEMSTRUCT)lParam; |
| 850 |
FillRect(di->hDC, &di->rcItem, hbColors[wParam - IDC_COLOR]); |
| 851 |
|
| 852 |
if (di->itemState & ODS_FOCUS) |
| 853 |
{ |
| 854 |
ExcludeClipRect(di->hDC, di->rcItem.left+4, di->rcItem.top+4, di->rcItem.right-4, di->rcItem.bottom-4); |
| 855 |
HPEN pen = CreatePen(PS_DASH, 1, RGB(255,255,255)); |
| 856 |
SelectObject(di->hDC, pen); |
| 857 |
Rectangle(di->hDC, di->rcItem.left+2, di->rcItem.top+2, di->rcItem.right-2, di->rcItem.bottom-2); |
| 858 |
} |
| 859 |
ExcludeClipRect(di->hDC, di->rcItem.left+2, di->rcItem.top+2, di->rcItem.right-2, di->rcItem.bottom-2); |
| 860 |
if (di->itemState & ODS_FOCUS) |
| 861 |
{ |
| 862 |
HPEN pen = CreatePen(PS_DASH, 3, RGB(0,0,0)); |
| 863 |
SelectObject(di->hDC, pen); |
| 864 |
Rectangle(di->hDC, di->rcItem.left, di->rcItem.top, di->rcItem.right, di->rcItem.bottom); |
| 865 |
} |
| 866 |
else |
| 867 |
{ |
| 868 |
if ((wParam - IDC_COLOR) == currColor) |
| 869 |
{ |
| 870 |
HPEN pen = CreatePen(PS_DASH, 3, RGB(255,255,255)); |
| 871 |
SelectObject(di->hDC, pen); |
| 872 |
Rectangle(di->hDC, di->rcItem.left, di->rcItem.top, di->rcItem.right, di->rcItem.bottom); |
| 873 |
} |
| 874 |
} |
| 875 |
return TRUE; |
| 876 |
} |
| 877 |
|
| 878 |
break; |
| 879 |
} |
| 880 |
case WM_CTLCOLORDLG: |
| 881 |
{ |
| 882 |
HDC hdc = (HDC)wParam; |
| 883 |
SetTextColor(hdc,RGB(200,200,200)); |
| 884 |
SetBkColor(hdc,RGB(60,60,60)); |
| 885 |
return (BOOL)hbBackground; |
| 886 |
} |
| 887 |
|
| 888 |
case WM_CTLCOLORBTN: |
| 889 |
return (BOOL)hbBackground; |
| 890 |
|
| 891 |
case WM_CTLCOLOREDIT: |
| 892 |
{ |
| 893 |
HDC hdc = (HDC)wParam; |
| 894 |
SetTextColor(hdc,RGB(200,200,200)); |
| 895 |
SetBkColor(hdc,RGB(60,60,60)); |
| 896 |
return (BOOL)hbEditBackground; |
| 897 |
} |
| 898 |
|
| 899 |
case WM_CTLCOLORSTATIC: |
| 900 |
{ |
| 901 |
HDC hdc = (HDC)wParam; |
| 902 |
SetTextColor(hdc,RGB(0xFF,0xFF,0xFF)); |
| 903 |
SetBkColor(hdc,RGB(0x6D,0x70, 0xA0)); |
| 904 |
return (LRESULT)hbBackground; |
| 905 |
} |
| 906 |
|
| 907 |
case WM_COMMAND: |
| 908 |
switch (LOWORD(wParam)) |
| 909 |
{ |
| 910 |
case IDOK: |
| 911 |
EndDialog(hdlg, 1); |
| 912 |
break; |
| 913 |
|
| 914 |
case IDCANCEL: |
| 915 |
EndDialog(hdlg, 0); |
| 916 |
break; |
| 917 |
|
| 918 |
} |
| 919 |
break; |
| 920 |
} |
| 921 |
return FALSE; |
| 922 |
} |
| 923 |
|
| 924 |
BOOL Browse() |
| 925 |
{ |
| 926 |
static OPENFILENAME ofn={0}; |
| 927 |
static BOOL bSetInitialDir = FALSE; |
| 928 |
|
| 929 |
ofn.lStructSize = sizeof(OPENFILENAME); |
| 930 |
ofn.hwndOwner = gMainWnd; |
| 931 |
ofn.lpstrFilter = NULL; |
| 932 |
ofn.lpstrFilter = "Binary (*.bin,*.rom)\0*.bin; *.rom\0All files (*.*)\0*.*\0"; |
| 933 |
ofn.lpstrCustomFilter = NULL; |
| 934 |
ofn.nFilterIndex = 1; |
| 935 |
ofn.lpstrFile = firmware_path; |
| 936 |
ofn.nMaxFile = MAX_PATH; |
| 937 |
ofn.lpstrTitle = TEXT("Open firmware\0"); |
| 938 |
ofn.lpstrFileTitle = NULL; |
| 939 |
ofn.lpstrDefExt = TEXT("*\0"); |
| 940 |
ofn.Flags = OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_HIDEREADONLY; |
| 941 |
ofn.lpstrInitialDir = NULL; |
| 942 |
|
| 943 |
return GetOpenFileName((LPOPENFILENAME)&ofn); |
| 944 |
} |
| 945 |
|
| 946 |
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) |
| 947 |
{ |
| 948 |
switch (msg) |
| 949 |
{ |
| 950 |
case WM_CREATE: |
| 951 |
{ |
| 952 |
u16 size = sizeof(TmainWnd)/sizeof(TmainWnd[0]); |
| 953 |
for (int i = 0; i < size; i++) |
| 954 |
{ |
| 955 |
if (!CreateWindow(TmainWnd[i].wclass, TmainWnd[i].wtitle, WS_CHILD | WS_VISIBLE | TmainWnd[i].style, |
| 956 |
TmainWnd[i].x, TmainWnd[i].y, TmainWnd[i].w, TmainWnd[i].h, hwnd, (HMENU)TmainWnd[i].id, gInstance, NULL)) |
| 957 |
{ |
| 958 |
INFO("ERROR: %03i - %s: %s\n", i, TmainWnd[i].wtitle, error()); |
| 959 |
return -1; |
| 960 |
} |
| 961 |
} |
| 962 |
|
| 963 |
return 0L; |
| 964 |
} |
| 965 |
case WM_DESTROY: |
| 966 |
{ |
| 967 |
PostQuitMessage(0); |
| 968 |
return 0L; |
| 969 |
} |
| 970 |
|
| 971 |
case WM_CTLCOLORSTATIC: |
| 972 |
{ |
| 973 |
HDC hdc = (HDC)wParam; |
| 974 |
u32 id = GetWindowLong((HWND)lParam, GWL_ID); |
| 975 |
|
| 976 |
if (id == IDC_BPATH) |
| 977 |
{ |
| 978 |
SetTextColor(hdc,RGB(200,200,200)); |
| 979 |
SetBkColor(hdc,RGB(60,60,60)); |
| 980 |
return (LRESULT)hbEditBackground; |
| 981 |
} |
| 982 |
if ((id > IDC_H_EDIT_START) && (id < IDC_H_EDIT_LAST)) |
| 983 |
{ |
| 984 |
char buf2[512] = {0}; |
| 985 |
GetWindowText((HWND)lParam, buf2, 512); |
| 986 |
if (strcmp(buf2, "not present ") == 0) |
| 987 |
{ |
| 988 |
SetTextColor(hdc,RGB(0xED,0xF5,0x11)); |
| 989 |
} |
| 990 |
else |
| 991 |
if (strcmp(buf2, "N/A") == 0) |
| 992 |
{ |
| 993 |
SetTextColor(hdc,RGB(0xFF,0x0F,0xFF)); |
| 994 |
} |
| 995 |
else |
| 996 |
if (strcmp(buf2, "ERROR") == 0) |
| 997 |
{ |
| 998 |
SetTextColor(hdc,RGB(0xFF,0x0F,0x0F)); |
| 999 |
} |
| 1000 |
else |
| 1001 |
{ |
| 1002 |
SetTextColor(hdc,RGB(0xFF,0xFF,0xFF)); |
| 1003 |
} |
| 1004 |
SetBkColor(hdc,RGB(60,60,60)); |
| 1005 |
return (LRESULT)hbEditBackground; |
| 1006 |
} |
| 1007 |
else |
| 1008 |
{ |
| 1009 |
SetTextColor(hdc,RGB(0xFF,0xFF,0xFF)); |
| 1010 |
SetBkColor(hdc,RGB(0x6D,0x70, 0xA0)); |
| 1011 |
return (LRESULT)hbBackground; |
| 1012 |
} |
| 1013 |
} |
| 1014 |
|
| 1015 |
case WM_CTLCOLORBTN: |
| 1016 |
return (LRESULT)hbBackground; |
| 1017 |
|
| 1018 |
case WM_CTLCOLOREDIT: |
| 1019 |
{ |
| 1020 |
HDC hdc = (HDC)wParam; |
| 1021 |
SetTextColor(hdc,RGB(200,200,200)); |
| 1022 |
SetBkColor(hdc,RGB(60,60,60)); |
| 1023 |
return (LRESULT)hbEditBackground; |
| 1024 |
} |
| 1025 |
|
| 1026 |
case WM_COMMAND: |
| 1027 |
{ |
| 1028 |
u32 id = GetWindowLong((HWND)lParam, GWL_ID); |
| 1029 |
switch (id) |
| 1030 |
{ |
| 1031 |
case IDC_BBROWSE: |
| 1032 |
if (HIWORD(wParam) == BN_CLICKED) |
| 1033 |
{ |
| 1034 |
char tmp_buf[MAX_PATH] = { 0 }; |
| 1035 |
strcpy(tmp_buf, firmware_path); |
| 1036 |
if (Browse()) |
| 1037 |
{ |
| 1038 |
if (loadFirmware()) |
| 1039 |
{ |
| 1040 |
EnableWindow(GetDlgItem(hwnd, IDC_BUSER), TRUE); |
| 1041 |
EnableWindow(GetDlgItem(hwnd, IDC_BWIFI), TRUE); |
| 1042 |
EnableWindow(GetDlgItem(hwnd, IDC_BWIFIAP), TRUE); |
| 1043 |
return 0L; |
| 1044 |
} |
| 1045 |
MessageBox(NULL, "Error loading firmware", _TITLE, MB_OK | MB_ICONERROR); |
| 1046 |
INFO("Error loading firmware\n"); |
| 1047 |
} |
| 1048 |
strcpy(firmware_path, tmp_buf); |
| 1049 |
return 0L; |
| 1050 |
} |
| 1051 |
break; |
| 1052 |
|
| 1053 |
case IDC_BEXIT: |
| 1054 |
if (HIWORD(wParam) == BN_CLICKED) |
| 1055 |
SendMessage(hwnd, WM_CLOSE, 0, 0); |
| 1056 |
break; |
| 1057 |
|
| 1058 |
case IDC_BUSER: |
| 1059 |
{ |
| 1060 |
LPDLGTEMPLATE dlgTemplate = (LPDLGTEMPLATE)malloc(1024); |
| 1061 |
if (dlgTemplate) |
| 1062 |
{ |
| 1063 |
memset(dlgTemplate, 0, 1024); |
| 1064 |
dlgTemplate->style = DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU; |
| 1065 |
dlgTemplate->cx = 205; |
| 1066 |
dlgTemplate->cy = 300; |
| 1067 |
if (DialogBoxIndirect(gInstance, dlgTemplate, hwnd, userDlgProc) == -1) |
| 1068 |
INFO("ERROR: %s\n", error()); |
| 1069 |
free(dlgTemplate); |
| 1070 |
return 0L; |
| 1071 |
} |
| 1072 |
INFO("ERROR: %s\n", error()); |
| 1073 |
return 0L; |
| 1074 |
} |
| 1075 |
case IDC_BWIFI: |
| 1076 |
{ |
| 1077 |
LPDLGTEMPLATE dlgTemplate = (LPDLGTEMPLATE)malloc(1024); |
| 1078 |
if (dlgTemplate) |
| 1079 |
{ |
| 1080 |
memset(dlgTemplate, 0, 1024); |
| 1081 |
dlgTemplate->style = DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU; |
| 1082 |
dlgTemplate->cx = 365; |
| 1083 |
dlgTemplate->cy = 300; |
| 1084 |
if (DialogBoxIndirect(gInstance, dlgTemplate, hwnd, wifiDlgProc) == -1) |
| 1085 |
INFO("ERROR: %s\n", error()); |
| 1086 |
free(dlgTemplate); |
| 1087 |
return 0L; |
| 1088 |
} |
| 1089 |
INFO("ERROR: %s\n", error()); |
| 1090 |
return 0L; |
| 1091 |
} |
| 1092 |
|
| 1093 |
case IDC_BWIFIAP: |
| 1094 |
{ |
| 1095 |
LPDLGTEMPLATE dlgTemplate = (LPDLGTEMPLATE)malloc(1024); |
| 1096 |
if (dlgTemplate) |
| 1097 |
{ |
| 1098 |
memset(dlgTemplate, 0, 1024); |
| 1099 |
dlgTemplate->style = DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU; |
| 1100 |
dlgTemplate->cx = 365; |
| 1101 |
dlgTemplate->cy = 350; |
| 1102 |
if (DialogBoxIndirect(gInstance, dlgTemplate, hwnd, wifiAPDlgProc) == -1) |
| 1103 |
INFO("ERROR: %s\n", error()); |
| 1104 |
free(dlgTemplate); |
| 1105 |
return 0L; |
| 1106 |
} |
| 1107 |
INFO("ERROR: %s\n", error()); |
| 1108 |
return 0L; |
| 1109 |
} |
| 1110 |
} |
| 1111 |
} |
| 1112 |
} |
| 1113 |
return DefWindowProc(hwnd,msg,wParam,lParam); |
| 1114 |
} |
| 1115 |
|
| 1116 |
int RegClass(WNDPROC Proc, LPCTSTR szName) |
| 1117 |
{ |
| 1118 |
WNDCLASS wc = { 0 }; |
| 1119 |
|
| 1120 |
wc.style=CS_HREDRAW|CS_VREDRAW; |
| 1121 |
wc.cbClsExtra=wc.cbWndExtra=0; |
| 1122 |
wc.lpfnWndProc=Proc; |
| 1123 |
wc.hInstance=gInstance; |
| 1124 |
wc.hIcon=LoadIcon(gInstance, IDI_APPLICATION); |
| 1125 |
wc.hCursor=LoadCursor(NULL,IDC_ARROW); |
| 1126 |
wc.hbrBackground=(HBRUSH)hbBackground; |
| 1127 |
wc.lpszMenuName=(LPCTSTR)NULL; |
| 1128 |
wc.lpszClassName=szName; |
| 1129 |
return RegisterClass(&wc); |
| 1130 |
} |
| 1131 |
|
| 1132 |
BOOL InitCommonCtrls() |
| 1133 |
{ |
| 1134 |
INITCOMMONCONTROLSEX CommCtrl; |
| 1135 |
|
| 1136 |
CommCtrl.dwSize=sizeof INITCOMMONCONTROLSEX; |
| 1137 |
CommCtrl.dwICC=ICC_WIN95_CLASSES|ICC_COOL_CLASSES|ICC_USEREX_CLASSES; |
| 1138 |
return InitCommonControlsEx(&CommCtrl); |
| 1139 |
} |
| 1140 |
|
| 1141 |
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) |
| 1142 |
{ |
| 1143 |
MSG msg; |
| 1144 |
|
| 1145 |
InitCommonCtrls(); |
| 1146 |
hbBackground = CreateSolidBrush(RGB(0x6D,0x70, 0xA0)); |
| 1147 |
hbEditBackground = CreateSolidBrush(RGB(60, 60, 60)); |
| 1148 |
OpenConsole(); |
| 1149 |
gInstance = hInstance; |
| 1150 |
if (!RegClass(WndProc, MAINCLASS)) |
| 1151 |
{ |
| 1152 |
DeleteObject(hbEditBackground); DeleteObject(hbBackground); |
| 1153 |
MessageBox(NULL, "Error registering class", _TITLE, MB_OK | MB_ICONERROR); |
| 1154 |
return -1; |
| 1155 |
} |
| 1156 |
|
| 1157 |
gFirmwareData = new u8 [512 * 1024]; |
| 1158 |
if (!gFirmwareData) |
| 1159 |
{ |
| 1160 |
DeleteObject(hbEditBackground); DeleteObject(hbBackground); |
| 1161 |
MessageBox(NULL, "Error allocating firmware data", _TITLE, MB_OK | MB_ICONERROR); |
| 1162 |
UnregisterClass(MAINCLASS, gInstance); |
| 1163 |
return -2; |
| 1164 |
} |
| 1165 |
memset(gFirmwareData, 0, 512*1024); |
| 1166 |
|
| 1167 |
gMainWnd=CreateWindow(MAINCLASS, _TITLE, |
| 1168 |
WS_OVERLAPPED | WS_SYSMENU, |
| 1169 |
gMainWndPos.left,gMainWndPos.top, |
| 1170 |
gMainWndPos.right,gMainWndPos.bottom, |
| 1171 |
NULL, (HMENU)NULL, hInstance,NULL); |
| 1172 |
|
| 1173 |
if (!gMainWnd) |
| 1174 |
{ |
| 1175 |
DeleteObject(hbEditBackground); DeleteObject(hbBackground); |
| 1176 |
MessageBox(NULL, "Error creating main window", _TITLE, MB_OK | MB_ICONERROR); |
| 1177 |
UnregisterClass(MAINCLASS, gInstance); |
| 1178 |
delete [] gFirmwareData; |
| 1179 |
gFirmwareData = NULL; |
| 1180 |
return -3; |
| 1181 |
} |
| 1182 |
|
| 1183 |
for (int t = 0; t < 16; t++) |
| 1184 |
hbColors[t] = CreateSolidBrush(firmColor[t]); |
| 1185 |
|
| 1186 |
ShowWindow(gMainWnd, SW_NORMAL); |
| 1187 |
UpdateWindow(gMainWnd); |
| 1188 |
while (GetMessage(&msg, 0,0,0)) |
| 1189 |
{ |
| 1190 |
{ |
| 1191 |
TranslateMessage(&msg); |
| 1192 |
DispatchMessage(&msg); |
| 1193 |
} |
| 1194 |
} |
| 1195 |
|
| 1196 |
for (int t = 0; t < 16; t++) |
| 1197 |
{ |
| 1198 |
DeleteObject(hbColors[t]); |
| 1199 |
} |
| 1200 |
DeleteObject(hbEditBackground); |
| 1201 |
DeleteObject(hbBackground); |
| 1202 |
|
| 1203 |
delete [] gFirmwareData; |
| 1204 |
gFirmwareData = NULL; |
| 1205 |
UnregisterClass(MAINCLASS, gInstance); |
| 1206 |
CloseConsole(); |
| 1207 |
|
| 1208 |
return 0; |
| 1209 |
} |