Commit graph

61 commits

Author SHA1 Message Date
Lephe
0aceb6f93e
kernel: compact VBR even more on SH3
This change moves interrupt handler from VBR + 0x640 to VBR + 0x200, in
the gap between the exception and TLB miss handlers.

This new scheme is not limited to VBR+0x200 .. VBR+0x400 as new large
block numbers can be used to jump over the TLB miss handler and the
interrupt handler entry points.
2020-07-10 13:07:12 +02:00
Lephe
9d1187b5b4
string: optimized memcpy, memcmp, memset; decent memmove
This change adds optimized versions of the core memory functions,
relying on 4-alignment, 2-alignment, and the SH4's unaligned move
instruction to (hopefully) attain good performance in all situations.
2020-07-04 15:05:28 +02:00
Lephe
4a0fc65c34
gray: add decent defaults for older fx9860g-like models
Gray quality is better on the Graph 35+E II, it still flickers a lot on
other models (as I remembered). There might be better settings out there
but I'm not sure we can reach the quality of the current Graph 35+E II
defaults. The Graph 75+E with which I tested might also be different
from other T6K11 such as the smaller Graph 35+E.
2020-06-20 19:16:42 +02:00
Lephe
b7de559b78
some cleanup in src/core and in the repository 2020-06-20 11:41:13 +02:00
Lephe
2fd4238d31
core: finalize TLB management in timer callbacks (STABLE)
This change enables interrupts within timer callbacks, making it
possible to load pages to MMU while handling a timer underflow. The call
to TLB_LoadPTEH() has been moved directly into the VBR handler to avoid
jumping to ILRAM for a short call on SH4.

The TMU and ETMU handlers have been changed to callback through a new
function gint_inth_callback() that saves the user bank and a few
registers, then invokes the callback with interrupts enabled and in user
bank; until now, callbacks were invoked with interrupts disabled and in
kernel bank. Note that IMASK is still set so a callback can only be
interrupted by a high-priority interrupt.

A timer_wait() function has also been added to simplify tests that
involve timers. Finally, the priority level of the TMU0 underflow
interrupt has been set to 13 (as per the comments) instead of 7.

This version is the first stable version that handles TLB misses
transparently for large add-ins. It is suitable for every gint
application.
2020-06-17 11:43:26 +02:00
Lephe
4ad2110efc
core: accept large add-ins and setup TLB management (UNSTABLE)
This change modifies the fx-CG 50 linker script to allow add-ins up to
2M and no longer complains about add-ins that don't fit in the TLB.

It also exposes the __TLB_LoadPTEH() syscall (%003 on fx9860g, %00c on
fxcg50) that answers TLB misses. This syscall can be called manually
from an add-in to load some pages and seems to work without problem.

However, this version does not provide any automatic TLB management,
some key areas of the kernel are still under TLB and some user code
(such as timer callbacks) is not! This version is suitable only for
add-ins smaller than 220k!
2020-06-14 11:01:27 +02:00
Lephe
caa4f675c9
bopti: deprecate image_t, renamed to bopti_image_t 2020-06-01 12:11:59 +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
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
e217309adf
render-cg: expose vram buffers with dgetvram() and dsetvram() 2020-05-10 23:03:02 +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
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
3147045196
bopti-cg: add p8, p4, and fix alignment issues on r5g6b5 2019-11-15 13:31:44 +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
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
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
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
64dbe6021d some formatting and comment updates 2019-08-04 13:59:17 +02: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
c80debacd7 keyboard stdio: some fixes 2019-07-17 19:29:12 -04:00
lephe
ff2db385a8 TODO update and miscellaneous style 2019-07-16 18:34:10 -04:00
lephe
f33cb3cf80 core: better bootlog API and implementation
* Now uses topti instead of fxlib for text (including MMU failure)
* Fit .pretext into 4k for everything before MMU succeeds
* A short version of sprintf() for dynamic messages
* Support a driver function, status(), to allow early driver debug
* Expose more useful platform information in <gint/mpu.h>
* Expose the first of a few CASIOWIN syscalls
2019-03-06 14:32:51 +01:00
lephe
3f7c0a04ad way too much, including bopti/topti, timers, and more. 2019-02-21 21:00:26 +01:00
lephe
79b78b5345 Hopefully the last adjustments before the first release. 2017-07-11 13:51:56 +02:00
lephe
34e42a03a6 Small Makefile adjustments, preparing fusion with fxSDK 2017-07-08 17:22:42 +02:00
lephe
f6133c26fc Startup logs instead of diagnostics, created .gint_bss, updated demo. 2017-07-05 21:38:12 +02:00
lephe
5e66efc560 Interrupt controller module description (WIP), task switch and return to menu. 2017-07-01 16:07:14 +02:00
lephe
a0f06fadd7 Interrupt Controller module draft, bopti bugfix. 2017-04-22 21:59:39 +02:00
lephe
3214f6b797 Almost ended quality review, and fixed tales-related vram overflows. 2017-04-19 19:57:31 +02:00
lephe
57a7e1c2d4 More quality review, more registers saved at startup. 2017-04-13 21:59:13 +02:00
lephe
a6e312a39c Some quality review. Made keyboard time milliseconds. 2017-03-26 18:38:32 +02:00
lephe
31e2b453dd Redesigned timer module: got a possibly infinite amount of virtual timers. 2017-03-01 11:07:28 +01:00
lephe
7ab6170ca3 Key repeat events & Timer callbacks with arguments. Fixed sleep_us(). 2017-02-25 23:19:35 +01:00
lephe
d852bc3310 Huh... debug app for crashes & whole new interrupt system. Minor edits. 2017-02-25 19:02:07 +01:00
lephe
49df2a5fb4 Added a --extended-libc option and some headers to allow porting external programs. 2017-01-22 18:35:02 +01:00
lephe
93dca0ef6f Made INCOMPATIBLE changes to image rendering. Added inttypes.h and bakclight management in getkey(). 2017-01-20 21:11:00 +01:00
lephe
28f790bade Fixed some font formats. Minor changes in README, headers. 2017-01-01 17:41:16 +01:00
lephe
4fceab4533 Updated README and TODO files 2016-12-25 11:45:05 +01:00
lephe
9a3433c52a Fixed left-side vram overflow with text, made install automatically along fxSDK. 2016-12-22 23:08:44 +01:00
lephe
2564096a13 Added natural delay/frequency settings for timers. 2016-12-22 19:47:05 +01:00
lephe
e6e0989436 Solved backlight issues and added backlight control to the API. 2016-12-22 18:36:39 +01:00
lephe
eedec2b124 Added a configure script with some options, made Makefile output pretty. Set up an event system (used by keyboard). 2016-11-05 22:00:23 +01:00
lephe
98fdbbc333 Proper RTC callback system. Moved keyboard to RTC (saves a timer). Reduced use of 7705.h / 7305.h. 2016-09-04 11:35:41 +02:00
lephe
d80de5683b Added clock frequency computations/measurements, and frequency-delay/timer expression. 2016-08-29 11:29:07 +02:00
lephe
0205c39f21 Fixed area functions (rectangles completely outside the screen). 2016-08-14 19:57:58 +02:00
lephe
58db663ae6 Some time manipulation. Added the targets to the .gitignore file. 2016-08-08 15:01:33 +02:00
lephe
1f223f807f Added an RTC test (clock), image part drawing and a few standard functions (stdlib, time). 2016-08-02 07:51:44 +02:00