Skip to content

Commit

Permalink
naomi: use background template for f355 printing
Browse files Browse the repository at this point in the history
template courtesy of Ciopy Burns
  • Loading branch information
flyinghead committed Nov 10, 2023
1 parent f0f2755 commit e60f30b
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,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
52 changes: 51 additions & 1 deletion core/hw/naomi/printer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@
#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(t, s, ...) printf(s "\n", __VA_ARGS__)
#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 +315,44 @@ 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("../resources/picture/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)
{
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 @@ -1085,6 +1127,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 @@ -1094,7 +1144,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
Binary file added resources/picture/f355_print_template.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e60f30b

Please sign in to comment.