1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-07-29 16:29:08 +00:00

Makes substantial optimisations to text mode.

Character optimisations to come.
This commit is contained in:
Thomas Harte 2017-12-04 22:18:51 -05:00
parent ec266d6c8e
commit 6eedc99286
2 changed files with 189 additions and 190 deletions

View File

@ -103,38 +103,27 @@ void TMS9918::run_for(const HalfCycles cycles) {
const int access_slot = column_ >> 1; // There are only 171 available memory accesses per line. const int access_slot = column_ >> 1; // There are only 171 available memory accesses per line.
switch(line_mode_) { switch(line_mode_) {
case LineMode::Text: case LineMode::Text:
while(access_pointer_ < access_slot) { access_pointer_ = std::min(30, access_slot);
if(access_pointer_ < 29) { if(access_pointer_ >= 30 && access_pointer_ < 150) {
access_pointer_ = std::min(29, access_slot); const int row_base = pattern_name_address_ + (row_ >> 3) * 40;
} const int start_column = (access_pointer_ - 30) / 3;
if(access_pointer_ >= 29) { const int end = std::min(150, access_slot);
int row_base = pattern_name_address_ + (row_ >> 3) * 40;
int character_column = (access_pointer_ - 29) / 3;
const int end = std::min(149, access_slot); // Pattern names are collected every third window starting from window 30.
const int pattern_names_end = (end - 30) / 3;
for(int column = start_column; column < pattern_names_end; ++column) {
pattern_names_[column] = ram_[row_base + column];
}
while(access_pointer_ < end) { // Patterns are collected every third window starting from window 32.
switch(access_pointer_%3) { const int pattern_buffer_end = (end - 32) / 3;
case 0: for(int column = start_column; column < pattern_buffer_end; ++column) {
pattern_buffer_[character_column] = ram_[pattern_generator_table_address_ + (pattern_name_ << 3) + (row_ & 7)]; pattern_buffer_[column] = ram_[pattern_generator_table_address_ + (pattern_names_[column] << 3) + (row_ & 7)];
character_column++;
break;
case 1: break; // TODO: CPU access.
case 2:
pattern_name_ = ram_[row_base + character_column];
break;
}
access_pointer_++;
}
}
if(access_pointer_ >= 149) {
access_pointer_ = access_slot;
} }
} }
break; break;
case LineMode::Character: case LineMode::Character:
while(access_pointer_ < access_slot) {
// Four access windows: no collection. // Four access windows: no collection.
access_pointer_ = std::min(4, access_slot); access_pointer_ = std::min(4, access_slot);
@ -147,7 +136,6 @@ void TMS9918::run_for(const HalfCycles cycles) {
const int target = 2 + (offset / 6); const int target = 2 + (offset / 6);
const int sprite = active_sprites_[target] & 31; const int sprite = active_sprites_[target] & 31;
const int subcycle = offset % 6; const int subcycle = offset % 6;
// printf("%d: %d %d\n", access_pointer_, target, subcycle);
switch(subcycle) { switch(subcycle) {
case 0: sprites_[target].y = ram_[sprite_attribute_table_address_ + (sprite << 2)]; break; case 0: sprites_[target].y = ram_[sprite_attribute_table_address_ + (sprite << 2)]; break;
case 1: sprites_[target].x = ram_[sprite_attribute_table_address_ + (sprite << 2) + 1]; break; case 1: sprites_[target].x = ram_[sprite_attribute_table_address_ + (sprite << 2) + 1]; break;
@ -203,7 +191,7 @@ void TMS9918::run_for(const HalfCycles cycles) {
int character_column = ((access_pointer_ - 26) >> 2); int character_column = ((access_pointer_ - 26) >> 2);
switch(access_pointer_&3) { switch(access_pointer_&3) {
case 2: case 2:
pattern_name_ = ram_[row_base + character_column]; pattern_names_[character_column] = ram_[row_base + character_column];
break; break;
case 3: { case 3: {
const int slot = (access_pointer_ - 31) >> 2; const int slot = (access_pointer_ - 31) >> 2;
@ -214,13 +202,13 @@ void TMS9918::run_for(const HalfCycles cycles) {
} break; } break;
case 0: case 0:
if(screen_mode_ != 1) { if(screen_mode_ != 1) {
colour_buffer_[character_column] = ram_[colour_base + (pattern_name_ >> 3)]; colour_buffer_[character_column] = ram_[colour_base + (pattern_names_[character_column] >> 3)];
} else { } else {
colour_buffer_[character_column] = ram_[colour_base + (pattern_name_ << 3) + (row_ & 7)]; colour_buffer_[character_column] = ram_[colour_base + (pattern_names_[character_column] << 3) + (row_ & 7)];
} }
break; break;
case 1: case 1:
pattern_buffer_[character_column] = ram_[pattern_base + (pattern_name_ << 3) + (row_ & 7)]; pattern_buffer_[character_column] = ram_[pattern_base + (pattern_names_[character_column] << 3) + (row_ & 7)];
break; break;
} }
access_pointer_++; access_pointer_++;
@ -272,7 +260,6 @@ void TMS9918::run_for(const HalfCycles cycles) {
const int target = (access_pointer_ - 156) / 6; const int target = (access_pointer_ - 156) / 6;
const int sprite = active_sprites_[target] & 31; const int sprite = active_sprites_[target] & 31;
const int subcycle = access_pointer_ % 6; const int subcycle = access_pointer_ % 6;
// printf("%d: %d %d\n", access_pointer_, target, subcycle);
switch(subcycle) { switch(subcycle) {
case 0: sprites_[target].y = ram_[sprite_attribute_table_address_ + (sprite << 2)]; break; case 0: sprites_[target].y = ram_[sprite_attribute_table_address_ + (sprite << 2)]; break;
case 1: sprites_[target].x = ram_[sprite_attribute_table_address_ + (sprite << 2) + 1]; break; case 1: sprites_[target].x = ram_[sprite_attribute_table_address_ + (sprite << 2) + 1]; break;
@ -293,7 +280,6 @@ void TMS9918::run_for(const HalfCycles cycles) {
// There's a single unused access window here. // There's a single unused access window here.
access_pointer_ = std::min(171, access_slot); access_pointer_ = std::min(171, access_slot);
}
break; break;
} }
} }
@ -344,17 +330,29 @@ void TMS9918::run_for(const HalfCycles cycles) {
if(output_column_ < pixels_end) { if(output_column_ < pixels_end) {
switch(line_mode_) { switch(line_mode_) {
case LineMode::Text: case LineMode::Text: {
while(output_column_ < pixels_end) { const uint32_t colours[2] = { palette[background_colour_], palette[text_colour_] };
const int base = (output_column_ - first_pixel_column_);
const int address = base / 6;
const int pattern = pattern_buffer_[address] << (base % 6);
*pixel_target_ = (pattern&0x80) ? palette[text_colour_] : palette[background_colour_]; const int shift = (output_column_ - first_pixel_column_) % 6;
int byte_column = (output_column_ - first_pixel_column_) / 6;
int pattern = pattern_buffer_[byte_column] << shift;
int pixels_left = pixels_end - output_column_;
int length = std::min(pixels_left, 6 - shift);
while(true) {
pixels_left -= length;
while(length--) {
*pixel_target_ = colours[(pattern >> 7)&0x01];
pixel_target_++; pixel_target_++;
output_column_ ++; pattern <<= 1;
} }
break;
if(!pixels_left) break;
length = std::min(6, pixels_left);
byte_column++;
pattern = pattern_buffer_[byte_column];
}
output_column_ = pixels_end;
} break;
case LineMode::Character: case LineMode::Character:
while(output_column_ < pixels_end) { while(output_column_ < pixels_end) {

View File

@ -93,12 +93,13 @@ class TMS9918 {
} line_mode_ = LineMode::Text; } line_mode_ = LineMode::Text;
int first_pixel_column_, first_right_border_column_; int first_pixel_column_, first_right_border_column_;
uint8_t pattern_names_[40];
uint8_t pattern_buffer_[40]; uint8_t pattern_buffer_[40];
uint8_t colour_buffer_[40]; uint8_t colour_buffer_[40];
uint8_t sprite_locations_[32]; uint8_t sprite_locations_[32];
int active_sprites_[4]; int active_sprites_[4];
int access_pointer_ = 0; int access_pointer_ = 0;
uint8_t pattern_name_ = 0;
struct Sprite { struct Sprite {
uint8_t x, y; uint8_t x, y;