use a common serial abstraction

This commit is contained in:
Jorj Bauer 2020-07-04 07:41:32 -04:00
parent 06189437cb
commit 7f561b1b90
6 changed files with 32 additions and 17 deletions

View File

@ -8,6 +8,10 @@
#include "globals.h" #include "globals.h"
#ifdef TEENSYDUINO
#include "teensy-println.h"
#endif
#include <errno.h> #include <errno.h>
const char *suspendHdr = "Sus2"; const char *suspendHdr = "Sus2";
@ -60,7 +64,7 @@ void AppleVM::Suspend(const char *fn)
hd32->Serialize(fh) hd32->Serialize(fh)
) { ) {
#ifdef TEENSYDUINO #ifdef TEENSYDUINO
Serial.println("All serialized successfully"); println("All serialized successfully");
#else #else
printf("All serialized successfully\n"); printf("All serialized successfully\n");
#endif #endif
@ -78,8 +82,8 @@ void AppleVM::Resume(const char *fn)
if (fh == -1) { if (fh == -1) {
// Unable to open; skip resume // Unable to open; skip resume
#ifdef TEENSYDUINO #ifdef TEENSYDUINO
Serial.print("Unable to open resume file "); print("Unable to open resume file ");
Serial.println(fn); println(fn);
#else #else
printf("Unable to open resume file\n"); printf("Unable to open resume file\n");
#endif #endif
@ -104,7 +108,7 @@ void AppleVM::Resume(const char *fn)
hd32->Deserialize(fh) hd32->Deserialize(fh)
) { ) {
#ifdef TEENSYDUINO #ifdef TEENSYDUINO
Serial.println("Deserialization successful"); println("Deserialization successful");
#else #else
printf("All deserialized successfully\n"); printf("All deserialized successfully\n");
#endif #endif

View File

@ -2,6 +2,7 @@
#ifdef TEENSYDUINO #ifdef TEENSYDUINO
#include <Arduino.h> #include <Arduino.h>
#include "teensy-println.h"
#else #else
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
@ -725,7 +726,7 @@ const char *DiskII::DiskName(int8_t num)
void DiskII::loadROM(uint8_t *toWhere) void DiskII::loadROM(uint8_t *toWhere)
{ {
#ifdef TEENSYDUINO #ifdef TEENSYDUINO
Serial.println("loading DiskII rom"); println("loading DiskII rom");
for (uint16_t i=0; i<=0xFF; i++) { for (uint16_t i=0; i<=0xFF; i++) {
toWhere[i] = pgm_read_byte(&romData[i]); toWhere[i] = pgm_read_byte(&romData[i]);
} }

View File

@ -11,6 +11,7 @@
#ifdef TEENSYDUINO #ifdef TEENSYDUINO
#include <Arduino.h> #include <Arduino.h>
#include "teensy-println.h"
#else #else
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
@ -197,7 +198,7 @@ void HD32::writeSwitches(uint8_t s, uint8_t v)
void HD32::loadROM(uint8_t *toWhere) void HD32::loadROM(uint8_t *toWhere)
{ {
#ifdef TEENSYDUINO #ifdef TEENSYDUINO
Serial.println("loading HD32 rom"); println("loading HD32 rom");
for (uint16_t i=0; i<=0xFF; i++) { for (uint16_t i=0; i<=0xFF; i++) {
toWhere[i] = pgm_read_byte(&romData[i]); toWhere[i] = pgm_read_byte(&romData[i]);
} }

View File

@ -4,6 +4,10 @@
#include "parallel-rom.h" #include "parallel-rom.h"
#include "fx80.h" #include "fx80.h"
#ifdef TEENSYDUINO
#include "teensy-println.h"
#endif
ParallelCard::ParallelCard() ParallelCard::ParallelCard()
{ {
fx80 = new Fx80(); fx80 = new Fx80();
@ -44,7 +48,7 @@ void ParallelCard::writeSwitches(uint8_t s, uint8_t v)
void ParallelCard::loadROM(uint8_t *toWhere) void ParallelCard::loadROM(uint8_t *toWhere)
{ {
#ifdef TEENSYDUINO #ifdef TEENSYDUINO
Serial.println("loading parallel slot rom"); println("loading parallel slot rom");
for (uint16_t i=0; i<=0xFF; i++) { for (uint16_t i=0; i<=0xFF; i++) {
toWhere[i] = pgm_read_byte(&romData[i]); toWhere[i] = pgm_read_byte(&romData[i]);
} }

16
cpu.cpp
View File

@ -9,6 +9,10 @@
#include "globals.h" #include "globals.h"
#ifdef TEENSYDUINO
#include "teensy-println.h"
#endif
// define DEBUGSTEPS to show disassembly of each instruction as it's processed // define DEBUGSTEPS to show disassembly of each instruction as it's processed
//#define DEBUGSTEPS //#define DEBUGSTEPS
#ifdef DEBUGSTEPS #ifdef DEBUGSTEPS
@ -326,11 +330,11 @@ bool Cpu::Serialize(int8_t fh)
x, x,
y, y,
flags, flags,
(cycles >> 24) & 0xFF, (uint8_t)((cycles >> 24) & 0xFF),
(cycles >> 16) & 0xFF, (uint8_t)((cycles >> 16) & 0xFF),
(cycles >> 8) & 0xFF, (uint8_t)((cycles >> 8) & 0xFF),
(cycles ) & 0xFF, (uint8_t)((cycles ) & 0xFF),
irqPending ? 1 : 0 }; irqPending ? (uint8_t)1 : (uint8_t)0 };
if (g_filemanager->write(fh, buf, 13) != 13) if (g_filemanager->write(fh, buf, 13) != 13)
return false; return false;
@ -339,7 +343,7 @@ bool Cpu::Serialize(int8_t fh)
#ifndef TEENSYDUINO #ifndef TEENSYDUINO
printf("MMU serialization failed\n"); printf("MMU serialization failed\n");
#else #else
Serial.println("MMU serialization failed"); println("MMU serialization failed");
#endif #endif
return false; return false;
} }

View File

@ -2,6 +2,7 @@
#include "teensy-keyboard.h" #include "teensy-keyboard.h"
#include <Keypad.h> #include <Keypad.h>
#include "LRingBuffer.h" #include "LRingBuffer.h"
#include "teensy-println.h"
const byte ROWS = 5; const byte ROWS = 5;
const byte COLS = 13; const byte COLS = 13;
@ -191,8 +192,8 @@ bool TeensyKeyboard::kbhit()
} }
// For debugging: also allow USB serial to act as a keyboard // For debugging: also allow USB serial to act as a keyboard
if (Serial.available()) { if (serialavailable()) {
buffer.addByte(Serial.read()); buffer.addByte(serialgetch());
} }
return buffer.hasData(); return buffer.hasData();
@ -230,8 +231,8 @@ void TeensyKeyboard::maintainKeyboard()
} }
// For debugging: also allow USB serial to act as a keyboard // For debugging: also allow USB serial to act as a keyboard
if (Serial.available()) { if (serialavailable()) {
int c = Serial.read(); int c = serialgetch();
vmkeyboard->keyDepressed(c); vmkeyboard->keyDepressed(c);
vmkeyboard->keyReleased(c); vmkeyboard->keyReleased(c);
} }