コード例 #1
0
ファイル: damf.cpp プロジェクト: Plombo/dega
int Damf_ED_101x_x00x(unsigned int op)
{
//     ED 101r s000    Transfer bytes from (hl) to (de)
//     ED 101r s001    compare bytes at (hl)
//   r -> once/repeat   s -> ++/--

// e.g ED 1011 0000  ldir

  DamOpStart(op);
  ot("  ; cp/ld/i/d/r\n");
  DamGet16("di",2,0);
  ot("  DAM_READ8\n");

  if (op&1)
  {
    // cp
    ot("  mov dh,ah\n");
    ot("  and dh,0x01\n");
    ot("  cmp al,dl\n");
    ot("  lahf\n");
    ot("  and ah,0xd0 ; SZ-H ----\n");
    ot("  or  ah,0x02 ; SZ-H --N-\n");
    ot("  or  ah,dh   ; SZ-H --NC\n");
    ot("  ; Now work out A-(HL)-H: for bits 5 and 3\n");
    ot("  sub dl,al\n");
    ot("  neg dl ; A-(HL)\n");
    ot("  mov dh,ah\n");
    ot("  ror dh,4\n");
    ot("  and dh,0x01\n");
    ot("  sub dl,dh ; A-(HL)-H\n");
  }
  else
  {
    // ld
    DamGet16("di",1,0);
    ot("  DAM_WRITE8\n");
    ot("  and ah,0xc1 ; SZ-H --NC  (SZC preserved, H=0, N=0)\n");
    ot("  ; Now work out A+(HL): for bits 5 and 3\n");
    ot("  add dl,al\n");
  }

  ot("  xor dh,dh\n");
  ot("  test dl,0x02 ; Bit 5 is copied from bit 1\n");
  ot("  setnz dh\n");
  ot("  rol dh,5\n");
  ot("  or ah,dh ; SZ5H --NC\n");

  ot("  mov dh,dl\n");
  ot("  and dh,0x08\n");
  ot("  or ah,dh ; SZ5H 3-NC\n");

  if ((op&1)==0)
  {
    ot("  ; Update DE\n");
    if (op&8) ot("  dec "); else ot("  inc ");
    ot("%s\n",DamLoc16(1,0));
  }

  ot("  ; Update HL\n");
  if (op&8) ot("  dec "); else ot("  inc ");
  ot("%s\n",DamLoc16(2,0));

  ot("  ; Update BC\n");
  ot("  dec %s\n",DamLoc16(0,0));

  ot("; Check if BC==0\n");
  ot("  xor dh,dh\n");
  ot("  test %s,0xffff\n",DamLoc16(0,0));
  ot("  setnz dh\n");
  ot("  rol dh,2\n");
  ot("  or ah,dh ; SZ5H 3VNC\n");

  if (op&0x10)
  {
    static int Lab=0;
    ot("; Stop repeating if BC==0\n");
    ot("  test ah,0x04 ; ---- -V--\n");
    ot("  jz Done%d\n",Lab);

    if (op&1)
    {
      ot("; Stop repeating if a-(HL) == 0\n");
      ot("  test ah,0x40 ; -Z-- ----\n");
      ot("  jnz Done%d\n",Lab);
    }

    ot("  ; Repeat instruction\n");
    ot("  INC_R\n");
    DamAddPc(-2);

    DamOpDone(17,0);
    ot("Done%d:\n",Lab++);
  }
  
  DamOpDone(12,0);
  return op;
}
コード例 #2
0
ファイル: damm.cpp プロジェクト: alfredox123/pifba
int DamMacros()
{
  ot(
  "%%macro SAVE_REGS 0\n"
  "  push ebx\n  push ecx\n  push edx\n  push esi\n  push edi\n  push ebp\n"
  "%%endmacro\n\n"

  "%%macro RESTORE_REGS 0\n"
  "  pop ebp\n  pop edi\n  pop esi\n  pop edx\n  pop ecx\n  pop ebx\n"
  "%%endmacro\n\n"
  );

  ot(
  "%%macro DOZE_TO_REG 0\n"
  "  ; Load a into al, f into ah\n"
  "  mov ax,word [DozeAF]\n"
  "  ror ax,8\n"
  "  ; Load hl into cx\n"
  "  mov cx,word [DozeHL]\n"
  "  mov bl,byte [DozeIR] ; Load bl <- R counter\n"
  "  rol bl,1 ; bl <-- R register bits (65432107)\n"
  "  xor esi,esi\n"
  "  mov si,word [DozePC] ; Load si <- PC\n"
  "%%endmacro\n\n"

  "%%macro REG_BLANK 0\n"
  "  xor edx,edx ; High 16 bits of edx kept clear\n"
  "  xor edi,edi ; High 16 bits of edi kept clear\n"
  "%%endmacro\n\n"

  "%%macro REG_TO_DOZE 0\n"
  "  ; Save a from al, f from ah\n"
  "  ror ax,8\n"
  "  mov word [DozeAF],ax\n"
  "  ; Save hl from cx\n"
  "  mov word [DozeHL],cx\n"
  "  ror bl,1 ; bl --> R register bits 76543210\n"
  "  mov byte [DozeIR],bl ; Save bl -> R counter\n"
  "  mov word [DozePC],si ; Save si -> PC\n"
  "%%endmacro\n\n"
  );

  // Memory access based on _DozeMemFetch/Read/Write:
  ot(
  "%%macro DAM_FETCH8 0\n"
  "; Fetch byte (esi) ==> dl\n"
  "  mov edx,esi\n"
  "  shr edx,8\n"
  "  mov ebp,[DozeMemFetch]\n"
  "  mov ebp,dword[ebp+edx*4]\n"
  "  mov dl,byte [ebp+esi]\n"
  "%%endmacro\n\n"

   "%%macro DAM_FETCH8D 0\n"
  "; Fetch byte (esi) ==> dl\n"
  "  mov edx,esi\n"
  "  shr edx,8\n"
  "  mov ebp,[DozeMemFetchData]\n"
  "  mov ebp,dword[ebp+edx*4]\n"
  "  mov dl,byte [ebp+esi]\n"
  "%%endmacro\n\n"

  "%%macro DAM_FETCH16D 0\n"
  "; Fetch word  (esi) ==> dx\n"
  "  mov edx,esi\n"
  "  shr edx,8\n"
  "  mov ebp,[DozeMemFetchData]\n"
  "  mov ebp,dword[ebp+edx*4]\n"
  "  mov dx,word [ebp+esi]\n"
  "%%endmacro\n\n"

  "%%macro DAM_READ8 0\n"
  "; Read byte   (edi) ==> dl\n"
  "  mov edx,edi\n"
  "  shr edx,8\n"
  "  mov ebp,[DozeMemRead]\n"
  "  mov ebp,dword[ebp+edx*4]\n"
  "  test ebp,ebp\n"
  "  jnz %%%%Direct\n"
  "  call Read\n"
  "  jmp %%%%Done\n"
  "%%%%Direct:\n"
  "  mov dl,byte [ebp+edi]\n"
  "%%%%Done:\n"
  "%%endmacro\n\n"

  "%%macro DAM_WRITE8 0\n"
  "; Write byte  dl ==> (edi)\n"
  "  mov ebp,edi\n"
  "  shr ebp,8\n"
  "  shl ebp,2\n"
  "  add ebp,[DozeMemWrite]\n"
  "  mov ebp,dword[ebp]\n"
  "  test ebp,ebp\n"
  "  jnz %%%%Direct\n"
  "  call Write\n"
  "  jmp %%%%Done\n"
  "%%%%Direct:\n"
  "  mov byte [ebp+edi],dl\n"
  "%%%%Done:\n"
  "%%endmacro\n\n"

  "%%macro DAM_READ16 0\n"
  "; Read word   (edi) ==> dx\n"
  "  mov edx,edi\n"
  "  shr edx,8\n"
  "  mov ebp,[DozeMemRead]\n"
  "  mov ebp,dword[ebp+edx*4]\n"
  "  test ebp,ebp\n"
  "  jnz %%%%Direct\n"
  "  inc di\n"
  "  call Read\n"
  "  dec di\n"
  "  mov dh,dl\n"
  "  jmp %%%%Done\n"
  "  call Read\n"
  "%%%%Direct:\n"
  "  mov dx,word [ebp+edi]\n"
  "%%%%Done:\n"
  "%%endmacro\n\n"

  "%%macro DAM_WRITE16 0\n"
  "; Write word  dx ==> (edi)\n"
  "  mov ebp,edi\n"
  "  shr ebp,8\n"
  "  shl ebp,2\n"
  "  add ebp,[DozeMemWrite]\n"
  "  mov ebp,dword[ebp]\n"
  "  test ebp,ebp\n"
  "  jnz %%%%Direct\n"
  "  inc di\n"
  "  ror dx,8\n"
  "  call Write\n"
  "  dec di\n"
  "  ror dx,8\n"
  "  call Write\n"
  "  jmp %%%%Done\n"
  "%%%%Direct:\n"
  "  mov word [ebp+edi],dx\n"
  "%%%%Done:\n"
  "%%endmacro\n\n"
  );

  ot(
  "%%macro FETCH_OP 0\n"
  "  ; Fetch next normal opcode\n"
  );

  DamFetch(0,3); DamAddPc(1);
  ot(
  "  xor dh,dh\n"
  "  jmp [JumpTab+edx*4]\n"
  "%%endmacro\n\n"
  );

  ot(
  "%%macro INC_R 0\n"
  "  add bl,2 ; Increase instruction counter R (bit 7 never modified)\n"
  "%%endmacro\n\n"
  );
  return 0;
}
コード例 #3
0
ファイル: damf.cpp プロジェクト: Plombo/dega
int Damf_ED_101x_x11x(unsigned int op)
{
  static int Lab=0;
//     ED 101r s000    ini /r/d
//     ED 101r s001    outi/r/d
  DamOpStart(op);
  ot("; Repeating I/O\n");

  if ((op&1)==0)
  {
    ot("  ; Read port (bc)\n");
    DamGet16("di",0,0);
    ot("  call PortIn ; Read port dl <-- di\n");
    ot("  mov bh,dl ; Remember port byte\n");
    ot("  ; Write to (hl)\n");
    DamGet16("di",2,0);
    ot("  DAM_WRITE8\n");
  }
  else
  {
    ot("  ; Read from (hl)\n");
    DamGet16("di",2,0);
    ot("  DAM_READ8\n");
    ot("  mov bh,dl ; Remember port byte\n");
  }

  if (op&8) ot("  dec di ; Decrement hl\n");
  else      ot("  inc di ; Increment hl\n");
  DamPut16("di",2,0);

  if (op&1)
  {
    ot("  ; Write to port (bc)\n");
    DamGet16("di",0,0);
    ot("  call PortOut ; Write port dl --> di\n");
  }

  ot("  ; Decrease b\n");
  DamGet8("dl",0,0);
  ot("  dec dl\n");
  DamPut8("dl",0,0);

  ot("  xor dh,dh\n");
  ot("  mov ah,byte [DecFlag+edx] ; flags based on dec b\n");
  ot("  and ah,0xe8 ; SZ5- 3---\n");

  ot("  ; Get negative bit from the port byte\n");
  ot("  mov dh,bh\n");
  ot("  rol dh,2\n");
  ot("  and dh,2\n");
  ot("  or  ah,dh   ; SZ5- 3-N-\n");

  ot("  ; Get H and C based on c + byte\n");
  DamGet8("dl",1,0);
  if (op&1) ot("  dec dl\n"); else  ot("  inc dl\n");
  ot("  add dl,bh\n");
  ot("  setc dl\n");
  ot("  and dl,1\n");
  ot("  mov dh,dl\n");
  ot("  rol dh,4\n");
  ot("  or dl,dh\n");
  ot("  or ah,dl ; SZ5H 3-NC\n");

  if (op&0x10)
  {
    ot("; Stop repeating if B==0\n");
    ot("  test ah,0x40\n");
    ot("  jnz IoStop%d\n",Lab);
    ot("  ; Repeat instruction\n");
    ot("  INC_R\n");
    
    DamAddPc(-2);
    DamOpDone(17,0);
    ot("IoStop%d:\n",Lab++);
    ot("  or ah,0x04 ; SZ5H 3VNC\n");
  }

  DamOpDone(12,0);
  return op;
}
コード例 #4
0
ファイル: damo.cpp プロジェクト: alfredox123/pifba
int DamoOp(unsigned int op)
{
  if (op==0x00)
  {
    ot("  ; 00 - nop\n");
    DamOpStart(op);
    DamOpDone(4,0);
    return op;
  }

  if (op==0x02)
  {
    DamOpStart(op);
    ot("  ; 02 - ld (bc),a\n");
    ot("  ; Get Save address:\n");
    DamGet16("di",0,0);
    ot("  mov dl,al\n");
    ot("  DAM_WRITE8 ; Save to address\n");
    DamOpDone(7,0);
    return op;
  }

  if (op==0x08)
  {
    DamOpStart(op);
    ot("  ; 08 - ex af,af'\n");
    ot("  rol ax,8\n");
    ot("  mov dx,ax\n");
    ot("  mov ax,word [DozeAF2]\n");
    ot("  mov word [DozeAF2],dx\n");
    ot("  rol ax,8\n");
    DamOpDone(4,0);
    return op;
  }

  if (op==0x0a)
  {
    DamOpStart(op);
    ot("  ; 0a - ld a,(bc)\n");
    ot("  ; Get Load address:\n");
    DamGet16("di",0,0);
    ot("  DAM_READ8 ; Load from address\n");
    ot("  mov al,dl\n");
    DamOpDone(7,0);
    return op;
  }

  if (op==0x10)
  {
    static int Lab=0;
    DamOpStart(op);
    DamAddPc(1);
    ot("  ; 10 nn - djnz +nn\n");

    DamGet8("dl",0,0);
    ot("  dec dl\n");
    ot("  jnz BNotZero%d\n",Lab);
    DamPut8("dl",0,0);
    DamOpDone( 8,0);

    ot("BNotZero%d:\n",Lab++);
    DamPut8("dl",0,0);
    ot("  ; Get Jump offset:\n");
    DamFetch(-1,1);
    ot("  xor dh,dh\n");
    ot("  xor dl,0x80\n");
    ot("  sub dx,0x80\n");
    ot("  add %s,dx\n",DamPc);
    DamOpDone(13,0);
    return op;
  }

  if (op==0x12)
  {
    DamOpStart(op);
    ot("  ; 02 - ld (de),a\n");
    ot("  ; Get Save address:\n");
    DamGet16("di",1,0);
    ot("  mov dl,al\n");
    ot("  DAM_WRITE8 ; Save to address\n");
    DamOpDone(7,0);
    return op;
  }

  if (op==0x18)
  {
    ot("  ; 18 nn - jr +nn\n");
    DamOpStart(op);
    ot("  ; Get Jump offset:\n");
    DamFetch(0,1); DamAddPc(1);
    ot("  xor dh,dh\n");
    ot("  xor dl,0x80\n");
    ot("  sub dx,0x80\n");
    ot("  add %s,dx\n",DamPc);
    DamOpDone(12,0);
    return op;
  }

  if (op==0x1a)
  {
    DamOpStart(op);
    ot("  ; 0a - ld a,(de)\n");
    ot("  ; Get Load address:\n");
    DamGet16("di",1,0);
    ot("  DAM_READ8 ; Load from address\n");
    ot("  mov al,dl\n");
    DamOpDone(7,0);
    return op;
  }

  if (op==0x27)
  {
    DamOpStart(op);
    ot("  ; 27 - daa\n");
    ot("  mov dh,ah\n");
    ot("  ror dh,2   ;H-- ---- ----\n");
    ot("  and dx,0x400\n");
    ot("  and ax,0x3ff\n");
    ot("  or  dx,ax ; HNC nnnn nnnn\n");
    ot("  mov ax,word[DaaTable+edx*2] ; Get flags and value in one go\n");
    DamOpDone(4,0);
    return op;
  }

  if (op==0x2f)
  {
    DamOpStart(op);
    ot("  ; 2f - cpl\n");
    ot("  and ah,0xc5 ; SZ-- -P-C\n");
    ot("  not al\n");
    ot("  or  ah,0x12 ; SZ-H -PNC\n");
    ot("  mov dh,al\n");
    ot("  and dh,0x28\n");
    ot("  or  ah,dh   ; SZ5H 3PNC\n");
    DamOpDone(4,0);
    return op;
  }

  if (op==0x32)
  {
    DamOpStart(op);
    ot("  ; 32 nn nn - ld ($nnnn),a\n");
    ot("  ; Get Save address:\n");
    DamFetch(0,2); DamAddPc(2);
    ot("  mov di,dx\n");
    ot("  mov dl,al\n");
    ot("  DAM_WRITE8 ; Save to address\n");
    DamOpDone(13,0);
    return op;
  }

  if (op==0x37)
  {
    DamOpStart(op);
    ot("  ; 37 - scf - set carry flag\n");
    ot("  and ah,0xc4\n");
    ot("  or  ah,0x01\n");
    DamOpDone(4,0);
    return op;
  }

  if (op==0x3a)
  {
    DamOpStart(op);
    ot("  ; 3a nn nn - ld a,($nnnn)\n");
    ot("  ; Get Load address:\n");
    DamFetch(0,2); DamAddPc(2);
    ot("  mov di,dx\n");
    ot("  DAM_READ8 ; Load from address\n");
    ot("  mov al,dl\n");
    DamOpDone(13,0);
    return op;
  }

  if (op==0x3f)
  {
    DamOpStart(op);
    ot("  ; 3f - ccf - complement carry flag\n");
    ot("  mov dh,ah\n");
    ot("  and ah,0xc5\n");
    ot("  rol dh,4\n");
    ot("  xor ah,0x01\n");
    ot("  and dh,0x10\n");
    ot("  or  ah,dh ; H is last Carry value\n");
    DamOpDone(4,0);
    return op;
  }

  if (op==0xc3)
  {
    DamOpStart(op);
    ot("  ; c3 nn nn - jp $nnnn\n");
    DamFetch(0,2);
    ot("  mov %s,dx\n",DamPc);
    DamOpDone(10,0);
    return op;
  }

  if (op==0xc9)
  {
    DamOpStart(op);
    ot("  ; c9 - ret\n");
    ot("  mov di,word [DozeSP]\n");
    ot("  DAM_READ16\n");
    ot("  mov %s,dx\n",DamPc);
    ot("  add word [DozeSP],2\n");
    DamOpDone(10,0);
    return op;
  }

  if (op==0xcb)
  {
    DamOpStart(op);
    ot("  ; %x - extend opcode, take 4 cycles\n",op);
    DamOpDone(4,1);
    DamFetch(0,3); DamAddPc(1);
    ot("  xor dh,dh\n");
    ot("  jmp [JumpTabCB+edx*4]\n\n");
    return op;
  }

  if (op==0xcd)
  {
    DamOpStart(op);
    ot("  ; cd nn nn - call $nnnn\n");
    ot("  sub word [DozeSP],2\n");
    ot("  mov di,word [DozeSP]\n");
    DamAddPc(2);
    ot("  mov dx,%s\n",DamPc);
    ot("  DAM_WRITE16\n");
    DamFetch(-2,2);
    ot("  mov %s,dx\n",DamPc);
    DamOpDone(17,0);
    return op;
  }

  if (op==0xddcb || op==0xfdcb)
  {
    DamOpStart(op);
    ot("  ; %x - extend opcode, take another 4 cycles\n",op);
    DamOpDone(4,1);
    ot("  ; Fetch op, and skip the I?+nn byte:\n");
    DamFetch(1,1); DamAddPc(2);
    ot("  xor dh,dh\n");
    if (op==0xfdcb) ot("  jmp [JumpTabFDCB+edx*4]\n");
    else            ot("  jmp [JumpTabDDCB+edx*4]\n");
    return op;
  }

  if (op==0xd3)
  {
    DamOpStart(op);
    ot("  ; d3 nn - out ($nn),a\n");
    DamFetch(0,1); DamAddPc(1);
    ot("  mov dh,al ; Fill high port byte with a\n");
    ot("  mov di,dx\n");
    ot("  mov dl,al\n");
    ot("  call PortOut ; Write port dl --> di\n");
    DamOpDone(11,0);
    return op;
  }

  if (op==0xdb)
  {
    DamOpStart(op);
    ot("  ; db nn - in a,($nn)\n");
    DamFetch(0,1); DamAddPc(1);
    ot("  mov dh,al ; Fill high port byte with a\n");
    ot("  mov di,dx\n");
    ot("  call PortIn ; Read port dl <-- di\n");
    ot("  mov al,dl\n");
    DamOpDone(11,0);
    return op;
  }

  if (op==0xd9)
  {
    DamOpStart(op);
    ot("  ; exx - flip registers BC,DE and HL with prime registers\n");

    DamGet16("dx",0,0);
    ot("  mov di,word[DozeBC2]\n");
    ot("  mov word[DozeBC2],dx\n");
    DamPut16("di",0,0);

    DamGet16("dx",1,0);
    ot("  mov di,word[DozeDE2]\n");
    ot("  mov word[DozeDE2],dx\n");
    DamPut16("di",1,0);

    DamGet16("dx",2,0);
    ot("  mov di,word[DozeHL2]\n");
    ot("  mov word[DozeHL2],dx\n");
    DamPut16("di",2,0);
    DamOpDone(4,0);
    return op;
  }

  if (op==0xdd)
  {
    DamOpStart(op);
    ot("  ; dd - extend opcode, take 4 cycles\n");
    DamOpDone(4,1);
    DamFetch(0,3); DamAddPc(1);
    ot("  xor dh,dh\n");
    ot("  jmp [JumpTabDD+edx*4]\n\n");
    return op;
  }

  if ((op&0xff)==0xe9)
  {
    int Ext=0;
    Ext=op>>8;
    DamOpStart(op);
    ot("  ; e9 - jp (hl) - PC <- HL/IX/IY\n");
    DamGet16("dx",2,Ext);
    ot("  mov %s,dx\n",DamPc);
    DamOpDone(4,0);
    return op;
  }