diff --git a/Machines/Atari2600.cpp b/Machines/Atari2600.cpp index 030b87209..9a0fd0342 100644 --- a/Machines/Atari2600.cpp +++ b/Machines/Atari2600.cpp @@ -166,7 +166,7 @@ void Machine::get_output_pixel(uint8_t *pixel, int offset) // this is faster than the straightforward +1)%160 per profiling #define increment_object_counter(c) _objectCounter[c] = (_objectCounter[c]+1)&~((158-_objectCounter[c]) >> 8) -void Machine::output_pixels(int count) +void Machine::output_pixels(unsigned int count) { const int32_t start_of_sync = 214; const int32_t end_of_sync = 198; @@ -264,16 +264,16 @@ void Machine::output_pixels(int count) } } -int Machine::perform_bus_operation(CPU6502::BusOperation operation, uint16_t address, uint8_t *value) +unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uint16_t address, uint8_t *value) { set_reset_line(false); uint8_t returnValue = 0xff; - int cycles_run_for = 1; + unsigned int cycles_run_for = 1; const int32_t ready_line_disable_time = 227;//horizontalTimerReload; if(operation == CPU6502::BusOperation::Ready) { - int32_t distance_to_end_of_ready = (_horizontalTimer - ready_line_disable_time + horizontalTimerReload + 1)%(horizontalTimerReload + 1); + unsigned int distance_to_end_of_ready = (_horizontalTimer - ready_line_disable_time + horizontalTimerReload + 1)%(horizontalTimerReload + 1); cycles_run_for = distance_to_end_of_ready / 3; output_pixels(distance_to_end_of_ready); } else { @@ -295,7 +295,7 @@ int Machine::perform_bus_operation(CPU6502::BusOperation operation, uint16_t add // check for a paging access if(_rom_size > 4096 && ((address & 0x1f00) == 0x1f00)) { uint8_t *base_ptr = _romPages[0]; - uint8_t first_paging_register = 0xf8 - (_rom_size >> 14)*2; + uint8_t first_paging_register = (uint8_t)(0xf8 - (_rom_size >> 14)*2); const uint8_t paging_register = address&0xff; if(paging_register >= first_paging_register) { @@ -530,11 +530,16 @@ int Machine::perform_bus_operation(CPU6502::BusOperation operation, uint16_t add break; } } else { - switch(address & 0x0f) { - case 0x04: _writtenPiaTimerShift = _piaTimerShift = 0; _piaTimerValue = *value << 0; _piaTimerStatus &= ~0xc0; break; - case 0x05: _writtenPiaTimerShift = _piaTimerShift = 3; _piaTimerValue = *value << 3; _piaTimerStatus &= ~0xc0; break; - case 0x06: _writtenPiaTimerShift = _piaTimerShift = 6; _piaTimerValue = *value << 6; _piaTimerStatus &= ~0xc0; break; - case 0x07: _writtenPiaTimerShift = _piaTimerShift = 10; _piaTimerValue = *value << 10; _piaTimerStatus &= ~0xc0; break; + const uint8_t decodedAddress = address & 0x0f; + switch(decodedAddress) { + case 0x04: + case 0x05: + case 0x06: + case 0x07: + _writtenPiaTimerShift = _piaTimerShift = (decodedAddress - 0x04) * 3 + (decodedAddress / 0x07); + _piaTimerValue = (unsigned int)(*value << _piaTimerShift); + _piaTimerStatus &= ~0xc0; + break; } } } diff --git a/Machines/Atari2600.hpp b/Machines/Atari2600.hpp index 595fc34d9..94ba6c25a 100644 --- a/Machines/Atari2600.hpp +++ b/Machines/Atari2600.hpp @@ -22,7 +22,7 @@ class Machine: public CPU6502::Processor { Machine(); ~Machine(); - int perform_bus_operation(CPU6502::BusOperation operation, uint16_t address, uint8_t *value); + unsigned int perform_bus_operation(CPU6502::BusOperation operation, uint16_t address, uint8_t *value); void set_rom(size_t length, const uint8_t *data); void switch_region(); @@ -81,12 +81,12 @@ class Machine: public CPU6502::Processor { Pixel }; - void output_pixels(int count); + void output_pixels(unsigned int count); void get_output_pixel(uint8_t *pixel, int offset); Outputs::CRT *_crt; // latched output state - int _lastOutputStateDuration; + unsigned int _lastOutputStateDuration; OutputState _lastOutputState; uint8_t *_outputBuffer; }; diff --git a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj index eabe9441d..72064745d 100644 --- a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj +++ b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj @@ -1584,6 +1584,8 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; + CLANG_WARN_IMPLICIT_SIGN_CONVERSION = YES; + CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES; CODE_SIGN_ENTITLEMENTS = "Clock Signal/Clock Signal.entitlements"; COMBINE_HIDPI_IMAGES = YES; INFOPLIST_FILE = "Clock Signal/Info.plist"; @@ -1600,6 +1602,8 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; + CLANG_WARN_IMPLICIT_SIGN_CONVERSION = YES; + CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES; CODE_SIGN_ENTITLEMENTS = "Clock Signal/Clock Signal.entitlements"; COMBINE_HIDPI_IMAGES = YES; INFOPLIST_FILE = "Clock Signal/Info.plist"; diff --git a/OSBindings/Mac/Clock Signal/CSCathodeRayView.m b/OSBindings/Mac/Clock Signal/CSCathodeRayView.m index ca9a1b8e8..d97ec0f82 100644 --- a/OSBindings/Mac/Clock Signal/CSCathodeRayView.m +++ b/OSBindings/Mac/Clock Signal/CSCathodeRayView.m @@ -95,7 +95,7 @@ static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt NSPoint backingSize = {.x = self.bounds.size.width, .y = self.bounds.size.height}; NSPoint viewSize = [self convertPointToBacking:backingSize]; - glViewport(0, 0, viewSize.x, viewSize.y); + glViewport(0, 0, (GLsizei)viewSize.x, (GLsizei)viewSize.y); CGLUnlockContext([[self openGLContext] CGLContextObj]); } @@ -128,7 +128,7 @@ static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt self.wantsBestResolutionOpenGLSurface = YES; } -- (GLint)formatForDepth:(int)depth +- (GLint)formatForDepth:(unsigned int)depth { switch(depth) { @@ -154,11 +154,11 @@ static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt if(_textureSize.width != _crtFrame->size.width || _textureSize.height != _crtFrame->size.height) { GLint format = [self formatForDepth:_crtFrame->buffers[0].depth]; - glTexImage2D(GL_TEXTURE_2D, 0, format, _crtFrame->size.width, _crtFrame->size.height, 0, format, GL_UNSIGNED_BYTE, _crtFrame->buffers[0].data); + glTexImage2D(GL_TEXTURE_2D, 0, format, _crtFrame->size.width, _crtFrame->size.height, 0, (GLenum)format, GL_UNSIGNED_BYTE, _crtFrame->buffers[0].data); _textureSize = _crtFrame->size; } else - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, _crtFrame->size.width, _crtFrame->dirty_size.height, [self formatForDepth:_crtFrame->buffers[0].depth], GL_UNSIGNED_BYTE, _crtFrame->buffers[0].data); + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, _crtFrame->size.width, _crtFrame->dirty_size.height, (GLenum)[self formatForDepth:_crtFrame->buffers[0].depth], GL_UNSIGNED_BYTE, _crtFrame->buffers[0].data); [self drawView]; @@ -213,7 +213,7 @@ const char *fragmentShader = GLint logLength; glGetShaderiv(object, GL_INFO_LOG_LENGTH, &logLength); if (logLength > 0) { - GLchar *log = (GLchar *)malloc(logLength); + GLchar *log = (GLchar *)malloc((size_t)logLength); glGetShaderInfoLog(object, logLength, &logLength, log); NSLog(@"Compile log:\n%s", log); free(log); @@ -262,14 +262,14 @@ const char *fragmentShader = _alphaUniform = glGetUniformLocation(_shaderProgram, "alpha"); _textureSizeUniform = glGetUniformLocation(_shaderProgram, "textureSize"); - glEnableVertexAttribArray(_positionAttribute); - glEnableVertexAttribArray(_textureCoordinatesAttribute); - glEnableVertexAttribArray(_lateralAttribute); + glEnableVertexAttribArray((GLuint)_positionAttribute); + glEnableVertexAttribArray((GLuint)_textureCoordinatesAttribute); + glEnableVertexAttribArray((GLuint)_lateralAttribute); const GLsizei vertexStride = kCRTSizeOfVertex; - glVertexAttribPointer(_positionAttribute, 2, GL_UNSIGNED_SHORT, GL_TRUE, vertexStride, (void *)kCRTVertexOffsetOfPosition); - glVertexAttribPointer(_textureCoordinatesAttribute, 2, GL_UNSIGNED_SHORT, GL_FALSE, vertexStride, (void *)kCRTVertexOffsetOfTexCoord); - glVertexAttribPointer(_lateralAttribute, 1, GL_UNSIGNED_BYTE, GL_FALSE, vertexStride, (void *)kCRTVertexOffsetOfLateral); + glVertexAttribPointer((GLuint)_positionAttribute, 2, GL_UNSIGNED_SHORT, GL_TRUE, vertexStride, (void *)kCRTVertexOffsetOfPosition); + glVertexAttribPointer((GLuint)_textureCoordinatesAttribute, 2, GL_UNSIGNED_SHORT, GL_FALSE, vertexStride, (void *)kCRTVertexOffsetOfTexCoord); + glVertexAttribPointer((GLuint)_lateralAttribute, 1, GL_UNSIGNED_BYTE, GL_FALSE, vertexStride, (void *)kCRTVertexOffsetOfLateral); glGenTextures(1, &_textureName); glBindTexture(GL_TEXTURE_2D, _textureName); @@ -294,7 +294,7 @@ const char *fragmentShader = if (_crtFrame) { glUniform2f(_textureSizeUniform, _crtFrame->size.width, _crtFrame->size.height); - glDrawArrays(GL_TRIANGLES, 0, _crtFrame->number_of_runs*6); + glDrawArrays(GL_TRIANGLES, 0, (GLsizei)(_crtFrame->number_of_runs*6)); } CGLFlushDrawable([[self openGLContext] CGLContextObj]); diff --git a/Outputs/CRT.cpp b/Outputs/CRT.cpp index 3e900d643..b13a77b19 100644 --- a/Outputs/CRT.cpp +++ b/Outputs/CRT.cpp @@ -18,11 +18,11 @@ static const uint32_t kCRTFixedPointOffset = 0x08000000; #define kRetraceXMask 0x01 #define kRetraceYMask 0x02 -void CRT::set_new_timing(int cycles_per_line, int height_of_display) +void CRT::set_new_timing(unsigned int cycles_per_line, unsigned int height_of_display) { - const int syncCapacityLineChargeThreshold = 3; - const int millisecondsHorizontalRetraceTime = 10; // source: Dictionary of Video and Television Technology, p. 234 - const int scanlinesVerticalRetraceTime = 7; // source: ibid + const unsigned int syncCapacityLineChargeThreshold = 3; + const unsigned int millisecondsHorizontalRetraceTime = 10; // source: Dictionary of Video and Television Technology, p. 234 + const unsigned int scanlinesVerticalRetraceTime = 7; // source: ibid _time_multiplier = (1000 + cycles_per_line - 1) / cycles_per_line; height_of_display += (height_of_display / 20); // this is the overrun area we'll use to @@ -36,7 +36,7 @@ void CRT::set_new_timing(int cycles_per_line, int height_of_display) _sync_capacitor_charge_threshold = ((syncCapacityLineChargeThreshold * _cycles_per_line) * 50) >> 7; _horizontal_retrace_time = (millisecondsHorizontalRetraceTime * _cycles_per_line) >> 6; - const int vertical_retrace_time = scanlinesVerticalRetraceTime * _cycles_per_line; + const unsigned int vertical_retrace_time = scanlinesVerticalRetraceTime * _cycles_per_line; const float halfLineWidth = (float)_height_of_display * 1.85f; for(int c = 0; c < 4; c++) @@ -46,19 +46,19 @@ void CRT::set_new_timing(int cycles_per_line, int height_of_display) // width should be 1.0 / _height_of_display, rotated to match the direction float angle = atan2f(_scanSpeed[c].y, _scanSpeed[c].x); - _beamWidth[c].x = (sinf(angle) / halfLineWidth) * kCRTFixedPointRange; - _beamWidth[c].y = (cosf(angle) / halfLineWidth) * kCRTFixedPointRange; + _beamWidth[c].x = (uint32_t)((sinf(angle) / halfLineWidth) * kCRTFixedPointRange); + _beamWidth[c].y = (uint32_t)((cosf(angle) / halfLineWidth) * kCRTFixedPointRange); } } -CRT::CRT(int cycles_per_line, int height_of_display, int number_of_buffers, ...) +CRT::CRT(unsigned int cycles_per_line, unsigned int height_of_display, unsigned int number_of_buffers, ...) { set_new_timing(cycles_per_line, height_of_display); // generate buffers for signal storage as requested — format is // number of buffers, size of buffer 1, size of buffer 2... - const int bufferWidth = 2048; - const int bufferHeight = 2048; + const uint16_t bufferWidth = 2048; + const uint16_t bufferHeight = 2048; for(int frame = 0; frame < sizeof(_frame_builders) / sizeof(*_frame_builders); frame++) { va_list va; @@ -96,14 +96,14 @@ CRT::~CRT() #pragma mark - Sync loop -CRT::SyncEvent CRT::get_next_vertical_sync_event(bool vsync_is_requested, int cycles_to_run_for, int *cycles_advanced) +CRT::SyncEvent CRT::get_next_vertical_sync_event(bool vsync_is_requested, unsigned int cycles_to_run_for, unsigned int *cycles_advanced) { SyncEvent proposedEvent = SyncEvent::None; - int proposedSyncTime = cycles_to_run_for; + unsigned int proposedSyncTime = cycles_to_run_for; // will an acceptable vertical sync be triggered? if (vsync_is_requested && !_is_in_vsync) { - if (_sync_capacitor_charge_level >= _sync_capacitor_charge_threshold && _rasterPosition.y >= (kCRTFixedPointRange * 7) >> 3) { + if (_sync_capacitor_charge_level >= _sync_capacitor_charge_threshold){// && _rasterPosition.y >= (kCRTFixedPointRange * 7) >> 3) { proposedSyncTime = 0; proposedEvent = SyncEvent::StartVSync; _did_detect_vsync = true; @@ -112,14 +112,14 @@ CRT::SyncEvent CRT::get_next_vertical_sync_event(bool vsync_is_requested, int cy // have we overrun the maximum permitted number of horizontal syncs for this frame? if (!_is_in_vsync) { - int time_until_end_of_frame = (kCRTFixedPointRange - _rasterPosition.y) / _scanSpeed[0].y; + unsigned int time_until_end_of_frame = (kCRTFixedPointRange - _rasterPosition.y) / _scanSpeed[0].y; if(time_until_end_of_frame < proposedSyncTime) { proposedSyncTime = time_until_end_of_frame; proposedEvent = SyncEvent::StartVSync; } } else { - uint32_t time_until_start_of_frame = _rasterPosition.y / (uint32_t)(-_scanSpeed[kRetraceYMask].y); + unsigned int time_until_start_of_frame = _rasterPosition.y / (uint32_t)(-_scanSpeed[kRetraceYMask].y); if(time_until_start_of_frame < proposedSyncTime) { proposedSyncTime = time_until_start_of_frame; @@ -131,20 +131,20 @@ CRT::SyncEvent CRT::get_next_vertical_sync_event(bool vsync_is_requested, int cy return proposedEvent; } -CRT::SyncEvent CRT::get_next_horizontal_sync_event(bool hsync_is_requested, int cycles_to_run_for, int *cycles_advanced) +CRT::SyncEvent CRT::get_next_horizontal_sync_event(bool hsync_is_requested, unsigned int cycles_to_run_for, unsigned int *cycles_advanced) { // do we recognise this hsync, thereby adjusting future time expectations? if(hsync_is_requested) { if (_horizontal_counter < _hsync_error_window || _horizontal_counter >= _expected_next_hsync - _hsync_error_window) { _did_detect_hsync = true; - int time_now = (_horizontal_counter < _hsync_error_window) ? _expected_next_hsync + _horizontal_counter : _horizontal_counter; + unsigned int time_now = (_horizontal_counter < _hsync_error_window) ? _expected_next_hsync + _horizontal_counter : _horizontal_counter; _expected_next_hsync = (_expected_next_hsync + _expected_next_hsync + _expected_next_hsync + time_now) >> 2; } } SyncEvent proposedEvent = SyncEvent::None; - int proposedSyncTime = cycles_to_run_for; + unsigned int proposedSyncTime = cycles_to_run_for; // will we end an ongoing hsync? if (_horizontal_counter < _horizontal_retrace_time && _horizontal_counter+proposedSyncTime >= _horizontal_retrace_time) { @@ -162,7 +162,7 @@ CRT::SyncEvent CRT::get_next_horizontal_sync_event(bool hsync_is_requested, int return proposedEvent; } -void CRT::advance_cycles(int number_of_cycles, bool hsync_requested, bool vsync_requested, const bool vsync_charging, const Type type, const char *data_type) +void CRT::advance_cycles(unsigned int number_of_cycles, bool hsync_requested, bool vsync_requested, const bool vsync_charging, const Type type, const char *data_type) { number_of_cycles *= _time_multiplier; @@ -177,13 +177,13 @@ void CRT::advance_cycles(int number_of_cycles, bool hsync_requested, bool vsync_ while(number_of_cycles) { - int time_until_vertical_sync_event, time_until_horizontal_sync_event; + unsigned int time_until_vertical_sync_event, time_until_horizontal_sync_event; SyncEvent next_vertical_sync_event = this->get_next_vertical_sync_event(vsync_requested, number_of_cycles, &time_until_vertical_sync_event); SyncEvent next_horizontal_sync_event = this->get_next_horizontal_sync_event(hsync_requested, time_until_vertical_sync_event, &time_until_horizontal_sync_event); // get the next sync event and its timing; hsync request is instantaneous (being edge triggered) so // set it to false for the next run through this loop (if any) - int next_run_length = std::min(time_until_vertical_sync_event, time_until_horizontal_sync_event); + unsigned int next_run_length = std::min(time_until_vertical_sync_event, time_until_horizontal_sync_event); hsync_requested = false; vsync_requested = false; @@ -252,7 +252,7 @@ void CRT::advance_cycles(int number_of_cycles, bool hsync_requested, bool vsync_ if (vsync_charging && !_is_in_vsync) _sync_capacitor_charge_level += next_run_length; else - _sync_capacitor_charge_level = std::max(_sync_capacitor_charge_level - next_run_length, 0); + _sync_capacitor_charge_level = std::max(_sync_capacitor_charge_level - (int)next_run_length, 0); // react to the incoming event... if(next_run_length == time_until_horizontal_sync_event) @@ -337,28 +337,28 @@ void CRT::set_delegate(CRTDelegate *delegate) /* These all merely channel into advance_cycles, supplying appropriate arguments */ -void CRT::output_sync(int number_of_cycles) +void CRT::output_sync(unsigned int number_of_cycles) { bool _hsync_requested = !_is_receiving_sync; // ensure this really is edge triggered; someone calling output_sync twice in succession shouldn't trigger it twice _is_receiving_sync = true; advance_cycles(number_of_cycles, _hsync_requested, false, true, Type::Sync, nullptr); } -void CRT::output_blank(int number_of_cycles) +void CRT::output_blank(unsigned int number_of_cycles) { bool _vsync_requested = _is_receiving_sync; _is_receiving_sync = false; advance_cycles(number_of_cycles, false, _vsync_requested, false, Type::Blank, nullptr); } -void CRT::output_level(int number_of_cycles, const char *type) +void CRT::output_level(unsigned int number_of_cycles, const char *type) { bool _vsync_requested = _is_receiving_sync; _is_receiving_sync = false; advance_cycles(number_of_cycles, false, _vsync_requested, false, Type::Level, type); } -void CRT::output_data(int number_of_cycles, const char *type) +void CRT::output_data(unsigned int number_of_cycles, const char *type) { bool _vsync_requested = _is_receiving_sync; _is_receiving_sync = false; @@ -380,7 +380,7 @@ uint8_t *CRT::get_write_target_for_buffer(int buffer) #pragma mark - CRTFrame -CRTFrameBuilder::CRTFrameBuilder(int width, int height, int number_of_buffers, va_list buffer_sizes) +CRTFrameBuilder::CRTFrameBuilder(uint16_t width, uint16_t height, unsigned int number_of_buffers, va_list buffer_sizes) { frame.size.width = width; frame.size.height = height; @@ -389,7 +389,7 @@ CRTFrameBuilder::CRTFrameBuilder(int width, int height, int number_of_buffers, v for(int buffer = 0; buffer < number_of_buffers; buffer++) { - frame.buffers[buffer].depth = va_arg(buffer_sizes, int); + frame.buffers[buffer].depth = va_arg(buffer_sizes, unsigned int); frame.buffers[buffer].data = new uint8_t[width * height * frame.buffers[buffer].depth]; } diff --git a/Outputs/CRT.hpp b/Outputs/CRT.hpp index 6ed15e136..f08b018cf 100644 --- a/Outputs/CRT.hpp +++ b/Outputs/CRT.hpp @@ -22,7 +22,7 @@ class CRT; struct CRTFrameBuilder { CRTFrame frame; - CRTFrameBuilder(int width, int height, int number_of_buffers, va_list buffer_sizes); + CRTFrameBuilder(uint16_t width, uint16_t height, unsigned int number_of_buffers, va_list buffer_sizes); ~CRTFrameBuilder(); private: @@ -39,24 +39,24 @@ struct CRTFrameBuilder { // a pointer to the section of content buffer currently being // returned and to where the next section will begin - int _next_write_x_position, _next_write_y_position; - int _write_x_position, _write_y_position; - int _write_target_pointer; + uint16_t _next_write_x_position, _next_write_y_position; + uint16_t _write_x_position, _write_y_position; + unsigned int _write_target_pointer; }; static const int kCRTNumberOfFrames = 4; class CRT { public: - CRT(int cycles_per_line, int height_of_display, int number_of_buffers, ...); + CRT(unsigned int cycles_per_line, unsigned int height_of_display, unsigned int number_of_buffers, ...); ~CRT(); - void set_new_timing(int cycles_per_line, int height_of_display); + void set_new_timing(unsigned int cycles_per_line, unsigned int height_of_display); - void output_sync(int number_of_cycles); - void output_blank(int number_of_cycles); - void output_level(int number_of_cycles, const char *type); - void output_data(int number_of_cycles, const char *type); + void output_sync(unsigned int number_of_cycles); + void output_blank(unsigned int number_of_cycles); + void output_level(unsigned int number_of_cycles, const char *type); + void output_data(unsigned int number_of_cycles, const char *type); class CRTDelegate { public: @@ -71,14 +71,14 @@ class CRT { private: // the incoming clock lengths will be multiplied by something to give at least 1000 // sample points per line - int _time_multiplier; + unsigned int _time_multiplier; // fundamental creator-specified properties - int _cycles_per_line; - int _height_of_display; + unsigned int _cycles_per_line; + unsigned int _height_of_display; // properties directly derived from there - int _hsync_error_window; // the permitted window around the expected sync position in which a sync pulse will be recognised; calculated once at init + unsigned int _hsync_error_window; // the permitted window around the expected sync position in which a sync pulse will be recognised; calculated once at init // the current scanning position struct Vector { @@ -100,9 +100,9 @@ class CRT { int _is_in_vsync; // components of the flywheel sync - int _horizontal_counter; // time run since the _start_ of the last horizontal sync - int _expected_next_hsync; // our current expection of when the next horizontal sync will be encountered (which implies current flywheel velocity) - int _horizontal_retrace_time; + unsigned int _horizontal_counter; // time run since the _start_ of the last horizontal sync + unsigned int _expected_next_hsync; // our current expection of when the next horizontal sync will be encountered (which implies current flywheel velocity) + unsigned int _horizontal_retrace_time; bool _is_in_hsync; // true for the duration of a horizontal sync — used to determine beam running direction and speed bool _did_detect_vsync; // true if vertical sync was detected in the input stream rather than forced by emergency measure @@ -110,7 +110,7 @@ class CRT { enum Type { Sync, Level, Data, Blank } type; - void advance_cycles(int number_of_cycles, bool hsync_requested, bool vsync_requested, bool vsync_charging, Type type, const char *data_type); + void advance_cycles(unsigned int number_of_cycles, bool hsync_requested, bool vsync_requested, bool vsync_charging, Type type, const char *data_type); // the inner entry point that determines whether and when the next sync event will occur within // the current output window @@ -119,8 +119,8 @@ class CRT { StartHSync, EndHSync, StartVSync, EndVSync }; - SyncEvent get_next_vertical_sync_event(bool vsync_is_requested, int cycles_to_run_for, int *cycles_advanced); - SyncEvent get_next_horizontal_sync_event(bool hsync_is_requested, int cycles_to_run_for, int *cycles_advanced); + SyncEvent get_next_vertical_sync_event(bool vsync_is_requested, unsigned int cycles_to_run_for, unsigned int *cycles_advanced); + SyncEvent get_next_horizontal_sync_event(bool hsync_is_requested, unsigned int cycles_to_run_for, unsigned int *cycles_advanced); }; } diff --git a/Outputs/CRTFrame.h b/Outputs/CRTFrame.h index ebb14ba4a..3dee7a2ca 100644 --- a/Outputs/CRTFrame.h +++ b/Outputs/CRTFrame.h @@ -15,20 +15,20 @@ extern "C" { typedef struct { uint8_t *data; - int depth; + unsigned int depth; } CRTBuffer; typedef struct { - int width, height; + uint16_t width, height; } CRTSize; typedef struct { CRTSize size, dirty_size; - int number_of_buffers; + unsigned int number_of_buffers; CRTBuffer *buffers; - int number_of_runs; + unsigned int number_of_runs; uint8_t *runs; } CRTFrame; diff --git a/Processors/6502/CPU6502.hpp b/Processors/6502/CPU6502.hpp index baec6aba3..103e4753d 100644 --- a/Processors/6502/CPU6502.hpp +++ b/Processors/6502/CPU6502.hpp @@ -576,17 +576,17 @@ template class Processor { case OperationCMP: { const uint16_t temp16 = _a - _operand; - _negativeResult = _zeroResult = temp16; + _negativeResult = _zeroResult = (uint8_t)temp16; _carryFlag = ((~temp16) >> 8)&1; } break; case OperationCPX: { const uint16_t temp16 = _x - _operand; - _negativeResult = _zeroResult = temp16; + _negativeResult = _zeroResult = (uint8_t)temp16; _carryFlag = ((~temp16) >> 8)&1; } break; case OperationCPY: { const uint16_t temp16 = _y - _operand; - _negativeResult = _zeroResult = temp16; + _negativeResult = _zeroResult = (uint8_t)temp16; _carryFlag = ((~temp16) >> 8)&1; } break; @@ -614,13 +614,13 @@ template class Processor { temp16 += (_a&0xf0) - (_operand&0xf0); _overflowFlag = ( ( (decimalResult^_a)&(~decimalResult^_operand) )&0x80) >> 1; - _negativeResult = temp16; - _zeroResult = decimalResult; + _negativeResult = (uint8_t)temp16; + _zeroResult = (uint8_t)decimalResult; if(temp16 > 0xff) temp16 -= 0x60; _carryFlag = (temp16 > 0xff) ? 0 : Flag::Carry; - _a = temp16; + _a = (uint8_t)temp16; break; } else { _operand = ~_operand; @@ -637,17 +637,17 @@ template class Processor { temp16 = (temp16&0x0f) + ((temp16 > 0x0f) ? 0x10 : 0x00) + (_a&0xf0) + (_operand&0xf0); _overflowFlag = (( (decimalResult^_a)&(decimalResult^_operand) )&0x80) >> 1; - _negativeResult = temp16; - _zeroResult = decimalResult; + _negativeResult = (uint8_t)temp16; + _zeroResult = (uint8_t)decimalResult; if(temp16 > 0x9f) temp16 += 0x60; _carryFlag = (temp16 > 0xff) ? Flag::Carry : 0; - _a = temp16; + _a = (uint8_t)temp16; } else { const uint16_t decimalResult = (uint16_t)_a + (uint16_t)_operand + (uint16_t)_carryFlag; _overflowFlag = (( (decimalResult^_a)&(decimalResult^_operand) )&0x80) >> 1; - _negativeResult = _zeroResult = _a = decimalResult; + _negativeResult = _zeroResult = _a = (uint8_t)decimalResult; _carryFlag = (decimalResult >> 8)&1; } @@ -671,13 +671,13 @@ template class Processor { break; case OperationROL: { - const uint8_t temp8 = (_operand << 1) | _carryFlag;\ - _carryFlag = _operand >> 7;\ + const uint8_t temp8 = (uint8_t)((_operand << 1) | _carryFlag); + _carryFlag = _operand >> 7; _operand = _negativeResult = _zeroResult = temp8; } break; case OperationRLA: { - const uint8_t temp8 = (_operand << 1) | _carryFlag; + const uint8_t temp8 = (uint8_t)((_operand << 1) | _carryFlag); _carryFlag = _operand >> 7; _operand = temp8; _a &= _operand; @@ -705,13 +705,13 @@ template class Processor { break; case OperationROR: { - const uint8_t temp8 = (_operand >> 1) | (_carryFlag << 7); + const uint8_t temp8 = (uint8_t)((_operand >> 1) | (_carryFlag << 7)); _carryFlag = _operand & 1; _operand = _negativeResult = _zeroResult = temp8; } break; case OperationRRA: { - const uint8_t temp8 = (_operand >> 1) | (_carryFlag << 7); + const uint8_t temp8 = (uint8_t)((_operand >> 1) | (_carryFlag << 7)); _carryFlag = _operand & 1; _operand = temp8; } break; @@ -849,7 +849,7 @@ template class Processor { case OperationBEQ: BRA(!_zeroResult); break; case CycleAddSignedOperandToPC: - _nextAddress.full = _pc.full + (int8_t)_operand; + _nextAddress.full = (uint16_t)(_pc.full + (int8_t)_operand); _pc.bytes.low = _nextAddress.bytes.low; if(_nextAddress.bytes.high != _pc.bytes.high) { uint16_t halfUpdatedPc = _pc.full; @@ -873,7 +873,7 @@ template class Processor { if(_decimalFlag) { _a &= _operand; uint8_t unshiftedA = _a; - _a = (_a >> 1) | (_carryFlag << 7); + _a = (uint8_t)((_a >> 1) | (_carryFlag << 7)); _zeroResult = _negativeResult = _a; _overflowFlag = (_a^(_a << 1))&Flag::Overflow; @@ -884,7 +884,7 @@ template class Processor { } else { _a &= _operand; - _a = (_a >> 1) | (_carryFlag << 7); + _a = (uint8_t)((_a >> 1) | (_carryFlag << 7)); _negativeResult = _zeroResult = _a; _carryFlag = (_a >> 6)&1; _overflowFlag = (_a^(_a << 1))&Flag::Overflow;