Also, make print_FatalError(*) independent from print_Error(*).
Also, factorise common parts of print_Error(*).
Frees 2336 bytes of program space and 5 bytes of global ram space.
IMPORTANT: with this change, the Adafruit clock generator becomes a hard
requirement to read and write gamecart eeproms.
This is a large patch, partly because JoyBus is used a lot:
- controller
- controller pak
- gamecart eeprom
and partly because of the further simplifications it allows.
Also, implement low-level bit shift functions in assembly in order to get
complete control of the timings: there can be just a few cycles of slack.
Also, use the time waiting for the input line to go high to pack received
bits into bytes on-the-fly, as there is now plenty of time.
This saves about 2080 bytes of program space, and 369 bytes of global ram
space.
More sizeof() use, avoiding high-level loops when a callee can do it
without the call overhead on every iteration, a bit of source code
factorisation, avoiding initializers for large variables.
These variables are set but never read. Removing them removes a non-trivial
amount of code, which I am not comfortable deleting: it contains knowledge
about cart data structure, even though it is currently not being used for
anything. So comment it out until someone who know this architecture better
comes around.
Frees 146 bytes of program space and 16 bytes of global ram space.
Also, remove dead error handling code: sd.exists internally opens the file
and returns the produced status, so myFile.open return value should be the
same.
Tagged with noreturn so the compiler knows about the effect of
forceReset=true.
Ideally, print_Error should lose its forceReset argument so that:
- print_Error never resets
- print_FatalError always resets (and hosts the code doing so)
so the compiler is more accurately aware of the execution flow.
Also, bypass sdBuffer when it was the directory copied to another buffer.
Also, factorise yet another pair of loops copying rom name.
This frees 59 bytes of global ram space.
Mainly, this removes a lot of the logic from selectMapping by reusing the
copy already present in getMapping. As a result, selectMapping is not
expected to be accessed from outside this module anymore.
Also, this factorises several smaller chunks of code found throughout the
module.
Also, get rid of a few easy globals along the way.
Also, move a bit more of NES-specific initialisation and menu display to
the NES.ino module.
This saves about 1490 bytes of code.
Replace switch blocks which produce one output with const tables.
Use functions instead of repeating code.
Move common initial and final statements outside of blocks.
Also, do not erase/flash second bank on dual-bank chips when the first one
had failures.
This saves about 520 bytes of code and increases ram use by 12 bytes.
It seems crc32EEP only exists because the actual number of bytes read from
file were not checked, hence falling back to smaller reads.
Instead, always read up to the full available buffer, adding to the CRC
only as many bytes as were actually read.
Also, move some related variables to local scope.
Overall, this saves about 50 bytes of code and 80 bytes of global ram.
In this codepath, there will be a second call just after displaying the
CRC, making this call redundant.
For completeness: In the alternate codepath, the next operation does a lot
of IO, so it makes sense to refresh the screen before printing the CRC.
This avoids code duplication between it and
convertPgm(const char* const [], byte)
for just 3 callers, when the callers can be easily updated to call the
latter.