kosarev / z80

Fast and flexible Z80/i8080 emulator with C++ and Python APIs
MIT License
65 stars 10 forks source link

missing OTIR #1

Closed jariseon closed 4 years ago

jariseon commented 4 years ago

hi ivan. i've been evaluating cpu emulators and was able to get your z80 up and running in an hour or so. thanks for great work.

in one of my tests i hit an assert. i suppose that was due to a missing OTIR handler. added the code below, though i'm unsure if it is entirely correct. no idea about tick count.

void on_otir() {
  fast_u16 hl = self().on_get_hl();
  fast_u16 bc = self().on_get_bc();
  fast_u8 b = bc >> 8;
  fast_u8 c = bc & 0xff;
  while (b--) {
    fast_u8 t = self().on_read_cycle(hl);
    self().on_output(c, t);
    hl = inc16(hl);
  }
  self().on_set_bc(make16(0,c));
  self().on_set_hl(hl);
  fast_u8 f = self().on_get_f();
  f |= zf_mask;
  f &= ~nf_mask;
  self().on_set_f(f);
}
kosarev commented 4 years ago

Thanks for reporting this, @jariseon. The code looks reasonable. I will need to take a closer look and check it against the specs I have. Should be able to it tomorrow evening. Thanks again!

kosarev commented 4 years ago

@jariseon Addressed in https://github.com/kosarev/z80/commit/8de084ac927a7cc972767c8389c7813b73b81db3. Can you check if the fix works for you, please?

jariseon commented 4 years ago

yes, it works! thanks a million.

btw, do the fast int types provide substantial performance improvements? for some reason i have totally missed them, and only used the basic types like uint8_t in my projects.

kosarev commented 4 years ago

Sure, no problem. Re fast_* types: they are primarily to avoid unnecessary truncations and extra warnings about integer promotions from uint8_t. I don't have any specific numbers, but logic suggests the less the number of truncations, the faster the code.

Closing this.