Printer compression support

This commit is contained in:
Lior Halphon 2017-01-20 23:00:02 +02:00
parent 8cd82ebb68
commit 517e72f92b
2 changed files with 26 additions and 1 deletions

View File

@ -110,7 +110,28 @@ static void serial_start(GB_gameboy_t *gb, uint8_t byte_received)
case GB_PRINTER_COMMAND_DATA: case GB_PRINTER_COMMAND_DATA:
if (gb->printer.command_length != GB_PRINTER_MAX_COMMAND_LENGTH) { if (gb->printer.command_length != GB_PRINTER_MAX_COMMAND_LENGTH) {
if (gb->printer.compression) {
if (!gb->printer.compression_run_lenth) {
gb->printer.compression_run_is_compressed = byte_received & 0x80;
gb->printer.compression_run_lenth = (byte_received & 0x7F) + 1 + gb->printer.compression_run_is_compressed;
}
else if (gb->printer.compression_run_is_compressed) {
while (gb->printer.compression_run_lenth) {
gb->printer.command_data[gb->printer.command_length++] = byte_received; gb->printer.command_data[gb->printer.command_length++] = byte_received;
gb->printer.compression_run_lenth--;
if (gb->printer.command_length == GB_PRINTER_MAX_COMMAND_LENGTH) {
gb->printer.compression_run_lenth = 0;
}
}
}
else {
gb->printer.command_data[gb->printer.command_length++] = byte_received;
gb->printer.compression_run_lenth--;
}
}
else {
gb->printer.command_data[gb->printer.command_length++] = byte_received;
}
} }
gb->printer.length_left--; gb->printer.length_left--;
break; break;
@ -173,6 +194,7 @@ static uint8_t serial_end(GB_gameboy_t *gb)
void GB_connect_printer(GB_gameboy_t *gb, GB_print_image_callback_t callback) void GB_connect_printer(GB_gameboy_t *gb, GB_print_image_callback_t callback)
{ {
memset(&gb->printer, 0, sizeof(gb->printer));
GB_set_serial_transfer_start_callback(gb, serial_start); GB_set_serial_transfer_start_callback(gb, serial_start);
GB_set_serial_transfer_end_callback(gb, serial_end); GB_set_serial_transfer_end_callback(gb, serial_end);
gb->printer.callback = callback; gb->printer.callback = callback;

View File

@ -51,6 +51,9 @@ typedef struct
uint16_t image_offset; uint16_t image_offset;
GB_print_image_callback_t callback; GB_print_image_callback_t callback;
uint8_t compression_run_lenth;
bool compression_run_is_compressed;
} GB_printer_t; } GB_printer_t;