Skip to content

Commit

Permalink
Improve vce and vdc
Browse files Browse the repository at this point in the history
  • Loading branch information
drhelius committed Aug 7, 2024
1 parent 484090f commit 8c4a9be
Show file tree
Hide file tree
Showing 13 changed files with 449 additions and 329 deletions.
3 changes: 3 additions & 0 deletions platforms/shared/desktop/emu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,9 @@ static void update_debug_background_buffer(void)

int color = ((byte1 >> (7 - tile_x)) & 0x01) | (((byte2 >> (7 - tile_x)) & 0x01) << 1) | (((byte3 >> (7 - tile_x)) & 0x01) << 2) | (((byte4 >> (7 - tile_x)) & 0x01) << 3);

if (color == 0)
color_table = 0;

u16 color_value = huc6260->GetColorTable()[(color_table * 16) + color];

// convert to 8 bit color
Expand Down
47 changes: 8 additions & 39 deletions platforms/shared/desktop/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ static u32 status_message_start_time = 0;
static u32 status_message_duration = 0;
static void main_window(void);
static void push_recent_rom(std::string path);
//static Cartridge::CartridgeRegions get_region(int index);
static void show_status_message(void);

void gui_init(void)
Expand Down Expand Up @@ -229,12 +228,19 @@ void gui_load_rom(const char* path)
if (config_emulator.start_paused)
{
emu_pause();

for (int i=0; i < (GG_MAX_RESOLUTION_WIDTH * GG_MAX_RESOLUTION_HEIGHT); i++)
{
emu_frame_buffer[i] = 0;
}
}

if (!emu_is_empty())
{
char title[256];
sprintf(title, "%s %s - %s", GEARGRAFX_TITLE, GEARGRAFX_VERSION, emu_get_core()->GetCartridge()->GetFileName());
application_update_title(title);
}
}

void gui_set_status_message(const char* message, u32 milliseconds)
Expand Down Expand Up @@ -364,28 +370,6 @@ static void main_window(void)
}
}




// static GC_Color color_float_to_int(ImVec4 color)
// {
// GC_Color ret;
// ret.red = (u8)floor(color.x >= 1.0 ? 255.0 : color.x * 256.0);
// ret.green = (u8)floor(color.y >= 1.0 ? 255.0 : color.y * 256.0);
// ret.blue = (u8)floor(color.z >= 1.0 ? 255.0 : color.z * 256.0);
// return ret;
// }

// static ImVec4 color_int_to_float(GC_Color color)
// {
// ImVec4 ret;
// ret.w = 0;
// ret.x = (1.0f / 255.0f) * color.red;
// ret.y = (1.0f / 255.0f) * color.green;
// ret.z = (1.0f / 255.0f) * color.blue;
// return ret;
// }

static void push_recent_rom(std::string path)
{
int slot = 0;
Expand All @@ -407,21 +391,6 @@ static void push_recent_rom(std::string path)
config_emulator.recent_roms[0] = path;
}

// static Cartridge::CartridgeRegions get_region(int index)
// {
// switch (index)
// {
// case 0:
// return Cartridge::CartridgeUnknownRegion;
// case 1:
// return Cartridge::CartridgeNTSC;
// case 2:
// return Cartridge::CartridgePAL;
// default:
// return Cartridge::CartridgeUnknownRegion;
// }
// }

