mirror of https://github.com/trudnai/Steve2.git
- Speed up disk read
- Less overshot with accelerated disk read - woz_LoadTrack to see where are the sectors - Removed some unused code
This commit is contained in:
parent
19ebe351b5
commit
f2f725b8c5
|
@ -1176,7 +1176,7 @@
|
|||
<scene sceneID="R2V-B0-nI4">
|
||||
<objects>
|
||||
<windowController id="B8D-0N-5wS" sceneMemberID="viewController">
|
||||
<window key="window" title="Apple ][ Emulator" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" animationBehavior="default" id="IQv-IB-iLA">
|
||||
<window key="window" title="Forever ][" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" animationBehavior="default" id="IQv-IB-iLA">
|
||||
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
|
||||
<rect key="contentRect" x="196" y="240" width="1280" height="840"/>
|
||||
<rect key="screenRect" x="0.0" y="0.0" width="1680" height="1027"/>
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include "6502.h"
|
||||
#include "common.h"
|
||||
#include "woz.h"
|
||||
#include "speaker.h"
|
||||
|
||||
|
||||
disk_t disk = {
|
||||
|
@ -17,7 +18,7 @@ disk_t disk = {
|
|||
0, // clk_since_last_read
|
||||
};
|
||||
|
||||
const int diskAccelerator_frames = 2;
|
||||
const int diskAccelerator_frames = 1;
|
||||
int diskAccelerator_count = 0;
|
||||
int diskAccelerator_speed = 25 * M / fps; // if less than actual CPU speed means no acceleration
|
||||
|
||||
|
@ -45,7 +46,8 @@ const int position_to_direction[8][8] = {
|
|||
|
||||
void disk_accelerator_speedup() {
|
||||
if ( diskAccelerator_speed >= clk_6502_per_frm ) {
|
||||
clk_6502_per_frm = diskAccelerator_speed; // clk_6502_per_frm_diskAccelerator;
|
||||
clk_6502_per_frm =
|
||||
clk_6502_per_frm_max = diskAccelerator_speed; // clk_6502_per_frm_diskAccelerator;
|
||||
diskAccelerator_count = diskAccelerator_frames;
|
||||
}
|
||||
}
|
||||
|
@ -66,7 +68,9 @@ void disk_phase() {
|
|||
disk.phase.count = maxDiskPhaseNum;
|
||||
}
|
||||
|
||||
// printf(", p:%d d:%d l:%d: ph:%u trk:%u)", position, direction, lastPosition, phase.count, woz_tmap.phase[phase.count]);
|
||||
spkr_toggle();
|
||||
|
||||
// printf("Head Position: p:%d d:%d l:%d: ph:%u)\n", position, direction, lastPosition, disk.phase.count);
|
||||
|
||||
disk.clk_last_access = m6502.clktime;
|
||||
disk_accelerator_speedup();
|
||||
|
@ -75,7 +79,7 @@ void disk_phase() {
|
|||
// invalid magnet config
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
// printf("\n");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ readState_t readState = readNormal;
|
|||
uint8_t readLatch;
|
||||
|
||||
|
||||
void woz_loadTrack( int track ) {
|
||||
void woz_loadTrack_old( int track ) {
|
||||
trackEntry_t reg = {0};
|
||||
|
||||
reg.shift = woz_trks[track].data[0];
|
||||
|
@ -77,6 +77,125 @@ void woz_loadTrack( int track ) {
|
|||
}
|
||||
|
||||
|
||||
typedef enum wozTrackState_e {
|
||||
wozTrackState_Start = 0,
|
||||
wozTrackState_D5,
|
||||
wozTrackState_D5_AA,
|
||||
wozTrackState_D5_AA_96,
|
||||
wozTrackState_vol1,
|
||||
wozTrackState_vol2,
|
||||
wozTrackState_trk1,
|
||||
wozTrackState_trk2,
|
||||
wozTrackState_sec1,
|
||||
wozTrackState_sec2,
|
||||
} wozTrackState_t;
|
||||
|
||||
|
||||
void woz_loadTrack( int track ) {
|
||||
trackEntry_t reg = {0};
|
||||
wozTrackState_t wozTrackState = wozTrackState_Start;
|
||||
|
||||
reg.shift = 0;
|
||||
reg.data = 0;
|
||||
prepared_track[0] = reg;
|
||||
|
||||
int vol = 0;
|
||||
int trk = 0;
|
||||
int sec = 0;
|
||||
|
||||
int bitOffs_D5_SecHdr = 0; // bit offset of D5 Sector Header
|
||||
|
||||
int bitOffs = 0;
|
||||
|
||||
for ( int byteOffs = 0; byteOffs < WOZ_TRACK_BYTE_COUNT; byteOffs++ ) {
|
||||
|
||||
reg.data = woz_trks[track].data[ byteOffs ];
|
||||
|
||||
for ( int i = 0; i < 8; i++ ) {
|
||||
reg.shift16 <<= 1;
|
||||
|
||||
if (reg.shift & 0x80) {
|
||||
switch (wozTrackState) {
|
||||
case wozTrackState_D5:
|
||||
switch (reg.shift) {
|
||||
case 0xAA:
|
||||
// printf("D5 AA at bitOffset:%d\n", bitOffs);
|
||||
wozTrackState = wozTrackState_D5_AA;
|
||||
break;
|
||||
|
||||
default:
|
||||
wozTrackState = wozTrackState_Start;
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case wozTrackState_D5_AA:
|
||||
switch (reg.shift) {
|
||||
case 0x96:
|
||||
wozTrackState = wozTrackState_vol1;
|
||||
// printf("D5 AA 96 at bitOffset:%d\n", bitOffs);
|
||||
// printf("Sector Header at bitOffset:%d\n", bitOffs_D5_SecHdr);
|
||||
break;
|
||||
|
||||
default:
|
||||
wozTrackState = wozTrackState_Start;
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case wozTrackState_vol1:
|
||||
vol = (reg.shift << 1) | 1;
|
||||
wozTrackState = wozTrackState_vol2;
|
||||
break;
|
||||
|
||||
case wozTrackState_vol2:
|
||||
vol &= reg.shift;
|
||||
wozTrackState = wozTrackState_trk1;
|
||||
break;
|
||||
|
||||
case wozTrackState_trk1:
|
||||
trk = (reg.shift << 1) | 1;
|
||||
wozTrackState = wozTrackState_trk2;
|
||||
break;
|
||||
|
||||
case wozTrackState_trk2:
|
||||
trk &= reg.shift;
|
||||
wozTrackState = wozTrackState_sec1;
|
||||
break;
|
||||
|
||||
case wozTrackState_sec1:
|
||||
sec = (reg.shift << 1) | 1;
|
||||
wozTrackState = wozTrackState_sec2;
|
||||
break;
|
||||
|
||||
case wozTrackState_sec2:
|
||||
sec &= reg.shift;
|
||||
wozTrackState = wozTrackState_Start;
|
||||
|
||||
printf("Vol:%d Track:%d Sector:%d at bitOffset:%d\n", vol, trk, sec, bitOffs_D5_SecHdr);
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
if ( reg.shift == 0xD5 ) {
|
||||
// printf("D5 at bitOffset:%d\n", bitOffs);
|
||||
wozTrackState = wozTrackState_D5;
|
||||
bitOffs_D5_SecHdr = bitOffs;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
reg.shift = 0;
|
||||
}
|
||||
|
||||
bitOffs++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uint8_t woz_read() {
|
||||
|
||||
int track = woz_tmap.phase[disk.phase.count];
|
||||
|
@ -251,20 +370,42 @@ uint8_t woz_read() {
|
|||
|
||||
|
||||
#else // WOZ_REAL_SPIN
|
||||
static int clkBeforeSync = 0;
|
||||
|
||||
clkelpased = m6502.clktime + clkfrm - m6502.clklast;
|
||||
m6502.clklast = m6502.clktime + clkfrm;
|
||||
|
||||
const int clkBeforeAdjusting = 250;
|
||||
clkBeforeSync += clkelpased;
|
||||
|
||||
const int clkBeforeAdjusting = 512;
|
||||
const int magicShiftOffset = 80;
|
||||
|
||||
uint16_t usedBytes = woz_trks[track].bytes_used < WOZ_TRACK_BYTE_COUNT ? woz_trks[track].bytes_used : WOZ_TRACK_BYTE_COUNT;
|
||||
if ( usedBytes ) {
|
||||
if ( clkelpased > clkBeforeAdjusting ) {
|
||||
// printf("NEED SYNC : %llu\n", clkelpased);
|
||||
printf("NEED SYNC : %llu (clkBefRd:%d)\n", clkelpased, clkBeforeSync);
|
||||
clkBeforeSync = 0;
|
||||
bitOffset = (clkelpased >> 2) & 7;
|
||||
trackOffset += ((clkelpased >> 5) + magicShiftOffset) % usedBytes;
|
||||
trackOffset += clkelpased >> 5;
|
||||
trackOffset %= usedBytes;
|
||||
WOZread.data = woz_trks[track].data[trackOffset];
|
||||
|
||||
// preroll data stream
|
||||
WOZread.shift16 = 0;
|
||||
WOZread.data = woz_trks[track].data[trackOffset++];
|
||||
|
||||
WOZread.shift16 <<= bitOffset;
|
||||
|
||||
for ( int i = 0; i < magicShiftOffset; i++ ) {
|
||||
for ( ; bitOffset < 8; bitOffset++ ) {
|
||||
WOZread.shift16 <<= 1;
|
||||
|
||||
if (WOZread.shift & 0x80) {
|
||||
WOZread.shift = 0;
|
||||
}
|
||||
}
|
||||
WOZread.data = woz_trks[track].data[trackOffset++];
|
||||
bitOffset = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// to avoid infinite loop and to search for bit 7 high
|
||||
|
@ -325,7 +466,11 @@ int woz_loadFile( const char * filename ) {
|
|||
|
||||
long r = fread( &woz_chunk_header, 1, sizeof(woz_chunk_header_t), f);
|
||||
if ( r != sizeof(woz_chunk_header_t) ) {
|
||||
return r == 0 ? 0 : WOZ_ERR_BAD_CHUNK_HDR;
|
||||
if ( r ) {
|
||||
return WOZ_ERR_BAD_CHUNK_HDR;
|
||||
}
|
||||
// ok we just reached the end of the file, we should exit properly, close file handle etc
|
||||
break;
|
||||
}
|
||||
long foffs = ftell(f);
|
||||
|
||||
|
@ -362,6 +507,10 @@ int woz_loadFile( const char * filename ) {
|
|||
}
|
||||
|
||||
fclose(f);
|
||||
|
||||
|
||||
// DO NOT COMMIT THIS! ONLY FOR DEBUG!!!
|
||||
// woz_loadTrack(0x11);
|
||||
|
||||
return WOZ_ERR_OK;
|
||||
}
|
||||
|
|
|
@ -953,22 +953,22 @@ INLINE uint8_t memread8_low( uint16_t addr ) {
|
|||
INLINE uint8_t memread8_high( uint16_t addr ) {
|
||||
return RDHIMEM[addr];
|
||||
}
|
||||
INLINE uint8_t memread8( uint16_t addr ) {
|
||||
if (addr >= 0xC000) {
|
||||
return memread8_high(addr);
|
||||
}
|
||||
|
||||
return memread8_low(addr);
|
||||
}
|
||||
//INLINE uint8_t memread8( uint16_t addr ) {
|
||||
// if (addr >= 0xC000) {
|
||||
// return memread8_high(addr);
|
||||
// }
|
||||
//
|
||||
// return memread8_low(addr);
|
||||
//}
|
||||
/**
|
||||
Naive implementation of RAM read from address
|
||||
**/
|
||||
INLINE uint16_t memread16_low( uint16_t addr ) {
|
||||
return * (uint16_t*) ( Apple2_64K_MEM + addr );
|
||||
}
|
||||
INLINE uint16_t memread16_high( uint16_t addr ) {
|
||||
return * (uint16_t*) ( RDHIMEM + addr );
|
||||
}
|
||||
//INLINE uint16_t memread16_high( uint16_t addr ) {
|
||||
// return * (uint16_t*) ( RDHIMEM + addr );
|
||||
//}
|
||||
INLINE uint16_t memread16( uint16_t addr ) {
|
||||
|
||||
// if (addr >= 0xC000) {
|
||||
|
@ -1085,9 +1085,9 @@ INLINE uint16_t fetch16() {
|
|||
}
|
||||
|
||||
|
||||
INLINE uint8_t * dest( uint8_t * mem, uint16_t addr ) {
|
||||
return mem + addr;
|
||||
}
|
||||
//INLINE uint8_t * dest( uint8_t * mem, uint16_t addr ) {
|
||||
// return mem + addr;
|
||||
//}
|
||||
|
||||
|
||||
/**
|
||||
|
@ -1102,9 +1102,9 @@ INLINE uint16_t addr_abs() {
|
|||
INLINE uint8_t src_abs() {
|
||||
return memread( addr_abs() );
|
||||
}
|
||||
INLINE uint8_t * dest_abs() {
|
||||
return WRLOMEM + addr_abs();
|
||||
}
|
||||
//INLINE uint8_t * dest_abs() {
|
||||
// return WRLOMEM + addr_abs();
|
||||
//}
|
||||
|
||||
|
||||
INLINE int8_t rel_addr() {
|
||||
|
@ -1133,9 +1133,9 @@ INLINE uint16_t addr_abs_X() {
|
|||
INLINE uint8_t src_abs_X() {
|
||||
return memread( addr_abs_X() );
|
||||
}
|
||||
INLINE uint8_t * dest_abs_X() {
|
||||
return WRLOMEM + addr_abs_X();
|
||||
}
|
||||
//INLINE uint8_t * dest_abs_X() {
|
||||
// return WRLOMEM + addr_abs_X();
|
||||
//}
|
||||
|
||||
|
||||
/**
|
||||
|
@ -1150,9 +1150,9 @@ INLINE uint16_t addr_abs_Y() {
|
|||
INLINE uint8_t src_abs_Y() {
|
||||
return memread(addr_abs_Y());
|
||||
}
|
||||
INLINE uint8_t * dest_abs_Y() {
|
||||
return WRLOMEM + addr_abs_Y();
|
||||
}
|
||||
//INLINE uint8_t * dest_abs_Y() {
|
||||
// return WRLOMEM + addr_abs_Y();
|
||||
//}
|
||||
|
||||
INLINE uint8_t imm() {
|
||||
disPrintf(disassembly.oper, "#$%02X", memread8(m6502.PC))
|
||||
|
@ -1172,19 +1172,19 @@ INLINE uint8_t addr_zp() {
|
|||
INLINE uint8_t src_zp() {
|
||||
return memread8_low(addr_zp());
|
||||
}
|
||||
INLINE uint8_t * dest_zp() {
|
||||
return WRLOMEM + addr_zp();
|
||||
}
|
||||
//INLINE uint8_t * dest_zp() {
|
||||
// return WRLOMEM + addr_zp();
|
||||
//}
|
||||
|
||||
/**
|
||||
get a 16 bit address from the zp:zp+1
|
||||
**/
|
||||
INLINE uint16_t addr_zp_ind( uint8_t addr ) {
|
||||
dbgPrintf("zpi:%02X:%04X(%02X) ", RAM[m6502.PC], *((uint16_t*)&RAM[m6502.PC]), RAM[*((uint16_t*)&RAM[m6502.PC])]);
|
||||
disPrintf(disassembly.oper, "($%02X)", memread8(m6502.PC) );
|
||||
disPrintf(disassembly.comment, "ind_addr:%04X", memread16( memread8(m6502.PC) ) );
|
||||
return memread16(addr);
|
||||
}
|
||||
//INLINE uint16_t addr_zp_ind( uint8_t addr ) {
|
||||
// dbgPrintf("zpi:%02X:%04X(%02X) ", RAM[m6502.PC], *((uint16_t*)&RAM[m6502.PC]), RAM[*((uint16_t*)&RAM[m6502.PC])]);
|
||||
// disPrintf(disassembly.oper, "($%02X)", memread8(m6502.PC) );
|
||||
// disPrintf(disassembly.comment, "ind_addr:%04X", memread16( memread8(m6502.PC) ) );
|
||||
// return memread16(addr);
|
||||
//}
|
||||
|
||||
/**
|
||||
X,ind .... X-indexed, indirect OPC ($LL,X)
|
||||
|
@ -1200,9 +1200,9 @@ INLINE uint16_t addr_ind_X() {
|
|||
INLINE uint8_t src_X_ind() {
|
||||
return memread( addr_ind_X() );
|
||||
}
|
||||
INLINE uint8_t * dest_X_ind() {
|
||||
return WRLOMEM + addr_ind_X();
|
||||
}
|
||||
//INLINE uint8_t * dest_X_ind() {
|
||||
// return WRLOMEM + addr_ind_X();
|
||||
//}
|
||||
|
||||
/**
|
||||
ind,Y .... indirect, Y-indexed OPC ($LL),Y
|
||||
|
@ -1219,9 +1219,9 @@ INLINE uint16_t addr_ind_Y() {
|
|||
INLINE uint8_t src_ind_Y() {
|
||||
return memread( addr_ind_Y() );
|
||||
}
|
||||
INLINE uint8_t * dest_ind_Y() {
|
||||
return WRLOMEM + addr_ind_Y();
|
||||
}
|
||||
//INLINE uint8_t * dest_ind_Y() {
|
||||
// return WRLOMEM + addr_ind_Y();
|
||||
//}
|
||||
|
||||
/**
|
||||
zpg,X .... zeropage, X-indexed OPC $LL,X
|
||||
|
@ -1235,9 +1235,9 @@ INLINE uint8_t addr_zp_X() {
|
|||
INLINE uint8_t src_zp_X() {
|
||||
return memread8_low(addr_zp_X());
|
||||
}
|
||||
INLINE uint8_t * dest_zp_X() {
|
||||
return WRLOMEM + addr_zp_X();
|
||||
}
|
||||
//INLINE uint8_t * dest_zp_X() {
|
||||
// return WRLOMEM + addr_zp_X();
|
||||
//}
|
||||
|
||||
/**
|
||||
zpg,Y .... zeropage, Y-indexed OPC $LL,Y
|
||||
|
@ -1251,9 +1251,9 @@ INLINE uint8_t addr_zp_Y() {
|
|||
INLINE uint8_t src_zp_Y() {
|
||||
return memread8_low(addr_zp_Y());
|
||||
}
|
||||
INLINE uint8_t * dest_zp_Y() {
|
||||
return WRLOMEM + addr_zp_Y();
|
||||
}
|
||||
//INLINE uint8_t * dest_zp_Y() {
|
||||
// return WRLOMEM + addr_zp_Y();
|
||||
//}
|
||||
|
||||
|
||||
#endif // __APPLE2_MMIO_H__
|
||||
|
|
Loading…
Reference in New Issue