diff --git a/main.c b/main.c index ac5db37..0da54d8 100644 --- a/main.c +++ b/main.c @@ -8,9 +8,11 @@ #include #include #include +#include +#include #ifdef DEBUG -#define DEBUG_MSG(...) scr_printf(__VA_ARGS__) +#define DEBUG_MSG(...) printf(__VA_ARGS__) #else #define DEBUG_MSG(...) #endif @@ -18,6 +20,26 @@ #define OFFSET_X 0 #define OFFSET_Y 0 +int print_buffer(qword_t *b, int len) { + DEBUG_MSG("-- buffer\n"); + for(int i = 0; i < len; i++) { + DEBUG_MSG("%016llx %016llx\n", b->dw[0], b->dw[1]); + b++; + } + DEBUG_MSG("-- /buffer\n"); + return 0; +} + +int gs_finish() { + qword_t buff[50]; + qword_t *q = buff; + q = draw_primitive_xyoffset(q, 0, 0, 0); + q = draw_finish(q); + dma_channel_send_normal(DMA_CHANNEL_GIF, buff, q-buff, 0, 0); + dma_wait_fast(); + return 0; +} + int gs_init(int width, int height, int psm, int psmz, int vmode, int gmode) { int fb_address = graph_vram_allocate(width, height, psm, GRAPH_ALIGN_PAGE); graph_set_mode(gmode, vmode, GRAPH_MODE_FIELD, GRAPH_DISABLE); @@ -26,12 +48,42 @@ int gs_init(int width, int height, int psm, int psmz, int vmode, int gmode) { graph_set_framebuffer_filtered(fb_address, width, psm, 0, 0); graph_enable_output(); - qword_t buff[20]; - qword_t *q = buff; - q = draw_primitive_xyoffset(q, 0, 0, 0); - q = draw_finish(q); - dma_channel_send_normal(DMA_CHANNEL_GIF, buff, q-buff, 0, 0); + gs_finish(); + return 0; +} + +static int tri[] = { + 10, 0, 0, + 600, 200, 0, + 20, 400, 0 +}; + +int draw() { + + uint64_t red = 0xf0; + uint64_t blue = 0x0f; + uint64_t green = 0x0f; + qword_t buf[50]; + qword_t *q = buf; + // GIFTag header - 3x(col, pos) + q->dw[0] = 0x6000000000008001; + q->dw[1] = 0x0000000000515151; + q++; + + for(int i = 0; i < 3; i++){ + q->dw[0] = (red&0xff) | (green&0xff)<<32; + q->dw[1] = (blue&0xff) | (0x80 << 32); + q++; + + q->dw[0] = (tri[i+0]<<4) | (tri[i+1]<<4)<<32; + q->dw[1] = (tri[i+2]<<4); + q++; + } + + print_buffer(buf, q-buf); + dma_channel_send_normal(DMA_CHANNEL_GIF, buf, q-buf, 0, 0); dma_wait_fast(); + gs_finish(); return 0; } @@ -44,12 +96,14 @@ int main() { // initialize DMAC dma_channel_initialize(DMA_CHANNEL_GIF, 0, 0); dma_channel_fast_waits(DMA_CHANNEL_GIF); - DEBUG_MSG("DMA Initialized..."); + DEBUG_MSG("DMA Initialized...\n"); // initialize graphics mode gs_init(664, 480, GS_PSM_32, GS_PSMZ_32, GRAPH_MODE_NTSC, GRAPH_MODE_FIELD); - DEBUG_MSG("GS Initialized..."); + DEBUG_MSG("GS Initialized...\n"); // clear screen + draw(); + // build buffer with triangle data - sleep(5); + while(1); } \ No newline at end of file