gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > Display image in mode3 or mode5

#4347 - delbogun - Fri Mar 28, 2003 7:14 pm

I have problem displaying an image in mode 3 or 5. I used Kaleid to convert my bmp into a mode3 gba image. Don't know if I understand this mode correctly... but this is how I did it:

Code:

typedef unsigned short u16;
typedef unsigned long u32;

#define REG_DISPCNT  *(u32*) 0x4000000
#define MODE_3       0x3
#define BG2_ENABLE   0x400

#include "picture.h"

u16* videoBuffer = (u16*) 0x6000000;

int main( void )
{
    int x, y;

    // set mode 3
    REG_DISPCNT = MODE_3 | BG2_ENABLE;

    // draw picture
    for( y = 0; y < 160; y++ )
    {
        for( x = 0; x < 240; x++ )
            videoBuffer[y*240 + x] = picData[y*240 + x];
    }

    while( 1 )
    {

    }

    return 0;
}


Anyone knows what i did wrong?

#4354 - Lord Graga - Fri Mar 28, 2003 9:28 pm

Code:
 typedef unsigned short u16;
typedef unsigned long u32;

#define REG_DISPCNT  *(u32*) 0x4000000
#define MODE_3       0x3
#define BG2_ENABLE   0x400

#include "picture.h"

u16* videoBuffer = (u16*) 0x6000000;

int main( void )
{
    int i;

    // set mode 3
    REG_DISPCNT = MODE_3 | BG2_ENABLE;

    // draw picture
   for( i = 0; i < 240*160; i++ )
       videoBuffer[i] = picData[i];

    while( 1 ) ;
    return 0;
}

#4356 - Dev - Fri Mar 28, 2003 9:44 pm

Unless I missed something here, the code Graga posted should have the same functionality -- although I might be assuming that your picData is stored as a u16 array 240x160.

How does Kaleid define picData? -- and what is the default type of picData in your compiler, if none is specified?

Also, is picData aligned on a u16 boundary?

#4358 - Vortex - Fri Mar 28, 2003 10:08 pm

It could be done even faster using DMA:

Code:

typedef unsigned short u16;
typedef unsigned long u32;

#define REG_DISPCNT  *(u32*) 0x4000000
#define MODE_3       0x3
#define BG2_ENABLE   0x400

#include "picture.h"

u16* videoBuffer = (u16*) 0x6000000;

int main( void )
{
    int x, y;

    // set mode 3
    REG_DISPCNT = MODE_3 | BG2_ENABLE;

    // draw picture
   (REG_DMA3SAD)     = (u32) picData;
   (REG_DMA3DAD)     = videoBuffer;
   (REG_DMA3CNT_L)  = (160 * 240 / 2);
   (REG_DMA3CNT_H)  = 0x9400;

    while( 1 )
    {

    }

    return 0;
}

#4369 - delbogun - Sat Mar 29, 2003 12:25 am

Dev wrote:
although I might be assuming that your picData is stored as a u16 array 240x160.


Yes, that's correct. the image is 240x160 and 32bit before I converted it with Kaleid. And the picData is u16. This is what is said in the picture.h:
unsigned short int picData[38400] = { 0x0000, ... }

Dev wrote:
How does Kaleid define picData? -- and what is the default type of picData in your compiler, if none is specified?


I have no idea. I just started programming. I'm using default settings when I use Dev-Kit Advance by Jason Wilkins.

Dev wrote:
Also, is picData aligned on a u16 boundary?


Sorry, don't know what you mean with u16 boundary.

Vortex wrote:
It could be done even faster using DMA:


How do I define DMA?

#4458 - Vortex - Mon Mar 31, 2003 4:34 pm

Quote:
How do I define DMA?


As defined in gba.h:

Code:

#define REG_DMA3SAD     *(vu32*)0x40000D4   //DMA3 Source Address
#define REG_DMA3SAD_L   *(vu16*)0x40000D4   //DMA3 Source Address Low Value
#define REG_DMA3SAD_H   *(vu16*)0x40000D6   //DMA3 Source Address High Value
#define REG_DMA3DAD     *(vu32*)0x40000D8   //DMA3 Destination Address
#define REG_DMA3DAD_L   *(vu16*)0x40000D8   //DMA3 Destination Address Low Value
#define REG_DMA3DAD_H   *(vu16*)0x40000DA   //DMA3 Destination Address High Value
#define REG_DMA3CNT     *(vu32*)0x40000DC   //DMA3 Control (Amount)
#define REG_DMA3CNT_L   *(vu16*)0x40000DC   //DMA3 Control Low Value
#define REG_DMA3CNT_H   *(vu16*)0x40000DE   //DMA3 Control High Value