Skip to content
This repository has been archived by the owner on Dec 4, 2021. It is now read-only.

Commit

Permalink
Draw mouse cursor
Browse files Browse the repository at this point in the history
  • Loading branch information
tyfkda committed Feb 28, 2014
1 parent 743a26a commit a046982
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 7 deletions.
50 changes: 45 additions & 5 deletions bootpack.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,44 @@ int sprintf(char *str, const char *fmt, ...) {
return dst - str;
}

void init_mouse_cursor8(unsigned char* mouse, char bc) {
static const char cursor[16][16] = {
"**************..",
"*ooooooooooo*...",
"*oooooooooo*....",
"*ooooooooo*.....",
"*oooooooo*......",
"*ooooooo*.......",
"*ooooooo*.......",
"*oooooooo*......",
"*oooo**ooo*.....",
"*ooo*..*ooo*....",
"*oo*....*ooo*...",
"*o*......*ooo*..",
"**........*ooo*.",
"*..........*ooo*",
"............*oo*",
".............***",
};
for (int y = 0; y < 16; ++y) {
for (int x = 0; x < 16; ++x) {
unsigned char c = bc;
switch (cursor[y][x]) {
case '*': c = COL8_BLACK; break;
case 'o': c = COL8_WHITE; break;
}
mouse[y * 16 + x] = c;
}
}
}

void putblock8_8(unsigned char* vram, int xsize, int pxsize, int pysize,
int px0, int py0, const unsigned char* buf, int bxsize) {
for (int y = 0; y < pysize; ++y)
for (int x = 0; x < pxsize; ++x)
vram[(py0 + y) * xsize + (px0 + x)] = buf[y * bxsize + x];
}

struct BOOTINFO {
char cyls, leds, vmode, reserve;
short scrnx, scrny;
Expand All @@ -143,13 +181,15 @@ void HariMain(void) {
struct BOOTINFO* binfo = (struct BOOTINFO*)0x0ff0;
init_screen(binfo->vram, binfo->scrnx, binfo->scrny);

putfonts8_asc(binfo->vram, binfo->scrnx, 8, 8, COL8_WHITE, "ABC 123");
putfonts8_asc(binfo->vram, binfo->scrnx, 31, 31, COL8_BLACK, "Haribote OS");
putfonts8_asc(binfo->vram, binfo->scrnx, 30, 30, COL8_WHITE, "Haribote OS");
unsigned char mcursor[256];
init_mouse_cursor8(mcursor, COL8_DARK_CYAN);
int mx = (binfo->scrnx - 16) / 2;
int my = (binfo->scrny - 28 - 16) / 2;
putblock8_8(binfo->vram, binfo->scrnx, 16, 16, mx, my, mcursor, 16);

char s[40];
sprintf(s, "scrnx = %d", binfo->scrnx);
putfonts8_asc(binfo->vram, binfo->scrnx, 16, 64, COL8_WHITE, s);
sprintf(s, "(%d, %d)", mx, my);
putfonts8_asc(binfo->vram, binfo->scrnx, 0, 0, COL8_WHITE, s);

for (;;)
io_hlt();
Expand Down
4 changes: 2 additions & 2 deletions harimain.ls
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ SECTIONS {
LONG(128 * 1024) /* 0 : stack+.data+heap の大きさ(4KBの倍数) */
LONG(0x69726148) /* 4 : シグネチャ "Hari" */
LONG(0) /* 8 : mmarea の大きさ(4KBの倍数) */
LONG(0x1000) /* 12 : スタック初期値&.data転送先 */
LONG(0x2000) /* 12 : スタック初期値&.data転送先 */
LONG(SIZEOF(.data)) /* 16 : .dataサイズ */
LONG(LOADADDR(.data)) /* 20 : .dataの初期値列のファイル位置 */
LONG(0xE9000000) /* 24 : 0xE9000000 */
Expand All @@ -15,7 +15,7 @@ SECTIONS {

.text : { *(.text) }

.data 0x1000 : AT ( ADDR(.text) + SIZEOF(.text) ) {
.data 0x2000 : AT ( ADDR(.text) + SIZEOF(.text) ) {
*(.data)
*(.rodata*)
*(.bss)
Expand Down

0 comments on commit a046982

Please sign in to comment.