Skip to content

Commit

Permalink
Merge pull request #486 from paulscottrobson/sw16fix
Browse files Browse the repository at this point in the history
Fixed Sweet16 yielding issue
  • Loading branch information
paulscottrobson authored May 4, 2024
2 parents a8a3da3 + c836002 commit 6116de0
Show file tree
Hide file tree
Showing 6 changed files with 344 additions and 13 deletions.
12 changes: 11 additions & 1 deletion emulator/src/core/sys_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ BYTE8 CPUExecuteInstruction(void) {
forceSync = CPUExecute16();
}

int cycleMax = CYCLES_PER_FRAME;
int cycleMax = CYCLES_PER_FRAME;
if (cycles < cycleMax && forceSync == 0) return 0; // Not completed a frame.
cycles = 0; // Reset cycle counter.
HWSync(); // Update any hardware
Expand All @@ -213,6 +213,16 @@ void CPUWriteMemory(WORD16 address,BYTE8 data) {

#include "gfx.h"

// ***************************************************************************************
//
// Handle Sweet16 Sync
//
// ***************************************************************************************

void TMRSweet16Sync(void) {
cycles = CYCLES_PER_FRAME; // If yields running via API do frame.
}

// *******************************************************************************************************************************
//
// Execute chunk of code, to either of two break points or frame-out, return non-zero frame rate on frame, breakpoint 0
Expand Down
1 change: 1 addition & 0 deletions firmware/common/include/interface/timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#define _TIMER_H

uint32_t TMRRead(void);
void TMRSweet16Sync(void);

#endif

Expand Down
19 changes: 7 additions & 12 deletions firmware/common/sources/interface/sweet16.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
//
// ***************************************************************************************

static uint16_t sweet_reg[16];
static uint16_t default_sweet_registers[16];

static uint16_t *sweet_reg = default_sweet_registers;

// ***************************************************************************************
//
Expand Down Expand Up @@ -113,7 +115,7 @@ bool SW16Execute(uint16_t reg) {
bool bQuitSweet = false; // Set by RTN.
int32_t yieldCounter = 6000000/60; // 6 MIPS , 60 frames per second
uint16_t temp; // (set by the emulator)

sweet_reg = default_sweet_registers; // Execute using the memory allocated.
for (int i = 0;i < 16;i++) { // Copy cpu memory to working registers
sweet_reg[i] = cpuMemory[reg+i*2]+(cpuMemory[reg+i*2+1] << 8);
}
Expand All @@ -126,6 +128,7 @@ bool SW16Execute(uint16_t reg) {
cpuMemory[reg+i*2] = sweet_reg[i] & 0xFF;
cpuMemory[reg+i*2+1] = sweet_reg[i] >> 8;
}
TMRSweet16Sync(); // Sweet 16 Frame Sync
return bQuitSweet;
}

Expand All @@ -138,18 +141,11 @@ bool SW16Execute(uint16_t reg) {
bool SW16ExecuteOne(uint16_t reg) {
bool bQuitSweet = false; // Set by RTN.
uint16_t temp; // (set by the emulator)

for (int i = 0;i < 16;i++) { // Copy cpu memory to working registers
sweet_reg[i] = cpuMemory[reg+i*2]+(cpuMemory[reg+i*2+1] << 8);
}

sweet_reg = (uint16_t *)(cpuMemory+reg); // This is non RISC so we can access directly.
switch(FETCH8()) {
#include "data/sweet_opcodes.h"
}
for (int i = 0;i < 16;i++) { // Copy working registers to CPU memory
cpuMemory[reg+i*2] = sweet_reg[i] & 0xFF;
cpuMemory[reg+i*2+1] = sweet_reg[i] >> 8;
}
sweet_reg = default_sweet_registers; // Execute using the memory allocated.
return bQuitSweet;
}

Expand All @@ -158,7 +154,6 @@ bool SW16ExecuteOne(uint16_t reg) {
// ***************************************************************************************

void SW16ExtendedRegister(uint8_t func,uint8_t reg) {
printf("Ext func %d on R%d\n",func,reg);
switch (func) {
case 0: // 0 multiply by Rn
R(0) = R(0) * R(reg);break;
Expand Down
9 changes: 9 additions & 0 deletions firmware/sources/hardware/timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ uint32_t TMRRead(void) {
return (time32 * 210) >> 11; // Error of about 0.07%
}

// ***************************************************************************************
//
// Handle Sweet16 Sync
//
// ***************************************************************************************

void TMRSweet16Sync(void) {
}

// ***************************************************************************************
//
// Date Revision
Expand Down
8 changes: 8 additions & 0 deletions nf.sublime-project
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"folders":
[
{
"path": "."
}
]
}
Loading

0 comments on commit 6116de0

Please sign in to comment.