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.

DS development > GBFS Error

#48424 - jandujar - Tue Jul 19, 2005 10:46 pm

Hello,
I have a problem, i'm trying to incorporate a DAT file to my rom.

My makefile is this:
Code:

# Makefile for gbfs_demo1.nds
# chris.double@double.co.nz
NDSLIB_INCLUDE=c:/ndsdev/libnds/include
NDSLIB_LIB=c:/ndsdev/libnds/lib

all: gbfs_demo1.nds.gba



libgbfs.o: libgbfs.c gbfs.h
   arm-elf-g++ -g -Wall -O2 -mcpu=arm7tdmi -mtune=arm7tdmi -fomit-frame-pointer -ffast-math -mthumb-interwork -I$(NDSLIB_INCLUDE) -DARM7 -c libgbfs.c -olibgbfs.o

arm7_main.o: arm7_main.cpp
   arm-elf-g++ -g -Wall -O2 -mcpu=arm7tdmi -mtune=arm7tdmi -fomit-frame-pointer -ffast-math -mthumb-interwork -I$(NDSLIB_INCLUDE) -DARM7 -c arm7_main.cpp -oarm7_main.o

arm7.elf: arm7_main.o
   arm-elf-g++ -g -mthumb-interwork -mno-fpu -specs=ds_arm7.specs arm7_main.o -L$(NDSLIB_LIB) -lnds7 -oarm7.elf

arm7.bin: arm7.elf
   arm-elf-objcopy -O binary arm7.elf arm7.bin

arm9_main.o: arm9_main.cpp
   arm-elf-g++ -g -Wall -O2 -mcpu=arm9tdmi -mtune=arm9tdmi -fomit-frame-pointer -ffast-math -mthumb-interwork -I$(NDSLIB_INCLUDE) -DARM9 -c arm9_main.cpp -oarm9_main.o

arm9.elf: arm9_main.o libgbfs.o
   arm-elf-g++ -g -mthumb-interwork -mno-fpu -specs=ds_arm9.specs arm9_main.o libgbfs.o  -L$(NDSLIB_LIB) -lnds9 -o arm9.elf

arm9.bin: arm9.elf
   arm-elf-objcopy -O binary arm9.elf arm9.bin

puzzles.gbfs: puzzles.dat
   gbfs puzzles.gbfs puzzles.dat

gbfs_demo1.nds: arm7.bin arm9.bin puzzles.gbfs
   ndstool -c gbfs_demo1.nds -9 arm9.bin -7 arm7.bin
   cat gbfs_demo1.nds puzzles.gbfs >gbfs_demo1_tmp.nds
   mv gbfs_demo1_tmp.nds gbfs_demo1.nds

gbfs_demo1.nds.gba: gbfs_demo1.nds
   dsbuild gbfs_demo1.nds -o gbfs_demo1.nds.gba

clean:
   rm -f *.bin
   rm -f *.elf
   rm -f *.o
   rm -f *~
   rm -f *.raw
   rm -f *.gbfs


And my source file is:

Code:


#include <nds.h>
#include "nds/arm9/console.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "gbfs.h"


struct Fichero{
  char const* filename;
  uint8* data;
  uint32 length;   
};

/*
 * Aqu? tengo el fichero con los puzzles
 *
 */
static Fichero ficheros[]={
   {"puzzles.dat",0,0},
   {0,0,0}
};


static Fichero* current_file = 0;


static void CargarDat(){
  // Map Game Cartridge memory to ARM9
  WAIT_CR &= ~0x80;
 
  /* Start searching from the beginning of cartridge memory */
  GBFS_FILE const* gbfs_file =
    find_first_gbfs_file((void*)0x08000000);

  unsigned int max_length = 0;
  Fichero* file = ficheros;
  while(file->filename) {
    file->data = (uint8*)gbfs_get_obj(gbfs_file,
                  file->filename,
                  &file->length);
    if(file->length > max_length)
      max_length = file->length;
    file++;
  }
  current_file=ficheros;
 
}
static int key_prev = 0;
static int key_curr = 0;
int numpuzzles;
static uint8* buffer = 0;

#define key_poll() { key_prev=key_curr; key_curr = KEYS; }
#define key_transit(key) ((key_curr^key_prev) & key)
#define key_held(key) (~(key_curr|key_prev) & key)
#define key_hit(key) ((~key_curr&key_prev) & key)
#define key_released(key) ((key_curr&~key_prev) & key)

void on_irq_vblank()
{   
 
  // Disable interrupts
  IME = 0;

  consoleClear();
  consolePrintf("GBFS Demo Program\n\n");

  consolePrintf("Press 'A' to play current file.\n");
  consolePrintf("'left/right' changes file.\n");
  consolePrintf("'up/down' changes channel.\n\n");

  consolePrintf("File:    %s (%d)\n",
      current_file->filename,
      current_file->length);
  consolePrintf("Channel: %d\n", 0); 
  //sscanf((const char*)current_file->data,"%d\n",&numpuzzles);
  consolePrintf("Numpuzzles: %d\n",numpuzzles);
 
  // Tell the DS we handled the VBLANK interrupt
  IF = IF;
  VBLANK_INTR_WAIT_FLAGS = IF | IE;

  // Enable interrupts
  IME = 1;
}

int main(void)
{
  powerON(POWER_ALL); 
  videoSetMode(MODE_0_2D | DISPLAY_BG0_ACTIVE);
  vramSetBankA(VRAM_A_MAIN_BG);
  BG0_CR = BG_MAP_BASE(31);
  BG_PALETTE[255] = RGB15(31,31,31);
  lcdSwap();
  irqInitHandler(irqDefaultHandler);
  irqSet(IRQ_VBLANK, on_irq_vblank);
  irqEnable(IRQ_VBLANK);
  consoleInitDefault((u16*)SCREEN_BASE_BLOCK(31), (u16*)CHAR_BASE_BLOCK(0), 16);


  CargarDat();
 
  while(1) {
    swiWaitForVBlank();
    key_poll();

    if(key_hit(KEY_UP)) {
     
    }
    if(key_hit(KEY_DOWN)) {
     
    }
    if(key_hit(KEY_LEFT)) {
      if(--current_file < ficheros)
   current_file = ficheros;
    }
    if(key_hit(KEY_RIGHT)) {
      if((++current_file)->filename == 0)
   --current_file;
    }
    if(key_hit(KEY_A)) {
      dmaCopy(current_file->data, buffer, current_file->length);
      sscanf((const char*)buffer,"%d\n",&numpuzzles);
   
    }
  }

  return 0;
}


my file puzzles.dat have this:
Code:

1
1 1 101010101010101010101010101010101010


But numpuzzles alwais sais "0"
_________________
http://jandujar.homelinux.com
http://www.dsrobot.com

#48435 - tepples - Tue Jul 19, 2005 11:22 pm

On newer versions of devkitARM, the ".bss" section (unitialized global variables) will overwrite any appended data file. Until a workaround is found, try the bin2s method instead of the find_first_gbfs_file method.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#48441 - doublec - Wed Jul 20, 2005 12:14 am

In this case though the gbfs file is appended to the nds file. The nds file lives in cartridge space ROM so can't be overwritten. I think the bss change will only affect those instances where the gbfs file is appended to the arm9 binary.

At a guess, you will need to padbin the nds file. I'll be changing the tutorial to mention this step. So change the following make line:

Code:
gbfs_demo1.nds: arm7.bin arm9.bin puzzles.gbfs
   ndstool -c gbfs_demo1.nds -9 arm9.bin -7 arm7.bin
   padbin 256 gbfs_demo1.nds
   cat gbfs_demo1.nds puzzles.gbfs >gbfs_demo1_tmp.nds
   mv gbfs_demo1_tmp.nds gbfs_demo1.nds


Note that addition of the padbin line.

#48463 - jandujar - Wed Jul 20, 2005 6:49 am

?what is the meaning of "bss" ?

I will try to padding the nds file, i don't know how to use bin2s
_________________
http://jandujar.homelinux.com
http://www.dsrobot.com

#48494 - Lord Graga - Wed Jul 20, 2005 12:53 pm

That Makefile could be a lot more dynamic.

#48507 - tepples - Wed Jul 20, 2005 1:59 pm

True, they could be more dynamic, but I see it as a "not yet" situation. A lot of people start with very simple shell scripts (*.bat), then write makefiles that are are essentially batch files with dependency information, then make them dynamic, making sure that they work after each stage. I know I've gone through these stages in some of my projects.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#48519 - GPFerror - Wed Jul 20, 2005 3:45 pm

doublec wrote:
In this case though the gbfs file is appended to the nds file. The nds file lives in cartridge space ROM so can't be overwritten. I think the bss change will only affect those instances where the gbfs file is appended to the arm9 binary.

At a guess, you will need to padbin the nds file. I'll be changing the tutorial to mention this step. So change the following make line:

Code:
gbfs_demo1.nds: arm7.bin arm9.bin puzzles.gbfs
   ndstool -c gbfs_demo1.nds -9 arm9.bin -7 arm7.bin
   padbin 256 gbfs_demo1.nds
   cat gbfs_demo1.nds puzzles.gbfs >gbfs_demo1_tmp.nds
   mv gbfs_demo1_tmp.nds gbfs_demo1.nds




Thanks
Note that addition of the padbin line.


will this work with any of the current emulators?

I can't seem to get it to work.


Last edited by GPFerror on Wed Jul 20, 2005 8:06 pm; edited 1 time in total

#48552 - tepples - Wed Jul 20, 2005 7:25 pm

If you are concatenating the loader and the .nds files, then the loader has to be a multiple of 256 bytes as well.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#48577 - jandujar - Wed Jul 20, 2005 8:59 pm

thanks a lot.
It seems that padbin makes good things, but i have still having problems.

When I uncomment this line:

sscanf((const char*)current_file->data,"%d\n",&numpuzzles); (read the number 1 from puzzles.dat)

makes print screen bad things.

How can I read data from puzzles.dat?
I know that current_file->data is uint8*
_________________
http://jandujar.homelinux.com
http://www.dsrobot.com