kbeckmann / PicoCart64

N64 development cart using a Raspberry Pi RP2040
BSD 2-Clause "Simplified" License
762 stars 43 forks source link

Problem with ROMs whose size isn't a multiple of 1024 bytes #56

Open michalderkacz opened 1 month ago

michalderkacz commented 1 month ago

The compression algorithm in the JS function generateAndSaveUF2 doesn't support the ROM size that isn't a multiple of 1024 bytes.

This is the likely cause of the problem with N64 240p test suite ROM that I reported before whose size is 6421760 bytes = 6271.25 KiB.

The generateAndSaveUF2 calculates the number of chunks as num_chunks = Math.floor(rom.fileSize / chunk_size) where chunk_size = 1024 so it doesn't handle the last incomplete chunk in any way.

michalderkacz commented 1 month ago

Another bug I found is using Uint16Array that produce native-endian byte stream. It's unlikely that someone will open the converter code on a big-endian machine but it's still a bug.

I'm translating your JS code to Go so such bugs easily reveal themselves.

kbeckmann commented 1 month ago

Thanks for finding the root cause. If you have the time to create a PR, I’d be happy to merge a fix in the repo https://github.com/kbeckmann/PicoCart64/tree/gh-pages

michalderkacz commented 1 month ago

I have a prototype but can't test it before evening. I'm not a JavaScript programmer so it may be not an optimal solution.