> compile NEMU
221220000 张三 Linux zzy 5.15.146.1-microsoft-standard-WSL2 #1 SMP Thu Jan 11 04:09:03 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux 23:30:15 up 7 days, 8:27, 1 user, load average: 0.34, 0.32, 0.35
This commit is contained in:
@ -5,5 +5,7 @@
|
||||
|
||||
size_t serial_write(const void *buf, size_t offset, size_t len);
|
||||
size_t events_read(void *buf, size_t offset, size_t len);
|
||||
size_t dispinfo_read(void *buf, size_t offset, size_t len);
|
||||
size_t fb_write(const void *buf, size_t offset, size_t len);
|
||||
|
||||
#endif
|
@ -31,11 +31,14 @@ size_t events_read(void *buf, size_t offset, size_t len) {
|
||||
}
|
||||
|
||||
size_t dispinfo_read(void *buf, size_t offset, size_t len) {
|
||||
return 0;
|
||||
AM_GPU_CONFIG_T gconf = io_read(AM_GPU_CONFIG);
|
||||
return snprintf(buf, len, "WIDTH : %d\nHEIGHT: %d\n", gconf.width, gconf.height);
|
||||
}
|
||||
|
||||
size_t fb_write(const void *buf, size_t offset, size_t len) {
|
||||
return 0;
|
||||
int w = io_read(AM_GPU_CONFIG).width;
|
||||
io_write(AM_GPU_FBDRAW, offset % w, offset / w, (void*)buf, len, 1, true);
|
||||
return len;
|
||||
}
|
||||
|
||||
void init_device() {
|
||||
|
@ -14,7 +14,9 @@ typedef struct {
|
||||
size_t open_offset;
|
||||
} Finfo;
|
||||
|
||||
enum {FD_STDIN, FD_STDOUT, FD_STDERR, FD_EVENTS, FD_FB};
|
||||
enum {FD_STDIN, FD_STDOUT, FD_STDERR,
|
||||
FD_DEV_EVENTS, FD_DEV_FB,
|
||||
FD_PROC_DISPINFO};
|
||||
|
||||
size_t invalid_read(void *buf, size_t offset, size_t len) {
|
||||
panic("should not reach here");
|
||||
@ -31,7 +33,9 @@ static Finfo file_table[] __attribute__((used)) = {
|
||||
[FD_STDIN] = {"stdin", 0, 0, invalid_read, invalid_write},
|
||||
[FD_STDOUT] = {"stdout", 0, 0, invalid_read, serial_write},
|
||||
[FD_STDERR] = {"stderr", 0, 0, invalid_read, serial_write},
|
||||
[FD_EVENTS] = {"/dev/events", 0, 0, events_read, invalid_write},
|
||||
[FD_DEV_EVENTS] = {"/dev/events", 0, 0, events_read, invalid_write},
|
||||
[FD_DEV_FB] = {"/dev/fb", 0, 0, invalid_read, fb_write},
|
||||
[FD_PROC_DISPINFO] = {"/proc/dispinfo", 0, 0, dispinfo_read, invalid_write},
|
||||
#include "files.h"
|
||||
};
|
||||
|
||||
|
@ -26,7 +26,7 @@ void init_proc() {
|
||||
|
||||
// load program here
|
||||
void naive_uload(PCB *pcb, const char *filename);
|
||||
naive_uload(NULL, "/bin/event-test");
|
||||
naive_uload(NULL, "/bin/bmp-test");
|
||||
|
||||
}
|
||||
|
||||
|
@ -167,7 +167,7 @@ $(CLEAN_ALL):
|
||||
|
||||
### Build fsimg and ramdisk for Nanos-lite
|
||||
APPS =
|
||||
TESTS = dummy hello file-test timer-test event-test
|
||||
TESTS = dummy hello file-test timer-test event-test bmp-test
|
||||
|
||||
fsimg: $(addprefix apps/, $(APPS)) $(addprefix tests/, $(TESTS))
|
||||
-for t in $^; do $(MAKE) -s -C $(NAVY_HOME)/$$t install; done
|
||||
|
@ -21,7 +21,9 @@ int NDL_PollEvent(char *buf, int len) {
|
||||
printf("cannot open /dev/events");
|
||||
exit(-1);
|
||||
}
|
||||
return fread(buf, 1, len, fd);
|
||||
size_t ret = fread(buf, 1, len, fd);
|
||||
fclose(fd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void NDL_OpenCanvas(int *w, int *h) {
|
||||
@ -42,9 +44,34 @@ void NDL_OpenCanvas(int *w, int *h) {
|
||||
}
|
||||
close(fbctl);
|
||||
}
|
||||
|
||||
FILE* fp = fopen("/proc/dispinfo", "w");
|
||||
if (fp == NULL) {
|
||||
printf("cannot open /proc/dispinfo");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
int dev_w, dev_h;
|
||||
if (fscanf(fp, "WIDTH %*c %d\nHEIGHT %*c %d", &dev_w, &dev_h) != 2) {
|
||||
printf("cannot parse dispinfo");
|
||||
exit(-1);
|
||||
}
|
||||
fclose(fp);
|
||||
|
||||
screen_w = (*w == 0 || *w > dev_w) ? dev_w : *w;
|
||||
screen_h = (*h == 0 || *h > dev_h) ? dev_h : *h;
|
||||
}
|
||||
|
||||
void NDL_DrawRect(uint32_t *pixels, int x, int y, int w, int h) {
|
||||
FILE* fp = fopen("/dev/fb", "w");
|
||||
if (fp == NULL) {
|
||||
printf("cannot open /dev/fb");
|
||||
exit(-1);
|
||||
}
|
||||
for (int i = 0; i < h; i ++) {
|
||||
fwrite(pixels + (screen_w * (y + i)) + x, sizeof(uint32_t), w, fp);
|
||||
}
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
void NDL_OpenAudio(int freq, int channels, int samples) {
|
||||
|
Reference in New Issue
Block a user