Skip to content

Instantly share code, notes, and snippets.

@mark-ignacio mark-ignacio/6502_to_d.py
Last active Nov 16, 2015

Embed
What would you like to do?
csaw2015 blox
import re
bit_map = {
'$8731': 'out_bit',
'$871A': 'in_bit',
'$875F': 'and_bit',
'$8769': 'or_bit',
'$8773': 'xor_bit'
}
for line in open('8a4c_blocky_state_shit.txt'):
opcode, arg = line.strip().split(' ')[-2:]
if opcode == 'LDA':
if arg == '$0302':
print('state.a = blocky_state;')
elif arg == '$0303':
print('state.a = pos1;')
elif arg == '$0304':
print('state.a = pos2;')
elif arg.startswith('#$'):
num = re.search(r'([0-9A-F]+)$', arg).group(1)
print('state.a = 0x{};'.format(num))
else:
raise Exception(arg)
elif opcode == 'AND':
if arg.startswith('#$'):
num = re.search(r'([0-9A-F]+)$', arg).group(1)
print('state.a &= 0x{};'.format(num))
else:
raise Exception(arg)
elif opcode == 'LDX':
num = re.search(r'([0-9A-F]+)$', arg).group(1)
print('state.x = 0x{};'.format(num))
elif opcode == 'JSR':
print('{}(&state);'.format(bit_map[arg]))
elif opcode == 'EOR':
num = re.search(r'([0-9A-F]+)$', arg).group(1)
print('state.a ^= 0x{};'.format(num))
else:
raise Exception(opcode)
import std.stdio;
struct NESState {
ubyte a = 0;
ubyte x = 0;
ubyte y = 0;
ubyte traces[256];
}
immutable ubyte toggle_mask[] = [0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80];
void out_bit(NESState *state)
{
state.y = state.x >>> 3;
state.x = state.x & 0x7;
if (state.a != 0) {
state.a = toggle_mask[state.x];
state.a |= state.traces[state.y];
}
else {
state.a = toggle_mask[state.x];
state.a ^= 0xff;
state.a &= state.traces[state.y];
}
state.traces[state.y] = state.a;
}
void in_bit(NESState *state)
{
state.y = state.x >>> 3;
state.x = state.x & 0x7;
state.a = toggle_mask[state.x];
state.a &= state.traces[state.y];
if (state.a != 0) {
state.a = 1;
}
}
void xor_bit(NESState *state)
{
immutable ubyte old_a = state.a;
in_bit(state);
state.a ^= old_a;
}
void and_bit(NESState *state)
{
immutable ubyte old_a = state.a;
in_bit(state);
state.a &= old_a;
}
void or_bit(NESState *state)
{
immutable ubyte old_a = state.a;
in_bit(state);
state.a |= old_a;
}
NESState run_sim(immutable ubyte blocky_state, immutable ubyte pos1, immutable ubyte pos2) {
NESState state;
state.a = blocky_state;
state.a &= 0x01;
state.x = 0x23;
out_bit(&state);
state.a = blocky_state;
state.a &= 0x02;
state.x = 0x2D;
out_bit(&state);
state.a = blocky_state;
state.a &= 0x04;
state.x = 0x3B;
out_bit(&state);
state.a = blocky_state;
state.a &= 0x08;
state.x = 0x44;
out_bit(&state);
state.a = blocky_state;
state.a &= 0x10;
state.x = 0x4F;
out_bit(&state);
state.a = blocky_state;
state.a &= 0x20;
state.x = 0x5C;
out_bit(&state);
state.a = blocky_state;
state.a &= 0x40;
state.x = 0x6B;
out_bit(&state);
state.a = blocky_state;
state.a &= 0x80;
state.x = 0x74;
out_bit(&state);
state.a = pos1;
state.a &= 0x01;
state.x = 0x7F;
out_bit(&state);
state.a = pos1;
state.a &= 0x02;
state.x = 0x10;
out_bit(&state);
state.a = pos1;
state.a &= 0x04;
state.x = 0x14;
out_bit(&state);
state.a = pos1;
state.a &= 0x08;
state.x = 0x1A;
out_bit(&state);
state.a = pos1;
state.a &= 0x10;
state.x = 0xA2;
out_bit(&state);
state.a = pos1;
state.a &= 0x20;
state.x = 0xA5;
out_bit(&state);
state.a = pos1;
state.a &= 0x40;
state.x = 0xA8;
out_bit(&state);
state.a = pos1;
state.a &= 0x80;
state.x = 0xAC;
out_bit(&state);
state.a = pos2;
state.a &= 0x01;
state.x = 0xB0;
out_bit(&state);
state.a = pos2;
state.a &= 0x02;
state.x = 0x8B;
out_bit(&state);
state.a = pos2;
state.a &= 0x04;
state.x = 0x8E;
out_bit(&state);
state.a = pos2;
state.a &= 0x08;
state.x = 0x92;
out_bit(&state);
state.a = pos2;
state.a &= 0x10;
state.x = 0x96;
out_bit(&state);
state.a = pos2;
state.a &= 0x20;
state.x = 0x99;
out_bit(&state);
state.a = pos2;
state.a &= 0x40;
state.x = 0x9C;
out_bit(&state);
state.a = pos2;
state.a &= 0x80;
state.x = 0x9F;
// writefln("a: %x, x: %x, y: %x", state.a, state.x, state.y);
out_bit(&state);
state.a = 0x01;
state.x = 0x11;
out_bit(&state);
state.a = 0x01;
state.x = 0x15;
out_bit(&state);
state.a = 0x01;
state.x = 0x1B;
out_bit(&state);
state.a = 0x00;
state.x = 0x24;
out_bit(&state);
state.a = 0x01;
state.x = 0x2E;
out_bit(&state);
state.a = 0x01;
state.x = 0x3C;
out_bit(&state);
state.a = 0x00;
state.x = 0x45;
out_bit(&state);
state.a = 0x00;
state.x = 0x50;
out_bit(&state);
state.a = 0x01;
state.x = 0x5D;
out_bit(&state);
state.a = 0x01;
state.x = 0x6C;
out_bit(&state);
state.a = 0x00;
state.x = 0x75;
out_bit(&state);
state.a = 0x00;
state.x = 0x80;
out_bit(&state);
state.a = 0x01;
state.x = 0x8C;
out_bit(&state);
state.a = 0x00;
state.x = 0x8F;
out_bit(&state);
state.a = 0x00;
state.x = 0x93;
out_bit(&state);
state.a = 0x00;
state.x = 0x97;
out_bit(&state);
state.a = 0x01;
state.x = 0x9A;
out_bit(&state);
state.a = 0x01;
state.x = 0x9D;
out_bit(&state);
state.a = 0x00;
state.x = 0xA0;
out_bit(&state);
state.a = 0x00;
state.x = 0xA3;
out_bit(&state);
state.a = 0x00;
state.x = 0xA6;
out_bit(&state);
state.a = 0x01;
state.x = 0xA9;
out_bit(&state);
state.a = 0x00;
state.x = 0xAD;
out_bit(&state);
state.a = 0x01;
state.x = 0xB1;
out_bit(&state);
state.x = 0x10;
in_bit(&state);
state.a ^= 0x01;
state.x = 0x0F;
out_bit(&state);
state.x = 0x0F;
in_bit(&state);
state.x = 0x11;
xor_bit(&state);
state.x = 0x0E;
out_bit(&state);
state.x = 0x14;
in_bit(&state);
state.x = 0x15;
xor_bit(&state);
state.x = 0x13;
out_bit(&state);
state.x = 0x0F;
in_bit(&state);
state.x = 0x11;
and_bit(&state);
state.x = 0x16;
out_bit(&state);
state.x = 0x13;
in_bit(&state);
state.x = 0x16;
xor_bit(&state);
state.x = 0x12;
out_bit(&state);
state.x = 0x1A;
in_bit(&state);
state.a ^= 0x01;
state.x = 0x19;
out_bit(&state);
state.x = 0x19;
in_bit(&state);
state.x = 0x1B;
xor_bit(&state);
state.x = 0x18;
out_bit(&state);
state.x = 0x14;
in_bit(&state);
state.x = 0x15;
and_bit(&state);
state.x = 0x1D;
out_bit(&state);
state.x = 0x14;
in_bit(&state);
state.x = 0x15;
or_bit(&state);
state.x = 0x1F;
out_bit(&state);
state.x = 0x0F;
in_bit(&state);
state.x = 0x11;
and_bit(&state);
state.x = 0x1F;
and_bit(&state);
state.x = 0x1E;
out_bit(&state);
state.x = 0x1D;
in_bit(&state);
state.x = 0x1E;
or_bit(&state);
state.x = 0x1C;
out_bit(&state);
state.x = 0x18;
in_bit(&state);
state.x = 0x1C;
xor_bit(&state);
state.x = 0x17;
out_bit(&state);
state.x = 0x0E;
in_bit(&state);
state.x = 0x12;
or_bit(&state);
state.x = 0x17;
or_bit(&state);
state.x = 0x0D;
out_bit(&state);
state.x = 0x23;
in_bit(&state);
state.a ^= 0x01;
state.x = 0x22;
out_bit(&state);
state.x = 0x22;
in_bit(&state);
state.x = 0x24;
xor_bit(&state);
state.x = 0x21;
out_bit(&state);
state.x = 0x19;
in_bit(&state);
state.x = 0x1B;
and_bit(&state);
state.x = 0x26;
out_bit(&state);
state.x = 0x19;
in_bit(&state);
state.x = 0x1B;
or_bit(&state);
state.x = 0x28;
out_bit(&state);
state.x = 0x14;
in_bit(&state);
state.x = 0x15;
and_bit(&state);
state.x = 0x28;
and_bit(&state);
state.x = 0x27;
out_bit(&state);
state.x = 0x0F;
in_bit(&state);
state.x = 0x11;
and_bit(&state);
state.x = 0x1F;
and_bit(&state);
state.x = 0x2A;
out_bit(&state);
state.x = 0x2A;
in_bit(&state);
state.x = 0x28;
and_bit(&state);
state.x = 0x29;
out_bit(&state);
state.x = 0x26;
in_bit(&state);
state.x = 0x27;
or_bit(&state);
state.x = 0x29;
or_bit(&state);
state.x = 0x25;
out_bit(&state);
state.x = 0x21;
in_bit(&state);
state.x = 0x25;
xor_bit(&state);
state.x = 0x20;
out_bit(&state);
state.x = 0x2D;
in_bit(&state);
state.x = 0x2E;
xor_bit(&state);
state.x = 0x2C;
out_bit(&state);
state.x = 0x22;
in_bit(&state);
state.x = 0x24;
and_bit(&state);
state.x = 0x31;
out_bit(&state);
state.x = 0x22;
in_bit(&state);
state.x = 0x24;
or_bit(&state);
state.x = 0x33;
out_bit(&state);
state.x = 0x19;
in_bit(&state);
state.x = 0x1B;
and_bit(&state);
state.x = 0x33;
and_bit(&state);
state.x = 0x32;
out_bit(&state);
state.x = 0x28;
in_bit(&state);
state.x = 0x33;
and_bit(&state);
state.x = 0x35;
out_bit(&state);
state.x = 0x14;
in_bit(&state);
state.x = 0x15;
and_bit(&state);
state.x = 0x35;
and_bit(&state);
state.x = 0x34;
out_bit(&state);
state.x = 0x31;
in_bit(&state);
state.x = 0x32;
or_bit(&state);
state.x = 0x34;
or_bit(&state);
state.x = 0x30;
out_bit(&state);
state.x = 0x1F;
in_bit(&state);
state.x = 0x35;
and_bit(&state);
state.x = 0x37;
out_bit(&state);
state.x = 0x0F;
in_bit(&state);
state.x = 0x11;
and_bit(&state);
state.x = 0x37;
and_bit(&state);
state.x = 0x36;
out_bit(&state);
state.x = 0x30;
in_bit(&state);
state.x = 0x36;
or_bit(&state);
state.x = 0x2F;
out_bit(&state);
state.x = 0x2C;
in_bit(&state);
state.x = 0x2F;
xor_bit(&state);
state.x = 0x2B;
out_bit(&state);
state.x = 0x0D;
in_bit(&state);
state.x = 0x20;
or_bit(&state);
state.x = 0x2B;
or_bit(&state);
state.x = 0x0C;
out_bit(&state);
state.x = 0x3B;
in_bit(&state);
state.a ^= 0x01;
state.x = 0x3A;
out_bit(&state);
state.x = 0x3A;
in_bit(&state);
state.x = 0x3C;
xor_bit(&state);
state.x = 0x39;
out_bit(&state);
state.x = 0x2D;
in_bit(&state);
state.x = 0x2E;
and_bit(&state);
state.x = 0x3E;
out_bit(&state);
state.x = 0x2D;
in_bit(&state);
state.x = 0x2E;
or_bit(&state);
state.x = 0x40;
out_bit(&state);
state.x = 0x40;
in_bit(&state);
state.x = 0x2F;
and_bit(&state);
state.x = 0x3F;
out_bit(&state);
state.x = 0x3E;
in_bit(&state);
state.x = 0x3F;
or_bit(&state);
state.x = 0x3D;
out_bit(&state);
state.x = 0x39;
in_bit(&state);
state.x = 0x3D;
xor_bit(&state);
state.x = 0x38;
out_bit(&state);
state.x = 0x44;
in_bit(&state);
state.a ^= 0x01;
state.x = 0x43;
out_bit(&state);
state.x = 0x43;
in_bit(&state);
state.x = 0x45;
xor_bit(&state);
state.x = 0x42;
out_bit(&state);
state.x = 0x3A;
in_bit(&state);
state.x = 0x3C;
and_bit(&state);
state.x = 0x47;
out_bit(&state);
state.x = 0x3A;
in_bit(&state);
state.x = 0x3C;
or_bit(&state);
state.x = 0x49;
out_bit(&state);
state.x = 0x2D;
in_bit(&state);
state.x = 0x2E;
and_bit(&state);
state.x = 0x49;
and_bit(&state);
state.x = 0x48;
out_bit(&state);
state.x = 0x40;
in_bit(&state);
state.x = 0x49;
and_bit(&state);
state.x = 0x4B;
out_bit(&state);
state.x = 0x2F;
in_bit(&state);
state.x = 0x4B;
and_bit(&state);
state.x = 0x4A;
out_bit(&state);
state.x = 0x47;
in_bit(&state);
state.x = 0x48;
or_bit(&state);
state.x = 0x4A;
or_bit(&state);
state.x = 0x46;
out_bit(&state);
state.x = 0x42;
in_bit(&state);
state.x = 0x46;
xor_bit(&state);
state.x = 0x41;
out_bit(&state);
state.x = 0x0C;
in_bit(&state);
state.x = 0x38;
or_bit(&state);
state.x = 0x41;
or_bit(&state);
state.x = 0x0B;
out_bit(&state);
state.x = 0x4F;
in_bit(&state);
state.a ^= 0x01;
state.x = 0x4E;
out_bit(&state);
state.x = 0x4E;
in_bit(&state);
state.x = 0x50;
xor_bit(&state);
state.x = 0x4D;
out_bit(&state);
state.x = 0x43;
in_bit(&state);
state.x = 0x45;
and_bit(&state);
state.x = 0x53;
out_bit(&state);
state.x = 0x43;
in_bit(&state);
state.x = 0x45;
or_bit(&state);
state.x = 0x55;
out_bit(&state);
state.x = 0x3A;
in_bit(&state);
state.x = 0x3C;
and_bit(&state);
state.x = 0x55;
and_bit(&state);
state.x = 0x54;
out_bit(&state);
state.x = 0x2D;
in_bit(&state);
state.x = 0x2E;
and_bit(&state);
state.x = 0x49;
and_bit(&state);
state.x = 0x57;
out_bit(&state);
state.x = 0x57;
in_bit(&state);
state.x = 0x55;
and_bit(&state);
state.x = 0x56;
out_bit(&state);
state.x = 0x53;
in_bit(&state);
state.x = 0x54;
or_bit(&state);
state.x = 0x56;
or_bit(&state);
state.x = 0x52;
out_bit(&state);
state.x = 0x2F;
in_bit(&state);
state.x = 0x4B;
and_bit(&state);
state.x = 0x55;
and_bit(&state);
state.x = 0x58;
out_bit(&state);
state.x = 0x52;
in_bit(&state);
state.x = 0x58;
or_bit(&state);
state.x = 0x51;
out_bit(&state);
state.x = 0x4D;
in_bit(&state);
state.x = 0x51;
xor_bit(&state);
state.x = 0x4C;
out_bit(&state);
state.x = 0x5C;
in_bit(&state);
state.a ^= 0x01;
state.x = 0x5B;
out_bit(&state);
state.x = 0x5B;
in_bit(&state);
state.x = 0x5D;
xor_bit(&state);
state.x = 0x5A;
out_bit(&state);
state.x = 0x4E;
in_bit(&state);
state.x = 0x50;
and_bit(&state);
state.x = 0x60;
out_bit(&state);
state.x = 0x4E;
in_bit(&state);
state.x = 0x50;
or_bit(&state);
state.x = 0x62;
out_bit(&state);
state.x = 0x43;
in_bit(&state);
state.x = 0x45;
and_bit(&state);
state.x = 0x62;
and_bit(&state);
state.x = 0x61;
out_bit(&state);
state.x = 0x55;
in_bit(&state);
state.x = 0x62;
and_bit(&state);
state.x = 0x64;
out_bit(&state);
state.x = 0x3A;
in_bit(&state);
state.x = 0x3C;
and_bit(&state);
state.x = 0x64;
and_bit(&state);
state.x = 0x63;
out_bit(&state);
state.x = 0x60;
in_bit(&state);
state.x = 0x61;
or_bit(&state);
state.x = 0x63;
or_bit(&state);
state.x = 0x5F;
out_bit(&state);
state.x = 0x49;
in_bit(&state);
state.x = 0x64;
and_bit(&state);
state.x = 0x66;
out_bit(&state);
state.x = 0x2D;
in_bit(&state);
state.x = 0x2E;
and_bit(&state);
state.x = 0x66;
and_bit(&state);
state.x = 0x65;
out_bit(&state);
state.x = 0x40;
in_bit(&state);
state.x = 0x66;
and_bit(&state);
state.x = 0x68;
out_bit(&state);
state.x = 0x2F;
in_bit(&state);
state.x = 0x68;
and_bit(&state);
state.x = 0x67;
out_bit(&state);
state.x = 0x5F;
in_bit(&state);
state.x = 0x65;
or_bit(&state);
state.x = 0x67;
or_bit(&state);
state.x = 0x5E;
out_bit(&state);
state.x = 0x5A;
in_bit(&state);
state.x = 0x5E;
xor_bit(&state);
state.x = 0x59;
out_bit(&state);
state.x = 0x0B;
in_bit(&state);
state.x = 0x4C;
or_bit(&state);
state.x = 0x59;
or_bit(&state);
state.x = 0x0A;
out_bit(&state);
state.x = 0x6B;
in_bit(&state);
state.x = 0x6C;
xor_bit(&state);
state.x = 0x6A;
out_bit(&state);
state.x = 0x5B;
in_bit(&state);
state.x = 0x5D;
and_bit(&state);
state.x = 0x6E;
out_bit(&state);
state.x = 0x5B;
in_bit(&state);
state.x = 0x5D;
or_bit(&state);
state.x = 0x70;
out_bit(&state);
state.x = 0x70;
in_bit(&state);
state.x = 0x5E;
and_bit(&state);
state.x = 0x6F;
out_bit(&state);
state.x = 0x6E;
in_bit(&state);
state.x = 0x6F;
or_bit(&state);
state.x = 0x6D;
out_bit(&state);
state.x = 0x6A;
in_bit(&state);
state.x = 0x6D;
xor_bit(&state);
state.x = 0x69;
out_bit(&state);
state.x = 0x74;
in_bit(&state);
state.a ^= 0x01;
state.x = 0x73;
out_bit(&state);
state.x = 0x73;
in_bit(&state);
state.x = 0x75;
xor_bit(&state);
state.x = 0x72;
out_bit(&state);
state.x = 0x6B;
in_bit(&state);
state.x = 0x6C;
and_bit(&state);
state.x = 0x77;
out_bit(&state);
state.x = 0x6B;
in_bit(&state);
state.x = 0x6C;
or_bit(&state);
state.x = 0x79;
out_bit(&state);
state.x = 0x5B;
in_bit(&state);
state.x = 0x5D;
and_bit(&state);
state.x = 0x79;
and_bit(&state);
state.x = 0x78;
out_bit(&state);
state.x = 0x70;
in_bit(&state);
state.x = 0x79;
and_bit(&state);
state.x = 0x7B;
out_bit(&state);
state.x = 0x5E;
in_bit(&state);
state.x = 0x7B;
and_bit(&state);
state.x = 0x7A;
out_bit(&state);
state.x = 0x77;
in_bit(&state);
state.x = 0x78;
or_bit(&state);
state.x = 0x7A;
or_bit(&state);
state.x = 0x76;
out_bit(&state);
state.x = 0x72;
in_bit(&state);
state.x = 0x76;
xor_bit(&state);
state.x = 0x71;
out_bit(&state);
state.x = 0x0A;
in_bit(&state);
state.x = 0x69;
or_bit(&state);
state.x = 0x71;
or_bit(&state);
state.x = 0x09;
out_bit(&state);
state.x = 0x7F;
in_bit(&state);
state.a ^= 0x01;
state.x = 0x7E;
out_bit(&state);
state.x = 0x7E;
in_bit(&state);
state.x = 0x80;
xor_bit(&state);
state.x = 0x7D;
out_bit(&state);
state.x = 0x73;
in_bit(&state);
state.x = 0x75;
and_bit(&state);
state.x = 0x83;
out_bit(&state);
state.x = 0x73;
in_bit(&state);
state.x = 0x75;
or_bit(&state);
state.x = 0x85;
out_bit(&state);
state.x = 0x6B;
in_bit(&state);
state.x = 0x6C;
and_bit(&state);
state.x = 0x85;
and_bit(&state);
state.x = 0x84;
out_bit(&state);
state.x = 0x5B;
in_bit(&state);
state.x = 0x5D;
and_bit(&state);
state.x = 0x79;
and_bit(&state);
state.x = 0x87;
out_bit(&state);
state.x = 0x87;
in_bit(&state);
state.x = 0x85;
and_bit(&state);
state.x = 0x86;
out_bit(&state);
state.x = 0x83;
in_bit(&state);
state.x = 0x84;
or_bit(&state);
state.x = 0x86;
or_bit(&state);
state.x = 0x82;
out_bit(&state);
state.x = 0x5E;
in_bit(&state);
state.x = 0x7B;
and_bit(&state);
state.x = 0x85;
and_bit(&state);
state.x = 0x88;
out_bit(&state);
state.x = 0x82;
in_bit(&state);
state.x = 0x88;
or_bit(&state);
state.x = 0x81;
out_bit(&state);
state.x = 0x7D;
in_bit(&state);
state.x = 0x81;
xor_bit(&state);
state.x = 0x7C;
out_bit(&state);
state.x = 0x8B;
in_bit(&state);
state.a ^= 0x01;
state.x = 0x8A;
out_bit(&state);
state.x = 0x8A;
in_bit(&state);
state.x = 0x8C;
xor_bit(&state);
state.x = 0x89;
out_bit(&state);
state.x = 0x09;
in_bit(&state);
state.x = 0x7C;
or_bit(&state);
state.x = 0x89;
or_bit(&state);
state.x = 0x08;
out_bit(&state);
state.x = 0x8E;
in_bit(&state);
state.x = 0x8F;
xor_bit(&state);
state.x = 0x8D;
out_bit(&state);
state.x = 0x92;
in_bit(&state);
state.a ^= 0x01;
state.x = 0x91;
out_bit(&state);
state.x = 0x91;
in_bit(&state);
state.x = 0x93;
xor_bit(&state);
state.x = 0x90;
out_bit(&state);
state.x = 0x08;
in_bit(&state);
state.x = 0x8D;
or_bit(&state);
state.x = 0x90;
or_bit(&state);
state.x = 0x07;
out_bit(&state);
state.x = 0x96;
in_bit(&state);
state.a ^= 0x01;
state.x = 0x95;
out_bit(&state);
state.x = 0x95;
in_bit(&state);
state.x = 0x97;
xor_bit(&state);
state.x = 0x94;
out_bit(&state);
state.x = 0x99;
in_bit(&state);
state.x = 0x9A;
xor_bit(&state);
state.x = 0x98;
out_bit(&state);
state.x = 0x07;
in_bit(&state);
state.x = 0x94;
or_bit(&state);
state.x = 0x98;
or_bit(&state);
state.x = 0x06;
out_bit(&state);
state.x = 0x9C;
in_bit(&state);
state.x = 0x9D;
xor_bit(&state);
state.x = 0x9B;
out_bit(&state);
state.x = 0x9F;
in_bit(&state);
state.x = 0xA0;
xor_bit(&state);
state.x = 0x9E;
out_bit(&state);
state.x = 0x06;
in_bit(&state);
state.x = 0x9B;
or_bit(&state);
state.x = 0x9E;
or_bit(&state);
state.x = 0x05;
out_bit(&state);
state.x = 0xA2;
in_bit(&state);
state.x = 0xA3;
xor_bit(&state);
state.x = 0xA1;
out_bit(&state);
state.x = 0xA5;
in_bit(&state);
state.x = 0xA6;
xor_bit(&state);
state.x = 0xA4;
out_bit(&state);
state.x = 0x05;
in_bit(&state);
state.x = 0xA1;
or_bit(&state);
state.x = 0xA4;
or_bit(&state);
state.x = 0x04;
out_bit(&state);
state.x = 0xA8;
in_bit(&state);
state.x = 0xA9;
xor_bit(&state);
state.x = 0xA7;
out_bit(&state);
state.x = 0xAC;
in_bit(&state);
state.a ^= 0x01;
state.x = 0xAB;
out_bit(&state);
state.x = 0xAB;
in_bit(&state);
state.x = 0xAD;
xor_bit(&state);
state.x = 0xAA;
out_bit(&state);
state.x = 0x04;
in_bit(&state);
state.x = 0xA7;
or_bit(&state);
state.x = 0xAA;
or_bit(&state);
state.x = 0x03;
out_bit(&state);
state.x = 0xB0;
in_bit(&state);
state.a ^= 0x01;
state.x = 0xAF;
out_bit(&state);
state.x = 0xAF;
in_bit(&state);
state.x = 0xB1;
xor_bit(&state);
state.x = 0xAE;
out_bit(&state);
state.x = 0x03;
in_bit(&state);
state.x = 0xAE;
or_bit(&state);
state.x = 0x02;
out_bit(&state);
state.x = 0x02;
in_bit(&state);
state.a ^= 0x01;
state.x = 0x01;
out_bit(&state);
state.x = 0x01;
in_bit(&state);
state.x = 0x00;
out_bit(&state);
state.x = 0x00;
in_bit(&state);
return state;
}
static int solve()
{
writeln("Solvin' time!");
ubyte i=0, j=0, k=0;
do {
do {
do {
immutable NESState state = run_sim(i, j, k);
if (state.a != 0 || state.x != 0 || state.y != 0) {
writefln("SOLUTION %x:%x:%x", i, j, k);
return 0;
}
} while (k++ != 0xff);
} while (j++ != 0xff);
writefln("Done with %x:ff:ff", i);
} while (i++ != 0xff);
return 1;
}
int main(string[] argv)
{
return solve();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.