Skip to content

Commit

Permalink
Some improvements on timing, and actually added EEPROM support
Browse files Browse the repository at this point in the history
  • Loading branch information
gdkchan committed Jan 21, 2017
1 parent 8bff72f commit 2c5750b
Show file tree
Hide file tree
Showing 9 changed files with 197 additions and 82 deletions.
2 changes: 1 addition & 1 deletion Make.bat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
gcc -Wall -Ofast -o gdkGBA *.c -lmingw32 -mwindows -mconsole -lSDL2main -lSDL2
mingw32-make CLIBS="-lmingw32 -mwindows -mconsole -lSDL2main"
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
TARGET = gdkGBA
LIBS = -lm -lSDL2
LIBS = $(CLIBS) -lSDL2
CC = gcc
CFLAGS = -std=c99 -g -Wall -Ofast

Expand All @@ -11,13 +11,13 @@ all: default
OBJECTS += $(patsubst %.c, %.o, $(wildcard *.c))
HEADERS = $(wildcard *.h) $(wildcard *.h)

%.o: %.cpp $(HEADERS)
%.o: %.c $(HEADERS)
$(CC) $(CFLAGS) -c $< -o $@

.PRECIOUS: $(TARGET) $(OBJECTS)

$(TARGET): $(OBJECTS)
$(CC) $(OBJECTS) -Wall -Ofast $(LIBS) -o $@
$(CC) $(OBJECTS) -Wall -Ofast $(LIBS) -o $@

clean:
-rm -f *.o
Expand Down
93 changes: 56 additions & 37 deletions arm.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
#include "io.h"
#include "timer.h"

void (*arm_proc[2][4096])();

void (*thumb_proc[2048])();

/*
* Utils
*/
Expand Down Expand Up @@ -392,6 +388,20 @@ static void arm_interwork() {
arm_load_pipe();
}

static void arm_cycles_s_to_n() {
if (arm_r.r[15] & 0x08000000) {
uint8_t idx = (arm_r.r[15] >> 25) & 3;

if (arm_in_thumb()) {
arm_cycles -= ws_s_t16[idx];
arm_cycles += ws_n_t16[idx];
} else {
arm_cycles -= ws_s_arm[idx];
arm_cycles += ws_n_arm[idx];
}
}
}

/*
* Execute
*/
Expand Down Expand Up @@ -777,6 +787,8 @@ static arm_shifter_t arm_data_regr(uint8_t rm, uint8_t type, uint8_t rs) {

arm_cycles++;

arm_cycles_s_to_n();

return out;
}

Expand Down Expand Up @@ -971,6 +983,8 @@ static void arm_mpy_inc_cycles(uint64_t rhs, bool u) {
arm_cycles += 3;
else
arm_cycles += 4;

arm_cycles_s_to_n();
}

static void arm_mpy_add(arm_mpy_t op) {
Expand Down Expand Up @@ -1346,6 +1360,8 @@ static void arm_memio_ldm(arm_memio_t op) {
}

arm_cycles++;

arm_cycles_s_to_n();
}

static void arm_memio_ldm_usr(arm_memio_t op) {
Expand Down Expand Up @@ -1379,6 +1395,8 @@ static void arm_memio_stm(arm_memio_t op) {
op.addr += 4;
}
}

arm_cycles_s_to_n();
}

static void arm_memio_stm_usr(arm_memio_t op) {
Expand All @@ -1398,6 +1416,8 @@ static void arm_memio_ldr(arm_memio_t op) {
}

arm_cycles++;

arm_cycles_s_to_n();
}

static void arm_memio_ldrb(arm_memio_t op) {
Expand All @@ -1409,6 +1429,8 @@ static void arm_memio_ldrb(arm_memio_t op) {
}

arm_cycles++;

arm_cycles_s_to_n();
}

static void arm_memio_ldrh(arm_memio_t op) {
Expand All @@ -1420,6 +1442,8 @@ static void arm_memio_ldrh(arm_memio_t op) {
}

arm_cycles++;

arm_cycles_s_to_n();
}

static void arm_memio_ldrsb(arm_memio_t op) {
Expand All @@ -1436,6 +1460,8 @@ static void arm_memio_ldrsb(arm_memio_t op) {
}

arm_cycles++;

arm_cycles_s_to_n();
}

static void arm_memio_ldrsh(arm_memio_t op) {
Expand All @@ -1452,6 +1478,8 @@ static void arm_memio_ldrsh(arm_memio_t op) {
}

arm_cycles++;

arm_cycles_s_to_n();
}

static void arm_memio_ldrd(arm_memio_t op) {
Expand All @@ -1464,23 +1492,33 @@ static void arm_memio_ldrd(arm_memio_t op) {
}

arm_cycles++;

arm_cycles_s_to_n();
}

static void arm_memio_str(arm_memio_t op) {
arm_write_n(op.addr, arm_memio_reg_get(op.rt));

arm_cycles_s_to_n();
}

static void arm_memio_strb(arm_memio_t op) {
arm_writeb_n(op.addr, arm_memio_reg_get(op.rt));

arm_cycles_s_to_n();
}

static void arm_memio_strh(arm_memio_t op) {
arm_writeh_n(op.addr, arm_memio_reg_get(op.rt));

arm_cycles_s_to_n();
}

