Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7609015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:04:09+00:00 2026-05-31T01:04:09+00:00

I am working on a gameboy project for a class asignment. I was told,

  • 0

I am working on a gameboy project for a class asignment. I was told, that we needed to have a separate “functions” file, and “main” file. I am going insane doing this. I have made a header file “myLib.h”, and in it I include definitions, and prototypes of the functions that are in “myLib.c”. In my main file, I call a function from “myLib.c”, and it compiles, but will not work. I have added “myLib.c” to my make file. The files are below:

myLib.h

typedef unsigned short u16;
typedef unsigned char u8;
typedef unsigned int u32;

#define REG_DISPCTL *(unsigned short *)0x4000000
#define MODE3 3
#define BG2_ENABLE  (1<<10)
#define SCANLINECOUNTER *(volatile u16 *)0x4000006

#define COLOR(r, g, b) ((r) | (g)<<5 | (b)<<10)

#define RED COLOR(31,0,0)
#define GREEN COLOR(0,31,0)
#define BLUE COLOR(0,0,31)
#define MAGENTA COLOR(31, 0, 31)
#define YELLOW COLOR(31, 31, 0)
#define CYAN COLOR(0,31,31)
#define WHITE COLOR(31,31,31)
#define BLACK 0


#define OFFSET(r, c, numcols)  ((r)*(numcols) + (c))


extern unsigned short *videoBuffer;

// Buttons

#define BUTTON_A        (1<<0)
#define BUTTON_B        (1<<1)
#define BUTTON_SELECT           (1<<2)
#define BUTTON_START            (1<<3)
#define BUTTON_RIGHT            (1<<4)
#define BUTTON_LEFT     (1<<5)
#define BUTTON_UP       (1<<6)
#define BUTTON_DOWN     (1<<7)
#define BUTTON_R        (1<<8)
#define BUTTON_L        (1<<9)

#define BUTTONS *(unsigned int *)0x4000130

#define KEY_DOWN_NOW(key)  (~(BUTTONS) & key)

/* DMA */

typedef struct
{
    const volatile void *src;
    const volatile void *dst;
    u32                  cnt;
} DMA_CONTROLLER;

#define DMA ((volatile DMA_CONTROLLER *) 0x040000B0)

#define REG_DMA0SAD         *(const volatile u32*)0x40000B0  // source address
#define REG_DMA0DAD         *(volatile u32*)0x40000B4  // destination address
#define REG_DMA0CNT         *(volatile u32*)0x40000B8  // control register

// DMA channel 1 register definitions
#define REG_DMA1SAD         *(const volatile u32*)0x40000BC  // source address
#define REG_DMA1DAD         *(volatile u32*)0x40000C0  // destination address
#define REG_DMA1CNT         *(volatile u32*)0x40000C4  // control register

// DMA channel 2 register definitions
#define REG_DMA2SAD         *(const volatile u32*)0x40000C8  // source address
#define REG_DMA2DAD         *(volatile u32*)0x40000CC  // destination address
#define REG_DMA2CNT         *(volatile u32*)0x40000D0  // control register

// DMA channel 3 register definitions
#define REG_DMA3SAD         *(volatile u32*)0x40000D4   // source address
#define REG_DMA3DAD         *(volatile u32*)0x40000D8  // destination address
#define REG_DMA3CNT         *(volatile u32*)0x40000DC  // control register

// Defines
#define DMA_CHANNEL_0 0
#define DMA_CHANNEL_1 1
#define DMA_CHANNEL_2 2
#define DMA_CHANNEL_3 3

#define DMA_DESTINATION_INCREMENT (0 << 21)
#define DMA_DESTINATION_DECREMENT (1 << 21)
#define DMA_DESTINATION_FIXED (2 << 21)
#define DMA_DESTINATION_RESET (3 << 21)

#define DMA_SOURCE_INCREMENT (0 << 23)
#define DMA_SOURCE_DECREMENT (1 << 23)
#define DMA_SOURCE_FIXED (2 << 23)

