Skip to content

Commit 8de7f81

Browse files
committed
Add getchar, putchar functions
1 parent 00beefa commit 8de7f81

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

core/c4.c

+5
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ enum {
6060
OR ,XOR ,AND ,EQ ,NE ,LT ,GT ,LE ,GE ,SHL ,SHR ,ADD ,SUB ,MUL ,DIV ,MOD ,
6161
// C functions
6262
OPEN,READ,CLOS,PRTF,DPRT,MALC,FREE,MSET,MCMP,EXIT,FDSZ,
63+
GETC,PUTC,
6364
// Platform related functions
6465
PINI,RPTH,PLGT,
6566
// VM related functions
@@ -78,6 +79,7 @@ void setup_opcodes() {
7879
"SC ,PSH ,OR ,XOR ,AND ,EQ ,NE ,LT ,GT ,LE ,GE ,SHL ,"
7980
"SHR ,ADD ,SUB ,MUL ,DIV ,MOD ,"
8081
"OPEN,READ,CLOS,PRTF,DPRT,MALC,FREE,MSET,MCMP,EXIT,FDSZ,"
82+
"GETC,PUTC",
8183
"PINI,RPTH,PLGT,"
8284
"PCHG,"
8385
"SYS1,SYS2,SYS3,SYS4,SYS5,SYS6,SYSI,SYSM";
@@ -91,6 +93,7 @@ void setup_symbols() {
9193
"char else enum if int return sizeof include while "
9294
// C functions
9395
"open read close printf dprintf malloc free memset memcmp exit fdsize "
96+
"getchar putchar "
9497
// Dynamic runtime platform functions
9598
"platform_init runtime_path platform_get "
9699
"process_changed "
@@ -902,6 +905,8 @@ int run_cycle(int *process, int cycles) {
902905
process[B_exitcode] = *sp;
903906
rem_cycle = 0;
904907
}
908+
else if (i == GETC) { a = (int)getchar(); }
909+
else if (i == PUTC) { a = putchar(*sp); }
905910
else if (i == SYS1) { a = (int)syscall1(*sp); }
906911
else if (i == SYS2) { a = (int)syscall2(sp[1], *sp); }
907912
else if (i == SYS3) { a = (int)syscall3(sp[2], sp[1], *sp); }

0 commit comments

Comments
 (0)