Speed bump (2x)

- Precise MHz measurements
This commit is contained in:
tudnai 2020-04-29 15:35:54 -07:00
parent deb6373f18
commit f56a2cb8c6
9 changed files with 91 additions and 90 deletions

View File

@ -1216,9 +1216,9 @@
"@executable_path/../Frameworks",
);
OTHER_CFLAGS = (
"-DDISASSEMBLER",
"-DINTERRUPT_CHECK_PER_STEP",
"-DCLK_ABSOLUTE_PRECISE",
"-D_NO_DISASSEMBLER",
"-D_NO_INTERRUPT_CHECK_PER_STEP",
"-D_NO_CLK_ABSOLUTE_PRECISE",
);
OTHER_SWIFT_FLAGS = "-DHIRES -DMETAL_NO -DHIRESDRAW -D_NO_HIRESLOW -DHIRESLOWCOLOR";
PRODUCT_BUNDLE_IDENTIFIER = com.gamealloy.A2Mac;
@ -1252,9 +1252,9 @@
"@executable_path/../Frameworks",
);
OTHER_CFLAGS = (
"-DDISASSEMBLER",
"-DINTERRUPT_CHECK_PER_STEP",
"-DCLK_ABSOLUTE_PRECISE",
"-D_NO_DISASSEMBLER",
"-D_NO_INTERRUPT_CHECK_PER_STEP",
"-D_NO_CLK_ABSOLUTE_PRECISE",
);
OTHER_SWIFT_FLAGS = "-DHIRES -DMETAL_NO -DHIRESDRAW -D_NO_HIRESLOW -DHIRESLOWCOLOR";
PRODUCT_BUNDLE_IDENTIFIER = com.gamealloy.A2Mac;

View File

@ -970,8 +970,8 @@
</connections>
</button>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="umb-DW-vGc">
<rect key="frame" x="-1" y="-1" width="47" height="18"/>
<buttonCell key="cell" type="radio" title="666" bezelStyle="regularSquare" imagePosition="left" alignment="left" refusesFirstResponder="YES" inset="2" id="8VU-4B-7Pe">
<rect key="frame" x="-1" y="-1" width="51" height="18"/>
<buttonCell key="cell" type="radio" title="MAX" bezelStyle="regularSquare" imagePosition="left" alignment="left" refusesFirstResponder="YES" inset="2" id="8VU-4B-7Pe">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>

View File

