@ -56,7 +56,7 @@ struct Display {
void update ( Chip8 & vm ) {
void update ( Chip8 & vm ) {
handle_inputs ( vm ) ;
handle_inputs ( vm ) ;
texture . update ( ( uint8_t * ) ( vm . video ) ) ;
texture . update ( ( uint8_t * ) ( vm . video ) , { 64 , 32 } , { 0 , 0 } ) ;
}
}
void render ( ) {
void render ( ) {
@ -70,7 +70,6 @@ struct Display {
}
}
} ;
} ;
int main ( int argc , char * argv [ ] ) {
int main ( int argc , char * argv [ ] ) {
if ( argc ! = 4 ) {
if ( argc ! = 4 ) {
fmt : : print ( " ERROR! " ) ;
fmt : : print ( " ERROR! " ) ;
@ -78,18 +77,17 @@ int main(int argc, char* argv[]) {
}
}
int videoScale = std : : stoi ( argv [ 1 ] ) ;
int videoScale = std : : stoi ( argv [ 1 ] ) ;
int cycleDelay = std : : stoi ( argv [ 2 ] ) ;
int framerate = std : : stoi ( argv [ 2 ] ) ;
std : : string romFilename { argv [ 3 ] } ;
std : : string romFilename { argv [ 3 ] } ;
Chip8 chip8 ;
Chip8 chip8 ;
chip8 . LoadROM ( romFilename ) ;
chip8 . LoadROM ( romFilename ) ;
int videoPitch = sizeof ( chip8 . video [ 0 ] ) * VIDEO_WIDTH ;
int videoPitch = sizeof ( chip8 . video [ 0 ] ) * VIDEO_WIDTH ;
auto lastCycleTime = std : : chrono : : high_resolution_clock : : now ( ) ;
sf : : RenderWindow window { sf : : VideoMode ( { 1280 , 720 } ) , " Chip8 Emulator " } ;
sf : : RenderWindow window { sf : : VideoMode ( { 1280 , 720 } ) , " Chip8 Emulator " } ;
window . setFramerateLimit ( 60 ) ;
window . setFramerateLimit ( framerate ) ;
window . setVerticalSyncEnabled ( tru e) ;
window . setVerticalSyncEnabled ( fals e) ;
Display display { window , { 0 , 0 } , { 1000 , 1000 } } ;
Display display { window , { 0 , 0 } , { 1000 , 1000 } } ;
Stats cycle_stats ;
Stats cycle_stats ;
@ -97,16 +95,9 @@ int main(int argc, char* argv[]) {
Stats update_stats ;
Stats update_stats ;
while ( display . active ( ) ) {
while ( display . active ( ) ) {
auto currentTime = std : : chrono : : high_resolution_clock : : now ( ) ;
auto t = cycle_stats . time_start ( ) ;
float dt = std : : chrono : : duration < float , std : : chrono : : milliseconds : : period > ( currentTime - lastCycleTime ) . count ( ) ;
chip8 . Cycle ( ) ;
cycle_stats . sample_time ( t ) ;
if ( dt > cycleDelay )
{
lastCycleTime = currentTime ;
auto t = cycle_stats . time_start ( ) ;
chip8 . Cycle ( ) ;
cycle_stats . sample_time ( t ) ;
}
auto ut = update_stats . time_start ( ) ;
auto ut = update_stats . time_start ( ) ;
display . update ( chip8 ) ;
display . update ( chip8 ) ;