#define DMA_REPEAT (1 << 25)

#define DMA_16 (0 << 26)
#define DMA_32 (1 << 26)

#define DMA_NOW (0 << 28)
#define DMA_AT_VBLANK (1 << 28)
#define DMA_AT_HBLANK (2 << 28)
#define DMA_AT_REFRESH (3 << 28)

#define DMA_IRQ (1 << 30)
#define DMA_ON (1 << 31)






// Prototypes
void setPixel(int , int , u16 );
void drawRect(int row, int col, int height, int width, u16 color);
void waitForVblank();
void fillScreen(u16 color);
void delay(int);

myLib.c

#include "myLib.h"

unsigned short *videoBuffer = (unsigned short *)0x6000000;
void setPixel(int row, int col, u16 color)
{
    videoBuffer[OFFSET(row, col, 240)] = color;
}

void drawRect(int row, int col, int height, int width, 
        volatile u16 color)
{
    int r;

    for(r=0;r<height; r++)
    {

        REG_DMA3SAD = (u32)&color;
        REG_DMA3DAD = (u32)(&videoBuffer[OFFSET(row+r, col, 240)]);
        REG_DMA3CNT = width | DMA_SOURCE_FIXED | 
                  DMA_DESTINATION_INCREMENT | DMA_ON;

    }
}

void waitForVblank()
{
    while(SCANLINECOUNTER > 160);
    while(SCANLINECOUNTER < 160);

}

void fillScreen(volatile u16 color)
{
    REG_DMA3SAD = (u32)&color;
    REG_DMA3DAD = (u32)videoBuffer;
    REG_DMA3CNT = (160*240) | DMA_SOURCE_FIXED | 
                  DMA_DESTINATION_INCREMENT | DMA_ON;
}
void delay(int n)
{
    int i;
    volatile int x;
    for(i=0; i<10000*n; i++)
    {
        x = x + 1;
    }
}

main.c

#include <stdio.h>
#include <stdlib.h>
#include "myLib.h"

int main() {
    int i = 0;
    int j = 0;
    for(i = 0; i < 160; i++){
        for(j = 0; j < 240; j++){
            {
                setPixel(i, j, RED);
            }
        }
    }
    return (EXIT_SUCCESS);
}

Makefile

########################################
## CS1372 Dual GBA/Console Makefile   ##
## Updated: 1/08/2010 - Drew Bratcher ##
########################################

# Student instructions:
# - Ensure that the paths are correct
# - Edit the SOURCES line with a space-separated list of your .c files
# - Keep updating SOURCES every time you add a new source file
# - Select "Release" in NetBeans if this is a GBA project
# - Select "Debug" in NetBeans if this is a console project
# - Make sure the Linker Output in NetBeans is set to "Program" for all configurations


# --- Project Settings (Change these for your proejct)
# PRODUCT_NAME should match your Linker Output in NetBeans
# SOURCES should be The .c files in your project
PRODUCT_NAME       = Program

###### LIST ALL C Files in your project here
SOURCES            = main.c myLib.c 

###### --- System Settings (Update these for your system)
###### Mac example paths
DKPATH             = C:/CS1372-Tools/devkitARM/devkitARM/bin
CCPATH             = C:/cygwin/bin
VBASIM             = C:/CS1372-Tools/VisualBoyAdvance-1.7.2/VisualBoyAdvance.exe
#DKPATH             = C:/devkitARM/bin
#CCPATH             = C:/cygwin/bin
#VBASIM             = C:/



FIND               = find
COPY               = cp -r

# --- File Names
ELF_NAME           = $(PRODUCT_NAME).elf
ROM_NAME           = $(PRODUCT_NAME).gba
BIN_NAME           = $(PRODUCT_NAME)

# --- Debug and Release Selection
# Don't change this or it'll break your Makefile
# If you need to override the selection, uncomment one:
#CONF               = Debug
#CONF               = Release
ifeq ($(CONF),Debug)
DEBUG              = yes
endif

