diff --git a/vm/asm.c b/vm/asm.c index 79e5ae5..de65851 100644 --- a/vm/asm.c +++ b/vm/asm.c @@ -195,6 +195,8 @@ static inline uint16_t linety_arithm_ins(LineTy ty); void assemble_to_binary(uint16_t* out, const Line* lines, size_t lines_size) { + bool debug = false; + uint16_t ip = 0; typedef struct { @@ -218,8 +220,11 @@ void assemble_to_binary(uint16_t* out, const Line* lines, size_t lines_size) out[ip++] = 0; \ } - printf("assembling...\n"); - printf("ip op n data...\n"); + if (debug) { + printf("assembling...\n"); + printf("ip op n data...\n"); + } + for (size_t i = 0; i < lines_size; ++i) { bool is_label = false; bool is_data = false; @@ -474,24 +479,28 @@ void assemble_to_binary(uint16_t* out, const Line* lines, size_t lines_size) } } - if (!is_label) { - printf("%02x %-5s %d", - ins_ip * 2, - is_data ? "data" : op_str(out[ins_ip] & 0x3f), - ip - ins_ip); - for (uint16_t i = 0; i < ip - ins_ip; ++i) { - printf(" %02x %c%c%c%c %c%c%c%c %02x %c%c%c%c %c%c%c%c ", - out[ins_ip + i] & 0xff, - fmt_binary(out[ins_ip + i] & 0xff), - out[ins_ip + i] >> 8, - fmt_binary(out[ins_ip + i] >> 8)); + if (debug) { + if (!is_label) { + printf("%02x %-5s %d", + ins_ip * 2, + is_data ? "data" : op_str(out[ins_ip] & 0x3f), + ip - ins_ip); + for (uint16_t i = 0; i < ip - ins_ip; ++i) { + printf(" %02x %c%c%c%c %c%c%c%c %02x %c%c%c%c %c%c%c%c ", + out[ins_ip + i] & 0xff, + fmt_binary(out[ins_ip + i] & 0xff), + out[ins_ip + i] >> 8, + fmt_binary(out[ins_ip + i] >> 8)); + } + printf("\n"); } - printf("\n"); } } - printf("resolving...\n"); - printf(" l ip v data\n"); + if (debug) { + printf("resolving...\n"); + printf(" l ip v data\n"); + } for (size_t i = 0; i < unres_labels_size; ++i) { bool found = false; for (size_t j = 0; j < res_labels_size; ++j) { @@ -499,15 +508,18 @@ void assemble_to_binary(uint16_t* out, const Line* lines, size_t lines_size) out[unres_labels[i].ptr] = res_labels[j].ip; found = true; - printf("%2d %02x %02x %02x %c%c%c%c %c%c%c%c %02x %c%c%c%c " - "%c%c%c%c\n", - res_labels[j].label, - unres_labels[i].ptr * 2, - res_labels[j].ip, - out[unres_labels[i].ptr] & 0xff, - fmt_binary(out[unres_labels[i].ptr] & 0xff), - out[unres_labels[i].ptr] >> 8, - fmt_binary(out[unres_labels[i].ptr] >> 8)); + if (debug) { + printf( + "%2d %02x %02x %02x %c%c%c%c %c%c%c%c %02x %c%c%c%c " + "%c%c%c%c\n", + res_labels[j].label, + unres_labels[i].ptr * 2, + res_labels[j].ip, + out[unres_labels[i].ptr] & 0xff, + fmt_binary(out[unres_labels[i].ptr] & 0xff), + out[unres_labels[i].ptr] >> 8, + fmt_binary(out[unres_labels[i].ptr] >> 8)); + } break; } } @@ -517,7 +529,9 @@ void assemble_to_binary(uint16_t* out, const Line* lines, size_t lines_size) unres_labels[i].label); } } - printf("done!\n"); + if (debug) { + printf("done!\n"); + } } static inline void add_dst_reg(uint32_t* ins, uint16_t reg) diff --git a/vm/main.c b/vm/main.c index 762e8e4..b493b3a 100644 --- a/vm/main.c +++ b/vm/main.c @@ -184,6 +184,7 @@ void sdldevice_destroy(SdlDevice* device) } extern const bool charset[][ch_height][ch_width]; +extern const uint64_t charset_2[]; void sdldevice_set_char(IODevice* io_device, uint16_t offset, uint8_t value) { @@ -207,7 +208,9 @@ void sdldevice_set_char(IODevice* io_device, uint16_t offset, uint8_t value) for (int ch_y = 0; ch_y < ch_height; ++ch_y) { for (int ch_x = 0; ch_x < ch_width; ++ch_x) { - bool ch = charset[value][ch_y][ch_x]; + bool ch + = charset_2[value] >> (ch_y * ch_width + (ch_width - ch_x - 1)) + & 1; for (int px_y = 0; px_y < px_height; ++px_y) { for (int px_x = 0; px_x < px_width; ++px_x) { @@ -475,14 +478,14 @@ int main(void) for (int y = 0; y < ch_height; ++y) { for (int x = 0; x < ch_width; ++x) { if (charset[i][y][x]) { - ch |= 1 << (y * ch_width + (ch_height - x - 1)); + ch |= 1ul << (y * ch_width + (ch_height - x - 1)); } } } printf("['%c'] = 0x%lX,\n", i, ch); } - return 0; + // return 0; MemDrive drive; memdrive_construct(&drive, (uint64_t*)program, 512); @@ -505,6 +508,32 @@ const char* __asan_default_options(void) const uint64_t charset_2[] = { [' '] = 0x0000000000000000, + ['A'] = 0x66667E66667E1800, + ['B'] = 0x7C7E667C667E7800, + ['C'] = 0x3C7E6060607E3C00, + ['D'] = 0x7C7E6666667E7C00, + ['E'] = 0x7E7E607E607E7E00, + ['F'] = 0x60607878607E7E00, + ['G'] = 0x7E7E666E607E7E00, + ['H'] = 0x6666667E7E666600, + ['I'] = 0x7E7E1818187E7E00, + ['J'] = 0x3C7E6606067E7E00, + ['K'] = 0x666E7C7C6E666600, + ['L'] = 0x7E7E606060606000, + ['M'] = 0xC3C3C3C3DBFFE700, + ['N'] = 0x6666666E7E766600, + ['O'] = 0x3C66666666663C00, + ['P'] = 0x60607C7E667C7C00, + ['Q'] = 0x3F7E6E66667E3C00, + ['R'] = 0x666C7C7E667E7C00, + ['S'] = 0x3C66063C60663C00, + ['T'] = 0x18181818187E7E00, + ['U'] = 0x3C7E666666666600, + ['V'] = 0x183C7E6666666600, + ['W'] = 0xE7FFDBDBC3C3C300, + ['X'] = 0x6666663C3C666600, + ['Y'] = 0x181818183C666600, + ['Z'] = 0x7E7E30180C7E7E00, }; #define _ false,