Improve shell completion and Bob64 text readability

This commit is contained in:
Alvin-Zilverstand committed 2026-10-13 23:26:00 +02:00
1 parent 57787bfc7f
commit 412000b481
14 files changed
+2383 -1249

No files matched your search

BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+11
View File
@@ -28,6 +28,17 @@ handoff has been booted under QEMU with x64 OVMF firmware; the kernel reaches it
shell after switching to its own page tables, and the GOP framebuffer has been
visually checked at 1280x800.
The kernel console and GUI text helper share `bob64/font.h`'s bitmap-glyph
renderer. The shell uses a clear 8x16 printable-ASCII font from
`bob64/font8x16.h` on 9x18 cells (`FONT_WIDTH`, `FONT_HEIGHT`, `LINE_HEIGHT`,
and `CHAR_SPACING`); lowercase and command punctuation have their own glyphs.
The compact 5x7 font remains available for existing small GUI labels. Run
`fonttest` in the shell to clear the display and show the alphabet, digits,
commonly confused characters, punctuation, and a pangram. Host checks cover
every printable glyph, cell wrapping, backspace, cursor position and scrolling;
the QEMU/OVMF regression checks the full font sample on the live GOP display.
The 8x16 bitmap's MIT license is included in `bob64/FONT_LICENSE.md`.
Kernel entry also adopts the seeded physical-page allocator and maps pages into
a small coalescing heap in the high canonical address range. Its boot smoke test
checks aligned allocation, zeroing, multi-page growth, writes, and freeing. The
+3 -2
View File
@@ -123,7 +123,7 @@ static void erase_previous_character(void) {
int bob64_framebuffer_init(u64 base,u64 size,u32 width,u32 height,
u32 pixels_per_scan_line,u32 pixel_format) {
u64 pixels,required;
if(!base||!size||width<FONT_CELL_WIDTH||height<FONT_HEIGHT||
if(!base||!size||!width||!height||
pixels_per_scan_line<width||
(pixel_format!=0&&pixel_format!=1)||
(u64)pixels_per_scan_line>~(u64)0/height)return -1;
@@ -136,6 +136,7 @@ int bob64_framebuffer_init(u64 base,u64 size,u32 width,u32 height,
framebuffer.Width=width;framebuffer.Height=height;
framebuffer.Stride=pixels_per_scan_line;framebuffer.Format=pixel_format;
framebuffer.Column=0;framebuffer.Row=0;framebuffer.Ready=1;
framebuffer.CursorDrawn=0;
for(u32 y=0;y<height;y++)clear_row(y);
return 0;
}
@@ -153,9 +154,9 @@ int bob64_framebuffer_resolution(u32 *width,u32 *height) {
int bob64_framebuffer_write_pixels(u64 first_pixel,const u32 *pixels,u32 count) {
u64 total;
if(!framebuffer.Ready||(!pixels&&count))return -1;
if(count&&framebuffer.CursorDrawn)erase_cursor();
total=(u64)framebuffer.Width*framebuffer.Height;
if(first_pixel>total||(u64)count>total-first_pixel)return -1;
if(count&&framebuffer.CursorDrawn)erase_cursor();
for(u32 i=0;i<count;i++) {
u64 index=first_pixel+i;
u32 red=(pixels[i]>>16)&0xff,green=(pixels[i]>>8)&0xff,blue=pixels[i]&0xff;
+1 -1
View File
@@ -41,7 +41,7 @@ typedef struct {
u8 BytesPerGlyph,ColumnMajor,MostSignificantBitFirst;
} BOB64_BITMAP_FONT;
static const BOB64_BITMAP_FONT bob64_font5x7={
static const BOB64_BITMAP_FONT bob64_font_compact5x7={
&bob64_font5x7[0][0],5,7,44,5,1,0
};
+1 -1
View File
@@ -149,7 +149,7 @@ static inline void bob64_gfx_text(BOB64_GFX *graphics,s32 x,s32 y,
if(!graphics||!text||!scale)return;
while(*text) {
u32 glyph=bob64_gfx_glyph((u8)*text++);
bob64_font_draw_glyph(&bob64_font5x7,glyph,cursor_x,origin_y,scale,
bob64_font_draw_glyph(&bob64_font_compact5x7,glyph,cursor_x,origin_y,scale,
bob64_gfx_font_plot_pixel,&context,color);
cursor_x+=(s64)6*scale;
}
+1
View File
@@ -90,6 +90,7 @@ static void show_font_test(BOB64_SHELL *shell) {
output(shell,"[] {} () <> / \\ | _ - + = : ; , . ! ?\r\n");
output(shell,"bob64 kernel shell\r\n");
output(shell,"The quick brown fox jumps over the lazy dog.\r\n");
output(shell,"bob!\r\n");
}
static void compile_file_command(BOB64_SHELL *shell,char *arguments) {
BIN
View File
Binary file not shown.
+2140 -1227
View File
File diff suppressed because it is too large. Load diff
+32
View File
@@ -51,6 +51,9 @@ void input_complete(void) {
int start; int count; int matches; int i; int length; char *words; char candidate[24]; char selected[24];
start = input_cursor;
while (start && command_line[start - 1] != ' ') start--;
if (input_cursor == input_length && input_length &&
command_line[input_length - 1] == ' ')
start = input_cursor;
count = input_cursor - start; matches = 0;
if (input_cursor != input_length) return;
if (!start) {
@@ -69,6 +72,35 @@ void input_complete(void) {
}
}
} else {
int command_end = 0, command, word_start = 0, word_end;
int argument = 1, in_word = 0;
char *file_commands = " read write edit load run "
#ifdef BOBC_WIDE
"run32 "
#endif
"cc go copy rename delete";
while (command_end < input_length && command_line[command_end] != ' ')
command_end++;
command = 0;
while (file_commands[word_start]) {
while (file_commands[word_start] == ' ') word_start++;
word_end = word_start;
while (file_commands[word_end] && file_commands[word_end] != ' ')
word_end++;
if (word_end - word_start == command_end) {
for (i = 0; i < command_end &&
command_line[i] == file_commands[word_start + i]; i++);
if (i == command_end) command = 1;
}
word_start = word_end;
}
for (i = command_end; i < start; i++) {
if (command_line[i] == ' ') in_word = 0;
else if (!in_word) { argument++; in_word = 1; }
}
if (!command || (argument > 1 &&
!(command_end == 2 && command_line[0] == 'c' &&
command_line[1] == 'c' && argument == 2))) return;
for (i = 0; i < FILE_COUNT; i++) {
if (file_used[i] && input_matches(file_name(i), start, count)) {
matches++; memcpy(selected, file_name(i), strlen(file_name(i)) + 1);
+99 -14
View File
@@ -6,6 +6,7 @@
#include "../bob64/interrupts.h"
#include "../bob64/bootstrap.h"
#include "../bob64/console.h"
#include "../bob64/font8x16.h"
#include "../bob64/heap.h"
#include "../bob64/keyboard.h"
#include "../bob64/mouse.h"
@@ -2625,24 +2626,96 @@ static int memory_tests(void) {
return 0;
}
static int console_cell_has_ink(const u32 *pixels,u32 stride,u32 x,u32 y,
u32 foreground) {
for(u32 row=0;row<FONT_HEIGHT;row++)for(u32 column=0;column<FONT_WIDTH;column++)
if(pixels[(y+row)*stride+x+column]==foreground)return 1;
return 0;
}
static int console_cells_differ(const u32 *pixels,u32 stride,u32 first_x,
u32 second_x,u32 y) {
for(u32 row=0;row<FONT_HEIGHT;row++)for(u32 column=0;column<FONT_WIDTH;column++)
if(pixels[(y+row)*stride+first_x+column]!=
pixels[(y+row)*stride+second_x+column])return 1;
return 0;
}
static int console_cell_matches_glyph(const u32 *pixels,u32 stride,u32 x,u32 y,
u8 character,u32 foreground,u32 background) {
u32 glyph=(u32)(character-' ');
for(u32 row=0;row<FONT_HEIGHT;row++)for(u32 column=0;column<FONT_WIDTH;column++) {
u32 expected=bob64_font_sample(&bob64_font8x16,glyph,column,row)?
foreground:background;
if(pixels[(y+row)*stride+x+column]!=expected)return 0;
}
return 1;
}
static int console_tests(void) {
u32 pixels[16*16];
CHECK(!bob64_framebuffer_init((u64)(uintptr_t)pixels,sizeof(pixels),16,16,16,0)&&
bob64_framebuffer_available(),"initialize a valid GOP framebuffer");
CHECK(pixels[0]==0x001c120cu&&pixels[5]==0x001c120cu,
"clear framebuffer and encode GOP RGB-reserved pixels");
bob64_framebuffer_write("B");
CHECK(pixels[0]==0x00f8eee4u&&pixels[5]==0x001c120cu,
"render a 5x7 glyph into the framebuffer");
CHECK(!bob64_framebuffer_init((u64)(uintptr_t)pixels,sizeof(pixels),16,16,16,1)&&
pixels[0]==0x000c121cu,
static u32 pixels[1024*20];
static u32 layout_pixels[18*36];
char printable[96];
u32 foreground=0x00f8eee4u,background=0x001c120cu;
CHECK(FONT_WIDTH==8&&FONT_HEIGHT==16&&LINE_HEIGHT==18&&CHAR_SPACING==1&&
FONT_CELL_WIDTH==9,
"define 8x16 terminal glyphs on consistent 9x18 text cells");
CHECK(!bob64_framebuffer_init((u64)(uintptr_t)pixels,sizeof(pixels),1024,20,
1024,0)&&bob64_framebuffer_available(),
"initialize a GOP framebuffer for a full printable ASCII row");
CHECK(pixels[0]==background&&pixels[1023]==background,
"clear the framebuffer and encode GOP RGB-reserved pixels");
for(u32 i=0;i<95;i++)printable[i]=(char)(' '+i);
printable[95]=0;bob64_framebuffer_write(printable);
int all_glyphs_present=1;
for(u32 i=1;i<95;i++)
if(!console_cell_has_ink(pixels,1024,(i%113)*FONT_CELL_WIDTH,
(i/113)*LINE_HEIGHT+(LINE_HEIGHT-FONT_HEIGHT)/2,foreground)) {
all_glyphs_present=0;break;
}
CHECK(all_glyphs_present,
"render every printable ASCII glyph with the 8x16 bitmap font");
CHECK(!bob64_framebuffer_init((u64)(uintptr_t)pixels,sizeof(pixels),1024,20,
1024,0),"reset the framebuffer before glyph distinction checks");
bob64_framebuffer_write("0O1lI5S8B");
CHECK(console_cells_differ(pixels,1024,0,9,1)&&
console_cells_differ(pixels,1024,18,27,1)&&
console_cells_differ(pixels,1024,27,36,1)&&
console_cells_differ(pixels,1024,45,54,1)&&
console_cells_differ(pixels,1024,63,72,1),
"distinguish 0/O, 1/l/I, 5/S, and 8/B glyphs");
CHECK(!bob64_framebuffer_init((u64)(uintptr_t)layout_pixels,
sizeof(layout_pixels),18,36,18,0),
"initialize a two-column, two-row terminal layout");
bob64_framebuffer_write("ABC");
CHECK(console_cell_matches_glyph(layout_pixels,18,0,1,'A',foreground,background)&&
console_cell_matches_glyph(layout_pixels,18,9,1,'B',foreground,background)&&
console_cell_matches_glyph(layout_pixels,18,0,19,'C',foreground,background)&&
layout_pixels[34*18+9]==0x00e8c294u,
"wrap at font-derived columns and align the shell cursor to its cell");
bob64_framebuffer_write("\nD");
CHECK(console_cell_matches_glyph(layout_pixels,18,0,1,'C',foreground,background)&&
console_cell_matches_glyph(layout_pixels,18,0,19,'D',foreground,background),
"scroll by one complete font-derived line without clipping glyphs");
bob64_framebuffer_write("\bE");
CHECK(console_cell_matches_glyph(layout_pixels,18,0,19,'E',foreground,background)&&
!console_cell_matches_glyph(layout_pixels,18,0,19,'D',foreground,background),
"erase and replace the previous glyph across wrapped shell output");
bob64_framebuffer_write("\rZ");
CHECK(console_cell_matches_glyph(layout_pixels,18,0,19,'Z',foreground,background),
"return carriage to the first cell without disturbing line alignment");
CHECK(!bob64_framebuffer_init((u64)(uintptr_t)pixels,sizeof(pixels),1024,20,
1024,1)&&pixels[0]==0x000c121cu,
"clear framebuffer in GOP BGR-reserved pixel format");
bob64_framebuffer_write("B");
CHECK(pixels[0]==0x00e4eef8u,"render BGR-reserved foreground pixels");
CHECK(bob64_framebuffer_init((u64)(uintptr_t)pixels,sizeof(pixels)-1,16,16,16,1)<0&&
CHECK(console_cell_has_ink(pixels,1024,0,1,0x00e4eef8u),
"render glyph pixels with the GOP BGR channel order");
CHECK(bob64_framebuffer_init((u64)(uintptr_t)pixels,sizeof(pixels)-1,
1024,20,1024,1)<0&&
bob64_framebuffer_init((u64)(uintptr_t)pixels,sizeof(pixels),16,16,16,3)<0&&
bob64_framebuffer_init((u64)(uintptr_t)pixels,sizeof(pixels),4,16,16,0)<0,
"reject undersized, blit-only, and too-small framebuffers");
bob64_framebuffer_init((u64)(uintptr_t)pixels,sizeof(pixels),0,16,16,0)<0&&
bob64_framebuffer_init((u64)(uintptr_t)pixels,sizeof(pixels),16,0,16,0)<0,
"reject undersized, unsupported, and zero-dimension framebuffers");
return 0;
}
@@ -4567,8 +4640,20 @@ static int shell_tests(void) {
strstr(output.Text,"restore restore persistent or RAM checkpoint")!=0&&
strstr(output.Text,"cc SOURCE [OUTPUT]")!=0&&
strstr(output.Text,"desktop.b64e [FILE]")!=0&&
strstr(output.Text,"fonttest show the printable ASCII font sample")!=0&&
strstr(output.Text,"Up/Down command history")!=0,
"help lists available commands");
shell_test_command(&shell,"fonttest");
CHECK(output.ClearCount==2&&
strstr(output.Text,"ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n")!=0&&
strstr(output.Text,"abcdefghijklmnopqrstuvwxyz\r\n")!=0&&
strstr(output.Text,"0123456789\r\n\r\n")!=0&&
strstr(output.Text,"0 O\r\n1 l I\r\n5 S\r\n8 B\r\n\r\n")!=0&&
strstr(output.Text,"[] {} () <> / \\ | _ - + = : ; , . ! ?\r\n")!=0&&
strstr(output.Text,"bob64 kernel shell\r\n")!=0&&
strstr(output.Text,"The quick brown fox jumps over the lazy dog.\r\n")!=0&&
strstr(output.Text,"bob!\r\n")!=0,
"fonttest clears the display and prints the full readability sample");
bob64_shell_set_runner(&shell,shell_test_run);
bob64_shell_set_compiler(&shell,shell_test_compile);
shell_test_command(&shell,"cc bob.c demo.b64e");
+3 -1
View File
@@ -1297,10 +1297,12 @@ static void persistence(void) {
storage_path("");
}
static void shell_editing(void) {
char *output=shell("echo bob!\n\033[A\n\033[A\033[Becho bob!\ncle\t\nrea\t bo\t\nwrite backup bob!\nread ba\t\nread b\t\necho bb!\033[D\033[Do\nxxecho bob!\033[H\033[3~\033[3~\nwrong\025echo bob!\nabc\001\033[3~\033[3~\033[3~echo bob!\005\nhalt\n");
char *output=shell("echo bob!\n\033[A\n\033[A\033[Becho bob!\ncle\t\nrea\t bo\t\nwrite backup bob!\nwrite note bo\t\nread note\necho ba\t\nread ba\t\nread b\t\necho bb!\033[D\033[Do\nxxecho bob!\033[H\033[3~\033[3~\nwrong\025echo bob!\nabc\001\033[3~\033[3~\033[3~echo bob!\005\nhalt\n");
contains(output,"\033[2J\033[H");
contains(output,"int main(void) { println(\"bob!\"); return 0; }");
contains(output,"File not found."); /* read b is ambiguous: no completion */
contains(output,"bob> ba\n"); /* echo arguments are never file-completed */
contains(output,"bob> bo\n"); /* write text is not filename-completed */
int markers=0;for(char *p=output;(p=strstr(p,"bob> bob!\n"))!=NULL;p+=10)markers++;
check(markers==8,"history, insertion, delete, home/end and clear line");free(output);
/* History keeps four commands and does not mutate recalled entries. */
+2 -2
View File
@@ -83,7 +83,7 @@ static int decay_type(int type);
static int global_address(Node *n,const char **name,int *offset);
static void binary_typed(int op,int left,int right);
static Node *top, **top_tail=&top;
static uint32_t code[65536];
static uint32_t code[131072];
static int ncode, legacy, wide, serial, return_label;
static uint32_t origin=0x300;
static int wide_app;
@@ -748,7 +748,7 @@ static void parse(void) {
}
parsing_types=0;
}
static void emit(int value) { if(ncode>=65536)error("code too large");code[ncode++]=(uint32_t)value; }
static void emit(int value) { if(ncode>=131072)error("code too large");code[ncode++]=(uint32_t)value; }
static void emit_relocation(const char *name,int offset) {
if(ncode>=65536 || nfixups>=65536)error("code/relocation limit exceeded");
fixups[nfixups++]=(Fixup){ncode,copy(name),offset};emit(0);
+90 -1
View File
@@ -273,6 +273,76 @@ function Assert-FramebufferRendered([string]$path) {
Write-Output " framebuffer: $width x $height, $($colors.Count) sampled colors"
}
function Assert-FontTestFramebuffer([string]$path) {
$qemuPath = $path.Replace('\', '/')
[void](Send-MonitorCommand "screendump $qemuPath" -Capture)
if (-not (Test-Path -LiteralPath $path -PathType Leaf)) {
throw 'QEMU did not produce the font-test framebuffer screenshot.'
}
$bytes = [IO.File]::ReadAllBytes($path)
$headerLength = [Math]::Min($bytes.Length,128)
$headerText = [Text.Encoding]::ASCII.GetString($bytes,0,$headerLength)
$header = [regex]::Match($headerText,'^P6\s+(\d+)\s+(\d+)\s+(\d+)\s')
if (-not $header.Success) { throw 'Font-test screenshot has an invalid PPM header.' }
$width = [int]$header.Groups[1].Value
$height = [int]$header.Groups[2].Value
$dataOffset = $header.Length
if ($width -lt 640 -or $height -lt 240 -or
$bytes.Length-$dataOffset -ne $width*$height*3) {
throw "Font-test screenshot has invalid dimensions or pixel data ($width x $height)."
}
$lines = @(
'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
'abcdefghijklmnopqrstuvwxyz',
'0123456789',
'',
'0 O',
'1 l I',
'5 S',
'8 B',
'',
'[] {} () <> / \ | _ - + = : ; , . ! ?',
'bob64 kernel shell',
'The quick brown fox jumps over the lazy dog.',
'bob!'
)
$background = @(12,18,28)
for ($row=0; $row -lt $lines.Count; $row++) {
$line = $lines[$row]
for ($column=0; $column -lt $line.Length; $column++) {
if ([char]::IsWhiteSpace($line[$column])) { continue }
$foundInk = $false
$left = $column*9
$top = $row*18+1
for ($y=$top; $y -lt $top+16 -and -not $foundInk; $y++) {
for ($x=$left; $x -lt $left+8; $x++) {
$offset = $dataOffset+($y*$width+$x)*3
if ($bytes[$offset] -ne $background[0] -or
$bytes[$offset+1] -ne $background[1] -or
$bytes[$offset+2] -ne $background[2]) {
$foundInk = $true
break
}
}
}
if (-not $foundInk) {
throw "Font-test glyph '$($line[$column])' has no visible pixels at row $row, column $column."
}
}
if ($row -lt 12) {
$spacingY = $row*18+17
for ($x=0; $x -lt $width; $x++) {
$offset=$dataOffset+($spacingY*$width+$x)*3
if ($bytes[$offset] -ne $background[0] -or
$bytes[$offset+1] -ne $background[1] -or
$bytes[$offset+2] -ne $background[2]) {
throw "Font-test line spacing is not clear after row $row."
}
}
}
}
}
$machine = 'q35'
if ($ProbeOnly) { $machine = 'q35,i8042=off' }
$xhciDevice = 'qemu-xhci,id=usb-controller'
@@ -810,6 +880,7 @@ try {
$deadline = [DateTime]::UtcNow.AddSeconds($overallTimeout)
$serialText = ''
$mouseSmokeStarted = $false
$fontTestStarted = $false
$graphicsSmokeStarted = $false
$nativeLauncherSmokeStarted = $false
$compilerSmokeStarted = $false
@@ -829,7 +900,25 @@ try {
break
}
}
if ($allPresent -and -not $mouseSmokeStarted) {
if ($allPresent -and -not $fontTestStarted) {
Send-GuestText 'fonttest'
$fontTestDeadline = [DateTime]::UtcNow.AddSeconds(10)
do {
Start-Sleep -Milliseconds 100
$serialText = [string](Get-Content -LiteralPath $serialPath -Raw)
} while ([DateTime]::UtcNow -lt $fontTestDeadline -and
-not $serialText.Contains(
'The quick brown fox jumps over the lazy dog.'))
if (-not $serialText.Contains(
'The quick brown fox jumps over the lazy dog.')) {
throw "The shell font-test screen did not print its final sample line.`n$serialText"
}
Start-Sleep -Milliseconds 200
Assert-FontTestFramebuffer $framebufferPath
Write-Output ' shell font test: printable ASCII glyphs and 9x18 line spacing passed on the GOP framebuffer'
$fontTestStarted = $true
}
if ($allPresent -and $fontTestStarted -and -not $mouseSmokeStarted) {
$shellMarkerCountBeforeMouse = [regex]::Matches($serialText,
[regex]::Escape($shellPromptMarker)).Count
$exitMarkerCountBeforeMouse = [regex]::Matches($serialText,