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 aiie-sdl
mockingboard-d.rom mockingboard-d.rom
*.d *.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 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 .PHONY: roms clean
@ -40,7 +40,7 @@ test: $(TSRC)
./testharness -f tests/65c02-all.bin -s 0x200 ./testharness -f tests/65c02-all.bin -s 0x200
roms: apple2e.rom disk.rom parallel.rom HDDRVR.BIN 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 apple/applemmu-rom.h: roms

View File

@ -2,8 +2,6 @@
#include <string.h> #include <string.h>
#include "globals.h" #include "globals.h"
#include "mouse-rom.h"
enum { enum {
SW_W_INIT = 0x00, SW_W_INIT = 0x00,
SW_R_HOMEMOUSE = 0x08, 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 "LRingBuffer.h"
#include "teensy-println.h" #include "teensy-println.h"
#include "globals.h"
#include "teensy-mouse.h"
const byte ROWS = 5; const byte ROWS = 5;
const byte COLS = 13; const byte COLS = 13;
@ -71,12 +74,13 @@ void TeensyKeyboard::pressedKey(uint8_t key)
break; break;
case PK_RSHFT: case PK_RSHFT:
rightShiftPressed = 1; rightShiftPressed = 1;
break; break;
case PK_LOCK: case PK_LOCK:
capsLock = !capsLock; capsLock = !capsLock;
break; break;
case PK_LA: case PK_LA:
leftApplePressed = 1; ((TeensyMouse *)g_mouse)->mouseButtonEvent(true);
leftApplePressed = 1;
break; break;
case PK_RA: case PK_RA:
rightApplePressed = 1; rightApplePressed = 1;
@ -162,6 +166,7 @@ void TeensyKeyboard::releasedKey(uint8_t key)
rightShiftPressed = 0; rightShiftPressed = 0;
break; break;
case PK_LA: case PK_LA:
((TeensyMouse *)g_mouse)->mouseButtonEvent(false);
leftApplePressed = 0; leftApplePressed = 0;
break; break;
case PK_RA: case PK_RA:
@ -218,9 +223,15 @@ void TeensyKeyboard::maintainKeyboard()
switch (keypad.key[i].kstate) { switch (keypad.key[i].kstate) {
case PRESSED: case PRESSED:
vmkeyboard->keyDepressed(keypad.key[i].kchar); vmkeyboard->keyDepressed(keypad.key[i].kchar);
if (keypad.key[i].kchar == PK_LSHFT) {
((TeensyMouse *)g_mouse)->mouseButtonEvent(true);
}
break; break;
case RELEASED: case RELEASED:
vmkeyboard->keyReleased(keypad.key[i].kchar); vmkeyboard->keyReleased(keypad.key[i].kchar);
if (keypad.key[i].kchar == PK_LSHFT) {
((TeensyMouse *)g_mouse)->mouseButtonEvent(false);
}
break; break;
case HOLD: case HOLD:
case IDLE: 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 "applevm.h"
#include "teensy-display.h" #include "teensy-display.h"
#include "teensy-keyboard.h" #include "teensy-keyboard.h"
#include "teensy-mouse.h"
#include "teensy-speaker.h" #include "teensy-speaker.h"
#include "teensy-paddles.h" #include "teensy-paddles.h"
#include "teensy-filemanager.h" #include "teensy-filemanager.h"
@ -211,6 +212,7 @@ void setup()
// And the physical keyboard needs hooks in to the virtual keyboard... // And the physical keyboard needs hooks in to the virtual keyboard...
println(" keyboard"); println(" keyboard");
g_keyboard = new TeensyKeyboard(g_vm->getKeyboard()); g_keyboard = new TeensyKeyboard(g_vm->getKeyboard());
g_mouse = new TeensyMouse();
println(" paddles"); println(" paddles");
g_paddles = new TeensyPaddles(A3, A2, g_invertPaddleX, g_invertPaddleY); 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 $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 $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 $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($romfile, 32768, "an Apple //e ROM image");
validate($diskrom, 256, "a DiskII ROM image"); validate($diskrom, 256, "a DiskII ROM image");
validate($parallelrom, 256, "a parallel card ROM image"); validate($parallelrom, 256, "a parallel card ROM image");
validate($hdrom, 256, "HDDRVR.BIN from AppleWin"); validate($hdrom, 256, "HDDRVR.BIN from AppleWin");
validate($mouserom, 2048, "2k Mouse extended ROM image");
dumpRom($romfile, "apple/applemmu-rom.h", "romData", 32768); dumpRom($romfile, "apple/applemmu-rom.h", "romData", 32768);
dumpRom($diskrom, "apple/diskii-rom.h", "romData", 256); dumpRom($diskrom, "apple/diskii-rom.h", "romData", 256);
dumpRom($parallelrom, "apple/parallel-rom.h", "romData", 256); dumpRom($parallelrom, "apple/parallel-rom.h", "romData", 256);
dumpRom($hdrom, "apple/hd32-rom.h", "romData", 256); dumpRom($hdrom, "apple/hd32-rom.h", "romData", 256);
dumpRom($hdrom, "apple/mouse-rom.h", "romData", 2048);
exit 0; exit 0;
sub validate { sub validate {