mirror of
https://github.com/st3fan/ewm.git
synced 2025-01-14 06:30:51 +00:00
Merge branch 'master' into Issue135BenchmarkMemoryModule
This commit is contained in:
commit
640bfd5289
13
README.md
13
README.md
@ -52,16 +52,3 @@ Here are some of the things I want to accomplish for each emulated machine:
|
||||
* Audio Support
|
||||
* Display Emulation - High resolution graphics - Mostly works.
|
||||
|
||||
### Apple IIe
|
||||
|
||||
*64K / 65C02 / Enhanced ROM*
|
||||
|
||||
* Central *MMU* to coordinate/own all memory and IO
|
||||
* Generic slot/card infrastructure
|
||||
* Disk II emulation - In progress
|
||||
* Extended 80-Column Text Card
|
||||
* Display Emulation - 40 Column mode
|
||||
* Display Emulation - 80 Column mode
|
||||
* Display Emulation - Low resolution graphics
|
||||
* Display Emulation - High resolution graphics
|
||||
* Display Emulation - Double high resolution graphics
|
||||
|
12
src/Makefile
12
src/Makefile
@ -39,15 +39,20 @@ SCR_TEST_SOURCES=cpu.c ins.c mem.c fmt.c two.c scr.c dsk.c chr.c alc.c utl.c scr
|
||||
SCR_TEST_OBJECTS=$(SCR_TEST_SOURCES:.c=.o)
|
||||
SCR_TEST_LIBS=-lSDL2
|
||||
|
||||
CPU_BENCH=cpu_bench
|
||||
CPU_BENCH_SOURCES=cpu.c ins.c mem.c fmt.c cpu_bench.c
|
||||
CPU_BENCH_OBJECTS=$(CPU_BENCH_SOURCES:.c=.o)
|
||||
CPU_BENCH_LIBS=
|
||||
|
||||
MEM_BENCH=mem_bench
|
||||
MEM_BENCH_SOURCES=cpu.c ins.c mem.c fmt.c mem_bench.c
|
||||
MEM_BENCH_OBJECTS=$(MEM_BENCH_SOURCES:.c=.o)
|
||||
MEM_BENCH_LIBS=
|
||||
|
||||
all: $(EWM_SOURCES) $(EWM_EXECUTABLE) $(CPU_TEST_SOURCES) $(CPU_TEST_EXECUTABLE) $(SCR_TEST_EXECUTABLE) $(MEM_BENCH)
|
||||
all: $(EWM_SOURCES) $(EWM_EXECUTABLE) $(CPU_TEST_SOURCES) $(CPU_TEST_EXECUTABLE) $(SCR_TEST_EXECUTABLE) $(CPU_BENCH) $(MEM_BENCH)
|
||||
|
||||
clean:
|
||||
rm -f $(EWM_OBJECTS) $(EWM_EXECUTABLE) $(CPU_TEST_OBJECTS) $(CPU_TEST_EXECUTABLE) $(SCR_TEST_OBJECTS) $(SCR_TEST_EXECUTABLE) $(MEM_BENCH)
|
||||
rm -f $(EWM_OBJECTS) $(EWM_EXECUTABLE) $(CPU_TEST_OBJECTS) $(CPU_TEST_EXECUTABLE) $(SCR_TEST_OBJECTS) $(SCR_TEST_EXECUTABLE) $(CPU_BENCH) $(MEM_BENCH)
|
||||
|
||||
$(EWM_EXECUTABLE): $(EWM_OBJECTS)
|
||||
$(CC) $(LDFLAGS) $(EWM_OBJECTS) $(EWM_LIBS) -o $@
|
||||
@ -58,6 +63,9 @@ $(CPU_TEST_EXECUTABLE): $(CPU_TEST_OBJECTS)
|
||||
$(SCR_TEST_EXECUTABLE): $(SCR_TEST_OBJECTS)
|
||||
$(CC) $(LDFLAGS) $(SCR_TEST_OBJECTS) $(SCR_TEST_LIBS) -o $@
|
||||
|
||||
$(CPU_BENCH): $(CPU_BENCH_OBJECTS)
|
||||
$(CC) $(LDFLAGS) $(CPU_BENCH_OBJECTS) $(CPU_BENCH_LIBS) -o $@
|
||||
|
||||
$(MEM_BENCH): $(MEM_BENCH_OBJECTS)
|
||||
$(CC) $(LDFLAGS) $(MEM_BENCH_OBJECTS) $(MEM_BENCH_LIBS) -o $@
|
||||
|
||||
|
@ -37,12 +37,6 @@
|
||||
#include "mem.h"
|
||||
#include "fmt.h"
|
||||
|
||||
/* Private API */
|
||||
|
||||
typedef void (*cpu_instruction_handler_t)(struct cpu_t *cpu);
|
||||
typedef void (*cpu_instruction_handler_byte_t)(struct cpu_t *cpu, uint8_t oper);
|
||||
typedef void (*cpu_instruction_handler_word_t)(struct cpu_t *cpu, uint16_t oper);
|
||||
|
||||
// Stack management.
|
||||
|
||||
void _cpu_push_byte(struct cpu_t *cpu, uint8_t b) {
|
||||
|
@ -56,6 +56,10 @@ struct cpu_t {
|
||||
uint64_t counter;
|
||||
};
|
||||
|
||||
typedef void (*cpu_instruction_handler_t)(struct cpu_t *cpu);
|
||||
typedef void (*cpu_instruction_handler_byte_t)(struct cpu_t *cpu, uint8_t oper);
|
||||
typedef void (*cpu_instruction_handler_word_t)(struct cpu_t *cpu, uint16_t oper);
|
||||
|
||||
#define MEM_FLAGS_READ 0x01
|
||||
#define MEM_FLAGS_WRITE 0x02
|
||||
|
||||
|
88
src/cpu_bench.c
Normal file
88
src/cpu_bench.c
Normal file
@ -0,0 +1,88 @@
|
||||
// The MIT License (MIT)
|
||||
//
|
||||
// Copyright (c) 2015 Stefan Arentz - http://github.com/st3fan/ewm
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "cpu.h"
|
||||
#include "ins.h"
|
||||
#include "mem.h"
|
||||
|
||||
#define CPU_BENCH_ITERATIONS (100 * 1000 * 1000)
|
||||
|
||||
void test(struct cpu_t *cpu, uint8_t opcode) {
|
||||
uint64_t runs[3];
|
||||
|
||||
struct cpu_instruction_t *ins = &cpu->instructions[opcode];
|
||||
|
||||
for (int run = 0; run < 3; run++) {
|
||||
struct timespec start;
|
||||
if (clock_gettime(CLOCK_REALTIME, &start) != 0) {
|
||||
perror("Cannot get time");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
switch (ins->bytes) {
|
||||
case 1:
|
||||
for (uint64_t i = 0; i < CPU_BENCH_ITERATIONS; i++) {
|
||||
((cpu_instruction_handler_t) ins->handler)(cpu);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
for (uint64_t i = 0; i < CPU_BENCH_ITERATIONS; i++) {
|
||||
((cpu_instruction_handler_byte_t) ins->handler)(cpu, 0x12);
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
for (uint64_t i = 0; i < CPU_BENCH_ITERATIONS; i++) {
|
||||
((cpu_instruction_handler_word_t) ins->handler)(cpu, 0x1234);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
struct timespec now;
|
||||
if (clock_gettime(CLOCK_REALTIME, &now) != 0) {
|
||||
perror("Cannot get time");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
uint64_t duration_ms = (now.tv_sec * 1000 + (now.tv_nsec / 1000000))
|
||||
- (start.tv_sec * 1000 + (start.tv_nsec / 1000000));
|
||||
|
||||
runs[run] = duration_ms;
|
||||
}
|
||||
|
||||
printf("$%.2X %s %8llu %8llu %8llu -> %8llu\n",
|
||||
opcode, ins->name, runs[0], runs[1], runs[2],
|
||||
(runs[0] + runs[1] + runs[2]) / 3);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
struct cpu_t *cpu = cpu_create(EWM_CPU_MODEL_65C02);
|
||||
cpu_add_ram_data(cpu, 0, 0xffff, malloc(0xffff));
|
||||
cpu_reset(cpu);
|
||||
|
||||
for (int opcode = 0; opcode <= 255; opcode++) {
|
||||
test(cpu, opcode);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user