git.y1.nz

SameBoy

Accurate GB/GBC emulator
download: https://git.y1.nz/archives/sameboy.tar.gz
README | Files | Log | Refs | LICENSE

commit ce44773caa26d6364c60895ae7bd3c770450d63d
parent cb721dae5d442fc592dea73b907228e515afc1fb
Author: Lior Halphon <LIJI32@gmail.com>
Date:   Fri, 26 Feb 2021 16:40:35 +0200

Make the printer not deadlock after a sudden termination

Diffstat:
MCore/printer.c10+++++++---
MCore/printer.h3+--
MCore/timing.c3+++
3 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/Core/printer.c b/Core/printer.c @@ -11,7 +11,6 @@ static void handle_command(GB_gameboy_t *gb) { - switch (gb->printer.command_id) { case GB_PRINTER_INIT_COMMAND: gb->printer.status = 0; @@ -71,7 +70,7 @@ static void handle_command(GB_gameboy_t *gb) } -static void byte_reieve_completed(GB_gameboy_t *gb, uint8_t byte_received) +static void byte_recieve_completed(GB_gameboy_t *gb, uint8_t byte_received) { gb->printer.byte_to_send = 0; switch (gb->printer.command_state) { @@ -189,11 +188,16 @@ static void byte_reieve_completed(GB_gameboy_t *gb, uint8_t byte_received) static void serial_start(GB_gameboy_t *gb, bool bit_received) { + if (gb->printer.idle_time > GB_get_unmultiplied_clock_rate(gb)) { + gb->printer.command_state = GB_PRINTER_COMMAND_MAGIC1; + gb->printer.bits_received = 0; + } + gb->printer.idle_time = 0; gb->printer.byte_being_received <<= 1; gb->printer.byte_being_received |= bit_received; gb->printer.bits_received++; if (gb->printer.bits_received == 8) { - byte_reieve_completed(gb, gb->printer.byte_being_received); + byte_recieve_completed(gb, gb->printer.byte_being_received); gb->printer.bits_received = 0; gb->printer.byte_being_received = 0; } diff --git a/Core/printer.h b/Core/printer.h @@ -48,8 +48,7 @@ typedef struct uint8_t image[160 * 200]; uint16_t image_offset; - /* TODO: Delete me. */ - uint64_t padding; + uint64_t idle_time; uint8_t compression_run_lenth; bool compression_run_is_compressed; diff --git a/Core/timing.c b/Core/timing.c @@ -198,6 +198,9 @@ main: static void advance_serial(GB_gameboy_t *gb, uint8_t cycles) { + if (gb->printer.command_state || gb->printer.bits_received) { + gb->printer.idle_time += cycles; + } if (gb->serial_length == 0) { gb->serial_cycles += cycles; return;

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.