fixed doubles becoming nan (was fpu corruption), some render fixes

This commit is contained in:
rgimad
2025-01-05 21:11:58 +03:00
parent 2173fc2774
commit b5dbcecfac
17 changed files with 3410 additions and 24 deletions

View File

@@ -1,5 +1,6 @@
#include "graphics.h"
#include "sprites.h"
#include <assert.h>
static ksys_colors_table_t sys_color_table;
static ksys_pos_t win_pos;
@@ -24,14 +25,75 @@ void graphicsInit() {
}
debug_printf("spriteAtlas->Type = %d\n", spriteAtlas->Type);
screenImage = img_create(DEFAULT_WIDTH, 200, IMAGE_BPP32);
// asm_inline("emms"); // doenst need bec. libimg functions used here does not use mmx (=> does not currept fpu state)
}
// void save_fpu_state(void *fpustate) {
// __asm__("fsave %0" : "=m" (*fpustate) : : "memory");
// }
// void restore_fpu_state(const void *fpustate) {
// __asm__("fnsave %0" : : "m" (*fpustate));
// }
void graphicsBlitAtlasImage(int atlasX, int atlasY, int destX, int destY, int w, int h, bool center) {
// debug_printf("start graphicsBlitAtlasImage %d %d %d %d %d %d %x %x\n", atlasX, atlasY, destX, destY, w, h, screenImage, spriteAtlas);
if (destX < 0 || destY < 0) {
// debug_printf("start graphicsBlitAtlasImage ax = %d ay = %d dx = %d dy = %d w = %d h = %d %x %x\n", atlasX, atlasY, destX, destY, w, h, screenImage, spriteAtlas);
// // asm_inline("int $3");
// if (destX < 0 || destY < 0) {
// return;
// }
// // assert(destX + w <= screenImage->Width && destY + h <= screenImage->Height);
// if (destX + w > screenImage->Width || destY + h > screenImage->Height) {
// return;
// }
int screen_width = (int)screenImage->Width;
int screen_height = (int)screenImage->Height;
if (destX >= screen_width) {
//debug_printf("dX>w!\n");
return;
}
if (destY >= screen_height) {
//debug_printf("dY>h!\n");
return;
}
if (destX < 0) {
destX = 0;
w = destX + w;
}
if (destX + w > screen_width) {
w = screen_width - destX;
}
if (destY < 0) {
destY = 0;
h = destY + h;
}
if (destY + h > screen_height) {
h = screen_height - destY;
}
//printf("start graphicsBlitAtlasImage ax = %d ay = %d dx = %d dy = %d w = %d h = %d %x %x\n\n", atlasX, atlasY, destX, destY, w, h, screenImage, spriteAtlas);
// assert(destX + w <= screen_width && destY + h <= screen_height);
// assert(destX >= 0 && destY >= 0);
// asm_inline("int $3");
/*unsigned char buf[512];
save_fpu_state(buf);
img_blend(screenImage, spriteAtlas, destX, destY, atlasX, atlasY, w, h);
restore_fpu_state(buf);*/
img_blend(screenImage, spriteAtlas, destX, destY, atlasX, atlasY, w, h);
asm_inline("emms");
// debug_printf("end graphicsBlitAtlasImage\n\n");
}