Commit bbdb4cf0 authored by lcgamboa's avatar lcgamboa

new: New part \"Logic Block\" with logic functions: Not, Buffer, And, Nand, Or, Nor, Xor and Xnor.

parent 4ba8ae87
...@@ -2,5 +2,5 @@ PACKAGE=picsimlab ...@@ -2,5 +2,5 @@ PACKAGE=picsimlab
MAINVER=0 MAINVER=0
MINORVER=9 MINORVER=9
VERSION=0.9.2 VERSION=0.9.2
DATE=240407 DATE=240414
VERSION_STABLE=0.9.1 VERSION_STABLE=0.9.1
<img src="[push_buttons] (sobrescrita)" width="581" height="112" border="0" usemap="#map" />
<map name="map">
<!-- #$-:Image map file created by GIMP Image Map plug-in -->
<!-- #$-:GIMP Image Map plug-in by Maurits Rijk -->
<!-- #$-:Please do not edit lines starting with "#$" -->
<!-- #$VERSION:2.3 -->
<!-- #$AUTHOR:Luis Claudio Gamboa Lopes -->
<area shape="rect" coords="523,58,572,77" href="O_PN_9" />
<area shape="rect" coords="523,82,572,101" href="O_PN_10" />
<area shape="rect" coords="559,43,569,53" href="O_OUT" />
<area shape="rect" coords="477,20,543,39" href="O_TYPE" />
<area shape="rect" coords="9,82,58,101" href="O_PN_1" />
<area shape="rect" coords="14,66,24,76" href="O_IN_1" />
<area shape="rect" coords="71,82,120,101" href="O_PN_2" />
<area shape="rect" coords="76,66,86,76" href="O_IN_2" />
<area shape="rect" coords="134,82,183,101" href="O_PN_3" />
<area shape="rect" coords="138,66,148,76" href="O_IN_3" />
<area shape="rect" coords="195,82,244,101" href="O_PN_4" />
<area shape="rect" coords="200,66,210,76" href="O_IN_4" />
<area shape="rect" coords="257,82,306,101" href="O_PN_5" />
<area shape="rect" coords="262,66,272,76" href="O_IN_5" />
<area shape="rect" coords="321,82,370,101" href="O_PN_6" />
<area shape="rect" coords="326,66,336,76" href="O_IN_6" />
<area shape="rect" coords="383,82,432,101" href="O_PN_7" />
<area shape="rect" coords="387,66,397,76" href="O_IN_7" />
<area shape="rect" coords="444,82,493,101" href="O_PN_8" />
<area shape="rect" coords="448,66,458,76" href="O_IN_8" />
</map>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
width="581"
height="112"
viewBox="0 0 46598 9016.9"
version="1.1"
id="svg1514"
sodipodi:docname="part.svg"
inkscape:version="1.2.2 (b0a8486541, 2022-12-01)"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<defs
id="defs1518">
<mask
maskUnits="userSpaceOnUse"
id="mask7851">
<g
id="g7877"
transform="translate(41785,12097)">
<g
id="g7875">
<path
fill="#ffffff"
d="M -105,-17 H 46734 V 9644 H -105 Z"
id="path7853" />
<path
stroke="#000000"
stroke-linecap="round"
stroke-width="393"
d="m 45215,4203 v 0 m -1000,0 v 0 m 1000,1000 v 0 m -1000,0 v 0 m 1000,1000 v 0 m -1000,0 v 0 m 1000,1000 v 0 m -1000,0 v 0 m 1000,1000 v 0 m -1000,0 v 0"
id="path7855" />
<path
stroke="#000000"
stroke-linecap="round"
stroke-width="433"
d="m 24274,2580 v 0 m 1,1771 v 0 M 21715,2579 v 0 m 0,1772 v 0 m 7600,-1748 v 0 m 0,1772 v 0 M 26755,2603 v 0 m 0,1772 v 0 m 7520,-1772 v 0 m -1,1771 v 0 M 31715,2603 v 0 m 0,1772 v 0"
id="path7857" />
<path
stroke="#000000"
stroke-linecap="round"
stroke-width="275"
d="m 25615,603 v 0 m 0,2000 v 0 M 30615,603 v 0 m 0,2000 v 0"
id="path7859" />
<path
stroke="#000000"
stroke-linecap="round"
stroke-width="433"
d="m 39174,2580 v 0 m 1,1771 v 0 M 36615,2579 v 0 m 0,1772 v 0 M 19215,2579 v 0 m 0,1772 v 0 M 16655,2579 v 0 m 0,1772 v 0"
id="path7861" />
<path
stroke="#000000"
stroke-linecap="round"
stroke-width="275"
d="m 20615,603 v 0 m 0,2000 v 0 M 5515,603 v 0 m 0,2000 v 0"
id="path7863" />
<path
stroke="#000000"
stroke-linecap="round"
stroke-width="354"
d="m 41047,1303 v 0 m 984,0 v 0 m 984,0 v 0 m -1968,1300 v 0 m 984,0 v 0 m 984,0 v 0"
id="path7865" />
<path
stroke="#000000"
stroke-linecap="round"
stroke-width="433"
d="m 4215,2603 v 0 m 0,1772 v 0 M 1655,2603 v 0 m 0,1772 v 0"
id="path7867" />
<path
stroke="#000000"
stroke-linecap="round"
stroke-width="275"
d="m 35515,603 v 0 m 0,2000 v 0"
id="path7869" />
<path
stroke="#000000"
stroke-linecap="round"
stroke-width="433"
d="m 14174,2580 v 0 m 1,1771 v 0 M 11615,2579 v 0 m 0,1772 v 0 M 9215,2579 v 0 m 0,1772 v 0 M 6655,2579 v 0 m 0,1772 v 0"
id="path7871" />
<path
stroke="#000000"
stroke-linecap="round"
stroke-width="275"
d="m 515,603 v 0 m 0,2000 v 0 M 10515,603 v 0 m 0,2000 v 0 M 15515,603 v 0 m 0,2000 v 0"
id="path7873" />
</g>
</g>
</mask>
<clipPath
clipPathUnits="userSpaceOnUse"
id="clipPath7907">
<g
id="g7913"
transform="translate(41785,12097)">
<g
id="g7911">
<path
d="M 46715,3 H -85 V 9003 H 46715 V 3"
fill-rule="evenodd"
id="path7909" />
</g>
</g>
</clipPath>
</defs>
<sodipodi:namedview
id="namedview1516"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:showpageshadow="2"
inkscape:pageopacity="0.0"
inkscape:pagecheckerboard="0"
inkscape:deskcolor="#d1d1d1"
showgrid="false"
inkscape:zoom="2.1071429"
inkscape:cx="251.76271"
inkscape:cy="55.999999"
inkscape:window-width="1920"
inkscape:window-height="1025"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:window-maximized="1"
inkscape:current-layer="svg1514" />
<rect
style="fill:#313d63;fill-opacity:1;stroke:#000000;stroke-width:1.3927;stroke-dasharray:none"
id="rect8030"
width="46748.02"
height="9015.5068"
x="-62.130016"
y="0.69635189" />
<g
fill-opacity="0"
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="39.37"
fill="none"
stroke="#000000"
id="g11"
transform="translate(-41785,-12097)"
mask="url(#mask7851)"
clip-path="url(#clipPath7907)" />
<rect
style="fill:#ffffff;stroke:#000000;stroke-width:0.588305;stroke-dasharray:none"
id="rect7976"
width="6577.9277"
height="3188.6836"
x="37671.254"
y="815.65051" />
</svg>
/* ########################################################################
PICSimLab - Programmable IC Simulator Laboratory
########################################################################
Copyright (c) : 2010-2024 Luis Claudio Gambôa Lopes <lcgamboa@yahoo.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
For e-mail suggestions : lcgamboa@yahoo.com
######################################################################## */
#include "other_logic_block.h"
#include "../lib/oscilloscope.h"
#include "../lib/picsimlab.h"
#include "../lib/spareparts.h"
/* outputs */
enum {
O_P1,
O_P2,
O_P3,
O_P4,
O_P5,
O_P6,
O_P7,
O_P8,
O_P9,
O_P10,
O_IN1,
O_IN2,
O_IN3,
O_IN4,
O_IN5,
O_IN6,
O_IN7,
O_IN8,
O_OUT,
O_TYPE
};
static PCWProp pcwprop[14] = {{PCW_COMBO, "1 - In 1"},
{PCW_COMBO, "2 - In 2"},
{PCW_COMBO, "3 - In 3"},
{PCW_COMBO, "4 - In 4"},
{PCW_COMBO, "5 - In 5"},
{PCW_COMBO, "6 - In 6"},
{PCW_COMBO, "7 - In 7"},
{PCW_COMBO, "8 - In 8"},
{PCW_COMBO, "9 - Out"},
{PCW_LABEL, "10 - Out,NC"},
{PCW_COMBO, "Type"},
{PCW_SPIN, "Size"},
{PCW_END, ""}};
cpart_lblock::cpart_lblock(const unsigned x, const unsigned y, const char* name, const char* type, board* pboard_,
const int id_)
: part(x, y, name, type, pboard_, id_) {
gatetype = LG_NOT;
Size = 0;
BitmapId = -1;
always_update = 1;
ReadMaps();
OWidth = Width;
OHeight = Height;
ChangeSize(1);
input_pins[0] = 0;
input_pins[1] = 0;
input_pins[2] = 0;
input_pins[3] = 0;
input_pins[4] = 0;
input_pins[5] = 0;
input_pins[6] = 0;
input_pins[7] = 0;
output_value = 0;
output_pins[0] = 0;
output_pins[1] = SpareParts.RegisterIOpin("LB0");
output_pins_alm = 0;
SetPCWProperties(pcwprop);
PinCount = 8;
Pins = input_pins;
}
void cpart_lblock::Reset(void) {
// release all
output_value = 0;
// force pin update
SpareParts.SetPin(output_pins[0], output_value);
SpareParts.SetPin(output_pins[1], output_value);
}
cpart_lblock::~cpart_lblock(void) {
SpareParts.UnregisterIOpin(output_pins[1]);
SpareParts.SetPartOnDraw(id);
SpareParts.CanvasCmd({CC_FREEBITMAP, .FreeBitmap{BitmapId}});
SpareParts.CanvasCmd({CC_DESTROY});
}
void cpart_lblock::DrawOutput(const unsigned int i) {
const picpin* ppins = SpareParts.GetPinsValues();
switch (output[i].id) {
case O_P1:
case O_P2:
case O_P3:
case O_P4:
case O_P5:
case O_P6:
case O_P7:
case O_P8:
SpareParts.CanvasCmd({CC_SETCOLOR, .SetColor{49, 61, 99}});
SpareParts.CanvasCmd({CC_RECTANGLE, .Rectangle{1, output[i].x1, output[i].y1, output[i].x2 - output[i].x1,
output[i].y2 - output[i].y1}});
SpareParts.CanvasCmd({CC_SETFGCOLOR, .SetFgColor{255, 255, 255}});
if (input_pins[output[i].id - O_P1] == 0)
SpareParts.CanvasCmd({CC_ROTATEDTEXT, .RotatedText{"NC", output[i].x1, output[i].y1, 0}});
else
SpareParts.CanvasCmd(
{CC_ROTATEDTEXT, .RotatedText{SpareParts.GetPinName(input_pins[output[i].id - O_P1]).c_str(),
output[i].x1, output[i].y1, 0}});
break;
case O_P9:
case O_P10:
SpareParts.CanvasCmd({CC_SETCOLOR, .SetColor{49, 61, 99}});
SpareParts.CanvasCmd({CC_RECTANGLE, .Rectangle{1, output[i].x1 - xoff, output[i].y1,
output[i].x2 - output[i].x1, output[i].y2 - output[i].y1}});
SpareParts.CanvasCmd({CC_SETFGCOLOR, .SetFgColor{255, 255, 255}});
if (output_pins[output[i].id - O_P9] == 0)
SpareParts.CanvasCmd({CC_ROTATEDTEXT, .RotatedText{"NC", output[i].x1 - xoff, output[i].y1, 0}});
else
SpareParts.CanvasCmd(
{CC_ROTATEDTEXT, .RotatedText{SpareParts.GetPinName(output_pins[output[i].id - O_P9]).c_str(),
output[i].x1 - xoff, output[i].y1, 0}});
break;
case O_IN1:
case O_IN2:
case O_IN3:
case O_IN4:
case O_IN5:
case O_IN6:
case O_IN7:
case O_IN8:
SpareParts.CanvasCmd(
{CC_SETCOLOR, .SetBgColor{(unsigned int)ppins[input_pins[output[i].id - O_IN1] - 1].oavalue, 0, 0}});
SpareParts.CanvasCmd({CC_RECTANGLE, .Rectangle{1, output[i].x1, output[i].y1, output[i].x2 - output[i].x1,
output[i].y2 - output[i].y1}});
break;
case O_OUT:
SpareParts.CanvasCmd({CC_SETCOLOR, .SetBgColor{(unsigned int)ppins[output_pins[1] - 1].oavalue, 0, 0}});
SpareParts.CanvasCmd({CC_RECTANGLE, .Rectangle{1, output[i].x1 - xoff, output[i].y1,
output[i].x2 - output[i].x1, output[i].y2 - output[i].y1}});
break;
case O_TYPE:
SpareParts.CanvasCmd({CC_SETCOLOR, .SetColor{255, 255, 255}});
SpareParts.CanvasCmd({CC_RECTANGLE, .Rectangle{1, output[i].x1 - xoff, output[i].y1,
output[i].x2 - output[i].x1, output[i].y2 - output[i].y1}});
SpareParts.CanvasCmd({CC_SETFGCOLOR, .SetFgColor{0, 0, 0}});
SpareParts.CanvasCmd(
{CC_ROTATEDTEXT, .RotatedText{logicgate_name[gatetype], output[i].x1 - xoff, output[i].y1, 0}});
break;
}
}
void cpart_lblock::PreProcess(void) {
output_pins_alm = 0;
JUMPSTEPS_ =
PICSimLab.GetJUMPSTEPS() * 4.0 * PICSimLab.GetBoard()->MGetInstClockFreq() / PICSimLab.GetBoard()->MGetFreq();
mcount = JUMPSTEPS_;
}
void cpart_lblock::Process(void) {
const picpin* ppins = SpareParts.GetPinsValues();
if (ioupdated) {
switch (gatetype) {
case LG_NOT:
output_value = !ppins[input_pins[0] - 1].value;
break;
case LG_BUFFER:
output_value = ppins[input_pins[0] - 1].value;
break;
case LG_AND:
output_value = ppins[input_pins[0] - 1].value;
for (unsigned int i = 1; i < Size; i++) {
output_value &= ppins[input_pins[i] - 1].value;
}
break;
case LG_NAND:
output_value = ppins[input_pins[0] - 1].value;
for (unsigned int i = 1; i < Size; i++) {
output_value &= ppins[input_pins[i] - 1].value;
}
output_value = !output_value;
break;
case LG_OR:
output_value = ppins[input_pins[0] - 1].value;
for (unsigned int i = 1; i < Size; i++) {
output_value |= ppins[input_pins[i] - 1].value;
}
break;
case LG_NOR:
output_value = ppins[input_pins[0] - 1].value;
for (unsigned int i = 1; i < Size; i++) {
output_value |= ppins[input_pins[i] - 1].value;
}
output_value = !output_value;
break;
case LG_XOR:
output_value = ppins[input_pins[0] - 1].value;
for (unsigned int i = 1; i < Size; i++) {
output_value ^= ppins[input_pins[i] - 1].value;
}
break;
case LG_XNOR:
output_value = ppins[input_pins[0] - 1].value;
for (unsigned int i = 1; i < Size; i++) {
output_value ^= ppins[input_pins[i] - 1].value;
}
output_value = !output_value;
break;
break;
}
SpareParts.SetPin(output_pins[0], output_value);
SpareParts.WritePin(output_pins[1], output_value);
}
mcount++;
if (mcount >= JUMPSTEPS_) {
if (ppins[output_pins[1] - 1].value)
output_pins_alm++;
mcount = -1;
}
}
void cpart_lblock::PostProcess(void) {
const long int NSTEPJ = PICSimLab.GetNSTEPJ();
// const picpin* ppins = SpareParts.GetPinsValues();
/*
for (unsigned int i = 0; i < Size; i++) {
if (input_pins[i] && (output_ids[O_L1 + i]->value != ppins[input_pins[i] - 1].oavalue)) {
output_ids[O_L1 + i]->value = ppins[input_pins[i] - 1].oavalue;
output_ids[O_L1 + i]->update = 1;
}
}
*/
// SpareParts.WritePinOA(output_pins[1],
// (ppins[output_pins[1] - 1].oavalue + ((output_pins_alm * 200.0) / NSTEPJ) + 55) / 2);
SpareParts.WritePinOA(output_pins[1], ((output_pins_alm * 200.0) / NSTEPJ) + 55);
SetUpdate(1); // TODO update only when necessary
}
unsigned short cpart_lblock::GetInputId(char* name) {
printf("Error input '%s' don't have a valid id! \n", name);
return INVALID_ID;
}
unsigned short cpart_lblock::GetOutputId(char* name) {
if (strcmp(name, "PN_1") == 0)
return O_P1;
if (strcmp(name, "PN_2") == 0)
return O_P2;
if (strcmp(name, "PN_3") == 0)
return O_P3;
if (strcmp(name, "PN_4") == 0)
return O_P4;
if (strcmp(name, "PN_5") == 0)
return O_P5;
if (strcmp(name, "PN_6") == 0)
return O_P6;
if (strcmp(name, "PN_7") == 0)
return O_P7;
if (strcmp(name, "PN_8") == 0)
return O_P8;
if (strcmp(name, "PN_9") == 0)
return O_P9;
if (strcmp(name, "PN_10") == 0)
return O_P10;
if (strcmp(name, "IN_1") == 0)
return O_IN1;
if (strcmp(name, "IN_2") == 0)
return O_IN2;
if (strcmp(name, "IN_3") == 0)
return O_IN3;
if (strcmp(name, "IN_4") == 0)
return O_IN4;
if (strcmp(name, "IN_5") == 0)
return O_IN5;
if (strcmp(name, "IN_6") == 0)
return O_IN6;
if (strcmp(name, "IN_7") == 0)
return O_IN7;
if (strcmp(name, "IN_8") == 0)
return O_IN8;
if (strcmp(name, "OUT") == 0)
return O_OUT;
if (strcmp(name, "TYPE") == 0)
return O_TYPE;
printf("Error output '%s' don't have a valid id! \n", name);
return INVALID_ID;
}
std::string cpart_lblock::WritePreferences(void) {
char prefs[256];
sprintf(prefs, "%hhu,%hhu,%hhu,%hhu,%hhu,%hhu,%hhu,%hhu,%hhu,%hhu,%hhu,%u", input_pins[0], input_pins[1],
input_pins[2], input_pins[3], input_pins[4], input_pins[5], input_pins[6], input_pins[7], output_pins[0],
output_pins[1], gatetype, Size);
return prefs;
}
void cpart_lblock::ReadPreferences(std::string value) {
unsigned int sz;
unsigned char outp;
sscanf(value.c_str(), "%hhu,%hhu,%hhu,%hhu,%hhu,%hhu,%hhu,%hhu,%hhu,%hhu,%hhu,%u", &input_pins[0], &input_pins[1],
&input_pins[2], &input_pins[3], &input_pins[4], &input_pins[5], &input_pins[6], &input_pins[7],
&output_pins[0], &outp, &gatetype, &sz);
SpareParts.UnregisterIOpin(output_pins[1]);
output_pins[1] = SpareParts.RegisterIOpin("LB0", outp);
ChangeSize(sz);
}
void cpart_lblock::ConfigurePropertiesWindow(void) {
SetPCWComboWithPinNames("combo1", input_pins[0]);
SetPCWComboWithPinNames("combo2", input_pins[1]);
SetPCWComboWithPinNames("combo3", input_pins[2]);
SetPCWComboWithPinNames("combo4", input_pins[3]);
SetPCWComboWithPinNames("combo5", input_pins[4]);
SetPCWComboWithPinNames("combo6", input_pins[5]);
SetPCWComboWithPinNames("combo7", input_pins[6]);
SetPCWComboWithPinNames("combo8", input_pins[7]);
SetPCWComboWithPinNames("combo9", output_pins[0]);
SpareParts.WPropCmd("combo11", PWA_COMBOSETITEMS, "NOT,BUFFER,AND,NAND,OR,NOR,XOR,XNOR,");
SpareParts.WPropCmd("combo11", PWA_COMBOPROPEV, "1");
switch (gatetype) {
case LG_NOT:
SpareParts.WPropCmd("combo11", PWA_COMBOSETTEXT, "NOT");
SpareParts.WPropCmd("spin12", PWA_SPINSETMAX, "1");
SpareParts.WPropCmd("spin12", PWA_SPINSETMIN, "1");
break;
case LG_BUFFER:
SpareParts.WPropCmd("combo11", PWA_COMBOSETTEXT, "BUFFER");
SpareParts.WPropCmd("spin12", PWA_SPINSETMAX, "1");
SpareParts.WPropCmd("spin12", PWA_SPINSETMIN, "1");
break;
case LG_AND:
SpareParts.WPropCmd("combo11", PWA_COMBOSETTEXT, "AND");
SpareParts.WPropCmd("spin12", PWA_SPINSETMAX, "8");
SpareParts.WPropCmd("spin12", PWA_SPINSETMIN, "2");
break;
case LG_NAND:
SpareParts.WPropCmd("combo11", PWA_COMBOSETTEXT, "NAND");
SpareParts.WPropCmd("spin12", PWA_SPINSETMAX, "8");
SpareParts.WPropCmd("spin12", PWA_SPINSETMIN, "2");
break;
case LG_OR:
SpareParts.WPropCmd("combo11", PWA_COMBOSETTEXT, "OR");
SpareParts.WPropCmd("spin12", PWA_SPINSETMAX, "8");
SpareParts.WPropCmd("spin12", PWA_SPINSETMIN, "2");
break;
case LG_NOR:
SpareParts.WPropCmd("combo11", PWA_COMBOSETTEXT, "NOR");
SpareParts.WPropCmd("spin12", PWA_SPINSETMAX, "8");
SpareParts.WPropCmd("spin12", PWA_SPINSETMIN, "2");
break;
case LG_XOR:
SpareParts.WPropCmd("combo11", PWA_COMBOSETTEXT, "XOR");
SpareParts.WPropCmd("spin12", PWA_SPINSETMAX, "8");
SpareParts.WPropCmd("spin12", PWA_SPINSETMIN, "2");
break;
case LG_XNOR:
SpareParts.WPropCmd("combo11", PWA_COMBOSETTEXT, "XNOR");
SpareParts.WPropCmd("spin12", PWA_SPINSETMAX, "8");
SpareParts.WPropCmd("spin12", PWA_SPINSETMIN, "2");
break;
}
SpareParts.WPropCmd("spin12", PWA_SPINSETVALUE, std::to_string(Size).c_str());
SpareParts.WPropCmd("spin12", PWA_SPINPROPEV, "1");
SpinChange(NULL, Size);
}
void cpart_lblock::ReadPropertiesWindow(void) {
input_pins[0] = GetPWCComboSelectedPin("combo1");
input_pins[1] = GetPWCComboSelectedPin("combo2");
input_pins[2] = GetPWCComboSelectedPin("combo3");
input_pins[3] = GetPWCComboSelectedPin("combo4");
input_pins[4] = GetPWCComboSelectedPin("combo5");
input_pins[5] = GetPWCComboSelectedPin("combo6");
input_pins[6] = GetPWCComboSelectedPin("combo7");
input_pins[7] = GetPWCComboSelectedPin("combo8");
output_pins[0] = GetPWCComboSelectedPin("combo9");
char buff[64];
SpareParts.WPropCmd("combo11", PWA_COMBOGETTEXT, NULL, buff);
for (int i = 0; i < 8; i++) {
if (!strcmp(buff, logicgate_name[i])) {
gatetype = i;
break;
}
}
int size;
SpareParts.WPropCmd("spin12", PWA_SPINGETVALUE, NULL, &size);
ChangeSize(size);
}
void cpart_lblock::SpinChange(const char* controlname, int value) {
for (int i = 0; i < 8; i++) {
char name[20];
sprintf(name, "combo%i", i + 1);
SpareParts.WPropCmd(name, PWA_SETENABLE, std::to_string(i < value).c_str());
}
}
void cpart_lblock::ComboChange(const char* controlname, std::string value) {
char buff[64];
SpareParts.WPropCmd("combo11", PWA_COMBOGETTEXT, NULL, buff);
for (int i = 0; i < 8; i++) {
if (!strcmp(buff, logicgate_name[i])) {
gatetype = i;
break;
}
}
switch (gatetype) {
case LG_NOT:
case LG_BUFFER:
ChangeSize(1);
break;
case LG_AND:
case LG_NAND:
case LG_OR:
case LG_NOR:
case LG_XOR:
case LG_XNOR:
ChangeSize(2);
break;
}
ConfigurePropertiesWindow();
}
void cpart_lblock::ChangeSize(const unsigned int sz) {
if (Size != sz) {
if (BitmapId >= 0) {
SpareParts.SetPartOnDraw(id);
SpareParts.CanvasCmd({CC_FREEBITMAP, .FreeBitmap{BitmapId}});
}
Size = sz;
if (Size > 8) {
Size = 8;
}
outputc = (Size * 2) + 4;
LoadPartImage();
}
}
void cpart_lblock::LoadPartImage(void) {
if (Size < 8) {
xoff = (8 - Size) * 62;
outputc = (Size * 2) + 4;
Width = OWidth - xoff;
Height = OHeight;
SpareParts.SetPartOnDraw(id);
BitmapId = SpareParts.CanvasCmd({CC_CREATEIMAGE, .CreateImage{Width, Height, Scale, 0, Orientation}});
SpareParts.CanvasCmd({CC_DESTROY});
SpareParts.CanvasCmd({CC_CREATE, .Create{BitmapId}});
int BackBitmap = SpareParts.CanvasCmd(
{CC_LOADIMAGE, .LoadImage{(PICSimLab.GetSharePath() + "parts/" + Type + "/" + GetPictureFileName()).c_str(),
Scale, 0, Orientation}});
SpareParts.CanvasCmd({CC_INIT, .Init{Scale, Scale, Orientation}});
SpareParts.CanvasCmd({CC_SETCOLOR, .SetColor{0x31, 0x3d, 0x63}});
SpareParts.CanvasCmd({CC_RECTANGLE, .Rectangle{1, 0, 0, (float)Width, (float)Height}});
SpareParts.CanvasCmd({CC_CHANGESCALE, .ChangeScale{1.0, 1.0}});
SpareParts.CanvasCmd({CC_PUTBITMAP, .PutBitmap{BackBitmap, -xoff * Scale, 0}});
SpareParts.CanvasCmd({CC_CHANGESCALE, .ChangeScale{Scale, Scale}});
SpareParts.CanvasCmd({CC_END});
SpareParts.CanvasCmd({CC_FREEBITMAP, .FreeBitmap{BackBitmap}});
} else {
Width = OWidth;
Height = OHeight;
xoff = 0;
part::LoadPartImage();
}
}
part_init(PART_LOGIC_BLOCK_Name, cpart_lblock, "Other");
/* ########################################################################
PICSimLab - Programmable IC Simulator Laboratory
########################################################################
Copyright (c) : 2010-2024 Luis Claudio Gambôa Lopes <lcgamboa@yahoo.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
For e-mail suggestions : lcgamboa@yahoo.com
######################################################################## */
#ifndef PART_LOGIC_BLOCK_H
#define PART_LOGIC_BLOCK_H
#include "../lib/part.h"
#define PART_LOGIC_BLOCK_Name "Logic Block"
enum { LG_NOT, LG_BUFFER, LG_AND, LG_NAND, LG_OR, LG_NOR, LG_XOR, LG_XNOR };
const char* logicgate_name[] = {"NOT", "BUFFER", "AND", "NAND", "OR", "NOR", "XOR", "XNOR"};
class cpart_lblock : public part {
public:
std::string GetAboutInfo(void) override { return "L.C. Gamboa \n <lcgamboa@yahoo.com>"; };
cpart_lblock(const unsigned x, const unsigned y, const char* name, const char* type, board* pboard_, const int id_);
~cpart_lblock(void);
void DrawOutput(const unsigned int index) override;
void PreProcess(void) override;
void Process(void) override;
void PostProcess(void) override;
void Reset(void) override;
void ConfigurePropertiesWindow(void) override;
void ReadPropertiesWindow(void) override;
void LoadPartImage(void) override;
std::string WritePreferences(void) override;
void ReadPreferences(std::string value) override;
unsigned short GetInputId(char* name) override;
unsigned short GetOutputId(char* name) override;
void SpinChange(const char* controlname, int value) override;
void ComboChange(const char* controlname, std::string value) override;
private:
void ChangeSize(const unsigned int sz);
unsigned char gatetype;
unsigned char input_pins[8];
unsigned char output_pins[2];
unsigned long output_pins_alm;
unsigned char output_value;
int OWidth;
int OHeight;
int xoff;
unsigned int Size;
long mcount;
int JUMPSTEPS_;
};
#endif /* PART_LOGIC_BLOCK_H */
...@@ -662,7 +662,7 @@ static void set_signal_handler(void) { ...@@ -662,7 +662,7 @@ static void set_signal_handler(void) {
} }
#endif #endif
#else #else
static void set_signal_handler(void){}; static void set_signal_handler(void) {};
#endif #endif
void CPWindow1::_EvOnCreate(CControl* control) { void CPWindow1::_EvOnCreate(CControl* control) {
...@@ -2187,7 +2187,7 @@ int CPWindow1::WinCmd(CControl* ctrl, const PICSimLabWindowAction action, const ...@@ -2187,7 +2187,7 @@ int CPWindow1::WinCmd(CControl* ctrl, const PICSimLabWindowAction action, const
case PWA_COMBODELETEITEMS: case PWA_COMBODELETEITEMS:
((CCombo*)ctrl)->DeleteItems(); ((CCombo*)ctrl)->DeleteItems();
break; break;
case PWM_COMBOADDITEM: case PWA_COMBOADDITEM:
((CCombo*)ctrl)->AddItem(Value); ((CCombo*)ctrl)->AddItem(Value);
break; break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment