Yangi boshlanuvchilar uchun qo'llanma Logisimga xush kelibsiz!


Download 1.38 Mb.
bet34/82
Sana16.04.2023
Hajmi1.38 Mb.
#1359783
1   ...   30   31   32   33   34   35   36   37   ...   82
Bog'liq
Logisim

SimpleCounter
com.cburch.gray paketi;
import com.cburch.logisim.data.BitWidth;
import com.cburch.logisim.data.Bounds;
import com.cburch.logisim.data.Direction;
import com.cburch.logisim.instance.InstanceFactory;
import com.cburch.logisim.instance.InstancePainter;
import com.cburch.logisim.instance.InstanceState;
import com.cburch.logisim.instance.Port;
import com.cburch.logisim.util.GraphicsUtil;
import com.cburch.logisim.util.StringUtil;
/** 4-bitli kulrang kodni takrorlaydigan oddiy hisoblagich ishlab chiqaradi. Bu
* misol komponent o'zining ichki holatini qanday saqlab turishini ko'rsatadi. Hammasi
Davlatga tegishli kodning * CounterData sinfida paydo bo'ladi. */
sinf SimpleGrayCounter InstanceFactory-ni kengaytiradi {
xususiy statik yakuniy BitWidth BIT_WIDTH = BitWidth.create(4);
// Yana e'tibor bering, bizda an bilan bog'liq hech qanday misol o'zgaruvchilari yo'q
// individual misol holati. Biz buni bu erga qo'ya olmaymiz, chunki faqat bitta
// SimpleGrayCounter ob'ekti doimo yaratilgan va uning vazifasi hammasini boshqarishdir
// har qanday sxemalarda paydo bo'ladigan misollar.
umumiy SimpleGrayCounter() {
super("Kulrang hisoblagich (oddiy)");
setOffsetBounds(Bounds.create(-30, -15, 30, 30));
setPorts(yangi port[] {
yangi port(-30, 0, Port.INPUT, 1),
yangi port (0, 0, Port.OUTPUT, BIT_WIDTH.getWidth()),
});
}
ommaviy bekor qilish (InstanceState holati) {
// Bu erda men ushbu komponent bilan bog'langan holatni yordamchi orqali olaman
// usul. Bunday holda, holat CounterData ob'ektida bo'ladi, ya'ni
// yordamchi metod aniqlangan joyda ham. Ushbu yordamchi usul tugaydi
// agar mavjud bo'lmasa, CounterData ob'ektini yaratish.
CounterData cur = CounterData.get (holat, BIT_WIDTH);
mantiqiy trigger = cur.updateClock(state.getPort(0));
if(trigger) cur.setValue(GrayIncrementer.nextGray(cur.getValue()));
state.setPort(1, cur.getValue(), 9);
// (Siz hisoblagichning joriy qiymatini aniqlash vasvasasiga tushishingiz mumkin
// state.getPort(1) orqali. Biroq, bu noto'g'ri, chunki boshqasi
// komponent qiymatni bir xil nuqtaga surishi mumkin
// u erda topilgan qiymatni "buzish". Biz haqiqatan ham saqlashimiz kerak
// misoldagi joriy qiymat.)
}
public void paintInstance (InstancePainter rassomi) {
painter.drawBounds();
painter.drawClock(0, Direction.EAST); // 0-portga uchburchak chizamiz
painter.drawPort(1); // 1-portni nuqta sifatida chizish
// To'rtburchaklar ichida markazlashtirilgan joriy hisoblagich qiymatini ko'rsatish.
// Biroq, agar kontekst holatni ko'rsatmaslikni aytsa (holatni yaratishda bo'lgani kabi
// printer chiqishi), keyin buni o'tkazib yuboring.
agar(painter.getShowState()) {
CounterData holati = CounterData.get(rassom, BIT_WIDTH);
Chegaralar bds = painter.getBounds();
GraphicsUtil.drawCenteredText(painter.getGraphics(),
StringUtil.toHexString(BIT_WIDTH.getWidth(), state.getValue().toIntValue()),
bds.getX() + bds.getWidth() / 2,
bds.getY() + bds.getHeight() / 2);
}
}
}

Download 1.38 Mb.

Do'stlaringiz bilan baham:
1   ...   30   31   32   33   34   35   36   37   ...   82




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling