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.

Beginners > a little help pls

#24898 - Inky - Fri Aug 13, 2004 6:37 am

ive been using an ebook called Programming The GBA the unofficial guide and ive come across a code in it i cant compile i was just wondering if some1 could mayb tell me if something is rong with ill post it here and post the error msg ive been getting


Code:
// add support for rand function
#include <stdlib.h>

//declare function prototype
void DrawPixel3 (int, int, unsigned short);

//declare some defines for the video mode
#define REG_DISPCNT *(unsigned long*) 0x4000000
#define MODE_3 0x3
#define BG2_ENABLE 0x400

//changes the video mode
#define SetMode(mode) REG_DISPCNT = (mode)

// packs three values into 15-bit color
#define RGB(r,g,b) ((r) +(g<<5) + (b<<10))

// create a pointer to the video buffer
unsigned short* videoBuffer = (unsigned short*) 0x6000000;


//////////////////////////////////////
// Function: main()
// Entry point for the program
/////////////////////////////////////

int main(void)

{
    int x, y;
    unsigned short color;

    SetMode(MODE_3 | BG2_ENABLE);

    while(1)

    {
        //randomize the pixel

        x = rand() % 240;
        y = rand() % 160;
        color = RGB (rand()%31, rand()%31, rand()%31);
        DrawPixel3 (x, y, color);
    }


    return 0;
}

////////////////////////////////////
// Function: DrawPixel3
// Draws a pixel in mode 3
//////////////////////////////////

void DrawPixel3 (int x, int y, unsigned short color)

{

    videoBuffer [y * 240 + x] = color;

}


thats exactly how its displayed in the book and this is the error ive been getting

C:/HAM/system/standard-targets.mak:136: warning: overriding commands for target `mode'
C:/HAM/system/standard-targets.mak:27: warning: ignoring old commands for target `mode'
C:/HAM/system/standard-targets.mak:136: warning: overriding commands for target `3'
C:/HAM/system/standard-targets.mak:27: warning: ignoring old commands for target `3'
MAKE: Circular mode <- mode dependency dropped.
MAKE: Circular 3 <- mode dependency dropped.
MAKE: Circular 3 <- 3 dependency dropped.
C:/HAM/gcc-arm/bin/arm-thumb-elf-ld.exe -L C:/HAM/gcc-arm/lib/gcc-lib/arm-thumb-elf/3.3.2/interwork -L C:/HAM/gcc-arm/lib/gcc-lib/arm-thumb-elf/3.3.2 -L C:/HAM/gcc-arm/arm-thumb-elf/lib/interwork -L C:/HAM/gcc-arm/arm-thumb-elf/lib -L C:/HAM/gcc-arm/lib --script C:/HAM/system/lnkscript-afm -o mode 3 pixeldrawing.elf crt0.o main.o -lafm -lham -lm -lstdc++ -lsupc++ -lgcc -lc -lgcc
C:/HAM/gcc-arm/bin/arm-thumb-elf-ld: cannot open 3: No such file or directory
MAKE: *** [pixeldrawing.elf] Error 1

by the way im not sure if this makes a diff but im using visualham
any help would be great

#24920 - tepples - Fri Aug 13, 2004 5:17 pm

What is the name of your .c file? Specifically, does this filename contain a space?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#24945 - Inky - Fri Aug 13, 2004 7:55 pm

no its main.c i didnt change it cause it was the only c file that was going to be there

#24961 - jma - Fri Aug 13, 2004 10:04 pm

Looks to me like your error isn't in the code but in the makefile:

