//Add with carry void adc(CPU *c, OP_CODE_INFO *o){ int8_t carry = getFlag(c,C); int8_t accum = getRegByte(c,ACCUM); int8_t operand = o->operand; int16_t sum = (0x00FF&carry) + (0x00FF&accum) + (0x00FF&operand); int8_t sumByte = sum & 0x00FF; setZero(c,sumByte); if(getFlag(c,D)){ //in decimal mode //if lower 4 bits of operands plus //the carry in are larger than 9, //then we need to apply conversions //to remain in binary coded decimal format. if((accum & 0xF) + (operand & 0xF) + carry > 9){ sum += 6; } setSign(c,sum&0xFF); setOverflow(c,accum,operand,sum&0xFF); //if the higher bits aren't in //BCD format we need to add 96 to convert. //Black magic from http://nesdev.com/6502.txt sum += sum > 0x99 ? 96 : 0; setCarryBCD(c, sum); } else { setSign(c,sumByte); setOverflow(c,accum,operand,sumByte); setCarry(c,sum); } setRegByte(c,ACCUM,sum&0xFF); }
// addi method // Add a value to a register value // r[RD] = r[RD] + CONST void VirtualMachine::addi() { clock += 1; int sum = reg[binaryCode.f3.RD] + binaryCode.f3.CONST; if ( reg[binaryCode.f3.RD] >= 0 && binaryCode.f3.CONST >= 0 && sum < 0 ) setOverflow(); else if ( reg[binaryCode.f3.RD] < 0 && binaryCode.f3.CONST < 0 && sum >= 0 ) setOverflow(); reg[binaryCode.f3.RD] = sum; setCarryBit(); } // end addi method
// subci method // Subtract value and carry value from a register value // r[RD] = r[RD] - CONST - CARRY void VirtualMachine::subci() { clock += 1; int temp = reg[binaryCode.f1.RD] - binaryCode.f3.CONST - getCarryBit(); int complRS = ~binaryCode.f3.CONST + 1; if ( reg[binaryCode.f1.RD] >= 0 && complRS >= 0 && temp < 0 ) setOverflow(); else if ( reg[binaryCode.f1.RD] < 0 && complRS < 0 && temp >= 0 ) setOverflow(); reg[binaryCode.f1.RD] = temp; setCarryBit(); } // end subci method
// testADC() void testADC(int value) { int tmp; if ((regA ^ value) & N_FLAG) { CLV(); } else { setOverflow(); } if (decimalMode()) { tmp = (regA & 0xf) + (value & 0xf) + carrySet(); if (tmp >= 10) { tmp = 0x10 | ((tmp + 6) & 0xf); } tmp += (regA & 0xf0) + (value & 0xf0); if (tmp >= 160) { SEC(); if (overflowSet() && tmp >= 0x180) { CLV(); } tmp += 0x60; } else { CLC(); if (overflowSet() && tmp < 0x80) { CLV(); } } } else { tmp = regA + value + carrySet(); if (tmp >= 2*N_FLAG) { SEC(); if (overflowSet() && tmp >= 3*N_FLAG) { CLV(); } } else { CLC(); if (overflowSet() && tmp < N_FLAG) { CLV(); } } } regA = tmp & UMASK; setNVflagsForRegA(); }
// add method // Add two register values // r[RD] = r[RD] + r[RS] void VirtualMachine::add() { clock += 1; if ( binaryCode.f1.I == 0 ) { int sum = reg[binaryCode.f1.RD] + reg[binaryCode.f1.RS]; if ( reg[binaryCode.f1.RD] >= 0 && reg[binaryCode.f1.RS] >= 0 && sum < 0 ) setOverflow(); else if ( reg[binaryCode.f1.RD] < 0 && reg[binaryCode.f1.RS] < 0 && sum >= 0 ) setOverflow(); reg[binaryCode.f1.RD] = sum; setCarryBit(); } else addi(); } // end add method
// subc method // Subtract a register value and carry value from a register value // r[RD] = r[RD] - r[RS] - CARRY void VirtualMachine::subc() { clock += 1; if ( binaryCode.f1.I == 0 ) { int temp = reg[binaryCode.f1.RD] - reg[binaryCode.f1.RS] - getCarryBit(); int complRS = ~reg[binaryCode.f1.RS] + 1; if ( reg[binaryCode.f1.RD] >= 0 && complRS >= 0 && temp < 0 ) setOverflow(); else if ( reg[binaryCode.f1.RD] < 0 && complRS < 0 && temp >= 0 ) setOverflow(); reg[binaryCode.f1.RD] = temp; setCarryBit(); } else subci(); } // end subc method
WidgetGallery::WidgetGallery() : WContainerWidget() { setOverflow(Wt::Overflow::Hidden); auto navigation = Wt::cpp14::make_unique<Wt::WNavigationBar>(); navigation_ = navigation.get(); navigation_->addStyleClass("main-nav"); navigation_->setTitle("Wt Widget Gallery", "https://www.webtoolkit.eu/widgets"); navigation_->setResponsive(true); auto contentsStack = Wt::cpp14::make_unique<Wt::WStackedWidget>(); contentsStack_ = contentsStack.get(); Wt::WAnimation animation(Wt::AnimationEffect::Fade, Wt::TimingFunction::Linear, 200); contentsStack_->setTransitionAnimation(animation, true); /* * Setup the top-level menu */ auto menu = Wt::cpp14::make_unique<Wt::WMenu>(contentsStack_); menu->setInternalPathEnabled(); menu->setInternalBasePath("/"); addToMenu(menu.get(), "Layout", Wt::cpp14::make_unique<Layout>()); addToMenu(menu.get(), "Forms", Wt::cpp14::make_unique<FormWidgets>()); addToMenu(menu.get(), "Navigation", Wt::cpp14::make_unique<Navigation>()); addToMenu(menu.get(), "Trees & Tables", Wt::cpp14::make_unique<TreesTables>()) ->setPathComponent("trees-tables"); addToMenu(menu.get(), "Graphics & Charts", Wt::cpp14::make_unique<GraphicsWidgets>()) ->setPathComponent("graphics-charts"); //addToMenu(menu.get(), "Events", Wt::cpp14::make_unique<EventsDemo>()); addToMenu(menu.get(), "Media", Wt::cpp14::make_unique<Media>()); navigation_->addMenu(std::move(menu)); /* * Add it all inside a layout */ auto layout = this->setLayout(Wt::cpp14::make_unique<Wt::WVBoxLayout>()); layout->addWidget(std::move(navigation), 0); layout->addWidget(std::move(contentsStack), 1); layout->setContentsMargins(0, 0, 0, 0); }
void WContainerWidget::setLayout(WLayout *layout, WFlags<AlignmentFlag> alignment) { #ifndef WT_NO_LAYOUT if (layout_ && layout != layout_) delete layout_; #ifndef OLD_LAYOUT if (alignment != AlignJustify) { LOG_WARN("setLayout(layout, alignment) is being deprecated (and does no longer " "have the special meaning it used to have). Use spacers or CSS " "instead to control alignment"); } #endif contentAlignment_ = alignment; if (layout != layout_) { layout_ = layout; flags_.set(BIT_LAYOUT_NEEDS_RERENDER); if (layout) { WWidget::setLayout(layout); layoutImpl()->setContainer(this); /* * Normally, scrollbars are not used automatically for a container, * which applies to when a layout overflows. * * Only for IE 6 we really need to set this otherwise the parent * increases its size automatically and then we cannot reduce in * size (standard behaviour is overflow visible which says the * parent size should not be affected). Luckily, IE does not show the * scrollbars unless really needed */ if (WApplication::instance()->environment().agentIsIElt(9)) { AlignmentFlag vAlign = alignment & AlignVerticalMask; if (vAlign == 0) setOverflow(WContainerWidget::OverflowHidden); } } } #else assert(false); #endif }
WidgetGallery::WidgetGallery() : WContainerWidget() { setOverflow(OverflowHidden); navigation_ = new Wt::WNavigationBar(); navigation_->addStyleClass("main-nav"); navigation_->setTitle("Wt Widget Gallery", "https://www.webtoolkit.eu/widgets"); navigation_->setResponsive(true); contentsStack_ = new Wt::WStackedWidget(); Wt::WAnimation animation(Wt::WAnimation::Fade, Wt::WAnimation::Linear, 200); contentsStack_->setTransitionAnimation(animation, true); /* * Setup the top-level menu */ Wt::WMenu *menu = new Wt::WMenu(contentsStack_, 0); menu->setInternalPathEnabled(); menu->setInternalBasePath("/"); addToMenu(menu, "Layout", new Layout()); addToMenu(menu, "Forms", new FormWidgets()); addToMenu(menu, "Navigation", new Navigation()); addToMenu(menu, "Trees & Tables", new TreesTables()) ->setPathComponent("trees-tables"); addToMenu(menu, "Graphics & Charts", new GraphicsWidgets()) ->setPathComponent("graphics-charts"); // addToMenu(menu, "Events", new EventsDemo()); addToMenu(menu, "Media", new Media()); navigation_->addMenu(menu); /* * Add it all inside a layout */ Wt::WVBoxLayout *layout = new Wt::WVBoxLayout(this); layout->addWidget(navigation_); layout->addWidget(contentsStack_, 1); layout->setContentsMargins(0, 0, 0, 0); }
// testSBC() void testSBC(int value ) { int tmp,w; if ((regA ^ value) & N_FLAG) {setOverflow();} else {CLV();} if (decimalMode()) { tmp = 0xf + (regA & 0xf) - (value & 0xf) + carrySet(); if (tmp < 0x10) { w = 0; tmp -= 6; } else { w = 0x10; tmp -= 0x10; } w += 0xf0 + (regA & 0xf0) - (value & 0xf0); if (w < 0x100) { CLC(); if (overflowSet() && w < 0x80) { CLV(); } w -= 0x60; } else { SEC(); if (overflowSet() && w >= 0x180) { CLV(); } } w += tmp; } else { w = UMASK + regA - value + carrySet(); if (w < 1+UMASK) { CLC(); if (overflowSet() && w < N_FLAG) { CLV(); } } else { SEC(); if (overflowSet() && w >= (3*N_FLAG)) { CLV(); } } } regA = w & UMASK; setNVflagsForRegA(); }
// ---------------------------------------------------------------------------- uint16_t xpcc::stm32::Timer1::setPeriod(uint32_t microseconds, bool autoApply) { // This will be inaccurate for non-smooth frequencies (last six digits // unequal to zero) uint32_t cycles = microseconds * ( ((STM32_APB2_FREQUENCY==STM32_AHB_FREQUENCY)?1:2) * STM32_APB2_FREQUENCY / 1000000UL); uint16_t prescaler = (cycles + 65535) / 65536; // always round up uint16_t overflow = cycles / prescaler; overflow = overflow - 1; // e.g. 36000 cycles are from 0 to 35999 setPrescaler(prescaler); setOverflow(overflow); if (autoApply) { // Generate Update Event to apply the new settings for ARR TIM1->EGR |= TIM_EGR_UG; } return overflow; }