Hamtaro126 wrote:
slobu wrote:
I'd just be happy with a basic Hello World template. But, everyone dreams of making a 4 way scrolling game
Is asm source actually easy to turn back into C equivalents?
You have to redo everything by hand, C and ASM are totally different languages, C compilation to ASM is possible, but not the other way around!
Decompilers exist and there is a decompiler for 6502.
http://6502.emulinks.de/blog/You need Python 3.0 to try it out. Not sure how sound it is. I tried it with the reset vector for SMB:
Code:
ldy #ColdBootOffset ;load default cold boot pointer
ldx #$05 ;this is where we check for a warm boot
WBootCheck: lda TopScoreDisplay,x ;check each score digit in the top score
cmp #10 ;to see if we have a valid digit
bcs ColdBoot ;if not, give up and proceed with cold boot
dex
bpl WBootCheck
lda WarmBootValidation ;second checkpoint, check to see if
cmp #$a5 ;another location has a specific value
bne ColdBoot
ldy #WarmBootOffset ;if passed both, load warm boot pointer
ColdBoot: jsr InitializeMemory ;clear memory using pointer in Y
It outputs this mess which omits the first y load and includes code below the ColdBoot label:
Code:
x = 5;
do {
a = arr_07d7[x];
if (a >= 10) {
label_003b:
fun_90cc();
outb(0x4011, a);
mem_0770 = a;
mem_07ff = 165;
mem_07a7 = 165;
outb(0x4015, 0xf);
outb(0x2001, 0x6);
fun_8220();
fun_8e19();
mem_0774 = mem_0774 + 1;
fun_8eed();
__illegal(0xf); /* XXX: unimplemented illegal opcode */
}
x = x - 1;
} while (x < 128);
a = mem_07ff;
goto label_003b;
Here's a decompilation of that loop I made by hand:
Code:
y = #ColdBootOffset
x = 5
do {
a = TopScoreDisplay[x]
x = x - 1
if (a < 10) {
if (x >= 128) {
if (0xA5 == WarmBootValidation) {
y = #WarmBootOffset
}
}
}
} while (x < 128)
InitializeMemory()
This command line got the above output in case someone wants to look at it. At a glance, it only decompiles snippets of code and stops when it hits an illegal instruction. Not sure if it can decompile a whole binary, but the -help is pretty vague on that score.
python3 decomp.py -o 0 -e 10 smb.nes > smb.c
Edit: His own example of disassembling the smb reset vector actually works; I had some difficulty figuring out the command line outside of the binaries included with the decompiler, so whatever.
Code:
y = 254;
x = 5;
do {
if (arr_07d7[x] >= 10) {
label_802b:
a = fun_90cc(y);
outb(0x4011, a);
mem_0770 = a;
mem_07ff = 165;
mem_07a7 = 165;
outb(0x4015, 0xf);
outb(0x2001, 0x6);
fun_8220();
fun_8e19();
mem_0774 = mem_0774 + 1;
fun_8eed(mem_0778 | 128);
for (;;);
}
x = x - 1;
} while (x < 128);
if (mem_07ff == 165) {
y = 214;
}
goto label_802b;