ROSE/print.c

46 lines
1008 B
C
Raw Normal View History

2022-09-14 21:54:59 -05:00
#include "print.h"
char nibbleToHex(uint8_t n) {
return n > 9 ? (n - 10) + 'A' : n + '0';
}
uintptr_t printByte(uint8_t v, uint16_t *buff) {
2022-09-14 21:54:59 -05:00
*(char *)&buff[0] = nibbleToHex((v >> 4) & 0xF);
*(char *)&buff[1] = nibbleToHex(v & 0xF);
return 2;
2022-09-14 21:54:59 -05:00
}
uintptr_t printWord(uint16_t v, uint16_t *buff) {
2022-09-14 21:54:59 -05:00
printByte(v >> 8, buff);
printByte(v, &buff[2]);
return 4;
2022-09-14 21:54:59 -05:00
}
uintptr_t printDword(uint32_t v, uint16_t *buff) {
2022-09-14 21:54:59 -05:00
printWord(v >> 16, buff);
printWord(v, &buff[4]);
return 8;
}
uintptr_t printStr(char *v, uint16_t *buff) {
char *s;
for (s = v;*s;s++,buff++)
*(char*)buff = *s;
return s - v;
2022-09-14 21:54:59 -05:00
}
2023-01-04 19:36:29 -06:00
uintptr_t printChar(char v, uint16_t *buff) {
*(char*)buff = v;
return 1;
}
2023-01-04 19:36:29 -06:00
uintptr_t printDec(uint32_t v, uint16_t *buff) {
char b[12];
char *s = &b[11];
if (!v) {
*(uint16_t*)&b[10] = '0'; // '0',0x00
s = &b[10];
} else {
*s = 0;
for (;v;v/=10) *--s = '0' + v%10;
}
return printStr(s, buff);
}