diff --git a/OSBindings/Mac/Clock SignalTests/MasterSystemVDPTests.mm b/OSBindings/Mac/Clock SignalTests/MasterSystemVDPTests.mm index ec5c36587..5ef2d72b5 100644 --- a/OSBindings/Mac/Clock SignalTests/MasterSystemVDPTests.mm +++ b/OSBindings/Mac/Clock SignalTests/MasterSystemVDPTests.mm @@ -57,6 +57,10 @@ // Get time until interrupt. int time_until_interrupt = vdp.get_time_until_interrupt().as_int() - 1; + // Check that an interrupt is now scheduled. + NSAssert(time_until_interrupt != -2, @"No interrupt scheduled"); + NSAssert(time_until_interrupt > 0, @"Interrupt is scheduled in the past"); + // Check interrupt flag isn't set prior to the reported time. vdp.run_for(HalfCycles(time_until_interrupt)); NSAssert(!vdp.get_interrupt_line(), @"Interrupt line went active early [1]"); @@ -79,4 +83,37 @@ NSAssert(vdp.get_interrupt_line(), @"Interrupt line wasn't set when promised [2]"); } +- (void)testFirstLineInterrupt { + TI::TMS::TMS9918 vdp(TI::TMS::Personality::SMSVDP); + + // Disable end-of-frame interrupts, enable line interrupts, set an interrupt to occur every line. + vdp.set_register(1, 0x00); + vdp.set_register(1, 0x81); + + vdp.set_register(1, 0x10); + vdp.set_register(1, 0x80); + + vdp.set_register(1, 0); + vdp.set_register(1, 0x8a); + + // Advance to outside of the counted area. + while(vdp.get_current_line() < 200) vdp.run_for(Cycles(228)); + + // Clear the pending interrupt and ask about the next one (i.e. the first one). + vdp.get_register(1); + int time_until_interrupt = vdp.get_time_until_interrupt().as_int() - 1; + + // Check that an interrupt is now scheduled. + NSAssert(time_until_interrupt != -2, @"No interrupt scheduled"); + NSAssert(time_until_interrupt > 0, @"Interrupt is scheduled in the past"); + + // Check interrupt flag isn't set prior to the reported time. + vdp.run_for(HalfCycles(time_until_interrupt)); + NSAssert(!vdp.get_interrupt_line(), @"Interrupt line went active early"); + + // Check interrupt flag is set at the reported time. + vdp.run_for(HalfCycles(1)); + NSAssert(vdp.get_interrupt_line(), @"Interrupt line wasn't set when promised"); +} + @end