using SDL2; using Tomlyn; using Tomlyn.Model; const int ScreenWidth = 320; const int ScreenHeight = 180; const string Title = "Micronona"; const int Scale = 3; string? runFile = null; for (int i = 0; i < args.Length - 1; i++) if (args[i] == "--run") { runFile = args[i + 1]; break; } // ------------------------------------------------------------------------- // 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"); } var mem = new MemoryModel(); var diskManager = new DiskManager(); var micrononaRenderer = new MicrononaRenderer(mem); var consoleHelper = new ConsoleHelper(mem); var cpu = new Cpu6809(mem, consoleHelper); var inputInterpreter = new InputInterpreter(mem, consoleHelper, diskManager, cpu); // 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 ); // " 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 + 35 * MemoryModel.FontGlyphHeight, 0x00, 0x034, 0x34, 0x7E, 0x34, 0x7E, 0x34, 0x34, 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 ); // * 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 ); // / mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 47 * MemoryModel.FontGlyphHeight, 0x00, 0x04, 0x0C, 0x08, 0x18, 0x10, 0x30, 0x20, 0x00, 0x00 ); // 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 ); // 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 ); // 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 ); // F mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 70 * MemoryModel.FontGlyphHeight, 0x00, 0x7E, 0x60, 0x60, 0x7C, 0x60, 0x60, 0x60, 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 ); // J mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 74 * MemoryModel.FontGlyphHeight, 0x00, 0x06, 0x06, 0x06, 0x06, 0x06, 0x66, 0x3C, 0x00, 0x00 ); // K mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 75 * MemoryModel.FontGlyphHeight, 0x00, 0x66, 0x6C, 0x78, 0x70, 0x78, 0x6C, 0x66, 0x00, 0x00 ); // 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 ); // Q mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 81 * MemoryModel.FontGlyphHeight, 0x00, 0x3C, 0x66, 0x66, 0x66, 0x66, 0x6E, 0x3C, 0x06, 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 ); // 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 ); // V mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 86 * MemoryModel.FontGlyphHeight, 0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x3C, 0x18, 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 ); // Y mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 89 * MemoryModel.FontGlyphHeight, 0x00, 0x66, 0x66, 0x3C, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00 ); // Z mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 90 * MemoryModel.FontGlyphHeight, 0x00, 0x7E, 0x06, 0x0C, 0x18, 0x30, 0x60, 0x7E, 0x00, 0x00 ); // _ mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 95 * MemoryModel.FontGlyphHeight, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 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 ); // 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 ); // f mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 102 * MemoryModel.FontGlyphHeight, 0x00, 0x0C, 0x18, 0x18, 0x3C, 0x18, 0x18, 0x18, 0x18, 0x00 ); // h mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 104 * MemoryModel.FontGlyphHeight, 0x00, 0x60, 0x60, 0x60, 0x7C, 0x66, 0x66, 0x66, 0x00, 0x00 ); // 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 ); // j mem.WriteFlat(MemoryModel.FontBankIndex * MemoryModel.BankSize + 106 * MemoryModel.FontGlyphHeight, 0x00, 0x18, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x30, 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 ); // 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 ); // ------------------------------------------------------------------------- // 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(); cpu.StartThread(); inputInterpreter.StartThread(); // ------------------------------------------------------------------------- // --run : load and execute file from stick, quit after 5 seconds // ------------------------------------------------------------------------- long runStartTick = 0; if (runFile != null) { var deadline = Environment.TickCount64 + 3000; while (diskManager.MountPath == null && Environment.TickCount64 < deadline) Thread.Sleep(50); if (diskManager.MountPath == null) { Console.Error.WriteLine($"--run: no Micronona stick mounted"); inputInterpreter.StopThread(); cpu.StopThread(); SDL.SDL_DestroyTexture(texture); SDL.SDL_DestroyRenderer(renderer); SDL.SDL_DestroyWindow(window); SDL.SDL_Quit(); return 1; } var filePath = Path.Combine(diskManager.MountPath, runFile.ToUpperInvariant()); if (!File.Exists(filePath)) { Console.Error.WriteLine($"--run: file not found on stick: {runFile}"); inputInterpreter.StopThread(); cpu.StopThread(); SDL.SDL_DestroyTexture(texture); SDL.SDL_DestroyRenderer(renderer); SDL.SDL_DestroyWindow(window); SDL.SDL_Quit(); return 1; } inputInterpreter.InterpretInput($"LOAD \"{runFile}\""); inputInterpreter.InterpretInput("RUN"); runStartTick = Environment.TickCount64; } // ------------------------------------------------------------------------- // 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; 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(); cpu.Stop(); break; } if (!inputInterpreter.IsRunning || inputInterpreter.IsWaitingForInput) { 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; 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)) { unsafe { byte ascii = e.text.text[0]; if (ascii >= 32 && ascii < 127) consoleHelper.WriteText(((char)ascii).ToString()); } } } scrollLock.Refresh(); // --- 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); mem.TickFrame(); if (runStartTick > 0 && Environment.TickCount64 - runStartTick >= 5000) running = false; } // ------------------------------------------------------------------------- // Cleanup // ------------------------------------------------------------------------- inputInterpreter.StopThread(); cpu.StopThread(); SDL.SDL_DestroyTexture(texture); SDL.SDL_DestroyRenderer(renderer); SDL.SDL_DestroyWindow(window); SDL.SDL_Quit(); return 0;