moving the triangle!

This commit is contained in:
2025-03-28 10:16:36 -06:00
parent 2a131e300c
commit 74d678d0bb

75
main.c
View File

@ -12,6 +12,9 @@
#include <stdio.h> #include <stdio.h>
#include <inttypes.h> #include <inttypes.h>
#include <gs_gp.h> #include <gs_gp.h>
#include <stdlib.h>
#define myftoi4(x) ((x)<<4)
#ifdef DEBUG #ifdef DEBUG
#define DEBUG_MSG(...) printf(__VA_ARGS__) #define DEBUG_MSG(...) printf(__VA_ARGS__)
@ -19,8 +22,12 @@
#define DEBUG_MSG(...) #define DEBUG_MSG(...)
#endif #endif
#define OFFSET_X 0
#define OFFSET_Y 0 #define OFFSET_X 2048
#define OFFSET_Y 2048
#define VID_W 640
#define VID_H 448
int print_buffer(qword_t *b, int len) { int print_buffer(qword_t *b, int len) {
DEBUG_MSG("-- buffer\n"); DEBUG_MSG("-- buffer\n");
@ -36,13 +43,12 @@ int gs_finish() {
qword_t buff[50]; qword_t buff[50];
qword_t *q = buff; qword_t *q = buff;
//TODO: Remove! //TODO: Remove!
q = draw_primitive_xyoffset(q, 0, 0, 0);
q = draw_finish(q); q = draw_finish(q);
dma_channel_send_normal(DMA_CHANNEL_GIF, buff, q-buff, 0, 0); dma_channel_send_normal(DMA_CHANNEL_GIF, buff, q-buff, 0, 0);
dma_wait_fast(); dma_wait_fast();
return 0; return 0;
} }
zbuffer_t *z;
int gs_init(int width, int height, int psm, int psmz, int vmode, int gmode) { int gs_init(int width, int height, int psm, int psmz, int vmode, int gmode) {
framebuffer_t fb; framebuffer_t fb;
fb.address = graph_vram_allocate(width, height, psm, GRAPH_ALIGN_PAGE); fb.address = graph_vram_allocate(width, height, psm, GRAPH_ALIGN_PAGE);
@ -50,43 +56,47 @@ int gs_init(int width, int height, int psm, int psmz, int vmode, int gmode) {
fb.height = height; fb.height = height;
fb.psm = psm; fb.psm = psm;
fb.mask = 0; fb.mask = 0;
zbuffer_t zb; z->address = graph_vram_allocate(width, height, psmz, GRAPH_ALIGN_PAGE);
zb.address = graph_vram_allocate(width, height, psmz, GRAPH_ALIGN_PAGE); z->enable = 0;
zb.enable = 0; z->method = 0;
zb.method = 0; z->zsm = 0;
zb.zsm = psmz; z->mask = 0;
zb.mask = 0;
graph_set_mode(gmode, vmode, GRAPH_MODE_FIELD, GRAPH_DISABLE); graph_set_mode(gmode, vmode, GRAPH_MODE_FIELD, GRAPH_DISABLE);
graph_set_screen(OFFSET_X, OFFSET_Y, width, height); graph_set_screen(0, 0, width, height);
graph_set_bgcolor(0, 0, 0); graph_set_bgcolor(0, 0, 0);
graph_set_framebuffer_filtered(fb.address, width, psm, 0, 0); graph_set_framebuffer_filtered(fb.address, width, psm, 0, 0);
graph_enable_output(); graph_enable_output();
qword_t buf[100]; qword_t buf[100];
qword_t *q = buf; qword_t *q = buf;
q = draw_setup_environment(q, 0, &fb, &zb); q = draw_setup_environment(q, 0, &fb, z);
q = draw_primitive_xyoffset(q, 0, 2048-(VID_W/2), 2048-(VID_H/2));
q = draw_finish(q);
dma_channel_send_normal(DMA_CHANNEL_GIF, buf, q-buf, 0, 0); dma_channel_send_normal(DMA_CHANNEL_GIF, buf, q-buf, 0, 0);
dma_wait_fast(); dma_wait_fast();
gs_finish();
return 0; return 0;
} }
static int tri[] = { static int tri[] = {
10, 0, 0, 10, 10, 0,
600, 200, 0, 600, 200, 0,
20, 400, 0 20, 400, 0
}; };
#define SHIFT_AS_I64(x, b) (((uint64_t)x)<<b); #define SHIFT_AS_I64(x, b) (((uint64_t)x)<<b);
uint64_t red = 0xf0;
uint64_t blue = 0x0f;
uint64_t green = 0xf0;
int draw() { int draw() {
uint64_t red = 0xf0;
uint64_t blue = 0x0f;
uint64_t green = 0x0f;
qword_t buf[50]; qword_t buf[50];
qword_t *q = buf; qword_t *q = buf;
q = draw_disable_tests(q, 0, z);
q = draw_clear(q, 0, 2048.0f - 320, 2048.0f - 244, VID_W, VID_H, 20, 20, 20);
//q = draw_enable_tests(q, 0, z);
// GIFTag header - 3x(col, pos) // GIFTag header - 3x(col, pos)
q->dw[0] = 0x7000000000008001; q->dw[0] = 0x7000000000000001;
q->dw[1] = 0x0000000005151510; q->dw[1] = 0x0000000005151510;
q++; q++;
@ -94,20 +104,27 @@ int draw() {
q->dw[1] = 0; q->dw[1] = 0;
q++; q++;
int cx = myftoi4(2048 - (VID_W/2));
int cy = myftoi4(2048 - (VID_H/2));
for(int i = 0; i < 3; i++){ for(int i = 0; i < 3; i++){
q->dw[0] = (red&0xff) | (green&0xff)<<32; q->dw[0] = (red&0xff) | (green&0xff)<<32;
q->dw[1] = (blue&0xff) | SHIFT_AS_I64(0x80, 32); q->dw[1] = (blue&0xff) | SHIFT_AS_I64(0x80, 32);
q++; q++;
q->dw[0] = (tri[i*3+0]<<4) | SHIFT_AS_I64(tri[i*3+1]<<4,32); int base = i*3;
q->dw[1] = (tri[i*3+2]<<4); int x = myftoi4(tri[base+0]) + cx;
int y = myftoi4(tri[base+1]) + cy;
int z = myftoi4(tri[base+2]);
q->dw[0] = x | SHIFT_AS_I64(y, 32);
q->dw[1] = z;
q++; q++;
} }
q = draw_finish(q);
print_buffer(buf, q-buf); print_buffer(buf, q-buf);
dma_channel_send_normal(DMA_CHANNEL_GIF, buf, q-buf, 0, 0); dma_channel_send_normal(DMA_CHANNEL_GIF, buf, q-buf, 0, 0);
dma_wait_fast(); dma_wait_fast();
gs_finish(); //gs_finish();
return 0; return 0;
} }
@ -122,12 +139,20 @@ int main() {
dma_channel_fast_waits(DMA_CHANNEL_GIF); dma_channel_fast_waits(DMA_CHANNEL_GIF);
DEBUG_MSG("DMA Initialized...\n"); DEBUG_MSG("DMA Initialized...\n");
// initialize graphics mode // initialize graphics mode
gs_init(640, 480, GS_PSM_32, GS_PSMZ_24, GRAPH_MODE_NTSC, GRAPH_MODE_INTERLACED); gs_init(VID_W, VID_H, GS_PSM_32, GS_PSMZ_24, GRAPH_MODE_NTSC, GRAPH_MODE_INTERLACED);
DEBUG_MSG("GS Initialized...\n"); DEBUG_MSG("GS Initialized...\n");
// clear screen // clear screen
draw();
// build buffer with triangle data // build buffer with triangle data
while(1); z = malloc(sizeof(zbuffer_t));
while(1) {
tri[0]++;
if(tri[0] > 480) {
tri[0] = 0;
}
draw();
graph_wait_vsync();
}
} }