ps2sdk  1.1
A collection of Open Source libraries used for developing applications on Sony's PlayStation 2® (PS2).
graph_vram.c
Go to the documentation of this file.
1 #include <gs_psm.h>
2 
3 #include <graph_vram.h>
4 
5 static int graph_vram_pointer = 0;
6 
7 int graph_vram_allocate(int width, int height, int psm, int alignment)
8 {
9 
10  int size;
11 
12  // Calculate the size and increment the pointer
13  size = graph_vram_size(width,height,psm,alignment);
14 
15  graph_vram_pointer += size;
16 
17  // If the pointer overflows the vram size
19  {
20 
21  graph_vram_pointer -= size;
22  return -1;
23 
24  }
25 
26  return graph_vram_pointer - size;
27 
28 }
29 
30 void graph_vram_free(int address)
31 {
32 
33  graph_vram_pointer = address;
34 
35 }
36 
37 void graph_vram_clear(void)
38 {
39 
41 
42 }
43 
44 int graph_vram_size(int width, int height, int psm, int alignment)
45 {
46 
47  int size = 0;
48 
49  // First correct the buffer width to be a multiple of 64 or 128
50  // If the width is less than or equal to 16, then it's a palette
51  if (width > 16)
52  {
53  switch (psm)
54  {
55 
56  case GS_PSM_8:
57  case GS_PSM_4:
58  case GS_PSM_8H:
59  case GS_PSM_4HL:
60  case GS_PSM_4HH: width = -128 & (width + 127); break;
61  default: width = -64 & (width + 63); break;
62 
63  }
64  }
65 
66  // Texture storage size is in pixels/word
67  switch (psm)
68  {
69 
70  case GS_PSM_4: size = width*(height>>3); break;
71  case GS_PSM_8: size = width*(height>>2); break;
72  case GS_PSM_24:
73  case GS_PSM_32:
74  case GS_PSM_8H:
75  case GS_PSM_4HL:
76  case GS_PSM_4HH:
77  case GS_PSMZ_24:
78  case GS_PSMZ_32: size = width*height; break;
79  case GS_PSM_16:
80  case GS_PSM_16S:
81  case GS_PSMZ_16:
82  case GS_PSMZ_16S: size = width*(height>>1); break;
83  default: return 0;
84 
85  }
86 
87  // The buffer size is dependent on alignment
88  size = -alignment & (size + (alignment-1));
89 
90  return size;
91 
92 }
void graph_vram_free(int address)
Definition: graph_vram.c:30
int graph_vram_allocate(int width, int height, int psm, int alignment)
Definition: graph_vram.c:7
static int graph_vram_pointer
Definition: graph_vram.c:5
void graph_vram_clear(void)
Definition: graph_vram.c:37
int graph_vram_size(int width, int height, int psm, int alignment)
Definition: graph_vram.c:44
#define GRAPH_VRAM_MAX_WORDS
Definition: graph_vram.h:10
#define GS_PSM_4HH
Definition: gs_psm.h:29
#define GS_PSM_4
Definition: gs_psm.h:23
#define GS_PSM_16S
Definition: gs_psm.h:17
#define GS_PSMZ_16S
Definition: gs_psm.h:37
#define GS_PSMZ_24
Definition: gs_psm.h:33
#define GS_PSMZ_32
Definition: gs_psm.h:31
#define GS_PSM_4HL
Definition: gs_psm.h:27
#define GS_PSM_8H
Definition: gs_psm.h:25
#define GS_PSM_32
Definition: gs_psm.h:11
#define GS_PSMZ_16
Definition: gs_psm.h:35
#define GS_PSM_24
Definition: gs_psm.h:13
#define GS_PSM_8
Definition: gs_psm.h:21
#define GS_PSM_16
Definition: gs_psm.h:15