Hertz to MHz

This commit is contained in:
tudnai 2020-06-13 20:13:20 -07:00
parent eea48cb7a0
commit e414e13ad4
8 changed files with 71 additions and 38 deletions

View File

@ -833,8 +833,8 @@ class ViewController: NSViewController {
func setCPUClockSpeed( freq : Double ) {
MHz_6502 = UInt64(freq * M)
clk_6502_per_frm = MHz_6502 / UInt64(fps)
MHz_6502 = freq
clk_6502_per_frm = UInt64( MHz_6502 * M / Double(fps) )
clk_6502_per_frm_set = clk_6502_per_frm
}
@ -848,19 +848,23 @@ class ViewController: NSViewController {
// TODO: Probably this is not the best way to deal with the problem: To make sound continous independent of FPS and Freq
spkr_extra_buf = 780 / fps
// spkr_extra_buf = Int32( 780 / fps )
spkr_extra_buf = 0
switch freq {
case 2.0:
spkr_extra_buf = UInt32( Double(spkr_extra_buf) * 2.961538461538462 ) // normally it should come up as 77, but this way it is calculated with FPS
// spkr_extra_buf = Int32( Double(spkr_extra_buf) * 2.961538461538462 ) // normally it should come up as 77, but this way it is calculated with FPS
spkr_extra_buf = 50
break
case 4.0:
spkr_extra_buf = UInt32( Double(spkr_extra_buf) * 1.346153846153846 ) // normally it should come up as 35, but this way it is calculated with FPS
// spkr_extra_buf = Int32( Double(spkr_extra_buf) * 1.346153846153846 ) // normally it should come up as 35, but this way it is calculated with FPS
spkr_extra_buf = 8
break
default:
spkr_extra_buf = 780 / fps // normally it should come up as 26, but this way it is calculated with FPS
// spkr_extra_buf = Int32( 780 / fps ) // normally it should come up as 26, but this way it is calculated with FPS
spkr_extra_buf = 0
break
}
@ -874,7 +878,7 @@ class ViewController: NSViewController {
@IBAction func SoundGapChanged(_ sender: NSStepper) {
SoundGap.integerValue = sender.integerValue
spkr_extra_buf = UInt32( sender.integerValue )
spkr_extra_buf = Int32( sender.integerValue )
}
@IBAction func Keyboard2JoystickOnOff(_ sender: NSButton) {

View File

@ -21,7 +21,6 @@
#include <string.h>
#include <time.h>
#include "6502.h"
#include "woz.h"
#include "speaker.h"
@ -41,15 +40,16 @@ 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 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 iigs_MHz_6502 = 2.8 * M;
const unsigned long long iicplus_MHz_6502 = 4 * M;
const unsigned long long startup_MHz_6502 = 32 * 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 clk_6502_per_frm_max_sound = 4 * default_MHz_6502 / fps;
unsigned int fps = DEFAULT_FPS;
const double default_MHz_6502 = 1.023; // 2 * M; // 4 * M; // 8 * M; // 16 * M; // 128 * M; // 256 * M; // 512 * M;
const double iigs_MHz_6502 = 2.8;
const double iicplus_MHz_6502 = 4;
const double startup_MHz_6502 = 32;
double MHz_6502 = default_MHz_6502;
unsigned long long clk_6502_per_frm = FRAME_INIT( default_MHz_6502 );
unsigned long long clk_6502_per_frm_set = FRAME_INIT( default_MHz_6502 );
unsigned long long clk_6502_per_frm_max_sound = 4 * FRAME_INIT( default_MHz_6502 );
unsigned long long clk_6502_per_frm_max = 0;
@ -673,11 +673,9 @@ void rom_loadFile( const char * bundlePath, const char * filename ) {
void m6502_ColdReset( const char * bundlePath, const char * romFileName ) {
inst_cnt = 0;
mhz = (double)MHz_6502 / M;
spkr_init();
unsigned long long saved_frm_set = clk_6502_per_frm_set;
clk_6502_per_frm =
clk_6502_per_frm_max =
clk_6502_per_frm_set = 0;
@ -842,7 +840,7 @@ void m6502_ColdReset( const char * bundlePath, const char * romFileName ) {
// set the default speed
clk_6502_per_frm_set = clk_6502_per_frm = default_MHz_6502 / fps;
clk_6502_per_frm_set = clk_6502_per_frm = FRAME(default_MHz_6502);
// Initialize Paddle / Game Controller / Joystick / Mouse Buttons

View File

@ -14,10 +14,10 @@
#include "woz.h"
extern const unsigned long long default_MHz_6502;
extern const unsigned long long iigs_MHz_6502;
extern const unsigned long long iicplus_MHz_6502;
extern unsigned long long MHz_6502;
extern const double default_MHz_6502;
extern const double iigs_MHz_6502;
extern const double iicplus_MHz_6502;
extern double 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;
@ -160,7 +160,8 @@ extern double * pdl_diffarr;
extern double mips;
extern double mhz;
#define fps 30U
#define DEFAULT_FPS 30U
extern unsigned int fps;
extern void rom_loadFile( const char * bundlePath, const char * filename );
extern void tst6502(void);

View File

@ -74,17 +74,17 @@ ALuint spkr_disk_arm_buf = 0;
ALuint spkr_disk_ioerr_buf = 0;
const int spkr_fps = fps;
const int spkr_fps = 30;
const int spkr_seconds = 1;
const unsigned spkr_sample_rate = 44100;
const unsigned sfx_sample_rate = 22050; // original sample rate
//const unsigned sfx_sample_rate = 26000; // bit higher pitch
unsigned spkr_extra_buf = 800 / spkr_fps;
int spkr_extra_buf = 0; // 800 / spkr_fps;
const unsigned spkr_buf_size = spkr_seconds * spkr_sample_rate * 2 / spkr_fps;
int16_t spkr_samples [ spkr_buf_size * spkr_fps * BUFFER_COUNT * 2]; // stereo
unsigned spkr_sample_idx = 0;
const unsigned spkr_play_timeout = 8; // increase to 32 for 240 fps
const unsigned spkr_play_timeout = 8; // increase to 32 for 240 fps, normally 8 for 30 fps
unsigned spkr_play_time = 0;
unsigned spkr_play_disk_motor_time = 0;
unsigned spkr_play_disk_arm_time = 0;
@ -273,7 +273,7 @@ void spkr_toggle() {
// push a click into the speaker buffer
// (we will play the entire buffer at the end of the frame)
spkr_sample_idx = (clkfrm / (default_MHz_6502 / spkr_sample_rate)) * 2;
spkr_sample_idx = (clkfrm / ( MHZ(default_MHz_6502) / spkr_sample_rate)) * 2;
if ( spkr_state ) {
// down edge
@ -498,20 +498,20 @@ void spkr_stop_sfx( ALuint src ) {
void spkr_play_disk_motor() {
if ( ( disk_sfx_enabled ) && ( clk_6502_per_frm <= iicplus_MHz_6502 / fps ) ) {
if ( ( disk_sfx_enabled ) && ( clk_6502_per_frm <= FRAME(iicplus_MHz_6502) ) ) {
spkr_play_sfx( spkr_src[SPKR_SRC_DISK_MOTOR_SFX], diskmotor_sfx, diskmotor_sfx_len );
}
}
void spkr_stop_disk_motor( int time ) {
if ( ( disk_sfx_enabled ) && ( clk_6502_per_frm <= iicplus_MHz_6502 / fps ) ) {
if ( ( disk_sfx_enabled ) && ( clk_6502_per_frm <= FRAME(iicplus_MHz_6502) ) ) {
spkr_play_disk_motor_time = time;
}
}
void spkr_play_disk_arm() {
if ( ( disk_sfx_enabled ) && ( clk_6502_per_frm <= iicplus_MHz_6502 / fps ) ) {
if ( ( disk_sfx_enabled ) && ( clk_6502_per_frm <= FRAME(iicplus_MHz_6502) ) ) {
if ( spkr_play_disk_ioerr_time == 0 ) {
spkr_play_sfx( spkr_src[SPKR_SRC_DISK_ARM_SFX], diskarm_sfx, diskarm_sfx_len );
spkr_play_disk_arm_time = 2;
@ -521,7 +521,7 @@ void spkr_play_disk_arm() {
void spkr_play_disk_ioerr() {
if ( ( disk_sfx_enabled ) && ( clk_6502_per_frm <= iicplus_MHz_6502 / fps ) ) {
if ( ( disk_sfx_enabled ) && ( clk_6502_per_frm <= FRAME(iicplus_MHz_6502) ) ) {
spkr_playqueue_sfx( spkr_src[SPKR_SRC_DISK_IOERR_SFX], diskioerr_sfx, diskioerr_sfx_len);
spkr_play_disk_ioerr_time = 4;
}
@ -538,7 +538,7 @@ void update_disk_sfx( unsigned * time, ALuint src ) {
void spkr_update_disk_sfx() {
// is user speeds up the machine, disk sfx needs to be stopped
if ( ( ! disk_sfx_enabled ) || ( clk_6502_per_frm > iicplus_MHz_6502 / fps ) ) {
if ( ( ! disk_sfx_enabled ) || ( clk_6502_per_frm > FRAME(iicplus_MHz_6502) ) ) {
if ( spkr_play_disk_motor_time ) {
spkr_play_disk_motor_time = 1; // rest will be taken care below
}

View File

@ -39,7 +39,7 @@ extern int16_t spkr_samples [];
extern unsigned spkr_sample_idx;
extern int spkr_level;
extern int freeBuffers;
extern unsigned spkr_extra_buf;
extern int spkr_extra_buf;
extern const unsigned spkr_play_timeout;
extern unsigned spkr_play_time;

View File

@ -20,7 +20,7 @@ disk_t disk = {
const int diskAccelerator_frames = 2;
int diskAccelerator_count = 0;
int diskAccelerator_speed = 25 * M / fps; // if less than actual CPU speed means no acceleration
int diskAccelerator_speed = 25; // if less than actual CPU speed means no acceleration
int diskAccelerator_enabled = 0;
int disk_sfx_enabled = 1;
@ -69,9 +69,9 @@ const uint8_t log2phy_cpm[16] = {
void disk_accelerator_speedup() {
if ( ( diskAccelerator_enabled ) && ( diskAccelerator_speed >= clk_6502_per_frm ) ) {
if ( ( diskAccelerator_enabled ) && ( FRAME(diskAccelerator_speed) >= clk_6502_per_frm ) ) {
clk_6502_per_frm =
clk_6502_per_frm_max = diskAccelerator_speed; // clk_6502_per_frm_diskAccelerator;
clk_6502_per_frm_max = FRAME(diskAccelerator_speed); // clk_6502_per_frm_diskAccelerator;
diskAccelerator_count = diskAccelerator_frames;
}
}

View File

@ -915,6 +915,30 @@ INLINE void ioWrite( uint16_t addr, uint8_t val ) {
textPageSelect();
break;
case (uint8_t)io_VID_Text_OFF:
videoMode.text = 0;
break;
case (uint8_t)io_VID_Text_ON:
videoMode.text = 1;
break;
case (uint8_t)io_VID_Mixed_OFF:
videoMode.mixed = 0;
break;
case (uint8_t)io_VID_Mixed_ON:
videoMode.mixed = 1;
break;
case (uint8_t)io_VID_Hires_OFF:
videoMode.hires = 0;
break;
case (uint8_t)io_VID_Hires_ON:
videoMode.hires = 1;
break;
case (uint8_t)io_MEM_RDRAM_NOWR_2:
case (uint8_t)io_MEM_RDROM_WRAM_2:
case (uint8_t)io_MEM_RDROM_NOWR_2:

View File

@ -42,6 +42,12 @@
#define TB (GB * KB)
// calculates number of cycles in one frame
#define MHZ(mhz) ( (mhz) * M )
#define FRAME(mhz) ( MHZ(mhz) / fps )
#define FRAME_INIT(mhz) ( MHZ(mhz) / DEFAULT_FPS )
typedef
union {
uint8_t bits;