MicroCorruption/common/io.c

40 lines
672 B
C
Raw Normal View History

2022-12-12 03:03:53 +00:00
#ifndef __uC_IO_C__
#define __uC_IO_C__
#include <stdio.h>
#include <string.h>
#include "mem.h"
// 512 600 0011
void INT (int 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__