implemented 20 more Z80 instructions

This commit is contained in:
FeralChild64 committed 2020-12-17 23:03:25 +01:00
1 parent 376cf2506d
commit 345e471cae
6 files changed
+1299 -1082

No files matched your search

+2 -2
View File
@@ -47,6 +47,6 @@
!set Z80_HF = %00010000 ; half carry
!set Z80_XF = %00001000 ; bit 3 result
!set Z80_PF = %00000100 ; parity
!set Z80_OF = %00000100 ; overflow
!set Z80_AF = %00000010 ; add/subtract
!set Z80_VF = %00000100 ; overflow
!set Z80_NF = %00000010 ; subtract
!set Z80_CF = %00000001 ; carry
File diff suppressed because it is too large. Load diff
+142 -1058
View File
File diff suppressed because it is too large. Load diff
+17
View File
@@ -0,0 +1,17 @@
;
; Z80 tables for quickly calculating instruction results
;
z80_ftable_parity:
+PUT_Z80_FTABLE_PARITY
z80_ftable_INC:
+PUT_Z80_FTABLE_INC
z80_ftable_DEC:
+PUT_Z80_FTABLE_DEC
-20
View File
@@ -101,56 +101,40 @@ ZVM_run:
Z80_instr_01: ; LD BC,nn
Z80_instr_02: ; LD (BC),A
Z80_instr_03: ; INC BC
Z80_instr_04: ; INC B
Z80_instr_05: ; DEC B
Z80_instr_07: ; RLCA
Z80_instr_09: ; ADD HL,BC
Z80_instr_0A: ; LD A,(BC)
Z80_instr_0B: ; DEC BC
Z80_instr_0C: ; INC C
Z80_instr_0D: ; DEC C
Z80_instr_0F: ; RRCA
Z80_instr_10: ; DJNZ e
Z80_instr_11: ; LD DE,nn
Z80_instr_12: ; LD (DE),A
Z80_instr_13: ; INC DE
Z80_instr_14: ; INC D
Z80_instr_15: ; DEC D
Z80_instr_17: ; RLA
Z80_instr_18: ; JR e
Z80_instr_19: ; ADD HL,DE
Z80_instr_1A: ; LD A,(DE)
Z80_instr_1B: ; DEC DE
Z80_instr_1C: ; INC E
Z80_instr_1D: ; DEC E
Z80_instr_1F: ; RRA
Z80_instr_20: ; JR NZ,e
Z80_instr_21: ; LD HL,nn
Z80_instr_22: ; LD (nn),HL
Z80_instr_23: ; INC HL
Z80_instr_24: ; INC H
Z80_instr_25: ; DEC H
Z80_instr_27: ; DAA
Z80_instr_28: ; JR Z,e
Z80_instr_29: ; ADD HL,HL
Z80_instr_2A: ; LD HL,(nn)
Z80_instr_2B: ; DEC HL
Z80_instr_2C: ; INC L
Z80_instr_2D: ; DEC L
Z80_instr_2F: ; CPL
Z80_instr_30: ; JR NC,e
Z80_instr_31: ; LD SP,nn
Z80_instr_32: ; LD (nn),A
Z80_instr_33: ; INC SP
Z80_instr_34: ; INC (HL)
Z80_instr_35: ; DEC (HL)
Z80_instr_37: ; SCF
Z80_instr_38: ; JR C,e
Z80_instr_39: ; ADD HL,SP
Z80_instr_3A: ; LD A,(nn)
Z80_instr_3B: ; DEC SP
Z80_instr_3C: ; INC A
Z80_instr_3D: ; DEC A
Z80_instr_3F: ; CCF
Z80_instr_76: ; HALT
Z80_instr_80: ; ADD A,B
@@ -407,8 +391,6 @@ Z80_instr_DD_23: ; DEC IX
Z80_instr_DD_29: ; ADD IX,IX
Z80_instr_DD_2A: ; LD IX,(nn)
Z80_instr_DD_2B: ; DEC IX
Z80_instr_DD_34: ; INC (IX+d)
Z80_instr_DD_35: ; DEC (IX+d)
Z80_instr_DD_39: ; ADD IX,SP
Z80_instr_DD_46: ; LD B,(IX+d)
Z80_instr_DD_4E: ; LD C,(IX+d)
@@ -502,8 +484,6 @@ Z80_instr_FD_23: ; INC IY
Z80_instr_FD_29: ; ADD IY,IY
Z80_instr_FD_2A: ; LD IY,(nn)
Z80_instr_FD_2B: ; DEC IY
Z80_instr_FD_34: ; INC (IY+d)
Z80_instr_FD_35: ; DEC (IY+d)
Z80_instr_FD_39: ; ADD IY,SP
Z80_instr_FD_46: ; LD B,(IY+d)
Z80_instr_FD_4E: ; LD C,(IY+d)
+64 -2
View File
@@ -10,6 +10,22 @@
#include <fstream>
#include <iomanip>
//
// Constants
//
static const uint8_t Z80_SF = 0x80; // sign
static const uint8_t Z80_ZF = 0x40; // zero
static const uint8_t Z80_YF = 0x20; // bit 5 result
static const uint8_t Z80_HF = 0x10; // half carry
static const uint8_t Z80_XF = 0x08; // bit 3 result
static const uint8_t Z80_PF = 0x04; // parity
static const uint8_t Z80_VF = 0x04; // overflow
static const uint8_t Z80_NF = 0x02; // add/subtract
static const uint8_t Z80_CF = 0x01; // carry
//
// Command line settings
//
@@ -59,7 +75,7 @@ void parseCommandLine(int argc, char **argv)
std::string generateParityTable(void)
{
std::string outStr = "!macro PUT_Z80_TABLE_PARITY {\n";;
std::string outStr = "!macro PUT_Z80_FTABLE_PARITY {\n";
for (uint16_t idx = 0; idx < 0x100; idx++)
{
@@ -89,7 +105,51 @@ std::string generateParityTable(void)
}
}
return outStr + "}\n\n\n";;
return outStr + "}\n\n\n";
}
std::string generateIncTable(void)
{
std::stringstream outStr;
outStr << "!macro PUT_Z80_FTABLE_INC {\n";
for (uint16_t idx = 0; idx < 0x100; idx++)
{
uint8_t flags = 0;
if (idx >= 0x7F && idx != 0xFF) flags |= Z80_SF; // for negative result
if (idx == 0xFF) flags |= Z80_ZF; // for result equal 0
if ((idx & 0x0F) == 0x0F) flags |= Z80_HF;
if (idx == 0x7F) flags |= Z80_VF;
outStr << "\t!byte ";
outStr << std::hex << std::setw(2) << int(flags) << "\n";
}
return outStr.str() + "}\n\n\n";
}
std::string generateDecTable(void)
{
std::stringstream outStr;
outStr << "!macro PUT_Z80_FTABLE_DEC {\n";
for (uint16_t idx = 0; idx < 0x100; idx++)
{
uint8_t flags = Z80_NF;
if (idx >= 0x81 || idx == 0x00) flags |= Z80_SF; // for negative result
if (idx == 0x01) flags |= Z80_ZF; // for result equal 0
if ((idx & 0x0F) == 0x00) flags |= Z80_HF;
if (idx == 0x80) flags |= Z80_VF;
outStr << "\t!byte ";
outStr << std::hex << std::setw(2) << int(flags) << "\n";
}
return outStr.str() + "}\n\n\n";
}
std::string generateDaaTables()
@@ -122,6 +182,8 @@ void writeTables()
// Write tables
outFile << generateParityTable();
outFile << generateIncTable();
outFile << generateDecTable();
outFile << generateDaaTables();
// XXX