Saturday, March 19, 2022

Crystal Castles Source Files

In my last post I gave an overview of the files in the Historical Source Code  repository for Atari's Crystal Castles arcade game. In this post I will go into the files in detail. Here are the files in alphabetical order:

C00.DAT - C33.DAT : These contain the level data. I will go into these in more detail in a later post.

BITPAT.MAC: This files contains 8 bytes, represented as binary numbers in the file. The file is included into CEL.MAC and appears between two subroutines. It doesn't appear that this data is actually used by the game. It might be some sort of security or anti-piracy protection.

C99.MAC: Links together all the level data. This is assembled separately from the main program and becomes the second bank of ROMs.

CAL.MAC: Handles the display of the score and the high score screen.

CATOUT.MAC: Displays the Atari Easter egg message. Shown on the next level after you have jumped 128 times on the previous level.

CCN.MAC: 650X 'Universal' coin routine. This is a standard code library for handling the coin mechanism.

CCT.MAC: Draws the levels

CCUBE.MAC: Draws a cube on the screen. This is only used by the special display that happens when you score over 700,000 points.

CDB.MAC:  Routine to transfer level data from ROM to RAM 

CEE.MAC: EEROM routines 

CEEDEF.MAC: definitions for EEROM routines

CEL.MAC: Elevator handling 

CEN.MAC: Main game logic

CET.MAC: Auxiliary EEROM information, tables, output routines etc.

CG.MAC:  Global definitions and memory allocation

CGR.MAC: Global data and routines

CIN.MAC: Interrupt handlers

CLS.MAC: Sound and music data

CMAC.MAC: A couple macros to simplify common 6502 tasks

CMN.MAC: Main loop

CMR.MAC: Message display routines

CMS.MAC: Word data

CMTB.MAC: Message table

CRF.MAC: Root file

CRP.MAC: RPM (Rusty's POKEY Music) Driver

CSL.MAC: Symbol shape data

CSS.MAC: Test menu

CST.MAC: Self test

CSTART.MAC: Includes macros and zero page definitions

CWV.MAC: Level handling

HLL65F.MAC: High level language macros

M6502.MAC:  6502 general purpose macros


CJTB.MAC: This file is missing from the archive but is included in CRP.MAC. It it a patch to the POKEY music driver. I recreated this file from the original ROMs.

Thursday, March 10, 2022

Crystal Castles Source File Overview

Recently Historical Source Code published the original source code for a couple Atari arcade games including Crystal Castles. In this post I will give an overview of the the files that are included in the archive. The files can be found here:

 https://github.com/historicalsource/crystal-castles

The archive contains three sets of files for Crystal Castles, the one in the root directory of the repository, which I will call the master set, and two others sets called version-2 and version-3. In this post I will focus on the master set, since the other two contain some different files. Using my assembler I was able to re-assemble the master set to produce the ROMs that match the MAME ccastles1 set. I still need to determine if the other two versions of the source match up with other MAME ROM sets. The main ROM set in MAME, ccastles, does not match any of the source in the archive. The first ROM has a copyright message in it and the MAME base set also contains the phrase "PIRATES BEWARE" which is not in any of the source. 

Here is an overview of the files in the archive:

372X1.DOC 

This appears to be some sort of standard form used by Atari to document game projects, since similar files appear in the repositories for other games. The file contains all the details of the ROMs that make up the game, a description of how to assemble the files and a signoff form at the bottom.

022X1.DAT

This contains a single line of ASCII data that provides details of the ROMs that make up the game. This file is referenced in 372X1.DOC and is called the "Verification control file". I still need to study this file some more to understand the format.

372BR.RS4

This file is referenced in 372X1.DOC and 022X1.DAT so has something to do with the verification process, but I am not sure what the data in it represents.

*.MAC

The .MAC files are the macro-assembler source files for the game. Most of the files are for the fixed ROM and the first ROM bank. C99.MAC and the .DAT files are for the second ROM bank. CRF.MAC is the root file, the other files are either included in CRF.MAC, or included into other includes. There was one file missing from the archive, CJTB.MAC, which is included into CRP.MAC. To be able to re-assemble the code I had to re-create this file from existing ROMs. I will look at these in more detail in a future post.

Cxx.DAT

These files contain the level data for the game and are included into C99.MAC. This is assembled separately and forms the second bank of ROM.

*.LDA

These are the binary output of the original assembler in a format that makes them linkable to other binaries to form the final output. I need to do some more research to figure out the format of these files. 



Saturday, March 5, 2022

Crystal Castles Source Code


I recently ran across a bunch of Atari arcade source code that was added to the Historical Source Github site, including the source for one of my favorite games, Crystal Castles.


https://github.com/historicalsource/crystal-castles


I thought it would be cool to be able to re-assemble this back into the original ROMs. I started by trying to find an existing assembler that could do this, but the assembler used for this source had a lot of syntactical differences and features I couldn't find in any other 6502 assembler. I assume Atari used a VAX based assembler and I did even find documentation for a VAX assembler with similar features, but still not an exact match. 


I then thought about manually modifying the source to work with an existing assembler. I quickly realized that this wasn't feasible due to some of the odd syntax in this assembler. For example the Atari assembler has an different syntax for addressing modes. You can write Zero Page X like this: "LDA ZX,$PSTSL", you couldn't fix this with a simple search and replace. This would also have to be done for every game I wanted to re-assemble. 


So I decided the best option was to build my own assembler that could handle these files with little changes to the original source. The assembler I build is now able to reassemble the main source from the historical source repository and reproduce the MAME ccastles1 ROM set. 


I have setup a GitHub repository to hold the C# source code for my assembler as well as tool to split the output into separate ROMs and handle the checksum process. There is also a folder there with the files and instructions needed to rebuild the source. There are some small changes needed to the source which I have documented in the instructions, and there was one file missing from the Historical Source archive which I re-created from the original ROMs. 


https://github.com/danlb2000/AT6502