include/mgba/internal/gb/sio/printer.h (view raw)
1/* Copyright (c) 2013-2017 Jeffrey Pfau
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6#ifndef GB_PRINTER_H
7#define GB_PRINTER_H
8
9#include <mgba-util/common.h>
10
11CXX_GUARD_START
12
13#include <mgba/gb/interface.h>
14
15enum GBPrinterPacketByte {
16 GB_PRINTER_BYTE_MAGIC_0,
17 GB_PRINTER_BYTE_MAGIC_1,
18 GB_PRINTER_BYTE_COMMAND,
19 GB_PRINTER_BYTE_COMPRESSION,
20 GB_PRINTER_BYTE_LENGTH_0,
21 GB_PRINTER_BYTE_LENGTH_1,
22 GB_PRINTER_BYTE_DATA,
23 GB_PRINTER_BYTE_CHECKSUM_0,
24 GB_PRINTER_BYTE_CHECKSUM_1,
25 GB_PRINTER_BYTE_KEEPALIVE,
26 GB_PRINTER_BYTE_STATUS,
27
28 GB_PRINTER_BYTE_COMPRESSED_DATUM,
29 GB_PRINTER_BYTE_UNCOMPRESSED_DATA
30};
31
32enum GBPrinterStatus {
33 GB_PRINTER_STATUS_CHECKSUM_ERROR = 0x01,
34 GB_PRINTER_STATUS_PRINTING = 0x02,
35 GB_PRINTER_STATUS_PRINT_REQ = 0x04,
36 GB_PRINTER_STATUS_READY = 0x08,
37 GB_PRINTER_STATUS_LOW_BATTERY = 0x10,
38 GB_PRINTER_STATUS_TIMEOUT = 0x20,
39 GB_PRINTER_STATUS_PAPER_JAM = 0x40,
40 GB_PRINTER_STATUS_TEMPERATURE_ISSUE = 0x80
41};
42
43enum GBPrinterCommand {
44 GB_PRINTER_COMMAND_INIT = 0x1,
45 GB_PRINTER_COMMAND_PRINT = 0x2,
46 GB_PRINTER_COMMAND_DATA = 0x4,
47 GB_PRINTER_COMMAND_STATUS = 0xF,
48};
49
50struct GBPrinter {
51 struct GBSIODriver d;
52
53 void (*print)(struct GBPrinter*, int height, const uint8_t* data);
54
55 uint8_t* buffer;
56 uint16_t checksum;
57 enum GBPrinterCommand command;
58 uint16_t remainingBytes;
59 uint8_t remainingCmpBytes;
60 unsigned currentIndex;
61 bool compression;
62
63 uint8_t byte;
64 enum GBPrinterPacketByte next;
65 uint8_t status;
66 int printWait;
67};
68
69void GBPrinterCreate(struct GBPrinter* printer);
70void GBPrinterDonePrinting(struct GBPrinter* printer);
71
72CXX_GUARD_END
73
74#endif