SNASM68K COFF dump tool

Talk about development tools here

Moderator: BigEvilCorporation

Post Reply
BigEvilCorporation
Very interested
Posts: 209
Joined: Sat Sep 08, 2012 10:41 am
Contact:

SNASM68K COFF dump tool

Post by BigEvilCorporation » Mon Jan 25, 2016 3:02 pm

Hi!

I'm writing some tools to help make my development life with SNASM68K easier, starting with a tool to extract file/line info from a physical address to use in conjunction with an exception handler in my game.

Here it is: sn68kcoffdump.exe!

It can show a summary of COFF contents, dump all symbols, extract the ROM as a standalone file, and fetch a symbol/file/line from a code address.

My aim is to work up to creating a source level debugger plugin for Exodus.

Source: https://github.com/BigEvilCorporation/SN68KCOFFDUMP
Binary: https://www.mediafire.com/?mwof7vbowbt8qr1

Usage:

Code: Select all

Usage:
        sn68kcoffdump filename.cof [options]
Options:
        -summary                 Prints COFF summary
        -symbols                 Prints symbol table
        -extractrom [filename]   Extracts ROM file
        -addr2line [hex address] Prints file/line and symbol from physical address
Example of -addr2line:

Code: Select all

C:\bigevilcorporation\bigevilframework\TANGLEWD\BIN>sn68kcoffdump.exe TANGLEWD.COF -addr2line 45e
-------------------------------------
SNASM2 68000 COFF File Info Dump Tool
-------------------------------------
Release 0.1a, 23/Jan/2016
Matt Phillips, Big Evil Corporation
http://www.bigevilcorporation.co.uk
-------------------------------------

Address 0x45e
Filename: C:\TANGLEWD/..\framewk\interpts.asm
Line: 38
Nearest symbol name: Exception
Nearest symbol address: 45a
Example of -symbols:

Code: Select all

C:\bigevilcorporation\bigevilframework\TANGLEWD\BIN>sn68kcoffdump.exe TANGLEWD.COF -symbols
-------------------------------------
SNASM2 68000 COFF File Info Dump Tool
-------------------------------------
Release 0.1a, 23/Jan/2016
Matt Phillips, Big Evil Corporation
http://www.bigevilcorporation.co.uk
-------------------------------------

-------------------------------------
SYMBOLS
-------------------------------------
0x0     __start
0x200   EntryPoint
0x26a   Main
0x270   VDPDMAQueue_AddJob
0x298   VDPDMAQueue_ExecuteAll
0x2d2   GetTerrainTile
0x310   GetCollisionTileFlags
0x348   GetTerrainHeight
0x3ac   InitGamepads
0x3be   InitEXTPort
0x3c8   ReadPadA
0x3f8   ReadPadB
0x428   VBlankInterrupt
0x44e   HBlankInterrupt
0x45a   Exception
0x460   NullInterrupt
0x462   Clamp
0x47c   RandInit
0x488   RandLong
0x4b8   VectorAdd
0x4c4   VectorSub
0x4d0   VectorDistSq
0x4e8   VectorDot
0x4f6   CompareString
0x514   strcmp_diff
0x51a   strcmp_end
0x51c   GetMCDType
0x590   MCD_RestoreHINT
0x5aa   InitMCD_Mode1
0x61e   SubCPU_int
0x626   SubCPU_rte
0x628   ClearRAM
0x64a   InitPSG
0x65e   LoadTiles
0x6b4   LoadTilesDMA
...
0x28101 bgm_titles
0x284c8 tiles_bigevil_logo
0x29688 tiles_tanglewood_logo
0x2c988 tiles_lvl1
0x366c8 collisiontiles_lvl1
0x37328 map_bigevil_logo
0x37c88 map_tanglewood_logo
0x385e8 map_lvl1
0x5feb8 collisionmap_lvl1
0x87788 Z80Program
0x88988 __end
SNASM COFF files are almost standard COFFs, with a few exceptions:

- Machine type is fixed at 0x150 (covers all 68000 family, no sub-type provided)
- There are 3 fixed sections: Filename Table Section (1-based string list), Debugger Section (format currently unknown), and ROM Section (contains ROM data, line number table, symbol table)
- Line number entries hold indices to the filename table, and not the symbol table like other COFF types
- There's no mapping from line number section headers to symbols, instead symbols must be sorted and the nearest entry searched for by address

I hope someone finds it useful!
A blog of my Megadrive programming adventures: http://www.bigevilcorporation.co.uk

BigEvilCorporation
Very interested
Posts: 209
Joined: Sat Sep 08, 2012 10:41 am
Contact:

Re: SNASM68K COFF dump tool

Post by BigEvilCorporation » Mon Jan 25, 2016 3:25 pm

Also I should probably mention how to generate a COFF file in the first place - pass the /sdb option and add the COF extension to the output file with SNASM68K.EXE:

Code: Select all

