- Disk read huge speed bump by accelerating CPU clock for 200ms

This commit is contained in:
Tamas Rudnai 2020-02-16 23:09:29 -08:00
parent 0c72992e8a
commit 9b3b79cca0
6 changed files with 71 additions and 47 deletions

View File

@ -429,6 +429,7 @@ class ViewController: NSViewController {
mhz = freq
MHz_6502 = UInt64(mhz * M)
clk_6502_per_frm = MHz_6502 / UInt64(fps)
clk_6502_per_frm_set = clk_6502_per_frm
}
@IBAction func speedSelected(_ sender: NSButton) {

View File

@ -33,10 +33,12 @@ void ViewController_spk_dn_play(void);
const unsigned long long int iterations = G;
unsigned long long int inst_cnt = 0;
const unsigned int fps = 30;
//const unsigned int fps = 30;
const unsigned long long default_MHz_6502 = 1.023 * M; // 2 * M; // 4 * M; // 8 * M; // 16 * M; // 128 * M; // 256 * M; // 512 * M;
unsigned long long MHz_6502 = default_MHz_6502;
unsigned long long clk_6502_per_frm = default_MHz_6502 / fps;
unsigned long long clk_6502_per_frm_set = default_MHz_6502 / fps;
unsigned long long tick_per_sec = G;
unsigned long long tick_6502_per_sec = 0;
@ -77,13 +79,56 @@ disassembly_t disassembly;
#include "disassembler.h"
#include "mmio.h"
uint16_t videoShadow [0x1000];
uint32_t videoMem [0x2000];
uint32_t * videoMemPtr = videoMem;
uint16_t HiResLineAddrTbl [0x2000];
INLINE void set_flags_N( const uint8_t test ) {
m6502.N = BITTEST(test, 7);
}
INLINE void set_flags_V( const uint8_t test ) {
m6502.V = BITTEST(test, 6);
}
INLINE void set_flags_Z( const uint8_t test ) {
m6502.Z = test == 0;
}
INLINE void set_flags_C( const int16_t test ) {
m6502.C = test >= 0;
}
INLINE void set_flags_NZ( const uint8_t test ) {
set_flags_N(test);
set_flags_Z(test);
}
INLINE void set_flags_NV( const uint8_t test ) {
set_flags_N(test);
set_flags_V(test);
}
INLINE void set_flags_NVZ( const uint8_t test ) {
set_flags_NZ(test);
set_flags_V(test);
}
INLINE void set_flags_NZC( const int16_t test ) {
set_flags_NZ(test);
set_flags_C(test);
}
//INLINE void set_flags_NZCV( int test ) {
// set_flags_NZC(test);
// set_flags_V(test);
//}
void initHiResLineAddresses() {
uint16_t i = 0;
for ( uint16_t x = 0; x <= 0x50; x+= 0x28 ) {

View File

@ -15,6 +15,7 @@
extern unsigned long long MHz_6502;
extern unsigned long long clk_6502_per_frm;
extern unsigned long long clk_6502_per_frm_set;
typedef enum {
@ -99,7 +100,8 @@ extern void hires_Update(void);
extern double mips;
extern double mhz;
extern const unsigned int fps;
#define fps 30
extern void tst6502(void);
extern void m6502_ColdReset(void);
@ -107,46 +109,5 @@ extern void m6502_Run(void);
extern void kbdInput ( uint8_t code );
INLINE void set_flags_N( const uint8_t test ) {
m6502.N = BITTEST(test, 7);
}
INLINE void set_flags_V( const uint8_t test ) {
m6502.V = BITTEST(test, 6);
}
INLINE void set_flags_Z( const uint8_t test ) {
m6502.Z = test == 0;
}
INLINE void set_flags_C( const int16_t test ) {
m6502.C = test >= 0;
}
INLINE void set_flags_NZ( const uint8_t test ) {
set_flags_N(test);
set_flags_Z(test);
}
INLINE void set_flags_NV( const uint8_t test ) {
set_flags_N(test);
set_flags_V(test);
}
INLINE void set_flags_NVZ( const uint8_t test ) {
set_flags_NZ(test);
set_flags_V(test);
}
INLINE void set_flags_NZC( const int16_t test ) {
set_flags_NZ(test);
set_flags_C(test);
}
//INLINE void set_flags_NZCV( int test ) {
// set_flags_NZC(test);
// set_flags_V(test);
//}
#endif /* __6502_H__ */

View File

@ -65,6 +65,12 @@ INLINE void RTS() {
dbgPrintf("RTS ");
disPrintf(disassembly.inst, "RTS");
m6502.PC = POP_addr() +1;
// disk accelerator would only work for a certain amount of time
// currently it is 200ms simulated times
if ( m6502.clktime - disk.clk_since_last_read > clk_diskAcceleratorTimeout ) {
clk_6502_per_frm = clk_6502_per_frm_set;
}
}
/**

View File

@ -13,9 +13,12 @@
disk_t disk = {
{ 0, 0, 0 }, // phase
{ 0, 0, 0 }, // phase
0, // clk_since_last_read
};
const unsigned long long clk_6502_per_frm_diskAccelerator = 100 * M / fps; // disk acceleration bumps up CPU clock to 100 MHz
const unsigned long long clk_diskAcceleratorTimeout = 200000ULL;
// motor position from the magnet state
@ -57,6 +60,9 @@ void disk_phase() {
// printf(", p:%d d:%d l:%d: ph:%u trk:%u)", position, direction, lastPosition, phase.count, woz_tmap.phase[phase.count]);
disk.clk_since_last_read = m6502.clktime;
clk_6502_per_frm = clk_6502_per_frm_diskAccelerator;
}
else {
// invalid magnet config
@ -68,6 +74,8 @@ void disk_phase() {
uint8_t disk_read() {
dbgPrintf("io_DISK_READ (S%u)\n", 6);
disk.clk_since_last_read = m6502.clktime;
clk_6502_per_frm = clk_6502_per_frm_diskAccelerator;
return woz_read();
}

View File

@ -26,6 +26,7 @@ typedef struct phase_s {
typedef struct disk_s {
phase_t phase;
uint64_t clk_since_last_read;
} disk_t;
extern disk_t disk;
@ -47,9 +48,11 @@ extern disk_t disk;
extern const int magnet_to_Poistion[16];
extern const int position_to_direction[8][8];
extern const unsigned long long clk_6502_per_frm_diskAccelerator;
extern const unsigned long long clk_diskAcceleratorTimeout;
extern void disk_phase();
extern uint8_t disk_read();
extern void disk_phase(void);
extern uint8_t disk_read(void);
#endif /* disk_h */