make new charset

This commit is contained in:
sfja 2025-03-31 15:23:07 +02:00
parent db6e20b4b1
commit ab55a9ff16
2 changed files with 72 additions and 29 deletions

View File

@ -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) void assemble_to_binary(uint16_t* out, const Line* lines, size_t lines_size)
{ {
bool debug = false;
uint16_t ip = 0; uint16_t ip = 0;
typedef struct { typedef struct {
@ -218,8 +220,11 @@ void assemble_to_binary(uint16_t* out, const Line* lines, size_t lines_size)
out[ip++] = 0; \ out[ip++] = 0; \
} }
printf("assembling...\n"); if (debug) {
printf("ip op n data...\n"); printf("assembling...\n");
printf("ip op n data...\n");
}
for (size_t i = 0; i < lines_size; ++i) { for (size_t i = 0; i < lines_size; ++i) {
bool is_label = false; bool is_label = false;
bool is_data = 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) { if (debug) {
printf("%02x %-5s %d", if (!is_label) {
ins_ip * 2, printf("%02x %-5s %d",
is_data ? "data" : op_str(out[ins_ip] & 0x3f), ins_ip * 2,
ip - ins_ip); is_data ? "data" : op_str(out[ins_ip] & 0x3f),
for (uint16_t i = 0; i < ip - ins_ip; ++i) { ip - ins_ip);
printf(" %02x %c%c%c%c %c%c%c%c %02x %c%c%c%c %c%c%c%c ", for (uint16_t i = 0; i < ip - ins_ip; ++i) {
out[ins_ip + i] & 0xff, printf(" %02x %c%c%c%c %c%c%c%c %02x %c%c%c%c %c%c%c%c ",
fmt_binary(out[ins_ip + i] & 0xff), out[ins_ip + i] & 0xff,
out[ins_ip + i] >> 8, fmt_binary(out[ins_ip + i] & 0xff),
fmt_binary(out[ins_ip + i] >> 8)); out[ins_ip + i] >> 8,
fmt_binary(out[ins_ip + i] >> 8));
}
printf("\n");
} }
printf("\n");
} }
} }
printf("resolving...\n"); if (debug) {
printf(" l ip v data\n"); printf("resolving...\n");
printf(" l ip v data\n");
}
for (size_t i = 0; i < unres_labels_size; ++i) { for (size_t i = 0; i < unres_labels_size; ++i) {
bool found = false; bool found = false;
for (size_t j = 0; j < res_labels_size; ++j) { 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; out[unres_labels[i].ptr] = res_labels[j].ip;
found = true; found = true;
printf("%2d %02x %02x %02x %c%c%c%c %c%c%c%c %02x %c%c%c%c " if (debug) {
"%c%c%c%c\n", printf(
res_labels[j].label, "%2d %02x %02x %02x %c%c%c%c %c%c%c%c %02x %c%c%c%c "
unres_labels[i].ptr * 2, "%c%c%c%c\n",
res_labels[j].ip, res_labels[j].label,
out[unres_labels[i].ptr] & 0xff, unres_labels[i].ptr * 2,
fmt_binary(out[unres_labels[i].ptr] & 0xff), res_labels[j].ip,
out[unres_labels[i].ptr] >> 8, out[unres_labels[i].ptr] & 0xff,
fmt_binary(out[unres_labels[i].ptr] >> 8)); fmt_binary(out[unres_labels[i].ptr] & 0xff),
out[unres_labels[i].ptr] >> 8,
fmt_binary(out[unres_labels[i].ptr] >> 8));
}
break; break;
} }
} }
@ -517,7 +529,9 @@ void assemble_to_binary(uint16_t* out, const Line* lines, size_t lines_size)
unres_labels[i].label); unres_labels[i].label);
} }
} }
printf("done!\n"); if (debug) {
printf("done!\n");
}
} }
static inline void add_dst_reg(uint32_t* ins, uint16_t reg) static inline void add_dst_reg(uint32_t* ins, uint16_t reg)

View File

@ -184,6 +184,7 @@ void sdldevice_destroy(SdlDevice* device)
} }
extern const bool charset[][ch_height][ch_width]; 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) 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_y = 0; ch_y < ch_height; ++ch_y) {
for (int ch_x = 0; ch_x < ch_width; ++ch_x) { 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_y = 0; px_y < px_height; ++px_y) {
for (int px_x = 0; px_x < px_width; ++px_x) { 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 y = 0; y < ch_height; ++y) {
for (int x = 0; x < ch_width; ++x) { for (int x = 0; x < ch_width; ++x) {
if (charset[i][y][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); printf("['%c'] = 0x%lX,\n", i, ch);
} }
return 0; // return 0;
MemDrive drive; MemDrive drive;
memdrive_construct(&drive, (uint64_t*)program, 512); memdrive_construct(&drive, (uint64_t*)program, 512);
@ -505,6 +508,32 @@ const char* __asan_default_options(void)
const uint64_t charset_2[] = { const uint64_t charset_2[] = {
[' '] = 0x0000000000000000, [' '] = 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, #define _ false,