- [NEW] Frequència del Z80 configurable

This commit is contained in:
2024-12-20 11:24:58 +01:00
parent 4a0e2b3b7d
commit fe36a970c2
5 changed files with 23 additions and 5 deletions

View File

@@ -72,7 +72,10 @@ namespace actions
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
const uint32_t clock = 3500000;
const uint32_t update_freq = clock / 10;
new zx_48mem(); new zx_48mem();
z80dis::loadSymbols(); z80dis::loadSymbols();
@@ -223,7 +226,7 @@ int main(int argc, char *argv[])
} }
} }
if (t_states>=350000) if (t_states>=update_freq)
{ {
//if (SDL_GetTicks()>=time+1000) //if (SDL_GetTicks()>=time+1000)
//printf("%i\n", SDL_GetTicks()-(time+1000)); //printf("%i\n", SDL_GetTicks()-(time+1000));
@@ -232,7 +235,7 @@ int main(int argc, char *argv[])
//t_states = 0; //t_states = 0;
//printf("%i: %i\n", SDL_GetTicks()-(time+1000), t_states); //printf("%i: %i\n", SDL_GetTicks()-(time+1000), t_states);
while (SDL_GetTicks()<time+100) {} while (SDL_GetTicks()<time+100) {}
t_states -= 350000; t_states -= update_freq;
time = SDL_GetTicks(); time = SDL_GetTicks();
z80analyze::refresh(); z80analyze::refresh();
} }

11
z80.cpp
View File

@@ -9,6 +9,7 @@ namespace z80
//static uint8_t *memory = nullptr; //static uint8_t *memory = nullptr;
//static uint8_t memtag[65536]; //static uint8_t memtag[65536];
//static uint8_t memtouched[65536]; //static uint8_t memtouched[65536];
static uint32_t clock = 3500000;
static uint32_t t = 0; static uint32_t t = 0;
static uint16_t current_opcode_address = 0; static uint16_t current_opcode_address = 0;
bool options[Z80_NUM_OPTIONS] = { true, false }; bool options[Z80_NUM_OPTIONS] = { true, false };
@@ -1130,6 +1131,16 @@ namespace z80
} }
} }
void setClock(uint32_t freq)
{
clock = freq;
}
uint32_t getClock()
{
return clock;
}
void BIT_INSTRUCTIONS(); void BIT_INSTRUCTIONS();
void IX_INSTRUCTIONS(); void IX_INSTRUCTIONS();
void IX_BIT_INSTRUCTIONS(); void IX_BIT_INSTRUCTIONS();

2
z80.h
View File

@@ -10,6 +10,8 @@ namespace z80
#define Z80_NUM_OPTIONS 3 #define Z80_NUM_OPTIONS 3
void reset(); void reset();
void setClock(uint32_t freq);
uint32_t getClock();
//void reset(uint8_t* mem); //void reset(uint8_t* mem);
void connect_port(int num, int (*in_ptr)(int), void (*out_ptr)(int,int)); void connect_port(int num, int (*in_ptr)(int), void (*out_ptr)(int,int));

View File

@@ -2,6 +2,7 @@
#include "zx_ula.h" #include "zx_ula.h"
#include "zx_screen.h" #include "zx_screen.h"
#include "z80debug.h" #include "z80debug.h"
#include "z80.h"
#include <vector> #include <vector>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@@ -209,7 +210,7 @@ namespace zx_tape
if (current_section == PULSE_WAIT) if (current_section == PULSE_WAIT)
{ {
pulse_level = 0; pulse_level = 0;
if (pulse_pos >= 3500000) if (pulse_pos >= z80::getClock())
{ {
pulse_pos = 0; pulse_pos = 0;
current_section = PULSE_PILOT; current_section = PULSE_PILOT;

View File

@@ -1,4 +1,5 @@
#include "zx_ula.h" #include "zx_ula.h"
#include <z80.h>
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
#define AUDIO_BUFFER_SIZE 2048 #define AUDIO_BUFFER_SIZE 2048
@@ -292,7 +293,7 @@ namespace zx_ula
if (t_sound>=317) { if (t_sound>=317) {
t_sound-=317; t_sound-=317;
samples_generated++; samples_generated++;
if (samples_t >=3500000) { if (samples_t >=z80::getClock()) {
//printf("%i\n", samples_generated); //printf("%i\n", samples_generated);
samples_generated=0; samples_generated=0;
samples_t = 0; samples_t = 0;