Using Eclipse as IDE

 

►Presentation

From some times now, we have C compilers for 68K modified to output Genesis rom.
I was always looking for a good IDE.
I know Stef's using Code::Blocks but ...I just don't like it myself.
Since I use Eclipse at work, I tried to use it at home too!
Here is how to do it.
Don't forget, you'll have to test yourself which one between Eclipse and Code::Blocks suits your need!

►Contents

Part 1 : Install and setup
- Download / Install
- Setup

Part 2 : First demo
- Stef's partic
- Update makefile
- Compile

Part 3 : Debugging

Part 4 : Setup additional tools
- MaccerX
- UCON64
- GenRes

 

►Part 1 : Install and setup

Download & Install

Before starting, you need 2 things :
- Gen's DevKit
- Eclipse CDT

If you could easily find Stef's GenDevKit on the forum or a mirror on my tools' page

For Eclipse, I think you sould try Yoxos Ondemand , it allows you to download an all-in-one page (Eclipse + CDT Plugin + other plugins of your choice)
So, select Eclipse C/C++ Development Tools (CDT), accept to add Eclipse core files and then, Start Download

Yoxos Ondemand

You now have 2 Zip files : GenDevKit04 and eclipseXXXXX.zip

Create a directory for Genesis development only, WITHOUT space or special chars (got some problems with them so...avoid!)
Unzip your 2 files there, rename GenDevKit one as "sdk" and create a directory called "projects".

workspace

You're now ready!

Setup

Open eclipse

first launch

Browse to your "projects" folder and don't forget to check the "Use this as the default and do not ask again"
The workspace is where every project created on Eclipse will be physically created / saved.

The first time I launched Eclipse, I was totally lost when I saw this screen :

help me!!

Don't panic ! You just need to click the "Workbench" button.

There, select Windows>Preferences...
First, select General>Workspace and click this damn 'Save automatically before build' checkbox
Optionnaly, you could uncheck the 'Build automatically' if you have a low powered PC (or use Vista)

save automatically

 

In, C/C++ > Environment, add your SDK\bin path
Be sure "Append variables to native environnement" is selected

SDK\bin

That's all, your workspace is now correctly installed !

 

►Part 2 : First demo

Stef's partic

Stef's GenDevKit comes with a demo called "partic".
Follow these steps to compile it under Eclipse

First we need to create a project called "partic" with File>New>Project...
New project

Create a "General" project
general

Call it "partic"
You could see "Use default location" is check and where your project "partic" will be save (for me e:/megadrive/projects/partic"

You must now add your source files.
Right click on your project and select "Import..."
Select General>File system...
Browse to your sdk\sample\partic folder
Select all the files and add them

We must also add the makefile
Same thing but browse to yout sdk\bin folder
Only add "makefile.gen"

Rename "makefile.gen" as "makefile"

 

Update makefile

The makefile included in Stef's GenDevKit is perfect for classic use.
But I updated it to be more flexible

It's very easy, I really dislike hard coded path so I used a variable to store GenDevKit path!

Here it comes :

#use only / and \ on path
GDK= D:/dev/megadrive/sdk/
CC= $(GDK)bin/gcc
OBJC= $(GDK)bin/objcopy
ASMZ80= $(GDK)bin/asmz80
BINTOC= $(GDK)bin/bintoc
#OPTION= -Dnologo_
SRC_C= $(wildcard *.c)
SRC_S= $(wildcard *.s)
SRC_SZ80= $(wildcard *.s80)
OBJ= $(SRC_SZ80:.s80=.o)
OBJ+= $(SRC_C:.c=.o)
OBJ+= $(SRC_S:.s=.o)
LINKOBJ= $(GDK)lib/sega.o \
     $(GDK)lib/base.o \
     $(GDK)lib/tools.o \
     $(GDK)lib/vdp.o \
     $(GDK)lib/font.o \
     $(GDK)lib/vdp_bg.o \
     $(GDK)lib/vdp_dma.o \
     $(GDK)lib/vdp_pal.o \
     $(GDK)lib/vdp_spr.o \
     $(GDK)lib/vdp_tile.o \
     $(GDK)lib/bitmap.o \
     $(GDK)lib/bitmapx.o \
     $(GDK)lib/z80_ctrl.o \
     $(GDK)lib/tab_sin.o \
     $(GDK)lib/tab_log2.o \
     $(GDK)lib/tab_pow2.o \
     $(GDK)lib/maths.o \
     $(GDK)lib/maths3D.o \
     $(GDK)lib/ym2612.o \
     $(GDK)lib/psg.o \
     $(GDK)lib/audio.o \
     $(GDK)lib/joy.o \
     $(GDK)lib/timer.o \
     $(GDK)lib/logo_lib.o \
     $(GDK)lib/z80_drv1.o \
     $(GDK)lib/z80_drv2.o \
     $(GDK)lib/z80_mvst.o \
     $(OBJ)
INCS= -I$(GDK)include
     FLAGS= $(OPTION) -m68000 -Wall -O1 -fomit-frame-pointer $(INCS)
     FLAGSZ80= -c -i -x1 -x2 -x3 -z -lnul
all: rom.bin
rom.bin: rom.out
     $(OBJC) --pad-to 131072 -O binary rom.out rom.bin
rom.out: $(OBJ)
     $(CC) -T $(GDK)bin/md.ld -nostdlib $(LINKOBJ) $(GDK)bin/libgcc.a -o rom.out
%.o80: %.s80
     $(ASMZ80) $(FLAGSZ80) -o$@ $<
%.c: %.o80
     $(BINTOC) $<
%.o: %.c
     $(CC) $(FLAGS) -c $< -o $@
%.o: %.s
     $(CC) $(FLAGS) -c $< -o $@

 

Use this one or search/replace feature ;)

 

