sdk-world v2026.11.05
PS2 SDK - world tier (copyleft-allowed, non-essential packages)
Loading...
Searching...
No Matches
gsMisc.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// gsMisc.c - Miscellaneous Helper Routines
10//
11
12#include "gsKit.h"
13
14void gsKit_setup_tbw(GSTEXTURE *Texture)
15{
16 if(Texture->PSM == GS_PSM_T8 || Texture->PSM == GS_PSM_T4)
17 {
18 Texture->TBW = (-GS_VRAM_TBWALIGN_CLUT)&(Texture->Width+GS_VRAM_TBWALIGN_CLUT-1);
19 if(Texture->TBW / 64 > 0)
20 Texture->TBW = (Texture->TBW / 64);
21 else
22 Texture->TBW = 1;
23 }
24 else
25 {
26 Texture->TBW = (-GS_VRAM_TBWALIGN)&(Texture->Width+GS_VRAM_TBWALIGN-1);
27 if(Texture->TBW / 64 > 0)
28 Texture->TBW = (Texture->TBW / 64);
29 else
30 Texture->TBW = 1;
31 }
32}
33
34void gsKit_vram_dump(GSGLOBAL *gsGlobal, char *Path, u32 StartAddr, u32 EndAddr)
35{
36#if 0
37 u64* p_store;
38 u64* p_data;
39 u32* p_mem;
40 int packets;
41 int remain;
42 int qwc;
43 int Size;
44
45 printf("THIS IS NOT DONE YET!\n");
46
47 return 0;
48
49 StartAddr = (-GS_VRAM_BLOCKSIZE)&(StartAddr+GS_VRAM_BLOCKSIZE-1);
50 EndAddr = (-GS_VRAM_BLOCKSIZE)&(EndAddr+GS_VRAM_BLOCKSIZE-1);
51
52 Size = EndAddr - StartAddr;
53
54 qwc = Size / 16;
55 if( Size % 16 )
56 {
57#ifdef DEBUG
58 printf("Uneven division of quad word count from VRAM alloc. Rounding up QWC.\n");
59#endif
60 qwc++;
61 }
62
63 packets = qwc / DMA_MAX_SIZE;
64 remain = qwc % DMA_MAX_SIZE;
65
66 p_store = p_data = dmaKit_spr_alloc( 7 * 16 );
67
68 FlushCache(0);
69
70 // DMA DATA
71 *p_data++ = DMA_TAG( 6, 0, DMA_CNT, 0, 0, 0 );
72 *p_data++ = 0;
73
74 *p_data++ = GIF_TAG( 5, 1, 0, 0, GSKIT_GIF_FLG_PACKED, 1 );
75 *p_data++ = GIF_AD;
76
77 *p_data++ = GS_SETREG_BITBLTBUF(StartAddr / 64, (4095.9375 / 64), 0, 0, 0, 0);
78 *p_data++ = GS_BITBLTBUF;
79
80 *p_data++ = GS_SETREG_TRXPOS(0, 0, 0, 0, 0);
81 *p_data++ = GS_TRXPOS;
82
83 *p_data++ = GS_SETREG_TRXREG(4095.9375, 4095.9375);
84 *p_data++ = GS_TRXREG;
85
86 *p_data++ = 0;
87 *p_data++ = GS_FINISH;
88
89 *p_data++ = GS_SETREG_TRXDIR(1);
90 *p_data++ = GS_TRXDIR;
91
92 dmaKit_send_spr( DMA_CHANNEL_GIF, 0, p_store, 7 );
93
94 while(GS_CSR_FINISH != 1);
95
97
98 FlushCache(0);
99
101#endif
102}
void dmaKit_send_spr(u16 channel, void *data, u32 size)
Definition dmaCore.c:110
void * dmaKit_spr_alloc(int size)
DMA Scratchpad Allocation.
Definition dmaSpr.c:36
#define GS_VRAM_TBWALIGN
Texture Base Width Allocation Allignment (32/24/16 Bit Textures).
Definition gsCore.h:39
#define GS_VRAM_TBWALIGN_CLUT
Texture Base Width Allocation Allignment (8/4 Bit CLUT Textures).
Definition gsCore.h:41
#define GS_SETREG_BUSDIR(A)
GS BUSDIR Register Writing Routine.
Definition gsInit.h:552
#define GS_PSM_T8
8 Bit Texture with CLUT
Definition gsInit.h:123
#define GS_TRXDIR
GS Activation for Transmission Between Buffers.
Definition gsInit.h:254
#define GS_SETREG_CSR_FINISH(A)
CSR FINISH Register Writing Routine.
Definition gsInit.h:546
#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_PSM_T4
4 Bit Texture with CLUT
Definition gsInit.h:127
#define GS_TRXREG
GS Specificiation for Transmission Area in Buffers.
Definition gsInit.h:252
#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_BITBLTBUF
GS Setting for Transmission Between Buffers.
Definition gsInit.h:248
#define GS_TRXPOS
GS Specificiation for Transmission Area in Buffers.
Definition gsInit.h:250
#define GIF_AD
GIF_TAG Address+Data Setting. (Used after GIF_TAG).
Definition gsInit.h:494
#define GSKIT_GIF_FLG_PACKED
gsKit GIFTAG data format "FLG"
Definition gsInit.h:299
u32 TBW
Texture Base Width.
Definition gsInit.h:960
u8 PSM
Pixel Storage Method (Color Format).
Definition gsInit.h:958
u32 Width
Width of the Texture.
Definition gsInit.h:956