📄 plc.h
字号:
/*
* Released under the GNU GPL. See http://www.gnu.org/licenses/gpl.txt
*
* This program is part of TinyPLC
*
* TinyPLC is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundatation; version 2 of the License.
*
* TinyPLC is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
/*
* My thanks to my employer, Athena Controls (www.athenacontrols.com)
* for allowing me to open source this project.
*/
/*
* TinyPLC kernel
* Processor: Atmel MEGA1281 or Atmel MEGA2561
* Compiler: Codevision AVR C compiler, 1.24.8e
*
* TinyPLC editor/compiler
* Processor: PC-clone, VESA video (mode 0x105, 1024x768x256)
* Compiler: DeSmet C, version 2.51 (PCC version 1.2)
*
* Revision history:
* Programmer Date Comments
* ---------------- --------- ---------------------------------------------
* William Couture 3/19/2006 Original code
* William Couture 9/13/2006 Modify for GPL release
*/
typedef unsigned char BYTE;
typedef unsigned int WORD;
typedef long DWORD; /* unsigned would be nice, but... */
/* a 'FILE' is simply an integer is this implimentation */
typedef int FILE; /* borrow this from STDIO.H, so I don't duplicate TRUE, etc */
#define NO_FILE (-1)
#define MIN(a,b) (((a) > (b)) ? (b) : (a))
#define MAX(a,b) (((a) < (b)) ? (b) : (a))
#define ESC '\033'
#define CR '\015'
#define TRUE 1
#define FALSE 0
/* #include "colors.h" */
#define BLACK 0
#define BLUE 1
#define GREEN 2
#define CYAN 3
#define RED 4
#define MAGENTA 5
#define BROWN 6
#define LTGREY 7
#define DKGREY 8
#define LTBLUE 9
#define LTGREEN 10
#define LTCYAN 11
#define LTRED 12
#define LTMAGENTA 13
#define YELLOW 14
#define WHITE 15
/* #define MAX_GRAPHICS_ROW 479 */
/* #define MAX_GRAPHICS_COL 639 */
#define MAX_GRAPHICS_ROW 767
#define MIDDLE_GRAPHICS_ROW ((MAX_GRAPHICS_ROW+1)/2)
#define MAX_GRAPHICS_COL 1023
#define NUMROWS (MAX_GRAPHICS_ROW + 1)
#define NUMCOLS (MAX_GRAPHICS_COL + 1)
/*
* NOTE: The graphics origin is in the UPPER LEFT corner.
* r = 0, c = 0 ---> r = 0,c = MAX_GRAPHICS_COL
* +------------------+
* | | | |
* | | | |
* v | | v
* +------------------+
* r = MAX_GRAPHICS_ROW,c = 0 ---> r = MAX_GRAPHICS_ROW, c = MAX_GRAPHICS_COL
*/
#define MODE_640X480_16COLOR 0x12
#define VESA_640x480_256COLOR 0x0101
#define VESA_1024X768_16COLOR 0x104
#define VESA_1024X768_256COLOR 0x105
#define MODE_STANDARD_TEXT 3
#define MAX_RUNGS 64
#define MAX_LADDER 32
#define TEXTWIDTH 8 /* if you change TEXTWIDTH, change strout() */
#define TEXTHEIGHTSMALL 8
#define TEXTHEIGHT 16
#define TEXTROWS (NUMROWS / TEXTHEIGHT)
#define TEXTROWSSMALL (NUMROWS / TEXTHEIGHTSMALL)
#define TEXTCOLS (NUMCOLS / TEXTWIDTH)
#define LEFT_BUTTON 0x0001
#define RIGHT_BUTTON 0x0002
#define MIDDLE_BUTTON 0x0004
#define TEXTFOREGROUND LTGREY
#define TEXTBACKGROUND BLACK
#define POPBOX_ROW 600
#define POPBOX_COL 200
#define POPBOX_SIZE 38
#define POPBOX_MAXROWS 7
#define POPBOX_FOREGROUND BLACK
#define POPBOX_BACKGROUND LTGREY
/* use #define instead of enum so it's obvious what the values are */
#define LEFT_EDGE 1
#define RIGHT_EDGE 2
#define VERT_BAR 3
#define START_NO_IN 4
#define END_NO_IN 5
#define START_NC_IN 6
#define END_NC_IN 7
#define START_NO_OUT 8
#define END_NO_OUT 9
#define START_NC_OUT 10
#define END_NC_OUT 11
/* #define SINGLE_CHAR_BOX 12 */
#define CHAR_BOX 32
#define BRANCH_BAR 15
#define START_BRANCH 16
#define END_BRANCH 17
#define EXPAND_BRANCH 18
#define OR_VERT_T 19
#define OR_VERT_BAR 20
#define OR_LEFT 21
#define OR_RIGHT 22
#define OR_LEFT_T 25
#define OR_RIGHT_T 26
#define MOUSE_CURSOR 27
#define SPACE 32
#define BOX_TOP_LEFT 23
#define BOX_TOP_RIGHT 24
#define BOX_BOTTOM_LEFT 21
#define BOX_BOTTOM_RIGHT 22
#define BOX_SIDEBAR 20
#define BOX_TOPBAR 3
#define SCROLL_UPARROW 12
#define SCROLL_DOWNARROW 13
#define SCROLL_BAR 14
#define SCROLL_BOX 28
#include "plcshare.h"
#define NUM_LABELS 256
#define NULL_LABEL 0xffff
#define NULL (void *)0
#define NULL_OBJECT 0xffff
#define OR_NULL 0xf000
#define OR_TAKEN 0xffff
#define OR_ENDLINK 0xff00
#define AVAILABLE 0
#define TAKEN 1
#define ENDLINK 2
#define OPCODE_MAX 6
struct logic_element
{
BYTE opcode[OPCODE_MAX];
BYTE opflags[OPCODE_MAX];
BYTE oplen;
WORD objindex;
WORD or_branch; /* index into rungs[] */
WORD or_parent; /* index into rungs[] */
WORD or_parentnode;
WORD linkstatus; /* AVAILABLE, TAKEN, ENDLINK */
};
struct element_info
{
WORD u_row;
WORD l_row;
WORD l_col;
WORD r_col;
WORD objindex;
void (*left_action)();
void (*right_action)();
};
#define SCREEN_MAX 128
#define ELEMENTS_PER_RUNG 10
#define LADDER_FIRST_CHAR 22
#define LADDER_ELEMENT_CHARS 10
#define LADDER_ELEMENT_WIDTH (LADDER_ELEMENT_CHARS * TEXTWIDTH)
#define LADDER_LEFT_COL (LADDER_FIRST_CHAR * TEXTWIDTH)
#define RUNG_WIDTH (LADDER_ELEMENT_WIDTH * ELEMENTS_PER_RUNG)
#define LADDER_RIGHT_COL (LADDER_LEFT_COL + RUNG_WIDTH)
#define LADDER_ROW_HEIGHT TEXTHEIGHT
#define FIRST_LADDER_ROW LADDER_ROW_HEIGHT
#define LADDER_ROW_INCREMENT (3 * TEXTHEIGHT)
#define LADDER_LABEL_COL (LADDER_LEFT_COL - 3 * TEXTWIDTH)
#define SCROLL_TOP 0
#define SCROLL_BOTTOM MAX_GRAPHICS_ROW
#define SCROLL_LEFTCOL (LADDER_RIGHT_COL + 3 * TEXTWIDTH)
#define SCROLL_RIGHTCOL (SCROLL_LEFTCOL + TEXTWIDTH)
#define SCROLL_UPARROW_ROW SCROLL_TOP
#define SCROLL_DOWNARROW_ROW (SCROLL_BOTTOM - TEXTHEIGHT + 1)
#define SCROLLBAR_SIZE ((MAX_GRAPHICS_ROW + 1) - 2 * TEXTHEIGHT)
struct ladder_rung
{
struct element_info info;
WORD num_elements; /* used elements on this rung */
WORD max_elements; /* max elements that can be on this rung */
struct logic_element node[ELEMENTS_PER_RUNG];
};
enum objtypes
{
INP_OBJ,
NINP_OBJ,
OUT_OBJ,
NOUT_OBJ,
LOUT_OBJ,
UOUT_OBJ,
ADD_OBJ,
SUB_OBJ,
MUL_OBJ,
DIV_OBJ,
MOD_OBJ,
AND_OBJ,
OR_OBJ,
XOR_OBJ,
NOT_OBJ,
NEG_OBJ,
EQU_OBJ,
NEQ_OBJ,
GRT_OBJ,
GEQ_OBJ,
LES_OBJ,
LEQ_OBJ,
MOV_OBJ,
JMP_OBJ,
OSR_OBJ,
CTT_OBJ,
CTF_OBJ,
TMT_OBJ,
TMF_OBJ,
RTMT_OBJ,
RTMF_OBJ,
RESET_OBJ,
INVERT_OBJ,
LBL_OBJ,
SAVE_OBJ,
LOAD_OBJ,
NEW_OBJ,
DOWNLOAD_OBJ,
ADDROW_OBJ,
DELROW_OBJ,
ONESTEP_OBJ,
LINESTEP_OBJ,
RUN_OBJ,
STOP_OBJ,
ORBRANCH_OBJ,
EXPAND_OBJ,
COPYR1_OBJ,
COPYR2_OBJ,
COPYR3_OBJ,
VERSION_OBJ,
EXIT_OBJ,
LADDER_OBJ,
NULL_OBJ,
SCROLL_OBJ,
NUMBER_OF_OBJECTS
};
#define COMPILE_OK 0
#define COMPILE_UNKNOWN_PARAMS 1
#define COMPILE_UNKNOWN_ADDR 2
#define COMPILE_DUP_ADDR 3
#define COMPILE_PROG_TOO_BIG 4
struct obj
{
BYTE *label;
BYTE *overlay;
void (*initfn)();
void (*delfn)();
void (*drawfn)();
WORD (*compilefn)();
};
#define INPUT_PREFIX 'X'
#define VAR_PREFIX 'V'
#define TIMER_PREFIX 'T'
#define COUNTER_PREFIX 'C'
#define ONESHOT_PREFIX 'R'
#define ANALOG_PREFIX 'A'
#define OUTPUT_PREFIX 'Y'
#define LABEL_PREFIX 'L'
enum
{
UNUSED_TYPE = 0,
INPUT_TYPE,
VAR_TYPE,
TIMER_TYPE,
COUNTER_TYPE,
ONESHOT_TYPE,
ANALOG_TYPE,
OUTPUT_TYPE,
LABEL_TYPE,
BYTEVAL_TYPE,
WORDVAL_TYPE,
DWORDVAL_TYPE,
NUM_VAR_TYPES
};
#ifndef _PLC_C_
extern struct obj objs[NUMBER_OF_OBJECTS];
extern WORD program_len;
extern WORD label_addresses[NUM_LABELS];
extern WORD is_littleendian;
extern BYTE tempstr[128];
WORD beep();
/* next 4 are for UGLY kludge in PLC2.C */
extern struct ladder_rung rungs[MAX_RUNGS];
extern WORD used_rungs[MAX_RUNGS];
extern WORD rung_list[MAX_RUNGS+1];
extern WORD ladder_size;
#endif /* _PLC_C_ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -