-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rewrite RGBFIX in Rust #2
base: master
Are you sure you want to change the base?
Conversation
This script should help: head -c 336 < /dev/urandom > random.gb
cp random.gb fixed.gb
rgbfix $* fixed.gb
xxd random.gb > random.txt
xxd fixed.gb > fixed.txt
diff random.txt fixed.txt
rm -f random.gb fixed.gb random.txt fixed.txt Invoke as: sh script.sh <rgbfix flags> |
Thank you! This works perfectly and confirms to me that the file is indeed getting edited, and that the padding flag works. I will be using this for further testing. |
src/fix/main.rs
Outdated
} | ||
|
||
Ok(nb_errors == 0) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sure your files end with an "empty" line—this way each line is newline-delimited.
huge MbcType refactor (eievui5)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much for this PR! The code quality seems quite good.
I haven't reviewed everything yet, only wrote some of my more major feedback.
testfix.sh
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you tried using test/fix/test.sh
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have obtained the test/fix
directory but am encountering some problems.
What I did:
- In test.sh, changed the RGBFIX variable to "cargo run --bin rgbfix" instead of "./rgbfix"
- Deleted:
cp ../../{rgbfix,contrib/gbdiff.bash} "$tmpdir"
cd "$tmpdir" || exit
# Immediate expansion is the desired behavior.
# shellcheck disable=SC2064
trap "cd; rm -rf ${tmpdir@Q}" EXIT
And manually brought gbdiff.bash
into the directory instead.
The problem:
This causes an output of a massive wall of mismatches and errors. Here is one selected at random:
tpp1-bad-minor.err piped mismatch!
test.sh: 60: our_rc: not found
test.sh: 60: 127: not found
test.sh: 61: [[: not found
test.sh: 66: rc: not found
test.sh: 66: our_rc: not found
test.sh: 67: [[: not found
test.sh: 38: tests++: not found
test.sh: 40: [[: not found
test.sh: 43: [[: not found
--- /home/limace/Bureau/rsgbds/gb_testing/rgbds/test/fix/tpp1-nonjap.err 2024-04-17 16:15:52.330842019 -0400
+++ - 2024-04-17 16:18:45.421775740 -0400
@@ -1,5 +1,7 @@
-warning: TPP1 overwrites region flag for its identification code, ignoring `-j`
-warning: Overwrote a non-zero byte in the cartridge type
-warning: Overwrote a non-zero byte in the TPP1 identification code
-warning: Overwrote a non-zero byte in the TPP1 revision number
-warning: Overwrote a non-zero byte in the TPP1 feature flags
+error: unexpected argument '-m' found
+
+ tip: to pass '-m' as a value, use '-- -m'
+
+Usage: cargo run [OPTIONS] [args]...
+
+For more information, try '--help'.
As you can see, the strangest thing about this is how it complains about not finding variables like "our_rc" even though they are in scope.
I only spent 30 minutes so far trying to understand this issue, so it is possible I am missing something obvious here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would advise transplanting the generated binary into the RGBDS directory instead, as that should be overall less finicky? But if you got something that works regardless, then great.
I don't understand the sh errors, they kind of look like the test script is invoked with sh
instead of bash
. Are you invoking it as ./test.sh
?
As for the mismatches, you're missing the suggested --
after --bin rgbfix
;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand the sh errors, they kind of look like the test script is invoked with sh instead of bash
Correct, that was the mistake! Thank you kindly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By the way, I would like rsgbds to pass RGBDS' test suite unaltered (save for the different error reporting, of course—which may require some tweaks to the test harness as well). Thus this file wouldn't be of much use.
(The plan is to move the tests to cargo test
afterwards, but that will be somewhat involved.)
tracing = "0.1.40" | ||
tracing-subscriber = "0.3.18" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're already pulling in codespan-reporting
as an error reporting crate, I'd like all of RGBDS to be consistent about it.
(Preferably, all programs would pull in a common module, but I'm fine with the PR duplicating work for the sake of simplicity; I can perform the deduplication refactoring myself afterwards.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. This change was Evie's pick, and she said she thinks codespans should not be used for error reporting, but I understand the need for consistency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I agree it's arguably abuse of the crate... but I also think consistency, being user-facing, trumps that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For what it's worth, I have pushed a commit that switches the diagnostics backend to ariadne
. It should have a much more practical API than codespan_reporting
for rgbfix.
I can explain how it works: RGBFIX has two ways of working,
This should be able to be emulated in some way. I'm considering something like enum InOut {
File(File),
Stdio,
} (...feel free to come up with a better name >_>) And then you can |
Turns out the |
This is an introductory project for me as a way to familiarize myself with the port of a lower level C++ program into Rust. I have 4 months of Rust experience, please do not expect senior-level quality.
How it works
Flags and arguments are taken in using clap's derive feature, editing a CLIOptions struct with all relevant data. The filename is sent to process_filename, which reads the file and sends it to process_file.
Then, each if statement checks if a relevant flag/argument was provided by the user using "if let Some" syntax, and overwrites bytes in the .gb file if necessary.
Questions & Weird Things
TODOs