Commit Graph

166 Commits

Author SHA1 Message Date
Lephe 0498344349
periodic check of SH3 compatibility 2020-05-31 22:26:30 +02:00
Lephe 50cc536324
libc: add random number generation with TinyMT
TinyMT is licensed under its own terms. See src/std/tinymt/LICENSE.txt.
2020-05-31 17:03:14 +02:00
Lephe 5ff1662e61
bfile: solve stability issues on fx9860g and fxcg50
This commit improves the stability of gint_switch() in two ways:

1. Wait for hardware availability every time driver contexts are saved
   or reloaded; this solves crashes due to DMA use when gint takes
   control after a BFile call, since BFile_Create() (and possibly
   BFile_Write()) leave the DMA running after returning.

2. Remap the add-in after a switch, as apparently calling BFile
   functions causes some pages to be evicted. This is more noticeable on
   fxcg50 when the size of add-ins nears 220k.

Additionally, dma_transfer_wait() has been updated to not sleep() unless
it is certain that the conditions for wakeup are fulfilled, as this
would sometimes freeze.
2020-05-31 15:52:00 +02:00
Lephe 14e59690a5
update README to clean up mkg3a reference and link 2020-05-21 10:41:35 +02:00
Lephe 4036a583df
bfile: add BFile syscalls on fx-CG 50 (still unstable)
For some reason these syscalls tend to crash in a basic delete, create,
open, write, close workflow (after the write is finished). I'll look
into using the new gint/fxlib switch to use them safely.
2020-05-16 17:11:55 +02:00
Lephe 15dd4990dd
core: add return-to-menu on Graph 90+E (looks bad though)
This is a first version of gint_osmenu() on Graph 90+E. It works on the
same basis as the mono version, with the caveat that the automatic VRAM
display done by the system is terrible because of the reduced resolution
and status bar. Disabling any of this requires taking back control
earlier, which would make the whole GetKeyWait() method obsolete.

Tried the special key processing syscall, but it crashes upon return in
the add-in even before the fxlib code finishes. Maybe try later.
2020-05-16 12:14:13 +02:00
Lephe e217309adf
render-cg: expose vram buffers with dgetvram() and dsetvram() 2020-05-10 23:03:02 +02:00
Lephe d3c43c3ecd
dma: do not wait before initialization
Hangs if the add-in is started first on a fresh boot, probably because
the OS doesn't bother initializing all the channels of its hardware.
2020-05-10 23:00:42 +02:00
Lephe 85311a0b31
drivers: update the model, replacing unload() with wait()
The unload() function is not very relevant for drivers because hardware
state is managed by ctx_save() and ctx_restore() and software state is
managed by underlying drivers when there are dependencies.

For now, it's been replaced with a wait() function that allows drivers
to not be interrupted at any point. It is currently used by the DMA to
wait for ongoing transfers to finish before disabling interrupts (which
would prevent the transfer end from being detected) and switching in and
out of gint.
2020-05-10 16:36:21 +02:00
Lephe 4485e7f865
core, tmu: add gint_switch(), return to menu, and improve timer code
* Add the gint_switch() function which executes user-provided code from
  the system (CASIOWIN) context.
* Added interrupt masks to the core context (should have been there long
  ago).
* Added the gint_osmenu() function that switches out of gint to invoke
  GetKeyWait() and inject KEY_CTRL_MENU to trigger the main menu. This
  uses many CASIOWIN syscalls, but we don't care because gint is unloaded.
  Trickery is used to catch the key following the return in the add-in
  and/or display a new application frame before GetKeyWait() even finishes
  after coming back. This is only available on fx9860g for now.
* Removed any public syscall definition to clear up interfaces.
* Patched the DMA interruption problem in a weird way on fxcg50, a
  driver function will be used to do that properly eventually.
* Changed the driver model to save driver contexts in preallocated
  spaces instead of on the stack for overall less risk.
