/
swimp_ctr.c
114 lines (87 loc) · 2.52 KB
/
swimp_ctr.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
/*
Copyright (C) 2017 Felipe Izzo
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "../ref_soft/r_local.h"
#include <3ds.h>
#define STACKSIZE 1024
Thread refresh_thread;
Handle refresh_request;
int run_thread = 1;
uint16_t *framebuffer;
uint8_t *swap_buffer;
uint16_t d_8to16table[256];
void SWimp_ThreadFunc(void *arg)
{
while(run_thread)
{
svcWaitSynchronization(refresh_request, U64_MAX);
for(int x=0; x<400; x++)
for(int y=0; y<240;y++)
framebuffer[(x*240 + (239 -y))] = d_8to16table[swap_buffer[y*400 + x]];
gfxFlushBuffers();
gfxSwapBuffers();
svcClearEvent(refresh_request);
}
}
void SWimp_BeginFrame( float camera_separation )
{
}
void SWimp_EndFrame (void)
{
framebuffer = (uint16_t*)gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);
memcpy(swap_buffer, vid.buffer, 400 * 240);
svcSignalEvent(refresh_request);
}
int SWimp_Init( void *hInstance, void *wndProc )
{
svcCreateEvent(&refresh_request,0);
refresh_thread = threadCreate(SWimp_ThreadFunc, 0, STACKSIZE, 0x18, 1, true);
return 0;
}
void SWimp_SetPalette( const unsigned char *palette)
{
int i;
unsigned char r, g, b;
if(palette==NULL)
return;
for(i = 0; i < 256; i++)
{
r = palette[i*4+0];
g = palette[i*4+1];
b = palette[i*4+2];
d_8to16table[i] = RGB8_to_565(r,g,b);
}
}
void SWimp_Shutdown( void )
{
run_thread = 0;
svcSignalEvent(refresh_request);
threadJoin(refresh_thread, U64_MAX);
svcCloseHandle(refresh_request);
free(swap_buffer);
free(vid.buffer);
}
rserr_t SWimp_SetMode( int *pwidth, int *pheight, int mode, qboolean fullscreen )
{
vid.height = 240;
vid.width = 400;
vid.rowbytes = 400;
vid.buffer = malloc(400 * 240);
swap_buffer = malloc(400 * 240);
return rserr_ok;
}
void SWimp_AppActivate( qboolean active )
{
}