Page 1 of 2
Help with a small program?
Posted: Mon Sep 27, 2010 9:52 am
by Searinox
Hello,
I am trying to put together some libraries and code from the acekard/woodrpg source to make a simple app that does nothing except slap on a border image and boot into GBA mode. I have overcome numerous obstacles yet am still not through.
As it stands I have a function cBMP15, which stores the bitmap that will be posted on screen. In that include file, there are two other functions in the cBMP15 function declaration. rgb2hsl and hsl2rgb which by name I would say swap hue saturation luminancy with red green blue... thing is I get this error "undefined reference to `hsl2rgb(int, int, int, int&, int&, int&)'" and another error for its counterpart rgb2hsl, the same way. The functions are declared in hls.h as follows:
#ifndef __HLS_H__
#define __HLS_H__
void rgb2hsl(s32 r,s32 g,s32 b,s32& h,s32& s,s32& l);
void hsl2rgb(s32 h,s32 s,s32 l,s32& r,s32& g,s32& b);
#endif
Please tell me if that is not enough and I need to include additional files. Also please tell me if and how I may upload the full source -- I have never issued reports like these before.
Thank you.
Re: Help with a small program?
Posted: Mon Sep 27, 2010 10:36 am
by zeromus
you neglected to copy the code for rgb2hsl() hsl2rgb() into a .c or .cpp file, only putting the declarations in the header.
Re: Help with a small program?
Posted: Mon Sep 27, 2010 2:12 pm
by Searinox
Thank you! I've fixed it and it compiles now. There is a new problem though... I get two black screens. Note blackscreens - NOT DS shutting off. The GBA mode doesn't boot, the frame isn't even put up. Can anyone tell anything by looking at this? I took it out just as it was in the woodrpg source.
Code: Select all
#include <nds.h>
#include <stdio.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <malloc.h>
#include <string.h>
#include "bmp15.h"
#include "fifotool.h"
#include <fat.h>
int main(void)
{
/*Mount Filesystem*/
fatInitDefault();
/*Init Video and Apply Frame*/
videoSetMode(MODE_5_2D | DISPLAY_BG3_ACTIVE);
videoSetModeSub(MODE_5_2D | DISPLAY_BG3_ACTIVE);
vramSetMainBanks(VRAM_A_MAIN_BG_0x06000000, VRAM_B_MAIN_BG_0x06020000, VRAM_C_SUB_BG_0x06200000, VRAM_D_LCD);
// for the main screen
REG_BG3CNT = BG_BMP16_256x256 | BG_BMP_BASE(0) | BG_WRAP_OFF;
REG_BG3PA = 1 << 8; //scale x
REG_BG3PB = 0; //rotation x
REG_BG3PC = 0; //rotation y
REG_BG3PD = 1 << 8; //scale y
REG_BG3X = 0; //translation x
REG_BG3Y = 0; //translation y
memset((void*)BG_BMP_RAM(0),0,0x18000);
memset((void*)BG_BMP_RAM(8),0,0x18000);
cBMP15 frameBMP=createBMP15FromFile("gbaframe.bmp");
if(frameBMP.valid()&&frameBMP.width()==SCREEN_WIDTH&&frameBMP.height()==SCREEN_HEIGHT)
{
DC_FlushRange(frameBMP.buffer(),SCREEN_WIDTH*SCREEN_HEIGHT*2);
dmaCopy(frameBMP.buffer(),(void*)BG_BMP_RAM(0),SCREEN_WIDTH*SCREEN_HEIGHT*2);
dmaCopy(frameBMP.buffer(),(void*)BG_BMP_RAM(8),SCREEN_WIDTH*SCREEN_HEIGHT*2);
}
/*Boot GBA*/
sysSetBusOwners(BUS_OWNER_ARM7,BUS_OWNER_ARM7);
if(PersonalData->gbaScreen)
REG_POWERCNT=1;
else
REG_POWERCNT=(POWER_SWAP_LCDS|1)&0xffff;
fifoSendValue32(FIFO_USER_01,MENU_MSG_GBA);
while(true) swiWaitForVBlank();
return 0;
}
Re: Help with a small program?
Posted: Mon Sep 27, 2010 6:35 pm
by zeromus
Did you ripoff the arm7 portion of the code as well?
Re: Help with a small program?
Posted: Mon Sep 27, 2010 7:08 pm
by Searinox
Okay THANK YOU! Now with the arm7 ripped the program DOES BOOT GBA MODE! However, it's still not applying the frame. Your advice has pretty much oneshot my issues with each response, could you please help with this aswell? This is the last bit I need to get working and I'm done!
I think I know what's wrong here. The filesystem isn't mounted or initialized, but no idea how to go about it.
Re: Help with a small program?
Posted: Mon Sep 27, 2010 10:09 pm
by WinterMute
add #include <fat.h>, a call to fatInitDefault() and make sure you have -lfat in the LIBS line in your arm9 Makefile *before* -lnds9
protip: don't do this -> cBMP15 frameBMP=createBMP15FromFile("fat0:/gbaframe.bmp");
createBMP15FromFile("gbaframe.bmp"); should load the bmp from the same directory as the nds file, assuming your card launcher sets up argv. If it doesn't work then complain to the manufacturer of your flashcard, point them to
http://devkitpro.org/wiki/Homebrew_Menu and use hbmenu until they fix their launcher. This will also allow you to migrate to a different filesystem without a lot of grief later.
We should probably add a boot in GBA mode function to libnds, seems like such a waste needing a custom arm7 just for that.
Re: Help with a small program?
Posted: Mon Sep 27, 2010 11:44 pm
by Searinox
Okay GREAT NEWS! That did indeed work! Now the frame is being applied! However, it looks garbled... Any idea as to why?
I first tried lower colordepth on the bmp but it didn't work. Then I had someone provide me with alternate coding to read and display the bmp. But it is giving me the exact same frame corruption. The garbled frame doesn't vary, it's the same all the time. Where should I be looking for an issue? I tried some graphics mode cleaning code but it doesn't help. And I can assure that the clean code works because if I call it after the BMP loading it resets to a black frame.
So it's not BMP displaying, it's not a dirty buffer, it's either the reading of the BMP from the file or writing it to the memory banks yes? Any idea how I can test each case out?
Re: Help with a small program?
Posted: Tue Sep 28, 2010 3:57 pm
by zeromus
It appears as if that bitmap loading code actually loads a 15 or 16bpp bmp file. Im not sure how you even created a 15/16bpp bmp file. Are you sure thats what youve got? Until I read the source, I wouldve assumed that the code loads a 24bpp bitmap into an ds-format 15bpp buffer. Try replacing the image youre using with one that woodrpg wouldve loaded with this function to verify this.
Re: Help with a small program?
Posted: Tue Sep 28, 2010 4:23 pm
by Searinox
As I stated in my first post, the FIRST thing I checked was if the BMP was a different bitrate. Because Supercard firmware has the same issue with >16bit BMPs and graphical garbling follows the same pattern, I immediately assumed it to be a bitrate problem. And I checked, and it didn't seem like it.
Yet...
I was wrong.
The bitmap pic from WoodRPG loads and displays absolutely FINE! I must have made some mistake at some point when converting the frame to 16bit because WRPG's frame displays correctly! Not only does this mean there was never a problem with the code, but also an obvious troubleshooting step I should have tried. Wether it is indeed 16bit or some other rate I will find out in time. But for now, the problem appears to be fixed!
I still fancy GBA ExpLoader's ability to load 24bit BMPs though.
Re: Help with a small program?
Posted: Tue Sep 28, 2010 5:40 pm
by zeromus
loading a 24bpp bmp should be a pretty trivial task for someone who seems to be operating at around your level of awareness..