Sprite GFX 0 is already in use. Error code 109

birdekek

Member
OP
Newcomer
Joined
Jul 25, 2023
Messages
19
Trophies
0
Age
19
XP
45
Country
United States
I keep having the Sprite GFX 0 is already in use. Error code 109 problem, ive tried everything and i cant fix it. heres my code


C++:
#include <nds.h>
#include <maxmod9.h>
#include <nf_lib.h>
#include <stdio.h>

volatile int frame = 0;

//---------------------------------------------------------------------------------
void Initialize()
{
    NF_SetRootFolder("NITROFS");
    NF_Set2D(0, 0);
    NF_InitTiledBgBuffers();
    NF_InitTiledBgSys(0);

    // Load the BMP file as a sprite graphics with palette
    NF_LoadSpriteGfx("nitrofiles/ui/birdekek.img", 0, 128, 32);
    NF_LoadSpritePal("nitrofiles/ui/birdekek.img", 0);

    // Apply the palette to the sprite
    NF_VramSpriteGfx(0, 0, 0, false);
    NF_VramSpritePal(0, 0, 0);
}

void Vblank()
{
    frame++;
}

//---------------------------------------------------------------------------------
int main(int argc, char** argv)
{
    irqSet(IRQ_VBLANK, Vblank);

    consoleDemoInit();

    Initialize();

    // Play the sound effect (replace SFX_BIRDEKEK with the actual sound effect ID)
    mmLoadEffect(0); // Example: Assuming SFX_BIRDEKEK is defined as 0
    mmEffect(0);     // Example: Assuming SFX_BIRDEKEK is defined as 0

    consoleClear();
    setBrightness(3, 0);

    // Display the sprite
    NF_CreateSprite(0, 0, 0, 0, 0, 0);

    // Wait for 4 seconds (about 240 frames at 60 FPS) with fading to black
    for (int i = 0; i < 240; i++)
    {
        setBrightness(3 - (i / 60), 0);
        swiWaitForVBlank();
    }

    setBrightness(0, 0);

    // Clear the sprite and load the main screen background
    NF_DeleteSprite(0, 0);
    NF_LoadTiledBg("nitrofiles/maps/mainscreen.img", "main_bg", 256, 192); // Pass the correct width and height

    // Load and play the MOD file (replace MOD_MAINTHEME with the actual MOD file ID)
    mmLoad(0); // Example: Assuming MOD_MAINTHEME is defined as 0
    mmStart(0, MM_PLAY_LOOP); // Example: Assuming MOD_MAINTHEME is defined as 0

    // Infinite loop for displaying the background and playing the MOD file
    while (1)
    {
        swiWaitForVBlank();
    }

    return 0;
}
 

plasturion

temporary hermit
Member
Joined
Aug 17, 2012
Messages
1,216
Trophies
2
Location
Tree
XP
3,505
Country
Poland
It seems there shoudl be initialiazing spritebuffers first.
Code:
    NF_InitSpriteBuffers();
    NF_InitSpriteSys(0);
With this sprite graphic / palette slots are getting available.
 

birdekek

Member
OP
Newcomer
Joined
Jul 25, 2023
Messages
19
Trophies
0
Age
19
XP
45
Country
United States
It seems there shoudl be initialiazing spritebuffers first.
Code:
    NF_InitSpriteBuffers();
    NF_InitSpriteSys(0);
With this sprite graphic / palette slots are getting available.
what do you mean by that, like do you mean it should be at the start of initalize?
 

plasturion

temporary hermit
Member
Joined
Aug 17, 2012
Messages
1,216
Trophies
2
Location
Tree
XP
3,505
Country
Poland
that's stragne, I changed Intialize() function to this one and described error doesn't appear anymore
Code:
void Initialize()
{
    NF_SetRootFolder("NITROFS");
    NF_Set2D(0, 0);
    NF_InitTiledBgBuffers();
    NF_InitTiledBgSys(0);
    
    //Prepare memory slots for sprites
    NF_InitSpriteBuffers();
    NF_InitSpriteSys(0);

    // Load the BMP file as a sprite graphics with palette
    NF_LoadSpriteGfx("nitrofiles/ui/birdekek.img", 0, 128, 32);
    NF_LoadSpritePal("nitrofiles/ui/birdekek.img", 0);

    // Apply the palette to the sprite
    NF_VramSpriteGfx(0, 0, 0, false);
    NF_VramSpritePal(0, 0, 0);
}
 

birdekek

