Skip to content

Commit

Permalink
Factor out instruction fetches
Browse files Browse the repository at this point in the history
  • Loading branch information
segher committed Feb 18, 2010
1 parent 91a26a2 commit be6aa52
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
29 changes: 16 additions & 13 deletions emu.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ static int trace_calls = 0;
static int pause_after_every_frame = 0;
//static u8 trace_irq[9] = { 0, 1, 1, 1, 1, 1, 1, 1, 1 };
static u8 trace_irq[9] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
static u8 unsp_version = 11; // version a.b as 10*a + b
static const u32 unsp_version = 11; // version a.b as 10*a + b
static u8 ever_ran_this[N_MEM];


Expand Down Expand Up @@ -117,7 +117,7 @@ static inline void set_cs_pc(u32 x)
reg[6] = (reg[6] & ~0x3f) | ((x >> 16) & 0x3f);
}

static inline void inc_cs_pc(s16 x)
static inline void inc_cs_pc(int x)
{
if (unsp_version < 11)
reg[7] += x;
Expand Down Expand Up @@ -259,6 +259,14 @@ static void maybe_enter_irq(void)
do_irq(irqno);
}

static inline u16 fetch(void)
{
u16 x = load(cs_pc());
inc_cs_pc(1);

return x;
}

static void step(void)
{
u16 op;
Expand All @@ -273,8 +281,7 @@ static void step(void)
print_state();
}

op = mem[cs_pc()];
inc_cs_pc(1);
op = fetch();


// the top four bits are the alu op or the branch condition, or E or F
Expand Down Expand Up @@ -451,8 +458,7 @@ static void step(void)

cycle_count += 9;

x1 = mem[cs_pc()];
inc_cs_pc(1);
x1 = fetch();
push(reg[7], 0);
push(reg[6], 0);
set_cs_pc((opimm << 16) | x1);
Expand All @@ -464,7 +470,7 @@ static void step(void)

cycle_count += 5;

x1 = mem[cs_pc()];
x1 = fetch();
set_cs_pc((opimm << 16) | x1);
return;

Expand Down Expand Up @@ -590,8 +596,7 @@ static void step(void)
cycle_count++;

x0 = reg[opB];
x1 = mem[cs_pc()];
inc_cs_pc(1);
x1 = fetch();
break;

case 2: // [imm16]
Expand All @@ -600,8 +605,7 @@ static void step(void)
cycle_count++;

x0 = reg[opB];
d = mem[cs_pc()];
inc_cs_pc(1);
d = fetch();
if (op0 == 13)
x1 = 0x0bad;
else
Expand All @@ -615,8 +619,7 @@ static void step(void)

x0 = reg[opB];
x1 = reg[opA];
d = mem[cs_pc()];
inc_cs_pc(1);
d = fetch();
break;

default: // ASR
Expand Down
3 changes: 2 additions & 1 deletion emu.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2008,2009 Segher Boessenkool <[email protected]>
// Copyright 2008-2010 Segher Boessenkool <[email protected]>
// Licensed under the terms of the GNU GPL, version 2
// http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt

Expand All @@ -12,6 +12,7 @@
extern u16 mem[N_MEM];

void emu(void);

u32 get_ds(void);
void set_ds(u32 ds);
u16 get_video_line(void);
Expand Down

0 comments on commit be6aa52

Please sign in to comment.