Added flag which forces the printing of hexes

Anything other than char (which can just use print.byte to print the
hex) and byte (which prints hexes anyway), all other types may be
forced to print a hex rather than a number if PRINT_HEX is 1.
This commit is contained in:
2023-10-31 22:29:07 +00:00
parent 0f0a1c7699
commit 5045452d7a
2 changed files with 31 additions and 4 deletions

View File

@@ -27,6 +27,9 @@
#ifndef VERBOSE
#define VERBOSE 0
#endif
#ifndef PRINT_HEX
#define PRINT_HEX 0
#endif
typedef uint8_t u8;
typedef int8_t i8;

View File

@@ -195,18 +195,42 @@ err_t vm_execute(vm_t *vm)
printf("0x%x", datum.as_byte);
break;
case TYPE_INT: {
printf("%" PRId32, datum.as_int);
printf(
#if PRINT_HEX == 1
"0x%X",
#else
"%" PRId32,
#endif
datum.as_int);
break;
}
case TYPE_HWORD:
printf("%" PRIu32, datum.as_hword);
printf(
#if PRINT_HEX == 1
"0x%X",
#else
"%" PRIu32,
#endif
datum.as_hword);
break;
case TYPE_LONG: {
printf("%" PRId64, datum.as_long);
printf(
#if PRINT_HEX == 1
"0x%dX",
#else
"%" PRId64,
#endif
datum.as_long);
break;
}
case TYPE_WORD:
printf("%" PRIu64, datum.as_word);
printf(
#if PRINT_HEX == 1
"0x%lX",
#else
"%" PRIu64,
#endif
datum.as_word);
break;
}