Member
OP
Newcomer
Joined
Jul 25, 2023
Messages
19
Trophies
0
Age
19
XP
45
Country
United States
I fixed the problem, but now it doesnt display images or play any audio when loaded, its just a black screen

heres my code

C++:
#include <nds.h>
#include <maxmod9.h>
#include <nf_lib.h>
#include <stdio.h>

volatile int frame = 0;

void Initialize()
{
    NF_SetRootFolder("NITROFS");
    NF_Set2D(0, 0);
    NF_InitTiledBgBuffers();
    NF_InitTiledBgSys(0);

    NF_InitSpriteBuffers();
    NF_InitSpriteSys(0);

    NF_LoadSpriteGfx("ui/birdekek", 0, 64, 64);
    NF_LoadSpritePal("ui/birdekek", 0);

    NF_VramSpriteGfx(0, 0, 0, false);
    NF_VramSpritePal(0, 0, 0);

#define SFX_BIRDEKEK 0
#define MOD_MAINTHEME 1
}

void Vblank()
{
    frame++;
}

int main(int argc, char** argv)
{
    irqSet(IRQ_VBLANK, Vblank);

    consoleDemoInit();

    Initialize();

    mmLoadEffect(0);
    mmEffect(0);

    consoleClear();
    setBrightness(3, 0);

    NF_CreateSprite(0, 0, 0, 0, 64, 64);

    for (int i = 0; i < 240; i++)
    {
        setBrightness(3 - (i / 60), 0);
        swiWaitForVBlank();
    }

    setBrightness(3, 0);

    NF_DeleteSprite(0, 0);

    NF_LoadTiledBg("maps/mainscreen", "main_bg", 256, 256);

    mmLoad(1);
    mmStart(1, MM_PLAY_LOOP);

    while (1)
    {
        swiWaitForVBlank();
    }

    return 0;
}

By the way, im fairly new to this type of programming, ive only done C# in unity before so i dont know alot about this

Ive read some of the documentation though.
 

plasturion

temporary hermit
Member
Joined
Aug 17, 2012
Messages
1,216
Trophies
2
Location
Tree
XP
3,505
Country
Poland
to display sprite on screen I think some functions are needed too - NF_SpriteOamSet(0) and oamUpdate(&oamMain); right after swiWaitForVblank(); loop, NFlib have some examples. Try to follow sourcecode in examples>graphics>sprite, There's everything.
Maxmod library needs some addons in Make file, this one in devkitpro examples.
 

birdekek

Member
OP
Newcomer
Joined
Jul 25, 2023
Messages
19
Trophies
0
Age
19
XP
45
Country
United States
to display sprite on screen I think some functions are needed too - NF_SpriteOamSet(0) and oamUpdate(&oamMain); right after swiWaitForVblank(); loop, NFlib have some examples. Try to follow sourcecode in examples>graphics>sprite, There's everything.
Maxmod library needs some addons in Make file, this one in devkitpro examples.
I tried adding those but still, no audio or video


C++:
#include <nds.h>
#include <maxmod9.h>
#include <stdlib.h>
#include <unistd.h>
#include <nf_lib.h>
#include <stdio.h>

volatile int frame = 0;

void Initialize()
{
    NF_SetRootFolder("NITROFS");
    NF_Set2D(0, 0);
    NF_InitTiledBgBuffers();
    NF_InitTiledBgSys(0);

    NF_InitSpriteBuffers();
    NF_InitSpriteSys(0);

    NF_LoadSpriteGfx("ui/birdekek", 0, 64, 64);
    NF_LoadSpritePal("ui/birdekek", 0);

    NF_VramSpriteGfx(0, 0, 0, false);
    NF_VramSpritePal(0, 0, 0);

#define SFX_BIRDEKEK 0
#define MOD_MAINTHEME 1
}

void Vblank()
{
    frame++;
}

int main(int argc, char** argv)
{
    irqSet(IRQ_VBLANK, Vblank);

    consoleDemoInit();

    Initialize();

    mmLoadEffect(0);
    mmEffect(0);

    consoleClear();
    setBrightness(3, 0);

    u16* gfx = oamAllocateGfx(&oamMain, SpriteSize_16x16, SpriteColorFormat_256Color);

    NF_CreateSprite(0, 0, 0, 0, 64, 64);

    for (int i = 0; i < 240; i++)
    {
        setBrightness(3 - (i / 60), 0);
        swiWaitForVBlank();
    }

    setBrightness(3, 0);

    NF_DeleteSprite(0, 0);

    NF_LoadTiledBg("maps/mainscreen", "main_bg", 256, 256);

    NF_SpriteOamSet(0);

    mmLoad(1);
    mmStart(1, MM_PLAY_LOOP);

    while (1)
    {
        oamSet(&oamMain, //main graphics engine context
            0,           //oam index (0 to 127) 
            64, 32,   //x and y pixle location of the sprite
            0,                    //priority, lower renders last (on top)
            0,                      //this is the palette index if multiple palettes or the alpha value if bmp sprite   
            SpriteSize_16x16,     
            SpriteColorFormat_256Color,
            gfx,                  //pointer to the loaded graphics
            -1,                  //sprite rotation data 
            false,               //double the size when rotating?
            false,            //hide the sprite?
            false, false, //vflip, hflip
            false    //apply mosaic
        );
        oamUpdate(&oamMain);

        swiWaitForVBlank();
    }

    return 0;
}
 

