Compiling Secret Scout's source code?

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

Post Reply
Weg
Posts: 6
Joined: Wed Mar 18, 2020 1:18 pm

Compiling Secret Scout's source code?

Post by Weg » Wed Mar 18, 2020 3:59 pm

Hello! It's my first post here, so I hope that I'm doing it in the right place. This category seemed like the most fitting for this question, since it's probably an easy answer that I only don't know because I've never programmed for the NES!

Secret Scout in The Temple of Demise, the unlicensed game by Color Dreams, has had its source code released online for some time now. Despite me really not being a programmer, it's not very difficult to understand what some of the files at least are, but I couldn't find how to compile changes made to them into a rom.
Of the 24 files in the source, 7 of them are Assembly code, 1 of them is a DRW file that can be read by Color Dreams' NinDraw, and the others are PRG, VID, OBJ, LST, and SEG files, and I don't know what they are.
The source also comes with 2 BAT files, one that I'm not really sure what is supposed to do, and the other that actually makes a working rom out of the files, but, of the 24 files in the source, it actually only compiles 2 of them, AZTECD.PRG and AZTECD.VID, which are, I believe, already compiled versions of everything else, since they literally are the final code in HEX, but split in half. The rom compiler doesn't do anything more than to put them together into a .nes file.

Other Color Dreams source codes include some executables that seem to be an answer, but I can't figure them out. A65 is a compiler that can make hex out of Assembly files, and NinLink seems to be what puts these files together into something that could be what are the final files that get compiled into the .nes rom, but I can't get that to work, and there is also NinBug, a game debugger.

So, this is my question! How can I edit the source files, compile them, and then compile them into a rom that has these changes.. or something? Heheh, this is pretty confusing to me. Thank you for reading!

EDIT: I think what I'm actually trying to do is compile the entire .DRW file into a .VID file, since it is all of the graphics in general, and all of the .ASM files into a single .PRG file, since the X.BAT only covers CODE and MEMORY, which then don't work when the game is compiled. Heheh, either that, or I'm using X.BAT wrong!
Last edited by Weg on Thu Mar 19, 2020 12:30 am, edited 1 time in total.

User avatar
dougeff
Posts: 2679
Joined: Fri May 08, 2015 7:17 pm
Location: DIGDUG
Contact:

Re: Compiling Secret Scout's source code?

Post by dougeff » Wed Mar 18, 2020 7:22 pm

Sounds like you have it mostly figured out. If there are bat files, then this was run on a DOS computer. I would assume it needs DOSBOX to run the .exe programs.

Given that the final 2 ROMs are called .PRG and .VID, I would assume that all .PRG are assembled code. All .VID are NES format 2bpp graphics.

The assembler A65 probably takes the source code, and produces object files OBJ. LST is probably a listing of labels of assembled code, used perhaps for debugging. Seg ... IDK. Probably short for segment. Could be part of the linking system.

You mentioned source files. 7 assembly code. That is what you should be looking at.

Probably simpler than figuring how to get this stuff to work would be porting it to a current assembler.

The graphics can be grabbed from a good dump of the actual game. Forget the source code for that.
nesdoug.com -- blog/tutorial on programming for the NES

Weg
Posts: 6
Joined: Wed Mar 18, 2020 1:18 pm

Re: Compiling Secret Scout's source code?

Post by Weg » Wed Mar 18, 2020 8:07 pm

dougeff wrote:
Wed Mar 18, 2020 7:22 pm
Sounds like you have it mostly figured out. If there are bat files, then this was run on a DOS computer. I would assume it needs DOSBOX to run the .exe programs.

Given that the final 2 ROMs are called .PRG and .VID, I would assume that all .PRG are assembled code. All .VID are NES format 2bpp graphics.

The assembler A65 probably takes the source code, and produces object files OBJ. LST is probably a listing of labels of assembled code, used perhaps for debugging. Seg ... IDK. Probably short for segment. Could be part of the linking system.

You mentioned source files. 7 assembly code. That is what you should be looking at.

Probably simpler than figuring how to get this stuff to work would be porting it to a current assembler.