@ -368,13 +368,24 @@ class ViewController: NSViewController {
var was = 0;
var currentVideoMode = videoMode
var lastFrameTime = CACurrentMediaTime() as Double
var frameCounter : UInt = 0
var clkCounter : Double = 0
func Update() {
clk_6502_per_frm_max = 0
clkCounter += Double(clkfrm)
#if SPEEDTEST
#else
m6502_Run()
#endif
frameCounter += 1
if ( frameCounter % UInt(fps) == 0 ) {
let currentTime = CACurrentMediaTime() as Double
let elpasedTime = currentTime - lastFrameTime
lastFrameTime = currentTime
mhz = Double( clkCounter ) / (elpasedTime * M);
clkCounter = 0
}
// render()
// hires.compute()
@ -468,12 +479,15 @@ class ViewController: NSViewController {
self.display.stringValue = txt
// self.display.stringValue = "testing\nit\nout"
if ( (mhz < 10) && (mhz != floor(mhz)) ) {
if ( (mhz < 1.5) && (mhz != floor(mhz)) ) {
self.speedometer.stringValue = String(format: "%0.3lf MHz", mhz);
}
else {
self.speedometer.stringValue = String(format: "%.0lf MHz", mhz);
self.speedometer.stringValue = String(format: "%0.1lf MHz", mhz);
}
// else {
// self.speedometer.stringValue = String(format: "%.0lf MHz", mhz);
// }
#if HIRES
// if ( self.was < 300 ) {
@ -492,6 +506,13 @@ class ViewController: NSViewController {
// }
#endif
}
#if SPEEDTEST
#else
m6502_Run()
#endif
}
@ -588,15 +609,14 @@ class ViewController: NSViewController {
func setCPUClockSpeed( freq : Double ) {
mhz = freq
MHz_6502 = UInt64(mhz * M)
MHz_6502 = UInt64(freq * M)
clk_6502_per_frm = MHz_6502 / UInt64(fps)
clk_6502_per_frm_set = clk_6502_per_frm
}
@IBAction func speedSelected(_ sender: NSButton) {
if ( sender.title == "Max" ) {
clk_6502_per_frm = UINT64_MAX
if ( sender.title == "MAX" ) {
setCPUClockSpeed(freq: 9999)
}
else if let freq = Double( sender.title ) {
setCPUClockSpeed(freq: freq)

View File

@ -35,9 +35,11 @@ unsigned long long int inst_cnt = 0;
//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;
const unsigned long long startup_MHz_6502 = 25 * M;
unsigned long long MHz_6502 = default_MHz_6502;
unsigned long long clk_6502_per_frm = 25 * M; //default_MHz_6502 / fps;
unsigned long long clk_6502_per_frm = startup_MHz_6502 / fps;
unsigned long long clk_6502_per_frm_set = default_MHz_6502 / fps;
unsigned long long clk_6502_per_frm_max = default_MHz_6502 / fps;
unsigned long long tick_per_sec = G;
@ -547,35 +549,35 @@ INLINE int m6502_Step() {
case 0x7E: ROR( dest_abs_X() ); return 7; // ROR abs,X
// case 0x7F:
// case 0x80:
case 0x81: STA( dest_X_ind() ) ; return 6; // STA X,ind
case 0x81: STA( addr_X_ind() ) ; return 6; // STA X,ind
// case 0x82:
// case 0x83:
case 0x84: STY( dest_zp() ); return 3; // STY zpg
case 0x85: STA( dest_zp() ); return 3; // STA zpg
case 0x86: STX( dest_zp() ); return 3; // STX zpg
case 0x84: STY( addr_zp() ); return 3; // STY zpg
case 0x85: STA( addr_zp() ); return 3; // STA zpg
case 0x86: STX( addr_zp() ); return 3; // STX zpg
// case 0x87:
case 0x88: DEY(); return 2; // DEY
// case 0x89: NOP(); imm(); return 4; // NOP imm
case 0x8A: TXA(); return 2; // TXA
// case 0x8B:
case 0x8C: STY( dest_abs() ); return 4; // STY abs
case 0x8D: STA( dest_abs() ); return 4; // STA abs
case 0x8E: STX( dest_abs() ); return 4; // STX abs
case 0x8C: STY( addr_abs() ); return 4; // STY abs
case 0x8D: STA( addr_abs() ); return 4; // STA abs
case 0x8E: STX( addr_abs() ); return 4; // STX abs
// case 0x8F:
case 0x90: BCC( rel_addr() ); return 2; // BCC rel
case 0x91: STA( dest_ind_Y() ); return 6; // STA ind,Y
case 0x91: STA( addr_ind_Y() ); return 6; // STA ind,Y
// case 0x92:
// case 0x93:
case 0x94: STY( dest_zp_X() ); return 4; // STY zpg,X
case 0x95: STA( dest_zp_X() ); return 4; // STA zpg,X
case 0x96: STX( dest_zp_Y() ); return 4; // STX zpg,Y
case 0x94: STY( addr_zp_X() ); return 4; // STY zpg,X
case 0x95: STA( addr_zp_X() ); return 4; // STA zpg,X
case 0x96: STX( addr_zp_Y() ); return 4; // STX zpg,Y
// case 0x97:
case 0x98: TYA(); return 2; // TYA
case 0x99: STA( dest_abs_Y() ); return 5; // STA abs,Y
case 0x99: STA( addr_abs_Y() ); return 5; // STA abs,Y
case 0x9A: TXS(); return 2; // TXS
// case 0x9B:
// case 0x9C:
case 0x9D: STA( dest_abs_X() ); return 5; // STA abs,X
case 0x9D: STA( addr_abs_X() ); return 5; // STA abs,X
// case 0x9E:
// case 0x9F:
case 0xA0: LDY( imm() ); return 2; // LDY imm
@ -694,19 +696,24 @@ double mips = 0;
double mhz = 0;
unsigned long long epoch = 0;
unsigned int clkfrm = 0;
void m6502_Run() {
static unsigned int clk = 0;
static unsigned int clkfrm = 0;
// init time
//#ifdef CLK_WAIT
// unsigned long long elpased = (unsigned long long)-1LL;
//#endif
// we will also use this to pause the simulation if not finished by the end of the frame
clk_6502_per_frm_max = clk_6502_per_frm;
#ifdef SPEEDTEST
for ( inst_cnt = 0; inst_cnt < iterations ; inst_cnt++ )
#elif defined( CLK_WAIT )
for ( clkfrm = 0; clkfrm < clk_6502_per_frm ; clkfrm += clk )
for ( clkfrm = 0; clkfrm < clk_6502_per_frm_max ; clkfrm += clk )
#else
// for ( ; m6502.pc ; )
for ( ; ; )

View File

@ -16,6 +16,8 @@
extern unsigned long long MHz_6502;
extern unsigned long long clk_6502_per_frm;
extern unsigned long long clk_6502_per_frm_set;
extern unsigned long long clk_6502_per_frm_max;
extern unsigned int clkfrm;
typedef enum {
@ -135,7 +137,7 @@ extern void hires_Update(void);
extern double mips;
extern double mhz;
#define fps 30
#define fps 30U
extern void rom_loadFile( const char * bundlePath, const char * filename );
extern void woz_loadFile( const char * bundlePath, const char * filename );

View File

@ -90,51 +90,17 @@ char * charConv =
(not a real instruction, only a helper function)
**/
INLINE void STR( uint8_t * dst, uint8_t src ) {
dbgPrintf("STR [%04X], %02X ", (int)(dst - RAM), src );
uint16_t addr = dst - RAM;
INLINE void STR( uint16_t addr, uint8_t src ) {
dbgPrintf("STR [%04X], %02X ", addr, src );
// I/O or ROM or RAM EXP
if ( addr >= 0xC000 ) {
// ROM or RAM EXP
if ( addr >= 0xD000 ) {
uint8_t * pgaddr;
// DO NOT MAKE IT NICER! faster this way!
if ( (pgaddr = RAM_PG_WR_TBL[ addr >> 8 ]) ) {
dst = pgaddr + (addr & 0xFF);
}
else {
// NULL page table, so no need to do anything
return;
}
}
// I/O
else {
// printf("mmio write:[%04X] = %02X\n", addr, src);
// dst = Apple2_Dummy_Page;
ioWrite( addr, src );
return;
}
if ( ( addr >= 0xC000 ) && ( addr < 0xC100 ) ) {
return ioWrite( addr, src );
}
// else if ( ( addr >= 0x400 ) && ( addr < 0x800 ) ) {
// // Peripheral-card scratchpad RAM locations should be available on both memory
// if ( ( ( addr >= 0x478 ) && ( addr <= 0x47F ) )
// || ( ( addr >= 0x4F8 ) && ( addr <= 0x4FF ) )
// || ( ( addr >= 0x578 ) && ( addr <= 0x57F ) )
// || ( ( addr >= 0x5F8 ) && ( addr <= 0x5FF ) )
// || ( ( addr >= 0x678 ) && ( addr <= 0x67F ) )
// || ( ( addr >= 0x6F8 ) && ( addr <= 0x6FF ) )
// || ( ( addr >= 0x778 ) && ( addr <= 0x77F ) )
// || ( ( addr >= 0x7F8 ) && ( addr <= 0x7FF ) )
// ) {
// AUX_VID_RAM[ addr - 0x400 ] = src;
// }
// }
*dst = src;
// DO NOT MAKE IT NICER! faster this way!
*(RAM_PG_WR_TBL[ addr >> 8 ] + (addr & 0xFF)) = src;
// RAM[addr] = src;
}
/**
@ -153,10 +119,10 @@ INLINE void STR( uint8_t * dst, uint8_t src ) {
(indirect,X) STA (oper,X) 81 2 6
(indirect),Y STA (oper),Y 91 2 6
**/
INLINE void STA( uint8_t * dst ) {
INLINE void STA( uint16_t addr ) {
dbgPrintf("STA ");
disPrintf(disassembly.inst, "STA");
STR(dst, m6502.A);
STR(addr, m6502.A);
}
/**
@ -171,10 +137,10 @@ INLINE void STA( uint8_t * dst ) {
zeropage,Y STX oper,Y 96 2 4
absolute STX oper 8E 3 4
**/
INLINE void STX( uint8_t * dst ) {
INLINE void STX( uint16_t addr ) {
dbgPrintf("STX ");
disPrintf(disassembly.inst, "STX");
STR(dst, m6502.X);
STR(addr, m6502.X);
}
/**
@ -189,10 +155,10 @@ INLINE void STX( uint8_t * dst ) {
zeropage,X STY oper,X 94 2 4
absolute STY oper 8C 3 4
**/
INLINE void STY( uint8_t * dst ) {
INLINE void STY( uint16_t addr ) {
dbgPrintf("STY ");
disPrintf(disassembly.inst, "STY");
STR(dst, m6502.Y);
STR(addr, m6502.Y);
}
#endif // __6502_INSTR_LOAD_STORE_H__

View File

@ -13,13 +13,17 @@ static const uint16_t stack_base_addr = 0x100;
INLINE void PUSH( uint8_t src ) {
RAM[ stack_base_addr | m6502.SP-- ] = src;
// RAM[ stack_base_addr | m6502.SP-- ] = src;
// DO NOT MAKE IT NICER! faster this way!
*( RAM_PG_WR_TBL[ stack_base_addr >> 8 ] + m6502.SP-- ) = src;
}
INLINE uint8_t POP() {
return RAM[ stack_base_addr | ++m6502.SP ];
// return RAM[ stack_base_addr | ++m6502.SP ];
return *( RAM_PG_WR_TBL[ stack_base_addr >> 8 ] + ++m6502.SP );
}
INLINE void PUSH_addr( uint16_t addr ) {
PUSH( (uint8_t)(addr >> 8) );
PUSH( (uint8_t)addr );

View File

@ -437,7 +437,7 @@ void auxMemorySelect() {
INLINE uint8_t ioRead( uint16_t addr ) {
if (outdev) fprintf(outdev, "ioRead:%04X\n", addr);
// if (outdev) fprintf(outdev, "ioRead:%04X\n", addr);
uint8_t currentMagnet = 0;
@ -677,7 +677,7 @@ INLINE uint8_t ioRead( uint16_t addr ) {
return RAM[addr];
}
// TODO:
void setIO ( uint16_t ioaddr, uint8_t val ) {
RAM[ioaddr] = val;
}
@ -710,7 +710,7 @@ void kbdInput ( uint8_t code ) {
INLINE void ioWrite( uint16_t addr, uint8_t val ) {
if (outdev) fprintf(outdev, "ioWrite:%04X (A:%02X)\n", addr, m6502.A);
// if (outdev) fprintf(outdev, "ioWrite:%04X (A:%02X)\n", addr, m6502.A);
switch (addr) {
case io_KBDSTRB:
RAM[io_KBD] &= 0x7F;
@ -834,14 +834,14 @@ INLINE void ioWrite( uint16_t addr, uint8_t val ) {
**/
INLINE uint8_t memread8( uint16_t addr ) {
return * ( RAM_PG_RD_TBL[addr >> 8] + (addr & 0xFF) );
// return RAM[ addr ];
// return RAM[addr];
}
/**
Naive implementation of RAM read from address
**/
INLINE uint16_t memread16( uint16_t addr ) {
return * (uint16_t*) ( RAM_PG_RD_TBL[addr >> 8] + (addr & 0xFF) );
// return * (uint16_t*) (& RAM[ addr ]);
// return * (uint16_t*) (RAM + addr);
}
INLINE uint8_t memread( uint16_t addr ) {
@ -890,7 +890,7 @@ static void memwrite( uint16_t addr, uint8_t byte ) {
increase pc by one
**/
INLINE uint8_t fetch() {
disHexB( disassembly.pOpcode, RAM[m6502.PC] );
disHexB( disassembly.pOpcode, memread(m6502.PC) );
#ifdef CLK_ABSOLUTE_PRECISE
if ( (m6502.PC & 0xFF) >= 0xFF ) {
m6502.clktime++;

View File

@ -59,6 +59,8 @@ union {
#define BITTEST(n,x) ((bits_t)(n)).b##x
//#define BITTEST(n,x) ( (n) >> (x) )
//#define BITTEST(n,x) ( (n) & (1 << (x)) )
extern FILE * outdev;