finishing touches for restructure

This commit is contained in:
Yuvia 2025-09-09 15:43:34 +00:00
parent d5155e7cb7
commit 1f6b0e1344
11 changed files with 51 additions and 39 deletions

BIN
6.out Executable file

Binary file not shown.

BIN
a.out Normal file

Binary file not shown.

BIN
cpu.6 Normal file

Binary file not shown.

41
cpu.c
View file

@ -3,32 +3,31 @@
#include "dat.h" #include "dat.h"
#include "fns.h" #include "fns.h"
u8int *mem;
u8int rA, rS, rX, rY, rP; u8int rA, rS, rX, rY, rP;
u16int pc; u16int pc;
int irq, nmi; int irq, nmi;
static void void
push8(u8int v) push8(u8int v)
{ {
memwrite(0x100 | rS--, v); memwrite(0x100 | rS--, v);
} }
static void void
push16(u16int v) push16(u16int v)
{ {
memwrite(0x100 | rS--, v >> 8); memwrite(0x100 | rS--, v >> 8);
memwrite(0x100 | rS--, v); memwrite(0x100 | rS--, v);
} }
static u8int u8int
pop8(void) pop8(void)
{ {
return memread(0x100 | ++rS); return memread(0x100 | ++rS);
} }
static u16int u16int
pop16(void) pop16(void)
{ {
u16int v; u16int v;
@ -38,13 +37,13 @@ pop16(void)
return v; return v;
} }
static u8int u8int
fetch8(void) fetch8(void)
{ {
return memread(pc++); return memread(pc++);
} }
static u16int u16int
fetch16(void) fetch16(void)
{ {
u16int r; u16int r;
@ -54,7 +53,7 @@ fetch16(void)
return r; return r;
} }
static void void
nz(u8int v) nz(u8int v)
{ {
rP &= ~(Negative | Zero); rP &= ~(Negative | Zero);
@ -64,7 +63,7 @@ nz(u8int v)
rP |= Zero; rP |= Zero;
} }
static void void
adc(u8int d) adc(u8int d)
{ {
int r; int r;
@ -78,7 +77,7 @@ adc(u8int d)
if(rA == 0) rP |= Zero; if(rA == 0) rP |= Zero;
} }
static void void
sbc(u8int d) sbc(u8int d)
{ {
int r; int r;
@ -92,7 +91,7 @@ sbc(u8int d)
if(rA & 0x80) rP |= Negative; if(rA & 0x80) rP |= Negative;
} }
static void void
asl(u16int a) asl(u16int a)
{ {
u8int v; u8int v;
@ -109,7 +108,7 @@ asl(u16int a)
memwrite(a, v); memwrite(a, v);
} }
static void void
lsr(u16int a) lsr(u16int a)
{ {
u8int v; u8int v;
@ -123,7 +122,7 @@ lsr(u16int a)
memwrite(a, v); memwrite(a, v);
} }
static void void
rol(u16int a) rol(u16int a)
{ {
u8int v, b; u8int v, b;
@ -138,7 +137,7 @@ rol(u16int a)
memwrite(a, v); memwrite(a, v);
} }
static void void
ror(u16int a) ror(u16int a)
{ {
u8int v, b; u8int v, b;
@ -153,7 +152,7 @@ ror(u16int a)
memwrite(a, v); memwrite(a, v);
} }
static void void
cmp(u8int A, u8int B) cmp(u8int A, u8int B)
{ {
rP &= ~(Negative | Zero | Carry); rP &= ~(Negative | Zero | Carry);
@ -162,7 +161,7 @@ cmp(u8int A, u8int B)
if((A - B) & 0x80) rP |= Negative; if((A - B) & 0x80) rP |= Negative;
} }
static void void
inc(u16int a) inc(u16int a)
{ {
u8int v; u8int v;
@ -173,7 +172,7 @@ inc(u16int a)
memwrite(a, v); memwrite(a, v);
} }
static void void
dec(u16int a) dec(u16int a)
{ {
u8int v; u8int v;
@ -184,7 +183,7 @@ dec(u16int a)
memwrite(a, v); memwrite(a, v);
} }
static int int
branch(void) branch(void)
{ {
s8int t; s8int t;
@ -200,7 +199,7 @@ branch(void)
return 3; return 3;
} }
static u16int u16int
aindX(void) aindX(void)
{ {
u8int r; u8int r;
@ -212,7 +211,7 @@ aindX(void)
return b; return b;
} }
static u16int u16int
aindY(int *p) aindY(int *p)
{ {
u8int r; u8int r;
@ -225,7 +224,7 @@ aindY(int *p)
return b; return b;
} }
static void void
interrupt(int nmi, int brk) interrupt(int nmi, int brk)
{ {
push16(pc); push16(pc);

8
fns.h
View file

@ -1,5 +1,5 @@
int step(void); extern int step(void);
u8int memread(u16int); extern u8int memread(u16int);
void memwrite(u16int, u8int); extern void memwrite(u16int, u8int);
static u16int fetch16(void); extern u16int fetch16(void);

BIN
main.6 Normal file

Binary file not shown.

15
main.c
View file

@ -6,7 +6,7 @@
void void
usage(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"); exits("usage");
} }
@ -23,14 +23,14 @@ openprog(char *f)
sysfatal("cannot open program: %r"); sysfatal("cannot open program: %r");
d = dirfstat(fd); d = dirfstat(fd);
if(d->length > 0xFF00) 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 = mem+32768;
romptr = romptr + 32768 - d->length; romptr += 32768 - d->length;
s = romptr-mem; s = mem+65536-romptr;
free(d); free(d);
n = read(fd, romptr, s); n = read(fd, romptr, s);
if(n != 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); close(fd);
} }
@ -42,6 +42,9 @@ main(int argc, char **argv)
vlong target; vlong target;
target = 1000; target = 1000;
mem = malloc(0x10000);
if(mem == nil)
sysfatal("bad malloc for mem");
ARGBEGIN{ ARGBEGIN{
case 's': case 's':
target = atoll(EARGF(usage())); target = atoll(EARGF(usage()));
@ -50,6 +53,8 @@ main(int argc, char **argv)
usage(); usage();
break; break;
}ARGEND }ARGEND
if(!argc)
usage();
openprog(*argv); openprog(*argv);
rP = 0x34; rP = 0x34;
pc = 0xFFFC; pc = 0xFFFC;

BIN
mem.6 Normal file

Binary file not shown.

5
mem.c
View file

@ -3,6 +3,9 @@
#include "dat.h" #include "dat.h"
#include "fns.h" #include "fns.h"
u8int *mem;
u8int *romptr;
u8int u8int
memread(u16int a) memread(u16int a)
{ {
@ -12,6 +15,6 @@ memread(u16int a)
void void
memwrite(u16int a, u8int v) memwrite(u16int a, u8int v)
{ {
if(a < romptr) if((void*)a < romptr)
mem[a] = v; mem[a] = v;
} }

10
mkfile
View file

@ -3,15 +3,9 @@
BIN=/$objtype/bin BIN=/$objtype/bin
TARG=scemu TARG=scemu
OFILES=scemu.$O OFILES=main.$O cpu.$O mem.$O
UPDATE=mkfile prog.s ${OFILES:%.$O=%.c} UPDATE=mkfile prog.s ${OFILES:%.$O=%.c}
default:V: $O.out a.out default:V: $O.out
</sys/src/cmd/mkone </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
View file

@ -0,0 +1,11 @@
.org $ff00
reset:
lda #'\'
sta $7000
loop:
ror
jmp loop
.org $fffa
.word reset
.word reset
.word reset