warn = -pedantic -Wall -Wno-unused-function
opt = -O2
-inc = -Isrc -Isrc/kern -Isrc/libc
+inc = -Isrc -Isrc/3dgfx -Isrc/kern -Isrc/libc
AS = nasm
void g3d_clear(unsigned int mask)
{
if(mask & G3D_COLOR_BUFFER_BIT) {
- memset16(pfill_fb.pixels, st->clear_color, pfill_fb.width * pfill_fb.height);
+ memset(pfill_fb.pixels, st->clear_color, pfill_fb.width * pfill_fb.height);
}
if(mask & G3D_DEPTH_BUFFER_BIT) {
- memset16(pfill_zbuf, st->clear_depth, pfill_fb.width * pfill_fb.height * sizeof *pfill_zbuf / 2);
+ memset32(pfill_zbuf, st->clear_depth, pfill_fb.width * pfill_fb.height);
}
}
polyfill_tex_flat,
polyfill_tex_gouraud,
0,
- 0, 0, 0, 0, 0, 0, 0, 0,
polyfill_wire,
polyfill_flat_zbuf,
polyfill_gouraud_zbuf,
polyfill_tex_flat_zbuf,
polyfill_tex_gouraud_zbuf,
0,
- 0, 0, 0, 0, 0, 0, 0, 0
};
struct pimage pfill_fb, pfill_tex;
POLYFILL_TEX_FLAT,
POLYFILL_TEX_GOURAUD,
- POLYFILL_WIRE_ZBUF = 16,
+ POLYFILL_WIRE_ZBUF = 8,
POLYFILL_FLAT_ZBUF,
POLYFILL_GOURAUD_ZBUF,
- POLYFILL_TEX_WIRE_ZBUF = 20,
+ POLYFILL_TEX_WIRE_ZBUF = 12,
POLYFILL_TEX_FLAT_ZBUF,
POLYFILL_TEX_GOURAUD_ZBUF
};
#include <string.h>
#include "game.h"
#include "colormgr.h"
+#include "3dgfx.h"
+#include "mesh.h"
+
+static struct g3d_mesh mesh;
int game_init(void)
{
init_colormgr();
+
+ g3d_init();
+ g3d_framebuffer(320, 200, framebuf);
+ g3d_viewport(0, 0, 320, 200);
+
+ g3d_clear_color(0, 0, 0);
+
+ g3d_matrix_mode(G3D_PROJECTION);
+ g3d_load_identity();
+ g3d_perspective(50.0f, 1.33333, 0.5, 500.0);
+
+ g3d_enable(G3D_CULL_FACE);
+ g3d_enable(G3D_DEPTH_TEST);
+ g3d_enable(G3D_LIGHTING);
+ g3d_enable(G3D_LIGHT0);
+
+ g3d_polygon_mode(G3D_GOURAUD);
+
+ gen_torus_mesh(&mesh, 2.0, 0.7, 24, 12);
return 0;
}
void game_draw(void)
{
- int i, j;
- unsigned char *fbptr = framebuf;
-
- for(i=0; i<200; i++) {
- for(j=0; j<320; j++) {
- int r, b;
- int idx = i + (rand() & 0x1f) - 16;
- if(idx < 0) idx = 0;
- if(idx > 199) idx = 199;
-
- r = 255 * idx / 199;
- b = 255 - r;
- *fbptr++ = find_color(r, 0, b);
- }
- }
+ unsigned long msec = game_getmsec();
+ float tsec = (float)msec / 1000.0f;
+
+ g3d_clear(G3D_COLOR_BUFFER_BIT | G3D_DEPTH_BUFFER_BIT);
+
+ g3d_matrix_mode(G3D_MODELVIEW);
+ g3d_load_identity();
+ g3d_translate(0, 0, -8);
+ g3d_rotate(tsec * 50.0f, 1, 0, 0);
+ g3d_rotate(tsec * 30.0f, 0, 0, 1);
+
+ draw_mesh(&mesh);
game_swap_buffers();
}
void game_mouse(int bn, int press, int x, int y);
void game_motion(int x, int y);
+unsigned long game_getmsec(void);
void game_quit(void);
void game_swap_buffers(void);
return 0;
}
+unsigned long game_getmsec(void)
+{
+ return TICKS_TO_MSEC(nticks);
+}
+
void game_quit(void)
{
quit = 1;
mov ax, 1
call far [vmswitch]
; broadcast windows exit
+ xor ax, ax
+ mov bx, ax
+ mov si, ax
+ mov es, ax
+ mov ds, ax
+ mov cx, ax
+ mov dx, ax
mov ax, 1606h
- xor dx, dx
int 2fh
exit: mov ax, 4c00h
str_errvm86 db 'Error: memory manager running. Stop it and try again (e.g. emm386 off)',10,0
str_enterpm db 'Entering 32bit protected mode ...',10,0
+ align 4
vmswitch:
vmswitch_off dw 0
vmswitch_seg dw 0
-%define BUG_WARNING
+%undef BUG_WARNING
%define CON_SERIAL
UART_BASE equ 2f8h ; COM1: 3f8, COM2: 2f8
: "flags", "memory"); \
} while(0)
+/*
+#define memset32(dest, val, count) \
+ asm volatile ( \
+ "cld\n\t" \
+ "rep stosl\n\t" \
+ :: "a"(val), "c"(count), "D"(dest) \
+ : "flags", "memory")
+*/
+#define memset32(dest, val, count) \
+ do { \
+ int i; \
+ uint32_t *ptr = (uint32_t*)dest; \
+ for(i=0; i<count; i++) { \
+ ptr[i] = val; \
+ } \
+ } while(0)
+
+
#ifdef USE_MMX
#define memcpy64(dest, src, count) asm volatile ( \
"0:\n\t" \