diff --git a/include/kernel/screen.h b/include/kernel/screen.h index 2521155d..1718b855 100755 --- a/include/kernel/screen.h +++ b/include/kernel/screen.h @@ -17,7 +17,6 @@ typedef enum { MODE_m = 'm' } vt100_mode_t; -void move_cursor_by_idx(int idx); void print(const char *str); void screen_clear(); void putchar(int ch); diff --git a/include/loader/screen.h b/include/loader/screen.h index 69762a70..f7ddff10 100755 --- a/include/loader/screen.h +++ b/include/loader/screen.h @@ -4,5 +4,4 @@ int klogf(const char *format, ...); void screen_clear(); void print(const char *str); void screen_ne(); -void move_cursor_by_idx(int idx); void putchar(char ch); diff --git a/src/kernel/cpu/x86.asm b/src/kernel/cpu/x86.asm index d31fd41f..62e49fd7 100755 --- a/src/kernel/cpu/x86.asm +++ b/src/kernel/cpu/x86.asm @@ -1,6 +1,5 @@ [bits 32] - global move_cursor_by_idx - global memtest_sub, start_app + global memtest_sub section .text @@ -52,38 +51,6 @@ memtest_sub: ; u32 memtest_sub(u32 start, u32 end) POP EDI RET -move_cursor_by_idx: ;移动光标 - mov dx, 03d4h ;03d4h是索引端口 - mov al, 0eh ;内部的0eh位置存放着光标位置的高八位 - out dx, al - inc dx ;03d5h是数据端口用于读写数据 - in al, dx ;读取光标的高八位并且放入bh - mov bh, al - - dec dx ;这儿开始读取光标位置的低八位放入bl - mov al, 0fh ;0fh位置存放着光标位置的低八位 - out dx, al - inc dx - in al, dx - mov bl, al - - mov word bx, [esp + 4] ;获取参数中的光标位置 - - mov dx, 03d4h ;这段代码将改变后的光标位置写入端口内相应的地方以便下次访问 - mov al, 0eh ;写入光标位置高八位 - out dx, al - inc dx - mov al, bh - out dx, al - - dec dx - mov al, 0fh ;写入光标位置低八位 - out dx, al - inc dx - mov al, bl - out dx, al - ret - extern task_current global asm_task_switch, asm_task_start ; 注意进入函数时必须 cli diff --git a/src/kernel/io/textmode.c b/src/kernel/io/textmode.c index 2d6b0f5e..ca861284 100755 --- a/src/kernel/io/textmode.c +++ b/src/kernel/io/textmode.c @@ -1,12 +1,27 @@ #include +static int get_cursor_idx() { + asm_out8(0x03d4, 0x0e); + byte hi = asm_in8(0x03d5); + asm_out8(0x03d4, 0x0f); + byte lo = asm_in8(0x03d5); + return (hi << 8) + lo; +} + +static void set_cursor_idx(int idx) { + asm_out8(0x03d4, 0x0e); + asm_out8(0x03d5, idx >> 8); + asm_out8(0x03d4, 0x0f); + asm_out8(0x03d5, idx & 0xff); +} + void MoveCursor_TextMode(struct tty *res, int x, int y) { res->x = x; res->y = y; if (!res->cur_moving) return; int i = y * res->xsize + x; if (res->vram == (void *)0xb8000) { // TODO 移除特判 - move_cursor_by_idx(i); + set_cursor_idx(i); } } diff --git a/src/loader/base/asmfunc.asm b/src/loader/base/asmfunc.asm index 41c64ba2..628de6ec 100755 --- a/src/loader/base/asmfunc.asm +++ b/src/loader/base/asmfunc.asm @@ -1,7 +1,6 @@ [BITS 32] EXTERN flint ; 在 fdc.c 中定义 GLOBAL memtest_sub - GLOBAL move_cursor_by_idx GLOBAL floppy_int [SECTION .text] @@ -64,8 +63,5 @@ mts_nomore: POP EDI RET -move_cursor_by_idx: ;移动光标 - ret - [SECTION .data] testsize: dd 0 diff --git a/src/loader/driver/BasicVideo.c b/src/loader/driver/BasicVideo.c index 582769c0..a62b4e9d 100755 --- a/src/loader/driver/BasicVideo.c +++ b/src/loader/driver/BasicVideo.c @@ -1,5 +1,20 @@ #include +static int get_cursor_idx() { + asm_out8(0x03d4, 0x0e); + byte hi = asm_in8(0x03d5); + asm_out8(0x03d4, 0x0f); + byte lo = asm_in8(0x03d5); + return (hi << 8) + lo; +} + +static void set_cursor_idx(int idx) { + asm_out8(0x03d4, 0x0e); + asm_out8(0x03d5, idx >> 8); + asm_out8(0x03d4, 0x0f); + asm_out8(0x03d5, idx & 0xff); +} + static int x, y; static int cons_x, cons_y; @@ -89,7 +104,7 @@ void putchar(char ch) { } void Move_Cursor(i16 x, i16 y) { int res = y * 80 + x; - move_cursor_by_idx(res); + set_cursor_idx(res); } void print(cstr str) { putstr(str, getlength(str));