34 printf(
"ERROR: Not enough VRAM for this allocation!\n");
49 return CurrentPointer;
88 p_data = p_store = (u64 *)
gsGlobal->dma_misc;
176 callback_id = AddIntcHandler(INTC_VBLANK_S, vsync_callback, 0);
177 EnableIntc(INTC_VBLANK_S);
179 GsPutIMR(GsGetIMR() & ~0x0800);
189 GsPutIMR(GsGetIMR() | 0x0800);
190 DisableIntc(INTC_VBLANK_S);
191 RemoveIntcHandler(INTC_VBLANK_S, callback_id);
200 callback_id = AddIntcHandler(INTC_GS, hsync_callback, 0);
203 GsPutIMR(GsGetIMR() & ~0x0400);
213 GsPutIMR(GsGetIMR() | 0x0400);
214 DisableIntc(INTC_GS);
215 RemoveIntcHandler(INTC_GS, callback_id);
224 callback_id = AddIntcHandler(INTC_GS, finish_callback, 0);
227 GsPutIMR(GsGetIMR() & ~0x0200);
237 GsPutIMR(GsGetIMR() | 0x0200);
238 DisableIntc(INTC_GS);
239 RemoveIntcHandler(INTC_GS, callback_id);
243#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
252 u32 count = (slices * 2) + 1;
253 u128 flat_content[count];
258 flat_content[0] = (u128)rgbaq_to_RGBAQ(color).rgbaq;
259 for (index = 0; index < slices; index++)
261 flat_content[index * 2 + 1] = vertex_to_XYZ2(
gsGlobal, index * 64, 0, 0).xyz2;
264 gsKit_prim_list_sprite_flat(
gsGlobal, count, flat_content);
282 *p_data++ = ScissorBounds;
386 *p_data++ = GS_SETREG_TEX1(0, 0, FilterMode, FilterMode, 0, 0, 0);
400 memcpy(p_data, &texClut,
sizeof(gs_texclut));
521 *(u64 *)Queue->
dma_tag = DMA_TAG(Queue->
tag_size, 0, DMA_END, 0, 0, 0);
591 u8 *p = memalign(64, size);
594 SyncDCache(p, p+size-1);
597 p = (u8*)((u32)p | 0x30000000);
606 p = (u64 *)((u32)p & ~0x30000000);
616 Queue->
pool_max[0] = (u64 *)((u32)Queue->pool[0] + size);
622 Queue->
pool_max[1] = (u64 *)((u32)Queue->pool[1] + size);
625 Queue->
dma_tag = Queue->pool[0];
626 Queue->
pool_cur = (u64 *)((u32)Queue->pool[0] + 16);
639 if (Queue->pool[0] != NULL)
642 Queue->pool[0] = NULL;
645 if (Queue->pool[1] != NULL)
648 Queue->pool[1] = NULL;
void dmaKit_wait_fast(void)
void dmaKit_send_ucab(u16 channel, void *data, u32 size)
void dmaKit_send_chain_ucab(u16 channel, void *data)
int gsKit_add_finish_handler(int(*finish_callback)(int))
Installs a finish interrupt handler.
#define GS_CMODE_CLAMP
Stretches Texture Across the Surface.
#define GS_ATEST_OFF
Turns off Alpha Testing (Source).
void gsKit_switch_context(GSGLOBAL *gsGlobal)
void gsKit_setactive(GSGLOBAL *gsGlobal)
Sets Your Active Framebuffer.
#define GS_VRAM_BLOCKSIZE_8K
VRAM Allcoate Blocksize (For System Buffers)(CRITICAL FOR VRAM ALIGNMENT).
void gsKit_queue_exec_real(GSGLOBAL *gsGlobal, GSQUEUE *Queue)
Specific Draw Queue "Execution" (Kicks the Queue passed for the second argument).
int gsKit_add_vsync_handler(int(*vsync_callback)(int))
Installs a vsync interrupt handler (vblank_start).
#define GS_ATEST_ON
Turns on Alpha Testing (Source).
#define GS_D_ATEST_OFF
Turns off Alpha Testing (Destination).
void gsKit_queue_reset(GSQUEUE *Queue)
Reset specified drawqueue to it's initial state (Useful for clearing the Persistent Queue).
#define GS_SCISSOR_RESET
Resets SCISSOR values to the entire display bounds.
#define GS_ZTEST_OFF
Turns off Z Testing.
#define GS_CMODE_REGION_REPEAT
Repeats a Portion of the Texture Defined by UMSK (MINU), VMSK (MINV), UFIX (MAXU),...
int gsKit_add_hsync_handler(int(*hsync_callback)(int))
Installs a hsync interrupt handler (hblank_start).
void gsKit_remove_finish_handler(int callback_id)
Removes a finish interrupt handler.
void gsKit_get_field(GSGLOBAL *gsGlobal)
Sets gsGlobal->EvenOrOdd depending on current field drawing.
#define GS_D_ATEST_ON
Turns on Alpha Testing (Destination).
void gsKit_vram_clear(GSGLOBAL *gsGlobal)
GS VRAM Clear.
void gsKit_vsync_nowait(void)
Initiates a vsync but doesn't block.
void gsKit_set_clamp(GSGLOBAL *gsGlobal, u8 Preset)
void gsKit_queue_set(GSGLOBAL *gsGlobal, GSQUEUE *Queue)
Set Current Draw Queue.
void gsKit_clear(GSGLOBAL *gsGlobal, u64 Color)
u32 gsKit_vram_alloc(GSGLOBAL *gsGlobal, u32 size, u8 type)
GS VRAM Allocation.
void gsKit_set_scissor(GSGLOBAL *gsGlobal, u64 ScissorBounds)
void gsKit_set_dither(GSGLOBAL *gsGlobal)
Enables/Disables dithering, with the gsGlobal Dithering option.
void gsKit_remove_vsync_handler(int callback_id)
Removes a vsync interrupt handler.
void gsKit_hsync_wait(void)
Blocks until a HSync.
void gsKit_display_buffer(GSGLOBAL *gsGlobal)
#define GS_ZTEST_ON
Turns on Z Testing.
void gsKit_set_texfilter(GSGLOBAL *gsGlobal, u8 FilterMode)
Sets the Texture Filtering Parameters.
GSQUEUE gsKit_set_finish(GSGLOBAL *gsGlobal)
Append the Current Queue with a GS_FINISH Register.
void gsKit_set_dither_matrix(GSGLOBAL *gsGlobal)
Sets the Dither Matrix Setting.
#define GS_CMODE_REGION_CLAMP
Stretches Texture Across the Region Defined by MINU, MAXU, MINV, and MAXV.
#define GS_CMODE_REPEAT
Repeats ("Tiles") Texture Across the Surface.
void gsKit_lock_buffer(GSGLOBAL *gsGlobal)
void gsKit_free_ucab(void *p)
Free UCAB buffer in GSQUEUE, internal use only.
void gsKit_remove_hsync_handler(int callback_id)
Removes a hsync interrupt handler.
void gsKit_set_primalpha(GSGLOBAL *gsGlobal, u64 AlphaMode, u8 PerPixel)
Sets the Alpha Blending Parameters.
#define GS_VRAM_BLOCKSIZE_256
VRAM Allcoate Blocksize (For User Textures)(CRITICAL FOR VRAM ALIGNMENT).
#define GSKIT_ALLOC_ERROR
Return this is VRAM allocation fails.
void gsKit_queue_free(GSGLOBAL *gsGlobal, GSQUEUE *Queue)
Free Allocated Memory for Draw Queue.
void gsKit_set_drawfield(GSGLOBAL *gsGlobal, u8 field)
Sets the GS to draw only on even/odd/both fields (from libgraph).
void gsKit_set_test(GSGLOBAL *gsGlobal, u8 Preset)
int gsKit_lock_status(GSGLOBAL *gsGlobal)
void gsKit_vsync_wait(void)
Blocks Until a VSync.
void gsKit_queue_init(GSGLOBAL *gsGlobal, GSQUEUE *Queue, u8 mode, int size)
Initialize a Draw Queue (Allocates memory for the Queue).
void gsKit_queue_exec(GSGLOBAL *gsGlobal)
Normal User Draw Queue "Execution" (Kicks Oneshot and Persistent Queues).
void gsKit_set_texclut(GSGLOBAL *gsGlobal, gs_texclut texClut)
Sets the CLUT position specfications.
#define GSKIT_ALLOC_SYSBUFFER
GS VRAM "System" Allocation (Framebuffer, ZBuffer, etc).
void gsKit_mode_switch(GSGLOBAL *gsGlobal, u8 mode)
Set Current Draw Queue (Between GS_ONESHOT and GS_PERSISTENT).
void gsKit_unlock_buffer(GSGLOBAL *gsGlobal)
void gsKit_finish(void)
Blocks until FINISH is triggered.
void gsKit_sync_flip(GSGLOBAL *gsGlobal)
void * gsKit_alloc_ucab(int size)
Allocate UCAB buffer in GSQUEUE, internal use only.
#define GIF_TAG_AD(NLOOP)
A+D GIFTAG.
#define GS_FRAME_1
GS Frame Buffer (Context 1).
#define GS_DTHE
GS Dither Control.
#define GS_PER_OS
Draw Persistent objects first, before oneshot objects.
#define GS_SETREG_CSR_FINISH(A)
CSR FINISH Register Writing Routine.
#define GS_FRAME_2
GS Frame Buffer (Context 2).
#define GS_SETREG_TEST(ate, atst, aref, afail, date, datm, zte, ztst)
GS TEST Packing Macro.
#define GS_FINISH
FINISH Event Occourence.
#define GS_CSR_FINISH
CSR FINISH Register Access Routine.
#define GS_CLAMP_1
GS Texture Wrap Mode (Context 1).
#define GS_FIELD_ODD
Odd Field Mode - Draws only odd lines.
#define GS_SETTING_OFF
Define a setting to be OFF.
#define GIF_TAG(NLOOP, EOP, PRE, PRIM, FLG, NREG)
DMA Packet Header "GIF Tag" For Packets Sent To GIF.
#define GS_DIMX
GS Dither Matrix.
#define GS_SETREG_SCISSOR(scax0, scax1, scay0, scay1)
GS SCISSOR Packing Macro.
#define GS_SETTING_ON
Define a setting to be ON.
#define GS_ONESHOT
Oneshot Draw Queue.
#define GS_TEX1_1
GS Texture Information Settings (Context 1).
#define GS_SCANMSK
GS Raster Address Mask.
#define GIF_AD
GIF_TAG Address+Data Setting. (Used after GIF_TAG).
#define GS_PERSISTENT
Persistent Draw Queue.
#define GS_SCISSOR_2
GS Scissoring Area (Context 2).
#define GS_SCISSOR_1
GS Scissoring Area (Context 1).
#define GS_FIELD_NORMAL
Normal Field Mode - Draws all lines.
#define GIF_RESERVED
Reserved GIF Tag. This is never sent, only used for sanity checks.
#define GS_TEST_1
GS TEST (Context 1).
#define GS_PABE
GS Alpha Blending (In Pixel Units).
#define GS_FIELD_EVEN
Even Field Mode - Draws only even lines.
#define GS_SETREG_SCISSOR_1
See GS_SETREG_SCISSOR.
#define GS_ALPHA_1
GS Alpha Blending (Context 1).
#define GS_SETREG_CLAMP(wms, wmt, minu, maxu, minv, maxv)
GS CLAMP Packing Macro.
#define GS_SETREG_FRAME_1
See GS_SETREG_FRAME.
#define GS_SET_DISPFB2(FBP, FBW, PSM, DBX, DBY)
GS Framebuffer Register Access Macro (Output Circuit 2).
#define GS_SETREG_DIMX(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P)
GS DIMX Packing Macro from dma.h in ps2sdk.
#define GS_CSR
GS CSR (GS System Status) Register.
#define GSKIT_GIF_FLG_PACKED
gsKit GIFTAG data format "FLG"
void gsKit_TexManager_init(GSGLOBAL *gsGlobal)
Initialize the texture manager.
int MAXU
Maximum Horizontal Clamp Value.
int MINV
Minimum Vertical Clamp Value.
u8 WMS
Wrap Mode Horizontal.
u8 WMT
Wrap Mode Vertical.
int MAXV
Maximum Vertical Clamp Value.
int MINU
Minimum Horizontal Clamp Value.
u8 ActiveBuffer
Active Framebuffer.
u8 EvenOrOdd
Is ((GSREG*)CSR)->FIELD (Used for Interlace Correction).
int Width
Framebuffer Width (the mode's DW is a multiple of this value).
u32 CurrentPointer
Current VRAM Pointer.
u8 Dithering
Dithering (On/Off).
GSTEST * Test
TEST Register Value Structure Pointer.
int PrimContext
Primitive Context.
GSQUEUE * CurQueue
Draw Queue (Current).
u32 TexturePointer
Pointer to beginning of Texture Buffer.
u8 DoubleBuffering
Enable/Disable Double Buffering.
GSQUEUE * Os_Queue
Draw Queue (Oneshot).
u32 ScreenBuffer[2]
Screenbuffer Pointer Array.
int PSM
Pixel Storage Method (Color Mode).
u8 DrawOrder
Drawing Order (GS_PER_OS/GS_OS_PER) (GS_PER_OS = Persitant objects always drawn first).
int Height
Framebuffer Height (the mode's DH is a multiple of this value).
u64 PrimAlpha
Primitive Alpha Value.
GSCLAMP * Clamp
CLAMP Register Value Structure Pointer.
u8 PABE
Choose if to do Alpha Blend on a Per-Pixel Basis.
s8 DitherMatrix[16]
Dithering Matrix.
u8 FirstFrame
Have we executed a frame yet?
GSQUEUE * Per_Queue
Draw Queue (Persistent).
volatile u8 LockBuffer
Used to lock the buffer so it doesn't switch.
void * dma_tag
Pointer to last DMA_TAG.
int same_obj
Number of times in a row the same REGLIST enabled object has been added (Used for NLOOP fixup later).
void * pool_max[2]
Pool Maximum Address (Used for bounds checking).
void * pool_cur
Current Pool Address (Offset from Base).
u8 mode
Mode of the draw queue (NOT USED RIGHT NOW).
void * last_tag
Pointer to the GIF_TAG of the last object in this draw queue.
int dbuf
Which of the pool[2] buffers we are using.
int last_type
Last type of object in this draw queue.
u32 tag_size
Quadwords in current DMA_TAG.
u8 ATST
Alpha Test Method.
u8 ZTE
Depth Test Enable (DO NOT USE THIS - IT IS BUGGED IN PARTICULAR GS REV - SET TO 1 ALWAYS).
u8 DATE
Destination Alpha Enable.
u8 DATM
Destination Alpha Mode.
u8 ZTST
Depth Test Method.
u8 AREF
Alpha Reference Value.
u8 AFAIL
Alpha Failure Action.