final construction parts & primitive output

This commit is contained in:
Yuvia 2025-09-09 16:00:07 +00:00
parent 6fcc8cd379
commit d827ee0f97
12 changed files with 36 additions and 15 deletions

BIN
6.out

Binary file not shown.

BIN
a.out

Binary file not shown.

BIN
cpu.6

Binary file not shown.

2
cpu.c
View file

@ -7,6 +7,7 @@ u8int rA, rS, rX, rY, rP;
u16int pc;
int irq, nmi;
int trace;
void
nz(u8int v)
@ -217,6 +218,7 @@ step(void)
}
cpc = pc;
op = fetch8();
if(trace)
print("%02x %08b %08b %08b %08b %04x %02x\n",
op, rA, rX, rY, rP, cpc, rS);
switch(op){

1
dat.h
View file

@ -12,3 +12,4 @@ extern u8int *mem;
extern u8int *romptr;
extern u8int rA, rS, rX, rY, rP;
extern u16int pc;
extern int trace;

7
fns.h
View file

@ -2,4 +2,11 @@ extern int step(void);
extern u8int memread(u16int);
extern void memwrite(u16int, u8int);
extern void push8(u8int);
extern void push16(u16int);
extern u8int pop8(void);
extern u16int pop16(void);
extern u8int fetch8(void);
extern u16int fetch16(void);
extern void out(void);

BIN
main.6

Binary file not shown.

7
main.c
View file

@ -6,7 +6,7 @@
void
usage(void)
{
fprint(2, "usage: %s [ -s target cycle length ] prog\n", argv0);
fprint(2, "usage: %s [ -t ] [ -s target cycle length ] prog\n", argv0);
exits("usage");
}
@ -41,6 +41,7 @@ main(int argc, char **argv)
vlong t, t2, t3;
vlong target;
trace = 0;
target = 1000;
mem = malloc(0x10000);
if(mem == nil)
@ -49,6 +50,9 @@ main(int argc, char **argv)
case 's':
target = atoll(EARGF(usage()));
break;
case 't':
trace = 1;
break;
default:
usage();
break;
@ -71,6 +75,7 @@ main(int argc, char **argv)
t3 = t2-t;
}
}
out();
}
}

BIN
mem.6

Binary file not shown.

2
mkfile
View file

@ -3,7 +3,7 @@
BIN=/$objtype/bin
TARG=scemu
OFILES=main.$O cpu.$O mem.$O
OFILES=main.$O cpu.$O mem.$O out.$O
UPDATE=mkfile prog.s ${OFILES:%.$O=%.c}
default:V: $O.out

17
out.c Normal file
View file

@ -0,0 +1,17 @@
#include <u.h>
#include <libc.h>
#include "dat.h"
#include "fns.h"
void
out(void)
{
int c;
if(memread(0x7002) == 1){
c = memread(0x7000);
memwrite(0x7001, 0);
print("%c", c);
memwrite(0x7001, 1);
}
}

11
test.s
View file

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