MicroCorruption/common/io.c
2023-01-09 01:39:54 -06:00

57 lines
1005 B
C

#ifndef __uC_IO_C__
#define __uC_IO_C__
#include <stdio.h>
#include <string.h>
#include "mem.h"
// 512 600 0011
int flag_enable_0x7f = 1;
void INT (int arg, ...) {
switch (arg) {
case 0x40:
flag_enable_0x7f = 0;
break;
case 0x7f:
if(flag_enable_0x7f) {
printf("The lock is now open.\n");
exit(0);
}
break;
default:
printf("INT(0x%02x, ...) unimplemented", arg);
}
}
char hascii(int i) {
if (i > '9')
i += 9;
return i & 0x0f;
}
// gets (getsn)
void getsn (char* buf, size_t size) {
char *temp = malloc(size*2);
fgets(temp, size*2, stdin);
for (int i = 0; i < size * 2; i+=2) {
buf[i/2] = ((hascii(temp[i]))<<4)|(hascii(temp[i+1]));
printf("%02x", buf[i/2] & 0xff);
}
printf("\n");
free(temp);
}
// putchar
// int putchar (int c);
// puts
// int puts(const char *);
// printf
//int printf (const char * restrict format_str, ...);
#endif // __uC_IO_C__