The graphics can be grabbed from a good dump of the actual game. Forget the source code for that.
In this time, I have figured out pretty much all of those things by now, and all you've said is what I was thinking! That's what all of these files are, nice!
Now, what is that about a currect assembler? I've tried to look for one, but I wasn't able to make any work with these files, but that's probably my fault. Do you have a recommendation for one?

User avatar
dougeff
Posts: 2679
Joined: Fri May 08, 2015 7:17 pm
Location: DIGDUG
Contact:

Re: Compiling Secret Scout's source code?

Post by dougeff » Wed Mar 18, 2020 8:59 pm

I'm looking at the files now.

Actually, I think it would be slow... but doable... to convert these asm files to work with a current assembler syntax.

Some of it could be done with a find and replace filter, such as H' to $ for hexadecimal.

I have a feeling that .DRW means output a 16 bit address (data write word) replace with .dw

The .equ commands look like defining constants. Will probably have to be changed by hand.

But, I think the sound data is missing, unless it has been pre-assembled into sound.prg.


Interesting... kungfu.doc seems to document a scripting system for enemy AI. Or something.

Looks like they originally wanted to call this game either Kung Fu or Aztec. Fascinating stuff.

The .org statements make this mostly incompatible with ca65, but maybe asm6 could do it if you made lots of changes.
nesdoug.com -- blog/tutorial on programming for the NES

User avatar
Memblers
Site Admin
Posts: 3831
Joined: Mon Sep 20, 2004 6:04 am
Location: Indianapolis
Contact:

Re: Compiling Secret Scout's source code?

Post by Memblers » Wed Mar 18, 2020 9:06 pm

Color Dreams source code is interesting, the game engine is written in 6502 (KUNGFU.ASM), but the game itself (KUNGTAB.ASM, YOURCODE.ASM) looks like some kind of script made up of constants defined with .DB and .DRW

The asm code includes some usage instructions:

Code: Select all

;			HOW THIS STATE MACHINE WORKS:
;
;TO ASSEMBLE, YOU JUST RUN A65 KUNGFU.  THE KUNGFU.ASM FILE "INCLUDES"
;ALL NECESSARY FILES.  THESE FILES ARE KUNGSUBS.ASM, KUNGTAB.ASM,
;YOURBACK.ASM, YOURCODE.ASM, YOURSND.ASM, AND DRAWDATA.ASM.  
;YOURBACK AND DRAWDATA ARE MADE AUTOMATICALLY
;BY THE ND.EXE DRAWING PROGRAM.  YOURBACK HAS BACKGROUND DATA FOR THE
;SECOND ROM PAGE AND DRAWDATA HAS PALETTE/SPRITE DEFFINITIONS.  KUNGSUBS
;HAS SUBROUTINES THAT GO DIRECTLY TO THE HARDWARE.  KUNGFU IS THE STATE
;MACHINE EXECUTION MAINLINE.  KUNGTAB IS WHERE YOU PUT YOUR GAME PLAY
;DATA.  YOURCODE AND YOURSND ARE EXPLAINED AT THE TOP OF KUNGTAB.ASM.
;THE RESULT OF THE ASSEMBLY IS CODE.PRG WHICH IS LOADED WITH
;THE COLOR DREAMS DEBUGGER BOARD FOR THE NES.  IT WILL HAVE 2 32K SEGMENTS
;EACH WITH A 6 BYTE HEADER.  THE FIRST LOADS INTO PAGE 0 AND THE SECOND
;INTO PAGE 1.  YOU MUST ALSO HAVE YOUR .VID FILE WHICH IS ALSO CREATED
;AUTOMATICALLY BY THE DRAWING PROGRAM.
;
;THE STATE MACHINE USES THE DATA YOU PLACE IN KUNGTAB TO EXECUTE THE 
;GAME.  THERE ARE 3 MAIN THINGS YOU DO IN KUNGTAB.  YOU DEFINE WORLDS
;WHICH ARE BACKGROUNDS AND PALETTES.  YOU DEFINE "ENTITIES" WHICH ARE
;MOVING SPRITES.   FINALLY, YOU DEFINE THINGS IN THE BACKGROUND WHICH
;INTERACT WITH THE SPRITES.  YOU NEED TO CHECK OUT KUNGTAB.ASM AND SIMPLY
;GO THROUGH IT LINE BY LINE SETTING THE DEFINED PARAMETERS IF YOU WANT
;LEARN TO USE THE STATE MACHINE.  THIS MODULE SHOULD OPERATE TRANSPARENTLY
;TO YOU, YOU SHOULD NOT MAKE MODIFICATIONS HERE.  

