Skip to content

Commit

Permalink
Merge branch 'master' into game-loop-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
jtothebell committed Jan 3, 2024
2 parents 4dcc758 + f30bc01 commit 8a30268
Show file tree
Hide file tree
Showing 11 changed files with 197 additions and 19 deletions.
56 changes: 55 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,34 @@ jobs:

- name: Build
run: make tests

xbox-series-libretro:
name: Xbox Series Libretro
runs-on: windows-latest
defaults:
run:
shell: msys2 {0}

steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules : recursive

- uses: msys2/setup-msys2@v2
with:
msystem: UCRT64
update: true
install: git make mingw-w64-ucrt-x86_64-gcc

- name: Build
run: cd platform/libretro && make

- uses: actions/upload-artifact@v3
with:
name: Xbox-Series-libretro
path: |
platform/libretro/fake08_libretro.dll
threeDS:
name: 3DS
Expand Down Expand Up @@ -228,4 +256,30 @@ jobs:
name: GCW0-libretro
path: |
platform/libretro/fake08_libretro_gcw0.so
platform/libretro/fake08_libretro.info
platform/libretro/fake08_libretro.info
switch-libretro:
name: switch-libretro
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules : recursive

- name: CheckoutLibretro
uses: actions/checkout@v3
with:
repository: libretro/RetroArch
path: retroarch

- name: Build
run: |
docker run -e ENABLE_COMPATIBILITY_REPORTING -v $GITHUB_WORKSPACE:/build_dir devkitpro/devkita64 /bin/bash -ex /build_dir/.github/workflows/buildSwitch-libretro.sh
- uses: actions/upload-artifact@v3
with:
name: switch-libretro
path: |
platform/libretro/fake08_libretro.info
retroarch/fake08_libretro_libnx.nro
16 changes: 16 additions & 0 deletions .github/workflows/buildSwitch-libretro.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#source /etc/profile.d/devkit-env.sh

cd /build_dir

#Build core
cd platform/libretro
make echo platform=libnx
make platform=libnx

cp fake08_libretro_libnx.a ../../retroarch/libretro_libnx.a

cd ../../retroarch

make -f Makefile.libnx

cp retroarch_switch.nro fake08_libretro_libnx.nro
1 change: 0 additions & 1 deletion .github/workflows/buildSwitch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ cd /build_dir
#Build nro
make switch

#todo: copy artifacts for uploading
23 changes: 20 additions & 3 deletions platform/libretro/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,23 @@ else ifeq ($(platform), gcw0)
CXXFLAGS += -fno-common -ftree-vectorize -funswitch-loops
fpic := -fPIC
SHARED := -shared -Wl,-version-script=link.T
else ifeq ($(platform), libnx)
TARGET := $(TARGET_NAME)_libretro_$(platform).a
include $(DEVKITPRO)/libnx/switch_rules
STATIC_LINKING = 1
DEFINES := -D__SWITCH__ -DSWITCH=1
CFLAGS := $(DEFINES) -g -O3 \
-fPIE -I$(LIBNX)/include/ -ffunction-sections -fdata-sections -ftls-model=local-exec -Wl,--allow-multiple-definition -specs=$(LIBNX)/switch.specs
CFLAGS += $(INCDIRS)
CFLAGS += -DHAVE_LIBNX -march=armv8-a -mtune=cortex-a57 -mtp=soft
CXXFLAGS := $(ASFLAGS) $(CFLAGS)
else
CC = gcc
TARGET := $(TARGET_NAME)_libretro.dll
SHARED := -shared -static-libgcc -static-libstdc++ -s -Wl,--version-script=link.T -Wl,--no-undefined
SHARED := -shared -static-libgcc -static-libstdc++ -Wl,--version-script=link.T -Wl,--no-undefined
ifneq ($(DEBUG), 1)
SHARED += -s
endif
endif

LDFLAGS += $(LIBM)
Expand All @@ -155,8 +168,8 @@ CC = $(CXX)

OBJECTS := $(SOURCES_C:.c=.o) $(SOURCES_CXX:.cpp=.o)

CFLAGS += $(fpic) -Wall -D__LIBRETRO__ -ffunction-sections -std=gnu++17 -fno-rtti $(INCFLAGS)
CXXFLAGS += $(fpic) -Wall -D__LIBRETRO__ -ffunction-sections -std=gnu++17 -fno-rtti $(INCFLAGS)
CFLAGS += $(fpic) -Wall -D__LIBRETRO__ -DMINIZ_NO_TIME -ffunction-sections -std=gnu++17 -fno-rtti $(INCFLAGS)
CXXFLAGS += $(fpic) -Wall -D__LIBRETRO__ -DMINIZ_NO_TIME -ffunction-sections -std=gnu++17 -fno-rtti $(INCFLAGS)

all: $(TARGET)

Expand All @@ -172,6 +185,10 @@ endif
@$(if $(Q), $(shell echo echo CC $<),)
$(Q)$(CXX) $(CFLAGS) $(fpic) -c -o $@ $<

