Skip to content
Permalink
Browse files

First commit

  • Loading branch information...
brovador committed Jun 26, 2016
0 parents commit adaaa1981d23f2d6b0e5212a1b4d9053ae977196
@@ -0,0 +1,3 @@
/obj
/dist
/emulator
@@ -0,0 +1,22 @@
ROM_NAME=rom.gb
BIN=./bin
OBJ=./obj
DIST=./dist
SRC=./src
EMULATOR=./emulator



build:
mkdir -p $(OBJ)
mkdir -p $(DIST)
$(BIN)/gbdk-n-compile.sh $(SRC)/main.c -o $(OBJ)/main.rel
$(BIN)/gbdk-n-link.sh $(OBJ)/main.rel -o $(OBJ)/main.ihx
$(BIN)/gbdk-n-make-rom.sh $(OBJ)/main.ihx $(DIST)/$(ROM_NAME)

clean:
rm -rf $(OBJ)
rm -f $(DIST)/$(ROM_NAME)

run:
wine $(EMULATOR)/bgb.exe $(DIST)/$(ROM_NAME)
@@ -0,0 +1,7 @@
#!/bin/sh

GBDK_DIR="$( cd "$( dirname "$0" )" && pwd )/.."

set -x

sdasgb -plosgff -I"libc" "$@"
@@ -0,0 +1,7 @@
#!/bin/sh

GBDK_DIR="$( cd "$( dirname "$0" )" && pwd )/.."

set -x

sdcc -mgbz80 --no-std-crt0 -I "$GBDK_DIR/include" -I "$GBDK_DIR/include/asm" -c "$@"
@@ -0,0 +1,7 @@
#!/bin/sh

GBDK_DIR="$( cd "$( dirname "$0" )" && pwd )/.."

set -x

sdcc -mgbz80 --no-std-crt0 --data-loc 0xc0a0 -I "$GBDK_DIR/include" -I "$GBDK_DIR/include/asm" -L "$GBDK_DIR/lib" "$GBDK_DIR/lib/crt0.rel" -l gb.lib -o a.ihx "$@"
@@ -0,0 +1,5 @@
#!/bin/sh

set -x

makebin -Z "$@"
@@ -0,0 +1,4 @@
#define USE_C_MEMCPY 1
#define USE_C_STRCPY 1
#define USE_C_STRCMP 1

@@ -0,0 +1,18 @@
#ifndef ASM_GBZ80_STDARG_INCLUDE
#define ASM_GBZ80_STDARG_INCLUDE

/* sdcc pushes right to left with the real sizes, not cast up
to an int.
so printf(int, char, long)
results in push long, push char, push int
On the z80 the stack grows down, so the things seem to be in
the correct order.
*/

typedef unsigned char * va_list;
#define va_start(list, last) list = (unsigned char *)&last + sizeof(last)
#define va_arg(list, type) *((type *)((list += sizeof(type)) - sizeof(type)))

#define va_end(list)

#endif
@@ -0,0 +1,43 @@
/** @file asm/gbz80/types.h
Types definitions for the gb.
*/
#ifndef ASM_GBZ80_TYPES_INCLUDE
#define ASM_GBZ80_TYPES_INCLUDE

#if SDCC_PORT!=gbz80
#error gbz80 only.
#endif

#define NONBANKED __nonbanked
#define BANKED __banked

/** Signed eight bit.
*/
typedef char INT8;
/** Unsigned eight bit.
*/
typedef unsigned char UINT8;
/** Signed sixteen bit.
*/
typedef int INT16;
/** Unsigned sixteen bit.
*/
typedef unsigned int UINT16;
/** Signed 32 bit.
*/
typedef long INT32;
/** Unsigned 32 bit.
*/
typedef unsigned long UINT32;

#ifndef __SIZE_T_DEFINED
#define __SIZE_T_DEFINED
typedef unsigned int size_t;
#endif

/** Returned from clock
@see clock
*/
typedef UINT16 clock_t;

#endif
@@ -0,0 +1,65 @@
/** @file asm/types.h
Shared types definitions.
*/
#ifndef ASM_TYPES_INCLUDE
#define ASM_TYPES_INCLUDE

#if SDCC_PORT == gbz80
#include <asm/gbz80/types.h>
#elif SDCC_PORT == z80
#include <asm/z80/types.h>
#else
#error Unrecognised port
#endif

#ifndef NONBANKED
#define NONBANKED
#endif

#ifndef BANKED
#define BANKED
#endif

/** TRUE or FALSE.
*/
typedef INT8 BOOLEAN;

#if BYTE_IS_UNSIGNED

typedef UINT8 BYTE;
typedef UINT16 WORD;
typedef UINT32 DWORD;

#else

/** Signed 8 bit.
*/
typedef INT8 BYTE;
/** Unsigned 8 bit.
*/
typedef UINT8 UBYTE;
/** Signed 16 bit */
typedef INT16 WORD;
/** Unsigned 16 bit */
typedef UINT16 UWORD;
/** Signed 32 bit */
typedef INT32 LWORD;
/** Unsigned 32 bit */
typedef UINT32 ULWORD;
/** Signed 32 bit */
typedef INT32 DWORD;
/** Unsigned 32 bit */
typedef UINT32 UDWORD;

