mirror of
https://github.com/TomHarte/CLK.git
synced 2024-12-26 09:29:45 +00:00
Makes substantial optimisations to text mode.
Character optimisations to come.
This commit is contained in:
parent
ec266d6c8e
commit
6eedc99286
@ -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.
|
||||
switch(line_mode_) {
|
||||
case LineMode::Text:
|
||||
while(access_pointer_ < access_slot) {
|
||||
if(access_pointer_ < 29) {
|
||||
access_pointer_ = std::min(29, access_slot);
|
||||
}
|
||||
if(access_pointer_ >= 29) {
|
||||
int row_base = pattern_name_address_ + (row_ >> 3) * 40;
|
||||
int character_column = (access_pointer_ - 29) / 3;
|
||||
access_pointer_ = std::min(30, access_slot);
|
||||
if(access_pointer_ >= 30 && access_pointer_ < 150) {
|
||||
const int row_base = pattern_name_address_ + (row_ >> 3) * 40;
|
||||
const int start_column = (access_pointer_ - 30) / 3;
|
||||
const int end = std::min(150, access_slot);
|
||||
|
||||
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) {
|
||||
switch(access_pointer_%3) {
|
||||
case 0:
|
||||
pattern_buffer_[character_column] = ram_[pattern_generator_table_address_ + (pattern_name_ << 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;
|
||||
// Patterns are collected every third window starting from window 32.
|
||||
const int pattern_buffer_end = (end - 32) / 3;
|
||||
for(int column = start_column; column < pattern_buffer_end; ++column) {
|
||||
pattern_buffer_[column] = ram_[pattern_generator_table_address_ + (pattern_names_[column] << 3) + (row_ & 7)];
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case LineMode::Character:
|
||||
while(access_pointer_ < access_slot) {
|
||||
// Four access windows: no collection.
|
||||
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 sprite = active_sprites_[target] & 31;
|
||||
const int subcycle = offset % 6;
|
||||
// printf("%d: %d %d\n", access_pointer_, target, subcycle);
|
||||
switch(subcycle) {
|
||||
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;
|
||||
@ -203,7 +191,7 @@ void TMS9918::run_for(const HalfCycles cycles) {
|
||||
int character_column = ((access_pointer_ - 26) >> 2);
|
||||
switch(access_pointer_&3) {
|
||||
case 2:
|
||||
pattern_name_ = ram_[row_base + character_column];
|
||||
pattern_names_[character_column] = ram_[row_base + character_column];
|
||||
break;
|
||||
case 3: {
|
||||
const int slot = (access_pointer_ - 31) >> 2;
|
||||
@ -214,13 +202,13 @@ void TMS9918::run_for(const HalfCycles cycles) {
|
||||
} break;
|
||||
case 0:
|
||||
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 {
|
||||
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;
|
||||
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;
|
||||
}
|
||||
access_pointer_++;
|
||||
@ -272,7 +260,6 @@ void TMS9918::run_for(const HalfCycles cycles) {
|
||||
const int target = (access_pointer_ - 156) / 6;
|
||||
const int sprite = active_sprites_[target] & 31;
|
||||
const int subcycle = access_pointer_ % 6;
|
||||
// printf("%d: %d %d\n", access_pointer_, target, subcycle);
|
||||
switch(subcycle) {
|
||||
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;
|
||||
@ -293,7 +280,6 @@ void TMS9918::run_for(const HalfCycles cycles) {
|
||||
|
||||
// There's a single unused access window here.
|
||||
access_pointer_ = std::min(171, access_slot);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -344,17 +330,29 @@ void TMS9918::run_for(const HalfCycles cycles) {
|
||||
|
||||
if(output_column_ < pixels_end) {
|
||||
switch(line_mode_) {
|
||||
case LineMode::Text:
|
||||
while(output_column_ < pixels_end) {
|
||||
const int base = (output_column_ - first_pixel_column_);
|
||||
const int address = base / 6;
|
||||
const int pattern = pattern_buffer_[address] << (base % 6);
|
||||
case LineMode::Text: {
|
||||
const uint32_t colours[2] = { palette[background_colour_], palette[text_colour_] };
|
||||
|
||||
*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_++;
|
||||
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:
|
||||
while(output_column_ < pixels_end) {
|
||||
|
@ -93,12 +93,13 @@ class TMS9918 {
|
||||
} line_mode_ = LineMode::Text;
|
||||
int first_pixel_column_, first_right_border_column_;
|
||||
|
||||
uint8_t pattern_names_[40];
|
||||
uint8_t pattern_buffer_[40];
|
||||
uint8_t colour_buffer_[40];
|
||||
uint8_t sprite_locations_[32];
|
||||
|
||||
int active_sprites_[4];
|
||||
int access_pointer_ = 0;
|
||||
uint8_t pattern_name_ = 0;
|
||||
|
||||
struct Sprite {
|
||||
uint8_t x, y;
|
||||
|
Loading…
Reference in New Issue
Block a user