From 7f561b1b909b06dfee48f22017e868ff99b1563d Mon Sep 17 00:00:00 2001 From: Jorj Bauer Date: Sat, 4 Jul 2020 07:41:32 -0400 Subject: [PATCH] use a common serial abstraction --- apple/applevm.cpp | 12 ++++++++---- apple/diskii.cpp | 3 ++- apple/hd32.cpp | 3 ++- apple/parallelcard.cpp | 6 +++++- cpu.cpp | 16 ++++++++++------ teensy/teensy-keyboard.cpp | 9 +++++---- 6 files changed, 32 insertions(+), 17 deletions(-) diff --git a/apple/applevm.cpp b/apple/applevm.cpp index 448eff1..e2b9a00 100644 --- a/apple/applevm.cpp +++ b/apple/applevm.cpp @@ -8,6 +8,10 @@ #include "globals.h" +#ifdef TEENSYDUINO +#include "teensy-println.h" +#endif + #include const char *suspendHdr = "Sus2"; @@ -60,7 +64,7 @@ void AppleVM::Suspend(const char *fn) hd32->Serialize(fh) ) { #ifdef TEENSYDUINO - Serial.println("All serialized successfully"); + println("All serialized successfully"); #else printf("All serialized successfully\n"); #endif @@ -78,8 +82,8 @@ void AppleVM::Resume(const char *fn) if (fh == -1) { // Unable to open; skip resume #ifdef TEENSYDUINO - Serial.print("Unable to open resume file "); - Serial.println(fn); + print("Unable to open resume file "); + println(fn); #else printf("Unable to open resume file\n"); #endif @@ -104,7 +108,7 @@ void AppleVM::Resume(const char *fn) hd32->Deserialize(fh) ) { #ifdef TEENSYDUINO - Serial.println("Deserialization successful"); + println("Deserialization successful"); #else printf("All deserialized successfully\n"); #endif diff --git a/apple/diskii.cpp b/apple/diskii.cpp index ce61924..7740b98 100644 --- a/apple/diskii.cpp +++ b/apple/diskii.cpp @@ -2,6 +2,7 @@ #ifdef TEENSYDUINO #include +#include "teensy-println.h" #else #include #include @@ -725,7 +726,7 @@ const char *DiskII::DiskName(int8_t num) void DiskII::loadROM(uint8_t *toWhere) { #ifdef TEENSYDUINO - Serial.println("loading DiskII rom"); + println("loading DiskII rom"); for (uint16_t i=0; i<=0xFF; i++) { toWhere[i] = pgm_read_byte(&romData[i]); } diff --git a/apple/hd32.cpp b/apple/hd32.cpp index f2cd894..405dc9d 100644 --- a/apple/hd32.cpp +++ b/apple/hd32.cpp @@ -11,6 +11,7 @@ #ifdef TEENSYDUINO #include +#include "teensy-println.h" #else #include #include @@ -197,7 +198,7 @@ void HD32::writeSwitches(uint8_t s, uint8_t v) void HD32::loadROM(uint8_t *toWhere) { #ifdef TEENSYDUINO - Serial.println("loading HD32 rom"); + println("loading HD32 rom"); for (uint16_t i=0; i<=0xFF; i++) { toWhere[i] = pgm_read_byte(&romData[i]); } diff --git a/apple/parallelcard.cpp b/apple/parallelcard.cpp index c20498c..d4db9cf 100644 --- a/apple/parallelcard.cpp +++ b/apple/parallelcard.cpp @@ -4,6 +4,10 @@ #include "parallel-rom.h" #include "fx80.h" +#ifdef TEENSYDUINO +#include "teensy-println.h" +#endif + ParallelCard::ParallelCard() { fx80 = new Fx80(); @@ -44,7 +48,7 @@ void ParallelCard::writeSwitches(uint8_t s, uint8_t v) void ParallelCard::loadROM(uint8_t *toWhere) { #ifdef TEENSYDUINO - Serial.println("loading parallel slot rom"); + println("loading parallel slot rom"); for (uint16_t i=0; i<=0xFF; i++) { toWhere[i] = pgm_read_byte(&romData[i]); } diff --git a/cpu.cpp b/cpu.cpp index b542e42..ff6d794 100644 --- a/cpu.cpp +++ b/cpu.cpp @@ -9,6 +9,10 @@ #include "globals.h" +#ifdef TEENSYDUINO +#include "teensy-println.h" +#endif + // define DEBUGSTEPS to show disassembly of each instruction as it's processed //#define DEBUGSTEPS #ifdef DEBUGSTEPS @@ -326,11 +330,11 @@ bool Cpu::Serialize(int8_t fh) x, y, flags, - (cycles >> 24) & 0xFF, - (cycles >> 16) & 0xFF, - (cycles >> 8) & 0xFF, - (cycles ) & 0xFF, - irqPending ? 1 : 0 }; + (uint8_t)((cycles >> 24) & 0xFF), + (uint8_t)((cycles >> 16) & 0xFF), + (uint8_t)((cycles >> 8) & 0xFF), + (uint8_t)((cycles ) & 0xFF), + irqPending ? (uint8_t)1 : (uint8_t)0 }; if (g_filemanager->write(fh, buf, 13) != 13) return false; @@ -339,7 +343,7 @@ bool Cpu::Serialize(int8_t fh) #ifndef TEENSYDUINO printf("MMU serialization failed\n"); #else - Serial.println("MMU serialization failed"); + println("MMU serialization failed"); #endif return false; } diff --git a/teensy/teensy-keyboard.cpp b/teensy/teensy-keyboard.cpp index 855543c..4558ef5 100644 --- a/teensy/teensy-keyboard.cpp +++ b/teensy/teensy-keyboard.cpp @@ -2,6 +2,7 @@ #include "teensy-keyboard.h" #include #include "LRingBuffer.h" +#include "teensy-println.h" const byte ROWS = 5; const byte COLS = 13; @@ -191,8 +192,8 @@ bool TeensyKeyboard::kbhit() } // For debugging: also allow USB serial to act as a keyboard - if (Serial.available()) { - buffer.addByte(Serial.read()); + if (serialavailable()) { + buffer.addByte(serialgetch()); } return buffer.hasData(); @@ -230,8 +231,8 @@ void TeensyKeyboard::maintainKeyboard() } // For debugging: also allow USB serial to act as a keyboard - if (Serial.available()) { - int c = Serial.read(); + if (serialavailable()) { + int c = serialgetch(); vmkeyboard->keyDepressed(c); vmkeyboard->keyReleased(c); }