// Copyright (c) 2026 - 2026 kio@little-bat.de
// BSD-2-Clause license
// https://opensource.org/licenses/BSD-2-Clause

#include "kilipili.h"


int main(int argc, char* argv[])
{
	using namespace kilipili;

	stdio_init_all();
	fprintf(stderr, "Hello world\n"); // print to stdio
	USB::initUSBHost();

	RCPtr pixmap	  = new Pixmap_a1w8(800, 600);
	RCPtr framebuffer = new FrameBuffer(pixmap);
	RCPtr printer	  = new Printer(pixmap);

	addVideoPlane(framebuffer);
	startVideo(vga_mode_800x600_60);

	printer->cls();
	printer->printf("Hello world ... %s mode\n", debug ? "DEBUG" : "RELEASE"); // print on video screen
	printer->printf("%s\n", printer->identification());						   // print on video screen
	pixmap->drawRect(100, 50, 400, 300, red);								   // draw on video screen

	Dispatcher::addHandler(&blinkOnboardLed);
	Dispatcher::addHandler(&USB::pollUSB);

	for (;;)
	{
		int c = stdio_getchar_timeout_us(1000); // get input from stdin (UART)
		if (c < 0) c = USB::getChar();			// get input from usb keyboard
		if (c == '\r') c = '\n';
		if (c == uchar(c)) printer->putc(char(c));

		Dispatcher::run(); // run the registered Dispatcher handlers
		purge_tempmem();   // house keeping
	}
}


/*






















































*/
