-
Notifications
You must be signed in to change notification settings - Fork 0
/
gs.c
executable file
·145 lines (121 loc) · 3.76 KB
/
gs.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/* Basic GS handling functions */
#include <tamtypes.h>
#include <kernel.h>
#include "harness.h"
#define CSR ((volatile u64 *)(0x12001000))
#define GS_RESET() *CSR = ((u64)(1) << 9)
#define PMODE ((volatile u64 *)(0x12000000))
#define GS_SET_PMODE(EN1,EN2,MMOD,AMOD,SLBG,ALP) \
*PMODE = \
((u64)(EN1) << 0) | \
((u64)(EN2) << 1) | \
((u64)(001) << 2) | \
((u64)(MMOD) << 5) | \
((u64)(AMOD) << 6) | \
((u64)(SLBG) << 7) | \
((u64)(ALP) << 8)
//---------------------------------------------------------------------------
// DISPFP2 Register
//---------------------------------------------------------------------------
#define DISPFB2 ((volatile u64 *)(0x12000090))
#define GS_SET_DISPFB2(FBP,FBW,PSM,DBX,DBY) \
*DISPFB2 = \
((u64)(FBP) << 0) | \
((u64)(FBW) << 9) | \
((u64)(PSM) << 15) | \
((u64)(DBX) << 32) | \
((u64)(DBY) << 43)
//---------------------------------------------------------------------------
// DISPLAY2 Register
//---------------------------------------------------------------------------
#define DISPLAY2 ((volatile u64 *)(0x120000a0))
#define GS_SET_DISPLAY2(DX,DY,MAGH,MAGV,DW,DH) \
*DISPLAY2 = \
((u64)(DX) << 0) | \
((u64)(DY) << 12) | \
((u64)(MAGH) << 23) | \
((u64)(MAGV) << 27) | \
((u64)(DW) << 32) | \
((u64)(DH) << 44)
//---------------------------------------------------------------------------
// DISPFP1 Register
//---------------------------------------------------------------------------
#define DISPFB1 ((volatile u64 *)(0x12000070))
#define GS_SET_DISPFB1(FBP,FBW,PSM,DBX,DBY) \
*DISPFB1 = \
((u64)(FBP) << 0) | \
((u64)(FBW) << 9) | \
((u64)(PSM) << 15) | \
((u64)(DBX) << 32) | \
((u64)(DBY) << 43)
//---------------------------------------------------------------------------
// DISPLAY1 Register
//---------------------------------------------------------------------------
#define DISPLAY1 ((volatile u64 *)(0x12000080))
#define GS_SET_DISPLAY1(DX,DY,MAGH,MAGV,DW,DH) \
*DISPLAY1 = \
((u64)(DX) << 0) | \
((u64)(DY) << 12) | \
((u64)(MAGH) << 23) | \
((u64)(MAGV) << 27) | \
((u64)(DW) << 32) | \
((u64)(DH) << 44)
//---------------------------------------------------------------------------
// BGCOLOR Register
//---------------------------------------------------------------------------
#define BGCOLOR ((volatile u64 *)(0x120000e0))
#define GS_SET_BGCOLOR(R,G,B) \
*BGCOLOR = \
((u64)(R) << 0) | \
((u64)(G) << 8) | \
((u64)(B) << 16)
int init_gs(int scr_mode)
{
/* Statically allocate vram. No checking done */
GS_RESET();
__asm__(" sync.p\n" \
" nop\n" \
);
GsPutIMR(0x0000F700);
SetGsCrt(SCR_INT, scr_mode, SCR_FIELD);
GS_SET_PMODE(
0, // ReadCircuit1 OFF
1, // ReadCircuit2 ON
0, // Use ALP register for Alpha Blending
1, // Alpha Value of ReadCircuit2 for output selection
0, // Blend Alpha with the output of ReadCircuit2
0xFF // Alpha Value = 1.0
);
GS_SET_DISPFB2(
0, // Frame Buffer base pointer = 0 (Address/2048)
SCR_W/64, // Buffer Width (Address/64)
SCR_PSM, // Pixel Storage Format
0, // Upper Left X in Buffer = 0
0 // Upper Left Y in Buffer = 0
);
GS_SET_DISPLAY2(
656, // X position in the display area (in VCK units)
30, // Y position in the display area (in Raster units)
SCR_MAGW-1, // Horizontal Magnification - 1
0, // Vertical Magnification = 1x
SCR_W*SCR_MAGW-1, // Display area width - 1 (in VCK units) (Width*HMag-1)
SCR_H-1 // Display area height - 1 (in pixels) (Height-1)
);
GS_SET_BGCOLOR(
0, // RED
0, // GREEN
0 // BLUE
);
return 1; /* Return success */
}
void wait_vsync(void)
{
*CSR = *CSR & 8;
while(!(*CSR & 8));
}
int is_pal(void)
{
if(*((char *)0x1FC80000 - 0xAE) == 'E')
return 1;
return 0;
}