fix compiler warnings; remove some DSL dependencies; use F keys for paddle buttons

This commit is contained in:
Christopher A. Mosher 2024-04-10 13:47:06 -04:00
parent 9781f55963
commit 7d94161653
15 changed files with 46 additions and 54 deletions

View File

@ -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));

View File

@ -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;
}

View File

@ -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
{
{

View File

@ -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),

View File

@ -19,8 +19,6 @@
#include <fstream>
#include <iostream>
#include <cstdlib>
#include <SDL_audio.h>
#include <SDL_log.h>
#include "cassetteout.h"
#include "e2const.h"
#include <vector>

View File

@ -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) {
}

View File

@ -25,8 +25,6 @@
#include <wx/msgdlg.h>
#include <wx/string.h>
#include <SDL.h>
#include <boost/log/trivial.hpp>
#include <ctime>
@ -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();
}

View File

@ -28,7 +28,6 @@
#include "KeyRepeatHandler.h"
#include "KeyEventHandler.h"
#include "clipboardhandler.h"
#include <SDL.h>
#include <wx/string.h>
class Timable;
@ -47,8 +46,6 @@ class Emulator {
Timable* timable;
Uint32 prev_ms;
void powerOnComputer();
void powerOffComputer();

View File

@ -18,7 +18,6 @@
*/
#include "gui.h"
#include <SDL.h>
#include <wx/app.h>
#include <cstdio>

View File

@ -17,7 +17,7 @@
*/
#include "paddlebuttonstates.h"
#include <SDL.h>
#include <wx/utils.h>
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);
}

View File

@ -17,20 +17,17 @@
*/
#include "e2const.h"
#include "paddles.h"
#include "screenimage.h"
#include <wx/gdicmn.h>
#include <wx/window.h>
#include <SDL.h>
#include <boost/log/trivial.hpp>
#include <iostream>
#include <ostream>
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() {

View File

@ -18,20 +18,25 @@
#ifndef PADDLES_H
#define PADDLES_H
#include <wx/utils.h>
#include <vector>
class ScreenImage;
class Paddles
{
private:
ScreenImage* scrn;
std::vector<int> 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();

View File

@ -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);
}

View File

@ -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

View File

@ -28,7 +28,7 @@ VideoStaticGenerator::VideoStaticGenerator(AnalogTV& display):
hpos(0)
{
this->display.signal = sig;
srand(time(0));
srand((unsigned int)time(0));
}