Skip to content

Instantly share code, notes, and snippets.

@maly
Created December 21, 2013 11:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maly/8068264 to your computer and use it in GitHub Desktop.
Save maly/8068264 to your computer and use it in GitHub Desktop.
Generátor disassembleru pro Z80
function toHex2($n) {
$o = dechex($n);
if (strlen($o)<2) $o='0'.$o;
return strtoupper($o);
};
function genrl($code,$ins, $DD, $IX) {
$n = '';
$n .= " case '${DD}CB".toHex2($code+0)."': return '".$ins." ($IX+'+p2+'),B';\n";
$n .= " case '${DD}CB".toHex2($code+1)."': return '".$ins." ($IX+'+p2+'),C';\n";
$n .= " case '${DD}CB".toHex2($code+2)."': return '".$ins." ($IX+'+p2+'),D';\n";
$n .= " case '${DD}CB".toHex2($code+3)."': return '".$ins." ($IX+'+p2+'),E';\n";
$n .= " case '${DD}CB".toHex2($code+4)."': return '".$ins." ($IX+'+p2+'),H';\n";
$n .= " case '${DD}CB".toHex2($code+5)."': return '".$ins." ($IX+'+p2+'),L';\n";
$n .= " case '${DD}CB".toHex2($code+6)."': return '".$ins." ($IX+'+p2+')';\n";
$n .= " case '${DD}CB".toHex2($code+7)."': return '".$ins." ($IX+'+p2+'),A';\n";
return $n;
};
function genrs($code,$bit,$ins, $DD, $IX) {
$n = '';
$n .= " case '${DD}CB".toHex2($code+0)."': return '".$ins." $bit,($IX+'+p2+'),B';\n";
$n .= " case '${DD}CB".toHex2($code+1)."': return '".$ins." $bit,($IX+'+p2+'),C';\n";
$n .= " case '${DD}CB".toHex2($code+2)."': return '".$ins." $bit,($IX+'+p2+'),D';\n";
$n .= " case '${DD}CB".toHex2($code+3)."': return '".$ins." $bit,($IX+'+p2+'),E';\n";
$n .= " case '${DD}CB".toHex2($code+4)."': return '".$ins." $bit,($IX+'+p2+'),H';\n";
$n .= " case '${DD}CB".toHex2($code+5)."': return '".$ins." $bit,($IX+'+p2+'),L';\n";
$n .= " case '${DD}CB".toHex2($code+6)."': return '".$ins." $bit,($IX+'+p2+')';\n";
$n .= " case '${DD}CB".toHex2($code+7)."': return '".$ins." $bit,($IX+'+p2+'),A';\n";
return $n;
};
function genbit($code,$bit, $DD, $IX) {
$n = '';
$n .= " case '${DD}CB".toHex2($code+0)."': return 'BIT $bit,($IX+'+p2+')*';\n";
$n .= " case '${DD}CB".toHex2($code+1)."': return 'BIT $bit,($IX+'+p2+')*';\n";
$n .= " case '${DD}CB".toHex2($code+2)."': return 'BIT $bit,($IX+'+p2+')*';\n";
$n .= " case '${DD}CB".toHex2($code+3)."': return 'BIT $bit,($IX+'+p2+')*';\n";
$n .= " case '${DD}CB".toHex2($code+4)."': return 'BIT $bit,($IX+'+p2+')*';\n";
$n .= " case '${DD}CB".toHex2($code+5)."': return 'BIT $bit,($IX+'+p2+')*';\n";
$n .= " case '${DD}CB".toHex2($code+6)."': return 'BIT $bit,($IX+'+p2+')';\n";
$n .= " case '${DD}CB".toHex2($code+7)."': return 'BIT $bit,($IX+'+p2+')*';\n";
return $n;
};
$out = '';
$out.=genrl(0x00,"RLC","DD","IX");
$out.=genrl(0x08,"RRC","DD","IX");
$out.=genrl(0x10,"RL ","DD","IX");
$out.=genrl(0x18,"RR ","DD","IX");
$out.=genrl(0x20,"SLA","DD","IX");
$out.=genrl(0x28,"SRA","DD","IX");
$out.=genrl(0x30,"SLL","DD","IX");
$out.=genrl(0x38,"SRL","DD","IX");
for ($bit=0;$bit<8;$bit++) {
$out.=genbit(0x40+8*$bit,$bit,"DD","IX");
}
for ($bit=0;$bit<8;$bit++) {
$out.=genrs(0x80+8*$bit,$bit,"RES","DD","IX");
}
for ($bit=0;$bit<8;$bit++) {
$out.=genrs(0xC0+8*$bit,$bit,"SET","DD","IX");
}
$out.=genrl(0x00,"RLC","FD","IY");
$out.=genrl(0x08,"RRC","FD","IY");
$out.=genrl(0x10,"RL ","FD","IY");
$out.=genrl(0x18,"RR ","FD","IY");
$out.=genrl(0x20,"SLA","FD","IY");
$out.=genrl(0x28,"SRA","FD","IY");
$out.=genrl(0x30,"SLL","FD","IY");
$out.=genrl(0x38,"SRL","FD","IY");
for ($bit=0;$bit<8;$bit++) {
$out.=genbit(0x40+8*$bit,$bit,"FD","IY");
}
for ($bit=0;$bit<8;$bit++) {
$out.=genrs(0x80+8*$bit,$bit,"RES","FD","IY");
}
for ($bit=0;$bit<8;$bit++) {
$out.=genrs(0xC0+8*$bit,$bit,"SET","FD","IY");
}
echo $out;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment