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