Emulator boots again; but disks don't work

This commit is contained in:
InvisibleUp 2020-07-12 15:47:54 -04:00
parent b16c65cc79
commit 725f477884
6 changed files with 129 additions and 47 deletions

View File

@ -1222,7 +1222,7 @@ GLOBALFUNC uint32_t MMDV_Access(ATTep p, uint32_t Data,
} }
#endif #endif
if (WriteMem) { if (WriteMem) {
VIA_Write(VIA1, (addr >> 9) & kVIA1_Mask, Data); VIA_Write(VIA1, (addr >> 9) & kVIA1_Mask, Data, true);
} else { } else {
Data = VIA_Read(VIA1, (addr >> 9) & kVIA1_Mask); Data = VIA_Read(VIA1, (addr >> 9) & kVIA1_Mask);
} }

View File

@ -178,12 +178,6 @@ void RTC_RegisterISRs()
VIA_RegisterDataISR(DataRegB, VIA1, 0, RTCdataLine_ChangeNtfy); VIA_RegisterDataISR(DataRegB, VIA1, 0, RTCdataLine_ChangeNtfy);
} }
void RTC_RaiseOneSecIRQ()
{
VIA_RaiseInterrupt(VIA1, 0);
}
/// End VIA wrappers ///////////////////////////////////////////////////////// /// End VIA wrappers /////////////////////////////////////////////////////////
GLOBALFUNC bool RTC_Init(void) GLOBALFUNC bool RTC_Init(void)
@ -362,7 +356,6 @@ GLOBALPROC RTC_Interrupt(void)
LastRealDate = NewRealDate; LastRealDate = NewRealDate;
} }
RTC_RaiseOneSecIRQ();
} }
LOCALFUNC uint8_t RTC_Access_PRAM_Reg(uint8_t Data, bool WriteReg, uint8_t t) LOCALFUNC uint8_t RTC_Access_PRAM_Reg(uint8_t Data, bool WriteReg, uint8_t t)

View File

@ -134,10 +134,9 @@ GLOBALPROC MacSound_SubTick(int SubTick)
#else #else
CPTR addr = addy + (2 * StartOffset); CPTR addr = addy + (2 * StartOffset);
#endif #endif
uint16_t SoundInvertTime = ((VIA_Read(VIA1, rT1CH) << 8) | VIA_Read(VIA1, rT1CL)); uint16_t SoundInvertTime = VIA1_GetT1InvertTime();
uint8_t SoundVolume = MacSound_GetVolume(); uint8_t SoundVolume = MacSound_GetVolume();
bool SoundDisable = MacSound_CheckDisabled(); bool SoundDisable = MacSound_CheckDisabled();
if (VIA_ReadBit(VIA1, rACR, 7) == 0) { SoundInvertTime = 0; }
#if dbglog_HAVE && 0 #if dbglog_HAVE && 0
dbglog_StartLine(); dbglog_StartLine();

View File

