diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml new file mode 100644 index 0000000..b1c650a --- /dev/null +++ b/.github/workflows/macos.yml @@ -0,0 +1,25 @@ +name: macOS CI + +on: + push: + branches: [ "master" ] + +jobs: + build: + runs-on: macos-latest + + steps: + - uses: actions/checkout@v3 + - name: Install SDL2 and dylibbundler + run: | + brew install sdl2 + brew install dylibbundler + - name: Build and pack PSXE + run: | + ./build.sh + mkdir -p psxe + mv psxe.app psxe + - uses: actions/upload-artifact@v3 + with: + name: psxe-macos-latest + path: psxe/ diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml new file mode 100644 index 0000000..22bdd70 --- /dev/null +++ b/.github/workflows/ubuntu.yml @@ -0,0 +1,22 @@ +name: Ubuntu CI + +on: + push: + branches: [ "master" ] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Install SDL2 + run: | + sudo apt update + sudo apt install libsdl2-dev + - name: make + run: make + - uses: actions/upload-artifact@v3 + with: + name: psxe-ubuntu-latest + path: bin/psxe \ No newline at end of file diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml new file mode 100644 index 0000000..b4300c6 --- /dev/null +++ b/.github/workflows/windows.yml @@ -0,0 +1,35 @@ +name: Windows CI + +on: + push: + branches: [ "master" ] + +jobs: + build: + runs-on: windows-latest + + steps: + - uses: actions/checkout@v3 + - name: Run build-deps + run: ./build-deps.ps1 + - name: 64-bit build + run: | + ./build-win64.ps1 + New-Item -Path "psxe" -ItemType Directory + Copy-Item -Recurse "bin" -Destination "psxe" + - uses: actions/upload-artifact@v3 + with: + name: psxe-win64-latest + path: psxe/ + - name: Cleanup + run: ./build-clean + - name: 32-bit build + run: | + Remove-Item -Path psxe -Recurse + ./build-win32.ps1 + New-Item -Path "psxe" -ItemType Directory + Copy-Item -Recurse "bin" -Destination "psxe" + - uses: actions/upload-artifact@v3 + with: + name: psxe-win32-latest + path: psxe/ \ No newline at end of file diff --git a/.gitignore b/.gitignore index 63760f8..5b329a9 100644 --- a/.gitignore +++ b/.gitignore @@ -5,9 +5,12 @@ imgui/ res/ sdl2/ SDL2-2.26.5/ +sdl2-win32/ +sdl2-win64/ test/ *.bin *.dll *.exe *.out -*.toml \ No newline at end of file +*.toml +*.zip \ No newline at end of file diff --git a/Info.plist b/Info.plist new file mode 100644 index 0000000..5cfc5cf --- /dev/null +++ b/Info.plist @@ -0,0 +1,32 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + psxe + CFBundleIdentifier + psxe.app.0 + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + psxe + CFBundlePackageType + APPL + CFBundleShortVersionString + 0.1-alpha + CFBundleSignature + psxe + CFBundleVersion + 0.1-alpha + LSApplicationCategoryType + public.app-category.games + LSMinimumSystemVersion + 10.6 + NSHighResolutionCapable + + NSPrincipalClass + NSApplication + + diff --git a/Makefile b/Makefile index 32a82ef..2214649 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,8 @@ bin/psxe frontend/main.c: -DREP_VERSION="$(VERSION_TAG)" \ -DREP_COMMIT_HASH="$(COMMIT_HASH)" \ -g -DLOG_USE_COLOR -lSDL2 -lSDL2main \ - -Ofast -Wno-overflow -Wall -pedantic + -Ofast -Wno-overflow -Wall -pedantic \ + -Wno-newline-eof clean: rm -rf "bin" diff --git a/build-deps.ps1 b/build-deps.ps1 index 89f0f80..6807f13 100644 --- a/build-deps.ps1 +++ b/build-deps.ps1 @@ -2,11 +2,19 @@ if (Test-Path "SDL2-2.26.5") { Remove-Item -Recurse "SDL2-2.26.5" } -$URL = "https://github.com/libsdl-org/SDL/releases/download/release-2.26.5/SDL2-devel-2.26.5-mingw.zip" +$SDL2_URL = "https://github.com/libsdl-org/SDL/releases/download/release-2.26.5/SDL2-devel-2.26.5-mingw.zip" +$WIN32_URL = "https://github.com/libsdl-org/SDL/releases/download/release-2.26.5/SDL2-2.26.5-win32-x86.zip" +$WIN64_URL = "https://github.com/libsdl-org/SDL/releases/download/release-2.26.5/SDL2-2.26.5-win32-x64.zip" -Invoke-WebRequest -URI $URL -OutFile "sdl2.zip" -Expand-Archive "sdl2.zip" -DestinationPath "." +Invoke-WebRequest -URI $SDL2_URL -OutFile "sdl2.zip" +Expand-Archive "sdl2.zip" -DestinationPath "." -Force + +Invoke-WebRequest -URI $WIN32_URL -OutFile "sdl2-win32.zip" +Expand-Archive "sdl2-win32.zip" -DestinationPath "sdl2-win32" -Force + +Invoke-WebRequest -URI $WIN64_URL -OutFile "sdl2-win64.zip" +Expand-Archive "sdl2-win64.zip" -DestinationPath "sdl2-win64" -Force Remove-Item "sdl2.zip" - -Copy-Item -Path "SDL2-2.26.5\x86_64-w64-mingw32\bin\SDL2.dll" -Destination . \ No newline at end of file +Remove-Item "sdl2-win32.zip" +Remove-Item "sdl2-win64.zip" \ No newline at end of file diff --git a/build-win32.ps1 b/build-win32.ps1 new file mode 100644 index 0000000..37e6d4a --- /dev/null +++ b/build-win32.ps1 @@ -0,0 +1,25 @@ +$VERSION_TAG = git describe --always --tags --abbrev=0 +$COMMIT_HASH = git rev-parse --short HEAD +$OS_INFO = (Get-WMIObject win32_operatingsystem).caption + " " + (Get-WMIObject win32_operatingsystem).version + " " + (Get-WMIObject win32_operatingsystem).OSArchitecture + +$SDL2_DIR = "SDL2-2.26.5\x86_64-w64-mingw32" +$PSX_DIR = "." + +mkdir -Force -Path bin > $null + +gcc -I"`"$($PSX_DIR)`"" ` + -I"`"$($SDL2_DIR)\include`"" ` + -I"`"$($SDL2_DIR)\include\SDL2`"" ` + "psx\*.c" ` + "psx\dev\*.c" ` + "frontend\*.c" ` + -o "bin\psxe.exe" ` + -DREP_VERSION="`"$($VERSION_TAG)`"" ` + -DREP_COMMIT_HASH="`"$($COMMIT_HASH)`"" ` + -DOS_INFO="`"$($OS_INFO)`"" ` + -L"`"$($SDL2_DIR)\lib`"" ` + -lSDL2main -lSDL2 -Wno-overflow ` + -Wall -pedantic -DLOG_USE_COLOR ` + -ffast-math -Ofast + +Copy-Item -Path "sdl2-win32/SDL2.dll" -Destination "bin" \ No newline at end of file diff --git a/build-win64.ps1 b/build-win64.ps1 new file mode 100644 index 0000000..c1337a0 --- /dev/null +++ b/build-win64.ps1 @@ -0,0 +1,25 @@ +$VERSION_TAG = git describe --always --tags --abbrev=0 +$COMMIT_HASH = git rev-parse --short HEAD +$OS_INFO = (Get-WMIObject win32_operatingsystem).caption + " " + (Get-WMIObject win32_operatingsystem).version + " " + (Get-WMIObject win32_operatingsystem).OSArchitecture + +$SDL2_DIR = "SDL2-2.26.5\x86_64-w64-mingw32" +$PSX_DIR = "." + +mkdir -Force -Path bin > $null + +gcc -I"`"$($PSX_DIR)`"" ` + -I"`"$($SDL2_DIR)\include`"" ` + -I"`"$($SDL2_DIR)\include\SDL2`"" ` + "psx\*.c" ` + "psx\dev\*.c" ` + "frontend\*.c" ` + -o "bin\psxe.exe" ` + -DREP_VERSION="`"$($VERSION_TAG)`"" ` + -DREP_COMMIT_HASH="`"$($COMMIT_HASH)`"" ` + -DOS_INFO="`"$($OS_INFO)`"" ` + -L"`"$($SDL2_DIR)\lib`"" ` + -m64 -lSDL2main -lSDL2 -Wno-overflow ` + -Wall -pedantic -DLOG_USE_COLOR ` + -ffast-math -Ofast + +Copy-Item -Path "sdl2-win64/SDL2.dll" -Destination "bin" \ No newline at end of file diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..f1838e5 --- /dev/null +++ b/build.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +# Build emulator +make clean && make + +# Create bundle filesystem +mkdir -p psxe.app/Contents/MacOS/Libraries + +# Move executable to folder +mv bin/psxe psxe.app/Contents/MacOS + +# Make executable +chmod 777 psxe.app/Contents/MacOS/psxe + +# Bundle required dylibs +dylibbundler -b -x ./psxe.app/Contents/MacOS/psxe -d ./psxe.app/Contents/Libraries/ -p @executable_path/../Libraries/ -cd + +# Move plist to Contents folder +mv Info.plist psxe.app/Contents/Info.plist \ No newline at end of file diff --git a/frontend/screen.c b/frontend/screen.c index cd31137..f8049aa 100644 --- a/frontend/screen.c +++ b/frontend/screen.c @@ -21,9 +21,13 @@ void psxe_screen_init(psxe_screen_t* screen, psx_t* psx) { screen->psx = psx; SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS); + + SDL_SetHint("SDL_HINT_RENDER_SCALE_QUALITY", "2"); } void psxe_screen_reload(psxe_screen_t* screen) { + SDL_SetHint("SDL_HINT_RENDER_SCALE_QUALITY", "2"); + if (screen->texture) SDL_DestroyTexture(screen->texture); if (screen->renderer) SDL_DestroyRenderer(screen->renderer); if (screen->window) SDL_DestroyWindow(screen->window); @@ -33,7 +37,7 @@ void psxe_screen_reload(psxe_screen_t* screen) { SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, screen->width * screen->scale, screen->height * screen->scale, - SDL_WINDOW_OPENGL + SDL_WINDOW_OPENGL | SDL_WINDOW_ALLOW_HIGHDPI ); screen->renderer = SDL_CreateRenderer( @@ -49,6 +53,18 @@ void psxe_screen_reload(psxe_screen_t* screen) { PSX_GPU_FB_WIDTH, PSX_GPU_FB_HEIGHT ); + // Check for retina displays + int width = 0, height = 0; + + SDL_GetRendererOutputSize(screen->renderer, &width, &height); + + if (width != (screen->width * screen->scale)) { + float width_scale = (float)width / (float)(screen->width * screen->scale); + float height_scale = (float)height / (float)(screen->height * screen->scale); + + SDL_RenderSetScale(screen->renderer, width_scale, height_scale); + } + screen->open = 1; }