* Enabled return-to-menu with the MENU key on fx9860g in getkey().
* Changed the keyboard driver to emit releases before presses, as a
  return-to-menu acts as a press+release of different keys in a single
  driver frame, which confuses getkey().
* Fixed a really stupid bug in memcpy() that made the function really
  not work.

Improvements in the timer driver:

* Expose ETMU modules as SH7705_TMU and SH7305_TMU in <gint/mpu/tmu.h>.
* Remove the timer_t structures, using SH*_ETMU and SH*_TMU instead.
  Only interrupt gate entries are left hardcoded.
* Discovered that not only every write to the TCNT or TCR of an ETMU
  takes about 1/32k of a second (hinting at registers being powered by
  the same clock as the timer), but every write occuring while a previous
  write is pending is *lost*. This led to terrible bugs when switching
  ETMU contexts too fast in gint_switch().
* Removed an internal timer_address() function.
* Overall simplified the handling of timers and the initialization step.
2020-05-10 14:03:41 +02:00
Lephe 2cdf925f94
interrupts: save caller-saved registers in main handler
This is an obvious requirement for the interrupt routine, which was
forgotten and only surfaced when I used a timer callback started with
multiplications in an innocent add-in. r0..r7 are saved automatically,
which leaves pr, gbr, mach et macl susceptible to corruption by the
interrupt handler.
2020-05-06 20:45:35 +02:00
Lephe 61da7debc8
code review and display driver changes
t6k11: use the gint array for variant detection
r61524: use true triple buffering by default
display: define DWIDTH and DHEIGHT
display: add C_RGB(r,g,b) (0 ≤ r,g,b ≤ 31) [fxcg50]
2020-02-23 16:05:25 +01:00
Lephe b6f545e63c
getkey: gracefully take command after other keyboard primitives 2020-02-20 21:09:39 +01:00
Lephe d655aa934f
core: slightly better integration of BFile calls 2020-02-19 23:09:06 +01:00
Alice 32aef78600 core: add BFile_FindFirst, Next and Close syscalls
The return code -1 noted in the BFile_FindFirst or BFile_FindNext is
from test,  which mean it could be possibles that they are negative
error code from functions failing and not meaning that no file have been
found, to be sure, the value IML_FILEERR_ENUMERATEEND from filebios.h in
the fxlib need to be checked (and maybe defined in gint with a more
meaningful name for user interactivity)
2020-01-13 23:14:30 +01:00
Alice 07e2de981a core: add BFile_Size syscall 2020-01-13 15:44:04 +01:00
Lephe 3147045196
bopti-cg: add p8, p4, and fix alignment issues on r5g6b5 2019-11-15 13:31:44 +01:00
Lephe 3baa7612ee
use sh-elf by default when building 2019-11-13 19:31:37 +01:00
Lephe 9eb723ee53
render: remove the GINT_NEED_VRAM macro
This macro used to protect the declaration of the [vram] variable of
gint. This variable was short to keep drawing functions short but could
clutter the namespace.

That being said, it's even better to just [#define vram gint_vram] if
you need. This change renames the variable to [gint_vram], exposes it
whenever <gint/display.h> is included, and removes the GINT_NEED_VRAM
macro altogether.
2019-10-27 08:14:42 +01:00
Lephe 95a3345326
keyboard: add keydown() in the model
This change adds a keydown() function that is synchronized with events,
ie. it returns the key state as seen by previously read events.

