mirror of
https://github.com/st3fan/ewm.git
synced 2024-05-29 08:41:28 +00:00
Fixes #110 Make cpu_test also print out the emulated cpu speed
This commit is contained in:
parent
4b8df8f151
commit
fee8efce69
|
@ -20,9 +20,12 @@
|
||||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
|
|
||||||
|
#include <inttypes.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
#include "cpu.h"
|
#include "cpu.h"
|
||||||
#include "mem.h"
|
#include "mem.h"
|
||||||
|
@ -36,6 +39,12 @@ int test(int model, uint16_t start_addr, uint16_t success_addr, char *rom_path)
|
||||||
|
|
||||||
uint16_t last_pc = cpu.state.pc;
|
uint16_t last_pc = cpu.state.pc;
|
||||||
|
|
||||||
|
struct timespec start;
|
||||||
|
if (clock_gettime(CLOCK_REALTIME, &start) != 0) {
|
||||||
|
perror("Cannot get time");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
int ret = cpu_step(&cpu);
|
int ret = cpu_step(&cpu);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
|
@ -54,7 +63,23 @@ int test(int model, uint16_t start_addr, uint16_t success_addr, char *rom_path)
|
||||||
// ideal. Is there a better way to detect this?
|
// ideal. Is there a better way to detect this?
|
||||||
|
|
||||||
if (cpu.state.pc == success_addr) {
|
if (cpu.state.pc == success_addr) {
|
||||||
fprintf(stderr, "TEST Success\n");
|
struct timespec now;
|
||||||
|
if (clock_gettime(CLOCK_REALTIME, &now) != 0) {
|
||||||
|
perror("Cannot get time");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Taking a shortcut here because our test will never run so
|
||||||
|
// long that it will overflow an uint64_t
|
||||||
|
|
||||||
|
uint64_t duration_ms = (now.tv_sec * 1000 + (now.tv_nsec / 1000000))
|
||||||
|
- (start.tv_sec * 1000 + (start.tv_nsec / 1000000));
|
||||||
|
double duration = (double) duration_ms / 1000.0;
|
||||||
|
double mhz = (double) cpu.counter * (1.0 / duration) / 1000000.0;
|
||||||
|
|
||||||
|
fprintf(stderr, "TEST Success; executed %" PRIu64 " cycles in %.4f at %.4f MHz\n",
|
||||||
|
cpu.counter, duration, mhz);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user