diff --git a/.gitignore b/.gitignore index 97bf4a3..6372f9a 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,5 @@ apple/hd32-rom.h aiie-sdl mockingboard-d.rom *.d - +*.dSYM +suspend.vm diff --git a/Makefile b/Makefile index eaf2de5..1997de9 100755 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/apple/mouse.cpp b/apple/mouse.cpp index f6e43ba..4ac82e2 100644 --- a/apple/mouse.cpp +++ b/apple/mouse.cpp @@ -2,8 +2,6 @@ #include #include "globals.h" -#include "mouse-rom.h" - enum { SW_W_INIT = 0x00, SW_R_HOMEMOUSE = 0x08, diff --git a/sdl/sdl-mouse.cpp b/sdl/sdl-mouse.cpp new file mode 100644 index 0000000..c7e386e --- /dev/null +++ b/sdl/sdl-mouse.cpp @@ -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; +} diff --git a/sdl/sdl-mouse.h b/sdl/sdl-mouse.h new file mode 100644 index 0000000..9da03db --- /dev/null +++ b/sdl/sdl-mouse.h @@ -0,0 +1,26 @@ +#ifndef __SDL_MOUSE_H +#define __SDL_MOUSE_H + +#include "physicalmouse.h" + +#include + +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 diff --git a/teensy/mouse.cpp b/teensy/mouse.cpp new file mode 120000 index 0000000..b2d16ed --- /dev/null +++ b/teensy/mouse.cpp @@ -0,0 +1 @@ +../apple/mouse.cpp \ No newline at end of file diff --git a/teensy/mouse.h b/teensy/mouse.h new file mode 120000 index 0000000..67eec56 --- /dev/null +++ b/teensy/mouse.h @@ -0,0 +1 @@ +../apple/mouse.h \ No newline at end of file diff --git a/teensy/physicalmouse.h b/teensy/physicalmouse.h new file mode 120000 index 0000000..80c4786 --- /dev/null +++ b/teensy/physicalmouse.h @@ -0,0 +1 @@ +../physicalmouse.h \ No newline at end of file diff --git a/teensy/teensy-keyboard.cpp b/teensy/teensy-keyboard.cpp index 7912fbc..7df9b1b 100644 --- a/teensy/teensy-keyboard.cpp +++ b/teensy/teensy-keyboard.cpp @@ -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: diff --git a/teensy/teensy-mouse.cpp b/teensy/teensy-mouse.cpp new file mode 100644 index 0000000..e6faaf4 --- /dev/null +++ b/teensy/teensy-mouse.cpp @@ -0,0 +1,81 @@ +#include +#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; +} diff --git a/teensy/teensy-mouse.h b/teensy/teensy-mouse.h new file mode 100644 index 0000000..8365d70 --- /dev/null +++ b/teensy/teensy-mouse.h @@ -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 diff --git a/teensy/teensy.ino b/teensy/teensy.ino index 9cb7b10..0b22b97 100644 --- a/teensy/teensy.ino +++ b/teensy/teensy.ino @@ -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); diff --git a/util/genrom.pl b/util/genrom.pl index b5ecaf2..867f2b0 100755 --- a/util/genrom.pl +++ b/util/genrom.pl @@ -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 {