uxn

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

console.c (1018B)


      1 #include <stdio.h>
      2 #include <stdlib.h>
      3 
      4 #include "../uxn.h"
      5 #include "console.h"
      6 
      7 /*
      8 Copyright (c) 2022-2023 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(Uxn *u, char c, int type)
     20 {
     21 	Uint8 *d = &u->dev[0x10];
     22 	d[0x2] = c;
     23 	d[0x7] = type;
     24 	return uxn_eval(u, PEEK2(d));
     25 }
     26 
     27 void
     28 console_listen(Uxn *u, int i, int argc, char **argv)
     29 {
     30 	for(; i < argc; i++) {
     31 		char *p = argv[i];
     32 		while(*p) console_input(u, *p++, CONSOLE_ARG);
     33 		console_input(u, '\n', i == argc - 1 ? CONSOLE_END : CONSOLE_EOA);
     34 	}
     35 }
     36 
     37 void
     38 console_deo(Uint8 *d, Uint8 port)
     39 {
     40 	switch(port) {
     41 	case 0x8:
     42 		fputc(d[port], stdout);
     43 		fflush(stdout);
     44 		return;
     45 	case 0x9:
     46 		fputc(d[port], stderr);
     47 		fflush(stderr);
     48 		return;
     49 	}
     50 }