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.
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2010 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     if (SDL_AddBasicVideoDisplay(&mode) < 0) {
   114         return -1;
   115     }
   116     SDL_AddRenderDriver(&_this->displays[0], &NDS_RenderDriver);
   117 
   118     SDL_zero(mode);
   119     SDL_AddDisplayMode(0, &mode);
   120 
   121     powerON(POWER_ALL_2D);
   122     irqInit();
   123     irqEnable(IRQ_VBLANK);
   124     NDS_SetDisplayMode(_this, &mode);
   125 
   126     return 0;
   127 }
   128 
   129 static int
   130 NDS_SetDisplayMode(_THIS, SDL_DisplayMode * mode)
   131 {
   132     /* right now this function is just hard-coded for 256x192 ABGR1555 */
   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.) */
   134                  DISPLAY_SPR_ACTIVE | DISPLAY_SPR_EXT_PALETTE); /* display on main core
   135                                                                    with lots of flags set for
   136                                                                    flexibility/capacity to render */
   137 
   138     /* hopefully these cover all the various things we might need to do */
   139     vramSetBankA(VRAM_A_MAIN_BG_0x06000000);
   140     vramSetBankB(VRAM_B_MAIN_BG_0x06020000);
   141     vramSetBankC(VRAM_C_SUB_BG_0x06200000);
   142     vramSetBankD(VRAM_D_MAIN_BG_0x06040000);    /* not a typo. vram d can't sub */
   143     vramSetBankE(VRAM_E_MAIN_SPRITE);
   144     vramSetBankF(VRAM_F_OBJ_EXT_PALETTE);
   145     vramSetBankG(VRAM_G_BG_EXT_PALETTE);
   146     vramSetBankH(VRAM_H_SUB_BG_EXT_PALETTE);
   147     vramSetBankI(VRAM_I_SUB_SPRITE);
   148 
   149     videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE);    /* debug text on sub
   150                                                            TODO: this will change
   151                                                            when multi-head is
   152                                                            introduced in render */
   153 
   154     return 0;
   155 }
   156 
   157 void
   158 NDS_VideoQuit(_THIS)
   159 {
   160     videoSetMode(DISPLAY_SCREEN_OFF);
   161     videoSetModeSub(DISPLAY_SCREEN_OFF);
   162     vramSetMainBanks(VRAM_A_LCD, VRAM_B_LCD, VRAM_C_LCD, VRAM_D_LCD);
   163     vramSetBankE(VRAM_E_LCD);
   164     vramSetBankF(VRAM_F_LCD);
   165     vramSetBankG(VRAM_G_LCD);
   166     vramSetBankH(VRAM_H_LCD);
   167     vramSetBankI(VRAM_I_LCD);
   168 }
   169 
   170 /* vi: set ts=4 sw=4 expandtab: */