Compile

I choose Eclipse CDT because, in fact, it handles makefile project.
So, all the power is only in this makefile. Eclipse doesn't care of which compiler, which system you compile for, etc... yes, you could use this same environment to develop for PSP if you want!

But for that, we must have a "Makefile project"
At this time we have a "General project" so....

Right click on project, New>Convert to a C/C++ Make Project

convert to makefileproject

We came from C language so be sure to select it

C project

At this time, Eclipse could ask you to switch to C/C++ perspective, answer yes since we need a view from this perspective

You know have a "Make" view (it must be full right ), right click on 'partic' to add a target

add a make target

 

You can now add your "Make" target

partic make

Some info for future use
Target name is the name shown on the Make view
Make Target is the target (!) asked to make like 'all','clean', 'debug'....leave it blank by default
Build comand is the command to call

So, if you want, you'll be easily able to call something like

make -f mymakefile
make clean

Right click on the 'partic' target you just created and select 'Build target'
(optionnal if you checked 'Build automatically')

et voilà!

Stef's partic

 

Now, if you want, you can make some change to partic code.
All you need to do is right click on partic Make target and...Build target!

►Part 3 : Debugging

As you should know, Gens KMod lacks some features to be a 'really' debugger like trace, breakpoint.
It's why I added 2 ways to inspect your value : debug register and watchers.
The debug register is a new register I added to let you send informations from your code to Gens KMod console.
The watchers lets you 'watch' rom or ram addresses.
If the debug register is easy to use, the watcher is only usable for hacking an existing game...since your code-defined variable addresses change each time you compile.
You so have to find each of your variable addresses and enter each one in watchers list....very boring!

While talking with Fonzie about a way to do this, he talked me about map.exe and nm.exe, after some hours, nm2wch was born.
This little tool is very useful : it creates the watcher list for you !

First you need nm.exe from binutils package, since it's not included in GenDevKit.
Then nm2wch for my website.
Copy these two tools in sdk\bin and modify your makefile

NM= $(GDK)bin/nm
NM2WCH= $(GDK)bin/nm2wch

and

rom.bin: rom.out
$(NM) -n -S -t x rom.out >rom.nm
$(NM2WCH) rom.nm rom.wch
$(OBJC) --pad-to 131072 -O binary rom.out rom.bin

These lines
- create a textfile describing your variables (rom.nm)
- convert this formatted textfile to a GensKMod watcher file

Unfortunatly, we have a problem : nm can't output directly to a textfile, it's why I use >rom.nm
But this command will produce an error if you try to build your makefile make: /bin/sh: Command not found
What is /bin/sh ?!! sh.exe is the default shell gcc is looking for.
We could download and copy it on our sdk\bin folder OR, for Windows users, change the default shell to existing one adding a single line at the top of the makefile

SHELL = c:/windows/system32/cmd.exe

Ok now, if your makefile successfully produce your rom with its linked rom.wch, launch Gens Kmod 0.7b+
Be sure "Auto load watchers & structures" is selected in Options>Debug...
Open your rom and open the watchers window : all your variables are here, you can now easily follow their values while playing !

 

►Part 4 : Setup additional tools

Maccer

Maccer is a tool I can't live without !
I often produce my gfx or sound files with my own tools, so I use Maccer to include them.
It's a replacement for 'bintoc', included in GenDevKit.
I made my own version of Maccer to support every Genesis C compilers.
For more info and to download it, see MaccerX page

UCON64

I use UCON64 to fix the checksum, pad the rom and convert it to a SMD file.
If you have a backup device, you also could send the produced rom directly to your backup device!
It's a replacement for 'objcopy', included in GenDevKit.
Just download and unzip it to our sdk\bin folder and modify the makefile to use it

$(UCON)=$(GDk)bin/ucon64/ucon64

GenRes

GenRes is my last gift to the genny dev scene.
If you already made some Windows development, you should be familiar with WinRes. GenRes is similar.
Throught a resource file, you can define resource to be used in your game.
Include bitmap, sound and much more WITHOUT additional tools.
You no longer need b2t or mmm, they are now available throught GenRes.
And if you want to add support to your own resource, just write the plugin needed !
Oh, and since a lot of you use Pascal's genitile, I wrote a plugin to access genitile features from GenRes.
For more info and to download it, see GenRes page.

►More info

Video tutorial, covers part 1 & 2

Eclipse CDT homepage (advanced users only)