Skip to content

Commit

Permalink
[DMG] Load GB Mobile homepage from external file for demo mode
Browse files Browse the repository at this point in the history
  • Loading branch information
shonumi committed Aug 3, 2018
1 parent da90ab2 commit 4c53dec
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 19 deletions.
File renamed without changes.
6 changes: 6 additions & 0 deletions src/data/gbma/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<html>
<body>
<img src="gbe_head.bmp" />
<center>Hello World</center>
</body>
</html>
55 changes: 38 additions & 17 deletions src/dmg/gbma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -854,29 +854,41 @@ void DMG_SIO::mobile_adapter_process_http()
//Process GET requests
if(get_match != std::string::npos)
{
std::string filename = "";

//See if this is the homepage for Mobile Trainer
if(mobile_adapter.http_data.find("/01/CGB-B9AJ/index.html") != std::string::npos) { not_found = false; }
if(mobile_adapter.http_data.find("/01/CGB-B9AJ/index.html") != std::string::npos)
{
not_found = false;
filename = config::data_path + "gbma/index.html";
}

//See if this is the homepage header image
else if(mobile_adapter.http_data.find("gbe_head.bmp") != std::string::npos)
{
std::string filename = config::data_path + "icons/gbe_plus_mobile_header.bmp";
not_found = false;
img = true;
filename = config::data_path + "gbma/gbe_plus_mobile_header.bmp";
}

if(!not_found)
{
//Open up GBE+ header image
std::ifstream f_img(filename.c_str(), std::ios::binary);
std::ifstream file(filename.c_str(), std::ios::binary);

if(f_img.is_open())
if(file.is_open())
{
//Get file size
f_img.seekg(0, f_img.end);
u32 file_size = f_img.tellg();
f_img.seekg(0, f_img.beg);
file.seekg(0, file.end);
u32 file_size = file.tellg();
file.seekg(0, file.beg);

mobile_adapter.gbe_header.resize(file_size, 0x0);
u8* ex_mem = &mobile_adapter.gbe_header[0];
mobile_adapter.net_data.resize(file_size, 0x0);
u8* ex_mem = &mobile_adapter.net_data[0];

f_img.read((char*)ex_mem, file_size);
f_img.seekg(0, f_img.beg);
f_img.close();
file.read((char*)ex_mem, file_size);
file.seekg(0, file.beg);
file.close();

not_found = false;
img = true;
Expand Down Expand Up @@ -931,24 +943,33 @@ void DMG_SIO::mobile_adapter_process_http()
//HTTP data payload
//TODO - Remove hardcoding for Mobile Trainer
case 0x3:
http_response = "<html><body><img src=\"gbe_head.bmp\" /><center>Hello World</center></body></html>";
for(int x = 0; x < 254; x++)
{
if(mobile_adapter.data_index < mobile_adapter.net_data.size())
{
http_response += mobile_adapter.net_data[mobile_adapter.data_index++];
}

else { x = 255; }
}

response_id = 0x95;
mobile_adapter.transfer_state = 4;
mobile_adapter.transfer_state = (mobile_adapter.data_index < mobile_adapter.net_data.size()) ? 0x3 : 0x4;
break;

case 0x13:
for(int x = 0; x < 254; x++)
{
if(mobile_adapter.data_index < mobile_adapter.gbe_header.size())
if(mobile_adapter.data_index < mobile_adapter.net_data.size())
{
http_response += mobile_adapter.gbe_header[mobile_adapter.data_index++];
http_response += mobile_adapter.net_data[mobile_adapter.data_index++];
}

else { x = 255; }
}

response_id = 0x95;
mobile_adapter.transfer_state = (mobile_adapter.data_index < mobile_adapter.gbe_header.size()) ? 0x13 : 0x4;
mobile_adapter.transfer_state = (mobile_adapter.data_index < mobile_adapter.net_data.size()) ? 0x13 : 0x4;
break;

//Close connection
Expand Down
2 changes: 1 addition & 1 deletion src/dmg/sio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ void DMG_SIO::reset()
mobile_adapter.data.clear();
mobile_adapter.data.resize(0xC0, 0x0);
mobile_adapter.packet_buffer.clear();
mobile_adapter.gbe_header.clear();
mobile_adapter.net_data.clear();
mobile_adapter.packet_size = 0;
mobile_adapter.current_state = GBMA_AWAITING_PACKET;

Expand Down
2 changes: 1 addition & 1 deletion src/dmg/sio.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class DMG_SIO
{
std::vector <u8> data;
std::vector <u8> packet_buffer;
std::vector <u8> gbe_header;
std::vector <u8> net_data;
u32 packet_size;
mobile_state current_state;
std::string http_data;
Expand Down

0 comments on commit 4c53dec

Please sign in to comment.