comparison src/video/nds/SDL_ndsvideo.c @ 2670:6e4669f4db49 gsoc2008_nds

Fix for the previous commit: actually 'svn add'ed some files.
author Darren Alton <dalton@stevens.edu>
date Tue, 10 Jun 2008 06:57:57 +0000
parents
children c3e7c0698cbb
comparison
equal deleted inserted replaced
2669:e27bdcc80744 2670:6e4669f4db49
1 /*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2006 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21 */
22 #include "SDL_config.h"
23
24 /* Dummy SDL video driver implementation; this is just enough to make an
25 * SDL-based application THINK it's got a working video driver, for
26 * applications that call SDL_Init(SDL_INIT_VIDEO) when they don't need it,
27 * and also for use as a collection of stubs when porting SDL to a new
28 * platform for which you haven't yet written a valid video driver.
29 *
30 * This is also a great way to determine bottlenecks: if you think that SDL
31 * is a performance problem for a given platform, enable this driver, and
32 * then see if your application runs faster without video overhead.
33 *
34 * Initial work by Ryan C. Gordon (icculus@icculus.org). A good portion
35 * of this was cut-and-pasted from Stephane Peter's work in the AAlib
36 * SDL video driver. Renamed to "DUMMY" by Sam Lantinga.
37 */
38
39 #include <stdio.h>
40 #include <stdlib.h>
41 #include <nds.h>
42
43 #include "SDL_video.h"
44 #include "SDL_mouse.h"
45 #include "../SDL_sysvideo.h"
46 #include "../SDL_pixels_c.h"
47 #include "../../events/SDL_events_c.h"
48
49 #include "SDL_ndsvideo.h"
50 #include "SDL_ndsevents_c.h"
51 #include "SDL_ndsrender_c.h"
52
53 #define NDSVID_DRIVER_NAME "nds"
54
55 /* Initialization/Query functions */
56 static int NDS_VideoInit(_THIS);
57 static int NDS_SetDisplayMode(_THIS, SDL_DisplayMode * mode);
58 static void NDS_VideoQuit(_THIS);
59
60 /* DUMMY driver bootstrap functions */
61
62 static int
63 NDS_Available(void)
64 {
65 const char *envr = SDL_getenv("SDL_VIDEODRIVER");
66 printf("NDS_Available()\n");
67 return (1);
68 }
69
70 static void
71 NDS_DeleteDevice(SDL_VideoDevice * device)
72 {
73 SDL_free(device);
74 }
75
76 static SDL_VideoDevice *
77 NDS_CreateDevice(int devindex)
78 {
79 SDL_VideoDevice *device;
80 printf("NDS_CreateDevice(%d)\n", devindex);
81
82 /* Initialize all variables that we clean on shutdown */
83 device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
84 if (!device) {
85 SDL_OutOfMemory();
86 if (device) {
87 SDL_free(device);
88 }
89 return (0);
90 }
91
92 /* Set the function pointers */
93 device->VideoInit = NDS_VideoInit;
94 device->VideoQuit = NDS_VideoQuit;
95 device->SetDisplayMode = NDS_SetDisplayMode;
96 device->PumpEvents = NDS_PumpEvents;
97
98 device->num_displays = 2; /* DS = dual screens */
99
100 device->free = NDS_DeleteDevice;
101
102 return device;
103 }
104
105 VideoBootStrap NDS_bootstrap = {
106 NDSVID_DRIVER_NAME, "SDL NDS video driver",
107 NDS_Available, NDS_CreateDevice
108 };
109
110 int
111 NDS_VideoInit(_THIS)
112 {
113 SDL_DisplayMode mode;
114 int i;
115
116 /* simple 256x192x16x60 for now */
117 mode.w = 256; mode.h = 192;
118 mode.format = SDL_PIXELFORMAT_ARGB1555;
119 mode.refresh_rate = 60;
120 mode.driverdata = NULL;
121
122 SDL_AddBasicVideoDisplay(&mode);
123 SDL_AddRenderDriver(0, &SDL_NDS_RenderDriver);
124
125 SDL_zero(mode);
126 SDL_AddDisplayMode(0, &mode);
127
128 /* hackish stuff to get things up and running for now, and for a console */
129 powerON(POWER_ALL);
130 videoSetMode(MODE_FB0);
131 videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE); /* debug text on sub */
132 vramSetBankA(VRAM_A_LCD);
133 vramSetBankC(VRAM_C_SUB_BG);
134 irqInit();
135 irqEnable(IRQ_VBLANK);
136 /* set up console for debug text 'n stuff */
137 SUB_BG0_CR = BG_MAP_BASE(31); BG_PALETTE_SUB[255] = RGB15(31,31,31);
138 consoleInitDefault((u16*)SCREEN_BASE_BLOCK_SUB(31),
139 (u16*)CHAR_BASE_BLOCK_SUB(0), 16);
140 for(i = 0; i < 256*192; ++i) {
141 ((u16*)VRAM_A)[i] = i;
142 }
143 for(i = 0; i < 60; ++i) swiWaitForVBlank();
144 /*NDS_SetDisplayMode(_this, &mode);*/
145 return 0;
146 }
147
148 static int
149 NDS_SetDisplayMode(_THIS, SDL_DisplayMode * mode)
150 {
151 /* right now this function is just hard-coded for 256x192 ARGB1555 */
152 #if 0
153 videoSetMode(MODE_5_2D | DISPLAY_BG3_ACTIVE); /* display on main core */
154 videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE); /* debug text on sub */
155 vramSetMainBanks(VRAM_A_MAIN_BG_0x06000000, VRAM_B_LCD,
156 VRAM_C_SUB_BG, VRAM_D_LCD);
157
158 /* maps well to the 256x192 screen anyway. note: need VRAM_B for bigger */
159 BG3_CR = BG_BMP16_256x256;
160 /* affine transformation matrix. nothing too fancy here */
161 BG3_XDX = 0x100; BG3_XDY = 0;
162 BG3_YDX = 0; BG3_YDY = 0x100;
163 /* x/y position */
164 BG3_CX = 0; BG3_CY = 0;
165 #endif
166 return 0;
167 }
168
169 void
170 NDS_VideoQuit(_THIS)
171 {
172 }
173
174 /* vi: set ts=4 sw=4 expandtab: */