micronona/Program.cs

559 lines
19 KiB
C#
Raw Normal View History

2026-04-03 10:49:53 +02:00
using SDL2;
using Tomlyn;
using Tomlyn.Model;
2026-04-03 10:49:53 +02:00
const int ScreenWidth = 320;
const int ScreenHeight = 180;
const string Title = "Micronona";
const int Scale = 3;
// -------------------------------------------------------------------------
// Memory
// -------------------------------------------------------------------------
bool isRawConsole = string.IsNullOrEmpty(Environment.GetEnvironmentVariable("DISPLAY"))
&& string.IsNullOrEmpty(Environment.GetEnvironmentVariable("WAYLAND_DISPLAY"));
if (isRawConsole)
{
Console.CancelKeyPress += (s, e) => e.Cancel = true;
}
else
{
Console.WriteLine("Running in developer mode");
}
2026-04-03 10:49:53 +02:00
var mem = new MemoryModel();
var diskManager = new DiskManager();
2026-04-03 10:49:53 +02:00
var micrononaRenderer = new MicrononaRenderer(mem);
var consoleHelper = new ConsoleHelper(mem);
var inputInterpreter = new InputInterpreter(mem, consoleHelper, diskManager);
// Unit Separator (ASCII 31) für Eingabeaufforderung
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 31 * MemoryModel.FontGlyphHeight,
0x00, 0x60, 0x70, 0x78, 0x7E, 0x7E, 0x78, 0x70, 0x60, 0x00
);
// !
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 33 * MemoryModel.FontGlyphHeight,
0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x18, 0x00, 0x00
);
2026-04-03 10:49:53 +02:00
// "
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 34 * MemoryModel.FontGlyphHeight,
0x00, 0x36, 0x66, 0x6C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
);
// $
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 36 * MemoryModel.FontGlyphHeight,
// 0x00, 0x18, 0x3E, 0x68, 0x3C, 0x16, 0x7C, 0x18, 0x00, 0x00
0x00, 0x08, 0x3E, 0x68, 0x3C, 0x16, 0x7C, 0x10, 0x00, 0x00
);
// (
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 40 * MemoryModel.FontGlyphHeight,
// 0x00, 0x08, 0x18, 0x30, 0x20, 0x20, 0x30, 0x18, 0x08, 0x00
//0x00,0x0C,0x08, 0x18,0x10,0x10,0x10,0x18,0x08, 0x0C,0x00
0x00,0x0C,0x18,0x30,0x30,0x30,0x30,0x18,0x0C,0x00
);
// )
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 41 * MemoryModel.FontGlyphHeight,
0x00,0x30,0x18,0x0C,0x0C,0x0C,0x0C,0x18,0x30,0x00
);
2026-04-03 10:49:53 +02:00
// *
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 42 * MemoryModel.FontGlyphHeight,
0x00, 0x00, 0x34, 0x18, 0x7E, 0x18, 0x2C, 0x00, 0x00, 0x00
);
// +
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 43 * MemoryModel.FontGlyphHeight,
0x00, 0x00, 0x18, 0x18, 0x7E, 0x18, 0x18, 0x00, 0x00, 0x00
);
// ,
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 44 * MemoryModel.FontGlyphHeight,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x30, 0x00
);
// -
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 45 * MemoryModel.FontGlyphHeight,
0x00, 0x00, 0x00, 0x00, 0x7E, 0x00, 0x00, 0x00, 0x00, 0x00
);
// .
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 46 * MemoryModel.FontGlyphHeight,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00
);
2026-04-03 10:49:53 +02:00
// 0
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 48 * MemoryModel.FontGlyphHeight,
// 0x00, 0x18, 0x3C, 0x66, 0x66, 0x66, 0x3C, 0x18, 0x00, 0x00
0x00, 0x3C, 0x66, 0x6E, 0x7E, 0x76, 0x66, 0x3C, 0x00, 0x00
);
// 1
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 49 * MemoryModel.FontGlyphHeight,
0x00, 0x0C, 0x1C, 0x3C, 0x0C, 0x0C, 0x0C, 0x1E, 0x00, 0x00
);
// 2
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 50 * MemoryModel.FontGlyphHeight,
// 0x00, 0x3C, 0x66, 0x0C, 0x18, 0x30, 0x60, 0x7F, 0x00, 0x00
0x00, 0x3C, 0x66, 0x06, 0x0C, 0x18, 0x30, 0x7E, 0x00, 0x00
);
// 3
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 51 * MemoryModel.FontGlyphHeight,
0x00, 0x3C, 0x66, 0x06, 0x1C, 0x06, 0x66, 0x3C, 0x00, 0x00
);
// 4
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 52 * MemoryModel.FontGlyphHeight,
0x00, 0x1C, 0x3C, 0x6C, 0x7E, 0x0C, 0x0C, 0x0C, 0x00, 0x00
);
// 5
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 53 * MemoryModel.FontGlyphHeight,
// 0x00, 0x7E, 0x60, 0x7C, 0x06, 0x06, 0x06, 0x7C, 0x00, 0x00
// 0x00, 0x7E, 0x60, 0x60, 0x7C, 0x06, 0x06, 0x7C, 0x00, 0x00
0x00, 0x7E, 0x60, 0x60, 0x7C, 0x06, 0x66, 0x3C, 0x00, 0x00
);
// 6
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 54 * MemoryModel.FontGlyphHeight,
0x00, 0x3C, 0x60, 0x60, 0x7C, 0x66, 0x66, 0x3C, 0x00, 0x00
);
// 7
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 55 * MemoryModel.FontGlyphHeight,
0x00, 0x7E, 0x06, 0x0E, 0x0C, 0x1C, 0x18, 0x18, 0x00, 0x00
);
// 8
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 56 * MemoryModel.FontGlyphHeight,
0x00, 0x3C, 0x66, 0x66, 0x3C, 0x66, 0x66, 0x3C, 0x00, 0x00
);
// 9
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 57 * MemoryModel.FontGlyphHeight,
0x00, 0x3C, 0x66, 0x66, 0x3E, 0x06, 0x06, 0x3C, 0x00, 0x00
);
// :
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 58 * MemoryModel.FontGlyphHeight,
0x00, 0x00, 0x18, 0x18, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00
);
// <
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 60 * MemoryModel.FontGlyphHeight,
0x00, 0x00, 0x0C, 0x18, 0x30, 0x18, 0x0C, 0x00, 0x00, 0x00
);
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 61 * MemoryModel.FontGlyphHeight,
0x00, 0x00, 0x00, 0x3C, 0x00, 0x3C, 0x00, 0x00, 0x00, 0x00
);
// >
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 62 * MemoryModel.FontGlyphHeight,
0x00, 0x00, 0x30, 0x18, 0x0C, 0x18, 0x30, 0x00, 0x00, 0x00
);
// ?
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 63 * MemoryModel.FontGlyphHeight,
0x00, 0x3C, 0x66, 0x06, 0x0C, 0x18, 0x00, 0x18, 0x00, 0x00
);
2026-04-03 10:49:53 +02:00
// A
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 65 * MemoryModel.FontGlyphHeight,
0x00, 0x18, 0x3C, 0x66, 0x7E, 0x66, 0x66, 0x66, 0x00, 0x00
);
// B
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 66 * MemoryModel.FontGlyphHeight,
0x00, 0x7C, 0x66, 0x66, 0x7C, 0x66, 0x66, 0x7C, 0x00, 0x00
);
2026-04-03 10:49:53 +02:00
// C
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 67 * MemoryModel.FontGlyphHeight,
// 0x00, 0x3A, 0x66, 0x60,0x60, 0x60,0x66,0x3A,0x00,0x00
0x00, 0x3C, 0x66, 0x60, 0x60, 0x60, 0x66, 0x3C, 0x00, 0x00
);
// D
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 68 * MemoryModel.FontGlyphHeight,
0x00, 0x7C, 0x66, 0x66, 0x66, 0x66, 0x66, 0x7C, 0x00, 0x00
);
// E
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 69 * MemoryModel.FontGlyphHeight,
0x00, 0x7E, 0x60, 0x60, 0x7C, 0x60, 0x60, 0x7E, 0x00, 0x00
);
// G
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 71 * MemoryModel.FontGlyphHeight,
0x00, 0x3C, 0x66, 0x60, 0x6E, 0x66, 0x66, 0x3C, 0x00, 0x00
);
// H
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 72 * MemoryModel.FontGlyphHeight,
0x00, 0x66, 0x66, 0x66, 0x7E, 0x66, 0x66, 0x66, 0x00, 0x00
);
// I
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 73 * MemoryModel.FontGlyphHeight,
0x00, 0x3C, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3C, 0x00, 0x00
);
// K
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 75 * MemoryModel.FontGlyphHeight,
0x00, 0x66, 0x6C, 0x78, 0x70, 0x78, 0x6C, 0x66, 0x00, 0x00
);
2026-04-03 10:49:53 +02:00
// L
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 76 * MemoryModel.FontGlyphHeight,
0x00, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x7E, 0x00, 0x00
);
// M
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 77 * MemoryModel.FontGlyphHeight,
// 0x00, 0x62, 0x76, 0x7E,0x6A, 0x62,0x62,0x62,0x00,0x00
// 0x00, 0x42, 0x66, 0x7e, 0x5a, 0x42, 0x66, 0x66
0x00, 0x42, 0x66, 0x7e, 0x7E, 0x66, 0x66, 0x66
// 0x00, 0x62, 0x76, 0x7E, 0x6A, 0x62, 0x62, 0x66, 0x00, 0x00
);
// N
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 78 * MemoryModel.FontGlyphHeight,
0x00, 0x66, 0x66, 0x76, 0x7E, 0x6E, 0x66, 0x66, 0x00, 0x00
);
// O
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 79 * MemoryModel.FontGlyphHeight,
0x00, 0x3C, 0x66, 0x66, 0x66, 0x66, 0x66, 0x3C, 0x00, 0x00
);
// P
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 80 * MemoryModel.FontGlyphHeight,
0x00, 0x7C, 0x66, 0x66, 0x7C, 0x60, 0x60, 0x60, 0x00, 0x00
// 0x00, 0x62, 0x76, 0x7E, 0x6A, 0x62, 0x62, 0x66, 0x00, 0x00
);
// R
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 82 * MemoryModel.FontGlyphHeight,
0x00, 0x7C, 0x66, 0x66, 0x7C, 0x78, 0x6C, 0x66, 0x00, 0x00
// 0x00, 0x62, 0x76, 0x7E, 0x6A, 0x62, 0x62, 0x66, 0x00, 0x00
);
// S
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 83 * MemoryModel.FontGlyphHeight,
// 0x00, 0x7E, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3C, 0x00, 0x00
0x00, 0x3C, 0x66, 0x60, 0x3C, 0x06, 0x66, 0x3C, 0x00, 0x00
);
2026-04-03 10:49:53 +02:00
// T
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 84 * MemoryModel.FontGlyphHeight,
// 0x00, 0x7E, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3C, 0x00, 0x00
0x00, 0x7E, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00
);
// U
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 85 * MemoryModel.FontGlyphHeight,
// 0x00, 0x7E, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3C, 0x00, 0x00
0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x3C, 0x00, 0x00
);
// W
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 87 * MemoryModel.FontGlyphHeight,
0x00, 0x62, 0x62, 0x6A, 0x7E, 0x76, 0x66, 0x42, 0x00, 0x00
);
// X
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 88 * MemoryModel.FontGlyphHeight,
0x00, 0x66, 0x66, 0x3C, 0x18, 0x3C, 0x66, 0x66, 0x00, 0x00
);
2026-04-03 10:49:53 +02:00
// Y
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 89 * MemoryModel.FontGlyphHeight,
0x00, 0x66, 0x66, 0x3C, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00
);
// a
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 97 * MemoryModel.FontGlyphHeight,
0x00, 0x00, 0x3C, 0x06, 0x3E, 0x66, 0x66, 0x3E, 0x00, 0x00
);
// b
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 98 * MemoryModel.FontGlyphHeight,
0x00, 0x60, 0x60, 0x60, 0x7C, 0x66, 0x76, 0x5C, 0x00, 0x00
);
2026-04-03 10:49:53 +02:00
// c
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 99 * MemoryModel.FontGlyphHeight,
0x00, 0x00, 0x3C, 0x66, 0x60, 0x60, 0x66, 0x3C, 0x00, 0x00
);
// d
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 100 * MemoryModel.FontGlyphHeight,
0x00, 0x06, 0x06, 0x06, 0x3E, 0x66, 0x66, 0x3E, 0x00, 0x00
);
// e
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 101 * MemoryModel.FontGlyphHeight,
0x00, 0x00, 0x3C, 0x66, 0x7E, 0x60, 0x66, 0x3C, 0x00, 0x00
);
// h
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 104 * MemoryModel.FontGlyphHeight,
0x00, 0x60, 0x60, 0x60, 0x7C, 0x66, 0x66, 0x66, 0x00, 0x00
);
2026-04-03 10:49:53 +02:00
// i
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 105 * MemoryModel.FontGlyphHeight,
// 0x00, 0x00, 0x10, 0x00, 0x10, 0x10, 0x10, 0x18, 0x00, 0x00
// 0x00, 0x00, 0x18, 0x00, 0x18, 0x18, 0x18, 0x3C, 0x00, 0x00
0x00, 0x18, 0x00, 0x18, 0x18, 0x18, 0x18, 0x3C, 0x00, 0x00
);
// k
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 107 * MemoryModel.FontGlyphHeight,
0x00, 0x60, 0x60, 0x66, 0x6C, 0x78, 0x6C, 0x66, 0x00, 0x00
);
// l
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 108 * MemoryModel.FontGlyphHeight,
0x00, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x1C, 0x00, 0x00
);
// m
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 109 * MemoryModel.FontGlyphHeight,
0x00, 0x00, 0x5C, 0x7E, 0x6A, 0x6A, 0x6A, 0x6A, 0x00, 0x00
);
// n
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 110 * MemoryModel.FontGlyphHeight,
0x00, 0x00, 0x5C, 0x76, 0x66, 0x66, 0x66, 0x66, 0x00, 0x00
);
// o
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 111 * MemoryModel.FontGlyphHeight,
0x00, 0x00, 0x3C, 0x66, 0x66, 0x66, 0x66, 0x3C, 0x00, 0x00
);
// p
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 112 * MemoryModel.FontGlyphHeight,
0x00, 0x00, 0x7C, 0x66, 0x66, 0x7C, 0x60, 0x60, 0x60, 0x00
);
// r
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 114 * MemoryModel.FontGlyphHeight,
0x00, 0x00, 0x6E, 0x78, 0x70, 0x60, 0x60, 0x60, 0x00, 0x00
);
// s
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 115 * MemoryModel.FontGlyphHeight,
// 0x00, 0x00, 0x3C, 0x60, 0x38, 0x1C, 0x06, 0x3C, 0x00, 0x00
0x00, 0x00, 0x3E, 0x60, 0x38, 0x1C, 0x06, 0x7C, 0x00, 0x00
);
2026-04-03 10:49:53 +02:00
// t
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 116 * MemoryModel.FontGlyphHeight,
0x00, 0x18, 0x18, 0x18, 0x3C, 0x18, 0x18, 0x0C, 0x00, 0x00
);
// u
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 117 * MemoryModel.FontGlyphHeight,
0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x6E, 0x3A, 0x00, 0x00
);
// v
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 118 * MemoryModel.FontGlyphHeight,
0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x3C, 0x18, 0x00, 0x00
);
// x
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 120 * MemoryModel.FontGlyphHeight,
0x00, 0x00, 0x66, 0x66, 0x3C, 0x3C, 0x66, 0x66, 0x00, 0x00
);
// y
mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 121 * MemoryModel.FontGlyphHeight,
0x00, 0x00, 0x66, 0x66, 0x66, 0x3C, 0x18, 0x18, 0x30, 0x00
2026-04-03 10:49:53 +02:00
);
// -------------------------------------------------------------------------
// SDL init
// -------------------------------------------------------------------------
if (SDL.SDL_Init(SDL.SDL_INIT_VIDEO) < 0)
{
Console.Error.WriteLine($"SDL_Init failed: {SDL.SDL_GetError()}");
return 1;
}
SDL.SDL_StartTextInput();
var window = SDL.SDL_CreateWindow(
Title,
SDL.SDL_WINDOWPOS_CENTERED,
SDL.SDL_WINDOWPOS_CENTERED,
ScreenWidth * Scale,
ScreenHeight * Scale,
SDL.SDL_WindowFlags.SDL_WINDOW_SHOWN
);
if (window == IntPtr.Zero)
{
Console.Error.WriteLine($"SDL_CreateWindow failed: {SDL.SDL_GetError()}");
SDL.SDL_Quit();
return 1;
}
var renderer = SDL.SDL_CreateRenderer(
window, -1,
SDL.SDL_RendererFlags.SDL_RENDERER_ACCELERATED |
SDL.SDL_RendererFlags.SDL_RENDERER_PRESENTVSYNC
);
if (renderer == IntPtr.Zero)
{
Console.Error.WriteLine($"SDL_CreateRenderer failed: {SDL.SDL_GetError()}");
SDL.SDL_DestroyWindow(window);
SDL.SDL_Quit();
return 1;
}
// Framebuffer texture: 320×180, RGB24 (expanded from RGB332 each frame)
var texture = SDL.SDL_CreateTexture(
renderer,
SDL.SDL_PIXELFORMAT_RGB24,
(int)SDL.SDL_TextureAccess.SDL_TEXTUREACCESS_STREAMING,
ScreenWidth, ScreenHeight
);
// RGB24 output buffer for SDL (expanded from memory each frame)
byte[] rgb24 = new byte[ScreenWidth * ScreenHeight * 3];
var top = "*** MICRONONA 256 ***";
var tab = (byte)((MemoryModel.TextCols - top.Length) / 2);
consoleHelper.SetCursor(tab, 0);
consoleHelper.WriteText(top);
consoleHelper.SetCursor(35, 16);
consoleHelper.WriteText("MICRONONA");
consoleHelper.SetCursor(5, 1);
SDL.SDL_SetWindowFullscreen(window, (uint)SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN_DESKTOP);
var scrollLock = new ScrollLockLed();
scrollLock.Set(false);
diskManager.OnMicrononaStickInserted += path => { Console.WriteLine($"Ready: {path}"); scrollLock.Set(true); };
diskManager.OnStickRemoved += () => { Console.WriteLine("Stick removed"); scrollLock.Set(false); };
diskManager.Start();
2026-04-03 10:49:53 +02:00
// -------------------------------------------------------------------------
// Main loop
// -------------------------------------------------------------------------
bool running = true;
SDL.SDL_Event e;
while (running)
{
// --- Events ---
while (SDL.SDL_PollEvent(out e) != 0)
{
if (e.type == SDL.SDL_EventType.SDL_QUIT)
running = false;
2026-04-03 10:49:53 +02:00
if (e.type == SDL.SDL_EventType.SDL_KEYDOWN)
{
switch (e.key.keysym.sym)
{
case SDL.SDL_Keycode.SDLK_ESCAPE:
running = false;
break;
case SDL.SDL_Keycode.SDLK_c when (e.key.keysym.mod & SDL.SDL_Keymod.KMOD_CTRL) != 0:
case SDL.SDL_Keycode.SDLK_PAUSE when (e.key.keysym.mod & SDL.SDL_Keymod.KMOD_CTRL) != 0:
inputInterpreter.Stop();
break;
}
if (!inputInterpreter.IsRunning || inputInterpreter.IsWaitingForInput)
2026-04-03 10:49:53 +02:00
{
switch (e.key.keysym.sym)
{
case SDL.SDL_Keycode.SDLK_LEFT: consoleHelper.MoveCursor(-1, 0); break;
case SDL.SDL_Keycode.SDLK_RIGHT: consoleHelper.MoveCursor(1, 0); break;
case SDL.SDL_Keycode.SDLK_UP: consoleHelper.MoveCursor(0, -1); break;
case SDL.SDL_Keycode.SDLK_DOWN: consoleHelper.MoveCursor(0, 1); break;
case SDL.SDL_Keycode.SDLK_RETURN:
var line = consoleHelper.ReadLine();
consoleHelper.NewLine();
if (inputInterpreter.IsWaitingForInput)
inputInterpreter.SubmitInput(line);
else
inputInterpreter.InterpretInput(line);
break;
2026-04-03 10:49:53 +02:00
case SDL.SDL_Keycode.SDLK_BACKSPACE: consoleHelper.Backspace(); break;
case SDL.SDL_Keycode.SDLK_DELETE: consoleHelper.Delete(); break;
}
}
}
if (e.type == SDL.SDL_EventType.SDL_TEXTINPUT && (!inputInterpreter.IsRunning || inputInterpreter.IsWaitingForInput))
2026-04-03 10:49:53 +02:00
{
unsafe
{
byte ascii = e.text.text[0];
if (ascii >= 32 && ascii < 127)
consoleHelper.WriteText(((char)ascii).ToString());
}
}
}
// --- Interpreter-Schritt ---
inputInterpreter.Tick();
scrollLock.Refresh();
2026-04-03 10:49:53 +02:00
// --- VSync flag setzen (wird später vom 6809-Emulator gelesen) ---
mem.Write(MemoryModel.IoBase + MemoryModel.REG_VSYNC, 1);
// --- Render ---
var span = micrononaRenderer.Render();
unsafe
{
fixed (byte* ptr = span)
{
SDL.SDL_UpdateTexture(texture, IntPtr.Zero, (IntPtr)ptr, 320 * 3);
}
}
SDL.SDL_RenderClear(renderer);
SDL.SDL_RenderCopy(renderer, texture, IntPtr.Zero, IntPtr.Zero);
SDL.SDL_RenderPresent(renderer);
}
// -------------------------------------------------------------------------
// Cleanup
// -------------------------------------------------------------------------
SDL.SDL_DestroyTexture(texture);
SDL.SDL_DestroyRenderer(renderer);
SDL.SDL_DestroyWindow(window);
SDL.SDL_Quit();
return 0;