From 5b9f8788399be2879f56e72269985490c5ad9f96 Mon Sep 17 00:00:00 2001 From: tracer-ics2023 Date: Wed, 25 Sep 2024 20:14:58 +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=2020:14:58=20up=207=20days,?= =?UTF-8?q?=2020:15,=20=201=20user,=20=20load=20average:=200.27,=200.25,?= =?UTF-8?q?=200.22?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- navy-apps/libs/libminiSDL/src/video.c | 15 +++++++++------ navy-apps/libs/libndl/NDL.c | 5 +++-- navy-apps/libs/libndl/include/NDL.h | 3 +++ 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/navy-apps/libs/libminiSDL/src/video.c b/navy-apps/libs/libminiSDL/src/video.c index a9f2daa..031cf07 100644 --- a/navy-apps/libs/libminiSDL/src/video.c +++ b/navy-apps/libs/libminiSDL/src/video.c @@ -8,19 +8,22 @@ void SDL_BlitSurface(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_ assert(dst && src); assert(dst->format->BitsPerPixel == src->format->BitsPerPixel == 32); SDL_Rect rect = { - .w = srcrect == NULL ? src->w : srcrect->w, - .h = srcrect == NULL ? src->h : srcrect->h, - .x = dstrect == NULL ? 0 : dstrect->x, - .y = dstrect == NULL ? 0 : dstrect->y, + .w = srcrect ? srcrect->w : src->w, + .h = srcrect ? srcrect->h : src->h, + .x = dstrect ? dstrect->x : 0, + .y = dstrect ? dstrect->y : 0, }; for (int i = 0; i < rect.h; i ++) { - memcpy(((uint32_t*)dst->pixels) + (rect.y + i) * dst->w + rect.x, - ((uint32_t*)src->pixels) + (srcrect->y + i) * src->w + srcrect->x, rect.w); + 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)); } } void SDL_FillRect(SDL_Surface *dst, SDL_Rect *dstrect, uint32_t color) { + assert(0); } 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 01a6e60..3fc5718 100644 --- a/navy-apps/libs/libndl/NDL.c +++ b/navy-apps/libs/libndl/NDL.c @@ -8,6 +8,7 @@ static int evtdev = -1; static int fbdev = -1; static int screen_w = 0, screen_h = 0; +#include #include uint32_t NDL_GetTicks() { struct timeval t; @@ -90,8 +91,8 @@ void NDL_DrawRect(uint32_t *pixels, int x, int y, int w, int h) { int _y = (dev_h - h) / 2; for (int i = 0; i < h; i ++) { // printf("log:%d,%d, dev %d,%d, wh %d,%d, xy %d,%d\n", _x, _y + i, dev_w, dev_h, w, h, x, y); - fseek(fp, (dev_w * (_y + i) + _x) * 4, SEEK_SET); - fwrite(pixels + screen_w * (y + i) + x, 4, w, fp); + fseek(fp, NDL_SCREEN_POS(_x, (_y + i), dev_w, dev_h), SEEK_SET); + fwrite(pixels + NDL_SCREEN_IDX(x, y + i, screen_w, screen_h), 4, w, fp); } fclose(fp); } diff --git a/navy-apps/libs/libndl/include/NDL.h b/navy-apps/libs/libndl/include/NDL.h index 6ff07aa..9dd2d7b 100644 --- a/navy-apps/libs/libndl/include/NDL.h +++ b/navy-apps/libs/libndl/include/NDL.h @@ -20,6 +20,9 @@ void NDL_CloseAudio(); int NDL_PlayAudio(void *buf, int len); int NDL_QueryAudio(); +#define NDL_SCREEN_IDX(x, y, w, h) ( (w) * (y) + (x) ) +#define NDL_SCREEN_POS(x, y, w, h) ( NDL_SCREEN_IDX(x, y, w, h) * 4 ) + #ifdef __cplusplus } #endif