> 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
 20:14:58 up 7 days, 20:15,  1 user,  load average: 0.27, 0.25, 0.22
This commit is contained in:
tracer-ics2023
2024-09-25 20:14:58 +08:00
committed by zzy
parent 389f8eecde
commit 5b9f878839
3 changed files with 15 additions and 8 deletions

View File

@ -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) {

View File

@ -8,6 +8,7 @@ static int evtdev = -1;
static int fbdev = -1;
static int screen_w = 0, screen_h = 0;
#include <NDL.h>
#include <sys/time.h>
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);
}

View File

@ -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