I made several improvements to GLCC after petersieg's thread (
https://forum.gigatron.io/viewtopic.php?t=431). They currently are in the head of the GLCC repository and will appear in the next release after a bit of testing time.
Conio interface
I added an include file <conio.h>
https://github.com/lb3361/gigatron-lcc/ ... on/conio.h that offers a more familiar interface to the console code. In the process I also made the console code a bit smaller, partly because more parts are hand coded in assembly code, and partly because it only understands the CR, LF, and BS control codes by defaults. The full handling comes back if one uses stdio.
Selectable input driver
I took advantage of the conio work to rethink the way the input code works. Input on the Gigatron is a mess because the pluggy keyboard was added as an afterthought. The Pluggy keyboard and the Famicom controller can emit the same codes to mean completely different things, e.g. an ascii key or a combination of buttons. Certain controllers, known as Type C controllers, can emit ascii codes for simple button presses.
The new include file <gigatron/kbget.h>
https://github.com/lb3361/gigatron-lcc/ ... on/kbget.h provides three alternative drivers to handle these problems in increasingly sophisticated ways.
- The default driver replicates the previous GLCC behavior and is suitable for keyboard centric applications.
- A more advanced driver provide a much better experience for applications that rely on the buttons and need a responsive interface. Although the design of the Gigatron input makes it impossible to fully distinguish keypresses from button presses, I believe that I found a very usable approximation (this was not easy). See the comments in the include file for an explanation.
- A third one adds autorepeat.
The simplest way to select one of these drivers is to use the new linker option '--option':
Code: Select all
stuff/conio % glcc -o TSTkbgetc.gt1 TSTkbget.c --option=KBGET_AUTOREPEAT
stuff/conio % glcc -o TSTkbgetb.gt1 TSTkbget.c --option=KBGET_AUTOBTN
stuff/conio % glcc -o TSTkbgeta.gt1 TSTkbget.c --option=KBGET_SIMPLE
Selectable formatting code for printf-like functions
The complexity of the ANSI C printf specification has long been a problem because the printf library code is too bulky. GLCC already offers a simpler function called mincprintf that is very compact but is annoyingly limited. I was trying to provide a more balanced one called midcprintf when I realized that it would be better to offer a choice of low-level formatting engines that will be used by all printf-like functions: printf, cprintf, sprintf, etc.
The new include files <gigatron/printf.h>
https://github.com/lb3361/gigatron-lcc/ ... intf.h#L69 defines a function pointer '_doprint' that can either be the default '_doprint_c89' or the more compact '_doprint_simple' which takes one third of the size and yet is far more capable than mincprintf.
The simplest way to select one is again to use the new linker option '--option' :
Code: Select all
% glcc -o TSTmem.gt1 TSTmem1.c --option=PRINTF_C89 && wc -c TSTmem1.gt1
5213 TSTmem.gt1
% glcc -o TSTmem.gt1 TSTmem2.c --option=PRINTF_SIMPLE && wc -c TSTmem2.gt1
4056 TSTmem.gt1
Note that using cprintf instead of printf still saves the stdio overhead. These options are just about the formatting routine that is used by all printf-like functions save for mincprintf, which has its own, and midcprintf, which always uses _doprint_simple.