Make your own OS in 30 days – day5: Characters and Mouse Cursor

VRAM address, x/y size were hard coded in Day 4 example.

vram = (char *) 0xa0000;
xsize = 320;
ysize = 200;

Day 5 reads it from 0x0ff4 set by asmhead.nas via BOOTINFO struct as below.
asmhead.nas:

; BOOT_INFO
CYLS    EQU             0x0ff0 
LEDS    EQU             0x0ff1
VMODE   EQU             0x0ff2 
SCRNX   EQU             0x0ff4 
SCRNY   EQU             0x0ff6 
VRAM    EQU             0x0ff8 
...
MOV		BYTE [VMODE],8
MOV		WORD [SCRNX],320
MOV		WORD [SCRNY],200
MOV		DWORD [VRAM],0x000a0000

bootpack.c:

struct BOOTINFO {
 char cyls, leds, vmode, reserve;
 short scrnx, scrny;
 char *vram;
};

void HariMain(void)
{
 struct BOOTINFO *binfo = (struct BOOTINFO *) 0x0ff0;                                                                                              
...
 init_screen8(binfo->vram, binfo->scrnx, binfo->scrny);

Then it creates ASCII bitmap fonts and a mouse cursor from obj file built from text files like this.

char 0x31
........
....*...
...**...
..*.*...
....*...
....*...
....*...
....*...
....*...
....*...
....*...
....*...
....*...
..*****.
........
........

And use it like this. Finally we can get variable values on the screen for debugging. Since we don’t have debug output or more fancy port to get debug info, this is useful during OS creation time.

void putfont8(char *vram, int xsize, int x, int y, char c, char *font)
{
	int i;
	char *p, d /* data */;
	for (i = 0; i < 16; i++) {
		p = vram + (y + i) * xsize + x;
		d = font[i];
		if ((d & 0x80) != 0) { p[0] = c; }
		if ((d & 0x40) != 0) { p[1] = c; }
		if ((d & 0x20) != 0) { p[2] = c; }
		if ((d & 0x10) != 0) { p[3] = c; }
		if ((d & 0x08) != 0) { p[4] = c; }
		if ((d & 0x04) != 0) { p[5] = c; }
		if ((d & 0x02) != 0) { p[6] = c; }
		if ((d & 0x01) != 0) { p[7] = c; }
	}
	return;
}

void putfonts8_asc(char *vram, int xsize, int x, int y, char c, unsigned char *s)
{
	extern char hankaku[4096]; // <-- stored in obj file as _hankaku
	for (; *s != 0x00; s++) {
		putfont8(vram, xsize, x, y, c, hankaku + *s * 16);
		x += 8;
	}
	return;
}

Then it explains GDT; Global Descriptor Table, IDT; Interrupt Descriptor Table, Segmentation Interrupt or etc to control devices such as a mouse/keyboard/NIC.

Screen Shot 2014-10-13 at 22.22.37

Leave a Reply

Your email address will not be published. Required fields are marked *