Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
flyinghead committed Nov 20, 2023
2 parents bc28c7c + 78a874d commit a9d5b77
Show file tree
Hide file tree
Showing 25 changed files with 195 additions and 55 deletions.
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@ target_compile_definitions(${PROJECT_NAME} PRIVATE
$<$<BOOL:${WINDOWS_STORE}>:NOCRYPT>
$<$<OR:$<BOOL:${MINGW}>,$<BOOL:${MSVC}>>:_USE_MATH_DEFINES>)

if(UNIX AND NOT ANDROID AND NOT APPLE)
execute_process(COMMAND getconf PAGESIZE OUTPUT_VARIABLE PAGE_SIZE OUTPUT_STRIP_TRAILING_WHITESPACE)
target_compile_definitions(${PROJECT_NAME} PRIVATE PAGE_SIZE=${PAGE_SIZE})
endif()

if(NOT "${SENTRY_UPLOAD_URL}" STREQUAL "")
target_compile_definitions(${PROJECT_NAME} PRIVATE SENTRY_UPLOAD="${SENTRY_UPLOAD_URL}")
endif()
Expand Down Expand Up @@ -960,7 +965,8 @@ cmrc_add_resources(flycast-resources
resources/flash/dirtypig.nvmem2.zip
resources/flash/vf4.nvmem.zip # card all day, stage select
resources/flash/vf4evob.nvmem.zip # card all day, stage select
resources/flash/vf4tuned.nvmem.zip) # card all day, stage select, 45 sec time limit, 3 match
resources/flash/vf4tuned.nvmem.zip # card all day, stage select, 45 sec time limit, 3 match
resources/picture/f355_print_template.png)

cmrc_add_resources(flycast-resources
fonts/printer_ascii8x16.bin
Expand Down
7 changes: 4 additions & 3 deletions core/cfg/option.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ std::array<Option<int>, 4> CrosshairColor {
Option<int>("rend.CrossHairColor3"),
Option<int>("rend.CrossHairColor4"),
};
Option<int> CrosshairSize("rend.CrosshairSize", 40);
Option<int> SkipFrame("ta.skip");
Option<int> MaxThreads("pvr.MaxThreads", 3);
Option<int> AutoSkipFrame("pvr.AutoSkipFrame", 0);
Expand All @@ -108,9 +109,9 @@ Option<int> PerPixelLayers("rend.PerPixelLayers", 32);
Option<bool> NativeDepthInterpolation("rend.NativeDepthInterpolation", false);
Option<bool> EmulateFramebuffer("rend.EmulateFramebuffer", false);
#ifdef VIDEO_ROUTING
Option<bool> VideoRouting("rend.VideoRouting", false);
Option<bool> VideoRoutingScale("rend.VideoRoutingScale", false);
Option<int> VideoRoutingVRes("rend.VideoRoutingVRes", 720);
Option<bool, false> VideoRouting("rend.VideoRouting", false);
Option<bool, false> VideoRoutingScale("rend.VideoRoutingScale", false);
Option<int, false> VideoRoutingVRes("rend.VideoRoutingVRes", 720);
#endif

// Misc
Expand Down
7 changes: 4 additions & 3 deletions core/cfg/option.h
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ extern Option<bool> PerStripSorting;
extern Option<bool> DelayFrameSwapping; // Delay swapping frame until FB_R_SOF matches FB_W_SOF
extern Option<bool> WidescreenGameHacks;
extern std::array<Option<int>, 4> CrosshairColor;
extern Option<int> CrosshairSize;
extern Option<int> SkipFrame;
extern Option<int> MaxThreads;
extern Option<int> AutoSkipFrame; // 0: none, 1: some, 2: more
Expand All @@ -474,9 +475,9 @@ extern Option<bool> DupeFrames;
extern Option<bool> NativeDepthInterpolation;
extern Option<bool> EmulateFramebuffer;
#ifdef VIDEO_ROUTING
extern Option<bool> VideoRouting;
extern Option<bool> VideoRoutingScale;
extern Option<int> VideoRoutingVRes;
extern Option<bool, false> VideoRouting;
extern Option<bool, false> VideoRoutingScale;
extern Option<int, false> VideoRoutingVRes;
#endif

// Misc
Expand Down
2 changes: 1 addition & 1 deletion core/hw/naomi/naomi_cart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ void naomi_cart_LoadRom(const std::string& path, const std::string& fileName, Lo
}
if (gameId == " TOUCH DE UNOH -------------"
|| gameId == " TOUCH DE UNOH 2 -----------"
|| (gameId == "F355 CHALLENGE JAPAN" && config::MultiboardSlaves == 2))
|| (gameId == "F355 CHALLENGE JAPAN" && (config::MultiboardSlaves == 2 || romName == "f355")))
{
printer::init();
}
Expand Down
12 changes: 6 additions & 6 deletions core/hw/naomi/naomi_flashrom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ void write_naomi_eeprom(u32 offset, u8 value)
WARN_LOG(NAOMI, "EEPROM record doesn't exist or is too short");
}

