mirror of
https://github.com/yourtion/30dayMakeOS.git
synced 2026-02-11 13:55:03 +08:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8ab05adb43 | ||
|
|
76c2755631 | ||
|
|
1b91f073c0 | ||
|
|
e7be9e0dfd | ||
|
|
b5f993ad72 | ||
|
|
094c0ccd8f | ||
|
|
8594061b02 | ||
|
|
6d4706d26c |
@@ -6,6 +6,8 @@ NASK = $(TOOLPATH)nask.exe
|
|||||||
CC1 = $(TOOLPATH)cc1.exe -I$(INCPATH) -Os -Wall -quiet
|
CC1 = $(TOOLPATH)cc1.exe -I$(INCPATH) -Os -Wall -quiet
|
||||||
GAS2NASK = $(TOOLPATH)gas2nask.exe -a
|
GAS2NASK = $(TOOLPATH)gas2nask.exe -a
|
||||||
OBJ2BIM = $(TOOLPATH)obj2bim.exe
|
OBJ2BIM = $(TOOLPATH)obj2bim.exe
|
||||||
|
MAKEFONT = $(TOOLPATH)makefont.exe
|
||||||
|
BIN2OBJ = $(TOOLPATH)bin2obj.exe
|
||||||
BIM2HRB = $(TOOLPATH)bim2hrb.exe
|
BIM2HRB = $(TOOLPATH)bim2hrb.exe
|
||||||
RULEFILE = $(TOOLPATH)haribote/haribote.rul
|
RULEFILE = $(TOOLPATH)haribote/haribote.rul
|
||||||
EDIMG = $(TOOLPATH)edimg.exe
|
EDIMG = $(TOOLPATH)edimg.exe
|
||||||
@@ -38,9 +40,15 @@ bootpack.obj : bootpack.nas Makefile
|
|||||||
naskfunc.obj : naskfunc.nas Makefile
|
naskfunc.obj : naskfunc.nas Makefile
|
||||||
$(NASK) naskfunc.nas naskfunc.obj naskfunc.lst
|
$(NASK) naskfunc.nas naskfunc.obj naskfunc.lst
|
||||||
|
|
||||||
bootpack.bim : bootpack.obj naskfunc.obj Makefile
|
hankaku.bin : hankaku.txt Makefile
|
||||||
|
$(MAKEFONT) hankaku.txt hankaku.bin
|
||||||
|
|
||||||
|
hankaku.obj : hankaku.bin Makefile
|
||||||
|
$(BIN2OBJ) hankaku.bin hankaku.obj _hankaku
|
||||||
|
|
||||||
|
bootpack.bim : bootpack.obj naskfunc.obj hankaku.obj Makefile
|
||||||
$(OBJ2BIM) @$(RULEFILE) out:bootpack.bim stack:3136k map:bootpack.map \
|
$(OBJ2BIM) @$(RULEFILE) out:bootpack.bim stack:3136k map:bootpack.map \
|
||||||
bootpack.obj naskfunc.obj
|
bootpack.obj naskfunc.obj hankaku.obj
|
||||||
# 3MB+64KB=3136KB
|
# 3MB+64KB=3136KB
|
||||||
|
|
||||||
bootpack.hrb : bootpack.bim Makefile
|
bootpack.hrb : bootpack.bim Makefile
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
void io_hlt(void);
|
void io_hlt(void);
|
||||||
void io_cli(void);
|
void io_cli(void);
|
||||||
void io_out8(int port, int data);
|
void io_out8(int port, int data);
|
||||||
@@ -8,6 +10,10 @@ void init_palette(void);
|
|||||||
void set_palette(int start, int end, unsigned char *rgb);
|
void set_palette(int start, int end, unsigned char *rgb);
|
||||||
void boxfill8(unsigned char *vram, int xsize, unsigned char c, int x0, int y0, int x1, int y1);
|
void boxfill8(unsigned char *vram, int xsize, unsigned char c, int x0, int y0, int x1, int y1);
|
||||||
void init_screen(char *vram, int x, int y);
|
void init_screen(char *vram, int x, int y);
|
||||||
|
void putfont8(char *vram, int xsize, int x, int y, char c, char *font);
|
||||||
|
void putfonts8_asc(char *vram, int xsize, int x, int y, char c, unsigned char *s);
|
||||||
|
void init_mouse_cursor8(char *mouse, char bc);
|
||||||
|
void putblock8_8(char *vram, int vxsize, int pxsize, int pysize, int px0, int py0, char *buf, int bxsize);
|
||||||
|
|
||||||
#define COL8_000000 0
|
#define COL8_000000 0
|
||||||
#define COL8_FF0000 1
|
#define COL8_FF0000 1
|
||||||
@@ -32,19 +38,45 @@ struct BOOTINFO {
|
|||||||
char *vram;
|
char *vram;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct SEGMENT_DESCRIPTOR {
|
||||||
|
short limit_low, base_low;
|
||||||
|
char base_mid, access_right;
|
||||||
|
char limit_high, base_high;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct GATE_DESCRIPTOR {
|
||||||
|
short offset_low, selector;
|
||||||
|
char dw_count, access_right;
|
||||||
|
short offset_high;
|
||||||
|
};
|
||||||
|
|
||||||
|
void init_gdtidt(void);
|
||||||
|
void set_segmdesc(struct SEGMENT_DESCRIPTOR *sd, unsigned int limit, int base, int ar);
|
||||||
|
void set_gatedesc(struct GATE_DESCRIPTOR *gd, int offset, int selector, int ar);
|
||||||
|
void load_gdtr(int limit, int addr);
|
||||||
|
void load_idtr(int limit, int addr);
|
||||||
|
|
||||||
void HariMain(void)
|
void HariMain(void)
|
||||||
{
|
{
|
||||||
char *vram;/* 声明变量vram、用于BYTE [...]地址 */
|
struct BOOTINFO *binfo = (struct BOOTINFO *) 0x0ff0;
|
||||||
int xsize, ysize;
|
char s[40], mcursor[256];
|
||||||
struct BOOTINFO *binfo;
|
int mx, my;
|
||||||
|
|
||||||
init_palette();
|
init_palette();
|
||||||
binfo = (struct BOOTINFO *) 0x0ff0;
|
init_screen(binfo->vram, binfo->scrnx, binfo->scrny);
|
||||||
xsize = (*binfo).scrnx;
|
|
||||||
ysize = (*binfo).scrny;
|
|
||||||
vram = (*binfo).vram;
|
|
||||||
|
|
||||||
init_screen(vram, xsize, ysize);
|
/* 显示鼠标 */
|
||||||
|
mx = (binfo->scrnx - 16) / 2; /* 计算画面的中心坐标*/
|
||||||
|
my = (binfo->scrny - 28 - 16) / 2;
|
||||||
|
init_mouse_cursor8(mcursor, COL8_008484);
|
||||||
|
putblock8_8(binfo->vram, binfo->scrnx, 16, 16, mx, my, mcursor, 16);
|
||||||
|
|
||||||
|
putfonts8_asc(binfo->vram, binfo->scrnx, 8, 8, COL8_FFFFFF, "ABC 123");
|
||||||
|
putfonts8_asc(binfo->vram, binfo->scrnx, 31, 31, COL8_000000, "Haribote OS.");
|
||||||
|
putfonts8_asc(binfo->vram, binfo->scrnx, 30, 30, COL8_FFFFFF, "Haribote OS.");
|
||||||
|
|
||||||
|
sprintf(s, "scrnx = %d", binfo->scrnx);
|
||||||
|
putfonts8_asc(binfo->vram, binfo->scrnx, 16, 64, COL8_FFFFFF, s);
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
io_hlt();
|
io_hlt();
|
||||||
@@ -123,3 +155,132 @@ void init_screen(char *vram, int x, int y)
|
|||||||
boxfill8(vram, x, COL8_FFFFFF, x - 3, y - 24, x - 3, y - 3);
|
boxfill8(vram, x, COL8_FFFFFF, x - 3, y - 24, x - 3, y - 3);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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];
|
||||||
|
/* C语言中,字符串都是以0x00结尾 */
|
||||||
|
for (; *s != 0x00; s++) {
|
||||||
|
putfont8(vram, xsize, x, y, c, hankaku + *s * 16);
|
||||||
|
x += 8;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void init_mouse_cursor8(char *mouse, char bc)
|
||||||
|
/* マウスカーソルを準備(16x16) */
|
||||||
|
{
|
||||||
|
static char cursor[16][16] = {
|
||||||
|
"**************..",
|
||||||
|
"*OOOOOOOOOOO*...",
|
||||||
|
"*OOOOOOOOOO*....",
|
||||||
|
"*OOOOOOOOO*.....",
|
||||||
|
"*OOOOOOOO*......",
|
||||||
|
"*OOOOOOO*.......",
|
||||||
|
"*OOOOOOO*.......",
|
||||||
|
"*OOOOOOOO*......",
|
||||||
|
"*OOOO**OOO*.....",
|
||||||
|
"*OOO*..*OOO*....",
|
||||||
|
"*OO*....*OOO*...",
|
||||||
|
"*O*......*OOO*..",
|
||||||
|
"**........*OOO*.",
|
||||||
|
"*..........*OOO*",
|
||||||
|
"............*OO*",
|
||||||
|
".............***"
|
||||||
|
};
|
||||||
|
int x, y;
|
||||||
|
|
||||||
|
for (y = 0; y < 16; y++) {
|
||||||
|
for (x = 0; x < 16; x++) {
|
||||||
|
if (cursor[y][x] == '*') {
|
||||||
|
mouse[y * 16 + x] = COL8_000000;
|
||||||
|
}
|
||||||
|
if (cursor[y][x] == 'O') {
|
||||||
|
mouse[y * 16 + x] = COL8_FFFFFF;
|
||||||
|
}
|
||||||
|
if (cursor[y][x] == '.') {
|
||||||
|
mouse[y * 16 + x] = bc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void putblock8_8(char *vram, int vxsize, int pxsize,
|
||||||
|
int pysize, int px0, int py0, char *buf, int bxsize)
|
||||||
|
{
|
||||||
|
int x, y;
|
||||||
|
for (y = 0; y < pysize; y++) {
|
||||||
|
for (x = 0; x < pxsize; x++) {
|
||||||
|
vram[(py0 + y) * vxsize + (px0 + x)] = buf[y * bxsize + x];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void init_gdtidt(void)
|
||||||
|
{
|
||||||
|
struct SEGMENT_DESCRIPTOR *gdt = (struct SEGMENT_DESCRIPTOR *) 0x00270000;
|
||||||
|
struct GATE_DESCRIPTOR *idt = (struct GATE_DESCRIPTOR *) 0x0026f800;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
/* GDT初始化 */
|
||||||
|
for (i = 0; i < 8192; i++) {
|
||||||
|
set_segmdesc(gdt + i, 0, 0, 0);
|
||||||
|
}
|
||||||
|
set_segmdesc(gdt + 1, 0xffffffff, 0x00000000, 0x4092);
|
||||||
|
set_segmdesc(gdt + 2, 0x0007ffff, 0x00280000, 0x409a);
|
||||||
|
load_gdtr(0xffff, 0x00270000);
|
||||||
|
|
||||||
|
/* IDT初始化 */
|
||||||
|
for (i = 0; i < 256; i++) {
|
||||||
|
set_gatedesc(idt + i, 0, 0, 0);
|
||||||
|
}
|
||||||
|
load_idtr(0x7ff, 0x0026f800);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_segmdesc(struct SEGMENT_DESCRIPTOR *sd, unsigned int limit, int base, int ar)
|
||||||
|
{
|
||||||
|
if (limit > 0xfffff) {
|
||||||
|
ar |= 0x8000; /* G_bit = 1 */
|
||||||
|
limit /= 0x1000;
|
||||||
|
}
|
||||||
|
sd->limit_low = limit & 0xffff;
|
||||||
|
sd->base_low = base & 0xffff;
|
||||||
|
sd->base_mid = (base >> 16) & 0xff;
|
||||||
|
sd->access_right = ar & 0xff;
|
||||||
|
sd->limit_high = ((limit >> 16) & 0x0f) | ((ar >> 8) & 0xf0);
|
||||||
|
sd->base_high = (base >> 24) & 0xff;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_gatedesc(struct GATE_DESCRIPTOR *gd, int offset, int selector, int ar)
|
||||||
|
{
|
||||||
|
gd->offset_low = offset & 0xffff;
|
||||||
|
gd->selector = selector;
|
||||||
|
gd->dw_count = (ar >> 8) & 0xff;
|
||||||
|
gd->access_right = ar & 0xff;
|
||||||
|
gd->offset_high = (offset >> 16) & 0xffff;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|||||||
4609
05_day/hankaku.txt
Normal file
4609
05_day/hankaku.txt
Normal file
File diff suppressed because it is too large
Load Diff
@@ -10,6 +10,7 @@
|
|||||||
GLOBAL _io_in8, _io_in16, _io_in32
|
GLOBAL _io_in8, _io_in16, _io_in32
|
||||||
GLOBAL _io_out8, _io_out16, _io_out32
|
GLOBAL _io_out8, _io_out16, _io_out32
|
||||||
GLOBAL _io_load_eflags, _io_store_eflags
|
GLOBAL _io_load_eflags, _io_store_eflags
|
||||||
|
GLOBAL _load_gdtr, _load_idtr
|
||||||
|
|
||||||
[SECTION .text]
|
[SECTION .text]
|
||||||
|
|
||||||
@@ -75,3 +76,15 @@ _io_store_eflags: ; void io_store_eflags(int eflags);
|
|||||||
PUSH EAX
|
PUSH EAX
|
||||||
POPFD ; POP EFLAGS
|
POPFD ; POP EFLAGS
|
||||||
RET
|
RET
|
||||||
|
|
||||||
|
_load_gdtr: ; void load_gdtr(int limit, int addr);
|
||||||
|
MOV AX,[ESP+4] ; limit
|
||||||
|
MOV [ESP+6],AX
|
||||||
|
LGDT [ESP+6]
|
||||||
|
RET
|
||||||
|
|
||||||
|
_load_idtr: ; void load_idtr(int limit, int addr);
|
||||||
|
MOV AX,[ESP+4] ; limit
|
||||||
|
MOV [ESP+6],AX
|
||||||
|
LIDT [ESP+6]
|
||||||
|
RET
|
||||||
Reference in New Issue
Block a user