;AT BOOT THIS PROGRAM SIMPLY ACTIVATES WORLD #0 AND ITS UP TO YOU TO
;DETECT RESET, INITIALIZE FLAGS, AND LOOK FOR THE START KEY. 
;CHECKOUT KUNGTAB AND BE METHODICAL ABOUT SETTING AND UNDERSTANDING 
;EACH ENTRY.
And here are the contents of x.bat (dated 1990-12-21):

Code: Select all

A65 -L KUNGFU >TEMP
TYPE TEMP
PAUSE
COPY CODE.SEG CODE.OBJ
COPY MEMORY.SEG MEMORY.OBJ
NINLINK CODE MEMORY
COPY CODE.PRG AZTEC.PRG
DEL CODE.PRG
The SAVE.BAT file that makes an NES is obviously made later when the source was released (2003-06-08)

You need to run that X.BAT in DOSBox. To see the result, look at the file "TEMP" that gets created by the "A65 -L > TEMP" command. The > symbol means to redirect output to that file instead of the screen. Then it does TYPE TEMP to display it on the screen (so it gets saved and printed to the screen). And we can see here that the .SEG and .OBJ files are the same.

Shouldn't the COPY command be COPY /B? Maybe it does matter if you're not appending files together. I would have used 'rename', myself. We don't know what DOS version they were using (but I imagine the main commands like COPY are pretty much compatible between versions).

edit: nevermind about the copy /B, the .SEG/.OBJ files are hex in ASCII, like you already said.

Weg
Posts: 6
Joined: Wed Mar 18, 2020 1:18 pm

Re: Compiling Secret Scout's source code?

Post by Weg » Thu Mar 19, 2020 12:30 am

I think what I'm actually trying to do is compile the entire .DRW file into a .VID file, since it is all of the graphics in general, and all of the .ASM files into a single .PRG file, since the X.BAT only covers CODE and MEMORY, which then don't work when the game is compiled. Heheh, either that, or I'm using X.BAT wrong!

User avatar
Memblers
Site Admin
Posts: 3831
Joined: Mon Sep 20, 2004 6:04 am
Location: Indianapolis
Contact:

Re: Compiling Secret Scout's source code?

Post by Memblers » Thu Mar 19, 2020 5:13 am

It says "YOU MUST ALSO HAVE YOUR .VID FILE WHICH IS ALSO CREATED AUTOMATICALLY BY THE DRAWING PROGRAM."

So, it sounds like you need to figure out how to load the DRW into NinDraw and have it create those files.. automatically?

Maybe not a problem here, but at one time I remember having problems with Windows not letting DOSBox create files. I usually just ran it in administrator mode after that.

Weg
Posts: 6
Joined: Wed Mar 18, 2020 1:18 pm

Re: Compiling Secret Scout's source code?

Post by Weg » Thu Mar 19, 2020 11:15 am

Memblers wrote:
Thu Mar 19, 2020 5:13 am
It says "YOU MUST ALSO HAVE YOUR .VID FILE WHICH IS ALSO CREATED AUTOMATICALLY BY THE DRAWING PROGRAM."
I have been trying that, but no luck. NinDraw can actually export graphical banks to VID(just one at a time, but they can probably be put together), but the thing is, the actual level assembly, sprite assembly, animation, and palettes seem to only be exportable to uncompiled ASM code. NinDraw can also export ASM files YOURBACK, DRAWDATA and PALETTES which probably contain all of these 4 things together, but compiling this code into the game is the tricky part

Weg
Posts: 6
Joined: Wed Mar 18, 2020 1:18 pm

Re: Compiling Secret Scout's source code?

Post by Weg » Thu Mar 19, 2020 3:47 pm