It also completely eliminates low-level repeat events, which are not
very meaningul as the keyboard scan frequency goes up (and would be
meaningless if KEYSC interrupts were used), and adapts getkey() by
giving it access to the current driver time through pollevent().
2019-09-28 19:25:01 +02:00
Lephe 86cd9b98d4
small improvements
* Update TOTO list
* Change the type of gint_vbr to comply with a new warning in GCC 9
* Add strcmp()
2019-09-19 15:59:38 +02:00
Lephe a05d3416f0
std: support integer size formats (hh, h, l, ll) 2019-09-19 15:58:35 +02:00
Lephe fc7aab6eba
dma: finalize dma_memset() and dma_memcpy()
Adds support for dma_memcpy(), and uses a proper ILRAM allocation scheme
(static linking here) for the temporary buffer in dma_memset().
2019-09-15 19:30:57 +02:00
Lephe 15558c8fb3
support data loading in ILRAM, XRAM and YRAM
This change adds support for three sections .ilram, .xram and .yram,
along with three macros GILRAM, GXRAM and GYRAM, that can be used to
statically load data to on-chip memory.
2019-09-15 19:29:47 +02:00
Lephe bb77e4588d
dma: fix freezes when transferring to/from IL memory
The IL memory is unavailable when the processor goes to sleep, causing
any involved DMA transfer to stall. The dma_transfer_wait() normally
sleeps to save battery power, but this causes the whole system to freeze
and never wake up.

This change lets dma_transfer_wait() decide dynamically whether to sleep
or spinlock. There is no concrete improvement over dma_transfer_noint()
when using IL memory, but it makes dma_transfer() fully generic.

Obviously the same goes for X and Y memory.
2019-09-15 15:20:23 +02:00
Lephe 552b9b9a43
dma: only expose API on fxcg50
Currently there seems to be no DMA at all on fx9860g. Further
investigation would be required, because this would be the first major
difference between the SH7305's found in fx9860g and fxcg50 models.

An automated peripheral register discovery strategy might help, but
identifying discovered registers would be non trivial.

Also use the pruning ability of the Makefile to avoid troublesome
ifdef's in the code.
2019-09-15 10:20:37 +02:00
Lephe 5630814897
core: allow custom panics and exception catching
This change introduces two new mechanismes for executing user code when
an exception occurs.

* This first is the custom panic message, which usually displays "System
  ERROR". The function that performs this task can now be user-defined.
  It is also run in user mode because the exception handler rte's into
  it, allowing it to execute any kind of interrupt-inducing task. The
  behavior is undefined if this function raises an exception.

* The second is an exception-catching function, which (when set) is
  called every time an exception occurs, and is granted the chance of
  handling the exception to continue execution normally. It can be used
  in various ways, the most primitive of which is recording the
  exception and going back. It runs in interrupt mode and must not raise
  any kind of exception.
2019-09-13 08:10:30 +02:00
Lephe 9a4ae4c80a
minor new definitions 2019-09-13 08:08:22 +02:00
Lephe 4a8ba82fab
truly support custom toolchains (almost) 2019-09-12 18:19:23 +02:00
Lephe ef0e5e32f8
render: add one-parameter dvline() and dhline()
Behave like Basic's Horizontal and Vertical commands. Internal dline()
optimizations are renamed gint_dhline() and gint_dvline().

Also supports ghline() and gvline() in the gray engine.

Optimization cases here are amost negligible due to limiting RAM access
frequencies and the very limited amount of work accomplished in the
functions. Code maintainability is prioritized by using dline().
2019-09-07 11:26:11 +02:00
Lephe 61e68d01bb
expose more platform-agnostic code
May be useful later on for libraries such as libprof.
2019-09-06 12:16:31 +02:00
lephe b9cba1d00a
style, formatting, font 2019-09-03 22:29:04 +02:00
lephe e1aca8d89b
exc: add exception handlers, use them in the DMA
This change introduces exception handlers that default to a fatal error
with an on-screen description of the exception and some debugging
information.

It also adds the dprint() function as a definitely-needed helper and
removes bootlog_unmapped() by using the exception handler for the fatal
error display. (Also printf() is now required in all gint add-ins; this
is sad, but space is not as much of a constraint as debugging.)

