PICSimLab - Programmable IC Simulator Laboratory 0.9.2
PICSimLab - API
Loading...
Searching...
No Matches
spareparts.h
1/* ########################################################################
2
3 PICSimLab - Programmable IC Simulator Laboratory
4
5 ########################################################################
6
7 Copyright (c) : 2010-2024 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
34#define IOINIT 110
35
37public:
39
40 void Init(void);
41
42 void UpdateAll(const int force = 0);
43 int GetCount(void) { return partsc; };
44 part* GetPart(const 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, const float scale);
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 Setfdtype(int value);
99
100 int Getfdtype(void) { return fdtype; };
101
102 void ReadPreferences(char* name, char* value);
103 void WritePreferences(void);
104
105 bool SaveConfig(std::string fname);
106
107 std::string GetLoadConfigFile(void) { return LoadConfigFile; };
108
109 void SetfdOldFilename(const std::string ofn);
110
111 std::string GetOldFilename(void) { return oldfname; };
112
113 void SetPartOnDraw(int pod) { PartOnDraw = pod; };
114 int GetPartOnDraw(void) { return PartOnDraw; };
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[256];
133 std::string PinAlias[256];
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};
150
151extern CSpareParts SpareParts;
152
153#endif // SPAREPARTS
Definition spareparts.h:36
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:111
PART class.
Definition part.h:49
Definition draw.h:80