PICSimLab - Programmable IC Simulator Laboratory 0.9.2
PICSimLab - API
All Classes Functions Variables Pages
spareparts.h
1/* ########################################################################
2
3 PICSimLab - Programmable IC Simulator Laboratory
4
5 ########################################################################
6
7 Copyright (c) : 2010-2025 Luis Claudio Gambôa Lopes <lcgamboa@yahoo.com>
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
12 any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22
23 For e-mail suggestions : lcgamboa@yahoo.com
24 ######################################################################## */
25
26#ifndef SPAREPARTS
27#define SPAREPARTS
28
29#include <atomic>
30#include "draw.h"
31#include "part.h"
32#include "types.h"
33
35public:
37
38 void Init(void);
39
40 void UpdateAll(const int force = 0);
41 int GetCount(void) { return partsc; };
42 part* GetPart(const int partn);
43 void DeleteParts(void);
44 void ResetPullupBus(unsigned char pin);
45 void SetPullupBus(unsigned char pin, unsigned char value);
46 unsigned char GetPullupBus(unsigned char pin);
47
51 void Process(void);
52
56 void PreProcess(void);
57
61 void PostProcess(void);
62
66 std::string GetPinsNames(void);
67
71 std::string GetPinName(unsigned char pin);
72
73 const picpin* GetPinsValues(void);
74 void SetPin(unsigned char pin, unsigned char value);
75 void SetAPin(unsigned char pin, float value);
76 void SetPinDOV(unsigned char pin, unsigned char ovalue);
77 void SetPinDir(unsigned char pin, unsigned char dir);
78 void WritePin(unsigned char pin, unsigned char value);
79 void WritePinA(unsigned char pin, unsigned char avalue);
80 void WritePinOA(unsigned char pin, unsigned short oavalue);
81 unsigned char RegisterIOpin(std::string pname, unsigned char pin = 0, unsigned char dir = PD_OUT);
82 unsigned char UnregisterIOpin(unsigned char pin);
83 part* AddPart(const char* partname, const int x, const int y, const float scale);
84 void DeletePart(const int partn);
85 void SetUseAlias(const int use) { useAlias = use; };
86 unsigned char GetUseAlias(void) { return useAlias; };
87 bool SavePinAlias(std::string fname);
88 bool LoadPinAlias(std::string fname, unsigned char show_error_msg = 0);
89 bool LoadConfig(std::string fname, const int disable_debug = 0);
90 void ClearPinAlias(void);
91 std::string GetAliasFname(void) { return alias_fname; };
92 float GetScale(void) { return scale; };
93 void SetScale(float s) { scale = s; };
94 void Reset(void);
95
96 void Setfdtype(int value);
97
98 int Getfdtype(void) { return fdtype; };
99
100 void ReadPreferences(char* name, char* value);
101 void WritePreferences(void);
102
103 bool SaveConfig(std::string fname);
104
105 std::string GetLoadConfigFile(void) { return LoadConfigFile; };
106
107 void SetfdOldFilename(const std::string ofn);
108
109 std::string GetOldFilename(void) { return oldfname; };
110
111 void SetPartOnDraw(int pod) { PartOnDraw = pod; };
112 int GetPartOnDraw(void) { return PartOnDraw; };
113
114 static int CanvasCmd(const CanvasCmd_t cmd);
115
116 static int WPropCmd(const char* ControlName, const PICSimLabWindowAction action, const char* Value,
117 void* ReturnBuff = NULL);
118
119 static int WindowCmd(const int id, const char* ControlName, const PICSimLabWindowAction action, const char* Value,
120 void* ReturnBuff = NULL);
121
122 int (*OnCanvasCmd)(const CanvasCmd_t cmd);
123
124 int (*OnWindowCmd)(const int id, const char* ControlName, const PICSimLabWindowAction action, const char* Value,
125 void* ReturnBuff);
126
127private:
128 float scale;
129 board* pboard;
130 std::string PinNames[MAX_PIN_COUNT];
131 std::string PinAlias[MAX_PIN_COUNT];
132 std::string alias_fname;
133 std::string LoadConfigFile;
134 picpin* Pins;
135 unsigned char PinsCount;
136 unsigned char useAlias;
137 std::atomic<int> partsc;
138 part* parts[MAX_PARTS];
139 int partsc_aup; // always update list
140 part* parts_aup[MAX_PARTS]; // always update list
141 unsigned char pullup_bus[IOINIT];
142 int pullup_bus_count;
143 unsigned char pullup_bus_ptr[IOINIT];
144 int fdtype;
145 std::string oldfname;
146 int PartOnDraw;
147};
148
149extern CSpareParts SpareParts;
150
151#endif // SPAREPARTS
Definition spareparts.h:34
void Process(void)
Execute the process code of spare parts N times (where N is the number of steps in 100ms)
Definition spareparts.cc:548
std::string GetPinsNames(void)
Return the name of all pins.
Definition spareparts.cc:119
std::string GetPinName(unsigned char pin)
Return the name of one pin.
Definition spareparts.cc:146
void PostProcess(void)
Execute the post process code of spare parts one time per 100ms.
Definition spareparts.cc:568
void PreProcess(void)
Execute the pre process code of spare parts one time per 100ms.
Definition spareparts.cc:523
Board class.
Definition board.h:114
PART class.
Definition part.h:49
Definition draw.h:80