My Project
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules
gfx.c
Go to the documentation of this file.
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <string.h>
4 #include <3ds.h>
5 
7 
10 
14 
16 bool enable3d;
17 
19 
20 void gfxSet3D(bool enable)
21 {
22  enable3d=enable;
23 }
24 
26 {
27  if(screen==GFX_TOP)
28  {
29  topFramebufferInfo.active_framebuf=id;
30  topFramebufferInfo.framebuf0_vaddr=(u32*)gfxTopLeftFramebuffers[id];
31  if(enable3d)topFramebufferInfo.framebuf1_vaddr=(u32*)gfxTopRightFramebuffers[id];
32  else topFramebufferInfo.framebuf1_vaddr=topFramebufferInfo.framebuf0_vaddr;
33  topFramebufferInfo.framebuf_widthbytesize=240*3;
34  u8 bit5=(enable3d!=0);
35  topFramebufferInfo.format=((1)<<8)|((1^bit5)<<6)|((bit5)<<5)|GSP_BGR8_OES;
36  topFramebufferInfo.framebuf_dispselect=id;
37  topFramebufferInfo.unk=0x00000000;
38  }else{
39  bottomFramebufferInfo.active_framebuf=id;
40  bottomFramebufferInfo.framebuf0_vaddr=(u32*)gfxBottomFramebuffers[id];
41  bottomFramebufferInfo.framebuf1_vaddr=0x00000000;
42  bottomFramebufferInfo.framebuf_widthbytesize=240*3;
43  bottomFramebufferInfo.format=GSP_BGR8_OES;
44  bottomFramebufferInfo.framebuf_dispselect=id;
45  bottomFramebufferInfo.unk=0x00000000;
46  }
47 }
48 
50 {
51  u8* framebufferInfoHeader=gfxSharedMemory+0x200+gfxThreadID*0x80;
52  if(screen==GFX_BOTTOM)framebufferInfoHeader+=0x40;
53  GSP_FramebufferInfo* framebufferInfo=(GSP_FramebufferInfo*)&framebufferInfoHeader[0x4];
54  framebufferInfoHeader[0x0]^=1;
55  framebufferInfo[framebufferInfoHeader[0x0]]=(screen==GFX_TOP)?(topFramebufferInfo):(bottomFramebufferInfo);
56  framebufferInfoHeader[0x1]=1;
57 }
58 
59 void gfxInit()
60 {
61  gspInit();
62 
63  gfxSharedMemory=(u8*)0x10002000;
64 
65  GSPGPU_AcquireRight(NULL, 0x0);
66  GSPGPU_SetLcdForceBlack(NULL, 0x0);
67 
68  //setup our gsp shared mem section
69  svcCreateEvent(&gspEvent, 0x0);
72 
73  // default gspHeap configuration :
74  // topleft1 0x00000000-0x00046500
75  // topleft2 0x00046500-0x0008CA00
76  // bottom1 0x0008CA00-0x000C4E00
77  // bottom2 0x000C4E00-0x000FD200
78  // if 3d enabled :
79  // topright1 0x000FD200-0x00143700
80  // topright2 0x00143700-0x00189C00
81 
88  enable3d=false;
89 
90  //initialize framebuffer info structures
93 
94  //GSP shared mem : 0x2779F000
95  gxCmdBuf=(u32*)(gfxSharedMemory+0x800+gfxThreadID*0x200);
96 
97  currentBuffer=0;
98 
99  // Initialize event handler and wait for VBlank
100  gspInitEventHandler(gspEvent, (vu8*)gfxSharedMemory, gfxThreadID);
102 }
103 
104 void gfxExit()
105 {
106  // Exit event handler
108 
109  // Free framebuffers (let's pretend linearFree is actually implemented...)
116 
117  //unmap GSP shared mem
119 
121 
124 
125  GSPGPU_ReleaseRight(NULL);
126 
127  gspExit();
128 }
129 
130 u8* gfxGetFramebuffer(gfxScreen_t screen, gfx3dSide_t side, u16* width, u16* height)
131 {
132  if(width)*width=240;
133 
134  if(screen==GFX_TOP)
135  {
136  if(height)*height=400;
138  }else{
139  if(height)*height=320;
141  }
142 }
143 
145 {
146  GSPGPU_FlushDataCache(NULL, gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL), 0x46500);
147  if(enable3d)GSPGPU_FlushDataCache(NULL, gfxGetFramebuffer(GFX_TOP, GFX_RIGHT, NULL, NULL), 0x46500);
148  GSPGPU_FlushDataCache(NULL, gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL), 0x38400);
149 }
150 
152 {
153  currentBuffer^=1;
156  GSPGPU_SetBufferSwap(NULL, GFX_TOP, &topFramebufferInfo);
157  GSPGPU_SetBufferSwap(NULL, GFX_BOTTOM, &bottomFramebufferInfo);
158 }
159 
161 {
162  currentBuffer^=1;
167 }
u8 currentBuffer
Definition: gfx.c:15
void gfxSet3D(bool enable)
Definition: gfx.c:20
s32 svcCloseHandle(Handle handle)
uint16_t u16
Definition: types.h:22
void gspExit()
Definition: gsp.c:28
Result gspInit()
Definition: gsp.c:23
Definition: gfx.h:7
u8 * gfxBottomFramebuffers[2]
Definition: gfx.c:13
u32 framebuf_widthbytesize
Definition: gsp.h:10
Result GSPGPU_AcquireRight(Handle *handle, u8 flags)
Definition: gsp.c:278
Result gspInitEventHandler(Handle gspEvent, vu8 *gspSharedMem, u8 gspThreadId)
Definition: gsp.c:33
u32 Handle
Definition: types.h:41
volatile u8 vu8
Definition: types.h:31
s32 svcUnmapMemoryBlock(Handle memblock, u32 addr)
Handle gspEvent
Definition: gfx.c:18
u32 framebuf_dispselect
Definition: gsp.h:12
void gfxInit()
Definition: gfx.c:59
uint8_t u8
Definition: types.h:21
u32 * gxCmdBuf
Definition: gx.c:8
void gfxSwapBuffersGpu()
Definition: gfx.c:160
u8 * gfxTopLeftFramebuffers[2]
Definition: gfx.c:11
Result GSPGPU_UnregisterInterruptRelayQueue(Handle *handle)
Definition: gsp.c:265
#define gspWaitForVBlank()
Definition: gsp.h:59
uint32_t u32
Definition: types.h:23
void gfxExit()
Definition: gfx.c:104
Definition: gfx.h:12
Definition: gfx.h:13
u8 * gfxSharedMemory
Definition: gfx.c:9
Result GSPGPU_ReleaseRight(Handle *handle)
Definition: gsp.c:294
Result GSPGPU_FlushDataCache(Handle *handle, u8 *adr, u32 size)
Definition: gsp.c:184
Handle gspSharedMemHandle
Definition: gfx.c:18
void gfxWriteFramebufferInfo(gfxScreen_t screen)
Definition: gfx.c:49
void gfxFlushBuffers()
Definition: gfx.c:144
void * linearAlloc(size_t size)
Definition: linear.cpp:102
u32 * framebuf1_vaddr
Definition: gsp.h:9
u8 * gfxGetFramebuffer(gfxScreen_t screen, gfx3dSide_t side, u16 *width, u16 *height)
Definition: gfx.c:130
Definition: gfx.h:6
Result GSPGPU_RegisterInterruptRelayQueue(Handle *handle, Handle eventHandle, u32 flags, Handle *outMemHandle, u8 *threadID)
Definition: gsp.c:246
GSP_FramebufferInfo topFramebufferInfo
Definition: gfx.c:6
gfx3dSide_t
Definition: gfx.h:10
void gspExitEventHandler()
Definition: gsp.c:57
bool enable3d
Definition: gfx.c:16
s32 svcCreateEvent(Handle *event, u8 reset_type)
gfxScreen_t
Definition: gfx.h:4
s32 svcMapMemoryBlock(Handle memblock, u32 addr, MemPerm my_perm, MemPerm other_perm)
void gfxSetFramebufferInfo(gfxScreen_t screen, u8 id)
Definition: gfx.c:25
void linearFree(void *mem)
Definition: linear.cpp:113
void gfxSwapBuffers()
Definition: gfx.c:151
u8 gfxThreadID
Definition: gfx.c:8
u8 * gfxTopRightFramebuffers[2]
Definition: gfx.c:12
GSP_FramebufferInfo bottomFramebufferInfo
Definition: gfx.c:6
u32 active_framebuf
Definition: gsp.h:7
Result GSPGPU_SetLcdForceBlack(Handle *handle, u8 flags)
Definition: gsp.c:219
Result GSPGPU_SetBufferSwap(Handle *handle, u32 screenid, GSP_FramebufferInfo *framebufinfo)
Definition: gsp.c:168
u32 * framebuf0_vaddr
Definition: gsp.h:8