src/video/nds/SDL_ndsvideo.c
author Sam Lantinga
Tue, 08 Feb 2011 16:50:51 -0800
changeset 5229 c015d3e63631
parent 3697 f7b03b6838cb
child 5262 b530ef003506
permissions -rw-r--r--
Fixed setting the texture unit, still doesn't work.
slouken@2735
     1
/*
slouken@2735
     2
    SDL - Simple DirectMedia Layer
slouken@3697
     3
    Copyright (C) 1997-2010 Sam Lantinga
slouken@2735
     4
slouken@2735
     5
    This library is free software; you can redistribute it and/or
slouken@2735
     6
    modify it under the terms of the GNU Lesser General Public
slouken@2735
     7
    License as published by the Free Software Foundation; either
slouken@2735
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@2735
     9
slouken@2735
    10
    This library is distributed in the hope that it will be useful,
slouken@2735
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@2735
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@2735
    13
    Lesser General Public License for more details.
slouken@2735
    14
slouken@2735
    15
    You should have received a copy of the GNU Lesser General Public
slouken@2735
    16
    License along with this library; if not, write to the Free Software
slouken@2735
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@2735
    18
slouken@2735
    19
    Sam Lantinga
slouken@2735
    20
    slouken@libsdl.org
slouken@2735
    21
*/
slouken@2735
    22
#include "SDL_config.h"
slouken@2735
    23
slouken@2735
    24
/* SDL Nintendo DS video driver implementation
slouken@2735
    25
 * based on dummy driver:
slouken@2735
    26
 *  Initial work by Ryan C. Gordon (icculus@icculus.org). A good portion
slouken@2735
    27
 *  of this was cut-and-pasted from Stephane Peter's work in the AAlib
slouken@2735
    28
 *  SDL video driver.  Renamed to "DUMMY" by Sam Lantinga.
slouken@2735
    29
 */
slouken@2735
    30
slouken@2735
    31
#include <stdio.h>
slouken@2735
    32
#include <stdlib.h>
slouken@2735
    33
#include <nds.h>
slouken@2735
    34
#include <nds/arm9/video.h>
slouken@2735
    35
slouken@2735
    36
#include "SDL_video.h"
slouken@2735
    37
#include "SDL_mouse.h"
slouken@2735
    38
#include "../SDL_sysvideo.h"
slouken@2735
    39
#include "../SDL_pixels_c.h"
slouken@2735
    40
#include "../../events/SDL_events_c.h"
slouken@2735
    41
slouken@2735
    42
#include "SDL_ndsvideo.h"
slouken@2735
    43
#include "SDL_ndsevents_c.h"
slouken@2735
    44
#include "SDL_ndsrender_c.h"
slouken@2735
    45
slouken@2735
    46
#define NDSVID_DRIVER_NAME "nds"
slouken@2735
    47
slouken@2735
    48
/* Initialization/Query functions */
slouken@2735
    49
static int NDS_VideoInit(_THIS);
slouken@2735
    50
static int NDS_SetDisplayMode(_THIS, SDL_DisplayMode * mode);
slouken@2735
    51
static void NDS_VideoQuit(_THIS);
slouken@2735
    52
slouken@2735
    53
slouken@2735
    54
/* SDL NDS driver bootstrap functions */
slouken@2735
    55
static int
slouken@2735
    56
NDS_Available(void)
slouken@2735
    57
{
slouken@2735
    58
    return (1);                 /* always here */
slouken@2735
    59
}
slouken@2735
    60
slouken@2735
    61
static void
slouken@2735
    62
NDS_DeleteDevice(SDL_VideoDevice * device)
slouken@2735
    63
{
slouken@2735
    64
    SDL_free(device);
slouken@2735
    65
}
slouken@2735
    66
slouken@2735
    67
static SDL_VideoDevice *
slouken@2735
    68
NDS_CreateDevice(int devindex)
slouken@2735
    69
{
slouken@2735
    70
    SDL_VideoDevice *device;
slouken@2735
    71
slouken@2735
    72
    /* Initialize all variables that we clean on shutdown */
slouken@2735
    73
    device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
slouken@2735
    74
    if (!device) {
slouken@2735
    75
        SDL_OutOfMemory();
slouken@2735
    76
        if (device) {
slouken@2735
    77
            SDL_free(device);
slouken@2735
    78
        }
slouken@2735
    79
        return (0);
slouken@2735
    80
    }
slouken@2735
    81
slouken@2735
    82
    /* Set the function pointers */
slouken@2735
    83
    device->VideoInit = NDS_VideoInit;
slouken@2735
    84
    device->VideoQuit = NDS_VideoQuit;
slouken@2735
    85
    device->SetDisplayMode = NDS_SetDisplayMode;
slouken@2735
    86
    device->PumpEvents = NDS_PumpEvents;
slouken@2735
    87
slouken@2735
    88
    device->num_displays = 2;   /* DS = dual screens */
slouken@2735
    89
slouken@2735
    90
    device->free = NDS_DeleteDevice;
slouken@2735
    91
slouken@2735
    92
    return device;
slouken@2735
    93
}
slouken@2735
    94