SNASM68K.EXE /sdb TANGLEWD.ASM,TANGLEWD.COF
The ROM built with and without the option will have matching lines/files/symbols, so you can either build a raw ROM (/p option) alongside it to load up in emulator/hardware, or use my tool to extract the ROM from the COF.
A blog of my Megadrive programming adventures: http://www.bigevilcorporation.co.uk

MintyTheCat
Very interested
Posts: 484
Joined: Sat Mar 05, 2011 11:11 pm
Location: Berlin, Germany

Re: SNASM68K COFF dump tool

Post by MintyTheCat » Tue Jan 26, 2016 11:11 am

Sounds a lot like readelf and the objdump commands. Have you not got those tools or something similar?

I use ELF files for my MD work and what I do is generate a disassembly of the ELF before I convert it into my MD ROM file.

Also, does this build under UNIX?
UMDK Fanboy

BigEvilCorporation
Very interested
Posts: 209
Joined: Sat Sep 08, 2012 10:41 am
Contact:

Re: SNASM68K COFF dump tool

Post by BigEvilCorporation » Tue Jan 26, 2016 1:27 pm

I don't have a functional Linux environment at the moment but I did come across BinUtils, I studied the source to figure out if it supported fetching filenames instead of symbol indices from the line number chunks. I'll get a Cygwin environment up and running and see if it does the job of reading these files; they're not entirely standard compliant COFFs.

ELF isn't possible since I'm limited to SNASM68K's output format for compatibility with my MegaCD dev unit and debugger. I could build my code under a GCC environment with some changes, but it would need some real work to get addresses to match up with the SNASM-built version, and really not worth the effort.

Even if my efforts do prove to be redundant, in the worst case this was a fine educational exercise.

The code will build under Linux with FILETIME, SYSTEMTIME and FileTimeToSystemTime() alternatives defined (or just strip the time stuff out entirely, it's only for interpreting the header).
A blog of my Megadrive programming adventures: http://www.bigevilcorporation.co.uk

MintyTheCat
Very interested
Posts: 484
Joined: Sat Mar 05, 2011 11:11 pm
Location: Berlin, Germany

Re: SNASM68K COFF dump tool

Post by MintyTheCat » Wed Jan 27, 2016 9:55 am

Cygwin is 'ok' but you might consider installing a VM of Linux to get a proper shell.

There are COFF versions of these tools available.

Indeed, it is all good education to find out how these things work :)
UMDK Fanboy

Pascal
Very interested
Posts: 200
Joined: Wed Nov 29, 2006 11:29 am
Location: Belgium
Contact:

Re: SNASM68K COFF dump tool

Post by Pascal » Wed Jan 27, 2016 12:47 pm

just in case you missed it , i released long tiiiiiiiiiime ago my debugger for snasm68k compiled program
have a look here :
viewtopic.php?f=7&t=325

BigEvilCorporation
Very interested
Posts: 209
Joined: Sat Sep 08, 2012 10:41 am
Contact:

Re: SNASM68K COFF dump tool

Post by BigEvilCorporation » Thu Jan 28, 2016 10:23 am

Pascal wrote:just in case you missed it , i released long tiiiiiiiiiime ago my debugger for snasm68k compiled program
have a look here :
viewtopic.php?f=7&t=325
That looks fantastic! Definitely checking that out later.

Are you still working on it? Was the source ever released?
A blog of my Megadrive programming adventures: http://www.bigevilcorporation.co.uk

Pascal
Very interested
Posts: 200
Joined: Wed Nov 29, 2006 11:29 am
Location: Belgium
Contact:

Re: SNASM68K COFF dump tool

Post by Pascal » Thu Jan 28, 2016 3:20 pm

Thanks but it's nothing to the level of exodus or Kmod, there's no sound , and it's slooooooooooooow as hell even with nowadays icore 7.
So don't get too excited ;)

It really helped me with Teenage Queen / Rick Dangerous 1 & 2

I don't and won't update it , it suits my needs and with 2 kids and an house to maintain , i've no times for that anymore :s
it was really tailored to my needs and i never intended to release it. The release was more to be seen like an "accident".

I might still have the source code, but it use an 10 year old version of wxwidget and DXSDK and it was poorly coded (switch the desktop to 16bits).

BigEvilCorporation
Very interested
Posts: 209
Joined: Sat Sep 08, 2012 10:41 am
Contact:

Re: SNASM68K COFF dump tool

Post by BigEvilCorporation » Thu Jan 28, 2016 10:27 pm

I can't use the debugger since my ROM is waaaaaay over 128kb, but while trying I've discovered the .LST file generation stuff in SNASM68K which renders my COFF tool completely moot!

I've started the Exodus plugin, so I'll just carry on with .LST support :)
A blog of my Megadrive programming adventures: http://www.bigevilcorporation.co.uk

Okie
Interested
Posts: 37
Joined: Wed Jun 30, 2021 7:31 pm
Location: United States Of America

Re: SNASM68K COFF dump tool

Post by Okie » Sat Jul 02, 2022 4:35 pm

Awesome work. This is a dream tool of mine to have annotated disassembly and trace logger. Keep up the fantastic work.

Post Reply