src/video/nds/SDL_ndsvideo.c
author Darren Alton <dalton@stevens.edu>
Wed, 02 Jul 2008 13:59:30 +0000
branchgsoc2008_nds
changeset 2677 6386764eb222
parent 2673 24a6b3588eac
child 2679 bc3e3e889f6d
permissions -rw-r--r--
Starting to work on a more complete video driver.
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@2673
    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@2673
    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@2671
    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@2673
   116
    /* simple 256x192x15x60 for now */
dalton@2671
   117
    mode.w = 256;
dalton@2671
   118
    mode.h = 192;
dalton@2673
   119
    mode.format = SDL_PIXELFORMAT_BGR555;
dalton@2670
   120
    mode.refresh_rate = 60;
dalton@2670
   121
    mode.driverdata = NULL;
dalton@2670
   122
dalton@2670
   123
    SDL_AddBasicVideoDisplay(&mode);
dalton@2677
   124
    SDL_AddRenderDriver(0, &NDS_RenderDriver);
dalton@2670
   125
dalton@2670
   126
    SDL_zero(mode);
dalton@2670
   127
    SDL_AddDisplayMode(0, &mode);
dalton@2670
   128
dalton@2671
   129
    /* hackish stuff to get things up and running for now, and for a console */
dalton@2671
   130
    powerON(POWER_ALL);
dalton@2671
   131
    videoSetMode(MODE_FB0);
dalton@2671
   132
    videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE);    /* debug text on sub */
dalton@2671
   133
    
dalton@2671
   134
    vramSetBankA(VRAM_A_LCD);
dalton@2671
   135
    vramSetBankC(VRAM_C_SUB_BG);
dalton@2671
   136
    
dalton@2670
   137
    irqInit();
dalton@2671
   138
    irqEnable(IRQ_VBLANK);
dalton@2671
   139
    /* set up console for debug text 'n stuff */
dalton@2671
   140
    SUB_BG0_CR = BG_MAP_BASE(31);
dalton@2671
   141
    BG_PALETTE_SUB[255] = RGB15(31, 31, 31);
dalton@2673
   142
    consoleInitDefault((u16 *) SCREEN_BASE_BLOCK_SUB(31),
dalton@2671
   143
                       (u16 *) CHAR_BASE_BLOCK_SUB(0), 16);
dalton@2670
   144
dalton@2670
   145
    /*NDS_SetDisplayMode(_this, &mode); */
dalton@2670
   146
    return 0;
dalton@2670
   147
}
dalton@2670
   148
dalton@2670
   149
static int
dalton@2673
   150
NDS_SetDisplayMode(_THIS, SDL_DisplayMode * mode)
dalton@2670
   151
{
dalton@2671
   152
    /* right now this function is just hard-coded for 256x192 ABGR1555 */
dalton@2671
   153
#if 0
dalton@2670
   154
    videoSetMode(MODE_5_2D | DISPLAY_BG3_ACTIVE);       /* display on main core */
dalton@2670
   155
    videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE);    /* debug text on sub */
dalton@2670
   156
    vramSetMainBanks(VRAM_A_MAIN_BG_0x06000000, VRAM_B_LCD,
dalton@2670
   157
                     VRAM_C_SUB_BG, VRAM_D_LCD);
dalton@2670
   158
dalton@2670
   159
    /* maps well to the 256x192 screen anyway.  note: need VRAM_B for bigger */
dalton@2671
   160
    BG3_CR = BG_BMP16_256x256;
dalton@2671
   161
    /* affine transformation matrix.  nothing too fancy here */
dalton@2671
   162
    BG3_XDX = 0x100;
dalton@2671
   163
    BG3_XDY = 0;
dalton@2671
   164
    BG3_YDX = 0;
dalton@2671
   165
    BG3_YDY = 0x100;
dalton@2671
   166
    /* x/y position */
dalton@2670
   167
    BG3_CX = 0;
dalton@2670
   168
    BG3_CY = 0;
dalton@2670
   169
#endif
dalton@2670
   170
    return 0;
dalton@2670
   171
}
dalton@2670
   172
dalton@2670
   173
void
dalton@2670
   174
NDS_VideoQuit(_THIS)
dalton@2670
   175
{
dalton@2670
   176
}
dalton@2677
   177
dalton@2677
   178
/* vi: set ts=4 sw=4 expandtab: */