diff options
-rw-r--r-- | emucpm.z80 | 14 | ||||
-rw-r--r-- | rundoc | 2 | ||||
-rw-r--r-- | test.z80 | 33 | ||||
-rw-r--r-- | z80_decode.c | 45 |
4 files changed, 63 insertions, 31 deletions
@@ -7,14 +7,22 @@ org 5 jp cpm - org $ff00 + org $f000 cpm: + push af + push bc + push de + push hl ld a,9 cp c - jr z,print_string + call z,print_string ld a,2 cp c - jr z,print_char + call z,print_char + pop hl + pop de + pop bc + pop af ret print_string: @@ -2,3 +2,5 @@ i emucpm.hex l zexdoc.com 0x100 s r 0x100 +#p 0x100 +#n @@ -3,15 +3,30 @@ ; org 0 - ld hl,$1234 + ld bc,1 + ld de,2 + ld hl,3 + ld ix,4 + ld iy,5 + + push af + push bc + push de push hl + push ix + push iy + add a,80 + ld bc,$ffff + ld de,$ffff + ld hl,$ffff + ld ix,$ffff + ld iy,$ffff + pop iy + pop ix + pop hl + pop de + pop bc pop af - ld bc,$5678 - ld de,$9abc - ld hl,$def0 - ld ix,$dead - ld iy,$beef - loop: - inc b - jp loop + add ix,bc + jr loop diff --git a/z80_decode.c b/z80_decode.c index 5b8207d..52a0423 100644 --- a/z80_decode.c +++ b/z80_decode.c @@ -262,17 +262,17 @@ do { \ do { \ REG++; \ cpu->AF.b[LO]=CARRY|SZtable[REG]; \ - if (REG&0x80) cpu->AF.b[LO]|=P_Z80; \ - if (REG&0x0f) cpu->AF.b[LO]|=H_Z80; \ + if (REG==0x80) cpu->AF.b[LO]|=P_Z80; \ + if ((REG&0x0f)==0) cpu->AF.b[LO]|=H_Z80; \ } while(0) #define DEC8(REG) \ do { \ - cpu->AF.b[LO]=N_Z80|CARRY; \ - if (REG&0x80) cpu->AF.b[LO]|=P_Z80; \ - if (REG&0x0f) cpu->AF.b[LO]|=H_Z80; \ REG--; \ + cpu->AF.b[LO]=N_Z80|CARRY; \ + if (REG==0x7f) cpu->AF.b[LO]|=P_Z80; \ + if ((REG&0x0f)==0x0f) cpu->AF.b[LO]|=H_Z80; \ cpu->AF.b[LO]|=SZtable[REG]; \ } while(0) @@ -281,7 +281,7 @@ do { \ */ #define RRCA \ do { \ - cpu->AF.b[LO]=(cpu->AF.b[LO]&0xec)|(cpu->AF.b[HI]&C_Z80); \ + cpu->AF.b[LO]=(cpu->AF.b[LO]&0xc8)|(cpu->AF.b[HI]&C_Z80); \ cpu->AF.b[HI]=(cpu->AF.b[HI]>>1)|(cpu->AF.b[HI]<<7); \ SETHIDDEN(cpu->AF.b[HI]); \ } while(0) @@ -291,7 +291,7 @@ do { \ do { \ Z80Byte c; \ c=CARRY; \ - cpu->AF.b[LO]=(cpu->AF.b[LO]&0xec)|(cpu->AF.b[HI]&C_Z80); \ + cpu->AF.b[LO]=(cpu->AF.b[LO]&0xc8)|(cpu->AF.b[HI]&C_Z80); \ cpu->AF.b[HI]=(cpu->AF.b[HI]>>1)|(c<<7); \ SETHIDDEN(cpu->AF.b[HI]); \ } while(0) @@ -319,7 +319,7 @@ do { \ #define RLCA \ do { \ - cpu->AF.b[LO]=(cpu->AF.b[LO]&0xec)|(cpu->AF.b[HI]>>7); \ + cpu->AF.b[LO]=(cpu->AF.b[LO]&0xc8)|(cpu->AF.b[HI]>>7); \ cpu->AF.b[HI]=(cpu->AF.b[HI]<<1)|(cpu->AF.b[HI]>>7); \ SETHIDDEN(cpu->AF.b[HI]); \ } while(0) @@ -329,7 +329,7 @@ do { \ do { \ Z80Byte c; \ c=CARRY; \ - cpu->AF.b[LO]=(cpu->AF.b[LO]&0xec)|(cpu->AF.b[HI]>>7); \ + cpu->AF.b[LO]=(cpu->AF.b[LO]&0xc8)|(cpu->AF.b[HI]>>7); \ cpu->AF.b[HI]=(cpu->AF.b[HI]<<1)|c; \ SETHIDDEN(cpu->AF.b[HI]); \ } while(0) @@ -683,7 +683,7 @@ do { \ /* ---------------------------------------- BASE OPCODE SHORT-HAND BLOCKS */ -#define LD_BLOCK(BASE,DEST) \ +#define LD_BLOCK(BASE,DEST,DEST2) \ case BASE: /* LD DEST,B */ \ TSTATE(4); \ DEST=cpu->BC.b[HI]; \ @@ -717,7 +717,7 @@ do { \ case BASE+6: /* LD DEST,(HL) */ \ TSTATE(7); \ OFFSET(off); \ - DEST=cpu->memory[*HL+off]; \ + DEST2=cpu->memory[*HL+off]; \ break; \ \ case BASE+7: /* LD DEST,A */ \ @@ -1994,7 +1994,7 @@ void Z80_Decode(Z80 *cpu, Z80Byte opcode) case 0x29: /* ADD HL,HL */ TSTATE(11); - ADD16(*HL,cpu->HL.w); + ADD16(*HL,*HL); break; case 0x2a: /* LD HL,(nnnn) */ @@ -2066,6 +2066,7 @@ void Z80_Decode(Z80 *cpu, Z80Byte opcode) case 0x37: /* SCF */ TSTATE(4); + CLRFLAG(H_Z80); SETFLAG(C_Z80); break; @@ -2105,15 +2106,21 @@ void Z80_Decode(Z80 *cpu, Z80Byte opcode) case 0x3f: /* CCF */ TSTATE(4); + + if (CARRY) + SETFLAG(H_Z80); + else + CLRFLAG(H_Z80); + cpu->AF.b[LO]^=C_Z80; break; - LD_BLOCK(0x40,cpu->BC.b[HI]) - LD_BLOCK(0x48,cpu->BC.b[LO]) - LD_BLOCK(0x50,cpu->DE.b[HI]) - LD_BLOCK(0x58,cpu->DE.b[LO]) - LD_BLOCK(0x60,*H) - LD_BLOCK(0x68,*L) + LD_BLOCK(0x40,cpu->BC.b[HI],cpu->BC.b[HI]) + LD_BLOCK(0x48,cpu->BC.b[LO],cpu->BC.b[LO]) + LD_BLOCK(0x50,cpu->DE.b[HI],cpu->DE.b[HI]) + LD_BLOCK(0x58,cpu->DE.b[LO],cpu->DE.b[LO]) + LD_BLOCK(0x60,*H,cpu->HL.b[HI]) + LD_BLOCK(0x68,*L,cpu->HL.b[LO]) case 0x70: /* LD (HL),B */ TSTATE(7); @@ -2167,7 +2174,7 @@ void Z80_Decode(Z80 *cpu, Z80Byte opcode) cpu->memory[*HL+off]=cpu->AF.b[HI]; break; - LD_BLOCK(0x78,cpu->AF.b[HI]) + LD_BLOCK(0x78,cpu->AF.b[HI],cpu->AF.b[HI]) ALU_BLOCK(0x80,ADD8) ALU_BLOCK(0x88,ADC8) |