plasturion

temporary hermit
Member
Joined
Aug 17, 2012
Messages
1,216
Trophies
2
Location
Tree
XP
3,505
Country
Poland
Wait, there's two loops with swiWaitForVBlank(); first time last 4 seconds, and that's the place and time when sprite should be displayed because right after is deleted, right.
There's no point to use ndslib oamAllocateGfx(), oamSet() function in this example since NFlib do this for you.
What i meant before was to add only those two lines in first loop.
C:
    for (int i = 0; i < 240; i++)
    {
        NF_SpriteOamSet(0);
        setBrightness(3 - (i / 60), 0);
        swiWaitForVBlank();
        oamUpdate(&oamMain);
    }

so speaking of sprites this code works on my side.
C:
#include <nds.h>
#include <maxmod9.h>
#include <nf_lib.h>
#include <stdio.h>

volatile int frame = 0;

void Initialize()
{
    NF_SetRootFolder("NITROFS");
    NF_Set2D(0, 0);
    NF_InitTiledBgBuffers();
    NF_InitTiledBgSys(0);

    NF_InitSpriteBuffers();
    NF_InitSpriteSys(0);

    NF_LoadSpriteGfx("ui/birdekek", 0, 64, 64);
    NF_LoadSpritePal("ui/birdekek", 0);

    NF_VramSpriteGfx(0, 0, 0, false);
    NF_VramSpritePal(0, 0, 0);

#define SFX_BIRDEKEK 0
#define MOD_MAINTHEME 1
}

void Vblank()
{
    frame++;
}

int main(int argc, char** argv)
{
    irqSet(IRQ_VBLANK, Vblank);

    consoleDemoInit();

    Initialize();

    //mmLoadEffect(0);
    //mmEffect(0);

    consoleClear();
    setBrightness(3, 0);

    NF_CreateSprite(0, 0, 0, 0, 64, 64);

    for (int i = 0; i < 240; i++)
    {
        NF_SpriteOamSet(0);
        setBrightness(3 - (i / 60), 0);
        swiWaitForVBlank();
        oamUpdate(&oamMain);
    }

    setBrightness(3, 0);

    NF_DeleteSprite(0, 0);
  

    NF_LoadTiledBg("maps/mainscreen", "main_bg", 256, 256);

    //mmLoad(1);
    //mmStart(1, MM_PLAY_LOOP);

    while (1)
    {       
        swiWaitForVBlank();
    }

    return 0;
}

For music make sure you added those libs and rules in makefile
Makefile:
#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project
#---------------------------------------------------------------------------------
LIBS    := -lmm9 -lnflib -lfilesystem -lfat -lnds9
.....
MUSIC       :=  maxmod_data
.....
BINFILES    :=    $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) soundbank.bin

