📄 ldmicro.h
字号:
#define IO_TYPE_GENERAL 12
int type;
#define NO_PIN_ASSIGNED 0
int pin;
} PlcProgramSingleIo;
#define MAX_IO 512
typedef struct PlcProgramTag {
struct {
PlcProgramSingleIo assignment[MAX_IO];
int count;
} io;
McuIoInfo *mcu;
int cycleTime;
int mcuClock;
int baudRate;
#define MAX_RUNGS 99
ElemSubcktSeries *rungs[MAX_RUNGS];
BOOL rungPowered[MAX_RUNGS];
int numRungs;
} PlcProgram;
//-----------------------------------------------
// For actually drawing the ladder logic on screen; constants that determine
// how the boxes are laid out in the window, need to know that lots of
// places for figuring out if a mouse click is in a box etc.
// dimensions, in characters, of the area reserved for 1 leaf element
#define POS_WIDTH 17
#define POS_HEIGHT 3
// offset from the top left of the window at which we start drawing, in pixels
#define X_PADDING 35
#define Y_PADDING 14
typedef struct PlcCursorTag {
int left;
int top;
int width;
int height;
} PlcCursor;
//-----------------------------------------------
// The syntax highlighting style colours; a structure for the palette.
typedef struct SyntaxHighlightingColoursTag {
COLORREF bg; // background
COLORREF def; // default foreground
COLORREF selected; // selected element
COLORREF op; // `op code' (like OSR, OSF, ADD, ...)
COLORREF punct; // punctuation, like square or curly braces
COLORREF lit; // a literal number
COLORREF name; // the name of an item
COLORREF rungNum; // rung numbers
COLORREF comment; // user-written comment text
COLORREF bus; // the `bus' at the right and left of screen
COLORREF simBg; // background, simulation mode
COLORREF simRungNum; // rung number, simulation mode
COLORREF simOff; // de-energized element, simulation mode
COLORREF simOn; // energzied element, simulation mode
COLORREF simBusLeft; // the `bus,' can be different colours for
COLORREF simBusRight; // right and left of the screen
} SyntaxHighlightingColours;
extern SyntaxHighlightingColours HighlightColours;
//-----------------------------------------------
// Processor definitions. These tables tell us where to find the I/Os on
// a processor, what bit in what register goes with what pin, etc. There
// is one master SupportedMcus table, which contains entries for each
// supported microcontroller.
typedef struct McuIoPinInfoTag {
char port;
int bit;
int pin;
} McuIoPinInfo;
typedef struct McuAdcPinInfoTag {
int pin;
BYTE muxRegValue;
} McuAdcPinInfo;
#define ISA_AVR 0x00
#define ISA_PIC16 0x01
#define ISA_ANSIC 0x02
#define ISA_INTERPRETED 0x03
#define MAX_IO_PORTS 10
#define MAX_RAM_SECTIONS 5
typedef struct McuIoInfoTag {
char *mcuName;
char portPrefix;
DWORD inputRegs[MAX_IO_PORTS]; // a is 0, j is 9
DWORD outputRegs[MAX_IO_PORTS];
DWORD dirRegs[MAX_IO_PORTS];
DWORD flashWords;
struct {
DWORD start;
int len;
} ram[MAX_RAM_SECTIONS];
McuIoPinInfo *pinInfo;
int pinCount;
McuAdcPinInfo *adcInfo;
int adcCount;
int adcMax;
struct {
int rxPin;
int txPin;
} uartNeeds;
int pwmNeedsPin;
int whichIsa;
BOOL avrUseIjmp;
WORD configurationWord;
} McuIoInfo;
#define NUM_SUPPORTED_MCUS 13
//-----------------------------------------------
// Function prototypes
// ldmicro.cpp
void ProgramChanged(void);
void SetMenusEnabled(BOOL canNegate, BOOL canNormal, BOOL canResetOnly,
BOOL canSetOnly, BOOL canDelete, BOOL canInsertEnd, BOOL canInsertOther,
BOOL canPushRungDown, BOOL canPushRungUp, BOOL canInsertComment);
void SetUndoEnabled(BOOL undoEnabled, BOOL redoEnabled);
void RefreshScrollbars(void);
extern HINSTANCE Instance;
extern HWND MainWindow;
extern HDC Hdc;
extern PlcProgram Prog;
extern char CurrentSaveFile[MAX_PATH];
extern char CurrentCompileFile[MAX_PATH];
extern McuIoInfo SupportedMcus[NUM_SUPPORTED_MCUS];
// memory debugging, because I often get careless; ok() will check that the
// heap used for all the program storage is not yet corrupt, and oops() if
// it is
void CheckHeap(char *file, int line);
#define ok() CheckHeap(__FILE__, __LINE__)
// maincontrols.cpp
void MakeMainWindowControls(void);
HMENU MakeMainWindowMenus(void);
void VscrollProc(WPARAM wParam);
void HscrollProc(WPARAM wParam);
void GenerateIoListDontLoseSelection(void);
void RefreshControlsToSettings(void);
void MainWindowResized(void);
void ToggleSimulationMode(void);
void StopSimulation(void);
void StartSimulation(void);
void UpdateMainWindowTitleBar(void);
extern int ScrollWidth;
extern int ScrollHeight;
extern BOOL NeedHoriz;
extern HWND IoList;
extern int IoListTop;
extern int IoListHeight;
// draw.cpp
int ProgCountWidestRow(void);
int CountHeightOfElement(int which, void *elem);
BOOL DrawElement(int which, void *elem, int *cx, int *cy, BOOL poweredBefore);
void DrawEndRung(int cx, int cy);
extern int ColsAvailable;
extern BOOL SelectionActive;
extern BOOL ThisHighlighted;
// draw_outputdev.cpp
extern void (*DrawChars)(int, int, char *);
void CALLBACK BlinkCursor(HWND hwnd, UINT msg, UINT_PTR id, DWORD time);
void PaintWindow(void);
void ExportDrawingAsText(char *file);
void InitForDrawing(void);
void SetUpScrollbars(BOOL *horizShown, SCROLLINFO *horiz, SCROLLINFO *vert);
int ScreenRowsAvailable(void);
int ScreenColsAvailable(void);
extern HFONT FixedWidthFont;
extern HFONT FixedWidthFontBold;
extern int SelectedGxAfterNextPaint;
extern int SelectedGyAfterNextPaint;
extern BOOL ScrollSelectedIntoViewAfterNextPaint;
extern int ScrollXOffset;
extern int ScrollYOffset;
extern int ScrollXOffsetMax;
extern int ScrollYOffsetMax;
// schematic.cpp
void SelectElement(int gx, int gy, int state);
void MoveCursorKeyboard(int keyCode);
void MoveCursorMouseClick(int x, int y);
BOOL MoveCursorTopLeft(void);
void EditElementMouseDoubleclick(int x, int y);
void EditSelectedElement(void);
void MakeResetOnlySelected(void);
void MakeSetOnlySelected(void);
void MakeNormalSelected(void);
void NegateSelected(void);
void ForgetFromGrid(void *p);
void ForgetEverything(void);
void WhatCanWeDoFromCursorAndTopology(void);
BOOL FindSelected(int *gx, int *gy);
void MoveCursorNear(int gx, int gy);
#define DISPLAY_MATRIX_X_SIZE 16
#define DISPLAY_MATRIX_Y_SIZE 512
extern ElemLeaf *DisplayMatrix[DISPLAY_MATRIX_X_SIZE][DISPLAY_MATRIX_Y_SIZE];
extern int DisplayMatrixWhich[DISPLAY_MATRIX_X_SIZE][DISPLAY_MATRIX_Y_SIZE];
extern ElemLeaf DisplayMatrixFiller;
#define PADDING_IN_DISPLAY_MATRIX (&DisplayMatrixFiller)
#define VALID_LEAF(x) ((x) != NULL && (x) != PADDING_IN_DISPLAY_MATRIX)
extern ElemLeaf *Selected;
extern int SelectedWhich;
extern PlcCursor Cursor;
extern BOOL CanInsertEnd;
extern BOOL CanInsertOther;
extern BOOL CanInsertComment;
// circuit.cpp
void AddTimer(int which);
void AddCoil(void);
void AddContact(void);
void AddEmpty(int which);
void AddMove(void);
void AddMath(int which);
void AddCmp(int which);
void AddReset(void);
void AddCounter(int which);
void AddReadAdc(void);
void AddSetPwm(void);
void AddUart(int which);
void AddPersist(void);
void AddComment(char *text);
void AddShiftRegister(void);
void AddMasterRelay(void);
void AddLookUpTable(void);
void AddPiecewiseLinear(void);
void AddFormattedString(void);
void DeleteSelectedFromProgram(void);
void DeleteSelectedRung(void);
void InsertRung(BOOL afterCursor);
int RungContainingSelected(void);
BOOL ItemIsLastInCircuit(ElemLeaf *item);
BOOL UartFunctionUsed(void);
BOOL PwmFunctionUsed(void);
void PushRungUp(void);
void PushRungDown(void);
void NewProgram(void);
ElemLeaf *AllocLeaf(void);
ElemSubcktSeries *AllocSubcktSeries(void);
ElemSubcktParallel *AllocSubcktParallel(void);
void FreeCircuit(int which, void *any);
void FreeEntireProgram(void);
void UndoUndo(void);
void UndoRedo(void);
void UndoRemember(void);
void UndoFlush(void);
BOOL CanUndo(void);
// loadsave.cpp
BOOL LoadProjectFromFile(char *filename);
BOOL SaveProjectToFile(char *filename);
// iolist.cpp
int GenerateIoList(int prevSel);
void SaveIoListToFile(FILE *f);
BOOL LoadIoListFromFile(FILE *f);
void ShowIoDialog(int item);
void IoListProc(NMHDR *h);
void ShowAnalogSliderPopup(char *name);
// commentdialog.cpp
void ShowCommentDialog(char *comment);
// contactsdialog.cpp
void ShowContactsDialog(BOOL *negated, char *name);
// coildialog.cpp
void ShowCoilDialog(BOOL *negated, BOOL *setOnly, BOOL *resetOnly, char *name);
// simpledialog.cpp
void ShowTimerDialog(int which, int *delay, char *name);
void ShowCounterDialog(int which, int *count, char *name);
void ShowMoveDialog(char *dest, char *src);
void ShowReadAdcDialog(char *name);
void ShowSetPwmDialog(char *name, int *targetFreq);
void ShowPersistDialog(char *var);
void ShowUartDialog(int which, char *name);
void ShowCmpDialog(int which, char *op1, char *op2);
void ShowMathDialog(int which, char *dest, char *op1, char *op2);
void ShowShiftRegisterDialog(char *name, int *stages);
void ShowFormattedStringDialog(char *var, char *string);
void ShowLookUpTableDialog(ElemLeaf *l);
void ShowPiecewiseLinearDialog(ElemLeaf *l);
void ShowResetDialog(char *name);
// confdialog.cpp
void ShowConfDialog(void);
// helpdialog.cpp
void ShowHelpDialog(BOOL about);
// miscutil.cpp
#define oops() { \
dbp("bad at %d %s\n", __LINE__, __FILE__); \
Error("Internal error at line %d file '%s'\n", __LINE__, __FILE__); \
exit(1); \
}
void dbp(char *str, ...);
void Error(char *str, ...);
void *CheckMalloc(size_t n);
void CheckFree(void *p);
extern HANDLE MainHeap;
void StartIhex(FILE *f);
void WriteIhex(FILE *f, BYTE b);
void FinishIhex(FILE *f);
char *IoTypeToString(int ioType);
void PinNumberForIo(char *dest, PlcProgramSingleIo *io);
HWND CreateWindowClient(DWORD exStyle, char *className, char *windowName,
DWORD style, int x, int y, int width, int height, HWND parent,
HMENU menu, HINSTANCE instance, void *param);
void MakeDialogBoxClass(void);
void NiceFont(HWND h);
void FixedFont(HWND h);
void CompileSuccessfulMessage(char *str);
extern BOOL RunningInBatchMode;
extern HFONT MyNiceFont;
extern HFONT MyFixedFont;
extern HWND OkButton;
extern HWND CancelButton;
extern BOOL DialogDone;
extern BOOL DialogCancel;
// lang.cpp
char *_(char *in);
// simulate.cpp
void SimulateOneCycle(BOOL forceRefresh);
void CALLBACK PlcCycleTimer(HWND hwnd, UINT msg, UINT_PTR id, DWORD time);
void StartSimulationTimer(void);
void ClearSimulationData(void);
void DescribeForIoList(char *name, char *out);
void SimulationToggleContact(char *name);
void SetAdcShadow(char *name, SWORD val);
SWORD GetAdcShadow(char *name);
void DestroyUartSimulationWindow(void);
void ShowUartSimulationWindow(void);
extern BOOL InSimulationMode;
extern BOOL SimulateRedrawAfterNextCycle;
// compilecommon.cpp
void AllocStart(void);
DWORD AllocOctetRam(void);
void AllocBitRam(DWORD *addr, int *bit);
void MemForVariable(char *name, DWORD *addrl, DWORD *addrh);
BYTE MuxForAdcVariable(char *name);
void MemForSingleBit(char *name, BOOL forRead, DWORD *addr, int *bit);
void MemCheckForErrorsPostCompile(void);
void BuildDirectionRegisters(BYTE *isInput, BYTE *isOutput);
void ComplainAboutBaudRateError(int divisor, double actual, double err);
void ComplainAboutBaudRateOverflow(void);
#define CompileError() longjmp(CompileErrorBuf, 1)
extern jmp_buf CompileErrorBuf;
// intcode.cpp
void IntDumpListing(char *outFile);
BOOL GenerateIntermediateCode(void);
// pic16.cpp
void CompilePic16(char *outFile);
// avr.cpp
void CompileAvr(char *outFile);
// ansic.cpp
void CompileAnsiC(char *outFile);
// interpreted.c
void CompileInterpreted(char *outFile);
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -