Skip to content

Instantly share code, notes, and snippets.

@jeandrek
Created July 23, 2025 02:24
Show Gist options
  • Save jeandrek/184ba32769cb555082b57f231c72309b to your computer and use it in GitHub Desktop.
Save jeandrek/184ba32769cb555082b57f231c72309b to your computer and use it in GitHub Desktop.
/*
* compile with DJGPP
*/
#include <stdio.h>
#include <conio.h>
#include <dos.h>
#include <pc.h>
void
rect(int w, int h)
{
for (int j = 0; j < h; j++) {
for (int i = 0; i < w; i++) {
putchar('\xdb');
}
putchar('\n');
}
}
void
draw_bitmap(int bitmap[], int w, int h, int x, int y)
{
for (int j = 0; j < h; j++) {
for (int i = 0; i < w; i++) {
ScreenSetCursor(y + j, 2*(x + i));
if ((bitmap[j] >> (w - 1 - i)) & 1) printf("\xdb\xdb");
else printf(" ");
}
}
}
struct glyph {
int width;
int bitmap[5];
} glyphs[127] = {
['a'] = {
3,
0b010,
0b101,
0b111,
0b101,
0b101
},
['b'] = {
3,
0b110,
0b101,
0b110,
0b101,
0b110
},
['c'] = {
3,
0b111,
0b101,
0b100,
0b101,
0b111
},
['d'] = {
3,
0b110,
0b101,
0b101,
0b101,
0b110
},
['e'] = {
3,
0b111,
0b100,
0b111,
0b100,
0b111
},
['f'] = {
3,
0b111,
0b100,
0b111,
0b100,
0b100
},
['g'] = {
3,
0b111,
0b101,
0b111,
0b001,
0b111
},
['h'] = {
3,
0b101,
0b101,
0b111,
0b101,
0b101
},
['i'] = {
3,
0b111,
0b010,
0b010,
0b010,
0b111
},
['j'] = {
4,
0b1111,
0b0010,
0b0010,
0b1010,
0b0110
},
['k'] = {
3,
0b101,
0b101,
0b110,
0b101,
0b101
},
['l'] = {
3,
0b100,
0b100,
0b100,
0b100,
0b111
},
['m'] = {
5,
0b01010,
0b10101,
0b10101,
0b10101,
0b10101
},
['n'] = {
3,
0b111,
0b101,
0b101,
0b101,
0b101
},
['o'] = {
3,
0b111,
0b101,
0b101,
0b101,
0b111
},
['p'] = {
3,
0b111,
0b101,
0b111,
0b100,
0b100
},
['q'] = {
3,
0b111,
0b101,
0b111,
0b010,
0b001
},
['r'] = {
3,
0b111,
0b101,
0b110,
0b101,
0b101
},
['s'] = {
3,
0b111,
0b100,
0b111,
0b001,
0b111
},
['t'] = {
3,
0b111,
0b010,
0b010,
0b010,
0b010
},
['u'] = {
3,
0b101,
0b101,
0b101,
0b101,
0b111
},
['v'] = {
3,
0b101,
0b101,
0b101,
0b101,
0b010
},
['w'] = {
5,
0b10101,
0b10101,
0b10101,
0b10101,
0b01010
},
['x'] = {
3,
0b101,
0b101,
0b010,
0b101,
0b101
},
['y'] = {
3,
0b101,
0b101,
0b010,
0b010,
0b010
},
['z'] = {
3,
0b111,
0b001,
0b010,
0b100,
0b111
},
['0'] = {
3,
0b010,
0b101,
0b101,
0b101,
0b010
},
['1'] = {
3,
0b010,
0b110,
0b010,
0b010,
0b111
},
['2'] = {
3,
0b010,
0b101,
0b001,
0b010,
0b111
},
['3'] = {
3,
0b110,
0b001,
0b111,
0b001,
0b110
},
['4'] = {
3,
0b101,
0b101,
0b111,
0b001,
0b001
},
['5'] = {
3,
0b111,
0b100,
0b111,
0b001,
0b110
},
['6'] = {
3,
0b011,
0b100,
0b111,
0b101,
0b010
},
['7'] = {
3,
0b111,
0b001,
0b001,
0b010,
0b100
},
['8'] = {
3,
0b111,
0b101,
0b111,
0b101,
0b111
},
['9'] = {
3,
0b111,
0b101,
0b111,
0b001,
0b110
}
};
void
draw_string(char *s)
{
int w = 0;
for (int i = 0; s[i] != 0; i++) {
if (s[i] == ' ') {
w += 2;
} else {
struct glyph *g = &glyphs[s[i]];
draw_bitmap(g->bitmap, g->width, 5, w, 0);
w += g->width + 1;
}
}
}
void
draw_bitmap_column(int bitmap[], int w, int i, int x)
{
for (int y = 0; y < 5; y++) {
ScreenSetCursor(y, 2*(x + i));
if ((bitmap[y] >> (w - 1 - i)) & 1) printf("\xdb\xdb");
else printf(" ");
}
}
void
marquee(char *s, int window, int shift)
{
int w = 0;
for (int i = 0; s[i] != 0; i++) {
if (s[i] == ' ') {
w += 2;
} else {
struct glyph *g = &glyphs[s[i]];
for (int j = 0; j < g->width; j++) {
if (w + j - shift >= window)
return;
if (w + j >= shift)
draw_bitmap_column(g->bitmap, g->width, j, w - shift);
}
w += g->width + 1;
}
}
}
int
main(int argc, char *argv)
{
int n = -39;
for (;;) {
clrscr();
marquee("abcdefghijklmnopqrstuvwxyz 0123456789", 40, n++);
delay(50);
if (n >= 150) n = -39;
if (kbhit()) break;
/*
int c = getch();
if (c == ' ') break;
struct glyph *g = &glyphs[c];
clrscr();
draw_bitmap(g->bitmap, g->width, 5, 0, 0);
*/
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment