                           /* Header file for zterm.c */
                                 /* Nik Conwell */


/* #define DEBUG 51914 */

#include <exec/types.h>
#include <lattice/stdio.h>
#include <sl-lc.c>
/*lint -e544 */
#include <exec/exec.h>
#include <intuition/intuition.h>
#include <devices/serial.h>
#include <devices/keymap.h>
#include <devices/console.h>
#include <graphics/gfxmacros.h>
#include <graphics/gfxbase.h>
#include <graphics/gfx.h>
#include <hardware/blit.h>
#include <libraries/dos.h>
#include <libraries/diskfont.h>

/* misc defs for io */
#define INTUITION_REV 0
#define GRAPHICS_REV 0
#define W1_INTUITION_MESSAGE (1<<zt->w1_intuitionmsgbit)
#define TIMER_MESSAGE (1<<zt->timerbit)
#define TYPED_CHARACTER (1<<zt->consolereadbit)
#define SERIAL_INPUT (1<<zt->serialipbit)
#define SBUFSIZE 255   /* text send buffer size */

#define STRINGSIZE 80
#define BGRP 0
#define WHTP 1
#define REDP 1
#define GRNP 2
#define YELP 3
#define AQUP 4
#define PURP 5
#define BLUP 6
#define BLKP 7
#define GREDP 3
#define GBLKP 2
#define GWHTP 1
#define GBLUP 0


#define TTIME    3           /* number of seconds for timeout */
#define TIMEOUT  -1          /* time out for xmodem read character */
#define USER_ABORT -1        /* User aborted xfer */
#define BUFSIZE  0x1000      /* Send/recv buffer */
#define ERRORMAX 100         /* Max errors before abort */
#define RETRYMAX 10          /* Maximum retrys before abort */
#define SOH      1           /* Start of 128 sector char */
#define STX      2           /* Start of 1024 byte sector char */
#define EOT      4           /* end of transmission char */
#define ACK      6           /* acknowledge sector transmission */
#define NAK      21          /* error in transmission detected */
#define CCHAR    67	     /* 'C' for crc transmissions */

#define BAUD_ALPHA_LEN 20    /* Alpha work space for stci_d() */

#define FAIL_NO_FAIL			 	9999
#define FAIL_INTUITION_OPEN			0
#define FAIL_GRAPHICS_OPEN			1
#define FAIL_W1_WINDOW_OPEN			2
#define FAIL_CONSOLEWRITEPORT_OPEN		3
#define FAIL_CONSOLEWRITESTDIO_OPEN		4
#define FAIL_CONSOLEREADPORT_OPEN		5
#define FAIL_CONSOLEREADSTDIO_OPEN		6
#define FAIL_CONSOLE_OPEN			7
#define FAIL_SERIAL_READ_OPEN			8
#define FAIL_SERIAL_WRITE_OPEN			9
#define FAIL_TIMER_CREATE_PORT			10
#define FAIL_TIMER_CREATE_STDIO                 11
#define FAIL_TIMER_OPEN_DEVICE                  12

/* Menu symbolic definitions */

#define MENU_PROJECT 				0
#define MENU_PROJECT_INFO			0
#define MENU_PROJECT_QUIT			1

#define MENU_BAUD				1

#define MENU_FILESTUFF				2
#define MENU_FILESTUFF_SEND_XMODEM		0
#define MEUN_FILESTUFF_SEND_MULTIPLE		1
#define MENU_FILESTUFF_READ_XMODEM		2
#define MENU_FILESTUFF_ABORT_XMODEM		3
#define MENU_FILESTUFF_RECEIVE_TEXT		4
#define MENU_FILESTUFF_RECEIVE_TEXT_END		5
#define MENU_FILESTUFF_SEND_TEXT		6

#define MENU_XMODEM_OPTIONS			3
#define MENU_XMODEM_OPTIONS_128_BLOCK		0
#define MENU_XMODEM_OPTIONS_1024_BLOCK		1
#define MENU_XMODEM_OPTIONS_CHECKSUM		2
#define MENU_XMODEM_OPTIONS_CRC16		3


#define XMODEM_CHECKSUM				1
#define XMODEM_CRC16				2
#define XMODEM_1024_BLOCK			1024
#define XMODEM_128_BLOCK			128

                /* Define all term associated routines */

void open_libraries();
void create_console(struct Z_Term *);
void create_ser_device(struct Z_Term *);
void create_timer_device(struct Z_Term *);
void con_put_str(char *,struct Z_Term *);
void queue_read(struct Z_Term *);
void con_put_char(char,struct Z_Term *);
void handle_intui_message(struct Z_Term *);
void handle_menu(struct Z_Term *);
void handle_baud(struct Z_Term *);
void getout(int,struct Z_Term *);
void getfilename(char *);

int xmodem_send_file(struct Z_Term *);
int xmodem_read_file(struct Z_Term *);
void type(struct Z_Term *);
void set_xmodem_options(struct Z_Term *);
void fix_baud(struct Z_Term *);
void sendchar(char,struct Z_Term *);
void remove_ser_1();
void remove_ser_2();
void set_timer(int,struct Z_Term *);

                       /* End of term.h */