I think I noticed something important!
The AztecD files are the final code and graphics that runs on Nintendo when you compile the rom, but if you look at them, you can see that they're basically alternate versions of the Aztec files. If you put AztecD's VID graphics on NinDraw, they will look like a corrupt version of Aztec's. Weird thing is, if you put Aztec's graphics with AztecD's code and then compile, the graphics on the rom will look like what the AztecD graphics look like before being put on the rom, on NinDraw.
This must mean that there's.. another kind of conversion or compiling that has to be done for the game to work!

EDIT: I discovered that the Aztec files actually had a bunch of headers in them, so just taking them out of the code actually fixes them completely

Weg
Posts: 6
Joined: Wed Mar 18, 2020 1:18 pm

Re: Compiling Secret Scout's source code?

Post by Weg » Fri Mar 20, 2020 7:32 pm

Memblers wrote:
Wed Mar 18, 2020 9:06 pm

Code: Select all

;			HOW THIS STATE MACHINE WORKS:
;
;TO ASSEMBLE, YOU JUST RUN A65 KUNGFU.  THE KUNGFU.ASM FILE "INCLUDES"
;ALL NECESSARY FILES.  THESE FILES ARE KUNGSUBS.ASM, KUNGTAB.ASM,
;YOURBACK.ASM, YOURCODE.ASM, YOURSND.ASM, AND DRAWDATA.ASM.  
;YOURBACK AND DRAWDATA ARE MADE AUTOMATICALLY
;BY THE ND.EXE DRAWING PROGRAM.  YOURBACK HAS BACKGROUND DATA FOR THE
;SECOND ROM PAGE AND DRAWDATA HAS PALETTE/SPRITE DEFFINITIONS.  KUNGSUBS
;HAS SUBROUTINES THAT GO DIRECTLY TO THE HARDWARE.  KUNGFU IS THE STATE
;MACHINE EXECUTION MAINLINE.  KUNGTAB IS WHERE YOU PUT YOUR GAME PLAY
;DATA.  YOURCODE AND YOURSND ARE EXPLAINED AT THE TOP OF KUNGTAB.ASM.
;THE RESULT OF THE ASSEMBLY IS CODE.PRG WHICH IS LOADED WITH
;THE COLOR DREAMS DEBUGGER BOARD FOR THE NES.  IT WILL HAVE 2 32K SEGMENTS
;EACH WITH A 6 BYTE HEADER.  THE FIRST LOADS INTO PAGE 0 AND THE SECOND
;INTO PAGE 1.  YOU MUST ALSO HAVE YOUR .VID FILE WHICH IS ALSO CREATED
;AUTOMATICALLY BY THE DRAWING PROGRAM.
;
;THE STATE MACHINE USES THE DATA YOU PLACE IN KUNGTAB TO EXECUTE THE 
;GAME.  THERE ARE 3 MAIN THINGS YOU DO IN KUNGTAB.  YOU DEFINE WORLDS
;WHICH ARE BACKGROUNDS AND PALETTES.  YOU DEFINE "ENTITIES" WHICH ARE
;MOVING SPRITES.   FINALLY, YOU DEFINE THINGS IN THE BACKGROUND WHICH
;INTERACT WITH THE SPRITES.  YOU NEED TO CHECK OUT KUNGTAB.ASM AND SIMPLY
;GO THROUGH IT LINE BY LINE SETTING THE DEFINED PARAMETERS IF YOU WANT
;LEARN TO USE THE STATE MACHINE.  THIS MODULE SHOULD OPERATE TRANSPARENTLY
;TO YOU, YOU SHOULD NOT MAKE MODIFICATIONS HERE.  

;AT BOOT THIS PROGRAM SIMPLY ACTIVATES WORLD #0 AND ITS UP TO YOU TO
;DETECT RESET, INITIALIZE FLAGS, AND LOOK FOR THE START KEY. 
;CHECKOUT KUNGTAB AND BE METHODICAL ABOUT SETTING AND UNDERSTANDING 
;EACH ENTRY.
Sooo, I got this to work, and this was the solution all along!! It just took me this long because I, for some reason, thought that compiling kungfu wasn't doing anything, when it fact it was making the (very very important and exactly the thing I was trying to do) CODE.SEG file, but I wasn't noticing because it was just replacing the old one and saying nothing. HEH, of course I had to be dumb enough to have the answer and not notice it.

Thank you, everybody!

Post Reply