static void show_status_message(void)
{
if (status_message_active)
Expand Down
20 changes: 15 additions & 5 deletions platforms/shared/desktop/gui_debug_huc6260.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,30 @@ void gui_debug_window_huc6260_info(void)
HuC6260* huc6260 = core->GetHuC6260();
HuC6260::HuC6260_State* huc6260_state = huc6260->GetState();

ImGui::TextColored(magenta, "SPEED"); ImGui::SameLine();
ImGui::TextColored(magenta, "SPEED "); ImGui::SameLine();
const char* speed[] = { "10.8 MHz", "7.16 MHz", "5.36 MHz" };
ImGui::TextColored(green, "%s", speed[huc6260->GetSpeed()]);

ImGui::TextColored(magenta, "CR "); ImGui::SameLine();
ImGui::TextColored(magenta, "SIGNALS "); ImGui::SameLine();
ImGui::TextColored(*huc6260_state->HSYNC ? gray : orange, "HSYNC"); ImGui::SameLine();
ImGui::TextColored(*huc6260_state->VSYNC ? gray : orange, "VSYNC");

ImGui::TextColored(magenta, "HPOS,VPOS"); ImGui::SameLine();
ImGui::TextColored(white, "%03X,%03X (%03d,%03d)", *huc6260_state->HPOS, *huc6260_state->VPOS, *huc6260_state->HPOS, *huc6260_state->VPOS);

ImGui::TextColored(magenta, "PIXEL "); ImGui::SameLine();
ImGui::TextColored(white, "%0X", *huc6260_state->PIXEL_INDEX);

ImGui::TextColored(magenta, "CTRL REG "); ImGui::SameLine();
ImGui::Text("$%02X (" BYTE_TO_BINARY_PATTERN_SPACED ")", *huc6260_state->CR, BYTE_TO_BINARY(*huc6260_state->CR));

ImGui::TextColored(magenta, "CTA "); ImGui::SameLine();
ImGui::TextColored(magenta, "CTA "); ImGui::SameLine();
ImGui::Text("$%04X (" BYTE_TO_BINARY_PATTERN_SPACED " " BYTE_TO_BINARY_PATTERN_SPACED ")", *huc6260_state->CTA, BYTE_TO_BINARY(*huc6260_state->CTA >> 8), BYTE_TO_BINARY(*huc6260_state->CTA & 0xFF));

ImGui::TextColored(magenta, "BLUR "); ImGui::SameLine();
ImGui::TextColored(magenta, "BLUR "); ImGui::SameLine();
ImGui::TextColored(IsSetBit(*huc6260_state->CR, 2) ? green : gray, "%s", IsSetBit(*huc6260_state->CR, 2) ? "ON" : "OFF");

ImGui::TextColored(magenta, "B&W "); ImGui::SameLine();
ImGui::TextColored(magenta, "B&W "); ImGui::SameLine();
ImGui::TextColored(IsSetBit(*huc6260_state->CR, 7) ? green : gray, "%s", IsSetBit(*huc6260_state->CR, 7) ? "ON" : "OFF");

ImGui::PopFont();
Expand Down
39 changes: 23 additions & 16 deletions platforms/shared/desktop/gui_debug_huc6270.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,19 @@ void gui_debug_window_huc6270_info(void)
const char* speed[] = { "10.8 MHz", "7.16 MHz", "5.36 MHz" };
ImGui::TextColored(green, "%s", speed[huc6260->GetSpeed()]);

ImGui::TextColored(magenta, "SCANLINE"); ImGui::SameLine();
ImGui::TextColored(orange, "%s", k_scanline_sections[*huc6270_state->SCANLINE_SECTION]);

ImGui::TextColored(magenta, "X,Y "); ImGui::SameLine();
ImGui::TextColored(white, "%03X,%03X (%03d,%03d)", *huc6270_state->HPOS, *huc6270_state->VPOS, *huc6270_state->HPOS, *huc6270_state->VPOS);

const char* h_states[] = { "HDS", "HDW", "HDE", "HSW" };
HuC6270::HuC6270_Horizontal_State* h_state = huc6270_state->H_STATE;
ImGui::TextColored(magenta, "H STATE "); ImGui::SameLine();
ImGui::TextColored(orange, "%s", h_states[*h_state]);

const char* v_states[] = { "VSW", "VDS", "VDW", "VCR" };
HuC6270::HuC6270_Vertical_State* v_state = huc6270_state->V_STATE;
ImGui::TextColored(magenta, "V STATE "); ImGui::SameLine();
ImGui::TextColored(orange, "%s", v_states[*v_state]);

ImGui::NewLine(); ImGui::TextColored(cyan, "CONTROL REGISTRY"); ImGui::Separator();

ImGui::TextColored(magenta, "BACKGRND"); ImGui::SameLine();
Expand Down Expand Up @@ -102,30 +109,30 @@ void gui_debug_window_huc6270_info(void)
ImGui::TextColored(magenta, "CG MODE "); ImGui::SameLine();
ImGui::TextColored(white, "%d", (huc6270_state->R[HUC6270_REG_MWR] >> 7) & 0x01);

ImGui::TextColored(magenta, "HDS"); ImGui::SameLine();
ImGui::TextColored(white, "%02X", (huc6270_state->R[HUC6270_REG_HSR] >> 8) & 0x7F); ImGui::SameLine();

ImGui::TextColored(magenta, "HDW"); ImGui::SameLine();
ImGui::TextColored(white, "%02X", huc6270_state->R[HUC6270_REG_HDR] & 0x7F); ImGui::SameLine();

ImGui::TextColored(magenta, "HDE"); ImGui::SameLine();
ImGui::TextColored(white, "%02X", (huc6270_state->R[HUC6270_REG_HDR] >> 8) & 0x7F); ImGui::SameLine();

ImGui::TextColored(magenta, "HSW"); ImGui::SameLine();
ImGui::TextColored(white, "%02X", huc6270_state->R[HUC6270_REG_HSR] & 0x1F);

ImGui::TextColored(magenta, "VSW"); ImGui::SameLine();
ImGui::TextColored(white, "%02X", huc6270_state->R[HUC6270_REG_VPR] & 0x1F); ImGui::SameLine();

ImGui::TextColored(magenta, "VDS"); ImGui::SameLine();
ImGui::TextColored(white, "%02X", (huc6270_state->R[HUC6270_REG_VPR] >> 8) & 0xFF); ImGui::SameLine();

ImGui::TextColored(magenta, "VDW"); ImGui::SameLine();
ImGui::TextColored(white, "%02X", huc6270_state->R[HUC6270_REG_VDR] & 0x1FF); ImGui::SameLine();
ImGui::TextColored(white, "%02X", huc6270_state->R[HUC6270_REG_VDW] & 0x1FF); ImGui::SameLine();

ImGui::TextColored(magenta, "VCR"); ImGui::SameLine();
ImGui::TextColored(white, "%02X", huc6270_state->R[HUC6270_REG_VCR] & 0xFF);

ImGui::TextColored(magenta, "HSW"); ImGui::SameLine();
ImGui::TextColored(white, "%02X", huc6270_state->R[HUC6270_REG_HSR] & 0x1F); ImGui::SameLine();

ImGui::TextColored(magenta, "HDS"); ImGui::SameLine();
ImGui::TextColored(white, "%02X", (huc6270_state->R[HUC6270_REG_HSR] >> 8) & 0x7F); ImGui::SameLine();

ImGui::TextColored(magenta, "HDW"); ImGui::SameLine();
ImGui::TextColored(white, "%02X", huc6270_state->R[HUC6270_REG_HDR] & 0x7F); ImGui::SameLine();

ImGui::TextColored(magenta, "HDE"); ImGui::SameLine();
ImGui::TextColored(white, "%02X", (huc6270_state->R[HUC6270_REG_HDR] >> 8) & 0x7F);

ImGui::NewLine(); ImGui::TextColored(cyan, "SCROLLING"); ImGui::Separator();

ImGui::TextColored(magenta, "X,Y "); ImGui::SameLine();
Expand Down
4 changes: 2 additions & 2 deletions platforms/shared/desktop/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ void renderer_init(void)
}

renderer_glew_version = (const char*)glewGetString(GLEW_VERSION);
Debug("Using GLEW %s", renderer_glew_version);
Log("Using GLEW %s", renderer_glew_version);
#endif

renderer_opengl_version = (const char*)glGetString(GL_VERSION);
Debug("Using OpenGL %s", renderer_opengl_version);
Log("Using OpenGL %s", renderer_opengl_version);

init_ogl_gui();
init_ogl_emu();
Expand Down
39 changes: 20 additions & 19 deletions src/geargrafx_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ GeargrafxCore::~GeargrafxCore()

void GeargrafxCore::Init(GG_Pixel_Format pixel_format)
{
Debug("--== %s %s by Ignacio Sanchez ==--", GEARGRAFX_TITLE, GEARGRAFX_VERSION);
Log("Loading %s core %s ...", GEARGRAFX_TITLE, GEARGRAFX_VERSION);
Log("by Ignacio Sanchez");

srand((unsigned int)time(NULL));

Expand All @@ -69,8 +70,8 @@ void GeargrafxCore::Init(GG_Pixel_Format pixel_format)

m_cartridge->Init();
m_memory->Init();
m_huc6260->Init();
m_huc6270->Init(m_huc6260, pixel_format);
m_huc6260->Init(pixel_format);
m_huc6270->Init();
m_huc6280->Init(m_memory, m_huc6270);
m_audio->Init();
m_input->Init();
Expand All @@ -90,28 +91,25 @@ bool GeargrafxCore::RunToVBlank(u8* frame_buffer, s16* sample_buffer, int* sampl
}
#endif

m_huc6260->SetBuffer(frame_buffer);
bool instruction_completed = false;
bool stop = false;
const int timer_divider = 3;
const int audio_divider = 6;
int failsafe_clocks = 0;
int huc6280_divider = m_huc6280->IsHighSpeed() ? 3 : 12;
int huc6260_divider = m_huc6260->GetClockDivider();

do
{
m_clock++;
instruction_completed = false;

if (m_clock % 3 == 0)
m_huc6280->ClockTimer();

if (m_clock % huc6280_divider == 0)
instruction_completed = m_huc6280->Clock();

if (m_clock % timer_divider == 0)
m_huc6280->ClockTimer();

if (m_clock % huc6260_divider == 0)
stop = m_huc6270->Clock(frame_buffer);
stop = m_huc6260->Clock();

if (m_clock % audio_divider == 0)
if (m_clock % 6 == 0)
m_audio->Clock();

#ifndef GG_DISABLE_DISASSEMBLER
Expand All @@ -125,11 +123,14 @@ bool GeargrafxCore::RunToVBlank(u8* frame_buffer, s16* sample_buffer, int* sampl
stop = true;
#endif
// Failsafe: if the emulator is running too long, stop it
// if (m_clock >= 89683)
// {
// m_clock -= 89683;
// if (failsafe_clocks >= 150000)
// stop = true;
// }

m_clock++;
failsafe_clocks++;

if ( m_clock == 12)
m_clock = 0;
}
while (!stop);

Expand Down Expand Up @@ -234,9 +235,9 @@ void GeargrafxCore::KeyReleased(GG_Controllers controller, GG_Keys key)
void GeargrafxCore::Pause(bool paused)
{
if (!m_paused && paused)
Log("Geargrafx PAUSED");
Debug("Core paused");
else if (m_paused && !paused)
Log("Geargrafx RESUMED");
Debug("Core resumed");
m_paused = paused;
}

Expand Down
Loading

0 comments on commit 8c4a9be

Please sign in to comment.