Commit MetaInfo

Revision5cd7a04c8f5a0d8ad425ccb16f1f120f0b622fe1 (tree)
Time2019-05-23 20:56:08
Authoringlorion <homemicro@ingl...>
Commiteringlorion

Log Message

added test program for emulator

Change Summary

Incremental Difference

diff -r 9881e238851f -r 5cd7a04c8f5a emulator/Makefile.in
--- a/emulator/Makefile.in Mon May 20 00:15:36 2019 -0700
+++ b/emulator/Makefile.in Thu May 23 04:56:08 2019 -0700
@@ -1,5 +1,5 @@
1-TARGETS = Makefile hm1000
2-OBJECTS = main.o xcb.o
1+TARGETS = Makefile hm1000 test_ret1
2+OBJECTS = main.o test_ret1.o xcb.o
33
44 CFLAGS = @CFLAGS@ @XCB_CFLAGS@
55 LIBS = @LIBS@ @XCB_LIBS@
@@ -12,12 +12,18 @@
1212 distclean : clean
1313 -rm $(TARGETS)
1414
15-hm1000 : $(OBJECTS)
16- $(CC) $(CFLAGS) -o hm1000 $(OBJECTS) $(LIBS)
15+hm1000 : main.o xcb.o
16+ $(CC) $(CFLAGS) -o hm1000 main.o xcb.o $(LIBS)
17+
18+test_ret1 : test_ret1.o
19+ $(CC) $(CFLAGS) -o test_ret1 test_ret1.o
1720
1821 main.o : main.c hm1000.c hm1000.h ops.inc xcb.h
1922 $(CC) $(CFLAGS) -c main.c
2023
24+test_ret1.o : test_ret1.c hm1000.c hm1000.h ops.inc
25+ $(CC) $(CFLAGS) -c test_ret1.c
26+
2127 xcb.o : xcb.c xcb.h
2228 $(CC) $(CFLAGS) -c xcb.c
2329
diff -r 9881e238851f -r 5cd7a04c8f5a emulator/test_ret1.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/emulator/test_ret1.c Thu May 23 04:56:08 2019 -0700
@@ -0,0 +1,47 @@
1+#include "hm1000.h"
2+
3+#include "hm1000.c"
4+
5+static void push(hm1k_state *s, uint8_t value) {
6+ s->ram[0x100 + s->s] = value;
7+ --s->s;
8+}
9+
10+static void push_return_address(hm1k_state *s, uint16_t addr) {
11+ --addr;
12+ push(s, addr >> 8);
13+ push(s, addr & 0xff);
14+}
15+
16+int main(int argc, char *argv[]) {
17+ hm1k_state state;
18+ uint8_t ram[RAM_SIZE];
19+ uint8_t rom[ROM_SIZE];
20+
21+ randomize(ram, sizeof(ram));
22+ randomize(rom, sizeof(rom));
23+ rom[0x1ffc] = 0;
24+ rom[0x1ffd] = 0x04;
25+ init_6502(&state, ram);
26+ state.rom = rom;
27+ state.io_read[SERIR - IO_BASE] = read_serir;
28+ state.io_write[SERCR - IO_BASE] = write_sercr;
29+ state.kbdrow = 0;
30+ memset(state.keyboard, 0xff, sizeof(state.keyboard));
31+ state.io_read[KBDCOL - IO_BASE] = read_kbdcol;
32+ state.io_write[KBDROW - IO_BASE] = write_kbdrow;
33+ reset(&state);
34+
35+ state.a = 0x00;
36+ state.s = 0xff;
37+ push_return_address(&state, 0xfffc);
38+ ram[0x0400] = 0xa9; /* lda # */
39+ ram[0x0401] = 0x01;
40+ ram[0x0402] = 0x60; /* rts */
41+ while (state.pc != 0xfffc) {
42+ printf("pc: %04x\n", state.pc);
43+ step_6502(&state);
44+ }
45+ printf("a: %02x\n", state.a);
46+ return 0;
47+}
Show on old repository browser