From 7d94161653a38d5dbca80a24017f29da7d807a11 Mon Sep 17 00:00:00 2001 From: "Christopher A. Mosher" Date: Wed, 10 Apr 2024 13:47:06 -0400 Subject: [PATCH] fix compiler warnings; remove some DSL dependencies; use F keys for paddle buttons --- src/E2wxApp.cpp | 2 +- src/KeyEventHandler.cpp | 7 ++----- src/analogtv.cpp | 2 +- src/apple2.cpp | 1 + src/cassetteout.cpp | 2 -- src/drive.cpp | 2 +- src/emulator.cpp | 10 ++-------- src/emulator.h | 3 --- src/main.cpp | 1 - src/paddlebuttonstates.cpp | 12 +++++++----- src/paddles.cpp | 18 +++++++++--------- src/paddles.h | 7 ++++++- src/screenimage.cpp | 28 +++++++++++++--------------- src/screenimage.h | 3 ++- src/videostaticgenerator.cpp | 2 +- 15 files changed, 46 insertions(+), 54 deletions(-) diff --git a/src/E2wxApp.cpp b/src/E2wxApp.cpp index cab635e..2ad871e 100644 --- a/src/E2wxApp.cpp +++ b/src/E2wxApp.cpp @@ -292,7 +292,7 @@ bool E2wxApp::OnCmdLineParsed(wxCmdLineParser& parser) { this->opt_config_from_prefs_only = parser.Found("p"); - const int n = parser.GetParamCount(); + const int n = (int)parser.GetParamCount(); if (n == 1) { this->arg_configfile = path_from_string(parser.GetParam(0)); diff --git a/src/KeyEventHandler.cpp b/src/KeyEventHandler.cpp index fd76f60..3df4c59 100644 --- a/src/KeyEventHandler.cpp +++ b/src/KeyEventHandler.cpp @@ -54,7 +54,7 @@ static bool is_key_down(const wxKeyEvent& keyEvent) { ); } -// Take real-world keystrokes from SDL and filter them to emulate the Apple ][ keyboard +// Take real-world keystrokes and filter them to emulate the Apple ][ keyboard static bool translate_key(const wxKeyEvent& keyEvent, unsigned char* key) { const int keycode = keyEvent.GetKeyCode(); @@ -79,8 +79,7 @@ static bool translate_key(const wxKeyEvent& keyEvent, unsigned char* key) { *key -= 32; } - // from SDL 1.2 to 2.0, we can't use UNICODE so we need to - // apply shift and control modifiers ourselves + // TODO can't we use UNICODE instead of applying shift and control modifiers ourselves if (keyEvent.ShiftDown()) { if (keycode == '`') *key = '~'; else if (keycode == '1') *key = '!'; @@ -155,8 +154,6 @@ void KeyEventHandler::dispatchKeyDown(const wxKeyEvent& keyEvent) { const int sym = keyEvent.GetKeyCode(); - //printf("keydown: mod: %04X sym: %08X scan:%04X name:%s\n", mod, sym, scan, SDL_GetKeyName(sym)); - if (is_key_down(keyEvent)) { ++this->keysDown; } diff --git a/src/analogtv.cpp b/src/analogtv.cpp index a7e8e8c..6cbf8d7 100644 --- a/src/analogtv.cpp +++ b/src/analogtv.cpp @@ -162,7 +162,7 @@ public: } } int get(const int i) const { return this->cb[i]; } - int length() const { return this->cb.size(); } + int length() const { return (int)this->cb.size(); } void getPhase(double phase[]) const { { diff --git a/src/apple2.cpp b/src/apple2.cpp index 9c5d201..fc7ce76 100644 --- a/src/apple2.cpp +++ b/src/apple2.cpp @@ -43,6 +43,7 @@ Apple2::Apple2(KeypressQueue& keypresses, PaddleButtonStates& paddleButtonStates slts(gui), kbd(keypresses, buffered), keyrepeater(keypresses), +paddles(&gui), rom(AddressBus::MOTHERBOARD_ROM_SIZ), ram(revision), cassetteIn(gui), diff --git a/src/cassetteout.cpp b/src/cassetteout.cpp index c07234b..faf3628 100644 --- a/src/cassetteout.cpp +++ b/src/cassetteout.cpp @@ -19,8 +19,6 @@ #include #include #include -#include -#include #include "cassetteout.h" #include "e2const.h" #include diff --git a/src/drive.cpp b/src/drive.cpp index ddd8a07..c2b95da 100644 --- a/src/drive.cpp +++ b/src/drive.cpp @@ -22,7 +22,7 @@ Disk2Drive::Disk2Drive(double p_random_ones_rate): pulse(false), bitBufferRead(0), random_ones_rate(p_random_ones_rate), - generator(std::chrono::system_clock::now().time_since_epoch().count()), + generator((unsigned int)std::chrono::system_clock::now().time_since_epoch().count()), distribution(0.0,1.0) { } diff --git a/src/emulator.cpp b/src/emulator.cpp index a8ac1cd..6f4d7c0 100644 --- a/src/emulator.cpp +++ b/src/emulator.cpp @@ -25,8 +25,6 @@ #include #include -#include - #include #include @@ -43,8 +41,7 @@ Emulator::Emulator() : videoStatic(display), apple2(keypresses, paddleButtonStates, display, buffered, screenImage), keyEventHandler(keypresses, apple2.keyrepeater), - timable(nullptr), // No ticked object (NULL pointer) - prev_ms(SDL_GetTicks()) { + timable(nullptr) {// No ticked object (NULL pointer) } Emulator::~Emulator() { @@ -61,7 +58,7 @@ void Emulator::config(E2Config& cfg) { -// How many emulation ticks between asking SDL if there is any new input +// How many emulation ticks between asking if there is any new input // from the user or other GUI events. // This is also how often we shall update the estimate of the emulator's // actual speed performance @@ -76,9 +73,6 @@ void Emulator::tick50ms() { this->timable->tick(); // this runs the emulator! } } - - this->screenImage.displayHz((1000*CHECK_EVERY_CYCLE)/(SDL_GetTicks() - this->prev_ms)); - this->prev_ms = SDL_GetTicks(); } diff --git a/src/emulator.h b/src/emulator.h index 690479f..667aeee 100644 --- a/src/emulator.h +++ b/src/emulator.h @@ -28,7 +28,6 @@ #include "KeyRepeatHandler.h" #include "KeyEventHandler.h" #include "clipboardhandler.h" -#include #include class Timable; @@ -47,8 +46,6 @@ class Emulator { Timable* timable; - Uint32 prev_ms; - void powerOnComputer(); void powerOffComputer(); diff --git a/src/main.cpp b/src/main.cpp index ff951e1..73ac351 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -18,7 +18,6 @@ */ #include "gui.h" -#include #include #include diff --git a/src/paddlebuttonstates.cpp b/src/paddlebuttonstates.cpp index c87f831..5765649 100644 --- a/src/paddlebuttonstates.cpp +++ b/src/paddlebuttonstates.cpp @@ -17,7 +17,7 @@ */ #include "paddlebuttonstates.h" -#include +#include const int PaddleButtonStates::PADDLE_COUNT(3); @@ -35,10 +35,12 @@ bool PaddleButtonStates::isDown(const int paddle) { return false; } - unsigned char btn = SDL_GetMouseState(0,0); + + + // TODO clean up paddle button F keys if (paddle==0) - return btn&SDL_BUTTON_LMASK; + return wxGetKeyState(wxKeyCode::WXK_F3); if (paddle==1) - return btn&SDL_BUTTON_RMASK; - return btn&SDL_BUTTON_MMASK; + return wxGetKeyState(wxKeyCode::WXK_F9); + return wxGetKeyState(wxKeyCode::WXK_F12); } diff --git a/src/paddles.cpp b/src/paddles.cpp index b138c0b..6cd7f03 100644 --- a/src/paddles.cpp +++ b/src/paddles.cpp @@ -17,20 +17,17 @@ */ #include "e2const.h" #include "paddles.h" +#include "screenimage.h" #include #include -#include - #include #include #include - - -Paddles::Paddles() : rTick(PADDLE_COUNT) { +Paddles::Paddles(ScreenImage* gui) : scrn(gui), rTick(PADDLE_COUNT) { } Paddles::~Paddles() { @@ -52,10 +49,13 @@ void Paddles::startTimers() { } } -static wxPoint current_mouse_position() { - int x, y; - SDL_GetMouseState(&x, &y); - return wxPoint(x, y); +wxPoint Paddles::current_mouse_position() { + const auto p = ::wxGetMousePosition(); + + int x,y; + this->scrn->getPos(&x,&y); + + return p-wxPoint(x,y); } void Paddles::tryStartPaddleTimers() { diff --git a/src/paddles.h b/src/paddles.h index ca082a4..ebfff55 100644 --- a/src/paddles.h +++ b/src/paddles.h @@ -18,20 +18,25 @@ #ifndef PADDLES_H #define PADDLES_H +#include #include +class ScreenImage; + class Paddles { private: + ScreenImage* scrn; std::vector rTick; enum { PADDLE_COUNT = 4 }; enum { PADDLE_CYCLES = 2805 }; // TODO: document where PADDLE_CYCLES==2805 came from void tryStartPaddleTimers(); + wxPoint current_mouse_position(); public: - Paddles(); + Paddles(ScreenImage* gui); ~Paddles(); void tick(); void startTimers(); diff --git a/src/screenimage.cpp b/src/screenimage.cpp index a72b5e8..664f20a 100644 --- a/src/screenimage.cpp +++ b/src/screenimage.cpp @@ -193,7 +193,7 @@ void ScreenImage::drawSlot(int slot, int r, int c) { drawChar(':', r, c++); drawChar(' ', r, c++); drawText(this->slotnames[slot], r, c); - const int len = this->slotnames[slot].length(); + const int len = (int)this->slotnames[slot].length(); if (len < 100) { drawText(std::string(100 - len, ' '), r, c + len); } @@ -205,7 +205,7 @@ void ScreenImage::drawCassette() { drawText("CASSETTE: IN<-", r, c); c += 15; drawText(this->cassInName, r, c); - int len = this->cassInName.length(); + int len = (int)this->cassInName.length(); if (len < 40) { drawText(std::string(40 - len, ' '), r, c + len); } @@ -214,7 +214,7 @@ void ScreenImage::drawCassette() { drawText("OUT->", r, c); c += 5; drawText(this->cassOutName, r, c); - len = this->cassOutName.length(); + len = (int)this->cassOutName.length(); if (len < 40) { drawText(std::string(40 - len, ' '), r, c + len); } @@ -302,12 +302,6 @@ void ScreenImage::drawChar(const char ch, int row, int col, int color, int bgcol } } -void ScreenImage::displayHz(int hz) { - char s[20]; - sprintf(s, "%5.3f MHz ", hz / 1e6); - drawText(s, 3, 141); -} - void ScreenImage::drawPower(bool on) { unsigned int* pn = this->pixels; pn += (HEIGHT + 35)*SCRW + 5; @@ -388,10 +382,10 @@ void ScreenImage::setDiskFile(int slot, int drive, const std::filesystem::path & int c(37 + 32 * drive); drawText(f, r, c); - const int dlen = 12 - f.length(); + const int dlen = 12 - (int)f.length(); if (dlen > 0) { std::string d(dlen, ' '); - drawText(d, r, c + f.length()); + drawText(d, r, c + (int)f.length()); } this->slotnames[slot].replace(c - 20, 12, 12, ' '); @@ -467,10 +461,10 @@ void ScreenImage::setCassetteInFile(const std::filesystem::path& filepath) { int c(85 + 11); drawText(f, r, c); - const int dlen = 12 - f.length(); + const int dlen = 12 - (int)f.length(); if (dlen > 0) { std::string d(dlen, ' '); - drawText(d, r, c + f.length()); + drawText(d, r, c + (int)f.length()); } this->cassInName.replace(c - 94, 12, 12, ' '); @@ -483,10 +477,10 @@ void ScreenImage::setCassetteOutFile(const std::filesystem::path& filepath) { int c(85 + 11); drawText(f, r, c); - const int dlen = 12 - f.length(); + const int dlen = 12 - (int)f.length(); if (dlen > 0) { std::string d(dlen, ' '); - drawText(d, r, c + f.length()); + drawText(d, r, c + (int)f.length()); } this->cassOutName.replace(c - 94, 12, 12, ' '); @@ -569,3 +563,7 @@ void ScreenImage::OnKeyDown(wxKeyEvent &evt) { void ScreenImage::OnKeyUp(wxKeyEvent &evt) { this->keyEventHandler.dispatchKeyUp(evt); } + +void ScreenImage::getPos(int* px, int* py) { + this->sdl->GetScreenPosition(px,py); +} diff --git a/src/screenimage.h b/src/screenimage.h index f0d2f5d..54239b2 100644 --- a/src/screenimage.h +++ b/src/screenimage.h @@ -84,7 +84,6 @@ public: void drawFnKeys(); void toggleKdbBufferLabel(); void cycleDisplayLabel(); - void displayHz(int hz); void toggleFillLinesLabel(); void invertText(int row, int begincol, int endcol); void drawDisplayLabel(); @@ -110,6 +109,8 @@ public: void setFirmCard(int slot, bool bank, bool F8); void saveBMP(); + + void getPos(int* px, int* py); }; #endif diff --git a/src/videostaticgenerator.cpp b/src/videostaticgenerator.cpp index 15addc1..e4d3933 100644 --- a/src/videostaticgenerator.cpp +++ b/src/videostaticgenerator.cpp @@ -28,7 +28,7 @@ VideoStaticGenerator::VideoStaticGenerator(AnalogTV& display): hpos(0) { this->display.signal = sig; - srand(time(0)); + srand((unsigned int)time(0)); }