finishing touches for restructure
This commit is contained in:
parent
d5155e7cb7
commit
1f6b0e1344
11 changed files with 51 additions and 39 deletions
BIN
6.out
Executable file
BIN
6.out
Executable file
Binary file not shown.
BIN
a.out
Normal file
BIN
a.out
Normal file
Binary file not shown.
BIN
cpu.6
Normal file
BIN
cpu.6
Normal file
Binary file not shown.
41
cpu.c
41
cpu.c
|
@ -3,32 +3,31 @@
|
|||
#include "dat.h"
|
||||
#include "fns.h"
|
||||
|
||||
u8int *mem;
|
||||
u8int rA, rS, rX, rY, rP;
|
||||
u16int pc;
|
||||
|
||||
int irq, nmi;
|
||||
|
||||
static void
|
||||
void
|
||||
push8(u8int v)
|
||||
{
|
||||
memwrite(0x100 | rS--, v);
|
||||
}
|
||||
|
||||
static void
|
||||
void
|
||||
push16(u16int v)
|
||||
{
|
||||
memwrite(0x100 | rS--, v >> 8);
|
||||
memwrite(0x100 | rS--, v);
|
||||
}
|
||||
|
||||
static u8int
|
||||
u8int
|
||||
pop8(void)
|
||||
{
|
||||
return memread(0x100 | ++rS);
|
||||
}
|
||||
|
||||
static u16int
|
||||
u16int
|
||||
pop16(void)
|
||||
{
|
||||
u16int v;
|
||||
|
@ -38,13 +37,13 @@ pop16(void)
|
|||
return v;
|
||||
}
|
||||
|
||||
static u8int
|
||||
u8int
|
||||
fetch8(void)
|
||||
{
|
||||
return memread(pc++);
|
||||
}
|
||||
|
||||
static u16int
|
||||
u16int
|
||||
fetch16(void)
|
||||
{
|
||||
u16int r;
|
||||
|
@ -54,7 +53,7 @@ fetch16(void)
|
|||
return r;
|
||||
}
|
||||
|
||||
static void
|
||||
void
|
||||
nz(u8int v)
|
||||
{
|
||||
rP &= ~(Negative | Zero);
|
||||
|
@ -64,7 +63,7 @@ nz(u8int v)
|
|||
rP |= Zero;
|
||||
}
|
||||
|
||||
static void
|
||||
void
|
||||
adc(u8int d)
|
||||
{
|
||||
int r;
|
||||
|
@ -78,7 +77,7 @@ adc(u8int d)
|
|||
if(rA == 0) rP |= Zero;
|
||||
}
|
||||
|
||||
static void
|
||||
void
|
||||
sbc(u8int d)
|
||||
{
|
||||
int r;
|
||||
|
@ -92,7 +91,7 @@ sbc(u8int d)
|
|||
if(rA & 0x80) rP |= Negative;
|
||||
}
|
||||
|
||||
static void
|
||||
void
|
||||
asl(u16int a)
|
||||
{
|
||||
u8int v;
|
||||
|
@ -109,7 +108,7 @@ asl(u16int a)
|
|||
memwrite(a, v);
|
||||
}
|
||||
|
||||
static void
|
||||
void
|
||||
lsr(u16int a)
|
||||
{
|
||||
u8int v;
|
||||
|
@ -123,7 +122,7 @@ lsr(u16int a)
|
|||
memwrite(a, v);
|
||||
}
|
||||
|
||||
static void
|
||||
void
|
||||
rol(u16int a)
|
||||
{
|
||||
u8int v, b;
|
||||
|
@ -138,7 +137,7 @@ rol(u16int a)
|
|||
memwrite(a, v);
|
||||
}
|
||||
|
||||
static void
|
||||
void
|
||||
ror(u16int a)
|
||||
{
|
||||
u8int v, b;
|
||||
|
@ -153,7 +152,7 @@ ror(u16int a)
|
|||
memwrite(a, v);
|
||||
}
|
||||
|
||||
static void
|
||||
void
|
||||
cmp(u8int A, u8int B)
|
||||
{
|
||||
rP &= ~(Negative | Zero | Carry);
|
||||
|
@ -162,7 +161,7 @@ cmp(u8int A, u8int B)
|
|||
if((A - B) & 0x80) rP |= Negative;
|
||||
}
|
||||
|
||||
static void
|
||||
void
|
||||
inc(u16int a)
|
||||
{
|
||||
u8int v;
|
||||
|
@ -173,7 +172,7 @@ inc(u16int a)
|
|||
memwrite(a, v);
|
||||
}
|
||||
|
||||
static void
|
||||
void
|
||||
dec(u16int a)
|
||||
{
|
||||
u8int v;
|
||||
|
@ -184,7 +183,7 @@ dec(u16int a)
|
|||
memwrite(a, v);
|
||||
}
|
||||
|
||||
static int
|
||||
int
|
||||
branch(void)
|
||||
{
|
||||
s8int t;
|
||||
|
@ -200,7 +199,7 @@ branch(void)
|
|||
return 3;
|
||||
}
|
||||
|
||||
static u16int
|
||||
u16int
|
||||
aindX(void)
|
||||
{
|
||||
u8int r;
|
||||
|
@ -212,7 +211,7 @@ aindX(void)
|
|||
return b;
|
||||
}
|
||||
|
||||
static u16int
|
||||
u16int
|
||||
aindY(int *p)
|
||||
{
|
||||
u8int r;
|
||||
|
@ -225,7 +224,7 @@ aindY(int *p)
|
|||
return b;
|
||||
}
|
||||
|
||||
static void
|
||||
void
|
||||
interrupt(int nmi, int brk)
|
||||
{
|
||||
push16(pc);
|
||||
|
|
8
fns.h
8
fns.h
|
@ -1,5 +1,5 @@
|
|||
int step(void);
|
||||
u8int memread(u16int);
|
||||
void memwrite(u16int, u8int);
|
||||
extern int step(void);
|
||||
extern u8int memread(u16int);
|
||||
extern void memwrite(u16int, u8int);
|
||||
|
||||
static u16int fetch16(void);
|
||||
extern u16int fetch16(void);
|
||||
|
|
BIN
main.6
Normal file
BIN
main.6
Normal file
Binary file not shown.
15
main.c
15
main.c
|
@ -6,7 +6,7 @@
|
|||
void
|
||||
usage(void)
|
||||
{
|
||||
fprint(2, "usage: %s [ -s target speed ] [ prog ]\n", argv0);
|
||||
fprint(2, "usage: %s [ -s target cycle length ] prog\n", argv0);
|
||||
exits("usage");
|
||||
}
|
||||
|
||||
|
@ -23,14 +23,14 @@ openprog(char *f)
|
|||
sysfatal("cannot open program: %r");
|
||||
d = dirfstat(fd);
|
||||
if(d->length > 0xFF00)
|
||||
sysfatal("program too big: size does not permit whole zp access");
|
||||
sysfatal("program too big: cannot be bigger than $ff00");
|
||||
romptr = mem+32768;
|
||||
romptr = romptr + 32768 - d->length;
|
||||
s = romptr-mem;
|
||||
romptr += 32768 - d->length;
|
||||
s = mem+65536-romptr;
|
||||
free(d);
|
||||
n = read(fd, romptr, s);
|
||||
if(n != s)
|
||||
fprint(2, "tried to read %uld bytes, got %ld bytes\n", s, n);
|
||||
fprint(2, "tried to read %ulld bytes, got %ld bytes\n", s, n);
|
||||
close(fd);
|
||||
}
|
||||
|
||||
|
@ -42,6 +42,9 @@ main(int argc, char **argv)
|
|||
vlong target;
|
||||
|
||||
target = 1000;
|
||||
mem = malloc(0x10000);
|
||||
if(mem == nil)
|
||||
sysfatal("bad malloc for mem");
|
||||
ARGBEGIN{
|
||||
case 's':
|
||||
target = atoll(EARGF(usage()));
|
||||
|
@ -50,6 +53,8 @@ main(int argc, char **argv)
|
|||
usage();
|
||||
break;
|
||||
}ARGEND
|
||||
if(!argc)
|
||||
usage();
|
||||
openprog(*argv);
|
||||
rP = 0x34;
|
||||
pc = 0xFFFC;
|
||||
|
|
BIN
mem.6
Normal file
BIN
mem.6
Normal file
Binary file not shown.
5
mem.c
5
mem.c
|
@ -3,6 +3,9 @@
|
|||
#include "dat.h"
|
||||
#include "fns.h"
|
||||
|
||||
u8int *mem;
|
||||
u8int *romptr;
|
||||
|
||||
u8int
|
||||
memread(u16int a)
|
||||
{
|
||||
|
@ -12,6 +15,6 @@ memread(u16int a)
|
|||
void
|
||||
memwrite(u16int a, u8int v)
|
||||
{
|
||||
if(a < romptr)
|
||||
if((void*)a < romptr)
|
||||
mem[a] = v;
|
||||
}
|
||||
|
|
10
mkfile
10
mkfile
|
@ -3,15 +3,9 @@
|
|||
BIN=/$objtype/bin
|
||||
|
||||
TARG=scemu
|
||||
OFILES=scemu.$O
|
||||
OFILES=main.$O cpu.$O mem.$O
|
||||
UPDATE=mkfile prog.s ${OFILES:%.$O=%.c}
|
||||
|
||||
default:V: $O.out a.out
|
||||
default:V: $O.out
|
||||
|
||||
</sys/src/cmd/mkone
|
||||
|
||||
a.out: prog.s
|
||||
vasm -Fbin -dotdir prog.s
|
||||
|
||||
clean:
|
||||
rm -f a.out [$OS].out *.[$OS]
|
||||
|
|
11
test.s
Normal file
11
test.s
Normal file
|
@ -0,0 +1,11 @@
|
|||
.org $ff00
|
||||
reset:
|
||||
lda #'\'
|
||||
sta $7000
|
||||
loop:
|
||||
ror
|
||||
jmp loop
|
||||
.org $fffa
|
||||
.word reset
|
||||
.word reset
|
||||
.word reset
|
Loading…
Add table
Reference in a new issue