static void arm_memio_strd(arm_memio_t op) {
arm_write_n(op.addr + 0, arm_memio_reg_get(op.rt));
arm_write_s(op.addr + 4, arm_memio_reg_get(op.rt2));

arm_cycles_s_to_n();
}

static void arm_memio_load_usr(arm_memio_t op, arm_size_e size) {
Expand Down Expand Up @@ -1949,8 +1987,6 @@ static void arm_b() {
imm <<= 8;
imm >>= 6;

arm_access_bus(arm_r.r[15], ARM_WORD_SZ, SEQUENTIAL);

arm_r.r[15] += imm;

arm_load_pipe();
Expand All @@ -1962,8 +1998,6 @@ static void t16_b_imm11() {
imm <<= 21;
imm >>= 20;

arm_access_bus(arm_r.r[15], ARM_HWORD_SZ, SEQUENTIAL);

arm_r.r[15] += imm;

arm_load_pipe();
Expand All @@ -1979,8 +2013,6 @@ static void t16_b_imm8() {
int8_t cond = (arm_op >> 8) & 0xf;

if (arm_cond(cond)) {
arm_access_bus(arm_r.r[15], ARM_HWORD_SZ, SEQUENTIAL);

arm_r.r[15] += imm;

arm_load_pipe();
Expand Down Expand Up @@ -2020,8 +2052,6 @@ static void arm_bl() {
imm <<= 8;
imm >>= 6;

arm_access_bus(arm_r.r[15], ARM_WORD_SZ, SEQUENTIAL);

arm_r.r[14] = arm_r.r[15] - ARM_WORD_SZ;
arm_r.r[15] = (arm_r.r[15] & ~3) + imm;

Expand All @@ -2039,8 +2069,6 @@ static void arm_blx_imm() {

arm_flag_set(ARM_T, true);

arm_access_bus(arm_r.r[15], ARM_WORD_SZ, SEQUENTIAL);

arm_r.r[14] = arm_r.r[15] - ARM_WORD_SZ;
arm_r.r[15] += imm;

Expand All @@ -2050,8 +2078,6 @@ static void arm_blx_imm() {
static void arm_blx_reg() {
uint8_t rm = arm_op & 0xf;

arm_access_bus(arm_r.r[15], ARM_WORD_SZ, SEQUENTIAL);

arm_r.r[14] = arm_r.r[15] - ARM_WORD_SZ;
arm_r.r[15] = arm_r.r[rm];

Expand All @@ -2061,8 +2087,6 @@ static void arm_blx_reg() {
static void t16_blx() {
uint8_t rm = (arm_op >> 3) & 0xf;

arm_access_bus(arm_r.r[15], ARM_HWORD_SZ, SEQUENTIAL);

arm_r.r[14] = (arm_r.r[15] - ARM_HWORD_SZ) | 1;
arm_r.r[15] = arm_r.r[rm];

Expand All @@ -2084,8 +2108,6 @@ static void t16_blx_lrimm() {

imm += (arm_op & 0x7ff) << 1;

arm_access_bus(arm_r.r[15], ARM_HWORD_SZ, SEQUENTIAL);

arm_r.r[14] = (arm_r.r[15] - ARM_HWORD_SZ) | 1;
arm_r.r[15] = imm & ~1;
}
Expand All @@ -2104,8 +2126,6 @@ static void t16_blx_h3() {
static void arm_bx() {
uint8_t rm = arm_op & 0xf;

arm_access_bus(arm_r.r[15], ARM_WORD_SZ, SEQUENTIAL);

arm_r.r[15] = arm_r.r[rm];

arm_interwork();
Expand All @@ -2114,8 +2134,6 @@ static void arm_bx() {
static void t16_bx() {
uint8_t rm = (arm_op >> 3) & 0xf;

arm_access_bus(arm_r.r[15], ARM_HWORD_SZ, SEQUENTIAL);

arm_r.r[15] = arm_r.r[rm];

arm_interwork();
Expand Down Expand Up @@ -2893,6 +2911,9 @@ static void arm_proc_set(void (**arr)(), void (*proc)(), uint32_t op, uint32_t m
}
}

void (*arm_proc[2][4096])();
void (*thumb_proc[2048])();

static void arm_proc_init() {
//Format 27:20,7:4
arm_proc_fill(arm_proc[0], arm_und, 4096);
Expand Down Expand Up @@ -3094,17 +3115,16 @@ static void thumb_proc_init() {
}

void arm_init() {
bios = malloc(0x4000);
wram = malloc(0x40000);
iwram = malloc(0x8000);
pram = malloc(0x400);
vram = malloc(0x18000);
oam = malloc(0x400);

rom = malloc(0x2000000);

sram = malloc(0x10000);
flash = malloc(0x20000);
bios = malloc(0x4000);
wram = malloc(0x40000);
iwram = malloc(0x8000);
pram = malloc(0x400);
vram = malloc(0x18000);
oam = malloc(0x400);
rom = malloc(0x2000000);
eeprom = malloc(0x2000);
sram = malloc(0x10000);
flash = malloc(0x20000);

arm_proc_init();
thumb_proc_init();
Expand All @@ -3123,9 +3143,8 @@ void arm_uninit() {
free(pram);
free(vram);
free(oam);

free(rom);

free(eeprom);
free(sram);
free(flash);
}
Expand Down
Loading

0 comments on commit 2c5750b

Please sign in to comment.