wader / fq

jq for binary formats - tool, language and decoders for working with binary and text formats
Other
9.54k stars 218 forks source link

nes: Add support for iNES/NES 2.0 ROM files #893

Closed mlofjard closed 3 months ago

mlofjard commented 3 months ago

This one has some "fun" stuff, like a toasm function for generating asm code, and tokitty for displaying graphics tiles in compatible terminals.

wader commented 3 months ago

Thanks! Had a quick skimthru, overall good i think. Will look closer tonight or later in the week. One thing is the toasm/tokitty functions, maybe some kind of name spacing would be good to to know they are nes format related? or possible move them to documentation?

wader commented 3 months ago

Noticed some possible fishy thing in format/nes/testdata/nestest.fqtest some text gets decode as op codes?

Screenshot 2024-03-11 at 18 10 06
mlofjard commented 3 months ago

Noticed some possible fishy thing in format/nes/testdata/nestest.fqtest some text gets decode as op codes?

Yup, that can happen. Since the PRG ROM is in fixed 16KiB blocks, it's very unlikely that all the data in it is actual code. And since the op code table contains all 256 entries (with the unofficial op codes) I have no way of knowing if a byte is an actual op code, added strings or random memory "junk" =) I wrote a note about it in the limitations section of the docs.

mlofjard commented 3 months ago

Thanks! Had a quick skimthru, overall good i think. Will look closer tonight or later in the week. One thing is the toasm/tokitty functions, maybe some kind of name spacing would be good to to know they are nes format related? or possible move them to documentation?

Since they live in the nes.jq file, are they not scoped implicitely?

wader commented 3 months ago

Thanks! Had a quick skimthru, overall good i think. Will look closer tonight or later in the week. One thing is the toasm/tokitty functions, maybe some kind of name spacing would be good to to know they are nes format related? or possible move them to documentation?

Since they live in the nes.jq file, are they not scoped implicitely?

All format *.jq files will be included globally no matter format being decoded atm. There is hacky way to have functions that will be overloaded based on input format https://github.com/wader/fq/blob/master/format/bson/bson.go#L24 but not sure it make sense in this case?

mlofjard commented 3 months ago

Thanks! Had a quick skimthru, overall good i think. Will look closer tonight or later in the week. One thing is the toasm/tokitty functions, maybe some kind of name spacing would be good to to know they are nes format related? or possible move them to documentation?

Since they live in the nes.jq file, are they not scoped implicitely?

All format *.jq files will be included globally no matter format being decoded atm. There is hacky way to have functions that will be overloaded based on input format https://github.com/wader/fq/blob/master/format/bson/bson.go#L24 but not sure it make sense in this case?

Ah ok, then I get it. Do you think to_nes_asm and to_nes_kitty would suffice our should I be more specific? from_nes_prg_to_asm?

wader commented 3 months ago

Maybe rename the test files after function name change?

Had some tiny comment but otherwise looks good it think

mlofjard commented 3 months ago

I found some more fun endianness bugs that I need to sort out (and create tests for), so there might not be any more commits before the weekend..

wader commented 3 months ago

I found some more fun endianness bugs that I need to sort out (and create tests for), so there might not be any more commits before the weekend..

Aha, no stress! will spend some time on trains this weekend so maybe will get some quality time with fq :)

mlofjard commented 3 months ago

Looks good! let me know if your ready

I've rebased on current master and squashed all my fixups, so I'm fine with merging as soon as CI is done.

wader commented 3 months ago

Thanks!

Any other decoders in the works? i should really try finish up some decoders i have laying around

mlofjard commented 3 months ago

Thanks!

Any other decoders in the works? i should really try finish up some decoders i have laying around

Thank you as well. It's a fun project to contribute to.

I'm not sure what's next. I might look into some other ROM formats, like SNES or GB, in the future. But I'm also interested in what goes inside an EDID binary, since I had to patch mine to get 120Hz refresh rate working on my laptop. =)

wader commented 3 months ago

Thanks! Any other decoders in the works? i should really try finish up some decoders i have laying around

Thank you as well. It's a fun project to contribute to.

🥳

I'm not sure what's next. I might look into some other ROM formats, like SNES or GB, in the future. But I'm also interested in what goes inside an EDID binary, since I had to patch mine to get 120Hz refresh rate working on my laptop. =)

Nice! GB bring back memories, i wrote a gameboy emulator many years ago https://github.com/wader/maggie :)

EDID looks like it would be quite straight forward, little logic but lots of mapping!