docs/templates/pages/sega/hardware/touch.md

8.8 KiB

The MaiMai Touchscreen

The touchscreen for MaiMai, pre-DX, is powered by a 838-15221 board, connected to COM3.

Unlike other IO boards, this board communicates using a custom, text-based, protocol.

Serial configuartion

Port COM3
Baud Rate 9600
Bits per byte 8
Stop bits 0
Parity bits 0

Packet format

As previously mentioned, all packets are text. This means, for the most part, values will stay within a normal printable range. More importantly, null bytes are not permitted as they will be interpted as the end of the string.

Packets sent from the game to the board are surrounded in braces, {like this}. Packets sent from the board to the game are surrounded in parentheses, (like this).

{HALT}

{ H A L T }
This instructs the board to stop sending the state of the touchscreen. No response is expected.

{STAT}

{ S T A T }
This instructs the board to begin sending the state of the touchscreen (detailed below). No response is expected.

{??th}

{ L/R sensor t h }
This requests the configured threshold value for a specific sensor from the board. The expected response is as follows:
( L/R sensor threshold value )

{??k?}

{ L/R sensor k threshold }
This configures the threshold value for a specific sensor. The expected response is as follows:
( L/R sensor )

Active mode

After a `{STAT}` packet is received, the board enters a mode where it begins constantly transmitting the state of the touchscreen. The data sent is in the following format:
(
P1: A1,B1,A2,B2,x P1: A3,B3,A4,B4,x P1: A5,B5,A6,B6,x P1: A7,B7,A8,B8,C
padding padding
P2: A1,B1,A2,B2,x P2: A3,B3,A4,B4,x P2: A5,B5,A6,B6,x P2: A7,B7,A8,B8,C
padding padding
)

Each data byte is a bit mask of the 5 values it contains, mapped to 1~h~, 2~h~, 4~h~, 8~h~, and 10~h~ respectively. While sending 1f~h~ would be a valid byte, it is recommended to make use of the upper bits to keep the value within a printable range. I personally recommend masking with 40~h~ ('@') for this purpose. Values will then range from @ to _. Bits indicated with x are unused. It is recommended, but not required, to leave them unset.

The four bytes marked as padding are unused, with the only requirement being that they are non-null. It is recommended, but not required, to set them to 40~h~ ('@').

Individual bit breakdown
<table class="code">
    <thead>
        <tr>
            <td rowspan="2">Byte</td>
            <td rowspan="2">Player</td>
            <td colspan="8">Bit</td>
            <td rowspan="2">ASCII</td>
        </tr>
        <tr>
            <td>7</td>
            <td>6</td>
            <td>5</td>
            <td>4</td>
            <td>3</td>
            <td>2</td>
            <td>1</td>
            <td>0</td>
        </tr>
    </thead>
    <tr>
        <td>0</td>
        <td></td>
        <td>0</td>
        <td>0</td>
        <td>1</td>
        <td>0</td>
        <td>1</td>
        <td>0</td>
        <td>0</td>
        <td>0</td>
        <td>(</td>
    </tr>
    <tr>
        <td>1</td>
        <td>P1</td>
        <td>0</td>
        <td>1</td>
        <td>0</td>
        <td>0</td>
        <td>B2</td>
        <td>A2</td>
        <td>B1</td>
        <td>A1</td>
        <td><i>varies</i></td>
    </tr>
    <tr>
        <td>2</td>
        <td>P1</td>
        <td>0</td>
        <td>1</td>
        <td>0</td>
        <td>0</td>
        <td>B4</td>
        <td>A4</td>
        <td>B3</td>
        <td>A3</td>
        <td><i>varies</i></td>
    </tr>
    <tr>
        <td>3</td>
        <td>P1</td>
        <td>0</td>
        <td>1</td>
        <td>0</td>
        <td>0</td>
        <td>B6</td>
        <td>A6</td>
        <td>B5</td>
        <td>A5</td>
        <td><i>varies</i></td>
    </tr>
    <tr>
        <td>4</td>
        <td>P1</td>
        <td>0</td>
        <td>1</td>
        <td>0</td>
        <td>C</td>
        <td>B8</td>
        <td>A8</td>
        <td>B7</td>
        <td>A7</td>
        <td><i>varies</i></td>
    </tr>
    <tr>
        <td>5</td>
        <td></td>
        <td>0</td>
        <td>1</td>
        <td>0</td>
        <td>0</td>
        <td>0</td>
        <td>0</td>
        <td>0</td>
        <td>0</td>
        <td>@</td>
    </tr>
    <tr>
        <td>6</td>
        <td></td>
        <td>0</td>
        <td>1</td>
        <td>0</td>
        <td>0</td>
        <td>0</td>
        <td>0</td>
        <td>0</td>
        <td>0</td>
        <td>@</td>
    </tr>
    <tr>
        <td>7</td>
        <td>P2</td>
        <td>0</td>
        <td>1</td>
        <td>0</td>
        <td>0</td>
        <td>B2</td>
        <td>A2</td>
        <td>B1</td>
        <td>A1</td>
        <td><i>varies</i></td>
    </tr>
    <tr>
        <td>8</td>
        <td>P2</td>
        <td>0</td>
        <td>1</td>
        <td>0</td>
        <td>0</td>
        <td>B4</td>
        <td>A4</td>
        <td>B3</td>
        <td>A3</td>
        <td><i>varies</i></td>
    </tr>
    <tr>
        <td>9</td>
        <td>P2</td>
        <td>0</td>
        <td>1</td>
        <td>0</td>
        <td>0</td>
        <td>B6</td>
        <td>A6</td>
        <td>B5</td>
        <td>A5</td>
        <td><i>varies</i></td>
    </tr>
    <tr>
        <td>10</td>
        <td>P2</td>
        <td>0</td>
        <td>1</td>
        <td>0</td>
        <td>C</td>
        <td>B8</td>
        <td>A8</td>
        <td>B7</td>
        <td>A7</td>
        <td><i>varies</i></td>
    </tr>
    <tr>
        <td>11</td>
        <td></td>
        <td>0</td>
        <td>1</td>
        <td>0</td>
        <td>0</td>
        <td>0</td>
        <td>0</td>
        <td>0</td>
        <td>0</td>
        <td>@</td>
    </tr>
    <tr>
        <td>12</td>
        <td></td>
        <td>0</td>
        <td>1</td>
        <td>0</td>
        <td>0</td>
        <td>0</td>
        <td>0</td>
        <td>0</td>
        <td>0</td>
        <td>@</td>
    </tr>
    <tr>
        <td>13</td>
        <td></td>
        <td>0</td>
        <td>0</td>
        <td>1</td>
        <td>0</td>
        <td>1</td>
        <td>0</td>
        <td>0</td>
        <td>1</td>
        <td>)</td>
    </tr>
</table>

An example may aid here. The following image is what transmitting (FIBT@@@@@@@@) is interpreted as: