Skip to content

Commit

Permalink
[libretro] working core. Fix #11
Browse files Browse the repository at this point in the history
  • Loading branch information
drhelius committed Jan 3, 2025
1 parent e1b3b39 commit 1e1e686
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 34 deletions.
2 changes: 1 addition & 1 deletion platforms/libretro/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ ifeq ($(DEBUG), 1)
CXXFLAGS += -O0 -DDEBUG -g
else
BUILD_CONFIG = Release
CXXFLAGS += -O3
CXXFLAGS += -O3 -DNDEBUG
endif

GIT_VERSION ?= "$(shell git describe --abbrev=7 --dirty --always --tags || echo unknown)"
Expand Down
22 changes: 14 additions & 8 deletions platforms/libretro/libretro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,20 +437,26 @@ static void update_input(void)
// Get current state
for (int j = 0; j < MAX_PADS; j++)
{
int up_pressed = IsButtonPressed(joypad_bits[j], RETRO_DEVICE_ID_JOYPAD_UP);
int down_pressed = IsButtonPressed(joypad_bits[j], RETRO_DEVICE_ID_JOYPAD_DOWN);
int left_pressed = IsButtonPressed(joypad_bits[j], RETRO_DEVICE_ID_JOYPAD_LEFT);
int right_pressed = IsButtonPressed(joypad_bits[j], RETRO_DEVICE_ID_JOYPAD_RIGHT);

if (allow_up_down)
{
joypad_current[j][0] = joypad_bits[j] & (1 << RETRO_DEVICE_ID_JOYPAD_UP) ? 1 : 0;
joypad_current[j][1] = joypad_bits[j] & (1 << RETRO_DEVICE_ID_JOYPAD_DOWN) ? 1 : 0;
joypad_current[j][2] = joypad_bits[j] & (1 << RETRO_DEVICE_ID_JOYPAD_LEFT) ? 1 : 0;
joypad_current[j][3] = joypad_bits[j] & (1 << RETRO_DEVICE_ID_JOYPAD_RIGHT) ? 1 : 0;
joypad_current[j][0] = up_pressed;
joypad_current[j][1] = down_pressed;
joypad_current[j][2] = left_pressed;
joypad_current[j][3] = right_pressed;
}
else
{
joypad_current[j][0] = (IsButtonPressed(joypad_bits[j], RETRO_DEVICE_ID_JOYPAD_UP) && IsButtonPressed(joypad_bits[j], RETRO_DEVICE_ID_JOYPAD_DOWN)) ? 1 : 0;
joypad_current[j][1] = (IsButtonPressed(joypad_bits[j], RETRO_DEVICE_ID_JOYPAD_DOWN) && IsButtonPressed(joypad_bits[j], RETRO_DEVICE_ID_JOYPAD_UP)) ? 1 : 0;
joypad_current[j][2] = (IsButtonPressed(joypad_bits[j], RETRO_DEVICE_ID_JOYPAD_LEFT) && IsButtonPressed(joypad_bits[j], RETRO_DEVICE_ID_JOYPAD_RIGHT)) ? 1 : 0;
joypad_current[j][3] = (IsButtonPressed(joypad_bits[j], RETRO_DEVICE_ID_JOYPAD_RIGHT) && IsButtonPressed(joypad_bits[j], RETRO_DEVICE_ID_JOYPAD_LEFT)) ? 1 : 0;
joypad_current[j][0] = (up_pressed && (!down_pressed || joypad_old[j][0])) ? 1 : 0;
joypad_current[j][1] = (down_pressed && (!up_pressed || joypad_old[j][1])) ? 1 : 0;
joypad_current[j][2] = (left_pressed && (!right_pressed || joypad_old[j][2])) ? 1 : 0;
joypad_current[j][3] = (right_pressed && (!left_pressed || joypad_old[j][3])) ? 1 : 0;
}

joypad_current[j][4] = IsButtonPressed(joypad_bits[j], RETRO_DEVICE_ID_JOYPAD_A);
joypad_current[j][5] = IsButtonPressed(joypad_bits[j], RETRO_DEVICE_ID_JOYPAD_B);
joypad_current[j][6] = IsButtonPressed(joypad_bits[j], RETRO_DEVICE_ID_JOYPAD_SELECT);
Expand Down
4 changes: 2 additions & 2 deletions platforms/shared/desktop/gui_debug_text.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
#ifndef GUI_DEBUG_TEXT_H
#define GUI_DEBUG_TEXT_H

#include <cstdio>
#include <cstdarg>
#include <stdio.h>
#include <stdarg.h>
#include "imgui/imgui.h"

const char k_color_marker_start = '{';
Expand Down
2 changes: 1 addition & 1 deletion src/geargrafx_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class GeargrafxCore
public:
GeargrafxCore();
~GeargrafxCore();
void Init(GG_Pixel_Format pixel_format = GG_PIXEL_RGB888);
void Init(GG_Pixel_Format pixel_format = GG_PIXEL_RGBA8888);
bool RunToVBlank(u8* frame_buffer, s16* sample_buffer, int* sample_count, GG_Debug_Run* debug = NULL);
bool LoadROM(const char* file_path);
bool LoadROMFromBuffer(const u8* buffer, int size);
Expand Down
103 changes: 88 additions & 15 deletions src/huc6260.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
*
*/

#include <assert.h>
#include "huc6260.h"

HuC6260::HuC6260(HuC6270* huc6270, HuC6280* huc6280)
{
m_huc6280 = huc6280;
m_huc6270 = huc6270;
m_pixel_format = GG_PIXEL_RGB888;
m_pixel_format = GG_PIXEL_RGBA8888;
m_state.CR = &m_control_register;
m_state.CTA = &m_color_table_address;
m_state.HPOS = &m_hpos;
Expand Down Expand Up @@ -67,8 +68,8 @@ void HuC6260::InitPalettes()
m_bgr888_palette[i][1] = green;
m_bgr888_palette[i][2] = red;

green = ((i >> 6) & 0x07) * 31 / 7;
red = ((i >> 3) & 0x07) * 63 / 7;
green = ((i >> 6) & 0x07) * 63 / 7;
red = ((i >> 3) & 0x07) * 31 / 7;
blue = (i & 0x07) * 31 / 7;
m_rgb565_palette[i] = (red << 11) | (green << 5) | blue;
m_bgr565_palette[i] = (blue << 11) | (green << 5) | red;
Expand Down Expand Up @@ -127,18 +128,7 @@ bool HuC6260::Clock()
if ((pixel & 0x10F) == 0)
pixel = 0;

u16 color = m_color_table[pixel];
u8 red = m_rgb888_palette[color][0];
u8 green = m_rgb888_palette[color][1];
u8 blue = m_rgb888_palette[color][2];

int component = m_pixel_index * 4;
m_frame_buffer[component + 0] = red;
m_frame_buffer[component + 1] = green;
m_frame_buffer[component + 2] = blue;
m_frame_buffer[component + 3] = 255;

m_pixel_index++;
WritePixel(pixel);
}

m_pixel_x = (m_pixel_x + 1) % k_huc6260_full_line_width[m_speed];
Expand Down Expand Up @@ -244,4 +234,87 @@ void HuC6260::SetScanlineEnd(int scanline_end)
void HuC6260::SetOverscan(bool overscan)
{
m_overscan = overscan ? 1 : 0;
}

void HuC6260::WritePixel(u16 pixel)
{
assert(pixel < 512);

if (pixel >= 512)
{
Debug("HuC6260: Invalid pixel value %04X\n", pixel);
pixel = 0;
}

u16 color = m_color_table[pixel];

assert(color < 512);

if (color >= 512)
{
Debug("HuC6260: Invalid color value %04X\n", color);
color = 0;
}

switch (m_pixel_format)
{
case GG_PIXEL_RGB565:
{
int byte = m_pixel_index * 2;
u16 color_16 = m_rgb565_palette[color];
m_frame_buffer[byte + 0] = color_16 & 0xFF;
m_frame_buffer[byte + 1] = (color_16 >> 8) & 0xFF;
}
break;
case GG_PIXEL_RGBA8888:
{
int byte = m_pixel_index * 4;
u8 red = m_rgb888_palette[color][0];
u8 green = m_rgb888_palette[color][1];
u8 blue = m_rgb888_palette[color][2];
m_frame_buffer[byte + 0] = red;
m_frame_buffer[byte + 1] = green;
m_frame_buffer[byte + 2] = blue;
m_frame_buffer[byte + 3] = 255;
}
break;
case GG_PIXEL_RGB555:
{
int byte = m_pixel_index * 2;
u16 color_16 = m_rgb555_palette[color];
m_frame_buffer[byte + 0] = color_16 & 0xFF;
m_frame_buffer[byte + 1] = (color_16 >> 8) & 0xFF;
}
break;
case GG_PIXEL_BGR565:
{
int byte = m_pixel_index * 2;
u16 color_16 = m_bgr565_palette[color];
m_frame_buffer[byte + 0] = color_16 & 0xFF;
m_frame_buffer[byte + 1] = (color_16 >> 8) & 0xFF;
}
break;
case GG_PIXEL_BGR555:
{
int byte = m_pixel_index * 2;
u16 color_16 = m_bgr555_palette[color];
m_frame_buffer[byte + 0] = color_16 & 0xFF;
m_frame_buffer[byte + 1] = (color_16 >> 8) & 0xFF;
}
break;
case GG_PIXEL_BGRA8888:
{
int byte = m_pixel_index * 4;
u8 blue = m_bgr888_palette[color][0];
u8 green = m_bgr888_palette[color][1];
u8 red = m_bgr888_palette[color][2];
m_frame_buffer[byte + 0] = blue;
m_frame_buffer[byte + 1] = green;
m_frame_buffer[byte + 2] = red;
m_frame_buffer[byte + 3] = 255;
}
break;
}

m_pixel_index++;
}
5 changes: 4 additions & 1 deletion src/huc6260.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class HuC6260
public:
HuC6260(HuC6270* huc6270, HuC6280* huc6280);
~HuC6260();
void Init(GG_Pixel_Format pixel_format = GG_PIXEL_RGB888);
void Init(GG_Pixel_Format pixel_format = GG_PIXEL_RGBA8888);
void InitPalettes();
void Reset();
bool Clock();
Expand All @@ -74,6 +74,9 @@ class HuC6260
void SetScanlineEnd(int scanline_end);
void SetOverscan(bool overscan);

private:
void WritePixel(u16 pixel);

private:
HuC6270* m_huc6270;
HuC6280* m_huc6280;
Expand Down
2 changes: 1 addition & 1 deletion src/huc6270.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
*
*/

#include <cassert>
#include <stdlib.h>
#include <assert.h>
#include "huc6270.h"

HuC6270::HuC6270(HuC6280* huC6280)
Expand Down
1 change: 0 additions & 1 deletion src/huc6280_psg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*
*/

#include <cmath>
#include <algorithm>
#include "huc6280_psg.h"

Expand Down
4 changes: 2 additions & 2 deletions src/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
#ifndef LOG_H
#define LOG_H

#include <cstdio>
#include <cstdarg>
#include <stdio.h>
#include <stdarg.h>
#include "defines.h"

#if defined(GG_DEBUG)
Expand Down
4 changes: 2 additions & 2 deletions src/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ enum GG_Pixel_Format
{
GG_PIXEL_RGB565,
GG_PIXEL_RGB555,
GG_PIXEL_RGB888,
GG_PIXEL_RGBA8888,
GG_PIXEL_BGR565,
GG_PIXEL_BGR555,
GG_PIXEL_BGR888
GG_PIXEL_BGRA8888
};

enum GG_Keys
Expand Down

0 comments on commit 1e1e686

Please sign in to comment.