Skip to content

Learning how to display Mega Drive graphics in 68000 assembly

Notifications You must be signed in to change notification settings

sroccaserra/learning-megadrive

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Learning how to display Mega Drive graphics in 68000 assembly.

I use the m68k vasm assembler with Motorola syntax, and the Mega Drive startup kit from the awesome Gamehut Youtube channel.

Prerequisites

Download the vasm tarball and build vasmm68k_mot with these options from the compilation instructions:

make CPU=m68k SYNTAX=mot

Now you need to have the vasmm68k_mot executable in your path somehow, see how it's done depending on your OS / shell.

Build the rom.bin file

To build the bin/rom.bin file from the assembly source code, run:

make

Run the rom.bin file

Open the generated bin/rom.bin file in your favourite Mega Drive emulator, it should display a scrolling checkboard :)

There is a run target in the Makefile, but it won't work for you unless you override the EMULATOR_PATH, EMULATOR_CMD, and ROM_PATH env variables. Chances are you don't have the same emulator installed in the exact same path as I do :)

Tools

To include the graphics in the cartridge ROM, it's easier to have the corresponding index and palette data in a binary format ready to inject in the Mega Drive VDP (Video Display Processor).

But I wanted to be able to edit the graphic assets with standard tools like GIMP, so the assets are images in indexed PNG format.

So I needed tools to extract the index and palette data from the PNG indexed images, and convert them to the right VDP binary formats. The VDP needs raw 8x8 nibble tiles representing indexes for graphics, each index points to a color in a 16 colors palette. And a 16 color palette is represented by 16 words, each word represents a color and is arranged in this order: 0000 bbb0 ggg0 rrr0. (This means that there are 3 bits per color component, so a palette is a 16 color set within a total of 2^3*2^3*2^3 = 512 possible colors.)

That's what the Python scripts in the tools/ directory do, they convert the index and palette data (16 first colors only) from the PNG images to binary formats ready to include in the cartridge rom. I used the .gfx and .pal extensions for the binary formats representing these data. The .gfx and .pal files are generated in the bin directory, they are not included in the source code.

See the Makefile and Python scripts & tests for more details.

Todo

Maybe:

  • Complete part 3 of GameHut tutorial
  • Add tiled font and try drawing text
  • Add support for 24bpp PNG files for PNG assets, build color palette as new colors are found (exception if > 16?)
  • Check that asset width & heigth are multiples of 8
  • Add info about assets dimentions in file names (so it's easier to remember while reading assembly code including them)

References

About

Learning how to display Mega Drive graphics in 68000 assembly

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published