X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;ds=sidebyside;f=ROM2%2Fhelpers.c;h=13c2d36360a8484317a94f087db8e39e3678ec90;hb=refs%2Fheads%2Fmaster;hp=f336ae103f20722be300430f9957b8662f8fd504;hpb=a1106ee52492a26f91897578c0761d1aedf6b44c;p=uccvend-snackrom.git diff --git a/ROM2/helpers.c b/ROM2/helpers.c index f336ae1..13c2d36 100644 --- a/ROM2/helpers.c +++ b/ROM2/helpers.c @@ -2,18 +2,9 @@ #include "vend.h" void delay(u16 ms) { - /* delay routine written in assembly so we know what we're really getting. - * each inner loop should take ~1 ms to execute. - * 15 cycles * (1/4.9152Mhz) * 327 = 0.997 ms + a little bit on the fringes. - * - * XXX - how do we know gcc isn't optimising this? it seems to optimise after - * parsing C -> asm, but before asm -> machine code. - */ - //asm volatile ("pshx\npsha\npshb\n"); /* save registers */ asm volatile ("ldx %0\n" :: "m" (ms) : "x"); asm volatile ( "delay_loop:\n" - //" ldd #327\n" /* 3 */ " ldd #150\n" /* 3 */ "delay_inner_loop:\n" /* 15 cycles each */ " cpd #0x0000\n" /* 5 */ @@ -25,9 +16,6 @@ void delay(u16 ms) { " beq delay_out\n" /* 3 */ " bra delay_loop\n" /* 3 */ "delay_out:\n" ::: "x", "d"); - /*" pulb\n" - " pula\n" - " pulx\n");*/ } u8 my_strlen(char* s) { @@ -61,3 +49,36 @@ void my_memset(char* dst, u8 val, u16 count) { char* c; for (c = dst; c < dst+count; c++) *c = val; } + +u8 hexchar2u8(char b) { + if (b >= '0' && b <= '9') return b-'0'; + if (b >= 'a' && b <= 'f') return b-'a'+0x0a; + if (b >= 'A' && b <= 'F') return b-'A'+0x0a; + return 0; +} + +char nibble2hexchar(u8 b) { + if (b <= 9) return b+'0'; + if (b >= 10 && b <= 15) return b+'A'-10; + return 'X'; +} + +u8 hex2u8(char msb, char lsb) { + return (hexchar2u8(msb) << 4) + hexchar2u8(lsb); +} + +static char hexconv_buf[3]; +char* u82hex(u8 a) { + hexconv_buf[0] = nibble2hexchar((a&0xf0) >> 4); + hexconv_buf[1] = nibble2hexchar(a&0x0f); + hexconv_buf[2] = '\0'; + return hexconv_buf; +} + +bool ishex(char b) { + if (b >= '0' && b <= '9') return 1; + if (b >= 'a' && b <= 'f') return 1; + if (b >= 'A' && b <= 'F') return 1; + return 0; +} +