Key input.

This commit is contained in:
ghosind 2021-05-24 22:38:50 +08:00
parent 79f49a9d4e
commit 683b9139b0
7 changed files with 101 additions and 2 deletions

@ -30,7 +30,7 @@ APPS := app/hello.hrb app/hello2.hrb app/a.hrb app/hello3.hrb app/crack1.hrb \
app/crack6.hrb app/bug1.hrb app/bug2.hrb app/bug3.hrb \
app/bug4.hrb app/hello5.hrb app/winhello.hrb app/winhelo2.hrb \
app/winhelo3.hrb app/star1.hrb app/stars.hrb app/stars2.hrb \
app/lines.hrb
app/lines.hrb app/walk.hrb
SYS := haribote.sys
IMG := haribote.img
@ -117,6 +117,10 @@ app/lines.hrb: app/api.o
$(CC) -Wall -Wno-format -Wno-unused -std=gnu99 -m32 -c app/lines.c -o app/lines.o
$(LD) -m elf_i386 --oformat elf32-i386 -e main -pie app/lines.o app/api.o -o app/lines.hrb
app/walk.hrb: app/api.o
$(CC) -Wall -Wno-format -Wno-unused -std=gnu99 -m32 -c app/walk.c -o app/walk.o
$(LD) -m elf_i386 --oformat elf32-i386 -e main -pie app/walk.o app/api.o -o app/walk.hrb
kernel.sys: ${K_OBJS} ${L_OBJS}
$(LD) -m elf_i386 --oformat binary -o kernel.sys -T kernel.ld $^

@ -3,6 +3,7 @@
#include "api.h"
#include "console.h"
#include "graphic.h"
#include "io.h"
#include "sheet.h"
#include "task.h"
#include "window.h"
@ -87,6 +88,39 @@ int *hrb_api(int edi, int esi, int ebp, int esp, int ebx, int edx, int ecx,
break;
case 14:
sheet_free((struct Sheet *)ebx);
break;
case 15:
for (;;) {
io_cli();
if (!fifo32_status(&task->fifo)) {
if (eax) {
task_sleep(task);
} else {
io_sti();
reg[7] = -1;
return 0;
}
}
int data = fifo32_get(&task->fifo);
io_sti();
if (data <= 1) {
timer_init(cons->timer, &task->fifo, 1);
timer_set_timer(cons->timer, 50);
}
if (data == 2) {
cons->cur_c = COL8_FFFFFF;
}
if (data == 3) {
cons->cur_c = -1;
}
if (256 <= data && data <= 511) {
reg[7] = data - 256;
return 0;
}
}
break;
default:
break;

@ -5,6 +5,7 @@
GLOBAL api_putstr_win, api_boxfill_win
GLOBAL api_malloc_init, api_malloc, api_free
GLOBAL api_point, api_refresh_win, api_line_win
GLOBAL api_get_key
api_putchar:
MOV EDX, 1
@ -166,3 +167,9 @@ api_close_win: ; void api_close_win(int win);
INT 0x40
POP EBX
RET
api_get_key: ; int api_get_key(int mode);
MOV EDX, 15
MOV EAX, [ESP+4]
INT 0x40
RET

@ -20,4 +20,6 @@ void api_point(int win, int x, int y, int col);
void api_line_win(int win, int x0, int y0, int x1, int y1, int col);
void api_refresh_win(int win, int x0, int y0, int x1, int y1);
int api_get_key(int mode);
#endif // U_API_H

@ -12,8 +12,14 @@ int main() {
}
api_refresh_win(win, 6, 26, 154, 90);
for (;;) {
if (api_get_key(1) == 0x0a) {
break;
}
}
api_close_win(win);
api_end();
return 0;

44
day23/app/walk.c Normal file

@ -0,0 +1,44 @@
#include "api.h"
int main() {
api_malloc_init();
char *buf = api_malloc(160 * 100);
int win = api_open_win(buf, 160, 100, -1, "walk");
api_boxfill_win(win, 4, 24, 155, 95, 0);
int x = 76;
int y = 56;
api_putstr_win(win, x, y, 3, 1, "*");
for (;;) {
int data = api_get_key(1);
api_putstr_win(win, x, y, 0, 1, "*");
if (data == '4' && x > 4) {
x -= 8;
}
if (data == '6' && x < 148) {
x += 8;
}
if (data == '8' && y > 24) {
y -= 8;
}
if (data == '2' && y < 80) {
y += 8;
}
if (data == 0x0a) {
break;
}
api_putstr_win(win, x, y, 3, 1, "*");
}
api_close_win(win);
api_end();
return 0;
}

@ -1,4 +1,5 @@
#include "sheet.h"
#include "timer.h"
#ifndef _CONSOLE_H_
#define _CONSOLE_H_
@ -6,6 +7,7 @@
struct Console {
struct Sheet *sheet;
int cur_x, cur_y, cur_c;
struct Timer *timer;
};
void console_task(struct Sheet *sheet, unsigned int memtotal);