Jump to content
IGNORED

SpiceWare's Blog - improved 6507 to C defines


RSS Bot

Recommended Posts

One of the difficulties about working with 2 sets of code (6507 assembly and C) is there's some common info that both need to know. Manually maintaining that info in 2 places is error prone, so you want to limit that as much as possible. While developing Stay Frosty 2 I came up with the idea of having the 6507 assembly maintain that info, and have output it for C via echo commands:

#define SUB   queue[ $0 ]#define SWCHA queue[ $1 ]#define SWCHB queue[ $2 ]#define INPT1 queue[ $3 ]#define INPT4 queue[ $4 ]#define ElevatorHM26  $f7d1#define ElevatorHM31  $f804

I would manually copy/paste that into a C header file, followed by an additional step of find/replace the $ with 0x as dasm and C use incompatible formats for representing hex values.
echo "#define SUB   queue[", [ARMsub]d ,"]"echo "#define SWCHA queue[", [ARMswcha]d ,"]"echo "#define SWCHB queue[", [ARMswchb]d ,"]"echo "#define INPT1 queue[", [ARMinpt1]d ,"]"        echo "#define INPT4 queue[", [ARMinpt4]d ,"]"echo "#define ElevatorHM26 ", [ElevatorHM26]decho "#define ElevatorHM31 ", [ElevatorHM31]d

which would output:
dasm testrom1.asm -f3 -otestrom1.cu | awk '!x[$$0]++' | grep "#define" > $(BASE)/defines_dasm.h

It uses grep to automatically capture the echoed out #defines and stash them in the header file for the C code. Awesome!


After implementing that in SpiceC I wondered if I could improve upon that further as writing all those echo statements would be tedious. After reading up on awk and realizing it could process columns of data, I got to thinking that the symbol file dasm outputs was in columns:
2.Start, so I'd also need to include some selection logic.

After some trial and error, and a bit of pondering, I came up with the following:
 
The dasm step does a normal compile and creates a symbol file. The awk step scans the symbol file for anything starting with _ and creates the define file for C. Given this:
#define _ARMmode            0x0009#define _AUDC0              0x000b#define _AUDC1              0x000c#define _AUDF0              0x000d#define _AUDF1              0x000e#define _AUDIO              0x0000#define _AUDIO_MUSIC        0x0001#define _AUDIO_SAMPLES      0x0002#define _AUDIO_TIA_ONLY     0x0000#define _AUDV0              0x000f#define _AUDV1              0x0010#define _COLUBK             0x0012#define _COLUPF             0x0011#define _DISPLAY_DATA_4_ARM 0x0013#define _FRAME              0x000a#define _FUNC               0x0000#define _INPT1              0x0005#define _INPT3              0x0006#define _INTP4              0x0003#define _INTP5              0x0004#define _OSTIME             0x0008#define _RUN_GAME_OS        0x0004#define _RUN_GAME_VB        0x0003#define _RUN_INIT           0x0000#define _RUN_INIT_LEVEL     0x0007#define _RUN_MENU_OS        0x0002#define _RUN_MENU_VB        0x0001#define _RUN_SPLASH_OS      0x0006#define _RUN_SPLASH_VB      0x0005#define _SWCHA              0x0001#define _SWCHB              0x0002#define _VBTIME             0x0007#define _WAVE_SIZE          0x0020

One of the benefits of using _ as a prefix is it lessens the chance of these defines conflicting with any end-user code.

http://atariage.com/forums/blog/148/entry-14588-improved-6507-to-c-defines/
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...