Commit MetaInfo

Revision0372971e292b6ca87c32d6c28c6a8b101cffa6bd (tree)
Time2019-05-25 15:56:45
Authoringlorion <homemicro@ingl...>
Commiteringlorion

Log Message

test micrornd using emulator

Change Summary

Incremental Difference

diff -r 5cd7a04c8f5a -r 0372971e292b apps/micrornd/Makefile
--- a/apps/micrornd/Makefile Thu May 23 04:56:08 2019 -0700
+++ b/apps/micrornd/Makefile Fri May 24 23:56:45 2019 -0700
@@ -1,4 +1,4 @@
1-TARGETS = micrornd.bin
1+TARGETS = micrornd.bin test test.bin
22
33 all : $(TARGETS)
44
@@ -7,7 +7,16 @@
77 distclean : clean
88 -rm $(TARGETS)
99
10-micrornd.bin : micrornd.s
10+test : test.o test.bin
11+ $(CC) $(CFLAGS) test.o -o test
12+
13+micrornd.bin : micrornd.s micrornd_code.inc micrornd_data.inc
1114 xa -M -bt 57344 -o micrornd.bin micrornd.s
1215
16+test.bin : test.s micrornd_code.inc micrornd_data.inc
17+ xa -M -bt 1024 -o test.bin test.s
18+
19+test.o : test.c ../../emulator/hm1000.h ../../emulator/hm1000.c
20+ $(CC) $(CFLAGS) -I../../emulator -c test.c
21+
1322 .PHONY : all clean distclean
diff -r 5cd7a04c8f5a -r 0372971e292b apps/micrornd/micrornd.s
--- a/apps/micrornd/micrornd.s Thu May 23 04:56:08 2019 -0700
+++ b/apps/micrornd/micrornd.s Fri May 24 23:56:45 2019 -0700
@@ -44,34 +44,7 @@
4444 halt:
4545 jmp halt
4646
47-rnd:
48-;;; Returns a pseudorandom number in a.
49-;;; If I've counted correctly, this takes 44 cycles and 29 bytes if
50-;;; micrornd_state is located on the zero page, 56 cycles and 41 bytes
51-;;; if micrornd_state is not on the zero page. In both cases excluding
52-;;; the rts at the end and the sequence to call the procedure. The
53-;;; PRNG uses 4 bytes of state.
54-;;; The four instructions at the beginning can be removed to reduce
55-;;; the size of the state by one byte, the size of the routine by
56-;;; 8 bytes (12 bytes if state is not on the zero page), and the number
57-;;; of clock cycles by 14 (18 if not using zero page).
58- lda micrornd_state + 1
59- eor micrornd_state + 3
60- sta micrornd_state + 1
61- inc micrornd_state + 3
62-
63- lda micrornd_state + 1
64- asl
65- eor #$d5
66- adc micrornd_state + 2
67- sta micrornd_state + 1
68- lda micrornd_state + 2
69- adc #1
70- sta micrornd_state + 2
71- lda micrornd_state
72- adc micrornd_state + 1
73- sta micrornd_state
74- rts
47+#include "micrornd_code.inc"
7548
7649 setcur:
7750 ;;; Sets the cursor position.
@@ -168,7 +141,6 @@
168141 hexits:
169142 .byte "0123456789abcdef"
170143
171-micrornd_state:
172- .byte 0, 0, 0, 0
144+#include "micrornd_data.inc"
173145
174146 _end:
diff -r 5cd7a04c8f5a -r 0372971e292b apps/micrornd/micrornd_code.inc
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/apps/micrornd/micrornd_code.inc Fri May 24 23:56:45 2019 -0700
@@ -0,0 +1,28 @@
1+rnd:
2+;;; Returns a pseudorandom number in a.
3+;;; If I've counted correctly, this takes 44 cycles and 29 bytes if
4+;;; micrornd_state is located on the zero page, 56 cycles and 41 bytes
5+;;; if micrornd_state is not on the zero page. In both cases excluding
6+;;; the rts at the end and the sequence to call the procedure. The
7+;;; PRNG uses 4 bytes of state.
8+;;; The four instructions at the beginning can be removed to reduce
9+;;; the size of the state by one byte, the size of the routine by
10+;;; 8 bytes (12 bytes if state is not on the zero page), and the number
11+;;; of clock cycles by 14 (18 if not using zero page).
12+ lda micrornd_state + 1 ; 3 1
13+ eor micrornd_state + 3 ; 6 1
14+ sta micrornd_state + 1 ; 9 1
15+ inc micrornd_state + 3 ; 14 1
16+
17+ lda micrornd_state + 1 ; 17 1
18+ asl ; 19
19+ eor #$d5 ; 21
20+ adc micrornd_state + 2 ; 24 1
21+ sta micrornd_state + 1 ; 27 1
22+ lda micrornd_state + 2 ; 30 1
23+ adc #1 ; 32
24+ sta micrornd_state + 2 ; 35 1
25+ lda micrornd_state ; 38 1
26+ adc micrornd_state + 1 ; 41 1
27+ sta micrornd_state ; 44 1
28+ rts
diff -r 5cd7a04c8f5a -r 0372971e292b apps/micrornd/micrornd_data.inc
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/apps/micrornd/micrornd_data.inc Fri May 24 23:56:45 2019 -0700
@@ -0,0 +1,2 @@
1+micrornd_state:
2+ .byte 0, 0, 0, 0
diff -r 5cd7a04c8f5a -r 0372971e292b apps/micrornd/test.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/apps/micrornd/test.c Fri May 24 23:56:45 2019 -0700
@@ -0,0 +1,58 @@
1+#include "hm1000.h"
2+
3+#include "hm1000.c"
4+
5+#define START 0x0400
6+
7+static void push(hm1k_state *s, uint8_t value) {
8+ s->ram[0x100 + s->s] = value;
9+ --s->s;
10+}
11+
12+static void push_return_address(hm1k_state *s, uint16_t addr) {
13+ --addr;
14+ push(s, addr >> 8);
15+ push(s, addr & 0xff);
16+}
17+
18+int main(int argc, char *argv[]) {
19+ int i;
20+ hm1k_state state;
21+ uint8_t ram[RAM_SIZE];
22+ uint8_t rom[ROM_SIZE];
23+ FILE *f;
24+
25+ randomize(ram, sizeof(ram));
26+ randomize(rom, sizeof(rom));
27+ rom[0x1ffc] = 0;
28+ rom[0x1ffd] = 0x04;
29+ init_6502(&state, ram);
30+ state.rom = rom;
31+ state.io_read[SERIR - IO_BASE] = read_serir;
32+ state.io_write[SERCR - IO_BASE] = write_sercr;
33+ state.kbdrow = 0;
34+ memset(state.keyboard, 0xff, sizeof(state.keyboard));
35+ state.io_read[KBDCOL - IO_BASE] = read_kbdcol;
36+ state.io_write[KBDROW - IO_BASE] = write_kbdrow;
37+ reset(&state);
38+
39+ f = fopen("test.bin", "rb");
40+ if (!f) {
41+ perror("test.bin");
42+ fprintf(stderr, "Could not open test.bin. Have you run make?\n");
43+ return 1;
44+ }
45+ fread(&ram[START], 1, RAM_SIZE - START, f);
46+ fclose(f);
47+
48+ state.s = 0xff;
49+ for (i = 0; i < 0x1000000; i++) {
50+ push_return_address(&state, 0xfffc);
51+ state.pc = START;
52+ while (state.pc != 0xfffc) {
53+ step_6502(&state);
54+ }
55+ printf("%c", state.a);
56+ }
57+ return 0;
58+}
diff -r 5cd7a04c8f5a -r 0372971e292b apps/micrornd/test.s
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/apps/micrornd/test.s Fri May 24 23:56:45 2019 -0700
@@ -0,0 +1,4 @@
1+;;; Test image for testing micrornd in the emulator.
2+ * = $0400
3+#include "micrornd_code.inc"
4+#include "micrornd_data.inc"
Show on old repository browser