Skip to content

Instantly share code, notes, and snippets.

@marcominerva
Last active November 12, 2026 17:02
Show Gist options
  • Select an option

  • Save marcominerva/5bfecdc5c458306abd0d7f09cc53443c to your computer and use it in GitHub Desktop.

Select an option

Save marcominerva/5bfecdc5c458306abd0d7f09cc53443c to your computer and use it in GitHub Desktop.
Gorilla.bas
#!/usr/bin/env dotnet
#:sdk Microsoft.NET.Sdk
#:property OutputType=Exe
#:property TargetFramework=net11.0
#:property ImplicitUsings=enable
#:property Nullable=enable
#:property AllowUnsafeBlocks=true
#:property PublishAot=false
#:package Raylib-cs@8.1.0
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Globalization;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Text;
using Raylib_cs;
Game.Run();
/// <summary>
/// Faithful 1:1 port of GORILLA.BAS (QBasic, 1991) running in a Raylib window.
/// The BASIC SCREEN 9 framebuffer is emulated at 640x350 with the EGA palette;
/// the original PALETTE/LINE/CIRCLE/PAINT/POINT/GET/PUT primitives are reproduced
/// in <see cref="QbScreen"/>. Game logic runs on a worker thread that calls those
/// primitives just like the original subroutines do.
/// </summary>
internal static class Game
{
// QBasic constants (identical names/values to the original).
private const int TRUE = -1;
private const int FALSE = 0;
private const int HITSELF = 1;
private const int BACKATTR = 0;
private const int OBJECTCOLOR = 1;
private const int WINDOWCOLOR = 14;
private const int SUNATTR = 3;
private const int SUNHAPPY = FALSE;
private const int SUNSHOCK = TRUE;
private const int RIGHTUP = 1;
private const int LEFTUP = 2;
private const int ARMSDOWN = 3;
// Globals (DIM SHARED ...).
private const int Mode = 9;
private const int ScrWidth = 640;
private const int ScrHeight = 350;
private const int GHeight = 25;
private const int SunHt = 39;
private const int MaxCol = 80;
private const int ExplosionColor = 2;
private const int BackColor = 1;
private const double Pi = Math.PI;
private static int _wind;
private static double _gravity = 9.8;
private static bool _sunHit;
private static int _lastBuilding;
private static readonly int[] _gorillaX = new int[3];
private static readonly int[] _gorillaY = new int[3];
private static QbSprite? _gorD, _gorL, _gorR;
// Random with seeded behaviour like RANDOMIZE TIMER.
private static Random _rng = new();
// Input pipeline from Raylib thread to game thread.
private static readonly BlockingCollection<int> _keyQueue = [with(new ConcurrentQueue<int>())];
// Codes above 255 stand for the two-character INKEY$ strings (CHR$(0) + scan code) of extended keys:
// they are never valid input, but they still count as "any key" and make GetNum beep.
private const int ExtendedKey = 0x100;
private static readonly (KeyboardKey Key, int Code)[] _specialKeys =
[
(KeyboardKey.Enter, '\r'),
(KeyboardKey.KpEnter, '\r'),
(KeyboardKey.Backspace, '\b'),
(KeyboardKey.Escape, 27),
(KeyboardKey.Tab, '\t'),
(KeyboardKey.Up, ExtendedKey + 72),
(KeyboardKey.Down, ExtendedKey + 80),
(KeyboardKey.Left, ExtendedKey + 75),
(KeyboardKey.Right, ExtendedKey + 77),
(KeyboardKey.Home, ExtendedKey + 71),
(KeyboardKey.End, ExtendedKey + 79),
(KeyboardKey.PageUp, ExtendedKey + 73),
(KeyboardKey.PageDown, ExtendedKey + 81),
(KeyboardKey.Insert, ExtendedKey + 82),
(KeyboardKey.Delete, ExtendedKey + 83),
(KeyboardKey.F1, ExtendedKey + 59),
(KeyboardKey.F2, ExtendedKey + 60),
(KeyboardKey.F3, ExtendedKey + 61),
(KeyboardKey.F4, ExtendedKey + 62),
(KeyboardKey.F5, ExtendedKey + 63),
(KeyboardKey.F6, ExtendedKey + 64),
(KeyboardKey.F7, ExtendedKey + 65),
(KeyboardKey.F8, ExtendedKey + 66),
(KeyboardKey.F9, ExtendedKey + 67),
(KeyboardKey.F10, ExtendedKey + 68),
(KeyboardKey.F11, ExtendedKey + 133),
(KeyboardKey.F12, ExtendedKey + 134),
];
public static void Run()
{
Raylib.SetConfigFlags(ConfigFlags.ResizableWindow);
const int scale = 2;
Raylib.InitWindow(ScrWidth * scale, ScrHeight * scale, "QBasic Gorillas (C# / Raylib)");
Raylib.SetExitKey(KeyboardKey.Null); // ESC is an ordinary key in the original, not "quit".
Raylib.ToggleBorderlessWindowed(); // Start full screen; Alt+Enter switches back to a window.
Raylib.SetTargetFPS(60);
Audio.Initialize();
var fbImage = Raylib.GenImageColor(ScrWidth, ScrHeight, Color.Black);
var tex = Raylib.LoadTextureFromImage(fbImage);
Raylib.UnloadImage(fbImage);
var rgba = new byte[ScrWidth * ScrHeight * 4];
Thread gameThread = new(GameLoop) { IsBackground = true, Name = "Gorilla-Logic" };
gameThread.Start();
while (!Raylib.WindowShouldClose() && !_shouldQuit)
{
// Printable characters, space included, come from GetCharPressed.
int key;
while ((key = Raylib.GetCharPressed()) > 0)
{
_keyQueue.Add(key);
}
var altDown = Raylib.IsKeyDown(KeyboardKey.LeftAlt) || Raylib.IsKeyDown(KeyboardKey.RightAlt);
if (altDown && (Raylib.IsKeyPressed(KeyboardKey.Enter) || Raylib.IsKeyPressed(KeyboardKey.KpEnter)))
{
Raylib.ToggleBorderlessWindowed();
}
// Control and extended keys, with typematic auto-repeat as INKEY$ sees them.
foreach (var (k, code) in _specialKeys)
{
if (altDown && k is KeyboardKey.Enter or KeyboardKey.KpEnter)
{
continue;
}
if (Raylib.IsKeyPressed(k) || Raylib.IsKeyPressedRepeat(k))
{
_keyQueue.Add(code);
}
}
lock (QbScreen.Pixels)
{
QbScreen.RenderTo(rgba);
}
unsafe
{
fixed (byte* p = rgba)
{
Raylib.UpdateTexture(tex, p);
}
}
float winW = Raylib.GetScreenWidth();
float winH = Raylib.GetScreenHeight();
var fit = Math.Min(winW / ScrWidth, winH / ScrHeight);
var dstW = ScrWidth * fit;
var dstH = ScrHeight * fit;
Raylib.BeginDrawing();
Raylib.ClearBackground(Color.Black);
Raylib.DrawTexturePro(tex,
new Rectangle(0, 0, ScrWidth, ScrHeight),
new Rectangle((winW - dstW) / 2, (winH - dstH) / 2, dstW, dstH),
Vector2.Zero, 0f, Color.White);
Raylib.EndDrawing();
}
Raylib.UnloadTexture(tex);
Audio.Shutdown();
Raylib.CloseWindow();
Environment.Exit(0);
}
private static void ApplyEgaPalette()
{
// SetScreen for Mode = 9: only these attributes are changed, the others keep the EGA defaults.
QbScreen.Palette(0, 1); // background = blue sky
QbScreen.Palette(1, 46); // OBJECTCOLOR = orange (gorillas)
QbScreen.Palette(2, 44); // ExplosionColor = red
QbScreen.Palette(3, 54); // sun = yellow
QbScreen.Palette(5, 7); // building light grey
QbScreen.Palette(6, 4); // building red
QbScreen.Palette(7, 3); // building cyan
QbScreen.Palette(9, 63); // display color
}
// ---------------------- main game loop on worker thread ----------------------
private static volatile bool _shouldQuit;
private static void GameLoop()
{
try
{
Intro();
// Replaces the original "spam:" label: answering "y" to "Play again?" does GOTO spam,
// so names, points and gravity are asked again before the next match.
while (true)
{
var (p1, p2, numGames) = GetInputs();
GorillaIntro(p1, p2);
PlayGame(p1, p2, numGames);
if (!AskPlayAgain())
{
break;
}
}
}
catch (Exception ex)
{
Console.Error.WriteLine(ex);
}
finally
{
_shouldQuit = true;
}
}
// ---------------------- helpers ----------------------
private static int Scl(double n) => (int)Math.Round(n);
private static int FnRan(int x) => _rng.Next(1, x + 1);
private static void Rest(double seconds) => Thread.Sleep((int)(seconds * 1000));
private static int WaitChar() => _keyQueue.Take();
private static void FlushKeys()
{
while (_keyQueue.TryTake(out _))
{
}
}
private static int? PeekChar() => _keyQueue.TryTake(out var c) ? c : null;
private static void DrawAt(int row, int col, string text, byte fg = 7, byte bg = 0)
{
lock (QbScreen.Pixels)
{
QbScreen.Color(fg, bg);
QbScreen.Locate(row, col);
QbScreen.Print(text);
}
}
private static void Center(int row, string text)
{
// BASIC: Col = MaxCol \ 2 : LOCATE Row, Col - (LEN(Text$) / 2 + .5)
// LOCATE rounds its argument, so the ".5" bias makes odd-length strings shift left.
var col = (MaxCol / 2) - Scl((text.Length / 2.0) + 0.5);
if (col < 1)
{
col = 1;
}
DrawAt(row, col, text, QbScreen.ForeColor, QbScreen.BackColor);
}
/// <summary>
/// Mirrors BASIC <c>SUB SparklePause</c>: animates the flashing asterisk border used on the
/// intro and game-over screens until the player presses a key.
/// </summary>
private static void SparklePause()
{
const string Pattern = "* * * * * * * * * * * * * * * * * ";
lock (QbScreen.Pixels)
{
QbScreen.Color(4, 0);
}
FlushKeys();
while (PeekChar() is null)
{
for (var a = 1; a <= 5; a++)
{
DrawAt(1, 1, Pattern.Substring(a - 1, 80), 4, 0);
DrawAt(22, 1, Pattern.Substring(5 - a, 80), 4, 0);
for (var b = 2; b <= 21; b++)
{
var s = (a + b) % 5 == 1 ? "*" : " ";
DrawAt(b, 80, s, 4, 0);
DrawAt(23 - b, 1, s, 4, 0);
}
Rest(0.05);
if (PeekChar() is not null)
{
return;
}
}
}
}
// ---------------------- BASIC subs ported 1:1 ----------------------
private static void Intro()
{
lock (QbScreen.Pixels)
{
QbScreen.Cls();
QbScreen.Color(15, 0);
}
Center(4, "Q B a s i c G O R I L L A S");
lock (QbScreen.Pixels)
{
QbScreen.Color(7, 0);
}
Center(6, "Copyright (C) Microsoft Corporation 1990");
Center(8, "Your mission is to hit your opponent with the exploding");
Center(9, "banana by varying the angle and power of your throw, taking");
Center(10, "into account wind speed, gravity, and the city skyline.");
Center(11, "The wind speed is shown by a directional arrow at the bottom");
Center(12, "of the playing field, its length relative to its strength.");
Center(24, "Press any key to continue");
Audio.Play("MBT160O1L8CDEDCDL4ECC");
SparklePause();
}
private static (string p1, string p2, int numGames) GetInputs()
{
lock (QbScreen.Pixels)
{
QbScreen.Color(7, 0);
QbScreen.Cls();
}
var p1 = ReadLine(8, 15, "Name of Player 1 (Default = 'Player 1'): ");
p1 = p1.Length == 0 ? "Player 1" : p1[..Math.Min(p1.Length, 10)];
var p2 = ReadLine(10, 15, "Name of Player 2 (Default = 'Player 2'): ");
p2 = p2.Length == 0 ? "Player 2" : p2[..Math.Min(p2.Length, 10)];
int numGames;
string game;
do
{
DrawAt(12, 56, new string(' ', 25));
game = ReadLine(12, 13, "Play to how many total points (Default = 3)? ").Trim();
// NumGames is an INTEGER (DEFINT A-Z): the assignment rounds, like CINT.
numGames = (int)Math.Round(Val(game[..Math.Min(game.Length, 2)]));
} while (!((numGames > 0 && game.Length < 3) || game.Length == 0));
if (numGames == 0)
{
numGames = 3;
}
string grav;
do
{
DrawAt(14, 53, new string(' ', 28));
grav = ReadLine(14, 17, "Gravity in Meters/Sec (Earth = 9.8)? ").Trim();
_gravity = Val(grav);
} while (!(_gravity > 0 || grav.Length == 0));
if (_gravity == 0)
{
_gravity = 9.8;
}
return (p1, p2, numGames);
}
/// <summary>
/// Emulates LINE INPUT / INPUT: up to 255 characters, echoed from the current position and wrapped
/// at the right edge of the 80-column text screen, with the blinking text-mode underline cursor
/// (VGA toggles it every 8 frames at 70 Hz). Truncation is left to the caller, as in the original.
/// </summary>
private static string ReadLine(int row, int col, string prompt)
{
const int maxLength = 255;
const int cursorBlinkMs = 8 * 1000 / 70;
DrawAt(row, col, prompt);
var start = ((row - 1) * MaxCol) + col - 1 + prompt.Length;
var buf = "";
var cursorOn = true;
while (true)
{
DrawWrapped(start, buf + (cursorOn ? "_ " : " "));
if (!_keyQueue.TryTake(out var k, cursorBlinkMs))
{
cursorOn = !cursorOn;
continue;
}
cursorOn = true;
if (k == '\r')
{
DrawWrapped(start, buf + " ");
return buf;
}
if (k == '\b')
{
if (buf.Length > 0)
{
buf = buf[..^1];
}
}
else if (k is >= 32 and < 127 && buf.Length < maxLength)
{
buf += (char)k;
}
}
}
private static void DrawWrapped(int offset, string text)
{
for (var i = 0; i < text.Length; i++)
{
var pos = offset + i;
if (pos >= MaxCol * 25)
{
break;
}
DrawAt((pos / MaxCol) + 1, (pos % MaxCol) + 1, text[i].ToString());
}
}
private static double GetNum(int row, int col)
{
var buf = "";
FlushKeys(); // BASIC: WHILE INKEY$ <> "": WEND
while (true)
{
DrawAt(row, col, buf + "_ ", fg: 15);
var k = WaitChar();
if (k is >= '0' and <= '9')
{
buf += (char)k;
}
else if (k == '.' && !buf.Contains('.'))
{
buf += '.';
}
else if (k == '\b' && buf.Length > 0)
{
buf = buf[..^1];
}
else if (k == '\r')
{
var v = Val(buf);
if (v <= 360)
{
DrawAt(row, col, buf + " ", fg: 15);
return v;
}
buf = "";
}
else if (k != '\b')
{
Audio.Beep();
}
}
}
/// <summary>
/// Mirrors BASIC <c>VAL</c>: blanks are ignored, the longest leading numeric prefix is converted
/// (so "3a" is 3) and a string without one, such as "" or ".", evaluates to 0.
/// </summary>
private static double Val(string s)
{
var t = s.Replace(" ", "").Replace("\t", "").Replace("\n", "");
var i = 0;
if (i < t.Length && t[i] is '+' or '-')
{
i++;
}
var digits = 0;
while (i < t.Length && char.IsAsciiDigit(t[i]))
{
i++;
digits++;
}
if (i < t.Length && t[i] == '.')
{
i++;
while (i < t.Length && char.IsAsciiDigit(t[i]))
{
i++;
digits++;
}
}
if (digits == 0)
{
return 0;
}
var end = i;
if (i < t.Length && t[i] is 'E' or 'e' or 'D' or 'd')
{
var j = i + 1;
if (j < t.Length && t[j] is '+' or '-')
{
j++;
}
var expStart = j;
while (j < t.Length && char.IsAsciiDigit(t[j]))
{
j++;
}
if (j > expStart)
{
end = j;
}
}
var number = t[..end].Replace('D', 'E').Replace('d', 'E');
return double.TryParse(number, NumberStyles.Float, CultureInfo.InvariantCulture, out var v) ? v : 0;
}
private static void PlayGame(string p1, string p2, int numGames)
{
// EGA palette + gorilla sprites are already installed by GorillaIntro.
var totalWins = new int[3];
var j = 1;
for (var game = 1; game <= numGames; game++)
{
lock (QbScreen.Pixels)
{
QbScreen.Cls();
}
_rng = new Random();
MakeCityScape();
PlaceGorillas();
DoSun(SUNHAPPY);
var hit = false;
while (!hit)
{
j = 1 - j;
// SCREEN 9 default foreground (15): the original never sets COLOR in graphics mode.
DrawAt(1, 1, p1, 15, 0);
DrawAt(1, MaxCol - 1 - p2.Length, p2, 15, 0);
Center(23, totalWins[1] + ">Score<" + totalWins[2]);
var tosser = j + 1;
_sunHit = false;
var playerHit = DoShot(tosser, _gorillaX[tosser], _gorillaY[tosser]);
if (playerHit != 0)
{
hit = true;
var winner = playerHit == tosser ? 3 - tosser : tosser;
if (playerHit == tosser) // self-hit: opponent gets the point
{
totalWins[3 - tosser]++;
}
else
{
totalWins[tosser]++;
}
VictoryDance(winner);
}
if (_sunHit)
{
DoSun(SUNHAPPY);
}
}
// SLEEP 1: ends after one second or as soon as a key is pressed (the key stays in the buffer).
var sleepEnd = Environment.TickCount64 + 1000;
while (Environment.TickCount64 < sleepEnd && _keyQueue.Count == 0)
{
Thread.Sleep(10);
}
}
lock (QbScreen.Pixels)
{
QbScreen.Screen(0);
QbScreen.Color(7, 0);
QbScreen.Cls();
}
Center(8, "GAME OVER!");
Center(10, "Score:");
// LOCATE r, 30: PRINT Player$; TAB(50); TotalWins(r): STR$ puts a sign space before positive numbers.
DrawAt(11, 30, p1);
DrawAt(11, 50, $" {totalWins[1]}");
DrawAt(12, 30, p2);
DrawAt(12, 50, $" {totalWins[2]}");
Center(24, "Press any key to continue");
SparklePause();
lock (QbScreen.Pixels)
{
QbScreen.Color(7, 0);
QbScreen.Cls();
}
}
/// <summary>
/// Mirrors BASIC <c>SUB GorillaIntro</c>: shows the V/P menu, captures the gorilla
/// poses on a clean canvas, and (only when 'V' is pressed) plays the "STARRING:"
/// title screen with the dancing gorillas before returning to the main game flow.
/// </summary>
private static void GorillaIntro(string player1, string player2)
{
// Menu prompt is drawn over the previous SCREEN 0 text-mode background.
DrawAt(16, 34, "--------------");
DrawAt(18, 34, "V = View Intro");
DrawAt(19, 34, "P = Play Game");
DrawAt(21, 35, "Your Choice?");
// As in the original, any key continues (type-ahead included): only V (either case) shows the intro.
var choice = char.ToUpperInvariant((char)WaitChar());
// SCREEN Mode: SetScreen. Switch to SCREEN 9 and capture the three gorilla poses.
lock (QbScreen.Pixels)
{
QbScreen.Screen(Mode);
}
ApplyEgaPalette();
CaptureGorillaSprites();
if (choice != 'V')
{
return;
}
// STARRING screen: two gorillas centered, names above, animated arm waves.
const int x = 278;
const int y = 175;
lock (QbScreen.Pixels)
{
QbScreen.Color(15, 0); // attr 0 is mapped to blue sky by ApplyEgaPalette
QbScreen.Cls();
}
Center(2, "Q B A S I C G O R I L L A S");
Center(5, " STARRING: ");
Center(7, player1 + " AND " + player2);
lock (QbScreen.Pixels)
{
QbScreen.Put(x - 13, y, _gorD!, PutMode.Pset);
QbScreen.Put(x + 47, y, _gorD!, PutMode.Pset);
}
Rest(1.0);
// The tunes inherit MB from Intro, so each PLAY returns as soon as its notes fit in the
// 32-note background buffer: that is what sets the pace of the poses, as in the original.
DrawDancers(x, y, swapped: false);
Audio.Play("t120o1l16b9n0baan0bn0bn0baaan0b9n0baan0b");
Rest(0.3);
DrawDancers(x, y, swapped: true);
Audio.Play("o2l16e-9n0e-d-d-n0e-n0e-n0e-d-d-d-n0e-9n0e-d-d-n0e-");
Rest(0.3);
DrawDancers(x, y, swapped: false);
Audio.Play("o2l16g-9n0g-een0g-n0g-n0g-eeen0g-9n0g-een0g-");
Rest(0.3);
DrawDancers(x, y, swapped: true);
Audio.Play("o2l16b9n0baan0g-n0g-n0g-eeen0o1b9n0baan0b");
Rest(0.3);
for (var i = 1; i <= 4; i++)
{
DrawDancers(x, y, swapped: false);
Audio.Play("T160O0L32EFGEFDC");
Rest(0.1);
DrawDancers(x, y, swapped: true);
Audio.Play("T160O0L32EFGEFDC");
Rest(0.1);
}
}
/// <summary>Draws the two intro gorillas, optionally with their raised arms swapped.</summary>
private static void DrawDancers(int x, int y, bool swapped)
{
var (left, right) = swapped ? (_gorR!, _gorL!) : (_gorL!, _gorR!);
lock (QbScreen.Pixels)
{
QbScreen.Put(x - 13, y, left, PutMode.Pset);
QbScreen.Put(x + 47, y, right, PutMode.Pset);
}
}
/// <summary>Mirrors the BASIC "Would you like to play again?" prompt after <c>EndGame</c>.</summary>
private static bool AskPlayAgain()
{
lock (QbScreen.Pixels)
{
QbScreen.Color(7, 0);
QbScreen.Cls();
}
DrawAt(11, 24, "Would you like to play again?", fg: 5);
FlushKeys();
while (true)
{
var c = WaitChar();
var ch = char.ToLowerInvariant((char)c);
if (ch == 'y')
{
lock (QbScreen.Pixels)
{
QbScreen.Color(7, 0);
QbScreen.Cls();
}
return true;
}
if (ch == 'n')
{
lock (QbScreen.Pixels)
{
QbScreen.Color(7, 0);
QbScreen.Cls();
}
return false;
}
}
}
private static void CaptureGorillaSprites()
{
var x = 278;
var y = 175;
lock (QbScreen.Pixels)
{
QbScreen.Cls();
DrawGorilla(x, y, ARMSDOWN);
_gorD = QbScreen.Get(x - Scl(15), y - Scl(1), x + Scl(14), y + Scl(28));
QbScreen.Cls();
DrawGorilla(x, y, LEFTUP);
_gorL = QbScreen.Get(x - Scl(15), y - Scl(1), x + Scl(14), y + Scl(28));
QbScreen.Cls();
DrawGorilla(x, y, RIGHTUP);
_gorR = QbScreen.Get(x - Scl(15), y - Scl(1), x + Scl(14), y + Scl(28));
QbScreen.Cls();
}
}
private static void ClearRect(int x1, int y1, int x2, int y2) => QbScreen.Line(x1, y1, x2, y2, BACKATTR, 'F');
private static void MakeCityScape()
{
// Set the sloping trend.
var slope = FnRan(6);
var newHt = slope switch
{
1 => 15,
2 => 130,
6 => 130,
_ => 15
};
const int bottomLine = 335;
const int htInc = 10;
const int defBWidth = 37;
const int randomHeight = 120;
const int wWidth = 3;
const int wHeight = 6;
const int wDifV = 15;
const int wDifh = 10;
var maxHeight = 0;
// BCoor(0..30): we just need x coords for placing gorillas.
var bx = new int[32];
var by = new int[32];
var curBuilding = 1;
var x = 2;
do
{
switch (slope)
{
case 1: newHt += htInc; break;
case 2: newHt -= htInc; break;
// The original has a separate CASE 4 after CASE 3 TO 5, but SELECT CASE stops at
// the first match, so slope 4 always follows this branch.
case 3:
case 4:
case 5:
if (x > ScrWidth / 2)
{
newHt -= 2 * htInc;
}
else
{
newHt += 2 * htInc;
}
break;
}
var bWidth = FnRan(defBWidth) + defBWidth;
if (x + bWidth > ScrWidth)
{
bWidth = ScrWidth - x - 2;
}
var bHeight = FnRan(randomHeight) + newHt;
if (bHeight < htInc)
{
bHeight = htInc;
}
if (bottomLine - bHeight <= maxHeight + GHeight)
{
bHeight = maxHeight + GHeight - 5;
}
bx[curBuilding] = x;
by[curBuilding] = bottomLine - bHeight;
var buildingColor = FnRan(3) + 4; // 5..7
lock (QbScreen.Pixels)
{
QbScreen.Line(x - 1, bottomLine + 1, x + bWidth + 1, bottomLine - bHeight - 1, BACKATTR, 'B');
QbScreen.Line(x, bottomLine, x + bWidth, bottomLine - bHeight, buildingColor, 'F');
var c = x + 3;
do
{
for (var i = bHeight - 3; i >= 7; i -= wDifV)
{
var winColr = FnRan(4) == 1 ? 8 : WINDOWCOLOR;
QbScreen.Line(c, bottomLine - i, c + wWidth, bottomLine - i + wHeight, winColr, 'F');
}
c += wDifh;
} while (c < x + bWidth - 3);
}
// Mirrors the implicit per-building delay of the BASIC interpreter:
// each building (and its windows) was drawn with separate LINE statements,
// producing a visible left-to-right "growing skyline" effect.
Rest(0.05);
x += bWidth + 2;
curBuilding++;
} while (x <= ScrWidth - htInc);
_lastBuilding = curBuilding - 1;
_bx = bx;
_by = by;
// Wind
_wind = FnRan(10) - 5;
if (FnRan(3) == 1)
{
_wind += _wind > 0 ? FnRan(10) : -FnRan(10);
}
if (_wind != 0)
{
var windLine = _wind * 3 * (ScrWidth / 320);
lock (QbScreen.Pixels)
{
QbScreen.Line(ScrWidth / 2, ScrHeight - 5, (ScrWidth / 2) + windLine, ScrHeight - 5, ExplosionColor);
var arrowDir = _wind > 0 ? -2 : 2;
QbScreen.Line((ScrWidth / 2) + windLine, ScrHeight - 5, (ScrWidth / 2) + windLine + arrowDir, ScrHeight - 5 - 2, ExplosionColor);
QbScreen.Line((ScrWidth / 2) + windLine, ScrHeight - 5, (ScrWidth / 2) + windLine + arrowDir, ScrHeight - 5 + 2, ExplosionColor);
}
}
}
private static int[] _bx = [];
private static int[] _by = [];
private static void PlaceGorillas()
{
const int xAdj = 14;
const int yAdj = 30;
for (var i = 1; i <= 2; i++)
{
var bNum = i == 1 ? FnRan(2) + 1 : _lastBuilding - FnRan(2);
if (bNum < 1)
{
bNum = 1;
}
if (bNum >= _lastBuilding)
{
bNum = _lastBuilding - 1;
}
var bWidth = _bx[bNum + 1] - _bx[bNum];
// BASIC uses "/" (floating-point division) and then rounds half-to-even when storing
// into the INTEGER array, which matches the default mode of Math.Round.
_gorillaX[i] = (int)Math.Round(_bx[bNum] + (bWidth / 2.0) - xAdj);
_gorillaY[i] = _by[bNum] - yAdj;
lock (QbScreen.Pixels)
{
QbScreen.Put(_gorillaX[i], _gorillaY[i], _gorD!, PutMode.Pset);
}
}
}
private static void DoSun(int mouth)
{
int x = ScrWidth / 2, y = Scl(25);
lock (QbScreen.Pixels)
{
QbScreen.Line(x - Scl(22), y - Scl(18), x + Scl(22), y + Scl(18), BACKATTR, 'F');
QbScreen.Circle(x, y, Scl(12), SUNATTR);
QbScreen.Paint(x, y, SUNATTR);
QbScreen.Line(x - Scl(20), y, x + Scl(20), y, SUNATTR);
QbScreen.Line(x, y - Scl(15), x, y + Scl(15), SUNATTR);
QbScreen.Line(x - Scl(15), y - Scl(10), x + Scl(15), y + Scl(10), SUNATTR);
QbScreen.Line(x - Scl(15), y + Scl(10), x + Scl(15), y - Scl(10), SUNATTR);
QbScreen.Line(x - Scl(8), y - Scl(13), x + Scl(8), y + Scl(13), SUNATTR);
QbScreen.Line(x - Scl(8), y + Scl(13), x + Scl(8), y - Scl(13), SUNATTR);
QbScreen.Line(x - Scl(18), y - Scl(5), x + Scl(18), y + Scl(5), SUNATTR);
QbScreen.Line(x - Scl(18), y + Scl(5), x + Scl(18), y - Scl(5), SUNATTR);
if (mouth != FALSE)
{
QbScreen.Circle(x, y + Scl(5), Scl(2.9), 0);
QbScreen.Paint(x, y + Scl(5), 0, 0);
}
else
{
QbScreen.Circle(x, y, Scl(8), 0, 210 * Pi / 180, 330 * Pi / 180);
}
QbScreen.Circle(x - 3, y - 2, 1, 0);
QbScreen.Circle(x + 3, y - 2, 1, 0);
QbScreen.PSet(x - 3, y - 2, 0);
QbScreen.PSet(x + 3, y - 2, 0);
}
}
private static void DrawGorilla(int x, int y, int arms)
{
// head
QbScreen.Line(x - Scl(4), y, x + Scl(2.9), y + Scl(6), OBJECTCOLOR, 'F');
QbScreen.Line(x - Scl(5), y + Scl(2), x + Scl(4), y + Scl(4), OBJECTCOLOR, 'F');
// brow
QbScreen.Line(x - Scl(3), y + Scl(2), x + Scl(2), y + Scl(2), 0);
// nose (EGA only)
for (var i = -2; i <= -1; i++)
{
QbScreen.PSet(x + i, y + 4, 0);
QbScreen.PSet(x + i + 3, y + 4, 0);
}
// neck
QbScreen.Line(x - Scl(3), y + Scl(7), x + Scl(2), y + Scl(7), OBJECTCOLOR);
// body
QbScreen.Line(x - Scl(8), y + Scl(8), x + Scl(6.9), y + Scl(14), OBJECTCOLOR, 'F');
QbScreen.Line(x - Scl(6), y + Scl(15), x + Scl(4.9), y + Scl(20), OBJECTCOLOR, 'F');
// legs
for (var i = 0; i <= 4; i++)
{
QbScreen.Circle(x + Scl(i), y + Scl(25), Scl(10), OBJECTCOLOR, 3 * Pi / 4, 9 * Pi / 8);
QbScreen.Circle(x + Scl(-6) + Scl(i - 0.1), y + Scl(25), Scl(10), OBJECTCOLOR, 15 * Pi / 8, Pi / 4);
}
// chest
QbScreen.Circle(x - Scl(4.9), y + Scl(10), Scl(4.9), 0, 3 * Pi / 2, 0);
QbScreen.Circle(x + Scl(4.9), y + Scl(10), Scl(4.9), 0, Pi, 3 * Pi / 2);
// arms
for (var i = -5; i <= -1; i++)
{
switch (arms)
{
case RIGHTUP:
QbScreen.Circle(x + Scl(i - 0.1), y + Scl(14), Scl(9), OBJECTCOLOR, 3 * Pi / 4, 5 * Pi / 4);
QbScreen.Circle(x + Scl(4.9) + Scl(i), y + Scl(4), Scl(9), OBJECTCOLOR, 7 * Pi / 4, Pi / 4);
break;
case LEFTUP:
QbScreen.Circle(x + Scl(i - 0.1), y + Scl(4), Scl(9), OBJECTCOLOR, 3 * Pi / 4, 5 * Pi / 4);
QbScreen.Circle(x + Scl(4.9) + Scl(i), y + Scl(14), Scl(9), OBJECTCOLOR, 7 * Pi / 4, Pi / 4);
break;
case ARMSDOWN:
QbScreen.Circle(x + Scl(i - 0.1), y + Scl(14), Scl(9), OBJECTCOLOR, 3 * Pi / 4, 5 * Pi / 4);
QbScreen.Circle(x + Scl(4.9) + Scl(i), y + Scl(14), Scl(9), OBJECTCOLOR, 7 * Pi / 4, Pi / 4);
break;
}
}
}
private static int DoShot(int playerNum, int x, int y)
{
var locateCol = playerNum == 1 ? 1 : 66;
DrawAt(2, locateCol, "Angle:", fg: 15);
var angle = GetNum(2, locateCol + 7);
DrawAt(3, locateCol, "Velocity:", fg: 15);
// Velocity is an INTEGER in the original (DEFINT A-Z): QBasic rounds the value half-to-even,
// which is also the default mode of Math.Round.
var velocity = (int)Math.Round(GetNum(3, locateCol + 10));
if (playerNum == 2)
{
angle = 180 - angle;
}
// erase input
for (var i = 1; i <= 4; i++)
{
DrawAt(i, 1, new string(' ', 30));
DrawAt(i, 50, new string(' ', 30));
}
_sunHit = false;
var playerHit = PlotShot(x, y, angle, velocity, playerNum);
return playerHit;
}
private static int PlotShot(int startX, int startY, double angleDeg, int velocity, int playerNum)
{
var angle = angleDeg / 180.0 * Pi;
var initXVel = Math.Cos(angle) * velocity;
var initYVel = Math.Sin(angle) * velocity;
double oldx = startX, oldy = startY;
lock (QbScreen.Pixels)
{
if (playerNum == 1)
{
QbScreen.Put(startX, startY, _gorL!, PutMode.Pset);
}
else
{
QbScreen.Put(startX, startY, _gorR!, PutMode.Pset);
}
}
// Throw sound (BASIC: PLAY "MBo0L32A-L64CL16BL64A+").
Audio.Play("MBo0L32A-L64CL16BL64A+");
Rest(0.1);
lock (QbScreen.Pixels)
{
QbScreen.Put(startX, startY, _gorD!, PutMode.Pset);
}
var adjust = Scl(4);
bool impact = false, shotInSun = false, onScreen = true, needErase = false;
var playerHit = 0;
var pointval = 0;
var oldRot = 0;
double startXPos = startX;
double startYPos = startY - adjust - 3;
int direction;
if (playerNum == 2)
{
startXPos += Scl(25);
direction = Scl(4);
}
else
{
direction = Scl(-4);
}
double t = 0;
double xCur = startX, yCur = startY;
// As in the original, Impact is not set here: the banana is still thrown and usually drops
// onto the thrower, but it can also drift away with low gravity or strong wind. The preset
// pointval only matters if the banana leaves the screen before any POINT check runs.
if (velocity < 2)
{
xCur = startX;
yCur = startY;
pointval = OBJECTCOLOR;
}
while (!impact && onScreen)
{
// BASIC: Rest .02 — but scaled by MachSpeed/SPEEDCONST (~1 on a slow PC, plus
// QBasic interpreter + PUT/GET overhead). On modern hardware 20ms is too quick,
// so we use ~45ms per frame to mirror the perceived pace of the original.
Rest(0.045);
if (needErase)
{
needErase = false;
lock (QbScreen.Pixels)
{
DrawBan(oldx, oldy, oldRot, false);
}
}
xCur = startXPos + (initXVel * t) + (0.5 * (_wind / 5.0) * t * t);
yCur = startYPos + (((-1 * (initYVel * t)) + (0.5 * _gravity * t * t)) * (ScrHeight / 350.0));
if (xCur >= ScrWidth - Scl(10) || xCur <= 3 || yCur >= ScrHeight - 3)
{
onScreen = false;
}
var rot = 0;
if (onScreen && yCur > 0)
{
var lookY = 0;
var lookX = Scl(8 * (2 - playerNum));
do
{
lock (QbScreen.Pixels)
{
pointval = QbScreen.Point(xCur + lookX, yCur + lookY);
}
if (pointval == 0)
{
impact = false;
if (shotInSun)
{
if (Math.Abs((ScrWidth / 2.0) - xCur) > Scl(20) || yCur > SunHt)
{
shotInSun = false;
}
}
}
else if (pointval == SUNATTR && yCur < SunHt)
{
if (!_sunHit)
{
DoSun(SUNSHOCK);
}
_sunHit = true;
shotInSun = true;
}
else
{
impact = true;
}
lookX += direction;
lookY += Scl(6);
} while (!impact && lookX == Scl(4));
if (!shotInSun && !impact)
{
// rot = (t# * 10) MOD 4: MOD rounds its operand to an integer first.
rot = (int)(Math.Round(t * 10) % 4);
lock (QbScreen.Pixels)
{
DrawBan(xCur, yCur, rot, true);
}
needErase = true;
}
oldx = xCur;
oldy = yCur;
oldRot = rot;
}
t += 0.1;
}
if (pointval != OBJECTCOLOR && impact)
{
DoExplosion(xCur + adjust, yCur + adjust);
}
else if (pointval == OBJECTCOLOR)
{
playerHit = ExplodeGorilla(xCur, yCur);
}
return playerHit;
}
private static void DrawBan(double xc, double yc, int r, bool draw)
{
var mode = draw ? PutMode.Pset : PutMode.Xor;
var s = r switch
{
0 => banLeft,
1 => banUp,
2 => banDown,
_ => banRight
};
QbScreen.Put(xc, yc, s, mode);
}
// EGABanana DATA blocks of the original, decoded from the QBasic GET/PUT array format.
private static readonly QbSprite banLeft = DecodeEgaSprite([458758, 202116096, 471604224, 943208448, 943208448, 943208448, 471604224, 202116096, 0]);
private static readonly QbSprite banDown = DecodeEgaSprite([262153, -2134835200, -2134802239, -2130771968, -2130738945, 8323072, 8323199, 4063232, 4063294]);
private static readonly QbSprite banUp = DecodeEgaSprite([262153, 4063232, 4063294, 8323072, 8323199, -2130771968, -2130738945, -2134835200, -2134802239]);
private static readonly QbSprite banRight = DecodeEgaSprite([458758, -1061109760, -522133504, 1886416896, 1886416896, 1886416896, -522133504, -1061109760, 0]);
/// <summary>
/// Decodes a QBasic SCREEN 9 GET array stored as LONGs: a header word with the width in pixels,
/// a header word with the height, then for each row one bit-plane per EGA plane (0..3),
/// each padded to whole bytes with the leftmost pixel in the most significant bit.
/// </summary>
private static QbSprite DecodeEgaSprite(int[] data)
{
var bytes = MemoryMarshal.AsBytes(data.AsSpan());
var width = bytes[0] | (bytes[1] << 8);
var height = bytes[2] | (bytes[3] << 8);
var bytesPerPlane = (width + 7) / 8;
var pixels = new byte[width * height];
for (var y = 0; y < height; y++)
{
for (var x = 0; x < width; x++)
{
var color = 0;
for (var plane = 0; plane < 4; plane++)
{
var b = bytes[4 + (((y * 4) + plane) * bytesPerPlane) + (x / 8)];
if (((b >> (7 - (x % 8))) & 1) != 0)
{
color |= 1 << plane;
}
}
pixels[(y * width) + x] = (byte)color;
}
}
return new QbSprite(width, height, pixels);
}
private static void DoExplosion(double x, double y)
{
// Faithful port of the original BASIC SUB DoExplosion: expanding red circle
// outlines followed by shrinking BACKATTR circle outlines with the same radii, so every
// red pixel is erased. The leftover "debris" are pixels never touched by any ring
// (gaps between the integer-rounded CIRCLE outlines) and keep the building's colour.
Audio.Play("MBO0L32EFGEFDC");
var radius = ScrHeight / 50;
var inc = 0.5;
for (double c = 0; c <= radius; c += inc)
{
lock (QbScreen.Pixels)
{
QbScreen.Circle(x, y, c, ExplosionColor);
}
Rest(0.005);
}
for (double c = radius; c >= 0; c -= inc)
{
lock (QbScreen.Pixels)
{
QbScreen.Circle(x, y, c, BACKATTR);
}
Rest(0.005);
}
}
private static bool IsBuildingPixel(int x, int y)
{
int pv;
lock (QbScreen.Pixels)
{
pv = QbScreen.Point(x, y);
}
return pv is not BACKATTR and not SUNATTR and not OBJECTCOLOR;
}
private static int ExplodeGorilla(double x, double y)
{
int yAdj = Scl(12), xAdj = Scl(5);
double sclX = ScrWidth / 320.0, sclY = ScrHeight / 200.0;
var playerHit = x < ScrWidth / 2.0 ? 1 : 2;
Audio.Play("MBO0L16EFGEFDC");
// The original passes an explicit aspect to every CIRCLE here, as in
// CIRCLE (...), i, ExplosionColor, , , -1.57 . The two empty arguments are the arc
// start/end, so -1.57 is the aspect ratio: the vertical radius is r / 1.57, which is
// what makes the blast a shallow ellipse instead of a near-perfect circle.
const double blastAspect = 1.0 / 1.57;
for (var i = 1; i <= 8 * sclX; i++)
{
lock (QbScreen.Pixels)
{
QbScreen.Circle(_gorillaX[playerHit] + (3.5 * sclX) + xAdj, _gorillaY[playerHit] + (7 * sclY) + yAdj, i, ExplosionColor, aspect: blastAspect);
QbScreen.Line((int)(_gorillaX[playerHit] + (7 * sclX)), Scl(_gorillaY[playerHit] + (9 * sclY) - i),
_gorillaX[playerHit], Scl(_gorillaY[playerHit] + (9 * sclY) - i), ExplosionColor);
}
Rest(0.005);
}
for (var i = 1; i <= 16 * sclX; i++)
{
lock (QbScreen.Pixels)
{
if (i < 8 * sclX)
{
QbScreen.Circle(_gorillaX[playerHit] + (3.5 * sclX) + xAdj, _gorillaY[playerHit] + (7 * sclY) + yAdj, (8 * sclX) + 1 - i, BACKATTR, aspect: blastAspect);
}
QbScreen.Circle(_gorillaX[playerHit] + (3.5 * sclX) + xAdj, _gorillaY[playerHit] + yAdj, i, (i % 2) + 1, aspect: blastAspect);
}
Rest(0.005);
}
for (var i = (int)(24 * sclX); i >= 1; i--)
{
lock (QbScreen.Pixels)
{
QbScreen.Circle(_gorillaX[playerHit] + (3.5 * sclX) + xAdj, _gorillaY[playerHit] + yAdj, i, BACKATTR, aspect: blastAspect);
}
Rest(0.005);
}
return playerHit;
}
private static void VictoryDance(int player)
{
for (var i = 1; i <= 4; i++)
{
lock (QbScreen.Pixels)
{
QbScreen.Put(_gorillaX[player], _gorillaY[player], _gorL!, PutMode.Pset);
}
Audio.Play("MFO0L32EFGEFDC");
Rest(0.2);
lock (QbScreen.Pixels)
{
QbScreen.Put(_gorillaX[player], _gorillaY[player], _gorR!, PutMode.Pset);
}
Audio.Play("MFO0L32EFGEFDC");
Rest(0.2);
}
}
}
/// <summary>
/// Software framebuffer that emulates QBasic SCREEN 9 (640x350, 16-color EGA palette).
/// Implements LINE, CIRCLE (with arc), PAINT (flood fill), POINT, PSET, GET/PUT (PSET/XOR)
/// and a 8x14 BIOS-style text overlay using LOCATE/PRINT semantics.
/// </summary>
internal static class QbScreen
{
public const int Width = 640;
public const int Height = 350;
public const int TextCols = 80;
public const int TextRows = 25;
public const int CharW = 8;
public const int CharH = 14;
// Pixel buffer holds palette indices (0..15).
public static readonly byte[] Pixels = new byte[Width * Height];
// Active EGA palette: maps the 16 logical attributes (0..15) to an EGA 64-color index (0..63).
// Initial QB defaults for SCREEN 9: identity-like mapping but we replicate Gorilla's PALETTE calls explicitly.
private static readonly int[] attrToEga = new int[16];
// EGA 64-color physical palette (RGB 6-bit -> 8-bit).
private static readonly Color[] egaTable = new Color[64];
// BIOS-style 8x14 font (256 glyphs, 14 bytes per glyph, MSB = leftmost pixel).
private static ReadOnlySpan<byte> Font8x14Data => Font8x14.Data;
// Text layer.
private static readonly char[] textChars = new char[TextCols * TextRows];
private static readonly byte[] textFg = new byte[TextCols * TextRows];
private static readonly byte[] textBg = new byte[TextCols * TextRows];
public static int CursorRow = 1;
public static int CursorCol = 1;
public static byte ForeColor = 7;
public static byte BackColor = 0;
// True after SCREEN 9: PRINT draws into the framebuffer, so text is part of the graphics
// (spaces erase what is below and POINT sees the characters), exactly as in the original.
public static bool GraphicsMode;
// VIEW PRINT range.
public static int ViewTop = 1;
public static int ViewBottom = TextRows;
static QbScreen()
{
// EGA 64-color palette: 6-bit value bits (MSB..LSB) = r g b R G B
// where lower-case = low-intensity (0x55) and upper-case = high-intensity (0xAA).
// Final channel = low + high components.
for (var i = 0; i < 64; i++)
{
var r = (((i >> 5) & 1) * 0x55) + (((i >> 2) & 1) * 0xAA);
var g = (((i >> 4) & 1) * 0x55) + (((i >> 1) & 1) * 0xAA);
var b = (((i >> 3) & 1) * 0x55) + (((i >> 0) & 1) * 0xAA);
egaTable[i] = new Color(r, g, b, 255);
}
// Default SCREEN 0/9 attribute mapping: identity-ish CGA-like default palette.
int[] defaults = [0, 1, 2, 3, 4, 5, 20, 7, 56, 57, 58, 59, 60, 61, 62, 63];
for (var i = 0; i < 16; i++)
{
attrToEga[i] = defaults[i];
}
}
public static void Palette(int attr, int egaColor)
{
if ((uint)attr < 16 && (uint)egaColor < 64)
{
attrToEga[attr] = egaColor;
}
}
/// <summary>
/// Mirrors QBasic <c>SCREEN</c>: switches between text mode (<c>SCREEN 0</c>, text kept in a character
/// buffer) and graphics mode (<c>SCREEN 9</c>, PRINT rasterizes glyphs into <see cref="Pixels"/>).
/// Like the real statement it restores the default palette and clears the screen.
/// </summary>
public static void Screen(int mode)
{
GraphicsMode = mode != 0;
ResetPalette();
ForeColor = GraphicsMode ? (byte)15 : (byte)7;
BackColor = 0;
Cls();
}
/// <summary>Restores the default SCREEN 0/9 attribute palette (mirrors QBasic <c>SCREEN 0</c>).</summary>
public static void ResetPalette()
{
int[] defaults = [0, 1, 2, 3, 4, 5, 20, 7, 56, 57, 58, 59, 60, 61, 62, 63];
for (var i = 0; i < 16; i++)
{
attrToEga[i] = defaults[i];
}
}
public static Color AttrToColor(int attr) => egaTable[attrToEga[attr & 15]];
public static void Cls(int viewport = 0)
{
if (viewport == 2)
{
Array.Fill(Pixels, (byte)0);
}
else
{
Array.Fill(Pixels, (byte)0);
Array.Fill(textChars, ' ');
Array.Fill(textFg, ForeColor);
Array.Fill(textBg, BackColor);
CursorRow = 1;
CursorCol = 1;
}
}
public static void PSet(int x, int y, int attr)
{
if ((uint)x < Width && (uint)y < Height)
{
Pixels[(y * Width) + x] = (byte)(attr & 15);
}
}
public static int Point(int x, int y)
{
if ((uint)x < Width && (uint)y < Height)
{
return Pixels[(y * Width) + x];
}
return -1;
}
public static int Point(double x, double y) => Point((int)Math.Round(x), (int)Math.Round(y));
public static void Line(int x1, int y1, int x2, int y2, int attr, char mode = 'L')
{
if (mode is 'B' or 'F')
{
int xa = Math.Min(x1, x2), xb = Math.Max(x1, x2);
int ya = Math.Min(y1, y2), yb = Math.Max(y1, y2);
if (mode == 'F')
{
for (var y = ya; y <= yb; y++)
{
for (var x = xa; x <= xb; x++)
{
PSet(x, y, attr);
}
}
}
else
{
LineRaw(xa, ya, xb, ya, attr);
LineRaw(xa, yb, xb, yb, attr);
LineRaw(xa, ya, xa, yb, attr);
LineRaw(xb, ya, xb, yb, attr);
}
return;
}
LineRaw(x1, y1, x2, y2, attr);
}
public static void Line(double x1, double y1, double x2, double y2, int attr, char mode = 'L')
=> Line((int)Math.Round(x1), (int)Math.Round(y1), (int)Math.Round(x2), (int)Math.Round(y2), attr, mode);
private static void LineRaw(int x0, int y0, int x1, int y1, int attr)
{
int dx = Math.Abs(x1 - x0), sx = x0 < x1 ? 1 : -1;
int dy = -Math.Abs(y1 - y0), sy = y0 < y1 ? 1 : -1;
var err = dx + dy;
while (true)
{
PSet(x0, y0, attr);
if (x0 == x1 && y0 == y1)
{
break;
}
var e2 = 2 * err;
if (e2 >= dy)
{
err += dy;
x0 += sx;
}
if (e2 <= dx)
{
err += dx;
y0 += sy;
}
}
}
/// <summary>
/// QBasic CIRCLE: outline of an ellipse with optional arc start/end (radians, CCW; a negative
/// angle also draws a radius line to that endpoint).
/// </summary>
/// <remarks>
/// This is the integer midpoint-ellipse rasterizer used by GW-BASIC/QBasic (as reproduced by
/// PC-BASIC), not a geometric approximation. Center and radii are rounded the BASIC way
/// (banker's rounding), so concentric outlines drawn with fractional radius steps leave gaps
/// between rings: that is what produces the "debris" pixels of the original DoExplosion.
/// The default <paramref name="aspect"/> is the SCREEN 9 one, 4·350 / (3·640).
/// </remarks>
public static void Circle(double cx, double cy, double radius, int attr, double? startRad = null, double? endRad = null, double? aspect = null)
{
var x0 = (int)Math.Round(cx);
var y0 = (int)Math.Round(cy);
var asp = aspect ?? (4.0 * Height / (3.0 * Width));
radius = Math.Abs(radius);
int rx, ry;
if (asp > 1)
{
ry = (int)Math.Round(radius);
rx = (int)Math.Round(ry / asp);
}
else
{
rx = (int)Math.Round(radius);
ry = (int)Math.Round(rx * asp);
}
if (startRad is null)
{
DrawEllipse(x0, y0, rx, ry, attr, -1, 0, 0, false, -1, 0, 0, false);
return;
}
var stop = endRad ?? (2 * Math.PI);
var (qua0, sx, sy, line0) = GetQuadrantPoint(startRad.Value, rx, ry);
var (qua1, ex, ey, line1) = GetQuadrantPoint(stop, rx, ry);
DrawEllipse(x0, y0, rx, ry, attr, qua0, sx, sy, line0, qua1, ex, ey, line1);
}
private static (int Quadrant, int X, int Y, bool Line) GetQuadrantPoint(double f, int rx, int ry)
{
var line = f < 0;
f = Math.Abs(f);
var octant = Math.Min((int)(f / (Math.PI / 4)), 7);
return (octant / 2, Math.Abs((int)Math.Round(rx * Math.Cos(f))), Math.Abs((int)Math.Round(ry * Math.Sin(f))), line);
}
private static bool QuadrantGt(int q, int x, int y, int x0, int y0) => (q % 2) == 0
? (y != y0 ? y > y0 : x < x0)
: (y != y0 ? y < y0 : x > x0);
private static bool QuadrantGte(int q, int x, int y, int x0, int y0) => (q % 2) == 0
? (y != y0 ? y > y0 : x <= x0)
: (y != y0 ? y < y0 : x >= x0);
private static (int X, int Y) QuadrantToScreen(int q, int cx, int cy, int x, int y) => q switch
{
0 => (cx + x, cy - y),
1 => (cx - x, cy - y),
2 => (cx - x, cy + y),
_ => (cx + x, cy + y),
};
private static void DrawEllipse(int cx, int cy, int rx, int ry, int attr, int qua0, int x0, int y0, bool line0, int qua1, int x1, int y1, bool line1)
{
Span<bool> hidden = stackalloc bool[4];
var isArc = qua0 >= 0;
if (isArc)
{
if (qua0 < qua1 || (qua0 == qua1 && QuadrantGte(qua0, x1, y1, x0, y0)))
{
for (var q = 0; q < 4; q++)
{
hidden[q] = q < qua0 || q > qua1;
}
}
else
{
for (var q = qua1 + 1; q < qua0; q++)
{
hidden[q] = true;
}
}
}
var arcForward = isArc && qua0 == qua1 && QuadrantGte(qua0, x1, y1, x0, y0);
bool IsVisible(int q, int x, int y, ReadOnlySpan<bool> hid)
{
if (!isArc)
{
return true;
}
if (hid[q])
{
return false;
}
if (qua0 != qua1)
{
return !((q == qua0 && QuadrantGt(qua0, x0, y0, x, y)) || (q == qua1 && QuadrantGt(qua1, x, y, x1, y1)));
}
if (q != qua0)
{
return true;
}
var afterStop = QuadrantGt(qua0, x, y, x1, y1);
var beforeStart = QuadrantGt(qua0, x0, y0, x, y);
return arcForward ? !(afterStop || beforeStart) : !(afterStop && beforeStart);
}
void Plot(int x, int y, ReadOnlySpan<bool> hid)
{
for (var q = 0; q < 4; q++)
{
if (IsVisible(q, x, y, hid))
{
var (px, py) = QuadrantToScreen(q, cx, cy, x, y);
PSet(px, py, attr);
}
}
}
long lrx = rx, lry = ry;
var dx = 16 * (1 - (2 * lrx)) * lry * lry;
var dy = 16 * lrx * lrx;
var ddy = 32 * lrx * lrx;
var ddx = 32 * lry * lry;
var err = dx + dy;
int xx = rx, yy = 0;
while (true)
{
Plot(xx, yy, hidden);
var e2 = 2 * err;
if (e2 <= dy)
{
yy++;
dy += ddy;
err += dy;
}
if (e2 >= dx || e2 > dy)
{
xx--;
dx += ddx;
err += dx;
}
if (xx < 0)
{
break;
}
}
// Finish the tip of very flat vertical ellipses.
while (yy < ry)
{
Plot(0, yy, hidden);
yy++;
}
if (line0)
{
var (px, py) = QuadrantToScreen(qua0, cx, cy, x0, y0);
LineRaw(cx, cy, px, py, attr);
}
if (line1)
{
var (px, py) = QuadrantToScreen(qua1, cx, cy, x1, y1);
LineRaw(cx, cy, px, py, attr);
}
}
/// <summary>QBasic PAINT: 4-way flood fill with given color until boundary color is reached.</summary>
public static void Paint(int x, int y, int fillAttr, int? boundaryAttr = null)
{
if ((uint)x >= Width || (uint)y >= Height)
{
return;
}
var boundary = boundaryAttr ?? fillAttr;
var fill = (byte)(fillAttr & 15);
var bnd = (byte)(boundary & 15);
var start = Pixels[(y * Width) + x];
if (start == bnd)
{
return;
}
// PAINT replaces the connected region of NON-boundary pixels with fill color.
Stack<(int x, int y)> stack = new();
stack.Push((x, y));
while (stack.Count > 0)
{
var (px, py) = stack.Pop();
if ((uint)px >= Width || (uint)py >= Height)
{
continue;
}
var idx = (py * Width) + px;
if (Pixels[idx] == bnd || Pixels[idx] == fill)
{
continue;
}
// scan left/right
var xl = px;
while (xl >= 0 && Pixels[(py * Width) + xl] != bnd && Pixels[(py * Width) + xl] != fill)
{
xl--;
}
var xr = px;
while (xr < Width && Pixels[(py * Width) + xr] != bnd && Pixels[(py * Width) + xr] != fill)
{
xr++;
}
for (var xi = xl + 1; xi < xr; xi++)
{
Pixels[(py * Width) + xi] = fill;
if (py > 0)
{
var u = Pixels[((py - 1) * Width) + xi];
if (u != bnd && u != fill)
{
stack.Push((xi, py - 1));
}
}
if (py < Height - 1)
{
var d = Pixels[((py + 1) * Width) + xi];
if (d != bnd && d != fill)
{
stack.Push((xi, py + 1));
}
}
}
}
}
public static void Paint(double x, double y, int fillAttr, int? boundaryAttr = null)
=> Paint((int)Math.Round(x), (int)Math.Round(y), fillAttr, boundaryAttr);
/// <summary>QBasic GET (x1,y1)-(x2,y2), array. We just store rect bounds + raw pixel attrs.</summary>
public static QbSprite Get(int x1, int y1, int x2, int y2)
{
int xa = Math.Min(x1, x2), xb = Math.Max(x1, x2);
int ya = Math.Min(y1, y2), yb = Math.Max(y1, y2);
int w = xb - xa + 1, h = yb - ya + 1;
var data = new byte[w * h];
for (var yi = 0; yi < h; yi++)
{
for (var xi = 0; xi < w; xi++)
{
int sx = xa + xi, sy = ya + yi;
data[(yi * w) + xi] = (uint)sx < Width && (uint)sy < Height ? Pixels[(sy * Width) + sx] : (byte)0;
}
}
return new QbSprite(w, h, data);
}
/// <summary>QBasic PUT with PSET/XOR action.</summary>
public static void Put(int x, int y, QbSprite s, PutMode mode)
{
for (var yi = 0; yi < s.Height; yi++)
{
for (var xi = 0; xi < s.Width; xi++)
{
int dx = x + xi, dy = y + yi;
if ((uint)dx >= Width || (uint)dy >= Height)
{
continue;
}
var idx = (dy * Width) + dx;
var src = s.Data[(yi * s.Width) + xi];
Pixels[idx] = mode == PutMode.Pset ? src : (byte)((Pixels[idx] ^ src) & 15);
}
}
}
public static void Put(double x, double y, QbSprite s, PutMode mode) => Put((int)Math.Round(x), (int)Math.Round(y), s, mode);
// ---- text layer (LOCATE/PRINT) ----
public static void Locate(int row, int col)
{
CursorRow = Math.Clamp(row, 1, TextRows);
CursorCol = Math.Clamp(col, 1, TextCols);
}
public static void Print(string text)
{
foreach (var ch in text)
{
if (ch == '\n')
{
CursorRow++;
CursorCol = 1;
if (CursorRow > TextRows)
{
CursorRow = TextRows;
}
continue;
}
if (CursorCol >= 1 && CursorCol <= TextCols && CursorRow >= 1 && CursorRow <= TextRows)
{
if (GraphicsMode)
{
DrawGlyph(CursorRow, CursorCol, ch);
}
else
{
var idx = ((CursorRow - 1) * TextCols) + (CursorCol - 1);
textChars[idx] = ch;
textFg[idx] = ForeColor;
textBg[idx] = BackColor;
}
}
CursorCol++;
if (CursorCol > TextCols)
{
CursorCol = 1;
CursorRow++;
if (CursorRow > TextRows)
{
CursorRow = TextRows;
}
}
}
}
/// <summary>
/// Graphics-mode PRINT: the 8x14 cell is fully overwritten, set bits with the foreground attribute
/// and clear bits with attribute 0 (in SCREEN 9 the COLOR background only changes palette entry 0).
/// </summary>
private static void DrawGlyph(int row, int col, char ch)
{
var font = Font8x14Data;
var glyphOff = (ch < 256 ? ch : '?') * CharH;
var px0 = (col - 1) * CharW;
var py0 = (row - 1) * CharH;
for (var gy = 0; gy < CharH && py0 + gy < Height; gy++)
{
var bits = font[glyphOff + gy];
var rowBase = ((py0 + gy) * Width) + px0;
for (var gx = 0; gx < CharW; gx++)
{
Pixels[rowBase + gx] = ((bits >> (7 - gx)) & 1) != 0 ? ForeColor : (byte)0;
}
}
}
public static void Color(byte fg, byte? bg = null)
{
ForeColor = (byte)(fg & 15);
if (bg.HasValue)
{
BackColor = (byte)(bg.Value & 15);
}
}
public static void ClearTextRow(int row)
{
if (row is < 1 or > TextRows)
{
return;
}
var start = (row - 1) * TextCols;
for (var i = 0; i < TextCols; i++)
{
textChars[start + i] = ' ';
textFg[start + i] = ForeColor;
textBg[start + i] = BackColor;
}
}
/// <summary>Render the framebuffer + text layer into RGBA pixels.</summary>
public static void RenderTo(byte[] rgba)
{
// 1) graphics layer.
for (var i = 0; i < Pixels.Length; i++)
{
var c = egaTable[attrToEga[Pixels[i]]];
var o = i * 4;
rgba[o] = c.R;
rgba[o + 1] = c.G;
rgba[o + 2] = c.B;
rgba[o + 3] = 255;
}
// 2) text layer overlaid on top, using IBM VGA 8x14 glyphs.
var font = Font8x14Data;
for (var row = 0; row < TextRows; row++)
{
var py0 = row * CharH;
for (var col = 0; col < TextCols; col++)
{
var idx = (row * TextCols) + col;
var ch = textChars[idx];
if (ch == 0)
{
continue;
}
if (ch == ' ' && textBg[idx] == 0)
{
continue; // transparent space
}
int code = ch < 256 ? ch : '?';
var fgAttr = textFg[idx];
var bgAttr = textBg[idx];
var fg = egaTable[attrToEga[fgAttr & 15]];
var bg = egaTable[attrToEga[bgAttr & 15]];
var drawBg = bgAttr != 0 || ch != ' ';
var px0 = col * CharW;
var glyphOff = code * 14;
for (var gy = 0; gy < CharH; gy++)
{
var py = py0 + gy;
if ((uint)py >= Height)
{
break;
}
var bits = font[glyphOff + gy];
var rowBase = (py * Width) + px0;
for (var gx = 0; gx < CharW; gx++)
{
var px = px0 + gx;
if ((uint)px >= Width)
{
break;
}
var on = ((bits >> (7 - gx)) & 1) != 0;
var o = (rowBase + gx) * 4;
if (on)
{
rgba[o] = fg.R;
rgba[o + 1] = fg.G;
rgba[o + 2] = fg.B;
rgba[o + 3] = 255;
}
else if (drawBg)
{
rgba[o] = bg.R;
rgba[o + 1] = bg.G;
rgba[o + 2] = bg.B;
rgba[o + 3] = 255;
}
}
}
}
}
}
/// <summary>Iterate live text cells grouped into contiguous runs sharing the same fg/bg.</summary>
public static IEnumerable<(int row, int colStart, string text, byte fg, byte bg)> EnumerateTextRuns()
{
for (var row = 0; row < TextRows; row++)
{
var col = 0;
while (col < TextCols)
{
var idx = (row * TextCols) + col;
var ch = textChars[idx];
if (ch is (char)0 or ' ')
{
col++;
continue;
}
var start = col;
var fg = textFg[idx];
var bg = textBg[idx];
var sb = new StringBuilder();
while (col < TextCols)
{
var j = (row * TextCols) + col;
var cj = textChars[j];
if (cj == 0 || cj == ' ' || textFg[j] != fg || textBg[j] != bg)
{
break;
}
sb.Append(cj);
col++;
}
yield return (row, start, sb.ToString(), fg, bg);
}
}
}
}
internal sealed record QbSprite(int Width, int Height, byte[] Data);
internal enum PutMode { Pset, Xor }
/// <summary>
/// Tiny QBasic-style PLAY (MML) player. The original GORILLA.BAS uses statements like
/// <c>PLAY "MBO0L32EFGEFDC"</c>; this class parses the same MML strings, synthesises a
/// PC-speaker-like square wave in memory and pipes it through Raylib's audio device,
/// preserving MB (background, non-blocking) vs. MF/MN (foreground, blocking) semantics.
/// </summary>
internal static class Audio
{
private const int SampleRate = 22050;
// QBasic's MB mode does not play sounds concurrently: it appends them to a note buffer
// that the interpreter drains in order. This queue plus its worker thread reproduce that
// behaviour, so consecutive PLAY calls are heard one after another instead of overlapping.
private static readonly BlockingCollection<Clip> _queue = [with(new ConcurrentQueue<Clip>())];
private static readonly ManualResetEventSlim _idle = new(true);
private static readonly Lock _pendingLock = new();
private static int _pending;
private static Thread? _worker;
// Capacity of the QBasic MB note buffer, and the bookkeeping needed to know how full it is.
private const int BackgroundBufferSize = 32;
private static int _queuedNotes;
private static Clip? _current;
private static long _currentStart;
// QBasic PLAY state is persistent across calls.
private static double _tempo = 120;
private static int _octave = 4;
private static int _length = 4;
private static char _articulation = 'N'; // L=legato, N=normal, S=staccato
private static bool _background; // M B vs. M F / M N
private sealed record Clip(short[] Samples, double[] NoteEnds, ManualResetEventSlim? Finished);
public static void Initialize()
{
Raylib.InitAudioDevice();
_worker = new Thread(DrainQueue) { IsBackground = true, Name = "Gorilla-Audio" };
_worker.Start();
}
public static void Shutdown()
{
_queue.CompleteAdding();
_worker?.Join(TimeSpan.FromSeconds(1));
Raylib.CloseAudioDevice();
}
/// <summary>
/// Play a QBasic MML string (e.g. <c>"MBO0L32EFGEFDC"</c>). The clip is appended to the
/// playback queue so it starts only once the previous one has finished, mirroring the
/// QBasic note buffer. In background mode (MB) the call returns as soon as the notes fit in the
/// 32-note background buffer; otherwise (MF / MN) it blocks until the clip has been played,
/// as the original BASIC does.
/// </summary>
public static void Play(string mml)
{
if (string.IsNullOrEmpty(mml))
{
return;
}
var notes = Parse(mml);
if (notes.Count == 0)
{
return;
}
if (!_background)
{
Enqueue(Synthesize(notes), NoteEnds(notes), blocking: true);
return;
}
// In MB mode QBasic returns only once the last note fits in its 32-note background buffer.
Enqueue(Synthesize(notes), NoteEnds(notes), blocking: false);
while (RemainingNotes() > BackgroundBufferSize)
{
Thread.Sleep(5);
}
}
private static int RemainingNotes()
{
lock (_pendingLock)
{
var remaining = _queuedNotes;
if (_current is { } clip)
{
var elapsed = Stopwatch.GetElapsedTime(_currentStart).TotalSeconds;
foreach (var end in clip.NoteEnds)
{
if (end > elapsed)
{
remaining++;
}
}
}
return remaining;
}
}
/// <summary>Computes, for each note or pause (the unit of the QBasic buffer), the time its sound ends.</summary>
private static double[] NoteEnds(List<Note> notes)
{
var ends = new List<double>(notes.Count);
var time = 0.0;
foreach (var n in notes)
{
time += (int)(n.Duration * SampleRate) / (double)SampleRate;
if (n.IsArticulationGap && ends.Count > 0)
{
ends[^1] = time;
}
else
{
ends.Add(time);
}
}
return [.. ends];
}
/// <summary>
/// Mirrors BASIC <c>BEEP</c>: an 800 Hz tone lasting a quarter of a second.
/// </summary>
/// <remarks>
/// It is synthesised directly rather than through <see cref="Play"/> so that it does not alter
/// the persistent PLAY state (tempo, octave, length, MB/MF), exactly like the original statement.
/// </remarks>
public static void Beep() => Enqueue(Synthesize([new Note(800, 0.25)]), [0.25], blocking: true);
private static void Enqueue(short[] samples, double[] noteEnds, bool blocking)
{
using var finished = blocking ? new ManualResetEventSlim(false) : null;
var clip = new Clip(samples, noteEnds, finished);
lock (_pendingLock)
{
_pending++;
_queuedNotes += noteEnds.Length;
_idle.Reset();
}
try
{
_queue.Add(clip);
}
catch (InvalidOperationException)
{
lock (_pendingLock)
{
_queuedNotes -= noteEnds.Length;
}
ClipCompleted();
return; // shutting down
}
finished?.Wait();
}
/// <summary>
/// Blocks until every queued clip has finished playing.
/// </summary>
/// <remarks>
/// Background (MB) clips return to the caller immediately, so a screen that fires several
/// of them in a row can still have audio pending when it ends. Callers use this to let the
/// music finish before moving on, matching how QBasic drains its note buffer.
/// </remarks>
public static void WaitUntilIdle() => _idle.Wait();
private static void ClipCompleted()
{
lock (_pendingLock)
{
if (--_pending <= 0)
{
_pending = 0;
_idle.Set();
}
}
}
private static unsafe void DrainQueue()
{
foreach (var clip in _queue.GetConsumingEnumerable())
{
var sound = CreateSound(clip.Samples);
try
{
lock (_pendingLock)
{
_queuedNotes -= clip.NoteEnds.Length;
_current = clip;
_currentStart = Stopwatch.GetTimestamp();
}
Raylib.PlaySound(sound);
while (Raylib.IsSoundPlaying(sound))
{
Thread.Sleep(5);
}
}
finally
{
Raylib.UnloadSound(sound);
lock (_pendingLock)
{
_current = null;
}
clip.Finished?.Set();
ClipCompleted();
}
}
}
private readonly record struct Note(double Frequency, double Duration, bool IsArticulationGap = false);
private static readonly int[] LetterSemitones =
[
9, // A
11, // B
0, // C
2, // D
4, // E
5, // F
7, // G
];
private static List<Note> Parse(string mml)
{
var notes = new List<Note>();
var i = 0;
var s = mml.ToUpperInvariant();
while (i < s.Length)
{
var c = s[i];
if (char.IsWhiteSpace(c))
{
i++;
continue;
}
switch (c)
{
case 'M':
i++;
if (i < s.Length)
{
var m = s[i++];
switch (m)
{
case 'B': _background = true; break;
case 'F': _background = false; break;
case 'N': _articulation = 'N'; break;
case 'L': _articulation = 'L'; break;
case 'S': _articulation = 'S'; break;
}
}
break;
case 'T':
i++;
_tempo = ReadInt(s, ref i, _tempo > 0 ? (int)_tempo : 120);
break;
case 'O':
i++;
_octave = Math.Clamp(ReadInt(s, ref i, _octave), 0, 6);
break;
case 'L':
i++;
_length = Math.Max(1, ReadInt(s, ref i, _length));
break;
case '>':
i++;
_octave = Math.Min(6, _octave + 1);
break;
case '<':
i++;
_octave = Math.Max(0, _octave - 1);
break;
case 'N':
i++;
var n = ReadInt(s, ref i, 0);
notes.Add(NoteFromN(n));
break;
case 'P':
i++;
var pl = ReadInt(s, ref i, _length);
notes.Add(new Note(0, NoteSeconds(pl, false)));
break;
case >= 'A' and <= 'G':
{
i++;
var semis = LetterSemitones[c - 'A'];
var acc = 0;
if (i < s.Length && (s[i] == '#' || s[i] == '+'))
{
acc = 1;
i++;
}
else if (i < s.Length && s[i] == '-')
{
acc = -1;
i++;
}
var len = ReadInt(s, ref i, _length);
var dotted = false;
if (i < s.Length && s[i] == '.')
{
dotted = true;
i++;
}
var totalSemis = (_octave * 12) + semis + acc;
var freq = MidiToFrequency(totalSemis);
var dur = NoteSeconds(len, dotted);
// Articulation: gap inside the note duration.
var gap = _articulation switch
{
'L' => 0.0,
'S' => 0.25,
_ => 0.125, // 'N'
};
notes.Add(new Note(freq, dur * (1 - gap)));
if (gap > 0)
{
notes.Add(new Note(0, dur * gap, IsArticulationGap: true));
}
}
break;
default:
i++;
break;
}
}
return notes;
}
private static int ReadInt(string s, ref int i, int defaultValue)
{
var start = i;
while (i < s.Length && char.IsDigit(s[i]))
{
i++;
}
if (i == start)
{
return defaultValue;
}
return int.Parse(s.AsSpan(start, i - start));
}
private static double NoteSeconds(int length, bool dotted)
{
var sec = 60.0 / _tempo * (4.0 / Math.Max(1, length));
if (dotted)
{
sec *= 1.5;
}
return sec;
}
private static Note NoteFromN(int n)
{
// QBasic N: 0 = silence, 1..84 = chromatic note number, where 1 is C in octave 0.
if (n <= 0)
{
return new Note(0, NoteSeconds(_length, false));
}
return new Note(MidiToFrequency(n - 1), NoteSeconds(_length, false));
}
/// <summary>
/// Converts a PLAY semitone index (0 = C in octave 0) to a frequency in hertz.
/// </summary>
/// <remarks>
/// QBasic spans seven octaves, 0 to 6, and octave 3 starts with middle C. Middle C is
/// therefore semitone index 36 and must map to 261.63 Hz, which places it 9 semitones
/// below the 440 Hz reference and yields the offset of 45 used below.
/// </remarks>
private static double MidiToFrequency(int semitones) =>
440.0 * Math.Pow(2, (semitones - 45) / 12.0);
private static short[] Synthesize(List<Note> notes)
{
var total = 0;
foreach (var n in notes)
{
total += (int)(n.Duration * SampleRate);
}
var buffer = new short[Math.Max(1, total)];
var amp = (short)(short.MaxValue * 0.18);
var idx = 0;
foreach (var n in notes)
{
var count = (int)(n.Duration * SampleRate);
if (n.Frequency <= 0)
{
idx += count;
continue;
}
var period = SampleRate / n.Frequency;
var half = period / 2.0;
for (var k = 0; k < count && idx < buffer.Length; k++, idx++)
{
buffer[idx] = (k % period) < half ? amp : (short)-amp;
}
}
return buffer;
}
private static unsafe Sound CreateSound(short[] samples)
{
var byteLen = samples.Length * sizeof(short);
var data = NativeMemory.Alloc((nuint)byteLen);
try
{
fixed (short* src = samples)
{
Buffer.MemoryCopy(src, data, byteLen, byteLen);
}
var wave = new Wave
{
FrameCount = (uint)samples.Length,
SampleRate = SampleRate,
SampleSize = 16,
Channels = 1,
Data = data,
};
return Raylib.LoadSoundFromWave(wave);
}
finally
{
NativeMemory.Free(data);
}
}
}
/// <summary>
/// The IBM BIOS 8x14 VGA character generator ROM font used by QBasic SCREEN 9.
/// </summary>
/// <remarks>
/// The data is embedded as a <see cref="ReadOnlySpan{T}"/> literal rather than an
/// <c>EmbeddedResource</c> so the game has no build- or run-time file dependency.
/// The compiler stores it in the assembly metadata, so reading it allocates nothing.
/// Layout: 256 glyphs, 14 scanlines each, one byte per scanline, MSB = leftmost pixel.
/// </remarks>
internal static class Font8x14
{
/// <summary>Gets the raw 3584-byte glyph bitmap table.</summary>
public static ReadOnlySpan<byte> Data =>
[
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x7E, 0x81, 0xA5, 0x81, 0x81, 0xBD, 0x99, 0x81, 0x7E, 0x00, 0x00, 0x00,
0x00, 0x00, 0x7E, 0xFF, 0xDB, 0xFF, 0xFF, 0xC3, 0xE7, 0xFF, 0x7E, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x6C, 0xFE, 0xFE, 0xFE, 0xFE, 0x7C, 0x38, 0x10, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x10, 0x38, 0x7C, 0xFE, 0x7C, 0x38, 0x10, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x18, 0x3C, 0x3C, 0xE7, 0xE7, 0xE7, 0x18, 0x18, 0x3C, 0x00, 0x00, 0x00,
0x00, 0x00, 0x18, 0x3C, 0x7E, 0xFF, 0xFF, 0x7E, 0x18, 0x18, 0x3C, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x3C, 0x3C, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE7, 0xC3, 0xC3, 0xE7, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0x00, 0x00, 0x00, 0x00, 0x3C, 0x66, 0x42, 0x42, 0x66, 0x3C, 0x00, 0x00, 0x00, 0x00,
0xFF, 0xFF, 0xFF, 0xFF, 0xC3, 0x99, 0xBD, 0xBD, 0x99, 0xC3, 0xFF, 0xFF, 0xFF, 0xFF,
0x00, 0x00, 0x1E, 0x0E, 0x1A, 0x32, 0x78, 0xCC, 0xCC, 0xCC, 0x78, 0x00, 0x00, 0x00,
0x00, 0x00, 0x3C, 0x66, 0x66, 0x66, 0x3C, 0x18, 0x7E, 0x18, 0x18, 0x00, 0x00, 0x00,
0x00, 0x00, 0x3F, 0x33, 0x3F, 0x30, 0x30, 0x30, 0x70, 0xF0, 0xE0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x7F, 0x63, 0x7F, 0x63, 0x63, 0x63, 0x67, 0xE7, 0xE6, 0xC0, 0x00, 0x00,
0x00, 0x00, 0x18, 0x18, 0xDB, 0x3C, 0xE7, 0x3C, 0xDB, 0x18, 0x18, 0x00, 0x00, 0x00,
0x00, 0x00, 0x80, 0xC0, 0xE0, 0xF8, 0xFE, 0xF8, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x00,
0x00, 0x00, 0x02, 0x06, 0x0E, 0x3E, 0xFE, 0x3E, 0x0E, 0x06, 0x02, 0x00, 0x00, 0x00,
0x00, 0x00, 0x18, 0x3C, 0x7E, 0x18, 0x18, 0x18, 0x7E, 0x3C, 0x18, 0x00, 0x00, 0x00,
0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x00, 0x66, 0x66, 0x00, 0x00, 0x00,
0x00, 0x00, 0x7F, 0xDB, 0xDB, 0xDB, 0x7B, 0x1B, 0x1B, 0x1B, 0x1B, 0x00, 0x00, 0x00,
0x00, 0x7C, 0xC6, 0x60, 0x38, 0x6C, 0xC6, 0xC6, 0x6C, 0x38, 0x0C, 0xC6, 0x7C, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFE, 0xFE, 0x00, 0x00, 0x00,
0x00, 0x00, 0x18, 0x3C, 0x7E, 0x18, 0x18, 0x18, 0x7E, 0x3C, 0x18, 0x7E, 0x00, 0x00,
0x00, 0x00, 0x18, 0x3C, 0x7E, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00,
0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x7E, 0x3C, 0x18, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x18, 0x0C, 0xFE, 0x0C, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x30, 0x60, 0xFE, 0x60, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xC0, 0xC0, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x28, 0x6C, 0xFE, 0x6C, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x10, 0x38, 0x38, 0x7C, 0x7C, 0xFE, 0xFE, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xFE, 0xFE, 0x7C, 0x7C, 0x38, 0x38, 0x10, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x18, 0x3C, 0x3C, 0x3C, 0x18, 0x18, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00,
0x00, 0x66, 0x66, 0x66, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x6C, 0x6C, 0xFE, 0x6C, 0x6C, 0x6C, 0xFE, 0x6C, 0x6C, 0x00, 0x00, 0x00,
0x18, 0x18, 0x7C, 0xC6, 0xC2, 0xC0, 0x7C, 0x06, 0x86, 0xC6, 0x7C, 0x18, 0x18, 0x00,
0x00, 0x00, 0x00, 0x00, 0xC2, 0xC6, 0x0C, 0x18, 0x30, 0x66, 0xC6, 0x00, 0x00, 0x00,
0x00, 0x00, 0x38, 0x6C, 0x6C, 0x38, 0x76, 0xDC, 0xCC, 0xCC, 0x76, 0x00, 0x00, 0x00,
0x00, 0x30, 0x30, 0x30, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x0C, 0x18, 0x30, 0x30, 0x30, 0x30, 0x30, 0x18, 0x0C, 0x00, 0x00, 0x00,
0x00, 0x00, 0x30, 0x18, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x18, 0x30, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x66, 0x3C, 0xFF, 0x3C, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x7E, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x30, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00,
0x00, 0x00, 0x02, 0x06, 0x0C, 0x18, 0x30, 0x60, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x7C, 0xC6, 0xCE, 0xDE, 0xF6, 0xE6, 0xC6, 0xC6, 0x7C, 0x00, 0x00, 0x00,
0x00, 0x00, 0x18, 0x38, 0x78, 0x18, 0x18, 0x18, 0x18, 0x18, 0x7E, 0x00, 0x00, 0x00,
0x00, 0x00, 0x7C, 0xC6, 0x06, 0x0C, 0x18, 0x30, 0x60, 0xC6, 0xFE, 0x00, 0x00, 0x00,
0x00, 0x00, 0x7C, 0xC6, 0x06, 0x06, 0x3C, 0x06, 0x06, 0xC6, 0x7C, 0x00, 0x00, 0x00,
0x00, 0x00, 0x0C, 0x1C, 0x3C, 0x6C, 0xCC, 0xFE, 0x0C, 0x0C, 0x1E, 0x00, 0x00, 0x00,
0x00, 0x00, 0xFE, 0xC0, 0xC0, 0xC0, 0xFC, 0x06, 0x06, 0xC6, 0x7C, 0x00, 0x00, 0x00,
0x00, 0x00, 0x38, 0x60, 0xC0, 0xC0, 0xFC, 0xC6, 0xC6, 0xC6, 0x7C, 0x00, 0x00, 0x00,
0x00, 0x00, 0xFE, 0xC6, 0x06, 0x0C, 0x18, 0x30, 0x30, 0x30, 0x30, 0x00, 0x00, 0x00,
0x00, 0x00, 0x7C, 0xC6, 0xC6, 0xC6, 0x7C, 0xC6, 0xC6, 0xC6, 0x7C, 0x00, 0x00, 0x00,
0x00, 0x00, 0x7C, 0xC6, 0xC6, 0xC6, 0x7E, 0x06, 0x06, 0x0C, 0x78, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x18, 0x18, 0x30, 0x00, 0x00, 0x00,
0x00, 0x00, 0x06, 0x0C, 0x18, 0x30, 0x60, 0x30, 0x18, 0x0C, 0x06, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, 0x00, 0x00, 0x7E, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x60, 0x30, 0x18, 0x0C, 0x06, 0x0C, 0x18, 0x30, 0x60, 0x00, 0x00, 0x00,
0x00, 0x00, 0x7C, 0xC6, 0xC6, 0x0C, 0x18, 0x18, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00,
0x00, 0x00, 0x7C, 0xC6, 0xC6, 0xDE, 0xDE, 0xDE, 0xDC, 0xC0, 0x7C, 0x00, 0x00, 0x00,
0x00, 0x00, 0x10, 0x38, 0x6C, 0xC6, 0xC6, 0xFE, 0xC6, 0xC6, 0xC6, 0x00, 0x00, 0x00,
0x00, 0x00, 0xFC, 0x66, 0x66, 0x66, 0x7C, 0x66, 0x66, 0x66, 0xFC, 0x00, 0x00, 0x00,
0x00, 0x00, 0x3C, 0x66, 0xC2, 0xC0, 0xC0, 0xC0, 0xC2, 0x66, 0x3C, 0x00, 0x00, 0x00,
0x00, 0x00, 0xF8, 0x6C, 0x66, 0x66, 0x66, 0x66, 0x66, 0x6C, 0xF8, 0x00, 0x00, 0x00,
0x00, 0x00, 0xFE, 0x66, 0x62, 0x68, 0x78, 0x68, 0x62, 0x66, 0xFE, 0x00, 0x00, 0x00,
0x00, 0x00, 0xFE, 0x66, 0x62, 0x68, 0x78, 0x68, 0x60, 0x60, 0xF0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x3C, 0x66, 0xC2, 0xC0, 0xC0, 0xDE, 0xC6, 0x66, 0x3A, 0x00, 0x00, 0x00,
0x00, 0x00, 0xC6, 0xC6, 0xC6, 0xC6, 0xFE, 0xC6, 0xC6, 0xC6, 0xC6, 0x00, 0x00, 0x00,
0x00, 0x00, 0x3C, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3C, 0x00, 0x00, 0x00,
0x00, 0x00, 0x1E, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0xCC, 0xCC, 0x78, 0x00, 0x00, 0x00,
0x00, 0x00, 0xE6, 0x66, 0x6C, 0x6C, 0x78, 0x6C, 0x6C, 0x66, 0xE6, 0x00, 0x00, 0x00,
0x00, 0x00, 0xF0, 0x60, 0x60, 0x60, 0x60, 0x60, 0x62, 0x66, 0xFE, 0x00, 0x00, 0x00,
0x00, 0x00, 0xC6, 0xEE, 0xFE, 0xFE, 0xD6, 0xC6, 0xC6, 0xC6, 0xC6, 0x00, 0x00, 0x00,
0x00, 0x00, 0xC6, 0xE6, 0xF6, 0xFE, 0xDE, 0xCE, 0xC6, 0xC6, 0xC6, 0x00, 0x00, 0x00,
0x00, 0x00, 0x38, 0x6C, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0x6C, 0x38, 0x00, 0x00, 0x00,
0x00, 0x00, 0xFC, 0x66, 0x66, 0x66, 0x7C, 0x60, 0x60, 0x60, 0xF0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x7C, 0xC6, 0xC6, 0xC6, 0xC6, 0xD6, 0xDE, 0x7C, 0x0C, 0x0E, 0x00, 0x00,
0x00, 0x00, 0xFC, 0x66, 0x66, 0x66, 0x7C, 0x6C, 0x66, 0x66, 0xE6, 0x00, 0x00, 0x00,
0x00, 0x00, 0x7C, 0xC6, 0xC6, 0x60, 0x38, 0x0C, 0xC6, 0xC6, 0x7C, 0x00, 0x00, 0x00,
0x00, 0x00, 0x7E, 0x7E, 0x5A, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3C, 0x00, 0x00, 0x00,
0x00, 0x00, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0x7C, 0x00, 0x00, 0x00,
0x00, 0x00, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0x6C, 0x38, 0x10, 0x00, 0x00, 0x00,
0x00, 0x00, 0xC6, 0xC6, 0xC6, 0xC6, 0xD6, 0xD6, 0xFE, 0x7C, 0x6C, 0x00, 0x00, 0x00,
0x00, 0x00, 0xC6, 0xC6, 0x6C, 0x38, 0x38, 0x38, 0x6C, 0xC6, 0xC6, 0x00, 0x00, 0x00,
0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x3C, 0x18, 0x18, 0x18, 0x3C, 0x00, 0x00, 0x00,
0x00, 0x00, 0xFE, 0xC6, 0x8C, 0x18, 0x30, 0x60, 0xC2, 0xC6, 0xFE, 0x00, 0x00, 0x00,
0x00, 0x00, 0x3C, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x3C, 0x00, 0x00, 0x00,
0x00, 0x00, 0x80, 0xC0, 0xE0, 0x70, 0x38, 0x1C, 0x0E, 0x06, 0x02, 0x00, 0x00, 0x00,
0x00, 0x00, 0x3C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x3C, 0x00, 0x00, 0x00,
0x10, 0x38, 0x6C, 0xC6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00,
0x30, 0x30, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x0C, 0x7C, 0xCC, 0xCC, 0x76, 0x00, 0x00, 0x00,
0x00, 0x00, 0xE0, 0x60, 0x60, 0x78, 0x6C, 0x66, 0x66, 0x66, 0x7C, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0xC6, 0xC0, 0xC0, 0xC6, 0x7C, 0x00, 0x00, 0x00,
0x00, 0x00, 0x1C, 0x0C, 0x0C, 0x3C, 0x6C, 0xCC, 0xCC, 0xCC, 0x76, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0xC6, 0xFE, 0xC0, 0xC6, 0x7C, 0x00, 0x00, 0x00,
0x00, 0x00, 0x38, 0x6C, 0x64, 0x60, 0xF0, 0x60, 0x60, 0x60, 0xF0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0xCC, 0xCC, 0xCC, 0x7C, 0x0C, 0xCC, 0x78, 0x00,
0x00, 0x00, 0xE0, 0x60, 0x60, 0x6C, 0x76, 0x66, 0x66, 0x66, 0xE6, 0x00, 0x00, 0x00,
0x00, 0x00, 0x18, 0x18, 0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x3C, 0x00, 0x00, 0x00,
0x00, 0x00, 0x06, 0x06, 0x00, 0x0E, 0x06, 0x06, 0x06, 0x06, 0x66, 0x66, 0x3C, 0x00,
0x00, 0x00, 0xE0, 0x60, 0x60, 0x66, 0x6C, 0x78, 0x6C, 0x66, 0xE6, 0x00, 0x00, 0x00,
0x00, 0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3C, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xEC, 0xFE, 0xD6, 0xD6, 0xD6, 0xC6, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xDC, 0x66, 0x66, 0x66, 0x66, 0x66, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0xC6, 0xC6, 0xC6, 0xC6, 0x7C, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xDC, 0x66, 0x66, 0x66, 0x7C, 0x60, 0x60, 0xF0, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0xCC, 0xCC, 0xCC, 0x7C, 0x0C, 0x0C, 0x1E, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xDC, 0x76, 0x66, 0x60, 0x60, 0xF0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0xC6, 0x70, 0x1C, 0xC6, 0x7C, 0x00, 0x00, 0x00,
0x00, 0x00, 0x10, 0x30, 0x30, 0xFC, 0x30, 0x30, 0x30, 0x36, 0x1C, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0x76, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x3C, 0x18, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xC6, 0xC6, 0xD6, 0xD6, 0xFE, 0x6C, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xC6, 0x6C, 0x38, 0x38, 0x6C, 0xC6, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xC6, 0xC6, 0xC6, 0xC6, 0x7E, 0x06, 0x0C, 0xF8, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xCC, 0x18, 0x30, 0x66, 0xFE, 0x00, 0x00, 0x00,
0x00, 0x00, 0x0E, 0x18, 0x18, 0x18, 0x70, 0x18, 0x18, 0x18, 0x0E, 0x00, 0x00, 0x00,
0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00,
0x00, 0x00, 0x70, 0x18, 0x18, 0x18, 0x0E, 0x18, 0x18, 0x18, 0x70, 0x00, 0x00, 0x00,
0x00, 0x00, 0x76, 0xDC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0x6C, 0xC6, 0xC6, 0xFE, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x3C, 0x66, 0xC2, 0xC0, 0xC0, 0xC2, 0x66, 0x3C, 0x0C, 0x06, 0x7C, 0x00,
0x00, 0x00, 0xCC, 0xCC, 0x00, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0x76, 0x00, 0x00, 0x00,
0x00, 0x0C, 0x18, 0x30, 0x00, 0x7C, 0xC6, 0xFE, 0xC0, 0xC6, 0x7C, 0x00, 0x00, 0x00,
0x00, 0x10, 0x38, 0x6C, 0x00, 0x78, 0x0C, 0x7C, 0xCC, 0xCC, 0x76, 0x00, 0x00, 0x00,
0x00, 0x00, 0xCC, 0xCC, 0x00, 0x78, 0x0C, 0x7C, 0xCC, 0xCC, 0x76, 0x00, 0x00, 0x00,
0x00, 0x60, 0x30, 0x18, 0x00, 0x78, 0x0C, 0x7C, 0xCC, 0xCC, 0x76, 0x00, 0x00, 0x00,
0x00, 0x38, 0x6C, 0x38, 0x00, 0x78, 0x0C, 0x7C, 0xCC, 0xCC, 0x76, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x3C, 0x66, 0x60, 0x66, 0x3C, 0x0C, 0x06, 0x3C, 0x00, 0x00,
0x00, 0x10, 0x38, 0x6C, 0x00, 0x7C, 0xC6, 0xFE, 0xC0, 0xC6, 0x7C, 0x00, 0x00, 0x00,
0x00, 0x00, 0xCC, 0xCC, 0x00, 0x7C, 0xC6, 0xFE, 0xC0, 0xC6, 0x7C, 0x00, 0x00, 0x00,
0x00, 0x60, 0x30, 0x18, 0x00, 0x7C, 0xC6, 0xFE, 0xC0, 0xC6, 0x7C, 0x00, 0x00, 0x00,
0x00, 0x00, 0x66, 0x66, 0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x3C, 0x00, 0x00, 0x00,
0x00, 0x18, 0x3C, 0x66, 0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x3C, 0x00, 0x00, 0x00,
0x00, 0x60, 0x30, 0x18, 0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x3C, 0x00, 0x00, 0x00,
0x00, 0xC6, 0xC6, 0x10, 0x38, 0x6C, 0xC6, 0xC6, 0xFE, 0xC6, 0xC6, 0x00, 0x00, 0x00,
0x38, 0x6C, 0x38, 0x00, 0x38, 0x6C, 0xC6, 0xC6, 0xFE, 0xC6, 0xC6, 0x00, 0x00, 0x00,
0x18, 0x30, 0x60, 0x00, 0xFE, 0x66, 0x60, 0x7C, 0x60, 0x66, 0xFE, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xCC, 0x76, 0x36, 0x7E, 0xD8, 0xD8, 0x6E, 0x00, 0x00, 0x00,
0x00, 0x00, 0x3E, 0x6C, 0xCC, 0xCC, 0xFE, 0xCC, 0xCC, 0xCC, 0xCE, 0x00, 0x00, 0x00,
0x00, 0x10, 0x38, 0x6C, 0x00, 0x7C, 0xC6, 0xC6, 0xC6, 0xC6, 0x7C, 0x00, 0x00, 0x00,
0x00, 0x00, 0xC6, 0xC6, 0x00, 0x7C, 0xC6, 0xC6, 0xC6, 0xC6, 0x7C, 0x00, 0x00, 0x00,
0x00, 0x60, 0x30, 0x18, 0x00, 0x7C, 0xC6, 0xC6, 0xC6, 0xC6, 0x7C, 0x00, 0x00, 0x00,
0x00, 0x30, 0x78, 0xCC, 0x00, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0x76, 0x00, 0x00, 0x00,
0x00, 0x60, 0x30, 0x18, 0x00, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0x76, 0x00, 0x00, 0x00,
0x00, 0x00, 0xC6, 0xC6, 0x00, 0xC6, 0xC6, 0xC6, 0xC6, 0x7E, 0x06, 0x0C, 0x78, 0x00,
0x00, 0xC6, 0xC6, 0x38, 0x6C, 0xC6, 0xC6, 0xC6, 0xC6, 0x6C, 0x38, 0x00, 0x00, 0x00,
0x00, 0xC6, 0xC6, 0x00, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0x7C, 0x00, 0x00, 0x00,
0x00, 0x18, 0x18, 0x3C, 0x66, 0x60, 0x60, 0x66, 0x3C, 0x18, 0x18, 0x00, 0x00, 0x00,
0x00, 0x38, 0x6C, 0x64, 0x60, 0xF0, 0x60, 0x60, 0x60, 0xE6, 0xFC, 0x00, 0x00, 0x00,
0x00, 0x00, 0x66, 0x66, 0x3C, 0x18, 0x7E, 0x18, 0x7E, 0x18, 0x18, 0x00, 0x00, 0x00,
0x00, 0xF8, 0xCC, 0xCC, 0xF8, 0xC4, 0xCC, 0xDE, 0xCC, 0xCC, 0xC6, 0x00, 0x00, 0x00,
0x00, 0x0E, 0x1B, 0x18, 0x18, 0x18, 0x7E, 0x18, 0x18, 0x18, 0x18, 0xD8, 0x70, 0x00,
0x00, 0x18, 0x30, 0x60, 0x00, 0x78, 0x0C, 0x7C, 0xCC, 0xCC, 0x76, 0x00, 0x00, 0x00,
0x00, 0x0C, 0x18, 0x30, 0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x3C, 0x00, 0x00, 0x00,
0x00, 0x18, 0x30, 0x60, 0x00, 0x7C, 0xC6, 0xC6, 0xC6, 0xC6, 0x7C, 0x00, 0x00, 0x00,
0x00, 0x18, 0x30, 0x60, 0x00, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0x76, 0x00, 0x00, 0x00,
0x00, 0x00, 0x76, 0xDC, 0x00, 0xDC, 0x66, 0x66, 0x66, 0x66, 0x66, 0x00, 0x00, 0x00,
0x76, 0xDC, 0x00, 0xC6, 0xE6, 0xF6, 0xFE, 0xDE, 0xCE, 0xC6, 0xC6, 0x00, 0x00, 0x00,
0x00, 0x3C, 0x6C, 0x6C, 0x3E, 0x00, 0x7E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x38, 0x6C, 0x6C, 0x38, 0x00, 0x7C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x30, 0x30, 0x00, 0x30, 0x30, 0x60, 0xC6, 0xC6, 0x7C, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xC0, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0x06, 0x06, 0x06, 0x00, 0x00, 0x00, 0x00,
0x00, 0xC0, 0xC0, 0xC6, 0xCC, 0xD8, 0x30, 0x60, 0xDC, 0x86, 0x0C, 0x18, 0x3E, 0x00,
0x00, 0xC0, 0xC0, 0xC6, 0xCC, 0xD8, 0x30, 0x66, 0xCE, 0x9E, 0x3E, 0x06, 0x06, 0x00,
0x00, 0x00, 0x18, 0x18, 0x00, 0x18, 0x18, 0x3C, 0x3C, 0x3C, 0x18, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x36, 0x6C, 0xD8, 0x6C, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xD8, 0x6C, 0x36, 0x6C, 0xD8, 0x00, 0x00, 0x00, 0x00, 0x00,
0x11, 0x44, 0x11, 0x44, 0x11, 0x44, 0x11, 0x44, 0x11, 0x44, 0x11, 0x44, 0x11, 0x44,
0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA,
0xDD, 0x77, 0xDD, 0x77, 0xDD, 0x77, 0xDD, 0x77, 0xDD, 0x77, 0xDD, 0x77, 0xDD, 0x77,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xF8, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0xF8, 0x18, 0xF8, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0xF6, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x18, 0xF8, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x36, 0x36, 0x36, 0x36, 0x36, 0xF6, 0x06, 0xF6, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0x06, 0xF6, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
0x36, 0x36, 0x36, 0x36, 0x36, 0xF6, 0x06, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x18, 0x18, 0x18, 0x18, 0x18, 0xF8, 0x18, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1F, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xFF, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x1F, 0x18, 0x1F, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x37, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
0x36, 0x36, 0x36, 0x36, 0x36, 0x37, 0x30, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x30, 0x37, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
0x36, 0x36, 0x36, 0x36, 0x36, 0xF7, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0xF7, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
0x36, 0x36, 0x36, 0x36, 0x36, 0x37, 0x30, 0x37, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x36, 0x36, 0x36, 0x36, 0x36, 0xF7, 0x00, 0xF7, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
0x18, 0x18, 0x18, 0x18, 0x18, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x18, 0x18, 0x18, 0x18, 0x18, 0x1F, 0x18, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x18, 0x1F, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0xFF, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
0x18, 0x18, 0x18, 0x18, 0x18, 0xFF, 0x18, 0xFF, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0xDC, 0xD8, 0xD8, 0xDC, 0x76, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7C, 0xC6, 0xFC, 0xC6, 0xC6, 0xFC, 0xC0, 0xC0, 0x40, 0x00,
0x00, 0x00, 0xFE, 0xC6, 0xC6, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xFE, 0x6C, 0x6C, 0x6C, 0x6C, 0x6C, 0x6C, 0x00, 0x00, 0x00,
0x00, 0x00, 0xFE, 0xC6, 0x60, 0x30, 0x18, 0x30, 0x60, 0xC6, 0xFE, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, 0xD8, 0xD8, 0xD8, 0xD8, 0x70, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x7C, 0x60, 0x60, 0xC0, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x76, 0xDC, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00,
0x00, 0x00, 0x7E, 0x18, 0x3C, 0x66, 0x66, 0x66, 0x3C, 0x18, 0x7E, 0x00, 0x00, 0x00,
0x00, 0x00, 0x38, 0x6C, 0xC6, 0xC6, 0xFE, 0xC6, 0xC6, 0x6C, 0x38, 0x00, 0x00, 0x00,
0x00, 0x00, 0x38, 0x6C, 0xC6, 0xC6, 0xC6, 0x6C, 0x6C, 0x6C, 0xEE, 0x00, 0x00, 0x00,
0x00, 0x00, 0x1E, 0x30, 0x18, 0x0C, 0x3E, 0x66, 0x66, 0x66, 0x3C, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, 0xDB, 0xDB, 0x7E, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x03, 0x06, 0x7E, 0xDB, 0xDB, 0xF3, 0x7E, 0x60, 0xC0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x1C, 0x30, 0x60, 0x60, 0x7C, 0x60, 0x60, 0x30, 0x1C, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x7C, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xFE, 0x00, 0x00, 0xFE, 0x00, 0x00, 0xFE, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x18, 0x18, 0x7E, 0x18, 0x18, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00,
0x00, 0x00, 0x30, 0x18, 0x0C, 0x06, 0x0C, 0x18, 0x30, 0x00, 0x7E, 0x00, 0x00, 0x00,
0x00, 0x00, 0x0C, 0x18, 0x30, 0x60, 0x30, 0x18, 0x0C, 0x00, 0x7E, 0x00, 0x00, 0x00,
0x00, 0x00, 0x0E, 0x1B, 0x1B, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xD8, 0xD8, 0x70, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x7E, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x76, 0xDC, 0x00, 0x76, 0xDC, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x38, 0x6C, 0x6C, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x0F, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0xEC, 0x6C, 0x3C, 0x1C, 0x00, 0x00, 0x00,
0x00, 0xD8, 0x6C, 0x6C, 0x6C, 0x6C, 0x6C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x70, 0xD8, 0x30, 0x60, 0xC8, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment