From 86246e4f455b772442325b4b7e16afa6d8870550 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Tue, 26 Jul 2022 21:28:12 -0400 Subject: [PATCH] Introduce partial Blitter sequencer test. --- .../Clock SignalTests/AmigaBlitterTests.mm | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/OSBindings/Mac/Clock SignalTests/AmigaBlitterTests.mm b/OSBindings/Mac/Clock SignalTests/AmigaBlitterTests.mm index 2a2be3375..57115dc16 100644 --- a/OSBindings/Mac/Clock SignalTests/AmigaBlitterTests.mm +++ b/OSBindings/Mac/Clock SignalTests/AmigaBlitterTests.mm @@ -271,4 +271,62 @@ using WriteVector = std::vector>; [self testCase:@"inclusive fills"]; } +- (void)testSequencer { + // These patterns are faithfully transcribed from the HRM's + // 'Pipeline Register' section, as captured online at + // http://www.amigadev.elowar.com/read/ADCD_2.1/Hardware_Manual_guide/node0127.html + NSArray *const patterns = @[ + @"- - - -", + @"D0 - D1 - D2", + @"C0 - C1 - C2", + @"C0 - - C1 D0 - C2 D1 - D2", + @"B0 - - B1 - - B2", + @"B0 - - B1 D0 - B2 D1 - D2", + @"B0 C0 - B1 C1 - B2 C2", + @"B0 C0 - - B1 C1 D0 - B2 C2 D1 - D2", + @"A0 - A1 - A2", + ]; + const int lengths[] = { + 4, 5, 5, 10, 7, 10, 8, 13, 5, 8, 6, 11, 8, 11, 9, 13 + }; + + for(int c = 0; c < 9; c++) { + Amiga::BlitterSequencer sequencer; + sequencer.set_control(c); + + int counts[4]{}; + const int writes = 2; + int length = lengths[c]; + bool is_first_write = c > 1; // control = 1 is D only, in which case don't pipeline. + NSMutableArray *const components = [[NSMutableArray alloc] init]; + + while(length--) { + const auto next = sequencer.next(); + + using Channel = Amiga::BlitterSequencer::Channel; + switch(next) { + case Channel::None: [components addObject:@"-"]; break; + case Channel::A: [components addObject:[NSString stringWithFormat:@"A%d", counts[0]++]]; break; + case Channel::B: [components addObject:[NSString stringWithFormat:@"B%d", counts[1]++]]; break; + case Channel::C: [components addObject:[NSString stringWithFormat:@"C%d", counts[2]++]]; break; + + case Channel::Write: + if(is_first_write) { + is_first_write = false; + [components addObject:@"-"]; + } else { + [components addObject:[NSString stringWithFormat:@"D%d", counts[3]++]]; + if(counts[3] == writes) sequencer.complete(); + } + break; + + default: break; + } + } + + NSString *pattern = [components componentsJoinedByString:@" "]; + XCTAssertEqualObjects(pattern, patterns[c]); + } +} + @end