aboutsummaryrefslogtreecommitdiffstats
path: root/print.h
blob: 781b0a0e7b18bdf87f2c5483fc0a171506625342 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#ifndef PRINT_H
#define PRINT_H

/*
 * abcprintd internal data structures
 */

#include "abcprintd.h"
#include "hostfile.h"

/* Ordinary input state machine */
enum input_state {
    is_normal,                  /* Normal operation */
    is_ff,                      /* 0xFF received */
    is_file,                    /* File operation in progress */
    is_console                  /* Output to console */
};

/* File operations state machine */
enum fileop_state {
    st_op,                      /* Receiving command */
    st_open,
    st_read,
    st_print,                   /* Before data */
    st_print2,                  /* After data */
    st_seek,
    st_rename,
    st_delete,
    st_pread,
    st_pwrite,                  /* Before data */
    st_pwrite2,                 /* After data */
    st_blksize
};

struct fileop_file {
    struct host_file *hf;
    bool binary;
};

typedef union argbuf {
    uint8_t b[32];
    char c[32];
    uint64_t q;
} argbuf;

struct abcprint {
    /* Function to send data */
    struct send_data {
	send_func func;
	void *pvt;
    } sd;

    /* Temporary file for actual printing */
    struct host_file *prfile;

    /* Input state machine */
    enum input_state istate;

    /* File opeerations state machine */
    enum fileop_state fstate;

    /* System block size */
    unsigned int blksize;

    /* Current ix value, and corresponding fileop_file, if any */
    uint16_t ix;
    struct fileop_file *ff;

    /* Pending I/O data */
    unsigned int datalen;	/* Data expected for the main data buffer */
    unsigned int byte_count;	/* Data still required */
    unsigned char *bytep;	/* Pointer to next byte to be received */


    /* Data buffers */
    unsigned char cmd[4];	/* Buffer for command */
    argbuf argbuf;		/* Buffer for argument(s) */
    unsigned char data[65536+2]; /* Data buffer (maximum possible size) */

    /* Filemap; massive waste of space -- clean up? */
    struct fileop_file filemap[65536];
};

extern void fileop_reset(struct abcprint *me);
extern bool file_op(struct abcprint *me, unsigned char c);

#endif /* PRINT_H */