<commit_before>The Blast ! Debugger protocol v2
================================

Electrical specification.
-------------------------

Connected receiver must be open collector, with no pull-up. For output, pull
the pin to low or release it for high. For input, just read logic value.  This
will avoid problems when switching direction.

Port mapping / pinout

Looking at the console socket :

     -----------
    \ 1 2 3 4 5 /
     \ 6 7 8 9 /
       -------

    Pin Bit Ard Name Mon.Out  Mon.In  Pad0  Pad1 Serial
     1   0    4   D0      D0      D0    Up    Up      -
     2   1    5   D1      D1      D1  Down  Down      -
     3   2    6   D2      D2      D2     0  Left      -
     4   3    7   D3      D3      D3     0 Right      -
     5   -   NC  Vcc       -       -     -     -      -
     6   4    8   TL  Clk/In  Clk/In     A     B     Tx
     7   6    3   TH Clk/Out Clk/Out   Sel   Sel    INT
     8   -  GND  GND       -       -     -     -      -
     9   5    9   TR  Mode:1  Mode:0 Start     C     Rx
    NC   7    -   -        -       -    ?      ?      -

Bit is the control bit of the port register in the genesis.

Ard is the Arduino pin. To remap pins, you must modify the Arduino source code.

Pad0 is the value returned by the gamepad when Sel is low, Pad1 is the state
when Sel is high. Serial is the pin role when the port is in serial mode
(unused in blast debugger).

TR pin indicates communication direction : If high, genesis sends data to
the arduino ; if TR is low, genesis is waiting for incoming data. This pin also
indicates whether the arduino is allowed to set D0..D3 as outputs or not.

When TR is high (genesis sends data), TL is the clock and TH is the ack pulse.
When TR is low (arduino sends data), TH is the clock and TL is the ack pulse.

When transmission is inactive, TH must be set to pull-up input, in case the
genesis polls the gamepad on that port, which could cause a short-circuit.

Byte transmission format
------------------------

The debug mode communicates via D-Pad data lines, passing 4 bits per clock.
Format is big nybble first. For example, to pass 0xA3, digit A would be passed
first, then 3. Each nybble is acknowledged by a transition. 5V pull-up is logic
high and 0V is logic low. When unused, pins should be high.

Example transmitting 0xA4 to the genesis :

    D0..D3       A               4
          _                               ____
    D0 --- \_____________________________/    ------ output
          ________________                ____
    D1 ---                \______________/    ------ output
          _                ___________________
    D2 --- \______________/                   ------ output
          ________________                ____<commit_msg>Update debug_protocol.md<commit_after>The Blast ! Debugger protocol v2
================================

Electrical specification.
-------------------------

The genesis uses 5V logic : 5V for logic high and 0V for logic low.
The genesis has an internal pull-up on input pins, and output pins
are regular outputs (not open collector).

Port mapping / pinout

Looking at the console socket :

     -----------
    \ 1 2 3 4 5 /
     \ 6 7 8 9 /
       -------

    Pin Bit Ard Name Mon.Out  Mon.In  Pad0  Pad1 Serial
     1   0    4   D0      D0      D0    Up    Up      -
     2   1    5   D1      D1      D1  Down  Down      -
     3   2    6   D2      D2      D2     0  Left      -
     4   3    7   D3      D3      D3     0 Right      -
     5   -   NC  Vcc       -       -     -     -      -
     6   4    8   TL  Clk/In  Clk/In     A     B     Tx
     7   6    3   TH Clk/Out Clk/Out   Sel   Sel    INT
     8   -  GND  GND       -       -     -     -      -
     9   5    9   TR  Mode:1  Mode:0 Start     C     Rx
    NC   7    -   -        -       -    ?      ?      -

Bit is the control bit of the port register in the genesis.

Ard is the Arduino pin. To remap pins, you must modify the Arduino source code.

Pad0 is the value returned by the gamepad when Sel is low, Pad1 is the state
when Sel is high. Serial is the pin role when the port is in serial mode
(unused in blast debugger).

TR pin indicates communication direction : If high, genesis sends data to
the arduino ; if TR is low, genesis is waiting for incoming data. This pin also
indicates whether the arduino is allowed to set D0..D3 as outputs or not.

When TR is high (genesis sends data), TL is the clock and TH is the ack pulse.
When TR is low (arduino sends data), TH is the clock and TL is the ack pulse.

When transmission is inactive, TH must be set to pull-up input in case the
genesis polls the gamepad on that port, which could cause a short-circuit.

Byte transmission format
------------------------

The debug mode communicates via D-Pad data lines, passing 4 bits per clock.
Format is big nybble first. For example, to pass 0xA3, digit A would be passed
first, then 3. Each nybble is acknowledged by a transition. 5V pull-up is logic
high (bit set) and 0V is logic low (bit clear). When unused, pins should be high.

Example transmitting 0xA4 to the genesis :

    D0..D3       A               4
          _                               ____
    D0 --- \_____________________________/    ------ output
          ________________                ____
    D1 ---                \______________/    ------ output
          _                ___________________
    D2 --- \______________/                   ------ output
          ________________                ____
{'fraction_non_alphanumeric': 0.08389444949954504, 'fraction_numerical': 0.02602365787079163, 'mean_word_length': 1.456861868573983, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3267287', 'n_tokens_mistral': 1610, 'n_tokens_neox': 1508, 'n_words': 739}