/** Useful definition for fixed point values */
typedef union _fixed {
struct {
UBYTE l;
UBYTE h;
} b;
UWORD w;
} fixed;

#endif

#endif
@@ -0,0 +1,3 @@
#undef USE_C_MEMCPY
#undef USE_C_STRCPY
#undef USE_C_STRCMP
@@ -0,0 +1,20 @@
#ifndef ASM_Z80_STDARG_INCLUDE
#define ASM_Z80_STDARG_INCLUDE

/* sdcc pushes right to left with the real sizes, not cast up
to an int.
so printf(int, char, long)
results in push long, push char, push int
On the z80 the stack grows down, so the things seem to be in
the correct order.
*/

typedef char * va_list;
#define va_start(list, last) list = (char *)&last + sizeof(last)
#ifdef STDIO_INCLUDE
#define va_arg(list, type) *(type *)list; list + sizeof(type)
#else
#define va_arg(list, type) (list + sizeof(type), *(type *)(list - sizeof(type)))
#endif

#endif
@@ -0,0 +1,18 @@
#ifndef ASM_Z80_TYPES_INCLUDE
#define ASM_Z80_TYPES_INCLUDE

#if SDCC_PORT!=z80
#error z80 only.
#endif

typedef char INT8;
typedef unsigned char UINT8;
typedef int INT16;
typedef unsigned int UINT16;
typedef long INT32;
typedef unsigned long UINT32;

typedef int size_t;
typedef UINT16 clock_t;

#endif
@@ -0,0 +1,83 @@
/** @file gb/cgb.h
Support for Color GameBoy.
*/

#ifndef _CGB_H
#define _CGB_H

/** Macro to create a palette entry out of the color components.
*/
#define RGB(r, g, b) \
((((UINT16)(b) & 0x1f) << 10) | (((UINT16)(g) & 0x1f) << 5) | (((UINT16)(r) & 0x1f) << 0))

/** Common colors based on the EGA default palette.
*/
#define RGB_RED RGB(31, 0, 0)
#define RGB_DARKRED RGB(15, 0, 0)
#define RGB_GREEN RGB( 0, 31, 0)
#define RGB_DARKGREEN RGB( 0, 15, 0)
#define RGB_BLUE RGB( 0, 0, 31)
#define RGB_DARKBLUE RGB( 0, 0, 15)
#define RGB_YELLOW RGB(31, 31, 0)
#define RGB_DARKYELLOW RGB(21, 21, 0)
#define RGB_CYAN RGB( 0, 31, 31)
#define RGB_AQUA RGB(28, 5, 22)
#define RGB_PINK RGB(11, 0, 31)
#define RGB_PURPLE RGB(21, 0, 21)
#define RGB_BLACK RGB( 0, 0, 0)
#define RGB_DARKGRAY RGB(10, 10, 10)
#define RGB_LIGHTGRAY RGB(21, 21, 21)
#define RGB_WHITE RGB(31, 31, 31)

#define RGB_LIGHTFLESH RGB(30, 20, 15)
#define RGB_BROWN RGB(10, 10, 0)
#define RGB_ORANGE RGB(30, 20, 0)
#define RGB_TEAL RGB(15, 15, 0)

/** Set bkg palette(s).
*/
void
set_bkg_palette(UINT8 first_palette,
UINT8 nb_palettes,
UINT16 *rgb_data) NONBANKED;

/** Set sprite palette(s).
*/
void
set_sprite_palette(UINT8 first_palette,
UINT8 nb_palettes,
UINT16 *rgb_data) NONBANKED;

/** Set a bkg palette entry.
*/
void
set_bkg_palette_entry(UINT8 palette,
UINT8 entry,
UINT16 rgb_data);

/** Set a sprite palette entry.
*/
void
set_sprite_palette_entry(UINT8 palette,
UINT8 entry,
UINT16 rgb_data);

/** Set CPU speed to slow operation.
Make sure interrupts are disabled before call.
@see cpu_fast
*/
void cpu_slow(void);

/** Set CPU speed to fast operation.
Make sure interrupts are disabled before call.
@see cpu_slow
*/
void cpu_fast(void);

/** Set defaults compatible with normal GameBoy.
*/
void cgb_compatibility(void);

#endif /* _CGB_H */
@@ -0,0 +1,33 @@
/** @file gb/console.h
Console functions that work like Turbo C's.
Note that the font is 8x8, making the screen 20x18 characters.
*/
#ifndef _CONSOLE_H
#define _CONSOLE_H

#include <types.h>

/** Move the cursor to an absolute position.
*/
void
gotoxy(UINT8 x,
UINT8 y);

/** Get the current X position of the cursor.
*/
UINT8
posx(void);

/** Get the current Y position of the cursor.
*/
UINT8
posy(void);

/** Writes out a single character at the current cursor
position.
Does not update the cursor or interpret the character.
*/
void
setchar(char c);

#endif /* _CONSOLE_H */

0 comments on commit adaaa19

Please sign in to comment.
You can’t perform that action at this time.