Skip to content

Instantly share code, notes, and snippets.

@F0bes
Created May 15, 2022 18:36
Show Gist options
  • Save F0bes/e98dceac010ff4176868cfe69f054c11 to your computer and use it in GitHub Desktop.
Save F0bes/e98dceac010ff4176868cfe69f054c11 to your computer and use it in GitHub Desktop.
EE_OBJS = tc_test.o
EE_BIN = tc_test.elf
EE_LIBS = -lkernel -lpacket -lgraph -ldraw -ldma
all: $(EE_BIN)
include $(PS2SDK)/samples/Makefile.pref
include $(PS2SDK)/samples/Makefile.eeglobal
#include <draw.h>
#include <graph.h>
#include <packet.h>
#include <gs_psm.h>
#include <dma.h>
#include <kernel.h>
framebuffer_t fb;
void setup_gs()
{
graph_vram_clear();
fb.address = graph_vram_allocate(640, 480, GS_PSM_24, GRAPH_ALIGN_PAGE);
fb.psm = GS_PSM_24;
fb.width = 640;
fb.height = 480;
graph_initialize(fb.address,fb.width,fb.height,fb.psm,0,0);
packet_t* packet = packet_init(30, PACKET_NORMAL);
qword_t* q = packet->data;
zbuffer_t zb;
zb.enable = 0;
zb.address = 0;
zb.mask = 0;
zb.method = 0;
zb.zsm = 0;
q = draw_setup_environment(q, 0, &fb, &zb);
dma_channel_send_normal(DMA_CHANNEL_GIF, &packet[0], q - packet->data, 0, 0);
graph_wait_vsync();
packet_free(packet);
}
void draw()
{
packet_t* packet = packet_init(10, PACKET_NORMAL);
qword_t* q = packet->data;
q = PACK_GIFTAG(q, GIF_SET_TAG(1, 1, GIF_PRE_ENABLE, GIF_SET_PRIM(GIF_PRIM_SPRITE, 0, 0, 0, 0, 0, 0, 0, 0), GIF_FLG_PACKED, 3),
GIF_REG_RGBAQ | (GIF_REG_XYZ2 << 4) | (GIF_REG_XYZ2 << 8));
q++;
// RGBAQ
q->dw[0] = (u64)(100) | ((u64)0 << 32);
q->dw[1] = (u64)(0) | ((u64)1 << 32);
q++;
// XYZ2
q->dw[0] = (u64)((((0 << 4)) | (((u64)(0 << 4)) << 32)));
q->dw[1] = (u64)(0);
q++;
// XYZ2
q->dw[0] = (u64)((((100 << 4)) | (((u64)(100 << 4)) << 32)));
q->dw[1] = (u64)(0);
q++;
q = draw_finish(q);
dma_channel_send_normal(DMA_CHANNEL_GIF, packet->data, q - packet->data, 0, 0);
draw_wait_finish();
graph_wait_vsync();
packet_free(packet);
}
int main()
{
setup_gs();
draw();
SleepThread();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment