1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-06-26 10:29:31 +00:00

Observation: offset is needed only ephemerally.

This commit is contained in:
Thomas Harte 2023-02-06 21:45:35 -05:00
parent a3df106f92
commit 7cb51c021b
3 changed files with 21 additions and 26 deletions

View File

@ -40,9 +40,6 @@ enum class VerticalState {
};
// Temporary buffers collect a representation of each line prior to pixel serialisation.
//
// TODO: either template on personality, to avoid having to be the union of all potential footprints,
// or just stop keeping so many of these in the 9918.
struct LineBuffer {
LineBuffer() {}
@ -62,10 +59,7 @@ struct LineBuffer {
// The TMS and Sega VDPs are close enough to always tile-based;
// this struct captures maximal potential detail there.
struct {
struct {
size_t offset = 0; // TODO: could presumably be much smaller. One byte maybe?
uint8_t flags = 0;
} names[40];
uint8_t flags[40]{};
// The patterns array holds tile patterns, corresponding 1:1 with names.
// Four bytes per pattern is the maximum required by any
@ -73,8 +67,8 @@ struct LineBuffer {
uint8_t patterns[40][4]{};
};
// The Yamaha VDP also has a variety of bitmap modes, the widest of which is
// 512px @ 4bpp.
// The Yamaha VDP also has a variety of bitmap modes,
// the widest of which is 512px @ 4bpp.
uint8_t bitmap[256];
};
@ -571,6 +565,7 @@ template <Personality personality> struct Base: public Storage<personality> {
ScreenMode screen_mode_, underlying_mode_;
LineBuffer line_buffers_[313];
size_t tile_offset_ = 0;
void posit_sprite(LineBuffer &buffer, int sprite_number, int sprite_y, int screen_row);
// There is a delay between reading into the line buffer and outputting from there to the screen. That delay

View File

@ -170,14 +170,14 @@ void Base<personality>::draw_sms(int start, int end, uint32_t cram_dot) {
int length = std::min(pixels_left, 8 - shift);
pattern = *reinterpret_cast<const uint32_t *>(line_buffer.patterns[byte_column]);
if(line_buffer.names[byte_column].flags&2)
if(line_buffer.flags[byte_column]&2)
pattern >>= shift;
else
pattern <<= shift;
while(true) {
const int palette_offset = (line_buffer.names[byte_column].flags&0x18) << 1;
if(line_buffer.names[byte_column].flags&2) {
const int palette_offset = (line_buffer.flags[byte_column]&0x18) << 1;
if(line_buffer.flags[byte_column]&2) {
for(int c = 0; c < length; ++c) {
colour_buffer[tile_offset] =
((pattern_index[3] & 0x01) << 3) |

View File

@ -142,9 +142,9 @@ struct TextFetcher {
constexpr int offset = cycle - 47;
constexpr auto column = AddressT(offset / 3);
switch(offset % 3) {
case 0: line_buffer.names[column].offset = base->ram_[row_base + column]; break; // (1) fetch tile name.
case 1: base->do_external_slot(to_internal<personality, Clock::TMSMemoryWindow>(cycle)); break; // (2) external slot.
case 2: line_buffer.patterns[column][0] = base->ram_[row_offset + size_t(line_buffer.names[column].offset << 3)]; break; // (3) fetch tile pattern.
case 0: base->tile_offset_ = base->ram_[row_base + column]; break; // (1) fetch tile name.
case 1: base->do_external_slot(to_internal<personality, Clock::TMSMemoryWindow>(cycle)); break; // (2) external slot.
case 2: line_buffer.patterns[column][0] = base->ram_[row_offset + size_t(base->tile_offset_ << 3)]; break; // (3) fetch tile pattern.
}
}
}
@ -206,11 +206,11 @@ template<bool use_end> void Base<personality>::fetch_tms_character(LineBuffer &l
#define sprite_y_read(location, sprite) \
slot(location): posit_sprite(sprite_selection_buffer, sprite, ram_[sprite_attribute_table_address_ & (((sprite) << 2) | 0x3f80)], y);
#define fetch_tile_name(column) line_buffer.names[column].offset = ram_[(row_base + column) & 0x3fff];
#define fetch_tile_name(column) tile_offset_ = ram_[(row_base + column) & 0x3fff];
#define fetch_tile(column) {\
line_buffer.patterns[column][1] = ram_[(colour_base + size_t((line_buffer.names[column].offset << 3) >> colour_name_shift)) & 0x3fff]; \
line_buffer.patterns[column][0] = ram_[(pattern_base + size_t(line_buffer.names[column].offset << 3)) & 0x3fff]; \
line_buffer.patterns[column][1] = ram_[(colour_base + size_t((tile_offset_ << 3) >> colour_name_shift)) & 0x3fff]; \
line_buffer.patterns[column][0] = ram_[(pattern_base + size_t(tile_offset_ << 3)) & 0x3fff]; \
}
#define background_fetch_block(location, column, sprite) \
@ -347,17 +347,17 @@ template<bool use_end> void Base<personality>::fetch_sms(LineBuffer &line_buffer
#define fetch_tile_name(column, row_info) {\
const size_t scrolled_column = (column - horizontal_offset) & 0x1f;\
const size_t address = row_info.pattern_address_base + (scrolled_column << 1); \
line_buffer.names[column].flags = ram_[address+1]; \
line_buffer.names[column].offset = size_t( \
(((line_buffer.names[column].flags&1) << 8) | ram_[address]) << 5 \
) + row_info.sub_row[(line_buffer.names[column].flags&4) >> 2]; \
line_buffer.flags[column] = ram_[address+1]; \
tile_offset_ = size_t( \
(((line_buffer.flags[column]&1) << 8) | ram_[address]) << 5 \
) + row_info.sub_row[(line_buffer.flags[column]&4) >> 2]; \
}
#define fetch_tile(column) \
line_buffer.patterns[column][0] = ram_[line_buffer.names[column].offset]; \
line_buffer.patterns[column][1] = ram_[line_buffer.names[column].offset+1]; \
line_buffer.patterns[column][2] = ram_[line_buffer.names[column].offset+2]; \
line_buffer.patterns[column][3] = ram_[line_buffer.names[column].offset+3];
line_buffer.patterns[column][0] = ram_[tile_offset_]; \
line_buffer.patterns[column][1] = ram_[tile_offset_+1]; \
line_buffer.patterns[column][2] = ram_[tile_offset_+2]; \
line_buffer.patterns[column][3] = ram_[tile_offset_+3];
#define background_fetch_block(location, column, sprite, row_info) \
slot(location): fetch_tile_name(column, row_info) \