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 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 SetBGColor(std::string bgc) { bgcolor = bgc; };
97 std::string GetBGColor(void) { return bgcolor; };
98
99 void Setfdtype(int value);
100
101 int Getfdtype(void) { return fdtype; };
102
103 void ReadPreferences(char* name, char* value);
104 void WritePreferences(void);
105
106 bool SaveConfig(std::string fname);
107
108 std::string GetLoadConfigFile(void) { return LoadConfigFile; };
109
110 void SetfdOldFilename(const std::string ofn);
111
112 std::string GetOldFilename(void) { return oldfname; };
113
114 void SetPartOnDraw(int pod) { PartOnDraw = pod; };
115 int GetPartOnDraw(void) { return PartOnDraw; };
116
117 static int CanvasCmd(const CanvasCmd_t cmd);
118
119 static int WPropCmd(const char* ControlName, const PICSimLabWindowAction action, const char* Value,
120 void* ReturnBuff = NULL);
121
122 static int WindowCmd(const int id, const char* ControlName, const PICSimLabWindowAction action, const char* Value,
123 void* ReturnBuff = NULL);
124
125 int (*OnCanvasCmd)(const CanvasCmd_t cmd);
126
127 int (*OnWindowCmd)(const int id, const char* ControlName, const PICSimLabWindowAction action, const char* Value,
128 void* ReturnBuff);
129
130private:
131 float scale;
132 board* pboard;
133 std::string PinNames[MAX_PIN_COUNT];
134 std::string PinAlias[MAX_PIN_COUNT];
135 std::string alias_fname;
136 std::string LoadConfigFile;
137 picpin* Pins;
138 unsigned char PinsCount;
139 unsigned char useAlias;
140 std::atomic<int> partsc;
141 part* parts[MAX_PARTS];
142 int partsc_aup; // always update list
143 part* parts_aup[MAX_PARTS]; // always update list
144 unsigned char pullup_bus[IOINIT];
145 int pullup_bus_count;
146 unsigned char pullup_bus_ptr[IOINIT];
147 int fdtype;
148 std::string oldfname;
149 int PartOnDraw;
150 std::string bgcolor;
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:551
std::string GetPinsNames(void)
Return the name of all pins.
Definition spareparts.cc:120
std::string GetPinName(unsigned char pin)
Return the name of one pin.
Definition spareparts.cc:147
void PostProcess(void)
Execute the post process code of spare parts one time per 100ms.
Definition spareparts.cc:571
void PreProcess(void)
Execute the pre process code of spare parts one time per 100ms.
Definition spareparts.cc:526
Board class.
Definition board.h:114
PART class.
Definition part.h:49
Definition draw.h:80