export AUDIOFILES    :=    $(foreach dir,$(notdir $(wildcard $(MUSIC)/*.*)),$(CURDIR)/$(MUSIC)/$(dir))
......
#---------------------------------------------------------------------------------
# rule to build soundbank from music files
#---------------------------------------------------------------------------------
soundbank.bin soundbank.h : $(AUDIOFILES)
#---------------------------------------------------------------------------------
    @mmutil $^ -d -osoundbank.bin -hsoundbank.h
maybe i could forgot about other tags so just compare both Makefiles to add all the things refering to maxmod.
 

birdekek

Member
OP
Newcomer
Joined
Jul 25, 2023
Messages
19
Trophies
0
Age
19
XP
45
Country
United States
Wait, there's two loops with swiWaitForVBlank(); first time last 4 seconds, and that's the place and time when sprite should be displayed because right after is deleted, right.
There's no point to use ndslib oamAllocateGfx(), oamSet() function in this example since NFlib do this for you.
What i meant before was to add only those two lines in first loop.
C:
    for (int i = 0; i < 240; i++)
    {
        NF_SpriteOamSet(0);
        setBrightness(3 - (i / 60), 0);
        swiWaitForVBlank();
        oamUpdate(&oamMain);
    }

so speaking of sprites this code works on my side.
C:
#include <nds.h>
#include <maxmod9.h>
#include <nf_lib.h>
#include <stdio.h>

volatile int frame = 0;

void Initialize()
{
    NF_SetRootFolder("NITROFS");
    NF_Set2D(0, 0);
    NF_InitTiledBgBuffers();
    NF_InitTiledBgSys(0);

    NF_InitSpriteBuffers();
    NF_InitSpriteSys(0);

    NF_LoadSpriteGfx("ui/birdekek", 0, 64, 64);
    NF_LoadSpritePal("ui/birdekek", 0);

    NF_VramSpriteGfx(0, 0, 0, false);
    NF_VramSpritePal(0, 0, 0);

#define SFX_BIRDEKEK 0
#define MOD_MAINTHEME 1
}

void Vblank()
{
    frame++;
}

int main(int argc, char** argv)
{
    irqSet(IRQ_VBLANK, Vblank);

    consoleDemoInit();

    Initialize();

    //mmLoadEffect(0);
    //mmEffect(0);

    consoleClear();
    setBrightness(3, 0);

    NF_CreateSprite(0, 0, 0, 0, 64, 64);

    for (int i = 0; i < 240; i++)
    {
        NF_SpriteOamSet(0);
        setBrightness(3 - (i / 60), 0);
        swiWaitForVBlank();
        oamUpdate(&oamMain);
    }

    setBrightness(3, 0);

    NF_DeleteSprite(0, 0);
 

    NF_LoadTiledBg("maps/mainscreen", "main_bg", 256, 256);

    //mmLoad(1);
    //mmStart(1, MM_PLAY_LOOP);

    while (1)
    {      
        swiWaitForVBlank();
    }

    return 0;
}
in make file make sure you had add libs

Makefile:
#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project
#---------------------------------------------------------------------------------
LIBS    := -lmm9 -lnflib -lfilesystem -lfat -lnds9
.....
MUSIC       :=  maxmod_data
.....
BINFILES    :=    $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) soundbank.bin

export AUDIOFILES    :=    $(foreach dir,$(notdir $(wildcard $(MUSIC)/*.*)),$(CURDIR)/$(MUSIC)/$(dir))
......
#---------------------------------------------------------------------------------
# rule to build soundbank from music files
#---------------------------------------------------------------------------------
soundbank.bin soundbank.h : $(AUDIOFILES)
#---------------------------------------------------------------------------------
    @mmutil $^ -d -osoundbank.bin -hsoundbank.h
maybe i could forgot about other tags so just compare both Makefiles to add all the things refering to maxmod.
I already added the maxmod files into the makefile, i had compiled this code before i tried adding the sprite with just the background and the music and both worked
Post automatically merged:

New issue,

Nvm, i forgot about how code works, :|
Post automatically merged:

i got the error

in2s: could not open soundbank.bin: No such file or directory
make[1]: *** [/c/STIDS/Makefile:201: soundbank.bin.o] Error 1
make: *** [Makefile:170: build] Error 2

when compiling
Post automatically merged:

Ok, i kinda fixed the solution to the compiling problem with a - in line 202
Makefile:
#---------------------------------------------------------------------------------
# Makefile for NightFox's Lib Projects
#---------------------------------------------------------------------------------



#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITARM)),)
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
endif


#---------------------------------------------------------------------------------
# This part substitutes this include:
# include $(DEVKITARM)/ds_rules
# This allows you to set ROM info and icon easy
# Please update this block from DS_RULES file at every DEVKITARM update
#---------------------------------------------------------------------------------
include $(DEVKITARM)/base_rules

LIBNDS    :=    $(DEVKITPRO)/libnds

GAME_TITLE        :=    Text 1
GAME_SUBTITLE1    :=    Text 2
GAME_SUBTITLE2    :=    Text 3
GAME_ICON        :=    $(CURDIR)/../icon.bmp

_ADDFILES    :=    -d $(NITRO_FILES)


#---------------------------------------------------------------------------------
%.nds: %.arm9
    @ndstool -c $@ -9 $< -b $(GAME_ICON) "$(GAME_TITLE);$(GAME_SUBTITLE1);$(GAME_SUBTITLE2)" $(_ADDFILES)
    @echo built ... $(notdir $@)

#---------------------------------------------------------------------------------
%.nds: %.elf
    @ndstool -c $@ -9 $< -b $(GAME_ICON) "$(GAME_TITLE);$(GAME_SUBTITLE1);$(GAME_SUBTITLE2)" $(_ADDFILES)
    @echo built ... $(notdir $@)

#---------------------------------------------------------------------------------
%.arm9: %.elf
    @$(OBJCOPY) -O binary $< $@
    @echo built ... $(notdir $@)

#---------------------------------------------------------------------------------
%.arm7: %.elf
    @$(OBJCOPY) -O binary $< $@
    @echo built ... $(notdir $@)

#---------------------------------------------------------------------------------
%.elf:
    @echo linking $(notdir $@)
    @$(LD)  $(LDFLAGS) $(OFILES) $(LIBPATHS) $(LIBS) -o $@

#---------------------------------------------------------------------------------
# TARGET is the name of the output
# BUILD is the directory where object files & intermediate files will be placed
# SOURCES is a list of directories containing source code
# INCLUDES is a list of directories containing extra header files
# AUDIO is a list of directories containing sound and music files
#---------------------------------------------------------------------------------
TARGET   :=  $(shell basename $(CURDIR))
BUILD    :=  build
SOURCES  :=  gfx source data 
INCLUDES :=  include build
DATA        :=    data
NITRODATA    :=    nitrofiles
AUDIO    :=  audio
GRAPHICS    :=    gfx
MUSIC        :=    music

#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
ARCH    :=    -mthumb -mthumb-interwork

CFLAGS    :=    -g -Wall -O2\
         -march=armv5te -mtune=arm946e-s -fomit-frame-pointer\
        -ffast-math \
        $(ARCH)

CFLAGS    +=    $(INCLUDE) -DARM9
CXXFLAGS    := $(CFLAGS) -fno-rtti -fno-exceptions

ASFLAGS    :=    -g $(ARCH)
LDFLAGS    =    -specs=ds_arm9.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)

#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project
#---------------------------------------------------------------------------------
LIBS    := -lnflib -lfilesystem -lfat -lmm9 -lnds9

MUSIC       :=  maxmod_data

BINFILES    :=    $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) soundbank.bin

export AUDIOFILES    :=    $(foreach dir,$(notdir $(wildcard $(MUSIC)/*.*)),$(CURDIR)/$(MUSIC)/$(dir))

#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS    :=    $(LIBNDS) $(CURDIR)/nflib


#---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional
# rules for different file extensions
#---------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
#---------------------------------------------------------------------------------

export OUTPUT    :=    $(CURDIR)/$(TARGET)

export VPATH    :=    $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
                    $(foreach dir,$(DATA),$(CURDIR)/$(dir))

export DEPSDIR    :=    $(CURDIR)/$(BUILD)

export NITRO_FILES    :=    $(CURDIR)/$(NITRODATA)

CFILES    :=  $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES  :=  $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
SFILES    :=  $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
BINFILES  :=  $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.bin))) soundbank.bin

# build audio file list, include full path
export AUDIOFILES := $(foreach dir,$(notdir $(wildcard $(AUDIO)/*.*)),$(CURDIR)/$(AUDIO)/$(dir))

#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
#---------------------------------------------------------------------------------
    export LD    :=    $(CC)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
    export LD    :=    $(CXX)
#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------

export OFILES    :=    $(addsuffix .o,$(BINFILES)) \
                    $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)

export INCLUDE    :=    $(foreach dir,$(INCLUDES),-iquote $(CURDIR)/$(dir)) \
                    $(foreach dir,$(LIBDIRS),-I$(dir)/include) \
                    -I$(CURDIR)/$(BUILD)

export LIBPATHS    :=    $(foreach dir,$(LIBDIRS),-L$(dir)/lib)

icons := $(wildcard *.bmp)

ifneq (,$(findstring $(TARGET).bmp,$(icons)))
    export GAME_ICON := $(CURDIR)/$(TARGET).bmp
else
    ifneq (,$(findstring icon.bmp,$(icons)))
        export GAME_ICON := $(CURDIR)/icon.bmp
    endif
endif

.PHONY: $(BUILD) clean

#---------------------------------------------------------------------------------
$(BUILD):
    @[ -d $@ ] || mkdir -p $@
    @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile

#---------------------------------------------------------------------------------
clean:
    @echo clean ...
    @rm -fr $(BUILD) $(TARGET).elf $(TARGET).nds $(TARGET).arm9

#---------------------------------------------------------------------------------
else

#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
$(OUTPUT).nds    :     $(OUTPUT).elf
$(OUTPUT).elf    :    $(OFILES)

#---------------------------------------------------------------------------------
%.bin.o    :    %.bin
#---------------------------------------------------------------------------------
    @echo $(notdir $<)
    $(bin2o)

#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------

#-------------------------------------------------------------
# rule for converting the output into an object file
#-------------------------------------------------------------
%.bin.o:    %.bin
#-------------------------------------------------------------
    -@$(bin2o)

#---------------------------------------------------------------------------------
# rule to build soundbank from music files
#---------------------------------------------------------------------------------
soundbank.bin soundbank.h : $(AUDIOFILES)
#---------------------------------------------------------------------------------
    @mmutil $^ -d -osoundbank.bin -hsoundbank.h

But now my problem is when it does compile the sprite shows up all distorted and out of place

This is how it looks currently
STIDS__16259.png
I want it to look like this
how its supposed to look.png
 
Last edited by birdekek,
  • Like
Reactions: plasturion

plasturion

temporary hermit
Member
Joined
Aug 17, 2012
Messages
1,216
Trophies
2
Location
Tree
XP
3,505
Country
Poland
I see... so now only grit... maybe source image was wrong size? Wasn't 64x64 or 64x (64 * X) (as frames), 8 bit colors?
In grit tools run convert_sprites_autopal.bat
 

Attachments

  • ui.zip
    1.6 KB · Views: 20
  • Like
Reactions: anotherthing

birdekek

Member
OP
Newcomer
Joined
Jul 25, 2023
Messages
19
Trophies
0
Age
19
XP
45
Country
United States
I see... so now only grit... maybe source image was wrong size? Wasn't 64x64 or 64x (64 * X) (as frames), 8 bit colors?
In grit tools run convert_sprites_autopal.bat
Tried yours but it still displays wrong

Heres the code, also the image im using IS 64 by 64


C++:
#include <nds.h>
#include <maxmod9.h>
#include <nf_lib.h>
#include <stdio.h>

volatile int frame = 0;

void Initialize()
{
    NF_SetRootFolder("NITROFS");
    NF_Set2D(0, 0);
    NF_InitTiledBgBuffers();
    NF_InitTiledBgSys(0);

    NF_InitSpriteBuffers();
    NF_InitSpriteSys(0);

    NF_LoadSpriteGfx("ui/birdekek", 0, 64, 64);
    NF_LoadSpritePal("ui/birdekek", 0);

    NF_VramSpriteGfx(0, 0, 0, false);
    NF_VramSpritePal(0, 0, 0);

#define SFX_BIRDEKEK 0
#define MOD_MAINTHEME 1
}

void Vblank()
{
    frame++;
}

int main(int argc, char** argv)
{
    irqSet(IRQ_VBLANK, Vblank);

    consoleDemoInit();

    Initialize();

    //mmLoadEffect(0);
    //mmEffect(0);

    consoleClear();
    setBrightness(3, 0);

    NF_CreateSprite(0, 0, 0, 0, 64, 64);

    for (int i = 0; i < 240; i++)
    {
        NF_SpriteOamSet(0);
        setBrightness(3 - (i / 60), 0);
        swiWaitForVBlank();
        oamUpdate(&oamMain);
    }

    setBrightness(3, 0);

    NF_DeleteSprite(0, 0);


    NF_LoadTiledBg("maps/mainscreen", "main_bg", 256, 256);

    //mmLoad(1);
    //mmStart(1, MM_PLAY_LOOP);

    while (1)
    {
        swiWaitForVBlank();
    }

    return 0;
}
 

plasturion

temporary hermit
Member
Joined
Aug 17, 2012
Messages
1,216
Trophies
2
Location
Tree
XP
3,505
Country
Poland
in that case I don't know, it's working fine on my side.
1690465362677.png

Try maybe download latest devkitpro and compile nflib, or work on a copy with fresh makefile till you display parrot...
or "make clean" before compile again.
 
Last edited by plasturion,
  • Like
Reactions: anotherthing

birdekek

Member
OP
Newcomer
Joined
Jul 25, 2023
Messages
19
Trophies
0
Age
19
XP
45
Country
United States
in that case I don't know, it's working fine on my side.
View attachment 385437
Try maybe download latest devkitpro and compile nflib, or work on a copy with fresh makefile till you display parrot...
or "make clean" before compile again.
Just discovered that it displays when it has 128 instead of 64

NF_CreateSprite(0, 0, 0, 0, 128, 128);

but the sprite is 64 by 64 for some odd reason which makes no sense

Same happens with any other number


For some reason it just fixed for no reason, i have no idea why
Post automatically merged:

I still have this issue with the audio though, because the makefile is wrong somehow

I get these errors everytime i compile it

make[1]: *** [/c/STIDS/Makefile:205: soundbank.bin.o] Error 1

make: *** [Makefile:171: build] Error 2


Makefile:
#---------------------------------------------------------------------------------
# Makefile for NightFox's Lib Projects
#---------------------------------------------------------------------------------



#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITARM)),)
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
endif


#---------------------------------------------------------------------------------
# This part substitutes this include:
# include $(DEVKITARM)/ds_rules
# This allows you to set ROM info and icon easy
# Please update this block from DS_RULES file at every DEVKITARM update
#---------------------------------------------------------------------------------
include $(DEVKITARM)/base_rules

LIBNDS    :=    $(DEVKITPRO)/libnds

GAME_TITLE        :=    Text 1
GAME_SUBTITLE1    :=    Text 2
GAME_SUBTITLE2    :=    Text 3
GAME_ICON        :=    $(CURDIR)/../icon.bmp

_ADDFILES    :=    -d $(NITRO_FILES)


#---------------------------------------------------------------------------------
%.nds: %.arm9
    @ndstool -c $@ -9 $< -b $(GAME_ICON) "$(GAME_TITLE);$(GAME_SUBTITLE1);$(GAME_SUBTITLE2)" $(_ADDFILES)
    @echo built ... $(notdir $@)

#---------------------------------------------------------------------------------
%.nds: %.elf
    @ndstool -c $@ -9 $< -b $(GAME_ICON) "$(GAME_TITLE);$(GAME_SUBTITLE1);$(GAME_SUBTITLE2)" $(_ADDFILES)
    @echo built ... $(notdir $@)

#---------------------------------------------------------------------------------
%.arm9: %.elf
    @$(OBJCOPY) -O binary $< $@
    @echo built ... $(notdir $@)

#---------------------------------------------------------------------------------
%.arm7: %.elf
    @$(OBJCOPY) -O binary $< $@
    @echo built ... $(notdir $@)

#---------------------------------------------------------------------------------
%.elf:
    @echo linking $(notdir $@)
    @$(LD)  $(LDFLAGS) $(OFILES) $(LIBPATHS) $(LIBS) -o $@

#---------------------------------------------------------------------------------
# TARGET is the name of the output
# BUILD is the directory where object files & intermediate files will be placed
# SOURCES is a list of directories containing source code
# INCLUDES is a list of directories containing extra header files
# AUDIO is a list of directories containing sound and music files
#---------------------------------------------------------------------------------
TARGET   :=  $(shell basename $(CURDIR))
BUILD    :=  build
SOURCES  :=  gfx source data 
INCLUDES :=  include build
DATA        :=    data
NITRODATA    :=    nitrofiles
AUDIO    :=  audio
GRAPHICS    :=    gfx
MUSIC        :=    music

#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
ARCH    :=    -mthumb -mthumb-interwork

CFLAGS    :=    -g -Wall -O2\
         -march=armv5te -mtune=arm946e-s -fomit-frame-pointer\
        -ffast-math \
        $(ARCH)

CFLAGS    +=    $(INCLUDE) -DARM9
CXXFLAGS    := $(CFLAGS) -fno-rtti -fno-exceptions

ASFLAGS    :=    -g $(ARCH)
LDFLAGS    =    -specs=ds_arm9.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)

#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project
#---------------------------------------------------------------------------------
LIBS    := -lnflib -lfilesystem -lfat -lmm9 -lnds9

MUSIC       :=  maxmod_data

BINFILES    :=    $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) soundbank.bin

export AUDIOFILES    :=    $(foreach dir,$(notdir $(wildcard $(MUSIC)/*.*)),$(CURDIR)/$(MUSIC)/$(dir))

#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS    :=    $(LIBNDS) $(CURDIR)/nflib


#---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional
# rules for different file extensions
#---------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
#---------------------------------------------------------------------------------

export OUTPUT    :=    $(CURDIR)/$(TARGET)

export VPATH    :=    $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
                    $(foreach dir,$(DATA),$(CURDIR)/$(dir))

export DEPSDIR    :=    $(CURDIR)/$(BUILD)

export NITRO_FILES    :=    $(CURDIR)/$(NITRODATA)

CFILES    :=  $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES  :=  $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
SFILES    :=  $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
BINFILES  :=  $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.bin))) soundbank.bin

# build audio file list, include full path
export AUDIOFILES := $(foreach dir,$(notdir $(wildcard $(AUDIO)/*.*)),$(CURDIR)/$(AUDIO)/$(dir))

#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
#---------------------------------------------------------------------------------
    export LD    :=    $(CC)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
    export LD    :=    $(CXX)
#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------

export OFILES    :=    $(addsuffix .o,$(BINFILES)) \
                    $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)

export INCLUDE    :=    $(foreach dir,$(INCLUDES),-iquote $(CURDIR)/$(dir)) \
                    $(foreach dir,$(LIBDIRS),-I$(dir)/include) \
                    -I$(CURDIR)/$(BUILD)

export LIBPATHS    :=    $(foreach dir,$(LIBDIRS),-L$(dir)/lib)

icons := $(wildcard *.bmp)

ifneq (,$(findstring $(TARGET).bmp,$(icons)))
    export GAME_ICON := $(CURDIR)/$(TARGET).bmp
else
    ifneq (,$(findstring icon.bmp,$(icons)))
        export GAME_ICON := $(CURDIR)/icon.bmp
    endif
endif

.PHONY: $(BUILD) clean

#---------------------------------------------------------------------------------
$(BUILD):
    @[ -d $@ ] || mkdir -p $@
    @$(MAKE) BUILDDIR=`cd $(BUILD) && pwd` --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile

#---------------------------------------------------------------------------------
clean:
    @echo clean ...
    @rm -fr $(BUILD) $(TARGET).elf $(TARGET).nds $(TARGET).arm9

#---------------------------------------------------------------------------------
else

#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
$(OUTPUT).nds    :     $(OUTPUT).elf
$(OUTPUT).elf    :    $(OFILES)

#-------------------------------------------------------------
# rule for converting the output into an object file
#-------------------------------------------------------------
%.bin.o:    %.bin
#-------------------------------------------------------------
    @$(bin2o)

#-------------------------------------------------------------
# rule for generating soundbank file from audio files
#-------------------------------------------------------------
soundbank.bin:    $(AUDIOFILES)
#-------------------------------------------------------------
    @mmutil $^ -osoundbank.bin -hsoundbank.h -d

#---------------------------------------------------------------------------------
%.bin.o    :    %.bin
#---------------------------------------------------------------------------------
    @echo $(notdir $<)
    $(bin2o)

#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------
 
Last edited by birdekek,

plasturion

temporary hermit
Member
Joined
Aug 17, 2012
Messages
1,216
Trophies
2
Location
Tree
XP
3,505
Country
Poland
Try with this, no sound effects but music modules works and play.
Please try to follow examples, compare, look for what is missing.
 

Attachments

  • fontext.zip
    2.6 KB · Views: 20

plasturion

temporary hermit
Member
Joined
Aug 17, 2012
Messages
1,216
Trophies
2
Location
Tree
XP
3,505
Country
Poland
In that case you are doing something wrong, try again, i tested those files before compiled and worked fine.
In main.c include "soundbank.h" and "soundbank_bin.h" same as in ndslib examples of maxmod "audio_modes".
or change MUSIC:= to the folder that you have, I have different.
 

birdekek

Member
OP
Newcomer
Joined
Jul 25, 2023
Messages
19
Trophies
0
Age
19
XP
45
Country
United States
How do i add the audio SFX_BIRDEKEK to play too, its in 8000 hz or whatever, its a .WAV file, and it is unsigned 8 bit pcm, also i noticed that the sprite will appear if you dont play the audio but i want the audio played
Post automatically merged:

How do i add the audio SFX_BIRDEKEK to play too, its in 8000 hz or whatever, its a .WAV file, and it is unsigned 8 bit pcm, also i noticed that the sprite will appear if you dont play the audio but i want the audio played
I fixed it, my dumbass brain forgot to play the sound effect
 
Last edited by birdekek,

plasturion

temporary hermit
Member
Joined
Aug 17, 2012
Messages
1,216
Trophies
2
Location
Tree
XP
3,505
Country
Poland
That's fine, also notice that soundbank.bin capacity have some limits here, as it compiles and link into arm9.bin I guess this music bank cannot or shouldn't be bigger than let's say 1-2 MB as arm9.bin loads into ram staying there whole time. It lacks audio examples in ndslib that store music data into nitrofiles as other files do in nflib. Also would be nice to play other different popular formats like FM (Korg) , SID, or even mp3. If you have much music ASlib would be better choice, but is not compatible with devkitPro anymore for many years. ("IPC system was removed"). If someone can recommend some good music libraries I would like to know too.
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    K3Nv2 @ K3Nv2: https://youtu.be/_sJ79aDQTeQ?si=dCPYbyGhZ8OFK8nb