wired in mouse support; left-apple is the mouse button on the teensy for now

This commit is contained in:
Jorj Bauer 2021-01-11 10:53:03 -05:00
parent 93746ed8d3
commit bab3560273
13 changed files with 215 additions and 10 deletions

3
.gitignore vendored
View File

@ -13,4 +13,5 @@ apple/hd32-rom.h
aiie-sdl
mockingboard-d.rom
*.d
*.dSYM
suspend.vm

View File

@ -20,7 +20,7 @@ SDLSRCS=sdl/sdl-speaker.cpp sdl/sdl-display.cpp sdl/sdl-keyboard.cpp sdl/sdl-pad
SDLOBJS=sdl/sdl-speaker.o sdl/sdl-display.o sdl/sdl-keyboard.o sdl/sdl-paddles.o nix/nix-filemanager.o sdl/aiie.o sdl/sdl-printer.o nix/nix-clock.o nix/nix-prefs.o nix/debugger.o nix/disassembler.o sdl/sdl-mouse.o
ROMS=apple/applemmu-rom.h apple/diskii-rom.h apple/parallel-rom.h apple/hd32-rom.h MouseInterface.rom
ROMS=apple/applemmu-rom.h apple/diskii-rom.h apple/parallel-rom.h apple/hd32-rom.h
.PHONY: roms clean
@ -40,7 +40,7 @@ test: $(TSRC)
./testharness -f tests/65c02-all.bin -s 0x200
roms: apple2e.rom disk.rom parallel.rom HDDRVR.BIN
./util/genrom.pl apple2e.rom disk.rom parallel.rom HDDRVR.BIN MouseInterface.rom
./util/genrom.pl apple2e.rom disk.rom parallel.rom HDDRVR.BIN
apple/applemmu-rom.h: roms

View File

