PICSimLab - Programmable IC Simulator Laboratory 0.9.3
PICSimLab - API
Loading...
Searching...
No Matches
spareparts.h
1/* ########################################################################
2
3 PICSimLab - Programmable IC Simulator Laboratory
4
5 ########################################################################
6
7 Copyright (c) : 2010-2026 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
34class CSpareParts {
35public:
36 CSpareParts();
37
38 void Init(void);
39
40 void SetUpdateAll(const int update);
41 int GetUpdateAll(void) { return need_update; };
42
43 int GetCount(void) { return partsc; };
44 part* GetPart(const unsigned int partn);
45 void DeleteParts(void);
46 void ResetPullupBus(unsigned char pin);
47 void SetPullupBus(unsigned char pin, unsigned char value);
48 unsigned char GetPullupBus(unsigned char pin);
49
53 void Process(void);
54
58 void PreProcess(void);
59
63 void PostProcess(void);
64
68 std::string GetPinsNames(void);
69
73 std::string GetPinName(unsigned char pin);
74
75 const picpin* GetPinsValues(void);
76 void SetPin(unsigned char pin, unsigned char value);
77 void SetAPin(unsigned char pin, float value);
78 void SetPinDOV(unsigned char pin, unsigned char ovalue);
79 void SetPinDir(unsigned char pin, unsigned char dir);
80 void WritePin(unsigned char pin, unsigned char value);
81 void WritePinA(unsigned char pin, unsigned char avalue);
82 void WritePinOA(unsigned char pin, unsigned short oavalue);
83 unsigned char RegisterIOpin(std::string pname, unsigned char pin = 0, unsigned char dir = PD_OUT);
84 unsigned char UnregisterIOpin(unsigned char pin);
85 part* AddPart(const char* partname, const int x, const int y);
86 void DeletePart(const int partn);
87 void SetUseAlias(const int use) { useAlias = use; };
88 unsigned char GetUseAlias(void) { return useAlias; };
89 bool SavePinAlias(std::string fname);
90 bool LoadPinAlias(std::string fname, unsigned char show_error_msg = 0);
91 bool LoadConfig(std::string fname, const int disable_debug = 0);
92 void ClearPinAlias(void);
93 std::string GetAliasFname(void) { return alias_fname; };
94 float GetScale(void) { return scale; };
95 void SetScale(float s) { scale = s; };
96 void Reset(void);
97
98 void SetBGColor(std::string bgc) { bgcolor = bgc; };
99 std::string GetBGColor(void) { return bgcolor; };
100
101 void Setfdtype(int value);
102
103 int Getfdtype(void) { return fdtype; };
104
105 void ReadPreferences(char* name, char* value);
106 void WritePreferences(void);
107
108 bool SaveConfig(std::string fname);
109
110 std::string GetLoadConfigFile(void) { return LoadConfigFile; };
111
112 void SetfdOldFilename(const std::string ofn);
113
114 std::string GetOldFilename(void) { return oldfname; };
115
116 static int CanvasCmd(const CanvasCmd_t cmd);
117
118 static int WPropCmd(const char* ControlName, const PICSimLabWindowAction action, const char* Value,
119 void* ReturnBuff = NULL);
120
121 static int WindowCmd(const int id, const char* ControlName, const PICSimLabWindowAction action, const char* Value,
122 void* ReturnBuff = NULL);
123
124 int (*OnCanvasCmd)(const CanvasCmd_t cmd);
125
126 int (*OnWindowCmd)(const int id, const char* ControlName, const PICSimLabWindowAction action, const char* Value,
127 void* ReturnBuff);
128
129private:
130 float scale;
131 board* pboard;
132 std::string PinNames[MAX_PIN_COUNT];
133 std::string PinAlias[MAX_PIN_COUNT];
134 std::string alias_fname;
135 std::string LoadConfigFile;
136 picpin* Pins;
137 unsigned char PinsCount;
138 unsigned char useAlias;
139 std::atomic<int> partsc;
140 part* parts[MAX_PARTS];
141 int partsc_aup; // always update list
142 part* parts_aup[MAX_PARTS]; // always update list
143 unsigned char pullup_bus[IOINIT];
144 int pullup_bus_count;
145 unsigned char pullup_bus_ptr[IOINIT];
146 int fdtype;
147 std::string oldfname;
148 int PartOnDraw;
149 std::string bgcolor;
150 int need_update;
151};
152
153extern CSpareParts SpareParts;
154
155#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:571
std::string GetPinsNames(void)
Return the name of all pins.
Definition spareparts.cc:127
std::string GetPinName(unsigned char pin)
Return the name of one pin.
Definition spareparts.cc:154
void PostProcess(void)
Execute the post process code of spare parts one time per 100ms.
Definition spareparts.cc:591
void PreProcess(void)
Execute the pre process code of spare parts one time per 100ms.
Definition spareparts.cc:546
Board class.
Definition board.h:114
PART class.
Definition part.h:49
Definition draw.h:81