Thursday, March 17, 2016

3D City Code Complete

3D City is a simple "Shoot 'em up" video game originally programmed StevePro Studios in New Zealand, in January 1988. The game was written using BASIC programming language built on the Sega SC-3000.

Inspired from previous posts on Sega Console Programming and z88dk Programming Setup, 3D City was the impetus to build an 8-bit video game in C / Z80 assembler to target the Sega Master System (SMS).

Let's check it out!
Download source code here.

Sega Retro Gaming post documents how to play video games like 3D City on PC using Fusion emulator.
z88dk Programming Setup post documents development environment required to build C / Z80 source.
Instructions
Simple! Move target and shoot all enemy ships before they kill you. 4x misses and it is Game Over.
Hint: hold controller Button2 down while moving target slows target down for more focused attack.

ROM Hacking
You can hack this ROM! Download and dump 3Dcity.sms into Hex Editor, e.g. HxD, and modify the bytes:
 ADDRESS  VARIABLE  DESCRIPTION
 0x00C0  Death  Non-zero = invincibility!
 0x00C1  Level  0=easy (default) 1=hard.
 0x00C2  Enemy  0=3x enemies else 1 or 2.
 0x00C3  Music  0=music on otherwise off.
 0x00C4  Sound  0=sound on otherwise off.
 0x00C5  Tiles  0=tiles scroll yes else no.
 0x00C6  Stars  0=stars flash yes else no.
#ifndef _HACK_MANAGER_H_
#define _HACK_MANAGER_H_

#define PEEK(addr)   (*(unsigned char *)(addr))
#define POKE(addr, data) (*(unsigned char *)(addr) = (data))

#define HACKER_START  0x00C0

extern unsigned char hacker_death, hacker_level, hacker_enemy, hacker_music;
extern unsigned char hacker_sound, hacker_tiles, hacker_stars;

void engine_hack_manager_init()
{
  hacker_death = PEEK(HACKER_START + 0);  // 0x00C0
  hacker_level = PEEK(HACKER_START + 1);  // 0x00C1
  hacker_enemy = PEEK(HACKER_START + 2);  // 0x00C2
  hacker_music = PEEK(HACKER_START + 3);  // 0x00C3
  hacker_sound = PEEK(HACKER_START + 4);  // 0x00C4
  hacker_tiles = PEEK(HACKER_START + 5);  // 0x00C5
  hacker_stars = PEEK(HACKER_START + 6);  // 0x00C6
}

#endif//_HACK_MANAGER_H_
Credits
StevePro Studios would like to thank the following, esp. at SMS Power, for making this project possible:
 haroldoop  Adapt z88dk (C cross-compiler) for Z80 systems + generate SMS ROMs
 Maxim  BMP2Tile  Converts BMP images into 8x8 SMS tile data
 Martin  Mod2PSG2  Music tracker software for SMS sound chip
 vhelin  WLA-DX  Z80 multi platform cross Assembler package
 Martin  SMS Examine  Z80 disassembler recompilable by WLA-DX
 Bock  Meka  SMS emulator (excellent debugging features)
 Steve Snake  Fusion  SMS emulator used for general play testing
Important: the psgmod.asm file (Mod2PSG2) was customized thus ASM could be invoked from C code.

Summary
In fact, the Homebrew community at SMS Power celebrates Sega 8-bit preservation and fanaticism each year with its annual competitions. Therefore, this is an opportunity to enter 3D City for 2016. Good luck!