@ -2,8 +2,6 @@
#include <string.h>
#include "globals.h"
#include "mouse-rom.h"
enum {
SW_W_INIT = 0x00,
SW_R_HOMEMOUSE = 0x08,

62
sdl/sdl-mouse.cpp Normal file
View File

@ -0,0 +1,62 @@
#include "sdl-mouse.h"
#include "globals.h"
SDLMouse::SDLMouse() : PhysicalMouse()
{
xpos = ypos = 0;
button = false;
}
SDLMouse::~SDLMouse()
{
}
void SDLMouse::gotMouseEvent(uint32_t buttonState, int32_t x, int32_t y)
{
xpos += x; ypos += y;
if (xpos < lowClamp[XCLAMP]) xpos=lowClamp[XCLAMP];
if (xpos > highClamp[XCLAMP]) xpos=highClamp[XCLAMP];
if (ypos < lowClamp[YCLAMP]) ypos = lowClamp[YCLAMP];
if (ypos > highClamp[YCLAMP]) ypos = highClamp[YCLAMP];
}
void SDLMouse::mouseButtonEvent(bool state)
{
button = state;
}
void SDLMouse::maintainMouse()
{
}
void SDLMouse::setPosition(uint16_t x, uint16_t y)
{
xpos = x;
ypos = y;
if (xpos < lowClamp[XCLAMP]) xpos=lowClamp[XCLAMP];
if (xpos > highClamp[XCLAMP]) xpos=highClamp[XCLAMP];
if (ypos < lowClamp[YCLAMP]) ypos = lowClamp[YCLAMP];
if (ypos > highClamp[YCLAMP]) ypos = highClamp[YCLAMP];
}
void SDLMouse::getPosition(uint16_t *x, uint16_t *y)
{
if (xpos < lowClamp[XCLAMP]) xpos=lowClamp[XCLAMP];
if (xpos > highClamp[XCLAMP]) xpos=highClamp[XCLAMP];
if (ypos < lowClamp[YCLAMP]) ypos = lowClamp[YCLAMP];
if (ypos > highClamp[YCLAMP]) ypos = highClamp[YCLAMP];
uint16_t outx = xpos;
uint16_t outy = ypos;
*x = outx;
*y = outy;
}
bool SDLMouse::getButton()
{
return button;
}

26
sdl/sdl-mouse.h Normal file
View File

@ -0,0 +1,26 @@
#ifndef __SDL_MOUSE_H
#define __SDL_MOUSE_H
#include "physicalmouse.h"
#include <SDL.h>
class SDLMouse : public PhysicalMouse {
public:
SDLMouse();
virtual ~SDLMouse();
virtual void maintainMouse();
virtual void setPosition(uint16_t x, uint16_t y);
virtual void getPosition(uint16_t *x, uint16_t *y);
virtual bool getButton();
void gotMouseEvent(uint32_t buttonState, int32_t x, int32_t y);
void mouseButtonEvent(bool state);
private:
int32_t xpos, ypos;
bool button;
};
#endif

1
teensy/mouse.cpp Symbolic link
View File

@ -0,0 +1 @@
../apple/mouse.cpp

1
teensy/mouse.h Symbolic link
View File

@ -0,0 +1 @@
../apple/mouse.h

1
teensy/physicalmouse.h Symbolic link
View File

@ -0,0 +1 @@
../physicalmouse.h

View File

@ -4,6 +4,9 @@
#include "LRingBuffer.h"
#include "teensy-println.h"
#include "globals.h"
#include "teensy-mouse.h"
const byte ROWS = 5;
const byte COLS = 13;
@ -71,12 +74,13 @@ void TeensyKeyboard::pressedKey(uint8_t key)
break;
case PK_RSHFT:
rightShiftPressed = 1;
break;
break;
case PK_LOCK:
capsLock = !capsLock;
break;
case PK_LA:
leftApplePressed = 1;
((TeensyMouse *)g_mouse)->mouseButtonEvent(true);
leftApplePressed = 1;
break;
case PK_RA:
rightApplePressed = 1;
@ -162,6 +166,7 @@ void TeensyKeyboard::releasedKey(uint8_t key)
rightShiftPressed = 0;
break;
case PK_LA:
((TeensyMouse *)g_mouse)->mouseButtonEvent(false);
leftApplePressed = 0;
break;
case PK_RA:
@ -218,9 +223,15 @@ void TeensyKeyboard::maintainKeyboard()
switch (keypad.key[i].kstate) {
case PRESSED:
vmkeyboard->keyDepressed(keypad.key[i].kchar);
if (keypad.key[i].kchar == PK_LSHFT) {
((TeensyMouse *)g_mouse)->mouseButtonEvent(true);
}
break;
case RELEASED:
vmkeyboard->keyReleased(keypad.key[i].kchar);
if (keypad.key[i].kchar == PK_LSHFT) {
((TeensyMouse *)g_mouse)->mouseButtonEvent(false);
}
break;
case HOLD:
case IDLE:

81
teensy/teensy-mouse.cpp Normal file
View File

@ -0,0 +1,81 @@
#include <Arduino.h>
#include "teensy-mouse.h"
#include "globals.h"
TeensyMouse::TeensyMouse() : PhysicalMouse()
{
xpos = ypos = 0;
button = false;
}
TeensyMouse::~TeensyMouse()
{
}
void TeensyMouse::gotMouseEvent(uint32_t buttonState, int32_t x, int32_t y)
{
xpos += x; ypos += y;
if (xpos < lowClamp[XCLAMP]) xpos=lowClamp[XCLAMP];
if (xpos > highClamp[XCLAMP]) xpos=highClamp[XCLAMP];
if (ypos < lowClamp[YCLAMP]) ypos = lowClamp[YCLAMP];
if (ypos > highClamp[YCLAMP]) ypos = highClamp[YCLAMP];
}
void TeensyMouse::mouseButtonEvent(bool state)
{
button = state;
}
void TeensyMouse::maintainMouse()
{
// FIXME: only do this if the mouse card is enabled, so we're not incurring
// analogRead delays constantly
uint8_t paddle0 = g_paddles->paddle0();
uint8_t paddle1 = g_paddles->paddle1();
int16_t dx=0, dy=0;
if (paddle0 <= 25) {
dx = -1;
} else if (paddle0 >= 245) {
dx = 1;
}
if (paddle1 <= 25) {
dy = -1;
} else if (paddle1 >= 245) {
dy = 1;
}
if (dx || dy) {
gotMouseEvent(button, dx, dy);
}
}
void TeensyMouse::setPosition(uint16_t x, uint16_t y)
{
xpos = x;
ypos = y;
if (xpos < lowClamp[XCLAMP]) xpos=lowClamp[XCLAMP];
if (xpos > highClamp[XCLAMP]) xpos=highClamp[XCLAMP];
if (ypos < lowClamp[YCLAMP]) ypos = lowClamp[YCLAMP];
if (ypos > highClamp[YCLAMP]) ypos = highClamp[YCLAMP];
}
void TeensyMouse::getPosition(uint16_t *x, uint16_t *y)
{
if (xpos < lowClamp[XCLAMP]) xpos=lowClamp[XCLAMP];
if (xpos > highClamp[XCLAMP]) xpos=highClamp[XCLAMP];
if (ypos < lowClamp[YCLAMP]) ypos = lowClamp[YCLAMP];
if (ypos > highClamp[YCLAMP]) ypos = highClamp[YCLAMP];
uint16_t outx = xpos;
uint16_t outy = ypos;
*x = outx;
*y = outy;
}
bool TeensyMouse::getButton()
{
return button;
}

24
teensy/teensy-mouse.h Normal file
View File

@ -0,0 +1,24 @@
#ifndef __TEENSY_MOUSE_H
#define __TEENSY_MOUSE_H
#include "physicalmouse.h"
class TeensyMouse : public PhysicalMouse {
public:
TeensyMouse();
virtual ~TeensyMouse();
virtual void maintainMouse();
virtual void setPosition(uint16_t x, uint16_t y);
virtual void getPosition(uint16_t *x, uint16_t *y);
virtual bool getButton();
void gotMouseEvent(uint32_t buttonState, int32_t x, int32_t y);
void mouseButtonEvent(bool state);
private:
int32_t xpos, ypos;
bool button;
};
#endif

View File

@ -6,6 +6,7 @@
#include "applevm.h"
#include "teensy-display.h"
#include "teensy-keyboard.h"
#include "teensy-mouse.h"
#include "teensy-speaker.h"
#include "teensy-paddles.h"
#include "teensy-filemanager.h"
@ -211,6 +212,7 @@ void setup()
// And the physical keyboard needs hooks in to the virtual keyboard...
println(" keyboard");
g_keyboard = new TeensyKeyboard(g_vm->getKeyboard());
g_mouse = new TeensyMouse();
println(" paddles");
g_paddles = new TeensyPaddles(A3, A2, g_invertPaddleX, g_invertPaddleY);

View File

@ -7,19 +7,16 @@ my $romfile = shift || die "Must provide the path to an Apple //e ROM image";
my $diskrom = shift || die "Must also provide the path to an Apple //e Disk II ROM image";
my $parallelrom = shift || die "Must also provide the path to an Apple // parallel card ROM image";
my $hdrom = shift || die "Must also provide the path to the AppleWin HDDRVR.BIN";
my $mouserom = shift || die "Also need the path to the 2k Mouse rom";
validate($romfile, 32768, "an Apple //e ROM image");
validate($diskrom, 256, "a DiskII ROM image");
validate($parallelrom, 256, "a parallel card ROM image");
validate($hdrom, 256, "HDDRVR.BIN from AppleWin");
validate($mouserom, 2048, "2k Mouse extended ROM image");
dumpRom($romfile, "apple/applemmu-rom.h", "romData", 32768);
dumpRom($diskrom, "apple/diskii-rom.h", "romData", 256);
dumpRom($parallelrom, "apple/parallel-rom.h", "romData", 256);
dumpRom($hdrom, "apple/hd32-rom.h", "romData", 256);
dumpRom($hdrom, "apple/mouse-rom.h", "romData", 2048);
exit 0;
sub validate {