C:/HAM/system/standard-targets.mak:136: warning: overriding commands for target `mode'

I don't use HAM (or C for that matter), so hopefully someone else can be more helpful. But appears that the makefile is malformed.

Jeff
_________________
massung@gmail.com
http://www.retrobyte.org

#24964 - dagamer34 - Fri Aug 13, 2004 10:20 pm

Here's my HAM makefile. Compare it to the one you have.

Code:

######################################
# Standard Makefile Targets for HAM
######################################

# ---------------------------------------------------------------
# Switches for tUME / tUMEric
# ---------------------------------------------------------START-

ifeq ($(USE_TUME),yes)
   TUME_OFILES = $(TUME_FILES:.TUM=.o)
endif

# ----------------------------------------------------------STOP-
# Switches for tUME / tUMEric
# ---------------------------------------------------------------


# ---------------------------------------------------------------
# Switches for Krawall
# ---------------------------------------------------------START-

ifeq ($(USE_KRAWALL),yes)
$(PROGNAME).$(EXT) : $(PROGNAME).elf
   $(OBJCOPY) -v -O binary $(PROGNAME).elf $(PROGNAME).$(EXT)
else
$(PROGNAME).$(EXT) : $(PROGNAME).elf
   $(OBJCOPY) -v -O binary $(PROGNAME).elf $(PROGNAME).$(EXT)
endif
#
# If Krawall support wanted, also compile samples.s and instruments.s and link Krawall lib
#
ifeq ($(USE_KRAWALL),yes)

 LDFLAGS += $(ADD_LDFLAGS) $(LIBDIR) --script $(HAMDIR)/system/lnkscript-krawall

ifeq ($(KRAWALL_IS_REGISTERED),yes)

#
# registered
#

ifeq ($(findstring .xm,$(KRAWALL_FILES)),.xm)

   KRAWALL_USED_XM=yes
   KRAWALL_OFILES=$(KRAWALL_FILES:.xm=.o) samples.o instruments.o

else
ifeq ($(findstring .s3m,$(KRAWALL_FILES)),.s3m)

    KRAWALL_USED_S3M=yes
    KRAWALL_OFILES=$(KRAWALL_FILES:.s3m=.o) samples.o instruments.o

else
    KRAWALL_USED_NOTHING=yes
endif
endif
else

#
# not registered
#

ifeq ($(findstring .s3m,$(KRAWALL_FILES)),.s3m)

KRAWALL_USED_S3M=yes
KRAWALL_OFILES=$(KRAWALL_FILES:.s3m=.o) samples.o

else
KRAWALL_USED_NOTHING=yes
endif


endif

# ----------------------------------------------------------STOP-
# Switches for Krawall
# ---------------------------------------------------------------

# ---------------------------------------------------------------
# Linking Step
# ---------------------------------------------------------START-

$(PROGNAME).elf : $(TUME_OFILES) $(KRAWALL_OFILES) $(OFILES)
ifeq ($(KRAWALL_USED_S3M),yes)
   @echo "-----------------------------"
   @echo " "
   @echo "HAM Krawall subsystem: found S3M input files."
   @echo "HAM will convert to: $(KRAWALL_OFILES)" 
   @echo "and link them into your GBA ROM. Also auto-linking Krawall lib."
   @echo " "
   @echo "ATTENTION: "
   @echo " "
   @echo "Please make sure you include the newly created modules.h and "
   @echo "samples.h in your code, you need them to use the Krawall lib."
   @echo " "
   @echo "For more information about how to use Krawall, see the docs in"
   @echo "the docs-krawall folder of your installation directory."
   @echo " "
   @echo "-----------------------------"
   $(LD) $(LDFLAGS) -o $(PROGNAME).elf $(OFILES) $(TUME_OFILES) $(KRAWALL_OFILES) $(ADD_LIBS) -lkrawall $(LD_LIBS)
else
ifeq ($(KRAWALL_USED_XM),yes)
   @echo "-----------------------------"
   @echo " "
   @echo "HAM Krawall subsystem: found XM input files."
   @echo "HAM will convert to: $(KRAWALL_OFILES)" 
   @echo "and link them into your GBA ROM. Also auto-linking Krawall lib."
   @echo " "
   @echo "ATTENTION: "
   @echo " "
   @echo "Please make sure you include the newly created modules.h and "
   @echo "samples.h in your code, you need them to use the Krawall lib."
   @echo " "
   @echo "For more information about how to use Krawall, see the docs in"
   @echo "the docs-krawall folder of your intallation directory."
   @echo " "
   @echo "-----------------------------"
   $(LD) $(LDFLAGS) -o $(PROGNAME).elf $(OFILES) $(TUME_OFILES) $(KRAWALL_OFILES) $(ADD_LIBS) -lkrawall $(LD_LIBS)
else
ifeq ($(KRAWALL_USED_NOTHING),yes)
   @echo "-----------------------------"
   @echo " "
   @echo "HAM Krawall subsystem: found NO input files (.s3m or .xm), not linking the library."
   @echo " "
   @echo "-----------------------------"
   $(LD) $(LDFLAGS) -o $(PROGNAME).elf $(OFILES) $(TUME_OFILES) $(ADD_LIBS) $(LD_LIBS)
endif
endif
endif

else

LDFLAGS += $(ADD_LDFLAGS) $(LIBDIR) --script $(HAMDIR)/system/lnkscript-afm

$(PROGNAME).elf : $(TUME_OFILES) $(OFILES)
   $(LD) $(LDFLAGS) -o $(PROGNAME).elf $(OFILES) $(TUME_OFILES) $(ADD_LIBS) -lafm $(LD_LIBS)
endif

# ----------------------------------------------------------STOP-
# Linking Step
# ---------------------------------------------------------------

# ---------------------------------------------------------------
# Compile Targets .x.x
# ---------------------------------------------------------START-

.s.o:
   $(AS) $(ASFLAGS) $< -o $@

.c.o:
   $(CC) $(CFLAGS) $< -o $@

.cpp.o:
   $(CC) $(CFLAGS) $< -o $@
   
%.c : %.TUM
   cd $(<D) ; \
   $(HAMDIR)/tools/$(HAM_PLATFORM)/tumeric $(<F)
   

#
# raw to object conversion, including interwork flipping
#

%.o : %.raw
   @$(LD) -A elf32-littlearm --format binary --oformat elf32-littlearm $< -o $@ -r -EL -T $(HAMDIR)/system/bin2rodata.x
   $(HAMDIR)/tools/$(HAM_PLATFORM)/elf_align$(EXEC_POSTFIX) $@ 4
   $(HAMDIR)/tools/$(HAM_PLATFORM)/interflip$(EXEC_POSTFIX) -mthumb-interwork $@
#
# XXX to raw conversion
#

%.raw : %.wav
   $(HAMDIR)/tools/$(HAM_PLATFORM)/wav2gba $< $@

%.o : %.mod
   $(LD) -A elf32-littlearm --format binary --oformat elf32-littlearm $< -o $@ -r -EL -T $(HAMDIR)/system/bin2rodata.x
   $(HAMDIR)/tools/$(HAM_PLATFORM)/elf_align$(EXEC_POSTFIX) $@ 4
   $(HAMDIR)/tools/$(HAM_PLATFORM)/interflip$(EXEC_POSTFIX) -mthumb-interwork $@
#
# Krawall s3m / XM conversion
#

%.s : %.s3m
   $(HAMDIR)/tools/$(HAM_PLATFORM)/krawall/converter $(KRAWALL_FILES)

%.s : %.xm
   $(HAMDIR)/tools/$(HAM_PLATFORM)/krawall/converter $(KRAWALL_FILES)



# ----------------------------------------------------------STOP-
# Compile Targets .x.x
# ---------------------------------------------------------------

crt0.o : $(HAMDIR)/system/crt0.s
   $(AS) $(ASFLAGS) $(HAMDIR)/system/crt0.s -ocrt0.o

# ---------------------------------------------------------------
# User Space Targets
# ---------------------------------------------------------START-

mbv2: all
   $(HAMDIR)/tools/$(HAM_PLATFORM)/mb$(EXEC_POSTFIX) -c -x 500 -w 50 -s $(PROGNAME).$(EXT)

vba: all fixheader
   $(HAMDIR)/tools/$(HAM_PLATFORM)/vba$(EXEC_POSTFIX) $(PROGNAME).$(EXT)

vbawin: all fixheader
   $(HAMDIR)/tools/$(HAM_PLATFORM)/vbawin$(EXEC_POSTFIX) $(PROGNAME).$(EXT)

runvba:
   $(HAMDIR)/tools/$(HAM_PLATFORM)/vba$(EXEC_POSTFIX) $(PROGNAME).$(EXT)

runvbawin:
   $(HAMDIR)/tools/$(HAM_PLATFORM)/vbawin$(EXEC_POSTFIX) $(PROGNAME).$(EXT)

ifeq ($(HAM_PLATFORM),linux)
gdb: clean all fixheader
   $(HAMDIR)/tools/$(HAM_PLATFORM)/vba$(EXEC_POSTFIX) -Gtcp &
   echo "file $(PROGNAME).elf" > insight.ini
   echo "target remote 127.0.0.1:55555" >> insight.ini
   echo "load $(PROGNAME).elf" >> insight.ini
   echo "b main" >> insight.ini
   echo "directory $(GDB_SOURCE_DIRS)" >> insight.ini
   echo "c" >> insight.ini
   $(GDB) --command=insight.ini $(PROGNAME).elf
rungdb:
   $(HAMDIR)/tools/$(HAM_PLATFORM)/vba$(EXEC_POSTFIX) -Gtcp &
   echo "file $(PROGNAME).elf" > insight.ini
   echo "target remote 127.0.0.1:55555" >> insight.ini
   echo "load $(PROGNAME).elf" >> insight.ini
   echo "b main" >> insight.ini
   echo "directory $(GDB_SOURCE_DIRS)" >> insight.ini
   echo "c" >> insight.ini
   $(GDB) --command=insight.ini $(PROGNAME).elf
else
gdb: clean all fixheader
   $(HAMDIR)/tools/$(HAM_PLATFORM)/vba$(EXEC_POSTFIX) -Gtcp &
   $(HAMDIR)/tools/$(HAM_PLATFORM)/echo "file $(PROGNAME).elf" > insight.ini
   $(HAMDIR)/tools/$(HAM_PLATFORM)/echo "target remote 127.0.0.1:55555" >> insight.ini
   $(HAMDIR)/tools/$(HAM_PLATFORM)/echo "load $(PROGNAME).elf" >> insight.ini
   $(HAMDIR)/tools/$(HAM_PLATFORM)/echo "b main" >> insight.ini
   $(HAMDIR)/tools/$(HAM_PLATFORM)/echo "directory $(GDB_SOURCE_DIRS)" >> insight.ini
   $(HAMDIR)/tools/$(HAM_PLATFORM)/echo "c" >> insight.ini
   $(GDB) --command=insight.ini $(PROGNAME).elf
rungdb:
   $(HAMDIR)/tools/$(HAM_PLATFORM)/vba$(EXEC_POSTFIX) -Gtcp &
   $(HAMDIR)/tools/$(HAM_PLATFORM)/echo "file $(PROGNAME).elf" > insight.ini
   $(HAMDIR)/tools/$(HAM_PLATFORM)/echo "target remote 127.0.0.1:55555" >> insight.ini
   $(HAMDIR)/tools/$(HAM_PLATFORM)/echo "load $(PROGNAME).elf" >> insight.ini
   $(HAMDIR)/tools/$(HAM_PLATFORM)/echo "b main" >> insight.ini
   $(HAMDIR)/tools/$(HAM_PLATFORM)/echo "directory $(GDB_SOURCE_DIRS)" >> insight.ini
   $(HAMDIR)/tools/$(HAM_PLATFORM)/echo "c" >> insight.ini
   $(GDB) --command=insight.ini $(PROGNAME).elf
endif

emu: all fixheader
   $(HAM_EMUPATH) $(PROGNAME).$(EXT)
runemu:
   $(HAM_EMUPATH) $(PROGNAME).$(EXT)

fla: all fixheader
   $(HAMDIR)/tools/$(HAM_PLATFORM)/fl$(EXEC_POSTFIX) -w 50 -p $(PROGNAME).$(EXT)

runfla:
   $(HAMDIR)/tools/$(HAM_PLATFORM)/fl$(EXEC_POSTFIX) -w 50 -p $(PROGNAME).$(EXT)

flambv2: all fixheader
   $(HAMDIR)/tools/$(HAM_PLATFORM)/mb$(EXEC_POSTFIX) -e -x 500 -w 50 -p $(PROGNAME).$(EXT)
   $(HAMDIR)/tools/$(HAM_PLATFORM)/mb$(EXEC_POSTFIX) -c -x 50

runflambv2:
   $(HAMDIR)/tools/$(HAM_PLATFORM)/mb$(EXEC_POSTFIX) -e -x 500 -w 50 -p $(PROGNAME).$(EXT)
   $(HAMDIR)/tools/$(HAM_PLATFORM)/mb$(EXEC_POSTFIX) -c -x 50

# ----------------------------------------------------------STOP-
# User Space Targets
# ---------------------------------------------------------------


# ---------------------------------------------------------------
# Misc Other Targets
# ---------------------------------------------------------START-

ifeq ($(HAM_PLATFORM),linux)
fixheader:
   cp $(PROGNAME).$(EXT)  $(PROGNAME)_tmp.$(EXT) 
   $(HAMDIR)/tools/$(HAM_PLATFORM)/ht.pl -n "$(PROGNAME)" -cl -o $(PROGNAME).$(EXT) $(PROGNAME)_tmp.$(EXT)
   rm -f $(PROGNAME)_tmp.$(EXT) 
else
fixheader:
   $(HAMDIR)/tools/$(HAM_PLATFORM)/gbafix$(EXEC_POSTFIX) $(PROGNAME).$(EXT) -t$(PROGNAME)
endif


ifeq ($(HAM_PLATFORM),linux)
clean: info
   rm -f *.o *.i *.ii
else
clean: info
   $(HAMDIR)/tools/$(HAM_PLATFORM)/rm -f *.o *.i *.ii
endif

ifeq ($(HAM_PLATFORM),win32)
info:
   @echo "------------------------------------------------------------------"
   @echo " HAM Win32 installation information:"
   @echo " "
   @echo " HAM version:        $(HAM_VERSION_MAJOR).$(HAM_VERSION_MINOR)" in $(HAMDIR)
   @echo " GCC/GDB version:    $(HAM_VERSION_GCC) / $(HAM_VERSION_INSIGHT)"
   @echo " Newlib/Binutils:    $(HAM_VERSION_NEWLIB) / $(HAM_VERSION_BINUTILS)"
   @echo " Krawall ena/regged: $(USE_KRAWALL) / $(KRAWALL_IS_REGISTERED)"
#   @echo " Cygwin: "
#   DllInfo.exe -f $(HAMDIR)/tools/win32/cygwin1.dll
   @echo "------------------------------------------------------------------"
else
info:
   @echo "------------------------------------------------------------------"
   @echo " HAM Linux installation information:"
   @echo " "
   @echo " HAM version:        $(HAM_VERSION_MAJOR).$(HAM_VERSION_MINOR)" in $(HAMDIR)
   @echo " GCC/GDB version:    $(HAM_VERSION_GCC) / $(HAM_VERSION_INSIGHT)"
   @echo " Newlib/Binutils:    $(HAM_VERSION_NEWLIB) / $(HAM_VERSION_BINUTILS)"
   @echo " Krawall ena/regged: $(USE_KRAWALL) / $(KRAWALL_IS_REGISTERED)"
   @echo "------------------------------------------------------------------"
endif

# ----------------------------------------------------------STOP-
# Misc Other Targets
# ---------------------------------------------------------------

_________________
Little kids and Playstation 2's don't mix. :(

#24966 - Inky - Fri Aug 13, 2004 10:28 pm

thx jma after u posted i went and checked my make file and found out when i typed in the name of the program at the create a new workspace area i put spaces in between mode and 3 and pixeldrawing i took out the spacing and it works fine now and thx for trying to help dagamer but i figured it out just as u were posting i think