diff --git a/player/player.c b/player/player.c index c648a3e..f39bfd9 100644 --- a/player/player.c +++ b/player/player.c @@ -49,12 +49,10 @@ void display() { #include "pocketlib.h" static void display() { - // ???? VSync(VSYNC_COUNT); uint32_t *src = (uint32_t*)screen; volatile unsigned int *dst = LCD_VRAM_ADRS; - int i = 32; - while (i--) {*dst++ = *src++;} + for (int i=32; i--;) {*dst++ = *src++;} } uint8_t ROMByteAccess(unsigned char *addr) diff --git a/tools/Makefile b/tools/Makefile index e75de7c..3b4cae5 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -1,9 +1,11 @@ -all: ascii2sjis bin2mcs bmp2ps1b mcpad +all: ascii2sjis bin2mcs bmp2ps1b mcpad bmp_to_1bit ascii2sjis: ascii2sjis.c bin2mcs: bin2mcs.c bmp2ps1b: bmp2ps1b.c mcpad: mcpad.c +bmp_to_1bit: bmp_to_1bit.c clean: - rm -f ascii2sjis bin2mcs bmp2ps1b mcpad \ No newline at end of file + rm -f ascii2sjis bin2mcs bmp2ps1b mcpad bmp_to_1bit + rm -f ascii2sjis.exe bin2mcs.exe bmp2ps1b.exe mcpad.exe bmp_to_1bit.exe diff --git a/tools/ascii2sjis.exe b/tools/ascii2sjis.exe deleted file mode 100644 index 159444f..0000000 Binary files a/tools/ascii2sjis.exe and /dev/null differ diff --git a/tools/bin2mcs.exe b/tools/bin2mcs.exe deleted file mode 100644 index 74fb7dc..0000000 Binary files a/tools/bin2mcs.exe and /dev/null differ diff --git a/tools/bmp2ps1b.exe b/tools/bmp2ps1b.exe deleted file mode 100644 index f83c3d3..0000000 Binary files a/tools/bmp2ps1b.exe and /dev/null differ diff --git a/tools/bmp_to_1bit.c b/tools/bmp_to_1bit.c new file mode 100644 index 0000000..82274b3 --- /dev/null +++ b/tools/bmp_to_1bit.c @@ -0,0 +1,91 @@ +#include +#include +#include + +typedef struct __attribute__((__packed__)) BMPHeader { + uint16_t type; // Magic identifier: 0x4d42 + uint32_t size; // File size in bytes + uint16_t reserved1; // Not used + uint16_t reserved2; // Not used + uint32_t offset; // Offset to image data in bytes from beginning of file + uint32_t dib_header_size; // DIB Header size in bytes + int32_t width_px; // Width of the image + int32_t height_px; // Height of image + uint16_t num_planes; // Number of color planes + uint16_t bits_per_pixel; // Bits per pixel + uint32_t compression; // Compression type + uint32_t image_size_bytes; // Image size in bytes + int32_t x_resolution_ppm; // Pixels per meter + int32_t y_resolution_ppm; // Pixels per meter + uint32_t num_colors; // Number of colors + uint32_t important_colors; // Important colors +} BMPHeader; + + +int main (int argc, char* argv[]) +{ + FILE* in, *out; + if(argc < 3) { + printf("Usage: %s \n", argv[0]); + return 1; + } + + in = fopen(argv[1], "rb"); + if(!in) { + printf("Could not open input file.\n"); + return 1; + } + + out = fopen(argv[2], "wb"); + if(!out) { + printf("Could not open output file.\n"); + return 1; + } + + BMPHeader in_header = {0}; + fread(&in_header, sizeof(BMPHeader), 1, in); + + fseek(in, in_header.offset, SEEK_SET); + uint8_t* px = malloc(in_header.image_size_bytes); + fread(px, in_header.image_size_bytes, 1, in); + fclose(in); + + printf("%d x %d\n", in_header.width_px, in_header.height_px); + printf("bpp: %d\n", in_header.bits_per_pixel); + + uint8_t* out_buffer = malloc(32 * 32 / 8); + for(int out_y = 0; out_y < 32; out_y++) { + for(int out_x = 0; out_x < 32; out_x++) { + // input is bigger than output + // so we need to skip some pixels + int in_x = out_x * in_header.width_px / 32; + int in_y = out_y * in_header.height_px / 32; + int in_offset = (in_y * in_header.width_px + in_x) * 3; + uint8_t v = (px[in_offset + 2] + px[in_offset + 1] + px[in_offset + 0]) / 3; + int out_offset = out_y * 32 / 8 + out_x / 8; + if(v > 127) { + out_buffer[out_offset] |= 1 << (7 - out_x % 8); + } else { + out_buffer[out_offset] &= ~(1 << (7 - out_x % 8)); + } + } + } + free(px); + + BMPHeader out_header = {0}; + out_header.type = 0x4d42; + out_header.size = sizeof(BMPHeader) + 32 * 32 / 8; + out_header.offset = sizeof(BMPHeader); + out_header.dib_header_size = sizeof(BMPHeader) - 14; + out_header.width_px = 32; + out_header.height_px = 32; + out_header.bits_per_pixel = 1; + out_header.image_size_bytes = 32 * 32 / 8; + out_header.num_colors = 2; + out_header.important_colors = 2; + + fwrite(&out_header, sizeof(BMPHeader), 1, out); + fwrite(out_buffer, out_header.image_size_bytes, 1, out); + fclose(out); + free(out_buffer); +} diff --git a/tools/bmp_to_1bit.exe b/tools/bmp_to_1bit.exe deleted file mode 100644 index 4cded03..0000000 Binary files a/tools/bmp_to_1bit.exe and /dev/null differ diff --git a/tools/bmp_to_1bit.py b/tools/bmp_to_1bit.py deleted file mode 100755 index 280cc76..0000000 --- a/tools/bmp_to_1bit.py +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/python3 -import sys -from PIL import Image - -img = Image.open(sys.argv[1]) -img = img.convert("1", dither=Image.Dither.NONE) -img = img.resize((32,32), Image.Resampling.NEAREST) -img.save(sys.argv[2]) diff --git a/tools/mcpad.exe b/tools/mcpad.exe deleted file mode 100644 index 1c0d2d1..0000000 Binary files a/tools/mcpad.exe and /dev/null differ