summaryrefslogtreecommitdiffstats
path: root/patches/cbmbasic/0001-Add-IOBASE-and-pseudo-timer-will-give-RND-functional.patch
blob: f455d0a14c498bc5d9991e439c877c542350307a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
From: Wolfram Sang <ninja@the-dreams.de>
Date: Sat, 29 Oct 2011 19:01:11 +0200
Subject: [PATCH] Add IOBASE and pseudo-timer (will give RND-functionality)

Signed-off-by: Wolfram Sang <ninja@the-dreams.de>

# ---
# 20091210 rsc: check if there is another upstream version
# 20081127 wsa: already sent mainline and accepted.
---
 runtime.c |   14 ++++++++++++--
 1 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/runtime.c b/runtime.c
index 454000e..2c3c54b 100644
--- a/runtime.c
+++ b/runtime.c
@@ -29,6 +29,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+#include <time.h>
 
 unsigned char RAM[65536];
 
@@ -155,6 +156,7 @@ init_os(int argc, char **argv) {
 		interactive = 1;
 		f = NULL;
 	}
+	srand(time(NULL));
 }
 
 static void
@@ -565,8 +567,16 @@ PLOT() {
 /* IOBASE */
 static void
 IOBASE() {
-		printf("UNIMPL: IOBASE\n");
-		exit(1);
+		/*
+		 * IOBASE is just used inside RND to get a timer value.
+		 * So, let's fake this here, too.
+		 */
+		int pseudo_timer = rand();
+		RAM[0xDC04] = pseudo_timer&0xff;
+		RAM[0xDC05] = pseudo_timer>>8;
+
+		X = 0x00;
+		Y = 0xDC;
 }
 
 int