slouken@2735
    95
VideoBootStrap NDS_bootstrap = {
slouken@2735
    96
    NDSVID_DRIVER_NAME, "SDL NDS video driver",
slouken@2735
    97
    NDS_Available, NDS_CreateDevice
slouken@2735
    98
};
slouken@2735
    99
slouken@2735
   100
int
slouken@2735
   101
NDS_VideoInit(_THIS)
slouken@2735
   102
{
slouken@2735
   103
    SDL_DisplayMode mode;
slouken@2735
   104
    int i;
slouken@2735
   105
slouken@2735
   106
    /* simple 256x192x16x60 for now */
slouken@2735
   107
    mode.w = 256;
slouken@2735
   108
    mode.h = 192;
slouken@2735
   109
    mode.format = SDL_PIXELFORMAT_ABGR1555;
slouken@2735
   110
    mode.refresh_rate = 60;
slouken@2735
   111
    mode.driverdata = NULL;
slouken@2735
   112
slouken@3520
   113
    if (SDL_AddBasicVideoDisplay(&mode) < 0) {
slouken@3520
   114
        return -1;
slouken@3520
   115
    }
slouken@3520
   116
    SDL_AddRenderDriver(&_this->displays[0], &NDS_RenderDriver);
slouken@2735
   117
slouken@2735
   118
    SDL_zero(mode);
slouken@2735
   119
    SDL_AddDisplayMode(0, &mode);
slouken@2735
   120
slouken@2735
   121
    powerON(POWER_ALL_2D);
slouken@2735
   122
    irqInit();
slouken@2735
   123
    irqEnable(IRQ_VBLANK);
slouken@2735
   124
    NDS_SetDisplayMode(_this, &mode);
slouken@2735
   125
slouken@2735
   126
    return 0;
slouken@2735
   127
}
slouken@2735
   128
slouken@2735
   129
static int
slouken@2735
   130
NDS_SetDisplayMode(_THIS, SDL_DisplayMode * mode)
slouken@2735
   131
{
slouken@2735
   132
    /* right now this function is just hard-coded for 256x192 ABGR1555 */
slouken@2735
   133
    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.) */
slouken@2735
   134
                 DISPLAY_SPR_ACTIVE | DISPLAY_SPR_EXT_PALETTE); /* display on main core
slouken@2735
   135
                                                                   with lots of flags set for
slouken@2735
   136
                                                                   flexibility/capacity to render */
slouken@2735
   137
slouken@2735
   138
    /* hopefully these cover all the various things we might need to do */
slouken@2735
   139
    vramSetBankA(VRAM_A_MAIN_BG_0x06000000);
slouken@2735
   140
    vramSetBankB(VRAM_B_MAIN_BG_0x06020000);
slouken@2735
   141
    vramSetBankC(VRAM_C_SUB_BG_0x06200000);
slouken@2735
   142
    vramSetBankD(VRAM_D_MAIN_BG_0x06040000);    /* not a typo. vram d can't sub */
slouken@2735
   143
    vramSetBankE(VRAM_E_MAIN_SPRITE);
slouken@2735
   144
    vramSetBankF(VRAM_F_OBJ_EXT_PALETTE);
slouken@2735
   145
    vramSetBankG(VRAM_G_BG_EXT_PALETTE);
slouken@2735
   146
    vramSetBankH(VRAM_H_SUB_BG_EXT_PALETTE);
slouken@2735
   147
    vramSetBankI(VRAM_I_SUB_SPRITE);
slouken@2735
   148
slouken@2735
   149
    videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE);    /* debug text on sub
slouken@2735
   150
                                                           TODO: this will change
slouken@2735
   151
                                                           when multi-head is
slouken@2735
   152
                                                           introduced in render */
slouken@2735
   153
slouken@2735
   154
    return 0;
slouken@2735
   155
}
slouken@2735
   156
slouken@2735
   157
void
slouken@2735
   158
NDS_VideoQuit(_THIS)
slouken@2735
   159
{
slouken@2735
   160
    videoSetMode(DISPLAY_SCREEN_OFF);
slouken@2735
   161
    videoSetModeSub(DISPLAY_SCREEN_OFF);
slouken@2735
   162
    vramSetMainBanks(VRAM_A_LCD, VRAM_B_LCD, VRAM_C_LCD, VRAM_D_LCD);
slouken@2735
   163
    vramSetBankE(VRAM_E_LCD);
slouken@2735
   164
    vramSetBankF(VRAM_F_LCD);
slouken@2735
   165
    vramSetBankG(VRAM_G_LCD);
slouken@2735
   166
    vramSetBankH(VRAM_H_LCD);
slouken@2735
   167
    vramSetBankI(VRAM_I_LCD);
slouken@2735
   168
}
slouken@2735
   169
slouken@2735
   170
/* vi: set ts=4 sw=4 expandtab: */