1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-06-25 18:30:07 +00:00

Takes a shot at the two video counter registers.

This commit is contained in:
Thomas Harte 2020-11-29 19:57:35 -05:00
parent 091bce9350
commit a9ce43d244
3 changed files with 56 additions and 8 deletions

View File

@ -462,18 +462,18 @@ class ConcreteMachine:
// Monochome/colour register.
case Read(0xc021):
// "Uses bit 7 to determine whether composite output is colour 9) or gray scale (1)."
*value = video_->get_composite_is_colour() ? 0x00 : 0x80;
*value = video_.last_valid()->get_composite_is_colour() ? 0x00 : 0x80;
break;
case Write(0xc021):
video_->set_composite_is_colour(!(*value & 0x80));
break;
// case Read(0xc02e):
// // TODO: read vertical video counter.
// break;
// case Read(0xc02f):
// // TODO: read horizontal video counter.
// break;
case Read(0xc02e):
*value = video_.last_valid()->get_vertical_counter(video_.time_since_flush());
break;
case Read(0xc02f):
*value = video_.last_valid()->get_horizontal_counter(video_.time_since_flush());
break;
// case Read(0xc037): case Write(0xc037):
// // TODO: "Used during DMA as bank address"?

View File

@ -15,7 +15,7 @@ namespace {
constexpr int CyclesPerTick = 7; // One 'tick' being the non-stretched length of a cycle on the old Apple II 1Mhz clock.
constexpr int CyclesPerLine = 456; // Each of the Mega II's cycles lasts 7 cycles, making 455/line except for the
// final on on a line which lasts an additional 1 (i.e. is 1/7th longer).
constexpr int Lines = 263;
constexpr int Lines = 262;
constexpr int FinalPixelLine = 192;
constexpr auto FinalColumn = CyclesPerLine / CyclesPerTick;
@ -420,6 +420,44 @@ bool Video::get_is_vertical_blank(Cycles offset) {
return (cycles_into_frame_ + offset.as<int>())%(Lines * CyclesPerLine) >= FinalPixelLine * CyclesPerLine;
}
Video::Counters Video::get_counters(Cycles offset) {
// Tech note #39:
//
// "The seven-bit horizontal counter starts at $00 and counts from $40 to $7F (the sequence
// is $00, $40, $41,...,$7E, $7F, $00, $40,...). The active video time consists of 40 one
// microsecond clock cycles starting with $58 and ending with $7F."
//
// "The nine-bit vertical counter ranges from $FA through $1FF (250 through 511) in NTSC mode
// (vertical line count of 262) and from $C8 through $1FF (200 through 511) in PAL video timing
// mode (vertical line count of 312). Vertical counter value $100 corresponds to scan line
// zero in NTSC mode."
// Work out the internal offset into frame.
auto cycles_into_frame = cycles_into_frame_ + offset.as<int>();
// Nudge slightly so that the regular start of line matches mine.
// TODO: reorient my drawing around the native offsets?
cycles_into_frame = (cycles_into_frame + 25 - start_of_pixels)%(Lines * CyclesPerLine);
// Break it down.
const auto cycles_into_line = cycles_into_frame / CyclesPerLine;
const auto lines_into_frame = (cycles_into_frame % CyclesPerLine) + 0x100;
return Counters(
lines_into_frame - ((lines_into_frame / 0x200) * 0x106), // TODO: this assumes NTSC.
cycles_into_line + bool(cycles_into_line) * 0x40);
}
uint8_t Video::get_horizontal_counter(Cycles offset) {
const auto counters = get_counters(offset);
return uint8_t(counters.horizontal | (counters.vertical << 7));
}
uint8_t Video::get_vertical_counter(Cycles offset) {
const auto counters = get_counters(offset);
return uint8_t(counters.vertical >> 1);
}
void Video::set_new_video(uint8_t new_video) {
new_video_ = new_video;
}

View File

@ -28,6 +28,8 @@ class Video: public Apple::II::VideoSwitches<Cycles> {
void set_internal_ram(const uint8_t *);
bool get_is_vertical_blank(Cycles offset);
uint8_t get_horizontal_counter(Cycles offset);
uint8_t get_vertical_counter(Cycles offset);
void set_new_video(uint8_t);
uint8_t get_new_video();
@ -178,6 +180,13 @@ class Video: public Apple::II::VideoSwitches<Cycles> {
/// Outputs the lowest 14 bits from @c ntsc_shift_, mapping to RGB.
/// Phase is derived from @c column.
uint16_t *output_shift(uint16_t *target, int column);
// Common getter for the two counters.
struct Counters {
Counters(int v, int h) : vertical(v), horizontal(h) {}
const int vertical, horizontal;
};
Counters get_counters(Cycles offset);
};
}
@ -185,3 +194,4 @@ class Video: public Apple::II::VideoSwitches<Cycles> {
}
#endif /* Video_hpp */