uxn

Varvara Ordinator, written in ANSI C(SDL2)
git clone https://git.eamoncaddigan.net/uxn.git
Log | Files | Refs | README | LICENSE

console.c (1058B)


      1 #include <stdio.h>
      2 #include <stdlib.h>
      3 
      4 #include "../uxn.h"
      5 #include "console.h"
      6 
      7 /*
      8 Copyright (c) 2022-2024 Devine Lu Linvega, Andrew Alderwick
      9 
     10 Permission to use, copy, modify, and distribute this software for any
     11 purpose with or without fee is hereby granted, provided that the above
     12 copyright notice and this permission notice appear in all copies.
     13 
     14 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
     15 WITH REGARD TO THIS SOFTWARE.
     16 */
     17 
     18 int
     19 console_input(int c, int type)
     20 {
     21 	if(c == EOF) c = 0, type = 4;
     22 	uxn.dev[0x12] = c, uxn.dev[0x17] = type;
     23 	uxn_eval(uxn.dev[0x10] << 8 | uxn.dev[0x11]);
     24 	return type != 4;
     25 }
     26 
     27 void
     28 console_listen(int i, int argc, char **argv)
     29 {
     30 	for(; i < argc; i++) {
     31 		char *p = argv[i];
     32 		while(*p) console_input(*p++, CONSOLE_ARG);
     33 		console_input('\n', i == argc - 1 ? CONSOLE_END : CONSOLE_EOA);
     34 	}
     35 }
     36 
     37 void
     38 console_deo(Uint8 addr)
     39 {
     40 	FILE *fd;
     41 	switch(addr) {
     42 	case 0x18: fd = stdout, fputc(uxn.dev[0x18], fd), fflush(fd); break;
     43 	case 0x19: fd = stderr, fputc(uxn.dev[0x19], fd), fflush(fd); break;
     44 	}
     45 }