Mercurial > repos > blastem
diff vdp.c @ 137:0e7e1ccc0a81
Implemented HV counter
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 30 Dec 2012 22:39:41 -0800 |
parents | a81c548cf353 |
children | aa3e1bb338c9 |
line wrap: on
line diff
--- a/vdp.c Sun Dec 30 18:40:33 2012 -0800 +++ b/vdp.c Sun Dec 30 22:39:41 2012 -0800 @@ -1092,6 +1092,10 @@ if (context->flags & FLAG_DMA_RUN) { value |= 0x20; } + uint32_t line= context->cycles / MCLKS_LINE; + if (line >= (context->latched_mode & BIT_PAL ? PAL_ACTIVE : NTSC_ACTIVE)) { + value |= 0x8; + } //TODO: Lots of other bits in status port return value; } @@ -1131,6 +1135,43 @@ return value; } +uint16_t vdp_hv_counter_read(vdp_context * context) +{ + uint32_t line= context->cycles / MCLKS_LINE; + if (!line) { + line = 0xFF; + } else { + line--; + if (line > 0xEA) { + line = (line + 0xFA) & 0xFF; + } + } + uint32_t linecyc = context->cycles % MCLKS_LINE; + if (context->latched_mode & BIT_H40) { + linecyc /= 8; + if (linecyc >= 86) { + linecyc -= 86; + } else { + linecyc += 334; + } + if (linecyc > 0x16C) { + linecyc += 92; + } + } else { + linecyc /= 10; + if (linecyc >= 74) { + linecyc -= 74; + } else { + linecyc += 268; + } + if (linecyc > 0x127) { + linecyc += 170; + } + } + linecyc &= 0xFF; + return (line << 8) | linecyc; +} + void vdp_adjust_cycles(vdp_context * context, uint32_t deduction) { context->cycles -= deduction;