Finally, the exception handler is used to handle an interrupt which is
an exception in practice, the DMA address error. On fx-CG 50, additional
DMA-related information is displayed on the screen. This is left out on
fx-9860G as there is not enough space.
2019-09-03 22:15:00 +02:00
lephe 6d54a5fe0a dma: add exception handler and dma_memset() 2019-08-27 21:18:44 +02:00
lephe 652637d475 bopti: add support for r5g6b5 and r5g6b5a on fxcg50
This commit introduces bopti for fxcg50 with the first basic 16-bit
formats. The performance is rather slow, especially for large images,
and will need refinements and/or overclock to be really efficient in
full-screen real-time applications.
2019-08-27 21:04:07 +02:00
lephe 62a49a543e topti: spacing bug fix on fxcg50
Fixes a bug where spaces were not being rendered.
2019-08-27 21:02:28 +02:00
lephe b3cbb0a43f dma: add support for all six channels (merges #1) 2019-08-08 11:21:10 +02:00
lephe ab0fa06a1d bopti: fix bug in non-zero stride renders
Forgot to take into account the number of layers in the input
stride. Anything after the first line would be pretty much
garbage.
2019-08-06 16:17:25 +02:00
lephe 2e17b77e56 bopti: first fxcg50 version with r5g6b5 and r5g6b5a
This commit introduces bopti for fx-CG 50. Currently the only
interfaces are the bopti_render_{clip,noclip} functions, and the
only supported formats are r5g6b5 and r5g6b5a.

The algorithm for r5g6b5 is optimized to perform longword accesses
using movua.l, whereas the algorithm for r5g6b5a uses plain word
accesses because transparency checks feel more difficult than one
more loop iteration.

These algorithms are still slow for large surfaces and struggle to
keep up 25 FPS in full-screen, so possible improvements with the
DMA should definitely be tested before restorting to overclock.
2019-08-04 13:59:35 +02:00
lephe 64dbe6021d some formatting and comment updates 2019-08-04 13:59:17 +02:00
Antoine 8cbd5be038 Ajout de la fonction srtcat et modification du 0 de la police de la Graph 90+E 2019-07-31 04:24:42 -04:00
lephe 62ae7e19d4 gray: considerably improve gray visuals 2019-07-29 12:17:25 -04:00
lephe 27f773ff7c bopti: account for layer count in initial offset 2019-07-29 08:58:58 -04:00
lephe 1cf5bf514a bopti: add gray support for all four profiles
This change finally introduces gray image rendering with bopti. This
is the final iteration of bopti v2 and certainly the fastest so far.
All four profiles are supported, without change to the format.
2019-07-27 19:51:53 -04:00
lephe 1906329552 topti: fix C_LIGHTEN and C_DARKEN
Light and dark were erroneously swapped in my documentation's
formulae, but not in the way operands were cancelled when x=0,
leading to strange results.
2019-07-27 19:49:39 -04:00
lephe 144ff90e37 gray: add gpixel() and gline()
Optimized cases for gline() rely on grect() instead of reimplementing
the mechanics of the fully-optimized drawing to save some space.
2019-07-27 19:48:36 -04:00
lephe d7c33b12a5 topti: return previously-configured font in dfont() 2019-07-27 19:47:04 -04:00
lephe ae4f7af172 gray: add engine, basic drawing and text
This revision includes the base gray engine with sensible starting
defaults, gclear() and grect(), as well as gtext().
2019-07-20 12:31:46 -04:00
lephe 705854da39 getkey: exclude other keys during a repetition
When a key is being held and repeated, ignore other key presses
until it is released. Without this, new keys would take priority.

This is the desired behavior because pressing other keys by
accident, especially on the directional pad, is common. Besdeis
this is the system's behavior.
2019-07-18 15:20:34 -04:00
lephe 1697998a9c tmu: improve code style and clear masks
Apparently there are some situations where the interrupt masks for
TMU0 are set in the system. They should obviously be cleared.
2019-07-18 15:19:29 -04:00