static u8 readEeprom(u32 offset)
u8 read_naomi_eeprom(u32 offset)
{
return EEPROM[offset & 127];
}
Expand Down Expand Up @@ -164,7 +164,7 @@ static bool initEeprom(const RomBootID *bootId)
// ROM-specific defaults
write_naomi_eeprom(2, bootId->coinFlag[0][1] | (((bootId->coinFlag[0][1] & 2) ^ 2) << 3));
if (bootId->coinFlag[0][2] == 1) // individual coin chute
write_naomi_eeprom(8, readEeprom(8) | 1);
write_naomi_eeprom(8, read_naomi_eeprom(8) | 1);
write_naomi_eeprom(9, bootId->coinFlag[0][3] - 1);
write_naomi_eeprom(10, std::max(bootId->coinFlag[0][6], (u8)1));
write_naomi_eeprom(11, std::max(bootId->coinFlag[0][4], (u8)1));
Expand Down Expand Up @@ -199,21 +199,21 @@ void configure_naomi_eeprom(const RomBootID *bootId)
if (bootId->vertical == 2)
{
NOTICE_LOG(NAOMI, "EEPROM: vertical monitor orientation");
write_naomi_eeprom(2, readEeprom(2) | 1);
write_naomi_eeprom(2, read_naomi_eeprom(2) | 1);
config::Rotate90.override(true);
}
else if (bootId->vertical == 1)
{
NOTICE_LOG(NAOMI, "EEPROM: horizontal monitor orientation");
write_naomi_eeprom(2, readEeprom(2) & ~1);
write_naomi_eeprom(2, read_naomi_eeprom(2) & ~1);
}
// Number of players
if (bootId->cabinet != 0 && bootId->cabinet < 0x10)
{
int nPlayers = readEeprom(8) >> 4; // 0 to 3
int nPlayers = read_naomi_eeprom(8) >> 4; // 0 to 3
if (!(bootId->cabinet & (1 << nPlayers)))
{
u8 coinChute = readEeprom(8) & 1;
u8 coinChute = read_naomi_eeprom(8) & 1;
if (bootId->cabinet & 8)
{
NOTICE_LOG(NAOMI, "EEPROM: 4-player cabinet");
Expand Down
1 change: 1 addition & 0 deletions core/hw/naomi/naomi_flashrom.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "naomi_cart.h"

void write_naomi_flash(u32 addr, u8 value);
u8 read_naomi_eeprom(u32 offset);
void write_naomi_eeprom(u32 offset, u8 value);
void configure_naomi_eeprom(const RomBootID *bootId);
void configure_maxspeed_flash(bool enableNetwork, bool master);
70 changes: 69 additions & 1 deletion core/hw/naomi/printer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,19 @@
#include <memory>
#include <vector>
#ifdef STANDALONE_TEST
#define STB_IMAGE_IMPLEMENTATION
#define STB_IMAGE_WRITE_IMPLEMENTATION
#undef INFO_LOG
#define INFO_LOG(t, s, ...) printf(s "\n", __VA_ARGS__)
#undef NOTICE_LOG
#define NOTICE_LOG INFO_LOG
#undef ERROR_LOG
#define ERROR_LOG INFO_LOG
#else
#include <cmrc/cmrc.hpp>
CMRC_DECLARE(flycast);
#endif
#include <stb/stb_image.h>
#include <stb/stb_image_write.h>

namespace printer
Expand Down Expand Up @@ -311,6 +317,59 @@ class BitmapWriter
{
if (page.empty())
return false;
if (settings.content.gameId.substr(0, 4) == "F355")
{
u8 *data = nullptr;
int x, y, comp;
#ifndef STANDALONE_TEST
try {
cmrc::embedded_filesystem fs = cmrc::flycast::get_filesystem();
cmrc::file templateFile = fs.open("picture/f355_print_template.png");
const u8 *fileData = (const u8 *)templateFile.begin();
data = stbi_load_from_memory(fileData, templateFile.size(), &x, &y, &comp, STBI_rgb_alpha);
} catch (const std::system_error& e) {
ERROR_LOG(NAOMI, "Failed to load the printer template: %s", e.what());
}
#else
FILE *f = fopen("f355_print_template.png", "rb");
if (f != nullptr)
{
data = stbi_load_from_file(f, &x, &y, &comp, STBI_rgb_alpha);
fclose(f);
}
else
fprintf(stderr, "Can't open template file %d\n", errno);
#endif
if (data != nullptr && (x != printerWidth || comp != STBI_rgb_alpha))
{
ERROR_LOG(NAOMI, "Invalid printer template: width %d comp %d", x, comp);
stbi_image_free(data);
data = nullptr;
}
if (data != nullptr)
{
if (lines > y)
{
u8 *newData = (u8 *)malloc(printerWidth * 4 * lines);
const u8 *end = newData + printerWidth * 4 * lines;
for (u8 *p = newData; p < end; p += printerWidth * 4 * y)
memcpy(p, data, std::min(printerWidth * 4 * y, (int)(end - p)));
stbi_image_free(data);
data = newData;
}
u32 *p = (u32 *)data;
for (u8 b : page)
{
if (b == 0xff)
*p = 0xff000000;
p++;
}
stbi_write_png(filename.c_str(), printerWidth, lines, 4, data, printerWidth * 4);
stbi_image_free(data);

return true;
}
}
for (u8& b : page)
b = 0xff - b;
stbi_write_png(filename.c_str(), printerWidth, lines, 1, &page[0], printerWidth);
Expand Down Expand Up @@ -744,6 +803,7 @@ class ThermalPrinter
bitmapWriter.reset();
s = "Print out saved to " + s;
gui_display_notification(s.c_str(), 5000);
NOTICE_LOG(NAOMI, "%s", s.c_str());
}
break;
case 'K': // Set Kanji mode
Expand Down Expand Up @@ -1084,6 +1144,14 @@ void deserialize(Deserializer& deser)
#ifdef STANDALONE_TEST
settings_t settings;

std::string get_writable_data_path(const std::string& s)
{
return "./" + s;
}

void gui_display_notification(char const*, int) {
}

int main(int argc, char *argv[])
{
if (argc < 2)
Expand All @@ -1093,7 +1161,7 @@ int main(int argc, char *argv[])
perror(argv[1]);
return 1;
}
settings.content.gameId = "somegame";
settings.content.gameId = "F355 CHALLENGE";
printer::ThermalPrinter printer;
for (;;)
{
Expand Down
14 changes: 9 additions & 5 deletions core/network/naomi_network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,27 +350,28 @@ void SetNaomiNetworkConfig(int node)
write_naomi_flash(0x224, node == -1 ? 0 : 1); // network on
write_naomi_flash(0x220, node == 0 ? 0 : 1); // node id
}
else if (gameId == "CLUB KART IN JAPAN")
else if (gameId == "CLUB KART IN JAPAN" && settings.content.fileName.substr(0, 6) != "clubkp")
{
write_naomi_eeprom(0x34, node + 1); // also 03 = satellite
}
else if (gameId == "INITIAL D"
|| gameId == "INITIAL D Ver.2"
|| gameId == "INITIAL D Ver.3")
{
write_naomi_eeprom(0x34, node == -1 ? 0x02 : node == 0 ? 0x12 : 0x22);
u8 b = read_naomi_eeprom(0x34) & 0xcf;
write_naomi_eeprom(0x34, (node == -1 ? 0x00 : node == 0 ? 0x10 : 0x20) | b);
}
else if (gameId == "THE KING OF ROUTE66")
{
write_naomi_eeprom(0x3d, node == -1 ? 0x44 : node == 0 ? 0x54 : 0x64);
u8 b = read_naomi_eeprom(0x3d) & 0xf;
write_naomi_eeprom(0x3d, (node == -1 ? 0x40 : node == 0 ? 0x50 : 0x60) | b);
}
else if (gameId == "MAXIMUM SPEED")
{
configure_maxspeed_flash(node != -1, node == 0);
}
else if (gameId == "F355 CHALLENGE JAPAN")
else if (gameId == "F355 CHALLENGE JAPAN" && settings.content.fileName != "f355")
{
// FIXME need default flash
write_naomi_flash(0x230, node == -1 ? 0 : node == 0 ? 1 : 2);
if (node != -1)
// car number (0 to 7)
Expand All @@ -393,6 +394,9 @@ bool NaomiNetworkSupported()
};
if (!config::NetworkEnable)
return false;
if (settings.content.fileName.substr(0, 6) == "clubkp" || settings.content.fileName == "f355")
// Club Kart Prize and F355 (vanilla) don't support networking
return false;
for (auto game : games)
if (settings.content.gameId == game)
return true;
Expand Down
11 changes: 7 additions & 4 deletions core/rend/dx11/dx11_overlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,17 @@ void DX11Overlay::draw(u32 width, u32 height, bool vmu, bool crosshair)
deviceContext->RSSetScissorRects(1, &rect);
if (vmu)
{
#ifndef LIBRETRO
float vmu_padding = 8.f * settings.display.uiScale;
float vmu_height = 70.f * settings.display.uiScale;
float vmu_width = 48.f / 32.f * vmu_height;

#ifndef LIBRETRO
const float blend_factor[4] = { 0.75f, 0.75f, 0.75f, 0.75f };
deviceContext->OMSetBlendState(blendStates.getState(true, 8, 8), blend_factor, 0xffffffff);
#else
float vmu_padding = 8.f * config::RenderResolution / 480.f;
float vmu_height = 32.f * config::RenderResolution / 480.f;
float vmu_width = 48.f * config::RenderResolution / 480.f;
deviceContext->OMSetBlendState(blendStates.getState(true, 4, 5), nullptr, 0xffffffff);
#endif

Expand Down Expand Up @@ -169,11 +172,11 @@ void DX11Overlay::draw(u32 width, u32 height, bool vmu, bool crosshair)

auto [x, y] = getCrosshairPosition(i);
#ifdef LIBRETRO
float halfWidth = LIGHTGUN_CROSSHAIR_SIZE / 2.f / config::ScreenStretching * 100.f;
float halfHeight = LIGHTGUN_CROSSHAIR_SIZE / 2.f;
float halfWidth = lightgun_crosshair_size / 2.f / config::ScreenStretching * 100.f * config::RenderResolution / 480.f;
float halfHeight = lightgun_crosshair_size / 2.f * config::RenderResolution / 480.f;
x /= config::ScreenStretching / 100.f;
#else
float halfWidth = XHAIR_WIDTH * settings.display.uiScale / 2.f;
float halfWidth = config::CrosshairSize * settings.display.uiScale / 2.f;
float halfHeight = halfWidth;
#endif
D3D11_VIEWPORT vp{};
Expand Down
2 changes: 1 addition & 1 deletion core/rend/dx9/d3d_overlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ void D3DOverlay::draw(u32 width, u32 height, bool vmu, bool crosshair)
continue;

auto [x, y] = getCrosshairPosition(i);
float halfWidth = XHAIR_WIDTH * settings.display.uiScale / 2.f;
float halfWidth = config::CrosshairSize * settings.display.uiScale / 2.f;
RECT rect { (long) (x - halfWidth), (long) (y - halfWidth), (long) (x + halfWidth), (long) (y + halfWidth) };
D3DCOLOR color = (config::CrosshairColor[i] & 0xFF00FF00)
| ((config::CrosshairColor[i] >> 16) & 0xFF)
Expand Down
12 changes: 9 additions & 3 deletions core/rend/dx9/d3d_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ void D3DRenderer::setBaseScissor()
}
}

void D3DRenderer::prepareRttRenderTarget(u32 texAddress)
void D3DRenderer::prepareRttRenderTarget(u32 texAddress, int& vpWidth, int& vpHeight)
{
u32 fbw = pvrrc.getFramebufferWidth();
u32 fbh = pvrrc.getFramebufferHeight();
Expand Down Expand Up @@ -916,6 +916,8 @@ void D3DRenderer::prepareRttRenderTarget(u32 texAddress)
viewport.MinZ = 0;
viewport.MaxZ = 1;
device->SetViewport(&viewport);
vpWidth = fbw;
vpHeight = fbh;
}

void D3DRenderer::readRttRenderTarget(u32 texAddress)
Expand Down Expand Up @@ -982,9 +984,10 @@ bool D3DRenderer::Render()
bool rc = SUCCEEDED(device->GetRenderTarget(0, &backbuffer.get()));
verify(rc);
u32 texAddress = pvrrc.fb_W_SOF1 & VRAM_MASK;
int vpWidth, vpHeight;
if (is_rtt)
{
prepareRttRenderTarget(texAddress);
prepareRttRenderTarget(texAddress, vpWidth, vpHeight);
}
else
{
Expand All @@ -1001,13 +1004,15 @@ bool D3DRenderer::Render()
viewport.MaxZ = 1;
rc = SUCCEEDED(device->SetViewport(&viewport));
verify(rc);
vpWidth = width;
vpHeight = height;
}
rc = SUCCEEDED(device->SetDepthStencilSurface(depthSurface));
verify(rc);
matrices.CalcMatrices(&pvrrc, width, height);
// infamous DX9 half-pixel viewport shift
// https://docs.microsoft.com/en-us/windows/win32/direct3d9/directly-mapping-texels-to-pixels
glm::mat4 normalMat = glm::translate(glm::vec3(-1.f / width, 1.f / height, 0)) * matrices.GetNormalMatrix();
glm::mat4 normalMat = glm::translate(glm::vec3(1.f / vpWidth, 1.f / vpHeight, 0)) * matrices.GetNormalMatrix();
rc = SUCCEEDED(device->SetVertexShaderConstantF(0, &normalMat[0][0], 4));
verify(rc);

Expand Down Expand Up @@ -1124,6 +1129,7 @@ bool D3DRenderer::Render()
devCache.SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);

devCache.SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
devCache.SetRenderState(D3DRS_SEPARATEALPHABLENDENABLE, FALSE);
devCache.SetRenderState(D3DRS_ALPHATESTENABLE, FALSE);
devCache.SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);
devCache.SetRenderState(D3DRS_CLIPPING, FALSE);
Expand Down
2 changes: 1 addition & 1 deletion core/rend/dx9/d3d_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ struct D3DRenderer : public Renderer
void drawModVols(int first, int count);
void setTexMode(D3DSAMPLERSTATETYPE state, u32 clamp, u32 mirror);
void setBaseScissor();
void prepareRttRenderTarget(u32 texAddress);
void prepareRttRenderTarget(u32 texAddress, int& vpWidth, int& vpHeight);
void readRttRenderTarget(u32 texAddress);
void writeFramebufferToVRAM();

Expand Down
Loading

0 comments on commit a9d5b77

Please sign in to comment.