@ -26,6 +26,7 @@
#include <stdbool.h> #include <stdbool.h>
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
#include <stdio.h>
#include "VIAEMDEV.h" #include "VIAEMDEV.h"
#include "GLOBGLUE.h" #include "GLOBGLUE.h"
@ -35,15 +36,20 @@ VIA_State_t VIA_State[VIA_MAXNUM];
// Hardware reset // Hardware reset
bool VIA_Zap(void) { bool VIA_Zap(void) {
memset(VIA_State, 0, sizeof(VIA_State)); memset(VIA_State, 0, sizeof(VIA_State));
for (int i = 0; i < VIA_MAXNUM; i += 1) { VIA_Reset();
VIA_State[i].vBufA = 0xFF;
VIA_State[i].vBufB = 0xFF;
}
return true; return true;
} }
// Software reset // Software reset
void VIA_Reset(void) { void VIA_Reset(void) {
VIA_Zap(); for (int i = 0; i < VIA_MAXNUM; i += 1) {
VIA_State[i].vBufA = 0xFF;
VIA_State[i].vBufB = 0xFF;
VIA_State[i].vIER = 0x00;
VIA_State[i].vIFR = 0x00;
VIA_State[i].vSR = 0x00;
VIA_State[i].vACR = 0x00;
VIA_State[i].vPCR = 0x00;
}
} }
// Raise an interrupt by irq number // Raise an interrupt by irq number
@ -53,13 +59,20 @@ void VIA_RaiseInterrupt(uint8_t id, uint8_t irq)
assert (irq < 7); assert (irq < 7);
// Set interrupt flag // Set interrupt flag
uint8_t vIFR_old = VIA_State[id].vIFR & VIA_State[id].vIER & 0b01111111;
VIA_State[id].vIFR |= (1 << irq) | (1 << 7); VIA_State[id].vIFR |= (1 << irq) | (1 << 7);
uint8_t vIFR_new = VIA_State[id].vIFR & VIA_State[id].vIER & 0b01111111;
// Call interrupt handler, if required // Call interrupt handler, if required
if (VIA_State[id].vISR[irq] != NULL) { if (vIFR_old != vIFR_new) {
/*if (VIA_State[id].vISR[irq] != NULL) {
VIA_State[id].vISR[irq](); VIA_State[id].vISR[irq]();
} }*/
VIAorSCCinterruptChngNtfy(); VIAorSCCinterruptChngNtfy();
//fprintf(stderr, "IRQ %d raised\n", irq);
} else {
//fprintf(stderr, "IRQ %d attempted\n", irq);
}
} }
// Lower an interrupt by irq number // Lower an interrupt by irq number
@ -69,13 +82,20 @@ void VIA_LowerInterrupt(uint8_t id, uint8_t irq)
assert (irq < 7); assert (irq < 7);
// Set interrupt flag // Set interrupt flag
uint8_t vIFR_old = VIA_State[id].vIFR & VIA_State[id].vIER & 0b01111111;
VIA_State[id].vIFR &= ~(1 << irq); VIA_State[id].vIFR &= ~(1 << irq);
uint8_t vIFR_new = VIA_State[id].vIFR & VIA_State[id].vIER & 0b01111111;
// Call interrupt handler, if required // Call interrupt handler, if required
if (VIA_State[id].vISR[irq] != NULL) { if (vIFR_old != vIFR_new) {
/*if (VIA_State[id].vISR[irq] != NULL) {
VIA_State[id].vISR[irq](); VIA_State[id].vISR[irq]();
} }*/
VIAorSCCinterruptChngNtfy(); VIAorSCCinterruptChngNtfy();
//fprintf(stderr, "IRQ %d lowered\n", irq);
} else {
//fprintf(stderr, "IRQ %d attempted (lower)\n", irq);
}
} }
// Register a VIA interrupt service routine // Register a VIA interrupt service routine
@ -95,10 +115,33 @@ void VIA_RegisterDataISR(uint8_t port, uint8_t id, uint8_t irq, VIA_ISR_t isr)
if (port == DataRegA) { if (port == DataRegA) {
VIA_State[id].vISR_A[irq] = isr; VIA_State[id].vISR_A[irq] = isr;
//fprintf(stderr, "ISR PA%d registered\n", irq);
} else { } else {
VIA_State[id].vISR_B[irq] = isr; VIA_State[id].vISR_B[irq] = isr;
//fprintf(stderr, "ISR PB%d registered\n", irq);
} }
} }
static void VIA_RunDataISR(uint8_t id, VIA_Register_t reg, uint8_t bit)
{
assert(id < VIA_MAXNUM);
if (reg == rIRA || reg == rORA) {
if (VIA_State[id].vISR_A[bit] != NULL) {
//fprintf(stderr, "ISR PA%d running\n", bit);
VIA_State[id].vISR_A[bit]();
} else {
//fprintf(stderr, "ISR PA%d not found\n", bit);
}
} else if (reg == rIRB) {
if (VIA_State[id].vISR_B[bit] != NULL) {
//fprintf(stderr, "ISR PB%d running\n", bit);
VIA_State[id].vISR_B[bit]();
} else {
//fprintf(stderr, "ISR PB%d not found\n", bit);
}
}
}
/* /*
const int TEMPSKIP = 1; const int TEMPSKIP = 1;
@ -174,15 +217,32 @@ void VIA_TickShiftRegister(uint8_t id)
} }
} }
// temporary debugging stuff
#define BIN_PAT "%c%c%c%c_%c%c%c%c"
#define TO_BIN(byte) \
(byte & 0x80 ? '1' : '0'), \
(byte & 0x40 ? '1' : '0'), \
(byte & 0x20 ? '1' : '0'), \
(byte & 0x10 ? '1' : '0'), \
(byte & 0x08 ? '1' : '0'), \
(byte & 0x04 ? '1' : '0'), \
(byte & 0x02 ? '1' : '0'), \
(byte & 0x01 ? '1' : '0')
// Write to a register, bypassing data ISRs // Write to a register, bypassing data ISRs
void VIA_Write(uint8_t id, VIA_Register_t reg, uint8_t data) void VIA_Write(uint8_t id, VIA_Register_t reg, uint8_t data, bool runISR)
{ {
assert(id < VIA_MAXNUM); assert(id < VIA_MAXNUM);
assert(reg < rINVALID); assert(reg < rINVALID);
VIA_State_t *via = &VIA_State[id]; VIA_State_t *via = &VIA_State[id];
uint8_t data_old = VIA_Read(id, reg); uint8_t data_old = VIA_Read(id, reg);
uint8_t vIFR_old = via->vIFR & via->vIER & 0b01111111;
if (reg == rIRA || reg == rORA) {
//fprintf(stderr, "Set PA to "BIN_PAT"\n", TO_BIN(data));
} else {
//`fprintf(stderr, "Set PB to "BIN_PAT"\n", TO_BIN(data));
}
switch(reg) { switch(reg) {
case rIRB: via->vIFR &= 0b11100111; // clear keyboard interrupts case rIRB: via->vIFR &= 0b11100111; // clear keyboard interrupts
@ -206,13 +266,13 @@ void VIA_Write(uint8_t id, VIA_Register_t reg, uint8_t data)
case rSR: via->vSR = data; break; case rSR: via->vSR = data; break;
case rACR: via->vACR = data; break; case rACR: via->vACR = data; break;
case rPCR: via->vPCR = data; break; case rPCR: via->vPCR = data; break;
case rIFR: via->vIFR = data; break; case rIFR: via->vIFR &= (~data & 0b01111111); break;
case rIER: case rIER:
switch(data & 0b10000000) { switch(data & 0b10000000) {
case 0b00000000: // clear case 0b00000000: // clear
via->vIER &= ~(data & 0b01111111); via->vIER &= ~(data & 0b01111111);
break; break;
case 0b10000000: // set default: // set
via->vIER |= (data & 0b01111111); via->vIER |= (data & 0b01111111);
break; break;
} }
@ -220,8 +280,37 @@ void VIA_Write(uint8_t id, VIA_Register_t reg, uint8_t data)
default: assert(true); default: assert(true);
} }
if ((data_old & via->vIFR) != (data & via->vIFR) && reg == rIFR) { /*if ((data_old & via->vIFR) != (data & via->vIFR) && reg == rIFR) {
VIAorSCCinterruptChngNtfy(); VIAorSCCinterruptChngNtfy();
}*/
// Assert vBufA or vBufB ISRs if needed
uint8_t diff = (data ^ data_old);
if (runISR && (reg == rIRA || reg == rORA || reg == rIRB)) {
// Iterate through each bit
uint8_t bit = 0;
uint8_t mask = 0b1;
while (mask != 0) {
// Run ISR only on rising edge
if (diff & mask) { VIA_RunDataISR(id, reg, bit); }
bit += 1;
mask <<= 1;
}
}
// Run global ISR if required
uint8_t vIFR_new = via->vIFR & via->vIER & 0b01111111;
if (runISR && (reg == rIFR || reg == rIER) && (vIFR_old != vIFR_new))
{
/*if (VIA_State[id].vISR[irq] != NULL) {
VIA_State[id].vISR[irq]();
}*/
VIAorSCCinterruptChngNtfy();
//fprintf(stderr, "IRQ raised ("BIN_PAT")\n", TO_BIN((vIFR_old ^ vIFR_new)));
}
else if (reg == rIFR || reg == rIER)
{
//fprintf(stderr, "IRQ attempt ("BIN_PAT")\n", TO_BIN((vIFR_old ^ vIFR_new)));
} }
} }
@ -272,21 +361,15 @@ void VIA_WriteBit(uint8_t id, VIA_Register_t reg, uint8_t bit, bool value, bool
uint8_t data = olddata; uint8_t data = olddata;
if (value) { data |= (1 << bit); } // set if (value) { data |= (1 << bit); } // set
else { data &= ~(1 << bit); } // clear else { data &= ~(1 << bit); } // clear
VIA_Write(id, reg, data); VIA_Write(id, reg, data, runISR);
// Call data-change ISR // Call data-change ISR
if (!runISR || (data == olddata)) { return; } /*uint8_t diff = ~data & olddata;
if (reg == rIRA || reg == rORA) { if (!runISR || (diff == 0)) { return; }
if (VIA_State[id].vISR_A[bit] != NULL) { VIA_RunDataISR(id, reg, bit);*/
VIA_State[id].vISR_A[bit]();
}
} else if (reg == rIRB) {
if (VIA_State[id].vISR_B[bit] != NULL) {
VIA_State[id].vISR_B[bit]();
}
}
} }
// Called by either end; store data in vSR. // Called by either end; store data in vSR.
// TODO: this probably shouldn't be instant. // TODO: this probably shouldn't be instant.
void VIA_ShiftInData(uint8_t id, uint8_t v) void VIA_ShiftInData(uint8_t id, uint8_t v)

