Commit 26e6ed74 authored by Brandon Warner's avatar Brandon Warner
Browse files

Added more instructions and started on ports

parent 2d3d6e03
<Properties StartupConfiguration="{CF7CAAA7-E25C-4EF7-A42E-749C02D461AA}|Default">
<Properties StartupConfiguration="{CF7CAAA7-E25C-4EF7-A42E-749C02D461AA}|Default" StartupItem="z80-emu/z80-emu.csproj">
<MonoDevelop.Ide.Workbench ActiveDocument="z80-emu/Program.cs">
<Files>
<File FileName="z80-emu/Program.cs" Line="235" Column="14" />
<File FileName="z80-emu/Program.cs" Line="170" Column="14" />
</Files>
</MonoDevelop.Ide.Workbench>
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug|x86" />
<MonoDevelop.Ide.ItemProperties.z80-emu PreferredExecutionTarget="MonoDevelop.Default" />
<MonoDevelop.Ide.DebuggingService.Breakpoints>
<BreakpointStore />
</MonoDevelop.Ide.DebuggingService.Breakpoints>
<MonoDevelop.Ide.DebuggingService.PinnedWatches />
<MultiItemStartupConfigurations />
<MonoDevelop.Ide.ItemProperties.z80-emu PreferredExecutionTarget="MonoDevelop.Default" />
</Properties>
\ No newline at end of file
......@@ -61,6 +61,7 @@ namespace z80emu
public byte R = 0;
public ushort IX = 0;
public byte IXL
{
get { return (byte)IX; }
......@@ -766,6 +767,10 @@ namespace z80emu
r.A -= r.C;
r.PC++;
break;
case 0xAF:
r.A ^= r.A;
r.PC++;
break;
case 0xB7:
r.A |= r.A;
r.F = (byte)(r.F & ~(1 << 0));
......@@ -797,8 +802,9 @@ namespace z80emu
cp(r.L);
r.PC++;
break;
case 0xC9:
r.PC = pop();
case 0xC1:
r.BC = pop ();
r.PC++;
break;
case 0xC2:
bit = (r.F >> 6) & 1;
......@@ -814,6 +820,13 @@ namespace z80emu
case 0xC3:
r.PC = (ushort)(readMEM((ushort)(r.PC + 1)) + (readMEM((ushort)(r.PC + 2)) * 256));
break;
case 0xC5:
push (r.BC);
r.PC++;
break;
case 0xC9:
r.PC = pop();
break;
case 0xCA:
bit = (r.F >> 6) & 1;
if (bit != 0)
......@@ -841,8 +854,7 @@ namespace z80emu
}
break;
case 0xD3:
// TODO implement output correctly
Console.Write((char)r.A);
doout (readMEM ((ushort)(r.PC + 1)), r.A);
r.PC += 2;
break;
case 0xDA:
......@@ -857,7 +869,7 @@ namespace z80emu
}
break;
case 0xDB:
r.A = buff;
r.A = doin(readMEM((ushort)(r.PC + 1)));
r.PC += 2;
break;
case 0xDD:
......@@ -908,7 +920,7 @@ namespace z80emu
throw new Exception(String.Format("Instruction 0x{0:X2}@0x{1:X4} not implemented", readMEM(r.PC), r.PC));
}
}
if (r.PC == 0x118) {
if (r.PC == 0x135) {
r.R = 0;
}
......@@ -917,15 +929,6 @@ namespace z80emu
{
if (Console.KeyAvailable)
{
ConsoleKeyInfo key = Console.ReadKey (true);
if (key.Key == ConsoleKey.Backspace) {
buff = 0x8;
} else {
int c = key.KeyChar;
if (c >= 0) {
buff = (byte)c;
}
}
AF_ = r.AF;
push (r.PC);
r.PC = 0x38;
......@@ -939,6 +942,12 @@ namespace z80emu
{
switch (readMEM((ushort)(r.PC + 1)))
{
case 0x42:
bit = (r.F >> 0) & 1;
r.HL -= r.BC;
r.HL -= (ushort)bit;
r.PC += 2;
break;
case 0x43:
writeMEM ((ushort)(readMEM ((ushort)(r.PC + 2)) + (readMEM ((ushort)(r.PC + 3)) * 256)), r.C);
writeMEM ((ushort)(readMEM ((ushort)(r.PC + 2)) + (readMEM ((ushort)(r.PC + 3)) * 256) + 1), r.B);
......@@ -961,6 +970,21 @@ namespace z80emu
}
r.PC += 2;
break;
case 0xB1:
do {
cp(readMEM(r.HL));
r.HL++;
r.BC--;
} while (readMEM (r.HL) != r.A && r.BC != 0);
r.PC += 2;
break;
case 0xB3:
for (; r.B != 0; r.B--) {
doout (r.C, readMEM (r.HL));
r.HL++;
}
r.PC += 2;
break;
default:
throw new Exception(String.Format("Instruction 0xED{0:X2}@0x{1:X4} not implemented", readMEM((ushort)(r.PC + 1)), r.PC));
}
......@@ -1021,53 +1045,61 @@ namespace z80emu
{
switch (readMEM((ushort)(r.PC + 1)))
{
case 0x09:
r.IX += r.BC;
r.PC += 2;
break;
case 0x21:
r.IY = (ushort)(readMEM((ushort)(r.PC + 2)) + (readMEM((ushort)(r.PC + 3)) * 256));
r.PC += 4;
break;
case 0x22:
writeMEM((ushort)(readMEM((ushort)(r.PC + 2)) + (readMEM((ushort)(r.PC + 3)) * 256)), r.IYL);
writeMEM((ushort)(readMEM((ushort)(r.PC + 2)) + (readMEM((ushort)(r.PC + 3)) * 256) + 1), r.IYH);
r.PC += 4;
break;
case 0x23:
r.IY++;
r.PC += 2;
break;
case 0x2A:
r.IYL = readMEM((ushort)(readMEM((ushort)(r.PC + 2)) + (readMEM((ushort)(r.PC + 3)) * 256)));
r.IYH = readMEM((ushort)(readMEM((ushort)(r.PC + 2)) + (readMEM((ushort)(r.PC + 3)) * 256) + 1));
r.PC += 4;
break;
case 0x36:
writeMEM((ushort)(r.IY + readMEM((ushort)(r.PC + 2))), readMEM((ushort)(r.PC + 3)));
r.PC += 3;
break;
case 0x77:
writeMEM((ushort)(r.IY + readMEM((ushort)(r.PC + 2))), r.A);
r.PC += 3;
break;
case 0x7E:
r.A = readMEM((ushort)(r.IY + (sbyte)readMEM((ushort)(r.PC + 3))));
r.PC += 3;
break;
case 0xE1:
r.IY = pop();
r.PC += 2;
break;
case 0xE5:
push(r.IY);
r.PC += 2;
break;
case 0xE9:
r.PC = r.IX;
break;
default:
throw new Exception(String.Format("Instruction 0xFD{0:X2}@0x{1:X4} not implemented", readMEM((ushort)(r.PC + 1)), r.PC));
case 0x09:
r.IX += r.BC;
r.PC += 2;
break;
case 0x21:
r.IY = (ushort)(readMEM((ushort)(r.PC + 2)) + (readMEM((ushort)(r.PC + 3)) * 256));
r.PC += 4;
break;
case 0x22:
writeMEM((ushort)(readMEM((ushort)(r.PC + 2)) + (readMEM((ushort)(r.PC + 3)) * 256)), r.IYL);
writeMEM((ushort)(readMEM((ushort)(r.PC + 2)) + (readMEM((ushort)(r.PC + 3)) * 256) + 1), r.IYH);
r.PC += 4;
break;
case 0x23:
r.IY++;
r.PC += 2;
break;
case 0x2A:
r.IYL = readMEM((ushort)(readMEM((ushort)(r.PC + 2)) + (readMEM((ushort)(r.PC + 3)) * 256)));
r.IYH = readMEM((ushort)(readMEM((ushort)(r.PC + 2)) + (readMEM((ushort)(r.PC + 3)) * 256) + 1));
r.PC += 4;
break;
case 0x2E:
r.IYL = readMEM ((ushort)(r.PC + 2));
r.PC += 3;
break;
case 0x36:
writeMEM((ushort)(r.IY + readMEM((ushort)(r.PC + 2))), readMEM((ushort)(r.PC + 3)));
r.PC += 3;
break;
case 0x77:
writeMEM((ushort)(r.IY + readMEM((ushort)(r.PC + 2))), r.A);
r.PC += 3;
break;
case 0x7E:
r.A = readMEM((ushort)(r.IY + (sbyte)readMEM((ushort)(r.PC + 3))));
r.PC += 3;
break;
case 0xBC:
cp (r.IXL);
r.PC += 2;
break;
case 0xE1:
r.IY = pop();
r.PC += 2;
break;
case 0xE5:
push(r.IY);
r.PC += 2;
break;
case 0xE9:
r.PC = r.IX;
break;
default:
throw new Exception(String.Format("Instruction 0xFD{0:X2}@0x{1:X4} not implemented", readMEM((ushort)(r.PC + 1)), r.PC));
}
}
......@@ -1104,6 +1136,33 @@ namespace z80emu
return data;
}
public static void doout(byte port, byte data) {
switch (port) {
case 1:
Console.Write ((char)data);
break;
}
}
public static byte doin(byte port) {
switch (port) {
case 1:
var key = Console.ReadKey ();
if (key.Key == ConsoleKey.Backspace) {
return 0x8;
} else {
return (byte)key.KeyChar;
}
case 2:
return (byte)(Console.KeyAvailable ? 1 : 0);
}
return 0;
}
public static byte readMEM(ushort loc)
{
if (loc < 8192)
......@@ -1194,8 +1253,11 @@ namespace z80emu
String name = System.Text.Encoding.ASCII.GetString(filename).TrimEnd('\0');
switch (data)
{
case 0:
case 0:
if (file != null) {
file.Close ();
}
break;
case 3:
file = new System.IO.FileStream(System.IO.Path.Combine(folder, name), System.IO.FileMode.Open);
for (int i = 0, a = dma_address; i < file.Length; i++, a++)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment