From cccb4ad2439b0d6424ec392951e8c2f0da5bbc4c Mon Sep 17 00:00:00 2001 From: tracer-ics2023 Date: Thu, 26 Sep 2024 00:53:25 +0800 Subject: [PATCH] =?UTF-8?q?>=20=20compile=20NEMU=20221220000=20=E5=BC=A0?= =?UTF-8?q?=E4=B8=89=20Linux=20zzy=205.15.146.1-microsoft-standard-WSL2=20?= =?UTF-8?q?#1=20SMP=20Thu=20Jan=2011=2004:09:03=20UTC=202024=20x86=5F64=20?= =?UTF-8?q?x86=5F64=20x86=5F64=20GNU/Linux=20=2000:53:25=20up=208=20days,?= =?UTF-8?q?=2053=20min,=20=201=20user,=20=20load=20average:=200.32,=200.28?= =?UTF-8?q?,=200.27?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nanos-lite/src/proc.c | 2 +- navy-apps/Makefile | 4 ++-- navy-apps/libs/libminiSDL/src/video.c | 33 +++++++++++++++++++++------ navy-apps/libs/libndl/NDL.c | 4 +++- 4 files changed, 32 insertions(+), 11 deletions(-) diff --git a/nanos-lite/src/proc.c b/nanos-lite/src/proc.c index 1a55beb..644abc1 100644 --- a/nanos-lite/src/proc.c +++ b/nanos-lite/src/proc.c @@ -26,7 +26,7 @@ void init_proc() { // load program here void naive_uload(PCB *pcb, const char *filename); - naive_uload(NULL, "/bin/nslider"); + naive_uload(NULL, "/bin/menu"); } diff --git a/navy-apps/Makefile b/navy-apps/Makefile index 544bf07..3826cf4 100644 --- a/navy-apps/Makefile +++ b/navy-apps/Makefile @@ -47,7 +47,7 @@ ARCHIVE = $(WORK_DIR)/build/$(NAME)-$(ISA).a ### Add default libraries for ISA != native ifneq ($(ISA), native) -LIBS += libc libos libndl libbmp libminiSDL +LIBS += libc libos libndl libbmp libminiSDL libbdf CFLAGS += -U_FORTIFY_SOURCE # fix compile error in Newlib on ubuntu else WL = -Wl, @@ -166,7 +166,7 @@ $(CLEAN_ALL): .PHONY: clean-all $(CLEAN_ALL) ### Build fsimg and ramdisk for Nanos-lite -APPS = nslider +APPS = nslider menu TESTS = dummy hello file-test timer-test event-test bmp-test fsimg: $(addprefix apps/, $(APPS)) $(addprefix tests/, $(TESTS)) diff --git a/navy-apps/libs/libminiSDL/src/video.c b/navy-apps/libs/libminiSDL/src/video.c index 031cf07..64b099c 100644 --- a/navy-apps/libs/libminiSDL/src/video.c +++ b/navy-apps/libs/libminiSDL/src/video.c @@ -6,24 +6,43 @@ void SDL_BlitSurface(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect) { assert(dst && src); - assert(dst->format->BitsPerPixel == src->format->BitsPerPixel == 32); + assert(dst->format->BitsPerPixel == src->format->BitsPerPixel); + SDL_Rect rect = { .w = srcrect ? srcrect->w : src->w, .h = srcrect ? srcrect->h : src->h, - .x = dstrect ? dstrect->x : 0, - .y = dstrect ? dstrect->y : 0, + .x = srcrect ? srcrect->x : 0, + .y = srcrect ? srcrect->y : 0, }; + // TODO NOT FULL VERSION + int byte_per_pixel = src->format->BytesPerPixel; for (int i = 0; i < rect.h; i ++) { memcpy( - (uint32_t*)dst->pixels + NDL_SCREEN_IDX(rect.x, rect.y, dst->w, dst->h), - (uint32_t*)src->pixels + NDL_SCREEN_IDX(srcrect->x, srcrect->y, rect.x, rect.y), - rect.w * sizeof(uint32_t)); + dst->pixels + byte_per_pixel * NDL_SCREEN_IDX( + dstrect ? dstrect->x : 0, (dstrect ? dstrect->y : 0) + i, dst->w, dst->h), + src->pixels + byte_per_pixel * NDL_SCREEN_IDX( + rect.x, rect.y + i, src->w, src->h), + rect.w * byte_per_pixel); } } void SDL_FillRect(SDL_Surface *dst, SDL_Rect *dstrect, uint32_t color) { - assert(0); + SDL_Rect rect = { + .w = dstrect ? dstrect->w : dst->w, + .h = dstrect ? dstrect->h : dst->h, + .x = dstrect ? dstrect->x : 0, + .y = dstrect ? dstrect->y : 0, + }; + int byte_per_pixel = dst->format->BytesPerPixel; + for (int i = 0; i < rect.h; i ++) { + for (int j = 0; j < rect.w; j ++) { + memcpy( + dst->pixels + byte_per_pixel * NDL_SCREEN_IDX(rect.x + j, rect.y + i, dst->w, dst->h), + &color, + byte_per_pixel); + } + } } void SDL_UpdateRect(SDL_Surface *s, int x, int y, int w, int h) { diff --git a/navy-apps/libs/libndl/NDL.c b/navy-apps/libs/libndl/NDL.c index 2b28214..b40442d 100644 --- a/navy-apps/libs/libndl/NDL.c +++ b/navy-apps/libs/libndl/NDL.c @@ -23,7 +23,7 @@ int NDL_PollEvent(char *buf, int len) { exit(-1); } size_t ret = fread(buf, 1, len, fd); - if (ret) printf("NDL_PollEvent read %d bytes is %s", ret, buf); + // if (ret) printf("NDL_PollEvent read %d bytes is %s", ret, buf); fclose(fd); return ret; } @@ -77,6 +77,8 @@ void NDL_OpenCanvas(int *w, int *h) { _get_screen(&dev_w, &dev_h); screen_w = (*w == 0 || *w > dev_w) ? dev_w : *w; screen_h = (*h == 0 || *h > dev_h) ? dev_h : *h; + *w = screen_w; + *h = screen_h; // printf("NDL_OpenCanvas: %d,%d, dev %d,%d\n", screen_w, screen_h, dev_w, dev_h); }