View File

@ -82,7 +82,7 @@ void VIA_RegisterDataISR(uint8_t port, uint8_t id, uint8_t bit, VIA_ISR_t isr);
//void VIA_TickTimers(); //void VIA_TickTimers();
// Write to a register. Does not raise data ISRs. // Write to a register. Does not raise data ISRs.
void VIA_Write(uint8_t id, VIA_Register_t reg, uint8_t data); void VIA_Write(uint8_t id, VIA_Register_t reg, uint8_t data, bool runISR);
// Read to a register // Read to a register
uint8_t VIA_Read(uint8_t id, VIA_Register_t reg); uint8_t VIA_Read(uint8_t id, VIA_Register_t reg);
// Read a single bit // Read a single bit

View File

@ -20,6 +20,7 @@
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
#include <stdio.h>
#include "SYSDEPNS.h" #include "SYSDEPNS.h"
#include "UI/MYOSGLUE.h" #include "UI/MYOSGLUE.h"
@ -71,7 +72,7 @@ const DevMethods_t DEVICES[] = {
.timeend = VIA1_ExtraTimeEnd, .timeend = VIA1_ExtraTimeEnd,
}, },
// RTC // RTC
/* { {
.init = EmRTC ? RTC_Init : NULL, .init = EmRTC ? RTC_Init : NULL,
.reset = NULL, .reset = NULL,
.starttick = NULL, .starttick = NULL,
@ -79,7 +80,7 @@ const DevMethods_t DEVICES[] = {
.subtick = NULL, .subtick = NULL,
.timebegin = NULL, .timebegin = NULL,
.timeend = NULL, .timeend = NULL,
},*/ },
// ROM // ROM
{ {
.init = ROM_Init, .init = ROM_Init,
@ -121,7 +122,7 @@ const DevMethods_t DEVICES[] = {
.timeend = NULL, .timeend = NULL,
},*/ },*/
// SCSI // SCSI
/* { {
.init = NULL, .init = NULL,
.reset = SCSI_Reset, .reset = SCSI_Reset,
.starttick = NULL, .starttick = NULL,
@ -139,7 +140,7 @@ const DevMethods_t DEVICES[] = {
.subtick = NULL, .subtick = NULL,
.timebegin = NULL, .timebegin = NULL,
.timeend = NULL, .timeend = NULL,
},*/ },
// Extn // Extn
{ {
.init = NULL, .init = NULL,
@ -161,7 +162,7 @@ const DevMethods_t DEVICES[] = {
.timeend = NULL, .timeend = NULL,
}, },
// Mouse // Mouse
/* { {
.init = NULL, .init = NULL,
.reset = NULL, .reset = NULL,
.starttick = Mouse_Update, .starttick = Mouse_Update,
@ -169,9 +170,9 @@ const DevMethods_t DEVICES[] = {
.subtick = NULL, .subtick = NULL,
.timebegin = NULL, .timebegin = NULL,
.timeend = NULL, .timeend = NULL,
},*/ },
// Classic Keyboard // Classic Keyboard
/* { {
.init = NULL, .init = NULL,
.reset = NULL, .reset = NULL,
.starttick = EmClassicKbrd ? KeyBoard_Update : NULL, .starttick = EmClassicKbrd ? KeyBoard_Update : NULL,
@ -179,7 +180,7 @@ const DevMethods_t DEVICES[] = {
.subtick = NULL, .subtick = NULL,
.timebegin = NULL, .timebegin = NULL,
.timeend = NULL, .timeend = NULL,
},*/ },
// ADB // ADB
/*{ /*{
.init = NULL, .init = NULL,
@ -383,9 +384,14 @@ LOCALFUNC bool InitEmulation(void)
if (DEVICES[i].init != NULL) { if (DEVICES[i].init != NULL) {
assert(DEVICES[i].init()); assert(DEVICES[i].init());
} }
if (DEVICES[i].reset != NULL) {
DEVICES[i].reset();
}
} }
EmulatedHardwareZap(); // temporarily register some ISRs until I put these in a better place
// Mac Plus only
VIA_RegisterDataISR(VIA1, DataRegA, 4, MemOverlay_ChangeNtfy);
return true; return true;
} }
// VBlank interrupt // VBlank interrupt
@ -572,6 +578,7 @@ LOCALPROC RunEmulatedTicksToTrueTime(void)
if (lag > 0) { if (lag > 0) {
DoEmulateOneTick(); DoEmulateOneTick();
CurEmulatedTime += 1; CurEmulatedTime += 1;
//fprintf(stderr, "Tick %d\n", CurEmulatedTime);
DoneWithDrawingForTick(); DoneWithDrawingForTick();
if (lag > 8) { if (lag > 8) {