Game boy模拟器:完整的 Z80 内核CPU源码

Posted 妇男主人

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Game boy模拟器:完整的 Z80 内核CPU源码相关的知识,希望对你有一定的参考价值。

/**
 * jsGB: Z80 core
 * Imran Nazar, May 2009
 * Notes: This is a GameBoy Z80, not a Z80. There are differences.
 * Bugs: If PC wraps at the top of memory, this will not be caught until the end of an instruction
 */

Z80 = {
  _r: {
    a:0, b:0, c:0, d:0, e:0, h:0, l:0, f:0,
    sp:0, pc:0, i:0, r:0,
    m:0, t:0,
    ime:0
  },

  _clock: {m:0, t:0},

  _halt: 0,
  _stop: 0,

  reset: function() {
    Z80._r.a=0; Z80._r.b=0; Z80._r.c=0; Z80._r.d=0; Z80._r.e=0; Z80._r.h=0; Z80._r.l=0; Z80._r.f=0;
    Z80._r.sp=0; Z80._r.pc=0; Z80._r.i=0; Z80._r.r=0;
    Z80._r.m=0; Z80._r.t=0;
    Z80._halt=0; Z80._stop=0;
    Z80._clock.m=0; Z80._clock.t=0;
    Z80._r.ime=1;
  },

  exec: function() {
    Z80._r.r = (Z80._r.r+1) & 127;
    Z80._map[MMU.rb(Z80._r.pc++)]();
    Z80._r.pc &= 65535;
    Z80._clock.m += Z80._r.m; Z80._clock.t += Z80._r.t;
    if(MMU._inbios && Z80._r.pc == 0x0100) MMU._inbios=0;
  },

  _ops: {
    /*--- Load/store ---*/
    LDrr_bb: function() { Z80._r.b=Z80._r.b; Z80._r.m=1; Z80._r.t=4; },
    LDrr_bc: function() { Z80._r.b=Z80._r.c; Z80._r.m=1; Z80._r.t=4; },
    LDrr_bd: function() { Z80._r.b=Z80._r.d; Z80._r.m=1; Z80._r.t=4; },
    LDrr_be: function() { Z80._r.b=Z80._r.e; Z80._r.m=1; Z80._r.t=4; },
    LDrr_bh: function() { Z80._r.b=Z80._r.h; Z80._r.m=1; Z80._r.t=4; },
    LDrr_bl: function() { Z80._r.b=Z80._r.l; Z80._r.m=1; Z80._r.t=4; },
    LDrr_ba: function() { Z80._r.b=Z80._r.a; Z80._r.m=1; Z80._r.t=4; },
    LDrr_cb: function() { Z80._r.c=Z80._r.b; Z80._r.m=1; Z80._r.t=4; },
    LDrr_cc: function() { Z80._r.c=Z80._r.c; Z80._r.m=1; Z80._r.t=4; },
    LDrr_cd: function() { Z80._r.c=Z80._r.d; Z80._r.m=1; Z80._r.t=4; },
    LDrr_ce: function() { Z80._r.c=Z80._r.e; Z80._r.m=1; Z80._r.t=4; },
    LDrr_ch: function() { Z80._r.c=Z80._r.h; Z80._r.m=1; Z80._r.t=4; },
    LDrr_cl: function() { Z80._r.c=Z80._r.l; Z80._r.m=1; Z80._r.t=4; },
    LDrr_ca: function() { Z80._r.c=Z80._r.a; Z80._r.m=1; Z80._r.t=4; },
    LDrr_db: function() { Z80._r.d=Z80._r.b; Z80._r.m=1; Z80._r.t=4; },
    LDrr_dc: function() { Z80._r.d=Z80._r.c; Z80._r.m=1; Z80._r.t=4; },
    LDrr_dd: function() { Z80._r.d=Z80._r.d; Z80._r.m=1; Z80._r.t=4; },
    LDrr_de: function() { Z80._r.d=Z80._r.e; Z80._r.m=1; Z80._r.t=4; },
    LDrr_dh: function() { Z80._r.d=Z80._r.h; Z80._r.m=1; Z80._r.t=4; },
    LDrr_dl: function() { Z80._r.d=Z80._r.l; Z80._r.m=1; Z80._r.t=4; },
    LDrr_da: function() { Z80._r.d=Z80._r.a; Z80._r.m=1; Z80._r.t=4; },
    LDrr_eb: function() { Z80._r.e=Z80._r.b; Z80._r.m=1; Z80._r.t=4; },
    LDrr_ec: function() { Z80._r.e=Z80._r.c; Z80._r.m=1; Z80._r.t=4; },
    LDrr_ed: function() { Z80._r.e=Z80._r.d; Z80._r.m=1; Z80._r.t=4; },
    LDrr_ee: function() { Z80._r.e=Z80._r.e; Z80._r.m=1; Z80._r.t=4; },
    LDrr_eh: function() { Z80._r.e=Z80._r.h; Z80._r.m=1; Z80._r.t=4; },
    LDrr_el: function() { Z80._r.e=Z80._r.l; Z80._r.m=1; Z80._r.t=4; },
    LDrr_ea: function() { Z80._r.e=Z80._r.a; Z80._r.m=1; Z80._r.t=4; },
    LDrr_hb: function() { Z80._r.h=Z80._r.b; Z80._r.m=1; Z80._r.t=4; },
    LDrr_hc: function() { Z80._r.h=Z80._r.c; Z80._r.m=1; Z80._r.t=4; },
    LDrr_hd: function() { Z80._r.h=Z80._r.d; Z80._r.m=1; Z80._r.t=4; },
    LDrr_he: function() { Z80._r.h=Z80._r.e; Z80._r.m=1; Z80._r.t=4; },
    LDrr_hh: function() { Z80._r.h=Z80._r.h; Z80._r.m=1; Z80._r.t=4; },
    LDrr_hl: function() { Z80._r.h=Z80._r.l; Z80._r.m=1; Z80._r.t=4; },
    LDrr_ha: function() { Z80._r.h=Z80._r.a; Z80._r.m=1; Z80._r.t=4; },
    LDrr_lb: function() { Z80._r.l=Z80._r.b; Z80._r.m=1; Z80._r.t=4; },
    LDrr_lc: function() { Z80._r.l=Z80._r.c; Z80._r.m=1; Z80._r.t=4; },
    LDrr_ld: function() { Z80._r.l=Z80._r.d; Z80._r.m=1; Z80._r.t=4; },
    LDrr_le: function() { Z80._r.l=Z80._r.e; Z80._r.m=1; Z80._r.t=4; },
    LDrr_lh: function() { Z80._r.l=Z80._r.h; Z80._r.m=1; Z80._r.t=4; },
    LDrr_ll: function() { Z80._r.l=Z80._r.l; Z80._r.m=1; Z80._r.t=4; },
    LDrr_la: function() { Z80._r.l=Z80._r.a; Z80._r.m=1; Z80._r.t=4; },
    LDrr_ab: function() { Z80._r.a=Z80._r.b; Z80._r.m=1; Z80._r.t=4; },
    LDrr_ac: function() { Z80._r.a=Z80._r.c; Z80._r.m=1; Z80._r.t=4; },
    LDrr_ad: function() { Z80._r.a=Z80._r.d; Z80._r.m=1; Z80._r.t=4; },
    LDrr_ae: function() { Z80._r.a=Z80._r.e; Z80._r.m=1; Z80._r.t=4; },
    LDrr_ah: function() { Z80._r.a=Z80._r.h; Z80._r.m=1; <

以上是关于Game boy模拟器:完整的 Z80 内核CPU源码的主要内容,如果未能解决你的问题,请参考以下文章

Game boy模拟器:图形

Game boy模拟器:中断

Game boy模拟器:GPU的时序

Game boy模拟器:运行内存

Game boy模拟器:内存池

Game boy模拟器:输入