It seems the Arduino IDE picks the position of the first definition to
insert all auto-generated forward declarations. This fails to compile if
any of these generated forward declarations references a type included
later.
So, reorder the code a bit so the first definition happens strictly after
the last inclusion.
This code was removed as part of
a555f21 ("All: Resolve all compiler and linker warnings")
because it was filling a 1kB buffer which was never read from.
While I expect reading values from PINC should be invisible from the
cartridge's perspective, writing to PORTL, PORTF and PORTK is definitely
visible.
I have currently no way of testing if this code is required, so in doubt
restore the parts which have effects visible from the cartridge.
I am not sure why I changed some variables from 16 bit types to 8 bit types
when the warnings being resolved were only about signedness.
Fixes: a555f21 ("All: Resolve all compiler and linker warnings")
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.
Also, this resolves a warning about `count` being potentially used
uninitialised: when landing in the "Too many files" codepath.
With this simplification, the limit on the number of files is removed. It
is unclear whether that was intentional (maybe this was gating other
issues ?)?
Values can be directly composed/initialised in menuOptionspceCart, avoiding
the need to strcpy to it.
This saves about 100 bytes of ram by dropping a few global char arrays.
Re-duplicates "Reset" string initialiser, but this should not be a big
deal.
flashid (almost) always contains the hexadecimal representation of two
bytes, which then means it gets compares with strcmp, which in turn need
another string argument. Instead, make it an integer, removing the need to
call strcmp.
Add a separate string representation for printing purposes (maybe this can be
avoided by having the print function format it when needed ?).
The only apparent case where flashid is not an hexadecimal representation
of a pair of bytes is when N64 clears it to "CONF". Set flashid to zero
this case.
This saves about 500 bytes of program space and 200 bytes of ram.
The header offsets were wrong so the size wasn't correctly computed and generally ended up defaulting to 32KB. Stunt Race FX, at least, uses 64KB and so only half the save data was being read.