The Agon Light is powered by USB, but the USB-C port provides more than simply powering the device. It also allows bi-directional serial comms. There is a tool called Agon Hexload that makes sending data to the Agon Light easy, removing the need to shuffle microSD cards around.
The same USB connection can be used for debug printing by enabling the Agon Light’s “Printer” via VDU 2
. When the printer is enabled, all text sent to the VDP is sent out the USB port as serial data. This is turned off by using VDU 3
.
So this incredibly simple piece of code will give you a nice debug_print()
function.
#include "debug_print.h"
#include <stdio.h>
#include <mos_api.h>
#ifdef DEBUG
void debug_print(const char *format, ...)
{
va_list args;
putch(2);
putch(21);
va_start(args, format);
vprintf(format, args);
va_end(args);
putch(6);
putch(3);
}
#else
#define debug_print(...) ((void)0)
#endif
Stick that in a C file, make an appropriate .H file, then include that wherever some debug logging is needed.
int main()
{
debug_print("----- Program Start -----\n");
GameStates_e next_state = GAME_STATE_REMAIN;
current_state = game_states[GAME_STATE_TITLE];
debug_print("VDU Init\n");
vdp_vdu_init();
vdp_mode(136); // 320x240 64 colour
vdp_cursor_enable(0);
vdp_logical_scr_dims(false);
debug_print("Keyboard Init\n");
keyboard_init();
bool quit = false;
debug_overlay_enabled = false;
debug_print("Current State Init\n");
current_state->init();
Then, before launching the software, transfer it to the Agon using Agon Hexload and attach a serial terminal to the Agon. I am currently using Minicom, but I want to write my own Python tool instead that dumps the text to a file.
Welcome to minicom 2.10
OPTIONS: I18n
Compiled on Feb 24 2025, 22:01:05.
Port /dev/ttyUSB0, 14:14:25 [F]
Press CTRL-A Z for help on special keys
----- Program Start -----
VDU Init
Keyboard Init
Current State Init
Entering main loop