From 33576aa2c42c6e3c8b037abc70f658d1a4615d5b Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sat, 18 Aug 2018 21:36:48 -0400 Subject: [PATCH] Uses `const` to ensure output_* are properly constrained. --- Machines/AppleII/Video.cpp | 19 +++++++------------ Machines/AppleII/Video.hpp | 14 +++++++------- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/Machines/AppleII/Video.cpp b/Machines/AppleII/Video.cpp index 443444708..c40a20550 100644 --- a/Machines/AppleII/Video.cpp +++ b/Machines/AppleII/Video.cpp @@ -117,7 +117,7 @@ void VideoBase::set_character_rom(const std::vector &character_rom) { } } -uint8_t *VideoBase::output_text(uint8_t *target, uint8_t *source, size_t length, size_t pixel_row) { +uint8_t *VideoBase::output_text(uint8_t *target, uint8_t *source, size_t length, size_t pixel_row) const { const uint8_t inverses[] = { 0xff, is_iie_ ? static_cast(0xff) : static_cast((flash_ / flash_length) * 0xff), @@ -144,11 +144,10 @@ uint8_t *VideoBase::output_text(uint8_t *target, uint8_t *source, size_t length, graphics_carry_ = character_pattern & 0x01; target += 7; } - return target; } -uint8_t *VideoBase::output_double_text(uint8_t *target, uint8_t *source, uint8_t *auxiliary_source, size_t length, size_t pixel_row) { +uint8_t *VideoBase::output_double_text(uint8_t *target, uint8_t *source, uint8_t *auxiliary_source, size_t length, size_t pixel_row) const { for(size_t c = 0; c < length; ++c) { const std::size_t character_addresses[2] = { static_cast( @@ -183,11 +182,10 @@ uint8_t *VideoBase::output_double_text(uint8_t *target, uint8_t *source, uint8_t graphics_carry_ = character_patterns[1] & 0x01; target += 14; } - return target; } -uint8_t *VideoBase::output_low_resolution(uint8_t *target, uint8_t *source, size_t length, int row) { +uint8_t *VideoBase::output_low_resolution(uint8_t *target, uint8_t *source, size_t length, int row) const { const int row_shift = row&4; for(size_t c = 0; c < length; ++c) { // Low-resolution graphics mode shifts the colour code on a loop, but has to account for whether this @@ -207,11 +205,10 @@ uint8_t *VideoBase::output_low_resolution(uint8_t *target, uint8_t *source, size } target += 14; } - return target; } -uint8_t *VideoBase::output_double_low_resolution(uint8_t *target, uint8_t *source, uint8_t *auxiliary_source, size_t length, int row) { +uint8_t *VideoBase::output_double_low_resolution(uint8_t *target, uint8_t *source, uint8_t *auxiliary_source, size_t length, int row) const { const int row_shift = row&4; for(size_t c = 0; c < length; ++c) { if(c&1) { @@ -239,11 +236,10 @@ uint8_t *VideoBase::output_double_low_resolution(uint8_t *target, uint8_t *sourc } target += 14; } - return target; } -uint8_t *VideoBase::output_high_resolution(uint8_t *target, uint8_t *source, size_t length) { +uint8_t *VideoBase::output_high_resolution(uint8_t *target, uint8_t *source, size_t length) const { for(size_t c = 0; c < length; ++c) { // High resolution graphics shift out LSB to MSB, optionally with a delay of half a pixel. // If there is a delay, the previous output level is held to bridge the gap. @@ -271,7 +267,7 @@ uint8_t *VideoBase::output_high_resolution(uint8_t *target, uint8_t *source, siz return target; } -uint8_t *VideoBase::output_double_high_resolution(uint8_t *target, uint8_t *source, uint8_t *auxiliary_source, size_t length) { +uint8_t *VideoBase::output_double_high_resolution(uint8_t *target, uint8_t *source, uint8_t *auxiliary_source, size_t length) const { for(size_t c = 0; c < length; ++c) { target[0] = graphics_carry_; target[1] = auxiliary_source[c] & 0x01; @@ -288,8 +284,7 @@ uint8_t *VideoBase::output_double_high_resolution(uint8_t *target, uint8_t *sour target[12] = auxiliary_source[c] & 0x10; target[13] = auxiliary_source[c] & 0x20; graphics_carry_ = auxiliary_source[c] & 0x40; - pixel_pointer_ += 14; + target += 14; } - return target; } diff --git a/Machines/AppleII/Video.hpp b/Machines/AppleII/Video.hpp index daacb656a..95385516c 100644 --- a/Machines/AppleII/Video.hpp +++ b/Machines/AppleII/Video.hpp @@ -178,7 +178,7 @@ class VideoBase { // Graphics carry is the final level output in a fetch window; // it carries on into the next if it's high resolution with // the delay bit set. - uint8_t graphics_carry_ = 0; + mutable uint8_t graphics_carry_ = 0; // This holds a copy of the character ROM. The regular character // set is assumed to be in the first 64*8 bytes; the alternative @@ -198,37 +198,37 @@ class VideoBase { Outputs 40-column text to @c target, using @c length bytes from @c source. @return One byte after the final value written to @c target. */ - uint8_t *output_text(uint8_t *target, uint8_t *source, size_t length, size_t pixel_row); + uint8_t *output_text(uint8_t *target, uint8_t *source, size_t length, size_t pixel_row) const; /*! Outputs 80-column text to @c target, drawing @c length columns from @c source and @c auxiliary_source. @return One byte after the final value written to @c target. */ - uint8_t *output_double_text(uint8_t *target, uint8_t *source, uint8_t *auxiliary_source, size_t length, size_t pixel_row); + uint8_t *output_double_text(uint8_t *target, uint8_t *source, uint8_t *auxiliary_source, size_t length, size_t pixel_row) const; /*! Outputs 40-column low-resolution graphics to @c target, drawing @c length columns from @c source. @return One byte after the final value written to @c target. */ - uint8_t *output_low_resolution(uint8_t *target, uint8_t *source, size_t length, int row); + uint8_t *output_low_resolution(uint8_t *target, uint8_t *source, size_t length, int row) const; /*! Outputs 80-column low-resolution graphics to @c target, drawing @c length columns from @c source and @c auxiliary_source. @return One byte after the final value written to @c target. */ - uint8_t *output_double_low_resolution(uint8_t *target, uint8_t *source, uint8_t *auxiliary_source, size_t length, int row); + uint8_t *output_double_low_resolution(uint8_t *target, uint8_t *source, uint8_t *auxiliary_source, size_t length, int row) const; /*! Outputs 40-column high-resolution graphics to @c target, drawing @c length columns from @c source. @return One byte after the final value written to @c target. */ - uint8_t *output_high_resolution(uint8_t *target, uint8_t *source, size_t length); + uint8_t *output_high_resolution(uint8_t *target, uint8_t *source, size_t length) const; /*! Outputs 80-column double-high-resolution graphics to @c target, drawing @c length columns from @c source. @return One byte after the final value written to @c target. */ - uint8_t *output_double_high_resolution(uint8_t *target, uint8_t *source, uint8_t *auxiliary_source, size_t length); + uint8_t *output_double_high_resolution(uint8_t *target, uint8_t *source, uint8_t *auxiliary_source, size_t length) const; }; template class Video: public VideoBase {