ifndef DEBUG
# ============ RELEASE MODE
# --- GBA Settings
MODEL              = -mthumb-interwork -mthumb
SPECS              = -specs=gba.specs

# --- Archiver
AS                 = $(DKPATH)/arm-eabi-as
ASFLAGS            = -mthumb-interwork

# --- Compiler
CC                 = $(DKPATH)/arm-eabi-gcc
CFLAGS             = $(MODEL) -O2 -Wall -pedantic -Wextra -Werror -ansi -std=c99 -D_ROM=$(ROM_NAME) -D_VBA=$(VBASIM)
CC_WRAP            = $(CCPATH)/gcc
CFLAGS_WRAP        = -O2 -Wall -pedantic -Wextra -Werror -ansi -std=c99 -D_ROM='"$(ROM_NAME)"' -D_VBA='"$(VBASIM)"'

# --- Linker
LD                 = $(DKPATH)/arm-eabi-gcc
LDFLAGS            = $(SPECS) $(MODEL) -lm

# --- Object/Executable Packager
OBJCOPY            = $(DKPATH)/arm-eabi-objcopy
OBJCOPYFLAGS       = -O binary

# --- ROM Fixer
GBAFIX             = $(DKPATH)/gbafix

# --- Delete
RM                 = rm -f

OBJECTS = $(filter-out gba_wrapper%,$(SOURCES:.c=.o))

# --- Main build target
all : build $(BIN_NAME)

run : build
    $(VBASIM) $(ROM_NAME)

build : UNZIP $(ROM_NAME)

$(BIN_NAME) : gba_wrapper.c
    $(CC_WRAP) $(CFLAGS_WRAP) -o $@ $^

# --- Build .elf file into .gba ROM file
$(ROM_NAME) : $(ELF_NAME)
    $(OBJCOPY) $(OBJCOPYFLAGS) $(ELF_NAME) $(ROM_NAME)
    $(GBAFIX) $(ROM_NAME)

# --- Build .o files into .elf file
$(ELF_NAME) : $(OBJECTS)
    $(LD) $(OBJECTS) $(LDFLAGS) -o $@

# -- Build .c files into .o files
$(OBJECTS) : %.o : %.c
    $(CC) $(CFLAGS) -c $< -o $@

# ============ RELEASE MODE
else
# ============ DEBUG MODE
# --- Compiler
CC                 = $(CCPATH)/gcc
CFLAGS             = -D_DEBUG -O2 -Wall -pedantic -Wextra -Werror -ansi -std=c99 -ggdb

all : build

run : build
    ./$(BIN_NAME)

clean :

build : UNZIP $(BIN_NAME)

$(BIN_NAME) : $(SOURCES)
    $(CC) -o $(BIN_NAME) $(CFLAGS) $(SOURCES)

# ============ DEBUG MODE
endif

# ============ Common
UNZIP :
    -@$(FIND) . -iname "*.zip" -exec unzip -n {} \; -exec echo "This project must be rebuilt" \; -exec rm {} \;

clean:
    $(RM) $(ROM_NAME)
    $(RM) $(ELF_NAME)
    $(RM) $(BIN_NAME)
    $(RM) *.o
# ============ Common
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T01:04:10+00:00Added an answer on May 31, 2026 at 1:04 am

    I was missing the line REG_DISPCTL = MODE3 | BG2_ENABLE;

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Working in Java: I have a JFrame class, and separate classes for my two
Working on a project at the moment and we have to implement soft deletion
Working on a project that parses a log of events, and then updates a
Working with jquery.ajax for first time... I have a class in C#: public class
Working with a Lucene index, I have a standard document format that looks something
Working with a SqlCommand in C# I've created a query that contains a IN
Working in Eclipse on a Dynamic Web Project (using Tomcat (v5.5) as the app
Working on a project where a sequential set of methods must be run every
Working on calling a C function from my asm project. I'm trying to push
Working on an extension that use the new experimental devtools apis. How do you

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.