diff src/video/nds/SDL_ndsvideo.c @ 2688:71c56e900f8b gsoc2008_nds

Cleaning up the renderer code to hopefully squish any problems. Starting to incorporate sprites, as well
author Darren Alton <dalton@stevens.edu>
date Fri, 15 Aug 2008 10:17:07 +0000
parents f7594fc66bda
children ca01c20274c0
line wrap: on
line diff
--- a/src/video/nds/SDL_ndsvideo.c	Thu Aug 14 04:33:55 2008 +0000
+++ b/src/video/nds/SDL_ndsvideo.c	Fri Aug 15 10:17:07 2008 +0000
@@ -31,8 +31,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <nds.h>
-#include <nds/arm9/sprite.h>
-#include <nds/arm9/trig_lut.h>
 #include <nds/arm9/video.h>
 
 #include "SDL_video.h"
@@ -52,65 +50,6 @@
 static int NDS_SetDisplayMode(_THIS, SDL_DisplayMode * mode);
 static void NDS_VideoQuit(_THIS);
 
-/* NDS sprite-related functions */
-
-#define SPRITE_DMA_CHANNEL 3
-#define SPRITE_ANGLE_MASK 0x01FF
-
-void
-NDS_OAM_Update(tOAM *oam)
-{
-    DC_FlushAll();
-    dmaCopyHalfWords(SPRITE_DMA_CHANNEL, oam->spriteBuffer, OAM,
-                     SPRITE_COUNT * sizeof(SpriteEntry));
-}
-
-void
-NDS_OAM_RotateSprite(SpriteRotation *spriteRotation, u16 angle)
-{
-    s16 s = SIN[angle & SPRITE_ANGLE_MASK] >> 4;
-    s16 c = COS[angle & SPRITE_ANGLE_MASK] >> 4;
-
-    spriteRotation->hdx = c;
-    spriteRotation->hdy = s;
-    spriteRotation->vdx = -s;
-    spriteRotation->vdy = c;
-}
-
-void
-NDS_OAM_Init(tOAM *oam)
-{
-    int i;
-    for(i = 0; i < SPRITE_COUNT; i++) {
-        oam->spriteBuffer[i].attribute[0] = ATTR0_DISABLED;
-        oam->spriteBuffer[i].attribute[1] = 0;
-        oam->spriteBuffer[i].attribute[2] = 0;
-    }
-    for(i = 0; i < MATRIX_COUNT; i++) {
-        NDS_OAM_RotateSprite(&(oam->matrixBuffer[i]), 0);
-    }
-    swiWaitForVBlank();
-    NDS_OAM_Update(oam);
-}
-
-void
-NDS_OAM_HideSprite(SpriteEntry *spriteEntry)
-{
-    spriteEntry->isRotoscale = 0;
-    spriteEntry->isHidden = 1;
-}
-
-void
-NDS_OAM_ShowSprite(SpriteEntry *spriteEntry, int affine, int double_bound)
-{
-    if (affine) {
-        spriteEntry->isRotoscale = 1;
-        spriteEntry->rsDouble = double_bound;
-    } else {
-        spriteEntry->isHidden = 0;
-    }
-}
-
 
 /* SDL NDS driver bootstrap functions */
 static int
@@ -169,7 +108,7 @@
     SDL_DisplayMode mode;
     int i;
 
-printf("+NDS_VideoInit\n");
+    printf("+NDS_VideoInit\n");
     /* simple 256x192x16x60 for now */
     mode.w = 256;
     mode.h = 192;
@@ -189,40 +128,58 @@
     powerON(POWER_ALL_2D);
    irqInit();
     irqEnable(IRQ_VBLANK);
     NDS_SetDisplayMode(_this, &mode);
-printf("-NDS_VideoInit\n");
+    printf("-NDS_VideoInit\n");
     return 0;
 }
 
 static int
 NDS_SetDisplayMode(_THIS, SDL_DisplayMode * mode)
 {
-printf("+NDS_SetDisplayMode\n");
+    printf("+NDS_SetDisplayMode\n");
     /* right now this function is just hard-coded for 256x192 ABGR1555 */
     videoSetMode(MODE_5_2D |
-        DISPLAY_BG2_ACTIVE | DISPLAY_BG3_ACTIVE |
-        DISPLAY_SPR_1D_LAYOUT | DISPLAY_SPR_ACTIVE); /* display on main core */
-    videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE); /* debug text on sub */
-    vramSetMainBanks(VRAM_A_MAIN_BG_0x06000000, VRAM_B_MAIN_BG_0x06020000,
-                     VRAM_C_SUB_BG_0x06200000,  VRAM_D_MAIN_BG_0x06040000);
+                 DISPLAY_BG2_ACTIVE |
+                 DISPLAY_BG3_ACTIVE |
+                 DISPLAY_BG_EXT_PALETTE |
+                 DISPLAY_SPR_1D_LAYOUT |
+                 DISPLAY_SPR_ACTIVE |
+                 DISPLAY_SPR_EXT_PALETTE); /* display on main core
+                                              with lots of flags set for
+                                              flexibility/capacity to render */
+
+    /* hopefully these cover all the various things we might need to do */
+    vramSetBankA(VRAM_A_MAIN_BG_0x06000000);
+    vramSetBankB(VRAM_B_MAIN_BG_0x06020000);
+    vramSetBankC(VRAM_C_SUB_BG_0x06200000);
+    vramSetBankD(VRAM_D_MAIN_BG_0x06040000); /* not a typo. vram d can't sub */
     vramSetBankE(VRAM_E_MAIN_SPRITE);
-    /* set up console for debug text 'n stuff */
-    SUB_BG0_CR = BG_MAP_BASE(31);
-    BG_PALETTE_SUB[255] = RGB15(31, 31, 31);
-   /* debugging purposes, uncomment this later.  then remove it & add 2screen.
-    consoleInitDefault((u16 *) SCREEN_BASE_BLOCK_SUB(31),
-                       (u16 *) CHAR_BASE_BLOCK_SUB(0), 16);*/
-printf("-NDS_SetDisplayMode\n");
+    vramSetBankF(VRAM_F_OBJ_EXT_PALETTE);
+    vramSetBankG(VRAM_G_BG_EXT_PALETTE);
+    vramSetBankH(VRAM_H_SUB_BG_EXT_PALETTE);
+    vramSetBankI(VRAM_I_SUB_SPRITE);
+
+    videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE); /* debug text on sub
+                                                        TODO: this will change
+                                                        when multi-head is
+                                                        introduced in render */
+
+    printf("-NDS_SetDisplayMode\n");
     return 0;
 }
 
 void
 NDS_VideoQuit(_THIS)
 {
-printf("+NDS_VideoQuit\n");
+    printf("+NDS_VideoQuit\n");
     videoSetMode(DISPLAY_SCREEN_OFF);
     videoSetModeSub(DISPLAY_SCREEN_OFF);
     vramSetMainBanks(VRAM_A_LCD, VRAM_B_LCD, VRAM_C_LCD, VRAM_D_LCD);
-printf("-NDS_VideoQuit\n");
+    vramSetBankE(VRAM_E_LCD);
+    vramSetBankF(VRAM_F_LCD);
+    vramSetBankG(VRAM_G_LCD);
+    vramSetBankH(VRAM_H_LCD);
+    vramSetBankI(VRAM_I_LCD);
+    printf("-NDS_VideoQuit\n");
 }
 
 /* vi: set ts=4 sw=4 expandtab: */