sdk-world v2026.11.05
PS2 SDK - world tier (copyleft-allowed, non-essential packages)
Loading...
Searching...
No Matches
gsCore.c
1// ____ ___ | / _____ _____
2// | __ | |___/ | |
3// |___| ___| | \ __|__ | gsKit Open Source Project.
4// ----------------------------------------------------------------------
5// Copyright 2004 - Chris "Neovanglist" Gilbert <Neovanglist@LainOS.org>
6// Licenced under Academic Free License version 2.0
7// Review gsKit README & LICENSE files for further details.
8//
9// gsCore.c - Core functionality implimentations. (Allocators, RenderStates, etc)
10//
11// Parts taken from emoon's BreakPoint Demo Library
12//
13
14#include "gsKit.h"
15#include "gsInline.h"
16
17#include <kernel.h>
18#include <malloc.h>
19
20u32 gsKit_vram_alloc(GSGLOBAL *gsGlobal, u32 size, u8 type)
21{
22 u32 CurrentPointer = gsGlobal->CurrentPointer;
23 #ifdef GSKIT_DEBUG
24 printf("CurrentPointer Before:\t0x%08X\n", gsGlobal->CurrentPointer);
25 #endif
26
27 if(type == GSKIT_ALLOC_SYSBUFFER)
29 else
31
32 if((gsGlobal->CurrentPointer + size)>= 4194304)
33 {
34 printf("ERROR: Not enough VRAM for this allocation!\n");
35 return GSKIT_ALLOC_ERROR;
36 }
37 else
38 {
39 gsGlobal->CurrentPointer += size;
40
41 // Re-initialize the texture manager
42 // NOTE: this is here for compatibility, it's better not to use
43 // gsKit_vram_alloc, and use gsKit_TexManager_bind instead.
45
46 #ifdef GSKIT_DEBUG
47 printf("CurrentPointer After:\t0x%08X\n", gsGlobal->CurrentPointer);
48 #endif
49 return CurrentPointer;
50 }
51}
52
54{
56
57 // Re-initialize the texture manager
58 // NOTE: this is here for compatibility, it's better not to use
59 // gsKit_vram_alloc, and use gsKit_TexManager_bind instead.
61}
62
64{
66 {
68
70 {
72 gsGlobal->Width / 64, gsGlobal->PSM, 0, 0 );
73
75 }
76
77 }
78
80
81}
82
84{
85 u64 *p_data;
86 u64 *p_store;
87
88 p_data = p_store = (u64 *)gsGlobal->dma_misc;
89
90 *p_data++ = GIF_TAG( 4, 1, 0, 0, GSKIT_GIF_FLG_PACKED, 1 );
91 *p_data++ = GIF_AD;
92
93 // Context 1
94
95 *p_data++ = GS_SETREG_SCISSOR_1( 0, gsGlobal->Width - 1, 0, gsGlobal->Height - 1 );
96 *p_data++ = GS_SCISSOR_1;
97
99 gsGlobal->Width / 64, gsGlobal->PSM, 0 );
100 *p_data++ = GS_FRAME_1;
101
102 // Context 2
103
104 *p_data++ = GS_SETREG_SCISSOR_1( 0, gsGlobal->Width - 1, 0, gsGlobal->Height - 1 );
105 *p_data++ = GS_SCISSOR_2;
106
108 gsGlobal->Width / 64, gsGlobal->PSM, 0 );
109 *p_data++ = GS_FRAME_2;
110
112 dmaKit_send_ucab(DMA_CHANNEL_GIF, p_store, 5);
113}
114
115void gsKit_finish(void)
116{
117 while(!(GS_CSR_FINISH));
118}
119
124
129
131{
132 return gsGlobal->LockBuffer;
133}
134
136{
138 gsGlobal->Width / 64, gsGlobal->PSM, 0, 0 );
139}
140
142{
144 gsGlobal->PrimContext ^= 1;
145
147}
148
150{
151 *GS_CSR = *GS_CSR & 8;
152 while(!(*GS_CSR & 8));
153}
154
156{
157 *GS_CSR = *GS_CSR & 8;
158}
159
161{
162 gsGlobal->EvenOrOdd=((GSREG*)GS_CSR)->FIELD;
163}
164
166{
167 *GS_CSR = *GS_CSR & 4;
168 while(!(*GS_CSR & 4));
169}
170
171int gsKit_add_vsync_handler(int (*vsync_callback)(int))
172{
173 int callback_id;
174
175 DIntr();
176 callback_id = AddIntcHandler(INTC_VBLANK_S, vsync_callback, 0);
177 EnableIntc(INTC_VBLANK_S);
178 // Unmask VSync interrupt
179 GsPutIMR(GsGetIMR() & ~0x0800);
180 EIntr();
181
182 return callback_id;
183}
184
185void gsKit_remove_vsync_handler(int callback_id)
186{
187 DIntr();
188 // Mask VSync interrupt
189 GsPutIMR(GsGetIMR() | 0x0800);
190 DisableIntc(INTC_VBLANK_S);
191 RemoveIntcHandler(INTC_VBLANK_S, callback_id);
192 EIntr();
193}
194
195int gsKit_add_hsync_handler(int (*hsync_callback)(int))
196{
197 int callback_id;
198
199 DIntr();
200 callback_id = AddIntcHandler(INTC_GS, hsync_callback, 0);
201 EnableIntc(INTC_GS);
202 // Unmask HSync interrupt
203 GsPutIMR(GsGetIMR() & ~0x0400);
204 EIntr();
205
206 return callback_id;
207}
208
209void gsKit_remove_hsync_handler(int callback_id)
210{
211 DIntr();
212 // Mask HSync interrupt
213 GsPutIMR(GsGetIMR() | 0x0400);
214 DisableIntc(INTC_GS);
215 RemoveIntcHandler(INTC_GS, callback_id);
216 EIntr();
217}
218
219int gsKit_add_finish_handler(int (*finish_callback)(int))
220{
221 int callback_id;
222
223 DIntr();
224 callback_id = AddIntcHandler(INTC_GS, finish_callback, 0);
225 EnableIntc(INTC_GS);
226 // Unmask Finish interrupt
227 GsPutIMR(GsGetIMR() & ~0x0200);
228 EIntr();
229
230 return callback_id;
231}
232
233void gsKit_remove_finish_handler(int callback_id)
234{
235 DIntr();
236 // Mask HSync interrupt
237 GsPutIMR(GsGetIMR() | 0x0200);
238 DisableIntc(INTC_GS);
239 RemoveIntcHandler(INTC_GS, callback_id);
240 EIntr();
241}
242
243#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
244void gsKit_clear(GSGLOBAL *gsGlobal, u64 color)
245{
246 u8 PrevZState;
247 u8 strips;
248 u8 remain;
249 u8 index;
250 u32 pos;
251 u8 slices = (gsGlobal->Width + 63)/ 64;
252 u32 count = (slices * 2) + 1;
253 u128 flat_content[count];
254
255 PrevZState = gsGlobal->Test->ZTST;
257
258 flat_content[0] = (u128)rgbaq_to_RGBAQ(color).rgbaq;
259 for (index = 0; index < slices; index++)
260 {
261 flat_content[index * 2 + 1] = vertex_to_XYZ2(gsGlobal, index * 64, 0, 0).xyz2;
262 flat_content[index * 2 + 2] = (u128)vertex_to_XYZ2(gsGlobal, MIN((index + 1) * 64, gsGlobal->Width) , gsGlobal->Height, 0).xyz2;
263 }
264 gsKit_prim_list_sprite_flat(gsGlobal, count, flat_content);
265
266 gsGlobal->Test->ZTST = PrevZState;
268}
269
270void gsKit_set_scissor(GSGLOBAL *gsGlobal, u64 ScissorBounds) {
271 u64 *p_data;
272 u64 *p_store;
273
274 if (ScissorBounds == GS_SCISSOR_RESET)
275 ScissorBounds = GS_SETREG_SCISSOR(0, gsGlobal->Width - 1, 0, gsGlobal->Height - 1);
276
277 p_data = p_store = gsKit_heap_alloc(gsGlobal, 1, 16, GIF_AD);
278
279 *p_data++ = GIF_TAG_AD(1);
280 *p_data++ = GIF_AD;
281
282 *p_data++ = ScissorBounds;
283 *p_data++ = GS_SCISSOR_1+gsGlobal->PrimContext;
284}
285
286void gsKit_set_test(GSGLOBAL *gsGlobal, u8 Preset)
287{
288 u64 *p_data;
289 u64 *p_store;
290
291 if(Preset == GS_ZTEST_OFF)
292 gsGlobal->Test->ZTST = 1;
293 else if (Preset == GS_ZTEST_ON)
294 gsGlobal->Test->ZTST = 2;
295 else if (Preset == GS_ATEST_OFF)
296 gsGlobal->Test->ATE = 0;
297 else if (Preset == GS_ATEST_ON)
298 gsGlobal->Test->ATE = 1;
299 else if (Preset == GS_D_ATEST_OFF)
300 gsGlobal->Test->DATE = 0;
301 else if (Preset == GS_D_ATEST_ON)
302 gsGlobal->Test->DATE = 1;
303
304 p_data = p_store = gsKit_heap_alloc(gsGlobal, 1, 16, GIF_AD);
305
306 *p_data++ = GIF_TAG_AD(1);
307 *p_data++ = GIF_AD;
308
309 *p_data++ = GS_SETREG_TEST( gsGlobal->Test->ATE, gsGlobal->Test->ATST,
313
314 *p_data++ = GS_TEST_1+gsGlobal->PrimContext;
315
316}
317
318void gsKit_set_clamp(GSGLOBAL *gsGlobal, u8 Preset)
319{
320 u64 *p_data;
321 u64 *p_store;
322
323 if(Preset == GS_CMODE_REPEAT)
324 {
327 }
328 else if(Preset == GS_CMODE_CLAMP)
329 {
332 }
333 else if(Preset == GS_CMODE_REGION_CLAMP)
334 {
337 }
338 else if(Preset == GS_CMODE_REGION_REPEAT)
339 {
342 }
343
344 p_data = p_store = gsKit_heap_alloc(gsGlobal, 1, 16, GIF_AD);
345
346 *p_data++ = GIF_TAG_AD(1);
347 *p_data++ = GIF_AD;
348
352
353 *p_data++ = GS_CLAMP_1+gsGlobal->PrimContext;
354}
355
356void gsKit_set_primalpha(GSGLOBAL *gsGlobal, u64 AlphaMode, u8 PerPixel)
357{
358 u64 *p_data;
359 u64 *p_store;
360
361 gsGlobal->PrimAlpha = AlphaMode;
362 gsGlobal->PABE = PerPixel;
363
364 p_data = p_store = gsKit_heap_alloc(gsGlobal, 2, 32, GIF_AD);
365
366 *p_data++ = GIF_TAG_AD(2);
367 *p_data++ = GIF_AD;
368
369 *p_data++ = gsGlobal->PABE;
370 *p_data++ = GS_PABE;
371
372 *p_data++ = gsGlobal->PrimAlpha;
373 *p_data++ = GS_ALPHA_1+gsGlobal->PrimContext;
374}
375
376void gsKit_set_texfilter(GSGLOBAL *gsGlobal, u8 FilterMode)
377{
378 u64 *p_data;
379 u64 *p_store;
380
381 p_data = p_store = gsKit_heap_alloc(gsGlobal, 1, 16, GIF_AD);
382
383 *p_data++ = GIF_TAG_AD(1);
384 *p_data++ = GIF_AD;
385
386 *p_data++ = GS_SETREG_TEX1(0, 0, FilterMode, FilterMode, 0, 0, 0);
387 *p_data++ = GS_TEX1_1+gsGlobal->PrimContext;
388}
389
390void gsKit_set_texclut(GSGLOBAL *gsGlobal, gs_texclut texClut)
391{
392 u64 *p_data;
393 u64 *p_store;
394
395 p_data = p_store = gsKit_heap_alloc(gsGlobal, 1, 16, GIF_AD);
396
397 *p_data++ = GIF_TAG_AD(1);
398 *p_data++ = GIF_AD;
399
400 memcpy(p_data, &texClut, sizeof(gs_texclut));
401 p_data += 2; // Advance 2 u64, which is 16 bytes the gs_texclut struct size
402}
403
405{
406 u64 *p_data;
407 u64 *p_store;
408
409 p_data = p_store = gsKit_heap_alloc(gsGlobal, 1 ,16, GIF_AD);
410
411 *p_data++ = GIF_TAG_AD(1);
412 *p_data++ = GIF_AD;
413
418 *p_data++ = GS_DIMX;
419}
420
422{
423 u64 *p_data;
424 u64 *p_store;
425
426 p_data = p_store = gsKit_heap_alloc(gsGlobal, 1, 16, GIF_AD);
427
428 *p_data++ = GIF_TAG_AD(1);
429 *p_data++ = GIF_AD;
430
432 *p_data++ = 1;
433 else
434 *p_data++ = 0;
435
436 *p_data++ = GS_DTHE;
437}
438
439// taken from libgraph
440void gsKit_set_drawfield(GSGLOBAL *gsGlobal, u8 field)
441{
442 u64 *p_data;
443 u64 *p_store;
444
445 p_data = p_store = gsKit_heap_alloc(gsGlobal, 1 ,16, GIF_AD);
446
447 *p_data++ = GIF_TAG_AD(1);
448 *p_data++ = GIF_AD;
449
450 if (field == GS_FIELD_NORMAL) { //Draw both
451 *p_data++ = 0;;
452 }
453 else if (field == GS_FIELD_ODD) { // Draw only odd
454 *p_data++ = 2;
455 }
456 else if (field == GS_FIELD_EVEN) { // Draw only even
457 *p_data++ = 3;
458 }
459
460 *p_data++ = GS_SCANMSK;
461}
462/*
463// taken from libgraph
464void gsKit_set_drawfield(GSGLOBAL *gsGlobal, u8 field)
465{
466 u64 *p_data;
467 u64 *p_store;
468
469 (u32)p_data = (u32)p_store = gsGlobal->dma_misc;
470
471 *p_data++ = GIF_TAG( 1, 1, 0, 0, GSKIT_GIF_FLG_PACKED, 1);
472 *p_data++ = GIF_AD;
473
474 if (field == GS_FIELD_NORMAL) { //Draw both
475 *p_data++ = GIF_TAG_SCANMSK(0);
476 }
477 else if (field == GS_FIELD_ODD) { // Draw only odd
478 *p_data++ = GIF_TAG_SCANMSK(2);
479 }
480 else if (field == GS_FIELD_EVEN) { // Draw only even
481 *p_data++ = GIF_TAG_SCANMSK(3);
482 }
483
484 *p_data++ = GS_SCANMSK;
485
486 dmaKit_wait_fast();
487 dmaKit_send_ucab(DMA_CHANNEL_GIF, p_store, 2);
488}
489*/
490
491GSQUEUE gsKit_set_finish(GSGLOBAL *gsGlobal)
492{
493 u64 *p_data;
494 u64 *p_store;
495
496 GSQUEUE oldQueue = *gsGlobal->CurQueue;
497
498 p_data = p_store = gsKit_heap_alloc(gsGlobal, 1, 16, GIF_AD);
499
500 *p_data++ = GIF_TAG_AD(1);
501 *p_data++ = GIF_AD;
502
503 *p_data++ = 0;
504 *p_data++ = GS_FINISH;
505
506 return oldQueue;
507}
508
509void gsKit_queue_exec_real(GSGLOBAL *gsGlobal, GSQUEUE *Queue)
510{
511 GSQUEUE oldQueue;
512
513 if(Queue->tag_size == 0)
514 return;
515
516 // This superstrange oldQueue crap is because Persistent drawbuffers need to be "backed up"
517 // or else they will balloon in size due to appending the finish token.
518 // So we back up the current *state* (NOT DATA) of them here and restore it afterward.
519 oldQueue = gsKit_set_finish(gsGlobal);
520
521 *(u64 *)Queue->dma_tag = DMA_TAG(Queue->tag_size, 0, DMA_END, 0, 0, 0);
522
523 if(Queue->last_type != GIF_AD)
524 {
525 *(u64 *)Queue->last_tag = ((u64)Queue->same_obj | *(u64 *)Queue->last_tag);
526 }
527
528 if(!gsGlobal->FirstFrame)
529 gsKit_finish();
530
532
534
535 dmaKit_send_chain_ucab(DMA_CHANNEL_GIF, Queue->pool[Queue->dbuf]);
536
537 if(Queue->mode != GS_PERSISTENT)
538 {
539 Queue->dbuf ^= 1;
540 Queue->dma_tag = Queue->pool[Queue->dbuf];
541 Queue->pool_cur = Queue->dma_tag + 16;
542 Queue->last_type = GIF_RESERVED;
543 Queue->last_tag = Queue->pool_cur;
544 Queue->tag_size = 0;
545 }
546 else
547 {
548 *Queue = oldQueue;
550 }
551}
552
553void gsKit_queue_reset(GSQUEUE *Queue)
554{
555 if(Queue->mode == GS_ONESHOT)
556 {
557 Queue->dbuf ^= 1;
558 }
559
560 Queue->dma_tag = Queue->pool[Queue->dbuf];
561 Queue->pool_cur = Queue->dma_tag + 16;
562 Queue->last_type = GIF_RESERVED;
563 Queue->last_tag = Queue->pool_cur;
564 Queue->tag_size = 0;
565}
566
587
588void *gsKit_alloc_ucab(int size)
589{
590 // Allocate aligned memory
591 u8 *p = memalign(64, size);
592
593 // Flush the data cache
594 SyncDCache(p, p+size-1);
595
596 // Convert normal to UCAB memory
597 p = (u8*)((u32)p | 0x30000000);
598
599 // Return memory to UCAB area
600 return p;
601}
602
603void gsKit_free_ucab(void *p)
604{
605 // Convert UCAB to normal memory
606 p = (u64 *)((u32)p & ~0x30000000);
607
608 // Free normal memory
609 free(p);
610}
611
612void gsKit_queue_init(GSGLOBAL *gsGlobal, GSQUEUE *Queue, u8 mode, int size)
613{
614 // Init pool 0
615 Queue->pool[0] = gsKit_alloc_ucab(size);
616 Queue->pool_max[0] = (u64 *)((u32)Queue->pool[0] + size);
617
618 if (mode == GS_ONESHOT)
619 {
620 // Init pool 1
621 Queue->pool[1] = gsKit_alloc_ucab(size);
622 Queue->pool_max[1] = (u64 *)((u32)Queue->pool[1] + size);
623 }
624
625 Queue->dma_tag = Queue->pool[0];
626 Queue->pool_cur = (u64 *)((u32)Queue->pool[0] + 16);
627 Queue->dbuf = 0;
628 Queue->tag_size = 0;
629 Queue->last_tag = Queue->pool_cur;
630 Queue->last_type = GIF_RESERVED;
631 Queue->mode = mode;
632}
633
634void gsKit_queue_free(GSGLOBAL *gsGlobal, GSQUEUE *Queue)
635{
636 if (Queue == NULL)
637 return;
638
639 if (Queue->pool[0] != NULL)
640 {
641 gsKit_free_ucab(Queue->pool[0]);
642 Queue->pool[0] = NULL;
643 }
644
645 if (Queue->pool[1] != NULL)
646 {
647 gsKit_free_ucab(Queue->pool[1]);
648 Queue->pool[1] = NULL;
649 }
650}
651
652void gsKit_queue_set(GSGLOBAL *gsGlobal, GSQUEUE *Queue)
653{
654 gsGlobal->CurQueue = Queue;
655}
656
657void gsKit_mode_switch(GSGLOBAL *gsGlobal, u8 mode)
658{
659 if(mode == GS_PERSISTENT)
660 {
662 }
663 else
664 {
666 }
667}
void dmaKit_wait_fast(void)
Definition dmaCore.c:45
void dmaKit_send_ucab(u16 channel, void *data, u32 size)
Definition dmaCore.c:84
void dmaKit_send_chain_ucab(u16 channel, void *data)
Definition dmaCore.c:163
int gsKit_add_finish_handler(int(*finish_callback)(int))
Installs a finish interrupt handler.
Definition gsCore.c:219
#define GS_CMODE_CLAMP
Stretches Texture Across the Surface.
Definition gsCore.h:46
#define GS_ATEST_OFF
Turns off Alpha Testing (Source).
Definition gsCore.h:62
void gsKit_switch_context(GSGLOBAL *gsGlobal)
Definition gsCore.c:141
void gsKit_setactive(GSGLOBAL *gsGlobal)
Sets Your Active Framebuffer.
Definition gsCore.c:83
#define GS_VRAM_BLOCKSIZE_8K
VRAM Allcoate Blocksize (For System Buffers)(CRITICAL FOR VRAM ALIGNMENT).
Definition gsCore.h:35
void gsKit_queue_exec_real(GSGLOBAL *gsGlobal, GSQUEUE *Queue)
Specific Draw Queue "Execution" (Kicks the Queue passed for the second argument).
Definition gsCore.c:509
int gsKit_add_vsync_handler(int(*vsync_callback)(int))
Installs a vsync interrupt handler (vblank_start).
Definition gsCore.c:171
#define GS_ATEST_ON
Turns on Alpha Testing (Source).
Definition gsCore.h:64
#define GS_D_ATEST_OFF
Turns off Alpha Testing (Destination).
Definition gsCore.h:66
void gsKit_queue_reset(GSQUEUE *Queue)
Reset specified drawqueue to it's initial state (Useful for clearing the Persistent Queue).
Definition gsCore.c:553
#define GS_SCISSOR_RESET
Resets SCISSOR values to the entire display bounds.
Definition gsCore.h:55
#define GS_ZTEST_OFF
Turns off Z Testing.
Definition gsCore.h:58
#define GS_CMODE_REGION_REPEAT
Repeats a Portion of the Texture Defined by UMSK (MINU), VMSK (MINV), UFIX (MAXU),...
Definition gsCore.h:50
int gsKit_add_hsync_handler(int(*hsync_callback)(int))
Installs a hsync interrupt handler (hblank_start).
Definition gsCore.c:195
void gsKit_remove_finish_handler(int callback_id)
Removes a finish interrupt handler.
Definition gsCore.c:233
void gsKit_get_field(GSGLOBAL *gsGlobal)
Sets gsGlobal->EvenOrOdd depending on current field drawing.
Definition gsCore.c:160
#define GS_D_ATEST_ON
Turns on Alpha Testing (Destination).
Definition gsCore.h:68
void gsKit_vram_clear(GSGLOBAL *gsGlobal)
GS VRAM Clear.
Definition gsCore.c:53
void gsKit_vsync_nowait(void)
Initiates a vsync but doesn't block.
Definition gsCore.c:155
void gsKit_set_clamp(GSGLOBAL *gsGlobal, u8 Preset)
Definition gsCore.c:318
void gsKit_queue_set(GSGLOBAL *gsGlobal, GSQUEUE *Queue)
Set Current Draw Queue.
Definition gsCore.c:652
void gsKit_clear(GSGLOBAL *gsGlobal, u64 Color)
Definition gsCore.c:244
u32 gsKit_vram_alloc(GSGLOBAL *gsGlobal, u32 size, u8 type)
GS VRAM Allocation.
Definition gsCore.c:20
void gsKit_set_scissor(GSGLOBAL *gsGlobal, u64 ScissorBounds)
Definition gsCore.c:270
void gsKit_set_dither(GSGLOBAL *gsGlobal)
Enables/Disables dithering, with the gsGlobal Dithering option.
Definition gsCore.c:421
void gsKit_remove_vsync_handler(int callback_id)
Removes a vsync interrupt handler.
Definition gsCore.c:185
void gsKit_hsync_wait(void)
Blocks until a HSync.
Definition gsCore.c:165
void gsKit_display_buffer(GSGLOBAL *gsGlobal)
Definition gsCore.c:135
#define GS_ZTEST_ON
Turns on Z Testing.
Definition gsCore.h:60
void gsKit_set_texfilter(GSGLOBAL *gsGlobal, u8 FilterMode)
Sets the Texture Filtering Parameters.
Definition gsCore.c:376
GSQUEUE gsKit_set_finish(GSGLOBAL *gsGlobal)
Append the Current Queue with a GS_FINISH Register.
Definition gsCore.c:491
void gsKit_set_dither_matrix(GSGLOBAL *gsGlobal)
Sets the Dither Matrix Setting.
Definition gsCore.c:404
#define GS_CMODE_REGION_CLAMP
Stretches Texture Across the Region Defined by MINU, MAXU, MINV, and MAXV.
Definition gsCore.h:48
#define GS_CMODE_REPEAT
Repeats ("Tiles") Texture Across the Surface.
Definition gsCore.h:44
void gsKit_lock_buffer(GSGLOBAL *gsGlobal)
Definition gsCore.c:120
void gsKit_free_ucab(void *p)
Free UCAB buffer in GSQUEUE, internal use only.
Definition gsCore.c:603
void gsKit_remove_hsync_handler(int callback_id)
Removes a hsync interrupt handler.
Definition gsCore.c:209
void gsKit_set_primalpha(GSGLOBAL *gsGlobal, u64 AlphaMode, u8 PerPixel)
Sets the Alpha Blending Parameters.
Definition gsCore.c:356
#define GS_VRAM_BLOCKSIZE_256
VRAM Allcoate Blocksize (For User Textures)(CRITICAL FOR VRAM ALIGNMENT).
Definition gsCore.h:37
#define GSKIT_ALLOC_ERROR
Return this is VRAM allocation fails.
Definition gsCore.h:29
void gsKit_queue_free(GSGLOBAL *gsGlobal, GSQUEUE *Queue)
Free Allocated Memory for Draw Queue.
Definition gsCore.c:634
void gsKit_set_drawfield(GSGLOBAL *gsGlobal, u8 field)
Sets the GS to draw only on even/odd/both fields (from libgraph).
Definition gsCore.c:440
void gsKit_set_test(GSGLOBAL *gsGlobal, u8 Preset)
Definition gsCore.c:286
int gsKit_lock_status(GSGLOBAL *gsGlobal)
Definition gsCore.c:130
void gsKit_vsync_wait(void)
Blocks Until a VSync.
Definition gsCore.c:149
void gsKit_queue_init(GSGLOBAL *gsGlobal, GSQUEUE *Queue, u8 mode, int size)
Initialize a Draw Queue (Allocates memory for the Queue).
Definition gsCore.c:612
void gsKit_queue_exec(GSGLOBAL *gsGlobal)
Normal User Draw Queue "Execution" (Kicks Oneshot and Persistent Queues).
Definition gsCore.c:567
void gsKit_set_texclut(GSGLOBAL *gsGlobal, gs_texclut texClut)
Sets the CLUT position specfications.
Definition gsCore.c:390
#define GSKIT_ALLOC_SYSBUFFER
GS VRAM "System" Allocation (Framebuffer, ZBuffer, etc).
Definition gsCore.h:24
void gsKit_mode_switch(GSGLOBAL *gsGlobal, u8 mode)
Set Current Draw Queue (Between GS_ONESHOT and GS_PERSISTENT).
Definition gsCore.c:657
void gsKit_unlock_buffer(GSGLOBAL *gsGlobal)
Definition gsCore.c:125
void gsKit_finish(void)
Blocks until FINISH is triggered.
Definition gsCore.c:115
void gsKit_sync_flip(GSGLOBAL *gsGlobal)
Definition gsCore.c:63
void * gsKit_alloc_ucab(int size)
Allocate UCAB buffer in GSQUEUE, internal use only.
Definition gsCore.c:588
#define GIF_TAG_AD(NLOOP)
A+D GIFTAG.
Definition gsInit.h:308
#define GS_FRAME_1
GS Frame Buffer (Context 1).
Definition gsInit.h:240
#define GS_DTHE
GS Dither Control.
Definition gsInit.h:226
#define GS_PER_OS
Draw Persistent objects first, before oneshot objects.
Definition gsInit.h:34
#define GS_SETREG_CSR_FINISH(A)
CSR FINISH Register Writing Routine.
Definition gsInit.h:546
#define GS_FRAME_2
GS Frame Buffer (Context 2).
Definition gsInit.h:242
#define GS_SETREG_TEST(ate, atst, aref, afail, date, datm, zte, ztst)
GS TEST Packing Macro.
Definition gsInit.h:758
#define GS_FINISH
FINISH Event Occourence.
Definition gsInit.h:260
#define GS_CSR_FINISH
CSR FINISH Register Access Routine.
Definition gsInit.h:543
#define GS_CLAMP_1
GS Texture Wrap Mode (Context 1).
Definition gsInit.h:172
#define GS_FIELD_ODD
Odd Field Mode - Draws only odd lines.
Definition gsInit.h:51
#define GS_SETTING_OFF
Define a setting to be OFF.
Definition gsInit.h:148
#define GIF_TAG(NLOOP, EOP, PRE, PRIM, FLG, NREG)
DMA Packet Header "GIF Tag" For Packets Sent To GIF.
Definition gsInit.h:570
#define GS_DIMX
GS Dither Matrix.
Definition gsInit.h:224
#define GS_SETREG_SCISSOR(scax0, scax1, scay0, scay1)
GS SCISSOR Packing Macro.
Definition gsInit.h:781
#define GS_SETTING_ON
Define a setting to be ON.
Definition gsInit.h:151
#define GS_ONESHOT
Oneshot Draw Queue.
Definition gsInit.h:26
#define GS_TEX1_1
GS Texture Information Settings (Context 1).
Definition gsInit.h:182
#define GS_SCANMSK
GS Raster Address Mask.
Definition gsInit.h:200
#define GIF_AD
GIF_TAG Address+Data Setting. (Used after GIF_TAG).
Definition gsInit.h:494
#define GS_PERSISTENT
Persistent Draw Queue.
Definition gsInit.h:24
#define GS_SCISSOR_2
GS Scissoring Area (Context 2).
Definition gsInit.h:218
#define GS_SCISSOR_1
GS Scissoring Area (Context 1).
Definition gsInit.h:216
#define GS_FIELD_NORMAL
Normal Field Mode - Draws all lines.
Definition gsInit.h:49
#define GIF_RESERVED
Reserved GIF Tag. This is never sent, only used for sanity checks.
Definition gsInit.h:492
#define GS_TEST_1
GS TEST (Context 1).
Definition gsInit.h:230
#define GS_PABE
GS Alpha Blending (In Pixel Units).
Definition gsInit.h:234
#define GS_FIELD_EVEN
Even Field Mode - Draws only even lines.
Definition gsInit.h:53
#define GS_SETREG_SCISSOR_1
See GS_SETREG_SCISSOR.
Definition gsInit.h:777
#define GS_ALPHA_1
GS Alpha Blending (Context 1).
Definition gsInit.h:220
#define GS_SETREG_CLAMP(wms, wmt, minu, maxu, minv, maxv)
GS CLAMP Packing Macro.
Definition gsInit.h:790
#define GS_SETREG_FRAME_1
See GS_SETREG_FRAME.
Definition gsInit.h:768
#define GS_SET_DISPFB2(FBP, FBW, PSM, DBX, DBY)
GS Framebuffer Register Access Macro (Output Circuit 2).
Definition gsInit.h:693
#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.
Definition gsInit.h:808
#define GS_CSR
GS CSR (GS System Status) Register.
Definition gsInit.h:540
#define GSKIT_GIF_FLG_PACKED
gsKit GIFTAG data format "FLG"
Definition gsInit.h:299
void gsKit_TexManager_init(GSGLOBAL *gsGlobal)
Initialize the texture manager.
int MAXU
Maximum Horizontal Clamp Value.
Definition gsInit.h:843
int MINV
Minimum Vertical Clamp Value.
Definition gsInit.h:844
u8 WMS
Wrap Mode Horizontal.
Definition gsInit.h:840
u8 WMT
Wrap Mode Vertical.
Definition gsInit.h:841
int MAXV
Maximum Vertical Clamp Value.
Definition gsInit.h:845
int MINU
Minimum Horizontal Clamp Value.
Definition gsInit.h:842
u8 ActiveBuffer
Active Framebuffer.
Definition gsInit.h:916
u8 EvenOrOdd
Is ((GSREG*)CSR)->FIELD (Used for Interlace Correction).
Definition gsInit.h:912
int Width
Framebuffer Width (the mode's DW is a multiple of this value).
Definition gsInit.h:918
u32 CurrentPointer
Current VRAM Pointer.
Definition gsInit.h:904
u8 Dithering
Dithering (On/Off).
Definition gsInit.h:906
GSTEST * Test
TEST Register Value Structure Pointer.
Definition gsInit.h:932
int PrimContext
Primitive Context.
Definition gsInit.h:942
GSQUEUE * CurQueue
Draw Queue (Current).
Definition gsInit.h:934
u32 TexturePointer
Pointer to beginning of Texture Buffer.
Definition gsInit.h:905
u8 DoubleBuffering
Enable/Disable Double Buffering.
Definition gsInit.h:908
GSQUEUE * Os_Queue
Draw Queue (Oneshot).
Definition gsInit.h:936
u32 ScreenBuffer[2]
Screenbuffer Pointer Array.
Definition gsInit.h:910
int PSM
Pixel Storage Method (Color Mode).
Definition gsInit.h:940
u8 DrawOrder
Drawing Order (GS_PER_OS/GS_OS_PER) (GS_PER_OS = Persitant objects always drawn first).
Definition gsInit.h:913
int Height
Framebuffer Height (the mode's DH is a multiple of this value).
Definition gsInit.h:919
u64 PrimAlpha
Primitive Alpha Value.
Definition gsInit.h:946
GSCLAMP * Clamp
CLAMP Register Value Structure Pointer.
Definition gsInit.h:933
u8 PABE
Choose if to do Alpha Blend on a Per-Pixel Basis.
Definition gsInit.h:947
s8 DitherMatrix[16]
Dithering Matrix.
Definition gsInit.h:907
u8 FirstFrame
Have we executed a frame yet?
Definition gsInit.h:914
GSQUEUE * Per_Queue
Draw Queue (Persistent).
Definition gsInit.h:935
volatile u8 LockBuffer
Used to lock the buffer so it doesn't switch.
Definition gsInit.h:917
void * dma_tag
Pointer to last DMA_TAG.
Definition gsInit.h:867
int same_obj
Number of times in a row the same REGLIST enabled object has been added (Used for NLOOP fixup later).
Definition gsInit.h:865
void * pool_max[2]
Pool Maximum Address (Used for bounds checking).
Definition gsInit.h:860
void * pool_cur
Current Pool Address (Offset from Base).
Definition gsInit.h:859
u8 mode
Mode of the draw queue (NOT USED RIGHT NOW).
Definition gsInit.h:870
void * last_tag
Pointer to the GIF_TAG of the last object in this draw queue.
Definition gsInit.h:863
int dbuf
Which of the pool[2] buffers we are using.
Definition gsInit.h:871
int last_type
Last type of object in this draw queue.
Definition gsInit.h:862
u32 tag_size
Quadwords in current DMA_TAG.
Definition gsInit.h:868
u8 ATE
Alpha Test Enable.
Definition gsInit.h:826
u8 ATST
Alpha Test Method.
Definition gsInit.h:827
u8 ZTE
Depth Test Enable (DO NOT USE THIS - IT IS BUGGED IN PARTICULAR GS REV - SET TO 1 ALWAYS).
Definition gsInit.h:832
u8 DATE
Destination Alpha Enable.
Definition gsInit.h:830
u8 DATM
Destination Alpha Mode.
Definition gsInit.h:831
u8 ZTST
Depth Test Method.
Definition gsInit.h:833
u8 AREF
Alpha Reference Value.
Definition gsInit.h:828
u8 AFAIL
Alpha Failure Action.
Definition gsInit.h:829