Skip to content

Commit f24a2d7

Browse files
committedMar 5, 2018
Fix crash when source file is missing
HCF is now a successful exit Fix crash when source file is missing or unreadable Add fizzbuzz sample
1 parent 09e899f commit f24a2d7

8 files changed

+88
-4
lines changed
 

‎Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CC=gcc
2-
#CFLAGS= -Wall -Wextra -Wpedantic -O3 -std=c11
3-
CFLAGS= -Wall -Wextra -Wpedantic -O0 -std=c11 -g
2+
CFLAGS= -Wall -Wextra -Wpedantic -O3 -std=c11
3+
#CFLAGS= -Wall -Wextra -Wpedantic -O0 -std=c11 -g
44
RM=rm -f
55

66
OBJECTS=tis.o tis_io.o tis_node.o tis_ops.o

‎README.md

+3
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@ A TIS-100 emulator, for the wonderful Zachtronics game of the same name. Uses TI
33

44
None of the others available did quite what I wanted, so I'm going to try my hand at making my own.
55

6+
This is all very WIP, so a bunch of things aren't implemented. However, the instruction set should be functional
7+
and complete. Also no documentation yet, sorry. It's on my short list.
8+
69
(useful links for dev'ment:)
710
https://alandesmet.github.io/TIS-100-Hackers-Guide/

‎sample/fizzbuzz.tisasm

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
@0
2+
## FizzBuzz
3+
# shuttle
4+
MOV RIGHT DOWN
5+
MOV DOWN RIGHT
6+
@1
7+
# div 3
8+
MOV RIGHT DOWN
9+
MOV DOWN NIL
10+
MOV RIGHT DOWN
11+
MOV DOWN NIL
12+
MOV RIGHT LEFT
13+
MOV LEFT DOWN
14+
MOV DOWN NIL
15+
@2
16+
# counter
17+
S: SUB 100
18+
JGZ Q
19+
ADD 101
20+
MOV ACC LEFT
21+
JMP S
22+
Q: HCF
23+
@3
24+
# shuttle
25+
MOV UP DOWN
26+
MOV DOWN UP
27+
@4
28+
# div 5
29+
MOV UP DOWN
30+
MOV NIL UP
31+
MOV UP DOWN
32+
MOV NIL UP
33+
MOV UP DOWN
34+
MOV NIL UP
35+
MOV UP DOWN
36+
MOV NIL UP
37+
MOV UP RIGHT
38+
MOV RIGHT DOWN
39+
MOV NIL UP
40+
@5
41+
# shuttle
42+
MOV LEFT DOWN
43+
MOV DOWN LEFT
44+
@6
45+
# print Fizz
46+
MOV UP NIL
47+
MOV 70 DOWN
48+
MOV 105 DOWN
49+
MOV 122 DOWN
50+
MOV 122 DOWN
51+
MOV NIL UP
52+
@7
53+
# print numbers
54+
MOV ANY ACC
55+
JEZ N
56+
MOV ACC DOWN
57+
N: MOV -1 RIGHT
58+
@8
59+
# print Buzz + \n
60+
S: MOV ANY ACC
61+
JLZ N
62+
MOV 66 DOWN
63+
MOV 117 DOWN
64+
MOV 122 DOWN
65+
MOV 122 DOWN
66+
MOV NIL UP
67+
JMP S
68+
N: MOV 10 DOWN

‎sample/fizzbuzz.tiscfg

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
3 3
2+
CCC
3+
CCC
4+
CCC
5+
O0 ASCII -
6+
O1 NUMERIC -
7+
O2 ASCII -

‎sample/hello.tisasm

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ MOV 114 DOWN
1212
MOV 108 DOWN
1313
MOV 100 DOWN
1414
MOV 33 DOWN
15-
MOV 0 UP
15+
MOV 10 DOWN
16+
HCF

‎tis.c

+4
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,10 @@ int init_layout(tis_t* tis, char* layoutfile, int layoutmode) {
259259

260260
int init_nodes(tis_t* tis, char* sourcefile) {
261261
FILE* source = fopen(sourcefile, "r");
262+
if(source == NULL) {
263+
error("Unable to open source file '%s' for reading\n", sourcefile);
264+
return INIT_FAIL;
265+
}
262266

263267
char buf[BUFSIZE];
264268
int id = -1, preid = -1;

‎tis_ops.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ tis_op_result_t step(tis_t* tis, tis_node_t* node, tis_op_t* op) {
2727
}
2828
break;
2929
case TIS_OP_TYPE_HCF:
30-
custom_abort();
30+
halt();
3131
break;
3232
case TIS_OP_TYPE_JEZ:
3333
if(node->acc == 0) {

‎tis_types.h

+1
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ extern tis_opt_t opts;
252252
#define error(...) do { if(opts.verbose >= -1) { fprintf(stderr, "ERROR:\t"__VA_ARGS__); } } while(0)
253253

254254
#define custom_abort() exit(EXIT_FAILURE)
255+
#define halt() exit(EXIT_SUCCESS)
255256

256257
/*
257258
* Begin inlines

0 commit comments

Comments
 (0)
Please sign in to comment.