2017-01-13 19:27:37 +00:00
|
|
|
#ifndef printer_h
|
|
|
|
#define printer_h
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
2017-04-17 17:16:17 +00:00
|
|
|
#include "gb_struct_def.h"
|
2017-01-13 19:27:37 +00:00
|
|
|
#define GB_PRINTER_MAX_COMMAND_LENGTH 0x280
|
|
|
|
#define GB_PRINTER_DATA_SIZE 0x280
|
|
|
|
|
|
|
|
typedef void (*GB_print_image_callback_t)(GB_gameboy_t *gb,
|
|
|
|
uint32_t *image,
|
|
|
|
uint8_t height,
|
|
|
|
uint8_t top_margin,
|
|
|
|
uint8_t bottom_margin,
|
|
|
|
uint8_t exposure);
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
/* Communication state machine */
|
|
|
|
|
|
|
|
enum {
|
|
|
|
GB_PRINTER_COMMAND_MAGIC1,
|
|
|
|
GB_PRINTER_COMMAND_MAGIC2,
|
|
|
|
GB_PRINTER_COMMAND_ID,
|
|
|
|
GB_PRINTER_COMMAND_COMPRESSION,
|
|
|
|
GB_PRINTER_COMMAND_LENGTH_LOW,
|
|
|
|
GB_PRINTER_COMMAND_LENGTH_HIGH,
|
|
|
|
GB_PRINTER_COMMAND_DATA,
|
|
|
|
GB_PRINTER_COMMAND_CHECKSUM_LOW,
|
|
|
|
GB_PRINTER_COMMAND_CHECKSUM_HIGH,
|
|
|
|
GB_PRINTER_COMMAND_ACTIVE,
|
|
|
|
GB_PRINTER_COMMAND_STATUS,
|
|
|
|
} command_state : 8;
|
|
|
|
enum {
|
|
|
|
GB_PRINTER_INIT_COMMAND = 1,
|
|
|
|
GB_PRINTER_START_COMMAND = 2,
|
|
|
|
GB_PRINTER_DATA_COMMAND = 4,
|
|
|
|
GB_PRINTER_NOP_COMMAND = 0xF,
|
|
|
|
} command_id : 8;
|
|
|
|
bool compression;
|
|
|
|
uint16_t length_left;
|
|
|
|
uint8_t command_data[GB_PRINTER_MAX_COMMAND_LENGTH];
|
|
|
|
uint16_t command_length;
|
|
|
|
uint16_t checksum;
|
|
|
|
uint8_t status;
|
|
|
|
uint8_t byte_to_send;
|
|
|
|
|
|
|
|
uint8_t image[160 * 200];
|
|
|
|
uint16_t image_offset;
|
|
|
|
|
2020-06-10 19:46:19 +00:00
|
|
|
/* TODO: Delete me. */
|
|
|
|
uint64_t padding;
|
2017-01-20 21:00:02 +00:00
|
|
|
|
|
|
|
uint8_t compression_run_lenth;
|
|
|
|
bool compression_run_is_compressed;
|
2019-03-15 12:36:10 +00:00
|
|
|
|
2020-09-19 16:31:24 +00:00
|
|
|
uint8_t bits_received;
|
|
|
|
uint8_t byte_being_received;
|
2019-03-15 12:36:10 +00:00
|
|
|
bool bit_to_send;
|
2017-01-13 19:27:37 +00:00
|
|
|
} GB_printer_t;
|
|
|
|
|
|
|
|
|
|
|
|
void GB_connect_printer(GB_gameboy_t *gb, GB_print_image_callback_t callback);
|
2017-04-17 17:16:17 +00:00
|
|
|
#endif
|