Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
664 lines (584 loc) · 21.2 KB

SDL_ndsrender.c

File metadata and controls

664 lines (584 loc) · 21.2 KB
 
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
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2006 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/
#include <stdio.h>
#include <stdlib.h>
#include <nds.h>
Aug 15, 2008
Aug 15, 2008
26
27
28
#include <nds/arm9/video.h>
#include <nds/arm9/sprite.h>
#include <nds/arm9/trig_lut.h>
29
30
31
32
33
34
35
36
#include "SDL_config.h"
#include "SDL_video.h"
#include "../SDL_sysvideo.h"
#include "../SDL_yuv_sw_c.h"
#include "../SDL_renderer_sw.h"
Aug 16, 2008
Aug 16, 2008
37
38
#define TRACE
//#define TRACE printf
Aug 15, 2008
Aug 15, 2008
39
40
41
42
43
44
/* NDS sprite-related functions */
#define SPRITE_DMA_CHANNEL 3
#define SPRITE_ANGLE_MASK 0x01FF
void
Aug 16, 2008
Aug 16, 2008
45
NDS_OAM_Update(tOAM *oam, int sub)
Aug 15, 2008
Aug 15, 2008
46
47
{
DC_FlushAll();
Aug 16, 2008
Aug 16, 2008
48
dmaCopyHalfWords(SPRITE_DMA_CHANNEL, oam->spriteBuffer, sub?OAM_SUB:OAM,
Aug 15, 2008
Aug 15, 2008
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
SPRITE_COUNT * sizeof(SpriteEntry));
}
void
NDS_OAM_RotateSprite(SpriteRotation *spriteRotation, u16 angle)
{
s16 s = SIN[angle & SPRITE_ANGLE_MASK] >> 4;
s16 c = COS[angle & SPRITE_ANGLE_MASK] >> 4;
spriteRotation->hdx = c;
spriteRotation->hdy = s;
spriteRotation->vdx = -s;
spriteRotation->vdy = c;
}
void
Aug 16, 2008
Aug 16, 2008
65
NDS_OAM_Init(tOAM *oam, int sub)
Aug 15, 2008
Aug 15, 2008
66
67
68
69
70
71
72
73
74
75
76
{
int i;
for(i = 0; i < SPRITE_COUNT; i++) {
oam->spriteBuffer[i].attribute[0] = ATTR0_DISABLED;
oam->spriteBuffer[i].attribute[1] = 0;
oam->spriteBuffer[i].attribute[2] = 0;
}
for(i = 0; i < MATRIX_COUNT; i++) {
NDS_OAM_RotateSprite(&(oam->matrixBuffer[i]), 0);
}
swiWaitForVBlank();
Aug 16, 2008
Aug 16, 2008
77
NDS_OAM_Update(oam, sub);
Aug 15, 2008
Aug 15, 2008
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
}
void
NDS_OAM_HideSprite(SpriteEntry *spriteEntry)
{
spriteEntry->isRotoscale = 0;
spriteEntry->isHidden = 1;
}
void
NDS_OAM_ShowSprite(SpriteEntry *spriteEntry, int affine, int double_bound)
{
if (affine) {
spriteEntry->isRotoscale = 1;
spriteEntry->rsDouble = double_bound;
} else {
spriteEntry->isHidden = 0;
}
}
Aug 13, 2008
Aug 13, 2008
99
/* SDL NDS renderer implementation */
Jul 2, 2008
Jul 2, 2008
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
static SDL_Renderer *NDS_CreateRenderer(SDL_Window * window, Uint32 flags);
static int NDS_ActivateRenderer(SDL_Renderer * renderer);
static int NDS_DisplayModeChanged(SDL_Renderer * renderer);
static int NDS_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
static int NDS_QueryTexturePixels(SDL_Renderer * renderer,
SDL_Texture * texture, void **pixels,
int *pitch);
static int NDS_SetTexturePalette(SDL_Renderer * renderer,
SDL_Texture * texture,
const SDL_Color * colors, int firstcolor,
int ncolors);
static int NDS_GetTexturePalette(SDL_Renderer * renderer,
SDL_Texture * texture, SDL_Color * colors,
int firstcolor, int ncolors);
static int NDS_SetTextureColorMod(SDL_Renderer * renderer,
SDL_Texture * texture);
static int NDS_SetTextureAlphaMod(SDL_Renderer * renderer,
SDL_Texture * texture);
static int NDS_SetTextureBlendMode(SDL_Renderer * renderer,
SDL_Texture * texture);
static int NDS_SetTextureScaleMode(SDL_Renderer * renderer,
SDL_Texture * texture);
static int NDS_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
Aug 16, 2008
Aug 16, 2008
124
125
const SDL_Rect * rect, const void *pixels,
int pitch);
Jul 2, 2008
Jul 2, 2008
126
127
128
129
130
131
132
133
static int NDS_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, int markDirty, void **pixels,
int *pitch);
static void NDS_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
static void NDS_DirtyTexture(SDL_Renderer * renderer,
SDL_Texture * texture, int numrects,
const SDL_Rect * rects);
static int NDS_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g,
Jun 12, 2008
Jun 12, 2008
134
Uint8 b, Uint8 a, const SDL_Rect * rect);
Jul 2, 2008
Jul 2, 2008
135
static int NDS_RenderCopy(SDL_Renderer * renderer,
Jun 12, 2008
Jun 12, 2008
136
137
138
SDL_Texture * texture,
const SDL_Rect * srcrect,
const SDL_Rect * dstrect);
Jul 2, 2008
Jul 2, 2008
139
140
141
static void NDS_RenderPresent(SDL_Renderer * renderer);
static void NDS_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture);
static void NDS_DestroyRenderer(SDL_Renderer * renderer);
Jul 2, 2008
Jul 2, 2008
144
145
SDL_RenderDriver NDS_RenderDriver = {
NDS_CreateRenderer,
Jul 13, 2008
Jul 13, 2008
146
{ "nds", /* char* name */
Aug 16, 2008
Aug 16, 2008
147
148
149
150
(SDL_RENDERER_SINGLEBUFFER |
SDL_RENDERER_ACCELERATED |
SDL_RENDERER_PRESENTDISCARD |
SDL_RENDERER_PRESENTVSYNC), /* u32 flags */
Jul 13, 2008
Jul 13, 2008
151
(SDL_TEXTUREMODULATE_NONE), /* u32 mod_modes */
Aug 16, 2008
Aug 16, 2008
152
153
(SDL_TEXTUREBLENDMODE_MASK), /* u32 blend_modes */
(SDL_TEXTURESCALEMODE_FAST), /* u32 scale_modes */
Jul 13, 2008
Jul 13, 2008
154
155
156
3, /* u32 num_texture_formats */
{
SDL_PIXELFORMAT_INDEX8,
Jul 25, 2008
Jul 25, 2008
157
158
SDL_PIXELFORMAT_ABGR1555,
SDL_PIXELFORMAT_BGR555,
Jul 13, 2008
Jul 13, 2008
159
160
161
162
}, /* u32 texture_formats[20] */
(256), /* int max_texture_width */
(256), /* int max_texture_height */
}
163
164
165
166
};
typedef struct
{
Aug 15, 2008
Aug 15, 2008
167
168
bg_attribute *bg; /* backgrounds */
tOAM oam_copy; /* sprites */
Jul 13, 2008
Jul 13, 2008
169
170
u8 bg_taken[4];
int sub;
Jul 2, 2008
Jul 2, 2008
171
} NDS_RenderData;
Jul 10, 2008
Jul 10, 2008
173
174
typedef struct
{
Aug 16, 2008
Aug 16, 2008
175
enum { NDSTX_BG, NDSTX_SPR } type; /* represented in a bg or sprite. */
Aug 16, 2008
Aug 16, 2008
176
int hw_index; /* sprite: index in the OAM. / bg: 2 or 3. */
Aug 16, 2008
Aug 16, 2008
177
178
179
180
181
182
183
184
struct
{
int hdx, hdy, vdx, vdy; /* affine transformation, used for scaling. */
int pitch, bpp; /* some useful info */
} dim;
u16 *vram_pixels; /* where the pixel data is stored (a pointer into VRAM) */
u16 *vram_palette; /* where the palette data is stored if it's indexed.*/
/*int size;*/
Jul 10, 2008
Jul 10, 2008
185
} NDS_TextureData;
Jun 17, 2008
Jun 17, 2008
186
187
188
189
SDL_Renderer *
Jul 2, 2008
Jul 2, 2008
190
NDS_CreateRenderer(SDL_Window * window, Uint32 flags)
191
192
193
194
{
SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
SDL_DisplayMode *displayMode = &display->current_mode;
SDL_Renderer *renderer;
Jul 2, 2008
Jul 2, 2008
195
NDS_RenderData *data;
Aug 15, 2008
Aug 15, 2008
197
int bpp;
Jun 19, 2008
Jun 19, 2008
198
Uint32 Rmask, Gmask, Bmask, Amask;
Aug 16, 2008
Aug 16, 2008
200
TRACE("+NDS_CreateRenderer\n");
Aug 15, 2008
Aug 15, 2008
201
if (!SDL_PixelFormatEnumToMasks(displayMode->format, &bpp,
Jun 19, 2008
Jun 19, 2008
202
203
204
205
&Rmask, &Gmask, &Bmask, &Amask)) {
SDL_SetError("Unknown display format");
return NULL;
}
Aug 15, 2008
Aug 15, 2008
206
207
208
209
210
211
switch(displayMode->format) {
case SDL_PIXELFORMAT_INDEX8:
case SDL_PIXELFORMAT_ABGR1555:
case SDL_PIXELFORMAT_BGR555:
/* okay */
break;
Aug 16, 2008
Aug 16, 2008
212
213
214
215
216
case SDL_PIXELFORMAT_RGB555:
case SDL_PIXELFORMAT_RGB565:
case SDL_PIXELFORMAT_ARGB1555:
/* we'll take these too for now */
break;
Aug 15, 2008
Aug 15, 2008
217
218
219
220
default:
printf("DEBUG: wrong display format!\n");
break;
}
221
222
223
224
225
226
227
renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
if (!renderer) {
SDL_OutOfMemory();
return NULL;
}
Jul 2, 2008
Jul 2, 2008
228
data = (NDS_RenderData *) SDL_malloc(sizeof(*data));
Jul 2, 2008
Jul 2, 2008
230
NDS_DestroyRenderer(renderer);
231
232
233
234
235
SDL_OutOfMemory();
return NULL;
}
SDL_zerop(data);
Jul 2, 2008
Jul 2, 2008
236
237
238
239
240
renderer->RenderFill = NDS_RenderFill;
renderer->RenderCopy = NDS_RenderCopy;
renderer->RenderPresent = NDS_RenderPresent;
renderer->DestroyRenderer = NDS_DestroyRenderer;
renderer->info.name = NDS_RenderDriver.info.name;
241
242
243
renderer->info.flags = 0;
renderer->window = window->id;
renderer->driverdata = data;
Jul 13, 2008
Jul 13, 2008
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
renderer->CreateTexture = NDS_CreateTexture;
renderer->QueryTexturePixels = NDS_QueryTexturePixels;
renderer->SetTexturePalette = NDS_SetTexturePalette;
renderer->GetTexturePalette = NDS_GetTexturePalette;
renderer->SetTextureColorMod = NDS_SetTextureColorMod;
renderer->SetTextureAlphaMod = NDS_SetTextureAlphaMod;
renderer->SetTextureBlendMode = NDS_SetTextureBlendMode;
renderer->SetTextureScaleMode = NDS_SetTextureScaleMode;
renderer->UpdateTexture = NDS_UpdateTexture;
renderer->LockTexture = NDS_LockTexture;
renderer->UnlockTexture = NDS_UnlockTexture;
renderer->DirtyTexture = NDS_DirtyTexture;
renderer->DestroyTexture = NDS_DestroyTexture;
renderer->info.mod_modes = NDS_RenderDriver.info.mod_modes;
renderer->info.blend_modes = NDS_RenderDriver.info.blend_modes;
renderer->info.scale_modes = NDS_RenderDriver.info.scale_modes;
renderer->info.num_texture_formats =
NDS_RenderDriver.info.num_texture_formats;
SDL_memcpy(renderer->info.texture_formats,
NDS_RenderDriver.info.texture_formats,
Aug 16, 2008
Aug 16, 2008
265
266
267
sizeof(renderer->info.texture_formats));
renderer->info.max_texture_width =
NDS_RenderDriver.info.max_texture_width;
Jul 13, 2008
Jul 13, 2008
268
269
270
renderer->info.max_texture_height =
NDS_RenderDriver.info.max_texture_height;
Aug 15, 2008
Aug 15, 2008
271
272
273
data->sub = 0; /* TODO: this is hard-coded to the "main" screen.
figure out how to detect whether to set it to
"sub" screen. window->id, perhaps? */
Aug 16, 2008
Aug 16, 2008
274
275
276
277
278
279
if(!data->sub) {
data->bg = &BACKGROUND;
} else {
data->bg = &BACKGROUND_SUB;
}
data->bg_taken[2] = data->bg_taken[3] = 0;
Aug 16, 2008
Aug 16, 2008
280
281
NDS_OAM_Init(&(data->oam_copy), data->sub); /* init sprites. */
Jun 17, 2008
Jun 17, 2008
282
Aug 16, 2008
Aug 16, 2008
283
TRACE("-NDS_CreateRenderer\n");
284
285
286
return renderer;
}
Jul 10, 2008
Jul 10, 2008
287
288
289
290
static int
NDS_ActivateRenderer(SDL_Renderer * renderer)
{
NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
Aug 16, 2008
Aug 16, 2008
291
TRACE("!NDS_ActivateRenderer\n");
Jul 10, 2008
Jul 10, 2008
292
293
294
295
296
297
298
return 0;
}
static int
NDS_DisplayModeChanged(SDL_Renderer * renderer)
{
NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
Aug 16, 2008
Aug 16, 2008
299
TRACE("!NDS_DisplayModeChanged\n");
Jul 10, 2008
Jul 10, 2008
300
301
302
303
304
305
306
return 0;
}
static int
NDS_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
{
NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
Jul 13, 2008
Jul 13, 2008
307
NDS_TextureData *txdat = NULL;
Jul 26, 2008
Jul 26, 2008
308
int i;
Aug 15, 2008
Aug 15, 2008
309
310
311
int bpp;
Uint32 Rmask, Gmask, Bmask, Amask;
Aug 16, 2008
Aug 16, 2008
312
TRACE("+NDS_CreateTexture\n");
Aug 15, 2008
Aug 15, 2008
313
314
315
if (!SDL_PixelFormatEnumToMasks
(texture->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
SDL_SetError("Unknown texture format");
Jul 10, 2008
Jul 10, 2008
316
return -1;
Aug 15, 2008
Aug 15, 2008
317
}
Jul 10, 2008
Jul 10, 2008
318
Aug 15, 2008
Aug 15, 2008
319
320
321
/* conditional statements on w/h to place it as bg/sprite
depending on which one it fits. */
if(texture->w <= 64 && texture->h <= 64) {
Aug 16, 2008
Aug 16, 2008
322
int whichspr = -1;
Aug 15, 2008
Aug 15, 2008
323
printf("Tried to make a sprite.\n");
Aug 16, 2008
Aug 16, 2008
324
txdat->type = NDSTX_SPR;
Aug 16, 2008
Aug 16, 2008
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
for(i = 0; i < SPRITE_COUNT; ++i) {
if(data->oam_copy.spriteBuffer[i].attribute[0] & ATTR0_DISABLED) {
whichspr = i;
break;
}
}
if(whichspr >= 0) {
SpriteEntry *sprent = &(data->oam_copy.spriteBuffer[whichspr]);
texture->driverdata = SDL_calloc(1, sizeof(NDS_TextureData));
txdat = (NDS_TextureData*)texture->driverdata;
if(!txdat) {
SDL_OutOfMemory();
return -1;
}
sprent->objMode = OBJMODE_BITMAP;
sprent->posX = 0; sprent->posY = 0;
sprent->colMode = OBJCOLOR_16; /* OBJCOLOR_256 for INDEX8 */
Aug 16, 2008
Aug 16, 2008
344
345
346
/* the first 32 sprites get transformation matrices.
first come, first served */
Aug 16, 2008
Aug 16, 2008
347
348
349
350
if(whichspr < MATRIX_COUNT) {
sprent->isRotoscale = 1;
sprent->rsMatrixIdx = whichspr;
}
Aug 16, 2008
Aug 16, 2008
351
352
353
354
355
356
357
358
359
sprent->objShape = OBJSHAPE_SQUARE;
if(texture->w/2 >= texture->h) {
sprent->objShape = OBJSHAPE_WIDE;
} else if(texture->h/2 >= texture->w) {
sprent->objShape = OBJSHAPE_TALL;
}
} else {
SDL_SetError("Out of NDS sprites.");
Aug 16, 2008
Aug 16, 2008
360
}
Aug 15, 2008
Aug 15, 2008
361
} else if(texture->w <= 256 && texture->h <= 256) {
Aug 16, 2008
Aug 16, 2008
362
int whichbg = -1, base = 0;
Aug 15, 2008
Aug 15, 2008
363
364
365
366
if(!data->bg_taken[2]) {
whichbg = 2;
} else if(!data->bg_taken[3]) {
whichbg = 3;
Aug 16, 2008
Aug 16, 2008
367
base = 4;
Jul 10, 2008
Jul 10, 2008
368
}
Aug 15, 2008
Aug 15, 2008
369
if(whichbg >= 0) {
Aug 16, 2008
Aug 16, 2008
370
371
372
373
374
375
376
texture->driverdata = SDL_calloc(1, sizeof(NDS_TextureData));
txdat = (NDS_TextureData*)texture->driverdata;
if(!txdat) {
SDL_OutOfMemory();
return -1;
}
Aug 15, 2008
Aug 15, 2008
377
378
/* TODO: maybe this should be in RenderPresent or RenderCopy
instead, copying from a malloc'd system RAM pixel buffer. */
Aug 16, 2008
Aug 16, 2008
379
/* this is hard-coded to being 256x256 for now. */
Aug 15, 2008
Aug 15, 2008
380
381
data->bg->control[whichbg] = (bpp == 8) ?
BG_BMP8_256x256 : BG_BMP16_256x256;
Aug 16, 2008
Aug 16, 2008
382
383
384
data->bg->control[whichbg] |= BG_BMP_BASE(base);
Aug 15, 2008
Aug 15, 2008
385
386
data->bg->scroll[whichbg].x = 0;
data->bg->scroll[whichbg].y = 0;
Aug 16, 2008
Aug 16, 2008
387
Aug 15, 2008
Aug 15, 2008
388
389
390
391
txdat->type = NDSTX_BG;
txdat->hw_index = whichbg;
txdat->dim.hdx = 0x100; txdat->dim.hdy = 0;
txdat->dim.vdx = 0; txdat->dim.vdy = 0x100;
Aug 16, 2008
Aug 16, 2008
392
txdat->dim.pitch = texture->w * ((bpp+1)/8);
Aug 15, 2008
Aug 15, 2008
393
txdat->dim.bpp = bpp;
Aug 16, 2008
Aug 16, 2008
394
395
txdat->vram_pixels = (u16*)(data->sub ?
BG_BMP_RAM_SUB(base) : BG_BMP_RAM(base));
Aug 16, 2008
Aug 16, 2008
396
Aug 16, 2008
Aug 16, 2008
397
/*txdat->size = txdat->dim.pitch * texture->h;*/
Jul 13, 2008
Jul 13, 2008
398
} else {
Aug 15, 2008
Aug 15, 2008
399
SDL_SetError("Out of NDS backgrounds.");
Jul 13, 2008
Jul 13, 2008
400
}
Aug 15, 2008
Aug 15, 2008
401
402
} else {
SDL_SetError("Texture too big for NDS hardware.");
Jul 10, 2008
Jul 10, 2008
403
404
}
Aug 16, 2008
Aug 16, 2008
405
TRACE("-NDS_CreateTexture\n");
Jul 10, 2008
Jul 10, 2008
406
407
408
if (!texture->driverdata) {
return -1;
}
Aug 15, 2008
Aug 15, 2008
409
Jul 10, 2008
Jul 10, 2008
410
411
412
413
414
415
416
return 0;
}
static int
NDS_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture,
void **pixels, int *pitch)
{
Aug 15, 2008
Aug 15, 2008
417
NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
Aug 16, 2008
Aug 16, 2008
418
419
TRACE("+NDS_QueryTexturePixels\n");
*pixels = txdat->vram_pixels;
Aug 15, 2008
Aug 15, 2008
420
*pitch = txdat->dim.pitch;
Aug 16, 2008
Aug 16, 2008
421
TRACE("-NDS_QueryTexturePixels\n");
Aug 15, 2008
Aug 15, 2008
422
return 0;
Jul 10, 2008
Jul 10, 2008
423
424
425
426
427
428
}
static int
NDS_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, const void *pixels, int pitch)
{
Aug 16, 2008
Aug 16, 2008
429
NDS_TextureData *txdat;
Aug 15, 2008
Aug 15, 2008
430
431
Uint8 *src, *dst;
int row; size_t length;
Aug 16, 2008
Aug 16, 2008
432
TRACE("+NDS_UpdateTexture\n");
Aug 16, 2008
Aug 16, 2008
433
Aug 16, 2008
Aug 16, 2008
434
txdat = (NDS_TextureData *) texture->driverdata;
Aug 15, 2008
Aug 15, 2008
435
436
437
src = (Uint8 *) pixels;
dst =
Aug 16, 2008
Aug 16, 2008
438
(Uint8 *) txdat->vram_pixels + rect->y * txdat->dim.pitch +
Aug 16, 2008
Aug 16, 2008
439
440
rect->x * ((txdat->dim.bpp+1)/8);
length = rect->w * ((txdat->dim.bpp+1)/8);
Aug 16, 2008
Aug 16, 2008
441
442
443
444
445
446
447
448
449
if(rect->w == texture->w) {
dmaCopy(src, dst, length*rect->h);
} else {
for (row = 0; row < rect->h; ++row) {
dmaCopy(src, dst, length);
src += pitch;
dst += txdat->dim.pitch;
}
Jul 10, 2008
Jul 10, 2008
450
}
Aug 15, 2008
Aug 15, 2008
451
Aug 16, 2008
Aug 16, 2008
452
TRACE("-NDS_UpdateTexture\n");
Aug 15, 2008
Aug 15, 2008
453
return 0;
Jul 10, 2008
Jul 10, 2008
454
455
456
457
458
459
460
}
static int
NDS_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, int markDirty, void **pixels,
int *pitch)
{
Aug 15, 2008
Aug 15, 2008
461
NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
Aug 16, 2008
Aug 16, 2008
462
TRACE("+NDS_LockTexture\n");
Aug 15, 2008
Aug 15, 2008
463
Aug 16, 2008
Aug 16, 2008
464
*pixels = (void *) ((u8 *)txdat->vram_pixels + rect->y
Aug 16, 2008
Aug 16, 2008
465
* txdat->dim.pitch + rect->x * ((txdat->dim.bpp+1)/8));
Aug 15, 2008
Aug 15, 2008
466
*pitch = txdat->dim.pitch;
Aug 16, 2008
Aug 16, 2008
467
Aug 16, 2008
Aug 16, 2008
468
TRACE("-NDS_LockTexture\n");
Aug 15, 2008
Aug 15, 2008
469
return 0;
Jul 10, 2008
Jul 10, 2008
470
471
472
473
474
}
static void
NDS_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
{
Aug 16, 2008
Aug 16, 2008
475
476
TRACE("+NDS_UnlockTexture\n");
TRACE("-NDS_UnlockTexture\n");
Jul 10, 2008
Jul 10, 2008
477
478
479
480
481
}
static void
NDS_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
int numrects, const SDL_Rect * rects)
Aug 15, 2008
Aug 15, 2008
482
483
{
/* stub */
Aug 16, 2008
Aug 16, 2008
484
TRACE("!NDS_DirtyTexture\n");
Jul 10, 2008
Jul 10, 2008
485
486
}
Jul 2, 2008
Jul 2, 2008
488
NDS_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b,
Jun 12, 2008
Jun 12, 2008
489
Uint8 a, const SDL_Rect * rect)
Jul 2, 2008
Jul 2, 2008
491
NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
492
SDL_Rect real_rect = *rect;
Jul 2, 2008
Jul 2, 2008
493
494
495
u16 color;
int i, j;
Aug 16, 2008
Aug 16, 2008
496
TRACE("+NDS_RenderFill\n");
Aug 15, 2008
Aug 15, 2008
497
color = RGB8(r,g,b); /* <-- macro in libnds that makes an ARGB1555 pixel */
Jul 13, 2008
Jul 13, 2008
498
/* TODO: make a single-color sprite and stretch it.
Aug 15, 2008
Aug 15, 2008
499
500
501
502
503
504
505
506
calculate the "HDX" width modifier of the sprite by:
let S be the actual sprite's width (like, 32 pixels for example)
let R be the rectangle's width (maybe 50 pixels)
HDX = (R<<8) / S;
(it's fixed point, hence the bit shift. same goes for vertical.
be sure to use 32-bit int's for the bit shift before the division!)
*/
Aug 16, 2008
Aug 16, 2008
507
TRACE("-NDS_RenderFill\n");
Jul 2, 2008
Jul 2, 2008
508
return 0;
Jul 10, 2008
Jul 10, 2008
510
Jul 2, 2008
Jul 2, 2008
512
NDS_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
Jun 12, 2008
Jun 12, 2008
513
const SDL_Rect * srcrect, const SDL_Rect * dstrect)
Jul 2, 2008
Jul 2, 2008
515
NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
Jul 25, 2008
Jul 25, 2008
516
NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
Aug 14, 2008
Aug 14, 2008
517
518
SDL_Window *window = SDL_GetWindowFromID(renderer->window);
SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
Jul 26, 2008
Jul 26, 2008
519
int i;
Aug 13, 2008
Aug 13, 2008
520
521
int bpp = SDL_BYTESPERPIXEL(texture->format);
int pitch = txdat->dim.pitch;
Aug 16, 2008
Aug 16, 2008
522
523
TRACE("+NDS_RenderCopy\n");
Aug 13, 2008
Aug 13, 2008
524
if(txdat->type == NDSTX_BG) {
Aug 16, 2008
Aug 16, 2008
525
bg_rotation *bgrot = (txdat->hw_index == 2) ?
Aug 13, 2008
Aug 13, 2008
526
&(data->bg->bg2_rotation) : &(data->bg->bg3_rotation);
Aug 16, 2008
Aug 16, 2008
527
528
529
530
531
532
533
534
535
bgrot->xdx = txdat->dim.hdx;
bgrot->xdy = txdat->dim.hdy;
bgrot->ydx = txdat->dim.vdx;
bgrot->ydy = txdat->dim.vdy;
bgrot->centerX = 0;
bgrot->centerY = 0;
data->bg->scroll[txdat->hw_index].x = dstrect->x;
data->bg->scroll[txdat->hw_index].y = dstrect->y;
Aug 13, 2008
Aug 13, 2008
536
} else {
Aug 16, 2008
Aug 16, 2008
537
538
539
540
541
542
543
544
545
546
547
/* sprites not fully implemented yet */
SpriteEntry *spr = &(data->oam_copy.spriteBuffer[txdat->hw_index]);
spr->posX = dstrect->x;
spr->posY = dstrect->y;
if(txdat->hw_index < MATRIX_COUNT) {
SpriteRotation *sprot = &(data->oam_copy.matrixBuffer[txdat->hw_index]);
sprot->hdx = txdat->dim.hdx;
sprot->hdy = txdat->dim.hdy;
sprot->vdx = txdat->dim.vdx;
sprot->vdy = txdat->dim.vdy;
}
Aug 16, 2008
Aug 16, 2008
548
printf("tried to RenderCopy a sprite.\n");
Aug 16, 2008
Aug 16, 2008
550
551
TRACE("-NDS_RenderCopy\n");
Jul 26, 2008
Jul 26, 2008
552
return 0;
Jun 17, 2008
Jun 17, 2008
555
Jul 2, 2008
Jul 2, 2008
557
NDS_RenderPresent(SDL_Renderer * renderer)
Jul 2, 2008
Jul 2, 2008
559
NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
Aug 14, 2008
Aug 14, 2008
560
561
562
SDL_Window *window = SDL_GetWindowFromID(renderer->window);
SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
Aug 16, 2008
Aug 16, 2008
563
564
565
TRACE("+NDS_RenderPresent\n");
/* update sprites */
NDS_OAM_Update(&(data->oam_copy), data->sub);
Aug 13, 2008
Aug 13, 2008
566
/* vsync for NDS */
Jul 13, 2008
Jul 13, 2008
567
568
if (renderer->info.flags & SDL_RENDERER_PRESENTVSYNC) {
swiWaitForVBlank();
Aug 16, 2008
Aug 16, 2008
570
TRACE("-NDS_RenderPresent\n");
Jul 10, 2008
Jul 10, 2008
573
574
575
static void
NDS_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
{
Aug 16, 2008
Aug 16, 2008
576
TRACE("+NDS_DestroyTexture\n");
Aug 16, 2008
Aug 16, 2008
577
578
579
580
/* free anything else allocated for texture */
NDS_TextureData *txdat = texture->driverdata;
/*SDL_FreeDirtyRects(&txdat->dirty);*/
SDL_free(txdat);
Aug 16, 2008
Aug 16, 2008
581
TRACE("-NDS_DestroyTexture\n");
Jul 10, 2008
Jul 10, 2008
582
583
}
Jul 2, 2008
Jul 2, 2008
585
NDS_DestroyRenderer(SDL_Renderer * renderer)
Jul 2, 2008
Jul 2, 2008
587
NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
Jul 10, 2008
Jul 10, 2008
588
589
/*SDL_Window *window = SDL_GetWindowFromID(renderer->window);
SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);*/
Aug 16, 2008
Aug 16, 2008
592
TRACE("+NDS_DestroyRenderer\n");
Aug 15, 2008
Aug 15, 2008
594
/* TODO: free anything else relevant. */
Aug 16, 2008
Aug 16, 2008
595
/*if (data->surface.format) {
Jul 10, 2008
Jul 10, 2008
596
597
598
599
600
601
SDL_SetSurfacePalette(&data->surface, NULL);
SDL_FreeFormat(data->surface.format);
}
if (display->palette) {
SDL_DelPaletteWatch(display->palette, DisplayPaletteChanged,
data);
Aug 16, 2008
Aug 16, 2008
602
603
}*/
/*SDL_FreeDirtyRects(&data->dirty);*/
604
605
606
SDL_free(data);
}
SDL_free(renderer);
Aug 16, 2008
Aug 16, 2008
607
TRACE("-NDS_DestroyRenderer\n");
Aug 13, 2008
Aug 13, 2008
610
611
612
613
static int
NDS_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Color * colors, int firstcolor, int ncolors)
{
Aug 15, 2008
Aug 15, 2008
614
NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
Aug 16, 2008
Aug 16, 2008
615
TRACE("+NDS_SetTexturePalette\n");
Aug 15, 2008
Aug 15, 2008
616
617
/* set 8-bit modes in the background control registers
for backgrounds, BGn_CR |= BG_256_COLOR */
Aug 16, 2008
Aug 16, 2008
618
TRACE("-NDS_SetTexturePalette\n");
Aug 15, 2008
Aug 15, 2008
619
return 0;
Aug 13, 2008
Aug 13, 2008
620
621
622
623
624
625
}
static int
NDS_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
SDL_Color * colors, int firstcolor, int ncolors)
{
Aug 16, 2008
Aug 16, 2008
626
TRACE("+NDS_GetTexturePalette\n");
Aug 15, 2008
Aug 15, 2008
627
NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
Aug 16, 2008
Aug 16, 2008
628
TRACE("-NDS_GetTexturePalette\n");
Aug 15, 2008
Aug 15, 2008
629
return 0;
Aug 13, 2008
Aug 13, 2008
630
631
632
633
634
}
static int
NDS_SetTextureColorMod(SDL_Renderer * renderer, SDL_Texture * texture)
{
Aug 16, 2008
Aug 16, 2008
635
TRACE("!NDS_SetTextureColorMod\n");
Aug 15, 2008
Aug 15, 2008
636
/* stub! */
Aug 13, 2008
Aug 13, 2008
637
638
639
640
641
642
return 0;
}
static int
NDS_SetTextureAlphaMod(SDL_Renderer * renderer, SDL_Texture * texture)
{
Aug 16, 2008
Aug 16, 2008
643
TRACE("!NDS_SetTextureAlphaMod\n");
Aug 15, 2008
Aug 15, 2008
644
/* stub! */
Aug 13, 2008
Aug 13, 2008
645
646
647
648
649
650
return 0;
}
static int
NDS_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture)
{
Aug 16, 2008
Aug 16, 2008
651
TRACE("!NDS_SetTextureBlendMode\n");
Aug 15, 2008
Aug 15, 2008
652
/* stub! */
Aug 13, 2008
Aug 13, 2008
653
654
655
656
657
658
return 0;
}
static int
NDS_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture)
{
Aug 16, 2008
Aug 16, 2008
659
TRACE("!NDS_SetTextureScaleMode\n");
Aug 15, 2008
Aug 15, 2008
660
/* stub! (note: NDS hardware scaling is nearest neighbor.) */
Aug 13, 2008
Aug 13, 2008
661
662
663
return 0;
}
664
/* vi: set ts=4 sw=4 expandtab: */