ASM update

This commit is contained in:
Frater 2026-05-15 15:17:48 +02:00
commit 9f5478f7eb
3 changed files with 44 additions and 6 deletions

View file

@ -79,7 +79,7 @@ build/app.exe: $(OBJS) MakeFile
$(LINK) @build/link.lnk
clean:
rm -rf build
rm -rf build/*.obj build/*.exe
# Nettoyage des logs d'erreurs
rm -f *.err src/**/*.err

View file

@ -50,8 +50,28 @@ typedef int32_t fixed;
#define f_to_int(a) ((a) >> 16)
#define int_to_f(a) ((a) << 16)
static __inline fixed f_mul(fixed a, fixed b) { return (fixed)(((int64_t)a * b) >> 16); }
static __inline fixed f_div(fixed a, fixed b) { if (b == 0) return 0; return (fixed)(((int64_t)a << 16) / b); }
//static __inline fixed f_mul(fixed a, fixed b) { return (fixed)(((int64_t)a * b) >> 16); }
//static __inline fixed f_div(fixed a, fixed b) { if (b == 0) return 0; return (fixed)(((int64_t)a << 16) / b); }
/* Optimisation OpenWatcom Inline Assembly pour mathématiques 16.16 */
fixed f_mul(fixed a, fixed b);
#pragma aux f_mul = \
"imul edx" \
"shrd eax, edx, 16" \
parm [eax] [edx] value [eax] modify [edx];
fixed f_div(fixed a, fixed b);
#pragma aux f_div = \
"test ebx, ebx" \
"jz div_zero" \
"cdq" \
"shld edx, eax, 16" \
"sal eax, 16" \
"idiv ebx" \
"jmp end_div" \
"div_zero:" \
"xor eax, eax" \
"end_div:" \
parm [eax] [ebx] value [eax] modify [edx];
typedef struct { fixed m[3][3]; } Matrix3;
typedef struct { fixed x, y, z; } Vector3;

View file

@ -26,13 +26,30 @@ uint8_t *vga = (uint8_t *)0xA0000;
void set_vga_mode(int mode);
#pragma aux set_vga_mode = "int 0x10" parm [ax];
void fast_clear_dwords(void *dest, uint32_t val, int count);
#pragma aux fast_clear_dwords = \
"cld" \
"rep stosd" \
parm [edi] [eax] [ecx] modify [edi ecx];
void fast_copy_dwords(void *dest, void *src, int count);
#pragma aux fast_copy_dwords = \
"cld" \
"rep movsd" \
parm [edi] [esi] [ecx] modify [edi esi ecx];
void clear_buffers(uint8_t color) {
memset(backbuffer, color, SCREEN_PIXELS);
memset(zbuffer, 0xFF, SCREEN_PIXELS * sizeof(uint16_t));
//memset(backbuffer, color, SCREEN_PIXELS);
uint32_t c32 = color | (color << 8) | (color << 16) | (color << 24);
fast_clear_dwords(backbuffer, c32, SCREEN_PIXELS / 4);
//memset(zbuffer, 0xFF, SCREEN_PIXELS * sizeof(uint16_t));
fast_clear_dwords(zbuffer, 0xFFFFFFFFUL, SCREEN_PIXELS / 2); /* 2 pixels (16 bits) par itération 32 bits */
}
void clear_zbuffer(void) {
memset(zbuffer, 0xFF, SCREEN_PIXELS * sizeof(uint16_t));
//memset(zbuffer, 0xFF, SCREEN_PIXELS * sizeof(uint16_t));
fast_clear_dwords(zbuffer, 0xFFFFFFFFUL, SCREEN_PIXELS / 2);
}
void blit_image(Image *img, int x, int y) {
@ -106,6 +123,7 @@ void apply_256_palette(RGB *pal) {
}
void flip(void) {
//fast_copy_dwords(vga, backbuffer, SCREEN_PIXELS / 4);
memcpy(vga, backbuffer, SCREEN_PIXELS);
}