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"
#ifdef TEENSYDUINO
#include "teensy-println.h"
#endif
#include <errno.h>
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

View File

@ -2,6 +2,7 @@
#ifdef TEENSYDUINO
#include <Arduino.h>
#include "teensy-println.h"
#else
#include <unistd.h>
#include <fcntl.h>
@ -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]);
}

View File

@ -11,6 +11,7 @@
#ifdef TEENSYDUINO
#include <Arduino.h>
#include "teensy-println.h"
#else
#include <unistd.h>
#include <fcntl.h>
@ -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]);
}

View File

@ -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]);
}

16
cpu.cpp
View File

@ -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;
}

View File

@ -2,6 +2,7 @@
#include "teensy-keyboard.h"
#include <Keypad.h>
#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);
}