%.o: %.cpp
@$(if $(Q), $(shell echo echo CXX $<),)
$(Q)$(CXX) $(CFLAGS) $(fpic) -c -o $@ $<

clean:
rm -f $(OBJECTS) $(TARGET)

Expand Down
8 changes: 6 additions & 2 deletions platform/libretro/libretro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ static std::array<int, 7> buttons
RETRO_DEVICE_ID_JOYPAD_RIGHT,
RETRO_DEVICE_ID_JOYPAD_UP,
RETRO_DEVICE_ID_JOYPAD_DOWN,
RETRO_DEVICE_ID_JOYPAD_A,
RETRO_DEVICE_ID_JOYPAD_B,
RETRO_DEVICE_ID_JOYPAD_A,
RETRO_DEVICE_ID_JOYPAD_START,
};

Expand Down Expand Up @@ -615,6 +615,11 @@ EXPORT void retro_cheat_set(unsigned index, bool enabled, const char *code)

EXPORT bool retro_load_game(struct retro_game_info const *info)
{
if (!info) {
_vm->QueueCartChange("__FAKE08-BIOS.p8");
return true;
}

auto containingDir = getDirectory(info->path);

if (containingDir.length() > 0) {
Expand All @@ -624,7 +629,6 @@ EXPORT bool retro_load_game(struct retro_game_info const *info)
if (info->size > 0) {
const unsigned char* data = reinterpret_cast<const unsigned char*>(info->data);
_vm->QueueCartChange(data, info->size);

}
else {
_vm->QueueCartChange(info->path);
Expand Down
1 change: 0 additions & 1 deletion source/filehelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,3 @@ bool isCPostFile (std::string const &fullString) {
return !isHiddenFile(fullString) &&
fullString.rfind("cpost", 0) == 0;
}

9 changes: 7 additions & 2 deletions source/graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,7 @@ void Graphics::line (int x1, int y1, int x2, int y2){
void Graphics::_private_h_line(int x1, int x2, int y){
auto &drawState = _memory->drawState;
auto &hwState = _memory->hwState;
uint8_t * screenBuffer = GetP8FrameBuffer();

if (!(y >= drawState.clip_yb && y < drawState.clip_ye)) {
return;
Expand Down Expand Up @@ -723,7 +724,7 @@ void Graphics::_private_h_line(int x1, int x2, int y){

if (canmemset) {
//zepto 8 adapted otimized line draw with memset
uint8_t *p = _memory->screenBuffer + (y*64);
uint8_t *p = screenBuffer + (y*64);
uint8_t color = getDrawPalMappedColor(drawState.color);

if (minx & 1)
Expand Down Expand Up @@ -1324,6 +1325,10 @@ int Graphics::drawCharacter(
? forceCharWidth > -1 && forceCharWidth < 4 ? forceCharWidth : defaultCharWidth
: forceCharWidth > -1 && forceCharWidth < 4 ? (forceCharWidth + 4) : defaultWideCharWidth;

if (ch >= 0x80) {
extraCharWidth = defaultWideCharWidth - defaultCharWidth;
}

uint8_t charHeight = forceCharHeight > -1 && forceCharHeight < 5 ? forceCharHeight : defaultCharHeight;

auto result = drawCharacterFromBytes(
Expand All @@ -1336,7 +1341,7 @@ int Graphics::drawCharacter(
charWidth,
charHeight
);
extraCharWidth = get<0>(result);
extraCharWidth += get<0>(result);
}

if ((printMode & PRINT_MODE_ON) == PRINT_MODE_ON){
Expand Down
4 changes: 2 additions & 2 deletions source/host.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ class Host {
#endif
StretchOption stretch = PixelPerfectStretch;
KeyboardOption kbmode = Emoji;
ResizekeyOption resizekey = NoResize;
MenuStyleOption menustyle = Fancy;
ResizekeyOption resizekey = YesResize;
MenuStyleOption menustyle = Classic;
BgColorOption bgcolor = Gray;

float scaleX = 1.0;
Expand Down
12 changes: 6 additions & 6 deletions source/printHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ int print(std::string str, int x, int y, uint8_t c) {
int lineHeight = 0;
int forceCharWidth = -1;
int forceCharHeight = -1;
uint8_t bgColor = 0;
uint8_t bgColor = 0xff;
uint8_t fgColor = _ph_mem->drawState.color;
uint8_t charBytes[8];
uint8_t audioStrBytes[32];
Expand Down Expand Up @@ -189,7 +189,7 @@ int print(std::string str, int x, int y, uint8_t c) {
x,
y,
drawPal[fgColor & 0x0f],
drawPal[bgColor & 0x0f],
bgColor == 0xff ? 0 : drawPal[bgColor & 0x0f],
printMode,
forceCharWidth,
forceCharHeight);
Expand Down Expand Up @@ -335,7 +335,7 @@ int print(std::string str, int x, int y, uint8_t c) {
x,
y,
drawPal[fgColor & 0x0f],
drawPal[bgColor & 0x0f],
bgColor == 0xff ? 0 : drawPal[bgColor & 0x0f],
printMode,
8,
charHeight);
Expand Down Expand Up @@ -432,7 +432,7 @@ int print(std::string str, int x, int y, uint8_t c) {
prevX + xOffset,
prevY + yOffset,
drawPal[fgColor & 0x0f],
drawPal[bgColor & 0x0f],
bgColor == 0xff ? 0 : drawPal[bgColor & 0x0f],
printMode,
forceCharWidth,
forceCharHeight);
Expand Down Expand Up @@ -467,7 +467,7 @@ int print(std::string str, int x, int y, uint8_t c) {
}
else if (ch >= 0x10) {
lineHeight = charHeight > lineHeight ? charHeight : lineHeight;
if (bgColor != 0) {
if (bgColor != 0xff) {
uint8_t prevPenColor = _ph_mem->drawState.color;
_ph_graphics->rectfill(x-1, y-1, x + charWidth-1, y + lineHeight-1, bgColor);
_ph_mem->drawState.color = prevPenColor;
Expand All @@ -479,7 +479,7 @@ int print(std::string str, int x, int y, uint8_t c) {
x,
y,
drawPal[fgColor & 0x0f],
drawPal[bgColor & 0x0f],
bgColor == 0xff ? 0 : drawPal[bgColor & 0x0f],
printMode,
forceCharWidth,
forceCharHeight);
Expand Down
71 changes: 70 additions & 1 deletion test/endtoendtests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ bool verifyScreenshot(Vm* vm, Host* host, std::string screenshotFilename) {
error = lodepng::decode(image, width, height, png);
}
if (error) {
CHECK_MESSAGE(error == 0, "Unable to decode screenshot png");
CHECK_MESSAGE(error == 0, "Unable to decode screenshot png %s", screenshotFilename.c_str());
return false;
}

Expand Down Expand Up @@ -71,10 +71,66 @@ bool verifyScreenshot(Vm* vm, Host* host, std::string screenshotFilename) {

}

/*
#include <filesystem>
namespace fs = std::filesystem;
std::vector<std::string> get_cart_files_in_dir(std::string directory){
std::vector<std::string> files;
for (const auto & entry : fs::directory_iterator(directory)) {
std::string path = entry.path().string();
if (isCartFile(path)) {
files.push_back(path.substr(path.find_last_of("/\\") + 1));
}
}
return files;
}
*/

TEST_CASE("Loading and running carts") {
Host* host = new Host();
Vm* vm = new Vm(host);

/*
SUBCASE("test carts") {
// char cwd[PATH_MAX];
// if (getcwd(cwd, sizeof(cwd)) != NULL) {
// printf("Current working dir: %s\n", cwd);
// }
auto screenshots = get_cart_files_in_dir("carts/screenshots");
for (auto screenshot : screenshots) {
if (screenshot.length() < 8) {
continue;
}
auto last8Chars = screenshot.substr(screenshot.length() - 8);
if (last8Chars != "_f01.png") {
continue;
}
auto cartfile = screenshot.substr(0, screenshot.length() - 8) + ".p8";
vm->LoadCart(cartfile, false);
vm->vm_reset();
SUBCASE("No error reported"){
CHECK(vm->GetBiosError() == "");
}
if (getFileExtension(cartfile) == ".p8") {
SUBCASE(cartfile.c_str()){
vm->UpdateAndDraw();
std::stringstream ss;
ss << "carts/screenshots/" << screenshot;
CHECK(verifyScreenshot(vm, host, ss.str()));
}
}
vm->CloseCart();
}
}
*/

SUBCASE("Load simple cart"){
vm->LoadCart("cartparsetest.p8", false);

Expand Down Expand Up @@ -762,7 +818,20 @@ TEST_CASE("Loading and running carts") {

vm->CloseCart();
}
SUBCASE("bold text with wide char test"){
vm->LoadCart("boldtexttest.p8", false);

SUBCASE("No error reported"){
CHECK(vm->GetBiosError() == "");
}
SUBCASE("sceen matches screenshot"){
vm->UpdateAndDraw();

CHECK(verifyScreenshot(vm, host, "carts/screenshots/boldtexttest_f01.png"));
}

vm->CloseCart();
}

delete vm;
delete host;
Expand Down
15 changes: 15 additions & 0 deletions test/printHelperTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,22 @@ TEST_CASE("Print helper functions") {

checkPoints(graphics, expectedPoints);
}
SUBCASE("pal mapping color 0 to another color does not color background") {
graphics->cls();
graphics->pal(0, 10, 0);

print("0", 0, 0, 10);

std::vector<coloredPoint> expectedPoints = {
{0, 0, 10}, {1, 0, 10}, {2, 0, 10},
{0, 1, 10}, {1, 1, 0}, {2, 1, 10},
{0, 2, 10}, {1, 2, 0}, {2, 2, 10},
{0, 3, 10}, {1, 3, 0}, {2, 3, 10},
{0, 4, 10}, {1, 4, 10}, {2, 4, 10},
};

checkPoints(graphics, expectedPoints);
}

delete stubHost;
delete graphics;
Expand Down

0 comments on commit 8a30268

Please sign in to comment.