comparison src/video/nds/SDL_ndsvideo.c @ 2735:204be4fc2726

Final merge of Google Summer of Code 2008 work... Port SDL 1.3 to the Nintendo DS by Darren Alton, mentored by Sam Lantinga
author Sam Lantinga <slouken@libsdl.org>
date Wed, 27 Aug 2008 15:10:03 +0000
parents
children 99210400e8b9
comparison
equal deleted inserted replaced
2734:dd25eabe441c 2735:204be4fc2726
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 /* SDL Nintendo DS video driver implementation
25 * based on dummy driver:
26 * Initial work by Ryan C. Gordon (icculus@icculus.org). A good portion
27 * of this was cut-and-pasted from Stephane Peter's work in the AAlib
28 * SDL video driver. Renamed to "DUMMY" by Sam Lantinga.
29 */
30
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <nds.h>
34 #include <nds/arm9/video.h>
35
36 #include "SDL_video.h"
37 #include "SDL_mouse.h"
38 #include "../SDL_sysvideo.h"
39 #include "../SDL_pixels_c.h"
40 #include "../../events/SDL_events_c.h"
41
42 #include "SDL_ndsvideo.h"
43 #include "SDL_ndsevents_c.h"
44 #include "SDL_ndsrender_c.h"
45
46 #define NDSVID_DRIVER_NAME "nds"
47
48 /* Initialization/Query functions */
49 static int NDS_VideoInit(_THIS);
50 static int NDS_SetDisplayMode(_THIS, SDL_DisplayMode * mode);
51 static void NDS_VideoQuit(_THIS);
52
53
54 /* SDL NDS driver bootstrap functions */
55 static int
56 NDS_Available(void)
57 {
58 return (1); /* always here */
59 }
60
61 static void
62 NDS_DeleteDevice(SDL_VideoDevice * device)
63 {
64 SDL_free(device);
65 }
66
67 static SDL_VideoDevice *
68 NDS_CreateDevice(int devindex)
69 {
70 SDL_VideoDevice *device;
71
72 /* Initialize all variables that we clean on shutdown */
73 device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
74 if (!device) {
75 SDL_OutOfMemory();
76 if (device) {
77 SDL_free(device);
78 }
79 return (0);
80 }
81
82 /* Set the function pointers */
83 device->VideoInit = NDS_VideoInit;
84 device->VideoQuit = NDS_VideoQuit;
85 device->SetDisplayMode = NDS_SetDisplayMode;
86 device->PumpEvents = NDS_PumpEvents;
87
88 device->num_displays = 2; /* DS = dual screens */
89
90 device->free = NDS_DeleteDevice;
91
92 return device;
93 }
94
95 VideoBootStrap NDS_bootstrap = {
96 NDSVID_DRIVER_NAME, "SDL NDS video driver",
97 NDS_Available, NDS_CreateDevice
98 };
99
100 int
101 NDS_VideoInit(_THIS)
102 {
103 SDL_DisplayMode mode;
104 int i;
105
106 /* simple 256x192x16x60 for now */
107 mode.w = 256;
108 mode.h = 192;
109 mode.format = SDL_PIXELFORMAT_ABGR1555;
110 mode.refresh_rate = 60;
111 mode.driverdata = NULL;
112
113 SDL_AddBasicVideoDisplay(&mode);
114 SDL_AddRenderDriver(0, &NDS_RenderDriver);
115
116 SDL_zero(mode);
117 SDL_AddDisplayMode(0, &mode);
118
119 powerON(POWER_ALL_2D);
120 irqInit();
121 irqEnable(IRQ_VBLANK);
122 NDS_SetDisplayMode(_this, &mode);
123
124 return 0;
125 }
126
127 static int
128 NDS_SetDisplayMode(_THIS, SDL_DisplayMode * mode)
129 {
130 /* right now this function is just hard-coded for 256x192 ABGR1555 */
131 videoSetMode(MODE_5_2D | DISPLAY_BG2_ACTIVE | DISPLAY_BG3_ACTIVE | DISPLAY_BG_EXT_PALETTE | DISPLAY_SPR_1D_LAYOUT | DISPLAY_SPR_1D_BMP | DISPLAY_SPR_1D_BMP_SIZE_256 | /* (try 128 if 256 is trouble.) */
132 DISPLAY_SPR_ACTIVE | DISPLAY_SPR_EXT_PALETTE); /* display on main core
133 with lots of flags set for
134 flexibility/capacity to render */
135
136 /* hopefully these cover all the various things we might need to do */
137 vramSetBankA(VRAM_A_MAIN_BG_0x06000000);
138 vramSetBankB(VRAM_B_MAIN_BG_0x06020000);
139 vramSetBankC(VRAM_C_SUB_BG_0x06200000);
140 vramSetBankD(VRAM_D_MAIN_BG_0x06040000); /* not a typo. vram d can't sub */
141 vramSetBankE(VRAM_E_MAIN_SPRITE);
142 vramSetBankF(VRAM_F_OBJ_EXT_PALETTE);
143 vramSetBankG(VRAM_G_BG_EXT_PALETTE);
144 vramSetBankH(VRAM_H_SUB_BG_EXT_PALETTE);
145 vramSetBankI(VRAM_I_SUB_SPRITE);
146
147 videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE); /* debug text on sub
148 TODO: this will change
149 when multi-head is
150 introduced in render */
151
152 return 0;
153 }
154
155 void
156 NDS_VideoQuit(_THIS)
157 {
158 videoSetMode(DISPLAY_SCREEN_OFF);
159 videoSetModeSub(DISPLAY_SCREEN_OFF);
160 vramSetMainBanks(VRAM_A_LCD, VRAM_B_LCD, VRAM_C_LCD, VRAM_D_LCD);
161 vramSetBankE(VRAM_E_LCD);
162 vramSetBankF(VRAM_F_LCD);
163 vramSetBankG(VRAM_G_LCD);
164 vramSetBankH(VRAM_H_LCD);
165 vramSetBankI(VRAM_I_LCD);
166 }
167
168 /* vi: set ts=4 sw=4 expandtab: */