sdk-world v2026.11.05
PS2 SDK - world tier (copyleft-allowed, non-essential packages)
Loading...
Searching...
No Matches
gsInit.h
Go to the documentation of this file.
1
5// ____ ___ | / _____ _____
6// | __ | |___/ | |
7// |___| ___| | \ __|__ | gsKit Open Source Project.
8// ----------------------------------------------------------------------
9// Copyright 2004 - Chris "Neovanglist" Gilbert <Neovanglist@LainOS.org>
10// Licenced under Academic Free License version 2.0
11// Review gsKit README & LICENSE files for further details.
12//
13// gsInit.h - Header for gsInit.c
14//
15// Parts taken from emoon's BreakPoint Demo Library
16//
17
18#ifndef __GSINIT_H__
19#define __GSINIT_H__
20
21#include "gsKit.h"
22
24#define GS_PERSISTENT 0x00
26#define GS_ONESHOT 0x01
27
29#define GS_RENDER_QUEUE_PER_POOLSIZE 1024 * 256 // 256K of persistent renderqueue
31#define GS_RENDER_QUEUE_OS_POOLSIZE 1024 * 1024 // 1024K of oneshot renderqueue
32
34#define GS_PER_OS 0x00
36#define GS_OS_PER 0x01
37
39#define GS_NONINTERLACED 0x00
41#define GS_INTERLACED 0x01
42
44#define GS_FIELD 0x00
46#define GS_FRAME 0x01
47
49#define GS_FIELD_NORMAL 0x00
51#define GS_FIELD_ODD 0x02
53#define GS_FIELD_EVEN 0x03
54
56#define GS_ASPECT_4_3 0x0
58#define GS_ASPECT_16_9 0x1
59
61#define GS_MODE_NTSC 0x02
63#define GS_MODE_PAL 0x03
65#define GS_MODE_VGA_640_60 0x1A
67#define GS_MODE_VGA_640_72 0x1B
69#define GS_MODE_VGA_640_75 0x1C
71#define GS_MODE_VGA_640_85 0x1D
72
74#define GS_MODE_VGA_800_56 0x2A
76#define GS_MODE_VGA_800_60 0x2B
78#define GS_MODE_VGA_800_72 0x2C
80#define GS_MODE_VGA_800_75 0x2D
82#define GS_MODE_VGA_800_85 0x2E
83
85#define GS_MODE_VGA_1024_60 0x3B
87#define GS_MODE_VGA_1024_70 0x3C
89#define GS_MODE_VGA_1024_75 0x3D
91#define GS_MODE_VGA_1024_85 0x3E
92
94#define GS_MODE_VGA_1280_60 0x4A
96#define GS_MODE_VGA_1280_75 0x4B
97
99#define GS_MODE_DTV_480P 0x50
101#define GS_MODE_DTV_576P 0x53
103#define GS_MODE_DTV_1080I 0x51
105#define GS_MODE_DTV_720P 0x52
106
108#define GS_MODE_DVD_NTSC 0x72
110#define GS_MODE_DVD_PAL 0x73
112#define GS_MODE_DVD_480P 0x74
113
115#define GS_PSM_CT32 0x00
117#define GS_PSM_CT24 0x01
119#define GS_PSM_CT16 0x02
121#define GS_PSM_CT16S 0x0A
123#define GS_PSM_T8 0x13
125#define GS_PSM_T8H 0x1B
127#define GS_PSM_T4 0x14
129#define GS_PSM_T4HL 0x24
131#define GS_PSM_T4HH 0x2C
132
134#define GS_PSMZ_32 0x00
136#define GS_PSMZ_24 0x01
138#define GS_PSMZ_16 0x02
140#define GS_PSMZ_16S 0x0A
141
143#define GS_BLEND_FRONT2BACK 0x12
145#define GS_BLEND_BACK2FRONT 0x01
146
148#define GS_SETTING_OFF 0x00
149
151#define GS_SETTING_ON 0x01
152
153// Begin Register List
154
156#define GS_PRIM 0x00
158#define GS_RGBAQ 0x01
160#define GS_ST 0x02
162#define GS_UV 0x03
164#define GS_XYZF2 0x04
166#define GS_XYZ2 0x05
168#define GS_TEX0_1 0x06
170#define GS_TEX0_2 0x07
172#define GS_CLAMP_1 0x08
174#define GS_CLAMP_2 0x09
176#define GS_FOG 0x0a
178#define GS_XYZF3 0x0c
180#define GS_XYZ3 0x0d
182#define GS_TEX1_1 0x14
184#define GS_TEX1_2 0x15
186#define GS_TEX2_1 0x16
188#define GS_TEX2_2 0x17
190#define GS_XYOFFSET_1 0x18
192#define GS_XYOFFSET_2 0x19
194#define GS_PRMODECONT 0x1a
196#define GS_PRMODE 0x1b
198#define GS_TEXCLUT 0x1c
200#define GS_SCANMSK 0x22
202#define GS_MIPTBP1_1 0x34
204#define GS_MIPTBP1_2 0x35
206#define GS_MIPTBP2_1 0x36
208#define GS_MIPTBP2_2 0x37
210#define GS_TEXA 0x3b
212#define GS_FOGCOL 0x3d
214#define GS_TEXFLUSH 0x3f
216#define GS_SCISSOR_1 0x40
218#define GS_SCISSOR_2 0x41
220#define GS_ALPHA_1 0x42
222#define GS_ALPHA_2 0x43
224#define GS_DIMX 0x44
226#define GS_DTHE 0x45
228#define GS_COLCLAMP 0x46
230#define GS_TEST_1 0x47
232#define GS_TEST_2 0x48
234#define GS_PABE 0x49
236#define GS_FBA_1 0x4a
238#define GS_FBA_2 0x4b
240#define GS_FRAME_1 0x4c
242#define GS_FRAME_2 0x4d
244#define GS_ZBUF_1 0x4e
246#define GS_ZBUF_2 0x4f
248#define GS_BITBLTBUF 0x50
250#define GS_TRXPOS 0x51
252#define GS_TRXREG 0x52
254#define GS_TRXDIR 0x53
256#define GS_HWREG 0x54
258#define GS_SIGNAL 0x60
260#define GS_FINISH 0x61
262#define GS_LABEL 0x62
263
264// End Register List
265
267#define GS_PRIM_PRIM_POINT 0x00
269#define GS_PRIM_PRIM_LINE 0x01
271#define GS_PRIM_PRIM_LINESTRIP 0x02
273#define GS_PRIM_PRIM_TRIANGLE 0x03
275#define GS_PRIM_PRIM_TRISTRIP 0x04
277#define GS_PRIM_PRIM_TRIFAN 0x05
279#define GS_PRIM_PRIM_SPRITE 0x06
280
282#define GSKIT_GIF_PRIM_POINT 0x1000
283#define GSKIT_GIF_PRIM_LINE 0x1100
284#define GSKIT_GIF_PRIM_LINESTRIP 0x1200
285#define GSKIT_GIF_PRIM_TRIANGLE 0x1300
286#define GSKIT_GIF_PRIM_TRISTRIP 0x1400
287#define GSKIT_GIF_PRIM_TRIFAN 0x1500
288#define GSKIT_GIF_PRIM_SPRITE 0x1600
289#define GSKIT_GIF_PRIM_QUAD 0x1700
290#define GSKIT_GIF_PRIM_TRIANGLE_GOURAUD 0x1800
291#define GSKIT_GIF_PRIM_QUAD_GOURAUD 0x1900
292#define GSKIT_GIF_PRIM_SPRITE_TEXTURED 0x1A00
293#define GSKIT_GIF_PRIM_TRIANGLE_TEXTURED 0x1B00
294#define GSKIT_GIF_PRIM_TRISTRIP_TEXTURED 0x1C00
295#define GSKIT_GIF_PRIM_TRIFAN_TEXTURED 0x1D00
296#define GSKIT_GIF_PRIM_QUAD_TEXTURED 0x1E00
297
299#define GSKIT_GIF_FLG_PACKED 0
300#define GSKIT_GIF_FLG_REGLIST 1
301#define GSKIT_GIF_FLG_IMAGE 2
302
303
304// DMA Packet Header "GIF Tag" For Packets Sent To GIF
305
306// A+D Data
308#define GIF_TAG_AD(NLOOP) GIF_TAG(NLOOP,1,0,0,GSKIT_GIF_FLG_PACKED,1)
309// Point Primitive
311#define GIF_TAG_POINT(NLOOP) GIF_TAG(NLOOP,1,0,0,GSKIT_GIF_FLG_REGLIST,4)
313#define GIF_TAG_POINT_REGS \
314 ((u64)(GS_PRIM) << 0) | \
315 ((u64)(GS_RGBAQ) << 4) | \
316 ((u64)(GS_XYZ2) << 8) | \
317 ((u64)(GIF_NOP) << 12);
318
319// Line Primitive
321#define GIF_TAG_LINE(NLOOP) GIF_TAG(NLOOP,1,0,0,GSKIT_GIF_FLG_REGLIST,4)
323#define GIF_TAG_LINE_REGS \
324 ((u64)(GS_PRIM) << 0) | \
325 ((u64)(GS_RGBAQ) << 4) | \
326 ((u64)(GS_XYZ2) << 8) | \
327 ((u64)(GS_XYZ2) << 12);
328
329// Line Goraud Primitive
331#define GIF_TAG_LINE_GORAUD(NLOOP) GIF_TAG(NLOOP,1,0,0,GSKIT_GIF_FLG_REGLIST,6)
333#define GIF_TAG_LINE_GORAUD_REGS \
334 ((u64)(GS_PRIM) << 0) | \
335 ((u64)(GS_RGBAQ) << 4) | \
336 ((u64)(GS_XYZ2) << 8) | \
337 ((u64)(GS_RGBAQ) << 12) | \
338 ((u64)(GS_XYZ2) << 16) | \
339 ((u64)(GIF_NOP) << 20);
340
341// Triangle Primitive
343#define GIF_TAG_TRIANGLE(NLOOP) GIF_TAG(NLOOP,1,0,0,GSKIT_GIF_FLG_REGLIST,6)
345#define GIF_TAG_TRIANGLE_REGS \
346 ((u64)(GS_PRIM) << 0) | \
347 ((u64)(GS_RGBAQ) << 4) | \
348 ((u64)(GS_XYZ2) << 8) | \
349 ((u64)(GS_XYZ2) << 12) | \
350 ((u64)(GS_XYZ2) << 16) | \
351 ((u64)(GIF_NOP) << 20);
352
353// Sprite Primitive
355#define GIF_TAG_SPRITE(NLOOP) GIF_TAG(NLOOP,1,0,0,GSKIT_GIF_FLG_REGLIST,4)
357#define GIF_TAG_SPRITE_REGS \
358 ((u64)(GS_PRIM) << 0) | \
359 ((u64)(GS_RGBAQ) << 4) | \
360 ((u64)(GS_XYZ2) << 8) | \
361 ((u64)(GS_XYZ2) << 12);
362
363// Quad Primitive
365#define GIF_TAG_QUAD(NLOOP) GIF_TAG(NLOOP,1,0,0,GSKIT_GIF_FLG_REGLIST,6)
367#define GIF_TAG_QUAD_REGS \
368 ((u64)(GS_PRIM) << 0) | \
369 ((u64)(GS_RGBAQ) << 4) | \
370 ((u64)(GS_XYZ2) << 8) | \
371 ((u64)(GS_XYZ2) << 12) | \
372 ((u64)(GS_XYZ2) << 16) | \
373 ((u64)(GS_XYZ2) << 20);
374
375// Gouraud Shaded Triangle Primitive
377#define GIF_TAG_TRIANGLE_GOURAUD(NLOOP) GIF_TAG(NLOOP,1,0,0,GSKIT_GIF_FLG_REGLIST,8)
379#define GIF_TAG_TRIANGLE_GOURAUD_REGS \
380 ((u64)(GS_PRIM) << 0) | \
381 ((u64)(GS_RGBAQ) << 4) | \
382 ((u64)(GS_XYZ2) << 8) | \
383 ((u64)(GS_RGBAQ) << 12) | \
384 ((u64)(GS_XYZ2) << 16) | \
385 ((u64)(GS_RGBAQ) << 20) | \
386 ((u64)(GS_XYZ2) << 24) | \
387 ((u64)(GIF_NOP) << 28);
388
389// Gouraud Shaded Quad Primitive
391#define GIF_TAG_QUAD_GOURAUD(NLOOP) GIF_TAG(NLOOP,1,0,0,GSKIT_GIF_FLG_REGLIST,10)
393#define GIF_TAG_QUAD_GOURAUD_REGS \
394 ((u64)(GS_PRIM) << 0) | \
395 ((u64)(GS_RGBAQ) << 4) | \
396 ((u64)(GS_XYZ2) << 8) | \
397 ((u64)(GS_RGBAQ) << 12) | \
398 ((u64)(GS_XYZ2) << 16) | \
399 ((u64)(GS_RGBAQ) << 20) | \
400 ((u64)(GS_XYZ2) << 24) | \
401 ((u64)(GS_RGBAQ) << 28) | \
402 ((u64)(GS_XYZ2) << 32) | \
403 ((u64)(GS_RGBAQ) << 36);
404
405// Textured Sprite Primitive
407#define GIF_TAG_SPRITE_TEXTURED(NLOOP) GIF_TAG(NLOOP,1,0,0,GSKIT_GIF_FLG_REGLIST,8)
409#define GIF_TAG_SPRITE_TEXTURED_REGS(ctx) \
410 ((u64)(GS_TEX0_1 + ctx) << 0) | \
411 ((u64)(GS_PRIM) << 4) | \
412 ((u64)(GS_RGBAQ) << 8) | \
413 ((u64)(GS_UV) << 12) | \
414 ((u64)(GS_XYZ2) << 16) | \
415 ((u64)(GS_UV) << 20) | \
416 ((u64)(GS_XYZ2) << 24) | \
417 ((u64)(GIF_NOP) << 28);
418
419// Textured Triangle Primitive
421#define GIF_TAG_TRIANGLE_TEXTURED(NLOOP) GIF_TAG(NLOOP,1,0,0,GSKIT_GIF_FLG_REGLIST,10)
423#define GIF_TAG_TRIANGLE_TEXTURED_REGS(ctx) \
424 ((u64)(GS_TEX0_1 + ctx) << 0) | \
425 ((u64)(GS_PRIM) << 4) | \
426 ((u64)(GS_RGBAQ) << 8) | \
427 ((u64)(GS_UV) << 12) | \
428 ((u64)(GS_XYZ2) << 16) | \
429 ((u64)(GS_UV) << 20) | \
430 ((u64)(GS_XYZ2) << 24) | \
431 ((u64)(GS_UV) << 28) | \
432 ((u64)(GS_XYZ2) << 32) | \
433 ((u64)(GIF_NOP) << 36);
434
435// Textured Quad Primitive
437#define GIF_TAG_QUAD_TEXTURED(NLOOP) GIF_TAG(NLOOP,1,0,0,GSKIT_GIF_FLG_REGLIST,12)
439#define GIF_TAG_QUAD_TEXTURED_REGS(ctx) \
440 ((u64)(GS_TEX0_1 + ctx) << 0) | \
441 ((u64)(GS_PRIM) << 4) | \
442 ((u64)(GS_RGBAQ) << 8) | \
443 ((u64)(GS_UV) << 12) | \
444 ((u64)(GS_XYZ2) << 16) | \
445 ((u64)(GS_UV) << 20) | \
446 ((u64)(GS_XYZ2) << 24) | \
447 ((u64)(GS_UV) << 28) | \
448 ((u64)(GS_XYZ2) << 32) | \
449 ((u64)(GS_UV) << 36) | \
450 ((u64)(GS_XYZ2) << 40) | \
451 ((u64)(GIF_NOP) << 44);
452
453// Textured Triangle Goraud Primitive
455#define GIF_TAG_TRIANGLE_GORAUD_TEXTURED(NLOOP) GIF_TAG(NLOOP,1,0,0,GSKIT_GIF_FLG_REGLIST,12)
457#define GIF_TAG_TRIANGLE_GORAUD_TEXTURED_REGS(ctx) \
458 ((u64)(GS_TEX0_1 + ctx) << 0) | \
459 ((u64)(GS_PRIM) << 4) | \
460 ((u64)(GS_RGBAQ) << 8) | \
461 ((u64)(GS_UV) << 12) | \
462 ((u64)(GS_XYZ2) << 16) | \
463 ((u64)(GS_RGBAQ) << 20) | \
464 ((u64)(GS_UV) << 24) | \
465 ((u64)(GS_XYZ2) << 28) | \
466 ((u64)(GS_RGBAQ) << 32) | \
467 ((u64)(GS_UV) << 36) | \
468 ((u64)(GS_XYZ2) << 40) | \
469 ((u64)(GIF_NOP) << 44);
470
471// Textured Quad Goraud Primitive
473#define GIF_TAG_QUAD_GORAUD_TEXTURED(NLOOP) GIF_TAG(NLOOP,1,0,0,GSKIT_GIF_FLG_REGLIST,14)
475#define GIF_TAG_QUAD_GORAUD_TEXTURED_REGS(ctx) \
476 ((u64)(GS_TEX0_1 + ctx) << 0) | \
477 ((u64)(GS_PRIM) << 4) | \
478 ((u64)(GS_RGBAQ) << 8) | \
479 ((u64)(GS_UV) << 12) | \
480 ((u64)(GS_XYZ2) << 16) | \
481 ((u64)(GS_RGBAQ) << 20) | \
482 ((u64)(GS_UV) << 24) | \
483 ((u64)(GS_XYZ2) << 28) | \
484 ((u64)(GS_RGBAQ) << 32) | \
485 ((u64)(GS_UV) << 36) | \
486 ((u64)(GS_XYZ2) << 40) | \
487 ((u64)(GS_RGBAQ) << 44) | \
488 ((u64)(GS_UV) << 48) | \
489 ((u64)(GS_XYZ2) << 52);
490
492#define GIF_RESERVED 0x0B
494#define GIF_AD 0x0E
496#define GIF_NOP 0x0F
497
499#define GSKIT_PREFETCH(address) asm __volatile__("pref 0, 0(%0)" : : "r" (address));
500
502#define GS_RESET() *GS_CSR = ((u64)(1) << 9)
503
505#define GIF_CTRL (volatile u32*)0x10003000
506
508#define GIF_MODE (volatile u32*)0x10003010
509
511#define GIF_STAT (volatile u32*)0x10003020
512
514#define GIF_SETREG_CTRL(RST, PSE) \
515 *GIF_CTRL = \
516 ((u32)(RST) << 0) | \
517 ((u32)(PSE) << 3);
518
520#define GIF_SETREG_MODE(M3R, IMT) \
521 *GIF_MODE = \
522 ((u32)(M3R) << 0) | \
523 ((u32)(IMT) << 2);
524
526#define GIF_STAT_M3R *GIF_STAT >> 0
527#define GIF_STAT_M3P *GIF_STAT >> 1
528#define GIF_STAT_IMT *GIF_STAT >> 2
529#define GIF_STAT_PSE *GIF_STAT >> 3
530#define GIF_STAT_IP3 *GIF_STAT >> 5
531#define GIF_STAT_P3Q *GIF_STAT >> 6
532#define GIF_STAT_P2Q *GIF_STAT >> 7
533#define GIF_STAT_P1Q *GIF_STAT >> 8
534#define GIF_STAT_OPH *GIF_STAT >> 9
535#define GIF_STAT_APATH *GIF_STAT >> 10
536#define GIF_STAT_DIR *GIF_STAT >> 12
537#define GIF_STAT_FQC *GIF_STAT >> 24
538
540#define GS_CSR (volatile u64 *)0x12001000
541
543#define GS_CSR_FINISH ((*GS_CSR) >> 1)&1
544
546#define GS_SETREG_CSR_FINISH(A) *GS_CSR = ((u64)(A) << 1)
547
549#define GS_BUSDIR ((volatile u64 *)(0x12001040))
550
552#define GS_SETREG_BUSDIR(A) *GS_BUSDIR = ((u64)(A))
553
555#define GS_IMR ((volatile u64 *)(0x12001010))
556
558#define GS_SIGNALID ((volatile u64 *)(0x12001080))
559
561#define GS_SETREG_CSR(A,B,C,D,E,F,G,H,I,J,K,L) \
562 (u64)(A & 0x00000001) << 0 | (u64)(B & 0x00000001) << 1 | \
563 (u64)(C & 0x00000001) << 2 | (u64)(D & 0x00000001) << 3 | \
564 (u64)(E & 0x00000001) << 4 | (u64)(F & 0x00000001) << 8 | \
565 (u64)(G & 0x00000001) << 9 | (u64)(H & 0x00000001) << 12 | \
566 (u64)(I & 0x00000001) << 13 | (u64)(J & 0x00000003) << 14 | \
567 (u64)(K & 0x000000FF) << 16 | (u64)(L & 0x000000FF) << 24
568
570#define GIF_TAG(NLOOP,EOP,PRE,PRIM,FLG,NREG) \
571 ((u64)(NLOOP) << 0) | \
572 ((u64)(EOP) << 15) | \
573 ((u64)(PRE) << 46) | \
574 ((u64)(PRIM) << 47) | \
575 ((u64)(FLG) << 58) | \
576 ((u64)(NREG) << 60);
577
579#define GS_SETREG_RGBAQ(r, g, b, a, q) \
580 ((u64)(r) | ((u64)(g) << 8) | ((u64)(b) << 16) | \
581 ((u64)(a) << 24) | ((u64)(q) << 32))
582
584#define GS_SETREG_RGBA(r, g, b, a) \
585 ((u64)(r) | ((u64)(g) << 8) | ((u64)(b) << 16) | ((u64)(a) << 24))
586
588#define GS_SETREG_XYZ3 GS_SETREG_XYZ
590#define GS_SETREG_XYZ2 GS_SETREG_XYZ
592#define GS_SETREG_XYZ(x, y, z) \
593 ((u64)(x) | ((u64)(y) << 16) | ((u64)(z) << 32))
594
596#define GS_SETREG_XYZF3 GS_SETREG_XYZF
598#define GS_SETREG_XYZF2 GS_SETREG_XYZF
600#define GS_SETREG_XYZF(x, y, z, f) \
601 ((u64)(x) | ((u64)(y) << 16) | ((u64)(z) << 32) | \
602 ((u64)(f) << 56))
603
605#define GS_PMODE ((volatile u64 *)(0x12000000))
606#define GS_SMODE1 ((volatile u64 *)(0x12000010))
607#define GS_SMODE2 ((volatile u64 *)(0x12000020))
608#define GS_SRFSH ((volatile u64 *)(0x12000030))
609#define GS_SYNCH1 ((volatile u64 *)(0x12000040))
610#define GS_SYNCH2 ((volatile u64 *)(0x12000050))
611#define GS_SYNCV ((volatile u64 *)(0x12000060))
612#define GS_EXTBUF ((volatile u64 *)(0x120000B0))
613#define GS_EXTDATA ((volatile u64 *)(0x120000C0))
614#define GS_EXTWRITE ((volatile u64 *)(0x120000D0))
615
617#define GS_DISPFB1 ((volatile u64 *)(0x12000070))
618
620#define GS_DISPFB2 ((volatile u64 *)(0x12000090))
621
623#define GS_SET_PMODE(EN1,EN2,MMOD,AMOD,SLBG,ALP) \
624 *GS_PMODE = \
625 ((u64)(EN1) << 0) | \
626 ((u64)(EN2) << 1) | \
627 ((u64)(001) << 2) | \
628 ((u64)(MMOD) << 5) | \
629 ((u64)(AMOD) << 6) | \
630 ((u64)(SLBG) << 7) | \
631 ((u64)(ALP) << 8)
632
634#define GS_SET_SMODE2(INT, FFMD, DPMS) \
635 *GS_SMODE2 = \
636 ((u64)(INT) << 0) | \
637 ((u64)(FFMD) << 1) | \
638 ((u64)(DPMS) << 2)
639
641#define GS_SET_PMODE_EXT(EN1,EN2,CRTMD,MMOD,AMOD,SLBG,ALP, NFLD, EXVWINS, EXVWINE, EVSYNCMD) \
642 *GS_PMODE = \
643 ((u64)(EN1) << 0) | \
644 ((u64)(EN2) << 1) | \
645 ((u64)(CRTMD) << 2) | \
646 ((u64)(MMOD) << 5) | \
647 ((u64)(AMOD) << 6) | \
648 ((u64)(SLBG) << 7) | \
649 ((u64)(ALP) << 8) | \
650 ((u64)(NFLD) << 16) | \
651 ((u64)(EXVWINS) << 32) | \
652 ((u64)(EXVWINE) << 42) | \
653 ((u64)(EVSYNCMD) << 52)
654
656#define GS_SET_EXTBUF(EXBP,EXBW,FBIN,WFFMD,EMODA,EMODC,WDX,WDY) \
657 *GS_EXTBUF = \
658 ((u64)(EXBP) << 0) | \
659 ((u64)(EXBW) << 14) | \
660 ((u64)(FBIN) << 20) | \
661 ((u64)(WFFMD) << 22) | \
662 ((u64)(EMODA) << 23) | \
663 ((u64)(EMODC) << 25) | \
664 ((u64)(WDX) << 32) | \
665 ((u64)(WDY) << 43)
666
668#define GS_SET_EXTDATA(SX,SY,SMPH,SMPV,WW,WH) \
669 *GS_EXTDATA = \
670 ((u64)(SX) << 0) | \
671 ((u64)(SY) << 12) | \
672 ((u64)(SMPH) << 23) | \
673 ((u64)(SMPV) << 27) | \
674 ((u64)(WW) << 32) | \
675 ((u64)(WH) << 44)
676
678#define GS_SET_EXTWRITE(WRITE) \
679 *GS_EXTWRITE = \
680 ((u64)(WRITE) << 0)
681
682
684#define GS_SET_DISPFB1(FBP,FBW,PSM,DBX,DBY) \
685 *GS_DISPFB1 = \
686 ((u64)(FBP) << 0) | \
687 ((u64)(FBW) << 9) | \
688 ((u64)(PSM) << 15) | \
689 ((u64)(DBX) << 32) | \
690 ((u64)(DBY) << 43)
691
693#define GS_SET_DISPFB2(FBP,FBW,PSM,DBX,DBY) \
694 *GS_DISPFB2 = \
695 ((u64)(FBP) << 0) | \
696 ((u64)(FBW) << 9) | \
697 ((u64)(PSM) << 15) | \
698 ((u64)(DBX) << 32) | \
699 ((u64)(DBY) << 43)
700
702#define GS_DISPLAY1 ((volatile u64 *)(0x12000080))
703
705#define GS_SET_DISPLAY1(DX,DY,MAGH,MAGV,DW,DH) \
706 *GS_DISPLAY1 = \
707 ((u64)(DX) << 0) | \
708 ((u64)(DY) << 12) | \
709 ((u64)(MAGH) << 23) | \
710 ((u64)(MAGV) << 27) | \
711 ((u64)(DW) << 32) | \
712 ((u64)(DH) << 44)
713
715#define GS_DISPLAY2 ((volatile u64 *)(0x120000a0))
716
718#define GS_SET_DISPLAY2(DX,DY,MAGH,MAGV,DW,DH) \
719 *GS_DISPLAY2 = \
720 ((u64)(DX) << 0) | \
721 ((u64)(DY) << 12) | \
722 ((u64)(MAGH) << 23) | \
723 ((u64)(MAGV) << 27) | \
724 ((u64)(DW) << 32) | \
725 ((u64)(DH) << 44)
726
728#define GS_BGCOLOR ((volatile u64 *)(0x120000e0))
729
731#define GS_SET_BGCOLOR(R,G,B) \
732 *GS_BGCOLOR = \
733 ((u64)(R) << 0) | \
734 ((u64)(G) << 8) | \
735 ((u64)(B) << 16)
736
738#define GS_SETREG_XYOFFSET_1 GS_SETREG_XYOFFSET
740#define GS_SETREG_XYOFFSET_2 GS_SETREG_XYOFFSET
742#define GS_SETREG_XYOFFSET(ofx, ofy) ((u64)(ofx) | ((u64)(ofy) << 32))
743
745#define GS_SETREG_ZBUF_1 GS_SETREG_ZBUF
747#define GS_SETREG_ZBUF_2 GS_SETREG_ZBUF
749#define GS_SETREG_ZBUF(zbp, psm, zmsk) \
750 ((u64)(zbp) | ((u64)(psm) << 24) | \
751 ((u64)(zmsk) << 32))
752
754#define GS_SETREG_TEST_1 GS_SETREG_TEST
756#define GS_SETREG_TEST_2 GS_SETREG_TEST
758#define GS_SETREG_TEST(ate, atst, aref, afail, date, datm, zte, ztst) \
759 ((u64)(ate) | ((u64)(atst) << 1) | \
760 ((u64)(aref) << 4) | ((u64)(afail) << 12) | \
761 ((u64)(date) << 14) | ((u64)(datm) << 15) | \
762 ((u64)(zte) << 16) | ((u64)(ztst) << 17))
763
765#define GS_SETREG_COLCLAMP(clamp) ((u64)(clamp))
766
768#define GS_SETREG_FRAME_1 GS_SETREG_FRAME
770#define GS_SETREG_FRAME_2 GS_SETREG_FRAME
772#define GS_SETREG_FRAME(fbp, fbw, psm, fbmask) \
773 ((u64)(fbp) | ((u64)(fbw) << 16) | \
774 ((u64)(psm) << 24) | ((u64)(fbmask) << 32))
775
777#define GS_SETREG_SCISSOR_1 GS_SETREG_SCISSOR
779#define GS_SETREG_SCISSOR_2 GS_SETREG_SCISSOR
781#define GS_SETREG_SCISSOR(scax0, scax1, scay0, scay1) \
782 ((u64)(scax0) | ((u64)(scax1) << 16) | \
783 ((u64)(scay0) << 32) | ((u64)(scay1) << 48))
784
786#define GS_SETREG_CLAMP_1 GS_SET_CLAMP
788#define GS_SETREG_CLAMP_2 GS_SET_CLAMP
790#define GS_SETREG_CLAMP(wms, wmt, minu, maxu, minv, maxv) \
791 ((u64)(wms) | ((u64)(wmt) << 2) | \
792 ((u64)(minu) << 4) | ((u64)(maxu) << 14) | \
793 ((u64)(minv) << 24) | ((u64)(maxv) << 34))
794
796#define GS_SETREG_ALPHA(A, B, C, D, FIX) \
797 ((u64)(A) << 0) | \
798 ((u64)(B) << 2) | \
799 ((u64)(C) << 4) | \
800 ((u64)(D) << 6) | \
801 ((u64)(FIX) << 32)
802
803// ABCD
804// EFGH
805// IJKL
806// MNOP
808 #define GS_SETREG_DIMX(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P) \
809((u64)(A) << 0) | ((u64)(B) << 4) | ((u64)(C) << 8) | ((u64)(D) << 12) | \
810((u64)(E) << 16) | ((u64)(F) << 20) | ((u64)(G) << 24) | ((u64)(H) << 28) | \
811((u64)(I) << 32) | ((u64)(J) << 36) | ((u64)(K) << 40) | ((u64)(L) << 44) | \
812((u64)(M) << 48) | ((u64)(N) << 52) | ((u64)(0) << 56) | ((u64)(P) << 60)
813
816{
817 u8 Red;
818 u8 Green;
819 u8 Blue;
820};
821typedef struct gsBGColor GSBGCOLOR;
822
824struct gsTest
825{
826 u8 ATE;
827 u8 ATST;
828 u8 AREF;
829 u8 AFAIL;
830 u8 DATE;
831 u8 DATM;
832 u8 ZTE;
833 u8 ZTST;
834};
835typedef struct gsTest GSTEST;
836
839{
840 u8 WMS;
841 u8 WMT;
842 int MINU;
843 int MAXU;
844 int MINV;
845 int MAXV;
846};
847typedef struct gsClamp GSCLAMP;
848
857{
858 void *pool[2] __attribute__ ((aligned (64)));
859 void *pool_cur;
860 void *pool_max[2];
861
863 void *last_tag;
864
866
867 void *dma_tag;
869
870 u8 mode;
871 int dbuf;
872};
873typedef struct gsQueue GSQUEUE;
874
949typedef struct gsGlobal GSGLOBAL;
950
955{
956 u32 Width;
957 u32 Height;
958 u8 PSM;
960 u32 TBW;
961 u32 *Mem;
962 u32 *Clut;
963 u32 Vram;
965 u32 Filter;
968};
969typedef struct gsTexture GSTEXTURE;
970
971typedef union {
972 u64 xyz;
973 struct {
974 u16 x;
975 u16 y;
976 u32 z;
977 };
978} __attribute__((packed)) gs_xyz_t;
979
980typedef union {
981 u32 rgba;
982 struct {
983 u8 r;
984 u8 g;
985 u8 b;
986 u8 a;
987 };
988} __attribute__((packed)) gs_rgba_t;
989
990typedef union {
991 u64 rgbaq;
992 struct {
993 gs_rgba_t components;
994 float q;
995 };
996} __attribute__((packed)) gs_rgbaq_t;
997
998typedef union {
999 u64 st;
1000 struct {
1001 float s;
1002 float t;
1003 };
1004} __attribute__((packed)) gs_stq_t;
1005
1006typedef union {
1007 u128 xyz2;
1008 struct {
1009 gs_xyz_t xyz;
1010 u64 tag;
1011 };
1012} __attribute__((packed)) gs_xyz2;
1013
1014typedef union {
1015 u128 rgbaq;
1016 struct {
1017 gs_rgbaq_t color;
1018 u64 tag;
1019 };
1020} __attribute__((packed)) gs_rgbaq;
1021
1022typedef union {
1023 u64 uv;
1024 struct {
1025 u16 u;
1026 u16 v;
1027 u32 notused;
1028 };
1029} __attribute__((packed)) gs_uv_t;
1030
1031typedef union {
1032 u128 uv;
1033 struct {
1034 gs_uv_t coord;
1035 u64 tag;
1036 };
1037} __attribute__((packed)) gs_uv;
1038
1039typedef union {
1040 u128 stq;
1041 struct {
1042 gs_stq_t st;
1043 u64 tag;
1044 };
1045} __attribute__((packed)) gs_stq;
1046
1047typedef union {
1048 u64 position;
1049 struct {
1050 u32 cbw : 6; // Bits 0-5 (6 bits)
1051 u32 cou : 6; // Bits 6-11 (6 bits)
1052 u32 cov : 10; // Bits 12-21 (10 bits)
1053 u32 unused_bits: 10; // Bits 22-31 (10 bits)
1054 u32 unused; // Remaining bits (64 - 22 = 42 bits)
1055 } __attribute__((packed)); // Pack the structure to avoid padding
1056} __attribute__((packed)) gs_textclut_t;
1057
1058typedef union {
1059 u128 texclut;
1060 struct {
1061 gs_textclut_t specification;
1062 u64 tag;
1063 };
1064} __attribute__((packed)) gs_texclut;
1065
1070{
1071 gs_rgbaq rgbaq;
1072 gs_xyz2 xyz2;
1073};
1074typedef struct gsPrimPoint GSPRIMPOINT;
1075
1077{
1078 gs_rgbaq rgbaq;
1079 gs_uv uv;
1080 gs_xyz2 xyz2;
1081};
1082typedef struct gsPrimUVPoint GSPRIMUVPOINT;
1083
1085{
1086 gs_uv uv;
1087 gs_xyz2 xyz2;
1088};
1089typedef struct gsPrimUVPointFlat GSPRIMUVPOINTFLAT;
1090
1092{
1093 gs_rgbaq rgbaq;
1094 gs_stq stq;
1095 gs_xyz2 xyz2;
1096};
1097typedef struct gsPrimSTQPoint GSPRIMSTQPOINT;
1098
1101 u64 SIGNAL: 1 __attribute__((packed)); /* ro */
1102 u64 FINISH: 1 __attribute__((packed)); /* ro */
1103 u64 HSINT: 1 __attribute__((packed)); /* ro */
1104 u64 VSINT: 1 __attribute__((packed)); /* ro */
1105 u64 reserved04: 3 __attribute__((packed)); /* ro */
1106 u64 pad07: 1 __attribute__((packed));
1107 u64 FLUSH: 1 __attribute__((packed)); /* rw */
1108 u64 RESET: 1 __attribute__((packed)); /* N/A */
1109 u64 pad10: 2 __attribute__((packed));
1110 u64 NFIELD: 1 __attribute__((packed)); /* ro */
1111 u64 FIELD: 1 __attribute__((packed)); /* ro */
1112 u64 FIFO: 2 __attribute__((packed)); /* ro */
1113 u64 REV: 8 __attribute__((packed)); /* ro */
1114 u64 ID: 8 __attribute__((packed)); /* ro */
1115 u64 pad32: 32 __attribute__((packed));
1116};
1117typedef struct gsRegisters GSREG;
1118
1119#ifdef __cplusplus
1120extern "C" {
1121#endif
1122
1124short int gsKit_check_rom(void);
1126#define gsKit_detect_signal() gsKit_check_rom()
1128void gsKit_init_screen(GSGLOBAL *gsGlobal);
1130void gsKit_set_display_offset(GSGLOBAL *gsGlobal, int x, int y);
1132//GSGLOBAL *gsKit_init_global_custom(u8 mode, int Os_AllocSize, int Per_AllocSize);
1133GSGLOBAL *gsKit_init_global_custom(int Os_AllocSize, int Per_AllocSize);
1134
1135#define gsKit_reset_screen(gsGlobal) \
1136 gsKit_init_screen(gsGlobal);
1137
1138#define gsKit_init_global() \
1139 gsKit_init_global_custom(GS_RENDER_QUEUE_OS_POOLSIZE, GS_RENDER_QUEUE_PER_POOLSIZE);
1140
1141void gsKit_deinit_global(GSGLOBAL *gsGlobal);
1142
1143#ifdef __cplusplus
1144}
1145#endif
1146
1147#endif /* __GSINIT_H__ */
GSGLOBAL * gsKit_init_global_custom(int Os_AllocSize, int Per_AllocSize)
Initialize gsGlobal (With Specified Sizes (In Bytes) for the Persistent and Oneshot drawbuffers).
Definition gsInit.c:468
void gsKit_init_screen(GSGLOBAL *gsGlobal)
Initialize Screen and GS Registers.
Definition gsInit.c:238
void gsKit_set_display_offset(GSGLOBAL *gsGlobal, int x, int y)
Position the framebuffer onto the display.
Definition gsInit.c:46
short int gsKit_check_rom(void)
Checks the console's capabilities based on the ROM version (returns default video format: GS_MODE_NTS...
Definition gsInit.c:28
Background Color Structure.
Definition gsInit.h:816
u8 Green
Green Value.
Definition gsInit.h:818
u8 Blue
Blue Value.
Definition gsInit.h:819
u8 Red
Red Value.
Definition gsInit.h:817
CLAMP Register Settings Structure.
Definition gsInit.h:839
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
int PrimAlphaEnable
Primitive Alpha Blending Enable.
Definition gsInit.h:945
u8 EvenOrOdd
Is ((GSREG*)CSR)->FIELD (Used for Interlace Correction).
Definition gsInit.h:912
u8 ZBuffering
Enable/Disable Z Buffering.
Definition gsInit.h:909
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
s16 Field
Field / Frame.
Definition gsInit.h:903
void *dma_misc __attribute__((aligned(64)))
Misc 512 byte DMA Transfer Buffer (so we don't malloc at runtime).
int MagH
X Magnification Value (MAGH = DW / Width - 1).
Definition gsInit.h:927
int Per_AllocSize
Persistent Drawbuffer Size (Per Buffer).
Definition gsInit.h:938
GSBGCOLOR * BGColor
Background Color Structure Pointer.
Definition gsInit.h:931
int Os_AllocSize
Oneshot Drawbuffer Size (Per Buffer).
Definition gsInit.h:937
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
int Aspect
Framebuffer Aspect Ratio (GS_ASPECT_4_3/GS_ASPECT_16_9).
Definition gsInit.h:920
int PSMZ
ZBuffer Pixel Storage Method.
Definition gsInit.h:941
u32 TexturePointer
Pointer to beginning of Texture Buffer.
Definition gsInit.h:905
s16 Mode
Display Mode.
Definition gsInit.h:901
u8 DoubleBuffering
Enable/Disable Double Buffering.
Definition gsInit.h:908
u8 DrawField
Field to draw (GS_FIELD_NORMAL/GS_FIELD_ODD/GS_FIELD_EVEN).
Definition gsInit.h:915
int StartYOffset
Y Starting Coordinate (Used for Placement Correction) Additional correction.
Definition gsInit.h:926
int StartXOffset
X Starting Coordinate (Used for Placement Correction) Additional correction.
Definition gsInit.h:925
GSQUEUE * Os_Queue
Draw Queue (Oneshot).
Definition gsInit.h:936
int OffsetX
X Window Offset.
Definition gsInit.h:921
int DW
Total Display Area Width (DW = Width * (MAGH + 1)).
Definition gsInit.h:929
u32 ScreenBuffer[2]
Screenbuffer Pointer Array.
Definition gsInit.h:910
int StartX
X Starting Coordinate (Used for Placement Correction) Default value.
Definition gsInit.h:923
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 MagV
Y Magnification Value (MAGV = DH / Height - 1).
Definition gsInit.h:928
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
int PrimFogEnable
Primitive Fog Enable.
Definition gsInit.h:943
GSCLAMP * Clamp
CLAMP Register Value Structure Pointer.
Definition gsInit.h:933
int PrimAAEnable
Primitive AntiAlaising Enable.
Definition gsInit.h:944
int OffsetY
Y Window Offset.
Definition gsInit.h:922
u32 ZBuffer
ZBuffer Pointer.
Definition gsInit.h:911
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
int DH
Total Display Area Height (DH = Height * (MAGH + 1)).
Definition gsInit.h:930
s16 Interlace
Interlace (On/Off).
Definition gsInit.h:902
int StartY
Y Starting Coordinate (Used for Placement Correction) Default value.
Definition gsInit.h:924
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 *pool[2] __attribute__((aligned(64)))
Pool Base Address (Two of these, since we doublebuffer).
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
Alternative Access Method to the GS CSR Register.
Definition gsInit.h:1100
TEST Register Settings Structure.
Definition gsInit.h:825
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
u32 * Clut
EE CLUT Memory Pointer.
Definition gsInit.h:962
u32 TBW
Texture Base Width.
Definition gsInit.h:960
u32 * Mem
EE Memory Pointer.
Definition gsInit.h:961
u8 ClutStorageMode
CLUT Storage Mode.
Definition gsInit.h:966
u32 Vram
GS VRAM Memory Pointer.
Definition gsInit.h:963
u32 VramClut
GS VRAM CLUT Memory Pointer.
Definition gsInit.h:964
u8 Delayed
Delay Texture Upload To VRAM.
Definition gsInit.h:967
u8 ClutPSM
CLUT Pixel Storage Method (Color Format).
Definition gsInit.h:959
u8 PSM
Pixel Storage Method (Color Format).
Definition gsInit.h:958
u32 Height
Height of the Texture.
Definition gsInit.h:957
u32 Width
Width of the Texture.
Definition gsInit.h:956
u32 Filter
NEAREST or LINEAR.
Definition gsInit.h:965