#58083 - Lazy1 - Thu Oct 20, 2005 6:22 pm
I'm having problems with mode 4, I have read that you need to write two pixels at a time but I couldn't find an example where an image is read into the framebuffer this way.
I'm going through the GBA tutorials on www.drunkencoders.com and I'm on day 2 where it deals with mode 4 and pcx images.
Rather than copy the tutorial files I prefer to go along and write my own code so I decided to replace the pcx images with a half-life sprite.
( Don't worry about incompatible licenses, I sat down with a hex editor and figured out the file format myself ).
So I'm at the point where I have loaded the sprite's palette into BGPaletteMem ( I have verified this to be correct using visualboy advance's palette viewer ) and have to write the actual image data into the framebuffer.
All my attempts so far haven't worked, though I did see something it was usually the image spaced out by black pixels.
There is also another wierd problem which I'm not sure if it was the way I was displaying the image but the top half of the image is cut off and displayed at the bottom aswell as some garbage at the very right.
Could someone provide an example of taking two pixels from an image and placing them on the screen in mode 4?
Thanks in advance.
[Added]
I found a few really dumb mistakes and now I can actually see the sprite!
There is still a problem though as you can see here http://img422.imageshack.us/img422/6417/day2mb8vf.png
Here is my ( so far ) hacked up code for day 2.
I'm going through the GBA tutorials on www.drunkencoders.com and I'm on day 2 where it deals with mode 4 and pcx images.
Rather than copy the tutorial files I prefer to go along and write my own code so I decided to replace the pcx images with a half-life sprite.
( Don't worry about incompatible licenses, I sat down with a hex editor and figured out the file format myself ).
So I'm at the point where I have loaded the sprite's palette into BGPaletteMem ( I have verified this to be correct using visualboy advance's palette viewer ) and have to write the actual image data into the framebuffer.
All my attempts so far haven't worked, though I did see something it was usually the image spaced out by black pixels.
There is also another wierd problem which I'm not sure if it was the way I was displaying the image but the top half of the image is cut off and displayed at the bottom aswell as some garbage at the very right.
Could someone provide an example of taking two pixels from an image and placing them on the screen in mode 4?
Thanks in advance.
[Added]
I found a few really dumb mistakes and now I can actually see the sprite!
There is still a problem though as you can see here http://img422.imageshack.us/img422/6417/day2mb8vf.png
Here is my ( so far ) hacked up code for day 2.
Code: |
#include "gba.h" #include "hl_sprite.h" #define MODE3_POS( x, y ) ( x + ( y * 240 ) ) #define MODE4_POS( x, y ) ( x + ( y * 120 ) ) #define MODE5_POS( x, y ) ( x + ( y * 160 ) ) int __gba_multiboot = 0; extern u8 _binary_blueflare1_spr_start[ ]; //extern u8 _binary_bluejet1_spr_start[ ]; void FatalError( void ) { unsigned int iX = 0; unsigned int iY = 0; SetMode( MODE_3 | BG2_ENABLE ); for ( iX = 0; iX < 240; iX++ ) { for ( iY = 0; iY < 160; iY++ ) { VideoBuffer[ MODE3_POS( iX, iY ) ] = RGB16( 31, 0, 0 ); } } while ( 1 ) { } } // Loads a Half-Life sprite into the frontbuffer int LoadHLSprite( u8* pSpritememory, int iFrame ) { hl_sprheader_t* pSprite = ( hl_sprheader_t* ) pSpritememory; hl_sprframe_t* pFrame = NULL; u8* pDataptr = pSpritememory; u32 iX = 0; u32 iY = 0; u32 i = 0; u16 p = 0; // Make sure this is has a valid sprite header ( ASCII "IDSP" ) and the version is 2 ( half-life format ) // If not, return failure now. if ( *( ( int* ) pSprite->sprIdentify ) != HL_SPR_IDENTITY || pSprite->iVersion != 2 ) return 0; // Move past the header pDataptr+= sizeof( hl_sprheader_t ); // Copy in the sprite's palette for ( i = 0; i < 256; i++, pDataptr+= 3 ) BGPaletteMem[ i ] = RGB16( pDataptr[ 0 ] >> 3, pDataptr[ 1 ] >> 3, pDataptr[ 2 ] >> 3 ); // Get a pointer to the first sprite frame after the palette and // point our data pointer past it pFrame = ( hl_sprheader_t* ) pDataptr; pDataptr+= sizeof( hl_sprheader_t ); // BROKEN // Display sprite for ( iX = 0; iX < pFrame->iWidth >> 1; iX++ ) { for ( iY = 0; iY < pFrame->iHeight; iY++ ) { p = ( ( *pDataptr++ ) << 8 ) + *pDataptr++; FrontBuffer[ MODE4_POS( iX, iY ) ] = p; } } return 1; } // Mode 4 16 bit // // 11111111 2222222 // Leftmost Rightmost int main( void ) { SetMode( MODE_4 | BG2_ENABLE ); if ( ! LoadHLSprite( _binary_blueflare1_spr_start, 0 ) ) FatalError( ); while ( 1 ) { } return 0; } |