text stringlengths 1 1.05M |
|---|
; A118226: Start with 1 and repeatedly reverse the digits and add 76 to get the next term.
; 1,77,153,427,800,84,124,497,870,154,527,801,184,557,831,214,488,960,145,617,792,373,449,1020,277,848,924,505,581,261,238,908,885,664,542,321,199,1067,7677,7843,3563,3729,9349,9515,5235,5401,1121,1287,7897
mov $2,$0
mov $0,1
lpb $2
seq $0,4086 ; Read n backwards (referred to as R(n) in many sequences).
add $0,76
sub $2,1
lpe
|
/*
tests/conv.cpp -- tests special functions
Enoki is a C++ template library that enables transparent vectorization
of numerical kernels using SIMD instruction sets available on current
processor architectures.
Copyright (c) 2021 Wenzel Jakob <wenzel.jakob@epfl.ch>
All rights reserved. Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file.
*/
#include "test.h"
#include <enoki/special.h>
ENOKI_TEST_FLOAT(test01_i0e) {
using Scalar = scalar_t<T>;
double results[] = {
1.000000000, 0.4657596076, 0.3085083226, 0.2430003542,
0.2070019212, 0.1835408126, 0.1666574326, 0.1537377447,
0.1434317819, 0.1349595246, 0.1278333372, 0.1217301682,
0.1164262212, 0.1117608338, 0.1076152517, 0.1038995314
};
for (int i = 0; i < 16; ++i)
assert(hmax(abs(i0e(T(Scalar(i))) - T(Scalar(results[i])))) < 1e-6);
}
ENOKI_TEST_FLOAT(test02_erf) {
test::probe_accuracy<T>(
[](const T &a) -> T { return erf(a); },
[](double a) { return std::erf(a); },
Value(-1), Value(1), 6
);
Array<T, 4> x((Value) 0.5);
Array<T&, 4> y(x);
assert(erf(x) == erf(y));
}
ENOKI_TEST_FLOAT(test02_erfc) {
test::probe_accuracy<T>(
[](const T &a) -> T { return erfc(a); },
[](double a) { return std::erfc(a); },
Value(-1), Value(1), 17
);
Array<T, 4> x((Value) 0.5);
Array<T&, 4> y(x);
assert(erfc(x) == erfc(y));
}
ENOKI_TEST_FLOAT(test04_erfinv) {
for (int i = 0; i < 1000; ++i) {
auto f = T((float) i / 1000.0f * 2 - 1 + 1e-6f);
auto inv = erfinv(f);
auto f2 = erf(inv);
assert(std::abs(T(f-f2)[0]) < 1e-6f);
}
}
ENOKI_TEST_FLOAT(test05_dawson) {
using Scalar = scalar_t<T>;
double results[] = { 0.0,
0.09933599239785286, 0.1947510333680280, 0.2826316650213119,
0.3599434819348881, 0.4244363835020223, 0.4747632036629779,
0.5105040575592318, 0.5321017070563654, 0.5407243187262987,
0.5380795069127684, 0.5262066799705525, 0.5072734964077396,
0.4833975173848241, 0.4565072375268973, 0.4282490710853986,
0.3999398943230814, 0.3725593489740788, 0.3467727691148722,
0.3229743193228178, 0.3013403889237920, 0.2818849389255278,
0.2645107599508320, 0.2490529568377667, 0.2353130556638426,
0.2230837221674355, 0.2121651242424990, 0.2023745109105140,
0.1935507238593668, 0.1855552345354998, 0.1782710306105583 };
for (int i = 0; i <= 30; ++i) {
assert(hmax(abs(dawson(T(Scalar(i * 0.1))) - T(Scalar( results[i])))) < 1e-6);
assert(hmax(abs(dawson(T(Scalar(i * -0.1))) - T(Scalar(-results[i])))) < 1e-6);
}
}
ENOKI_TEST_FLOAT(test06_ellint_1) {
double result[] = { -14.28566868, -13.24785552, -11.73287659, -9.893205471,
-8.835904570, -7.468259577, -5.516159896, -4.419121129, -3.170330916,
-1.159661071, 0, 1.159661071, 3.170330916, 4.419121129, 5.516159896,
7.468259577, 8.835904570, 9.893205471, 11.73287659, 13.24785552,
14.28566868 };
for (int i=-10; i<=10; ++i)
assert((ellint_1(T((float) i), T(.9f))[0] - result[i+10]) < 2e-6);
}
ENOKI_TEST_FLOAT(test07_comp_ellint_1) {
double result[] = { 1.570796327, 1.574745562, 1.586867847, 1.608048620,
1.639999866, 1.685750355, 1.750753803, 1.845693998,
1.995302778, 2.280549138 };
for (int i=0; i<10; ++i)
assert((comp_ellint_1(T((float) i/10.f))[0] - result[i]) < 1e-6);
}
ENOKI_TEST_FLOAT(test08_ellint_2) {
double result[] = { -7.580388582, -6.615603622, -5.923080706, -5.355941680,
-4.406649345, -3.647370231, -3.121560380, -2.202184075, -1.380263348,
-0.8762622200, 0, 0.8762622200, 1.380263348, 2.202184075, 3.121560380,
3.647370231, 4.406649345, 5.355941680, 5.923080706, 6.615603622,
7.580388582 };
for (int i=-10; i<=10; ++i)
assert((ellint_2(scalar_t<T>(i), T(.9f))[0] - result[i+10]) < 3e-6);
}
ENOKI_TEST_FLOAT(test09_comp_ellint_2) {
double result[] = { 1.570796327, 1.566861942, 1.554968546, 1.534833465,
1.505941612, 1.467462209, 1.418083394, 1.355661136,
1.276349943, 1.171697053 };
for (int i=0; i<10; ++i)
assert((comp_ellint_2(T((float) i/10.f))[0] - result[i]) < 1e-6);
}
ENOKI_TEST_FLOAT(test10_ellint_3) {
double values[] = {
1.000000000, 1.001368050, 1.005529262, 1.012662720, 1.023095616,
1.037356120, 1.056273110, 1.081169466, 1.114267715, 1.159661071,
0.9739108232, 0.9752197204, 0.9792006242, 0.9860236410, 0.9959994565,
1.009629332, 1.027699365, 1.051463019, 1.083023814, 1.126250332,
0.9499559681, 0.9512112978, 0.9550289363, 0.9615709238, 0.9711331194,
0.9841926334, 1.001497200, 1.024238112, 1.054412465, 1.095688359,
0.9278496365, 0.9290561820, 0.9327251506, 0.9390112903, 0.9481970619,
0.9607377650, 0.9773465184, 0.9991585837, 1.028075279, 1.067584596,
0.9073578181, 0.9085197125, 0.9120526214, 0.9181046645, 0.9269461292,
0.9390125110, 0.9549855234, 0.9759496456, 1.003719507, 1.041620361,
0.8882866913, 0.8894075341, 0.8928153640, 0.8986522470, 0.9071773565,
0.9188081175, 0.9341976099, 0.9543840576, 0.9811032294, 1.017532566,
0.8704740713, 0.8715570194, 0.8748493996, 0.8804877250, 0.8887209781,
0.8999500224, 0.9148017149, 0.9342719585, 0.9600244531, 0.9951017555,
0.8537829977, 0.8548308371, 0.8580162656, 0.8634706822, 0.8714336878,
0.8822909075, 0.8966450863, 0.9154532476, 0.9403129557, 0.9741431606,
0.8380968526, 0.8391120566, 0.8421980757, 0.8474815829, 0.8551935114,
0.8657054139, 0.8795977838, 0.8977917933, 0.9218240876, 0.9544999068,
0.8233155947, 0.8243003700, 0.8272937093, 0.8324179034, 0.8398958507,
0.8500860662, 0.8635484385, 0.8811709703, 0.9044339982, 0.9360377889
};
int k = 0;
for (int j = 0; j < 10; ++j)
for (int i = 0; i < 10; ++i)
assert(std::abs(ellint_3(1.0f, (float) i / 10.f, T((float) j / 10.f))[0] - values[k++]) <
1e-6f);
double values2[] = { -11.3057, -10.3096, -9.16461, -7.87078, -6.87262,
-5.78783, -4.44026, -3.4361, -2.39321, -1.01753,
0, 1.01753, 2.39321, 3.4361, 4.44026,
5.78783, 6.87262, 7.87078, 9.16461, 10.3096,
11.3057 };
k = 0;
for (int i = -10; i <= 10; ++i)
assert(std::abs(ellint_3(T((float) i), 0.9f, 0.5f)[0] - values2[k++]) < 5e-5f);
}
ENOKI_TEST_FLOAT(test11_comp_ellint_3) {
double values[] = {
1.570796327, 1.574745562, 1.586867847, 1.608048620, 1.639999866,
1.685750355, 1.750753803, 1.845693998, 1.995302778, 2.280549138,
1.497695533, 1.501371111, 1.512651347, 1.532353469, 1.562056689,
1.604552494, 1.664861577, 1.752805017, 1.891075542, 2.153786851,
1.433934302, 1.437374939, 1.447932393, 1.466365815, 1.494141434,
1.533849048, 1.590141802, 1.672109878, 1.800722666, 2.044319458,
1.377679515, 1.380915961, 1.390845351, 1.408176743, 1.434278986,
1.471568194, 1.524381424, 1.601181365, 1.721461105, 1.948628026,
1.327565199, 1.330622327, 1.340000252, 1.356364354, 1.380998621,
1.416167952, 1.465934528, 1.538216200, 1.651226784, 1.864111423,
1.282549830, 1.285448071, 1.294337440, 1.309844876, 1.333179718,
1.366473953, 1.413548429, 1.481843319, 1.588452895, 1.788801324,
1.241823533, 1.244579894, 1.253033068, 1.267775880, 1.289951467,
1.321574029, 1.366250754, 1.430999474, 1.531926255, 1.721178113,
1.204745787, 1.207374591, 1.215435656, 1.229491324, 1.250625592,
1.280747518, 1.323273747, 1.384845919, 1.480691232, 1.660048075,
1.170802455, 1.173315887, 1.181022345, 1.194456757, 1.214649957,
1.243416541, 1.284002126, 1.342711065, 1.433983702, 1.604459196,
1.139575429, 1.141983949, 1.149367992, 1.162237690, 1.181575812,
1.209111610, 1.247936297, 1.304050050, 1.391184541, 1.553642024
};
int k = 0;
for (int j = 0; j < 10; ++j)
for (int i = 0; i < 10; ++i)
assert(std::abs(comp_ellint_3((double) i / 10.0, T((float) j / 10.f))[0] - values[k++]) <
1e-6f);
}
|
; A299265: Partial sums of A299259.
; 1,6,19,45,90,159,257,390,563,781,1050,1375,1761,2214,2739,3341,4026,4799,5665,6630,7699,8877,10170,11583,13121,14790,16595,18541,20634,22879,25281,27846,30579,33485,36570,39839,43297,46950,50803,54861,59130,63615,68321,73254,78419,83821,89466,95359,101505,107910,114579,121517,128730,136223,144001,152070,160435,169101,178074,187359,196961,206886,217139,227725,238650,249919,261537,273510,285843,298541,311610,325055,338881,353094,367699,382701,398106,413919,430145,446790,463859,481357,499290,517663,536481,555750,575475,595661,616314,637439,659041,681126,703699,726765,750330,774399,798977,824070,849683,875821
mul $0,2
mov $1,$0
add $0,2
pow $0,3
div $0,3
pow $1,2
sub $0,$1
div $0,3
add $0,1
|
// Copyright 2020 Advanced Remanufacturing and Technology Centre
// Copyright 2020 ROS-Industrial Consortium Asia Pacific Team
//
// 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 <opencv2/tracking.hpp>
#include <opencv2/core/ocl.hpp>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include "pcl/point_cloud.h"
#include "pcl/point_types.h"
#include "pcl/common/centroid.h"
#include "pcl/common/eigen.h"
#include "opencv2/opencv.hpp"
#include "tf2/LinearMath/Quaternion.h"
#include "p3_ort_base.hpp"
#include "epd_utils_lib/usecase_config.hpp"
namespace Ort
{
// Constructor
P3OrtBase::P3OrtBase(
float ratio,
int newW,
int newH,
int paddedW,
int paddedH,
const uint16_t numClasses,
const std::string & modelPath,
const boost::optional<size_t> & gpuIdx,
const boost::optional<std::vector<std::vector<int64_t>>> & inputShapes)
: OrtBase(modelPath, gpuIdx, inputShapes),
m_numClasses(numClasses),
m_ratio(ratio),
m_newW(newW),
m_newH(newH),
m_paddedW(paddedW),
m_paddedH(paddedH)
{}
// Destructor
P3OrtBase::~P3OrtBase()
{}
// Mutator: Classification
cv::Mat P3OrtBase::infer_visualize(const cv::Mat & inputImg)
{
std::vector<float> dst(3 * m_paddedH * m_paddedW);
return this->infer_visualize(
inputImg, m_newW, m_newH,
m_paddedW, m_paddedH, m_ratio, dst.data(), 0.5,
cv::Scalar(102.9801, 115.9465, 122.7717));
}
// Mutator: Localization
cv::Mat P3OrtBase::infer_visualize(
const cv::Mat & inputImg,
const cv::Mat & depthImg,
sensor_msgs::msg::CameraInfo camera_info)
{
std::vector<float> dst(3 * m_paddedH * m_paddedW);
return this->infer_visualize(
inputImg, depthImg, camera_info, m_newW, m_newH,
m_paddedW, m_paddedH, m_ratio, dst.data(), 0.5,
cv::Scalar(102.9801, 115.9465, 122.7717));
}
// Mutator: Tracking
cv::Mat P3OrtBase::infer_visualize(
const cv::Mat & inputImg,
const cv::Mat & depthImg,
sensor_msgs::msg::CameraInfo camera_info,
const std::string tracker_type,
std::vector<cv::Ptr<cv::Tracker>> & trackers,
std::vector<int> & tracker_logs,
std::vector<EPD::LabelledRect2d> & tracker_results)
{
std::vector<float> dst(3 * m_paddedH * m_paddedW);
return this->infer_visualize(
inputImg, depthImg, camera_info, tracker_type, trackers, tracker_logs,
tracker_results, m_newW, m_newH, m_paddedW, m_paddedH, m_ratio,
dst.data(), 0.5, cv::Scalar(102.9801, 115.9465, 122.7717));
}
// Mutator: Classification
EPD::EPDObjectDetection P3OrtBase::infer_action(const cv::Mat & inputImg)
{
std::vector<float> dst(3 * m_paddedH * m_paddedW);
return this->infer_action(
inputImg, m_newW, m_newH,
m_paddedW, m_paddedH, m_ratio, dst.data(), 0.5,
cv::Scalar(102.9801, 115.9465, 122.7717));
}
// Mutator: Localization
EPD::EPDObjectLocalization P3OrtBase::infer_action(
const cv::Mat & inputImg,
const cv::Mat & depthImg,
sensor_msgs::msg::CameraInfo camera_info,
double camera_to_plane_distance_mm)
{
std::vector<float> dst(3 * m_paddedH * m_paddedW);
return this->infer_action(
inputImg, depthImg, camera_info, camera_to_plane_distance_mm,
m_newW, m_newH, m_paddedW, m_paddedH, m_ratio, dst.data(), 0.5,
cv::Scalar(102.9801, 115.9465, 122.7717));
}
// Mutator: Tracking
EPD::EPDObjectTracking P3OrtBase::infer_action(
const cv::Mat & inputImg,
const cv::Mat & depthImg,
sensor_msgs::msg::CameraInfo camera_info,
double camera_to_plane_distance_mm,
const std::string tracker_type,
std::vector<cv::Ptr<cv::Tracker>> & trackers,
std::vector<int> & tracker_logs,
std::vector<EPD::LabelledRect2d> & tracker_results)
{
std::vector<float> dst(3 * m_paddedH * m_paddedW);
return this->infer_action(
inputImg, depthImg, camera_info, camera_to_plane_distance_mm,
tracker_type, trackers, tracker_logs, tracker_results,
m_newW, m_newH, m_paddedW, m_paddedH, m_ratio, dst.data(), 0.5,
cv::Scalar(102.9801, 115.9465, 122.7717));
}
void P3OrtBase::initClassNames(const std::vector<std::string> & classNames)
{
if (classNames.size() != m_numClasses) {
throw std::runtime_error("Mismatch number of classes\n");
}
m_classNames = classNames;
}
void P3OrtBase::preprocess(
float * dst,
const cv::Mat & imgSrc,
const int64_t targetImgWidth,
const int64_t targetImgHeight,
const int numChannels) const
{
for (int i = 0; i < targetImgHeight; ++i) {
for (int j = 0; j < targetImgWidth; ++j) {
for (int c = 0; c < numChannels; ++c) {
dst[c * targetImgHeight * targetImgWidth +
i * targetImgWidth + j] =
imgSrc.ptr<float>(i, j)[c];
}
}
}
}
// Mutator 4
cv::Mat P3OrtBase::infer_visualize(
const cv::Mat & inputImg,
int newW,
int newH,
int paddedW,
int paddedH,
float ratio,
float * dst,
float confThresh,
const cv::Scalar & meanVal)
{
cv::Mat tmpImg;
cv::resize(inputImg, tmpImg, cv::Size(newW, newH));
tmpImg.convertTo(tmpImg, CV_32FC3);
tmpImg -= meanVal;
cv::Mat paddedImg(paddedH, paddedW, CV_32FC3, cv::Scalar(0, 0, 0));
tmpImg.copyTo(paddedImg(cv::Rect(0, 0, newW, newH)));
this->preprocess(dst, paddedImg, paddedW, paddedH, 3);
// boxes, labels, scores, masks
auto inferenceOutput = (*this)({dst});
assert(inferenceOutput[1].second.size() == 1);
size_t nBoxes = inferenceOutput[1].second[0];
std::vector<std::array<float, 4>> bboxes;
std::vector<uint64_t> classIndices;
std::vector<float> scores;
std::vector<cv::Mat> masks;
bboxes.reserve(nBoxes);
classIndices.reserve(nBoxes);
scores.reserve(nBoxes);
masks.reserve(nBoxes);
for (size_t i = 0; i < nBoxes; ++i) {
if (inferenceOutput[2].first[i] > confThresh) {
float xmin = inferenceOutput[0].first[i * 4 + 0] / ratio;
float ymin = inferenceOutput[0].first[i * 4 + 1] / ratio;
float xmax = inferenceOutput[0].first[i * 4 + 2] / ratio;
float ymax = inferenceOutput[0].first[i * 4 + 3] / ratio;
xmin = std::max<float>(xmin, 0);
ymin = std::max<float>(ymin, 0);
xmax = std::min<float>(xmax, inputImg.cols);
ymax = std::min<float>(ymax, inputImg.rows);
bboxes.emplace_back(std::array<float, 4>{xmin, ymin, xmax, ymax});
classIndices.emplace_back(reinterpret_cast<int64_t *>(inferenceOutput[1].first)[i]);
scores.emplace_back(inferenceOutput[2].first[i]);
cv::Mat curMask(28, 28, CV_32FC1);
memcpy(
curMask.data,
inferenceOutput[3].first + i * 28 * 28,
28 * 28 * sizeof(float));
masks.emplace_back(curMask);
}
}
if (bboxes.size() == 0) {
return inputImg;
}
EPD::activateUseCase(inputImg, bboxes, classIndices, scores, masks, this->getClassNames());
return visualize(inputImg, bboxes, classIndices, masks, this->getClassNames(), 0.5);
}
// Mutator 5: Localization
cv::Mat P3OrtBase::infer_visualize(
const cv::Mat & inputImg,
const cv::Mat & depthImg,
sensor_msgs::msg::CameraInfo camera_info,
int newW,
int newH,
int paddedW,
int paddedH,
float ratio,
float * dst,
float confThresh,
const cv::Scalar & meanVal)
{
cv::Mat tmpImg;
cv::resize(inputImg, tmpImg, cv::Size(newW, newH));
tmpImg.convertTo(tmpImg, CV_32FC3);
tmpImg -= meanVal;
cv::Mat paddedImg(paddedH, paddedW, CV_32FC3, cv::Scalar(0, 0, 0));
tmpImg.copyTo(paddedImg(cv::Rect(0, 0, newW, newH)));
this->preprocess(dst, paddedImg, paddedW, paddedH, 3);
// boxes, labels, scores, masks
auto inferenceOutput = (*this)({dst});
assert(inferenceOutput[1].second.size() == 1);
size_t nBoxes = inferenceOutput[1].second[0];
std::vector<std::array<float, 4>> bboxes;
std::vector<uint64_t> classIndices;
std::vector<float> scores;
std::vector<cv::Mat> masks;
bboxes.reserve(nBoxes);
classIndices.reserve(nBoxes);
scores.reserve(nBoxes);
masks.reserve(nBoxes);
for (size_t i = 0; i < nBoxes; ++i) {
if (inferenceOutput[2].first[i] > confThresh) {
float xmin = inferenceOutput[0].first[i * 4 + 0] / ratio;
float ymin = inferenceOutput[0].first[i * 4 + 1] / ratio;
float xmax = inferenceOutput[0].first[i * 4 + 2] / ratio;
float ymax = inferenceOutput[0].first[i * 4 + 3] / ratio;
xmin = std::max<float>(xmin, 0);
ymin = std::max<float>(ymin, 0);
xmax = std::min<float>(xmax, inputImg.cols);
ymax = std::min<float>(ymax, inputImg.rows);
bboxes.emplace_back(std::array<float, 4>{xmin, ymin, xmax, ymax});
classIndices.emplace_back(reinterpret_cast<int64_t *>(inferenceOutput[1].first)[i]);
scores.emplace_back(inferenceOutput[2].first[i]);
cv::Mat curMask(28, 28, CV_32FC1);
memcpy(
curMask.data,
inferenceOutput[3].first + i * 28 * 28,
28 * 28 * sizeof(float));
masks.emplace_back(curMask);
}
}
if (bboxes.size() == 0) {
return inputImg;
}
return localize_visualize(
inputImg,
depthImg,
camera_info,
bboxes,
classIndices,
masks,
this->getClassNames(),
0.5);
}
// Mutator 5: Tracking
cv::Mat P3OrtBase::infer_visualize(
const cv::Mat & inputImg,
const cv::Mat & depthImg,
sensor_msgs::msg::CameraInfo camera_info,
const std::string tracker_type,
std::vector<cv::Ptr<cv::Tracker>> & trackers,
std::vector<int> & tracker_logs,
std::vector<EPD::LabelledRect2d> & tracker_results,
int newW,
int newH,
int paddedW,
int paddedH,
float ratio,
float * dst,
float confThresh,
const cv::Scalar & meanVal)
{
cv::Mat tmpImg;
cv::resize(inputImg, tmpImg, cv::Size(newW, newH));
tmpImg.convertTo(tmpImg, CV_32FC3);
tmpImg -= meanVal;
cv::Mat paddedImg(paddedH, paddedW, CV_32FC3, cv::Scalar(0, 0, 0));
tmpImg.copyTo(paddedImg(cv::Rect(0, 0, newW, newH)));
this->preprocess(dst, paddedImg, paddedW, paddedH, 3);
// boxes, labels, scores, masks
auto inferenceOutput = (*this)({dst});
assert(inferenceOutput[1].second.size() == 1);
size_t nBoxes = inferenceOutput[1].second[0];
std::vector<std::array<float, 4>> bboxes;
std::vector<uint64_t> classIndices;
std::vector<float> scores;
std::vector<cv::Mat> masks;
bboxes.reserve(nBoxes);
classIndices.reserve(nBoxes);
scores.reserve(nBoxes);
masks.reserve(nBoxes);
for (size_t i = 0; i < nBoxes; ++i) {
if (inferenceOutput[2].first[i] > confThresh) {
float xmin = inferenceOutput[0].first[i * 4 + 0] / ratio;
float ymin = inferenceOutput[0].first[i * 4 + 1] / ratio;
float xmax = inferenceOutput[0].first[i * 4 + 2] / ratio;
float ymax = inferenceOutput[0].first[i * 4 + 3] / ratio;
xmin = std::max<float>(xmin, 0);
ymin = std::max<float>(ymin, 0);
xmax = std::min<float>(xmax, inputImg.cols);
ymax = std::min<float>(ymax, inputImg.rows);
bboxes.emplace_back(std::array<float, 4>{xmin, ymin, xmax, ymax});
classIndices.emplace_back(reinterpret_cast<int64_t *>(inferenceOutput[1].first)[i]);
scores.emplace_back(inferenceOutput[2].first[i]);
cv::Mat curMask(28, 28, CV_32FC1);
memcpy(
curMask.data,
inferenceOutput[3].first + i * 28 * 28,
28 * 28 * sizeof(float));
masks.emplace_back(curMask);
}
}
// DEBUG
// Evaluate detection results and tracking results.
tracking_evaluate(bboxes, inputImg, tracker_type, trackers, tracker_logs, tracker_results);
if (bboxes.size() == 0) {
return inputImg;
}
return tracking_visualize(
inputImg,
depthImg,
camera_info,
tracker_results,
bboxes,
classIndices,
masks,
this->getClassNames(),
0.5);
}
// Mutator 4
EPD::EPDObjectDetection P3OrtBase::infer_action(
const cv::Mat & inputImg,
int newW,
int newH,
int paddedW,
int paddedH,
float ratio,
float * dst,
float confThresh,
const cv::Scalar & meanVal)
{
cv::Mat tmpImg;
cv::resize(inputImg, tmpImg, cv::Size(newW, newH));
tmpImg.convertTo(tmpImg, CV_32FC3);
tmpImg -= meanVal;
cv::Mat paddedImg(paddedH, paddedW, CV_32FC3, cv::Scalar(0, 0, 0));
tmpImg.copyTo(paddedImg(cv::Rect(0, 0, newW, newH)));
this->preprocess(dst, paddedImg, paddedW, paddedH, 3);
// boxes, labels, scores, masks
auto inferenceOutput = (*this)({dst});
assert(inferenceOutput[1].second.size() == 1);
size_t nBoxes = inferenceOutput[1].second[0];
std::vector<std::array<float, 4>> bboxes;
std::vector<uint64_t> classIndices;
std::vector<float> scores;
std::vector<cv::Mat> masks;
bboxes.reserve(nBoxes);
classIndices.reserve(nBoxes);
scores.reserve(nBoxes);
masks.reserve(nBoxes);
for (size_t i = 0; i < nBoxes; ++i) {
if (inferenceOutput[2].first[i] > confThresh) {
float xmin = inferenceOutput[0].first[i * 4 + 0] / ratio;
float ymin = inferenceOutput[0].first[i * 4 + 1] / ratio;
float xmax = inferenceOutput[0].first[i * 4 + 2] / ratio;
float ymax = inferenceOutput[0].first[i * 4 + 3] / ratio;
xmin = std::max<float>(xmin, 0);
ymin = std::max<float>(ymin, 0);
xmax = std::min<float>(xmax, inputImg.cols);
ymax = std::min<float>(ymax, inputImg.rows);
bboxes.emplace_back(std::array<float, 4>{xmin, ymin, xmax, ymax});
classIndices.emplace_back(reinterpret_cast<int64_t *>(inferenceOutput[1].first)[i]);
scores.emplace_back(inferenceOutput[2].first[i]);
cv::Mat curMask(28, 28, CV_32FC1);
memcpy(
curMask.data,
inferenceOutput[3].first + i * 28 * 28,
28 * 28 * sizeof(float));
masks.emplace_back(curMask);
}
}
if (bboxes.size() == 0) {
EPD::EPDObjectDetection output_msg(0);
return output_msg;
}
EPD::activateUseCase(inputImg, bboxes, classIndices, scores, masks, this->getClassNames());
EPD::EPDObjectDetection output_obj(bboxes.size());
output_obj.bboxes = bboxes;
output_obj.classIndices = classIndices;
output_obj.scores = scores;
output_obj.masks = masks;
return output_obj;
}
cv::Mat P3OrtBase::visualize(
const cv::Mat & img,
const std::vector<std::array<float, 4>> & bboxes,
const std::vector<uint64_t> & classIndices,
const std::vector<cv::Mat> & masks,
const std::vector<std::string> & allClassNames = {},
const float maskThreshold = 0.5)
{
assert(bboxes.size() == classIndices.size());
if (!allClassNames.empty()) {
assert(allClassNames.size() > *std::max_element(classIndices.begin(), classIndices.end()));
}
cv::Scalar allColors(255.0, 0.0, 0.0, 0.0);
cv::Mat result = img.clone();
for (size_t i = 0; i < bboxes.size(); ++i) {
const auto & curBbox = bboxes[i];
const uint64_t classIdx = classIndices[i];
cv::Mat curMask = masks[i].clone();
const cv::Scalar & curColor = allColors;
const std::string curLabel = allClassNames.empty() ?
std::to_string(classIdx) : allClassNames[classIdx];
cv::rectangle(
result, cv::Point(curBbox[0], curBbox[1]),
cv::Point(curBbox[2], curBbox[3]), curColor, 2);
int baseLine = 0;
cv::Size labelSize = cv::getTextSize(
curLabel, cv::FONT_HERSHEY_COMPLEX,
0.35, 1, &baseLine);
cv::rectangle(
result, cv::Point(curBbox[0], curBbox[1]),
cv::Point(
curBbox[0] + labelSize.width, curBbox[1] +
static_cast<int>(1.3 * labelSize.height)),
curColor, -1);
cv::putText(
result, curLabel, cv::Point(curBbox[0], curBbox[1] + labelSize.height),
cv::FONT_HERSHEY_COMPLEX,
0.35, cv::Scalar(255, 255, 255));
// Visualize masks
const cv::Rect curBoxRect(cv::Point(curBbox[0], curBbox[1]),
cv::Point(curBbox[2], curBbox[3]));
cv::resize(curMask, curMask, curBoxRect.size());
cv::Mat finalMask = (curMask > maskThreshold);
cv::Mat coloredRoi = (0.3 * curColor + 0.7 * result(curBoxRect));
coloredRoi.convertTo(coloredRoi, CV_8UC3);
std::vector<cv::Mat> contours;
cv::Mat hierarchy;
finalMask.convertTo(finalMask, CV_8U);
cv::findContours(finalMask, contours, hierarchy, cv::RETR_TREE, cv::CHAIN_APPROX_SIMPLE);
cv::drawContours(coloredRoi, contours, -1, curColor, 5, cv::LINE_8, hierarchy, 100);
coloredRoi.copyTo(result(curBoxRect), finalMask);
}
return result;
}
double P3OrtBase::findMedian(cv::Mat depthImg)
{
double m = (depthImg.rows * depthImg.cols) / 2;
int bin = 0;
double median = -1.0;
// Setting to hardcoded 2000 millimeters
// This is the limit of intel realsense D415.
int histSize = 2000;
float range[] = {0, 2000};
const float * histRange = {range};
bool uniform = true;
bool accumulate = false;
cv::Mat hist;
cv::calcHist(&depthImg, 1, 0, cv::Mat(), hist, 1, &histSize, &histRange, uniform, accumulate);
for (int i = 0; i < histSize && median < 0.0; ++i) {
bin += cvRound(hist.at<float>(i));
if (bin > m && median < 0.0) {
median = i;
}
}
return median;
}
double P3OrtBase::findMin(cv::Mat depthImg)
{
int bin = 0;
double min = -1.0;
// Setting to hardcoded 2000 millimeters
// This is the limit of intel realsense D415.
int histSize = 2000;
float range[] = {0, 2000};
const float * histRange = {range};
bool uniform = true;
bool accumulate = false;
cv::Mat hist;
cv::calcHist(&depthImg, 1, 0, cv::Mat(), hist, 1, &histSize, &histRange, uniform, accumulate);
for (int i = 0; i < histSize; ++i) {
bin += cvRound(hist.at<float>(i));
// Store the first depth value that is shared among more than 1 point.
// Break and escape for loop.
if (i != 0 && cvRound(hist.at<float>(i)) > 0) {
// std::cout << "Depth Value = " << i << " has " << cvRound(hist.at<float>(i)) << std::endl;
min = i;
break;
}
}
return min;
}
cv::Mat P3OrtBase::localize_visualize(
const cv::Mat & img,
const cv::Mat & depthImg,
sensor_msgs::msg::CameraInfo camera_info,
const std::vector<std::array<float, 4>> & bboxes,
const std::vector<uint64_t> & classIndices,
const std::vector<cv::Mat> & masks,
const std::vector<std::string> & allClassNames = {},
const float maskThreshold = 0.5)
{
assert(bboxes.size() == classIndices.size());
if (!allClassNames.empty()) {
assert(
allClassNames.size() >
*std::max_element(classIndices.begin(), classIndices.end()));
}
cv::Scalar allColors(0.0, 0.0, 255.0, 0.0);
// // num of objects will be equal to number of bboxes
cv::Mat result = img.clone();
for (size_t i = 0; i < bboxes.size(); ++i) {
const auto & curBbox = bboxes[i];
const uint64_t classIdx = classIndices[i];
cv::Mat curMask = masks[i].clone();
const cv::Scalar & curColor = allColors[classIdx];
const std::string curLabel = allClassNames.empty() ?
std::to_string(classIdx) :
allClassNames[classIdx];
cv::rectangle(
result, cv::Point(curBbox[0], curBbox[1]),
cv::Point(curBbox[2], curBbox[3]), curColor, 2);
int baseLine = 0;
cv::Size labelSize =
cv::getTextSize(curLabel, cv::FONT_HERSHEY_COMPLEX, 0.35, 1, &baseLine);
cv::rectangle(
result, cv::Point(
curBbox[0], curBbox[1]),
cv::Point(
curBbox[0] + labelSize.width,
curBbox[1] + static_cast<int>(1.3 * labelSize.height)),
curColor, -1);
cv::putText(
result, curLabel,
cv::Point(curBbox[0], curBbox[1] + labelSize.height),
cv::FONT_HERSHEY_COMPLEX, 0.35, cv::Scalar(255, 255, 255));
// Visualizing masks
const cv::Rect curBoxRect(cv::Point(curBbox[0], curBbox[1]),
cv::Point(curBbox[2], curBbox[3]));
cv::resize(curMask, curMask, curBoxRect.size());
// Assigning masks that exceed the maskThreshold.
cv::Mat finalMask = (curMask > maskThreshold);
// Assigning coloredRoi with the bounding box.
cv::Mat coloredRoi = (0.3 * curColor + 0.7 * result(curBoxRect));
coloredRoi.convertTo(coloredRoi, CV_8UC3);
std::vector<cv::Mat> contours;
cv::Mat hierarchy;
cv::Mat tempFinalMask;
finalMask.convertTo(tempFinalMask, CV_8U);
// Generate red contour lines of segmentation mask.
cv::findContours(
tempFinalMask, contours, hierarchy, cv::RETR_TREE,
cv::CHAIN_APPROX_SIMPLE);
// Draw red contour lines on output image.
cv::drawContours(
coloredRoi, contours, -1, cv::Scalar(0, 0, 255), 5, cv::LINE_8,
hierarchy, 100);
// For more details, refer to link below:
// https://tinyurl.com/y5qnnxud
float ppx = camera_info.k.at(2);
float fx = camera_info.k.at(0);
float ppy = camera_info.k.at(5);
float fy = camera_info.k.at(4);
// Getting rotated rectangle and draw the major axis
std::vector<cv::RotatedRect> minRect(contours.size());
float obj_surface_depth;
float object_length, object_breadth, object_height;
cv::Point pt_a, pt_b, pt_c, pt_d;
cv::Point rotated_mid;
// Getting only the largest contour
// The largest contour is the one which has the largest area.
// TODO(cardboardcode): Changed according to your use case.
double maxArea = 0;
int maxAreaContourId = 999;
for (unsigned int j = 0; j < contours.size(); j++) {
double newArea = cv::contourArea(contours[j]);
if (newArea > maxArea) {
maxArea = newArea;
maxAreaContourId = j;
} // End if
} // End for
unsigned int maxID = maxAreaContourId;
for (unsigned int index = 0; index < contours.size(); index++) {
if (index != maxID) {
continue;
}
// Compute rotated rectangle based on contours
minRect[index] = cv::minAreaRect(cv::Mat(contours[index]));
cv::Point2f rect_points[4];
// 4 points of the rotated rectangle
minRect[index].points(rect_points);
// Mid points of the each side of the rotated rectangle
pt_a = (rect_points[0] + rect_points[3]) / 2;
pt_b = (rect_points[1] + rect_points[2]) / 2;
pt_c = (rect_points[0] + rect_points[1]) / 2;
pt_d = (rect_points[3] + rect_points[2]) / 2;
// Add the top left corner to the coordinate in the small bbox
// For temporary, bboxes center
rotated_mid = (cv::Point(curBbox[0], curBbox[1]) +
cv::Point(curBbox[2], curBbox[3])) / 2;
// Get coordinates of the object center
float table_depth = this->findMedian(depthImg) * 0.001;
obj_surface_depth = this->findMin(depthImg(curBoxRect)) * 0.001;
float x = (rotated_mid.x - ppx) / fx * obj_surface_depth;
float y = (rotated_mid.y - ppy) / fy * obj_surface_depth;
std::cout << "[-cam -> table-] = " << table_depth <<
" meters" << std::endl;
std::cout << "[-cam -> obj_top-] = " << obj_surface_depth <<
" meters" << std::endl;
std::cout << "[-OBJ centroid x-] = " << x << std::endl;
std::cout << "[-OBJ centroid y-] = " << y << std::endl;
std::cout << "[-OBJ centroid z-] = " << obj_surface_depth +
(table_depth - obj_surface_depth) / 2 << std::endl;
// Get estimated size of object
// Compare the length of 2 side of the rectangle,
// the longer side will be the major axis
if (cv::norm(rect_points[0] - rect_points[1]) >
cv::norm(rect_points[1] - rect_points[2]))
{
// Draws the major axis(red)
cv::line(coloredRoi, pt_a, pt_b, cv::Scalar(0, 0, 255), 2);
// Draws the minor axis (green)
cv::line(coloredRoi, pt_c, pt_d, cv::Scalar(0, 255, 0), 2);
// Calculates the length of the object
object_length = obj_surface_depth * sqrt(
pow((pt_a.x - pt_b.x) / fx, 2) +
pow(
(pt_a.y - pt_b.y) / fy,
2));
// Calculates the breadth of the object
object_breadth = obj_surface_depth * sqrt(
pow((pt_c.x - pt_d.x) / fx, 2) +
pow(
(pt_c.y - pt_d.y) / fy,
2));
} else {
// Draw the major axis
cv::line(coloredRoi, pt_c, pt_d, cv::Scalar(0, 0, 255), 2);
// Draw the minor axis (green)
cv::line(coloredRoi, pt_a, pt_b, cv::Scalar(0, 255, 0), 2);
// Get object breadth and length
object_breadth = obj_surface_depth * sqrt(
pow((pt_a.x - pt_b.x) / fx, 2) +
pow((pt_a.y - pt_b.y) / fy, 2));
object_length = obj_surface_depth * sqrt(
pow((pt_c.x - pt_d.x) / fx, 2) +
pow((pt_c.y - pt_d.y) / fy, 2));
}
// Setting height of object
object_height = table_depth - obj_surface_depth;
// TODO(cardboardcode): To provide optimized debug prints in future iterations.
std::cout << "[-OBJ Name-] = " << curLabel << std::endl;
std::cout << "[-OBJ Length-] = " << object_length << " meters" << std::endl;
std::cout << "[-OBJ Breadth-] = " << object_breadth << " meters" << std::endl;
std::cout << "[-OBJ Height-] = " << object_height << " meters" << std::endl;
// Mark the center point with blue dot
cv::circle(coloredRoi, rotated_mid, 1, cv::Scalar(255, 0, 0), 1);
}
// Push each Region-Of-Interest (ROI) in sequence
coloredRoi.copyTo(result(curBoxRect), finalMask);
}
return result;
}
cv::Mat P3OrtBase::tracking_visualize(
const cv::Mat & img,
const cv::Mat & depthImg,
sensor_msgs::msg::CameraInfo camera_info,
std::vector<EPD::LabelledRect2d> & tracker_results,
const std::vector<std::array<float, 4>> & bboxes,
const std::vector<uint64_t> & classIndices,
const std::vector<cv::Mat> & masks,
const std::vector<std::string> & allClassNames = {},
const float maskThreshold = 0.5)
{
assert(bboxes.size() == classIndices.size());
if (!allClassNames.empty()) {
assert(
allClassNames.size() >
*std::max_element(classIndices.begin(), classIndices.end()));
}
cv::Scalar allColors(0.0, 0.0, 255.0, 0.0);
cv::Scalar trackingColor(255.0, 0.0, 0.0, 0.0);
cv::Mat result = img.clone();
for (size_t i = 0; i < tracker_results.size(); i++) {
cv::rectangle(
result,
tracker_results[i].obj_bounding_box,
trackingColor,
4);
}
for (size_t i = 0; i < bboxes.size(); ++i) {
const auto & curBbox = bboxes[i];
const uint64_t classIdx = classIndices[i];
cv::Mat curMask = masks[i].clone();
const cv::Scalar & curColor = allColors[classIdx];
std::string curLabel = allClassNames.empty() ?
std::to_string(classIdx) :
allClassNames[classIdx];
cv::rectangle(
result, cv::Point(curBbox[0], curBbox[1]),
cv::Point(curBbox[2], curBbox[3]), curColor, 2);
int baseLine = 0;
cv::Size labelSize =
cv::getTextSize(curLabel, cv::FONT_HERSHEY_COMPLEX, 0.35, 1, &baseLine);
cv::rectangle(
result, cv::Point(
curBbox[0], curBbox[1]),
cv::Point(
curBbox[0] + labelSize.width,
curBbox[1] + static_cast<int>(1.3 * labelSize.height)),
curColor, -1);
// Update curLabel with tracker number tag for object.
for (size_t j = 0; j < tracker_results.size(); j++) {
if (tracker_results[j].obj_bounding_box.x == curBbox[0] &&
tracker_results[j].obj_bounding_box.y == curBbox[1] &&
tracker_results[j].obj_bounding_box.width == curBbox[2] - curBbox[0] &&
tracker_results[j].obj_bounding_box.height == curBbox[3] - curBbox[1])
{
curLabel = curLabel + "_" + std::string(tracker_results[j].obj_tag);
}
}
cv::putText(
result, curLabel,
cv::Point(curBbox[0], curBbox[1] + labelSize.height),
cv::FONT_HERSHEY_COMPLEX, 0.55, cv::Scalar(255, 255, 255));
// Visualizing masks
const cv::Rect curBoxRect(cv::Point(curBbox[0], curBbox[1]),
cv::Point(curBbox[2], curBbox[3]));
cv::resize(curMask, curMask, curBoxRect.size());
// Assigning masks that exceed the maskThreshold.
cv::Mat finalMask = (curMask > maskThreshold);
// Assigning coloredRoi with the bounding box.
cv::Mat coloredRoi = (0.3 * curColor + 0.7 * result(curBoxRect));
coloredRoi.convertTo(coloredRoi, CV_8UC3);
std::vector<cv::Mat> contours;
cv::Mat hierarchy;
cv::Mat tempFinalMask;
finalMask.convertTo(tempFinalMask, CV_8U);
// Generate red contour lines of segmentation mask.
cv::findContours(
tempFinalMask, contours, hierarchy, cv::RETR_TREE,
cv::CHAIN_APPROX_SIMPLE);
// Draw red contour lines on output image.
cv::drawContours(
coloredRoi, contours, -1, cv::Scalar(0, 0, 255), 5, cv::LINE_8,
hierarchy, 100);
// For more details, refer to link below:
// https://tinyurl.com/y5qnnxud
float fx = camera_info.k.at(0);
float fy = camera_info.k.at(4);
// Getting rotated rectangle and draw the major axis
std::vector<cv::RotatedRect> minRect(contours.size());
float obj_surface_depth;
float object_length, object_breadth, object_height;
cv::Point pt_a, pt_b, pt_c, pt_d;
cv::Point rotated_mid;
// Getting only the largest contour
// The largest contour is the one which has the largest area.
// TODO(cardboardcode): Changed according to your use case.
double maxArea = 0;
int maxAreaContourId = 999;
for (unsigned int j = 0; j < contours.size(); j++) {
double newArea = cv::contourArea(contours[j]);
if (newArea > maxArea) {
maxArea = newArea;
maxAreaContourId = j;
} // End if
} // End for
unsigned int maxID = maxAreaContourId;
for (unsigned int index = 0; index < contours.size(); index++) {
if (index != maxID) {
continue;
}
// Compute rotated rectangle based on contours
minRect[index] = cv::minAreaRect(cv::Mat(contours[index]));
cv::Point2f rect_points[4];
// 4 points of the rotated rectangle
minRect[index].points(rect_points);
// Mid points of the each side of the rotated rectangle
pt_a = (rect_points[0] + rect_points[3]) / 2;
pt_b = (rect_points[1] + rect_points[2]) / 2;
pt_c = (rect_points[0] + rect_points[1]) / 2;
pt_d = (rect_points[3] + rect_points[2]) / 2;
// Add the top left corner to the coordinate in the small bbox
// For temporary, bboxes center
rotated_mid = (cv::Point(curBbox[0], curBbox[1]) +
cv::Point(curBbox[2], curBbox[3])) / 2;
// Get coordinates of the object center
float table_depth = this->findMedian(depthImg) * 0.001;
obj_surface_depth = this->findMin(depthImg(curBoxRect)) * 0.001;
// std::cout << "table_depth = " << table_depth << std::endl;
// std::cout << "obj_surface_depth = " << obj_surface_depth << std::endl;
// std::cout << "[-OBJ centroid x-] = " << x << std::endl;
// std::cout << "[-OBJ centroid y-] = " << y << std::endl;
// std::cout << "[-OBJ centroid z-] = " << obj_surface_depth +
// (table_depth - obj_surface_depth) / 2 << std::endl;
// Get estimated size of object
// Compare the length of 2 side of the rectangle,
// the longer side will be the major axis
if (cv::norm(rect_points[0] - rect_points[1]) >
cv::norm(rect_points[1] - rect_points[2]))
{
// Draws the major axis(red)
cv::line(coloredRoi, pt_a, pt_b, cv::Scalar(0, 0, 255), 2);
// Draws the minor axis (green)
cv::line(coloredRoi, pt_c, pt_d, cv::Scalar(0, 255, 0), 2);
// Calculates the length of the object
object_length = obj_surface_depth * sqrt(
pow((pt_a.x - pt_b.x) / fx, 2) +
pow(
(pt_a.y - pt_b.y) / fy,
2));
// Calculates the breadth of the object
object_breadth = obj_surface_depth * sqrt(
pow((pt_c.x - pt_d.x) / fx, 2) +
pow(
(pt_c.y - pt_d.y) / fy,
2));
} else {
// Draw the major axis
cv::line(coloredRoi, pt_c, pt_d, cv::Scalar(0, 0, 255), 2);
// Draw the minor axis (green)
cv::line(coloredRoi, pt_a, pt_b, cv::Scalar(0, 255, 0), 2);
// Get object breadth and length
object_breadth = obj_surface_depth * sqrt(
pow((pt_a.x - pt_b.x) / fx, 2) +
pow((pt_a.y - pt_b.y) / fy, 2));
object_length = obj_surface_depth * sqrt(
pow((pt_c.x - pt_d.x) / fx, 2) +
pow((pt_c.y - pt_d.y) / fy, 2));
}
// Setting height of object
object_height = table_depth - obj_surface_depth;
// TODO(cardboardcode): To provide optimized debug prints in future iterations.
std::cout << "[-OBJ Name-] = " << curLabel << std::endl;
std::cout << "[-OBJ Length-] = " << object_length << std::endl;
std::cout << "[-OBJ Breadth-] = " << object_breadth << std::endl;
std::cout << "[-OBJ Height-] = " << object_height << std::endl;
// Mark the center point with blue dot
cv::circle(coloredRoi, rotated_mid, 1, cv::Scalar(255, 0, 0), 1);
}
// Push each Region-Of-Interest (ROI) in sequence
coloredRoi.copyTo(result(curBoxRect), finalMask);
}
return result;
}
// DEBUG
// A mutator function that will output an EPD::EPDObjectLocalization object that
// contains all information required for Localization.
EPD::EPDObjectLocalization P3OrtBase::infer_action(
const cv::Mat & inputImg,
const cv::Mat & depthImg,
sensor_msgs::msg::CameraInfo camera_info,
double camera_to_plane_distance_mm,
int newW,
int newH,
int paddedW,
int paddedH,
float ratio,
float * dst,
float confThresh,
const cv::Scalar & meanVal)
{
cv::Mat tmpImg;
cv::resize(inputImg, tmpImg, cv::Size(newW, newH));
tmpImg.convertTo(tmpImg, CV_32FC3);
tmpImg -= meanVal;
cv::Mat paddedImg(paddedH, paddedW, CV_32FC3, cv::Scalar(0, 0, 0));
tmpImg.copyTo(paddedImg(cv::Rect(0, 0, newW, newH)));
this->preprocess(dst, paddedImg, paddedW, paddedH, 3);
// boxes, labels, scores, masks
auto inferenceOutput = (*this)({dst});
assert(inferenceOutput[1].second.size() == 1);
size_t nBoxes = inferenceOutput[1].second[0];
std::vector<std::array<float, 4>> bboxes;
std::vector<uint64_t> classIndices;
std::vector<float> scores;
std::vector<cv::Mat> masks;
bboxes.reserve(nBoxes);
classIndices.reserve(nBoxes);
scores.reserve(nBoxes);
masks.reserve(nBoxes);
for (size_t i = 0; i < nBoxes; ++i) {
if (inferenceOutput[2].first[i] > confThresh) {
float xmin = inferenceOutput[0].first[i * 4 + 0] / ratio;
float ymin = inferenceOutput[0].first[i * 4 + 1] / ratio;
float xmax = inferenceOutput[0].first[i * 4 + 2] / ratio;
float ymax = inferenceOutput[0].first[i * 4 + 3] / ratio;
xmin = std::max<float>(xmin, 0);
ymin = std::max<float>(ymin, 0);
xmax = std::min<float>(xmax, inputImg.cols);
ymax = std::min<float>(ymax, inputImg.rows);
bboxes.emplace_back(std::array<float, 4>{xmin, ymin, xmax, ymax});
classIndices.emplace_back(reinterpret_cast<int64_t *>(inferenceOutput[1].first)[i]);
scores.emplace_back(inferenceOutput[2].first[i]);
cv::Mat curMask(28, 28, CV_32FC1);
memcpy(
curMask.data,
inferenceOutput[3].first + i * 28 * 28,
28 * 28 * sizeof(float));
masks.emplace_back(curMask);
}
}
std::vector<std::string> allClassNames = this->getClassNames();
float maskThreshold = 0.5;
cv::Mat result = inputImg.clone();
assert(bboxes.size() == classIndices.size());
if (!allClassNames.empty()) {
assert(
allClassNames.size() >
*std::max_element(classIndices.begin(), classIndices.end()));
}
// If there is zero bounding boxes generated, return empty EPDObjectLocalization object.
if (bboxes.size() == 0) {
EPD::EPDObjectLocalization output_msg(0);
return output_msg;
}
EPD::EPDObjectLocalization output_obj(bboxes.size());
float table_depth = this->findMedian(depthImg) * 0.001;
// No. of objects will be equal to number of bboxes
/* START of Populating EPDObjectLocalization object */
for (size_t i = 0; i < bboxes.size(); ++i) {
const auto & curBbox = bboxes[i];
const uint64_t classIdx = classIndices[i];
cv::Mat curMask = masks[i].clone();
const std::string curLabel = allClassNames.empty() ?
std::to_string(classIdx) :
allClassNames[classIdx];
output_obj.objects[i].name = curLabel;
// Top x of ROI
output_obj.objects[i].roi.x_offset = curBbox[0];
// Top y of ROI
output_obj.objects[i].roi.y_offset = curBbox[1];
// Bounding Box height as ROI
output_obj.objects[i].roi.height = curBbox[3] - curBbox[1];
// Bounding Box width as ROI
output_obj.objects[i].roi.width = curBbox[2] - curBbox[0];
output_obj.objects[i].mask = curMask;
// Visualizing masks
const cv::Rect curBoxRect(cv::Point(curBbox[0], curBbox[1]),
cv::Point(curBbox[2], curBbox[3]));
cv::resize(curMask, curMask, curBoxRect.size());
// Assigning masks that exceed the maskThreshold.
cv::Mat finalMask = (curMask > maskThreshold);
std::vector<cv::Mat> contours;
cv::Mat hierarchy;
cv::Mat tempFinalMask;
finalMask.convertTo(tempFinalMask, CV_8U);
// Generate contours.
cv::findContours(
tempFinalMask, contours, hierarchy, cv::RETR_TREE,
cv::CHAIN_APPROX_SIMPLE);
// For more details, refer to link below:
// https://tinyurl.com/y5qnnxud
float ppx = camera_info.k.at(2);
float fx = camera_info.k.at(0);
float ppy = camera_info.k.at(5);
float fy = camera_info.k.at(4);
// Getting rotated rectangle and draw the major axis
std::vector<cv::RotatedRect> minRect(contours.size());
std::vector<float> angles;
float obj_surface_depth;
cv::Point pt_a, pt_b, pt_c, pt_d;
cv::Point rotated_mid;
// Getting only the largest contour
// The largest contour is the one which has the largest area.
double maxArea = 0;
int maxAreaContourId = 999;
for (unsigned int j = 0; j < contours.size(); j++) {
double newArea = cv::contourArea(contours[j]);
if (newArea > maxArea) {
maxArea = newArea;
maxAreaContourId = j;
} // End if
} // End for
unsigned int maxID = maxAreaContourId;
for (unsigned int index = 0; index < contours.size(); index++) {
if (index != maxID) {
continue;
}
// Function that compute rotated rectangle based on contours
minRect[index] = cv::minAreaRect(cv::Mat(contours[index]));
cv::Point2f rect_points[4];
// 4 points of the rotated rectangle
minRect[index].points(rect_points);
// Mid points of the each side of the rotated rectangle
pt_a = (rect_points[0] + rect_points[3]) / 2;
pt_b = (rect_points[1] + rect_points[2]) / 2;
pt_c = (rect_points[0] + rect_points[1]) / 2;
pt_d = (rect_points[3] + rect_points[2]) / 2;
// For temporary, bboxes center
rotated_mid = (cv::Point(curBbox[0], curBbox[1]) +
cv::Point(curBbox[2], curBbox[3])) / 2;
obj_surface_depth = this->findMin(depthImg(curBoxRect)) * 0.001;
float x = (rotated_mid.x - ppx) / fx * obj_surface_depth;
float y = (rotated_mid.y - ppy) / fy * obj_surface_depth;
output_obj.objects[i].centroid.x = x;
output_obj.objects[i].centroid.y = y;
output_obj.objects[i].centroid.z = obj_surface_depth +
(table_depth - obj_surface_depth) / 2;
// Get Real Size and angle of object
// Compare the length of 2 side of the rectangle,
// the longer side will be the major axis
if (cv::norm(rect_points[0] - rect_points[1]) >
cv::norm(rect_points[1] - rect_points[2]))
{
// Calculates the length of the object
output_obj.objects[i].length = obj_surface_depth * sqrt(
pow((pt_a.x - pt_b.x) / fx, 2) +
pow((pt_a.y - pt_b.y) / fy, 2));
// Calculates the breadth of the object
output_obj.objects[i].breadth = obj_surface_depth * sqrt(
pow((pt_c.x - pt_d.x) / fx, 2) +
pow((pt_c.y - pt_d.y) / fy, 2));
} else {
// Gets object breadth and length
output_obj.objects[i].breadth = obj_surface_depth * sqrt(
pow((pt_a.x - pt_b.x) / fx, 2) +
pow((pt_a.y - pt_b.y) / fy, 2));
output_obj.objects[i].length = obj_surface_depth * sqrt(
pow((pt_c.x - pt_d.x) / fx, 2) +
pow((pt_c.y - pt_d.y) / fy, 2));
}
// Setting height of object
output_obj.objects[i].height = table_depth - obj_surface_depth;
pcl::PointCloud<pcl::PointXYZ>::Ptr segmented_cloud(new pcl::PointCloud<pcl::PointXYZ>);
segmented_cloud->header.frame_id = "camera_color_optical_frame";
segmented_cloud->is_dense = true;
cv::Mat tempImg = inputImg.clone();
// Converting Depth Image to PointCloud
for (int j = 0; j < tempFinalMask.rows; j++) {
for (int k = 0; k < tempFinalMask.cols; k++) {
// TODO(cardboardcode) convert segmented mask into segmented pointcloud
int pixelValue = static_cast<int>(tempFinalMask.at<uchar>(j, k));
if (pixelValue != 0) {
float z = static_cast<float>(depthImg.at<uint16_t>(
curBoxRect.y + j, curBoxRect.x + k) * 0.001);
float x = static_cast<float>((curBoxRect.x + k - ppx) / fx) * z;
float y = static_cast<float>((curBoxRect.y + j - ppy) / fy) * z;
// Ignore all points that has a value of less than 0.1mm in z.
if (std::abs(z) < 0.0001 || std::abs(z) > camera_to_plane_distance_mm * 0.001) {
continue;
} else {
pcl::PointXYZ curPoint(x, y, z);
segmented_cloud->points.push_back(curPoint);
}
}
}
}
output_obj.objects[i].segmented_pcl = *segmented_cloud;
// Determine object axis of segmented_pcl
Eigen::Vector3f axis;
Eigen::Vector4f centerpoint;
Eigen::Vector3f eigenvalues;
Eigen::Matrix3f eigenvectors;
Eigen::Matrix3f covariance_matrix;
pcl::compute3DCentroid(output_obj.objects[i].segmented_pcl, centerpoint);
pcl::computeCovarianceMatrix(
output_obj.objects[i].segmented_pcl,
centerpoint,
covariance_matrix);
pcl::eigen33(covariance_matrix, eigenvectors, eigenvalues);
axis = Eigen::Vector3f(
eigenvectors.col(2)(0),
eigenvectors.col(2)(1),
eigenvectors.col(2)(2));
axis = axis.normalized();
output_obj.objects[i].axis.x = axis(0);
output_obj.objects[i].axis.y = axis(1);
output_obj.objects[i].axis.z = axis(2);
}
}
// END of Populating EPDObjectLocalization object
return output_obj;
}
// DEBUG
// A mutator function that will output an EPD::EPDObjectTracking object that
// contains all information required for Localization.
EPD::EPDObjectTracking P3OrtBase::infer_action(
const cv::Mat & inputImg,
const cv::Mat & depthImg,
sensor_msgs::msg::CameraInfo camera_info,
double camera_to_plane_distance_mm,
const std::string tracker_type,
std::vector<cv::Ptr<cv::Tracker>> & trackers,
std::vector<int> & tracker_logs,
std::vector<EPD::LabelledRect2d> & tracker_results,
int newW,
int newH,
int paddedW,
int paddedH,
float ratio,
float * dst,
float confThresh,
const cv::Scalar & meanVal)
{
cv::Mat tmpImg;
cv::resize(inputImg, tmpImg, cv::Size(newW, newH));
tmpImg.convertTo(tmpImg, CV_32FC3);
tmpImg -= meanVal;
cv::Mat paddedImg(paddedH, paddedW, CV_32FC3, cv::Scalar(0, 0, 0));
tmpImg.copyTo(paddedImg(cv::Rect(0, 0, newW, newH)));
this->preprocess(dst, paddedImg, paddedW, paddedH, 3);
// boxes, labels, scores, masks
auto inferenceOutput = (*this)({dst});
assert(inferenceOutput[1].second.size() == 1);
size_t nBoxes = inferenceOutput[1].second[0];
std::vector<std::array<float, 4>> bboxes;
std::vector<uint64_t> classIndices;
std::vector<float> scores;
std::vector<cv::Mat> masks;
bboxes.reserve(nBoxes);
classIndices.reserve(nBoxes);
scores.reserve(nBoxes);
masks.reserve(nBoxes);
for (size_t i = 0; i < nBoxes; ++i) {
if (inferenceOutput[2].first[i] > confThresh) {
float xmin = inferenceOutput[0].first[i * 4 + 0] / ratio;
float ymin = inferenceOutput[0].first[i * 4 + 1] / ratio;
float xmax = inferenceOutput[0].first[i * 4 + 2] / ratio;
float ymax = inferenceOutput[0].first[i * 4 + 3] / ratio;
xmin = std::max<float>(xmin, 0);
ymin = std::max<float>(ymin, 0);
xmax = std::min<float>(xmax, inputImg.cols);
ymax = std::min<float>(ymax, inputImg.rows);
bboxes.emplace_back(std::array<float, 4>{xmin, ymin, xmax, ymax});
classIndices.emplace_back(reinterpret_cast<int64_t *>(inferenceOutput[1].first)[i]);
scores.emplace_back(inferenceOutput[2].first[i]);
cv::Mat curMask(28, 28, CV_32FC1);
memcpy(
curMask.data,
inferenceOutput[3].first + i * 28 * 28,
28 * 28 * sizeof(float));
masks.emplace_back(curMask);
}
}
tracking_evaluate(bboxes, inputImg, tracker_type, trackers, tracker_logs, tracker_results);
std::vector<std::string> allClassNames = this->getClassNames();
float maskThreshold = 0.5;
cv::Mat result = inputImg.clone();
assert(bboxes.size() == classIndices.size());
if (!allClassNames.empty()) {
assert(
allClassNames.size() >
*std::max_element(classIndices.begin(), classIndices.end()));
}
// If there is zero bounding boxes generated, return empty EPDObjectTracking object.
if (bboxes.size() == 0) {
EPD::EPDObjectTracking output_msg(0);
return output_msg;
}
EPD::EPDObjectTracking output_obj(bboxes.size());
float table_depth = this->findMedian(depthImg) * 0.001;
// No. of objects will be equal to number of bboxes
/* START of Populating EPDObjectTracking object */
for (size_t i = 0; i < bboxes.size(); ++i) {
const auto & curBbox = bboxes[i];
const uint64_t classIdx = classIndices[i];
cv::Mat curMask = masks[i].clone();
const std::string curLabel = allClassNames.empty() ?
std::to_string(classIdx) :
allClassNames[classIdx];
output_obj.objects[i].name = curLabel;
// Top x of ROI
output_obj.objects[i].roi.x_offset = curBbox[0];
// Top y of ROI
output_obj.objects[i].roi.y_offset = curBbox[1];
// Bounding Box height as ROI
output_obj.objects[i].roi.height = curBbox[3] - curBbox[1];
// Bounding Box width as ROI
output_obj.objects[i].roi.width = curBbox[2] - curBbox[0];
output_obj.objects[i].mask = curMask;
// Print out tracker number tag for object.
for (size_t j = 0; j < tracker_results.size(); j++) {
if (tracker_results[j].obj_bounding_box.x == curBbox[0] &&
tracker_results[j].obj_bounding_box.y == curBbox[1] &&
tracker_results[j].obj_bounding_box.width == curBbox[2] - curBbox[0] &&
tracker_results[j].obj_bounding_box.height == curBbox[3] - curBbox[1])
{
output_obj.object_ids[i] = tracker_results[j].obj_tag;
}
}
// Visualizing masks
const cv::Rect curBoxRect(cv::Point(curBbox[0], curBbox[1]),
cv::Point(curBbox[2], curBbox[3]));
cv::resize(curMask, curMask, curBoxRect.size());
// Assigning masks that exceed the maskThreshold.
cv::Mat finalMask = (curMask > maskThreshold);
std::vector<cv::Mat> contours;
cv::Mat hierarchy;
cv::Mat tempFinalMask;
finalMask.convertTo(tempFinalMask, CV_8U);
// Generate contours.
cv::findContours(
tempFinalMask, contours, hierarchy, cv::RETR_TREE,
cv::CHAIN_APPROX_SIMPLE);
// For more details, refer to link below:
// https://tinyurl.com/y5qnnxud
float ppx = camera_info.k.at(2);
float fx = camera_info.k.at(0);
float ppy = camera_info.k.at(5);
float fy = camera_info.k.at(4);
// Getting rotated rectangle and draw the major axis
std::vector<cv::RotatedRect> minRect(contours.size());
std::vector<float> angles;
float obj_surface_depth;
cv::Point pt_a, pt_b, pt_c, pt_d;
cv::Point rotated_mid;
// Getting only the largest contour
// The largest contour is the one which has the largest area.
double maxArea = 0;
int maxAreaContourId = 999;
for (unsigned int j = 0; j < contours.size(); j++) {
double newArea = cv::contourArea(contours[j]);
if (newArea > maxArea) {
maxArea = newArea;
maxAreaContourId = j;
}
}
unsigned int maxID = maxAreaContourId;
for (unsigned int index = 0; index < contours.size(); index++) {
if (index != maxID) {
continue;
}
// Function that compute rotated rectangle based on contours
minRect[index] = cv::minAreaRect(cv::Mat(contours[index]));
cv::Point2f rect_points[4];
// 4 points of the rotated rectangle
minRect[index].points(rect_points);
// Mid points of the each side of the rotated rectangle
pt_a = (rect_points[0] + rect_points[3]) / 2;
pt_b = (rect_points[1] + rect_points[2]) / 2;
pt_c = (rect_points[0] + rect_points[1]) / 2;
pt_d = (rect_points[3] + rect_points[2]) / 2;
// For temporary, bboxes center
rotated_mid = (cv::Point(curBbox[0], curBbox[1]) +
cv::Point(curBbox[2], curBbox[3])) / 2;
obj_surface_depth = this->findMin(depthImg(curBoxRect)) * 0.001;
float x = (rotated_mid.x - ppx) / fx * obj_surface_depth;
float y = (rotated_mid.y - ppy) / fy * obj_surface_depth;
output_obj.objects[i].centroid.x = x;
output_obj.objects[i].centroid.y = y;
output_obj.objects[i].centroid.z = obj_surface_depth +
(table_depth - obj_surface_depth) / 2;
// Get Real Size and angle of object
// Compare the length of 2 side of the rectangle,
// the longer side will be the major axis
if (cv::norm(rect_points[0] - rect_points[1]) >
cv::norm(rect_points[1] - rect_points[2]))
{
// Calculates the length of the object
output_obj.objects[i].length = obj_surface_depth * sqrt(
pow((pt_a.x - pt_b.x) / fx, 2) +
pow((pt_a.y - pt_b.y) / fy, 2));
// Calculates the breadth of the object
output_obj.objects[i].breadth = obj_surface_depth * sqrt(
pow((pt_c.x - pt_d.x) / fx, 2) +
pow((pt_c.y - pt_d.y) / fy, 2));
} else {
// Gets object breadth and length
output_obj.objects[i].breadth = obj_surface_depth * sqrt(
pow((pt_a.x - pt_b.x) / fx, 2) +
pow((pt_a.y - pt_b.y) / fy, 2));
output_obj.objects[i].length = obj_surface_depth * sqrt(
pow((pt_c.x - pt_d.x) / fx, 2) +
pow((pt_c.y - pt_d.y) / fy, 2));
}
// Setting height of object
output_obj.objects[i].height = table_depth - obj_surface_depth;
pcl::PointCloud<pcl::PointXYZ>::Ptr segmented_cloud(new pcl::PointCloud<pcl::PointXYZ>);
segmented_cloud->header.frame_id = "camera_color_optical_frame";
segmented_cloud->is_dense = true;
cv::Mat tempImg = inputImg.clone();
// Converting Depth Image to PointCloud
for (int j = 0; j < tempFinalMask.rows; j++) {
for (int k = 0; k < tempFinalMask.cols; k++) {
// TODO(cardboardcode) convert segmented mask into segmented pointcloud
int pixelValue = static_cast<int>(tempFinalMask.at<uchar>(j, k));
if (pixelValue != 0) {
float z = static_cast<float>(depthImg.at<uint16_t>(
curBoxRect.y + j, curBoxRect.x + k) * 0.001);
float x = static_cast<float>((curBoxRect.x + k - ppx) / fx) * z;
float y = static_cast<float>((curBoxRect.y + j - ppy) / fy) * z;
// Ignore all points that has a value of less than 0.1mm in z.
if (std::abs(z) < 0.0001 || std::abs(z) > camera_to_plane_distance_mm * 0.001) {
continue;
} else {
pcl::PointXYZ curPoint(x, y, z);
segmented_cloud->points.push_back(curPoint);
}
}
}
}
output_obj.objects[i].segmented_pcl = *segmented_cloud;
// Determine object axis of segmented_pcl
Eigen::Vector3f axis;
Eigen::Vector4f centerpoint;
Eigen::Vector3f eigenvalues;
Eigen::Matrix3f eigenvectors;
Eigen::Matrix3f covariance_matrix;
pcl::compute3DCentroid(output_obj.objects[i].segmented_pcl, centerpoint);
pcl::computeCovarianceMatrix(
output_obj.objects[i].segmented_pcl,
centerpoint,
covariance_matrix);
pcl::eigen33(covariance_matrix, eigenvectors, eigenvalues);
axis = Eigen::Vector3f(
eigenvectors.col(2)(0),
eigenvectors.col(2)(1),
eigenvectors.col(2)(2));
axis = axis.normalized();
output_obj.objects[i].axis.x = axis(0);
output_obj.objects[i].axis.y = axis(1);
output_obj.objects[i].axis.z = axis(2);
}
}
// END of Populating EPDObjectTracking object
return output_obj;
}
// Filter out accurate tracked objects using both new detection results and predicted
// trackign results.
void P3OrtBase::tracking_evaluate(
const std::vector<std::array<float, 4>> & bboxes,
const cv::Mat & img,
const std::string tracker_type,
std::vector<cv::Ptr<cv::Tracker>> & trackers,
std::vector<int> & tracker_logs,
std::vector<EPD::LabelledRect2d> & tracker_results)
{
if (tracker_results.size() == 0 && bboxes.size() == 0) {
// Action 1
// Do nothing.
return;
} else if (tracker_results.size() != 0 && bboxes.size() == 0) {
// Action 2
// If there are no detection results in frame, remove all tracking results
// Assumption: Existing static object detections do not fluctuate and disappear for lunch.
trackers.clear();
tracker_results.clear();
return;
} else if (tracker_results.size() == 0 && bboxes.size() != 0) {
// Action 3
// If tracking results is empty,
// immediately assign detection results to tracker_results with new labels.
for (size_t i = 0; i < bboxes.size(); i++) {
create_tracker_tag(tracker_logs);
const auto & curBbox = bboxes[i];
cv::Rect2d detected_box = cv::Rect2d(
curBbox[0],
curBbox[1],
curBbox[2] - curBbox[0],
curBbox[3] - curBbox[1]);
// Create, initialize and add tracker.
cv::Ptr<cv::Tracker> temp_tracker = create_tracker(tracker_type);
temp_tracker->init(img, detected_box);
trackers.push_back(temp_tracker);
// Create LabelledRect2d object
EPD::LabelledRect2d tracker_output;
tracker_output.obj_tag = std::to_string(tracker_logs.size());
tracker_output.obj_bounding_box = detected_box;
tracker_results.push_back(tracker_output);
}
return;
} else if (tracker_results.size() != 0 && bboxes.size() != 0) {
// Action 4
// If there is new detection results and existing tracking results,
// determine if the new detection results are of new objects.
// Update trackers
for (size_t i = 0; i < trackers.size(); i++) {
trackers[i]->update(img, tracker_results[i].obj_bounding_box);
}
if (tracker_results.size() > bboxes.size()) {
// Remove tracked objects that have been removed out of frame.
// Scan through all detection results.
// Determine which trackers are updated.
// If a tracker is not updated, remove it.
std::vector<bool> updatedTrackers(tracker_results.size(), false);
std::vector<float> trackerIOUScore(tracker_results.size(), 0.0);
for (size_t i = 0; i < bboxes.size(); i++) {
const auto & curBbox = bboxes[i];
cv::Rect2d detected_box(
curBbox[0],
curBbox[1],
curBbox[2] - curBbox[0],
curBbox[3] - curBbox[1]);
// Check through all tracking results and update tracking results.
for (size_t j = 0; j < tracker_results.size(); j++) {
cv::Rect2d & tracked_box = tracker_results[j].obj_bounding_box;
// If detection results boxes has more than 0.5 intersection over union
// (IoU), update tracker results boxes with detection results boxes.
float iouScore = getIOU(detected_box, tracked_box);
if (iouScore > 0.5 && iouScore > trackerIOUScore[j]) {
tracked_box = detected_box;
trackerIOUScore[j] = iouScore;
updatedTrackers[j] = true;
break;
}
}
}
// Remove all trackers that are not updated.
for (size_t i = 0; i < tracker_results.size(); i++) {
if (updatedTrackers[i] == false) {
trackers.erase(trackers.begin() + i);
tracker_results.erase(tracker_results.begin() + i);
}
}
} else if (tracker_results.size() < bboxes.size()) {
// Update existing trackers and add new object.
// Add new detection results to existing trackers.
// Scan through all detection results.
// Determine which detections are new.
// If a detection is new, add it to trackers and tracker_results.
// If a tracker is not updated, remove it.
std::vector<bool> newDetection(bboxes.size(), false);
std::vector<float> trackerIOUScore(tracker_results.size(), 0.0);
for (size_t i = 0; i < bboxes.size(); i++) {
const auto & curBbox = bboxes[i];
cv::Rect2d detected_box(
curBbox[0],
curBbox[1],
curBbox[2] - curBbox[0],
curBbox[3] - curBbox[1]);
// Check through all tracking results and update tracking results.
bool isNewDetection = true;
for (size_t j = 0; j < tracker_results.size(); j++) {
cv::Rect2d & tracked_box = tracker_results[j].obj_bounding_box;
// If detection results boxes has more than 0.5 intersection over union
// (IoU), update tracker results boxes with detection results boxes.
float iouScore = getIOU(detected_box, tracked_box);
if (iouScore > 0.5 && iouScore > trackerIOUScore[j]) {
tracked_box = detected_box;
trackerIOUScore[j] = iouScore;
isNewDetection = false;
break;
}
}
if (isNewDetection) {
newDetection[i] = true;
}
}
// Add new detections to trackers.
for (size_t i = 0; i < bboxes.size(); i++) {
if (newDetection[i] == true) {
const auto & curBbox = bboxes[i];
cv::Rect2d detected_box(
curBbox[0],
curBbox[1],
curBbox[2] - curBbox[0],
curBbox[3] - curBbox[1]);
create_tracker_tag(tracker_logs);
cv::Ptr<cv::Tracker> temp_tracker = create_tracker(tracker_type);
temp_tracker->init(img, detected_box);
trackers.push_back(temp_tracker);
EPD::LabelledRect2d tracker_output;
tracker_output.obj_tag = std::to_string(tracker_logs.size());
tracker_output.obj_bounding_box = detected_box;
tracker_results.push_back(tracker_output);
}
}
} else {
// Update existing trackers or add and remove objects.
std::vector<bool> updatedTrackers(tracker_results.size(), false);
std::vector<bool> newDetection(bboxes.size(), false);
std::vector<float> trackerIOUScore(tracker_results.size(), 0.0);
for (size_t i = 0; i < bboxes.size(); i++) {
const auto & curBbox = bboxes[i];
cv::Rect2d detected_box(
curBbox[0],
curBbox[1],
curBbox[2] - curBbox[0],
curBbox[3] - curBbox[1]);
// Check through all tracking results and update tracking results.
bool isNewDetection = true;
for (size_t j = 0; j < tracker_results.size(); j++) {
cv::Rect2d & tracked_box = tracker_results[j].obj_bounding_box;
// If detection results boxes has more than 0.5 intersection over union
// (IoU), update tracker results boxes with detection results boxes.
float iouScore = getIOU(detected_box, tracked_box);
if (iouScore > 0.5 && iouScore > trackerIOUScore[j]) {
tracked_box = detected_box;
isNewDetection = false;
updatedTrackers[j] = true;
trackerIOUScore[j] = iouScore;
break;
}
}
if (isNewDetection) {
newDetection[i] = true;
}
}
// Add new detections to trackers.
for (size_t i = 0; i < bboxes.size(); i++) {
if (newDetection[i] == true) {
const auto & curBbox = bboxes[i];
cv::Rect2d detected_box(
curBbox[0],
curBbox[1],
curBbox[2] - curBbox[0],
curBbox[3] - curBbox[1]);
create_tracker_tag(tracker_logs);
cv::Ptr<cv::Tracker> temp_tracker = create_tracker(tracker_type);
temp_tracker->init(img, detected_box);
trackers.push_back(temp_tracker);
EPD::LabelledRect2d tracker_output;
tracker_output.obj_tag = std::to_string(tracker_logs.size());
tracker_output.obj_bounding_box = detected_box;
tracker_results.push_back(tracker_output);
}
}
// Remove all trackers that are not updated.
for (size_t i = 0; i < tracker_results.size(); i++) {
if (updatedTrackers[i] == false) {
trackers.erase(trackers.begin() + i);
tracker_results.erase(tracker_results.begin() + i);
}
}
}
return;
}
}
double P3OrtBase::getIOU(cv::Rect2d detected_box, cv::Rect2d tracked_box) const
{
cv::Rect2d intersection = detected_box & tracked_box;
return intersection.area();
}
void P3OrtBase::create_tracker_tag(std::vector<int> & tracker_logs)
{
if (tracker_logs.size() == 0) {
tracker_logs.push_back(0);
} else {
tracker_logs.push_back(tracker_logs.back() + 1);
}
}
// Create tracker by name
cv::Ptr<cv::Tracker> P3OrtBase::create_tracker(std::string tracker_type)
{
if (tracker_type == "KCF") {
return cv::TrackerKCF::create();
} else if (tracker_type == "MEDIANFLOW") {
return cv::TrackerMedianFlow::create();
} else if (tracker_type == "CSRT") {
return cv::TrackerCSRT::create();
} else {
throw std::runtime_error(
"Invalid OpenCV Tracker name given in usecase_config.txt. "
"Please use [KCF, MedianFlow, CSRT] only.");
}
}
} // namespace Ort
|
.global s_prepare_buffers
s_prepare_buffers:
push %r13
push %r15
push %r9
push %rax
push %rbx
push %rcx
push %rdi
push %rsi
lea addresses_A_ht+0x88c3, %rsi
lea addresses_WC_ht+0x170c3, %rdi
cmp %rbx, %rbx
mov $61, %rcx
rep movsq
nop
nop
nop
nop
nop
and %r13, %r13
lea addresses_WT_ht+0x50c3, %r9
cmp $42926, %rax
mov $0x6162636465666768, %rdi
movq %rdi, %xmm2
movups %xmm2, (%r9)
nop
nop
nop
nop
nop
cmp %r13, %r13
lea addresses_normal_ht+0xd0c3, %rdi
dec %r13
and $0xffffffffffffffc0, %rdi
movntdqa (%rdi), %xmm0
vpextrq $0, %xmm0, %rsi
nop
add $18432, %rbx
lea addresses_normal_ht+0x18ec3, %rcx
nop
nop
nop
and %rbx, %rbx
movb (%rcx), %r9b
nop
sub %r9, %r9
lea addresses_WT_ht+0x18fc3, %rdi
nop
nop
nop
nop
xor %rcx, %rcx
mov $0x6162636465666768, %r9
movq %r9, (%rdi)
nop
nop
and %rsi, %rsi
lea addresses_WT_ht+0xb04b, %rdi
nop
nop
sub $50277, %rbx
vmovups (%rdi), %ymm5
vextracti128 $0, %ymm5, %xmm5
vpextrq $0, %xmm5, %rax
nop
nop
nop
cmp $48647, %r9
lea addresses_WT_ht+0x10cc3, %rsi
lea addresses_UC_ht+0x419b, %rdi
inc %r15
mov $49, %rcx
rep movsw
nop
nop
nop
nop
nop
cmp $33417, %rsi
lea addresses_D_ht+0x1c543, %rsi
lea addresses_A_ht+0x6883, %rdi
clflush (%rdi)
nop
nop
nop
nop
nop
xor $12617, %rbx
mov $101, %rcx
rep movsb
sub %rax, %rax
lea addresses_A_ht+0xbcc3, %r15
inc %rax
movups (%r15), %xmm4
vpextrq $1, %xmm4, %rbx
nop
nop
nop
nop
sub $48395, %r13
lea addresses_normal_ht+0x1ece2, %r15
nop
nop
nop
xor $17618, %r9
mov $0x6162636465666768, %rcx
movq %rcx, (%r15)
nop
nop
nop
nop
nop
sub %rcx, %rcx
lea addresses_WC_ht+0x1e0c3, %rbx
nop
nop
cmp %r9, %r9
mov $0x6162636465666768, %rdi
movq %rdi, %xmm0
and $0xffffffffffffffc0, %rbx
vmovaps %ymm0, (%rbx)
nop
sub $62643, %rbx
pop %rsi
pop %rdi
pop %rcx
pop %rbx
pop %rax
pop %r9
pop %r15
pop %r13
ret
.global s_faulty_load
s_faulty_load:
push %r10
push %r15
push %r8
push %rbp
push %rdi
push %rsi
// Faulty Load
lea addresses_A+0x40c3, %rdi
nop
nop
nop
and $31094, %rsi
vmovups (%rdi), %ymm4
vextracti128 $1, %ymm4, %xmm4
vpextrq $1, %xmm4, %r8
lea oracles, %rbp
and $0xff, %r8
shlq $12, %r8
mov (%rbp,%r8,1), %r8
pop %rsi
pop %rdi
pop %rbp
pop %r8
pop %r15
pop %r10
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'type': 'addresses_A', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': False}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'type': 'addresses_A', 'size': 32, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': True}}
<gen_prepare_buffer>
{'OP': 'REPM', 'src': {'type': 'addresses_A_ht', 'congruent': 8, 'same': False}, 'dst': {'type': 'addresses_WC_ht', 'congruent': 8, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 10, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_normal_ht', 'size': 16, 'AVXalign': False, 'NT': True, 'congruent': 11, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_normal_ht', 'size': 1, 'AVXalign': False, 'NT': False, 'congruent': 9, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 6, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_WT_ht', 'size': 32, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_WT_ht', 'congruent': 10, 'same': False}, 'dst': {'type': 'addresses_UC_ht', 'congruent': 2, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_D_ht', 'congruent': 7, 'same': False}, 'dst': {'type': 'addresses_A_ht', 'congruent': 6, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_A_ht', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 10, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_normal_ht', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WC_ht', 'size': 32, 'AVXalign': True, 'NT': False, 'congruent': 10, 'same': False}}
{'35': 21829}
35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35
*/
|
/*=========================================================================
Program: Visualization Toolkit
Module: vtkSimple3DCirclesStrategy.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkSimple3DCirclesStrategy.h"
#include "vtkAbstractArray.h"
#include "vtkCharArray.h" // For temporary store for point ordering
#include "vtkDirectedGraph.h" // For this->Graph type check
#include "vtkIdTypeArray.h" // For Ordered array
#include "vtkInEdgeIterator.h" // For in edge(s) checks
#include "vtkIntArray.h" // For hierarchy layers
#include "vtkMath.h" // For cross, outer, norm and dot
#include "vtkObjectFactory.h" // For VTK ::New() function
#include "vtkOutEdgeIterator.h" // For out edge(s) checks
#include "vtkPoints.h" // For output target
#include "vtkSmartPointer.h" // For good memory handling
#include <cmath> // For abs, sin, cos and tan
#include <algorithm> // For min, max, swap, etc.
#include <list> // For internal store
template <class T> bool IsZero( T value )
{
return ( ( value < VTK_DBL_EPSILON ) && ( value > ( -1.0 * VTK_DBL_EPSILON ) ) );
};
class vtkSimple3DCirclesStrategyInternal
{
public:
vtkSimple3DCirclesStrategyInternal( void )
{
};
vtkSimple3DCirclesStrategyInternal( const vtkSimple3DCirclesStrategyInternal &from )
{
if ( &from != this )
this->store = from.store;
};
vtkSimple3DCirclesStrategyInternal & operator = ( const vtkSimple3DCirclesStrategyInternal &from )
{
if ( &from != this )
this->store = from.store;
return *this;
};
vtkSimple3DCirclesStrategyInternal & operator = ( const std::list<vtkIdType> &from )
{
this->store = from;
return *this;
};
vtkIdType front( void )
{
return this->store.front();
};
void pop_front( void )
{
this->store.pop_front();
};
std::size_t size( void )
{
return this->store.size();
};
void push_back( const vtkIdType &value )
{
this->store.push_back( value );
};
~vtkSimple3DCirclesStrategyInternal( void )
{
this->store.clear();
};
private:
std::list<vtkIdType> store;
};
vtkStandardNewMacro(vtkSimple3DCirclesStrategy);
void vtkSimple3DCirclesStrategy::PrintSelf( ostream &os, vtkIndent indent )
{
this->Superclass::PrintSelf( os, indent );
os << indent << "Radius : " << this->Radius << endl;
os << indent << "Height : " << this->Height << endl;
os << indent << "Origin : (" << this->Origin[0] << "," << this->Origin[1] << "," << this->Origin[2] << ")" << endl;
os << indent << "Direction : (" << this->Direction[0] << "," << this->Direction[1] << "," << this->Direction[2] << ")" << endl;
os << indent << "Rotate matrix : [[" << this->T[0][0] << ";" << this->T[1][0] << ";" << this->T[2][0] << "]";
os << "[" << this->T[0][1] << ";" << this->T[1][1] << ";" << this->T[2][1] << "]";
os << "[" << this->T[0][2] << ";" << this->T[1][2] << ";" << this->T[2][2] << "]]" << endl;
os << indent << "Method : ";
if ( this->Method == FixedRadiusMethod )
os << "fixed radius method" << endl;
else if ( this->Method == FixedDistanceMethod )
os << "fixed distance method" << endl;
os << indent << "MarkValue : " << this->MarkedValue << endl;
os << indent << "Auto height : ";
if ( this->AutoHeight == 1 )
os << "On" << endl;
else
os << "Off" << endl;
os << indent << "Minimum degree for autoheight : " << this->MinimumRadian << " rad [" << vtkMath::DegreesFromRadians( this->MinimumRadian ) << " deg]" << endl;
os << indent << "Registered MarkedStartPoints :";
if ( this->MarkedStartVertices == 0 )
os << " (none)" << endl;
else
{
os << endl;
this->MarkedStartVertices->PrintSelf( os, indent.GetNextIndent() );
}
os << indent << "Registered HierarchicalLayers :";
if ( this->HierarchicalLayers == 0 )
os << " (none)" << endl;
else
{
os << endl;
this->HierarchicalLayers->PrintSelf( os, indent.GetNextIndent() );
}
os << indent << "Registered HierarchicalOrder :";
if ( this->HierarchicalOrder == 0 )
os << " (none)" << endl;
else
{
os << endl;
this->HierarchicalOrder->PrintSelf( os, indent.GetNextIndent() );
}
os << indent << "ForceToUseUniversalStartPointsFinder :"
<< this->ForceToUseUniversalStartPointsFinder << endl;
}
void vtkSimple3DCirclesStrategy::SetDirection( double dx, double dy, double dz )
{
vtkDebugMacro( << this->GetClassName() << " (" << this << "): setting Direction to (" << dx << "," << dy << "," << dz << ")" );
if ( ( this->Direction[0] != dx ) || ( this->Direction[1] != dy ) || ( this->Direction[2] != dz ) )
{
double global[3], local[3];
global[0] = dx;
global[1] = dy;
global[2] = dz;
local[0] = 0.0;
local[1] = 1.0;
local[2] = 0.0;
double length_global = vtkMath::Norm( global );
if ( IsZero( length_global ) )
{
vtkWarningMacro( << "The length of direction vector is zero! Direction has not been changed!" );
return;
}
double cosfi, n[3], E[3][3], U[3][3], u[3][3], number;
global[0] = global[0] / length_global;
global[1] = global[1] / length_global;
global[2] = global[2] / length_global;
// http://en.citizendium.org/wiki/Rotation_matrix
// we are going from local to global.
// cos(fi) = local.global -> cosfi, because |local|=1 and |global|=1
cosfi = vtkMath::Dot( local, global );
// if fi == 2*Pi -> cosfi = -1
if ( IsZero( cosfi + 1.0 ) )
{
// if "local" is on "z" axes
if ( IsZero( local[2] + 1.0 ) || IsZero( local[2] - 1.0 ) )
{
this->T[0][0] = this->T[2][2] = -1.0;
this->T[1][1] = 1.0;
this->T[0][1] = this->T[1][0] = this->T[0][2] = this->T[2][0] = this->T[1][2] = this->T[2][1] = 0.0;
}
// if local != ( (0,0,1) or (0,0,-1) )
else
{
// n vector
n[0] = 1.0 / (1.0 - local[2]*local[2] ) * local[1];
n[1] = -1.0 / (1.0 - local[2]*local[2] ) * local[0];
n[2] = 0.0;
// u = n X n
vtkMath::Outer( n, n, u );
// -E
E[0][0] = E[1][1] = E[2][2] = -1.0;
E[0][1] = E[1][0] = E[0][2] = E[2][0] = E[1][2] = E[2][1] = 0.0;
// T = -E + 2*u
int i,j;
for ( i = 0; i < 3; ++i )
for ( j = 0; j < 3; ++j )
this->T[i][j] = E[i][j] + ( u[i][j] * 2.0 );
}
}
// fi < 2*Pi
else
{
// n = local x global -> n(nx,ny,nz)
vtkMath::Cross( local, global, n );
//
// cos(fi)*E
//
E[0][0] = E[1][1] = E[2][2] = cosfi;
E[0][1] = E[1][0] = E[0][2] = E[2][0] = E[1][2] = E[2][1] = 0.0;
// | 0 -nz ny |
// U = sin(fi)*N = | nz 0 -nx |
// | -ny nx 0 |
U[0][0] = U[1][1] = U[2][2] = 0.0;
U[0][1] = -1.0 * n[2]; U[1][0] = n[2];
U[0][2] = n[1]; U[2][0] = -1.0 * n[1];
U[1][2] = -1.0 * n[0]; U[2][1] = n[0];
// u = n X n
vtkMath::Outer( n, n, u );
int i,j;
// T = cos(fi)*E + U + 1/(1+cos(fi))*[n X n]
// [ number = 1/(1+cos(fi)) ]
number = 1.0 / ( 1.0 + cosfi );
for ( i = 0; i < 3; ++i )
for ( j = 0; j < 3; ++j )
this->T[i][j] = E[i][j] + U[i][j] + ( u[i][j] * number );
}
this->Direction[0] = dx;
this->Direction[1] = dy;
this->Direction[2] = dz;
vtkDebugMacro( << "Transformation matrix : [[" << this->T[0][0] << "," << this->T[1][0] << "," << this->T[2][0] << "][" << this->T[0][1] << "," << this->T[1][1] << "," << this->T[2][1] << "][" << this->T[0][2] << "," << this->T[1][2] << "," << this->T[2][2] << "]]" );
this->Modified();
}
}
void vtkSimple3DCirclesStrategy::SetDirection( double d[3] )
{
this->SetDirection( d[0], d[1], d[2] );
}
vtkCxxSetObjectMacro(vtkSimple3DCirclesStrategy,MarkedStartVertices,vtkAbstractArray);
void vtkSimple3DCirclesStrategy::SetMarkedValue( vtkVariant val )
{
if ( !this->MarkedValue.IsEqual(val) )
{
this->MarkedValue = val;
vtkDebugMacro( << "Setting MarkedValue : " << this->MarkedValue );
this->Modified();
}
}
vtkVariant vtkSimple3DCirclesStrategy::GetMarkedValue( void )
{
return this->MarkedValue;
}
void vtkSimple3DCirclesStrategy::SetMinimumDegree( double degree )
{
this->SetMinimumRadian( vtkMath::RadiansFromDegrees( degree ) );
}
double vtkSimple3DCirclesStrategy::GetMinimumDegree( void )
{
return vtkMath::DegreesFromRadians( this->GetMinimumRadian() );
}
vtkCxxSetObjectMacro(vtkSimple3DCirclesStrategy,HierarchicalLayers,vtkIntArray);
vtkCxxSetObjectMacro(vtkSimple3DCirclesStrategy,HierarchicalOrder,vtkIdTypeArray);
vtkSimple3DCirclesStrategy::vtkSimple3DCirclesStrategy( void )
: Radius(1), Height(1), Method(FixedRadiusMethod), MarkedStartVertices(0), ForceToUseUniversalStartPointsFinder(0), AutoHeight(0), MinimumRadian(vtkMath::DoublePi()/6.0), HierarchicalLayers(0), HierarchicalOrder(0)
{
this->Direction[0] = this->Direction[1] = 0.0; this->Direction[2] = 1.0;
this->T[0][1] = this->T[0][2] = this->T[1][2] = 0.0;
this->T[1][0] = this->T[2][0] = this->T[2][1] = 0.0;
this->T[0][0] = this->T[1][1] = this->T[2][2] = 1.0;
this->Origin[0] = this->Origin[1] = this->Origin[2] = 0.0;
}
vtkSimple3DCirclesStrategy::~vtkSimple3DCirclesStrategy( void )
{
this->SetMarkedStartVertices(0);
this->SetHierarchicalLayers(0);
this->SetHierarchicalOrder(0);
}
void vtkSimple3DCirclesStrategy::Layout( void )
{
if ( this->Graph == 0 )
{
vtkErrorMacro( << "Graph is null!" );
return;
}
if ( this->Graph->GetNumberOfVertices() == 0 )
{
vtkDebugMacro( << "Graph is empty (no no vertices)!" );
return;
}
vtkSmartPointer<vtkDirectedGraph> target = vtkSmartPointer<vtkDirectedGraph>::New();
if ( ! target->CheckedShallowCopy( this->Graph ) )
{
vtkErrorMacro( << "Graph must be directed graph!" );
return;
}
vtkSimple3DCirclesStrategyInternal start_points, order_points, stand_alones;
// Layers begin
vtkSmartPointer<vtkIntArray> layers = 0;
if ( this->HierarchicalLayers != 0 )
{
if ( ( this->HierarchicalLayers->GetMaxId() + 1 ) == target->GetNumberOfVertices() )
{
layers = this->HierarchicalLayers;
}
}
if ( layers == 0 )
{
layers = vtkSmartPointer<vtkIntArray>::New();
if ( this->HierarchicalLayers != 0 )
this->HierarchicalLayers->UnRegister(this);
this->HierarchicalLayers = layers;
this->HierarchicalLayers->Register(this);
layers->SetNumberOfValues( target->GetNumberOfVertices() );
for ( vtkIdType i = 0; i <= layers->GetMaxId(); ++i )
layers->SetValue(i,-1);
if ( this->UniversalStartPoints( target, &start_points, &stand_alones, layers ) == -1 )
{
vtkErrorMacro( << "There is no start point!" );
return;
}
order_points = start_points;
this->BuildLayers( target, &start_points, layers );
}
else
{
for ( vtkIdType i = 0; i <= layers->GetMaxId(); ++i )
{
if ( layers->GetValue(i) == 0 )
order_points.push_back(i);
else if ( layers->GetValue(i) == -2 )
stand_alones.push_back(i);
}
}
// Layers end
// Order begin
vtkSmartPointer<vtkIdTypeArray> order = 0;
if ( this->HierarchicalOrder != 0 )
{
if ( ( this->HierarchicalOrder->GetMaxId() + 1 ) == target->GetNumberOfVertices() )
{
order = this->HierarchicalOrder;
}
}
if ( order == 0 )
{
order = vtkSmartPointer<vtkIdTypeArray>::New();
if ( this->HierarchicalOrder != 0 )
this->HierarchicalOrder->UnRegister(this);
this->HierarchicalOrder = order;
this->HierarchicalOrder->Register(this);
order->SetNumberOfValues( target->GetNumberOfVertices() );
for ( vtkIdType i = 0; i <= order->GetMaxId(); ++i )
order->SetValue(i,-1);
this->BuildPointOrder( target, &order_points, &stand_alones, layers, order );
}
// Order end
if ( order->GetValue( order->GetMaxId() ) == -1 )
{
vtkErrorMacro( << "Not all parts of the graph is accessible. There may be a loop." );
return;
}
int index = 0;
int layer = 0;
int start = 0;
double R = this->Radius;
double Rprev = 0.0;
double localXYZ[3], globalXYZ[3], localHeight = this->Height;
double alfa = 0.0;
double tangent = tan( vtkMath::DoublePi() / 2 - this->MinimumRadian );
int ind = 0;
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
points->SetNumberOfPoints( target->GetNumberOfVertices() );
while ( index <= order->GetMaxId() )
{
start = index;
R = this->Radius;
layer = layers->GetValue( order->GetValue(index) );
while ( index <= order->GetMaxId() )
{
if ( layers->GetValue( order->GetValue(index) ) == layer )
++index;
else
break;
}
alfa = vtkMath::DoubleTwoPi() / double( index - start );
if ( this->Method == FixedDistanceMethod )
{
R = double( index - start - 1 ) * this->Radius / vtkMath::DoublePi();
}
else if ( this->Method == FixedRadiusMethod )
{
if ( ( index - start ) == 1 )
R = 0.0;
}
else
{
vtkErrorMacro( << "Method must be FixedRadiusMethod or FixedDistanceMethod!" );
return;
}
if ( ( this->AutoHeight == 1 ) && ( this->Method == FixedDistanceMethod ) )
{
if ( fabs( tangent * ( R - Rprev ) ) > this->Height )
localHeight = fabs( tangent * ( R - Rprev ) );
else
localHeight = this->Height;
}
if ( layer != 0 )
localXYZ[2] = localXYZ[2] + localHeight;
else
localXYZ[2] = 0.0;
for ( ind = start; ind < index; ++ind )
{
localXYZ[0] = R * cos( double(ind - start) * alfa );
localXYZ[1] = R * sin( double(ind - start) * alfa );
this->Transform( localXYZ, globalXYZ );
points->SetPoint( order->GetValue(ind), globalXYZ );
}
Rprev = R;
}
this->Graph->SetPoints( points );
vtkDebugMacro( << "vtkPoints is added to the graph. Vertex layout is ready." );
return;
}
void vtkSimple3DCirclesStrategy::SetGraph( vtkGraph * graph )
{
if ( this->Graph != graph )
{
this->Superclass::SetGraph( graph );
if ( this->HierarchicalLayers != 0 )
{
this->HierarchicalLayers->UnRegister(this);
this->HierarchicalLayers = 0;
}
if ( this->HierarchicalOrder != 0 )
{
this->HierarchicalOrder->UnRegister(this);
this->HierarchicalOrder = 0;
}
}
}
int vtkSimple3DCirclesStrategy::UniversalStartPoints( vtkDirectedGraph * input, vtkSimple3DCirclesStrategyInternal *target, vtkSimple3DCirclesStrategyInternal *StandAlones, vtkIntArray * layers )
{
if ( ( this->MarkedStartVertices != 0 ) && ( this->ForceToUseUniversalStartPointsFinder == 0 ) )
{
if ( this->MarkedStartVertices->GetMaxId() == layers->GetMaxId() )
{
for ( vtkIdType i = 0; i < input->GetNumberOfVertices(); ++i )
{
if ( ( input->GetInDegree(i) == 0 ) && ( input->GetOutDegree(i) > 0 ) )
{
target->push_back(i);
layers->SetValue( i, 0 );
}
else if ( ( input->GetInDegree(i) == 0 ) && ( input->GetOutDegree(i) == 0 ) )
{
layers->SetValue( i, -2 );
StandAlones->push_back(i);
}
else if ( ( this->MarkedStartVertices->GetVariantValue(i) == this->MarkedValue ) && ( input->GetOutDegree(i) > 0 ) )
{
target->push_back(i);
layers->SetValue( i, 0 );
}
}
vtkDebugMacro( << "StartPoint finder: Universal start point finder was used. Number of start point(s): " << target->size() << "; Number of stand alone point(s): " << StandAlones->size() );
return static_cast<int>(target->size());
}
else
{
vtkErrorMacro( << "MarkedStartPoints number is NOT equal number of vertices!" );
return -1;
}
}
for ( vtkIdType i = 0; i < input->GetNumberOfVertices(); ++i )
{
if ( ( input->GetInDegree(i) == 0 ) && ( input->GetOutDegree(i) > 0 ) )
{
target->push_back(i);
layers->SetValue( i, 0 );
}
else if ( ( input->GetInDegree(i) == 0 ) && ( input->GetOutDegree(i) == 0 ) )
{
layers->SetValue( i, -2 );
StandAlones->push_back(i);
}
}
vtkDebugMacro( << "StartPoint finder: Universal start point finder was used. Number of start points: " << target->size() << "; Number of stand alone point(s): " << StandAlones->size() );
return static_cast<int>(target->size());
}
int vtkSimple3DCirclesStrategy::BuildLayers( vtkDirectedGraph * input, vtkSimple3DCirclesStrategyInternal *source, vtkIntArray * layers )
{
vtkSmartPointer<vtkOutEdgeIterator> edge_out_iterator = vtkSmartPointer<vtkOutEdgeIterator>::New();
vtkSmartPointer<vtkInEdgeIterator> edge_in_iterator = vtkSmartPointer<vtkInEdgeIterator>::New();
int layer = 0, flayer = 0;
vtkInEdgeType in_edge;
vtkOutEdgeType out_edge;
bool HasAllInput = true;
vtkIdType ID = 0;
int max_layer_id = -1;
while ( source->size() > 0 )
{
ID = source->front();
source->pop_front();
input->GetOutEdges( ID, edge_out_iterator );
while ( edge_out_iterator->HasNext() )
{
out_edge = edge_out_iterator->Next();
if ( layers->GetValue( out_edge.Target ) == -1 )
{
input->GetInEdges( out_edge.Target, edge_in_iterator );
layer = layers->GetValue( ID );
HasAllInput = true;
while ( edge_in_iterator->HasNext() && HasAllInput )
{
in_edge = edge_in_iterator->Next();
flayer = layers->GetValue( in_edge.Source );
if ( flayer == -1 )
HasAllInput = false;
layer = std::max( layer, flayer );
}
if ( HasAllInput )
{
source->push_back( out_edge.Target );
layers->SetValue( out_edge.Target, layer + 1 );
max_layer_id = std::max( max_layer_id, layer + 1 );
}
}
}
}
vtkDebugMacro( << "Layer building is successful." );
return max_layer_id;
}
void vtkSimple3DCirclesStrategy::BuildPointOrder( vtkDirectedGraph * input, vtkSimple3DCirclesStrategyInternal *source, vtkSimple3DCirclesStrategyInternal *StandAlones, vtkIntArray * layers, vtkIdTypeArray * order )
{
vtkSmartPointer<vtkOutEdgeIterator> edge_out_iterator = vtkSmartPointer<vtkOutEdgeIterator>::New();
vtkSmartPointer<vtkCharArray> mark = vtkSmartPointer<vtkCharArray>::New();
vtkOutEdgeType out_edge;
int step = 0;
int layer = 0;
vtkIdType ID = 0;
mark->SetNumberOfValues( input->GetNumberOfVertices() );
for ( vtkIdType i = 0; i <= mark->GetMaxId(); ++i )
mark->SetValue(i,0);
while ( source->size() > 0 )
{
ID = source->front();
source->pop_front();
order->SetValue( step, ID );
input->GetOutEdges( ID, edge_out_iterator );
layer = layers->GetValue( ID ) + 1;
while ( edge_out_iterator->HasNext() )
{
out_edge = edge_out_iterator->Next();
if ( mark->GetValue( out_edge.Target ) == 0 )
{
if ( layers->GetValue( out_edge.Target ) == layer )
{
mark->SetValue( out_edge.Target, 1 );
source->push_back( out_edge.Target );
}
}
}
++step;
}
while ( StandAlones->size() > 0 )
{
order->SetValue( step, StandAlones->front() );
StandAlones->pop_front();
++step;
}
vtkDebugMacro( << "Vertex order building is successful." );
}
void vtkSimple3DCirclesStrategy::Transform( double Local[], double Global[] )
{
vtkMath::Multiply3x3( this->T, Local, Global );
Global[0] = this->Origin[0] + Global[0];
Global[1] = this->Origin[1] + Global[1];
Global[2] = this->Origin[2] + Global[2];
}
|
;; This version applies colour but tries to follow the
;; contour of the text when applying it.
;;
;; This was voted undesirable at WOS.
; int fzx_putc(struct fzx_state *fs, int c)
; ===============================================================
; FZX driver - Copyright (c) 2013 Einar Saukas
; FZX format - Copyright (c) 2013 Andrew Owen
; ===============================================================
; Modified for z88dk - aralbrec
; * removed self-modifying code
; * removed control code sequences
; * added colour and rop modes
; * added window
; * made fields 16-bit for hi-res
; ===============================================================
SECTION code_font
SECTION code_font_fzx
PUBLIC asm_fzx_putc
EXTERN l_jpix, error_zc
EXTERN asm_zx_pxy2saddr, asm_zx_saddr2aaddr, asm_zx_saddrpdown
asm_fzx_putc:
; print fzx glyph to window on screen
;
; enter : c = ascii code
; ix = struct fzx_state *
;
; exit : ix = struct fzx_state *
;
; success
;
; hl = screen address below glyph (may be off window)
; fzx_state.x += glyph width
; carry reset
;
; fail if glyph does not fit horizontally
;
; a = 0
; carry set
;
; fail if glyph does not fit vertically
;
; a = 1
; carry set
;
; uses : af, bc, de, hl, af'
ld l,(ix+3)
ld h,(ix+4) ; hl = struct fzx_font *
ld a,(hl)
ex af,af' ; a' = font height
inc hl
ld a,(hl)
push af ; save tracking
inc hl ; hl = & fzx_font.last_char
ld a,c ; a = char
dec a
cp (hl)
jr nc, char_undefined ; if char > fzx_font.last_char
sub 31 ; a = char - 32
jr nc, char_defined
char_undefined:
ld a,'?'-32 ; print '?' for undefined chars
char_defined:
inc hl
; hl = struct fzx_char * (code 32)
; ix = struct fzx_state *
; a = char-32
; a'= font height
; stack = tracking
ld c,a
ld b,0
add hl,bc
add hl,bc
add hl,bc ; hl = struct fzx_char *
; space character can have additional padding
or a
jr nz, no_padding ; char not space
ld a,(ix+19) ; a = space_expand
and $0f
ld b,a
no_padding:
ld d,b
; hl = struct fzx_char *
; ix = struct fzx_state *
; d = additional_padding
; a'= font height
; stack = tracking
ld c,(hl)
inc hl
ld a,(hl)
and $3f
ld b,a ; bc = bitmap offset
xor (hl)
rlca
rlca
ld e,a ; e = kern
push hl ; save & fzx_char + 1b
add hl,bc
dec hl ; hl = bitmap address
ex (sp),hl
inc hl ; hl = & fzx_char.shift_width_1
; ix = struct fzx_state *
; hl = & fzx_char.shift_width_1
; d = additional_padding
; e = kern
; a'= font height
; stack = tracking, & bitmap
ld a,(hl)
and $0f
add a,d
ld c,a ; c = width - 1 + additional_padding
ld a,(hl)
rra
rra
rra
rra
and $0f
push af ; save vertical shift
; ix = struct fzx_state *
; hl = & fzx_char.shift_width_1
; c = width - 1
; e = kern
; a'= font height
; stack = tracking, & bitmap, shift
inc hl ; hl = & fzx_char.next
ld a,(hl)
add a,l
ld b,a ; b = LSB of next char bitmap address
; ix = struct fzx_state *
; b = LSB of end of bitmap
; c = width - 1
; e = kern
; a'= font height
; stack = tracking, & bitmap, shift
; check if glyph fits window horizontally
; spectrum resolution 8-bits so ignore MSB in coordinates
ld a,(ix+6)
or a
;; jr nz, x_too_large ; if x > 255
jp nz, x_too_large
ld a,(ix+5) ; a = x coord
ld d,(ix+17) ; d = left_margin
cp d
jr nc, exceeds_margin
ld a,d
exceeds_margin:
sub e ; a = x - kern
jr nc, x_ok
xor a
x_ok:
ld (ix+5),a ; update possibly different x coord
ld e,a ; e = x coord
add a,c ; a = x + width - 1
jr c, x_too_large ; if glyph exceeds right edge of window
cp (ix+11)
jr c, width_adequate
ld a,(ix+12)
or a
jr z, x_too_large ; if glyph exceeds right edge of window
width_adequate:
ld a,(ix+9) ; a = window.x
add a,e
ld l,a ; l = absolute x coord
; ix = struct fzx_state *
; b = LSB of end of bitmap
; c = width - 1
; l = absolute x coord
; a'= font height
; stack = tracking, & bitmap, shift
; check if glyph fits window vertically
ld a,(ix+8)
or a
jr nz, y_too_large ; if y > 255
ld h,(ix+7) ; h = y coord
ex af,af' ; a = font height
add a,h
jr c, y_too_large ; if glyph exceeds bottom edge of window
dec a
cp (ix+15)
jr c, height_adequate
ld a,(ix+16)
or a
jr z, y_too_large ; if glyph exceeds bottom edge of window
height_adequate:
pop af ; a = vertical shift
add a,h ; + y coord
add a,(ix+13) ; + window.y
ld h,a ; h = absolute y coord
; ix = struct fzx_state *
; b = LSB of end of bitmap
; c = width - 1
; l = absolute x coord
; h = absolute y coord
; stack = tracking, & bitmap
ld a,l
and $07
ld e,a
ld a,c
add a,e
rra
rra
rra
inc a
and $1f ; a = width of font in bytes
pop de
push bc
push af
push de
call asm_zx_pxy2saddr ; hl = screen address, de = coords
ld a,e
and $07 ; a = rotate amount, z = zero rotate
ex af,af'
ex (sp),hl ; hl = & bitmap
ld e,b ; e = LSB of end of bitmap
ld a,d
and $07
neg
add a,8
ld b,a ; b = number of rows until next attr
ld a,c ; a = width - 1
cp 8
jr nc, wide_char
narrow_char:
ex af,af'
scf
ex af,af'
wide_char:
; ix = struct fzx_state *
; hl = & bitmap
; b = number of rows until next attr
; e = LSB of end of bitmap
; af'= rotate 0-7, carry = narrow char, z = zero rotate
; stack = tracking, width - 1, width in bytes, screen address
ld a,l
cp e
jr nz, draw_attr ; if bitmap is not zero length
; glyph drawn, update x coordinate
; ix = struct fzx_state *
; stack = tracking, width - 1, width in bytes, screen address
draw_attr_ret:
pop hl ; hl = screen address
pop bc
pop bc ; c = width - 1
pop af ; a = tracking
inc a
add a,c
add a,(ix+5) ; a = new x coordinate
ld (ix+5),a ; store new x coordinate
ret nc
ld (ix+6),1
or a
ret
x_too_large:
; ix = struct fzx_state *
; stack = tracking, & bitmap, shift
xor a
jp error_zc - 3
y_too_large:
; ix = struct fzx_state *
; stack = tracking, & bitmap, shift
ld a,1
jp error_zc - 3
draw_attr:
; ix = struct fzx_state *
; hl = & bitmap
; b = row count until next attr
; e = LSB of end of bitmap
; af'= rotate 0-7, carry = narrow char, z = zero rotate
; stack = width in bytes, screen address
ld d,b
pop af
pop bc ; b = width in bytes
push bc
push af
ex (sp),hl
push hl ; save screen address
call asm_zx_saddr2aaddr ; hl = attribute address
attr_loop:
ld a,(ix+23) ; a = foregound mask
and (hl) ; keep screen attribute bits
or (ix+22) ; mix foregound colour
ld (hl),a ; new colour to screen
inc l
djnz attr_loop
ld b,d ; b = row count until next attr
pop hl ; hl = screen address
ex (sp),hl
draw_row:
; ix = struct fzx_state *
; hl = & bitmap
; b = row count until next attr
; e = LSB of end of bitmap
; af'= rotate 0-7, carry = narrow char, z = zero rotate
; stack = width in bytes, screen address
; bitmap bytes
ld d,(hl) ; first bitmap byte
inc hl
ld c,(hl) ; second bitmap byte
inc hl
xor a ; third bitmap byte
; narrow char test
ex af,af'
jr nc, rotate_bitmap ; if wide char
dec hl ; no second bitmap byte
ld c,0 ; second byte = 0
rotate_bitmap:
ex (sp),hl ; hl = screen address
push bc ; save row count until next attr
jr z, no_rotate
ld b,a ; b = rotate amount
ex af,af'
rotate_loop:
srl d ; rotate bitmap DCA right one pixel
rr c
rra
djnz rotate_loop
ex af,af'
no_rotate:
ex af,af'
; ix = struct fzx_state *
; hl = screen address
; b = row count until next attr
; e = LSB of end of bitmap
; dca= bitmap bytes
; af'= rotate 0-7, carry = narrow char, z = zero rotate
; stack = width in bytes, & bitmap, row count until attr
call l_jpix ; call fzx_draw
call asm_zx_saddrpdown ; move screen address down one pixel
pop bc ; b = row count until next attr
ex (sp),hl ; hl = & bitmap
ld a,l
cp e
jr z, draw_attr_ret ; if bitmap finished
djnz draw_row ; if not time for new attr
ld b,8 ; row count until next attr
jr draw_attr
|
; Hooks for drawing exp bars in status_screen.asm
StatusScreenHook:
; b = SET_PAL_STATUS_SCREEN
call RunPaletteCommand
coord de, 18, 5
ld a, [wBattleMonLevel]
push af
ld a, [wLoadedMonLevel]
ld [wBattleMonLevel], a
callba PrintEXPBar
pop af
ld [wBattleMonLevel], a
ret
StatusScreen2Hook:
coord hl, 19, 1
lb bc, 6, 9
jp DrawLineBox ; Draws the box around name, HP and status
|
; =============================================================================
; BareMetal -- a 64-bit OS written in Assembly for x86-64 systems
; Copyright (C) 2008-2010 Return Infinity -- see LICENSE.TXT
;
; Screen Output Functions
; =============================================================================
align 16
db 'DEBUG: SCREEN '
align 16
; -----------------------------------------------------------------------------
; os_move_cursor -- Moves cursor in text mode
; IN: AH = row
; AL = column
; OUT: All registers preserved
os_move_cursor:
push rdx
push rcx
push rbx
push rax
mov [screen_cursor_x], ah
mov [screen_cursor_y], al
push rax
and rax, 0x000000000000FFFF ; only keep the low 16 bits
;calculate the new offset
mov cl, 80
mul cl ; AX = AL * CL
xor rbx, rbx
mov bl, [screen_cursor_x]
add ax, bx
shl ax, 1 ; multiply by 2
add rax, 0x00000000000B8000
mov [screen_cursor_offset], rax
pop rax ; Move the hardware cursor
mov bh, ah
mov bl, al
xor ax, ax
mov al, 0x50
mul bl ; bl * al = ax
movzx bx, bh
add bx, ax
mov al, 0x0E
mov ah, bh
mov dx, 0x03D4
out dx, ax
inc ax
mov ah, bl
out dx, ax
pop rax
pop rbx
pop rcx
pop rdx
ret
; -----------------------------------------------------------------------------
; -----------------------------------------------------------------------------
; os_inc_cursor -- Increment the hardware cursor by one
; IN: Nothing
; OUT: All registers preserved
os_inc_cursor:
push rax
mov ah, [screen_cursor_x] ; grab the current cursor location values
mov al, [screen_cursor_y]
inc ah
cmp ah, [screen_cols] ; 80
jne os_inc_cursor_done
xor ah, ah
inc al
cmp al, [screen_rows] ; 25
jne os_inc_cursor_done
call os_scroll_screen ; we are on the last column of the last row (bottom right) so we need to scroll the screen up by one line
mov ah, 0x00 ; now reset the cursor to be in the first colum of the last row (bottom left)
mov al, [screen_rows]
dec al
os_inc_cursor_done:
call os_move_cursor
pop rax
ret
; -----------------------------------------------------------------------------
; -----------------------------------------------------------------------------
; os_dec_cursor -- Decrement the hardware cursor by one
; IN: Nothing
; OUT: All registers preserved
os_dec_cursor:
push rax
mov ah, [screen_cursor_x] ; Get the current cursor location values
mov al, [screen_cursor_y]
cmp ah, 0 ; Check if the cursor in located on the first column?
jne os_dec_cursor_done
dec al ; Wrap the cursor back to the above line
mov ah, [screen_cols]
os_dec_cursor_done:
dec ah
call os_move_cursor
pop rax
ret
; -----------------------------------------------------------------------------
; -----------------------------------------------------------------------------
; os_print_newline -- Reset cursor to start of next line and scroll if needed
; IN: Nothing
; OUT: All registers perserved
os_print_newline:
push rax
mov ah, 0 ; Set the cursor x value to 0
mov al, [screen_cursor_y] ; Grab the cursor y value
cmp al, 24 ; Compare to see if we are on the last line
je os_print_newline_scroll ; If so then we need to scroll the sreen
inc al ; If not then we can go ahead an increment the y value
jmp os_print_newline_done
os_print_newline_scroll:
call os_scroll_screen
os_print_newline_done:
call os_move_cursor ; Update the cursor
pop rax
ret
; -----------------------------------------------------------------------------
; -----------------------------------------------------------------------------
; os_print_string -- Displays text
; IN: RSI = message location (zero-terminated string)
; OUT: All registers perserved
os_print_string:
push rsi
push rax
cld ; Clear the direction flag.. we want to increment through the string
mov ah, 0x07 ; Store the attribute into AH so STOSW can be used later on
os_print_string_nextchar:
lodsb ; Get char from string and store in AL
cmp al, 0 ; Strings are Zero terminated.
je os_print_string_done ; If char is Zero then it is the end of the string
cmp al, 10 ; Check if there was a newline character in the string
je os_print_string_newline ; If so then we print a new line
cmp al, 13 ; Check if there was a newline character in the string
je os_print_string_newline ; If so then we print a new line
mov rdi, [screen_cursor_offset]
stosw ; Write the character and attribute with one call
call os_inc_cursor
jmp os_print_string_nextchar
os_print_string_newline:
call os_print_newline
jmp os_print_string_nextchar
os_print_string_done:
pop rax
pop rsi
ret
; -----------------------------------------------------------------------------
; -----------------------------------------------------------------------------
; os_print_string_with_color -- Displays text with color
; IN: RSI = message location (zero-terminated string)
; BL = color
; OUT: All registers perserved
os_print_string_with_color:
push rsi
push rax
cld ; Clear the direction flag.. we want to increment through the string
mov ah, bl ; Copy the attribute into AH so STOSW can be used later on
os_print_string_with_color_nextchar:
lodsb ; Get char from string and store in AL
cmp al, 0 ; Strings are Zero terminated.
je os_print_string_with_color_done ; If char is Zero then it is the end of the string
cmp al, 13 ; Check if there was a newline character in the string
je os_print_string_with_color_newline ; If so then we print a new line
mov rdi, [screen_cursor_offset]
stosw ; Write the character and attribute with one call
call os_inc_cursor
jmp os_print_string_with_color_nextchar
os_print_string_with_color_newline:
call os_print_newline
jmp os_print_string_with_color_nextchar
os_print_string_with_color_done:
pop rax
pop rsi
ret
; -----------------------------------------------------------------------------
; -----------------------------------------------------------------------------
; os_print_char -- Displays a char
; IN: AL = char to display
; OUT: All registers perserved
os_print_char:
push rdi
mov rdi, [screen_cursor_offset]
stosb ; Store the character to video memory
push ax
mov al, 0x07 ; Default of light grey on black
stosb ; Store the color attribute to video memory
pop ax
call os_inc_cursor
pop rdi
ret
; -----------------------------------------------------------------------------
; -----------------------------------------------------------------------------
; os_print_char_with_color -- Displays a char with color
; IN: AL = char to display
; BL = color
; OUT: All registers perserved
os_print_char_with_color:
push rdi
mov rdi, [screen_cursor_offset]
stosb ; Store the character to video memory
xchg al, bl ; Swap AL and BL as stosb uses AL
stosb ; Store the color attribute to video memory
xchg al, bl ; Swap AL and BL back again
call os_inc_cursor
pop rdi
ret
; -----------------------------------------------------------------------------
; -----------------------------------------------------------------------------
; os_print_char_hex -- Displays a char in hex mode
; IN: AL = char to display
; OUT: All registers perserved
os_print_char_hex:
push rbx
push rax
mov rbx, hextable
push rax ; save rax for the next part
shr al, 4 ; we want to work on the high part so shift right by 4 bits
xlatb
call os_print_char
pop rax
and al, 0x0f ; we want to work on the low part so clear the high part
xlatb
call os_print_char
pop rax
pop rbx
ret
; -----------------------------------------------------------------------------
; -----------------------------------------------------------------------------
; os_scroll_screen -- Scrolls the screen up by one line
; IN: Nothing
; OUT: All registers perserved
os_scroll_screen:
push rsi
push rdi
push rcx
push rax
cld ; Clear the direction flag as we want to increment through memory
cmp byte [os_show_sysstatus], 0
je os_scroll_screen_no_sysstatus
mov rsi, 0x00000000000B8140 ; Start of video text memory for row 3
mov rdi, 0x00000000000B80A0 ; Start of video text memory for row 2
mov rcx, 1840 ; 80 x 23
rep movsw ; Copy the Character and Attribute
jmp os_scroll_screen_lastline
os_scroll_screen_no_sysstatus:
mov rsi, 0x00000000000B80A0 ; Start of video text memory for row 2
mov rdi, 0x00000000000B8000 ; Start of video text memory for row 1
mov rcx, 1920 ; 80 x 24
rep movsw ; Copy the Character and Attribute
os_scroll_screen_lastline: ; Clear the last line in video memory
mov ax, 0x0720 ; 0x07 for black background/white foreground, 0x20 for space (black) character
mov rdi, 0x00000000000B8F00
mov rcx, 80
rep stosw ; Store word in AX to RDI, RCX times
pop rax
pop rcx
pop rdi
pop rsi
ret
; -----------------------------------------------------------------------------
; -----------------------------------------------------------------------------
; os_clear_screen -- Clear the screen
; IN: Nothing
; OUT: All registers perserved
os_clear_screen:
push rdi
push rcx
push rax
mov ax, 0x0720 ; 0x07 for black background/white foreground, 0x20 for space (black) character
mov rdi, 0x00000000000B8000 ; Address for start of color video memory
mov rcx, 2000
rep stosw ; Clear the screen. Store word in AX to RDI, RCX times
pop rax
pop rcx
pop rdi
ret
; -----------------------------------------------------------------------------
; -----------------------------------------------------------------------------
; os_hide_cursor -- Turns off cursor in text mode
; IN: Nothing
; OUT: All registers perserved
os_hide_cursor:
push rdx
push rbx
push rax
mov dx, 0x03d4
mov ax, 0x000a ; Cursor Start Register
out dx, ax
inc dx
xor ax, ax
in al, dx
mov bl, al
or bl, 00100000b ; Bit 5 set to 1 to disable cursor
dec dx
mov ax, 0x000a ; Cursor Start Register
out dx, ax
inc dx
mov al, bl
out dx, al
pop rax
pop rbx
pop rdx
ret
; -----------------------------------------------------------------------------
; -----------------------------------------------------------------------------
; os_show_cursor -- Turns on cursor in text mode
; IN: Nothing
; OUT: All registers perserved
os_show_cursor:
push rdx
push rbx
push rax
mov dx, 0x03d4
mov ax, 0x000a ; Cursor Start Register
out dx, ax
inc dx
xor ax, ax
in al, dx
mov bl, al
and bl, 11011111b ; Bit 5 set to 0 to enable cursor
dec dx
mov ax, 0x000a ; Cursor Start Register
out dx, ax
inc dx
mov al, bl
out dx, al
pop rax
pop rbx
pop rdx
ret
; -----------------------------------------------------------------------------
; =============================================================================
; EOF
|
/* ---------------------------------------------------------------------------------
Implementation file of POPUP_DISPLAY class
Copyright (c) 2011-2013 AnS
(The MIT License)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
------------------------------------------------------------------------------------
Popup display - Manager of popup windows
[Single instance]
* implements all operations with popup windows: initialization, redrawing, centering, screenshot decompression and conversion
* regularly inspects changes of Bookmarks Manager and shows/updates/hides popup windows
* on demand: updates contents of popup windows
* stores resources: coordinates and appearance of popup windows, timings of fade in/out
------------------------------------------------------------------------------------ */
#include "taseditor_project.h"
#include "zlib.h"
extern TASEDITOR_CONFIG taseditorConfig;
extern TASEDITOR_WINDOW taseditorWindow;
extern BOOKMARKS bookmarks;
extern BRANCHES branches;
extern PIANO_ROLL pianoRoll;
extern MARKERS_MANAGER markersManager;
extern PLAYBACK playback;
LRESULT CALLBACK screenshotBitmapWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
LRESULT APIENTRY noteDescriptionWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
// resources
char szClassName[] = "ScreenshotBitmap";
char szClassName2[] = "NoteDescription";
POPUP_DISPLAY::POPUP_DISPLAY()
{
hwndScreenshotBitmap = 0;
hwndNoteDescription = 0;
// create BITMAPINFO
screenshotBmi = (LPBITMAPINFO)malloc(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD)); // 256 color in palette
screenshotBmi->bmiHeader.biSize = sizeof(screenshotBmi->bmiHeader);
screenshotBmi->bmiHeader.biWidth = SCREENSHOT_WIDTH;
screenshotBmi->bmiHeader.biHeight = -SCREENSHOT_HEIGHT; // negative value = top-down bmp
screenshotBmi->bmiHeader.biPlanes = 1;
screenshotBmi->bmiHeader.biBitCount = 8;
screenshotBmi->bmiHeader.biCompression = BI_RGB;
screenshotBmi->bmiHeader.biSizeImage = 0;
// register SCREENSHOT_DISPLAY window class
winCl1.hInstance = fceu_hInstance;
winCl1.lpszClassName = szClassName;
winCl1.lpfnWndProc = screenshotBitmapWndProc;
winCl1.style = CS_DBLCLKS;
winCl1.cbSize = sizeof(WNDCLASSEX);
winCl1.hIcon = 0;
winCl1.hIconSm = 0;
winCl1.hCursor = 0;
winCl1.lpszMenuName = 0;
winCl1.cbClsExtra = 0;
winCl1.cbWndExtra = 0;
winCl1.hbrBackground = 0;
if (!RegisterClassEx(&winCl1))
FCEU_printf("Error registering SCREENSHOT_DISPLAY window class\n");
// register NOTE_DESCRIPTION window class
winCl2.hInstance = fceu_hInstance;
winCl2.lpszClassName = szClassName2;
winCl2.lpfnWndProc = noteDescriptionWndProc;
winCl2.style = CS_DBLCLKS;
winCl2.cbSize = sizeof(WNDCLASSEX);
winCl2.hIcon = 0;
winCl2.hIconSm = 0;
winCl2.hCursor = 0;
winCl2.lpszMenuName = 0;
winCl2.cbClsExtra = 0;
winCl2.cbWndExtra = 0;
winCl2.hbrBackground = 0;
if (!RegisterClassEx(&winCl2))
FCEU_printf("Error registering NOTE_DESCRIPTION window class\n");
// create blendfunction
blend.BlendOp = AC_SRC_OVER;
blend.BlendFlags = 0;
blend.AlphaFormat = 0;
blend.SourceConstantAlpha = 255;
}
void POPUP_DISPLAY::init()
{
free();
// fill scr_bmp palette with current palette colors
extern PALETTEENTRY *color_palette;
for (int i = 0; i < 256; ++i)
{
screenshotBmi->bmiColors[i].rgbRed = color_palette[i].peRed;
screenshotBmi->bmiColors[i].rgbGreen = color_palette[i].peGreen;
screenshotBmi->bmiColors[i].rgbBlue = color_palette[i].peBlue;
}
HDC win_hdc = GetWindowDC(pianoRoll.hwndList);
screenshotHBitmap = CreateDIBSection(win_hdc, screenshotBmi, DIB_RGB_COLORS, (void**)&screenshotRasterPointer, 0, 0);
// calculate coordinates of popup windows (relative to TAS Editor window)
updateBecauseParentWindowMoved();
}
void POPUP_DISPLAY::free()
{
reset();
if (screenshotHBitmap)
{
DeleteObject(screenshotHBitmap);
screenshotHBitmap = 0;
}
}
void POPUP_DISPLAY::reset()
{
currentlyDisplayedBookmark = ITEM_UNDER_MOUSE_NONE;
nextUpdateTime = screenshotBitmapPhase = 0;
if (hwndScreenshotBitmap)
{
DestroyWindow(hwndScreenshotBitmap);
hwndScreenshotBitmap = 0;
}
if (hwndNoteDescription)
{
DestroyWindow(hwndNoteDescription);
hwndNoteDescription = 0;
}
}
void POPUP_DISPLAY::update()
{
// once per 40 milliseconds update popup windows alpha
if (clock() > nextUpdateTime)
{
nextUpdateTime = clock() + DISPLAY_UPDATE_TICK;
if (branches.isSafeToShowBranchesData() && bookmarks.itemUnderMouse >= 0 && bookmarks.itemUnderMouse < TOTAL_BOOKMARKS && bookmarks.bookmarksArray[bookmarks.itemUnderMouse].notEmpty)
{
if (taseditorConfig.displayBranchScreenshots && !hwndScreenshotBitmap)
{
// create window
hwndScreenshotBitmap = CreateWindowEx(WS_EX_LAYERED | WS_EX_TRANSPARENT, szClassName, szClassName, WS_POPUP, taseditorConfig.windowX + screenshotBitmapX, taseditorConfig.windowY + screenshotBitmapY, SCREENSHOT_WIDTH, SCREENSHOT_HEIGHT, taseditorWindow.hwndTASEditor, NULL, fceu_hInstance, NULL);
redrawScreenshotBitmap();
ShowWindow(hwndScreenshotBitmap, SW_SHOWNA);
}
if (taseditorConfig.displayBranchDescriptions && !hwndNoteDescription)
{
RECT wrect;
GetWindowRect(playback.hwndPlaybackMarkerEditField, &wrect);
descriptionX = screenshotBitmapX + (SCREENSHOT_WIDTH - (wrect.right - wrect.left)) / 2;
hwndNoteDescription = CreateWindowEx(WS_EX_LAYERED | WS_EX_TRANSPARENT, szClassName2, szClassName2, WS_POPUP, taseditorConfig.windowX + descriptionX, taseditorConfig.windowY + descriptionY, wrect.right - wrect.left, wrect.bottom - wrect.top, taseditorWindow.hwndTASEditor, NULL, fceu_hInstance, NULL);
changeDescriptionText();
ShowWindow(hwndNoteDescription, SW_SHOWNA);
}
// change screenshot_bitmap pic and description text if needed
if (currentlyDisplayedBookmark != bookmarks.itemUnderMouse)
{
if (taseditorConfig.displayBranchScreenshots)
changeScreenshotBitmap();
if (taseditorConfig.displayBranchDescriptions)
changeDescriptionText();
currentlyDisplayedBookmark = bookmarks.itemUnderMouse;
}
if (screenshotBitmapPhase < SCREENSHOT_BITMAP_PHASE_MAX)
{
screenshotBitmapPhase++;
// update alpha
int phase_alpha = screenshotBitmapPhase;
if (phase_alpha > SCREENSHOT_BITMAP_PHASE_ALPHA_MAX) phase_alpha = SCREENSHOT_BITMAP_PHASE_ALPHA_MAX;
if (hwndScreenshotBitmap)
{
SetLayeredWindowAttributes(hwndScreenshotBitmap, 0, (255 * phase_alpha) / SCREENSHOT_BITMAP_PHASE_ALPHA_MAX, LWA_ALPHA);
UpdateLayeredWindow(hwndScreenshotBitmap, 0, 0, 0, 0, 0, 0, &blend, ULW_ALPHA);
}
if (hwndNoteDescription)
{
SetLayeredWindowAttributes(hwndNoteDescription, 0, (255 * phase_alpha) / SCREENSHOT_BITMAP_PHASE_ALPHA_MAX, LWA_ALPHA);
UpdateLayeredWindow(hwndNoteDescription, 0, 0, 0, 0, 0, 0, &blend, ULW_ALPHA);
}
}
} else
{
// fade and finally hide screenshot
if (screenshotBitmapPhase > 0)
screenshotBitmapPhase--;
if (screenshotBitmapPhase > 0)
{
// update alpha
int phase_alpha = screenshotBitmapPhase;
if (phase_alpha > SCREENSHOT_BITMAP_PHASE_ALPHA_MAX)
phase_alpha = SCREENSHOT_BITMAP_PHASE_ALPHA_MAX;
else if (phase_alpha < 0)
phase_alpha = 0;
if (hwndScreenshotBitmap)
{
SetLayeredWindowAttributes(hwndScreenshotBitmap, 0, (255 * phase_alpha) / SCREENSHOT_BITMAP_PHASE_ALPHA_MAX, LWA_ALPHA);
UpdateLayeredWindow(hwndScreenshotBitmap, 0, 0, 0, 0, 0, 0, &blend, ULW_ALPHA);
}
if (hwndNoteDescription)
{
SetLayeredWindowAttributes(hwndNoteDescription, 0, (255 * phase_alpha) / SCREENSHOT_BITMAP_PHASE_ALPHA_MAX, LWA_ALPHA);
UpdateLayeredWindow(hwndNoteDescription, 0, 0, 0, 0, 0, 0, &blend, ULW_ALPHA);
}
} else
{
// destroy popup windows
screenshotBitmapPhase = 0;
if (hwndScreenshotBitmap)
{
DestroyWindow(hwndScreenshotBitmap);
hwndScreenshotBitmap = 0;
}
if (hwndNoteDescription)
{
DestroyWindow(hwndNoteDescription);
hwndNoteDescription = 0;
}
// immediately redraw the window below those
UpdateWindow(taseditorWindow.hwndTASEditor);
}
}
}
}
void POPUP_DISPLAY::changeScreenshotBitmap()
{
// uncompress
uLongf destlen = SCREENSHOT_SIZE;
int e = uncompress(&screenshotRasterPointer[0], &destlen, &bookmarks.bookmarksArray[bookmarks.itemUnderMouse].savedScreenshot[0], bookmarks.bookmarksArray[bookmarks.itemUnderMouse].savedScreenshot.size());
if (e != Z_OK && e != Z_BUF_ERROR)
{
// error decompressing
FCEU_printf("Error decompressing screenshot %d\n", bookmarks.itemUnderMouse);
// at least fill bitmap with zeros
memset(&screenshotRasterPointer[0], 0, SCREENSHOT_SIZE);
}
redrawScreenshotBitmap();
}
void POPUP_DISPLAY::redrawScreenshotBitmap()
{
HBITMAP temp_bmp = (HBITMAP)SendMessage(hwndScreenshotPicture, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)screenshotHBitmap);
if (temp_bmp && temp_bmp != screenshotHBitmap)
DeleteObject(temp_bmp);
}
void POPUP_DISPLAY::changeDescriptionText()
{
// retrieve info from the pointed bookmark's Markers
int frame = bookmarks.bookmarksArray[bookmarks.itemUnderMouse].snapshot.keyFrame;
int markerID = markersManager.getMarkerAboveFrame(bookmarks.bookmarksArray[bookmarks.itemUnderMouse].snapshot.markers, frame);
char new_text[MAX_NOTE_LEN];
strcpy(new_text, markersManager.getNoteCopy(bookmarks.bookmarksArray[bookmarks.itemUnderMouse].snapshot.markers, markerID).c_str());
SetWindowText(hwndNoteText, new_text);
}
void POPUP_DISPLAY::updateBecauseParentWindowMoved()
{
// calculate new positions relative to IDC_BOOKMARKS_BOX
RECT temp_rect, parent_rect;
GetWindowRect(taseditorWindow.hwndTASEditor, &parent_rect);
GetWindowRect(GetDlgItem(taseditorWindow.hwndTASEditor, IDC_BOOKMARKS_BOX), &temp_rect);
screenshotBitmapX = temp_rect.left - SCREENSHOT_WIDTH - SCREENSHOT_BITMAP_DX - parent_rect.left;
screenshotBitmapY = (temp_rect.bottom - SCREENSHOT_HEIGHT) - parent_rect.top;
RECT wrect;
GetWindowRect(playback.hwndPlaybackMarkerEditField, &wrect);
descriptionX = screenshotBitmapX + (SCREENSHOT_WIDTH - (wrect.right - wrect.left)) / 2;
descriptionY = screenshotBitmapY + SCREENSHOT_HEIGHT + SCREENSHOT_BITMAP_DESCRIPTION_GAP;
// if popup windows are currently shown, update their positions
if (hwndScreenshotBitmap)
SetWindowPos(hwndScreenshotBitmap, 0, taseditorConfig.windowX + screenshotBitmapX, taseditorConfig.windowY + screenshotBitmapY, 0, 0, SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE);
if (hwndNoteDescription)
SetWindowPos(hwndNoteDescription, 0, taseditorConfig.windowX + descriptionX, taseditorConfig.windowY + descriptionY, 0, 0, SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE);
}
// ----------------------------------------------------------------------------------------
LRESULT APIENTRY screenshotBitmapWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
extern POPUP_DISPLAY popupDisplay;
switch(message)
{
case WM_CREATE:
{
// create static bitmap placeholder
popupDisplay.hwndScreenshotPicture = CreateWindow(WC_STATIC, NULL, SS_BITMAP | WS_CHILD | WS_VISIBLE, 0, 0, 255, 255, hwnd, NULL, NULL, NULL);
return 0;
}
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
}
LRESULT APIENTRY noteDescriptionWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
extern POPUP_DISPLAY popupDisplay;
switch(message)
{
case WM_CREATE:
{
// create static text field
RECT wrect;
GetWindowRect(playback.hwndPlaybackMarkerEditField, &wrect);
popupDisplay.hwndNoteText = CreateWindow(WC_STATIC, NULL, WS_CHILD | WS_VISIBLE | SS_CENTER | SS_ENDELLIPSIS | SS_SUNKEN, 1, 1, wrect.right - wrect.left - 2, wrect.bottom - wrect.top - 2, hwnd, NULL, NULL, NULL);
SendMessage(popupDisplay.hwndNoteText, WM_SETFONT, (WPARAM)pianoRoll.hMarkersEditFont, 0);
return 0;
}
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
}
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Emit a beep of a certain frequency
; AX - Freq
os_speaker_tone:
pusha
mov cx, ax
mov al, 182
out 43h, al
mov ax, cx
out 42h, al
mov al, ah
out 42h, al
in al, 61h
or al, 03h
out 61h, al
popa
ret
; Turns off PC speaker
os_speaker_off:
pusha
in al, 61h
and al, 0FCh
out 61h, al
popa
ret |
.data
message: .asciiz "Fim da Execução"
space: .asciiz ", "
.text
main:
addi $t0,$zero,0
loop:
bgt $t0,9,exit
addi $t0,$t0,1
li $v0, 5 # chama função para ler
syscall
la $t7, ($v0) # carrega o inteiro lido em $t7
add $t1,$t1,$t7
j loop
exit:
div $t2,$t1,$t0
jal media
li $v0, 4
la $a0, message
syscall
#fim da execução
li $v0, 10
syscall
media:
li $v0, 1
add $a0,$t2,$zero
syscall
li $v0, 4
la $a0,space
syscall
jr $ra |
comment $
\`. |\
\`-. \ `.| \!,,
\ \ `.\ _ (__
_ `-.> \ ___ \ __ ------------------------------------------
`-/,o-./O `. ._` Badf00d Polymorphic Engine
-// j_ | `` _<` ------------------------------------------
|\__( \--' ' \ . by Piotr Bania <bania.piotr@gmail.com>
> _ `--' _/ ; http://pb.specialised.info
| / `----.. . / (
| ( `. Y )
\ \ ,-.-.| |_ (_
`.`.___\ \ \/=.`. __) a little bit of this,
`--,==\ )==\,\ (_ a little bit of that
,'\===`--'====\,\ `-.
,'.` ============\,\ (`-'
/`=.`Y=============\,\ .'
/`-. `|==============\_,-._
/`-._`=|=___=========,'^, c-)
\`-----+' ._)=====_(_`-' ^-'`-.
-----`=====, \ `.-==(^_ ^c_,.^ `^_\-----
(__/`--'('(_,-._)-._,-.,__)`) hjw
`-._`._______.'_.-'
`---------'
Disclaimer__________________________________________________________________________________]
Author takes no responsibility for any actions with provided informations or codes.
The copyright for any material created by the author is reserved. Any duplication of
codes or texts provided here in electronic or printed publications is not permitted
without the author's agreement. If you disagree - leave now!
Introduction________________________________________________________________________________]
I must confess i was pretty bored and that's why i have written this engine. Meanwhile
i was also thinking about some PE encrypter, so sooner or later i got to produce some
poly engine for it. This little thingie was written in 2 days (few hours each day).
Current version is super beta, drop me an mail if you will find any errors.
Features____________________________________________________________________________________]
+ SEH frames generator (int3/sti/cli exceptions, BPM removers (dr0-3 cleaners), random
registry usage, random size of garbage block (return address is calculated via size
of the generated junks), generated SEH block looks like this:
* SNIP *
00402814 E8 3D000000 CALL pol.00402856
00402819 8BD4 MOV EDX,ESP ; generated REG
0040281B 81C2 0C000000 ADD EDX,0C
00402821 8B12 MOV EDX,DWORD PTR DS:[EDX]
00402823 C782 04000000 00>MOV DWORD PTR DS:[EDX+4],0
0040282D C782 08000000 00>MOV DWORD PTR DS:[EDX+8],0
00402837 C782 12000000 00>MOV DWORD PTR DS:[EDX+12],0
00402841 C782 16000000 00>MOV DWORD PTR DS:[EDX+16],0
0040284B 8182 B8000000 05>ADD DWORD PTR DS:[EDX+B8],5 ; calcs return addr
00402855 C3 RETN
00402856 33C9 XOR ECX,ECX
00402858 64:FF31 PUSH DWORD PTR FS:[ECX]
0040285B 64:8921 MOV DWORD PTR FS:[ECX],ESP
0040285E CC INT3
0040285F AF SCAS DWORD PTR ES:[EDI]
00402860 C8 50C933 ENTER 0C950,33
00402864 C0648F 00 5A SHL BYTE PTR DS:[EDI+ECX*4],5A
* SNIP *
As you can see doing only regswaping is not a good solution (still signature can be
generated - look RegSwap virus description), prolly it is better to mix randomly SEH
instructions with garbage. Use your imagination.
+ safe garbage generator (generates stepable garbage code, moreover user can specyfi
what registers should be used and what should be not, this feature gives an
advantage to mix original code together with garbage code, without destroying the
values from orginal one), like this snipet shows:
* SNIP - ALL REGS ALLOWED *
00402814 F7D2 NOT EDX
00402816 D1D3 RCL EBX,1
00402818 9B WAIT
00402819 9B WAIT
0040281A D1F9 SAR ECX,1
0040281C 93 XCHG EAX,EBX
0040281D 81C3 B9B1F0A8 ADD EBX,A8F0B1B9
00402823 F9 STC
00402824 81EF 73D13C4E SUB EDI,4E3CD173
0040282A 3BC7 CMP EAX,EDI
0040282C FD STD
0040282D 2BC6 SUB EAX,ESI
0040282F 57 PUSH EDI
00402830 81C9 6FA7215F OR ECX,5F21A76F
00402836 33F3 XOR ESI,EBX
00402838 F7D8 NEG EAX
0040283A 1BCE SBB ECX,ESI
* SNIP - ALL REGS ALLOWED *
* SNIP - ALLOWED EAX/EBX *
00402814 F7DB NEG EBX
00402816 F7D0 NOT EAX
00402818 85C3 TEST EBX,EAX
0040281A F8 CLC
0040281B 90 NOP
0040281C C7C3 BB153882 MOV EBX,823815BB
00402822 F7D8 NEG EAX
00402824 09DB OR EBX,EBX
00402826 D1D3 RCL EBX,1
00402828 D1D8 RCR EAX,1
0040282A EB 00 JMP SHORT pol.0040282C
0040282C 81EB 011DAF21 SUB EBX,21AF1D01
00402832 81E8 3BB25C3B SUB EAX,3B5CB23B
00402838 F8 CLC
* SNIP - ALLOWED EAX/EBX *
+ hardcore garbage generator (generates jmp over_garbage and generates garbage stepable
or totaly randomized - this one will be never executed), like here:
* SNIP - SOME GARBAGE CODE *
00402810 EB 14 JMP SHORT pol.00402826
00402812 CB RETF
00402813 69A0 1C1E85D1 F9>IMUL ESP,DWORD PTR DS:[EAX+D1851E1C],886>
0040281D F2: PREFIX REPNE:
0040281E 4B DEC EBX
0040281F 85FF TEST EDI,EDI
00402821 198A 797CF6EB SBB DWORD PTR DS:[EDX+EBF67C79],ECX
00402827 0C C8 OR AL,0C8
* SNIP - SOME GARBAGE CODE *
+ backwards jumps generator (generates some funny jumps :))
* SNIP *
0040280C EB 3A JMP SHORT pol.00402848
0040280E 33FE XOR EDI,ESI
00402810 EB 3B JMP SHORT pol.0040284D
00402812 AE SCAS BYTE PTR ES:[EDI]
00402813 ^73 C8 JNB SHORT pol.004027DD
00402815 71 13 JNO SHORT pol.0040282A
00402817 90 NOP
00402818 5E POP ESI
00402819 C2 AFE0 RETN 0E0AF
0040281C BB 8406103D MOV EBX,3D100684
00402821 60 PUSHAD
00402822 E5 77 IN EAX,77
00402824 2AC4 SUB AL,AH
00402826 59 POP ECX
00402827 3E:5C POP ESP
00402829 0E PUSH CS
0040282A 67:73 7A JNB SHORT pol.004028A7
0040282D AF SCAS DWORD PTR ES:[EDI]
0040282E 27 DAA
0040282F 0880 3B2E3EF3 OR BYTE PTR DS:[EAX+F33E2E3B],AL
00402835 5D POP EBP
00402836 52 PUSH EDX
00402837 D9FB FSINCOS
00402839 ^E1 BD LOOPDE SHORT pol.004027F8
0040283B 4E DEC ESI
0040283C 53 PUSH EBX
0040283D 4D DEC EBP
0040283E 62D6 BOUND EDX,ESI
00402840 A7 CMPS DWORD PTR DS:[ESI],DWORD PTR ES:[ED>
00402841 FF49 8C DEC DWORD PTR DS:[ECX-74]
00402844 07 POP ES
00402845 56 PUSH ESI
00402846 7A 15 JPE SHORT pol.0040285D
00402848 9B WAIT
00402849 ^EB C5 JMP SHORT pol.00402810
0040284B 6E OUTS DX,BYTE PTR ES:[EDI]
0040284C 45 INC EBP
* SNIP *
TODO________________________________________________________________________________________]
+ code some multiple decryption routines (xlat/xor/etc. etc - backwards/forwards)
+ add some checksum checker routines
+ code new engine :))
Sample_usage________________________________________________________________________________]
* SNIP *
call random_setup ; set seed
mov ecx,30 ; loop counter
lea edi,temp_buff ; EDI = where to store
gen_it:
mov eax,3
call random_eax ; give random
cmp eax,0
je skip_jmp
cmp eax,1
je skip_sehs
call t_normalize_pops ; normalize stack before SEHs
add edi,eax
call gen_seh ; generate SEHs
add edi,eax ; add edi,generated_code_size
skip_sehs:
call gen_bjumps ; generate backwards jumps
add edi,eax ; add edi,generated_code_size
skip_jmp:
mov eax,2
call random_eax ; give random
test eax,eax
jnz gen_it2
call gen_garbage_i ; generate some stepable junk
jmp loopers
gen_it2:
call hardcode_garbage_i ; generate some hard junks
loopers:
add edi,eax ; add edi,generated_code_size
loop gen_it
call t_normalize_pops ; normalize stack if it wasn't
add edi,eax ; normalized
* SNIP *
Have phun,
Piotr Bania
$
M0_EAX equ 0
M0_ECX equ 1
M0_EDX equ 2
M0_EBX equ 3
M0_ESI equ 4
M0_EDI equ 5
M1_EAX equ 0
M1_ECX equ 1
M1_EDX equ 2
M1_EBX equ 3
M1_ESI equ 6
M1_EDI equ 7
M2_EAX equ 0 shl 3
M2_ECX equ 1 shl 3
M2_EDX equ 2 shl 3
M2_EBX equ 3 shl 3
M2_ESI equ 6 shl 3
M2_EDI equ 7 shl 3
; -------------- MAIN REGISTERS TABLES ----------------------------------------
x1_table: db M1_EAX
db M1_ECX
db M1_EDX
db M1_EBX
db M1_ESI
db M1_EDI
x1_tbl_size = $ - offset x1_table
x2_table: db M2_EAX
db M2_ECX
db M2_EDX
db M2_EBX
db M2_ESI
db M2_EDI
x2_tbl_size = $ - offset x2_table
; -------------- INSTRUCTION TABLES -------------------------------------------
; FORMAT: (1 BYTE) (BYTE) (BYTE) (BYTE)
; <OPCODE> <MODRM> <LEN> <CSET>
;
; if there is no MODRM, MODRM must be set to 2Dh (temp)
NO_M equ 02dh
C_NONE equ 0
C_SRC equ 1
C_DST equ 2
C_BOTH equ 3
allowed_regs: db M0_EAX, M0_ECX, M0_EDX, M0_EBX, M0_ESI, M0_EDI
instr_table: db 0f9h, NO_M, 1h, C_NONE ; stc
db 0EBh, NO_M, 2h, C_NONE ; jmp $+1
db 0c7h, 0c0h, 6h, C_SRC ; mov reg(EAX),NUM
db 08bh, 0c0h, 2h, C_BOTH ; mov reg(EAX),reg(EAX)
db 081h, 0c0h, 6h, C_SRC ; add reg(EAX),NUM
db 003h, 0c0h, 2h, C_BOTH ; add reg(EAX),reg(EAX)
db 081h, 0e8h, 6h, C_SRC ; sub reg(EAX),NUM
db 02bh, 0c0h, 2h, C_BOTH ; sub reg(EAX),reg(EAX)
db 040h, NO_M, 1h, C_SRC ; inc reg(EAX)
db 048h, NO_M, 1h, C_SRC ; dec reg(EAX)
_i_xor_r db 033h, 0c0h, 2h, C_BOTH ; xor reg(EAX),reg(EAX)
db 009h, 0c0h, 2h, C_BOTH ; or reg(EAX),reg(EAX)
db 081h, 0c8h, 6h, C_SRC ; or reg(EAX),NUM
db 03bh, 0c0h, 2h, C_BOTH
db 085h, 0c0h, 2h, C_BOTH
db 01bh, 0c0h, 2h, C_BOTH ; sbb reg(EAX),reg(EAX)
db 011h, 0c0h, 2h, C_BOTH ; adc reg(EAX),reg(EAX)
db 0f7h, 0d0h, 2h, C_SRC ; not reg(EAX)
db 0f7h, 0d8h, 2h, C_SRC ; neg reg(EAX)
db 0d1h, 0f8h, 2h, C_SRC ; sar reg(EAX),1
db 0d1h, 0d8h, 2h, C_SRC ; rcr reg(EAX),1
db 0d1h, 0d0h, 2h, C_SRC ; rcl reg(EAX),1
db 091h, NO_M, 1h, C_SRC ; xchg reg(EAX),reg(ECX)
db 090h, NO_M, 1h, C_NONE ; nop
db 0fch, NO_M, 1h, C_NONE ; cld
db 0f8h, NO_M, 1h, C_NONE ; clc
db 0fdh, NO_M, 1h, C_NONE ; std
db 09bh, NO_M, 1h, C_NONE ; wait
db 050h, NO_M, 1h, C_SRC ; push reg(eax)
_i_pop db 058h, NO_M, 1h, C_SRC ; pop reg(eax) (must be last one)
ENTRY_TABLE_SIZE = 4
instr_table_size = (($-offset instr_table)/4)
dd 0
push_number dd 0
do_push db 1 ; should we process pushs?
O_JMP equ 0EBh
O_PUSH equ 050h
O_POP equ 058h
i_jmp: db 0EBh, NO_M, 2h ; jmp $+1
; -------------- GARBAGE GENERATOR (SAFE) ------------------------------------
; EDI = where
; ----------------------------------------------------------------------------
gen_garbage_i:
pushad
garbage_again:
mov eax,instr_table_size
call random_eax
lea esi,instr_table
mov ecx,ENTRY_TABLE_SIZE
mul ecx ; eax=member from table to use
add esi,eax
jmp garbage_co
garbage_hand: pushad
garbage_co: lodsw ; ah = modrm value / al=opcode
cmp ah,NO_M
je no_modrm
stosb ; store opcode
xor edx,edx
mov dl,ah
cmp byte ptr [esi+1],C_BOTH ; what registers to mutate
je p_01
cmp byte ptr [esi+1],C_SRC
jne t_01
p_01: and dl,0F8h
mov eax,x1_tbl_size
call random_eax
mov al,byte ptr [allowed_regs[eax]]
mov al,byte ptr [x1_table[eax]]
or dl,al
mov byte ptr [edi],dl
t_01: cmp byte ptr [esi+1],C_BOTH ; what registers to mutate
je p_02
cmp byte ptr [esi+1],C_DST
jne finish_i
p_02: and dl,0C7h
mov eax,x2_tbl_size
call random_eax
mov al,byte ptr [allowed_regs[eax]]
mov al,byte ptr [x2_table[eax]]
or dl,al ; update modrm value
mov byte ptr [edi],dl
finish_i: mov cl,byte ptr [esi]
sub cl,2
inc edi
cmp cl,0
jle garbage_done
store_op: mov eax,12345678h
call random_eax
stosb
loop store_op
garbage_done: xor eax,eax
mov al,byte ptr [esi]
mov [esp+PUSHA_STRUCT._EAX],eax
popad
ret
; ----------------------------------------------------
; NO MOD-RMs
; ----------------------------------------------------
no_modrm: xor edx,edx
mov dl,al
cmp byte ptr [esi+1],C_NONE
je t_none
cmp dl,O_PUSH
je t_push
cmp dl,O_POP
je t_pop
go_nomodrm: mov eax,x1_tbl_size
call random_eax
mov al,byte ptr [allowed_regs[eax]]
mov al,byte ptr [x1_table[eax]]
and dl,0F8h
or dl,al
mov byte ptr [edi],dl
inc edi
jmp finish_i
t_none: mov byte ptr [edi],dl
inc edi
cmp dl,O_JMP
jne finish_i
mov byte ptr [edi],0
inc edi
jmp finish_i
t_push: cmp byte ptr [do_push],1
jne garbage_again
inc dword ptr [push_number]
jmp go_nomodrm
t_pop: cmp byte ptr [do_push],1
jne garbage_again
cmp dword ptr [push_number],0
jle garbage_again
dec dword ptr [push_number]
jmp go_nomodrm
t_normalize_pops:
pushad
xor ebx,ebx
mov ecx,dword ptr [push_number]
test ecx,ecx
jz t_opsexit
t_givepops: lea esi,_i_pop
call garbage_hand
add edi,eax
add ebx,eax
loop t_givepops
t_opsexit: mov [esp+PUSHA_STRUCT._EAX],ebx
popad
ret
; ---------------------------------------------------------------------------
; HARDCORE GARBAGER
; ---------------------------------------------------------------------------
; EDI = where to store
;
; This one generates code like this:
; jmp over_garbage
; <totaly random generated garbage>
; <normal garbage>
; max: up to 20 "instructions"
; ---------------------------------------------------------------------------
hardcode_garbage_i:
pushad
mov ebx,edi
lea edi,hardcore_temp
mov eax,20
call random_eax
mov ecx,eax
add ecx,4
h_fill: mov eax,2
call random_eax
test eax,eax
jnz h_hard
call gen_garbage_i
jmp h_cont
h_hard: mov eax,5
call random_eax
mov edx,eax
inc edx
xor esi,esi
h_hard_fill: mov eax,0FFFFh
call random_eax
stosb
inc esi
dec edx
jnz h_hard_fill
loop h_fill
jmp h_done
h_cont: add edi,eax
loop h_fill
h_done: lea ecx,hardcore_temp
sub edi,ecx
mov ecx,edi
mov byte ptr [ebx],O_JMP
inc ebx
mov byte ptr [ebx],cl
inc ebx
push ecx
mov edi,ebx
lea esi,hardcore_temp
rep movsb
pop eax
add eax,2
mov [esp+PUSHA_STRUCT._EAX],eax
popad
ret
; -------------------------------------------------------------
; Generates backwards jumps
; -------------------------------------------------------------
; EDI = buffor
gen_bjumps:
pushad
mov ebx,edi
mov byte ptr [jmp_flag],0
mov byte ptr [jmp_flag_b],0
mov dword ptr [count_jmp],0
mov dword ptr [where_where],0
mov dword ptr [jmp_bytes],0
mov byte ptr [do_push],0
mov byte ptr [where_losed],0
mov byte ptr [ebx],O_JMP
mov dword ptr [where_start],ebx
add dword ptr [where_start],2
inc ebx
xor esi,esi
add edi,2
add dword ptr [jmp_bytes],2
gen_gar_i: mov eax,20
call random_eax
mov ecx,eax
add ecx,10
gen_gar_ii: call gen_garbage_i
add dword ptr [jmp_bytes],eax
add esi,eax
add edi,eax
cmp byte ptr [jmp_flag],1
jne gen_gari_ix
add dword ptr [count_jmp],eax
jmp gen_gari_ixx
gen_gari_ix: push eax
mov eax,2
call random_eax
mov edx,eax
pop eax
cmp byte ptr [where_losed],1
je gen_gari_ixx
add dword ptr [where_start],eax
cmp edx,1
je gen_gari_ixx
mov byte ptr [where_losed],1
gen_gari_ixx: mov eax,3
call random_eax
cmp eax,2
jne cont_gari
cmp byte ptr [jmp_flag],1
je cont_gari
mov byte ptr [jmp_flag],1
mov byte ptr [edi],O_JMP
inc edi
mov dword ptr [where_jmp],edi
inc edi
add esi,2
cont_gari: loop gen_gar_ii
mov eax,esi
mov byte ptr [ebx],al
cmp byte ptr [jmp_flag],1
je cont_gari2
mov byte ptr [edi],O_JMP
inc edi
mov dword ptr [where_jmp],edi
inc edi
cont_gari2: mov dword ptr [where_where],edi
add dword ptr [jmp_bytes],2
mov eax,5
call random_eax
inc eax
mov ecx,eax
cont_gari3: call gen_garbage_i
add dword ptr [jmp_bytes],eax
add edi,eax
add dword ptr [count_jmp],eax
loop cont_gari3
mov byte ptr [edi],O_JMP
mov eax,edi
sub eax,dword ptr [where_start]
add eax,2
neg eax
pushad
add edi,2
mov eax,4
call random_eax
mov ecx,eax
test ecx,ecx
jz cont_gari4
place_gar: mov eax,0FFh
call random_eax
inc dword ptr [count_jmp]
inc dword ptr [jmp_bytes]
stosb
loop place_gar
cont_gari4: add dword ptr [count_jmp],2
mov eax,dword ptr [count_jmp]
mov edx,dword ptr [where_jmp]
mov byte ptr [edx],al
popad
mov byte ptr [edi+1],al
add dword ptr [jmp_bytes],2
mov edx,dword ptr [where_where]
sub edx,dword ptr [where_jmp]
dec edx
mov ecx,edx
mov edx,dword ptr [where_jmp]
inc edx
cmp ecx,0
jle cont_no_xor
cont_xor: mov eax,0FFh
call random_eax
xor byte ptr [edx],al
inc edx
loop cont_xor
cont_no_xor: mov byte ptr [do_push],1
mov edx,dword ptr [jmp_bytes]
mov [esp+PUSHA_STRUCT._EAX],edx
popad
ret
jmp_bytes dd 0
where_losed db 0
where_where dd 0
where_start dd 0
count_jmp dd 0
where_jmp dd 0
jmp_flag db 0
jmp_flag_b db 0
; -------------------------------------------------------------
; Generates SEH frames/exceptions/etc.
; -------------------------------------------------------------
; EDI = buffor
FS_PREFIX equ 064h
seh_push_fs db 0ffh, 030h, 2h, C_SRC
seh_mov_fs db 089h, 020h, 2h, C_SRC
seh_pop_fs db 08fh, 000h, 2h, C_SRC
_mov_reg_esp db 08bh, 0c4h, 2h, C_DST ; mov reg,ESP
_add_reg_num db 081h, 0c0h, 2h, C_SRC ; add reg,NUM (we must typo NUM by hand: 4) LEN=6
_mov_reg_oreg db 08bh, 000h, 2h, C_BOTH ; mov reg,[REG]
_mov_dreg_num db 0c7h, 080h, 2h, C_SRC ; mov [reg+NUM],0 (add NUM by hand) LEN: A
_add_dreg_num db 081h, 080h, 2h, C_SRC
exception_table:
db 0CCh ; int 3
db 0fah ; cli
db 0fbh ; sti
exception_table_size = $-offset exception_table
gen_seh:
pushad
xor edx,edx
mov ebx,edi
mov byte ptr [edi],0E8h
mov dword ptr [edi+1],0
add edx,5
add edi,5
push edi
lea esi,allowed_regs
mov ecx,x1_tbl_size
push esi
push ecx
lea edi,allowed_regs_temp
rep movsb
pop ecx
pop edi
pushad
mov eax,x1_tbl_size
call random_eax
cmp eax,M0_EAX
jne reg_p
inc eax ; somehow :) EAX usage results with invalid disposition error
reg_p: rep stosb
mov edi,[esp+PUSHA_STRUCT_SIZE]
lea esi,_mov_reg_esp
call garbage_hand
add dword ptr [esp+PUSHA_STRUCT._EDX],eax
add [esp+PUSHA_STRUCT_SIZE],eax
add edi,eax
lea esi,_add_reg_num
call garbage_hand
add edi,2
mov dword ptr [edi],0Ch
add dword ptr [esp+PUSHA_STRUCT._EDX],6
add [esp+PUSHA_STRUCT_SIZE],6
add edi,4
lea esi,_mov_reg_oreg
call garbage_hand
add dword ptr [esp+PUSHA_STRUCT._EDX],eax
add [esp+PUSHA_STRUCT_SIZE],eax
add edi,eax
lea esi,_mov_dreg_num
call garbage_hand
add dword ptr [esp+PUSHA_STRUCT._EDX],0ah
add [esp+PUSHA_STRUCT_SIZE],0ah
add edi,2
mov dword ptr [edi],04h
mov dword ptr [edi+4],0h
add edi,0ah-2
lea esi,_mov_dreg_num
call garbage_hand
add dword ptr [esp+PUSHA_STRUCT._EDX],0ah
add [esp+PUSHA_STRUCT_SIZE],0ah
add edi,2
mov dword ptr [edi],08h
mov dword ptr [edi+4],0h
add edi,0ah-2
lea esi,_mov_dreg_num
call garbage_hand
add dword ptr [esp+PUSHA_STRUCT._EDX],0ah
add [esp+PUSHA_STRUCT_SIZE],0ah
add edi,2
mov dword ptr [edi],12h
mov dword ptr [edi+4],0h
add edi,0ah-2
lea esi,_mov_dreg_num
call garbage_hand
add dword ptr [esp+PUSHA_STRUCT._EDX],0ah
add [esp+PUSHA_STRUCT_SIZE],0ah
add edi,2
mov dword ptr [edi],16h
mov dword ptr [edi+4],0h
add edi,0ah-2
lea esi,_add_dreg_num
call garbage_hand
add dword ptr [esp+PUSHA_STRUCT._EDX],0ah+1
add [esp+PUSHA_STRUCT_SIZE],0ah+1
add edi,2
mov dword ptr [edi],0b8h
add edi,4
mov dword ptr [where_over],edi
add edi,0ah-6
mov byte ptr [edi],0C3h ; ret
inc edi
popad
mov byte ptr [ebx+1],dl
sub byte ptr [ebx+1],5
mov eax,x1_tbl_size
call random_eax
rep stosb
pop edi
lea esi,_i_xor_r
call garbage_hand
add edi,eax
add edx,eax
mov byte ptr [edi],FS_PREFIX
inc edi
inc edx
lea esi,seh_push_fs
call garbage_hand
add edi,eax
add edx,eax
mov byte ptr [edi],FS_PREFIX
inc edi
inc edx
lea esi,seh_mov_fs
call garbage_hand
add edi,eax
add edx,eax
call reset_regs
xor ebx,ebx
mov eax,exception_table_size
call random_eax
mov cl,byte ptr exception_table[eax]
mov byte ptr [edi],cl
inc edx
inc edi
inc ebx
call fill_trash
add edx,eax
add ebx,eax
add edi,eax
push edi
mov edi,dword ptr [where_over]
mov dword ptr [edi],ebx
pop edi
call finalize_seh
add edx,eax
mov [esp+PUSHA_STRUCT._EAX],edx
popad
ret
where_over dd 0
allowed_regs_temp db x1_tbl_size dup (0)
finalize_seh:
pushad
call gen_regs
xor edx,edx
lea esi,_i_xor_r
call garbage_hand
add edi,eax
add edx,eax
mov byte ptr [edi],FS_PREFIX
inc edi
inc edx
lea esi,seh_pop_fs
call garbage_hand
add edi,eax
add edx,eax
call reset_regs
inc dword ptr [push_number]
lea esi,_i_pop
call garbage_hand
add edx,eax
add edi,eax
mov [esp+PUSHA_STRUCT._EAX],edx
popad
ret
fill_trash: pushad
xor ebx,ebx
mov eax,20
call random_eax
mov ecx,eax
test eax,eax
jz done_fill_trash
fill_trash_x: mov eax,0FFh
call random_eax
stosb
inc ebx
loop fill_trash_x
done_fill_trash:
mov [esp+PUSHA_STRUCT._EAX],ebx
popad
ret
reset_regs:
pushad
lea esi,allowed_regs_temp
mov ecx,x1_tbl_size
lea edi,allowed_regs
rep movsb
popad
ret
gen_regs: pushad
mov eax,x1_tbl_size
call random_eax
lea edi,allowed_regs
mov ecx,x1_tbl_size
rep stosb
popad
ret
set_random: pushad
mov eax,6
call random_eax
cmp eax,5
jne not_set
call gen_bjumps
jmp le_set
not_set: xor eax,eax
le_set: mov [esp+PUSHA_STRUCT._EAX],eax
popad
ret
random_setup proc
@callx GetTickCount
mov Random_Seed,eax
ret
random_setup endp
Random_Seed dd 0
random_eax proc
PUSH ECX
PUSH EDX
PUSH EAX
db 0Fh, 31h ; RDTSC
MOV ECX, Random_Seed
ADD EAX, ECX
ROL ECX, 1
ADD ECX, 666h
MOV Random_Seed, ECX
PUSH 32
POP ECX
CRC_Bit: SHR EAX, 1
JNC Loop_CRC_Bit
XOR EAX, 0EDB88320h
Loop_CRC_Bit: LOOP CRC_Bit
POP ECX
XOR EDX, EDX
DIV ECX
XCHG EDX, EAX
OR EAX, EAX
POP EDX
POP ECX
RETN
random_eax endp
|
; A016918: a(n) = (6*n)^10.
; 0,60466176,61917364224,3570467226624,63403380965376,590490000000000,3656158440062976,17080198121677824,64925062108545024,210832519264920576,604661760000000000,1568336880910795776,3743906242624487424,8335775831236199424,17490122876598091776,34867844010000000000,66483263599150104576,121899441999475713024,215892499727278669824,370722131411856638976,619173642240000000000,1008568618886953829376,1605976966052654874624,2504902718110474036224,3833759992447475122176,5766503906250000000000,8535834451185868210176,12449449430074295092224,17909885825636445978624,25438557613203014501376,35704672266240000000000,49559788255159621886976,68078861925529707085824,92608724480901579777024,124825028607463130136576,166798809782010000000000,221073919720733357899776,290756708973467203175424,379619462565741198311424,492219227058666339787776,634033809653760000000000,811616880235713665688576,1032774265740240721281024,1306763693175932538061824,1644520413237918591614976,2058911320946490000000000,2565020383345125413093376,3180468387218973248922624,3925770232266214525108224,4824733217390275632178176,5904900000000000000000000,7198040150627041378354176,8740694478014329047220224,10574776563315896351130624,12748236216396078174437376,15315789852644490000000000,18339723085451720682110976,21890771137738722674893824,26049082995919886849409024,30905275561625163865752576,36561584400629760000000000,43133118044960312019403776,50749223173283452812263424,59554968376655736670823424,69712754611742420055883776,81404060851916010000000000,94831333868443217691672576,110220031509480408885249024,127820829294042245259853824,147912000601705381364990976,170801981216778240000000000,196832129478228454438757376,226379693794030958489370624,259860999801001344630580224,297734869988830416051634176,340506289160156250000000000,388730329667318987070898176,443016350951160383613748224,504032488508074331942682624,572510448028705485180773376,649250621085450240000000000,735127539396457050900734976,831095685361370793665101824,938195677248838082877441024,1057560848118006498591768576,1190424238276130010000000000,1338126021812154918975307776,1502121388502024803291751424,1683988903155628637813735424,1885439365268042931666379776,2108325192649205760000000000,2354650353536627410108056576,2626580872545408423007617024,2926455936678920512804045824,3256799628512228606896766976,3620333314568912490000000000,4019988717840603673710821376,4458921704347506570616218624,4940526814607642247350452224,5468452571872757384253490176
pow $0,10
mul $0,60466176
|
#include "pch.h"
#include "Engine.h"
#include "ProjectionState.h"
#include "Error.h"
//#if defined(NDEBUG)
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pCmdLine, int nCmdShow)
//#else // defined(NDEBUG)
//int main()
//#endif
{
Engine& engine = Engine::Instance();
try
{
engine.init();
engine.pushState(new ProjectionState);
auto maxFrametime = chrono::milliseconds(1000) / 80;
auto lastTime = chrono::steady_clock::now();
while (engine.isRunning())
{
auto frametime = chrono::steady_clock::now();
engine.poolEvents();
auto deltatime = chrono::steady_clock::now() - lastTime;
lastTime += deltatime;
float dt = deltatime.count() / 1'000'000'000.f;
engine.update(dt);
engine.draw();
std::this_thread::sleep_for(maxFrametime -
(chrono::steady_clock::now() - frametime));
}
engine.cleanup();
}
catch (const std::runtime_error& ex)
{
Error::error(ex.what());
}
catch (const std::string& ex)
{
Error::error(ex);
}
catch (const char* ex)
{
Error::error(ex);
}
catch (...)
{
Error::error("Unknown Error");
}
return 0;
} |
; float sin(float x) __z88dk_fastcall
SECTION code_clib
SECTION code_fp_math48
PUBLIC cm48_sdcciy_sin_fastcall
EXTERN cm48_sdcciyp_dx2m48, am48_sin, cm48_sdcciyp_m482d
cm48_sdcciy_sin_fastcall:
call cm48_sdcciyp_dx2m48
call am48_sin
jp cm48_sdcciyp_m482d
|
lc r4, 0x0000006d
lc r5, 0x00008000
eq r6, r4, r5
halt
#@expected values
#r4 = 0x0000006d
#r5 = 0x00008000
#r6 = 0x00000000
#pc = -2147483628
#e0 = 0
#e1 = 0
#e2 = 0
#e3 = 0
|
// Copyright 2016, Tobias Hermann.
// https://github.com/Dobiasd/frugally-deep
// Distributed under the MIT License.
// (See accompanying LICENSE file or at
// https://opensource.org/licenses/MIT)
#pragma once
#include "fdeep/base64.hpp"
#if defined(__GNUC__) || defined(__GNUG__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wctor-dtor-privacy"
#endif
#if defined _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4706)
#pragma warning(disable : 4996)
#endif
#include <nlohmann/json.hpp>
#if defined _MSC_VER
#pragma warning(pop)
#endif
#if defined(__GNUC__) || defined(__GNUG__)
#pragma GCC diagnostic pop
#endif
#include "fdeep/common.hpp"
#include "fdeep/layers/add_layer.hpp"
#include "fdeep/layers/average_layer.hpp"
#include "fdeep/layers/average_pooling_2d_layer.hpp"
#include "fdeep/layers/batch_normalization_layer.hpp"
#include "fdeep/layers/bidirectional_layer.hpp"
#include "fdeep/layers/concatenate_layer.hpp"
#include "fdeep/layers/conv_2d_layer.hpp"
#include "fdeep/layers/cropping_2d_layer.hpp"
#include "fdeep/layers/dense_layer.hpp"
#include "fdeep/layers/depthwise_conv_2d_layer.hpp"
#include "fdeep/layers/elu_layer.hpp"
#include "fdeep/layers/flatten_layer.hpp"
#include "fdeep/layers/global_average_pooling_1d_layer.hpp"
#include "fdeep/layers/global_max_pooling_1d_layer.hpp"
#include "fdeep/layers/global_average_pooling_2d_layer.hpp"
#include "fdeep/layers/global_max_pooling_2d_layer.hpp"
#include "fdeep/layers/hard_sigmoid_layer.hpp"
#include "fdeep/layers/input_layer.hpp"
#include "fdeep/layers/layer.hpp"
#include "fdeep/layers/leaky_relu_layer.hpp"
#include "fdeep/layers/embedding_layer.hpp"
#include "fdeep/layers/lstm_layer.hpp"
#include "fdeep/layers/gru_layer.hpp"
#include "fdeep/layers/permute_layer.hpp"
#include "fdeep/layers/prelu_layer.hpp"
#include "fdeep/layers/linear_layer.hpp"
#include "fdeep/layers/max_pooling_2d_layer.hpp"
#include "fdeep/layers/maximum_layer.hpp"
#include "fdeep/layers/model_layer.hpp"
#include "fdeep/layers/multiply_layer.hpp"
#include "fdeep/layers/pooling_2d_layer.hpp"
#include "fdeep/layers/relu_layer.hpp"
#include "fdeep/layers/reshape_layer.hpp"
#include "fdeep/layers/separable_conv_2d_layer.hpp"
#include "fdeep/layers/selu_layer.hpp"
#include "fdeep/layers/sigmoid_layer.hpp"
#include "fdeep/layers/softmax_layer.hpp"
#include "fdeep/layers/softplus_layer.hpp"
#include "fdeep/layers/subtract_layer.hpp"
#include "fdeep/layers/tanh_layer.hpp"
#include "fdeep/layers/time_distributed_layer.hpp"
#include "fdeep/layers/upsampling_1d_layer.hpp"
#include "fdeep/layers/upsampling_2d_layer.hpp"
#include "fdeep/layers/zero_padding_2d_layer.hpp"
#include "fdeep/tensor_shape.hpp"
#include "fdeep/tensor_shape_variable.hpp"
#include "fdeep/tensor.hpp"
#include <fplus/fplus.hpp>
#include <algorithm>
#include <iostream>
#include <limits>
#include <memory>
#include <string>
#include <map>
#include <utility>
#include <vector>
namespace fdeep { namespace internal
{
template<typename KeyT, typename ValueT>
ValueT json_object_get(const nlohmann::json& data, KeyT&& key, ValueT&& default_value)
{
auto&& it = data.find(key);
if (it != data.end())
return *it;
else
return std::forward<ValueT>(default_value);
}
inline bool json_obj_has_member(const nlohmann::json& data,
const std::string& member_name)
{
return data.is_object() && data.find(member_name) != data.end();
}
inline fplus::maybe<std::size_t> create_maybe_size_t(const nlohmann::json& data)
{
if (data.is_null())
{
return fplus::nothing<std::size_t>();
}
const std::size_t result = data;
return fplus::just(result);
}
inline tensor_shape_variable create_tensor_shape_variable(const nlohmann::json& data)
{
assertion(data.is_array(), "tensor_shape_variable needs to be an array");
assertion(data.size() > 0, "need at least one dimension");
if (data.size() == 1)
return tensor_shape_variable(
create_maybe_size_t(data[0]));
if (data.size() == 2)
return tensor_shape_variable(
create_maybe_size_t(data[0]),
create_maybe_size_t(data[1]));
if (data.size() == 3)
return tensor_shape_variable(
create_maybe_size_t(data[0]),
create_maybe_size_t(data[1]),
create_maybe_size_t(data[2]));
if (data.size() == 4)
return tensor_shape_variable(
create_maybe_size_t(data[0]),
create_maybe_size_t(data[1]),
create_maybe_size_t(data[2]),
create_maybe_size_t(data[3]));
if (data.size() == 5)
return tensor_shape_variable(
create_maybe_size_t(data[0]),
create_maybe_size_t(data[1]),
create_maybe_size_t(data[2]),
create_maybe_size_t(data[3]),
create_maybe_size_t(data[4]));
raise_error("tensor_shape_variable needs 1, 2, 3, 4 or 5 dimensions");
return tensor_shape_variable(
fplus::nothing<std::size_t>(),
fplus::nothing<std::size_t>(),
fplus::nothing<std::size_t>(),
fplus::nothing<std::size_t>(),
fplus::nothing<std::size_t>()); // Is never called
}
inline tensor_shape_variable create_tensor_shape_variable_leading_null(const nlohmann::json& data)
{
assertion(data.is_array(), "tensor_shape_variable needs to be an array");
assertion(data.size() > 0, "need at least one dimension");
if (data.size() == 2)
return tensor_shape_variable(
create_maybe_size_t(data[1]));
if (data.size() == 3)
return tensor_shape_variable(
create_maybe_size_t(data[1]),
create_maybe_size_t(data[2]));
if (data.size() == 4)
return tensor_shape_variable(
create_maybe_size_t(data[1]),
create_maybe_size_t(data[2]),
create_maybe_size_t(data[3]));
if (data.size() == 5)
return tensor_shape_variable(
create_maybe_size_t(data[1]),
create_maybe_size_t(data[2]),
create_maybe_size_t(data[3]),
create_maybe_size_t(data[4]));
if (data.size() == 6)
return tensor_shape_variable(
create_maybe_size_t(data[1]),
create_maybe_size_t(data[2]),
create_maybe_size_t(data[3]),
create_maybe_size_t(data[4]),
create_maybe_size_t(data[5]));
raise_error("tensor_shape_variable needs 1, 2, 3, 4 or 5 dimensions");
return tensor_shape_variable(
fplus::nothing<std::size_t>(),
fplus::nothing<std::size_t>(),
fplus::nothing<std::size_t>(),
fplus::nothing<std::size_t>(),
fplus::nothing<std::size_t>()); // Is never called
}
inline tensor_shape create_tensor_shape(const nlohmann::json& data)
{
assertion(data.is_array(), "tensor_shape needs to be an array");
assertion(data.size() > 0, "need at least one dimension");
if (data.size() == 1)
return tensor_shape(static_cast<std::size_t>(data[0]));
if (data.size() == 2)
return tensor_shape(data[0], data[1]);
if (data.size() == 3)
return tensor_shape(data[0], data[1], data[2]);
if (data.size() == 4)
return tensor_shape(data[0], data[1], data[2], data[3]);
if (data.size() == 5)
return tensor_shape(data[0], data[1], data[2], data[3], data[4]);
raise_error("tensor_shape needs 1, 2, 3, 4 or 5 dimensions");
return tensor_shape(static_cast<std::size_t>(0)); // Is never be called
}
inline shape2 create_shape2(const nlohmann::json& data)
{
if (data.is_array())
{
assertion(data.size() == 1 || data.size() == 2,
"invalid number of dimensions in shape2");
if (data.size() == 1)
return shape2(1, data[0]);
else
return shape2(data[0], data[1]);
}
else
{
const std::size_t width = data;
return shape2(1, width);
}
}
inline std::size_t create_size_t(const nlohmann::json& int_data)
{
const int val = int_data;
assertion(val >= 0, "invalid size_t value");
return static_cast<std::size_t>(val);
}
inline int create_int(const nlohmann::json& int_data)
{
const int val = int_data;
return val;
}
inline float_vec decode_floats(const nlohmann::json& data)
{
assertion(data.is_array() || data.is_string(),
"invalid float array format");
if (data.is_array() && !data.empty() && data[0].is_number())
{
const float_vec result = data;
return result;
}
assertion(std::numeric_limits<float>::is_iec559,
"The floating-point format of your system is not supported.");
const auto res = Base64_decode(json_data_strs_char_prodiver(data, '='));
float_vec out;
assertion(res.size() % 4 == 0, "invalid float vector data");
out.reserve(res.size() / 4);
for (std::size_t i = 0; i < res.size(); i+=4)
{
float_type val = static_cast<float_type>(
*(reinterpret_cast<const float*>(&(res[i]))));
out.push_back(val);
}
return out;
}
inline tensor create_tensor(const nlohmann::json& data)
{
const tensor_shape shape = create_tensor_shape(data["shape"]);
return tensor(shape, decode_floats(data["values"]));
}
template <typename T, typename F>
std::vector<T> create_vector(F f, const nlohmann::json& data)
{
if (data.is_array())
return fplus::transform_convert<std::vector<T>>(f, data);
else
return fplus::singleton_seq(f(data));
}
inline std::vector<tensor_shape_variable> create_tensor_shapes_variable(const nlohmann::json& data)
{
return create_vector<tensor_shape_variable>(create_tensor_shape_variable, data);
}
inline node_connection create_node_connection(const nlohmann::json& data)
{
assertion(data.is_array(), "invalid format for inbound node");
const std::string layer_id = data.front();
const auto node_idx = create_size_t(data[1]);
const auto tensor_idx = create_size_t(data[2]);
return node_connection(layer_id, node_idx, tensor_idx);
}
using get_param_f =
std::function<nlohmann::json(const std::string&, const std::string&)>;
using layer_creators =
std::map<
std::string,
std::function<layer_ptr(
const get_param_f&,
const nlohmann::json&,
const std::string&)>>;
using wrapper_layer_creators =
std::map<
std::string,
std::function<layer_ptr(
const get_param_f&,
const nlohmann::json&,
const std::string&,
const layer_creators&,
const std::string)>>;
layer_ptr create_layer(const get_param_f&,
const nlohmann::json&,
const layer_creators& custom_layer_creators,
const std::string&);
inline layer_ptr create_model_layer(const get_param_f& get_param,
const nlohmann::json& data,
const std::string& name, const layer_creators& custom_layer_creators,
const std::string& prefix)
{
assertion(data["config"]["layers"].is_array(), "missing layers array");
const std::function<nlohmann::json(
const std::string&, const std::string&)>
get_prefixed_param = [&]
(const std::string& layer_name, const std::string& param_name)
-> nlohmann::json
{
return get_param(prefix + layer_name, param_name);
};
const auto make_layer = [&](const nlohmann::json& json)
{
return create_layer(get_prefixed_param, json,
custom_layer_creators, prefix);
};
const auto layers = create_vector<layer_ptr>(make_layer,
data["config"]["layers"]);
assertion(data["config"]["input_layers"].is_array(), "no input layers");
const auto inputs = create_vector<node_connection>(
create_node_connection, data["config"]["input_layers"]);
const auto outputs = create_vector<node_connection>(
create_node_connection, data["config"]["output_layers"]);
return std::make_shared<model_layer>(name, layers, inputs, outputs);
}
inline void fill_with_zeros(float_vec& xs)
{
std::fill(std::begin(xs), std::end(xs), static_cast<float_type>(0));
}
inline padding create_padding(const std::string& padding_str)
{
return fplus::throw_on_nothing(error("no padding"),
fplus::choose<std::string, padding>({
{ std::string("valid"), padding::valid },
{ std::string("same"), padding::same },
{ std::string("causal"), padding::causal },
}, padding_str));
}
inline layer_ptr create_conv_2d_layer(const get_param_f& get_param,
const nlohmann::json& data,
const std::string& name)
{
const std::string padding_str = data["config"]["padding"];
const auto pad_type = create_padding(padding_str);
const shape2 strides = create_shape2(data["config"]["strides"]);
const shape2 dilation_rate = create_shape2(data["config"]["dilation_rate"]);
const auto filter_count = create_size_t(data["config"]["filters"]);
float_vec bias(filter_count, 0);
const bool use_bias = data["config"]["use_bias"];
if (use_bias)
bias = decode_floats(get_param(name, "bias"));
assertion(bias.size() == filter_count, "size of bias does not match");
const float_vec weights = decode_floats(get_param(name, "weights"));
const shape2 kernel_size = create_shape2(data["config"]["kernel_size"]);
assertion(weights.size() % kernel_size.area() == 0,
"invalid number of weights");
const std::size_t filter_depths =
weights.size() / (kernel_size.area() * filter_count);
const tensor_shape filter_shape(
kernel_size.height_, kernel_size.width_, filter_depths);
return std::make_shared<conv_2d_layer>(name,
filter_shape, filter_count, strides, pad_type,
dilation_rate, weights, bias);
}
inline layer_ptr create_separable_conv_2D_layer(const get_param_f& get_param,
const nlohmann::json& data,
const std::string& name)
{
const std::string padding_str = data["config"]["padding"];
const auto pad_type = create_padding(padding_str);
const shape2 strides = create_shape2(data["config"]["strides"]);
const shape2 dilation_rate = create_shape2(data["config"]["dilation_rate"]);
const auto filter_count = create_size_t(data["config"]["filters"]);
float_vec bias(filter_count, 0);
const bool use_bias = data["config"]["use_bias"];
if (use_bias)
bias = decode_floats(get_param(name, "bias"));
assertion(bias.size() == filter_count, "size of bias does not match");
const float_vec slice_weights = decode_floats(
get_param(name, "slice_weights"));
const float_vec stack_weights = decode_floats(
get_param(name, "stack_weights"));
const shape2 kernel_size = create_shape2(data["config"]["kernel_size"]);
assertion(slice_weights.size() % kernel_size.area() == 0,
"invalid number of weights");
assertion(stack_weights.size() % filter_count == 0,
"invalid number of weights");
const std::size_t input_depth = slice_weights.size() / kernel_size.area();
const std::size_t stack_output_depths_1 =
stack_weights.size() / input_depth;
assertion(stack_output_depths_1 == filter_count, "invalid weights sizes");
const tensor_shape filter_shape(kernel_size.height_, kernel_size.width_, 1);
float_vec bias_0(input_depth, 0);
return std::make_shared<separable_conv_2d_layer>(name, input_depth,
filter_shape, filter_count, strides, pad_type,
dilation_rate, slice_weights, stack_weights, bias_0, bias);
}
inline layer_ptr create_depthwise_conv_2D_layer(const get_param_f& get_param,
const nlohmann::json& data,
const std::string& name)
{
const std::string padding_str = data["config"]["padding"];
const auto pad_type = create_padding(padding_str);
const shape2 strides = create_shape2(data["config"]["strides"]);
const shape2 dilation_rate = create_shape2(data["config"]["dilation_rate"]);
const float_vec slice_weights = decode_floats(
get_param(name, "slice_weights"));
const shape2 kernel_size = create_shape2(data["config"]["kernel_size"]);
assertion(slice_weights.size() % kernel_size.area() == 0,
"invalid number of weights");
const std::size_t input_depth = slice_weights.size() / kernel_size.area();
const tensor_shape filter_shape(kernel_size.height_, kernel_size.width_, 1);
const std::size_t filter_count = input_depth;
float_vec bias(filter_count, 0);
const bool use_bias = data["config"]["use_bias"];
if (use_bias)
bias = decode_floats(get_param(name, "bias"));
assertion(bias.size() == filter_count, "size of bias does not match");
return std::make_shared<depthwise_conv_2d_layer>(name, input_depth,
filter_shape, filter_count, strides, pad_type,
dilation_rate, slice_weights, bias);
}
inline layer_ptr create_input_layer(
const get_param_f&, const nlohmann::json& data, const std::string& name)
{
assertion(data["inbound_nodes"].empty(),
"input layer is not allowed to have inbound nodes");
const auto input_shape = create_tensor_shape_variable_leading_null(data["config"]["batch_input_shape"]);
return std::make_shared<input_layer>(name, input_shape);
}
inline layer_ptr create_batch_normalization_layer(const get_param_f& get_param,
const nlohmann::json& data, const std::string& name)
{
const float_vec moving_mean = decode_floats(get_param(name, "moving_mean"));
const float_vec moving_variance =
decode_floats(get_param(name, "moving_variance"));
const bool center = data["config"]["center"];
const bool scale = data["config"]["scale"];
const auto axis_vec = create_vector<int>(create_int, data["config"]["axis"]);
assertion(axis_vec.size() == 1, "invalid axis configuration");
const int axis = axis_vec.front();
const float_type epsilon = data["config"]["epsilon"];
float_vec gamma;
float_vec beta;
if (scale) gamma = decode_floats(get_param(name, "gamma"));
if (center) beta = decode_floats(get_param(name, "beta"));
return std::make_shared<batch_normalization_layer>(
name, axis, moving_mean, moving_variance, beta, gamma, epsilon);
}
inline layer_ptr create_identity_layer(
const get_param_f&, const nlohmann::json&, const std::string& name)
{
// Dropout and noise layers are identity functions during prediction.
return std::make_shared<linear_layer>(name);
}
inline layer_ptr create_max_pooling_2d_layer(
const get_param_f&, const nlohmann::json& data,
const std::string& name)
{
const auto pool_size = create_shape2(data["config"]["pool_size"]);
const auto strides = create_shape2(data["config"]["strides"]);
const bool channels_first = json_object_get(data["config"], "data_format", std::string("channels_last")) == "channels_first";
const std::string padding_str = data["config"]["padding"];
const auto pad_type = create_padding(padding_str);
return std::make_shared<max_pooling_2d_layer>(name,
pool_size, strides, channels_first, pad_type);
}
inline layer_ptr create_average_pooling_2d_layer(
const get_param_f&, const nlohmann::json& data,
const std::string& name)
{
const auto pool_size = create_shape2(data["config"]["pool_size"]);
const auto strides = create_shape2(data["config"]["strides"]);
const bool channels_first = json_object_get(data["config"], "data_format", std::string("channels_last")) == "channels_first";
const std::string padding_str = data["config"]["padding"];
const auto pad_type = create_padding(padding_str);
return std::make_shared<average_pooling_2d_layer>(name,
pool_size, strides, channels_first, pad_type);
}
inline layer_ptr create_global_max_pooling_1d_layer(
const get_param_f&, const nlohmann::json& data,
const std::string& name)
{
const bool channels_first = json_obj_has_member(data, "config")
&& json_object_get(data["config"], "data_format", std::string("channels_last")) == "channels_first";
return std::make_shared<global_max_pooling_1d_layer>(name, channels_first);
}
inline layer_ptr create_global_max_pooling_2d_layer(
const get_param_f&, const nlohmann::json& data,
const std::string& name)
{
const bool channels_first = json_obj_has_member(data, "config")
&& json_object_get(data["config"], "data_format", std::string("channels_last")) == "channels_first";
return std::make_shared<global_max_pooling_2d_layer>(name, channels_first);
}
inline layer_ptr create_global_average_pooling_1d_layer(
const get_param_f&, const nlohmann::json& data,
const std::string& name)
{
const bool channels_first = json_obj_has_member(data, "config")
&& json_object_get(data["config"], "data_format", std::string("channels_last")) == "channels_first";
return std::make_shared<global_average_pooling_1d_layer>(name, channels_first);
}
inline layer_ptr create_global_average_pooling_2d_layer(
const get_param_f&, const nlohmann::json& data,
const std::string& name)
{
const bool channels_first = json_obj_has_member(data, "config")
&& json_object_get(data["config"], "data_format", std::string("channels_last")) == "channels_first";
return std::make_shared<global_average_pooling_2d_layer>(name, channels_first);
}
inline layer_ptr create_upsampling_1d_layer(
const get_param_f&, const nlohmann::json& data,
const std::string& name)
{
const std::size_t size = data["config"]["size"];
return std::make_shared<upsampling_1d_layer>(name, size);
}
inline layer_ptr create_upsampling_2d_layer(
const get_param_f&, const nlohmann::json& data,
const std::string& name)
{
const auto scale_factor = create_shape2(data["config"]["size"]);
const std::string interpolation = data["config"]["interpolation"];
return std::make_shared<upsampling_2d_layer>(
name, scale_factor, interpolation);
}
inline layer_ptr create_dense_layer(const get_param_f& get_param,
const nlohmann::json& data, const std::string& name)
{
const float_vec weights = decode_floats(get_param(name, "weights"));
std::size_t units = data["config"]["units"];
float_vec bias(units, 0);
const bool use_bias = data["config"]["use_bias"];
if (use_bias)
bias = decode_floats(get_param(name, "bias"));
assertion(bias.size() == units, "size of bias does not match");
return std::make_shared<dense_layer>(
name, units, weights, bias);
}
inline layer_ptr create_concatenate_layer(
const get_param_f&, const nlohmann::json& data,
const std::string& name)
{
const std::int32_t keras_axis = data["config"]["axis"];
return std::make_shared<concatenate_layer>(name, keras_axis);
}
inline layer_ptr create_add_layer(
const get_param_f&, const nlohmann::json&,
const std::string& name)
{
return std::make_shared<add_layer>(name);
}
inline layer_ptr create_maximum_layer(
const get_param_f&, const nlohmann::json&,
const std::string& name)
{
return std::make_shared<maximum_layer>(name);
}
inline layer_ptr create_multiply_layer(
const get_param_f&, const nlohmann::json&,
const std::string& name)
{
return std::make_shared<multiply_layer>(name);
}
inline layer_ptr create_average_layer(
const get_param_f&, const nlohmann::json&,
const std::string& name)
{
return std::make_shared<average_layer>(name);
}
inline layer_ptr create_subtract_layer(
const get_param_f&, const nlohmann::json&,
const std::string& name)
{
return std::make_shared<subtract_layer>(name);
}
inline layer_ptr create_flatten_layer(
const get_param_f&, const nlohmann::json&,
const std::string& name)
{
return std::make_shared<flatten_layer>(name);
}
inline layer_ptr create_zero_padding_2d_layer(
const get_param_f&, const nlohmann::json& data,
const std::string& name)
{
const auto padding =
create_vector<std::vector<std::size_t>>(fplus::bind_1st_of_2(
create_vector<std::size_t, decltype(create_size_t)>, create_size_t),
data["config"]["padding"]);
assertion(padding.size() == 2 && padding[0].size() == padding[1].size(),
"invalid padding format");
if (padding[0].size() == 1)
{
const std::size_t top_pad = 0;
const std::size_t bottom_pad = 0;
const std::size_t left_pad = padding[0][0];
const std::size_t right_pad = padding[1][0];
return std::make_shared<zero_padding_2d_layer>(name,
top_pad, bottom_pad, left_pad, right_pad);
}
else
{
const std::size_t top_pad = padding[0][0];
const std::size_t bottom_pad = padding[0][1];
const std::size_t left_pad = padding[1][0];
const std::size_t right_pad = padding[1][1];
return std::make_shared<zero_padding_2d_layer>(name,
top_pad, bottom_pad, left_pad, right_pad);
}
}
inline layer_ptr create_cropping_2d_layer(
const get_param_f&, const nlohmann::json& data,
const std::string& name)
{
const auto cropping =
create_vector<std::vector<std::size_t>>(fplus::bind_1st_of_2(
create_vector<std::size_t, decltype(create_size_t)>, create_size_t),
data["config"]["cropping"]);
assertion(cropping.size() == 2 && cropping[0].size() == cropping[1].size(),
"invalid cropping format");
if (cropping[0].size() == 1)
{
const std::size_t top_crop = 0;
const std::size_t bottom_crop = 0;
const std::size_t left_crop = cropping[0][0];
const std::size_t right_crop = cropping[1][0];
return std::make_shared<cropping_2d_layer>(name,
top_crop, bottom_crop, left_crop, right_crop);
}
else
{
const std::size_t top_crop = cropping[0][0];
const std::size_t bottom_crop = cropping[0][1];
const std::size_t left_crop = cropping[1][0];
const std::size_t right_crop = cropping[1][1];
return std::make_shared<cropping_2d_layer>(name,
top_crop, bottom_crop, left_crop, right_crop);
}
}
inline layer_ptr create_reshape_layer(
const get_param_f&, const nlohmann::json& data,
const std::string& name)
{
const auto target_shape = create_tensor_shape(data["config"]["target_shape"]);
return std::make_shared<reshape_layer>(name, target_shape);
}
inline activation_layer_ptr create_linear_layer(
const get_param_f&, const nlohmann::json&,
const std::string& name)
{
return std::make_shared<linear_layer>(name);
}
inline activation_layer_ptr create_softmax_layer(
const get_param_f&, const nlohmann::json&,
const std::string& name)
{
return std::make_shared<softmax_layer>(name);
}
inline activation_layer_ptr create_softplus_layer(
const get_param_f&, const nlohmann::json&,
const std::string& name)
{
return std::make_shared<softplus_layer>(name);
}
inline activation_layer_ptr create_tanh_layer(
const get_param_f&, const nlohmann::json&,
const std::string& name)
{
return std::make_shared<tanh_layer>(name);
}
inline activation_layer_ptr create_sigmoid_layer(
const get_param_f&, const nlohmann::json&,
const std::string& name)
{
return std::make_shared<sigmoid_layer>(name);
}
inline activation_layer_ptr create_hard_sigmoid_layer(
const get_param_f&, const nlohmann::json&,
const std::string& name)
{
return std::make_shared<hard_sigmoid_layer>(name);
}
inline activation_layer_ptr create_relu_layer(
const get_param_f&, const nlohmann::json& data,
const std::string& name)
{
float_type max_value = std::numeric_limits<float_type>::max();
if (json_obj_has_member(data, "config") &&
json_obj_has_member(data["config"], "max_value") &&
!data["config"]["max_value"].is_null())
{
max_value = data["config"]["max_value"];
}
return std::make_shared<relu_layer>(name, max_value);
}
inline activation_layer_ptr create_selu_layer(
const get_param_f&, const nlohmann::json&,
const std::string& name)
{
return std::make_shared<selu_layer>(name);
}
inline activation_layer_ptr create_leaky_relu_layer(
const get_param_f&, const nlohmann::json& data,
const std::string& name)
{
float_type alpha = 1.0f;
if (json_obj_has_member(data, "config") &&
json_obj_has_member(data["config"], "alpha"))
{
alpha = data["config"]["alpha"];
}
return std::make_shared<leaky_relu_layer>(name, alpha);
}
inline layer_ptr create_leaky_relu_layer_isolated(
const get_param_f& get_param,
const nlohmann::json& data, const std::string& name)
{
return create_leaky_relu_layer(get_param, data, name);
}
inline layer_ptr create_prelu_layer(
const get_param_f& get_param,
const nlohmann::json& data, const std::string& name)
{
std::vector<std::size_t> shared_axes;
if (json_obj_has_member(data, "config") &&
json_obj_has_member(data["config"], "shared_axes") &&
!data["config"]["shared_axes"].empty())
{
shared_axes = create_vector<std::size_t>(create_size_t,
data["config"]["shared_axes"]);
}
const float_vec alpha = decode_floats(get_param(name, "alpha"));
return std::make_shared<prelu_layer>(name, alpha, shared_axes);
}
inline activation_layer_ptr create_elu_layer(
const get_param_f&, const nlohmann::json& data,
const std::string& name)
{
float_type alpha = 1.0f;
if (json_obj_has_member(data, "config") &&
json_obj_has_member(data["config"], "alpha"))
{
alpha = data["config"]["alpha"];
}
return std::make_shared<elu_layer>(name, alpha);
}
inline layer_ptr create_elu_layer_isolated(
const get_param_f& get_param,
const nlohmann::json& data, const std::string& name)
{
return create_elu_layer(get_param,data, name);
}
inline layer_ptr create_relu_layer_isolated(
const get_param_f& get_param,
const nlohmann::json& data, const std::string& name)
{
return create_relu_layer(get_param, data, name);
}
inline activation_layer_ptr create_activation_layer_type_name(
const get_param_f& get_param,
const nlohmann::json& data,
const std::string& type, const std::string& name)
{
const std::map<std::string,
std::function<activation_layer_ptr(const get_param_f&,
const nlohmann::json&,
const std::string&)>>
creators = {
{"linear", create_linear_layer},
{"softmax", create_softmax_layer},
{"softplus", create_softplus_layer},
{"tanh", create_tanh_layer},
{"sigmoid", create_sigmoid_layer},
{"hard_sigmoid", create_hard_sigmoid_layer},
{"relu", create_relu_layer},
{"selu", create_selu_layer},
{"elu", create_elu_layer}
};
return fplus::throw_on_nothing(
error("unknown activation type: " + type),
fplus::get_from_map(creators, type))(
get_param, data, name);
}
inline layer_ptr create_activation_layer(
const get_param_f& get_param,
const nlohmann::json& data, const std::string& name)
{
const std::string type = data["config"]["activation"];
return create_activation_layer_type_name(get_param,
data, type, name);
}
inline layer_ptr create_permute_layer(
const get_param_f&,
const nlohmann::json& data, const std::string& name)
{
const auto dims = create_vector<std::size_t>(create_size_t,
data["config"]["dims"]);
return std::make_shared<permute_layer>(name, dims);
}
inline node create_node(const nlohmann::json& inbound_nodes_data)
{
assertion(inbound_nodes_data.is_array(), "nodes need to be an array");
return node(create_vector<node_connection>(create_node_connection,
inbound_nodes_data));
}
inline nodes create_nodes(const nlohmann::json& data)
{
assertion(data["inbound_nodes"].is_array(), "no inbound nodes");
const std::vector<nlohmann::json> inbound_nodes_data =
data["inbound_nodes"];
return fplus::transform(create_node, inbound_nodes_data);
}
inline layer_ptr create_embedding_layer(const get_param_f &get_param,
const nlohmann::json &data,
const std::string &name)
{
const std::size_t input_dim = data["config"]["input_dim"];
const std::size_t output_dim = data["config"]["output_dim"];
const float_vec weights = decode_floats(get_param(name, "weights"));
return std::make_shared<embedding_layer>(name, input_dim, output_dim, weights);
}
inline layer_ptr create_lstm_layer(const get_param_f &get_param,
const nlohmann::json &data,
const std::string &name)
{
auto&& config = data["config"];
const std::size_t units = config["units"];
const std::string unit_activation = json_object_get(config, "activation", std::string("tanh"));
const std::string recurrent_activation = json_object_get(config,
"recurrent_activation",
data["class_name"] == "CuDNNLSTM"
? std::string("sigmoid")
: std::string("hard_sigmoid")
);
const bool use_bias = json_object_get(config, "use_bias", true);
float_vec bias;
if (use_bias)
bias = decode_floats(get_param(name, "bias"));
const float_vec weights = decode_floats(get_param(name, "weights"));
const float_vec recurrent_weights = decode_floats(get_param(name, "recurrent_weights"));
const bool return_sequences = json_object_get(config, "return_sequences", false);
const bool return_state = json_object_get(config, "return_state", false);
const bool stateful = json_object_get(config, "stateful", false);
return std::make_shared<lstm_layer>(name, units, unit_activation,
recurrent_activation, use_bias,
return_sequences, return_state, stateful,
weights, recurrent_weights, bias);
}
inline layer_ptr create_gru_layer(const get_param_f &get_param,
const nlohmann::json &data,
const std::string &name)
{
auto&& config = data["config"];
const std::size_t units = config["units"];
const std::string unit_activation = json_object_get(config, "activation", std::string("tanh"));
const std::string recurrent_activation = json_object_get(config,
"recurrent_activation",
data["class_name"] == "CuDNNGRU"
? std::string("sigmoid")
: std::string("hard_sigmoid")
);
const bool use_bias = json_object_get(config, "use_bias", true);
const bool return_sequences = json_object_get(config, "return_sequences", false);
const bool return_state = json_object_get(config, "return_state", false);
const bool stateful = json_object_get(config, "stateful", false);
float_vec bias;
if (use_bias)
bias = decode_floats(get_param(name, "bias"));
const float_vec weights = decode_floats(get_param(name, "weights"));
const float_vec recurrent_weights = decode_floats(get_param(name, "recurrent_weights"));
bool reset_after = json_object_get(config,
"reset_after",
data["class_name"] == "CuDNNGRU"
);
return std::make_shared<gru_layer>(name, units, unit_activation,
recurrent_activation, use_bias, reset_after,
return_sequences, return_state, stateful,
weights, recurrent_weights, bias);
}
inline layer_ptr create_bidirectional_layer(const get_param_f& get_param,
const nlohmann::json& data,
const std::string& name)
{
const std::string merge_mode = data["config"]["merge_mode"];
auto&& layer = data["config"]["layer"];
auto&& layer_config = layer["config"];
const std::string wrapped_layer_type = layer["class_name"];
const std::size_t units = layer_config["units"];
const std::string unit_activation = json_object_get(layer_config, "activation", std::string("tanh"));
const std::string recurrent_activation = json_object_get(layer_config,
"recurrent_activation",
wrapped_layer_type == "CuDNNGRU" || wrapped_layer_type == "CuDNNLSTM"
? std::string("sigmoid")
: std::string("hard_sigmoid")
);
const bool use_bias = json_object_get(layer_config, "use_bias", true);
float_vec forward_bias;
float_vec backward_bias;
if (use_bias)
{
forward_bias = decode_floats(get_param(name, "forward_bias"));
backward_bias = decode_floats(get_param(name, "backward_bias"));
}
const float_vec forward_weights = decode_floats(get_param(name, "forward_weights"));
const float_vec backward_weights = decode_floats(get_param(name, "backward_weights"));
const float_vec forward_recurrent_weights = decode_floats(get_param(name, "forward_recurrent_weights"));
const float_vec backward_recurrent_weights = decode_floats(get_param(name, "backward_recurrent_weights"));
const bool reset_after = json_object_get(layer_config,
"reset_after",
wrapped_layer_type == "CuDNNGRU"
);
const bool return_sequences = json_object_get(layer_config, "return_sequences", false);
const bool stateful = json_object_get(layer_config, "stateful", false);
return std::make_shared<bidirectional_layer>(name, merge_mode, units, unit_activation,
recurrent_activation, wrapped_layer_type,
use_bias, reset_after, return_sequences, stateful,
forward_weights, forward_recurrent_weights, forward_bias,
backward_weights, backward_recurrent_weights, backward_bias);
}
inline layer_ptr create_time_distributed_layer(const get_param_f& get_param,
const nlohmann::json& data,
const std::string& name,
const layer_creators& custom_layer_creators,
const std::string& prefix)
{
const std::string wrapped_layer_type = data["config"]["layer"]["class_name"];
nlohmann::json data_inner_layer = data["config"]["layer"];
data_inner_layer["name"] = data["name"];
data_inner_layer["inbound_nodes"] = data["inbound_nodes"];
const std::size_t td_input_len = std::size_t(decode_floats(get_param(name, "td_input_len")).front());
const std::size_t td_output_len = std::size_t(decode_floats(get_param(name, "td_output_len")).front());
layer_ptr inner_layer = create_layer(get_param, data_inner_layer, custom_layer_creators, prefix);
return std::make_shared<time_distributed_layer>(name, inner_layer, td_input_len, td_output_len);
}
inline layer_ptr create_layer(const get_param_f& get_param,
const nlohmann::json& data,
const layer_creators& custom_layer_creators,
const std::string& prefix)
{
const std::string name = data["name"];
const layer_creators default_creators = {
{"Conv1D", create_conv_2d_layer},
{"Conv2D", create_conv_2d_layer},
{"SeparableConv1D", create_separable_conv_2D_layer},
{"SeparableConv2D", create_separable_conv_2D_layer},
{"DepthwiseConv2D", create_depthwise_conv_2D_layer},
{"InputLayer", create_input_layer},
{"BatchNormalization", create_batch_normalization_layer},
{"Dropout", create_identity_layer},
{"AlphaDropout", create_identity_layer},
{"GaussianDropout", create_identity_layer},
{"GaussianNoise", create_identity_layer},
{"SpatialDropout1D", create_identity_layer},
{"SpatialDropout2D", create_identity_layer},
{"SpatialDropout3D", create_identity_layer},
{"LeakyReLU", create_leaky_relu_layer_isolated},
{"Permute", create_permute_layer },
{"PReLU", create_prelu_layer },
{"ELU", create_elu_layer_isolated},
{"ReLU", create_relu_layer_isolated},
{"MaxPooling1D", create_max_pooling_2d_layer},
{"MaxPooling2D", create_max_pooling_2d_layer},
{"AveragePooling1D", create_average_pooling_2d_layer},
{"AveragePooling2D", create_average_pooling_2d_layer},
{"GlobalMaxPooling1D", create_global_max_pooling_1d_layer},
{"GlobalMaxPooling2D", create_global_max_pooling_2d_layer},
{"GlobalAveragePooling1D", create_global_average_pooling_1d_layer},
{"GlobalAveragePooling2D", create_global_average_pooling_2d_layer},
{"UpSampling1D", create_upsampling_1d_layer},
{"UpSampling2D", create_upsampling_2d_layer},
{"Dense", create_dense_layer},
{"Add", create_add_layer},
{"Maximum", create_maximum_layer},
{"Concatenate", create_concatenate_layer},
{"Multiply", create_multiply_layer},
{"Average", create_average_layer},
{"Subtract", create_subtract_layer},
{"Flatten", create_flatten_layer},
{"ZeroPadding1D", create_zero_padding_2d_layer},
{"ZeroPadding2D", create_zero_padding_2d_layer},
{"Cropping1D", create_cropping_2d_layer},
{"Cropping2D", create_cropping_2d_layer},
{"Activation", create_activation_layer},
{"Reshape", create_reshape_layer},
{"Embedding", create_embedding_layer},
{"LSTM", create_lstm_layer},
{"CuDNNLSTM", create_lstm_layer},
{"GRU", create_gru_layer},
{"CuDNNGRU", create_gru_layer},
{"Bidirectional", create_bidirectional_layer},
{"Softmax", create_softmax_layer},
};
const wrapper_layer_creators wrapper_creators = {
{"Model", create_model_layer},
{"Functional", create_model_layer},
{"TimeDistributed", create_time_distributed_layer}
};
const std::string type = data["class_name"];
if (fplus::map_contains(wrapper_creators, type))
{
auto result = fplus::get_from_map_unsafe(wrapper_creators, type)(
get_param, data, name, custom_layer_creators, prefix + name + "_");
result->set_nodes(create_nodes(data));
return result;
}
else
{
const layer_creators creators = fplus::map_union(custom_layer_creators,
default_creators);
auto result = fplus::throw_on_nothing(
error("unknown layer type: " + type),
fplus::get_from_map(creators, type))(
get_param, data, name);
if (type != "Activation" &&
json_obj_has_member(data["config"], "activation")
&& type != "GRU"
&& type != "LSTM"
&& type != "Bidirectional")
{
result->set_activation(
create_activation_layer_type_name(get_param, data,
data["config"]["activation"], ""));
}
result->set_nodes(create_nodes(data));
return result;
}
}
struct test_case
{
tensors input_;
tensors output_;
};
using test_cases = std::vector<test_case>;
inline test_case load_test_case(const nlohmann::json& data)
{
assertion(data["inputs"].is_array(), "test needs inputs");
assertion(data["outputs"].is_array(), "test needs outputs");
return {
create_vector<tensor>(create_tensor, data["inputs"]),
create_vector<tensor>(create_tensor, data["outputs"])
};
}
inline test_cases load_test_cases(const nlohmann::json& data)
{
return create_vector<test_case>(load_test_case, data);
}
inline void check_test_outputs(float_type epsilon,
const tensors& outputs, const tensors& targets)
{
assertion(outputs.size() == targets.size(), "invalid output count");
for (std::size_t i = 0; i < outputs.size(); ++i)
{
const auto& output = outputs[i];
const auto& target = targets[i];
assertion(output.shape() == target.shape(),
"Wrong output size. Is " + show_tensor_shape(output.shape()) +
", should be " + show_tensor_shape(target.shape()) + ".");
for (std::size_t pos_dim_5 = 0; pos_dim_5 < output.shape().size_dim_5_; ++pos_dim_5)
{
for (std::size_t pos_dim_4 = 0; pos_dim_4 < output.shape().size_dim_4_; ++pos_dim_4)
{
for (std::size_t y = 0; y < output.shape().height_; ++y)
{
for (std::size_t x = 0; x < output.shape().width_; ++x)
{
for (std::size_t z = 0; z < output.shape().depth_; ++z)
{
const tensor_pos pos(pos_dim_5, pos_dim_4, y, x, z);
const auto target_val = target.get_ignore_rank(pos);
const auto output_val = output.get_ignore_rank(pos);
if (!fplus::is_in_closed_interval_around(epsilon,
target_val, output_val) &&
!(std::isnan(target_val) && std::isnan(output_val)))
{
const std::string msg =
std::string("test failed: ") +
"output=" + fplus::show(i) + " " +
"pos=" +
fplus::show(y) + "," +
fplus::show(x) + "," +
fplus::show(z) + " " +
"value=" + fplus::show(output_val) + " "
"target=" + fplus::show(target_val);
internal::raise_error(msg);
}
}
}
}
}
}
}
}
} } // namespace fdeep, namespace internal
|
;
;
; Copyright (c) 2018 by blindtiger. All rights reserved.
;
; The contents of this file are subject to the Mozilla Public 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.mozilla.org/MPL/
;
; Software distributed under the License is distributed on an "AS IS" basis,
; WITHOUT WARRANTY OF ANY KIND, either express or implied. SEe the License
; for the specific language governing rights and limitations under the
; License.
;
; The Initial Developer of the Original e is blindtiger.
;
;
include ksamd64.inc
include macamd64.inc
PgbIoGetInitialStack equ 00000000h
PgbWorkerContext equ 00000008h
PgbExpWorkerThread equ 00000010h
PgbPspSystemThreadStartup equ 00000018h
PgbKiStartSystemThread equ 00000020h
PgbDbgPrint equ 00000028h
PgbClearEncryptedContextMessage equ 00000030h
PgbRevertWorkerToSelfMessage equ 00000038h
PgbRtlCompareMemory equ 00000040h
PgbSdbpCheckDll equ 00000048h
PgbSizeOfSdbpCheckDll equ 00000050h
PgbCheckPatchGuardCode equ 00000058h
PgbClearEncryptedContext equ 00000060h
PgbRevertWorkerToSelf equ 00000068h
PgbRtlRestoreContext equ 00000070h
PgbExQueueWorkItem equ 00000078h
PgbExFreePool equ 00000080h
PgbReferenceCount equ 00000088h
; ULONG64
; NTAPI
; _btc64(
; __in ULONG64 a,
; __in ULONG64 b
; );
LEAF_ENTRY _btc64, _TEXT$00
btc rcx, rdx
mov rax, rcx
ret
LEAF_END _btc64, _TEXT$00
; VOID
; NTAPI
; _MakePgFire(
; VOID
; );
LEAF_ENTRY _MakePgFire, _TEXT$00
sub rsp, 10h
lea rcx, [rsp + 2]
sidt fword ptr [rcx]
mov ax, 0ffffh
mov [rcx], ax
lidt fword ptr [rcx]
sidt fword ptr [rcx]
add rsp, 10h
ret
LEAF_END _MakePgFire, _TEXT$00
; PVOID
; NTAPI
; _ClearEncryptedContext(
; __in PVOID Reserved,
; __in PVOID PatchGuardContext
; );
LEAF_ENTRY _ClearEncryptedContext, _TEXT$00
@@:
dq 1 dup (0) ; PgbPatchGuardBlock
push rbx
sub rsp, KSTART_FRAME_LENGTH - 10h
lea rbx, @b
mov rbx, [rbx]
lea rcx, PgbReferenceCount [rbx]
lock dec qword ptr [rcx]
mov rdx, [rcx]
mov rcx, PgbClearEncryptedContextMessage [rbx]
mov rax, PgbDbgPrint [rbx]
call rax
add rsp, KSTART_FRAME_LENGTH - 10h
pop rbx
add rsp, 30h
ret
LEAF_END _ClearEncryptedContext, _TEXT$00
; VOID
; NTAPI
; _RevertWorkerToSelf(
; VOID
; );
LEAF_ENTRY _RevertWorkerToSelf, _TEXT$00
@@:
dq 1 dup (0) ; PgbPatchGuardBlock
and rsp, not 0fh
lea rbx, @b
mov rbx, [rbx]
mov r15, PgbWorkerContext [rbx]
mov r14, PgbExpWorkerThread [rbx]
mov r13, PgbPspSystemThreadStartup [rbx]
mov r12, PgbKiStartSystemThread [rbx]
lea rcx, PgbReferenceCount [rbx]
lock dec qword ptr [rcx]
mov rdx, [rcx]
mov rcx, PgbRevertWorkerToSelfMessage [rbx]
mov rax, PgbDbgPrint [rbx]
call rax
mov rax, PgbIoGetInitialStack [rbx]
call rax
mov rsp, rax
sub rsp, KSTART_FRAME_LENGTH
mov SfP1Home [rsp], r15
mov SfP2Home [rsp], r14
mov SfP3Home [rsp], r13
mov qword ptr SfReturn [rsp], 0
jmp r12
LEAF_END _RevertWorkerToSelf, _TEXT$00
; VOID
; NTAPI
; _CheckPatchGuardCode(
; __in PVOID BaseAddress,
; __in SIZE_T RegionSize
; );
NESTED_ENTRY _CheckPatchGuardCode, _TEXT$00
alloc_stack ( KSTART_FRAME_LENGTH - 8 )
END_PROLOGUE
mov rsi, rcx
mov rdi, PgbSdbpCheckDll [rbx]
mov r12, rdx
mov r13, PgbSizeOfSdbpCheckDll [rbx]
sub r12, r13
xor r14, r14
mov r15, PgbRtlCompareMemory [rbx]
@@:
lea rcx, [rsi + r14]
mov rdx, rdi
mov r8, r13
call r15
cmp rax, r13
setnz al
jz @f
inc r14
cmp r14, r12
jnz @b
@@:
add rsp, ( KSTART_FRAME_LENGTH - 8 )
ret
NESTED_END _CheckPatchGuardCode, _TEXT$00
; VOID
; NTAPI
; _PgGuardCall(
; VOID
; );
NESTED_ENTRY _PgGuardCall, _TEXT$00
@@:
dq 1 dup (0) ; _GuardCall->Usable
dq 1 dup (0) ; PgbPatchGuardBlock
dq 4 dup (0) ; _GuardCall->Parameters
alloc_stack CONTEXT_FRAME_LENGTH
END_PROLOGUE
mov CxSegCs [rsp], cs
mov CxSegDs [rsp], ds
mov CxSegEs [rsp], es
mov CxSegSs [rsp], ss
mov CxSegFs [rsp], fs
mov CxSegGs [rsp], gs
mov CxRax [rsp], rax
mov CxRcx [rsp], rcx
mov CxRdx [rsp], rdx
mov CxRbx [rsp], rbx
lea rax, CONTEXT_FRAME_LENGTH [rsp]
mov CxRsp [rsp], rax
mov CxRbp [rsp], rbp
mov CxRsi [rsp], rsi
mov CxRdi [rsp], rdi
mov CxR8 [rsp], r8
mov CxR9 [rsp], r9
mov CxR10 [rsp], r10
mov CxR11 [rsp], r11
mov CxR12 [rsp], r12
mov CxR13 [rsp], r13
mov CxR14 [rsp], r14
mov CxR15 [rsp], r15
movdqa CxXmm0 [rsp], xmm0
movdqa CxXmm1 [rsp], xmm1
movdqa CxXmm2 [rsp], xmm2
movdqa CxXmm3 [rsp], xmm3
movdqa CxXmm4 [rsp], xmm4
movdqa CxXmm5 [rsp], xmm5
movdqa CxXmm6 [rsp], xmm6
movdqa CxXmm7 [rsp], xmm7
movdqa CxXmm8 [rsp], xmm8
movdqa CxXmm9 [rsp], xmm9
movdqa CxXmm10 [rsp], xmm10
movdqa CxXmm11 [rsp], xmm11
movdqa CxXmm12 [rsp], xmm12
movdqa CxXmm13 [rsp], xmm13
movdqa CxXmm14 [rsp], xmm14
movdqa CxXmm15 [rsp], xmm15
stmxcsr CxMxCsr[rsp]
pushfq
pop rax
mov CxEFlags[rsp], eax
mov eax, CONTEXT_FULL or CONTEXT_SEGMENTS
mov CxContextFlags [rsp], eax
lea rbx, @b
mov rax, [rbx + 10h]
mov CxRip [rsp], rax
mov rcx, [rbx + 18h] ; BaseAddress
mov rdx, [rbx + 20h] ; RegionSize
mov rbx, [rbx + 8]
mov rax, PgbCheckPatchGuardCode [rbx]
call rax
test al, al
jnz @f
mov rax, PgbRevertWorkerToSelf [rbx]
call rax
int 3
@@:
mov rax, PgbRtlRestoreContext [rbx]
lea rcx, [rsp]
xor rdx, rdx
call rax
int 3
NESTED_END _PgGuardCall, _TEXT$00
end
|
; print binary code
Start:
; where to print
LDX #$A000
; a byte consists of eight bits
LDY #8
; 0
LDA #48
;target
LDB #$81
Loop1:
; test one bit
ROLB
ADCA
STA ,X
LDA #48
INCX
INCX
DECY
CMPY #$00
JNE #Loop1
END Start |
/*
* Copyright (c) 2010, Anima Games, Benjamin Karaban, Laurent Schneider,
* Jérémie Comarmond, Didier Colin.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of the copyright holder 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 "PtyTexture.moc.h"
#include <QGridLayout>
#include <Universe/World.h>
#include <QtToolbox/SmartGroupBox.moc.h>
#include <QtToolbox/CollapsibleWidget.moc.h>
#include <EPI/ImportInfo/ImportTextureInfo.h>
#include <EPI/GUI/Widget/TextureGenerationOptions.moc.h>
#include <Workflow/TexCompression.h>
#include <QLabel>
#include <EPI/Constants.h>
namespace EPI
{
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
PtyTexture::PtyTexture( const Ptr<Universe::World>& pWorld,
const Ptr<ImportTextureInfo> & pImportTextureInfo,
const Core::String& title)
: PropertyNode(title, true, false, CONTENT),
_pImportTextureInfo(pImportTextureInfo),
_pWorld(pWorld)
{
_pNodeDecal = _pWorld->createDecal(pImportTextureInfo->textureName, Renderer::DECAL_LERP);
_pNodeDecal->beginMatrixUpdate();
_pNodeDecal->setLocalPosition(Core::Vector3f(0.0f, 0.0f, 0.0f));
_pNodeDecal->endMatrixUpdate();
updateProperty();
}
PtyTexture::~PtyTexture()
{}
Ptr<PropertyWidget> PtyTexture::internalCreatePropertyWidget(const Ptr<PropertyWidgetDataProxy>& pDataProxy, QWidget * parent)
{
Ptr<PtyWidgetTexture> pPW (new PtyWidgetTexture(pDataProxy, _pImportTextureInfo, parent));
return pPW;
}
void PtyTexture::updateProperty()
{
_bcgColor = _pWorld->getFogColor();
Ptr<Assets::Texture> pTexture = _pImportTextureInfo->pTexture;
if (pTexture != null)
{
if (pTexture->getMipmapCount() == 0)
{
pTexture = _pWorld->getRessourcesPool()->getTextureData(_pImportTextureInfo->textureName);
}
float w = pTexture->getWidth();
float h = pTexture->getHeight();
float ratio = 1.f;
if (h>0)
ratio = w/h;
_pNodeDecal->setSize(1, 1/ratio);
}
}
void PtyTexture::updateData()
{
_pWorld->setFogColor(_bcgColor);
}
Ptr<Property> PtyTexture::clone() const
{
return Ptr<Property>(new PtyTexture( *this ));
}
void PtyTexture::internalCopy(const Ptr<Property>& pSrc)
{
Ptr<PtyTexture> pPty = LM_DEBUG_PTR_CAST<PtyTexture>(pSrc);
_pWorld = pPty->_pWorld;
_bcgColor = pPty->_bcgColor;
updateData();
}
void PtyTexture::generateTexture(const Ptr<Workflow::TextureOptions> & pTextureOptions)
{
_pImportTextureInfo->pTextureOptions = pTextureOptions;
emit generate(_pImportTextureInfo);
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
PtyWidgetTexture::PtyWidgetTexture( const Ptr<PropertyWidgetDataProxy>& data,
const Ptr<ImportTextureInfo> & pImportTextureInfo,
QWidget * parent)
: PropertyWidget(data, parent)
{
setupUi();
_textureGenerationOptions->setTextureInfo(pImportTextureInfo);
}
PtyWidgetTexture::~PtyWidgetTexture()
{}
void PtyWidgetTexture::readProperty()
{
Ptr<PtyTexture> pPtyTex = LM_DEBUG_PTR_CAST<PtyTexture>(getDataProxy()->getProperty());
_backGroundColor->setColorLinear(pPtyTex->_bcgColor);
updateInfo();
}
void PtyWidgetTexture::writeProperty(QWidget* pWidget)
{
Ptr<PtyTexture> pPtyTex = LM_DEBUG_PTR_CAST<PtyTexture>(getDataProxy()->getProperty());
_backGroundColor->getColorLinear(pPtyTex->_bcgColor);
}
void PtyWidgetTexture::setupUi()
{
Ptr<PtyTexture> pPtyTex = LM_DEBUG_PTR_CAST<PtyTexture>(getDataProxy()->getProperty());
_layout = new QGridLayout(this);
_layout->setContentsMargins(0, 0, 0, 0);
_groupBoxDoc = new QtToolbox::CollapsibleWidget(this, "World", false);
_groupBoxTex = new QtToolbox::CollapsibleWidget(this, "Texture", false);
_groupBoxInfo = new QtToolbox::CollapsibleWidget(this, "Information", false);
_backGroundColor = new QtToolbox::QuickColorPicker(this, "BackGround Color");
_textureGenerationOptions = new TextureGenerationOptions(this, false);
_width = new QLabel();
_height = new QLabel();
_size = new QLabel();
_groupBoxDoc->getLayout()->addWidget(_backGroundColor);
_groupBoxTex->getLayout()->addWidget(_textureGenerationOptions);
_groupBoxInfo->getLayout()->addWidget(_width);
_groupBoxInfo->getLayout()->addWidget(_height);
_groupBoxInfo->getLayout()->addWidget(_size);
_layout->addWidget(_groupBoxDoc);
_layout->addWidget(_groupBoxTex);
_layout->addWidget(_groupBoxInfo);
getWidgetsForUndoRedo().push_back(_backGroundColor);
PropertyWidget::setupUi();
connect(_textureGenerationOptions, SIGNAL(accept()), this, SLOT(launchGeneration()));
connect(pPtyTex->_pImportTextureInfo.get(), SIGNAL(importationFinished()), this, SLOT(updateIHM()));
_groupBoxDoc->setFixedHeight(150);
}
void PtyWidgetTexture::launchGeneration()
{
Ptr<Workflow::TextureOptions> pTextureOptions = _textureGenerationOptions->getTextureOptions();
LM_DEBUG_PTR_CAST<PtyTexture>(getDataProxy()->getProperty())->generateTexture(pTextureOptions);
}
void PtyWidgetTexture::updateIHM()
{
updateInfo();
_textureGenerationOptions->optionsChanged();
}
void PtyWidgetTexture::updateInfo()
{
Ptr<PtyTexture> pPtyTex = LM_DEBUG_PTR_CAST<PtyTexture>(getDataProxy()->getProperty());
Ptr<Assets::Texture> pTexture = pPtyTex->_pImportTextureInfo->pTexture;
if (pTexture->getMipmapCount() == 0)
{
pTexture = pPtyTex->_pWorld->getRessourcesPool()->getTextureData(pPtyTex->_pImportTextureInfo->textureName);
}
int32 w = pTexture->getWidth();
int32 h = pTexture->getHeight();
float size = 0;
for (int32 iMipMap = 0; iMipMap<pTexture->getMipmapCount(); ++iMipMap)
{
Core::List<Assets::TextureImage> pImage = pTexture->getImage(iMipMap);
for (int32 iImage = 0; iImage < pImage.size(); iImage++)
{
size += pImage[iImage].getDataSize();
}
}
size /= 1048576.0f;
_width->setText("Width : " + StrToQStr(Core::toString(w)));
_height->setText("Height : " + StrToQStr(Core::toString(h)));
_size->setText("Size : " + StrToQStr(Core::toString(size, 3)) + " Mo");
pPtyTex->updateProperty();
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
}//namespace EPI |
.Title "RTC"
;
; Program: rtc.asm
; Author: Andrew Lynch
; Date: 22 Feb 2007
; Enviroment: TASM MS-DOS Z80 Cross Assembler source for CP/M
;
;[2011/8/11] VK5DG modified for N8
; Changed base address to $88
; Changed trickle charger value to 2k+2 diodes for DS1210s
;
;[2012/2/7] WBW modified to build for either
; traditional N8VEM/Zeta or N8 via conditionals
;
;[2013/12/29] WBW modified to build for MK4
;
;[2017/11/29] WBW modified to adjust to RTC in use dynamically
; using HBIOS platform detection
;
;[2018/11/8] v1.2 PMS Add boot option. Code optimization.
;
;[2019/06/21] v1.3 Finalized RC2014 Z180 support.
;
;[2019/08/11] v1.4 Support SCZ180 platform.
;
;[2020/02/02] v1.5 PMS Basic command line support
;
;[2020/05/15] v1.6 Added Warm Start option
;
; Constants
;
mask_data .EQU %10000000 ; RTC data line
mask_clk .EQU %01000000 ; RTC Serial Clock line
mask_rd .EQU %00100000 ; Enable data read from RTC
mask_rst .EQU %00010000 ; De-activate RTC reset line
PORT_SBC .EQU $70 ; RTC port for SBC/ZETA
PORT_N8 .EQU $88 ; RTC port for N8
PORT_MK4 .EQU $8A ; RTC port for MK4
PORT_RCZ80 .EQU $C0 ; RTC port for RC2014
PORT_RCZ180 .EQU $0C ; RTC port for RC2014
PORT_EZZ80 .EQU $C0 ; RTC port for EZZ80 (actually does not have one!!!)
PORT_SCZ180 .EQU $0C ; RTC port for SCZ180
PORT_DYNO .EQU $0C ; RTC port for DYNO
PORT_RCZ280 .EQU $C0 ; RTC port for RCZ280
BDOS .EQU 5 ; BDOS invocation vector
FCB .EQU 05CH ; Start of command line
;BID_BOOT .EQU $00
;HB_BNKCALL .EQU $FFF9
BF_SYSRESET .EQU $F0 ; RESTART SYSTEM
BF_SYSRES_INT .EQU $00 ; RESET HBIOS INTERNAL
BF_SYSRES_WARM .EQU $01 ; WARM START (RESTART BOOT LOADER)
BF_SYSRES_COLD .EQU $02 ; COLD START
;
; Program
;
.ORG 0100H
LOOP:
LD DE,MSG
LD C,09H ; CP/M write string to console call
CALL 0005H
; program starts here
CALL RTC_INIT ; Program initialization
CALL RTC_TOP_LOOP
LD C,00H ; CP/M system reset call - shut down
CALL 0005H
HALT ; This code is never reached
; function HEXSTR
; input number in A
; output upper nibble of number in ASCII in H
; output lower nibble of number in ASCII in L
; uses BC
;
; based on following algorithm:
;
; const
; hextab : string = ('0','1','2','3','4','5','6','7','8',
; '9','A','B','C','D','E','F');
;
; PROCEDURE hexstr(n: int): ^string;
; BEGIN
; n := n and 255;
; tmpstr[1] := hextab[n / 16];
; tmpstr[2] := hextab[n and 15];
; tmpstr[0] := #2;
; return @tmpstr;
; END;
HEXSTR:
PUSH BC ;SAVE BC
LD B,A
RLC A ;DO HIGH NIBBLE FIRST
RLC A
RLC A
RLC A
AND 0FH ;ONLY THIS NOW
ADD A,30H ;TRY A NUMBER
CP 3AH ;TEST IT
JR C,HEXSTR1 ;IF CY SET SAVE 'NUMBER' in H
ADD A,07H ;MAKE IT AN ALPHA
HEXSTR1:
LD H,A ;SAVE 'ALPHA' in H
LD A,B ;NEXT NIBBLE
AND 0FH ;JUST THIS
ADD A,30H ;TRY A NUMBER
CP 3AH ;TEST IT
JR C,HEXSTR2 ;IF CY SET SAVE 'NUMBER' in L
ADD A,07H ;MAKE IT ALPHA
HEXSTR2:
LD L,A ;SAVE 'ALPHA' in L
POP BC ;RESTORE BC
RET
;*****************************************************
;* GET K.B. DATA & MAKE IT 'HEX'
;*****************************************************
HEXIN:
PUSH BC ;SAVE BC REGS.
CALL NIBL ;DO A NIBBLE
RLC A ;MOVE FIRST BYTE UPPER NIBBLE
RLC A
RLC A
RLC A
LD B,A ;SAVE ROTATED BYTE
PUSH BC
CALL NIBL ;DO NEXT NIBBLE
POP BC
ADD A,B ;COMBINE NIBBLES IN ACC.
POP BC ;RESTORE BC
RET ;DONE
NIBL:
LD C,01H ; CP/M console input call
CALL 0005H ;GET K.B. DATA
CP 40H ;TEST FOR ALPHA
JR NC,ALPH
AND 0FH ;GET THE BITS
RET
ALPH:
AND 0FH ;GET THE BITS
ADD A,09H ;MAKE IT HEX A-F
RET
; function RTC_IN
;
; read a byte from RTC port, return in A
; NOTE: port address is dynamically set in RTC_INIT
RTC_IN:
INP .EQU $ + 1
IN A,($FF)
RET
; function RTC_OUT
;
; write a byte to RTC port, value in A
; NOTE: port address is dynamically set in RTC_INIT
RTC_OUT:
OUTP .EQU $ + 1
OUT ($FF),A
RET
; function RTC_BIT_DELAY
;
; based on following algorithm:
;
; { Make a short delay }
; PROCEDURE rtc_bit_delay;
; var
; x : int;
; BEGIN
; x := 3;
; END;
RTC_BIT_DELAY: ; purpose is to delay ~36 uS or 144 t-states at 4MHz
PUSH AF ; 11 t-states
LD A,07H ; 7 t-states ADJUST THE TIME 13h IS FOR 4 MHZ
RTC_BIT_DELAY1:
DEC A ; 4 t-states DEC COUNTER. 4 T-states = 1 uS.
JP NZ,RTC_BIT_DELAY1 ; 10 t-states JUMP TO PAUSELOOP2 IF A <> 0.
NOP ; 4 t-states
NOP ; 4 t-states
POP AF ; 10 t-states
RET ; 10 t-states (144 t-states total)
; function RTC_RESET
;
; based on following algorithm:
;
; { Output a RTC reset signal }
; PROCEDURE rtc_reset;
; BEGIN
; out(rtc_base,mask_data + mask_rd);
; rtc_bit_delay();
; rtc_bit_delay();
; out(rtc_base,mask_data + mask_rd + mask_rst);
; rtc_bit_delay();
; rtc_bit_delay();
; END;
;
RTC_RESET:
LD A,mask_data + mask_rd
;OUT (RTC),A
CALL RTC_OUT
CALL RTC_BIT_DELAY
CALL RTC_BIT_DELAY
LD A,mask_data + mask_rd + mask_rst
;OUT (RTC),A
CALL RTC_OUT
CALL RTC_BIT_DELAY
CALL RTC_BIT_DELAY
RET
; function RTC_RESET_ON
;
; based on following algorithm:
;
; { Assert RTC reset signal }
; PROCEDURE rtc_reset_on;
; BEGIN
; out(rtc_base,mask_data + mask_rd);
; rtc_bit_delay();
; rtc_bit_delay();
; END;
RTC_RESET_ON:
LD A,mask_data + mask_rd
;OUT (RTC),A
CALL RTC_OUT
CALL RTC_BIT_DELAY
CALL RTC_BIT_DELAY
RET
; function RTC_RESET_OFF
;
; based on following algorithm:
;
; { De-assert RTC reset signal }
; PROCEDURE rtc_reset_off;
; BEGIN
; out(rtc_base,mask_data + mask_rd + mask_rst);
; rtc_bit_delay();
; rtc_bit_delay();
; END;
RTC_RESET_OFF:
LD A,mask_data + mask_rd + mask_rst
;OUT (RTC),A
CALL RTC_OUT
CALL RTC_BIT_DELAY
CALL RTC_BIT_DELAY
RET
; function RTC_WR
; input value in C
; uses A
;
; PROCEDURE rtc_wr(n : int);
; var
; i : int;
; BEGIN
; for i := 0 while i < 8 do inc(i) loop
; if (n and 1) <> 0 then
; out(rtc_base,mask_rst + mask_data);
; rtc_bit_delay();
; out(rtc_base,mask_rst + mask_clk + mask_data);
; else
; out(rtc_base,mask_rst);
; rtc_bit_delay();
; out(rtc_base,mask_rst + mask_clk);
; end;
; rtc_bit_delay();
; n := shr(n,1);
; end loop;
; END;
RTC_WR:
XOR A ; set A=0 index counter of FOR loop
RTC_WR1:
PUSH AF ; save accumulator as it is the index counter in FOR loop
LD A,C ; get the value to be written in A from C (passed value to write in C)
BIT 0,A ; is LSB a 0 or 1?
JP Z,RTC_WR2 ; if it's a 0, handle it at RTC_WR2.
; LSB is a 1, handle it below
; setup RTC latch with RST and DATA high, SCLK low
LD A,mask_rst + mask_data
;OUT (RTC),A ; output to RTC latch
CALL RTC_OUT
CALL RTC_BIT_DELAY ; let it settle a while
; setup RTC with RST, DATA, and SCLK high
LD A,mask_rst + mask_clk + mask_data
;OUT (RTC),A ; output to RTC latch
CALL RTC_OUT
JP RTC_WR3 ; exit FOR loop
RTC_WR2:
; LSB is a 0, handle it below
LD A,mask_rst ; setup RTC latch with RST high, SCLK and DATA low
;OUT (RTC),A ; output to RTC latch
CALL RTC_OUT
CALL RTC_BIT_DELAY ; let it settle a while
; setup RTC with RST and SCLK high, DATA low
LD A,mask_rst + mask_clk
;OUT (RTC),A ; output to RTC latch
CALL RTC_OUT
RTC_WR3:
CALL RTC_BIT_DELAY ; let it settle a while
RRC C ; move next bit into LSB position for processing to RTC
POP AF ; recover accumulator as it is the index counter in FOR loop
INC A ; increment A in FOR loop (A=A+1)
CP $08 ; is A < $08 ?
JP NZ,RTC_WR1 ; No, do FOR loop again
RET ; Yes, end function and return
; function RTC_RD
; output value in C
; uses A
;
; function RTC_RD
;
; PROCEDURE rtc_rd(): int ;
; var
; i,n,mask : int;
; BEGIN
; n := 0;
; mask := 1;
; for i := 0 while i < 8 do inc(i) loop
; out(rtc_base,mask_rst + mask_rd);
; rtc_bit_delay();
; if (in(rtc_base) and #1) <> #0 then
; { Data = 1 }
; n := n + mask;
; else
; { Data = 0 }
; end;
; mask := shl(mask,1);
; out(rtc_base,mask_rst + mask_clk + mask_rd);
; rtc_bit_delay();
; end loop;
; return n;
; END;
RTC_RD:
XOR A ; set A=0 index counter of FOR loop
LD C,$00 ; set C=0 output of RTC_RD is passed in C
LD B,$01 ; B is mask value
RTC_RD1:
PUSH AF ; save accumulator as it is the index counter in FOR loop
; setup RTC with RST and RD high, SCLK low
LD A,mask_rst + mask_rd
;OUT (RTC),A ; output to RTC latch
CALL RTC_OUT
CALL RTC_BIT_DELAY ; let it settle a while
;IN A,(RTC) ; input from RTC latch
CALL RTC_IN ; input from RTC latch
BIT 0,A ; is LSB a 0 or 1?
JP Z,RTC_RD2 ; if LSB is a 1, handle it below
LD A,C
ADD A,B
LD C,A
; INC C
; if LSB is a 0, skip it (C=C+0)
RTC_RD2:
RLC B ; move input bit out of LSB position to save it in C
; setup RTC with RST, SCLK high, and RD high
LD A,mask_rst + mask_clk + mask_rd
;OUT (RTC),A ; output to RTC latch
CALL RTC_OUT
CALL RTC_BIT_DELAY ; let it settle
POP AF ; recover accumulator as it is the index counter in FOR loop
INC A ; increment A in FOR loop (A=A+1)
CP $08 ; is A < $08 ?
JP NZ,RTC_RD1 ; No, do FOR loop again
RET ; Yes, end function and return. Read RTC value is in C
; function RTC_WRITE
; input address in D
; input value in E
; uses A
;
; based on following algorithm:
;
; PROCEDURE rtc_write(address, value: int);
; BEGIN
; lock();
; rtc_reset_off();
; { Write command }
; rtc_wr(128 + shl(address and $3f,1));
; { Write data }
; rtc_wr(value and $ff);
; rtc_reset_on();
; unlock();
; END;
RTC_WRITE:
DI ; disable interrupts during critical section
CALL RTC_RESET_OFF ; turn off RTC reset
LD A,D ; bring into A the address from D
; AND $3F ; keep only bits 6 LSBs, discard 2 MSBs
AND %00111111 ; keep only bits 6 LSBs, discard 2 MSBs
RLC A ; rotate address bits to the left
; ADD A,$80 ; set MSB to one for DS1302 COMMAND BYTE (WRITE)
ADD A,%10000000 ; set MSB to one for DS1302 COMMAND BYTE (WRITE)
LD C,A ; RTC_WR expects write data (address) in reg C
CALL RTC_WR ; write address to DS1302
LD A,E ; start processing value
AND $FF ; seems unnecessary, probably delete since all values are 8-bit
LD C,A ; RTC_WR expects write data (value) in reg C
CALL RTC_WR ; write address to DS1302
CALL RTC_RESET_ON ; turn on RTC reset
EI
RET
; function RTC_READ
; input address in D
; output value in C
; uses A
;
; based on following algorithm
;
; PROCEDURE rtc_read(address: int): int;
; var
; n : int;
; BEGIN
; lock();
; rtc_reset_off();
; { Write command }
; rtc_wr(128 + shl(address and $3f,1) + 1);
; { Read data }
; n := rtc_rd();
; rtc_reset_on();
; unlock();
; return n;
; END;
RTC_READ:
DI ; disable interrupts during critical section
CALL RTC_RESET_OFF ; turn off RTC reset
LD A,D ; bring into A the address from D
AND $3F ; keep only bits 6 LSBs, discard 2 MSBs
RLC A ; rotate address bits to the left
ADD A,$81 ; set MSB to one for DS1302 COMMAND BYTE (READ)
LD C,A ; RTC_WR expects write data (address) in reg C
CALL RTC_WR ; write address to DS1302
CALL RTC_RD ; read value from DS1302 (value is in reg C)
CALL RTC_RESET_ON ; turn on RTC reset
EI
RET
; function RTC_WR_PROTECT
; input D (address) $07
; input E (value) $80
; uses A
;
; based on following algorithm
;
; PROCEDURE rtc_wr_protect;
; BEGIN
; rtc_write(7,128);
; END;
RTC_WR_PROTECT:
; LD D,$07
LD D,%00000111
; LD E,$80
LD E,%10000000
CALL RTC_WRITE
RET
; function RTC_WR_UNPROTECT
; input D (address) $07
; input E (value) $00
; uses A
;
; based on following algorithm
;
; PROCEDURE rtc_wr_unprotect;
; BEGIN
; rtc_write(7,0);
; END;
RTC_WR_UNPROTECT:
; LD D,$07
LD D,%00000111
; LD E,$00
LD E,%00000000
CALL RTC_WRITE
RET
; function RTC_GET_TIME
; input HL (memory address of buffer)
; uses A,C,D,E
;
; based on following algorithm
;
; PROCEDURE rtc_get_time(var buf: string);
; var
; n : int;
; BEGIN
; lock();
; rtc_reset_off();
; { Write command, burst read }
; rtc_wr(255 - 64);
; { Read seconds }
; n := rtc_rd(); 0
; buf[16] := char(((n / 16) and $07)) + '0';
; buf[17] := char((n and $0f)) + '0';
; { Read minutes }
; n := rtc_rd(); 1
; buf[13] := char(((n / 16) and $07)) + '0';
; buf[14] := char((n and $0f)) + '0';
; buf[15] := ':';
; { Read hours }
; n := rtc_rd(); 2
; buf[10] := char(((n / 16) and $03)) + '0';
; buf[11] := char((n and $0f)) + '0';
; buf[12] := ':';
; { Read date }
; n := rtc_rd(); 3
; buf[7] := char(((n / 16) and $03)) + '0';
; buf[8] := char((n and $0f)) + '0';
; buf[9] := ' ';
; { Read month }
; n := rtc_rd(); 4
; buf[4] := char(((n / 16) and $03)) + '0';
; buf[5] := char((n and $0f)) + '0';
; buf[6] := '-';
; { Read day }
; n := rtc_rd(); 5
; {
; buf[4] := char(((n / 16) and $03)) + '0';
; buf[4] := char((n and $0f)) + '0';
; }
; { Read year }
; n := rtc_rd(); 6
; buf[1] := char(((n / 16) and $0f)) + '0';
; buf[2] := char((n and $0f)) + '0';
; buf[3] := '-';
; length(buf) := 17;
; rtc_reset_on();
; unlock();
; END rtc_get_time;
RTC_GET_TIME:
DI ; disable interrupts during DS1302 read
CALL RTC_RESET_OFF ; turn of RTC reset
; { Write command, burst read }
LD C,%10111111 ; (255 - 64)
CALL RTC_WR ; send COMMAND BYTE (BURST READ) to DS1302
; { Read seconds }
CALL RTC_RD ; read value from DS1302, value is in Reg C
; digit 16
LD A,C ; put value output in Reg C into accumulator
RLC A
RLC A
RLC A
RLC A
AND $07
ADD A,'0'
LD (RTC_PRINT_BUFFER+15),A
; digit 17
LD A,C ; put value output in Reg C into accumulator
AND $0F
ADD A,'0'
LD (RTC_PRINT_BUFFER+16),A
; { Read minutes }
CALL RTC_RD ; read value from DS1302, value is in Reg C
; digit 13
LD A,C ; put value output in Reg C into accumulator
RLC A
RLC A
RLC A
RLC A
AND $07
ADD A,'0'
LD (RTC_PRINT_BUFFER+12),A
; digit 14
LD A,C ; put value output in Reg C into accumulator
AND $0F
ADD A,'0'
LD (RTC_PRINT_BUFFER+13),A
; digit 15
LD A,':'
LD (RTC_PRINT_BUFFER+14),A
; { Read hours }
CALL RTC_RD ; read value from DS1302, value is in Reg C
; digit 10
LD A,C ; put value output in Reg C into accumulator
RLC A
RLC A
RLC A
RLC A
AND $03
ADD A,'0'
LD (RTC_PRINT_BUFFER+09),A
; digit 11
LD A,C ; put value output in Reg C into accumulator
AND $0F
ADD A,'0'
LD (RTC_PRINT_BUFFER+10),A
; digit 12
LD A,':'
LD (RTC_PRINT_BUFFER+11),A
; { Read date }
CALL RTC_RD ; read value from DS1302, value is in Reg C
; digit 07
LD A,C ; put value output in Reg C into accumulator
RLC A
RLC A
RLC A
RLC A
AND $03
ADD A,'0'
LD (RTC_PRINT_BUFFER+06),A
; digit 08
LD A,C ; put value output in Reg C into accumulator
AND $0F
ADD A,'0'
LD (RTC_PRINT_BUFFER+07),A
; digit 09
LD A,' '
LD (RTC_PRINT_BUFFER+08),A
; { Read month }
CALL RTC_RD ; read value from DS1302, value is in Reg C
; digit 04
LD A,C ; put value output in Reg C into accumulator
RLC A
RLC A
RLC A
RLC A
AND $03
ADD A,'0'
LD (RTC_PRINT_BUFFER+03),A
; digit 05
LD A,C ; put value output in Reg C into accumulator
AND $0F
ADD A,'0'
LD (RTC_PRINT_BUFFER+04),A
; digit 06
LD A,'-'
LD (RTC_PRINT_BUFFER+05),A
; { Read day }
CALL RTC_RD ; read value from DS1302, value is in Reg C
; digit 04
; LD A,C ; put value output in Reg C into accumulator
; RLC A
; RLC A
; RLC A
; RLC A
; AND $03
; ADD A,'0'
; LD (RTC_PRINT_BUFFER+03),A
; digit 04
; LD A,C ; put value output in Reg C into accumulator
; AND $0F
; ADD A,'0'
; LD (RTC_PRINT_BUFFER+03),A
; add special code to put "DAY" value at end of string until better solution known
; digit 18
LD A,'-'
LD (RTC_PRINT_BUFFER+17),A
; digit 19
LD A,C ; put value output in Reg C into accumulator
RLC A
RLC A
RLC A
RLC A
AND $0F
ADD A,'0'
LD (RTC_PRINT_BUFFER+18),A
; digit 20
LD A,C ; put value output in Reg C into accumulator
AND $0F
ADD A,'0'
LD (RTC_PRINT_BUFFER+19),A
; { Read year }
CALL RTC_RD ; read value from DS1302, value is in Reg C
; digit 01
LD A,C ; put value output in Reg C into accumulator
RLC A
RLC A
RLC A
RLC A
AND $0F
ADD A,'0'
LD (RTC_PRINT_BUFFER+00),A
; digit 02
LD A,C ; put value output in Reg C into accumulator
AND $0F
ADD A,'0'
LD (RTC_PRINT_BUFFER+01),A
; digit 03
LD A,'-'
LD (RTC_PRINT_BUFFER+02),A
CALL RTC_RESET_ON ; turn RTC reset back on
EI ; re-enable interrupts
RET ; Yes, end function and return
; function RTC_SET_NOW
; uses A, D, E
;
; based on following algorithm
;
; { Set time to 96-02-18 19:43:00 }
; PROCEDURE rtc_set_now;
; BEGIN
; rtc_wr_unprotect();
; { Set seconds }
; rtc_write(0,0);
; { Set minutes }
; rtc_write(1,$43);
; { Set hours }
; rtc_write(2,$19);
; { Set date }
; rtc_write(3,$18);
; { Set month }
; rtc_write(4,$02);
; { Set day }
; rtc_write(5,$07);
; { Set year }
; rtc_write(6,$96);
; rtc_wr_protect();
; END;
RTC_SET_NOW:
; set time to 07-02-23 19:45:00-05 <-Friday
CALL RTC_WR_UNPROTECT
; seconds
LD D,$00
LD A,(SECONDS)
LD E,A
CALL RTC_WRITE
; minutes
LD D,$01
LD A,(MINUTES)
LD E,A
CALL RTC_WRITE
; hours
LD D,$02
LD A,(HOURS)
LD E,A
CALL RTC_WRITE
; date
LD D,$03
LD A,(DATE)
LD E,A
CALL RTC_WRITE
; month
LD D,$04
LD A,(MONTH)
LD E,A
CALL RTC_WRITE
; day
LD D,$05
LD A,(DAY)
LD E,A
CALL RTC_WRITE
; year
LD D,$06
LD A,(YEAR)
LD E,A
CALL RTC_WRITE
CALL RTC_WR_PROTECT
RET
RTC_INIT_NOW:
; set time to Current Time
; year
LD DE,RTC_TOP_LOOP1_INIT_YEAR
LD C,09H ; CP/M write string to console call
CALL 0005H
CALL HEXIN
LD (YEAR),A
; month
LD DE,RTC_TOP_LOOP1_INIT_MONTH
LD C,09H ; CP/M write string to console call
CALL 0005H
CALL HEXIN
LD (MONTH),A
; date
LD DE,RTC_TOP_LOOP1_INIT_DATE
LD C,09H ; CP/M write string to console call
CALL 0005H
CALL HEXIN
LD (DATE),A
; hours
LD DE,RTC_TOP_LOOP1_INIT_HOURS
LD C,09H ; CP/M write string to console call
CALL 0005H
CALL HEXIN
LD (HOURS),A
; minutes
LD DE,RTC_TOP_LOOP1_INIT_MINUTES
LD C,09H ; CP/M write string to console call
CALL 0005H
CALL HEXIN
LD (MINUTES),A
; seconds
LD DE,RTC_TOP_LOOP1_INIT_SECONDS
LD C,09H ; CP/M write string to console call
CALL 0005H
CALL HEXIN
LD (SECONDS),A
; day
LD DE,RTC_TOP_LOOP1_INIT_DAY
LD C,09H ; CP/M write string to console call
CALL 0005H
CALL HEXIN
LD (DAY),A
RET
; function RTC_RESTART
;
; uses A, D, E,
;
; based on the following algorithm
;
; { Restart clock, set seconds to 00 }
; PROCEDURE rtc_restart;
; BEGIN
; rtc_wr_unprotect();
; { Set seconds }
; rtc_write(0,0);
; rtc_wr_protect();
; END;
RTC_RESTART:
CALL RTC_WR_UNPROTECT
LD D,$00
LD E,$00
CALL RTC_WRITE
CALL RTC_WR_PROTECT
RET
; function RTC_CHARGE_ENABLE
;
; uses A, D, E
;
; based on following algorithm
;
; PROCEDURE rtc_charge_enable;
; BEGIN
; rtc_wr_unprotect();
; { Enable trickle charger, 2kohm, 1 diode }
; rtc_write(8,$A5);
; rtc_wr_protect();
; END;
;
; Trickle Charge Current:
;
; Imax = (5.0V - (0.7 * Ndiode)) / R
; (5.0 - (0.7 * 1)) / 2000 = .00215A = 2.15 milliamps
; (5.0 - (0.7 * 1)) / 8000 = 0.0005375A = .537 milliamps
;
RTC_CHARGE_ENABLE
CALL RTC_WR_UNPROTECT
LD D,$08
LD E,$A5
CALL RTC_WRITE
CALL RTC_WR_PROTECT
RET
; function RTC_CHARGE_DISABLE
;
; uses A, D, E
;
; based on following algorithm
;
; PROCEDURE rtc_charge_disable;
; BEGIN
; rtc_wr_unprotect();
; { Disable trickle charger}
; rtc_write(8,$00);
; rtc_wr_protect();
; END;
RTC_CHARGE_DISABLE
CALL RTC_WR_UNPROTECT
LD D,$08
LD E,$00
CALL RTC_WRITE
CALL RTC_WR_PROTECT
RET
; function TEST_BIT_DELAY
;
; based on the following algorithm
;
;
; PROCEDURE test_bit_delay();
; var
; i,t0,t1 : int;
; BEGIN
; putln("Testing bit delay...");
; t0 := sys_time();
; for i := 0 while i < 1000 do inc(i) loop
; rtc_bit_delay();
; end loop;
; t1 := sys_time();
; putln(i," rtc_bit_delay calls took ",t1-t0," ms.");
; END;
RTC_TEST_BIT_DELAY
LD DE,TESTING_BIT_DELAY_MSG
LD C,09H ; CP/M write string to console call
CALL 0005H
LD C,01H ; CP/M console input call
CALL 0005H
; test should take approximately 43 seconds based on the following code analysis
; of Z80 T-states on a 4 MHz processor
; =(4+15*(7+255*(7+255*(17+144+4+10)+4+10)+10)+7)/4/1000000
LD B,$0F
PAUSE:
LD C,$FF
PAUSE1:
LD A,$FF ; ADJUST THE TIME 13h IS FOR 4 MHZ
PAUSE2:
CALL RTC_BIT_DELAY ; CAUSE 36uS DELAY
DEC A ; DEC COUNTER.
JP NZ,PAUSE2 ; JUMP TO PAUSE2 IF A <> 0.
DEC C ; DEC COUNTER
JP NZ,PAUSE1 ; JUMP TO PAUSE1 IF C <> 0.
DJNZ PAUSE ; JUMP TO PAUSE IF B <> 0.
LD DE,TESTING_BIT_DELAY_OVER
LD C,09H ; CP/M write string to console call
CALL 0005H
RET
; function RTC_HELP
;
; based on following algorithm
;
; PROCEDURE help();
; BEGIN
; putln();
; putln("rtc: ",version);
; putln("rtc: Commands: (E)xit (T)ime st(A)rt (S)et (R)aw (L)oop (C)harge (N)ocharge (H)elp");
; END;
RTC_HELP
LD DE,RTC_HELP_MSG
LD C,09H ; CP/M write string to console call
CALL 0005H
RET
; function RTC_INIT
;
; Determine RTC port based on hardware platform
; and record it dynamically in code (see RTC_IN and RTC_OUT).
;
RTC_INIT:
CALL IDBIO ; Id BIOS, 1=HBIOS, 2=UBIOS
DEC A ; Test for HBIOS
JR Z,HINIT ; Do HBIOS setup
DEC A ; Test for UBIOS
JR Z,UINIT ; Do UBIOS setup
;
; Neither UNA nor RomWBW
LD DE,BIOERR ; BIOS error message
LD C,9 ; BDOS string display function
CALL BDOS ; Do it
JP 0 ; Bail out!
;
HINIT:
;
; Display RomWBW notification string
LD DE,HBTAG ; BIOS notification string
LD C,9 ; BDOS string display function
CALL BDOS ; Do it
;
; Get platform id from RomWBW HBIOS
LD B,0F1H ; HBIOS VER function 0xF1
LD C,0 ; Required reserved value
RST 08 ; Do it, L := Platform ID
LD A,L ; Move to A
;
; Assign correct port to C
LD C,PORT_SBC
LD DE,PLT_SBC
CP $01 ; SBC
JR Z,RTC_INIT2
CP $02 ; ZETA
JR Z,RTC_INIT2
CP $03 ; ZETA 2
JR Z,RTC_INIT2
;
LD C,PORT_N8
LD DE,PLT_N8
CP $04 ; N8
JR Z,RTC_INIT2
;
LD C,PORT_MK4
LD DE,PLT_MK4
CP $05 ; Mark IV
JR Z,RTC_INIT2
;
LD C,PORT_RCZ80
LD DE,PLT_RCZ80
CP $07 ; RC2014 w/ Z80
JR Z,RTC_INIT2
;
LD C,PORT_RCZ180
LD DE,PLT_RCZ180
CP $08 ; RC2014 w/ Z180
JR Z,RTC_INIT2
;
LD C,PORT_EZZ80
LD DE,PLT_EZZ80
CP $09 ; Easy Z80
JR Z,RTC_INIT2
;
LD C,PORT_SCZ180
LD DE,PLT_SCZ180
CP $0A ; SCZ180
JR Z,RTC_INIT2
;
LD C,PORT_DYNO
LD DE,PLT_DYNO
CP 11 ; DYNO
JR Z,RTC_INIT2
;
LD C,PORT_RCZ280
LD DE,PLT_RCZ280
CP 12 ; RCZ280
JR Z,RTC_INIT2
;
; Unknown platform
LD DE,PLTERR ; BIOS error message
LD C,9 ; BDOS string display function
CALL BDOS ; Do it
JP 0 ; Bail out!
;
UINIT:
;; Display UNA notification string
;LD DE,UBTAG ; BIOS notification string
;LD C,9 ; BDOS string display function
;CALL BDOS ; Do it
;
; Notify UNA not supported at present
LD DE,UBERR ; BIOS not support message
LD C,9 ; BDOS string display function
CALL BDOS ; Do it
JP 0 ; Bail out!
RTC_INIT2:
; Record port number in code routines
LD A,C
LD (INP),A
LD (OUTP),A
;
; Display platform
LD C,9 ; BDOS string display function
CALL BDOS ; Do it
RET
;
; Identify active BIOS. RomWBW HBIOS=1, UNA UBIOS=2, else 0
;
IDBIO:
;
; Check for UNA (UBIOS)
LD A,(0FFFDH) ; fixed location of UNA API vector
CP 0C3H ; jp instruction?
JR NZ,IDBIO1 ; if not, not UNA
LD HL,(0FFFEH) ; get jp address
LD A,(HL) ; get byte at target address
CP 0FDH ; first byte of UNA push ix instruction
JR NZ,IDBIO1 ; if not, not UNA
INC HL ; point to next byte
LD A,(HL) ; get next byte
CP 0E5H ; second byte of UNA push ix instruction
JR NZ,IDBIO1 ; if not, not UNA, check others
LD A,2 ; UNA BIOS id = 2
RET ; and done
;
IDBIO1:
; Check for RomWBW (HBIOS)
LD HL,(0FFFEH) ; HL := HBIOS ident location
LD A,'W' ; First byte of ident
CP (HL) ; Compare
JR NZ,IDBIO2 ; Not HBIOS
INC HL ; Next byte of ident
LD A,~'W' ; Second byte of ident
CP (HL) ; Compare
JR NZ,IDBIO2 ; Not HBIOS
LD A,1 ; HBIOS BIOS id = 1
RET ; and done
;
IDBIO2:
; No idea what this is
XOR A ; Setup return value of 0
RET ; and done
; function RTC_TOP_LOOP
;
; based on following algorithm
;
; PROCEDURE toploop();
; var
; err,i,n,fd : int;
; BEGIN
; putln();
; help();
; rtc_reset_on();
; hold(100);
; test_bit_delay();
; rtc_charge_disable();
; putln("rtc: trickle charger disabled.");
; loop
; put("rtc>");
; gets(line);
; if line = "exit" then
; putln("Bye.");
; exit(0);
; elsif line = "charge" then
; putln("Trickle charger enabled.");
; rtc_charge_enable();
; elsif line = "nocharge" then
; putln("Trickle charger disabled.");
; rtc_charge_disable();
; elsif line = "start" then
; rtc_restart();
; putln("Restarting RTC");
; elsif line = "t" then
; rtc_get_time(line);
; putln("Current time: ",line);
; elsif line = "raw" then
; putln();
; putln("Raw read loop, hit any key to stop...");
; while read(0,@n,1 + RD_NOWAIT) = 0 loop
; put(#13,"sec=",hexstr(rtc_read(0))^);
; put(" min=",hexstr(rtc_read(1))^);
; hold(500);
; end loop;
; elsif line = "loop" then
; putln();
; putln("Clock loop, hit any key to stop...");
; while read(0,@n,1 + RD_NOWAIT) = 0 loop
; rtc_get_time(line);
; put(#13,line);
; hold(200);
; end loop;
; elsif line = "set" then
; putln("Setting RTC time to 96-02-18 19:43:00");
; rtc_set_now();
; elsif (line = "help") or (line = "?") then
; help();
; elsif length(line) <> 0 then
; putln("You typed: """,line,"""");
; end;
; end loop;
; END toploop;
; Note:above code is not fully in sync with current menu code
RTC_TOP_LOOP:
CALL RTC_RESET_ON
CALL RTC_BIT_DELAY
CALL RTC_BIT_DELAY
CALL RTC_BIT_DELAY
LD A,(FCB+1) ; If there a command line tail
CP '/' ; get the command and feed it
LD A,(FCB+2) ; into the input stream
JR Z,RTC_UCL
LD DE,CRLF_MSG
LD C,09H ; CP/M write string to console call
CALL 0005H
CALL RTC_HELP
RTC_TOP_LOOP_1:
LD DE,RTC_TOP_LOOP1_PROMPT
LD C,09H ; CP/M write string to console call
CALL 0005H
LD C,01H ; CP/M console input call
CALL 0005H
RTC_UCL:
AND %01011111 ; handle lower case responses to menu
CP 'L'
JP Z,RTC_TOP_LOOP_LOOP
CP 'R'
JP Z,RTC_TOP_LOOP_RAW
CP 'G'
JP Z,RTC_TOP_LOOP_GET
CP 'P'
JP Z,RTC_TOP_LOOP_PUT
CP 'E'
; JP Z,RTC_TOP_LOOP_EXIT
RET Z
CP 'H'
JP Z,RTC_TOP_LOOP_HELP
CP 'D'
JP Z,RTC_TOP_LOOP_DELAY
CP 'B'
JP Z,RTC_TOP_LOOP_BOOT
CP 'W'
JP Z,RTC_TOP_LOOP_WARMSTART
CP 'C'
JP Z,RTC_TOP_LOOP_CHARGE
CP 'N'
JP Z,RTC_TOP_LOOP_NOCHARGE
CP 'A'
JP Z,RTC_TOP_LOOP_START
CP 'S'
JP Z,RTC_TOP_LOOP_SET
CP 'I'
JP Z,RTC_TOP_LOOP_INIT
CP 'T'
JP Z,RTC_TOP_LOOP_TIME
LD DE,CRLF_MSG
LD C,09H ; CP/M write string to console call
CALL 0005H
JR RTC_TOP_LOOP_1
;RTC_TOP_LOOP_EXIT:
; RET
RTC_TOP_LOOP_HELP:
CALL RTC_HELP
JP RTC_TOP_LOOP_1
RTC_TOP_LOOP_DELAY:
CALL RTC_TEST_BIT_DELAY
JP RTC_TOP_LOOP_1
RTC_TOP_LOOP_BOOT:
LD DE,BOOTMSG ; BOOT message
LD C,9 ; BDOS string display function
CALL BDOS ; Do it
; WAIT FOR MESSAGE TO BE DISPLAYED
LD HL,10000
DELAY_LOOP: ; LOOP IS 26TS
DEC HL ; 6TS
LD A,H ; 4TS
OR L ; 4TS
JR NZ,DELAY_LOOP ; 12TS
; RESTART SYSTEM FROM ROM BANK 0, ADDRESS $0000
LD B,BF_SYSRESET ; SYSTEM RESTART
LD C,BF_SYSRES_COLD ; COLD START
CALL $FFF0 ; CALL HBIOS
RTC_TOP_LOOP_WARMSTART:
LD B,BF_SYSRESET ; SYSTEM RESTART
LD C,BF_SYSRES_WARM ; WARM START
CALL $FFF0 ; CALL HBIOS
RTC_TOP_LOOP_CHARGE:
LD DE,RTC_TOP_LOOP1_CHARGE
LD C,09H ; CP/M write string to console call
CALL 0005H
CALL RTC_CHARGE_ENABLE
LD A,(FCB+1) ; If we came from the
CP '/' ; command line
RET Z ; exit back to CP/M
JP RTC_TOP_LOOP_1
RTC_TOP_LOOP_NOCHARGE:
LD DE,RTC_TOP_LOOP1_NOCHARGE
LD C,09H ; CP/M write string to console call
CALL 0005H
CALL RTC_CHARGE_DISABLE
LD A,(FCB+1) ; If we came from the
CP '/' ; command line
RET Z ; exit back to CP/M
JP RTC_TOP_LOOP_1
RTC_TOP_LOOP_START:
LD DE,RTC_TOP_LOOP1_START
LD C,09H ; CP/M write string to console call
CALL 0005H
CALL RTC_RESTART
JP RTC_TOP_LOOP_1
RTC_TOP_LOOP_SET:
LD DE,RTC_TOP_LOOP1_SET
LD C,09H ; CP/M write string to console call
CALL 0005H
CALL RTC_SET_NOW
JP RTC_TOP_LOOP_1
RTC_TOP_LOOP_INIT:
LD DE,RTC_TOP_LOOP1_INIT
LD C,09H ; CP/M write string to console call
CALL 0005H
CALL RTC_INIT_NOW
JP RTC_TOP_LOOP_1
RTC_TOP_LOOP_TIME:
LD DE,RTC_TOP_LOOP1_TIME
LD C,09H ; CP/M write string to console call
CALL 0005H
CALL RTC_GET_TIME
LD DE,RTC_PRINT_BUFFER
LD C,09H ; CP/M write string to console call
CALL 0005H
LD A,(FCB+1) ; If we came from the
CP '/' ; command line
RET Z ; exit back to CP/M
JP RTC_TOP_LOOP_1
RTC_TOP_LOOP_RAW:
LD DE,RTC_TOP_LOOP1_RAW
LD C,09H ; CP/M write string to console call
CALL 0005H
RTC_TOP_LOOP_RAW1:
; { Read seconds }
LD D,$00 ; seconds register in DS1302
CALL RTC_READ ; read value from DS1302, value is in Reg C
; digit 16
LD A,C ; put value output in Reg C into accumulator
RLC A
RLC A
RLC A
RLC A
AND $07
ADD A,'0'
LD (RTC_PRINT_BUFFER+15),A
; digit 17
LD A,C ; put value output in Reg C into accumulator
AND $0F
ADD A,'0'
LD (RTC_PRINT_BUFFER+16),A
; { Read minutes }
LD D,$01 ; minutes register in DS1302
CALL RTC_READ ; read value from DS1302, value is in Reg C
; digit 13
LD A,C ; put value output in Reg C into accumulator
RLC A
RLC A
RLC A
RLC A
AND $07
ADD A,'0'
LD (RTC_PRINT_BUFFER+12),A
; digit 14
LD A,C ; put value output in Reg C into accumulator
AND $0F
ADD A,'0'
LD (RTC_PRINT_BUFFER+13),A
; digit 15
LD A,':'
LD (RTC_PRINT_BUFFER+14),A
; digits 1-12 and 18-20 are spaces
LD A,' ' ; space
LD (RTC_PRINT_BUFFER+19),A
LD (RTC_PRINT_BUFFER+18),A
LD (RTC_PRINT_BUFFER+17),A
LD (RTC_PRINT_BUFFER+11),A
LD (RTC_PRINT_BUFFER+10),A
LD (RTC_PRINT_BUFFER+09),A
LD (RTC_PRINT_BUFFER+08),A
LD (RTC_PRINT_BUFFER+07),A
LD (RTC_PRINT_BUFFER+06),A
LD (RTC_PRINT_BUFFER+05),A
LD (RTC_PRINT_BUFFER+04),A
LD (RTC_PRINT_BUFFER+03),A
LD (RTC_PRINT_BUFFER+02),A
LD (RTC_PRINT_BUFFER+01),A
LD (RTC_PRINT_BUFFER+00),A
LD DE,RTC_PRINT_BUFFER
LD C,09H ; CP/M write string to console call
CALL 0005H
LD C,01H ; CP/M console input call
CALL 0005H
CP ' ' ; space
JP Z,RTC_TOP_LOOP_RAW1
JP RTC_TOP_LOOP_1
RTC_TOP_LOOP_LOOP:
LD DE,RTC_TOP_LOOP1_LOOP
LD C,09H ; CP/M write string to console call
CALL 0005H
RTC_TOP_LOOP_LOOP1:
CALL RTC_GET_TIME
LD DE,RTC_PRINT_BUFFER
LD C,09H ; CP/M write string to console call
CALL 0005H
LD C,01H ; CP/M console input call
CALL 0005H
CP ' '
JP Z,RTC_TOP_LOOP_LOOP1
JP RTC_TOP_LOOP_1
RTC_TOP_LOOP_PUT:
LD A,$01 ; set PUT as true
LD (GET_PUT),A
RTC_TOP_LOOP_GET:
LD DE,RTC_TOP_LOOP1_GET
LD C,09H ; CP/M write string to console call
CALL 0005H
CALL HEXIN ; read NVRAM address
LD (PUT_ADR),A ; store for possible PUT later
; { Read NVRAM address }
LD D,A ; seconds register in DS1302
CALL RTC_READ ; read value from DS1302, value is in Reg C
; first digit
LD A,C ; put value output in Reg C into accumulator
RLC A
RLC A
RLC A
RLC A
AND $0F
CP 0AH ;TEST FOR NUMERIC & convert to ASCII
JR C,NUM1 ;if not ALPHA, its numeric and skip
ADD A,$07
NUM1: ADD A,'0'
LD (RTC_GET_BUFFER),A
; second digit
LD A,C ; put value output in Reg C into accumulator
AND $0F
CP 0AH ;TEST FOR NUMERIC & convert to ASCII
JR C,NUM2 ;if not ALPHA, its numeric and skip
ADD A,$07
NUM2: ADD A,'0'
LD (RTC_GET_BUFFER+1),A
LD DE,CRLF_MSG
LD C,09H ; CP/M write string to console call
CALL 0005H
LD DE,RTC_GET_BUFFER
LD C,09H ; CP/M write string to console call
CALL 0005H
LD A,(GET_PUT) ; check if GET or PUT mode
CP $00
JP Z,RTC_GET_PUT_EXIT ; if GET mode, exit
LD DE,RTC_TOP_LOOP1_PUT
LD C,09H ; CP/M write string to console call
CALL 0005H
; { Write NVRAM address }
CALL RTC_WR_UNPROTECT
CALL HEXIN ; read NVRAM address
LD E,A ; new data for NVRAM register in DS1302
LD A,(PUT_ADR)
LD D,A ; load address from before
CALL RTC_WRITE ; read value from DS1302, value is in Reg C
CALL RTC_WR_PROTECT
RTC_GET_PUT_EXIT:
LD A,$00 ; reset GET mode
LD (GET_PUT),A
JP RTC_TOP_LOOP_1
;
; Text Strings
;
MSG:
.TEXT "Start RTC Program"
CRLF_MSG:
.DB 0Ah, 0Dh ; line feed and carriage return
.DB "$" ; Line terminator
TESTING_BIT_DELAY_MSG:
.DB 0Ah, 0Dh ; line feed and carriage return
.TEXT "Testing bit delay. Successful test is ~43 sec."
.DB 0Ah, 0Dh ; line feed and carriage return
.TEXT "Start clock and press space bar."
.DB 0Ah, 0Dh ; line feed and carriage return
.DB "$" ; Line terminator
TESTING_BIT_DELAY_OVER:
.DB 0Ah, 0Dh ; line feed and carriage return
.TEXT "Test complete. Stop clock."
.DB 0Ah, 0Dh ; line feed and carriage return
.DB "$" ; Line terminator
RTC_HELP_MSG:
.DB 0Ah, 0Dh ; line feed and carriage return
.TEXT "RTC: Version 1.5"
.DB 0Ah, 0Dh ; line feed and carriage return
.TEXT "Commands: E)xit T)ime st(A)rt S)et R)aw L)oop C)harge N)ocharge D)elay I)nit G)et P)ut B)oot W)arm-start H)elp"
.DB 0Ah, 0Dh ; line feed and carriage return
.DB "$" ; Line terminator
RTC_TOP_LOOP1_PROMPT:
.DB 0Ah, 0Dh ; line feed and carriage return
.TEXT "RTC>"
.DB "$" ; Line terminator
RTC_TOP_LOOP1_CHARGE:
.DB 0Ah, 0Dh ; line feed and carriage return
.TEXT "Trickle charger enabled."
.DB 0Ah, 0Dh ; line feed and carriage return
.DB "$" ; Line terminator
RTC_TOP_LOOP1_NOCHARGE:
.DB 0Ah, 0Dh ; line feed and carriage return
.TEXT "Trickle charger disabled."
.DB 0Ah, 0Dh ; line feed and carriage return
.DB "$" ; Line terminator
RTC_TOP_LOOP1_START:
.DB 0Ah, 0Dh ; line feed and carriage return
.TEXT "Restart RTC."
.DB 0Ah, 0Dh ; line feed and carriage return
.DB "$" ; Line terminator
RTC_TOP_LOOP1_TIME:
.DB 0Ah, 0Dh ; line feed and carriage return
.TEXT "Current time: "
.DB "$" ; Line terminator
RTC_TOP_LOOP1_RAW:
.DB 0Ah, 0Dh ; line feed and carriage return
.TEXT "Raw read Loop. Press SPACE BAR for next."
.DB 0Ah, 0Dh ; line feed and carriage return
.DB "$" ; Line terminator
RTC_TOP_LOOP1_LOOP:
.DB 0Ah, 0Dh ; line feed and carriage return
.TEXT "Clock Loop. Press SPACE BAR for next."
.DB 0Ah, 0Dh ; line feed and carriage return
.DB "$" ; Line terminator
RTC_TOP_LOOP1_SET:
.DB 0Ah, 0Dh ; line feed and carriage return
.TEXT "Set RTC time."
.DB 0Ah, 0Dh ; line feed and carriage return
.DB "$" ; Line terminator
RTC_TOP_LOOP1_INIT:
.DB 0Ah, 0Dh ; line feed and carriage return
.TEXT "Init date/time."
.DB 0Ah, 0Dh ; line feed and carriage return
.DB "$" ; Line terminator
RTC_TOP_LOOP1_GET:
.DB 0Ah, 0Dh ; line feed and carriage return
.TEXT "Get NVRAM addr:"
.DB "$" ; Line terminator
RTC_TOP_LOOP1_PUT:
.DB 0Ah, 0Dh ; line feed and carriage return
.TEXT "NVRAM data:"
.DB "$" ; Line terminator
RTC_TOP_LOOP1_INIT_SECONDS:
.DB 0Ah, 0Dh ; line feed and carriage return
.TEXT "SECONDS:"
.DB "$" ; Line terminator
RTC_TOP_LOOP1_INIT_MINUTES:
.DB 0Ah, 0Dh ; line feed and carriage return
.TEXT "MINUTES:"
.DB "$" ; Line terminator
RTC_TOP_LOOP1_INIT_HOURS:
.DB 0Ah, 0Dh ; line feed and carriage return
.TEXT "HOURS:"
.DB "$" ; Line terminator
RTC_TOP_LOOP1_INIT_DATE:
.DB 0Ah, 0Dh ; line feed and carriage return
.TEXT "DATE:"
.DB "$" ; Line terminator
RTC_TOP_LOOP1_INIT_MONTH:
.DB 0Ah, 0Dh ; line feed and carriage return
.TEXT "MONTH:"
.DB "$" ; Line terminator
RTC_TOP_LOOP1_INIT_DAY:
.DB 0Ah, 0Dh ; line feed and carriage return
.TEXT "DAY:"
.DB "$" ; Line terminator
RTC_TOP_LOOP1_INIT_YEAR:
.DB 0Ah, 0Dh ; line feed and carriage return
.TEXT "YEAR:"
.DB "$" ; Line terminator
RTC_PRINT_BUFFER:
.FILL 20,0 ; Buffer for formatted date & time to print
.DB 0Ah, 0Dh ; line feed and carriage return
.DB "$" ; line terminator
RTC_GET_BUFFER:
.FILL 2,0 ; Buffer for formatted NVRAM data to print
.DB 0Ah, 0Dh ; line feed and carriage return
.DB "$" ; line terminator
BIOERR .TEXT "\r\nUnknown BIOS, aborting...\r\n$"
PLTERR .TEXT "\r\n\r\nUnknown/unsupported hardware platform, aborting...\r\n$"
UBERR .TEXT "\r\nUNA UBIOS is not currently supported, aborting...\r\n$"
HBTAG .TEXT "RomWBW HBIOS$"
UBTAG .TEXT "UNA UBIOS"
BOOTMSG .TEXT "\r\n\r\nRebooting...$"
PLT_SBC .TEXT ", SBC/Zeta RTC Latch Port 0x70\r\n$"
PLT_N8 .TEXT ", N8 RTC Latch Port 0x88\r\n$"
PLT_MK4 .TEXT ", Mark 4 RTC Latch Port 0x8A\r\n$"
PLT_RCZ80 .TEXT ", RC2014 Z80 RTC Module Latch Port 0xC0\r\n$"
PLT_RCZ180 .TEXT ", RC2014 Z180 RTC Module Latch Port 0x0C\r\n$"
PLT_EZZ80 .TEXT ", Easy Z80 RTC Module Latch Port 0xC0\r\n$"
PLT_SCZ180 .TEXT ", SC Z180 RTC Module Latch Port 0x0C\r\n$"
PLT_DYNO .TEXT ", DYNO RTC Module Latch Port 0x0C\r\n$"
PLT_RCZ280 .TEXT ", RC2014 Z280 RTC Module Latch Port 0xC0\r\n$"
;
; Generic FOR-NEXT loop algorithm
;
; LD A,$00 ; set A=0 index counter of FOR loop
;FOR_LOOP:
; PUSH AF ; save accumulator as it is the index counter in FOR loop
; { contents of FOR loop here } ; setup RTC with RST and RD high, SCLK low
; POP AF ; recover accumulator as it is the index counter in FOR loop
; INC A ; increment A in FOR loop (A=A+1)
; CP $08 ; is A < $08 ?
; JP NZ,FOR_LOOP ; No, do FOR loop again
; RET ; Yes, end function and return. Read RTC value is in C
YEAR .DB $18
MONTH .DB $11
DATE .DB $08
HOURS .DB $00
MINUTES .DB $00
SECONDS .DB $00
DAY .DB $05
GET_PUT .DB $00
PUT_ADR .DB 0
.END
|
// Copyright 2020 Zhafyarov Oleg
#include <mpi.h>
#include <vector>
#include <random>
#include <ctime>
#include "../../../modules/task_1/zhafyarov_o_vector_sum/vector_sum.h"
std::vector <int> GetRandomVector(int size) {
std::vector<int> vec_tmp(size);
std::mt19937 gen;
gen.seed(static_cast<unsigned int>(time(0)));
for (int i = 0; i < size; i++) {
vec_tmp[i] = gen() % 50;
}
return vec_tmp;
}
int GetParallelSum(std::vector <int> vec, int size) {
int process_number, process_rank;
int buffer = 0;
int sum = 0;
MPI_Comm_size(MPI_COMM_WORLD, &process_number);
MPI_Comm_rank(MPI_COMM_WORLD, &process_rank);
MPI_Status status;
int size_for_process = size / process_number;
int div = size % process_number;
if (process_rank == 0) {
if (size < process_number) {
buffer += GetSequentialSum(vec);
} else {
for (int i = 1; i < process_number; i++) {
MPI_Send(&vec[0] + i * size_for_process + div, size_for_process, MPI_INT, i, 0, MPI_COMM_WORLD);
}
for (int i = 0; i < div + size_for_process; i++) {
buffer += vec[i];
}
}
} else {
if (size < process_number) {
buffer = 0;
} else {
std::vector <int> vec(size_for_process);
MPI_Recv(&vec[0], size_for_process, MPI_INT, 0, 0, MPI_COMM_WORLD, &status);
for (int i = 0; i < size_for_process; i++) {
buffer += vec[i];
}
}
}
MPI_Reduce(&buffer, &sum, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
vec.clear();
return sum;
}
int GetSequentialSum(std::vector<int> vec) {
int sum = 0;
const int size = vec.size();
for (int i = 0; i < size; i++) {
sum += vec[i];
}
return sum;
}
|
#include <ossim/parallel/ossimJobQueue.h>
#include <algorithm> /* for std::find */
ossimJobQueue::ossimJobQueue()
{
}
void ossimJobQueue::add(ossimJob* job, bool guaranteeUniqueFlag)
{
ossimRefPtr<Callback> cb;
{
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(m_jobQueueMutex);
if(guaranteeUniqueFlag)
{
if(findByPointer(job) != m_jobQueue.end())
{
m_block.set(true);
return;
}
}
cb = m_callback.get();
}
if(cb.valid()) cb->adding(this, job);
job->ready();
m_jobQueueMutex.lock();
m_jobQueue.push_back(job);
m_jobQueueMutex.unlock();
}
if(cb.valid())
{
cb->added(this, job);
}
m_block.set(true);
}
ossimRefPtr<ossimJob> ossimJobQueue::removeByName(const ossimString& name)
{
ossimRefPtr<ossimJob> result;
ossimRefPtr<Callback> cb;
if(name.empty()) return result;
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(m_jobQueueMutex);
ossimJob::List::iterator iter = findByName(name);
if(iter!=m_jobQueue.end())
{
result = *iter;
m_jobQueue.erase(iter);
}
cb = m_callback.get();
}
m_block.set(!m_jobQueue.empty());
if(cb.valid()&&result.valid())
{
cb->removed(this, result.get());
}
return result;
}
ossimRefPtr<ossimJob> ossimJobQueue::removeById(const ossimString& id)
{
ossimRefPtr<ossimJob> result;
ossimRefPtr<Callback> cb;
if(id.empty()) return result;
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(m_jobQueueMutex);
ossimJob::List::iterator iter = findById(id);
if(iter!=m_jobQueue.end())
{
result = *iter;
m_jobQueue.erase(iter);
}
cb = m_callback.get();
m_block.set(!m_jobQueue.empty());
}
if(cb.valid()&&result.valid())
{
cb->removed(this, result.get());
}
return result;
}
void ossimJobQueue::remove(const ossimJob* Job)
{
ossimRefPtr<ossimJob> removedJob;
ossimRefPtr<Callback> cb;
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(m_jobQueueMutex);
ossimJob::List::iterator iter = std::find(m_jobQueue.begin(), m_jobQueue.end(), Job);
if(iter!=m_jobQueue.end())
{
removedJob = (*iter);
m_jobQueue.erase(iter);
}
cb = m_callback.get();
}
if(cb.valid()&&removedJob.valid())
{
cb->removed(this, removedJob.get());
}
}
void ossimJobQueue::removeStoppedJobs()
{
ossimJob::List removedJobs;
ossimRefPtr<Callback> cb;
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(m_jobQueueMutex);
cb = m_callback.get();
ossimJob::List::iterator iter = m_jobQueue.begin();
while(iter!=m_jobQueue.end())
{
if((*iter)->isStopped())
{
removedJobs.push_back(*iter);
iter = m_jobQueue.erase(iter);
}
else
{
++iter;
}
}
}
if(!removedJobs.empty())
{
if(cb.valid())
{
ossimJob::List::iterator iter = removedJobs.begin();
while(iter!=removedJobs.end())
{
cb->removed(this, (*iter).get());
++iter;
}
}
removedJobs.clear();
}
}
void ossimJobQueue::clear()
{
ossimJob::List removedJobs(m_jobQueue);
ossimRefPtr<Callback> cb;
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(m_jobQueueMutex);
m_jobQueue.clear();
cb = m_callback.get();
}
if(cb.valid())
{
// ossim_uint32 idx = 0;
for(ossimJob::List::iterator iter=removedJobs.begin();iter!=removedJobs.end();++iter)
{
cb->removed(this, (*iter).get());
}
}
}
ossimRefPtr<ossimJob> ossimJobQueue::nextJob(bool blockIfEmptyFlag)
{
m_jobQueueMutex.lock();
bool emptyFlag = m_jobQueue.empty();
m_jobQueueMutex.unlock();
if (blockIfEmptyFlag && emptyFlag)
{
m_block.block();
}
ossimRefPtr<ossimJob> result;
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(m_jobQueueMutex);
if (m_jobQueue.empty())
{
m_block.set(false);
return result;
}
ossimJob::List::iterator iter= m_jobQueue.begin();
while((iter != m_jobQueue.end())&&
(((*iter)->isCanceled())))
{
(*iter)->finished(); // mark the ob as being finished
iter = m_jobQueue.erase(iter);
}
if(iter != m_jobQueue.end())
{
result = *iter;
m_jobQueue.erase(iter);
}
m_block.set(!m_jobQueue.empty());
return result;
}
void ossimJobQueue::releaseBlock()
{
m_block.release();
}
bool ossimJobQueue::isEmpty()const
{
// OpenThreads::ScopedLock<OpenThreads::Mutex> lock(m_jobQueueMutex);
// return m_jobQueue.empty();
m_jobQueueMutex.lock();
bool result = m_jobQueue.empty();
m_jobQueueMutex.unlock();
return result;
}
ossim_uint32 ossimJobQueue::size()
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(m_jobQueueMutex);
return (ossim_uint32) m_jobQueue.size();
}
ossimJob::List::iterator ossimJobQueue::findById(const ossimString& id)
{
if(id.empty()) return m_jobQueue.end();
ossimJob::List::iterator iter = m_jobQueue.begin();
while(iter != m_jobQueue.end())
{
if(id == (*iter)->id())
{
return iter;
}
++iter;
}
return m_jobQueue.end();
}
ossimJob::List::iterator ossimJobQueue::findByName(const ossimString& name)
{
if(name.empty()) return m_jobQueue.end();
ossimJob::List::iterator iter = m_jobQueue.begin();
while(iter != m_jobQueue.end())
{
if(name == (*iter)->name())
{
return iter;
}
++iter;
}
return m_jobQueue.end();
}
ossimJob::List::iterator ossimJobQueue::findByPointer(const ossimJob* job)
{
return std::find(m_jobQueue.begin(),
m_jobQueue.end(),
job);
}
ossimJob::List::iterator ossimJobQueue::findByNameOrPointer(const ossimJob* job)
{
ossimString n = job->name();
ossimJob::List::iterator iter = m_jobQueue.begin();
while(iter != m_jobQueue.end())
{
if((*iter).get() == job)
{
return iter;
}
else if((!n.empty())&&
(job->name() == (*iter)->name()))
{
return iter;
}
++iter;
}
return m_jobQueue.end();
}
bool ossimJobQueue::hasJob(ossimJob* job)
{
ossimJob::List::const_iterator iter = m_jobQueue.begin();
while(iter != m_jobQueue.end())
{
if(job == (*iter).get())
{
return true;
}
++iter;
}
return false;
}
void ossimJobQueue::setCallback(Callback* c)
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(m_jobQueueMutex);
m_callback = c;
}
ossimJobQueue::Callback* ossimJobQueue::callback()
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(m_jobQueueMutex);
return m_callback.get();
}
|
// Copyright 2015 Stellar Development Foundation and contributors. Licensed
// under the Apache License, Version 2.0. See the COPYING file at the root
// of this distribution or at http://www.apache.org/licenses/LICENSE-2.0
#include "crypto/ECDH.h"
#include "crypto/SHA.h"
#include "util/HashOfHash.h"
#include <functional>
#include <sodium.h>
#ifdef MSAN_ENABLED
#include <sanitizer/msan_interface.h>
#endif
namespace iotchain
{
Curve25519Secret
EcdhRandomSecret()
{
Curve25519Secret out;
randombytes_buf(out.key.data(), out.key.size());
#ifdef MSAN_ENABLED
__msan_unpoison(out.key.data(), out.key.size());
#endif
return out;
}
Curve25519Public
EcdhDerivePublic(Curve25519Secret const& sec)
{
Curve25519Public out;
if (crypto_scalarmult_base(out.key.data(), sec.key.data()) != 0)
{
throw std::runtime_error("Could not derive key (mult_base)");
}
return out;
}
HmacSha256Key
EcdhDeriveSharedKey(Curve25519Secret const& localSecret,
Curve25519Public const& localPublic,
Curve25519Public const& remotePublic, bool localFirst)
{
auto const& publicA = localFirst ? localPublic : remotePublic;
auto const& publicB = localFirst ? remotePublic : localPublic;
unsigned char q[crypto_scalarmult_BYTES];
if (crypto_scalarmult(q, localSecret.key.data(), remotePublic.key.data()) !=
0)
{
throw std::runtime_error("Could not derive shared key (mult)");
}
#ifdef MSAN_ENABLED
__msan_unpoison(q, crypto_scalarmult_BYTES);
#endif
std::vector<uint8_t> buf;
buf.reserve(crypto_scalarmult_BYTES + publicA.key.size() +
publicB.key.size());
buf.insert(buf.end(), q, q + crypto_scalarmult_BYTES);
buf.insert(buf.end(), publicA.key.begin(), publicA.key.end());
buf.insert(buf.end(), publicB.key.begin(), publicB.key.end());
return hkdfExtract(buf);
}
}
namespace std
{
size_t
hash<iotchain::Curve25519Public>::
operator()(iotchain::Curve25519Public const& k) const noexcept
{
return std::hash<iotchain::uint256>()(k.key);
}
}
|
; A170362: Number of reduced words of length n in Coxeter group on 17 generators S_i with relations (S_i)^2 = (S_i S_j)^43 = I.
; 1,17,272,4352,69632,1114112,17825792,285212672,4563402752,73014444032,1168231104512,18691697672192,299067162755072,4785074604081152,76561193665298432,1224979098644774912,19599665578316398592
seq $0,168838 ; Number of reduced words of length n in Coxeter group on 17 generators S_i with relations (S_i)^2 = (S_i S_j)^20 = I.
|
SSAnne1F_Script:
call EnableAutoTextBoxDrawing
ret
SSAnne1F_TextPointers:
dw SSAnne1Text1
dw SSAnne1Text2
SSAnne1Text1:
TX_FAR _SSAnne1Text1
db "@"
SSAnne1Text2:
TX_FAR _SSAnne1Text2
db "@"
|
; A261557: a(0) = a(1) = 0; for n>1, a(n) = 2*n - a(n-1) - a(n-2).
; 0,0,4,2,2,6,4,4,8,6,6,10,8,8,12,10,10,14,12,12,16,14,14,18,16,16,20,18,18,22,20,20,24,22,22,26,24,24,28,26,26,30,28,28,32,30,30,34,32,32,36,34,34,38,36,36,40,38,38,42,40,40,44,42,42,46,44,44,48,46,46,50,48,48,52,50,50,54,52,52,56,54,54,58,56,56,60,58,58,62,60,60,64,62,62,66,64,64,68,66,66,70,68,68,72,70,70,74,72,72,76,74,74,78,76,76,80,78,78,82,80,80,84,82,82,86,84,84,88,86,86,90,88,88,92,90,90,94,92,92,96,94,94,98,96,96,100,98,98,102,100,100,104,102,102,106,104,104,108,106,106,110,108,108,112,110,110,114,112,112,116,114,114,118,116,116,120,118,118,122,120,120,124,122,122,126,124,124,128,126,126,130,128,128,132,130,130,134,132,132,136,134,134,138,136,136,140,138,138,142,140,140,144,142,142,146,144,144,148,146,146,150,148,148,152,150,150,154,152,152,156,154,154,158,156,156,160,158,158,162,160,160,164,162,162,166,164,164,168,166
add $0,1
mov $1,$0
mul $0,2
mod $0,6
add $1,10
sub $1,$0
sub $1,7
div $1,3
mul $1,2
|
; A007662: Quadruple factorial numbers n!!!!: a(n) = n*a(n-4).
; 1,1,2,3,4,5,12,21,32,45,120,231,384,585,1680,3465,6144,9945,30240,65835,122880,208845,665280,1514205,2949120,5221125,17297280,40883535,82575360,151412625,518918400,1267389585,2642411520,4996616625,17643225600,44358635475,95126814720,184874815125,670442572800,1729986783525,3805072588800,7579867420125,28158588057600,74389431691575,167423193907200,341094033905625,1295295050649600,3496303289504025,8036313307545600,16713607661375625,64764752532480000,178311467764705275,417888291992371200
mov $1,12
lpb $0
mul $1,$0
trn $0,4
lpe
div $1,12
mov $0,$1
|
_init: file format elf32-i386
Disassembly of section .text:
00000000 <main>:
char *argv[] = { "sh", 0 };
int
main(void)
{
0: 8d 4c 24 04 lea 0x4(%esp),%ecx
4: 83 e4 f0 and $0xfffffff0,%esp
7: ff 71 fc pushl -0x4(%ecx)
a: 55 push %ebp
b: 89 e5 mov %esp,%ebp
d: 51 push %ecx
e: 83 ec 14 sub $0x14,%esp
int pid, wpid;
if(open("console", O_RDWR) < 0){
11: 83 ec 08 sub $0x8,%esp
14: 6a 02 push $0x2
16: 68 76 09 00 00 push $0x976
1b: e8 06 04 00 00 call 426 <open>
20: 83 c4 10 add $0x10,%esp
23: 85 c0 test %eax,%eax
25: 79 26 jns 4d <main+0x4d>
mknod("console", 1, 1);
27: 83 ec 04 sub $0x4,%esp
2a: 6a 01 push $0x1
2c: 6a 01 push $0x1
2e: 68 76 09 00 00 push $0x976
33: e8 f6 03 00 00 call 42e <mknod>
38: 83 c4 10 add $0x10,%esp
open("console", O_RDWR);
3b: 83 ec 08 sub $0x8,%esp
3e: 6a 02 push $0x2
40: 68 76 09 00 00 push $0x976
45: e8 dc 03 00 00 call 426 <open>
4a: 83 c4 10 add $0x10,%esp
}
dup(0); // stdout
4d: 83 ec 0c sub $0xc,%esp
50: 6a 00 push $0x0
52: e8 07 04 00 00 call 45e <dup>
57: 83 c4 10 add $0x10,%esp
dup(0); // stderr
5a: 83 ec 0c sub $0xc,%esp
5d: 6a 00 push $0x0
5f: e8 fa 03 00 00 call 45e <dup>
64: 83 c4 10 add $0x10,%esp
for(;;){
printf(1, "init: starting sh\n");
67: 83 ec 08 sub $0x8,%esp
6a: 68 7e 09 00 00 push $0x97e
6f: 6a 01 push $0x1
71: e8 47 05 00 00 call 5bd <printf>
76: 83 c4 10 add $0x10,%esp
pid = fork();
79: e8 60 03 00 00 call 3de <fork>
7e: 89 45 f4 mov %eax,-0xc(%ebp)
if(pid < 0){
81: 83 7d f4 00 cmpl $0x0,-0xc(%ebp)
85: 79 17 jns 9e <main+0x9e>
printf(1, "init: fork failed\n");
87: 83 ec 08 sub $0x8,%esp
8a: 68 91 09 00 00 push $0x991
8f: 6a 01 push $0x1
91: e8 27 05 00 00 call 5bd <printf>
96: 83 c4 10 add $0x10,%esp
exit();
99: e8 48 03 00 00 call 3e6 <exit>
}
if(pid == 0){
9e: 83 7d f4 00 cmpl $0x0,-0xc(%ebp)
a2: 75 3e jne e2 <main+0xe2>
exec("sh", argv);
a4: 83 ec 08 sub $0x8,%esp
a7: 68 34 0c 00 00 push $0xc34
ac: 68 73 09 00 00 push $0x973
b1: e8 68 03 00 00 call 41e <exec>
b6: 83 c4 10 add $0x10,%esp
printf(1, "init: exec sh failed\n");
b9: 83 ec 08 sub $0x8,%esp
bc: 68 a4 09 00 00 push $0x9a4
c1: 6a 01 push $0x1
c3: e8 f5 04 00 00 call 5bd <printf>
c8: 83 c4 10 add $0x10,%esp
exit();
cb: e8 16 03 00 00 call 3e6 <exit>
}
while((wpid=wait()) >= 0 && wpid != pid)
printf(1, "zombie!\n");
d0: 83 ec 08 sub $0x8,%esp
d3: 68 ba 09 00 00 push $0x9ba
d8: 6a 01 push $0x1
da: e8 de 04 00 00 call 5bd <printf>
df: 83 c4 10 add $0x10,%esp
if(pid == 0){
exec("sh", argv);
printf(1, "init: exec sh failed\n");
exit();
}
while((wpid=wait()) >= 0 && wpid != pid)
e2: e8 07 03 00 00 call 3ee <wait>
e7: 89 45 f0 mov %eax,-0x10(%ebp)
ea: 83 7d f0 00 cmpl $0x0,-0x10(%ebp)
ee: 0f 88 73 ff ff ff js 67 <main+0x67>
f4: 8b 45 f0 mov -0x10(%ebp),%eax
f7: 3b 45 f4 cmp -0xc(%ebp),%eax
fa: 75 d4 jne d0 <main+0xd0>
printf(1, "zombie!\n");
}
fc: e9 66 ff ff ff jmp 67 <main+0x67>
00000101 <stosb>:
"cc");
}
static inline void
stosb(void *addr, int data, int cnt)
{
101: 55 push %ebp
102: 89 e5 mov %esp,%ebp
104: 57 push %edi
105: 53 push %ebx
asm volatile("cld; rep stosb" :
106: 8b 4d 08 mov 0x8(%ebp),%ecx
109: 8b 55 10 mov 0x10(%ebp),%edx
10c: 8b 45 0c mov 0xc(%ebp),%eax
10f: 89 cb mov %ecx,%ebx
111: 89 df mov %ebx,%edi
113: 89 d1 mov %edx,%ecx
115: fc cld
116: f3 aa rep stos %al,%es:(%edi)
118: 89 ca mov %ecx,%edx
11a: 89 fb mov %edi,%ebx
11c: 89 5d 08 mov %ebx,0x8(%ebp)
11f: 89 55 10 mov %edx,0x10(%ebp)
"=D" (addr), "=c" (cnt) :
"0" (addr), "1" (cnt), "a" (data) :
"memory", "cc");
}
122: 90 nop
123: 5b pop %ebx
124: 5f pop %edi
125: 5d pop %ebp
126: c3 ret
00000127 <strcpy>:
#include "user.h"
#include "x86.h"
char*
strcpy(char *s, char *t)
{
127: 55 push %ebp
128: 89 e5 mov %esp,%ebp
12a: 83 ec 10 sub $0x10,%esp
char *os;
os = s;
12d: 8b 45 08 mov 0x8(%ebp),%eax
130: 89 45 fc mov %eax,-0x4(%ebp)
while((*s++ = *t++) != 0)
133: 90 nop
134: 8b 45 08 mov 0x8(%ebp),%eax
137: 8d 50 01 lea 0x1(%eax),%edx
13a: 89 55 08 mov %edx,0x8(%ebp)
13d: 8b 55 0c mov 0xc(%ebp),%edx
140: 8d 4a 01 lea 0x1(%edx),%ecx
143: 89 4d 0c mov %ecx,0xc(%ebp)
146: 0f b6 12 movzbl (%edx),%edx
149: 88 10 mov %dl,(%eax)
14b: 0f b6 00 movzbl (%eax),%eax
14e: 84 c0 test %al,%al
150: 75 e2 jne 134 <strcpy+0xd>
;
return os;
152: 8b 45 fc mov -0x4(%ebp),%eax
}
155: c9 leave
156: c3 ret
00000157 <strcmp>:
int
strcmp(const char *p, const char *q)
{
157: 55 push %ebp
158: 89 e5 mov %esp,%ebp
while(*p && *p == *q)
15a: eb 08 jmp 164 <strcmp+0xd>
p++, q++;
15c: 83 45 08 01 addl $0x1,0x8(%ebp)
160: 83 45 0c 01 addl $0x1,0xc(%ebp)
}
int
strcmp(const char *p, const char *q)
{
while(*p && *p == *q)
164: 8b 45 08 mov 0x8(%ebp),%eax
167: 0f b6 00 movzbl (%eax),%eax
16a: 84 c0 test %al,%al
16c: 74 10 je 17e <strcmp+0x27>
16e: 8b 45 08 mov 0x8(%ebp),%eax
171: 0f b6 10 movzbl (%eax),%edx
174: 8b 45 0c mov 0xc(%ebp),%eax
177: 0f b6 00 movzbl (%eax),%eax
17a: 38 c2 cmp %al,%dl
17c: 74 de je 15c <strcmp+0x5>
p++, q++;
return (uchar)*p - (uchar)*q;
17e: 8b 45 08 mov 0x8(%ebp),%eax
181: 0f b6 00 movzbl (%eax),%eax
184: 0f b6 d0 movzbl %al,%edx
187: 8b 45 0c mov 0xc(%ebp),%eax
18a: 0f b6 00 movzbl (%eax),%eax
18d: 0f b6 c0 movzbl %al,%eax
190: 29 c2 sub %eax,%edx
192: 89 d0 mov %edx,%eax
}
194: 5d pop %ebp
195: c3 ret
00000196 <strlen>:
uint
strlen(char *s)
{
196: 55 push %ebp
197: 89 e5 mov %esp,%ebp
199: 83 ec 10 sub $0x10,%esp
int n;
for(n = 0; s[n]; n++)
19c: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%ebp)
1a3: eb 04 jmp 1a9 <strlen+0x13>
1a5: 83 45 fc 01 addl $0x1,-0x4(%ebp)
1a9: 8b 55 fc mov -0x4(%ebp),%edx
1ac: 8b 45 08 mov 0x8(%ebp),%eax
1af: 01 d0 add %edx,%eax
1b1: 0f b6 00 movzbl (%eax),%eax
1b4: 84 c0 test %al,%al
1b6: 75 ed jne 1a5 <strlen+0xf>
;
return n;
1b8: 8b 45 fc mov -0x4(%ebp),%eax
}
1bb: c9 leave
1bc: c3 ret
000001bd <memset>:
void*
memset(void *dst, int c, uint n)
{
1bd: 55 push %ebp
1be: 89 e5 mov %esp,%ebp
stosb(dst, c, n);
1c0: 8b 45 10 mov 0x10(%ebp),%eax
1c3: 50 push %eax
1c4: ff 75 0c pushl 0xc(%ebp)
1c7: ff 75 08 pushl 0x8(%ebp)
1ca: e8 32 ff ff ff call 101 <stosb>
1cf: 83 c4 0c add $0xc,%esp
return dst;
1d2: 8b 45 08 mov 0x8(%ebp),%eax
}
1d5: c9 leave
1d6: c3 ret
000001d7 <strchr>:
char*
strchr(const char *s, char c)
{
1d7: 55 push %ebp
1d8: 89 e5 mov %esp,%ebp
1da: 83 ec 04 sub $0x4,%esp
1dd: 8b 45 0c mov 0xc(%ebp),%eax
1e0: 88 45 fc mov %al,-0x4(%ebp)
for(; *s; s++)
1e3: eb 14 jmp 1f9 <strchr+0x22>
if(*s == c)
1e5: 8b 45 08 mov 0x8(%ebp),%eax
1e8: 0f b6 00 movzbl (%eax),%eax
1eb: 3a 45 fc cmp -0x4(%ebp),%al
1ee: 75 05 jne 1f5 <strchr+0x1e>
return (char*)s;
1f0: 8b 45 08 mov 0x8(%ebp),%eax
1f3: eb 13 jmp 208 <strchr+0x31>
}
char*
strchr(const char *s, char c)
{
for(; *s; s++)
1f5: 83 45 08 01 addl $0x1,0x8(%ebp)
1f9: 8b 45 08 mov 0x8(%ebp),%eax
1fc: 0f b6 00 movzbl (%eax),%eax
1ff: 84 c0 test %al,%al
201: 75 e2 jne 1e5 <strchr+0xe>
if(*s == c)
return (char*)s;
return 0;
203: b8 00 00 00 00 mov $0x0,%eax
}
208: c9 leave
209: c3 ret
0000020a <gets>:
char*
gets(char *buf, int max)
{
20a: 55 push %ebp
20b: 89 e5 mov %esp,%ebp
20d: 83 ec 18 sub $0x18,%esp
int i, cc;
char c;
for(i=0; i+1 < max; ){
210: c7 45 f4 00 00 00 00 movl $0x0,-0xc(%ebp)
217: eb 42 jmp 25b <gets+0x51>
cc = read(0, &c, 1);
219: 83 ec 04 sub $0x4,%esp
21c: 6a 01 push $0x1
21e: 8d 45 ef lea -0x11(%ebp),%eax
221: 50 push %eax
222: 6a 00 push $0x0
224: e8 d5 01 00 00 call 3fe <read>
229: 83 c4 10 add $0x10,%esp
22c: 89 45 f0 mov %eax,-0x10(%ebp)
if(cc < 1)
22f: 83 7d f0 00 cmpl $0x0,-0x10(%ebp)
233: 7e 33 jle 268 <gets+0x5e>
break;
buf[i++] = c;
235: 8b 45 f4 mov -0xc(%ebp),%eax
238: 8d 50 01 lea 0x1(%eax),%edx
23b: 89 55 f4 mov %edx,-0xc(%ebp)
23e: 89 c2 mov %eax,%edx
240: 8b 45 08 mov 0x8(%ebp),%eax
243: 01 c2 add %eax,%edx
245: 0f b6 45 ef movzbl -0x11(%ebp),%eax
249: 88 02 mov %al,(%edx)
if(c == '\n' || c == '\r')
24b: 0f b6 45 ef movzbl -0x11(%ebp),%eax
24f: 3c 0a cmp $0xa,%al
251: 74 16 je 269 <gets+0x5f>
253: 0f b6 45 ef movzbl -0x11(%ebp),%eax
257: 3c 0d cmp $0xd,%al
259: 74 0e je 269 <gets+0x5f>
gets(char *buf, int max)
{
int i, cc;
char c;
for(i=0; i+1 < max; ){
25b: 8b 45 f4 mov -0xc(%ebp),%eax
25e: 83 c0 01 add $0x1,%eax
261: 3b 45 0c cmp 0xc(%ebp),%eax
264: 7c b3 jl 219 <gets+0xf>
266: eb 01 jmp 269 <gets+0x5f>
cc = read(0, &c, 1);
if(cc < 1)
break;
268: 90 nop
buf[i++] = c;
if(c == '\n' || c == '\r')
break;
}
buf[i] = '\0';
269: 8b 55 f4 mov -0xc(%ebp),%edx
26c: 8b 45 08 mov 0x8(%ebp),%eax
26f: 01 d0 add %edx,%eax
271: c6 00 00 movb $0x0,(%eax)
return buf;
274: 8b 45 08 mov 0x8(%ebp),%eax
}
277: c9 leave
278: c3 ret
00000279 <stat>:
int
stat(char *n, struct stat *st)
{
279: 55 push %ebp
27a: 89 e5 mov %esp,%ebp
27c: 83 ec 18 sub $0x18,%esp
int fd;
int r;
fd = open(n, O_RDONLY);
27f: 83 ec 08 sub $0x8,%esp
282: 6a 00 push $0x0
284: ff 75 08 pushl 0x8(%ebp)
287: e8 9a 01 00 00 call 426 <open>
28c: 83 c4 10 add $0x10,%esp
28f: 89 45 f4 mov %eax,-0xc(%ebp)
if(fd < 0)
292: 83 7d f4 00 cmpl $0x0,-0xc(%ebp)
296: 79 07 jns 29f <stat+0x26>
return -1;
298: b8 ff ff ff ff mov $0xffffffff,%eax
29d: eb 25 jmp 2c4 <stat+0x4b>
r = fstat(fd, st);
29f: 83 ec 08 sub $0x8,%esp
2a2: ff 75 0c pushl 0xc(%ebp)
2a5: ff 75 f4 pushl -0xc(%ebp)
2a8: e8 91 01 00 00 call 43e <fstat>
2ad: 83 c4 10 add $0x10,%esp
2b0: 89 45 f0 mov %eax,-0x10(%ebp)
close(fd);
2b3: 83 ec 0c sub $0xc,%esp
2b6: ff 75 f4 pushl -0xc(%ebp)
2b9: e8 50 01 00 00 call 40e <close>
2be: 83 c4 10 add $0x10,%esp
return r;
2c1: 8b 45 f0 mov -0x10(%ebp),%eax
}
2c4: c9 leave
2c5: c3 ret
000002c6 <atoi>:
int
atoi(const char *s)
{
2c6: 55 push %ebp
2c7: 89 e5 mov %esp,%ebp
2c9: 83 ec 10 sub $0x10,%esp
int n;
n = 0;
2cc: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%ebp)
while('0' <= *s && *s <= '9')
2d3: eb 25 jmp 2fa <atoi+0x34>
n = n*10 + *s++ - '0';
2d5: 8b 55 fc mov -0x4(%ebp),%edx
2d8: 89 d0 mov %edx,%eax
2da: c1 e0 02 shl $0x2,%eax
2dd: 01 d0 add %edx,%eax
2df: 01 c0 add %eax,%eax
2e1: 89 c1 mov %eax,%ecx
2e3: 8b 45 08 mov 0x8(%ebp),%eax
2e6: 8d 50 01 lea 0x1(%eax),%edx
2e9: 89 55 08 mov %edx,0x8(%ebp)
2ec: 0f b6 00 movzbl (%eax),%eax
2ef: 0f be c0 movsbl %al,%eax
2f2: 01 c8 add %ecx,%eax
2f4: 83 e8 30 sub $0x30,%eax
2f7: 89 45 fc mov %eax,-0x4(%ebp)
atoi(const char *s)
{
int n;
n = 0;
while('0' <= *s && *s <= '9')
2fa: 8b 45 08 mov 0x8(%ebp),%eax
2fd: 0f b6 00 movzbl (%eax),%eax
300: 3c 2f cmp $0x2f,%al
302: 7e 0a jle 30e <atoi+0x48>
304: 8b 45 08 mov 0x8(%ebp),%eax
307: 0f b6 00 movzbl (%eax),%eax
30a: 3c 39 cmp $0x39,%al
30c: 7e c7 jle 2d5 <atoi+0xf>
n = n*10 + *s++ - '0';
return n;
30e: 8b 45 fc mov -0x4(%ebp),%eax
}
311: c9 leave
312: c3 ret
00000313 <atoo>:
int
atoo(const char *s)
{
313: 55 push %ebp
314: 89 e5 mov %esp,%ebp
316: 83 ec 10 sub $0x10,%esp
int n, sign;
n = 0;
319: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%ebp)
while (*s == ' ')
320: eb 04 jmp 326 <atoo+0x13>
s++;
322: 83 45 08 01 addl $0x1,0x8(%ebp)
int
atoo(const char *s)
{
int n, sign;
n = 0;
while (*s == ' ')
326: 8b 45 08 mov 0x8(%ebp),%eax
329: 0f b6 00 movzbl (%eax),%eax
32c: 3c 20 cmp $0x20,%al
32e: 74 f2 je 322 <atoo+0xf>
s++;
sign = (*s == '-') ? -1 : 1;
330: 8b 45 08 mov 0x8(%ebp),%eax
333: 0f b6 00 movzbl (%eax),%eax
336: 3c 2d cmp $0x2d,%al
338: 75 07 jne 341 <atoo+0x2e>
33a: b8 ff ff ff ff mov $0xffffffff,%eax
33f: eb 05 jmp 346 <atoo+0x33>
341: b8 01 00 00 00 mov $0x1,%eax
346: 89 45 f8 mov %eax,-0x8(%ebp)
if (*s == '+' || *s == '-')
349: 8b 45 08 mov 0x8(%ebp),%eax
34c: 0f b6 00 movzbl (%eax),%eax
34f: 3c 2b cmp $0x2b,%al
351: 74 0a je 35d <atoo+0x4a>
353: 8b 45 08 mov 0x8(%ebp),%eax
356: 0f b6 00 movzbl (%eax),%eax
359: 3c 2d cmp $0x2d,%al
35b: 75 27 jne 384 <atoo+0x71>
s++;
35d: 83 45 08 01 addl $0x1,0x8(%ebp)
while ('0' <= *s && *s <= '7')
361: eb 21 jmp 384 <atoo+0x71>
n = n*8 + *s++ - '0';
363: 8b 45 fc mov -0x4(%ebp),%eax
366: 8d 0c c5 00 00 00 00 lea 0x0(,%eax,8),%ecx
36d: 8b 45 08 mov 0x8(%ebp),%eax
370: 8d 50 01 lea 0x1(%eax),%edx
373: 89 55 08 mov %edx,0x8(%ebp)
376: 0f b6 00 movzbl (%eax),%eax
379: 0f be c0 movsbl %al,%eax
37c: 01 c8 add %ecx,%eax
37e: 83 e8 30 sub $0x30,%eax
381: 89 45 fc mov %eax,-0x4(%ebp)
while (*s == ' ')
s++;
sign = (*s == '-') ? -1 : 1;
if (*s == '+' || *s == '-')
s++;
while ('0' <= *s && *s <= '7')
384: 8b 45 08 mov 0x8(%ebp),%eax
387: 0f b6 00 movzbl (%eax),%eax
38a: 3c 2f cmp $0x2f,%al
38c: 7e 0a jle 398 <atoo+0x85>
38e: 8b 45 08 mov 0x8(%ebp),%eax
391: 0f b6 00 movzbl (%eax),%eax
394: 3c 37 cmp $0x37,%al
396: 7e cb jle 363 <atoo+0x50>
n = n*8 + *s++ - '0';
return sign*n;
398: 8b 45 f8 mov -0x8(%ebp),%eax
39b: 0f af 45 fc imul -0x4(%ebp),%eax
}
39f: c9 leave
3a0: c3 ret
000003a1 <memmove>:
void*
memmove(void *vdst, void *vsrc, int n)
{
3a1: 55 push %ebp
3a2: 89 e5 mov %esp,%ebp
3a4: 83 ec 10 sub $0x10,%esp
char *dst, *src;
dst = vdst;
3a7: 8b 45 08 mov 0x8(%ebp),%eax
3aa: 89 45 fc mov %eax,-0x4(%ebp)
src = vsrc;
3ad: 8b 45 0c mov 0xc(%ebp),%eax
3b0: 89 45 f8 mov %eax,-0x8(%ebp)
while(n-- > 0)
3b3: eb 17 jmp 3cc <memmove+0x2b>
*dst++ = *src++;
3b5: 8b 45 fc mov -0x4(%ebp),%eax
3b8: 8d 50 01 lea 0x1(%eax),%edx
3bb: 89 55 fc mov %edx,-0x4(%ebp)
3be: 8b 55 f8 mov -0x8(%ebp),%edx
3c1: 8d 4a 01 lea 0x1(%edx),%ecx
3c4: 89 4d f8 mov %ecx,-0x8(%ebp)
3c7: 0f b6 12 movzbl (%edx),%edx
3ca: 88 10 mov %dl,(%eax)
{
char *dst, *src;
dst = vdst;
src = vsrc;
while(n-- > 0)
3cc: 8b 45 10 mov 0x10(%ebp),%eax
3cf: 8d 50 ff lea -0x1(%eax),%edx
3d2: 89 55 10 mov %edx,0x10(%ebp)
3d5: 85 c0 test %eax,%eax
3d7: 7f dc jg 3b5 <memmove+0x14>
*dst++ = *src++;
return vdst;
3d9: 8b 45 08 mov 0x8(%ebp),%eax
}
3dc: c9 leave
3dd: c3 ret
000003de <fork>:
name: \
movl $SYS_ ## name, %eax; \
int $T_SYSCALL; \
ret
SYSCALL(fork)
3de: b8 01 00 00 00 mov $0x1,%eax
3e3: cd 40 int $0x40
3e5: c3 ret
000003e6 <exit>:
SYSCALL(exit)
3e6: b8 02 00 00 00 mov $0x2,%eax
3eb: cd 40 int $0x40
3ed: c3 ret
000003ee <wait>:
SYSCALL(wait)
3ee: b8 03 00 00 00 mov $0x3,%eax
3f3: cd 40 int $0x40
3f5: c3 ret
000003f6 <pipe>:
SYSCALL(pipe)
3f6: b8 04 00 00 00 mov $0x4,%eax
3fb: cd 40 int $0x40
3fd: c3 ret
000003fe <read>:
SYSCALL(read)
3fe: b8 05 00 00 00 mov $0x5,%eax
403: cd 40 int $0x40
405: c3 ret
00000406 <write>:
SYSCALL(write)
406: b8 10 00 00 00 mov $0x10,%eax
40b: cd 40 int $0x40
40d: c3 ret
0000040e <close>:
SYSCALL(close)
40e: b8 15 00 00 00 mov $0x15,%eax
413: cd 40 int $0x40
415: c3 ret
00000416 <kill>:
SYSCALL(kill)
416: b8 06 00 00 00 mov $0x6,%eax
41b: cd 40 int $0x40
41d: c3 ret
0000041e <exec>:
SYSCALL(exec)
41e: b8 07 00 00 00 mov $0x7,%eax
423: cd 40 int $0x40
425: c3 ret
00000426 <open>:
SYSCALL(open)
426: b8 0f 00 00 00 mov $0xf,%eax
42b: cd 40 int $0x40
42d: c3 ret
0000042e <mknod>:
SYSCALL(mknod)
42e: b8 11 00 00 00 mov $0x11,%eax
433: cd 40 int $0x40
435: c3 ret
00000436 <unlink>:
SYSCALL(unlink)
436: b8 12 00 00 00 mov $0x12,%eax
43b: cd 40 int $0x40
43d: c3 ret
0000043e <fstat>:
SYSCALL(fstat)
43e: b8 08 00 00 00 mov $0x8,%eax
443: cd 40 int $0x40
445: c3 ret
00000446 <link>:
SYSCALL(link)
446: b8 13 00 00 00 mov $0x13,%eax
44b: cd 40 int $0x40
44d: c3 ret
0000044e <mkdir>:
SYSCALL(mkdir)
44e: b8 14 00 00 00 mov $0x14,%eax
453: cd 40 int $0x40
455: c3 ret
00000456 <chdir>:
SYSCALL(chdir)
456: b8 09 00 00 00 mov $0x9,%eax
45b: cd 40 int $0x40
45d: c3 ret
0000045e <dup>:
SYSCALL(dup)
45e: b8 0a 00 00 00 mov $0xa,%eax
463: cd 40 int $0x40
465: c3 ret
00000466 <getpid>:
SYSCALL(getpid)
466: b8 0b 00 00 00 mov $0xb,%eax
46b: cd 40 int $0x40
46d: c3 ret
0000046e <sbrk>:
SYSCALL(sbrk)
46e: b8 0c 00 00 00 mov $0xc,%eax
473: cd 40 int $0x40
475: c3 ret
00000476 <sleep>:
SYSCALL(sleep)
476: b8 0d 00 00 00 mov $0xd,%eax
47b: cd 40 int $0x40
47d: c3 ret
0000047e <uptime>:
SYSCALL(uptime)
47e: b8 0e 00 00 00 mov $0xe,%eax
483: cd 40 int $0x40
485: c3 ret
00000486 <halt>:
SYSCALL(halt)
486: b8 16 00 00 00 mov $0x16,%eax
48b: cd 40 int $0x40
48d: c3 ret
0000048e <date>:
SYSCALL(date)
48e: b8 17 00 00 00 mov $0x17,%eax
493: cd 40 int $0x40
495: c3 ret
00000496 <getuid>:
SYSCALL(getuid)
496: b8 18 00 00 00 mov $0x18,%eax
49b: cd 40 int $0x40
49d: c3 ret
0000049e <getgid>:
SYSCALL(getgid)
49e: b8 19 00 00 00 mov $0x19,%eax
4a3: cd 40 int $0x40
4a5: c3 ret
000004a6 <getppid>:
SYSCALL(getppid)
4a6: b8 1a 00 00 00 mov $0x1a,%eax
4ab: cd 40 int $0x40
4ad: c3 ret
000004ae <setuid>:
SYSCALL(setuid)
4ae: b8 1b 00 00 00 mov $0x1b,%eax
4b3: cd 40 int $0x40
4b5: c3 ret
000004b6 <setgid>:
SYSCALL(setgid)
4b6: b8 1c 00 00 00 mov $0x1c,%eax
4bb: cd 40 int $0x40
4bd: c3 ret
000004be <getprocs>:
SYSCALL(getprocs)
4be: b8 1d 00 00 00 mov $0x1d,%eax
4c3: cd 40 int $0x40
4c5: c3 ret
000004c6 <setpriority>:
SYSCALL(setpriority)
4c6: b8 1e 00 00 00 mov $0x1e,%eax
4cb: cd 40 int $0x40
4cd: c3 ret
000004ce <chmod>:
SYSCALL(chmod)
4ce: b8 1f 00 00 00 mov $0x1f,%eax
4d3: cd 40 int $0x40
4d5: c3 ret
000004d6 <chown>:
SYSCALL(chown)
4d6: b8 20 00 00 00 mov $0x20,%eax
4db: cd 40 int $0x40
4dd: c3 ret
000004de <chgrp>:
SYSCALL(chgrp)
4de: b8 21 00 00 00 mov $0x21,%eax
4e3: cd 40 int $0x40
4e5: c3 ret
000004e6 <putc>:
#include "stat.h"
#include "user.h"
static void
putc(int fd, char c)
{
4e6: 55 push %ebp
4e7: 89 e5 mov %esp,%ebp
4e9: 83 ec 18 sub $0x18,%esp
4ec: 8b 45 0c mov 0xc(%ebp),%eax
4ef: 88 45 f4 mov %al,-0xc(%ebp)
write(fd, &c, 1);
4f2: 83 ec 04 sub $0x4,%esp
4f5: 6a 01 push $0x1
4f7: 8d 45 f4 lea -0xc(%ebp),%eax
4fa: 50 push %eax
4fb: ff 75 08 pushl 0x8(%ebp)
4fe: e8 03 ff ff ff call 406 <write>
503: 83 c4 10 add $0x10,%esp
}
506: 90 nop
507: c9 leave
508: c3 ret
00000509 <printint>:
static void
printint(int fd, int xx, int base, int sgn)
{
509: 55 push %ebp
50a: 89 e5 mov %esp,%ebp
50c: 53 push %ebx
50d: 83 ec 24 sub $0x24,%esp
static char digits[] = "0123456789ABCDEF";
char buf[16];
int i, neg;
uint x;
neg = 0;
510: c7 45 f0 00 00 00 00 movl $0x0,-0x10(%ebp)
if(sgn && xx < 0){
517: 83 7d 14 00 cmpl $0x0,0x14(%ebp)
51b: 74 17 je 534 <printint+0x2b>
51d: 83 7d 0c 00 cmpl $0x0,0xc(%ebp)
521: 79 11 jns 534 <printint+0x2b>
neg = 1;
523: c7 45 f0 01 00 00 00 movl $0x1,-0x10(%ebp)
x = -xx;
52a: 8b 45 0c mov 0xc(%ebp),%eax
52d: f7 d8 neg %eax
52f: 89 45 ec mov %eax,-0x14(%ebp)
532: eb 06 jmp 53a <printint+0x31>
} else {
x = xx;
534: 8b 45 0c mov 0xc(%ebp),%eax
537: 89 45 ec mov %eax,-0x14(%ebp)
}
i = 0;
53a: c7 45 f4 00 00 00 00 movl $0x0,-0xc(%ebp)
do{
buf[i++] = digits[x % base];
541: 8b 4d f4 mov -0xc(%ebp),%ecx
544: 8d 41 01 lea 0x1(%ecx),%eax
547: 89 45 f4 mov %eax,-0xc(%ebp)
54a: 8b 5d 10 mov 0x10(%ebp),%ebx
54d: 8b 45 ec mov -0x14(%ebp),%eax
550: ba 00 00 00 00 mov $0x0,%edx
555: f7 f3 div %ebx
557: 89 d0 mov %edx,%eax
559: 0f b6 80 3c 0c 00 00 movzbl 0xc3c(%eax),%eax
560: 88 44 0d dc mov %al,-0x24(%ebp,%ecx,1)
}while((x /= base) != 0);
564: 8b 5d 10 mov 0x10(%ebp),%ebx
567: 8b 45 ec mov -0x14(%ebp),%eax
56a: ba 00 00 00 00 mov $0x0,%edx
56f: f7 f3 div %ebx
571: 89 45 ec mov %eax,-0x14(%ebp)
574: 83 7d ec 00 cmpl $0x0,-0x14(%ebp)
578: 75 c7 jne 541 <printint+0x38>
if(neg)
57a: 83 7d f0 00 cmpl $0x0,-0x10(%ebp)
57e: 74 2d je 5ad <printint+0xa4>
buf[i++] = '-';
580: 8b 45 f4 mov -0xc(%ebp),%eax
583: 8d 50 01 lea 0x1(%eax),%edx
586: 89 55 f4 mov %edx,-0xc(%ebp)
589: c6 44 05 dc 2d movb $0x2d,-0x24(%ebp,%eax,1)
while(--i >= 0)
58e: eb 1d jmp 5ad <printint+0xa4>
putc(fd, buf[i]);
590: 8d 55 dc lea -0x24(%ebp),%edx
593: 8b 45 f4 mov -0xc(%ebp),%eax
596: 01 d0 add %edx,%eax
598: 0f b6 00 movzbl (%eax),%eax
59b: 0f be c0 movsbl %al,%eax
59e: 83 ec 08 sub $0x8,%esp
5a1: 50 push %eax
5a2: ff 75 08 pushl 0x8(%ebp)
5a5: e8 3c ff ff ff call 4e6 <putc>
5aa: 83 c4 10 add $0x10,%esp
buf[i++] = digits[x % base];
}while((x /= base) != 0);
if(neg)
buf[i++] = '-';
while(--i >= 0)
5ad: 83 6d f4 01 subl $0x1,-0xc(%ebp)
5b1: 83 7d f4 00 cmpl $0x0,-0xc(%ebp)
5b5: 79 d9 jns 590 <printint+0x87>
putc(fd, buf[i]);
}
5b7: 90 nop
5b8: 8b 5d fc mov -0x4(%ebp),%ebx
5bb: c9 leave
5bc: c3 ret
000005bd <printf>:
// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, char *fmt, ...)
{
5bd: 55 push %ebp
5be: 89 e5 mov %esp,%ebp
5c0: 83 ec 28 sub $0x28,%esp
char *s;
int c, i, state;
uint *ap;
state = 0;
5c3: c7 45 ec 00 00 00 00 movl $0x0,-0x14(%ebp)
ap = (uint*)(void*)&fmt + 1;
5ca: 8d 45 0c lea 0xc(%ebp),%eax
5cd: 83 c0 04 add $0x4,%eax
5d0: 89 45 e8 mov %eax,-0x18(%ebp)
for(i = 0; fmt[i]; i++){
5d3: c7 45 f0 00 00 00 00 movl $0x0,-0x10(%ebp)
5da: e9 59 01 00 00 jmp 738 <printf+0x17b>
c = fmt[i] & 0xff;
5df: 8b 55 0c mov 0xc(%ebp),%edx
5e2: 8b 45 f0 mov -0x10(%ebp),%eax
5e5: 01 d0 add %edx,%eax
5e7: 0f b6 00 movzbl (%eax),%eax
5ea: 0f be c0 movsbl %al,%eax
5ed: 25 ff 00 00 00 and $0xff,%eax
5f2: 89 45 e4 mov %eax,-0x1c(%ebp)
if(state == 0){
5f5: 83 7d ec 00 cmpl $0x0,-0x14(%ebp)
5f9: 75 2c jne 627 <printf+0x6a>
if(c == '%'){
5fb: 83 7d e4 25 cmpl $0x25,-0x1c(%ebp)
5ff: 75 0c jne 60d <printf+0x50>
state = '%';
601: c7 45 ec 25 00 00 00 movl $0x25,-0x14(%ebp)
608: e9 27 01 00 00 jmp 734 <printf+0x177>
} else {
putc(fd, c);
60d: 8b 45 e4 mov -0x1c(%ebp),%eax
610: 0f be c0 movsbl %al,%eax
613: 83 ec 08 sub $0x8,%esp
616: 50 push %eax
617: ff 75 08 pushl 0x8(%ebp)
61a: e8 c7 fe ff ff call 4e6 <putc>
61f: 83 c4 10 add $0x10,%esp
622: e9 0d 01 00 00 jmp 734 <printf+0x177>
}
} else if(state == '%'){
627: 83 7d ec 25 cmpl $0x25,-0x14(%ebp)
62b: 0f 85 03 01 00 00 jne 734 <printf+0x177>
if(c == 'd'){
631: 83 7d e4 64 cmpl $0x64,-0x1c(%ebp)
635: 75 1e jne 655 <printf+0x98>
printint(fd, *ap, 10, 1);
637: 8b 45 e8 mov -0x18(%ebp),%eax
63a: 8b 00 mov (%eax),%eax
63c: 6a 01 push $0x1
63e: 6a 0a push $0xa
640: 50 push %eax
641: ff 75 08 pushl 0x8(%ebp)
644: e8 c0 fe ff ff call 509 <printint>
649: 83 c4 10 add $0x10,%esp
ap++;
64c: 83 45 e8 04 addl $0x4,-0x18(%ebp)
650: e9 d8 00 00 00 jmp 72d <printf+0x170>
} else if(c == 'x' || c == 'p'){
655: 83 7d e4 78 cmpl $0x78,-0x1c(%ebp)
659: 74 06 je 661 <printf+0xa4>
65b: 83 7d e4 70 cmpl $0x70,-0x1c(%ebp)
65f: 75 1e jne 67f <printf+0xc2>
printint(fd, *ap, 16, 0);
661: 8b 45 e8 mov -0x18(%ebp),%eax
664: 8b 00 mov (%eax),%eax
666: 6a 00 push $0x0
668: 6a 10 push $0x10
66a: 50 push %eax
66b: ff 75 08 pushl 0x8(%ebp)
66e: e8 96 fe ff ff call 509 <printint>
673: 83 c4 10 add $0x10,%esp
ap++;
676: 83 45 e8 04 addl $0x4,-0x18(%ebp)
67a: e9 ae 00 00 00 jmp 72d <printf+0x170>
} else if(c == 's'){
67f: 83 7d e4 73 cmpl $0x73,-0x1c(%ebp)
683: 75 43 jne 6c8 <printf+0x10b>
s = (char*)*ap;
685: 8b 45 e8 mov -0x18(%ebp),%eax
688: 8b 00 mov (%eax),%eax
68a: 89 45 f4 mov %eax,-0xc(%ebp)
ap++;
68d: 83 45 e8 04 addl $0x4,-0x18(%ebp)
if(s == 0)
691: 83 7d f4 00 cmpl $0x0,-0xc(%ebp)
695: 75 25 jne 6bc <printf+0xff>
s = "(null)";
697: c7 45 f4 c3 09 00 00 movl $0x9c3,-0xc(%ebp)
while(*s != 0){
69e: eb 1c jmp 6bc <printf+0xff>
putc(fd, *s);
6a0: 8b 45 f4 mov -0xc(%ebp),%eax
6a3: 0f b6 00 movzbl (%eax),%eax
6a6: 0f be c0 movsbl %al,%eax
6a9: 83 ec 08 sub $0x8,%esp
6ac: 50 push %eax
6ad: ff 75 08 pushl 0x8(%ebp)
6b0: e8 31 fe ff ff call 4e6 <putc>
6b5: 83 c4 10 add $0x10,%esp
s++;
6b8: 83 45 f4 01 addl $0x1,-0xc(%ebp)
} else if(c == 's'){
s = (char*)*ap;
ap++;
if(s == 0)
s = "(null)";
while(*s != 0){
6bc: 8b 45 f4 mov -0xc(%ebp),%eax
6bf: 0f b6 00 movzbl (%eax),%eax
6c2: 84 c0 test %al,%al
6c4: 75 da jne 6a0 <printf+0xe3>
6c6: eb 65 jmp 72d <printf+0x170>
putc(fd, *s);
s++;
}
} else if(c == 'c'){
6c8: 83 7d e4 63 cmpl $0x63,-0x1c(%ebp)
6cc: 75 1d jne 6eb <printf+0x12e>
putc(fd, *ap);
6ce: 8b 45 e8 mov -0x18(%ebp),%eax
6d1: 8b 00 mov (%eax),%eax
6d3: 0f be c0 movsbl %al,%eax
6d6: 83 ec 08 sub $0x8,%esp
6d9: 50 push %eax
6da: ff 75 08 pushl 0x8(%ebp)
6dd: e8 04 fe ff ff call 4e6 <putc>
6e2: 83 c4 10 add $0x10,%esp
ap++;
6e5: 83 45 e8 04 addl $0x4,-0x18(%ebp)
6e9: eb 42 jmp 72d <printf+0x170>
} else if(c == '%'){
6eb: 83 7d e4 25 cmpl $0x25,-0x1c(%ebp)
6ef: 75 17 jne 708 <printf+0x14b>
putc(fd, c);
6f1: 8b 45 e4 mov -0x1c(%ebp),%eax
6f4: 0f be c0 movsbl %al,%eax
6f7: 83 ec 08 sub $0x8,%esp
6fa: 50 push %eax
6fb: ff 75 08 pushl 0x8(%ebp)
6fe: e8 e3 fd ff ff call 4e6 <putc>
703: 83 c4 10 add $0x10,%esp
706: eb 25 jmp 72d <printf+0x170>
} else {
// Unknown % sequence. Print it to draw attention.
putc(fd, '%');
708: 83 ec 08 sub $0x8,%esp
70b: 6a 25 push $0x25
70d: ff 75 08 pushl 0x8(%ebp)
710: e8 d1 fd ff ff call 4e6 <putc>
715: 83 c4 10 add $0x10,%esp
putc(fd, c);
718: 8b 45 e4 mov -0x1c(%ebp),%eax
71b: 0f be c0 movsbl %al,%eax
71e: 83 ec 08 sub $0x8,%esp
721: 50 push %eax
722: ff 75 08 pushl 0x8(%ebp)
725: e8 bc fd ff ff call 4e6 <putc>
72a: 83 c4 10 add $0x10,%esp
}
state = 0;
72d: 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++){
734: 83 45 f0 01 addl $0x1,-0x10(%ebp)
738: 8b 55 0c mov 0xc(%ebp),%edx
73b: 8b 45 f0 mov -0x10(%ebp),%eax
73e: 01 d0 add %edx,%eax
740: 0f b6 00 movzbl (%eax),%eax
743: 84 c0 test %al,%al
745: 0f 85 94 fe ff ff jne 5df <printf+0x22>
putc(fd, c);
}
state = 0;
}
}
}
74b: 90 nop
74c: c9 leave
74d: c3 ret
0000074e <free>:
static Header base;
static Header *freep;
void
free(void *ap)
{
74e: 55 push %ebp
74f: 89 e5 mov %esp,%ebp
751: 83 ec 10 sub $0x10,%esp
Header *bp, *p;
bp = (Header*)ap - 1;
754: 8b 45 08 mov 0x8(%ebp),%eax
757: 83 e8 08 sub $0x8,%eax
75a: 89 45 f8 mov %eax,-0x8(%ebp)
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
75d: a1 58 0c 00 00 mov 0xc58,%eax
762: 89 45 fc mov %eax,-0x4(%ebp)
765: eb 24 jmp 78b <free+0x3d>
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
767: 8b 45 fc mov -0x4(%ebp),%eax
76a: 8b 00 mov (%eax),%eax
76c: 3b 45 fc cmp -0x4(%ebp),%eax
76f: 77 12 ja 783 <free+0x35>
771: 8b 45 f8 mov -0x8(%ebp),%eax
774: 3b 45 fc cmp -0x4(%ebp),%eax
777: 77 24 ja 79d <free+0x4f>
779: 8b 45 fc mov -0x4(%ebp),%eax
77c: 8b 00 mov (%eax),%eax
77e: 3b 45 f8 cmp -0x8(%ebp),%eax
781: 77 1a ja 79d <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)
783: 8b 45 fc mov -0x4(%ebp),%eax
786: 8b 00 mov (%eax),%eax
788: 89 45 fc mov %eax,-0x4(%ebp)
78b: 8b 45 f8 mov -0x8(%ebp),%eax
78e: 3b 45 fc cmp -0x4(%ebp),%eax
791: 76 d4 jbe 767 <free+0x19>
793: 8b 45 fc mov -0x4(%ebp),%eax
796: 8b 00 mov (%eax),%eax
798: 3b 45 f8 cmp -0x8(%ebp),%eax
79b: 76 ca jbe 767 <free+0x19>
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
break;
if(bp + bp->s.size == p->s.ptr){
79d: 8b 45 f8 mov -0x8(%ebp),%eax
7a0: 8b 40 04 mov 0x4(%eax),%eax
7a3: 8d 14 c5 00 00 00 00 lea 0x0(,%eax,8),%edx
7aa: 8b 45 f8 mov -0x8(%ebp),%eax
7ad: 01 c2 add %eax,%edx
7af: 8b 45 fc mov -0x4(%ebp),%eax
7b2: 8b 00 mov (%eax),%eax
7b4: 39 c2 cmp %eax,%edx
7b6: 75 24 jne 7dc <free+0x8e>
bp->s.size += p->s.ptr->s.size;
7b8: 8b 45 f8 mov -0x8(%ebp),%eax
7bb: 8b 50 04 mov 0x4(%eax),%edx
7be: 8b 45 fc mov -0x4(%ebp),%eax
7c1: 8b 00 mov (%eax),%eax
7c3: 8b 40 04 mov 0x4(%eax),%eax
7c6: 01 c2 add %eax,%edx
7c8: 8b 45 f8 mov -0x8(%ebp),%eax
7cb: 89 50 04 mov %edx,0x4(%eax)
bp->s.ptr = p->s.ptr->s.ptr;
7ce: 8b 45 fc mov -0x4(%ebp),%eax
7d1: 8b 00 mov (%eax),%eax
7d3: 8b 10 mov (%eax),%edx
7d5: 8b 45 f8 mov -0x8(%ebp),%eax
7d8: 89 10 mov %edx,(%eax)
7da: eb 0a jmp 7e6 <free+0x98>
} else
bp->s.ptr = p->s.ptr;
7dc: 8b 45 fc mov -0x4(%ebp),%eax
7df: 8b 10 mov (%eax),%edx
7e1: 8b 45 f8 mov -0x8(%ebp),%eax
7e4: 89 10 mov %edx,(%eax)
if(p + p->s.size == bp){
7e6: 8b 45 fc mov -0x4(%ebp),%eax
7e9: 8b 40 04 mov 0x4(%eax),%eax
7ec: 8d 14 c5 00 00 00 00 lea 0x0(,%eax,8),%edx
7f3: 8b 45 fc mov -0x4(%ebp),%eax
7f6: 01 d0 add %edx,%eax
7f8: 3b 45 f8 cmp -0x8(%ebp),%eax
7fb: 75 20 jne 81d <free+0xcf>
p->s.size += bp->s.size;
7fd: 8b 45 fc mov -0x4(%ebp),%eax
800: 8b 50 04 mov 0x4(%eax),%edx
803: 8b 45 f8 mov -0x8(%ebp),%eax
806: 8b 40 04 mov 0x4(%eax),%eax
809: 01 c2 add %eax,%edx
80b: 8b 45 fc mov -0x4(%ebp),%eax
80e: 89 50 04 mov %edx,0x4(%eax)
p->s.ptr = bp->s.ptr;
811: 8b 45 f8 mov -0x8(%ebp),%eax
814: 8b 10 mov (%eax),%edx
816: 8b 45 fc mov -0x4(%ebp),%eax
819: 89 10 mov %edx,(%eax)
81b: eb 08 jmp 825 <free+0xd7>
} else
p->s.ptr = bp;
81d: 8b 45 fc mov -0x4(%ebp),%eax
820: 8b 55 f8 mov -0x8(%ebp),%edx
823: 89 10 mov %edx,(%eax)
freep = p;
825: 8b 45 fc mov -0x4(%ebp),%eax
828: a3 58 0c 00 00 mov %eax,0xc58
}
82d: 90 nop
82e: c9 leave
82f: c3 ret
00000830 <morecore>:
static Header*
morecore(uint nu)
{
830: 55 push %ebp
831: 89 e5 mov %esp,%ebp
833: 83 ec 18 sub $0x18,%esp
char *p;
Header *hp;
if(nu < 4096)
836: 81 7d 08 ff 0f 00 00 cmpl $0xfff,0x8(%ebp)
83d: 77 07 ja 846 <morecore+0x16>
nu = 4096;
83f: c7 45 08 00 10 00 00 movl $0x1000,0x8(%ebp)
p = sbrk(nu * sizeof(Header));
846: 8b 45 08 mov 0x8(%ebp),%eax
849: c1 e0 03 shl $0x3,%eax
84c: 83 ec 0c sub $0xc,%esp
84f: 50 push %eax
850: e8 19 fc ff ff call 46e <sbrk>
855: 83 c4 10 add $0x10,%esp
858: 89 45 f4 mov %eax,-0xc(%ebp)
if(p == (char*)-1)
85b: 83 7d f4 ff cmpl $0xffffffff,-0xc(%ebp)
85f: 75 07 jne 868 <morecore+0x38>
return 0;
861: b8 00 00 00 00 mov $0x0,%eax
866: eb 26 jmp 88e <morecore+0x5e>
hp = (Header*)p;
868: 8b 45 f4 mov -0xc(%ebp),%eax
86b: 89 45 f0 mov %eax,-0x10(%ebp)
hp->s.size = nu;
86e: 8b 45 f0 mov -0x10(%ebp),%eax
871: 8b 55 08 mov 0x8(%ebp),%edx
874: 89 50 04 mov %edx,0x4(%eax)
free((void*)(hp + 1));
877: 8b 45 f0 mov -0x10(%ebp),%eax
87a: 83 c0 08 add $0x8,%eax
87d: 83 ec 0c sub $0xc,%esp
880: 50 push %eax
881: e8 c8 fe ff ff call 74e <free>
886: 83 c4 10 add $0x10,%esp
return freep;
889: a1 58 0c 00 00 mov 0xc58,%eax
}
88e: c9 leave
88f: c3 ret
00000890 <malloc>:
void*
malloc(uint nbytes)
{
890: 55 push %ebp
891: 89 e5 mov %esp,%ebp
893: 83 ec 18 sub $0x18,%esp
Header *p, *prevp;
uint nunits;
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
896: 8b 45 08 mov 0x8(%ebp),%eax
899: 83 c0 07 add $0x7,%eax
89c: c1 e8 03 shr $0x3,%eax
89f: 83 c0 01 add $0x1,%eax
8a2: 89 45 ec mov %eax,-0x14(%ebp)
if((prevp = freep) == 0){
8a5: a1 58 0c 00 00 mov 0xc58,%eax
8aa: 89 45 f0 mov %eax,-0x10(%ebp)
8ad: 83 7d f0 00 cmpl $0x0,-0x10(%ebp)
8b1: 75 23 jne 8d6 <malloc+0x46>
base.s.ptr = freep = prevp = &base;
8b3: c7 45 f0 50 0c 00 00 movl $0xc50,-0x10(%ebp)
8ba: 8b 45 f0 mov -0x10(%ebp),%eax
8bd: a3 58 0c 00 00 mov %eax,0xc58
8c2: a1 58 0c 00 00 mov 0xc58,%eax
8c7: a3 50 0c 00 00 mov %eax,0xc50
base.s.size = 0;
8cc: c7 05 54 0c 00 00 00 movl $0x0,0xc54
8d3: 00 00 00
}
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
8d6: 8b 45 f0 mov -0x10(%ebp),%eax
8d9: 8b 00 mov (%eax),%eax
8db: 89 45 f4 mov %eax,-0xc(%ebp)
if(p->s.size >= nunits){
8de: 8b 45 f4 mov -0xc(%ebp),%eax
8e1: 8b 40 04 mov 0x4(%eax),%eax
8e4: 3b 45 ec cmp -0x14(%ebp),%eax
8e7: 72 4d jb 936 <malloc+0xa6>
if(p->s.size == nunits)
8e9: 8b 45 f4 mov -0xc(%ebp),%eax
8ec: 8b 40 04 mov 0x4(%eax),%eax
8ef: 3b 45 ec cmp -0x14(%ebp),%eax
8f2: 75 0c jne 900 <malloc+0x70>
prevp->s.ptr = p->s.ptr;
8f4: 8b 45 f4 mov -0xc(%ebp),%eax
8f7: 8b 10 mov (%eax),%edx
8f9: 8b 45 f0 mov -0x10(%ebp),%eax
8fc: 89 10 mov %edx,(%eax)
8fe: eb 26 jmp 926 <malloc+0x96>
else {
p->s.size -= nunits;
900: 8b 45 f4 mov -0xc(%ebp),%eax
903: 8b 40 04 mov 0x4(%eax),%eax
906: 2b 45 ec sub -0x14(%ebp),%eax
909: 89 c2 mov %eax,%edx
90b: 8b 45 f4 mov -0xc(%ebp),%eax
90e: 89 50 04 mov %edx,0x4(%eax)
p += p->s.size;
911: 8b 45 f4 mov -0xc(%ebp),%eax
914: 8b 40 04 mov 0x4(%eax),%eax
917: c1 e0 03 shl $0x3,%eax
91a: 01 45 f4 add %eax,-0xc(%ebp)
p->s.size = nunits;
91d: 8b 45 f4 mov -0xc(%ebp),%eax
920: 8b 55 ec mov -0x14(%ebp),%edx
923: 89 50 04 mov %edx,0x4(%eax)
}
freep = prevp;
926: 8b 45 f0 mov -0x10(%ebp),%eax
929: a3 58 0c 00 00 mov %eax,0xc58
return (void*)(p + 1);
92e: 8b 45 f4 mov -0xc(%ebp),%eax
931: 83 c0 08 add $0x8,%eax
934: eb 3b jmp 971 <malloc+0xe1>
}
if(p == freep)
936: a1 58 0c 00 00 mov 0xc58,%eax
93b: 39 45 f4 cmp %eax,-0xc(%ebp)
93e: 75 1e jne 95e <malloc+0xce>
if((p = morecore(nunits)) == 0)
940: 83 ec 0c sub $0xc,%esp
943: ff 75 ec pushl -0x14(%ebp)
946: e8 e5 fe ff ff call 830 <morecore>
94b: 83 c4 10 add $0x10,%esp
94e: 89 45 f4 mov %eax,-0xc(%ebp)
951: 83 7d f4 00 cmpl $0x0,-0xc(%ebp)
955: 75 07 jne 95e <malloc+0xce>
return 0;
957: b8 00 00 00 00 mov $0x0,%eax
95c: eb 13 jmp 971 <malloc+0xe1>
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){
95e: 8b 45 f4 mov -0xc(%ebp),%eax
961: 89 45 f0 mov %eax,-0x10(%ebp)
964: 8b 45 f4 mov -0xc(%ebp),%eax
967: 8b 00 mov (%eax),%eax
969: 89 45 f4 mov %eax,-0xc(%ebp)
return (void*)(p + 1);
}
if(p == freep)
if((p = morecore(nunits)) == 0)
return 0;
}
96c: e9 6d ff ff ff jmp 8de <malloc+0x4e>
}
971: c9 leave
972: c3 ret
|
extern m7_ippsTDESDecryptECB:function
extern n8_ippsTDESDecryptECB:function
extern y8_ippsTDESDecryptECB:function
extern e9_ippsTDESDecryptECB:function
extern l9_ippsTDESDecryptECB:function
extern n0_ippsTDESDecryptECB:function
extern k0_ippsTDESDecryptECB:function
extern ippcpJumpIndexForMergedLibs
extern ippcpSafeInit:function
segment .data
align 8
dq .Lin_ippsTDESDecryptECB
.Larraddr_ippsTDESDecryptECB:
dq m7_ippsTDESDecryptECB
dq n8_ippsTDESDecryptECB
dq y8_ippsTDESDecryptECB
dq e9_ippsTDESDecryptECB
dq l9_ippsTDESDecryptECB
dq n0_ippsTDESDecryptECB
dq k0_ippsTDESDecryptECB
segment .text
global ippsTDESDecryptECB:function (ippsTDESDecryptECB.LEndippsTDESDecryptECB - ippsTDESDecryptECB)
.Lin_ippsTDESDecryptECB:
db 0xf3, 0x0f, 0x1e, 0xfa
call ippcpSafeInit wrt ..plt
align 16
ippsTDESDecryptECB:
db 0xf3, 0x0f, 0x1e, 0xfa
mov rax, qword [rel ippcpJumpIndexForMergedLibs wrt ..gotpc]
movsxd rax, dword [rax]
lea r11, [rel .Larraddr_ippsTDESDecryptECB]
mov r11, qword [r11+rax*8]
jmp r11
.LEndippsTDESDecryptECB:
|
/***********************************************************************************************************************
* OpenStudio(R), Copyright (c) 2008-2016, Alliance for Sustainable Energy, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
* following conditions are met:
*
* (1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following
* disclaimer.
*
* (2) 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.
*
* (3) Neither the name of the copyright holder nor the names of any contributors may be used to endorse or promote
* products derived from this software without specific prior written permission from the respective party.
*
* (4) Other than as required in clauses (1) and (2), distributions in any form of modifications or other derivative
* works may not use the "OpenStudio" trademark, "OS", "os", or any other confusingly similar designation without
* specific prior written permission from Alliance for Sustainable Energy, LLC.
*
* 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 HOLDER, THE UNITED STATES GOVERNMENT, OR ANY 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 "ExternalInterfaceVariable.hpp"
#include "ExternalInterfaceVariable_Impl.hpp"
#include <utilities/idd/IddEnums.hxx>
#include <utilities/idd/OS_ExternalInterface_Variable_FieldEnums.hxx>
#include "../utilities/units/Unit.hpp"
#include "../utilities/core/Assert.hpp"
namespace openstudio {
namespace model {
namespace detail {
ExternalInterfaceVariable_Impl::ExternalInterfaceVariable_Impl(const IdfObject& idfObject,
Model_Impl* model,
bool keepHandle)
: ModelObject_Impl(idfObject,model,keepHandle)
{
OS_ASSERT(idfObject.iddObject().type() == ExternalInterfaceVariable::iddObjectType());
}
ExternalInterfaceVariable_Impl::ExternalInterfaceVariable_Impl(const openstudio::detail::WorkspaceObject_Impl& other,
Model_Impl* model,
bool keepHandle)
: ModelObject_Impl(other,model,keepHandle)
{
OS_ASSERT(other.iddObject().type() == ExternalInterfaceVariable::iddObjectType());
}
ExternalInterfaceVariable_Impl::ExternalInterfaceVariable_Impl(const ExternalInterfaceVariable_Impl& other,
Model_Impl* model,
bool keepHandle)
: ModelObject_Impl(other,model,keepHandle)
{}
const std::vector<std::string>& ExternalInterfaceVariable_Impl::outputVariableNames() const
{
static std::vector<std::string> result;
if (result.empty()){
}
return result;
}
IddObjectType ExternalInterfaceVariable_Impl::iddObjectType() const {
return ExternalInterfaceVariable::iddObjectType();
}
double ExternalInterfaceVariable_Impl::initialValue() const {
boost::optional<double> value = getDouble(OS_ExternalInterface_VariableFields::InitialValue,true);
if (value) {
return value.get();
}
return -9999;
}
bool ExternalInterfaceVariable_Impl::setInitialValue(double initialValue) {
bool result = setDouble(OS_ExternalInterface_VariableFields::InitialValue, initialValue);
OS_ASSERT(result);
return result;
}
bool ExternalInterfaceVariable_Impl::exportToBCVTB() const {
boost::optional<std::string> value = getString(OS_ExternalInterface_VariableFields::ExportToBCVTB, true);
OS_ASSERT(value);
return openstudio::istringEqual(value.get(), "True");
}
bool ExternalInterfaceVariable_Impl::isExportToBCVTBDefaulted() const {
return isEmpty(OS_ExternalInterface_VariableFields::ExportToBCVTB);
}
bool ExternalInterfaceVariable_Impl::setExportToBCVTB(bool exportToBCVTB) {
bool result = false;
if (exportToBCVTB) {
result = setString(OS_ExternalInterface_VariableFields::ExportToBCVTB, "True");
} else {
result = setString(OS_ExternalInterface_VariableFields::ExportToBCVTB, "False");
}
OS_ASSERT(result);
return result;
}
void ExternalInterfaceVariable_Impl::resetExportToBCVTB() {
bool result = setString(OS_ExternalInterface_VariableFields::ExportToBCVTB, "");
OS_ASSERT(result);
}
} // detail
ExternalInterfaceVariable::ExternalInterfaceVariable(const Model& model, const std::string& variableName, double initialValue)
: ModelObject(ExternalInterfaceVariable::iddObjectType(),model)
{
OS_ASSERT(getImpl<detail::ExternalInterfaceVariable_Impl>());
bool ok = getImpl<detail::ExternalInterfaceVariable_Impl>()->setName(variableName);
if ( (!ok) || (variableName != this->nameString() )) {
remove();
LOG_AND_THROW("Unable to set " << briefDescription() << "'s Name to " << variableName << ".");
}
setInitialValue(initialValue);
}
IddObjectType ExternalInterfaceVariable::iddObjectType() {
return IddObjectType(IddObjectType::OS_ExternalInterface_Variable);
}
double ExternalInterfaceVariable::initialValue() const {
return getImpl<detail::ExternalInterfaceVariable_Impl>()->initialValue();
}
bool ExternalInterfaceVariable::setInitialValue(double initialValue) {
return getImpl<detail::ExternalInterfaceVariable_Impl>()->setInitialValue(initialValue);
}
bool ExternalInterfaceVariable::exportToBCVTB() const {
return getImpl<detail::ExternalInterfaceVariable_Impl>()->exportToBCVTB();
}
bool ExternalInterfaceVariable::isExportToBCVTBDefaulted() const {
return getImpl<detail::ExternalInterfaceVariable_Impl>()->isExportToBCVTBDefaulted();
}
bool ExternalInterfaceVariable::setExportToBCVTB(bool exportToBCVTB) {
return getImpl<detail::ExternalInterfaceVariable_Impl>()->setExportToBCVTB(exportToBCVTB);
}
void ExternalInterfaceVariable::resetExportToBCVTB() {
getImpl<detail::ExternalInterfaceVariable_Impl>()->resetExportToBCVTB();
}
/// @cond
ExternalInterfaceVariable::ExternalInterfaceVariable(std::shared_ptr<detail::ExternalInterfaceVariable_Impl> impl)
: ModelObject(impl)
{}
/// @endcond
} // model
} // openstudio
|
; A141214: Defining A to be the interior angle of a regular polygon, the number of constructible regular polygons such that A is in a field extension <= degree 2^n, starting with n=0. This is also the number of values of x such that phi(x)/2 is a power of 2 <= 2^n (where phi is Euler's phi function), also starting with n=0.
; 3,7,12,18,25,33,42,52,63,75,88,102,117,133,150,168,187,207,228,250,273,297,322,348,375,403,432,462,493,525,558,592,626,660,694
mov $3,$0
mov $4,$0
mov $0,31
lpb $0
sub $0,1
add $2,$4
trn $4,1
lpe
mov $1,$2
lpb $3
add $1,3
sub $3,1
lpe
add $1,3
|
aci -128 ; CE 80
aci 127 ; CE 7F
aci 255 ; CE FF
adc (hl) ; 8E
adc -128 ; CE 80
adc 127 ; CE 7F
adc 255 ; CE FF
adc a ; 8F
adc a, (hl) ; 8E
adc a, -128 ; CE 80
adc a, 127 ; CE 7F
adc a, 255 ; CE FF
adc a, a ; 8F
adc a, b ; 88
adc a, c ; 89
adc a, d ; 8A
adc a, e ; 8B
adc a, h ; 8C
adc a, l ; 8D
adc b ; 88
adc c ; 89
adc d ; 8A
adc e ; 8B
adc h ; 8C
adc hl, bc ; CD @__z80asm__adc_hl_bc
adc hl, de ; CD @__z80asm__adc_hl_de
adc hl, hl ; CD @__z80asm__adc_hl_hl
adc hl, sp ; CD @__z80asm__adc_hl_sp
adc l ; 8D
adc m ; 8E
add (hl) ; 86
add -128 ; C6 80
add 127 ; C6 7F
add 255 ; C6 FF
add a ; 87
add a, (hl) ; 86
add a, -128 ; C6 80
add a, 127 ; C6 7F
add a, 255 ; C6 FF
add a, a ; 87
add a, b ; 80
add a, c ; 81
add a, d ; 82
add a, e ; 83
add a, h ; 84
add a, l ; 85
add b ; 80
add bc, -32768 ; E5 21 00 80 09 44 4D E1
add bc, 32767 ; E5 21 FF 7F 09 44 4D E1
add bc, 65535 ; E5 21 FF FF 09 44 4D E1
add bc, a ; CD @__z80asm__add_bc_a
add c ; 81
add d ; 82
add de, -32768 ; E5 21 00 80 19 54 5D E1
add de, 32767 ; E5 21 FF 7F 19 54 5D E1
add de, 65535 ; E5 21 FF FF 19 54 5D E1
add de, a ; CD @__z80asm__add_de_a
add e ; 83
add h ; 84
add hl, -32768 ; D5 11 00 80 19 D1
add hl, 32767 ; D5 11 FF 7F 19 D1
add hl, 65535 ; D5 11 FF FF 19 D1
add hl, a ; CD @__z80asm__add_hl_a
add hl, bc ; 09
add hl, de ; 19
add hl, hl ; 29
add hl, sp ; 39
add l ; 85
add m ; 86
add.a sp, -128 ; E5 3E 80 6F 17 9F 67 39 F9 E1
add.a sp, 127 ; E5 3E 7F 6F 17 9F 67 39 F9 E1
adi -128 ; C6 80
adi 127 ; C6 7F
adi 255 ; C6 FF
ana a ; A7
ana b ; A0
ana c ; A1
ana d ; A2
ana e ; A3
ana h ; A4
ana l ; A5
ana m ; A6
and (hl) ; A6
and -128 ; E6 80
and 127 ; E6 7F
and 255 ; E6 FF
and a ; A7
and a, (hl) ; A6
and a, -128 ; E6 80
and a, 127 ; E6 7F
and a, 255 ; E6 FF
and a, a ; A7
and a, b ; A0
and a, c ; A1
and a, d ; A2
and a, e ; A3
and a, h ; A4
and a, l ; A5
and b ; A0
and c ; A1
and d ; A2
and e ; A3
and h ; A4
and l ; A5
and.a hl, bc ; 7C A0 67 7D A1 6F
and.a hl, de ; 7C A2 67 7D A3 6F
ani -128 ; E6 80
ani 127 ; E6 7F
ani 255 ; E6 FF
arhl ; CD @__z80asm__sra_hl
bit.a 0, (hl) ; 7E E6 01
bit.a 0, a ; E6 01
bit.a 0, b ; 78 E6 01
bit.a 0, c ; 79 E6 01
bit.a 0, d ; 7A E6 01
bit.a 0, e ; 7B E6 01
bit.a 0, h ; 7C E6 01
bit.a 0, l ; 7D E6 01
bit.a 1, (hl) ; 7E E6 02
bit.a 1, a ; E6 02
bit.a 1, b ; 78 E6 02
bit.a 1, c ; 79 E6 02
bit.a 1, d ; 7A E6 02
bit.a 1, e ; 7B E6 02
bit.a 1, h ; 7C E6 02
bit.a 1, l ; 7D E6 02
bit.a 2, (hl) ; 7E E6 04
bit.a 2, a ; E6 04
bit.a 2, b ; 78 E6 04
bit.a 2, c ; 79 E6 04
bit.a 2, d ; 7A E6 04
bit.a 2, e ; 7B E6 04
bit.a 2, h ; 7C E6 04
bit.a 2, l ; 7D E6 04
bit.a 3, (hl) ; 7E E6 08
bit.a 3, a ; E6 08
bit.a 3, b ; 78 E6 08
bit.a 3, c ; 79 E6 08
bit.a 3, d ; 7A E6 08
bit.a 3, e ; 7B E6 08
bit.a 3, h ; 7C E6 08
bit.a 3, l ; 7D E6 08
bit.a 4, (hl) ; 7E E6 10
bit.a 4, a ; E6 10
bit.a 4, b ; 78 E6 10
bit.a 4, c ; 79 E6 10
bit.a 4, d ; 7A E6 10
bit.a 4, e ; 7B E6 10
bit.a 4, h ; 7C E6 10
bit.a 4, l ; 7D E6 10
bit.a 5, (hl) ; 7E E6 20
bit.a 5, a ; E6 20
bit.a 5, b ; 78 E6 20
bit.a 5, c ; 79 E6 20
bit.a 5, d ; 7A E6 20
bit.a 5, e ; 7B E6 20
bit.a 5, h ; 7C E6 20
bit.a 5, l ; 7D E6 20
bit.a 6, (hl) ; 7E E6 40
bit.a 6, a ; E6 40
bit.a 6, b ; 78 E6 40
bit.a 6, c ; 79 E6 40
bit.a 6, d ; 7A E6 40
bit.a 6, e ; 7B E6 40
bit.a 6, h ; 7C E6 40
bit.a 6, l ; 7D E6 40
bit.a 7, (hl) ; 7E E6 80
bit.a 7, a ; E6 80
bit.a 7, b ; 78 E6 80
bit.a 7, c ; 79 E6 80
bit.a 7, d ; 7A E6 80
bit.a 7, e ; 7B E6 80
bit.a 7, h ; 7C E6 80
bit.a 7, l ; 7D E6 80
call -32768 ; CD 00 80
call 32767 ; CD FF 7F
call 65535 ; CD FF FF
call c, -32768 ; DC 00 80
call c, 32767 ; DC FF 7F
call c, 65535 ; DC FF FF
call m, -32768 ; FC 00 80
call m, 32767 ; FC FF 7F
call m, 65535 ; FC FF FF
call nc, -32768 ; D4 00 80
call nc, 32767 ; D4 FF 7F
call nc, 65535 ; D4 FF FF
call nv, -32768 ; E4 00 80
call nv, 32767 ; E4 FF 7F
call nv, 65535 ; E4 FF FF
call nz, -32768 ; C4 00 80
call nz, 32767 ; C4 FF 7F
call nz, 65535 ; C4 FF FF
call p, -32768 ; F4 00 80
call p, 32767 ; F4 FF 7F
call p, 65535 ; F4 FF FF
call pe, -32768 ; EC 00 80
call pe, 32767 ; EC FF 7F
call pe, 65535 ; EC FF FF
call po, -32768 ; E4 00 80
call po, 32767 ; E4 FF 7F
call po, 65535 ; E4 FF FF
call v, -32768 ; EC 00 80
call v, 32767 ; EC FF 7F
call v, 65535 ; EC FF FF
call z, -32768 ; CC 00 80
call z, 32767 ; CC FF 7F
call z, 65535 ; CC FF FF
cc -32768 ; DC 00 80
cc 32767 ; DC FF 7F
cc 65535 ; DC FF FF
ccf ; 3F
cm -32768 ; FC 00 80
cm 32767 ; FC FF 7F
cm 65535 ; FC FF FF
cma ; 2F
cmc ; 3F
cmp (hl) ; BE
cmp -128 ; FE 80
cmp 127 ; FE 7F
cmp 255 ; FE FF
cmp a ; BF
cmp a, (hl) ; BE
cmp a, -128 ; FE 80
cmp a, 127 ; FE 7F
cmp a, 255 ; FE FF
cmp a, a ; BF
cmp a, b ; B8
cmp a, c ; B9
cmp a, d ; BA
cmp a, e ; BB
cmp a, h ; BC
cmp a, l ; BD
cmp b ; B8
cmp c ; B9
cmp d ; BA
cmp e ; BB
cmp h ; BC
cmp l ; BD
cmp m ; BE
cnc -32768 ; D4 00 80
cnc 32767 ; D4 FF 7F
cnc 65535 ; D4 FF FF
cnv -32768 ; E4 00 80
cnv 32767 ; E4 FF 7F
cnv 65535 ; E4 FF FF
cnz -32768 ; C4 00 80
cnz 32767 ; C4 FF 7F
cnz 65535 ; C4 FF FF
cp (hl) ; BE
cp -128 ; FE 80
cp 127 ; FE 7F
cp 255 ; FE FF
cp a ; BF
cp a, (hl) ; BE
cp a, -128 ; FE 80
cp a, 127 ; FE 7F
cp a, 255 ; FE FF
cp a, a ; BF
cp a, b ; B8
cp a, c ; B9
cp a, d ; BA
cp a, e ; BB
cp a, h ; BC
cp a, l ; BD
cp b ; B8
cp c ; B9
cp d ; BA
cp e ; BB
cp h ; BC
cp l ; BD
cpd ; CD @__z80asm__cpd
cpdr ; CD @__z80asm__cpdr
cpe -32768 ; EC 00 80
cpe 32767 ; EC FF 7F
cpe 65535 ; EC FF FF
cpi ; CD @__z80asm__cpi
cpi -128 ; FE 80
cpi 127 ; FE 7F
cpi 255 ; FE FF
cpir ; CD @__z80asm__cpir
cpl ; 2F
cpl a ; 2F
cpo -32768 ; E4 00 80
cpo 32767 ; E4 FF 7F
cpo 65535 ; E4 FF FF
cv -32768 ; EC 00 80
cv 32767 ; EC FF 7F
cv 65535 ; EC FF FF
cz -32768 ; CC 00 80
cz 32767 ; CC FF 7F
cz 65535 ; CC FF FF
daa ; 27
dad b ; 09
dad bc ; 09
dad d ; 19
dad de ; 19
dad h ; 29
dad hl ; 29
dad sp ; 39
dcr a ; 3D
dcr b ; 05
dcr c ; 0D
dcr d ; 15
dcr e ; 1D
dcr h ; 25
dcr l ; 2D
dcr m ; 35
dcx b ; 0B
dcx bc ; 0B
dcx d ; 1B
dcx de ; 1B
dcx h ; 2B
dcx hl ; 2B
dcx sp ; 3B
dec (hl) ; 35
dec a ; 3D
dec b ; 05
dec bc ; 0B
dec c ; 0D
dec d ; 15
dec de ; 1B
dec e ; 1D
dec h ; 25
dec hl ; 2B
dec l ; 2D
dec sp ; 3B
di ; F3
djnz -32768 ; 05 C2 00 80
djnz 32767 ; 05 C2 FF 7F
djnz 65535 ; 05 C2 FF FF
djnz b, -32768 ; 05 C2 00 80
djnz b, 32767 ; 05 C2 FF 7F
djnz b, 65535 ; 05 C2 FF FF
dsub ; CD @__z80asm__sub_hl_bc
ei ; FB
ex (sp), hl ; E3
ex de, hl ; EB
halt ; 76
hlt ; 76
in -128 ; DB 80
in 127 ; DB 7F
in 255 ; DB FF
in a, (-128) ; DB 80
in a, (127) ; DB 7F
in a, (255) ; DB FF
inc (hl) ; 34
inc a ; 3C
inc b ; 04
inc bc ; 03
inc c ; 0C
inc d ; 14
inc de ; 13
inc e ; 1C
inc h ; 24
inc hl ; 23
inc l ; 2C
inc sp ; 33
inr a ; 3C
inr b ; 04
inr c ; 0C
inr d ; 14
inr e ; 1C
inr h ; 24
inr l ; 2C
inr m ; 34
inx b ; 03
inx bc ; 03
inx d ; 13
inx de ; 13
inx h ; 23
inx hl ; 23
inx sp ; 33
jc -32768 ; DA 00 80
jc 32767 ; DA FF 7F
jc 65535 ; DA FF FF
jm -32768 ; FA 00 80
jm 32767 ; FA FF 7F
jm 65535 ; FA FF FF
jmp -32768 ; C3 00 80
jmp 32767 ; C3 FF 7F
jmp 65535 ; C3 FF FF
jnc -32768 ; D2 00 80
jnc 32767 ; D2 FF 7F
jnc 65535 ; D2 FF FF
jnv -32768 ; E2 00 80
jnv 32767 ; E2 FF 7F
jnv 65535 ; E2 FF FF
jnz -32768 ; C2 00 80
jnz 32767 ; C2 FF 7F
jnz 65535 ; C2 FF FF
jp (bc) ; C5 C9
jp (de) ; D5 C9
jp (hl) ; E9
jp -32768 ; C3 00 80
jp 32767 ; C3 FF 7F
jp 65535 ; C3 FF FF
jp c, -32768 ; DA 00 80
jp c, 32767 ; DA FF 7F
jp c, 65535 ; DA FF FF
jp m, -32768 ; FA 00 80
jp m, 32767 ; FA FF 7F
jp m, 65535 ; FA FF FF
jp nc, -32768 ; D2 00 80
jp nc, 32767 ; D2 FF 7F
jp nc, 65535 ; D2 FF FF
jp nv, -32768 ; E2 00 80
jp nv, 32767 ; E2 FF 7F
jp nv, 65535 ; E2 FF FF
jp nz, -32768 ; C2 00 80
jp nz, 32767 ; C2 FF 7F
jp nz, 65535 ; C2 FF FF
jp p, -32768 ; F2 00 80
jp p, 32767 ; F2 FF 7F
jp p, 65535 ; F2 FF FF
jp pe, -32768 ; EA 00 80
jp pe, 32767 ; EA FF 7F
jp pe, 65535 ; EA FF FF
jp po, -32768 ; E2 00 80
jp po, 32767 ; E2 FF 7F
jp po, 65535 ; E2 FF FF
jp v, -32768 ; EA 00 80
jp v, 32767 ; EA FF 7F
jp v, 65535 ; EA FF FF
jp z, -32768 ; CA 00 80
jp z, 32767 ; CA FF 7F
jp z, 65535 ; CA FF FF
jpe -32768 ; EA 00 80
jpe 32767 ; EA FF 7F
jpe 65535 ; EA FF FF
jpo -32768 ; E2 00 80
jpo 32767 ; E2 FF 7F
jpo 65535 ; E2 FF FF
jr -32768 ; C3 00 80
jr 32767 ; C3 FF 7F
jr 65535 ; C3 FF FF
jr c, -32768 ; DA 00 80
jr c, 32767 ; DA FF 7F
jr c, 65535 ; DA FF FF
jr nc, -32768 ; D2 00 80
jr nc, 32767 ; D2 FF 7F
jr nc, 65535 ; D2 FF FF
jr nz, -32768 ; C2 00 80
jr nz, 32767 ; C2 FF 7F
jr nz, 65535 ; C2 FF FF
jr z, -32768 ; CA 00 80
jr z, 32767 ; CA FF 7F
jr z, 65535 ; CA FF FF
jv -32768 ; EA 00 80
jv 32767 ; EA FF 7F
jv 65535 ; EA FF FF
jz -32768 ; CA 00 80
jz 32767 ; CA FF 7F
jz 65535 ; CA FF FF
ld (-32768), a ; 32 00 80
ld (-32768), hl ; 22 00 80
ld (32767), a ; 32 FF 7F
ld (32767), hl ; 22 FF 7F
ld (65535), a ; 32 FF FF
ld (65535), hl ; 22 FF FF
ld (bc), a ; 02
ld (bc+), a ; 02 03
ld (bc-), a ; 02 0B
ld (de), a ; 12
ld (de+), a ; 12 13
ld (de-), a ; 12 1B
ld (hl), -128 ; 36 80
ld (hl), 127 ; 36 7F
ld (hl), 255 ; 36 FF
ld (hl), a ; 77
ld (hl), b ; 70
ld (hl), c ; 71
ld (hl), d ; 72
ld (hl), e ; 73
ld (hl), h ; 74
ld (hl), l ; 75
ld (hl+), a ; 77 23
ld (hl-), a ; 77 2B
ld (hld), a ; 77 2B
ld (hli), a ; 77 23
ld a, (-32768) ; 3A 00 80
ld a, (32767) ; 3A FF 7F
ld a, (65535) ; 3A FF FF
ld a, (bc) ; 0A
ld a, (bc+) ; 0A 03
ld a, (bc-) ; 0A 0B
ld a, (de) ; 1A
ld a, (de+) ; 1A 13
ld a, (de-) ; 1A 1B
ld a, (hl) ; 7E
ld a, (hl+) ; 7E 23
ld a, (hl-) ; 7E 2B
ld a, (hld) ; 7E 2B
ld a, (hli) ; 7E 23
ld a, -128 ; 3E 80
ld a, 127 ; 3E 7F
ld a, 255 ; 3E FF
ld a, a ; 7F
ld a, b ; 78
ld a, c ; 79
ld a, d ; 7A
ld a, e ; 7B
ld a, h ; 7C
ld a, l ; 7D
ld b, (hl) ; 46
ld b, -128 ; 06 80
ld b, 127 ; 06 7F
ld b, 255 ; 06 FF
ld b, a ; 47
ld b, b ; 40
ld b, c ; 41
ld b, d ; 42
ld b, e ; 43
ld b, h ; 44
ld b, l ; 45
ld bc, -32768 ; 01 00 80
ld bc, 32767 ; 01 FF 7F
ld bc, 65535 ; 01 FF FF
ld bc, de ; 42 4B
ld bc, hl ; 44 4D
ld c, (hl) ; 4E
ld c, -128 ; 0E 80
ld c, 127 ; 0E 7F
ld c, 255 ; 0E FF
ld c, a ; 4F
ld c, b ; 48
ld c, c ; 49
ld c, d ; 4A
ld c, e ; 4B
ld c, h ; 4C
ld c, l ; 4D
ld d, (hl) ; 56
ld d, -128 ; 16 80
ld d, 127 ; 16 7F
ld d, 255 ; 16 FF
ld d, a ; 57
ld d, b ; 50
ld d, c ; 51
ld d, d ; 52
ld d, e ; 53
ld d, h ; 54
ld d, l ; 55
ld de, -32768 ; 11 00 80
ld de, 32767 ; 11 FF 7F
ld de, 65535 ; 11 FF FF
ld de, bc ; 50 59
ld de, hl ; 54 5D
ld de, sp ; EB 21 00 00 39 EB
ld de, sp+0 ; EB 21 00 00 39 EB
ld de, sp+255 ; EB 21 FF 00 39 EB
ld e, (hl) ; 5E
ld e, -128 ; 1E 80
ld e, 127 ; 1E 7F
ld e, 255 ; 1E FF
ld e, a ; 5F
ld e, b ; 58
ld e, c ; 59
ld e, d ; 5A
ld e, e ; 5B
ld e, h ; 5C
ld e, l ; 5D
ld h, (hl) ; 66
ld h, -128 ; 26 80
ld h, 127 ; 26 7F
ld h, 255 ; 26 FF
ld h, a ; 67
ld h, b ; 60
ld h, c ; 61
ld h, d ; 62
ld h, e ; 63
ld h, h ; 64
ld h, l ; 65
ld hl, (-32768) ; 2A 00 80
ld hl, (32767) ; 2A FF 7F
ld hl, (65535) ; 2A FF FF
ld hl, -32768 ; 21 00 80
ld hl, 32767 ; 21 FF 7F
ld hl, 65535 ; 21 FF FF
ld hl, bc ; 60 69
ld hl, de ; 62 6B
ld hl, sp ; 21 00 00 39
ld hl, sp+-128 ; 21 80 FF 39
ld hl, sp+127 ; 21 7F 00 39
ld l, (hl) ; 6E
ld l, -128 ; 2E 80
ld l, 127 ; 2E 7F
ld l, 255 ; 2E FF
ld l, a ; 6F
ld l, b ; 68
ld l, c ; 69
ld l, d ; 6A
ld l, e ; 6B
ld l, h ; 6C
ld l, l ; 6D
ld sp, -32768 ; 31 00 80
ld sp, 32767 ; 31 FF 7F
ld sp, 65535 ; 31 FF FF
ld sp, hl ; F9
lda -32768 ; 3A 00 80
lda 32767 ; 3A FF 7F
lda 65535 ; 3A FF FF
ldax b ; 0A
ldax bc ; 0A
ldax d ; 1A
ldax de ; 1A
ldd ; CD @__z80asm__ldd
ldd (bc), a ; 02 0B
ldd (de), a ; 12 1B
ldd (hl), a ; 77 2B
ldd a, (bc) ; 0A 0B
ldd a, (de) ; 1A 1B
ldd a, (hl) ; 7E 2B
lddr ; CD @__z80asm__lddr
ldi ; CD @__z80asm__ldi
ldi (bc), a ; 02 03
ldi (de), a ; 12 13
ldi (hl), a ; 77 23
ldi a, (bc) ; 0A 03
ldi a, (de) ; 1A 13
ldi a, (hl) ; 7E 23
ldir ; CD @__z80asm__ldir
lhld -32768 ; 2A 00 80
lhld 32767 ; 2A FF 7F
lhld 65535 ; 2A FF FF
lxi b, -32768 ; 01 00 80
lxi b, 32767 ; 01 FF 7F
lxi b, 65535 ; 01 FF FF
lxi bc, -32768 ; 01 00 80
lxi bc, 32767 ; 01 FF 7F
lxi bc, 65535 ; 01 FF FF
lxi d, -32768 ; 11 00 80
lxi d, 32767 ; 11 FF 7F
lxi d, 65535 ; 11 FF FF
lxi de, -32768 ; 11 00 80
lxi de, 32767 ; 11 FF 7F
lxi de, 65535 ; 11 FF FF
lxi h, -32768 ; 21 00 80
lxi h, 32767 ; 21 FF 7F
lxi h, 65535 ; 21 FF FF
lxi hl, -32768 ; 21 00 80
lxi hl, 32767 ; 21 FF 7F
lxi hl, 65535 ; 21 FF FF
lxi sp, -32768 ; 31 00 80
lxi sp, 32767 ; 31 FF 7F
lxi sp, 65535 ; 31 FF FF
mov a, a ; 7F
mov a, b ; 78
mov a, c ; 79
mov a, d ; 7A
mov a, e ; 7B
mov a, h ; 7C
mov a, l ; 7D
mov a, m ; 7E
mov b, a ; 47
mov b, b ; 40
mov b, c ; 41
mov b, d ; 42
mov b, e ; 43
mov b, h ; 44
mov b, l ; 45
mov b, m ; 46
mov c, a ; 4F
mov c, b ; 48
mov c, c ; 49
mov c, d ; 4A
mov c, e ; 4B
mov c, h ; 4C
mov c, l ; 4D
mov c, m ; 4E
mov d, a ; 57
mov d, b ; 50
mov d, c ; 51
mov d, d ; 52
mov d, e ; 53
mov d, h ; 54
mov d, l ; 55
mov d, m ; 56
mov e, a ; 5F
mov e, b ; 58
mov e, c ; 59
mov e, d ; 5A
mov e, e ; 5B
mov e, h ; 5C
mov e, l ; 5D
mov e, m ; 5E
mov h, a ; 67
mov h, b ; 60
mov h, c ; 61
mov h, d ; 62
mov h, e ; 63
mov h, h ; 64
mov h, l ; 65
mov h, m ; 66
mov l, a ; 6F
mov l, b ; 68
mov l, c ; 69
mov l, d ; 6A
mov l, e ; 6B
mov l, h ; 6C
mov l, l ; 6D
mov l, m ; 6E
mov m, a ; 77
mov m, b ; 70
mov m, c ; 71
mov m, d ; 72
mov m, e ; 73
mov m, h ; 74
mov m, l ; 75
mvi a, -128 ; 3E 80
mvi a, 127 ; 3E 7F
mvi a, 255 ; 3E FF
mvi b, -128 ; 06 80
mvi b, 127 ; 06 7F
mvi b, 255 ; 06 FF
mvi c, -128 ; 0E 80
mvi c, 127 ; 0E 7F
mvi c, 255 ; 0E FF
mvi d, -128 ; 16 80
mvi d, 127 ; 16 7F
mvi d, 255 ; 16 FF
mvi e, -128 ; 1E 80
mvi e, 127 ; 1E 7F
mvi e, 255 ; 1E FF
mvi h, -128 ; 26 80
mvi h, 127 ; 26 7F
mvi h, 255 ; 26 FF
mvi l, -128 ; 2E 80
mvi l, 127 ; 2E 7F
mvi l, 255 ; 2E FF
mvi m, -128 ; 36 80
mvi m, 127 ; 36 7F
mvi m, 255 ; 36 FF
neg ; 2F 3C
neg a ; 2F 3C
nop ; 00
or (hl) ; B6
or -128 ; F6 80
or 127 ; F6 7F
or 255 ; F6 FF
or a ; B7
or a, (hl) ; B6
or a, -128 ; F6 80
or a, 127 ; F6 7F
or a, 255 ; F6 FF
or a, a ; B7
or a, b ; B0
or a, c ; B1
or a, d ; B2
or a, e ; B3
or a, h ; B4
or a, l ; B5
or b ; B0
or c ; B1
or d ; B2
or e ; B3
or h ; B4
or l ; B5
ora a ; B7
ora b ; B0
ora c ; B1
ora d ; B2
ora e ; B3
ora h ; B4
ora l ; B5
ora m ; B6
ori -128 ; F6 80
ori 127 ; F6 7F
ori 255 ; F6 FF
out (-128), a ; D3 80
out (127), a ; D3 7F
out (255), a ; D3 FF
out -128 ; D3 80
out 127 ; D3 7F
out 255 ; D3 FF
pchl ; E9
pop af ; F1
pop b ; C1
pop bc ; C1
pop d ; D1
pop de ; D1
pop h ; E1
pop hl ; E1
pop psw ; F1
push af ; F5
push b ; C5
push bc ; C5
push d ; D5
push de ; D5
push h ; E5
push hl ; E5
push psw ; F5
ral ; 17
rar ; 1F
rc ; D8
rdel ; CD @__z80asm__rl_de
res.a 0, (hl) ; 7E E6 FE 77
res.a 0, a ; E6 FE
res.a 0, b ; 78 E6 FE 47
res.a 0, c ; 79 E6 FE 4F
res.a 0, d ; 7A E6 FE 57
res.a 0, e ; 7B E6 FE 5F
res.a 0, h ; 7C E6 FE 67
res.a 0, l ; 7D E6 FE 6F
res.a 1, (hl) ; 7E E6 FD 77
res.a 1, a ; E6 FD
res.a 1, b ; 78 E6 FD 47
res.a 1, c ; 79 E6 FD 4F
res.a 1, d ; 7A E6 FD 57
res.a 1, e ; 7B E6 FD 5F
res.a 1, h ; 7C E6 FD 67
res.a 1, l ; 7D E6 FD 6F
res.a 2, (hl) ; 7E E6 FB 77
res.a 2, a ; E6 FB
res.a 2, b ; 78 E6 FB 47
res.a 2, c ; 79 E6 FB 4F
res.a 2, d ; 7A E6 FB 57
res.a 2, e ; 7B E6 FB 5F
res.a 2, h ; 7C E6 FB 67
res.a 2, l ; 7D E6 FB 6F
res.a 3, (hl) ; 7E E6 F7 77
res.a 3, a ; E6 F7
res.a 3, b ; 78 E6 F7 47
res.a 3, c ; 79 E6 F7 4F
res.a 3, d ; 7A E6 F7 57
res.a 3, e ; 7B E6 F7 5F
res.a 3, h ; 7C E6 F7 67
res.a 3, l ; 7D E6 F7 6F
res.a 4, (hl) ; 7E E6 EF 77
res.a 4, a ; E6 EF
res.a 4, b ; 78 E6 EF 47
res.a 4, c ; 79 E6 EF 4F
res.a 4, d ; 7A E6 EF 57
res.a 4, e ; 7B E6 EF 5F
res.a 4, h ; 7C E6 EF 67
res.a 4, l ; 7D E6 EF 6F
res.a 5, (hl) ; 7E E6 DF 77
res.a 5, a ; E6 DF
res.a 5, b ; 78 E6 DF 47
res.a 5, c ; 79 E6 DF 4F
res.a 5, d ; 7A E6 DF 57
res.a 5, e ; 7B E6 DF 5F
res.a 5, h ; 7C E6 DF 67
res.a 5, l ; 7D E6 DF 6F
res.a 6, (hl) ; 7E E6 BF 77
res.a 6, a ; E6 BF
res.a 6, b ; 78 E6 BF 47
res.a 6, c ; 79 E6 BF 4F
res.a 6, d ; 7A E6 BF 57
res.a 6, e ; 7B E6 BF 5F
res.a 6, h ; 7C E6 BF 67
res.a 6, l ; 7D E6 BF 6F
res.a 7, (hl) ; 7E E6 7F 77
res.a 7, a ; E6 7F
res.a 7, b ; 78 E6 7F 47
res.a 7, c ; 79 E6 7F 4F
res.a 7, d ; 7A E6 7F 57
res.a 7, e ; 7B E6 7F 5F
res.a 7, h ; 7C E6 7F 67
res.a 7, l ; 7D E6 7F 6F
ret ; C9
ret c ; D8
ret m ; F8
ret nc ; D0
ret nv ; E0
ret nz ; C0
ret p ; F0
ret pe ; E8
ret po ; E0
ret v ; E8
ret z ; C8
rl bc ; CD @__z80asm__rl_bc
rl de ; CD @__z80asm__rl_de
rl hl ; CD @__z80asm__rl_hl
rla ; 17
rlc ; 07
rlca ; 07
rld ; CD @__z80asm__rld
rlde ; CD @__z80asm__rl_de
rm ; F8
rnc ; D0
rnv ; E0
rnz ; C0
rp ; F0
rpe ; E8
rpo ; E0
rr bc ; CD @__z80asm__rr_bc
rr de ; CD @__z80asm__rr_de
rr hl ; CD @__z80asm__rr_hl
rra ; 1F
rrc ; 0F
rrca ; 0F
rrd ; CD @__z80asm__rrd
rrhl ; CD @__z80asm__sra_hl
rst 0 ; C7
rst 1 ; CF
rst 16 ; D7
rst 2 ; D7
rst 24 ; DF
rst 3 ; DF
rst 32 ; E7
rst 4 ; E7
rst 40 ; EF
rst 48 ; F7
rst 5 ; EF
rst 56 ; FF
rst 6 ; F7
rst 7 ; FF
rst 8 ; CF
rv ; E8
rz ; C8
sbb a ; 9F
sbb b ; 98
sbb c ; 99
sbb d ; 9A
sbb e ; 9B
sbb h ; 9C
sbb l ; 9D
sbb m ; 9E
sbc (hl) ; 9E
sbc -128 ; DE 80
sbc 127 ; DE 7F
sbc 255 ; DE FF
sbc a ; 9F
sbc a, (hl) ; 9E
sbc a, -128 ; DE 80
sbc a, 127 ; DE 7F
sbc a, 255 ; DE FF
sbc a, a ; 9F
sbc a, b ; 98
sbc a, c ; 99
sbc a, d ; 9A
sbc a, e ; 9B
sbc a, h ; 9C
sbc a, l ; 9D
sbc b ; 98
sbc c ; 99
sbc d ; 9A
sbc e ; 9B
sbc h ; 9C
sbc hl, bc ; CD @__z80asm__sbc_hl_bc
sbc hl, de ; CD @__z80asm__sbc_hl_de
sbc hl, hl ; CD @__z80asm__sbc_hl_hl
sbc hl, sp ; CD @__z80asm__sbc_hl_sp
sbc l ; 9D
sbi -128 ; DE 80
sbi 127 ; DE 7F
sbi 255 ; DE FF
scf ; 37
set.a 0, (hl) ; 7E F6 01 77
set.a 0, a ; F6 01
set.a 0, b ; 78 F6 01 47
set.a 0, c ; 79 F6 01 4F
set.a 0, d ; 7A F6 01 57
set.a 0, e ; 7B F6 01 5F
set.a 0, h ; 7C F6 01 67
set.a 0, l ; 7D F6 01 6F
set.a 1, (hl) ; 7E F6 02 77
set.a 1, a ; F6 02
set.a 1, b ; 78 F6 02 47
set.a 1, c ; 79 F6 02 4F
set.a 1, d ; 7A F6 02 57
set.a 1, e ; 7B F6 02 5F
set.a 1, h ; 7C F6 02 67
set.a 1, l ; 7D F6 02 6F
set.a 2, (hl) ; 7E F6 04 77
set.a 2, a ; F6 04
set.a 2, b ; 78 F6 04 47
set.a 2, c ; 79 F6 04 4F
set.a 2, d ; 7A F6 04 57
set.a 2, e ; 7B F6 04 5F
set.a 2, h ; 7C F6 04 67
set.a 2, l ; 7D F6 04 6F
set.a 3, (hl) ; 7E F6 08 77
set.a 3, a ; F6 08
set.a 3, b ; 78 F6 08 47
set.a 3, c ; 79 F6 08 4F
set.a 3, d ; 7A F6 08 57
set.a 3, e ; 7B F6 08 5F
set.a 3, h ; 7C F6 08 67
set.a 3, l ; 7D F6 08 6F
set.a 4, (hl) ; 7E F6 10 77
set.a 4, a ; F6 10
set.a 4, b ; 78 F6 10 47
set.a 4, c ; 79 F6 10 4F
set.a 4, d ; 7A F6 10 57
set.a 4, e ; 7B F6 10 5F
set.a 4, h ; 7C F6 10 67
set.a 4, l ; 7D F6 10 6F
set.a 5, (hl) ; 7E F6 20 77
set.a 5, a ; F6 20
set.a 5, b ; 78 F6 20 47
set.a 5, c ; 79 F6 20 4F
set.a 5, d ; 7A F6 20 57
set.a 5, e ; 7B F6 20 5F
set.a 5, h ; 7C F6 20 67
set.a 5, l ; 7D F6 20 6F
set.a 6, (hl) ; 7E F6 40 77
set.a 6, a ; F6 40
set.a 6, b ; 78 F6 40 47
set.a 6, c ; 79 F6 40 4F
set.a 6, d ; 7A F6 40 57
set.a 6, e ; 7B F6 40 5F
set.a 6, h ; 7C F6 40 67
set.a 6, l ; 7D F6 40 6F
set.a 7, (hl) ; 7E F6 80 77
set.a 7, a ; F6 80
set.a 7, b ; 78 F6 80 47
set.a 7, c ; 79 F6 80 4F
set.a 7, d ; 7A F6 80 57
set.a 7, e ; 7B F6 80 5F
set.a 7, h ; 7C F6 80 67
set.a 7, l ; 7D F6 80 6F
shld -32768 ; 22 00 80
shld 32767 ; 22 FF 7F
shld 65535 ; 22 FF FF
sphl ; F9
sra bc ; CD @__z80asm__sra_bc
sra de ; CD @__z80asm__sra_de
sra hl ; CD @__z80asm__sra_hl
sta -32768 ; 32 00 80
sta 32767 ; 32 FF 7F
sta 65535 ; 32 FF FF
stax b ; 02
stax bc ; 02
stax d ; 12
stax de ; 12
stc ; 37
sub (hl) ; 96
sub -128 ; D6 80
sub 127 ; D6 7F
sub 255 ; D6 FF
sub a ; 97
sub a, (hl) ; 96
sub a, -128 ; D6 80
sub a, 127 ; D6 7F
sub a, 255 ; D6 FF
sub a, a ; 97
sub a, b ; 90
sub a, c ; 91
sub a, d ; 92
sub a, e ; 93
sub a, h ; 94
sub a, l ; 95
sub b ; 90
sub c ; 91
sub d ; 92
sub e ; 93
sub h ; 94
sub hl, bc ; CD @__z80asm__sub_hl_bc
sub hl, de ; CD @__z80asm__sub_hl_de
sub hl, hl ; CD @__z80asm__sub_hl_hl
sub hl, sp ; CD @__z80asm__sub_hl_sp
sub l ; 95
sub m ; 96
sui -128 ; D6 80
sui 127 ; D6 7F
sui 255 ; D6 FF
xchg ; EB
xor (hl) ; AE
xor -128 ; EE 80
xor 127 ; EE 7F
xor 255 ; EE FF
xor a ; AF
xor a, (hl) ; AE
xor a, -128 ; EE 80
xor a, 127 ; EE 7F
xor a, 255 ; EE FF
xor a, a ; AF
xor a, b ; A8
xor a, c ; A9
xor a, d ; AA
xor a, e ; AB
xor a, h ; AC
xor a, l ; AD
xor b ; A8
xor c ; A9
xor d ; AA
xor e ; AB
xor h ; AC
xor l ; AD
xra a ; AF
xra b ; A8
xra c ; A9
xra d ; AA
xra e ; AB
xra h ; AC
xra l ; AD
xra m ; AE
xri -128 ; EE 80
xri 127 ; EE 7F
xri 255 ; EE FF
xthl ; E3
|
; A100158: Structured disdyakis triacontahedral numbers (vertex structure 11).
; 1,62,293,804,1705,3106,5117,7848,11409,15910,21461,28172,36153,45514,56365,68816,82977,98958,116869,136820,158921,183282,210013,239224,271025,305526,342837,383068,426329,472730,522381,575392,631873,691934,755685,823236,894697,970178,1049789,1133640,1221841,1314502,1411733,1513644,1620345,1731946,1848557,1970288,2097249,2229550,2367301,2510612,2659593,2814354,2975005,3141656,3314417,3493398,3678709,3870460,4068761,4273722,4485453,4704064,4929665,5162366,5402277,5649508,5904169,6166370,6436221,6713832,6999313,7292774,7594325,7904076,8222137,8548618,8883629,9227280,9579681,9940942,10311173,10690484,11078985,11476786,11883997,12300728,12727089,13163190,13609141,14065052,14531033,15007194,15493645,15990496,16497857,17015838,17544549,18084100,18634601,19196162,19768893,20352904,20948305,21555206,22173717,22803948,23446009,24100010,24766061,25444272,26134753,26837614,27552965,28280916,29021577,29775058,30541469,31320920,32113521,32919382,33738613,34571324,35417625,36277626,37151437,38039168,38940929,39856830,40786981,41731492,42690473,43664034,44652285,45655336,46673297,47706278,48754389,49817740,50896441,51990602,53100333,54225744,55366945,56524046,57697157,58886388,60091849,61313650,62551901,63806712,65078193,66366454,67671605,68993756,70333017,71689498,73063309,74454560,75863361,77289822,78734053,80196164,81676265,83174466,84690877,86225608,87778769,89350470,90940821,92549932,94177913,95824874,97490925,99176176,100880737,102604718,104348229,106111380,107894281,109697042,111519773,113362584,115225585,117108886,119012597,120936828,122881689,124847290,126833741,128841152,130869633,132919294,134990245,137082596,139196457,141331938,143489149,145668200,147869201,150092262,152337493,154605004,156894905,159207306,161542317,163900048,166280609,168684110,171110661,173560372,176033353,178529714,181049565,183593016,186160177,188751158,191366069,194005020,196668121,199355482,202067213,204803424,207564225,210349726,213160037,215995268,218855529,221740930,224651581,227587592,230549073,233536134,236548885,239587436,242651897,245742378,248858989,252001840,255171041,258366702,261588933,264837844,268113545,271416146,274745757,278102488,281486449,284897750
mov $7,$0
lpb $0
add $4,$0
sub $0,1
add $4,6
add $1,$4
lpe
mul $1,4
add $1,1
mov $3,$7
mov $6,$7
lpb $3
sub $3,1
add $5,$6
lpe
mov $2,16
mov $6,$5
lpb $2
add $1,$6
sub $2,1
lpe
mov $3,$7
mov $5,0
lpb $3
sub $3,1
add $5,$6
lpe
mov $2,17
mov $6,$5
lpb $2
add $1,$6
sub $2,1
lpe
|
//
// FILE: unit_test_001.cpp
// AUTHOR: Rob Tillaart
// DATE: 2021-01-01
// PURPOSE: unit tests for the PrintCharArray library
// https://github.com/RobTillaart/PrintCharArray
// https://github.com/Arduino-CI/arduino_ci/blob/master/REFERENCE.md
//
// supported assertions
// ----------------------------
// assertEqual(expected, actual); // a == b
// assertNotEqual(unwanted, actual); // a != b
// assertComparativeEquivalent(expected, actual); // abs(a - b) == 0 or (!(a > b) && !(a < b))
// assertComparativeNotEquivalent(unwanted, actual); // abs(a - b) > 0 or ((a > b) || (a < b))
// assertLess(upperBound, actual); // a < b
// assertMore(lowerBound, actual); // a > b
// assertLessOrEqual(upperBound, actual); // a <= b
// assertMoreOrEqual(lowerBound, actual); // a >= b
// assertTrue(actual);
// assertFalse(actual);
// assertNull(actual);
// // special cases for floats
// assertEqualFloat(expected, actual, epsilon); // fabs(a - b) <= epsilon
// assertNotEqualFloat(unwanted, actual, epsilon); // fabs(a - b) >= epsilon
// assertInfinity(actual); // isinf(a)
// assertNotInfinity(actual); // !isinf(a)
// assertNAN(arg); // isnan(a)
// assertNotNAN(arg); // !isnan(a)
#include <ArduinoUnitTests.h>
#include "Arduino.h"
#include "PrintCharArray.h"
unittest_setup()
{
fprintf(stderr, "PRINTCHARARRAY_VERSION: %s\n", (char *) PRINTCHARARRAY_VERSION);
}
unittest_teardown()
{
}
unittest(test_constants)
{
assertEqual(PRINTCHARARRAY_MAX_BUFFER_SIZE, 250);
}
unittest(test_constructor)
{
PrintCharArray ps(100);
assertEqual(100, ps.bufSize());
assertEqual(100, ps.available());
assertEqual(0, ps.size());
ps.print("Hello World");
fprintf(stderr, "%s\n", ps.getBuffer());
assertEqual(89, ps.available());
assertEqual(11, ps.size());
ps.print(" and moon");
fprintf(stderr, "%s\n", ps.getBuffer());
assertEqual(80, ps.available());
assertEqual(20, ps.size());
ps.clear();
assertEqual(100, ps.available());
assertEqual(0, ps.size());
}
unittest_main()
// --------
|
#ifdef CH_LANG_CC
/*
* _______ __
* / ___/ / ___ __ _ / / ___
* / /__/ _ \/ _ \/ V \/ _ \/ _ \
* \___/_//_/\___/_/_/_/_.__/\___/
* Please refer to Copyright.txt, in Chombo's root directory.
*/
#endif
#include <cmath>
#include "REAL.H"
#include "IntVect.H"
#include "Box.H"
#include "FArrayBox.H"
#include "LevelData.H"
#include "IntVectSet.H"
#include "DisjointBoxLayout.H"
#include "LayoutIterator.H"
#include "InterpF_F.H"
#include "CH_Timer.H"
#include "parstream.H"
#include "MayDay.H"
using std::endl;
#include "PiecewiseLinearFillPatch.H"
#include "NamespaceHeader.H"
#ifndef copysign
template <class T>
inline
T
copysign (const T& a,
const T& b)
{
return ( b >= 0 ) ? ( ( a >= 0 ) ? a : -a) : ( (a >= 0 ) ? -a : a);
}
#endif
const int PiecewiseLinearFillPatch::s_stencil_radius = 1;
PiecewiseLinearFillPatch::PiecewiseLinearFillPatch()
:
m_is_defined(false)
{
}
PiecewiseLinearFillPatch::~PiecewiseLinearFillPatch()
{
}
PiecewiseLinearFillPatch::PiecewiseLinearFillPatch(
const DisjointBoxLayout& a_fine_domain,
const DisjointBoxLayout& a_coarse_domain,
int a_num_comps,
const Box& a_crse_problem_domain,
int a_ref_ratio,
int a_interp_radius,
bool a_pwconst_interp_only)
:
m_is_defined(false)
{
ProblemDomain crseProbDomain(a_crse_problem_domain);
define(a_fine_domain,
a_coarse_domain,
a_num_comps,
crseProbDomain,
a_ref_ratio,
a_interp_radius,
a_pwconst_interp_only);
}
PiecewiseLinearFillPatch::PiecewiseLinearFillPatch(
const DisjointBoxLayout& a_fine_domain,
const DisjointBoxLayout& a_coarse_domain,
int a_num_comps,
const ProblemDomain& a_crse_problem_domain,
int a_ref_ratio,
int a_interp_radius,
bool a_pwconst_interp_only)
:
m_is_defined(false)
{
define(a_fine_domain,
a_coarse_domain,
a_num_comps,
a_crse_problem_domain,
a_ref_ratio,
a_interp_radius,
a_pwconst_interp_only);
}
void
PiecewiseLinearFillPatch::define(
const DisjointBoxLayout& a_fine_domain,
const DisjointBoxLayout& a_coarse_domain,
int a_num_comps,
const Box& a_crse_problem_domain,
int a_ref_ratio,
int a_interp_radius,
bool a_pwconst_interp_only
)
{
ProblemDomain crseProbDomain(a_crse_problem_domain);
define(a_fine_domain, a_coarse_domain, a_num_comps,
crseProbDomain, a_ref_ratio, a_interp_radius,
a_pwconst_interp_only);
}
bool getNearPeriodic(const Box & a_box,
const ProblemDomain& a_pdom,
const int & a_rad)
{
bool nearPeriodic = false;
const Box& domBox = a_pdom.domainBox();
for (int idir = 0; idir < SpaceDim; idir++)
{
if (a_pdom.isPeriodic(idir))
{
if ((Abs(a_box.smallEnd(idir) - domBox.smallEnd(idir)) <= a_rad) ||
(Abs( a_box.bigEnd(idir) - domBox.bigEnd(idir)) <= a_rad))
{
nearPeriodic = true;
break;
}
}
}
return nearPeriodic;
}
void
PiecewiseLinearFillPatch::define(
const DisjointBoxLayout& a_fine_domain,
const DisjointBoxLayout& a_coarse_domain,
int a_num_comps,
const ProblemDomain& a_crse_problem_domain,
int a_ref_ratio,
int a_interp_radius,
bool a_pwconst_interp_only
)
{
CH_TIME("PiecewiseLinearFillPatch::define");
m_ref_ratio = a_ref_ratio;
m_interp_radius = a_interp_radius;
m_crse_problem_domain = a_crse_problem_domain;
bool isSorted = (a_fine_domain.isSorted() && a_coarse_domain.isSorted());
const ProblemDomain fine_problem_domain = refine(m_crse_problem_domain,
m_ref_ratio);
// quick sanity checks
CH_assert (a_fine_domain.checkPeriodic(fine_problem_domain));
if (a_coarse_domain.isClosed())
{
CH_assert (a_coarse_domain.checkPeriodic(a_crse_problem_domain));
//
// create the work array
DisjointBoxLayout coarsened_fine_domain;
coarsen ( coarsened_fine_domain,
a_fine_domain,
m_ref_ratio );
{
CH_TIME("data allocation");
const int coarse_slope_radius =
(m_interp_radius + m_ref_ratio - 1) / m_ref_ratio;
const int coarse_ghost_radius = coarse_slope_radius + s_stencil_radius;
m_coarsenCopier.define(a_coarse_domain,
coarsened_fine_domain,
m_crse_problem_domain,
coarse_ghost_radius * IntVect::Unit);
const IntVect coarse_slope = coarse_slope_radius * IntVect::Unit;
// (wasteful) extra storage here, but who cares? Mmm... well, only waste
// if using piecewise linear.
if (!a_pwconst_interp_only)
{
for (int dir=0; dir<3; dir++)
m_slopes[dir].define(coarsened_fine_domain,
a_num_comps,
coarse_slope);
}
const IntVect coarse_ghost = coarse_ghost_radius * IntVect::Unit;
m_coarsened_fine_data.define(coarsened_fine_domain,
a_num_comps,
coarse_ghost);
// allocate intvectsets
m_fine_interp.define(a_fine_domain);
if (!a_pwconst_interp_only)
{
for (int dir = 0; dir < SpaceDim; ++dir)
{
m_coarse_centered_interp[dir].define(coarsened_fine_domain);
m_coarse_lo_interp[dir].define(coarsened_fine_domain);
m_coarse_hi_interp[dir].define(coarsened_fine_domain);
}
}
}
// Compute intvectsets. We do this mostly in the coarsened domain, with
// only an intersection with the fine domain at the end.
// first, create a box which will determine whether a given box
// adjoins a periodic boundary
Box periodicTestBox(m_crse_problem_domain.domainBox());
if (m_crse_problem_domain.isPeriodic())
{
for (int idir=0; idir<SpaceDim; idir++)
{
if (m_crse_problem_domain.isPeriodic(idir))
periodicTestBox.grow(idir,-1);
}
}
// create regions in which to interpolate, then intersect with borders
// to form regions for centered, one-sided low, and one-sided high
// differences, per coordinate direction.
{
CH_TIME("stencil definition");
DataIterator dit = coarsened_fine_domain.dataIterator();
for (dit.begin(); dit.ok(); ++dit)
{
const Box& fine_box = a_fine_domain[dit()];
Box coarsened_fine_box = m_crse_problem_domain
& coarsen(grow(fine_box, m_interp_radius),m_ref_ratio);
IntVectSet coarsened_fine_interp(coarsened_fine_box);
const Box& ghostBox = coarsened_fine_box;
bool nearPeriodic = getNearPeriodic(fine_box, fine_problem_domain,
m_interp_radius);
// Iterate over boxes in coarsened fine domain, and subtract off
// from the set of coarse cells from which the fine ghost cells
// will be interpolated.
LayoutIterator other_lit = coarsened_fine_domain.layoutIterator();
for (other_lit.begin(); other_lit.ok(); ++other_lit)
{
const Box& other_coarsened_box
= coarsened_fine_domain.get(other_lit());
const Box& testBox = other_coarsened_box;
if (!nearPeriodic && isSorted && (testBox.bigEnd(0) < ghostBox.smallEnd(0)))
{
// can skip rest cuz we haven't gotten
// to something interesting
continue;
}
if (!nearPeriodic && isSorted && (testBox.smallEnd(0) > ghostBox.bigEnd(0)))
{
//can break out of loop, since we know that
// the smallEnd of all the remaining boxes
// are lexigraphically beyond this ghosted
//box.
break;
}
coarsened_fine_interp -= other_coarsened_box;
// also need to remove periodic images from list of cells
// to be filled, since they will be filled through exchange
// as well
if (m_crse_problem_domain.isPeriodic()
&& !periodicTestBox.contains(other_coarsened_box)
&& !periodicTestBox.contains(coarsened_fine_box))
{
ShiftIterator shiftIt = m_crse_problem_domain.shiftIterator();
IntVect shiftMult(m_crse_problem_domain.domainBox().size());
Box shiftedBox(other_coarsened_box);
for (shiftIt.begin(); shiftIt.ok(); ++shiftIt)
{
IntVect shiftVect = shiftMult*shiftIt();
shiftedBox.shift(shiftVect);
coarsened_fine_interp -= shiftedBox;
shiftedBox.shift(-shiftVect);
}
}
}
// Now that we have the coarsened cells required for interpolation,
// construct IntvectSets specifying the one-sided and centered
// stencil locations.
if (!a_pwconst_interp_only)
{
for (int dir = 0; dir < SpaceDim; ++dir)
{
IntVectSet& coarse_centered_interp
= m_coarse_centered_interp[dir][dit()];
coarse_centered_interp = coarsened_fine_interp;
IntVectSet& coarse_lo_interp = m_coarse_lo_interp[dir][dit()];
coarse_lo_interp = coarse_centered_interp;
coarse_lo_interp.shift(BASISV(dir));
IntVectSet& coarse_hi_interp = m_coarse_hi_interp[dir][dit()];
coarse_hi_interp = coarse_centered_interp;
coarse_hi_interp.shift(-BASISV(dir));
// We iterate over the coarse grids and subtract them off of the
// one-sided stencils.
LayoutIterator coarse_lit = a_coarse_domain.layoutIterator();
for (coarse_lit.begin();coarse_lit.ok();++coarse_lit)
{
Box bx = a_coarse_domain.get(coarse_lit());
coarse_lo_interp -= bx;
coarse_hi_interp -= bx;
// once again, need to do periodic images, too
if (m_crse_problem_domain.isPeriodic()
&& !periodicTestBox.contains(bx)
&& !periodicTestBox.contains(coarsened_fine_box))
{
ShiftIterator shiftIt = m_crse_problem_domain.shiftIterator();
IntVect shiftMult(m_crse_problem_domain.domainBox().size());
Box shiftedBox(bx);
for (shiftIt.begin(); shiftIt.ok(); ++shiftIt)
{
IntVect shiftVect = shiftMult*shiftIt();
shiftedBox.shift(shiftVect);
coarse_lo_interp -= shiftedBox;
coarse_hi_interp -= shiftedBox;
shiftedBox.shift(-shiftVect);
}
}
}
coarse_lo_interp.shift(-BASISV(dir));
coarse_hi_interp.shift(BASISV(dir));
coarse_centered_interp -= coarse_lo_interp;
coarse_centered_interp -= coarse_hi_interp;
}
}
// Finally, we construct the fine cells that are going to be
// interpolated by intersecting them with the refined version of the
// coarse IntVectSet.
IntVectSet& fine_interp = m_fine_interp[dit()];
fine_interp = refine(coarsened_fine_interp,m_ref_ratio);
fine_interp &= fine_problem_domain & grow(fine_box, m_interp_radius);
}
}
m_is_defined = true;
} // end if coarser level is well-defined
}
bool
PiecewiseLinearFillPatch::isDefined() const
{
return ( m_is_defined );
}
// fill the interpolation region of the fine level ghost cells
void
PiecewiseLinearFillPatch::fillInterp(
LevelData<FArrayBox>& a_fine_data,
const LevelData<FArrayBox>& a_old_coarse_data,
const LevelData<FArrayBox>& a_new_coarse_data,
Real a_time_interp_coef,
int a_src_comp,
int a_dest_comp,
int a_num_comp
)
{
CH_TIME("PiecewiseLinearFillPatch::fillInterp");
// sanity checks
CH_assert (m_is_defined);
CH_assert(m_slopes[0].isDefined()); // otherwise defined with
// a_pwconst_interp_only = true and we
// shouldn't be here
CH_assert (a_time_interp_coef >= 0.);
CH_assert (a_time_interp_coef <= 1.);
const DisjointBoxLayout oldCrseGrids = a_old_coarse_data.getBoxes();
const DisjointBoxLayout newCrseGrids = a_new_coarse_data.getBoxes();
const DisjointBoxLayout fineGrids = a_fine_data.getBoxes();
CH_assert (oldCrseGrids.checkPeriodic(m_crse_problem_domain));
CH_assert (newCrseGrids.checkPeriodic(m_crse_problem_domain));
CH_assert (fineGrids.checkPeriodic(refine(m_crse_problem_domain,
m_ref_ratio)));
//
// time interpolation of coarse level data, to coarsened fine level work array
timeInterp(a_old_coarse_data,
a_new_coarse_data,
a_time_interp_coef,
a_src_comp,
a_dest_comp,
a_num_comp);
//
// piecewise contant interpolation, from coarsened fine level work
// array, to fine level
fillConstantInterp(a_fine_data,
a_src_comp,
a_dest_comp,
a_num_comp);
//
// increment fine level data with per-direction linear terms
computeSlopes(a_src_comp,
a_num_comp);
incrementLinearInterp(a_fine_data,
a_src_comp,
a_dest_comp,
a_num_comp);
}
// fill the interpolation region of the fine level ghost cells using only
// piecewise constant interpolation in space
void
PiecewiseLinearFillPatch::fillInterpPWConstSpace(
LevelData<FArrayBox>& a_fine_data,
const LevelData<FArrayBox>& a_coarse_data,
int a_src_comp,
int a_dest_comp,
int a_num_comp
)
{
// sanity checks
CH_assert (m_is_defined);
const DisjointBoxLayout crseGrids = a_coarse_data.getBoxes();
const DisjointBoxLayout fineGrids = a_fine_data.getBoxes();
CH_assert (crseGrids.checkPeriodic(m_crse_problem_domain));
CH_assert (fineGrids.checkPeriodic(refine(m_crse_problem_domain,
m_ref_ratio)));
// Just need to copy the coarse data before calling internal piecewise
// constant interpolator
Interval src_interval (a_src_comp, a_src_comp + a_num_comp - 1);
Interval dest_interval(a_dest_comp, a_dest_comp + a_num_comp - 1);
a_coarse_data.copyTo(src_interval,
m_coarsened_fine_data,
dest_interval,
m_coarsenCopier);
fillConstantInterp(a_fine_data,
a_src_comp,
a_dest_comp,
a_num_comp);
}
//
// time interpolation of coarse level data, to coarsened fine level work array
void
PiecewiseLinearFillPatch::timeInterp(
const LevelData<FArrayBox>& a_old_coarse_data,
const LevelData<FArrayBox>& a_new_coarse_data,
Real a_time_interp_coef,
int a_src_comp,
int a_dest_comp,
int a_num_comp
)
{
CH_TIME("PiecewiseLinearFillPatch::timeInterp");
Interval src_interval (a_src_comp, a_src_comp + a_num_comp - 1);
Interval dest_interval(a_dest_comp, a_dest_comp + a_num_comp - 1);
if ( (a_old_coarse_data.boxLayout().size() == 0) &&
(a_new_coarse_data.boxLayout().size() == 0) )
{
MayDay::Error ( "PiecewiseLinearFillPatch::fillInterp: no old coarse data and no new coarse data" );
}
else if ( (a_time_interp_coef == 1.) ||
(a_old_coarse_data.boxLayout().size() == 0) )
{
// old coarse data is absent, or fine time level is the new coarse time level
a_new_coarse_data.copyTo( src_interval,
m_coarsened_fine_data,
dest_interval,
m_coarsenCopier
);
}
else if ( (a_time_interp_coef == 0.) ||
(a_new_coarse_data.boxLayout().size() == 0) )
{
// new coarse data is absent, or fine time level is the old coarse time level
a_old_coarse_data.copyTo( src_interval,
m_coarsened_fine_data,
dest_interval,
m_coarsenCopier
);
}
else
{
// linearly interpolate between old and new time levels
a_new_coarse_data.copyTo( src_interval,
m_coarsened_fine_data,
dest_interval,
m_coarsenCopier
);
const DisjointBoxLayout&
coarsened_fine_layout = m_coarsened_fine_data.disjointBoxLayout();
LevelData<FArrayBox>
tmp_coarsened_fine_data(coarsened_fine_layout,
m_coarsened_fine_data.nComp(),
m_coarsened_fine_data.ghostVect());
a_old_coarse_data.copyTo( src_interval,
tmp_coarsened_fine_data,
dest_interval,
m_coarsenCopier
);
DataIterator dit = coarsened_fine_layout.dataIterator();
for (dit.begin(); dit.ok(); ++dit)
{
FArrayBox& coarsened_fine_fab = m_coarsened_fine_data[dit()];
FArrayBox& tmp_coarsened_fine_fab = tmp_coarsened_fine_data[dit()];
coarsened_fine_fab.mult(a_time_interp_coef,a_src_comp,a_num_comp);
tmp_coarsened_fine_fab.mult(1.0 - a_time_interp_coef,a_src_comp,a_num_comp);
coarsened_fine_fab.plus(tmp_coarsened_fine_fab,a_src_comp,a_dest_comp,a_num_comp);
}
}
}
// fill the fine interpolation region piecewise-constantly
void
PiecewiseLinearFillPatch::fillConstantInterp(
LevelData<FArrayBox>& a_fine_data,
int a_src_comp,
int a_dest_comp,
int a_num_comp
)
const
{
CH_TIME("PiecewiseLinearFillPatch::fillConstantInterp");
DataIterator dit = a_fine_data.boxLayout().dataIterator();
for (dit.begin(); dit.ok(); ++dit)
{
FArrayBox& fine_fab = a_fine_data[dit()];
const FArrayBox& coarse_fab = m_coarsened_fine_data[dit()];
const IntVectSet& local_fine_interp = m_fine_interp[dit()];
IVSIterator ivsit(local_fine_interp);
for (ivsit.begin(); ivsit.ok(); ++ivsit)
{
const IntVect& fine_iv = ivsit();
IntVect coarse_iv = coarsen(fine_iv, m_ref_ratio);
int coarse_comp = a_src_comp;
int fine_comp = a_dest_comp;
for (; coarse_comp < a_src_comp + a_num_comp; ++fine_comp, ++coarse_comp)
fine_fab(fine_iv, fine_comp) = coarse_fab(coarse_iv, coarse_comp);
}
}
}
// compute slopes at the coarse interpolation sites in the specified direction
void
PiecewiseLinearFillPatch::computeSlopes(int a_src_comp,
int a_num_comp)
{
CH_TIME("PiecewiseLinearFillPatch::computeSlopes");
DataIterator dit = m_coarsened_fine_data.boxLayout().dataIterator();
for (int dir=0; dir<SpaceDim; dir++)
{
for (dit.begin(); dit.ok(); ++dit)
{
FArrayBox& slope_fab = m_slopes[dir][dit()];
const FArrayBox& dataFab = m_coarsened_fine_data[dit()];
const IntVectSet& local_centered_interp = m_coarse_centered_interp[dir][dit()];
const IntVectSet& local_lo_interp = m_coarse_lo_interp[dir][dit()];
const IntVectSet& local_hi_interp = m_coarse_hi_interp[dir][dit()];
computeSimpleSlopesFab(slope_fab,
a_src_comp,
a_num_comp,
dir,
dataFab,
local_centered_interp,
local_lo_interp,
local_hi_interp);
}
}
for (dit.begin(); dit.ok(); ++dit)
{
const Box& slopeBox = m_slopes[0][dit()].box();
const FArrayBox& dataFab = m_coarsened_fine_data[dit()];
computeMultiDimSlopes(m_slopes[0][dit()],
m_slopes[1][dit()] ,
m_slopes[2][dit()],
dataFab,
a_src_comp,
a_num_comp,
slopeBox);
}
}
void PiecewiseLinearFillPatch::computeSimpleSlopesFab(FArrayBox & a_slopeFab,
const int & a_src_comp,
const int & a_num_comp,
const int & a_dir,
const FArrayBox & a_dataFab,
const IntVectSet& a_local_centered_interp,
const IntVectSet& a_local_lo_interp,
const IntVectSet& a_local_hi_interp)
{
CH_TIME("PiecewiseLinearFillPatch::computeSimpleSlopes");
// van leer limited central difference
IVSIterator centered_ivsit(a_local_centered_interp);
for (centered_ivsit.begin(); centered_ivsit.ok(); ++centered_ivsit)
{
const IntVect& iv = centered_ivsit();
const IntVect ivlo = iv - BASISV(a_dir);
const IntVect ivhi = iv + BASISV(a_dir);
for (int comp = a_src_comp; comp < a_src_comp + a_num_comp; ++comp)
{
Real dcenter = 0.5 * (a_dataFab(ivhi,comp) - a_dataFab(ivlo,comp));
a_slopeFab(iv,comp) = dcenter;
}
}
// one-sided difference (low)
IVSIterator lo_ivsit(a_local_lo_interp);
for (lo_ivsit.begin(); lo_ivsit.ok(); ++lo_ivsit)
{
const IntVect& iv = lo_ivsit();
const IntVect ivlo = iv - BASISV(a_dir);
for (int comp = a_src_comp; comp < a_src_comp + a_num_comp; ++comp)
{
Real dlo = a_dataFab(iv,comp) - a_dataFab(ivlo,comp);
a_slopeFab(iv,comp) = dlo;
}
}
// one-sided difference (high)
IVSIterator hi_ivsit(a_local_hi_interp);
for (hi_ivsit.begin(); hi_ivsit.ok(); ++hi_ivsit)
{
const IntVect& iv = hi_ivsit();
const IntVect ivhi = iv + BASISV(a_dir);
for (int comp = a_src_comp; comp < a_src_comp + a_num_comp; ++comp)
{
Real dhi = a_dataFab(ivhi,comp) - a_dataFab(iv,comp);
a_slopeFab(iv,comp) = dhi;
}
}
}
void PiecewiseLinearFillPatch::computeMultiDimSlopes(FArrayBox & a_slopes0,
FArrayBox & a_slopes1,
FArrayBox & a_slopes2,
const FArrayBox& a_dataFab,
const int & a_src_comp,
const int & a_num_comp,
const Box & a_slopeBox)
{
// this is the same stuff that is in FineInterp.cpp
Box b_mod(a_slopeBox);
b_mod.grow(1);
b_mod = m_crse_problem_domain & b_mod;
b_mod.grow(-1);
// create a box big enough to remove periodic BCs from domain
Box domBox = grow(a_slopeBox,2);
domBox = m_crse_problem_domain & domBox;
// to do limits, we need to have a box which includes
// the neighbors of a given point (to check for the
// local maximum...
Box neighborBox(-1*IntVect::Unit,
IntVect::Unit);
FORT_INTERPLIMIT( CHF_FRA(a_slopes0),
CHF_FRA(a_slopes1),
CHF_FRA(a_slopes2),
CHF_CONST_FRA(a_dataFab),
CHF_BOX(b_mod),
CHF_BOX(neighborBox),
CHF_BOX(domBox));
}
// increment the fine interpolation sites with linear term for the
// specified coordinate direction
void
PiecewiseLinearFillPatch::incrementLinearInterp(
LevelData<FArrayBox>& a_fine_data,
int a_src_comp,
int a_dest_comp,
int a_num_comp
)
const
{
CH_TIME("PiecewiseLinearFillPatch::incrementLinearInterp");
for (int dir=0; dir<SpaceDim; dir++)
{
DataIterator dit = a_fine_data.boxLayout().dataIterator();
for (dit.begin(); dit.ok(); ++dit)
{
const FArrayBox& slope_fab = m_slopes[dir][dit()];
FArrayBox& fine_data_fab = a_fine_data[dit()];
const IntVectSet& fine_interp = m_fine_interp[dit()];
IVSIterator ivsit(fine_interp);
for (ivsit.begin(); ivsit.ok(); ++ivsit)
{
const IntVect& fine_iv = ivsit();
const IntVect coarse_iv = coarsen(fine_iv,m_ref_ratio);
const int offset = fine_iv[dir] - m_ref_ratio * coarse_iv[dir];
Real interp_coef = -.5 + (offset +.5) / m_ref_ratio;
int coarse_comp = a_src_comp;
int fine_comp = a_dest_comp;
for (; coarse_comp < a_src_comp + a_num_comp; ++coarse_comp, ++fine_comp)
{
fine_data_fab(fine_iv,fine_comp)
+= interp_coef * slope_fab(coarse_iv,coarse_comp);
}
}
}
}
}
void
PiecewiseLinearFillPatch::printIntVectSets() const
{
DataIterator lit = m_fine_interp.boxLayout().dataIterator();
for (lit.begin(); lit.ok(); ++lit)
{
pout() << "grid " << lit().intCode() << ": " << endl;
pout() << "fine ivs" << endl;
pout() << m_fine_interp[lit()] << endl;
for (int dir = 0; dir < SpaceDim; ++dir)
{
pout() << "coarse centered ivs [" << dir << "]: " << endl;
pout() << m_coarse_centered_interp[dir][lit()] << endl;
pout() << "coarse lo ivs [" << dir << "]: " << endl;
pout() << m_coarse_lo_interp[dir][lit()] << endl;
pout() << "coarse hi ivs [" << dir << "]: " << endl;
pout() << m_coarse_hi_interp[dir][lit()] << endl;
}
}
}
#include "NamespaceFooter.H"
|
; A020801: Decimal expansion of 1/sqrt(44).
; Submitted by Jamie Morken(s4)
; 1,5,0,7,5,5,6,7,2,2,8,8,8,8,1,8,1,1,3,2,3,4,0,6,0,3,3,4,8,5,0,3,1,2,1,2,9,0,5,7,7,6,7,5,2,0,7,2,2,4,3,3,4,5,3,2,0,8,4,9,1,8,8,4,5,9,8,4,0,2,1,1,0,2,7,6,8,3,8,1,1,2,1,4,0,3,8,3,3,6,3,2,4,0,1,3,2,1,1,4
mov $1,1
mov $2,1
mov $3,$0
add $3,8
mov $4,$0
add $0,5
add $4,3
mul $4,2
mov $7,10
pow $7,$4
mov $9,10
lpb $3
mov $4,$2
pow $4,2
mul $4,44
mov $5,$1
pow $5,2
add $4,$5
mov $6,$1
mov $1,$4
mul $6,$2
mul $6,2
mov $2,$6
mov $8,$4
div $8,$7
max $8,2
div $1,$8
div $2,$8
sub $3,2
lpe
mov $3,$9
pow $3,$0
div $2,$3
mov $0,$2
mod $0,10
|
; **********************************************************************
; memviewer View memory dump
; **********************************************************************
; langDump Shows "program" structure
.langDump
{
JSR langStart ; Point to the program start
JSR memViewer
LDA #0
STA tempAddr
.l1
JSR outputReset
LDA curLine+1
JSR outputAppendHexChar
LDA curLine
JSR outputAppendHexChar
LDA #32
JSR outputAppend
LDY #1
LDA (curLine),Y
JSR outputAppendHexChar
DEY
LDA (curLine),Y
JSR outputAppendHexChar
LDA #32
JSR outputAppend
INY
INY
LDA (curLine),Y
JSR outputAppendHexChar
LDA #32
JSR outputAppend
JSR langGetToken
JSR outputAppendHexChar
JSR outputTerminate
JSR writeOutputBuffer
JSR osnewl
JSR langNextLine
BEQ end
DEC tempAddr
BNE l1
.end
RTS
}
; memViewer Shows first &A0 bytes of dataBase for debugging
.memViewer
{
LDA #31 ; Move cursor to line 1 on screen
JSR oswrch
LDA #0
JSR oswrch
LDA #1
JSR oswrch
LDA curLine
STA tempAddr
LDA curLine+1
STA tempAddr+1
LDA #20 ; no of lines to write
STA tempChar
.l1
JSR outputReset
LDA tempAddr+1
JSR outputAppendHexChar
LDA tempAddr
JSR outputAppendHexChar
LDY #0
LDX #8
.l2
TYA
PHA
LDA #32
JSR outputAppend
PLA
TAY
LDA (tempAddr),Y
JSR outputAppendHexChar
INY
DEX
BNE l2
LDA #32
JSR outputAppend
LDY #0
LDX #8
.l3
LDA (tempAddr),Y
CMP #32
BMI l4
CMP #127
BMI l5
.l4
LDA #'.'
.l5
STA tempA
TYA
PHA
LDA tempA
JSR outputAppend
PLA
TAY
INY
DEX
BNE l3
JSR outputTerminate
JSR writeOutputBuffer
JSR osnewl
CLC
LDA tempAddr
ADC #8
STA tempAddr
LDA tempAddr+1
ADC #0
STA tempAddr+1
DEC tempChar
BNE l1
RTS
}
|
; A117794: Hexagonal numbers divisible by 6.
; 0,6,66,120,276,378,630,780,1128,1326,1770,2016,2556,2850,3486,3828,4560,4950,5778,6216,7140,7626,8646,9180,10296,10878,12090,12720,14028,14706,16110,16836,18336,19110,20706,21528,23220,24090,25878,26796,28680,29646,31626,32640,34716,35778,37950,39060,41328,42486,44850,46056,48516,49770,52326,53628,56280,57630,60378,61776,64620,66066,69006,70500,73536,75078,78210,79800,83028,84666,87990,89676,93096,94830,98346,100128,103740,105570,109278,111156,114960,116886,120786,122760,126756,128778,132870
mul $0,3
div $0,2
mul $0,4
bin $0,2
|
; A166147: a(n) = 4n^2 + 4n - 7.
; 1,17,41,73,113,161,217,281,353,433,521,617,721,833,953,1081,1217,1361,1513,1673,1841,2017,2201,2393,2593,2801,3017,3241,3473,3713,3961,4217,4481,4753,5033,5321,5617,5921,6233,6553,6881,7217,7561,7913,8273,8641,9017,9401,9793,10193,10601,11017,11441,11873,12313,12761,13217,13681,14153,14633,15121,15617,16121,16633,17153,17681,18217,18761,19313,19873,20441,21017,21601,22193,22793,23401,24017,24641,25273,25913,26561,27217,27881,28553,29233,29921,30617,31321,32033,32753,33481,34217,34961,35713,36473,37241,38017,38801,39593,40393
mov $1,2
mul $1,$0
add $1,3
pow $1,2
sub $1,8
mov $0,$1
|
; "Springs are going to the party"
; - 256 bytes intro by Frog for CC'2017
;
; http://frog.enlight.ru
; frog@enlight.ru
;
include "vectrex.i"
frames_c equ $C880
base_x equ $C882
springs equ $C890 ; index in sine table for each spring
sine equ $fc6d ; sine table from BIOS (access via reg y)
;***************************************************************************
org 0
db "g GCE 1982", $80 ; 'g' is copyright sign
dw $f600 ; music from the rom ($F600 - no music)
db $FC, $30, 33, -$46 ; height, width, rel y, rel x
title: db "SPRINGS - 256 BYTES", $80 ; app title, ending with $80
db 0 ; end of header
jsr $f92e
; copy initial springs positions to RAM
ldu #springstmp
ldx #springs
lda #(3*3)
jsr Move_Mem_a ; A - byte count, U - source, X - destination
clr frames_c
; inc Vec_Music_Flag
loop:
jsr DP_to_C8
ldu #$fe38
jsr Init_Music_chk ; Initialize the music
jsr Wait_Recal ; recalibrate CRT, reset beam to 0,0. D, X - trashed
jsr Do_Sound
tst Vec_Music_Flag ; Loop if music is still playing
bne stillplaying
inc Vec_Music_Flag ; restart music
; ldu #$fe38
; jsr Init_Music_chk ; Initialize the music
stillplaying:
; jsr DP_to_D0 ; wtf? I need this bytes!
; intro title
ldu #title
ldd #(-127*256+(-54)) ; Y,X
jsr Print_Str_d
; draw floor
lda #$ff ; scale (max possible)
sta <VIA_t1_cnt_lo
ldd #(-60*256+(-54)) ; Y,X
jsr Moveto_d
ldd #(0*256+(127)) ; Y,X
jsr Draw_Line_d
clr base_x
ldu #0 ; curves counter
ldx #springs ; reset after each series of curves
; jsr Intensity_5F
nextcurve:
; start drawing curve
jsr Reset0Ref ; recalibrate crt (x,y = 0)
lda #$CE ; /Blank low, /ZERO high
sta <VIA_cntl ; enable beam, disable zeroing
; calculate Y position and height for curve
ldb ,x ; load pos in sine for cur cuve froom springs to y
cmpb #32 ; check if end of sine. was:15
bne skipreset
clrb
skipreset:
; move only each nth frame
lda frames_c
bita #$03
bne skipinc
incb ; next sine point
skipinc:
stb ,x+
; b - index in sine
clra
addd #sine ; index to addr
; b - offset in sine
tfr d,y
lda ,y
lsra
lsra
pshs a
suba #60 ; ground level
ldb frames_c
addb base_x
jsr Moveto_d ; A = y coord, B = x coord (D trashed)
; Draw_Curve begin
; params: y - coeff. to make curves look different
ldd #$1881
stb <VIA_port_b ; disable MUX, disable ~RAMP
sta <VIA_aux_cntl ; AUX: shift mode 4. PB7 not timer controlled. PB7 is ~RAMP
puls a
lsra
sta <VIA_port_a ; end Y to DAC (kinda "scale")
decb ; b now $80
stb <VIA_port_b ; enable MUX
clrb ; X start = 0
inc <VIA_port_b ; MUX off, only X on DAC now
stb <VIA_port_a ; X to DAC
incb
stb <VIA_port_b ; MUX disable, ~RAMP enable. Start integration
ldb #$ff
stb <VIA_shift_reg ; pattern
; draw spring
ldd #$300e ; a = spring width ($80 = -127...+127), b = $0f (number of turns)
lda ,u ; to make springs different
nextturn:
sta <VIA_port_a ; put X to DAC
eora #1 ; 127 -> -127
nega
; delay to make springs more wide
ldy #4
delaywidth: leay -1,y
bne delaywidth
decb ; next turn
bne nextturn
; restore hardware after drawing curve
ldd #$9881 ; b - 81, a - 98
; ldb #$81 ; ramp off, MUX off
stb <VIA_port_b
; lda #$98
sta <VIA_aux_cntl ; restore usual AUX setting (enable PB7 timer, SHIFT mode 4)
; ldb #30 ; end dot brightness (20-30 is ok for release)
lsrb ; 81 => 40 (saved 1 byte :)
repeat_dot: decb
bne repeat_dot
clr <VIA_shift_reg ; Blank beam in VIA shift register
lda base_x
adda #80 ; x gap between curves
sta base_x
cmpx #springs+3 ; check if all curves processed
bne skip
ldx #springs
skip:
leau 1,u
cmpu #3 ; number of curves
bne nextcurve
dec frames_c
jmp loop
; (moved to springs, access via reg x)
; current index in sine table for each curve
springstmp:
db 15, 20, 25 ; yes, it could be heavely optimized - 3 items don't require tables, memcpy etc..
|
// Catch2
#include "../submodules/Catch2/single_include/catch2/catch.hpp"
// Project headers
#include "../src/TimestampPattern.hpp"
using std::string;
TEST_CASE("Test known timestamp patterns", "[KnownTimestampPatterns]") {
TimestampPattern::init();
string line;
const TimestampPattern* pattern;
epochtime_t timestamp;
size_t timestamp_begin_pos;
size_t timestamp_end_pos;
string content;
line = "2015-02-01T01:02:03.004 content after";
pattern = TimestampPattern::search_known_ts_patterns(line, timestamp, timestamp_begin_pos, timestamp_end_pos);
REQUIRE(nullptr != pattern);
REQUIRE(pattern->get_num_spaces_before_ts() == 0);
REQUIRE(pattern->get_format() == "%Y-%m-%dT%H:%M:%S.%3");
REQUIRE(1422752523004 == timestamp);
REQUIRE(0 == timestamp_begin_pos);
REQUIRE(23 == timestamp_end_pos);
content.assign(line, 0, timestamp_begin_pos);
content.append(line, timestamp_end_pos, timestamp_end_pos - timestamp_begin_pos);
pattern->insert_formatted_timestamp(timestamp, content);
REQUIRE(line == content);
line = "2015-02-01T01:02:03,004 content after";
pattern = TimestampPattern::search_known_ts_patterns(line, timestamp, timestamp_begin_pos, timestamp_end_pos);
REQUIRE(nullptr != pattern);
REQUIRE(pattern->get_num_spaces_before_ts() == 0);
REQUIRE(pattern->get_format() == "%Y-%m-%dT%H:%M:%S,%3");
REQUIRE(1422752523004 == timestamp);
REQUIRE(0 == timestamp_begin_pos);
REQUIRE(23 == timestamp_end_pos);
content.assign(line, 0, timestamp_begin_pos);
content.append(line, timestamp_end_pos, timestamp_end_pos - timestamp_begin_pos);
pattern->insert_formatted_timestamp(timestamp, content);
REQUIRE(line == content);
line = "[2015-02-01T01:02:03 content after";
pattern = TimestampPattern::search_known_ts_patterns(line, timestamp, timestamp_begin_pos, timestamp_end_pos);
REQUIRE(nullptr != pattern);
REQUIRE(pattern->get_num_spaces_before_ts() == 0);
REQUIRE(pattern->get_format() == "[%Y-%m-%dT%H:%M:%S");
REQUIRE(1422752523000 == timestamp);
REQUIRE(0 == timestamp_begin_pos);
REQUIRE(20 == timestamp_end_pos);
content.assign(line, 0, timestamp_begin_pos);
content.append(line, timestamp_end_pos, timestamp_end_pos - timestamp_begin_pos);
pattern->insert_formatted_timestamp(timestamp, content);
REQUIRE(line == content);
line = "[20150201-01:02:03] content after";
pattern = TimestampPattern::search_known_ts_patterns(line, timestamp, timestamp_begin_pos, timestamp_end_pos);
REQUIRE(nullptr != pattern);
REQUIRE(pattern->get_num_spaces_before_ts() == 0);
REQUIRE(pattern->get_format() == "[%Y%m%d-%H:%M:%S]");
REQUIRE(1422752523000 == timestamp);
REQUIRE(0 == timestamp_begin_pos);
REQUIRE(19 == timestamp_end_pos);
content.assign(line, 0, timestamp_begin_pos);
content.append(line, timestamp_end_pos, timestamp_end_pos - timestamp_begin_pos);
pattern->insert_formatted_timestamp(timestamp, content);
REQUIRE(line == content);
line = "2015-02-01 01:02:03,004 content after";
pattern = TimestampPattern::search_known_ts_patterns(line, timestamp, timestamp_begin_pos, timestamp_end_pos);
REQUIRE(nullptr != pattern);
REQUIRE(pattern->get_num_spaces_before_ts() == 0);
REQUIRE(pattern->get_format() == "%Y-%m-%d %H:%M:%S,%3");
REQUIRE(1422752523004 == timestamp);
REQUIRE(0 == timestamp_begin_pos);
REQUIRE(23 == timestamp_end_pos);
content.assign(line, 0, timestamp_begin_pos);
content.append(line, timestamp_end_pos, timestamp_end_pos - timestamp_begin_pos);
pattern->insert_formatted_timestamp(timestamp, content);
REQUIRE(line == content);
line = "2015-02-01 01:02:03.004 content after";
pattern = TimestampPattern::search_known_ts_patterns(line, timestamp, timestamp_begin_pos, timestamp_end_pos);
REQUIRE(nullptr != pattern);
REQUIRE(pattern->get_num_spaces_before_ts() == 0);
REQUIRE(pattern->get_format() == "%Y-%m-%d %H:%M:%S.%3");
REQUIRE(1422752523004 == timestamp);
REQUIRE(0 == timestamp_begin_pos);
REQUIRE(23 == timestamp_end_pos);
content.assign(line, 0, timestamp_begin_pos);
content.append(line, timestamp_end_pos, timestamp_end_pos - timestamp_begin_pos);
pattern->insert_formatted_timestamp(timestamp, content);
REQUIRE(line == content);
line = "[2015-02-01 01:02:03,004] content after";
pattern = TimestampPattern::search_known_ts_patterns(line, timestamp, timestamp_begin_pos, timestamp_end_pos);
REQUIRE(nullptr != pattern);
REQUIRE(pattern->get_num_spaces_before_ts() == 0);
REQUIRE(pattern->get_format() == "[%Y-%m-%d %H:%M:%S,%3]");
REQUIRE(1422752523004 == timestamp);
REQUIRE(0 == timestamp_begin_pos);
REQUIRE(25 == timestamp_end_pos);
content.assign(line, 0, timestamp_begin_pos);
content.append(line, timestamp_end_pos, timestamp_end_pos - timestamp_begin_pos);
pattern->insert_formatted_timestamp(timestamp, content);
REQUIRE(line == content);
line = "2015-02-01 01:02:03 content after";
pattern = TimestampPattern::search_known_ts_patterns(line, timestamp, timestamp_begin_pos, timestamp_end_pos);
REQUIRE(nullptr != pattern);
REQUIRE(pattern->get_num_spaces_before_ts() == 0);
REQUIRE(pattern->get_format() == "%Y-%m-%d %H:%M:%S");
REQUIRE(1422752523000 == timestamp);
REQUIRE(0 == timestamp_begin_pos);
REQUIRE(19 == timestamp_end_pos);
content.assign(line, 0, timestamp_begin_pos);
content.append(line, timestamp_end_pos, timestamp_end_pos - timestamp_begin_pos);
pattern->insert_formatted_timestamp(timestamp, content);
REQUIRE(line == content);
line = "2015/02/01 01:02:03 content after";
pattern = TimestampPattern::search_known_ts_patterns(line, timestamp, timestamp_begin_pos, timestamp_end_pos);
REQUIRE(nullptr != pattern);
REQUIRE(pattern->get_num_spaces_before_ts() == 0);
REQUIRE(pattern->get_format() == "%Y/%m/%d %H:%M:%S");
REQUIRE(1422752523000 == timestamp);
REQUIRE(0 == timestamp_begin_pos);
REQUIRE(19 == timestamp_end_pos);
content.assign(line, 0, timestamp_begin_pos);
content.append(line, timestamp_end_pos, timestamp_end_pos - timestamp_begin_pos);
pattern->insert_formatted_timestamp(timestamp, content);
REQUIRE(line == content);
line = "15/02/01 01:02:03 content after";
pattern = TimestampPattern::search_known_ts_patterns(line, timestamp, timestamp_begin_pos, timestamp_end_pos);
REQUIRE(nullptr != pattern);
REQUIRE(pattern->get_num_spaces_before_ts() == 0);
REQUIRE(pattern->get_format() == "%y/%m/%d %H:%M:%S");
REQUIRE(1422752523000 == timestamp);
REQUIRE(0 == timestamp_begin_pos);
REQUIRE(17 == timestamp_end_pos);
content.assign(line, 0, timestamp_begin_pos);
content.append(line, timestamp_end_pos, timestamp_end_pos - timestamp_begin_pos);
pattern->insert_formatted_timestamp(timestamp, content);
REQUIRE(line == content);
line = "150201 1:02:03 content after";
pattern = TimestampPattern::search_known_ts_patterns(line, timestamp, timestamp_begin_pos, timestamp_end_pos);
REQUIRE(nullptr != pattern);
REQUIRE(pattern->get_num_spaces_before_ts() == 0);
REQUIRE(pattern->get_format() == "%y%m%d %k:%M:%S");
REQUIRE(1422752523000 == timestamp);
REQUIRE(0 == timestamp_begin_pos);
REQUIRE(15 == timestamp_end_pos);
content.assign(line, 0, timestamp_begin_pos);
content.append(line, timestamp_end_pos, timestamp_end_pos - timestamp_begin_pos);
pattern->insert_formatted_timestamp(timestamp, content);
REQUIRE(line == content);
line = "01 Feb 2015 01:02:03,004 content after";
pattern = TimestampPattern::search_known_ts_patterns(line, timestamp, timestamp_begin_pos, timestamp_end_pos);
REQUIRE(nullptr != pattern);
REQUIRE(pattern->get_num_spaces_before_ts() == 0);
REQUIRE(pattern->get_format() == "%d %b %Y %H:%M:%S,%3");
REQUIRE(1422752523004 == timestamp);
REQUIRE(0 == timestamp_begin_pos);
REQUIRE(24 == timestamp_end_pos);
content.assign(line, 0, timestamp_begin_pos);
content.append(line, timestamp_end_pos, timestamp_end_pos - timestamp_begin_pos);
pattern->insert_formatted_timestamp(timestamp, content);
REQUIRE(line == content);
line = "Feb 01, 2015 1:02:03 AM content after";
pattern = TimestampPattern::search_known_ts_patterns(line, timestamp, timestamp_begin_pos, timestamp_end_pos);
REQUIRE(nullptr != pattern);
REQUIRE(pattern->get_num_spaces_before_ts() == 0);
REQUIRE(pattern->get_format() == "%b %d, %Y %l:%M:%S %p");
REQUIRE(1422752523000 == timestamp);
REQUIRE(0 == timestamp_begin_pos);
REQUIRE(24 == timestamp_end_pos);
content.assign(line, 0, timestamp_begin_pos);
content.append(line, timestamp_end_pos, timestamp_end_pos - timestamp_begin_pos);
pattern->insert_formatted_timestamp(timestamp, content);
REQUIRE(line == content);
line = "February 01, 2015 01:02 content after";
pattern = TimestampPattern::search_known_ts_patterns(line, timestamp, timestamp_begin_pos, timestamp_end_pos);
REQUIRE(nullptr != pattern);
REQUIRE(pattern->get_num_spaces_before_ts() == 0);
REQUIRE(pattern->get_format() == "%B %d, %Y %H:%M");
REQUIRE(1422752520000 == timestamp);
REQUIRE(0 == timestamp_begin_pos);
REQUIRE(23 == timestamp_end_pos);
content.assign(line, 0, timestamp_begin_pos);
content.append(line, timestamp_end_pos, timestamp_end_pos - timestamp_begin_pos);
pattern->insert_formatted_timestamp(timestamp, content);
REQUIRE(line == content);
line = "E [01/Feb/2015:01:02:03 content after";
pattern = TimestampPattern::search_known_ts_patterns(line, timestamp, timestamp_begin_pos, timestamp_end_pos);
REQUIRE(nullptr != pattern);
REQUIRE(pattern->get_num_spaces_before_ts() == 1);
REQUIRE(pattern->get_format() == "[%d/%b/%Y:%H:%M:%S");
REQUIRE(1422752523000 == timestamp);
REQUIRE(2 == timestamp_begin_pos);
REQUIRE(23 == timestamp_end_pos);
content.assign(line, 0, timestamp_begin_pos);
content.append(line, timestamp_end_pos, timestamp_end_pos - timestamp_begin_pos);
pattern->insert_formatted_timestamp(timestamp, content);
REQUIRE(line == content);
line = "localhost - - [01/Feb/2015:01:02:03 content after";
pattern = TimestampPattern::search_known_ts_patterns(line, timestamp, timestamp_begin_pos, timestamp_end_pos);
REQUIRE(nullptr != pattern);
REQUIRE(pattern->get_num_spaces_before_ts() == 3);
REQUIRE(pattern->get_format() == "[%d/%b/%Y:%H:%M:%S");
REQUIRE(1422752523000 == timestamp);
REQUIRE(14 == timestamp_begin_pos);
REQUIRE(35 == timestamp_end_pos);
content.assign(line, 0, timestamp_begin_pos);
content.append(line, timestamp_end_pos, timestamp_end_pos - timestamp_begin_pos);
pattern->insert_formatted_timestamp(timestamp, content);
REQUIRE(line == content);
line = "INFO [main] 2015-02-01 01:02:03,004 content after";
pattern = TimestampPattern::search_known_ts_patterns(line, timestamp, timestamp_begin_pos, timestamp_end_pos);
REQUIRE(nullptr != pattern);
REQUIRE(pattern->get_num_spaces_before_ts() == 2);
REQUIRE(pattern->get_format() == "%Y-%m-%d %H:%M:%S,%3");
REQUIRE(1422752523004 == timestamp);
REQUIRE(12 == timestamp_begin_pos);
REQUIRE(35 == timestamp_end_pos);
content.assign(line, 0, timestamp_begin_pos);
content.append(line, timestamp_end_pos, timestamp_end_pos - timestamp_begin_pos);
pattern->insert_formatted_timestamp(timestamp, content);
REQUIRE(line == content);
line = "Started POST \"/api/v3/internal/allowed\" for 127.0.0.1 at 2015-02-01 01:02:03 content after";
pattern = TimestampPattern::search_known_ts_patterns(line, timestamp, timestamp_begin_pos, timestamp_end_pos);
REQUIRE(nullptr != pattern);
REQUIRE(pattern->get_num_spaces_before_ts() == 6);
REQUIRE(pattern->get_format() == "%Y-%m-%d %H:%M:%S");
REQUIRE(1422752523000 == timestamp);
REQUIRE(57 == timestamp_begin_pos);
REQUIRE(76 == timestamp_end_pos);
content.assign(line, 0, timestamp_begin_pos);
content.append(line, timestamp_end_pos, timestamp_end_pos - timestamp_begin_pos);
pattern->insert_formatted_timestamp(timestamp, content);
REQUIRE(line == content);
line = "update-alternatives 2015-02-01 01:02:03 content after";
pattern = TimestampPattern::search_known_ts_patterns(line, timestamp, timestamp_begin_pos, timestamp_end_pos);
REQUIRE(nullptr != pattern);
REQUIRE(pattern->get_num_spaces_before_ts() == 1);
REQUIRE(pattern->get_format() == "%Y-%m-%d %H:%M:%S");
REQUIRE(1422752523000 == timestamp);
REQUIRE(20 == timestamp_begin_pos);
REQUIRE(39 == timestamp_end_pos);
content.assign(line, 0, timestamp_begin_pos);
content.append(line, timestamp_end_pos, timestamp_end_pos - timestamp_begin_pos);
pattern->insert_formatted_timestamp(timestamp, content);
REQUIRE(line == content);
line = "ERROR: apport (pid 4557) Sun Feb 1 01:02:03 2015 content after";
pattern = TimestampPattern::search_known_ts_patterns(line, timestamp, timestamp_begin_pos, timestamp_end_pos);
REQUIRE(nullptr != pattern);
REQUIRE(pattern->get_num_spaces_before_ts() == 4);
REQUIRE(pattern->get_format() == "%a %b %e %H:%M:%S %Y");
REQUIRE(1422752523000 == timestamp);
REQUIRE(25 == timestamp_begin_pos);
REQUIRE(49 == timestamp_end_pos);
content.assign(line, 0, timestamp_begin_pos);
content.append(line, timestamp_end_pos, timestamp_end_pos - timestamp_begin_pos);
pattern->insert_formatted_timestamp(timestamp, content);
REQUIRE(line == content);
line = "<<<2015-02-01 01:02:03:004 content after";
pattern = TimestampPattern::search_known_ts_patterns(line, timestamp, timestamp_begin_pos, timestamp_end_pos);
REQUIRE(nullptr != pattern);
REQUIRE(pattern->get_num_spaces_before_ts() == 0);
REQUIRE(pattern->get_format() == "<<<%Y-%m-%d %H:%M:%S:%3");
REQUIRE(1422752523004 == timestamp);
REQUIRE(0 == timestamp_begin_pos);
REQUIRE(26 == timestamp_end_pos);
content.assign(line, 0, timestamp_begin_pos);
content.append(line, timestamp_end_pos, timestamp_end_pos - timestamp_begin_pos);
pattern->insert_formatted_timestamp(timestamp, content);
REQUIRE(line == content);
line = "Jan 21 11:56:42";
pattern = TimestampPattern::search_known_ts_patterns(line, timestamp, timestamp_begin_pos, timestamp_end_pos);
REQUIRE(nullptr != pattern);
REQUIRE(pattern->get_num_spaces_before_ts() == 0);
REQUIRE(pattern->get_format() == "%b %d %H:%M:%S");
REQUIRE(0 == timestamp_begin_pos);
REQUIRE(15 == timestamp_end_pos);
content.assign(line, 0, timestamp_begin_pos);
content.append(line, timestamp_end_pos, timestamp_end_pos - timestamp_begin_pos);
pattern->insert_formatted_timestamp(timestamp, content);
REQUIRE(line == content);
line = "01-21 11:56:42.392";
pattern = TimestampPattern::search_known_ts_patterns(line, timestamp, timestamp_begin_pos, timestamp_end_pos);
REQUIRE(nullptr != pattern);
REQUIRE(pattern->get_num_spaces_before_ts() == 0);
REQUIRE(pattern->get_format() == "%m-%d %H:%M:%S.%3");
REQUIRE(0 == timestamp_begin_pos);
REQUIRE(18 == timestamp_end_pos);
content.assign(line, 0, timestamp_begin_pos);
content.append(line, timestamp_end_pos, timestamp_end_pos - timestamp_begin_pos);
pattern->insert_formatted_timestamp(timestamp, content);
REQUIRE(line == content);
}
|
;***************************************************************************
; vector.asm
; Ejercicio que llena un vector ingresando datos por telcado y luego imprime
; Objetivos
; - definir un vector con times y resb
; - manejar un vector usando formula (i-1)*longElem
; - usar printf con varios parametros de distinto tipo
;
;***************************************************************************
global _main
extern _printf
extern _gets
section .data
msgIng db 'Ingrese un nombre para la posicion %d: ',0
msgSal db 'Elemento guardado en posicion %d: %s',10,13,0
longNombre dw 10
section .bss
vector times 3 resb 10
section .text
_main:
mov esi,1
ingElem:
push esi
push msgIng
call _printf
add esp,8
mov eax,esi ;eax = posicion
dec eax ;eax = posicion - 1
imul word[longNombre] ;eax = (posicion - 1) * 10
lea eax,[vector+eax] ;eax = dir nombre
push eax
call _gets
add esp,4
inc esi ;incremento esi para posicionarlo en la sgte posicion del vector
cmp esi,3
jle ingElem
mov esi,1
impElem:
mov eax,esi ;eax = posicion
dec eax ;eax = posicion - 1
imul word[longNombre] ;eax = (posicion - 1) * 10
lea eax,[vector+eax] ;eax = dir nombre
push eax
push esi
push msgSal
call _printf
add esp,12
inc esi ;incremento esi para posicionarlo en la sgte posicion del vector
cmp esi,3
jle impElem
ret |
// Copyright (c) 2015, Andre Gaschler, Quirin Fischer
// 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.
//
// 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 HOLDER 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 "boundingmesh/VoxelSet.h"
#include <algorithm>
#include <cassert>
#include <fstream>
#include <iostream>
#include <limits>
#include <queue>
#include <tuple>
namespace boundingmesh {
// License of the following functions is public domain according to
// http://fileadmin.cs.lth.se/cs/Personal/Tomas_Akenine-Moller/code/
/********************************************************/
/* AABB-triangle overlap test code */
/* by Tomas Akenine-Möller */
/* Function: int triBoxOverlap(float boxcenter[3], */
/* float boxhalfsize[3],float triverts[3][3]); */
/* History: */
/* 2001-03-05: released the code in its first version */
/* 2001-06-18: changed the order of the tests, faster */
/* */
/* Acknowledgement: Many thanks to Pierre Terdiman for */
/* suggestions and discussions on how to optimize code. */
/* Thanks to David Hunt for finding a ">="-bug! */
/********************************************************/
// Modified to use local types
#define X 0
#define Y 1
#define Z 2
#define FINDMINMAX(x0, x1, x2, min, max) \
min = max = x0; \
if (x1 < min) min = x1; \
if (x1 > max) max = x1; \
if (x2 < min) min = x2; \
if (x2 > max) max = x2;
#define AXISTEST_X01(a, b, fa, fb) \
p0 = a * v0[Y] - b * v0[Z]; \
p2 = a * v2[Y] - b * v2[Z]; \
if (p0 < p2) { \
min = p0; \
max = p2; \
} else { \
min = p2; \
max = p0; \
} \
rad = fa * boxhalfsize[Y] + fb * boxhalfsize[Z]; \
if (min > rad || max < -rad) return 0;
#define AXISTEST_X2(a, b, fa, fb) \
p0 = a * v0[Y] - b * v0[Z]; \
p1 = a * v1[Y] - b * v1[Z]; \
if (p0 < p1) { \
min = p0; \
max = p1; \
} else { \
min = p1; \
max = p0; \
} \
rad = fa * boxhalfsize[Y] + fb * boxhalfsize[Z]; \
if (min > rad || max < -rad) return 0;
#define AXISTEST_Y02(a, b, fa, fb) \
p0 = -a * v0[X] + b * v0[Z]; \
p2 = -a * v2[X] + b * v2[Z]; \
if (p0 < p2) { \
min = p0; \
max = p2; \
} else { \
min = p2; \
max = p0; \
} \
rad = fa * boxhalfsize[X] + fb * boxhalfsize[Z]; \
if (min > rad || max < -rad) return 0;
#define AXISTEST_Y1(a, b, fa, fb) \
p0 = -a * v0[X] + b * v0[Z]; \
p1 = -a * v1[X] + b * v1[Z]; \
if (p0 < p1) { \
min = p0; \
max = p1; \
} else { \
min = p1; \
max = p0; \
} \
rad = fa * boxhalfsize[X] + fb * boxhalfsize[Z]; \
if (min > rad || max < -rad) return 0;
#define AXISTEST_Z12(a, b, fa, fb) \
p1 = a * v1[X] - b * v1[Y]; \
p2 = a * v2[X] - b * v2[Y]; \
if (p2 < p1) { \
min = p2; \
max = p1; \
} else { \
min = p1; \
max = p2; \
} \
rad = fa * boxhalfsize[X] + fb * boxhalfsize[Y]; \
if (min > rad || max < -rad) return 0;
#define AXISTEST_Z0(a, b, fa, fb) \
p0 = a * v0[X] - b * v0[Y]; \
p1 = a * v1[X] - b * v1[Y]; \
if (p0 < p1) { \
min = p0; \
max = p1; \
} else { \
min = p1; \
max = p0; \
} \
rad = fa * boxhalfsize[X] + fb * boxhalfsize[Y]; \
if (min > rad || max < -rad) return 0;
bool PlaneBoxOverlap(const Vector3& normal, const Vector3& vert,
const Vector3& maxbox) {
int q;
Vector3 vmin, vmax;
Real v;
for (q = X; q <= Z; q++) {
v = vert[q];
if (normal[q] > 0.0) {
vmin[q] = -maxbox[q] - v;
vmax[q] = maxbox[q] - v;
} else {
vmin[q] = maxbox[q] - v;
vmax[q] = -maxbox[q] - v;
}
}
if (normal.dot(vmin) > 0.0) return false;
if (normal.dot(vmax) >= 0.0) return true;
return false;
}
bool TriBoxOverlap(const Vector3& boxcenter, const Vector3& boxhalfsize,
const Vector3& triver0, const Vector3& triver1,
const Vector3& triver2) {
/* use separating axis theorem to test overlap between triangle and box */
/* need to test for overlap in these directions: */
/* 1) the {x,y,z}-directions (actually, since we use the AABB of the
* triangle */
/* we do not even need to test these) */
/* 2) normal of the triangle */
/* 3) crossproduct(edge from tri, {x,y,z}-directin) */
/* this gives 3x3=9 more tests */
Vector3 v0, v1, v2;
double min, max, p0, p1, p2, rad, fex, fey,
fez; // -NJMP- "d" local variable removed
Vector3 normal, e0, e1, e2;
/* This is the fastest branch on Sun */
/* move everything so that the boxcenter is in (0,0,0) */
v0 = triver0 - boxcenter;
v1 = triver1 - boxcenter;
v2 = triver2 - boxcenter;
/* compute triangle edges */
e0 = v1 - v0; /* tri edge 0 */
e1 = v2 - v1; /* tri edge 1 */
e2 = v0 - v2; /* tri edge 2 */
/* Bullet 3: */
/* test the 9 tests first (this was faster) */
fex = fabs(e0[X]);
fey = fabs(e0[Y]);
fez = fabs(e0[Z]);
AXISTEST_X01(e0[Z], e0[Y], fez, fey);
AXISTEST_Y02(e0[Z], e0[X], fez, fex);
AXISTEST_Z12(e0[Y], e0[X], fey, fex);
fex = fabs(e1[X]);
fey = fabs(e1[Y]);
fez = fabs(e1[Z]);
AXISTEST_X01(e1[Z], e1[Y], fez, fey);
AXISTEST_Y02(e1[Z], e1[X], fez, fex);
AXISTEST_Z0(e1[Y], e1[X], fey, fex);
fex = fabs(e2[X]);
fey = fabs(e2[Y]);
fez = fabs(e2[Z]);
AXISTEST_X2(e2[Z], e2[Y], fez, fey);
AXISTEST_Y1(e2[Z], e2[X], fez, fex);
AXISTEST_Z12(e2[Y], e2[X], fey, fex);
/* Bullet 1: */
/* first test overlap in the {x,y,z}-directions */
/* find min, max of the triangle each direction, and test for overlap in */
/* that direction -- this is equivalent to testing a minimal AABB around */
/* the triangle against the AABB */
/* test in X-direction */
FINDMINMAX(v0[X], v1[X], v2[X], min, max);
if (min > boxhalfsize[X] || max < -boxhalfsize[X]) return false;
/* test in Y-direction */
FINDMINMAX(v0[Y], v1[Y], v2[Y], min, max);
if (min > boxhalfsize[Y] || max < -boxhalfsize[Y]) return false;
/* test in Z-direction */
FINDMINMAX(v0[Z], v1[Z], v2[Z], min, max);
if (min > boxhalfsize[Z] || max < -boxhalfsize[Z]) return false;
/* Bullet 2: */
/* test if the box intersects the plane of the triangle */
/* compute plane equation of triangle: normal*x+d=0 */
normal = e0.cross(e1);
if (!PlaneBoxOverlap(normal, v0, boxhalfsize)) return false;
return true; /* box and triangle overlaps */
}
Voxel::Voxel() {}
Voxel::Voxel(Index x, Index y, Index z, VoxelType type)
: x_(x), y_(y), z_(z), type_(type), triangles_() {}
Voxel::Voxel(const Voxel& voxel)
: x_(voxel.x_),
y_(voxel.y_),
z_(voxel.z_),
type_(voxel.type_),
triangles_(voxel.triangles_) {}
Voxel::~Voxel() {}
Voxel& Voxel::operator=(Voxel other) {
swap(*this, other);
return *this;
}
void swap(Voxel& first, Voxel& second) {
std::swap(first.x_, second.x_);
std::swap(first.y_, second.y_);
std::swap(first.z_, second.z_);
std::swap(first.type_, second.type_);
first.triangles_.swap(second.triangles_);
}
Index Voxel::x() const { return x_; }
Index Voxel::y() const { return y_; }
Index Voxel::z() const { return z_; }
Index Voxel::coordinate(int dimension) const {
assert(dimension >= 0 && dimension < 3);
switch (dimension) {
case 0:
return x_;
case 1:
return y_;
case 2:
return z_;
default:
return 0;
};
}
VoxelType Voxel::type() const { return type_; }
unsigned int Voxel::nTriangles() const { return triangles_.size(); }
Index Voxel::triangle(unsigned int i) const { return triangles_[i]; }
void Voxel::addTriangle(Index triangle) { triangles_.push_back(triangle); }
VoxelSet::VoxelSet() : origin_(0, 0, 0), voxel_size_(0), mesh_(NULL) {
resolution_[0] = 0;
resolution_[1] = 0;
resolution_[2] = 0;
}
VoxelSet::VoxelSet(const VoxelSet& voxel_set) {
origin_ = voxel_set.origin_;
voxel_size_ = voxel_set.voxel_size_;
resolution_[0] = voxel_set.resolution_[0];
resolution_[1] = voxel_set.resolution_[1];
resolution_[2] = voxel_set.resolution_[2];
mesh_ = voxel_set.mesh_;
voxels_ = voxel_set.voxels_;
grid_ = voxel_set.grid_;
}
VoxelSet::VoxelSet(std::shared_ptr<Mesh> triangle_mesh, Real voxel_size,
bool newVersion) {
//"Rasterize" triangle mesh to generate a voxel set
mesh_ = triangle_mesh;
voxel_size_ = voxel_size;
// Set up the grid dimensions
// First compute bounding box of the mesh
Vector3 bounding_box_min = Vector3(std::numeric_limits<Real>::max(),
std::numeric_limits<Real>::max(),
std::numeric_limits<Real>::max());
Vector3 bounding_box_max = Vector3(std::numeric_limits<Real>::min(),
std::numeric_limits<Real>::min(),
std::numeric_limits<Real>::min());
for (unsigned int i = 0; i < triangle_mesh->nVertices(); ++i) {
Vector3 position = triangle_mesh->vertex(i).position();
bounding_box_min(0) = std::min(bounding_box_min(0), position(0));
bounding_box_min(1) = std::min(bounding_box_min(1), position(1));
bounding_box_min(2) = std::min(bounding_box_min(2), position(2));
bounding_box_max(0) = std::max(bounding_box_max(0), position(0));
bounding_box_max(1) = std::max(bounding_box_max(1), position(1));
bounding_box_max(2) = std::max(bounding_box_max(2), position(2));
}
// Compute voxel resolution along the axes
// All voxels are cubes with side size voxel_size
//-> Round up, extend in all directions by 1
// Adjust origin so the mesh is centered
Vector3 size = bounding_box_max - bounding_box_min;
for (int i = 0; i < 3; ++i) {
resolution_[i] = (Index)(size(i) / voxel_size_);
if (resolution_[i] * voxel_size_ < size(i)) resolution_[i] += 1;
resolution_[i] += 2;
origin_(i) =
bounding_box_min(i) - ((resolution_[i] * voxel_size_) - size(i)) / 2;
}
Vector3 check_origin = origin_;
if (resolution_[0] * resolution_[1] * resolution_[2] > 256 * 256 * 256)
std::cout << "Very high resolution detected, might not fit into memory: "
<< resolution_[0] << ", " << resolution_[1] << ", "
<< resolution_[2] << std::endl;
grid_ = std::vector<int>(resolution_[0] * resolution_[1] * resolution_[2]);
for (unsigned int i = 0; i < grid_.size(); ++i) grid_[i] = -1;
// Rasterize triangles to find voxels intersecting the surface of the mesh
for (unsigned int i = 0; i < triangle_mesh->nTriangles(); ++i) {
const Triangle& triangle = triangle_mesh->triangle(i);
// Calculate bounding box of triangle
Vector3 triangle_box_min = Vector3(std::numeric_limits<Real>::max(),
std::numeric_limits<Real>::max(),
std::numeric_limits<Real>::max());
Vector3 triangle_box_max = Vector3(std::numeric_limits<Real>::lowest(),
std::numeric_limits<Real>::lowest(),
std::numeric_limits<Real>::lowest());
Vector3 vertices[3];
for (unsigned int j = 0; j < 3; ++j) {
Vector3 position = triangle_mesh->vertex(triangle.vertex(j)).position();
vertices[j] = position;
triangle_box_min(0) = std::min(triangle_box_min(0), position(0));
triangle_box_min(1) = std::min(triangle_box_min(1), position(1));
triangle_box_min(2) = std::min(triangle_box_min(2), position(2));
triangle_box_max(0) = std::max(triangle_box_max(0), position(0));
triangle_box_max(1) = std::max(triangle_box_max(1), position(1));
triangle_box_max(2) = std::max(triangle_box_max(2), position(2));
}
// Calculate range of voxels intersecting with the bounding box
Index min_indices[3];
Index max_indices[3];
for (unsigned int j = 0; j < 3; ++j) {
min_indices[j] = (int)((triangle_box_min(j) - origin_(j)) / voxel_size_);
if (origin_(j) + (min_indices[j] * voxel_size_) + voxel_size_ / 2 <
triangle_box_min(j))
min_indices[j]++;
max_indices[j] = (int)((triangle_box_max(j) - origin_(j)) / voxel_size_);
if (origin_(j) + (max_indices[j] * voxel_size_) + voxel_size_ / 2 <
triangle_box_max(j))
max_indices[j]++;
}
// Test every voxel in range for intersection with the triangle
for (int vox_x = min_indices[0]; vox_x <= max_indices[0]; vox_x++) {
for (int vox_y = min_indices[1]; vox_y <= max_indices[1]; vox_y++) {
for (int vox_z = min_indices[2]; vox_z <= max_indices[2]; vox_z++) {
Vector3 voxel_position = origin_ +
Vector3(voxel_size_, 0, 0) * vox_x +
Vector3(0, voxel_size_, 0) * vox_y +
Vector3(0, 0, voxel_size_) * vox_z;
Vector3 voxel_halfdiagonal =
Vector3(voxel_size_ / 2, voxel_size_ / 2, voxel_size_ / 2);
if (TriBoxOverlap(voxel_position, voxel_halfdiagonal, vertices[0],
vertices[1], vertices[2])) {
unsigned int grid_index = vox_x + vox_y * resolution_[0] +
vox_z * resolution_[0] * resolution_[1];
if (grid_[grid_index] == -1) {
Voxel new_voxel(vox_x, vox_y, vox_z, SURFACE);
new_voxel.addTriangle(i);
grid_[grid_index] = voxels_.size();
voxels_.push_back(new_voxel);
} else {
voxels_[grid_[grid_index]].addTriangle(i);
}
}
}
}
}
}
// The new version uses an alternative approach to fill the interior, as the
// ray casting approach
// sometimes currently seems to leave holes within the interior
if (!newVersion) {
// Fill interior volume of shape
// Cast rays through X-Y plane in direction -Z
// fill empty areas after entering and before leaving the surface (check ray
// against triangle plane)
Vector3 ray_direction(0, 0, -1);
for (int vox_x = 0; vox_x < resolution_[0]; vox_x++) {
for (int vox_y = 0; vox_y < resolution_[1]; vox_y++) {
int last_found_voxel = -1;
for (int vox_z = 0; vox_z < resolution_[2]; vox_z++) {
unsigned int grid_index = vox_x + vox_y * resolution_[0] +
vox_z * resolution_[0] * resolution_[1];
if (grid_[grid_index] == -1 && last_found_voxel != -1) {
const Voxel& vox = voxel(last_found_voxel);
int fill = 0;
for (unsigned int triangle_i = 0; triangle_i < vox.nTriangles();
++triangle_i) {
const Triangle& triangle =
triangle_mesh->triangle(vox.triangle(triangle_i));
Real side = triangle.plane().normal.dot(ray_direction);
if (side > 0 && fill == 0) {
fill = 1;
} else if (side <= 0) {
fill = -1;
break;
}
}
if (fill == 1) {
Voxel new_voxel(vox_x, vox_y, vox_z, INNER);
grid_[grid_index] = voxels_.size();
voxels_.push_back(new_voxel);
}
} else if (grid_[grid_index] != -1) {
last_found_voxel = grid_[grid_index];
}
}
}
}
} else {
// Mark all outside Voxels (the ones reachable from a border) with -2
int neighbours[6][3] = {{0, 0, 1}, {0, 0, -1}, {0, 1, 0},
{0, -1, 0}, {1, 0, 0}, {-1, 0, 0}};
for (int vox_x = 0; vox_x < resolution_[0]; vox_x++) {
for (int vox_y = 0; vox_y < resolution_[1]; vox_y++) {
for (int vox_z = 0; vox_z < resolution_[2]; vox_z++) {
unsigned int grid_index = vox_x + vox_y * resolution_[0] +
vox_z * resolution_[0] * resolution_[1];
if (grid_[grid_index] == -1 &&
(vox_x == 0 || vox_y == 0 || vox_z == 0 ||
vox_x == resolution_[0] || vox_y == resolution_[1] ||
vox_z == resolution_[2])) {
std::queue<std::tuple<int, int, int>> q;
q.push(std::make_tuple(vox_x, vox_y, vox_z));
grid_[grid_index] = -2;
while (!q.empty()) {
std::tuple<int, int, int> current = q.front();
q.pop();
int x = std::get<0>(current);
int y = std::get<1>(current);
int z = std::get<2>(current);
for (int i = 0; i < 6; i++) {
int ax = x + neighbours[i][0];
int ay = y + neighbours[i][1];
int az = z + neighbours[i][2];
unsigned int ni = ax + ay * resolution_[0] +
az * resolution_[0] * resolution_[1];
if (ni < 0 || ni > grid_.size() || ax < 0 || ay < 0 || az < 0 ||
ax >= resolution_[0] || ay >= resolution_[1] ||
az >= resolution_[2]) {
continue;
}
if (grid_[ni] == -1) {
grid_[ni] = -2;
q.push(std::make_tuple(ax, ay, az));
}
}
}
}
}
}
}
// Mark all voxels not marked as outside, that are not part of the surface
// as inner voxel
for (int vox_x = 0; vox_x < resolution_[0]; vox_x++) {
for (int vox_y = 0; vox_y < resolution_[1]; vox_y++) {
for (int vox_z = 0; vox_z < resolution_[2]; vox_z++) {
unsigned int grid_index = vox_x + vox_y * resolution_[0] +
vox_z * resolution_[0] * resolution_[1];
if (grid_[grid_index] == -1) {
Voxel new_voxel(vox_x, vox_y, vox_z, INNER);
grid_[grid_index] = voxels_.size();
voxels_.push_back(new_voxel);
}
}
}
}
// Revert all -2 marks to -1
for (int vox_x = 0; vox_x < resolution_[0]; vox_x++) {
for (int vox_y = 0; vox_y < resolution_[1]; vox_y++) {
for (int vox_z = 0; vox_z < resolution_[2]; vox_z++) {
unsigned int grid_index = vox_x + vox_y * resolution_[0] +
vox_z * resolution_[0] * resolution_[1];
if (grid_[grid_index] == -2) {
grid_[grid_index] = -1;
}
}
}
}
// Use BFS to fix empty cells in the inside (convert them to inner cells)
// Needed to fix bugs from previous procedure
/*for(int vox_x = 0; vox_x < resolution_[0]; vox_x++)
{
for(int vox_y = 0; vox_y < resolution_[1]; vox_y++)
{
for(int vox_z = 0; vox_z < resolution_[2]; vox_z++)
{
unsigned int grid_index = vox_x + vox_y*resolution_[0] +
vox_z*resolution_[0]*resolution_[1];
if(grid_[grid_index] == -1) {
continue;
}
const Voxel& vox = voxel(grid_[grid_index]);
if (vox.type() == INNER) {
for (int i = 0; i < 6; i++) {
int nx = vox_x + neighbours[i][0];
int ny = vox_y + neighbours[i][1];
int nz = vox_z + neighbours[i][2];
unsigned int neighbour_index = nx + ny*resolution_[0] +
nz*resolution_[0]*resolution_[1];
if (neighbour_index < 0 || neighbour_index > grid_.size()) {
continue;
}
if (grid_[neighbour_index] == -1) {
std::queue<std::tuple<int,int,int>> q;
q.push(std::make_tuple(nx, ny, nz));
Voxel new_voxel(nx, ny, nz, INNER);
grid_[grid_index] = voxels_.size();
voxels_.push_back(new_voxel);
while (!q.empty()) {
std::tuple<int,int,int> current = q.front();
q.pop();
int x = std::get<0>(current);
int y = std::get<1>(current);
int z = std::get<2>(current);
for (int i = 0; i < 6; i++) {
int ax = x + neighbours[i][0];
int ay = y + neighbours[i][1];
int az = z + neighbours[i][2];
unsigned int ni = ax + ay*resolution_[0] +
az*resolution_[0]*resolution_[1];
if (ni < 0 || ni > grid_.size() || ax < 0 || ay < 0 || az < 0 || ax >=
resolution_[0] || ay >= resolution_[1] || az >= resolution_[2]) {
continue;
}
if (grid_[ni] == -1) {
Voxel new_voxel(ax, ay, az, INNER);
grid_[ni] = voxels_.size();
voxels_.push_back(new_voxel);
q.push(std::make_tuple(ax, ay, az));
}
}
}
}
}
}
}
}
}*/
}
std::cout << "Finished voxeling: Dimensions " << resolution_[0] << " x "
<< resolution_[1] << " x " << resolution_[2] << "; generated "
<< voxels_.size() << " voxels" << std::endl;
}
VoxelSet::~VoxelSet() {}
VoxelSet& VoxelSet::operator=(VoxelSet other) {
swap(*this, other);
return *this;
}
void swap(VoxelSet& first, VoxelSet& second) {
std::swap(first.origin_, second.origin_);
std::swap(first.voxel_size_, second.voxel_size_);
std::swap(first.resolution_[0], second.resolution_[0]);
std::swap(first.resolution_[1], second.resolution_[1]);
std::swap(first.resolution_[2], second.resolution_[2]);
std::swap(first.mesh_, second.mesh_);
first.voxels_.swap(second.voxels_);
first.grid_.swap(second.grid_);
}
unsigned int VoxelSet::nVoxels() const { return voxels_.size(); }
const Voxel& VoxelSet::voxel(Index i) const { return voxels_[i]; }
const Vector3& VoxelSet::origin() const { return origin_; }
Real VoxelSet::voxelSize() const { return voxel_size_; }
unsigned int VoxelSet::resolution(int dimension) const {
assert(0 <= dimension && dimension < 3);
return resolution_[dimension];
}
std::shared_ptr<Mesh> VoxelSet::mesh() const { return mesh_; }
int VoxelSet::voxelAt(unsigned int x, unsigned int y, unsigned int z) const {
assert(x >= 0 && x < resolution_[0]);
assert(y >= 0 && y < resolution_[1]);
assert(z >= 0 && z < resolution_[2]);
return grid_[x + y * resolution_[0] + z * resolution_[0] * resolution_[1]];
}
void VoxelSet::addVoxel(const Voxel& voxel) {
assert(voxel.x() >= 0 && voxel.x() < resolution_[0]);
assert(voxel.y() >= 0 && voxel.y() < resolution_[1]);
assert(voxel.z() >= 0 && voxel.z() < resolution_[2]);
grid_[voxel.x() + voxel.y() * resolution_[0] +
voxel.z() * resolution_[0] * resolution_[1]] = voxels_.size();
voxels_.push_back(voxel);
}
Real VoxelSet::volume() {
return voxels_.size() * voxel_size_ * voxel_size_ * voxel_size_;
}
Vector3 VoxelSet::computePosition(const Voxel& voxel) const {
return origin_ + Vector3(voxel_size_, 0, 0) * voxel.x() +
Vector3(voxel_size_, 0, 0) * voxel.y() +
Vector3(voxel_size_, 0, 0) * voxel.z();
}
void VoxelSet::writeWRL(std::string filename) {
std::ofstream file(filename.c_str());
file << "#VRML V2.0 utf8" << std::endl << std::endl;
file << "#Created by boundingmesh" << std::endl << std::endl;
file << "Transform {" << std::endl;
file << "\t translation " << origin_(0) << " " << origin_(1) << " "
<< origin_(2) << std::endl;
file << "\t scale " << voxel_size_ << " " << voxel_size_ << " " << voxel_size_
<< std::endl;
file << "\t children [ " << std::endl;
for (unsigned int i = 0; i < nVoxels(); ++i) {
file << "\t\tTransform {" << std::endl;
file << "\t\t\t translation " << voxel(i).x() << " " << voxel(i).y() << " "
<< voxel(i).z() << std::endl;
file << "\t\t\t children [ " << std::endl;
file << "\t\t\t\tShape {" << std::endl;
file << "\t\t\t\t\tappearance Appearance {" << std::endl;
file << "\t\t\t\t\t\tmaterial Material {" << std::endl;
if (voxel(i).type() == SURFACE)
file << "\t\t\t\t\t\t\tdiffuseColor 1 1 1" << std::endl;
else if (voxel(i).type() == INNER)
file << "\t\t\t\t\t\t\tdiffuseColor 0 0 1" << std::endl;
file << "\t\t\t\t\t\t}" << std::endl;
file << "\t\t\t\t\t}" << std::endl;
file << "\t\t\t\t\tgeometry Sphere {" << std::endl;
file << "\t\t\t\t\t\tradius " << 0.25 << std::endl;
file << "\t\t\t\t\t}" << std::endl;
file << "\t\t\t\t}" << std::endl;
file << "\t\t\t ]" << std::endl;
file << "\t\t}";
}
file << "\t ]" << std::endl;
file << "}";
}
}
|
<%
from pwnlib.shellcraft.thumb.linux import syscall
%>
<%page args="pid"/>
<%docstring>
Invokes the syscall getsid. See 'man 2 getsid' for more information.
Arguments:
pid(pid_t): pid
</%docstring>
${syscall('SYS_getsid', pid)}
|
; Z88 Small C+ Run time Library
; Moved functions over to proper libdefs
; To make startup code smaller and neater!
;
; 6/9/98 djm
SECTION code_crt0_sccz80
PUBLIC l_ult
;
; DE < HL [unsigned]
; set carry if true
.l_ult
ld a,d
cp h
ret nz
ld a,e
cp l
ret
|
//*****************************************************************************
// Copyright 2017-2018 Intel Corporation
//
// 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.
//*****************************************************************************
#pragma once
#include "ngraph/pass/graph_rewrite.hpp"
namespace ngraph
{
namespace runtime
{
namespace cpu
{
namespace pass
{
class CPUPostLayoutOptimizations;
}
}
}
}
class ngraph::runtime::cpu::pass::CPUPostLayoutOptimizations : public ngraph::pass::GraphRewrite
{
public:
CPUPostLayoutOptimizations()
: GraphRewrite()
{
construct_weight_fusion();
}
void construct_weight_fusion();
};
|
; size_t b_array_push_back_callee(b_array_t *a, int c)
SECTION code_adt_b_array
PUBLIC _b_array_push_back_callee
EXTERN _b_array_append_callee
defc _b_array_push_back_callee = _b_array_append_callee
INCLUDE "adt/b_array/z80/asm_b_array_push_back.asm"
|
TITLE Combinations Quiz (program6b_Nguyen_Richard.asm)
; Author: Richard Nguyen
; Last Modified: 12/8/19
; OSU email address: nguyeric@oregonstate.edu
; Course number/section:CS_271_400_F2019
; Project Number: 6B Due Date: 12/8/2019
; Description: Asks User to calculate the number of combinations of r items from set of n items.
; System generates problems with n in [3..12] and r in [1..n]. User answers answer
; and system reports correct answer and evaluation of User's answer. Process repeats
; until user quits.
INCLUDE Irvine32.inc
; (insert constant definitions here)
; min and max of n, in range 3 to 12
NMIN=3
NMAX=12
; min and max of r, in range of 1 to n
RMIN = 2
.data
; (insert variable definitions here)
;*****introduction
intro_1 BYTE "Program #6b: Combinations Calculator/Practice Problems by Richard Nguyen ", 0
intro_2 BYTE "I will generate a combinations problem for you.", 0
intro_3 BYTE "Enter your answer and I'll tell you if you got it right!", 0
;******showProblem
r DWORD ? ; r to be randomly generated [3..12]
n DWORD ? ; n to be randomly generated [1..n]
problem_1 BYTE "Problem: ",0
problem_2 BYTE "Number of elements in the set: ",0
problem_3 BYTE "Number of elements to choose from set: ",0
;*****getData
userAnswer DWORD ? ; variable for user int
userString BYTE 10 DUP(0) ; variable for user string
prompt BYTE "How many ways can you choose?: ",0
error_1 BYTE "Invalid answer! Please try again. ",0
;*****combinations
result DWORD ? ; stores correct answer from calculation
;*****showResults
result_1 BYTE "There are ",0
result_2 BYTE " ways to choose ",0
result_3 BYTE " items from a set of ",0
correct BYTE "Your answer was correct!", 0
incorrect BYTE "Your answer was incorrect!",0
showUserAnswer BYTE "You answered: ", 0
;******playAgain
prompt_again BYTE "Play again?(y/n): "
choice BYTE 10 DUP(0) ; variable for choice answer
choiceYes BYTE "y",0 ; yes string
choiceNo BYTE "n",0 ; no string
;****goodbye
goodbye_1 BYTE "Thanks for using the combinatorics practice program! Goodbye! ", 0
; ------------ Macros
;displayString - string argument replaces buffer parameter and is displayed to screen
displayString MACRO buffer
push edx
mov edx, OFFSET buffer
call WriteString
pop edx
ENDM
.code
main PROC
; (insert executable instructions here)
call Randomize ;initializes sequence based on clock (random seed)
call introduction ; call introduction procedure
newGame: ;label to jump back to if user chooses play again
; generate r and n, display problem
; pass r and n by reference
push offset r
push offset n
call showProblem ; call showProblem procedure
;get user answer
push offset userAnswer
call getData ; call getData procedure
;calculate combination answer
; pass r and n by value. pass correctAnswer by reference
push r
push n
push OFFSET result
call combinations ; call combinations procedure
;show results. Pass n, r, userAnswer, and result
push r
push n
push result
push userAnswer
call showResults
; if ebx is set to 1, loop and play again
call playAgain
cmp ebx, 1
je newGame
call goodbye ; call goodbye procedure
exit ; exit to operating system
main ENDP
; (insert additional procedures here)
;*************INTRODUCTION*******************************
;**Introduce program.
;**recieves: intro_1, intro_2, intro_3 string variables
;**returns: nothing
;**preconditions: none
;**registers changed: none
;********************************************************
introduction PROC
;introduction, display name and program title to output
displayString intro_1
call CrLf
;Show instructions.
displayString intro_2
call CrLf
displayString intro_3
call CrLf
call crlf
ret
introduction ENDP
;*************showProblem*******************************
;** generate random n and r, display problem
;**recieves: OFFSETS of n and r
;**returns: random n and random r within respective ranges
;**preconditions: r and n parameters pushed to stack. (2 items pushed)
;**registers changed: eax, ecx ,edx
;********************************************************
showProblem PROC
; set stack frame n is [ebp+8], r is [ebp+12]
push ebp
mov ebp, esp
; move pushed parameters to registers.
mov edx, [ebp+8] ; move n to edx
mov ecx, [ebp+12] ; move r to ecx
; generate random n within range. REFERENCE: Method implemented from lecture 20
mov eax, NMAX ; upper limit of random num
sub eax, NMIN ; subtract upper limit by lower limit
inc eax ; inc by 1 to get range of random numbers
call randomRange ; get random number from range
add eax, NMIN ; range of random number [3..12]
mov [edx], eax ; store random n, move result from eax to [edx], variable n
; generate random r within range [1..n]
;Note: max value is n. REFERENCE: Using random method from lecture 20
mov eax, [edx] ; upper limit
sub eax, RMIN ; subtract upper limit by lower limit
inc eax ; get range of random numbers
call randomRange ; get random number in range
add eax, RMIN ; range is [1..n]
mov [ecx], eax ; store random r, move result from eax to [ecx], variable r
; ****display problem to screen
call CrLf
displayString problem_1 ;"Problem: "
call CrLf
displayString problem_2
mov eax, [edx] ; move n to eax for display
call WriteDec
call CrLf
displayString problem_3
mov eax, [ecx] ;move r to eax for display
call WriteDec
call CrLf
pop ebp
ret 8
showProblem ENDP
;*************getData*****************************
;**get user's answer. Validates answer
;**recieves: OFFSETS of userAnswer
;**returns: instructions to user, read their input answer
;**preconditions: userAnswer pushed on stack
;**registers changed: eax, ebx, ecx, esi
;*************************************************
getData PROC
; set stack frame userAnswer is [ebp+8]
push ebp
mov ebp, esp
mov edi, [ebp+8] ; address user answer in edi
mov eax, 0 ; reset registers
mov ecx, 0
mov edx, 0
mov [edi], eax ; reset edi to 0
jmp getAnswer ;skip error message if first try
invalid:
displayString error_1
call CrLf
getAnswer:
displayString prompt
;set conditions for readstring
mov edx, OFFSET userString ; move offset of userString to edx
mov ecx, 9 ; move max non-null chars into ecx
call ReadString ; readstring, size of string in eax
;Note: readstring returns size of input string to eax
;setting up loop to step through string, REFERENCE: from demo6
mov ecx, eax ; size of input string as loop counter
mov esi, OFFSET userString ; put userString address in source register
cld ; clear direction flag
checkValid:
mov ebx, [ebp+8] ; userAnswer into ebx register
mov eax, [ebx] ; move value of answer into eax
mov ebx, 10 ; max string size
mul ebx ; eax * ebx, value * 10, result in eax
mov ebx, [ebp+8] ;move user answer to ebx
mov [ebx], eax
mov al, [esi] ; userString to al
cmp al, 48 ; compare string byte to 48 (digit 0 on ASCII)
jb invalid ; char is not a digit, jump to invalid to display error and get new answer
cmp al, 57 ; compare string byte to 57 (digit 9 on ASCII)
ja invalid ; char is not a digit, jump to invalid to display error and get new answer
inc esi ; inc esi to check next
sub al, 48 ; convert ASCII char value to digit value (ex. dec 48 is 0)
mov ebx, [ebp+8] ; move userAnswer to ebx
add [ebx], al ; add digit from al to [ebx]
loop checkValid ; step through string
jmp inputEnd
inputEnd:
call crlf
pop ebp
ret 4
getData ENDP
;*************factorial*****************************
;** sub procedure of combinations. perform calculations of factorial via recursion
;**recieves: integer values (N) in edx
;**returns: The factorial of argument. N! in eax
;**preconditions: value of N pushed onto stack
;**registers changed: eax, ebx, esi
;*************************************************
factorial PROC
; set stack frame. integer N is [ebp+8]
push ebp ; store registers
mov ebp,esp
mov eax, [ebp+8] ; move N to eax
;factorial of 1 or 0 is 1
;BASE CASE
cmp eax, 1
jle factorialDone
;else, perform recursion
dec eax ;eax is now N-1
push eax
call factorial
mov esi, [ebp+8]
mul esi
factorialDone:
pop ebp ; restore registers
ret 4
factorial ENDP
;*************combinations*****************************
;** perform calculatons on generated n and r
;**recieves: n, r, address of result
;**returns: result
;**preconditions: n and r values, OFFSET of result
; pushed on stack
;**registers changed: eax, ebx, ecx, edx
; REFERENCE: formula for combination from program 6b pdf
;*************************************************
combinations PROC
; set stack frame.
;r is [ebp+16],
;n is [ebp+12],
;@result is [ebp+8]
push ebp
mov ebp,esp
mov edx, [ebp+16] ;move r into register
mov eax, [ebp+12] ;move n into register
cmp eax,edx
je nrEqual
;calculate (n-r)!
mov eax, [ebp+12] ; move n to eax
sub eax, [ebp+16] ; get n-r, result in eax
mov edx, eax ; move result n-r into edx for factorial
push edx ;push edx to stack to prep factorial
call factorial
mov ecx, eax
;calculate r!
mov edx, [ebp+16]
push edx ;push edx to stack to prep factorial
call factorial
; result of (n-r)! in now in eax
; multiply (n-r)! by r!
;Note: (n-r)! already in eax, r! in ecx
mul ecx ; multiply ecx by eax, result in eax
mov ecx, eax ; r!(n-r)! in ecx
;calculate value for n!
mov edx, [ebp+12]
push edx
call factorial ; n! in eax
;calculate n!/ (r!(n-r)!)
; prepare division, set edx to 0
mov edx,0
div ecx ; divide by r!(n-r)!
; @result at [ebp+8], move to ebx register for storage
mov ebx, [ebp+8]
mov [ebx], eax ; store answer in result
jmp combinationsDone
; n and r are equal ... factorial is 1
nrEqual:
mov ebx, [ebp+8]
mov ecx, 1
mov [ebx], ecx
combinationsDone:
pop ebp
ret 12 ; 3 items were pushed
combinations ENDP
;*************showResults*****************************
;** show results of combination problem , note user performance
;**recieves: goodbye_1 string variable
;**returns: nothing
;**preconditions: none
;**registers changed: none
;*************************************************
showResults PROC
;set stack frame
;[ebp+20] is r
;[ebp+16] is n
;[ebp+12] is result
;[ebp+8] is userAnswer
push ebp
mov ebp, esp
;dispay result
displayString result_1
mov eax, [ebp+12] ; move result for display
call WriteDec
;display random r value
displayString result_2
mov eax, [ebp+20] ;move r to eax for display
call WriteDec
;display random n value
displayString result_3
mov eax, [ebp+16] ; move n to eax for display
call WriteDec
call CrLf
; show user's amser
displayString showUserAnswer
mov eax, [ebp+8] ; move userAnswer for display
call WriteDec
call CrLf
; compare user answer to correct answer
mov ecx, [ebp+12] ; move result
mov edx, [ebp+8] ; move user answer
cmp ecx, edx ; if equal jump to correct
je userCorrect
;else display incorrect
displayString incorrect
call CrLf
jmp endDisplay
userCorrect:
displayString correct
call CrLf
endDisplay:
pop ebp
ret 16
showResults ENDP
;*************playAgain*****************************
;**ask if user wants to play again
;**recieves: prompt_again string variable
;**returns: ebx as 1 (yes) or 0 (no)
;**preconditions: none
;**registers changed: ecx
;*************************************************
playAgain PROC
choose:
mov ebx, 0
displayString prompt_again
; prep conditions for read string
mov edx, OFFSET choice
mov ecx, 9
call ReadString
; check if yes
mov esi, OFFSET choice
mov edi, OFFSET choiceYes
; compare bytes of string
cmpsb
mov ebx, 1 ; 1 interpreted as yes in main
je doneAgain
; check if no
mov esi, OFFSET choice
mov edi, OFFSET choiceNo
; compare bytes of string
cmpsb
mov ebx, 0 ; 0 interpreted as no in main
je doneAgain
; no jump means no valid answer
displayString error_1
call Crlf
jmp choose
doneAgain:
ret
playAgain ENDP
;*************goodbye*****************************
;**display goodbye
;**recieves: goodbye_1 string variable
;**returns: nothing
;**preconditions: none
;**registers changed: none
;*************************************************
goodbye PROC
call CrLf
displayString goodbye_1
call CrLf
call Crlf
ret
goodbye ENDP
END main
|
.if VAR_DEBUG
title_versionLabelShow:
push r4-r7,r14
// Copyright CAPCOM
mov r0,0x8
mov r1,0x8C
mov r2,0x1
bl 0x80291B4
// Version label
mov r0,0x0
mov r1,0x0
ldr r2,=@labelParams
bl 0x80291C4
pop r4-r7,r15
title_versionLabelPrint:
push r14
ldr r0,=@versionNameText
mov r1,0x0
ldr r2,=0x201C2C0
ldr r3,=0x60102C0
mov r4,(@NAME_END - @NAME_START)
mov r5,0x1
ldr r6,=file_601738+0xC // shift 3 pixels up
mov r7,0x0
bl 0x80554A4
bl 0x8001698
pop r15
.pool
.align 4
@versionNameText:
// Trivial text archive
.dh 0x2
@NAME_START:
.strn VAR_TARGET
.strn "-"
.if VAR_REVISION != 0xFFFFFFFF
.strn tohex(VAR_REVISION, 7)
.else
.strn tohex(VAR_VERSION_DATE)
.strn "-"
.strn tostring(VAR_VERSION_REVISION & 0x3F)
.endif
@NAME_END:
.db 0xE5 // end
.align 2
@labelParams:
.db (@NAME_END - @NAME_START)
.db 0x01
.dh 0x0016 // base tile
.db 0x02 // palette
.db 0x00
.endif
.align 2
title_inputCode:
push r14
// Draw menu cursor
bl 0x80291B4
// Trim off lower bit on progress
// This is soft reset flag, no longer used at this point
ldrb r0,[r5,0x3]
lsr r0,r0,0x1
lsl r0,r0,0x1
strb r0,[r5,0x3]
// Check if title code is available
bl @isTitleCodeAvailable
cmp r0,0h
beq @@reset
// Check cursor is on CONTINUE
ldrb r0,[r5,0x8]
cmp r0,0x1
bne @@reset
// Get new button input
mov r7,r10
ldr r7,[r7,0x4]
ldrh r0,[r7,0x2]
tst r0,r0
beq @@end
// Check button pressed
ldrb r1,[r5,0x3]
ldr r3,=@buttons
ldrh r2,[r3,r1]
cmp r0,r2
bne @@reset
// Increment progress
add r1,0x2
strb r1,[r5,0x3]
ldrh r2,[r3,r1]
tst r2,r2
bne @@end
bl @unlockAllLibraryIcons
@@reset:
// Reset code
mov r0,0x0
strb r0,[r5,0x3]
@@end:
pop r15
@isTitleCodeAvailable:
push r14
// Check Standard library
bl 0x804267C
cmp r0,0xBE
blt @@no
// Check Mega library
bl 0x80426BC
cmp r0,0x55
blt @@no
// Check Giga library
bl 0x80426FC
cmp r0,0xB
blt @@no
// Check P.A. Memo
bl 0x804273C
cmp r0,0x1E
blt @@no
// Check Bass kills
bl @getNumberOfBassKills
cmp r0,0x15
blt @@no
// Check Official Tournament clears
bl @getNumberOfOfficialClears
cmp r0,0x15
blt @@no
@@yes:
mov r0,0x1
pop r15
@@no:
mov r0,0x0
pop r15
@getNumberOfBassKills:
push r4-r5,r14
mov r4,0x0
mov r5,0x0
@@loop:
ldr r0,=0x125E
add r0,r0,r5
bl 0x80287B2
beq @@next
add r4,0x1
@@next:
add r5,0x1
cmp r5,0x17
bge @@end
cmp r5,0xD
bne @@loop
mov r5,0xF
b @@loop
@@end:
mov r0,r4
pop r4-r5,r15
@getNumberOfOfficialClears:
push r4-r5,r14
mov r4,0x0
mov r5,0x0
@@loop:
lsl r0,r5,0x1
add r0,0x2
bl 0x80287B2
beq @@next
add r4,0x1
@@next:
add r5,0x1
cmp r5,0x17
bge @@end
cmp r5,0xD
bne @@loop
mov r5,0xF
b @@loop
@@end:
mov r0,r4
pop r4-r5,r15
@unlockAllLibraryIcons:
push r4,r14
mov r4,0x0
mov r0,0x1
mov r1,0xBA
bl @unlockLibraryIconsRange
add r4,r4,r0
mov r0,0xC9
mov r1,0x5A
bl @unlockLibraryIconsRange
add r4,r4,r0
ldr r0,=0x12D
mov r1,0xA
bl @unlockLibraryIconsRange
add r4,r4,r0
tst r4,r4
beq @@end
// Update unlock bytes for all library icons
bl 0x8005E94
// Play SFX
mov r0,0x74
bl 0x8000534
@@end:
pop r4,r15
@unlockLibraryIconsRange:
// r0 = start
// r1 = count
// return r0 = number of icons added
push r4-r6,r14
mov r5,r0 // r0 = start
add r6,r0,r1 // r1 = count
mov r4,0x0 // number of icons added
@@loop:
// Check if end reached
cmp r5,r6
bge @@end
// Check flag
ldr r0,=0x2AC0
add r0,r0,r5
bl 0x80287B2
bne @@next
// Set flag
ldr r0,=0x2AC0
add r0,r0,r5
bl 0x8028722
add r4,0x1
@@next:
add r5,0x1
b @@loop
@@end:
mov r0,r4
pop r4-r6,r15
.pool
@buttons:
.dh 0x200 // L
.dh 0x200 // L
.dh 0x100 // R
.dh 0x200 // L
.dh 0x100 // R
.dh 0x200 // L
.dh 0x100 // R
.dh 0x100 // R
.dh 0x0 // end
|
.global s_prepare_buffers
s_prepare_buffers:
push %r10
push %r13
push %r8
push %rbp
push %rcx
push %rdi
push %rdx
push %rsi
lea addresses_WC_ht+0x3c78, %rsi
lea addresses_D_ht+0x6d8, %rdi
nop
nop
nop
sub %rbp, %rbp
mov $78, %rcx
rep movsl
nop
nop
nop
nop
nop
inc %r13
lea addresses_normal_ht+0x25d6, %r10
nop
nop
nop
inc %rdx
mov (%r10), %cx
nop
nop
dec %rsi
lea addresses_WC_ht+0x1ad8, %rsi
lea addresses_A_ht+0x16098, %rdi
nop
nop
nop
nop
nop
and %r8, %r8
mov $113, %rcx
rep movsq
add %rsi, %rsi
lea addresses_A_ht+0x4ad8, %rsi
lea addresses_A_ht+0xac48, %rdi
nop
nop
sub $52023, %r13
mov $37, %rcx
rep movsw
nop
cmp %rdx, %rdx
lea addresses_D_ht+0x828c, %rcx
nop
and $32171, %r8
mov $0x6162636465666768, %rsi
movq %rsi, (%rcx)
add $65430, %rdi
lea addresses_WC_ht+0x1a5dc, %rsi
lea addresses_WT_ht+0x4718, %rdi
nop
xor $51317, %r8
mov $59, %rcx
rep movsq
xor %r10, %r10
lea addresses_A_ht+0x168d8, %rsi
lea addresses_WC_ht+0x95a8, %rdi
clflush (%rdi)
nop
nop
nop
nop
xor $11476, %r10
mov $117, %rcx
rep movsw
nop
xor %rsi, %rsi
lea addresses_WC_ht+0x2f98, %r10
clflush (%r10)
nop
nop
nop
inc %rdi
mov $0x6162636465666768, %r8
movq %r8, %xmm1
and $0xffffffffffffffc0, %r10
movaps %xmm1, (%r10)
nop
and $56279, %r10
lea addresses_WC_ht+0xa0d8, %rsi
lea addresses_normal_ht+0x15fb8, %rdi
nop
nop
cmp $14069, %r10
mov $81, %rcx
rep movsb
cmp $61656, %r8
pop %rsi
pop %rdx
pop %rdi
pop %rcx
pop %rbp
pop %r8
pop %r13
pop %r10
ret
.global s_faulty_load
s_faulty_load:
push %r10
push %r12
push %r14
push %r8
push %r9
push %rbp
push %rdx
// Store
lea addresses_normal+0x3dc, %r10
dec %rdx
movb $0x51, (%r10)
nop
nop
nop
nop
nop
add %rdx, %rdx
// Store
lea addresses_A+0xc3d8, %r8
nop
sub $61715, %r9
movl $0x51525354, (%r8)
nop
nop
nop
nop
nop
add %rdx, %rdx
// Store
lea addresses_RW+0x17cd8, %r10
nop
sub %r12, %r12
movl $0x51525354, (%r10)
nop
nop
nop
sub %r12, %r12
// Faulty Load
lea addresses_PSE+0x42d8, %r14
nop
nop
xor %r10, %r10
mov (%r14), %bp
lea oracles, %r8
and $0xff, %rbp
shlq $12, %rbp
mov (%r8,%rbp,1), %rbp
pop %rdx
pop %rbp
pop %r9
pop %r8
pop %r14
pop %r12
pop %r10
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'type': 'addresses_PSE', 'AVXalign': False, 'congruent': 0, 'size': 16, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_normal', 'AVXalign': False, 'congruent': 2, 'size': 1, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_A', 'AVXalign': False, 'congruent': 5, 'size': 4, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_RW', 'AVXalign': False, 'congruent': 8, 'size': 4, 'same': False, 'NT': False}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'type': 'addresses_PSE', 'AVXalign': False, 'congruent': 0, 'size': 2, 'same': True, 'NT': True}}
<gen_prepare_buffer>
{'OP': 'REPM', 'src': {'type': 'addresses_WC_ht', 'congruent': 5, 'same': False}, 'dst': {'type': 'addresses_D_ht', 'congruent': 7, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_normal_ht', 'AVXalign': False, 'congruent': 1, 'size': 2, 'same': False, 'NT': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_WC_ht', 'congruent': 10, 'same': False}, 'dst': {'type': 'addresses_A_ht', 'congruent': 5, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_A_ht', 'congruent': 11, 'same': False}, 'dst': {'type': 'addresses_A_ht', 'congruent': 2, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_D_ht', 'AVXalign': False, 'congruent': 1, 'size': 8, 'same': False, 'NT': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_WC_ht', 'congruent': 1, 'same': False}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 6, 'same': True}}
{'OP': 'REPM', 'src': {'type': 'addresses_A_ht', 'congruent': 5, 'same': False}, 'dst': {'type': 'addresses_WC_ht', 'congruent': 4, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WC_ht', 'AVXalign': True, 'congruent': 3, 'size': 16, 'same': False, 'NT': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_WC_ht', 'congruent': 9, 'same': False}, 'dst': {'type': 'addresses_normal_ht', 'congruent': 5, 'same': False}}
{'33': 21829}
33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33
*/
|
.global s_prepare_buffers
s_prepare_buffers:
push %r11
push %r13
push %r15
push %rbx
push %rcx
push %rdi
push %rdx
push %rsi
lea addresses_WC_ht+0x15299, %rdx
nop
nop
nop
nop
sub $39084, %r13
mov $0x6162636465666768, %rbx
movq %rbx, %xmm6
movups %xmm6, (%rdx)
nop
nop
nop
nop
nop
dec %rbx
lea addresses_normal_ht+0x11099, %rsi
lea addresses_A_ht+0xfbb1, %rdi
nop
nop
nop
nop
dec %r11
mov $65, %rcx
rep movsw
nop
nop
cmp $14326, %r11
lea addresses_A_ht+0xd5b9, %rsi
lea addresses_D_ht+0x7344, %rdi
nop
nop
nop
nop
nop
add $47371, %r13
mov $43, %rcx
rep movsw
nop
nop
nop
sub $40208, %rcx
lea addresses_normal_ht+0x1b2a1, %rdi
nop
nop
nop
nop
nop
xor %rsi, %rsi
mov $0x6162636465666768, %r13
movq %r13, (%rdi)
nop
nop
nop
nop
cmp $2084, %rdi
lea addresses_A_ht+0x5b49, %rsi
lea addresses_A_ht+0xc531, %rdi
clflush (%rdi)
sub %r15, %r15
mov $49, %rcx
rep movsl
nop
nop
nop
inc %rbx
lea addresses_normal_ht+0x10c59, %rdx
nop
xor %rdi, %rdi
mov $0x6162636465666768, %r11
movq %r11, %xmm4
and $0xffffffffffffffc0, %rdx
movntdq %xmm4, (%rdx)
nop
xor $29558, %r15
lea addresses_D_ht+0xdded, %rbx
xor %rdx, %rdx
movb (%rbx), %cl
nop
nop
xor $8683, %r13
lea addresses_WT_ht+0x8bf9, %r13
nop
and %rdi, %rdi
vmovups (%r13), %ymm0
vextracti128 $1, %ymm0, %xmm0
vpextrq $1, %xmm0, %r15
nop
nop
nop
nop
sub $40939, %r11
lea addresses_D_ht+0x2499, %rsi
lea addresses_UC_ht+0x1966a, %rdi
nop
nop
nop
sub %r15, %r15
mov $46, %rcx
rep movsq
nop
nop
nop
cmp $19817, %r13
pop %rsi
pop %rdx
pop %rdi
pop %rcx
pop %rbx
pop %r15
pop %r13
pop %r11
ret
.global s_faulty_load
s_faulty_load:
push %r15
push %r8
push %r9
push %rbp
push %rcx
push %rdx
// Store
lea addresses_PSE+0x382d, %rbp
xor $17499, %rdx
mov $0x5152535455565758, %r15
movq %r15, %xmm7
movups %xmm7, (%rbp)
nop
nop
sub $38950, %r15
// Faulty Load
mov $0xc99, %r8
nop
nop
nop
nop
xor $62855, %r15
vmovaps (%r8), %ymm7
vextracti128 $1, %ymm7, %xmm7
vpextrq $1, %xmm7, %rbp
lea oracles, %r15
and $0xff, %rbp
shlq $12, %rbp
mov (%r15,%rbp,1), %rbp
pop %rdx
pop %rcx
pop %rbp
pop %r9
pop %r8
pop %r15
ret
/*
<gen_faulty_load>
[REF]
{'src': {'type': 'addresses_P', 'AVXalign': False, 'size': 8, 'NT': False, 'same': False, 'congruent': 0}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'type': 'addresses_PSE', 'AVXalign': False, 'size': 16, 'NT': False, 'same': False, 'congruent': 2}}
[Faulty Load]
{'src': {'type': 'addresses_P', 'AVXalign': True, 'size': 32, 'NT': False, 'same': True, 'congruent': 0}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'OP': 'STOR', 'dst': {'type': 'addresses_WC_ht', 'AVXalign': False, 'size': 16, 'NT': False, 'same': True, 'congruent': 6}}
{'src': {'type': 'addresses_normal_ht', 'congruent': 10, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_A_ht', 'congruent': 3, 'same': False}}
{'src': {'type': 'addresses_A_ht', 'congruent': 5, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_D_ht', 'congruent': 0, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_normal_ht', 'AVXalign': False, 'size': 8, 'NT': True, 'same': False, 'congruent': 3}}
{'src': {'type': 'addresses_A_ht', 'congruent': 4, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_A_ht', 'congruent': 3, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_normal_ht', 'AVXalign': False, 'size': 16, 'NT': True, 'same': False, 'congruent': 5}}
{'src': {'type': 'addresses_D_ht', 'AVXalign': False, 'size': 1, 'NT': False, 'same': False, 'congruent': 2}, 'OP': 'LOAD'}
{'src': {'type': 'addresses_WT_ht', 'AVXalign': False, 'size': 32, 'NT': False, 'same': False, 'congruent': 5}, 'OP': 'LOAD'}
{'src': {'type': 'addresses_D_ht', 'congruent': 8, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_UC_ht', 'congruent': 0, 'same': False}}
{'44': 4920, '72': 1, '46': 16820, '45': 60, '49': 28}
46 46 46 46 44 46 44 46 46 46 46 46 46 46 46 46 44 46 46 46 44 46 46 46 46 44 46 46 46 46 44 46 46 46 46 44 46 44 46 46 46 46 46 44 46 46 46 46 44 46 46 46 46 46 46 44 46 46 46 46 46 46 46 46 46 46 46 46 44 44 46 46 46 46 46 46 44 46 46 46 46 46 46 46 44 46 46 46 44 46 46 44 46 46 46 46 44 46 46 46 46 44 46 44 46 46 44 44 46 46 46 44 46 46 46 44 46 46 46 46 46 46 46 46 44 46 46 46 46 46 44 44 46 44 46 46 46 44 46 44 46 46 44 44 46 46 46 44 46 46 46 46 46 46 46 44 46 46 46 46 46 46 44 46 44 46 44 46 44 46 46 44 46 44 46 44 46 46 46 46 46 44 46 46 44 44 46 46 46 46 46 46 44 46 46 46 44 46 46 46 46 46 44 46 46 46 46 46 46 44 46 44 46 46 46 46 46 44 46 46 46 46 44 46 44 46 46 44 46 46 46 44 46 46 46 46 44 46 46 46 46 44 46 46 46 46 44 46 46 46 44 44 46 46 44 46 46 46 46 44 46 46 46 46 44 44 46 46 44 46 46 44 46 46 44 46 46 46 44 46 46 44 46 46 46 46 44 46 46 46 46 44 46 46 46 46 46 44 46 46 46 44 46 46 46 44 46 44 46 46 46 46 46 46 44 46 46 46 46 44 46 46 46 44 46 46 44 46 44 46 46 46 44 46 46 44 46 46 44 46 44 46 46 46 46 44 46 46 46 46 44 46 46 46 46 46 44 46 46 46 44 46 44 46 46 44 46 44 46 46 44 46 46 46 46 46 46 46 46 46 46 46 44 46 46 46 46 46 46 46 46 46 46 46 44 46 46 46 46 46 46 46 46 46 46 44 46 46 44 46 46 46 46 46 44 46 46 44 46 44 46 46 46 44 46 46 46 46 46 46 46 46 46 46 46 44 46 46 46 46 44 46 46 44 46 46 46 46 46 44 44 46 46 46 44 46 44 46 46 46 46 46 44 44 46 44 46 46 46 46 46 44 46 44 44 46 46 46 46 46 46 44 46 46 46 46 46 46 46 46 46 46 46 46 44 44 46 46 46 46 46 46 46 46 46 46 44 46 44 46 46 46 46 46 44 46 46 44 46 46 44 46 44 46 46 46 46 46 46 44 46 44 46 46 46 44 46 46 46 46 46 46 44 46 46 44 46 46 46 46 46 44 46 46 46 46 46 44 46 46 46 44 46 46 46 46 44 46 46 46 44 46 46 46 46 46 46 46 44 46 46 44 44 44 46 46 46 44 46 44 44 46 44 46 46 46 46 46 46 46 44 46 46 46 46 46 46 44 46 44 46 46 46 46 46 46 46 46 46 44 46 46 46 46 46 46 46 46 44 46 46 44 46 46 46 44 46 46 46 44 46 44 46 46 46 44 46 46 46 45 44 46 46 46 44 46 46 46 46 46 46 46 46 44 46 46 44 46 46 44 46 44 46 46 44 46 46 46 46 44 46 46 46 46 44 46 46 46 44 46 46 44 46 46 44 46 46 46 46 44 46 46 46 46 46 46 44 46 44 46 44 46 46 46 46 46 46 46 44 46 44 46 46 46 44 46 46 46 46 46 46 46 46 44 46 46 46 46 46 46 46 46 44 46 44 46 44 44 46 46 46 46 44 46 46 46 46 44 46 46 46 44 46 46 46 46 46 44 46 46 44 46 46 46 46 44 46 46 46 44 46 46 46 46 44 46 46 46 44 44 46 46 46 46 44 46 46 46 46 46 46 46 44 46 46 44 46 46 46 46 46 46 46 46 46 46 44 46 46 46 44 46 46 46 46 44 46 46 46 46 46 44 46 46 46 44 44 46 46 44 46 46 46 46 46 46 46 44 46 46 46 46 44 46 44 46 46 46 46 46 46 46 46 44 46 46 46 44 46 46 46 44 46 46 46 46 44 46 46 46 46 46 46 44 44 46 46 46 44 46 44 46 46 46 46 46 46 46 46 44 46 46 46 46 46 46 46 44 46 46 46 46 46 46 46 44 46 46 46 44 46 46 46 44 46 44 46 46 46 46 46 46 44 46 46 46 46 46 44 46 46 46 46 46 46 44 46 46 46 46 44 46 46 44 46 46 46 44 46 44 44 46 46 46 46 44 46 44 46 44 46 46 46 46 46 46 46 46 44 46 46 46 46 46 46 46 46 46 46 46 46 46 44 46 44 44 46 46 46 44
*/
|
;
; Copyright (c) 2006-2008 Advanced Micro Devices,Inc. ("AMD").
;
; This library is free software; you can redistribute it and/or modify
; it under the terms of the GNU Lesser General Public License as
; published by the Free Software Foundation; either version 2.1 of the
; License, or (at your option) any later version.
;
; This code 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 this library; if not, write to the
; Free Software Foundation, Inc., 59 Temple Place, Suite 330,
; Boston, MA 02111-1307 USA
;
;* Function: *
;* This file implements the SYS_GET_NEXT_MSG & SYS_REGISTER_EVENT *
;* macros as well as the code to perform a system call.
include sysmgr.inc
include smimac.mac
include vsa2.inc
.model tiny,c
.586p
.CODE
public Async_VSM
Async_VSM dd 0
;***********************************************************************
; USHORT sys_get_next_msg(ULONG *)
;
; This routine retrieves a message packet from a VSM's message queue.
;
; Input:
; MsgPacket = ptr to message packet (relative to DS)
; Returns:
; Message code
;***********************************************************************
sys_get_next_msg proc uses si di \
MsgPacket: PTR
CheckMsgQ:
xor di, di
ASSUME di: PTR VSM_Header
mov si, [di].SysStuff.Qtail ; Is the message queue empty ?
cmp si, [di].SysStuff.Qhead
jne MessageIsWaiting
mov ax, SYS_CODE_EXIT ; Return to the System Manager
smint
; Returns here when there are message(s) pending for this VSM.
jmp short CheckMsgQ
MessageIsWaiting:
ASSUME si: PTR Message
lea di, [si+sizeof(Message)]
mov dx, [si].Msg ; Get the message code
mov eax, [si].From_VSM ; Get VSM message is from
mov [Async_VSM], eax
; Copy message packet into caller's buffer
cld
lea si, [si].Param
mov cx, MAX_MSG_PARAM
mov bx, [MsgPacket] ; Get ptr to message buffer
CopyMsg:
lodsd
mov [bx], eax
add bx, 4
loop CopyMsg
;
; Advance the message queue ptr
;
mov si, OFFSET VSM_Header.SysStuff
ASSUME si: PTR System
cmp di, [si].EndMsgQ ; Is Qtail at end ?
jb UpdateQtail
lea di, [si].MsgQueue ; Yes, wrap ptr to start of queue
UpdateQtail:
mov [si].Qtail, di
; Return value of function is the message code
mov ax, dx
Exit: ret
ASSUME si:NOTHING
sys_get_next_msg endp
;***********************************************************************
; USHORT sys_query_msg_queue(ULONG *)
;
; This routine queries the VSM's message queue
;
; Input:
; If a message is present:
; MsgPacket = ptr to message packet (relative to DS)
; Returns:
; If a message is present:
; Message code
; Else
; 0xFFFF
;***********************************************************************
sys_query_msg_queue proc uses si \
MsgPacket: PTR
xor bx, bx
ASSUME bx: PTR VSM_Header
mov si, [bx].SysStuff.Qtail ; Is the message queue empty ?
cmp si, [bx].SysStuff.Qhead
mov ax, 0FFFFh ; Return value if queue is empty
je short Exit
ASSUME si: PTR Message
mov dx, [si].Msg ; Get the message code
; Copy message packet into caller's buffer
cld
lea si, [si].Param
mov cx, MAX_MSG_PARAM
mov bx, [MsgPacket] ; Get ptr to message buffer
CopyMsg:
lodsd
mov dword ptr [bx], eax
add bx, 4
loop CopyMsg
; NOTE: Qtail is not advanced !!
; Return value of function is the message code
mov ax, dx
Exit: ret
sys_query_msg_queue endp
;***********************************************************************
; Registers this VSM as a handler for an event
;***********************************************************************
sys_register_event proc pascal uses edi \
Event: EVENT, \
Param1: DWORD, \
Param2: DWORD, \
Priority: WORD
mov bx, [Event] ; Get event to register
shl ebx, 16
mov bx, [Priority] ; Get event priority
mov ecx, [Param1] ; Get parameters
mov edi, [Param2]
mov ax, SYS_CODE_EVENT
call sys_system_call
ret
sys_register_event endp
;***********************************************************************
; Performs a system call
;***********************************************************************
sys_system_call proc
smint
ret
sys_system_call endp
END
|
#include <iostream>
#include "core/measurements.h"
#include "core/properties.h"
using namespace ycsbc;
void test_OneMeasurementRaw() {
utils::Properties p;
p.SetProperty("measurement.raw.output_file", "measurement_raw_output");
OneMeasurementRaw m("test_OneMeasurementRaw", p);
TextMeasurementsExporter exporter;
for (int i = 0; i < 100; i++)
m.measure(i);
std::cout << "OneMeasurementRaw get_summary" << std::endl;
std::cout << m.get_summary() << std::endl << std::endl;
m.export_measurements(&exporter);
// std::cout << exporter.buf() << std::endl;
}
void test_OneMeasurementHistogram() {
utils::Properties p;
p.SetProperty("measurement.histogram.verbose", "true");
OneMeasurementHistogram m("test_OneMeasurementHistogram", p);
TextMeasurementsExporter exporter;
for (int i = 0; i < 100; i++)
m.measure(i);
std::cout << "OneMeasurementHistogram get_summary" << std::endl;
std::cout << m.get_summary() << std::endl << std::endl;
m.export_measurements(&exporter);
std::cout << exporter.buf() << std::endl;
}
void test_OneMeasurementHdrHistogram() {
utils::Properties p;
p.SetProperty("measurement.histogram.verbose", "true");
p.SetProperty("hdrhistogram.fileoutput", "true");
p.SetProperty("hdrhistogram.output.path", "./");
OneMeasurementHdrHistogram m("test_OneMeasurementHdrHistogram", p);
TextMeasurementsExporter exporter;
for (int i = 0; i < 100; i++)
m.measure(i);
std::cout << "OneMeasurementHdrHistogram get_summary" << std::endl;
std::cout << m.get_summary() << std::endl << std::endl;
m.export_measurements(&exporter);
std::cout << exporter.buf() << std::endl;
}
void test_Measurements() {
utils::Properties p;
p.SetProperty("measurement.histogram.verbose", "true");
p.SetProperty("hdrhistogram.fileoutput", "true");
p.SetProperty("hdrhistogram.output.path", "./");
Measurements::set_properties(p);
Measurements& m = Measurements::get_measurements();
TextMeasurementsExporter exporter;
for (int i = 0; i < 100; i++)
m.measure("alec", i);
std::cout << "Measurements get_summary" << std::endl;
std::cout << m.get_summary() << std::endl << std::endl;
m.export_measurements(&exporter);
std::cout << exporter.buf() << std::endl;
}
int main() {
test_OneMeasurementRaw();
test_OneMeasurementHistogram();
test_OneMeasurementHdrHistogram();
test_Measurements();
} |
#include <rleahylib/rleahylib.hpp>
#include <client.hpp>
#include <hash.hpp>
#include <mod.hpp>
#include <packet.hpp>
#include <server.hpp>
#include <limits>
#include <unordered_map>
#include <utility>
using namespace MCPP;
// The frequency with which every player's
// list is updated to propagate ping changes
// et cetera
static const Word update_freq=30000;
static const String name("Player List Support");
static const Word priority=1;
class PlayerList : public Module {
private:
typedef Packets::Play::Clientbound::PlayerListItem packet_type;
std::unordered_map<
SmartPointer<Client>,
// This boolean value indicates
// whether disconnect processing
// has occurred
bool
> map;
Mutex lock;
typedef decltype(packet_type::Ping) ping_type;
static ping_type get_ping (Word ping) noexcept {
constexpr auto ping_max=std::numeric_limits<ping_type>::max();
return (ping>ping_max) ? ping_max : static_cast<ping_type>(ping);
}
static packet_type get_packet (const SmartPointer<Client> & client, bool online) {
packet_type retr;
retr.Name=client->GetUsername();
retr.Online=online;
retr.Ping=get_ping(client->Ping);
return retr;
}
Vector<packet_type> get_packets () {
Vector<packet_type> retr(map.size());
for (auto & pair : map) if (!pair.second) retr.Add(
get_packet(
pair.first,
true
)
);
return retr;
}
void login (SmartPointer<Client> client) {
lock.Execute([&] () mutable {
// Attempt to find this client
// in the map
auto loc=map.find(client);
// If there's an entry, it means
// that disconnect processing has occurred,
// delete and return
if (loc!=map.end()) {
map.erase(loc);
return;
}
// Otherwise disconnect processing has not
// occurred, and we may proceed
// Send a full update to this connecting
// client
for (auto & packet : get_packets()) client->Send(packet);
// Insert an entry specifying that disconnect
// processing has not occurred
map.emplace(
client,
false
);
// Send packet to all connected clients
// who are in the correct state
auto packet=get_packet(client,true);
for (auto & c : Server::Get().Clients) if (c->GetState()==ProtocolState::Play) c->Send(packet);
});
}
void disconnect (SmartPointer<Client> client) {
lock.Execute([&] () mutable {
// Attempt to find this client in the
// map
auto loc=map.find(client);
// If there's no entry, this means that
// no client has been notified that this
// client ever connected/was online, and
// therefore we simply add an entry and
// proceed without sending packets
if (loc==map.end()) {
map.emplace(
client,
true
);
return;
}
// Remove the player's entry -- they're
// disconnected
map.erase(loc);
// Otherwise we send a packet to all connected
// clients notifying them
auto packet=get_packet(client,false);
for (auto & c : Server::Get().Clients) if (
(c!=client) &&
(c->GetState()==ProtocolState::Play)
) c->Send(packet);
});
}
void periodic () {
auto & server=Server::Get();
lock.Execute([&] () mutable {
auto packets=get_packets();
// Loop over all connected clients in the
// Play state and send them these packets
for (auto & c : server.Clients)
if (c->GetState()==ProtocolState::Play)
for (auto & packet : packets) c->Send(packet);
});
// Execute the task again after a delay
server.Pool().Enqueue(
update_freq,
[this] () mutable { periodic(); }
);
}
public:
virtual const String & Name () const noexcept override {
return name;
}
virtual Word Priority () const noexcept override {
return priority;
}
virtual void Install () override {
auto & server=Server::Get();
server.OnLogin.Add([this] (SmartPointer<Client> client) mutable { login(std::move(client)); });
server.OnDisconnect.Add([this] (SmartPointer<Client> client, const String &) mutable { disconnect(std::move(client)); });
server.Pool().Enqueue(
update_freq,
[this] () mutable { periodic(); }
);
}
};
INSTALL_MODULE(PlayerList)
|
// --------------------------------------------------------------------------
// OpenMS -- Open-Source Mass Spectrometry
// --------------------------------------------------------------------------
// Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
// ETH Zurich, and Freie Universitaet Berlin 2002-2020.
//
// This software is released under a three-clause BSD license:
// * 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 any author or any participating institution
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
// For a full list of authors, refer to the file AUTHORS.
// --------------------------------------------------------------------------
// 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 ANY OF THE AUTHORS OR THE CONTRIBUTING
// INSTITUTIONS 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.
//
// --------------------------------------------------------------------------
// $Maintainer: Timo Sachsenberg $
// $Authors: Eva Lange $
// --------------------------------------------------------------------------
#include <OpenMS/FORMAT/MzMLFile.h>
#include <OpenMS/KERNEL/MSExperiment.h>
#include <OpenMS/TRANSFORMATIONS/RAW2PEAK/PeakPickerCWT.h>
#include <OpenMS/APPLICATIONS/TOPPBase.h>
#include <OpenMS/CONCEPT/LogStream.h>
using namespace OpenMS;
using namespace std;
//-------------------------------------------------------------
//Doxygen docu
//-------------------------------------------------------------
/**
@page TOPP_PeakPickerWavelet PeakPickerWavelet
@brief A tool for peak detection in profile data. Executes the peak picking with the algorithm described in described in Lange et al. (2006) Proc. PSB-06.
<CENTER>
<table>
<tr>
<td ALIGN = "center" BGCOLOR="#EBEBEB"> pot. predecessor tools </td>
<td VALIGN="middle" ROWSPAN=4> \f$ \longrightarrow \f$ PeakPickerWavelet \f$ \longrightarrow \f$</td>
<td ALIGN = "center" BGCOLOR="#EBEBEB"> pot. successor tools </td>
</tr>
<tr>
<td VALIGN="middle" ALIGN = "center" ROWSPAN=1> @ref TOPP_BaselineFilter </td>
<td VALIGN="middle" ALIGN = "center" ROWSPAN=3> any tool operating on MS peak data @n (in mzML format)</td>
</tr>
<tr>
<td VALIGN="middle" ALIGN = "center" ROWSPAN=1> @ref TOPP_NoiseFilterGaussian </td>
</tr>
<tr>
<td VALIGN="middle" ALIGN = "center" ROWSPAN=1> @ref TOPP_NoiseFilterSGolay </td>
</tr>
</table>
</CENTER>
The conversion of the ''raw'' ion count data acquired
by the machine into peak lists for further processing
is usually called peak picking. The choice of the algorithm
should mainly depend on the resolution of the data.
As the name implies, the @ref OpenMS::PeakPickerHiRes "high_res"
algorithm is fit for high resolution data whereas in case
of low-resoluted data the @ref OpenMS::PeakPickerCWT "wavelet"
algorithm offers the ability to resolve highly convoluted
and asymmetric signals, separation of overlapping peaks
and nonlinear optimization.
@ref TOPP_example_signalprocessing_parameters is explained in the TOPP tutorial.
<B>The command line parameters of this tool are:</B>
@verbinclude TOPP_PeakPickerWavelet.cli
<B>INI file documentation of this tool:</B>
@htmlinclude TOPP_PeakPickerWavelet.html
For the parameters of the algorithm section see the algorithm documentation: @n
@ref OpenMS::PeakPickerCWT "PeakPickerCWT" @n
In the following table you, can find example values of the most important algorithm parameters for
different instrument types. @n These parameters are not valid for all instruments of that type,
but can be used as a starting point for finding suitable parameters.
<table>
<tr BGCOLOR="#EBEBEB">
<td> </td>
<td><b>Q-TOF</b></td>
<td><b>LTQ Orbitrap</b></td>
</tr>
<tr>
<td BGCOLOR="#EBEBEB"><b>signal_to_noise</b></td>
<td>2</td>
<td>0</td>
</tr>
<tr>
<td BGCOLOR="#EBEBEB"><b>peak_width ("wavelet" only)</b></td>
<td>0.1</td>
<td>0.012</td>
</tr>
</table>
In order to impove the results of the peak detection on low resolution data @ref TOPP_NoiseFilterSGolay or @ref TOPP_NoiseFilterGaussian and @ref TOPP_BaselineFilter can be applied.
For high resolution data this is not necessary.
*/
// We do not want this class to show up in the docu:
/// @cond TOPPCLASSES
class TOPPPeakPickerWavelet :
public TOPPBase
{
public:
TOPPPeakPickerWavelet() :
TOPPBase("PeakPickerWavelet", "Finds mass spectrometric peaks in profile mass spectra.")
{
}
protected:
void registerOptionsAndFlags_() override
{
registerInputFile_("in", "<file>", "", "input profile data file ");
setValidFormats_("in", ListUtils::create<String>("mzML"));
registerOutputFile_("out", "<file>", "", "output peak file ");
setValidFormats_("out", ListUtils::create<String>("mzML"));
registerFlag_("write_peak_meta_data", "Write additional information about the picked peaks (maximal intensity, left and right area...) into the mzML-file. Attention: this can blow up files, since seven arrays are stored per spectrum!", true);
registerSubsection_("algorithm", "Algorithm parameters section");
}
Param getSubsectionDefaults_(const String & /*section*/) const override
{
return PeakPickerCWT().getDefaults();
}
ExitCodes main_(int, const char **) override
{
//-------------------------------------------------------------
// parameter handling
//-------------------------------------------------------------
String in = getStringOption_("in");
String out = getStringOption_("out");
bool write_meta_data_arrays(getFlag_("write_peak_meta_data"));
//-------------------------------------------------------------
// loading input
//-------------------------------------------------------------
MzMLFile mz_data_file;
mz_data_file.setLogType(log_type_);
PeakMap ms_exp_raw;
mz_data_file.load(in, ms_exp_raw);
if (ms_exp_raw.empty())
{
OPENMS_LOG_WARN << "The given file does not contain any conventional peak data, but might"
" contain chromatograms. This tool currently cannot handle them, sorry.";
return INCOMPATIBLE_INPUT_DATA;
}
// check for peak type (profile data required)
if (ms_exp_raw[0].getType(true) == SpectrumSettings::CENTROID)
{
writeLog_("Warning: OpenMS peak type estimation indicates that this is not profile data!");
}
//check if spectra are sorted
for (Size i = 0; i < ms_exp_raw.size(); ++i)
{
if (!ms_exp_raw[i].isSorted())
{
writeLog_("Error: Not all spectra are sorted according to peak m/z positions. Use FileFilter to sort the input!");
return INCOMPATIBLE_INPUT_DATA;
}
}
//-------------------------------------------------------------
// pick
//-------------------------------------------------------------
PeakMap ms_exp_peaks;
Param pepi_param = getParam_().copy("algorithm:", true);
writeDebug_("Parameters passed to PeakPickerWavelet", pepi_param, 3);
PeakPickerCWT pp;
pp.setLogType(log_type_);
pp.setParameters(pepi_param);
try
{
pp.pickExperiment(ms_exp_raw, ms_exp_peaks);
}
catch (Exception::BaseException & e)
{
OPENMS_LOG_ERROR << "Exception caught: " << e.what() << "\n";
return INTERNAL_ERROR;
}
if (!write_meta_data_arrays)
{
for (Size i = 0; i < ms_exp_peaks.size(); ++i)
{
ms_exp_peaks[i].getFloatDataArrays().clear();
}
}
//-------------------------------------------------------------
// writing output
//-------------------------------------------------------------
//annotate output with data processing info
addDataProcessing_(ms_exp_peaks, getProcessingInfo_(DataProcessing::PEAK_PICKING));
mz_data_file.store(out, ms_exp_peaks);
return EXECUTION_OK;
}
};
int main(int argc, const char ** argv)
{
TOPPPeakPickerWavelet tool;
return tool.main(argc, argv);
}
/// @endcond
|
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/04/Mult.asm
// Multiplies R0 and R1 and stores the result in R2.
// (R0, R1, R2 refer to RAM[0], RAM[1], and RAM[2], respectively.)
@2
M=0 // R2 = 0
@i
M=0 // i=0
(LOOP)
@i
D=M // D=i
@0
D=D-M // D=i-R0
@END
D;JGE // if i-R0 >= 0 goto END
@1
D=M // D=R1
@2
M=D+M // R2=R2+R1
@i
M=M+1 // i=i+1
@LOOP
0;JMP // Repeat
(END)
@END
0;JMP |
; A032169: Number of aperiodic necklaces of n beads of 2 colors, 11 of them black.
; 1,6,26,91,273,728,1768,3978,8398,16796,32065,58786,104006,178296,297160,482885,766935,1193010,1820910,2731365,4032015,5864749,8414640,11920740,16689036,23107896,31666376,42975796
add $0,11
mov $2,10
mov $3,$0
lpb $0,1
mov $0,7
mov $1,$3
bin $1,$2
mul $1,6
div $1,11
lpe
mul $1,2
sub $1,12
div $1,12
add $1,1
|
; $Id: beeper_mwr.asm,v 1.5 2016-06-11 20:52:25 dom Exp $
;
; 1 bit sound library - version for "memory write" I/O architectures
; by Stefano Bodrato, 31/03/08
;
; ZX Spectrum-like call:
; HL=duration
; DE=frequency
;
IF !__CPU_GBZ80__ && !__CPU_INTEL__
SECTION code_clib
PUBLIC beeper
PUBLIC _beeper
INCLUDE "games/games.inc"
EXTERN __snd_tick
EXTERN bit_open_di
EXTERN bit_close_ei
.beeper
._beeper
push ix
ld a,l
srl l
srl l
cpl
and 3
ld c,a
ld b,0
ld ix,beixp3
add ix,bc
call bit_open_di
.beixp3
nop
nop
nop
inc b
inc c
.behllp dec c
jr nz,behllp
ld c,$3F
dec b
jp nz,behllp
xor sndbit_mask
ld (sndbit_port),a ; This is three cycles slower tha the OUT based version
ld b,h
ld c,a
bit sndbit_bit,a ;if o/p go again!
jr nz,be_again
ld a,d
or e
jr z,be_end
ld a,c
ld c,l
dec de
jp (ix)
.be_again
ld c,l
inc c
jp (ix)
.be_end
call bit_close_ei
pop ix
ret
ENDIF
|
#include "dataio.h"
Eigen::Map<Eigen::MatrixXd> DataIO::readPointFile(std::string fileName, double *data /* = nullptr */)
{
std::ifstream fin(fileName, std::ios::in|std::ios::binary);
// Check for existance for file
if (!fin)
throw std::runtime_error("File not found : " + fileName);
// Read the header for number of points, dimensions
unsigned temp = 0;
unsigned numPoints = 0;
unsigned numDims = 0;
fin.read((char *)&temp, sizeof(unsigned));
//if (temp != version)
// throw std::runtime_error("Dataset version incorrect!");
fin.read((char *)&numDims, sizeof(unsigned));
fin.read((char *)&numPoints, sizeof(unsigned));
// Printing for debugging
// std::cout << "\nNumber of points: " << numPoints << "\nNumber of dims : " << numDims << std::endl;
// allocate memory
if (data == nullptr)
data = new double[numDims*numPoints];
// Read the points
fin.read((char *)(data), sizeof(double)*numPoints*numDims);
// Close the file
fin.close();
// Matrix of points
Eigen::Map<Eigen::MatrixXd> pointMatrix(data, numDims, numPoints);
// std::cout<<"IsRowMajor?: "<<pointMatrix.IsRowMajor << std::endl;
//
// std::cout<<pointMatrix.rows() << " " << pointMatrix.cols() << std::endl;
// std::cout<<pointMatrix(0,0) << " " << pointMatrix(0,1) << " " << pointMatrix(1,0) << std::endl;
return pointMatrix;
}
std::vector<std::string> DataIO::read_wordmap(std::string wordmapfile)
{
std::string temp;
std::ifstream fin(wordmapfile);
if (!fin)
throw std::runtime_error( "Error: Unable to read the file: " + wordmapfile );
std::vector<std::string> word_map;
while (std::getline(fin, temp))
word_map.push_back(temp);
fin.close();
return word_map;
}
int DataIO::document::write(std::ofstream& fout) const
{
if (!fout)
throw std::runtime_error("Cannot open to write!");
unsigned M = (unsigned)_size;
fout.write((char *)&M, sizeof(unsigned));
fout.write((char *)(words), sizeof(unsigned)*_size);
return 0;
}
int DataIO::document::read(std::ifstream& fin)
{
if (!fin)
throw std::runtime_error("Dataset not found!");
unsigned M;
fin.read((char *)&M, sizeof(unsigned));
_size = M;
// free existing memory
if(words) delete[] words;
words = new unsigned[_size];
fin.read((char *)(words), sizeof(unsigned)*_size);
return 0;
}
int DataIO::corpus::read_data(std::string dfile, std::map<std::string, unsigned> * pword2id, std::set<std::string> * stopwords)
{
std::ifstream fin(dfile);
if (!fin)
{
std::cout << "Error: Invalid data file" << std::endl;
throw std::runtime_error("Error: Invalid data file: " + dfile);
}
// if (pword2id == nullptr)
// pword2id = new std::map<std::string, unsigned>;
if (stopwords == nullptr)
stopwords = new std::set<std::string>;
std::cout << "Size of stopwords: " << stopwords->size() << std::endl;
// free existing memory
if(docs)
delete[] docs;
std::string line;
// retrieve the number of documents in dataset
std::getline(fin, line);
try{
_size = std::stoi(line);
}catch (std::exception& e)
{
//std::cout << "While trying to read number of lines, encountered exception: ";
//std::cout << e.what() << std::endl;
//std::cout << "Trying to estimate number of lines via brute force ..." << std::endl;
_size = 1;
while ( std::getline(fin, line) )
++_size;
fin.close();
fin.open(dfile);
}
//std::cout << "Num documents found: " << _size << std::endl;
if (_size <= 0)
throw std::runtime_error( "Error: Empty corpus!" );
// allocate memory for corpus
docs = new DataIO::document[_size];
unsigned temp_words[100000];
std::map<std::string, unsigned>::iterator it;
for (size_t i = 0; i < _size; ++i)
{
//progressbar
if ( (i % (_size/10+1) == 0) && _size>10000 )
{
const unsigned w = 50;
double ratio = i/(double)_size;
unsigned c = unsigned(ratio * w);
std::cerr << std::setw(3) << (int)(ratio*100) << "% [";
for (unsigned x=0; x<c; x++) std::cerr << "=";
for (unsigned x=c; x<w; x++) std::cerr << " ";
std::cerr << "]\r" << std::flush;
}
std::getline(fin, line);
StringTokenizer strtok(line);
unsigned length = strtok.count_tokens();
if (length <= 0)
std::runtime_error("Error: Invalid document object! " + i);
unsigned js = 0;
for (unsigned j = 0; j < length; ++j)
{
std::string key = strtok.nextToken();
//std::cout << j << ", " << key << std::endl;
if(stopwords->count(key))
continue;
it = pword2id->lower_bound(key);
if (it == pword2id->end() || key < it->first)
{
// word not found, i.e., new word
temp_words[js] = (unsigned) pword2id->size();
pword2id->insert(it, std::map<std::string, unsigned>::value_type(key, (unsigned)pword2id->size()));
}
else
{
// Give the word current id
temp_words[js] = it->second;
}
++js;
}
// add new doc to the corpus
docs[i].reassign(temp_words, temp_words + js);
}
if ( _size>10000 )
{
std::cerr << std::setw(3) << (int)(100) << "% [";
for (unsigned x=0; x<50; x++) std::cerr << "=";
std::cerr << "]" << std::endl;
}
fin.close();
return 0;
}
int DataIO::corpus::write(std::ofstream& fout) const
{
if (!fout)
throw std::runtime_error("Cannot open to write!");
unsigned M = (unsigned)_size;
fout.write((char *)&version, sizeof(int));
fout.write((char *)&M, sizeof(unsigned));
for(const auto& d : *this)
d.write(fout);
return 0;
}
int DataIO::corpus::read(std::ifstream& fin)
{
int temp;
if (!fin)
throw std::runtime_error("Dataset not found!");
fin.read((char *)&temp, sizeof(int));
if (temp != version)
throw std::runtime_error("Dataset version incorrect!");
// free existing memory
if(docs)
delete[] docs;
unsigned M;
fin.read((char *)&M, sizeof(unsigned));
_size = M;
// allocate memory for corpus
docs = new DataIO::document[_size];
for (auto& d : *this)
d.read(fin);
return 0;
}
|
; inner error
#ruledef
{
emit {x} => x / 0
test {x} => asm { emit x }
}
test 12 ; error: failed / error:_:4: zero |
#note: r40 (the exception handler) and r46 (the start of usermode code) must
#be specified in hex (0xwhatever)
#I just don't see any reason not to, and it makes programming the script
#much nicer to deal with...
#load exception handler
lc r40, 0x80000050
leh r40
#enable exceptions
cle
#load TLB entries
#virtual page 0 is for instructions
#virtual page 1 is for data
lc r46, 0x0000005c #usermode start address
lc r47, 1 #interrupts off
lc r48, 1 #in user mode
lc r42, 0x00000000 #denotes VPN 0
lc r43, 0x0000000d #denotes VPN 0 maps to physical page 0
#and is fetchable, readable, and valid
tlbse r0, r42 #load into entry 0
lc r42, 0x00001000 #denotes VPN 1
lc r43, 0x0000101e #denotes VPN 1 maps to physical page 1
#and is readable, writable, valid, and dirty
#(dirty to prevent taking a
#read-only exception)
tlbse r48, r42 #load into entry 1
#this last tlb entry is designed to produce a bus error
lc r44, 2 #load into TLB entry 2
lc r42, 0x3fffe000 #denotes VPN 0x3fffe
lc r43, 0x3fffe01f #map VPN 0x3fffe to page 0x3fffe
#and is readable, writable, valid, and dirty
#(dirty to prevent taking a
#read-only exception)
tlbse r44, r42
#warp to user mode
rfe r46, r47, r48
#handle exceptions
lc r49, 0xdeadbeef
halt #or rather don't =)
lc r30, 1
jnz r30, r30, k2
trap
#@expected values
#e3 = 0x000000a0
#mode = S
#interrupts = off
#exceptions = off
#r40 = 0x80000050
#r46 = 0x0000005c
#r47 = 1
#r48 = 1
#r42 = 0x3fffe000
#r43 = 0x3fffe01f
#r44 = 2
#r49 = 0xdeadbeef
#pc = 0x8000005c
#e0 = 0x00000060
#e2 = 0x00000060
#e1 = 0x00000001
#tlb 0:
# vpn = 0x00000
# os = 0x000
# ppn = 0x00000
# at = 0x00d
#tlb 1:
# vpn = 0x00001
# os = 0x000
# ppn = 0x00001
# at = 0x01e
#tlb 2:
# vpn = 0x3fffe
# os = 0x000
# ppn = 0x3fffe
# at = 0x01f
|
; Characteristics of each move.
move: MACRO
; the animation byte will be filled when the move is loaded
db \1 ; effect
db \2 ; power
db \3 ; type
db \4 percent ; accuracy
db \5 ; pp
db \6 percent ; effect chance
ENDM
Moves::
; entries correspond to constants/move_constants.asm
indirect_table MOVE_LENGTH - 1, 1
indirect_entries NUM_ATTACKS, Moves1
indirect_table_end
Moves1:
move EFFECT_NORMAL_HIT, 40, NORMAL, 100, 35, 0 ;POUND
move EFFECT_NORMAL_HIT, 50, FIGHTING, 100, 25, 0 ;KARATE_CHOP
move EFFECT_MULTI_HIT, 15, NORMAL, 85, 10, 0 ;DOUBLESLAP
move EFFECT_MULTI_HIT, 18, NORMAL, 85, 15, 0 ;COMET_PUNCH
move EFFECT_NORMAL_HIT, 80, NORMAL, 85, 20, 0 ;MEGA_PUNCH
move EFFECT_PAY_DAY, 40, NORMAL, 100, 20, 0 ;PAY_DAY
move EFFECT_BURN_HIT, 75, FIRE, 100, 15, 10 ;FIRE_PUNCH
move EFFECT_FREEZE_HIT, 75, ICE, 100, 15, 10 ;ICE_PUNCH
move EFFECT_PARALYZE_HIT, 75, ELECTRIC, 100, 15, 10 ;THUNDERPUNCH
move EFFECT_NORMAL_HIT, 40, NORMAL, 100, 35, 0 ;SCRATCH
move EFFECT_NORMAL_HIT, 55, NORMAL, 100, 30, 0 ;VICEGRIP
move EFFECT_OHKO, 0, NORMAL, 30, 5, 0 ;GUILLOTINE
move EFFECT_RAZOR_WIND, 80, NORMAL, 75, 10, 0 ;RAZOR_WIND
move EFFECT_ATTACK_UP_2, 0, NORMAL, 100, 30, 0 ;SWORDS_DANCE
move EFFECT_NORMAL_HIT, 50, NORMAL, 95, 30, 0 ;CUT
move EFFECT_GUST, 40, FLYING, 100, 35, 0 ;GUST
move EFFECT_NORMAL_HIT, 60, FLYING, 100, 35, 0 ;WING_ATTACK
move EFFECT_FORCE_SWITCH, 0, NORMAL, 100, 20, 0 ;WHIRLWIND
move EFFECT_FLY, 70, FLYING, 95, 15, 0 ;FLY
move EFFECT_TRAP_TARGET, 15, NORMAL, 75, 20, 0 ;BIND
move EFFECT_NORMAL_HIT, 80, NORMAL, 75, 20, 0 ;SLAM
move EFFECT_NORMAL_HIT, 35, GRASS, 100, 10, 0 ;VINE_WHIP
move EFFECT_STOMP, 65, NORMAL, 100, 20, 30 ;STOMP
move EFFECT_DOUBLE_HIT, 30, FIGHTING, 100, 30, 0 ;DOUBLE_KICK
move EFFECT_NORMAL_HIT, 120, NORMAL, 75, 5, 0 ;MEGA_KICK
move EFFECT_JUMP_KICK, 70, FIGHTING, 95, 25, 0 ;JUMP_KICK
move EFFECT_FLINCH_HIT, 60, FIGHTING, 85, 15, 30 ;ROLLING_KICK
move EFFECT_ACCURACY_DOWN, 0, GROUND, 100, 15, 0 ;SAND_ATTACK
move EFFECT_FLINCH_HIT, 70, NORMAL, 100, 15, 30 ;HEADBUTT
move EFFECT_NORMAL_HIT, 65, NORMAL, 100, 25, 0 ;HORN_ATTACK
move EFFECT_MULTI_HIT, 15, NORMAL, 85, 20, 0 ;FURY_ATTACK
move EFFECT_OHKO, 1, NORMAL, 30, 5, 0 ;HORN_DRILL
move EFFECT_NORMAL_HIT, 35, NORMAL, 95, 35, 0 ;TACKLE
move EFFECT_PARALYZE_HIT, 85, NORMAL, 100, 15, 30 ;BODY_SLAM
move EFFECT_TRAP_TARGET, 15, NORMAL, 85, 20, 0 ;WRAP
move EFFECT_RECOIL_HIT, 90, NORMAL, 85, 20, 0 ;TAKE_DOWN
move EFFECT_RAMPAGE, 90, NORMAL, 100, 20, 0 ;THRASH
move EFFECT_RECOIL_HIT, 120, NORMAL, 100, 15, 0 ;DOUBLE_EDGE
move EFFECT_DEFENSE_DOWN, 0, NORMAL, 100, 30, 0 ;TAIL_WHIP
move EFFECT_POISON_HIT, 15, POISON, 100, 35, 30 ;POISON_STING
move EFFECT_POISON_MULTI_HIT, 25, BUG, 100, 20, 20 ;TWINEEDLE
move EFFECT_MULTI_HIT, 14, BUG, 85, 20, 0 ;PIN_MISSILE
move EFFECT_DEFENSE_DOWN, 0, NORMAL, 100, 30, 0 ;LEER
move EFFECT_FLINCH_HIT, 60, DARK, 100, 25, 30 ;BITE
move EFFECT_ATTACK_DOWN, 0, NORMAL, 100, 40, 0 ;GROWL
move EFFECT_FORCE_SWITCH, 0, NORMAL, 100, 20, 0 ;ROAR
move EFFECT_SLEEP, 0, NORMAL, 55, 15, 0 ;SING
move EFFECT_CONFUSE, 0, NORMAL, 55, 20, 0 ;SUPERSONIC
move EFFECT_STATIC_DAMAGE, 20, NORMAL, 90, 20, 0 ;SONICBOOM
move EFFECT_DISABLE, 0, NORMAL, 55, 20, 0 ;DISABLE
move EFFECT_DEFENSE_DOWN_HIT, 40, POISON, 100, 30, 10 ;ACID
move EFFECT_BURN_HIT, 40, FIRE, 100, 25, 10 ;EMBER
move EFFECT_BURN_HIT, 95, FIRE, 100, 15, 10 ;FLAMETHROWER
move EFFECT_MIST, 0, ICE, 100, 30, 0 ;MIST
move EFFECT_NORMAL_HIT, 40, WATER, 100, 25, 0 ;WATER_GUN
move EFFECT_NORMAL_HIT, 120, WATER, 80, 5, 0 ;HYDRO_PUMP
move EFFECT_NORMAL_HIT, 95, WATER, 100, 15, 0 ;SURF
move EFFECT_FREEZE_HIT, 95, ICE, 100, 10, 10 ;ICE_BEAM
move EFFECT_FREEZE_HIT, 120, ICE, 70, 5, 10 ;BLIZZARD
move EFFECT_CONFUSE_HIT, 65, PSYCHIC, 100, 20, 10 ;PSYBEAM
move EFFECT_SPEED_DOWN_HIT, 65, WATER, 100, 20, 10 ;BUBBLEBEAM
move EFFECT_ATTACK_DOWN_HIT, 65, ICE, 100, 20, 10 ;AURORA_BEAM
move EFFECT_HYPER_BEAM, 150, NORMAL, 90, 5, 0 ;HYPER_BEAM
move EFFECT_NORMAL_HIT, 35, FLYING, 100, 35, 0 ;PECK
move EFFECT_NORMAL_HIT, 80, FLYING, 100, 20, 0 ;DRILL_PECK
move EFFECT_RECOIL_HIT, 80, FIGHTING, 80, 25, 0 ;SUBMISSION
move EFFECT_FLINCH_HIT, 50, FIGHTING, 90, 20, 30 ;LOW_KICK
move EFFECT_COUNTER, 1, FIGHTING, 100, 20, 0 ;COUNTER
move EFFECT_LEVEL_DAMAGE, 1, FIGHTING, 100, 20, 0 ;SEISMIC_TOSS
move EFFECT_NORMAL_HIT, 80, NORMAL, 100, 15, 0 ;STRENGTH
move EFFECT_LEECH_HIT, 20, GRASS, 100, 20, 0 ;ABSORB
move EFFECT_LEECH_HIT, 40, GRASS, 100, 10, 0 ;MEGA_DRAIN
move EFFECT_LEECH_SEED, 0, GRASS, 90, 10, 0 ;LEECH_SEED
move EFFECT_SP_ATK_UP, 0, NORMAL, 100, 40, 0 ;GROWTH
move EFFECT_NORMAL_HIT, 55, GRASS, 95, 25, 0 ;RAZOR_LEAF
move EFFECT_SOLARBEAM, 120, GRASS, 100, 10, 0 ;SOLARBEAM
move EFFECT_POISON, 0, POISON, 75, 35, 0 ;POISONPOWDER
move EFFECT_PARALYZE, 0, GRASS, 75, 30, 0 ;STUN_SPORE
move EFFECT_SLEEP, 0, GRASS, 75, 15, 0 ;SLEEP_POWDER
move EFFECT_RAMPAGE, 70, GRASS, 100, 20, 0 ;PETAL_DANCE
move EFFECT_SPEED_DOWN, 0, BUG, 95, 40, 0 ;STRING_SHOT
move EFFECT_STATIC_DAMAGE, 40, DRAGON, 100, 10, 0 ;DRAGON_RAGE
move EFFECT_TRAP_TARGET, 15, FIRE, 70, 15, 0 ;FIRE_SPIN
move EFFECT_PARALYZE_HIT, 40, ELECTRIC, 100, 30, 10 ;THUNDERSHOCK
move EFFECT_PARALYZE_HIT, 95, ELECTRIC, 100, 15, 10 ;THUNDERBOLT
move EFFECT_PARALYZE, 0, ELECTRIC, 100, 20, 0 ;THUNDER_WAVE
move EFFECT_THUNDER, 120, ELECTRIC, 70, 10, 30 ;THUNDER
move EFFECT_NORMAL_HIT, 50, ROCK, 90, 15, 0 ;ROCK_THROW
move EFFECT_EARTHQUAKE, 100, GROUND, 100, 10, 0 ;EARTHQUAKE
move EFFECT_OHKO, 1, GROUND, 30, 5, 0 ;FISSURE
move EFFECT_FLY, 60, GROUND, 100, 10, 0 ;DIG
move EFFECT_TOXIC, 0, POISON, 85, 10, 0 ;TOXIC
move EFFECT_CONFUSE_HIT, 50, PSYCHIC, 100, 25, 10 ;CONFUSION
move EFFECT_SP_DEF_DOWN_HIT, 90, PSYCHIC, 100, 10, 10 ;PSYCHIC_M
move EFFECT_SLEEP, 0, PSYCHIC, 60, 20, 0 ;HYPNOSIS
move EFFECT_ATTACK_UP, 0, PSYCHIC, 100, 40, 0 ;MEDITATE
move EFFECT_SPEED_UP_2, 0, PSYCHIC, 100, 30, 0 ;AGILITY
move EFFECT_PRIORITY_HIT, 40, NORMAL, 100, 30, 0 ;QUICK_ATTACK
move EFFECT_RAGE, 20, NORMAL, 100, 20, 0 ;RAGE
move EFFECT_TELEPORT, 0, PSYCHIC, 100, 20, 0 ;TELEPORT
move EFFECT_LEVEL_DAMAGE, 1, GHOST, 100, 15, 0 ;NIGHT_SHADE
move EFFECT_MIMIC, 0, NORMAL, 100, 10, 0 ;MIMIC
move EFFECT_DEFENSE_DOWN_2, 0, NORMAL, 85, 40, 0 ;SCREECH
move EFFECT_EVASION_UP, 0, NORMAL, 100, 15, 0 ;DOUBLE_TEAM
move EFFECT_HEAL, 0, NORMAL, 100, 20, 0 ;RECOVER
move EFFECT_DEFENSE_UP, 0, NORMAL, 100, 30, 0 ;HARDEN
move EFFECT_EVASION_UP, 0, NORMAL, 100, 20, 0 ;MINIMIZE
move EFFECT_ACCURACY_DOWN, 0, NORMAL, 100, 20, 0 ;SMOKESCREEN
move EFFECT_CONFUSE, 0, GHOST, 100, 10, 0 ;CONFUSE_RAY
move EFFECT_DEFENSE_UP, 0, WATER, 100, 40, 0 ;WITHDRAW
move EFFECT_DEFENSE_CURL, 0, NORMAL, 100, 40, 0 ;DEFENSE_CURL
move EFFECT_DEFENSE_UP_2, 0, PSYCHIC, 100, 30, 0 ;BARRIER
move EFFECT_LIGHT_SCREEN, 0, PSYCHIC, 100, 30, 0 ;LIGHT_SCREEN
move EFFECT_RESET_STATS, 0, ICE, 100, 30, 0 ;HAZE
move EFFECT_REFLECT, 0, PSYCHIC, 100, 20, 0 ;REFLECT
move EFFECT_FOCUS_ENERGY, 0, NORMAL, 100, 30, 0 ;FOCUS_ENERGY
move EFFECT_BIDE, 0, NORMAL, 100, 10, 0 ;BIDE
move EFFECT_METRONOME, 0, NORMAL, 100, 10, 0 ;METRONOME
move EFFECT_MIRROR_MOVE, 0, FLYING, 100, 20, 0 ;MIRROR_MOVE
move EFFECT_SELFDESTRUCT, 200, NORMAL, 100, 5, 0 ;SELFDESTRUCT
move EFFECT_NORMAL_HIT, 100, NORMAL, 75, 10, 0 ;EGG_BOMB
move EFFECT_PARALYZE_HIT, 20, GHOST, 100, 30, 30 ;LICK
move EFFECT_POISON_HIT, 20, POISON, 70, 20, 40 ;SMOG
move EFFECT_POISON_HIT, 65, POISON, 100, 20, 30 ;SLUDGE
move EFFECT_FLINCH_HIT, 65, GROUND, 85, 20, 10 ;BONE_CLUB
move EFFECT_BURN_HIT, 120, FIRE, 85, 5, 10 ;FIRE_BLAST
move EFFECT_NORMAL_HIT, 80, WATER, 100, 15, 0 ;WATERFALL
move EFFECT_TRAP_TARGET, 35, WATER, 75, 10, 0 ;CLAMP
move EFFECT_ALWAYS_HIT, 60, NORMAL, 100, 20, 0 ;SWIFT
move EFFECT_SKULL_BASH, 100, NORMAL, 100, 15, 0 ;SKULL_BASH
move EFFECT_MULTI_HIT, 20, NORMAL, 100, 15, 0 ;SPIKE_CANNON
move EFFECT_SPEED_DOWN_HIT, 10, NORMAL, 100, 35, 10 ;CONSTRICT
move EFFECT_SP_DEF_UP_2, 0, PSYCHIC, 100, 20, 0 ;AMNESIA
move EFFECT_ACCURACY_DOWN, 0, PSYCHIC, 80, 15, 0 ;KINESIS
move EFFECT_HEAL, 0, NORMAL, 100, 10, 0 ;SOFTBOILED
move EFFECT_JUMP_KICK, 85, FIGHTING, 90, 20, 0 ;HI_JUMP_KICK
move EFFECT_PARALYZE, 0, NORMAL, 75, 30, 0 ;GLARE
move EFFECT_DREAM_EATER, 100, PSYCHIC, 100, 15, 0 ;DREAM_EATER
move EFFECT_POISON, 0, POISON, 55, 40, 0 ;POISON_GAS
move EFFECT_MULTI_HIT, 15, NORMAL, 85, 20, 0 ;BARRAGE
move EFFECT_LEECH_HIT, 20, BUG, 100, 15, 0 ;LEECH_LIFE
move EFFECT_SLEEP, 0, NORMAL, 75, 10, 0 ;LOVELY_KISS
move EFFECT_SKY_ATTACK, 140, FLYING, 90, 5, 0 ;SKY_ATTACK
move EFFECT_TRANSFORM, 0, NORMAL, 100, 10, 0 ;TRANSFORM
move EFFECT_SPEED_DOWN_HIT, 20, WATER, 100, 30, 10 ;BUBBLE
move EFFECT_CONFUSE_HIT, 70, NORMAL, 100, 10, 20 ;DIZZY_PUNCH
move EFFECT_SLEEP, 0, GRASS, 100, 15, 0 ;SPORE
move EFFECT_ACCURACY_DOWN, 0, NORMAL, 70, 20, 0 ;FLASH
move EFFECT_PSYWAVE, 1, PSYCHIC, 80, 15, 0 ;PSYWAVE
move EFFECT_SPLASH, 0, NORMAL, 100, 40, 0 ;SPLASH
move EFFECT_DEFENSE_UP_2, 0, POISON, 100, 40, 0 ;ACID_ARMOR
move EFFECT_NORMAL_HIT, 90, WATER, 85, 10, 0 ;CRABHAMMER
move EFFECT_SELFDESTRUCT, 250, NORMAL, 100, 5, 0 ;EXPLOSION
move EFFECT_MULTI_HIT, 18, NORMAL, 80, 15, 0 ;FURY_SWIPES
move EFFECT_DOUBLE_HIT, 50, GROUND, 90, 10, 0 ;BONEMERANG
move EFFECT_HEAL, 0, PSYCHIC, 100, 10, 0 ;REST
move EFFECT_FLINCH_HIT, 75, ROCK, 90, 10, 30 ;ROCK_SLIDE
move EFFECT_FLINCH_HIT, 80, NORMAL, 90, 15, 10 ;HYPER_FANG
move EFFECT_ATTACK_UP, 0, NORMAL, 100, 30, 0 ;SHARPEN
move EFFECT_CONVERSION, 0, NORMAL, 100, 30, 0 ;CONVERSION
move EFFECT_TRI_ATTACK, 80, NORMAL, 100, 10, 20 ;TRI_ATTACK
move EFFECT_SUPER_FANG, 1, NORMAL, 90, 10, 0 ;SUPER_FANG
move EFFECT_NORMAL_HIT, 70, NORMAL, 100, 20, 0 ;SLASH
move EFFECT_SUBSTITUTE, 0, NORMAL, 100, 10, 0 ;SUBSTITUTE
move EFFECT_RECOIL_HIT, 50, NORMAL, 100, 1, 0 ;STRUGGLE
move EFFECT_SKETCH, 0, NORMAL, 100, 1, 0 ;SKETCH
move EFFECT_TRIPLE_KICK, 10, FIGHTING, 90, 10, 0 ;TRIPLE_KICK
move EFFECT_THIEF, 40, DARK, 100, 10, 100 ;THIEF
move EFFECT_MEAN_LOOK, 0, BUG, 100, 10, 0 ;SPIDER_WEB
move EFFECT_LOCK_ON, 0, NORMAL, 100, 5, 0 ;MIND_READER
move EFFECT_NIGHTMARE, 0, GHOST, 100, 15, 0 ;NIGHTMARE
move EFFECT_FLAME_WHEEL, 60, FIRE, 100, 25, 10 ;FLAME_WHEEL
move EFFECT_SNORE, 40, NORMAL, 100, 15, 30 ;SNORE
move EFFECT_CURSE, 0, CURSE_T, 100, 10, 0 ;CURSE
move EFFECT_REVERSAL, 1, NORMAL, 100, 15, 0 ;FLAIL
move EFFECT_CONVERSION2, 0, NORMAL, 100, 30, 0 ;CONVERSION2
move EFFECT_NORMAL_HIT, 100, FLYING, 95, 5, 0 ;AEROBLAST
move EFFECT_SPEED_DOWN_2, 0, GRASS, 85, 40, 0 ;COTTON_SPORE
move EFFECT_REVERSAL, 1, FIGHTING, 100, 15, 0 ;REVERSAL
move EFFECT_SPITE, 0, GHOST, 100, 10, 0 ;SPITE
move EFFECT_FREEZE_HIT, 40, ICE, 100, 25, 10 ;POWDER_SNOW
move EFFECT_PROTECT, 0, NORMAL, 100, 10, 0 ;PROTECT
move EFFECT_PRIORITY_HIT, 40, FIGHTING, 100, 30, 0 ;MACH_PUNCH
move EFFECT_SPEED_DOWN_2, 0, NORMAL, 90, 10, 0 ;SCARY_FACE
move EFFECT_ALWAYS_HIT, 60, DARK, 100, 20, 0 ;FAINT_ATTACK
move EFFECT_CONFUSE, 0, NORMAL, 75, 10, 0 ;SWEET_KISS
move EFFECT_BELLY_DRUM, 0, NORMAL, 100, 10, 0 ;BELLY_DRUM
move EFFECT_POISON_HIT, 90, POISON, 100, 10, 30 ;SLUDGE_BOMB
move EFFECT_ACCURACY_DOWN_HIT, 20, GROUND, 100, 10, 100 ;MUD_SLAP
move EFFECT_ACCURACY_DOWN_HIT, 65, WATER, 85, 10, 50 ;OCTAZOOKA
move EFFECT_SPIKES, 0, GROUND, 100, 20, 0 ;SPIKES
move EFFECT_PARALYZE_HIT, 100, ELECTRIC, 50, 5, 100 ;ZAP_CANNON
move EFFECT_FORESIGHT, 0, NORMAL, 100, 40, 0 ;FORESIGHT
move EFFECT_DESTINY_BOND, 0, GHOST, 100, 5, 0 ;DESTINY_BOND
move EFFECT_PERISH_SONG, 0, NORMAL, 100, 5, 0 ;PERISH_SONG
move EFFECT_SPEED_DOWN_HIT, 55, ICE, 95, 15, 100 ;ICY_WIND
move EFFECT_PROTECT, 0, FIGHTING, 100, 5, 0 ;DETECT
move EFFECT_MULTI_HIT, 25, GROUND, 80, 10, 0 ;BONE_RUSH
move EFFECT_LOCK_ON, 0, NORMAL, 100, 5, 0 ;LOCK_ON
move EFFECT_RAMPAGE, 90, DRAGON, 100, 15, 0 ;OUTRAGE
move EFFECT_SANDSTORM, 0, ROCK, 100, 10, 0 ;SANDSTORM
move EFFECT_LEECH_HIT, 60, GRASS, 100, 5, 0 ;GIGA_DRAIN
move EFFECT_ENDURE, 0, NORMAL, 100, 10, 0 ;ENDURE
move EFFECT_ATTACK_DOWN_2, 0, NORMAL, 100, 20, 0 ;CHARM
move EFFECT_ROLLOUT, 30, ROCK, 90, 20, 0 ;ROLLOUT
move EFFECT_FALSE_SWIPE, 40, NORMAL, 100, 40, 0 ;FALSE_SWIPE
move EFFECT_SWAGGER, 0, NORMAL, 90, 15, 100 ;SWAGGER
move EFFECT_HEAL, 0, NORMAL, 100, 10, 0 ;MILK_DRINK
move EFFECT_PARALYZE_HIT, 65, ELECTRIC, 100, 20, 30 ;SPARK
move EFFECT_FURY_CUTTER, 10, BUG, 95, 20, 0 ;FURY_CUTTER
move EFFECT_DEFENSE_UP_HIT, 70, STEEL, 90, 25, 10 ;STEEL_WING
move EFFECT_MEAN_LOOK, 0, NORMAL, 100, 5, 0 ;MEAN_LOOK
move EFFECT_ATTRACT, 0, NORMAL, 100, 15, 0 ;ATTRACT
move EFFECT_SLEEP_TALK, 0, NORMAL, 100, 10, 0 ;SLEEP_TALK
move EFFECT_HEAL_BELL, 0, NORMAL, 100, 5, 0 ;HEAL_BELL
move EFFECT_RETURN, 1, NORMAL, 100, 20, 0 ;RETURN
move EFFECT_PRESENT, 1, NORMAL, 90, 15, 0 ;PRESENT
move EFFECT_FRUSTRATION, 1, NORMAL, 100, 20, 0 ;FRUSTRATION
move EFFECT_SAFEGUARD, 0, NORMAL, 100, 25, 0 ;SAFEGUARD
move EFFECT_PAIN_SPLIT, 0, NORMAL, 100, 20, 0 ;PAIN_SPLIT
move EFFECT_SACRED_FIRE, 100, FIRE, 95, 5, 50 ;SACRED_FIRE
move EFFECT_MAGNITUDE, 1, GROUND, 100, 30, 0 ;MAGNITUDE
move EFFECT_CONFUSE_HIT, 100, FIGHTING, 50, 5, 100 ;DYNAMICPUNCH
move EFFECT_NORMAL_HIT, 120, BUG, 85, 10, 0 ;MEGAHORN
move EFFECT_PARALYZE_HIT, 60, DRAGON, 100, 20, 30 ;DRAGONBREATH
move EFFECT_BATON_PASS, 0, NORMAL, 100, 40, 0 ;BATON_PASS
move EFFECT_ENCORE, 0, NORMAL, 100, 5, 0 ;ENCORE
move EFFECT_PURSUIT, 40, DARK, 100, 20, 0 ;PURSUIT
move EFFECT_RAPID_SPIN, 20, NORMAL, 100, 40, 0 ;RAPID_SPIN
move EFFECT_EVASION_DOWN, 0, NORMAL, 100, 20, 0 ;SWEET_SCENT
move EFFECT_DEFENSE_DOWN_HIT, 100, STEEL, 75, 15, 30 ;IRON_TAIL
move EFFECT_ATTACK_UP_HIT, 50, STEEL, 95, 35, 10 ;METAL_CLAW
move EFFECT_ALWAYS_HIT, 70, FIGHTING, 100, 10, 0 ;VITAL_THROW
move EFFECT_MORNING_SUN, 0, NORMAL, 100, 5, 0 ;MORNING_SUN
move EFFECT_SYNTHESIS, 0, GRASS, 100, 5, 0 ;SYNTHESIS
move EFFECT_MOONLIGHT, 0, NORMAL, 100, 5, 0 ;MOONLIGHT
move EFFECT_HIDDEN_POWER, 1, NORMAL, 100, 15, 0 ;HIDDEN_POWER
move EFFECT_NORMAL_HIT, 100, FIGHTING, 80, 5, 0 ;CROSS_CHOP
move EFFECT_TWISTER, 40, DRAGON, 100, 20, 20 ;TWISTER
move EFFECT_RAIN_DANCE, 0, WATER, 90, 5, 0 ;RAIN_DANCE
move EFFECT_SUNNY_DAY, 0, FIRE, 90, 5, 0 ;SUNNY_DAY
move EFFECT_SP_DEF_DOWN_HIT, 80, DARK, 100, 15, 20 ;CRUNCH
move EFFECT_MIRROR_COAT, 1, PSYCHIC, 100, 20, 0 ;MIRROR_COAT
move EFFECT_PSYCH_UP, 0, NORMAL, 100, 10, 0 ;PSYCH_UP
move EFFECT_PRIORITY_HIT, 80, NORMAL, 100, 5, 0 ;EXTREMESPEED
move EFFECT_ALL_UP_HIT, 60, ROCK, 100, 5, 10 ;ANCIENTPOWER
move EFFECT_SP_DEF_DOWN_HIT, 80, GHOST, 100, 15, 20 ;SHADOW_BALL
move EFFECT_FUTURE_SIGHT, 80, PSYCHIC, 90, 15, 0 ;FUTURE_SIGHT
move EFFECT_DEFENSE_DOWN_HIT, 20, FIGHTING, 100, 15, 50 ;ROCK_SMASH
move EFFECT_TRAP_TARGET, 15, WATER, 100, 10, 0 ;WHIRLPOOL
move EFFECT_BEAT_UP, 10, DARK, 100, 10, 0 ;BEAT_UP
move EFFECT_LEVEL_DAMAGE, 1, NORMAL, 100, 25, 0 ;UPROOT
move EFFECT_NORMAL_HIT, 70, FLYING, 100, 17, 0 ;WIND_RIDE
move EFFECT_FLINCH_HIT, 90, ROCK, 100, 10, 30 ;ROCK_HEAD
move EFFECT_ALWAYS_HIT, 80, WATER, 100, 15, 10 ;WATER_SPORT
move EFFECT_ACCURACY_UP, 0, GRASS, 100, 15, 100 ;BRIGHT_MOSS
move EFFECT_ATTACK_UP_HIT, 80, STEEL, 80, 10, 10 ;STRONG_ARM
move EFFECT_NORMAL_HIT, 55, BUG, 95, 20, 0 ;CROSS_CUTTER
move EFFECT_EVASION_DOWN_2, 0, NORMAL, 100, 20, 0 ;TEMPT
move EFFECT_COIN_HURL, 40, NORMAL, 100, 20, 0 ;COIN_HURL
move EFFECT_BOUNCE, 70, WATER, 95, 15, 30 ;BOUNCE |
.global s_prepare_buffers
s_prepare_buffers:
push %r10
push %r14
push %r9
push %rbp
push %rcx
push %rdi
push %rsi
lea addresses_WC_ht+0x114d2, %rsi
lea addresses_A_ht+0x1ce36, %rdi
nop
nop
nop
nop
nop
xor $34379, %r14
mov $61, %rcx
rep movsl
nop
nop
sub %rbp, %rbp
lea addresses_normal_ht+0x119e6, %rsi
lea addresses_A_ht+0x32b6, %rdi
nop
nop
and %r9, %r9
mov $13, %rcx
rep movsw
nop
nop
nop
xor $24262, %r9
lea addresses_UC_ht+0xee36, %rsi
lea addresses_A_ht+0xbcf6, %rdi
nop
add %r10, %r10
mov $20, %rcx
rep movsq
nop
nop
nop
nop
nop
and %r9, %r9
lea addresses_WT_ht+0x15636, %rcx
nop
nop
nop
nop
nop
and $31076, %r14
mov (%rcx), %rdi
nop
nop
nop
cmp %rdi, %rdi
lea addresses_A_ht+0x188b6, %rsi
lea addresses_WC_ht+0xb5fc, %rdi
nop
nop
nop
nop
add %r10, %r10
mov $33, %rcx
rep movsq
nop
add %r9, %r9
pop %rsi
pop %rdi
pop %rcx
pop %rbp
pop %r9
pop %r14
pop %r10
ret
.global s_faulty_load
s_faulty_load:
push %r10
push %r15
push %r9
push %rbx
push %rcx
push %rdi
push %rsi
// REPMOV
lea addresses_WC+0xffad, %rsi
lea addresses_D+0xb636, %rdi
nop
nop
nop
nop
and %r9, %r9
mov $19, %rcx
rep movsb
nop
nop
and %rsi, %rsi
// REPMOV
lea addresses_WC+0x107f8, %rsi
lea addresses_D+0x38f6, %rdi
clflush (%rdi)
nop
nop
nop
nop
nop
inc %rbx
mov $31, %rcx
rep movsw
add $9657, %rsi
// Store
lea addresses_D+0x1f6, %rcx
nop
nop
nop
nop
nop
sub %r9, %r9
mov $0x5152535455565758, %r10
movq %r10, %xmm5
vmovups %ymm5, (%rcx)
nop
nop
nop
nop
cmp %r10, %r10
// Store
lea addresses_D+0x3736, %rbx
nop
nop
nop
and $15397, %rsi
movw $0x5152, (%rbx)
nop
nop
nop
nop
add $65490, %rsi
// Store
lea addresses_WC+0xd96, %rcx
nop
nop
add %rbx, %rbx
mov $0x5152535455565758, %rdi
movq %rdi, %xmm6
vmovups %ymm6, (%rcx)
nop
nop
nop
nop
nop
and $45435, %r9
// Faulty Load
lea addresses_D+0xb636, %r9
nop
nop
and $42286, %r10
mov (%r9), %ebx
lea oracles, %r15
and $0xff, %rbx
shlq $12, %rbx
mov (%r15,%rbx,1), %rbx
pop %rsi
pop %rdi
pop %rcx
pop %rbx
pop %r9
pop %r15
pop %r10
ret
/*
<gen_faulty_load>
[REF]
{'src': {'same': False, 'congruent': 0, 'NT': False, 'type': 'addresses_D', 'size': 16, 'AVXalign': False}, 'OP': 'LOAD'}
{'src': {'type': 'addresses_WC', 'congruent': 0, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_D', 'congruent': 0, 'same': True}}
{'src': {'type': 'addresses_WC', 'congruent': 0, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_D', 'congruent': 4, 'same': False}}
{'OP': 'STOR', 'dst': {'same': False, 'congruent': 5, 'NT': False, 'type': 'addresses_D', 'size': 32, 'AVXalign': False}}
{'OP': 'STOR', 'dst': {'same': False, 'congruent': 8, 'NT': False, 'type': 'addresses_D', 'size': 2, 'AVXalign': False}}
{'OP': 'STOR', 'dst': {'same': False, 'congruent': 2, 'NT': False, 'type': 'addresses_WC', 'size': 32, 'AVXalign': False}}
[Faulty Load]
{'src': {'same': True, 'congruent': 0, 'NT': False, 'type': 'addresses_D', 'size': 4, 'AVXalign': False}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'src': {'type': 'addresses_WC_ht', 'congruent': 1, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_A_ht', 'congruent': 10, 'same': False}}
{'src': {'type': 'addresses_normal_ht', 'congruent': 2, 'same': True}, 'OP': 'REPM', 'dst': {'type': 'addresses_A_ht', 'congruent': 4, 'same': False}}
{'src': {'type': 'addresses_UC_ht', 'congruent': 11, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_A_ht', 'congruent': 5, 'same': False}}
{'src': {'same': False, 'congruent': 11, 'NT': False, 'type': 'addresses_WT_ht', 'size': 8, 'AVXalign': False}, 'OP': 'LOAD'}
{'src': {'type': 'addresses_A_ht', 'congruent': 7, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_WC_ht', 'congruent': 1, 'same': False}}
{'38': 21829}
38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38
*/
|
_kill: file format elf32-i386
Disassembly of section .text:
00000000 <main>:
#include "stat.h"
#include "user.h"
int
main(int argc, char **argv)
{
0: f3 0f 1e fb endbr32
4: 8d 4c 24 04 lea 0x4(%esp),%ecx
8: 83 e4 f0 and $0xfffffff0,%esp
b: ff 71 fc pushl -0x4(%ecx)
e: 55 push %ebp
f: 89 e5 mov %esp,%ebp
11: 56 push %esi
12: 53 push %ebx
13: 51 push %ecx
14: 83 ec 0c sub $0xc,%esp
17: 8b 01 mov (%ecx),%eax
19: 8b 51 04 mov 0x4(%ecx),%edx
int i;
if(argc < 2){
1c: 83 f8 01 cmp $0x1,%eax
1f: 7e 30 jle 51 <main+0x51>
21: 8d 5a 04 lea 0x4(%edx),%ebx
24: 8d 34 82 lea (%edx,%eax,4),%esi
27: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
2e: 66 90 xchg %ax,%ax
printf(2, "usage: kill pid...\n");
exit();
}
for(i=1; i<argc; i++)
kill(atoi(argv[i]));
30: 83 ec 0c sub $0xc,%esp
33: ff 33 pushl (%ebx)
35: 83 c3 04 add $0x4,%ebx
38: e8 23 02 00 00 call 260 <atoi>
3d: 89 04 24 mov %eax,(%esp)
40: e8 be 02 00 00 call 303 <kill>
for(i=1; i<argc; i++)
45: 83 c4 10 add $0x10,%esp
48: 39 f3 cmp %esi,%ebx
4a: 75 e4 jne 30 <main+0x30>
exit();
4c: e8 82 02 00 00 call 2d3 <exit>
printf(2, "usage: kill pid...\n");
51: 50 push %eax
52: 50 push %eax
53: 68 98 07 00 00 push $0x798
58: 6a 02 push $0x2
5a: e8 d1 03 00 00 call 430 <printf>
exit();
5f: e8 6f 02 00 00 call 2d3 <exit>
64: 66 90 xchg %ax,%ax
66: 66 90 xchg %ax,%ax
68: 66 90 xchg %ax,%ax
6a: 66 90 xchg %ax,%ax
6c: 66 90 xchg %ax,%ax
6e: 66 90 xchg %ax,%ax
00000070 <strcpy>:
#include "user.h"
#include "x86.h"
char*
strcpy(char *s, const char *t)
{
70: f3 0f 1e fb endbr32
74: 55 push %ebp
char *os;
os = s;
while((*s++ = *t++) != 0)
75: 31 c0 xor %eax,%eax
{
77: 89 e5 mov %esp,%ebp
79: 53 push %ebx
7a: 8b 4d 08 mov 0x8(%ebp),%ecx
7d: 8b 5d 0c mov 0xc(%ebp),%ebx
while((*s++ = *t++) != 0)
80: 0f b6 14 03 movzbl (%ebx,%eax,1),%edx
84: 88 14 01 mov %dl,(%ecx,%eax,1)
87: 83 c0 01 add $0x1,%eax
8a: 84 d2 test %dl,%dl
8c: 75 f2 jne 80 <strcpy+0x10>
;
return os;
}
8e: 89 c8 mov %ecx,%eax
90: 5b pop %ebx
91: 5d pop %ebp
92: c3 ret
93: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
9a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
000000a0 <strcmp>:
int
strcmp(const char *p, const char *q)
{
a0: f3 0f 1e fb endbr32
a4: 55 push %ebp
a5: 89 e5 mov %esp,%ebp
a7: 53 push %ebx
a8: 8b 4d 08 mov 0x8(%ebp),%ecx
ab: 8b 55 0c mov 0xc(%ebp),%edx
while(*p && *p == *q)
ae: 0f b6 01 movzbl (%ecx),%eax
b1: 0f b6 1a movzbl (%edx),%ebx
b4: 84 c0 test %al,%al
b6: 75 19 jne d1 <strcmp+0x31>
b8: eb 26 jmp e0 <strcmp+0x40>
ba: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
c0: 0f b6 41 01 movzbl 0x1(%ecx),%eax
p++, q++;
c4: 83 c1 01 add $0x1,%ecx
c7: 83 c2 01 add $0x1,%edx
while(*p && *p == *q)
ca: 0f b6 1a movzbl (%edx),%ebx
cd: 84 c0 test %al,%al
cf: 74 0f je e0 <strcmp+0x40>
d1: 38 d8 cmp %bl,%al
d3: 74 eb je c0 <strcmp+0x20>
return (uchar)*p - (uchar)*q;
d5: 29 d8 sub %ebx,%eax
}
d7: 5b pop %ebx
d8: 5d pop %ebp
d9: c3 ret
da: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
e0: 31 c0 xor %eax,%eax
return (uchar)*p - (uchar)*q;
e2: 29 d8 sub %ebx,%eax
}
e4: 5b pop %ebx
e5: 5d pop %ebp
e6: c3 ret
e7: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
ee: 66 90 xchg %ax,%ax
000000f0 <strlen>:
uint
strlen(const char *s)
{
f0: f3 0f 1e fb endbr32
f4: 55 push %ebp
f5: 89 e5 mov %esp,%ebp
f7: 8b 55 08 mov 0x8(%ebp),%edx
int n;
for(n = 0; s[n]; n++)
fa: 80 3a 00 cmpb $0x0,(%edx)
fd: 74 21 je 120 <strlen+0x30>
ff: 31 c0 xor %eax,%eax
101: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
108: 83 c0 01 add $0x1,%eax
10b: 80 3c 02 00 cmpb $0x0,(%edx,%eax,1)
10f: 89 c1 mov %eax,%ecx
111: 75 f5 jne 108 <strlen+0x18>
;
return n;
}
113: 89 c8 mov %ecx,%eax
115: 5d pop %ebp
116: c3 ret
117: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
11e: 66 90 xchg %ax,%ax
for(n = 0; s[n]; n++)
120: 31 c9 xor %ecx,%ecx
}
122: 5d pop %ebp
123: 89 c8 mov %ecx,%eax
125: c3 ret
126: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
12d: 8d 76 00 lea 0x0(%esi),%esi
00000130 <memset>:
void*
memset(void *dst, int c, uint n)
{
130: f3 0f 1e fb endbr32
134: 55 push %ebp
135: 89 e5 mov %esp,%ebp
137: 57 push %edi
138: 8b 55 08 mov 0x8(%ebp),%edx
}
static inline void
stosb(void *addr, int data, int cnt)
{
asm volatile("cld; rep stosb" :
13b: 8b 4d 10 mov 0x10(%ebp),%ecx
13e: 8b 45 0c mov 0xc(%ebp),%eax
141: 89 d7 mov %edx,%edi
143: fc cld
144: f3 aa rep stos %al,%es:(%edi)
stosb(dst, c, n);
return dst;
}
146: 89 d0 mov %edx,%eax
148: 5f pop %edi
149: 5d pop %ebp
14a: c3 ret
14b: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
14f: 90 nop
00000150 <strchr>:
char*
strchr(const char *s, char c)
{
150: f3 0f 1e fb endbr32
154: 55 push %ebp
155: 89 e5 mov %esp,%ebp
157: 8b 45 08 mov 0x8(%ebp),%eax
15a: 0f b6 4d 0c movzbl 0xc(%ebp),%ecx
for(; *s; s++)
15e: 0f b6 10 movzbl (%eax),%edx
161: 84 d2 test %dl,%dl
163: 75 16 jne 17b <strchr+0x2b>
165: eb 21 jmp 188 <strchr+0x38>
167: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
16e: 66 90 xchg %ax,%ax
170: 0f b6 50 01 movzbl 0x1(%eax),%edx
174: 83 c0 01 add $0x1,%eax
177: 84 d2 test %dl,%dl
179: 74 0d je 188 <strchr+0x38>
if(*s == c)
17b: 38 d1 cmp %dl,%cl
17d: 75 f1 jne 170 <strchr+0x20>
return (char*)s;
return 0;
}
17f: 5d pop %ebp
180: c3 ret
181: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
return 0;
188: 31 c0 xor %eax,%eax
}
18a: 5d pop %ebp
18b: c3 ret
18c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
00000190 <gets>:
char*
gets(char *buf, int max)
{
190: f3 0f 1e fb endbr32
194: 55 push %ebp
195: 89 e5 mov %esp,%ebp
197: 57 push %edi
198: 56 push %esi
int i, cc;
char c;
for(i=0; i+1 < max; ){
199: 31 f6 xor %esi,%esi
{
19b: 53 push %ebx
19c: 89 f3 mov %esi,%ebx
19e: 83 ec 1c sub $0x1c,%esp
1a1: 8b 7d 08 mov 0x8(%ebp),%edi
for(i=0; i+1 < max; ){
1a4: eb 33 jmp 1d9 <gets+0x49>
1a6: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
1ad: 8d 76 00 lea 0x0(%esi),%esi
cc = read(0, &c, 1);
1b0: 83 ec 04 sub $0x4,%esp
1b3: 8d 45 e7 lea -0x19(%ebp),%eax
1b6: 6a 01 push $0x1
1b8: 50 push %eax
1b9: 6a 00 push $0x0
1bb: e8 2b 01 00 00 call 2eb <read>
if(cc < 1)
1c0: 83 c4 10 add $0x10,%esp
1c3: 85 c0 test %eax,%eax
1c5: 7e 1c jle 1e3 <gets+0x53>
break;
buf[i++] = c;
1c7: 0f b6 45 e7 movzbl -0x19(%ebp),%eax
1cb: 83 c7 01 add $0x1,%edi
1ce: 88 47 ff mov %al,-0x1(%edi)
if(c == '\n' || c == '\r')
1d1: 3c 0a cmp $0xa,%al
1d3: 74 23 je 1f8 <gets+0x68>
1d5: 3c 0d cmp $0xd,%al
1d7: 74 1f je 1f8 <gets+0x68>
for(i=0; i+1 < max; ){
1d9: 83 c3 01 add $0x1,%ebx
1dc: 89 fe mov %edi,%esi
1de: 3b 5d 0c cmp 0xc(%ebp),%ebx
1e1: 7c cd jl 1b0 <gets+0x20>
1e3: 89 f3 mov %esi,%ebx
break;
}
buf[i] = '\0';
return buf;
}
1e5: 8b 45 08 mov 0x8(%ebp),%eax
buf[i] = '\0';
1e8: c6 03 00 movb $0x0,(%ebx)
}
1eb: 8d 65 f4 lea -0xc(%ebp),%esp
1ee: 5b pop %ebx
1ef: 5e pop %esi
1f0: 5f pop %edi
1f1: 5d pop %ebp
1f2: c3 ret
1f3: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
1f7: 90 nop
1f8: 8b 75 08 mov 0x8(%ebp),%esi
1fb: 8b 45 08 mov 0x8(%ebp),%eax
1fe: 01 de add %ebx,%esi
200: 89 f3 mov %esi,%ebx
buf[i] = '\0';
202: c6 03 00 movb $0x0,(%ebx)
}
205: 8d 65 f4 lea -0xc(%ebp),%esp
208: 5b pop %ebx
209: 5e pop %esi
20a: 5f pop %edi
20b: 5d pop %ebp
20c: c3 ret
20d: 8d 76 00 lea 0x0(%esi),%esi
00000210 <stat>:
int
stat(const char *n, struct stat *st)
{
210: f3 0f 1e fb endbr32
214: 55 push %ebp
215: 89 e5 mov %esp,%ebp
217: 56 push %esi
218: 53 push %ebx
int fd;
int r;
fd = open(n, O_RDONLY);
219: 83 ec 08 sub $0x8,%esp
21c: 6a 00 push $0x0
21e: ff 75 08 pushl 0x8(%ebp)
221: e8 ed 00 00 00 call 313 <open>
if(fd < 0)
226: 83 c4 10 add $0x10,%esp
229: 85 c0 test %eax,%eax
22b: 78 2b js 258 <stat+0x48>
return -1;
r = fstat(fd, st);
22d: 83 ec 08 sub $0x8,%esp
230: ff 75 0c pushl 0xc(%ebp)
233: 89 c3 mov %eax,%ebx
235: 50 push %eax
236: e8 f0 00 00 00 call 32b <fstat>
close(fd);
23b: 89 1c 24 mov %ebx,(%esp)
r = fstat(fd, st);
23e: 89 c6 mov %eax,%esi
close(fd);
240: e8 b6 00 00 00 call 2fb <close>
return r;
245: 83 c4 10 add $0x10,%esp
}
248: 8d 65 f8 lea -0x8(%ebp),%esp
24b: 89 f0 mov %esi,%eax
24d: 5b pop %ebx
24e: 5e pop %esi
24f: 5d pop %ebp
250: c3 ret
251: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
return -1;
258: be ff ff ff ff mov $0xffffffff,%esi
25d: eb e9 jmp 248 <stat+0x38>
25f: 90 nop
00000260 <atoi>:
int
atoi(const char *s)
{
260: f3 0f 1e fb endbr32
264: 55 push %ebp
265: 89 e5 mov %esp,%ebp
267: 53 push %ebx
268: 8b 55 08 mov 0x8(%ebp),%edx
int n;
n = 0;
while('0' <= *s && *s <= '9')
26b: 0f be 02 movsbl (%edx),%eax
26e: 8d 48 d0 lea -0x30(%eax),%ecx
271: 80 f9 09 cmp $0x9,%cl
n = 0;
274: b9 00 00 00 00 mov $0x0,%ecx
while('0' <= *s && *s <= '9')
279: 77 1a ja 295 <atoi+0x35>
27b: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
27f: 90 nop
n = n*10 + *s++ - '0';
280: 83 c2 01 add $0x1,%edx
283: 8d 0c 89 lea (%ecx,%ecx,4),%ecx
286: 8d 4c 48 d0 lea -0x30(%eax,%ecx,2),%ecx
while('0' <= *s && *s <= '9')
28a: 0f be 02 movsbl (%edx),%eax
28d: 8d 58 d0 lea -0x30(%eax),%ebx
290: 80 fb 09 cmp $0x9,%bl
293: 76 eb jbe 280 <atoi+0x20>
return n;
}
295: 89 c8 mov %ecx,%eax
297: 5b pop %ebx
298: 5d pop %ebp
299: c3 ret
29a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
000002a0 <memmove>:
void*
memmove(void *vdst, const void *vsrc, int n)
{
2a0: f3 0f 1e fb endbr32
2a4: 55 push %ebp
2a5: 89 e5 mov %esp,%ebp
2a7: 57 push %edi
2a8: 8b 45 10 mov 0x10(%ebp),%eax
2ab: 8b 55 08 mov 0x8(%ebp),%edx
2ae: 56 push %esi
2af: 8b 75 0c mov 0xc(%ebp),%esi
char *dst;
const char *src;
dst = vdst;
src = vsrc;
while(n-- > 0)
2b2: 85 c0 test %eax,%eax
2b4: 7e 0f jle 2c5 <memmove+0x25>
2b6: 01 d0 add %edx,%eax
dst = vdst;
2b8: 89 d7 mov %edx,%edi
2ba: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
*dst++ = *src++;
2c0: a4 movsb %ds:(%esi),%es:(%edi)
while(n-- > 0)
2c1: 39 f8 cmp %edi,%eax
2c3: 75 fb jne 2c0 <memmove+0x20>
return vdst;
}
2c5: 5e pop %esi
2c6: 89 d0 mov %edx,%eax
2c8: 5f pop %edi
2c9: 5d pop %ebp
2ca: c3 ret
000002cb <fork>:
name: \
movl $SYS_ ## name, %eax; \
int $T_SYSCALL; \
ret
SYSCALL(fork)
2cb: b8 01 00 00 00 mov $0x1,%eax
2d0: cd 40 int $0x40
2d2: c3 ret
000002d3 <exit>:
SYSCALL(exit)
2d3: b8 02 00 00 00 mov $0x2,%eax
2d8: cd 40 int $0x40
2da: c3 ret
000002db <wait>:
SYSCALL(wait)
2db: b8 03 00 00 00 mov $0x3,%eax
2e0: cd 40 int $0x40
2e2: c3 ret
000002e3 <pipe>:
SYSCALL(pipe)
2e3: b8 04 00 00 00 mov $0x4,%eax
2e8: cd 40 int $0x40
2ea: c3 ret
000002eb <read>:
SYSCALL(read)
2eb: b8 05 00 00 00 mov $0x5,%eax
2f0: cd 40 int $0x40
2f2: c3 ret
000002f3 <write>:
SYSCALL(write)
2f3: b8 10 00 00 00 mov $0x10,%eax
2f8: cd 40 int $0x40
2fa: c3 ret
000002fb <close>:
SYSCALL(close)
2fb: b8 15 00 00 00 mov $0x15,%eax
300: cd 40 int $0x40
302: c3 ret
00000303 <kill>:
SYSCALL(kill)
303: b8 06 00 00 00 mov $0x6,%eax
308: cd 40 int $0x40
30a: c3 ret
0000030b <exec>:
SYSCALL(exec)
30b: b8 07 00 00 00 mov $0x7,%eax
310: cd 40 int $0x40
312: c3 ret
00000313 <open>:
SYSCALL(open)
313: b8 0f 00 00 00 mov $0xf,%eax
318: cd 40 int $0x40
31a: c3 ret
0000031b <mknod>:
SYSCALL(mknod)
31b: b8 11 00 00 00 mov $0x11,%eax
320: cd 40 int $0x40
322: c3 ret
00000323 <unlink>:
SYSCALL(unlink)
323: b8 12 00 00 00 mov $0x12,%eax
328: cd 40 int $0x40
32a: c3 ret
0000032b <fstat>:
SYSCALL(fstat)
32b: b8 08 00 00 00 mov $0x8,%eax
330: cd 40 int $0x40
332: c3 ret
00000333 <link>:
SYSCALL(link)
333: b8 13 00 00 00 mov $0x13,%eax
338: cd 40 int $0x40
33a: c3 ret
0000033b <mkdir>:
SYSCALL(mkdir)
33b: b8 14 00 00 00 mov $0x14,%eax
340: cd 40 int $0x40
342: c3 ret
00000343 <chdir>:
SYSCALL(chdir)
343: b8 09 00 00 00 mov $0x9,%eax
348: cd 40 int $0x40
34a: c3 ret
0000034b <dup>:
SYSCALL(dup)
34b: b8 0a 00 00 00 mov $0xa,%eax
350: cd 40 int $0x40
352: c3 ret
00000353 <getpid>:
SYSCALL(getpid)
353: b8 0b 00 00 00 mov $0xb,%eax
358: cd 40 int $0x40
35a: c3 ret
0000035b <sbrk>:
SYSCALL(sbrk)
35b: b8 0c 00 00 00 mov $0xc,%eax
360: cd 40 int $0x40
362: c3 ret
00000363 <sleep>:
SYSCALL(sleep)
363: b8 0d 00 00 00 mov $0xd,%eax
368: cd 40 int $0x40
36a: c3 ret
0000036b <uptime>:
SYSCALL(uptime)
36b: b8 0e 00 00 00 mov $0xe,%eax
370: cd 40 int $0x40
372: c3 ret
00000373 <getprocs>:
SYSCALL(getprocs)
373: b8 16 00 00 00 mov $0x16,%eax
378: cd 40 int $0x40
37a: c3 ret
37b: 66 90 xchg %ax,%ax
37d: 66 90 xchg %ax,%ax
37f: 90 nop
00000380 <printint>:
write(fd, &c, 1);
}
static void
printint(int fd, int xx, int base, int sgn)
{
380: 55 push %ebp
381: 89 e5 mov %esp,%ebp
383: 57 push %edi
384: 56 push %esi
385: 53 push %ebx
386: 83 ec 3c sub $0x3c,%esp
389: 89 4d c4 mov %ecx,-0x3c(%ebp)
uint x;
neg = 0;
if(sgn && xx < 0){
neg = 1;
x = -xx;
38c: 89 d1 mov %edx,%ecx
{
38e: 89 45 b8 mov %eax,-0x48(%ebp)
if(sgn && xx < 0){
391: 85 d2 test %edx,%edx
393: 0f 89 7f 00 00 00 jns 418 <printint+0x98>
399: f6 45 08 01 testb $0x1,0x8(%ebp)
39d: 74 79 je 418 <printint+0x98>
neg = 1;
39f: c7 45 bc 01 00 00 00 movl $0x1,-0x44(%ebp)
x = -xx;
3a6: f7 d9 neg %ecx
} else {
x = xx;
}
i = 0;
3a8: 31 db xor %ebx,%ebx
3aa: 8d 75 d7 lea -0x29(%ebp),%esi
3ad: 8d 76 00 lea 0x0(%esi),%esi
do{
buf[i++] = digits[x % base];
3b0: 89 c8 mov %ecx,%eax
3b2: 31 d2 xor %edx,%edx
3b4: 89 cf mov %ecx,%edi
3b6: f7 75 c4 divl -0x3c(%ebp)
3b9: 0f b6 92 b4 07 00 00 movzbl 0x7b4(%edx),%edx
3c0: 89 45 c0 mov %eax,-0x40(%ebp)
3c3: 89 d8 mov %ebx,%eax
3c5: 8d 5b 01 lea 0x1(%ebx),%ebx
}while((x /= base) != 0);
3c8: 8b 4d c0 mov -0x40(%ebp),%ecx
buf[i++] = digits[x % base];
3cb: 88 14 1e mov %dl,(%esi,%ebx,1)
}while((x /= base) != 0);
3ce: 39 7d c4 cmp %edi,-0x3c(%ebp)
3d1: 76 dd jbe 3b0 <printint+0x30>
if(neg)
3d3: 8b 4d bc mov -0x44(%ebp),%ecx
3d6: 85 c9 test %ecx,%ecx
3d8: 74 0c je 3e6 <printint+0x66>
buf[i++] = '-';
3da: c6 44 1d d8 2d movb $0x2d,-0x28(%ebp,%ebx,1)
buf[i++] = digits[x % base];
3df: 89 d8 mov %ebx,%eax
buf[i++] = '-';
3e1: ba 2d 00 00 00 mov $0x2d,%edx
while(--i >= 0)
3e6: 8b 7d b8 mov -0x48(%ebp),%edi
3e9: 8d 5c 05 d7 lea -0x29(%ebp,%eax,1),%ebx
3ed: eb 07 jmp 3f6 <printint+0x76>
3ef: 90 nop
3f0: 0f b6 13 movzbl (%ebx),%edx
3f3: 83 eb 01 sub $0x1,%ebx
write(fd, &c, 1);
3f6: 83 ec 04 sub $0x4,%esp
3f9: 88 55 d7 mov %dl,-0x29(%ebp)
3fc: 6a 01 push $0x1
3fe: 56 push %esi
3ff: 57 push %edi
400: e8 ee fe ff ff call 2f3 <write>
while(--i >= 0)
405: 83 c4 10 add $0x10,%esp
408: 39 de cmp %ebx,%esi
40a: 75 e4 jne 3f0 <printint+0x70>
putc(fd, buf[i]);
}
40c: 8d 65 f4 lea -0xc(%ebp),%esp
40f: 5b pop %ebx
410: 5e pop %esi
411: 5f pop %edi
412: 5d pop %ebp
413: c3 ret
414: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
neg = 0;
418: c7 45 bc 00 00 00 00 movl $0x0,-0x44(%ebp)
41f: eb 87 jmp 3a8 <printint+0x28>
421: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
428: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
42f: 90 nop
00000430 <printf>:
// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, const char *fmt, ...)
{
430: f3 0f 1e fb endbr32
434: 55 push %ebp
435: 89 e5 mov %esp,%ebp
437: 57 push %edi
438: 56 push %esi
439: 53 push %ebx
43a: 83 ec 2c sub $0x2c,%esp
int c, i, state;
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
43d: 8b 75 0c mov 0xc(%ebp),%esi
440: 0f b6 1e movzbl (%esi),%ebx
443: 84 db test %bl,%bl
445: 0f 84 b4 00 00 00 je 4ff <printf+0xcf>
ap = (uint*)(void*)&fmt + 1;
44b: 8d 45 10 lea 0x10(%ebp),%eax
44e: 83 c6 01 add $0x1,%esi
write(fd, &c, 1);
451: 8d 7d e7 lea -0x19(%ebp),%edi
state = 0;
454: 31 d2 xor %edx,%edx
ap = (uint*)(void*)&fmt + 1;
456: 89 45 d0 mov %eax,-0x30(%ebp)
459: eb 33 jmp 48e <printf+0x5e>
45b: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
45f: 90 nop
460: 89 55 d4 mov %edx,-0x2c(%ebp)
c = fmt[i] & 0xff;
if(state == 0){
if(c == '%'){
state = '%';
463: ba 25 00 00 00 mov $0x25,%edx
if(c == '%'){
468: 83 f8 25 cmp $0x25,%eax
46b: 74 17 je 484 <printf+0x54>
write(fd, &c, 1);
46d: 83 ec 04 sub $0x4,%esp
470: 88 5d e7 mov %bl,-0x19(%ebp)
473: 6a 01 push $0x1
475: 57 push %edi
476: ff 75 08 pushl 0x8(%ebp)
479: e8 75 fe ff ff call 2f3 <write>
47e: 8b 55 d4 mov -0x2c(%ebp),%edx
} else {
putc(fd, c);
481: 83 c4 10 add $0x10,%esp
for(i = 0; fmt[i]; i++){
484: 0f b6 1e movzbl (%esi),%ebx
487: 83 c6 01 add $0x1,%esi
48a: 84 db test %bl,%bl
48c: 74 71 je 4ff <printf+0xcf>
c = fmt[i] & 0xff;
48e: 0f be cb movsbl %bl,%ecx
491: 0f b6 c3 movzbl %bl,%eax
if(state == 0){
494: 85 d2 test %edx,%edx
496: 74 c8 je 460 <printf+0x30>
}
} else if(state == '%'){
498: 83 fa 25 cmp $0x25,%edx
49b: 75 e7 jne 484 <printf+0x54>
if(c == 'd'){
49d: 83 f8 64 cmp $0x64,%eax
4a0: 0f 84 9a 00 00 00 je 540 <printf+0x110>
printint(fd, *ap, 10, 1);
ap++;
} else if(c == 'x' || c == 'p'){
4a6: 81 e1 f7 00 00 00 and $0xf7,%ecx
4ac: 83 f9 70 cmp $0x70,%ecx
4af: 74 5f je 510 <printf+0xe0>
printint(fd, *ap, 16, 0);
ap++;
} else if(c == 's'){
4b1: 83 f8 73 cmp $0x73,%eax
4b4: 0f 84 d6 00 00 00 je 590 <printf+0x160>
s = "(null)";
while(*s != 0){
putc(fd, *s);
s++;
}
} else if(c == 'c'){
4ba: 83 f8 63 cmp $0x63,%eax
4bd: 0f 84 8d 00 00 00 je 550 <printf+0x120>
putc(fd, *ap);
ap++;
} else if(c == '%'){
4c3: 83 f8 25 cmp $0x25,%eax
4c6: 0f 84 b4 00 00 00 je 580 <printf+0x150>
write(fd, &c, 1);
4cc: 83 ec 04 sub $0x4,%esp
4cf: c6 45 e7 25 movb $0x25,-0x19(%ebp)
4d3: 6a 01 push $0x1
4d5: 57 push %edi
4d6: ff 75 08 pushl 0x8(%ebp)
4d9: e8 15 fe ff ff call 2f3 <write>
putc(fd, c);
} else {
// Unknown % sequence. Print it to draw attention.
putc(fd, '%');
putc(fd, c);
4de: 88 5d e7 mov %bl,-0x19(%ebp)
write(fd, &c, 1);
4e1: 83 c4 0c add $0xc,%esp
4e4: 6a 01 push $0x1
4e6: 83 c6 01 add $0x1,%esi
4e9: 57 push %edi
4ea: ff 75 08 pushl 0x8(%ebp)
4ed: e8 01 fe ff ff call 2f3 <write>
for(i = 0; fmt[i]; i++){
4f2: 0f b6 5e ff movzbl -0x1(%esi),%ebx
putc(fd, c);
4f6: 83 c4 10 add $0x10,%esp
}
state = 0;
4f9: 31 d2 xor %edx,%edx
for(i = 0; fmt[i]; i++){
4fb: 84 db test %bl,%bl
4fd: 75 8f jne 48e <printf+0x5e>
}
}
}
4ff: 8d 65 f4 lea -0xc(%ebp),%esp
502: 5b pop %ebx
503: 5e pop %esi
504: 5f pop %edi
505: 5d pop %ebp
506: c3 ret
507: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
50e: 66 90 xchg %ax,%ax
printint(fd, *ap, 16, 0);
510: 83 ec 0c sub $0xc,%esp
513: b9 10 00 00 00 mov $0x10,%ecx
518: 6a 00 push $0x0
51a: 8b 5d d0 mov -0x30(%ebp),%ebx
51d: 8b 45 08 mov 0x8(%ebp),%eax
520: 8b 13 mov (%ebx),%edx
522: e8 59 fe ff ff call 380 <printint>
ap++;
527: 89 d8 mov %ebx,%eax
529: 83 c4 10 add $0x10,%esp
state = 0;
52c: 31 d2 xor %edx,%edx
ap++;
52e: 83 c0 04 add $0x4,%eax
531: 89 45 d0 mov %eax,-0x30(%ebp)
534: e9 4b ff ff ff jmp 484 <printf+0x54>
539: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
printint(fd, *ap, 10, 1);
540: 83 ec 0c sub $0xc,%esp
543: b9 0a 00 00 00 mov $0xa,%ecx
548: 6a 01 push $0x1
54a: eb ce jmp 51a <printf+0xea>
54c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
putc(fd, *ap);
550: 8b 5d d0 mov -0x30(%ebp),%ebx
write(fd, &c, 1);
553: 83 ec 04 sub $0x4,%esp
putc(fd, *ap);
556: 8b 03 mov (%ebx),%eax
write(fd, &c, 1);
558: 6a 01 push $0x1
ap++;
55a: 83 c3 04 add $0x4,%ebx
write(fd, &c, 1);
55d: 57 push %edi
55e: ff 75 08 pushl 0x8(%ebp)
putc(fd, *ap);
561: 88 45 e7 mov %al,-0x19(%ebp)
write(fd, &c, 1);
564: e8 8a fd ff ff call 2f3 <write>
ap++;
569: 89 5d d0 mov %ebx,-0x30(%ebp)
56c: 83 c4 10 add $0x10,%esp
state = 0;
56f: 31 d2 xor %edx,%edx
571: e9 0e ff ff ff jmp 484 <printf+0x54>
576: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
57d: 8d 76 00 lea 0x0(%esi),%esi
putc(fd, c);
580: 88 5d e7 mov %bl,-0x19(%ebp)
write(fd, &c, 1);
583: 83 ec 04 sub $0x4,%esp
586: e9 59 ff ff ff jmp 4e4 <printf+0xb4>
58b: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
58f: 90 nop
s = (char*)*ap;
590: 8b 45 d0 mov -0x30(%ebp),%eax
593: 8b 18 mov (%eax),%ebx
ap++;
595: 83 c0 04 add $0x4,%eax
598: 89 45 d0 mov %eax,-0x30(%ebp)
if(s == 0)
59b: 85 db test %ebx,%ebx
59d: 74 17 je 5b6 <printf+0x186>
while(*s != 0){
59f: 0f b6 03 movzbl (%ebx),%eax
state = 0;
5a2: 31 d2 xor %edx,%edx
while(*s != 0){
5a4: 84 c0 test %al,%al
5a6: 0f 84 d8 fe ff ff je 484 <printf+0x54>
5ac: 89 75 d4 mov %esi,-0x2c(%ebp)
5af: 89 de mov %ebx,%esi
5b1: 8b 5d 08 mov 0x8(%ebp),%ebx
5b4: eb 1a jmp 5d0 <printf+0x1a0>
s = "(null)";
5b6: bb ac 07 00 00 mov $0x7ac,%ebx
while(*s != 0){
5bb: 89 75 d4 mov %esi,-0x2c(%ebp)
5be: b8 28 00 00 00 mov $0x28,%eax
5c3: 89 de mov %ebx,%esi
5c5: 8b 5d 08 mov 0x8(%ebp),%ebx
5c8: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
5cf: 90 nop
write(fd, &c, 1);
5d0: 83 ec 04 sub $0x4,%esp
s++;
5d3: 83 c6 01 add $0x1,%esi
5d6: 88 45 e7 mov %al,-0x19(%ebp)
write(fd, &c, 1);
5d9: 6a 01 push $0x1
5db: 57 push %edi
5dc: 53 push %ebx
5dd: e8 11 fd ff ff call 2f3 <write>
while(*s != 0){
5e2: 0f b6 06 movzbl (%esi),%eax
5e5: 83 c4 10 add $0x10,%esp
5e8: 84 c0 test %al,%al
5ea: 75 e4 jne 5d0 <printf+0x1a0>
5ec: 8b 75 d4 mov -0x2c(%ebp),%esi
state = 0;
5ef: 31 d2 xor %edx,%edx
5f1: e9 8e fe ff ff jmp 484 <printf+0x54>
5f6: 66 90 xchg %ax,%ax
5f8: 66 90 xchg %ax,%ax
5fa: 66 90 xchg %ax,%ax
5fc: 66 90 xchg %ax,%ax
5fe: 66 90 xchg %ax,%ax
00000600 <free>:
static Header base;
static Header *freep;
void
free(void *ap)
{
600: f3 0f 1e fb endbr32
604: 55 push %ebp
Header *bp, *p;
bp = (Header*)ap - 1;
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
605: a1 64 0a 00 00 mov 0xa64,%eax
{
60a: 89 e5 mov %esp,%ebp
60c: 57 push %edi
60d: 56 push %esi
60e: 53 push %ebx
60f: 8b 5d 08 mov 0x8(%ebp),%ebx
612: 8b 10 mov (%eax),%edx
bp = (Header*)ap - 1;
614: 8d 4b f8 lea -0x8(%ebx),%ecx
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
617: 39 c8 cmp %ecx,%eax
619: 73 15 jae 630 <free+0x30>
61b: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
61f: 90 nop
620: 39 d1 cmp %edx,%ecx
622: 72 14 jb 638 <free+0x38>
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
624: 39 d0 cmp %edx,%eax
626: 73 10 jae 638 <free+0x38>
{
628: 89 d0 mov %edx,%eax
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
62a: 8b 10 mov (%eax),%edx
62c: 39 c8 cmp %ecx,%eax
62e: 72 f0 jb 620 <free+0x20>
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
630: 39 d0 cmp %edx,%eax
632: 72 f4 jb 628 <free+0x28>
634: 39 d1 cmp %edx,%ecx
636: 73 f0 jae 628 <free+0x28>
break;
if(bp + bp->s.size == p->s.ptr){
638: 8b 73 fc mov -0x4(%ebx),%esi
63b: 8d 3c f1 lea (%ecx,%esi,8),%edi
63e: 39 fa cmp %edi,%edx
640: 74 1e je 660 <free+0x60>
bp->s.size += p->s.ptr->s.size;
bp->s.ptr = p->s.ptr->s.ptr;
} else
bp->s.ptr = p->s.ptr;
642: 89 53 f8 mov %edx,-0x8(%ebx)
if(p + p->s.size == bp){
645: 8b 50 04 mov 0x4(%eax),%edx
648: 8d 34 d0 lea (%eax,%edx,8),%esi
64b: 39 f1 cmp %esi,%ecx
64d: 74 28 je 677 <free+0x77>
p->s.size += bp->s.size;
p->s.ptr = bp->s.ptr;
} else
p->s.ptr = bp;
64f: 89 08 mov %ecx,(%eax)
freep = p;
}
651: 5b pop %ebx
freep = p;
652: a3 64 0a 00 00 mov %eax,0xa64
}
657: 5e pop %esi
658: 5f pop %edi
659: 5d pop %ebp
65a: c3 ret
65b: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
65f: 90 nop
bp->s.size += p->s.ptr->s.size;
660: 03 72 04 add 0x4(%edx),%esi
663: 89 73 fc mov %esi,-0x4(%ebx)
bp->s.ptr = p->s.ptr->s.ptr;
666: 8b 10 mov (%eax),%edx
668: 8b 12 mov (%edx),%edx
66a: 89 53 f8 mov %edx,-0x8(%ebx)
if(p + p->s.size == bp){
66d: 8b 50 04 mov 0x4(%eax),%edx
670: 8d 34 d0 lea (%eax,%edx,8),%esi
673: 39 f1 cmp %esi,%ecx
675: 75 d8 jne 64f <free+0x4f>
p->s.size += bp->s.size;
677: 03 53 fc add -0x4(%ebx),%edx
freep = p;
67a: a3 64 0a 00 00 mov %eax,0xa64
p->s.size += bp->s.size;
67f: 89 50 04 mov %edx,0x4(%eax)
p->s.ptr = bp->s.ptr;
682: 8b 53 f8 mov -0x8(%ebx),%edx
685: 89 10 mov %edx,(%eax)
}
687: 5b pop %ebx
688: 5e pop %esi
689: 5f pop %edi
68a: 5d pop %ebp
68b: c3 ret
68c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
00000690 <malloc>:
return freep;
}
void*
malloc(uint nbytes)
{
690: f3 0f 1e fb endbr32
694: 55 push %ebp
695: 89 e5 mov %esp,%ebp
697: 57 push %edi
698: 56 push %esi
699: 53 push %ebx
69a: 83 ec 1c sub $0x1c,%esp
Header *p, *prevp;
uint nunits;
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
69d: 8b 45 08 mov 0x8(%ebp),%eax
if((prevp = freep) == 0){
6a0: 8b 3d 64 0a 00 00 mov 0xa64,%edi
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
6a6: 8d 70 07 lea 0x7(%eax),%esi
6a9: c1 ee 03 shr $0x3,%esi
6ac: 83 c6 01 add $0x1,%esi
if((prevp = freep) == 0){
6af: 85 ff test %edi,%edi
6b1: 0f 84 a9 00 00 00 je 760 <malloc+0xd0>
base.s.ptr = freep = prevp = &base;
base.s.size = 0;
}
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
6b7: 8b 07 mov (%edi),%eax
if(p->s.size >= nunits){
6b9: 8b 48 04 mov 0x4(%eax),%ecx
6bc: 39 f1 cmp %esi,%ecx
6be: 73 6d jae 72d <malloc+0x9d>
6c0: 81 fe 00 10 00 00 cmp $0x1000,%esi
6c6: bb 00 10 00 00 mov $0x1000,%ebx
6cb: 0f 43 de cmovae %esi,%ebx
p = sbrk(nu * sizeof(Header));
6ce: 8d 0c dd 00 00 00 00 lea 0x0(,%ebx,8),%ecx
6d5: 89 4d e4 mov %ecx,-0x1c(%ebp)
6d8: eb 17 jmp 6f1 <malloc+0x61>
6da: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
6e0: 8b 10 mov (%eax),%edx
if(p->s.size >= nunits){
6e2: 8b 4a 04 mov 0x4(%edx),%ecx
6e5: 39 f1 cmp %esi,%ecx
6e7: 73 4f jae 738 <malloc+0xa8>
6e9: 8b 3d 64 0a 00 00 mov 0xa64,%edi
6ef: 89 d0 mov %edx,%eax
p->s.size = nunits;
}
freep = prevp;
return (void*)(p + 1);
}
if(p == freep)
6f1: 39 c7 cmp %eax,%edi
6f3: 75 eb jne 6e0 <malloc+0x50>
p = sbrk(nu * sizeof(Header));
6f5: 83 ec 0c sub $0xc,%esp
6f8: ff 75 e4 pushl -0x1c(%ebp)
6fb: e8 5b fc ff ff call 35b <sbrk>
if(p == (char*)-1)
700: 83 c4 10 add $0x10,%esp
703: 83 f8 ff cmp $0xffffffff,%eax
706: 74 1b je 723 <malloc+0x93>
hp->s.size = nu;
708: 89 58 04 mov %ebx,0x4(%eax)
free((void*)(hp + 1));
70b: 83 ec 0c sub $0xc,%esp
70e: 83 c0 08 add $0x8,%eax
711: 50 push %eax
712: e8 e9 fe ff ff call 600 <free>
return freep;
717: a1 64 0a 00 00 mov 0xa64,%eax
if((p = morecore(nunits)) == 0)
71c: 83 c4 10 add $0x10,%esp
71f: 85 c0 test %eax,%eax
721: 75 bd jne 6e0 <malloc+0x50>
return 0;
}
}
723: 8d 65 f4 lea -0xc(%ebp),%esp
return 0;
726: 31 c0 xor %eax,%eax
}
728: 5b pop %ebx
729: 5e pop %esi
72a: 5f pop %edi
72b: 5d pop %ebp
72c: c3 ret
if(p->s.size >= nunits){
72d: 89 c2 mov %eax,%edx
72f: 89 f8 mov %edi,%eax
731: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
if(p->s.size == nunits)
738: 39 ce cmp %ecx,%esi
73a: 74 54 je 790 <malloc+0x100>
p->s.size -= nunits;
73c: 29 f1 sub %esi,%ecx
73e: 89 4a 04 mov %ecx,0x4(%edx)
p += p->s.size;
741: 8d 14 ca lea (%edx,%ecx,8),%edx
p->s.size = nunits;
744: 89 72 04 mov %esi,0x4(%edx)
freep = prevp;
747: a3 64 0a 00 00 mov %eax,0xa64
}
74c: 8d 65 f4 lea -0xc(%ebp),%esp
return (void*)(p + 1);
74f: 8d 42 08 lea 0x8(%edx),%eax
}
752: 5b pop %ebx
753: 5e pop %esi
754: 5f pop %edi
755: 5d pop %ebp
756: c3 ret
757: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
75e: 66 90 xchg %ax,%ax
base.s.ptr = freep = prevp = &base;
760: c7 05 64 0a 00 00 68 movl $0xa68,0xa64
767: 0a 00 00
base.s.size = 0;
76a: bf 68 0a 00 00 mov $0xa68,%edi
base.s.ptr = freep = prevp = &base;
76f: c7 05 68 0a 00 00 68 movl $0xa68,0xa68
776: 0a 00 00
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
779: 89 f8 mov %edi,%eax
base.s.size = 0;
77b: c7 05 6c 0a 00 00 00 movl $0x0,0xa6c
782: 00 00 00
if(p->s.size >= nunits){
785: e9 36 ff ff ff jmp 6c0 <malloc+0x30>
78a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
prevp->s.ptr = p->s.ptr;
790: 8b 0a mov (%edx),%ecx
792: 89 08 mov %ecx,(%eax)
794: eb b1 jmp 747 <malloc+0xb7>
|
;-------------------------------------------------------------------
; Praktikum SMD 2015
; M.Wahyudin (140310120031)
;
; Name : LATIH28.ASM (TIMER3)
; Desc : Timer 1 sekon/999424us (mode 2)
; Timer 0 8bit auto diulang 256-134 kali (r6 & r7)
; tidak termasuk header program
; Input : P3.4 masukkan pencacah
; Output: 7Seg(P1)
;-------------------------------------------------------------------
scountL equ 0h ;nilai cacah nibble bawah
scountH equ 10h ;nilai cacah nibble atas
reload equ 86h ;nilai reload TL0 di TH0
mov TMOD,#82h ;konfigurasi timer 0 di mode 2
setb TR0 ;aktifkan timer 0
mov b,#0
mov r6,#scountL ;pencacah software nibble bawah
mov r7,#scountH ;pencacah software nibble atas
mov a,b
lcall display
mov P1,a
mov a,b
loop:
jnb TF0,loop ;ulang hingga timer 0 selesai
clr TF0 ;clear flag overflow timer 0
djnz r6,loop ;kurangi pencacah software hingga 0
mov r6,#scountL ;mereset pencacah software
djnz r7,loop ;kurangi pencacah software hingga 0
mov r7,#scountH ;mereset pencacah software
inc b
anl b,#0Fh
mov a,b
lcall display
mov P1,a
mov a,b
sjmp loop
display:
inc a
movc a,@a+pc
ret
db 3fh ;0
db 06h ;1
db 5bh ;2
db 4fh ;3
db 66h ;4
db 6dh ;5
db 7dh ;6
db 07h ;7
db 7fh ;8
db 67h ;9
db 77h ;a
db 7ch ;b
db 39h ;c
db 5eh ;d
db 79h ;e
db 71h ;f
end
|
; A087215: Lucas(6*n): a(n) = 18*a(n-1) - a(n-2), starting with a(0) = 2 and a(1) = 18.
; 2,18,322,5778,103682,1860498,33385282,599074578,10749957122,192900153618,3461452808002,62113250390418,1114577054219522,20000273725560978,358890350005878082,6440026026380244498,115561578124838522882,2073668380220713167378,37210469265847998489922,667714778405043259651218,11981655542024930675232002,215002084978043708894524818,3858055874062761829426214722,69230003648151669220777340178,1242282009792667284144565908482,22291846172619859445381409012498,400010949097364802732720796316482
mul $0,6
mov $1,2
mov $2,1
lpb $0
sub $0,2
add $1,$2
add $2,$1
lpe
mov $0,$1
|
67_Header:
sHeaderInit ; Z80 offset is $C8C3
sHeaderPatch 67_Patches
sHeaderTick $01
sHeaderCh $01
sHeaderSFX $80, $02, 67_FM3, $2B, $00
67_FM3:
sPatFM $00
67_Loop1:
dc.b nCs1, $02
saVolFM $01
sLoop $00, $08, 67_Loop1
saVolFM $E0
sLoop $00, $05, 67_Loop1
sStop
67_Patches:
; Patch $00
; $35
; $00, $00, $00, $00, $1F, $1F, $1F, $1F
; $00, $00, $00, $00, $00, $00, $00, $00
; $0F, $0F, $0F, $0F, $15, $80, $80, $80
spAlgorithm $05
spFeedback $06
spDetune $00, $00, $00, $00
spMultiple $00, $00, $00, $00
spRateScale $00, $00, $00, $00
spAttackRt $1F, $1F, $1F, $1F
spAmpMod $00, $00, $00, $00
spSustainRt $00, $00, $00, $00
spSustainLv $00, $00, $00, $00
spDecayRt $00, $00, $00, $00
spReleaseRt $0F, $0F, $0F, $0F
spTotalLv $15, $00, $00, $00
|
; Test case:
define kip "hoppa!"
byte kip,0,0,kip
byte "kip"
define one 1
byte one
define one 2
byte one
define val 1
xdefine val val+1 ; c expands to 1+1
byte val
define val 1
assign val val+1 ; c expands to 2
byte val
|
; A048500: a(n) = 2^(n-1)*(7*n-12)+7.
; 1,2,11,43,135,375,967,2375,5639,13063,29703,66567,147463,323591,704519,1523719,3276807,7012359,14942215,31719431,67108871,141557767,297795591,624951303,1308622855,2734686215,5704253447,11878268935,24696061959,51271172103,106300440583,220117073927,455266533383,940597837831,1941325217799,4002909519879,8246337208327,16973710753799,34909494181895,71743133712391,147334558121991,302365697638407,620124558065671,1271035441709063,2603643534573575,5330432371458055
mov $1,1
lpb $0,1
sub $0,1
add $2,$1
add $1,$2
add $1,$0
add $1,$0
add $1,$0
mov $2,$0
lpe
|
; void SMS_hideSprite(unsigned char sprite)
SECTION code_clib
SECTION code_SMSlib
PUBLIC _SMS_hideSprite_fastcall
EXTERN asm_SMSlib_hideSprite
defc _SMS_hideSprite_fastcall = asm_SMSlib_hideSprite
|
// Copyright 2021 Sony Group Corporation. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "include/video_player/video_player_plugin.h"
#include <flutter/basic_message_channel.h>
#include <flutter/encodable_value.h>
#include <flutter/event_channel.h>
#include <flutter/event_stream_handler_functions.h>
#include <flutter/method_channel.h>
#include <flutter/plugin_registrar.h>
#include <flutter/standard_message_codec.h>
#include <flutter/standard_method_codec.h>
#include <unordered_map>
#include "gst_video_player.h"
#include "messages/messages.h"
#include "video_player_stream_handler_impl.h"
namespace {
constexpr char kVideoPlayerApiChannelInitializeName[] =
"dev.flutter.pigeon.VideoPlayerApi.initialize";
constexpr char kVideoPlayerApiChannelSetMixWithOthersName[] =
"dev.flutter.pigeon.VideoPlayerApi.setMixWithOthers";
constexpr char kVideoPlayerApiChannelCreateName[] =
"dev.flutter.pigeon.VideoPlayerApi.create";
constexpr char kVideoPlayerApiChannelDisposeName[] =
"dev.flutter.pigeon.VideoPlayerApi.dispose";
constexpr char kVideoPlayerApiChannelSetLoopingName[] =
"dev.flutter.pigeon.VideoPlayerApi.setLooping";
constexpr char kVideoPlayerApiChannelSetVolumeName[] =
"dev.flutter.pigeon.VideoPlayerApi.setVolume";
constexpr char kVideoPlayerApiChannelPauseName[] =
"dev.flutter.pigeon.VideoPlayerApi.pause";
constexpr char kVideoPlayerApiChannelPlayName[] =
"dev.flutter.pigeon.VideoPlayerApi.play";
constexpr char kVideoPlayerApiChannelPositionName[] =
"dev.flutter.pigeon.VideoPlayerApi.position";
constexpr char kVideoPlayerApiChannelSetPlaybackSpeedName[] =
"dev.flutter.pigeon.VideoPlayerApi.setPlaybackSpeed";
constexpr char kVideoPlayerApiChannelSeekToName[] =
"dev.flutter.pigeon.VideoPlayerApi.seekTo";
constexpr char kVideoPlayerVideoEventsChannelName[] =
"flutter.io/videoPlayer/videoEvents";
constexpr char kEncodableMapkeyResult[] = "result";
constexpr char kEncodableMapkeyError[] = "error";
class VideoPlayerPlugin : public flutter::Plugin {
public:
static void RegisterWithRegistrar(flutter::PluginRegistrar* registrar);
VideoPlayerPlugin(flutter::PluginRegistrar* plugin_registrar,
flutter::TextureRegistrar* texture_registrar)
: plugin_registrar_(plugin_registrar),
texture_registrar_(texture_registrar) {
// Needs to call 'gst_init' that initializing the GStreamer library before
// using it.
GstVideoPlayer::GstLibraryLoad();
}
virtual ~VideoPlayerPlugin() {
for (auto itr = players_.begin(); itr != players_.end(); itr++) {
auto texture_id = itr->first;
auto* player = itr->second.get();
player->event_sink = nullptr;
if (player->event_channel) {
player->event_channel->SetStreamHandler(nullptr);
}
player->player = nullptr;
player->buffer = nullptr;
player->texture = nullptr;
texture_registrar_->UnregisterTexture(texture_id);
}
players_.clear();
GstVideoPlayer::GstLibraryUnload();
}
private:
struct FlutterVideoPlayer {
int64_t texture_id;
std::unique_ptr<GstVideoPlayer> player;
std::unique_ptr<flutter::TextureVariant> texture;
std::unique_ptr<FlutterDesktopPixelBuffer> buffer;
std::unique_ptr<flutter::EventChannel<flutter::EncodableValue>>
event_channel;
std::unique_ptr<flutter::EventSink<flutter::EncodableValue>> event_sink;
};
void HandleInitializeMethodCall(
const flutter::EncodableValue& message,
flutter::MessageReply<flutter::EncodableValue> reply);
void HandleCreateMethodCall(
const flutter::EncodableValue& message,
flutter::MessageReply<flutter::EncodableValue> reply);
void HandleDisposeMethodCall(
const flutter::EncodableValue& message,
flutter::MessageReply<flutter::EncodableValue> reply);
void HandlePauseMethodCall(
const flutter::EncodableValue& message,
flutter::MessageReply<flutter::EncodableValue> reply);
void HandlePlayMethodCall(
const flutter::EncodableValue& message,
flutter::MessageReply<flutter::EncodableValue> reply);
void HandleSetLoopingMethodCall(
const flutter::EncodableValue& message,
flutter::MessageReply<flutter::EncodableValue> reply);
void HandleSetVolumeMethodCall(
const flutter::EncodableValue& message,
flutter::MessageReply<flutter::EncodableValue> reply);
void HandleSetMixWithOthersMethodCall(
const flutter::EncodableValue& message,
flutter::MessageReply<flutter::EncodableValue> reply);
void HandleSetPlaybackSpeedMethodCall(
const flutter::EncodableValue& message,
flutter::MessageReply<flutter::EncodableValue> reply);
void HandleSeekToMethodCall(
const flutter::EncodableValue& message,
flutter::MessageReply<flutter::EncodableValue> reply);
void HandlePositionMethodCall(
const flutter::EncodableValue& message,
flutter::MessageReply<flutter::EncodableValue> reply);
void SendInitializedEventMessage(int64_t texture_id);
void SendPlayCompletedEventMessage(int64_t texture_id);
flutter::EncodableValue WrapError(const std::string& message,
const std::string& code = std::string(),
const std::string& details = std::string());
flutter::PluginRegistrar* plugin_registrar_;
flutter::TextureRegistrar* texture_registrar_;
std::unordered_map<int64_t, std::unique_ptr<FlutterVideoPlayer>> players_;
};
// static
void VideoPlayerPlugin::RegisterWithRegistrar(
flutter::PluginRegistrar* registrar) {
auto plugin = std::make_unique<VideoPlayerPlugin>(
registrar, registrar->texture_registrar());
{
auto channel =
std::make_unique<flutter::BasicMessageChannel<flutter::EncodableValue>>(
registrar->messenger(), kVideoPlayerApiChannelInitializeName,
&flutter::StandardMessageCodec::GetInstance());
channel->SetMessageHandler(
[plugin_pointer = plugin.get()](const auto& message, auto reply) {
plugin_pointer->HandleInitializeMethodCall(message, reply);
});
}
{
auto channel =
std::make_unique<flutter::BasicMessageChannel<flutter::EncodableValue>>(
registrar->messenger(), kVideoPlayerApiChannelCreateName,
&flutter::StandardMessageCodec::GetInstance());
channel->SetMessageHandler(
[plugin_pointer = plugin.get()](const auto& message, auto reply) {
plugin_pointer->HandleCreateMethodCall(message, reply);
});
}
{
auto channel =
std::make_unique<flutter::BasicMessageChannel<flutter::EncodableValue>>(
registrar->messenger(), kVideoPlayerApiChannelDisposeName,
&flutter::StandardMessageCodec::GetInstance());
channel->SetMessageHandler(
[plugin_pointer = plugin.get()](const auto& message, auto reply) {
plugin_pointer->HandleDisposeMethodCall(message, reply);
});
}
{
auto channel =
std::make_unique<flutter::BasicMessageChannel<flutter::EncodableValue>>(
registrar->messenger(), kVideoPlayerApiChannelPauseName,
&flutter::StandardMessageCodec::GetInstance());
channel->SetMessageHandler(
[plugin_pointer = plugin.get()](const auto& message, auto reply) {
plugin_pointer->HandlePauseMethodCall(message, reply);
});
}
{
auto channel =
std::make_unique<flutter::BasicMessageChannel<flutter::EncodableValue>>(
registrar->messenger(), kVideoPlayerApiChannelPlayName,
&flutter::StandardMessageCodec::GetInstance());
channel->SetMessageHandler(
[plugin_pointer = plugin.get()](const auto& message, auto reply) {
plugin_pointer->HandlePlayMethodCall(message, reply);
});
}
{
auto channel =
std::make_unique<flutter::BasicMessageChannel<flutter::EncodableValue>>(
registrar->messenger(), kVideoPlayerApiChannelSetLoopingName,
&flutter::StandardMessageCodec::GetInstance());
channel->SetMessageHandler(
[plugin_pointer = plugin.get()](const auto& message, auto reply) {
plugin_pointer->HandleSetLoopingMethodCall(message, reply);
});
}
{
auto channel =
std::make_unique<flutter::BasicMessageChannel<flutter::EncodableValue>>(
registrar->messenger(), kVideoPlayerApiChannelSetVolumeName,
&flutter::StandardMessageCodec::GetInstance());
channel->SetMessageHandler(
[plugin_pointer = plugin.get()](const auto& message, auto reply) {
plugin_pointer->HandleSetVolumeMethodCall(message, reply);
});
}
{
auto channel =
std::make_unique<flutter::BasicMessageChannel<flutter::EncodableValue>>(
registrar->messenger(), kVideoPlayerApiChannelSetMixWithOthersName,
&flutter::StandardMessageCodec::GetInstance());
channel->SetMessageHandler(
[plugin_pointer = plugin.get()](const auto& message, auto reply) {
plugin_pointer->HandleSetMixWithOthersMethodCall(message, reply);
});
}
{
auto channel =
std::make_unique<flutter::BasicMessageChannel<flutter::EncodableValue>>(
registrar->messenger(), kVideoPlayerApiChannelSetPlaybackSpeedName,
&flutter::StandardMessageCodec::GetInstance());
channel->SetMessageHandler(
[plugin_pointer = plugin.get()](const auto& message, auto reply) {
plugin_pointer->HandleSetPlaybackSpeedMethodCall(message, reply);
});
}
{
auto channel =
std::make_unique<flutter::BasicMessageChannel<flutter::EncodableValue>>(
registrar->messenger(), kVideoPlayerApiChannelSeekToName,
&flutter::StandardMessageCodec::GetInstance());
channel->SetMessageHandler(
[plugin_pointer = plugin.get()](const auto& message, auto reply) {
plugin_pointer->HandleSeekToMethodCall(message, reply);
});
}
{
auto channel =
std::make_unique<flutter::BasicMessageChannel<flutter::EncodableValue>>(
registrar->messenger(), kVideoPlayerApiChannelPositionName,
&flutter::StandardMessageCodec::GetInstance());
channel->SetMessageHandler(
[plugin_pointer = plugin.get()](const auto& message, auto reply) {
plugin_pointer->HandlePositionMethodCall(message, reply);
});
}
registrar->AddPlugin(std::move(plugin));
}
void VideoPlayerPlugin::HandleInitializeMethodCall(
const flutter::EncodableValue& message,
flutter::MessageReply<flutter::EncodableValue> reply) {
flutter::EncodableMap result;
result.emplace(flutter::EncodableValue(kEncodableMapkeyResult),
flutter::EncodableValue());
reply(flutter::EncodableValue(result));
}
void VideoPlayerPlugin::HandleCreateMethodCall(
const flutter::EncodableValue& message,
flutter::MessageReply<flutter::EncodableValue> reply) {
auto meta = CreateMessage::FromMap(message);
std::string uri;
if (!meta.GetAsset().empty()) {
// todo: gets propery path of the Flutter project.
std::string flutter_project_path = "./bundle/data/";
uri = flutter_project_path + "flutter_assets/" + meta.GetAsset();
} else {
uri = meta.GetUri();
}
auto instance = std::make_unique<FlutterVideoPlayer>();
instance->buffer = std::make_unique<FlutterDesktopPixelBuffer>();
instance->texture =
std::make_unique<flutter::TextureVariant>(flutter::PixelBufferTexture(
[instance = instance.get()](
size_t width, size_t height) -> const FlutterDesktopPixelBuffer* {
instance->buffer->width = instance->player->GetWidth();
instance->buffer->height = instance->player->GetHeight();
instance->buffer->buffer = instance->player->GetFrameBuffer();
return instance->buffer.get();
}));
const auto texture_id =
texture_registrar_->RegisterTexture(instance->texture.get());
instance->texture_id = texture_id;
{
auto event_channel =
std::make_unique<flutter::EventChannel<flutter::EncodableValue>>(
plugin_registrar_->messenger(),
kVideoPlayerVideoEventsChannelName + std::to_string(texture_id),
&flutter::StandardMethodCodec::GetInstance());
auto event_channel_handler = std::make_unique<
flutter::StreamHandlerFunctions<flutter::EncodableValue>>(
[instance = instance.get(), host = this](
const flutter::EncodableValue* arguments,
std::unique_ptr<flutter::EventSink<flutter::EncodableValue>>&&
events)
-> std::unique_ptr<
flutter::StreamHandlerError<flutter::EncodableValue>> {
instance->event_sink = std::move(events);
host->SendInitializedEventMessage(instance->texture_id);
return nullptr;
},
[instance = instance.get()](const flutter::EncodableValue* arguments)
-> std::unique_ptr<
flutter::StreamHandlerError<flutter::EncodableValue>> {
instance->event_sink = nullptr;
return nullptr;
});
event_channel->SetStreamHandler(std::move(event_channel_handler));
instance->event_channel = std::move(event_channel);
}
{
auto player_handler = std::make_unique<VideoPlayerStreamHandlerImpl>(
// OnNotifyInitialized
[texture_id, host = this]() {
host->SendInitializedEventMessage(texture_id);
},
// OnNotifyFrameDecoded
[texture_id, host = this]() {
host->texture_registrar_->MarkTextureFrameAvailable(texture_id);
},
// OnNotifyCompleted
[texture_id, host = this]() {
host->SendPlayCompletedEventMessage(texture_id);
});
instance->player =
std::make_unique<GstVideoPlayer>(uri, std::move(player_handler));
players_[texture_id] = std::move(instance);
}
flutter::EncodableMap value;
TextureMessage result;
result.SetTextureId(texture_id);
value.emplace(flutter::EncodableValue(kEncodableMapkeyResult),
result.ToMap());
reply(flutter::EncodableValue(value));
}
void VideoPlayerPlugin::HandleDisposeMethodCall(
const flutter::EncodableValue& message,
flutter::MessageReply<flutter::EncodableValue> reply) {
auto parameter = TextureMessage::FromMap(message);
const auto texture_id = parameter.GetTextureId();
flutter::EncodableMap result;
if (players_.find(texture_id) != players_.end()) {
auto* player = players_[texture_id].get();
player->event_sink = nullptr;
player->event_channel->SetStreamHandler(nullptr);
player->player = nullptr;
player->buffer = nullptr;
player->texture = nullptr;
players_.erase(texture_id);
texture_registrar_->UnregisterTexture(texture_id);
result.emplace(flutter::EncodableValue(kEncodableMapkeyResult),
flutter::EncodableValue());
} else {
auto error_message = "Couldn't find the player with texture id: " +
std::to_string(texture_id);
result.emplace(flutter::EncodableValue(kEncodableMapkeyError),
flutter::EncodableValue(WrapError(error_message)));
}
reply(flutter::EncodableValue(result));
}
void VideoPlayerPlugin::HandlePauseMethodCall(
const flutter::EncodableValue& message,
flutter::MessageReply<flutter::EncodableValue> reply) {
auto parameter = TextureMessage::FromMap(message);
const auto texture_id = parameter.GetTextureId();
flutter::EncodableMap result;
if (players_.find(texture_id) != players_.end()) {
players_[texture_id]->player->Pause();
result.emplace(flutter::EncodableValue(kEncodableMapkeyResult),
flutter::EncodableValue());
} else {
auto error_message = "Couldn't find the player with texture id: " +
std::to_string(texture_id);
result.emplace(flutter::EncodableValue(kEncodableMapkeyError),
flutter::EncodableValue(WrapError(error_message)));
}
reply(flutter::EncodableValue(result));
}
void VideoPlayerPlugin::HandlePlayMethodCall(
const flutter::EncodableValue& message,
flutter::MessageReply<flutter::EncodableValue> reply) {
auto parameter = TextureMessage::FromMap(message);
const auto texture_id = parameter.GetTextureId();
flutter::EncodableMap result;
if (players_.find(texture_id) != players_.end()) {
players_[texture_id]->player->Play();
result.emplace(flutter::EncodableValue(kEncodableMapkeyResult),
flutter::EncodableValue());
} else {
auto error_message = "Couldn't find the player with texture id: " +
std::to_string(texture_id);
result.emplace(flutter::EncodableValue(kEncodableMapkeyError),
flutter::EncodableValue(WrapError(error_message)));
}
reply(flutter::EncodableValue(result));
}
void VideoPlayerPlugin::HandleSetLoopingMethodCall(
const flutter::EncodableValue& message,
flutter::MessageReply<flutter::EncodableValue> reply) {
auto parameter = LoopingMessage::FromMap(message);
const auto texture_id = parameter.GetTextureId();
flutter::EncodableMap result;
if (players_.find(texture_id) != players_.end()) {
players_[texture_id]->player->SetAutoRepeat(parameter.GetIsLooping());
result.emplace(flutter::EncodableValue(kEncodableMapkeyResult),
flutter::EncodableValue());
} else {
auto error_message = "Couldn't find the player with texture id: " +
std::to_string(texture_id);
result.emplace(flutter::EncodableValue(kEncodableMapkeyError),
flutter::EncodableValue(WrapError(error_message)));
}
reply(flutter::EncodableValue(result));
}
void VideoPlayerPlugin::HandleSetVolumeMethodCall(
const flutter::EncodableValue& message,
flutter::MessageReply<flutter::EncodableValue> reply) {
auto parameter = VolumeMessage::FromMap(message);
const auto texture_id = parameter.GetTextureId();
flutter::EncodableMap result;
if (players_.find(texture_id) != players_.end()) {
players_[texture_id]->player->SetVolume(parameter.GetVolume());
result.emplace(flutter::EncodableValue(kEncodableMapkeyResult),
flutter::EncodableValue());
} else {
auto error_message = "Couldn't find the player with texture id: " +
std::to_string(texture_id);
result.emplace(flutter::EncodableValue(kEncodableMapkeyError),
flutter::EncodableValue(WrapError(error_message)));
}
reply(flutter::EncodableValue(result));
}
void VideoPlayerPlugin::HandleSetMixWithOthersMethodCall(
const flutter::EncodableValue& message,
flutter::MessageReply<flutter::EncodableValue> reply) {
// todo: implements here.
flutter::EncodableMap result;
result.emplace(flutter::EncodableValue(kEncodableMapkeyResult),
flutter::EncodableValue());
reply(flutter::EncodableValue(result));
}
void VideoPlayerPlugin::HandlePositionMethodCall(
const flutter::EncodableValue& message,
flutter::MessageReply<flutter::EncodableValue> reply) {
auto parameter = TextureMessage::FromMap(message);
const auto texture_id = parameter.GetTextureId();
flutter::EncodableMap result;
if (players_.find(texture_id) != players_.end()) {
PositionMessage send_message;
send_message.SetTextureId(texture_id);
send_message.SetPosition(
players_[texture_id]->player->GetCurrentPosition());
result.emplace(flutter::EncodableValue(kEncodableMapkeyResult),
send_message.ToMap());
} else {
auto error_message = "Couldn't find the player with texture id: " +
std::to_string(texture_id);
result.emplace(flutter::EncodableValue(kEncodableMapkeyError),
flutter::EncodableValue(WrapError(error_message)));
}
reply(flutter::EncodableValue(result));
}
void VideoPlayerPlugin::HandleSetPlaybackSpeedMethodCall(
const flutter::EncodableValue& message,
flutter::MessageReply<flutter::EncodableValue> reply) {
auto parameter = PlaybackSpeedMessage::FromMap(message);
const auto texture_id = parameter.GetTextureId();
flutter::EncodableMap result;
if (players_.find(texture_id) != players_.end()) {
players_[texture_id]->player->SetPlaybackRate(parameter.GetSpeed());
result.emplace(flutter::EncodableValue(kEncodableMapkeyResult),
flutter::EncodableValue());
} else {
auto error_message = "Couldn't find the player with texture id: " +
std::to_string(texture_id);
result.emplace(flutter::EncodableValue(kEncodableMapkeyError),
flutter::EncodableValue(WrapError(error_message)));
}
reply(flutter::EncodableValue(result));
}
void VideoPlayerPlugin::HandleSeekToMethodCall(
const flutter::EncodableValue& message,
flutter::MessageReply<flutter::EncodableValue> reply) {
auto parameter = PositionMessage::FromMap(message);
const auto texture_id = parameter.GetTextureId();
flutter::EncodableMap result;
if (players_.find(texture_id) != players_.end()) {
players_[texture_id]->player->SetSeek(parameter.GetPosition());
result.emplace(flutter::EncodableValue(kEncodableMapkeyResult),
flutter::EncodableValue());
} else {
auto error_message = "Couldn't find the player with texture id: " +
std::to_string(texture_id);
result.emplace(flutter::EncodableValue(kEncodableMapkeyError),
flutter::EncodableValue(WrapError(error_message)));
}
reply(flutter::EncodableValue(result));
}
void VideoPlayerPlugin::SendInitializedEventMessage(int64_t texture_id) {
if (players_.find(texture_id) == players_.end() ||
!players_[texture_id]->event_sink) {
return;
}
auto duration = players_[texture_id]->player->GetDuration();
auto width = players_[texture_id]->player->GetWidth();
auto height = players_[texture_id]->player->GetHeight();
flutter::EncodableMap encodables = {
{flutter::EncodableValue("event"),
flutter::EncodableValue("initialized")},
{flutter::EncodableValue("duration"), flutter::EncodableValue(duration)},
{flutter::EncodableValue("width"), flutter::EncodableValue(width)},
{flutter::EncodableValue("height"), flutter::EncodableValue(height)}};
flutter::EncodableValue event(encodables);
players_[texture_id]->event_sink->Success(event);
}
void VideoPlayerPlugin::SendPlayCompletedEventMessage(int64_t texture_id) {
if (players_.find(texture_id) == players_.end() ||
!players_[texture_id]->event_sink) {
return;
}
flutter::EncodableMap encodables = {
{flutter::EncodableValue("event"), flutter::EncodableValue("completed")}};
flutter::EncodableValue event(encodables);
players_[texture_id]->event_sink->Success(event);
}
flutter::EncodableValue VideoPlayerPlugin::WrapError(
const std::string& message, const std::string& code,
const std::string& details) {
flutter::EncodableMap map = {
{flutter::EncodableValue("message"), flutter::EncodableValue(message)},
{flutter::EncodableValue("code"), flutter::EncodableValue(code)},
{flutter::EncodableValue("details"), flutter::EncodableValue(details)}};
return flutter::EncodableValue(map);
}
} // namespace
void VideoPlayerPluginRegisterWithRegistrar(
FlutterDesktopPluginRegistrarRef registrar) {
VideoPlayerPlugin::RegisterWithRegistrar(
flutter::PluginRegistrarManager::GetInstance()
->GetRegistrar<flutter::PluginRegistrar>(registrar));
}
|
; Project DC 2002
; Hexadecimal View: functions, scroll, Options, etc
.model small
.stack 80h
HexQuanta equ 250h
line_count equ 25
at_Main equ 1Bh
at_Status equ 0B1h
.data
sModeHex db "Hex:",0
HintBar db "Help ",0," ",0," ",0,"Mode ",0,"GoTo ",0," ",0," ",0," ",0,"Open ",0,"Quit "
s_Separate1 db " ",0b3h," "
EXTRN LineBuffer:Byte, ViewOffset:DWORD, Filename24:Byte, sAppTitle:byte, RFileSize:DWORD
.code
.386
include base.inc
EXTRN GetDiskBuffer:PROC, DisplayHintBar: PROC
PUBLIC UpdateHexView, Hex_LineDown, Hex_LineUp, Hex_PageDown, Hex_PageUp
Hex_LineDown PROC
mov eax, ViewOffset
add eax, 16
mov edx, eax
and dl, 0f0h
cmp edx, RFileSize
ja @HexLD_Done
mov ViewOffset, eax
@HexLD_Done:
ret
Hex_LineDown ENDP
Hex_PageDown PROC
mov eax, ViewOffset
add eax, 16*(line_count-2)
mov edx, eax
and dl, 0f0h
cmp edx, RFileSize
ja @HexPD_Done
mov ViewOffset, eax
@HexPD_Done:
ret
Hex_PageDown ENDP
Hex_PageUp PROC
mov eax, ViewOffset
sub eax, 16*(line_count-2)
mov edx, eax
and dl, 0f0h
test edx, edx
jge @HexPU_Done
xor eax, eax
@HexPU_Done:
mov ViewOffset, eax
ret
Hex_PageUp ENDP
Hex_LineUp PROC
mov eax, ViewOffset
sub eax, 16
test eax, eax
jl @HexLU_Done
mov ViewOffset, eax
@HexLU_Done:
ret
Hex_LineUp ENDP
; Procedure HexView
; Purpose Display currently open file from given offset
; Input FileSize - (Mem) Size of opened file
; ViewOffset - (Mem) Offset to start displaying from
; Output Lines 1-23 filled with Hext from opened file, offset ViewOffset
UpdateHexView PROC
; Create stack frame for locals
push bp
mov bp, sp
RequestLoc equ [bp-4] ; Location to request from file buffers
CurrentLoc equ [bp-8] ; Offset of bytes being sent to output
BufferLimit equ [bp-0Ah]
ThisLine equ [bp-0Ch]
sub sp, 0Ch
mov edx, ViewOffset
and edx, 0fffffff0h ; lose lowest tetrad
mov CurrentLoc, edx ; (output is 16 bytes-aligned)
mov RequestLoc, edx
call HexViewStatus
mov word ptr ThisLine, 01h
@HexV_LoadBuffer:
mov edx, RequestLoc
mov cx, HexQuanta
call GetDiskBuffer ; Should return adress in ds:si, characters in cx
test cx, cx
jz @HexV_Fill ; End draw if nothing else is on buffer
; might be caused by EOF or other errors
@HexV_BufferCheck:
; Fix cur_loc
mov edx, RequestLoc
cmp cx, 10h
jb @HexV_LastLine
and ecx, 0fff0h
add edx, ecx
mov RequestLoc, edx
add cx, si ; End of valid data block
mov BufferLimit, cx
@HexV_Next16:
cmp word ptr ThisLine, line_count-1 ; if there are enough lines on screen,
jae @HexV_Done ; we are done
cmp si, BufferLimit ; Check buffer underrun
jae @HexV_LoadBuffer ; Try to load more if still needed
@HexV_LineStart:
push es
push ds ; es should keep video page offset for a while
pop es ; es is data
mov LineBuffer, 0 ; Clear current line buffer
lea di, LineBuffer
mov eax, CurrentLoc
call Int2Hex32
mov dword ptr [di-1], ' :' ; write ": " instead of zero-terminator
add di,2 ; increment di accordingly
push si
mov cx, 10h
@HexV_HexData:
lodsb ; Load current character
call Int2Hex8
mov byte ptr [di-1], ' ' ; Make space instead of zero-byte
cmp cl,9
jnz @HexV_HexDelim
mov al, ' '
stosb
@HexV_HexDelim:
loop @HexV_HexData
;@HexV_CharData:
dec di
mov eax, dword ptr s_Separate1
stosd
pop si
mov cx, 4h
rep movsd
xor ax, ax
stosb
@HexV_OutputBuffer:
mov eax, CurrentLoc
add eax, 10h
mov CurrentLoc, eax
pop es
push si
mov ax, ThisLine
xchg al, ah
call GetVideoOffset
mov di, ax
lea si, LineBuffer
mov cx, 80
mov ah, at_Main
call OutCharsAt_x
inc word ptr ThisLine
pop si
jmp @HexV_Next16
@HexV_LastLine:
push es
push ds ; es should keep video page offset for a while
pop es ; es is data
mov LineBuffer, 0 ; Clear current line buffer
lea di, LineBuffer
push cx
mov eax, CurrentLoc
call Int2Hex32
mov dword ptr [di-1], ' :' ; write ": " instead of zero-terminator
add di,2 ; increment di accordingly
pop cx
push cx
push si
mov dx, 16
@HexV_HexLast:
lodsb ; Load current character
call Int2Hex8
mov byte ptr [di-1], ' ' ; Make space instead of zero-byte
cmp dl, 9
jnz @HexV_HexLD
mov al, ' '
stosb
@HexV_HexLD:
dec dx
loop @HexV_HexLast
@HexV_LastChars:
xor ax, ax ; Need to mark line-end
stosb ; before call to "FillUp"
lea di, LineBuffer
mov cx, 59
mov al, ' '
call sFillUp
dec di
mov eax, ' | '
stosd
pop si
pop cx
push cx
rep movsb
xor ax, ax
stosb
;@HexV_OutputLastBuffer:
mov cx, 80-16-1 ; width - 16chars area - 1 space
pop ax
add cx, ax
mov ax, ThisLine
xchg al, ah
call GetVideoOffset
mov di, ax
mov ah, At_Main
lea si, LineBuffer
pop es
call OutCharsAt_x
jmp @HexV_FillEx
@HexV_Fill:
mov ax, ThisLine
xchg al, ah
call GetVideoOffset
mov di, ax
@HexV_FillEx:
mov ax, at_Main*256 + 32
mov dx, 1800h
call FillUpAt
@HexV_Done:
mov sp,bp
pop bp
lea si, HintBar
call DisplayHintbar
ret
UpdateHexView endp
HexViewStatus PROC
push es
push ds
pop es
; Status line
lea di, LineBuffer ; Output Mode Name
lea si, sModeHex
call strcpy_x
lea di, LineBuffer ; Tabulate 8
mov cx, 8
mov al, 32
call sFillUp
dec di
lea si, Filename24 ; Output Filename short format
call strcpy_x
mov ax, 32 ; tabulate 36
mov cx, 36
lea di, LineBuffer
call sFillUp
dec di
mov eax, ViewOffset ; Out currently viewed location
call Int2Hex32
mov byte ptr [di-1],'/'
mov eax, RFileSize
call Int2Hex32
mov ax, 32 ; Tabulate 60
mov cx, 60
lea di, LineBuffer
call sFillUp
dec di
lea si, sAppTitle ; Append AppName
call strcpy_x
pop es ; Send to video
xor di, di
lea si, LineBuffer
mov cx, 80
mov ah, at_Status
call OutCharsAt_x
ret
HexViewStatus ENDP
end |
#ruledef reg
{
a => 0xaa
b => 0xbb
}
#ruledef
{
emit {r: reg} => r`8
test {r: reg} => asm { emit {r} }
}
emit a ; = 0xaa
emit b ; = 0xbb
test a ; = 0xaa
test b ; = 0xbb |
; A021289: Decimal expansion of 1/285.
; Submitted by Jon Maiga
; 0,0,3,5,0,8,7,7,1,9,2,9,8,2,4,5,6,1,4,0,3,5,0,8,7,7,1,9,2,9,8,2,4,5,6,1,4,0,3,5,0,8,7,7,1,9,2,9,8,2,4,5,6,1,4,0,3,5,0,8,7,7,1,9,2,9,8,2,4,5,6,1,4,0,3,5,0,8,7,7,1,9,2,9,8,2,4,5,6,1,4,0,3,5,0,8,7,7,1
seq $0,173833 ; 10^n - 3.
div $0,285
mod $0,10
|
/*
*
* Copyright (c) 2020 vesoft inc. All rights reserved.
*
* This source code is licensed under Apache 2.0 License.
*
*/
#include "common/geo/GeoIndex.h"
#include <folly/String.h>
#include <folly/hash/Hash.h>
#include <s2/mutable_s2shape_index.h>
#include <s2/s2cap.h>
#include <s2/s2cell.h>
#include <s2/s2cell_id.h>
#include <s2/s2earth.h>
#include <s2/s2latlng.h>
#include <s2/s2polygon.h>
#include <s2/s2region_coverer.h>
#include <s2/s2shape_index_buffered_region.h>
#include <s2/util/units/length-units.h>
#include <cstdint>
#include "common/datatypes/Geography.h"
#include "common/utils/IndexKeyUtils.h"
#include "interface/gen-cpp2/storage_types.h"
namespace nebula {
namespace geo {
bool ScanRange::operator==(const ScanRange& rhs) const {
if (isRangeScan != rhs.isRangeScan) {
return false;
}
if (isRangeScan) {
return rangeMin == rhs.rangeMin && rangeMax == rhs.rangeMax;
}
return rangeMin == rhs.rangeMin;
}
nebula::storage::cpp2::IndexColumnHint ScanRange::toIndexColumnHint() const {
nebula::storage::cpp2::IndexColumnHint hint;
// column_name should be set by the caller
if (isRangeScan) {
hint.set_scan_type(nebula::storage::cpp2::ScanType::RANGE);
// Encode uint64_t as string in advance
hint.set_begin_value(IndexKeyUtils::encodeUint64(rangeMin));
hint.set_end_value(IndexKeyUtils::encodeUint64(rangeMax));
hint.set_include_begin(true);
hint.set_include_end(true);
} else {
hint.set_scan_type(nebula::storage::cpp2::ScanType::PREFIX);
hint.set_begin_value(IndexKeyUtils::encodeUint64(rangeMin));
}
return hint;
}
std::vector<uint64_t> GeoIndex::indexCells(const Geography& g) const noexcept {
auto r = g.asS2();
if (UNLIKELY(!r)) {
return {};
}
auto cells = coveringCells(*r, g.shape() == GeoShape::POINT);
std::vector<uint64_t> cellIds;
cellIds.reserve(cells.size());
for (auto& cell : cells) {
cellIds.push_back(cell.id());
}
return cellIds;
}
std::vector<ScanRange> GeoIndex::intersects(const Geography& g) const noexcept {
auto r = g.asS2();
if (UNLIKELY(!r)) {
return {};
}
return intersects(*r, g.shape() == GeoShape::POINT);
}
// covers degenerates to intersects currently
std::vector<ScanRange> GeoIndex::covers(const Geography& g) const noexcept { return intersects(g); }
// coveredBy degenerates to intersects currently
std::vector<ScanRange> GeoIndex::coveredBy(const Geography& g) const noexcept {
return intersects(g);
}
std::vector<ScanRange> GeoIndex::dWithin(const Geography& g, double distance) const noexcept {
auto r = g.asS2();
if (UNLIKELY(!r)) {
return {};
}
S1Angle radius = S2Earth::ToAngle(util::units::Meters(distance));
// First expand the region, then build the covering
switch (g.shape()) {
case GeoShape::POINT: {
const S2Point& gPoint = static_cast<S2PointRegion*>(r.get())->point();
S2Cap gCap(gPoint, radius);
return intersects(gCap);
}
case GeoShape::LINESTRING: {
S2Polyline* gLine = static_cast<S2Polyline*>(r.get());
MutableS2ShapeIndex index;
index.Add(std::make_unique<S2Polyline::Shape>(gLine));
S2ShapeIndexBufferedRegion gBuffer(&index, radius);
return intersects(gBuffer);
}
case GeoShape::POLYGON: {
S2Polygon* gPolygon = static_cast<S2Polygon*>(r.get());
S2ShapeIndexBufferedRegion gBuffer(&gPolygon->index(), radius);
return intersects(gBuffer);
}
default:
LOG(FATAL)
<< "Geography shapes other than Point/LineString/Polygon are not currently supported";
return {};
}
}
std::vector<ScanRange> GeoIndex::intersects(const S2Region& r, bool isPoint) const noexcept {
auto cells = coveringCells(r, isPoint);
std::vector<ScanRange> scanRanges;
for (const S2CellId& cellId : cells) {
if (cellId.is_leaf()) {
scanRanges.emplace_back(cellId.id());
} else {
scanRanges.emplace_back(cellId.range_min().id(), cellId.range_max().id());
}
}
// For the indexed column which only contains point, we don't need to get the ancestor cells,
// because the point is at max level(30).
if (!pointsOnly_) {
auto ancestors = ancestorCells(cells);
for (const S2CellId& cellId : ancestors) {
scanRanges.emplace_back(cellId.id());
}
}
return scanRanges;
}
std::vector<S2CellId> GeoIndex::coveringCells(const S2Region& r, bool isPoint) const noexcept {
// Currently we don't apply region coverer params to point, because it's useless.
// Point always use level 30.
if (isPoint) {
const S2Point& gPoint = static_cast<const S2PointRegion*>(&r)->point();
return {S2CellId(gPoint)};
}
S2RegionCoverer rc(rcParams_.s2RegionCovererOpts());
std::vector<S2CellId> covering;
rc.GetCovering(r, &covering);
// 1. NO NEED TO CALL S2RegionCoverer::CanonicalizeCovering(covering), because the covering is
// already canonical, which means that is sorted, non-overlapping and satisfy the desired
// constraints min_level, max_level.
// 2. DO NOT CALL S2CellUnion::Normalize(covering), it will replacing groups of 4 child cells by
// their parent cell, In this case, it may cause the covering don't satisfy the desired
// constraints min_level.
return covering;
}
std::vector<S2CellId> GeoIndex::ancestorCells(const std::vector<S2CellId>& cells) const noexcept {
// DCHECK(rc.IsCanonical(cells));
std::vector<S2CellId> ancestors;
std::unordered_set<S2CellId> seen;
for (const auto& cellId : cells) {
for (auto l = cellId.level() - 1; l >= rcParams_.minCellLevel_; --l) {
S2CellId parentCellId = cellId.parent(l);
if (seen.find(parentCellId) != seen.end()) {
break;
}
seen.emplace(parentCellId);
ancestors.push_back(parentCellId);
}
}
// The ancestors here is non-overlapping but unsorted. Do we need to sort it?
// May need to call S2RegionCoverer::CanonicalizeCovering(&ancestors)?
return ancestors;
}
} // namespace geo
} // namespace nebula
namespace std {
// Inject a customized hash function
std::size_t hash<S2CellId>::operator()(const S2CellId& c) const noexcept {
return hash<uint64_t>{}(c.id());
}
} // namespace std
|
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#include "pal_asn1_print.h"
static_assert(PAL_B_ASN1_NUMERICSTRING == B_ASN1_NUMERICSTRING, "");
static_assert(PAL_B_ASN1_PRINTABLESTRING == B_ASN1_PRINTABLESTRING, "");
static_assert(PAL_B_ASN1_T61STRING == B_ASN1_T61STRING, "");
static_assert(PAL_B_ASN1_VIDEOTEXSTRING == B_ASN1_VIDEOTEXSTRING, "");
static_assert(PAL_B_ASN1_IA5STRING == B_ASN1_IA5STRING, "");
static_assert(PAL_B_ASN1_GRAPHICSTRING == B_ASN1_GRAPHICSTRING, "");
static_assert(PAL_B_ASN1_VISIBLESTRING == B_ASN1_VISIBLESTRING, "");
static_assert(PAL_B_ASN1_GENERALSTRING == B_ASN1_GENERALSTRING, "");
static_assert(PAL_B_ASN1_UNIVERSALSTRING == B_ASN1_UNIVERSALSTRING, "");
static_assert(PAL_B_ASN1_OCTET_STRING == B_ASN1_OCTET_STRING, "");
static_assert(PAL_B_ASN1_BIT_STRING == B_ASN1_BIT_STRING, "");
static_assert(PAL_B_ASN1_BMPSTRING == B_ASN1_BMPSTRING, "");
static_assert(PAL_B_ASN1_UNKNOWN == B_ASN1_UNKNOWN, "");
static_assert(PAL_B_ASN1_UTF8STRING == B_ASN1_UTF8STRING, "");
static_assert(PAL_B_ASN1_UTCTIME == B_ASN1_UTCTIME, "");
static_assert(PAL_B_ASN1_GENERALIZEDTIME == B_ASN1_GENERALIZEDTIME, "");
static_assert(PAL_B_ASN1_SEQUENCE == B_ASN1_SEQUENCE, "");
static_assert(PAL_ASN1_STRFLGS_UTF8_CONVERT == ASN1_STRFLGS_UTF8_CONVERT, "");
extern "C" ASN1_STRING* CryptoNative_DecodeAsn1TypeBytes(const uint8_t* buf, int32_t len, Asn1StringTypeFlags type)
{
if (!buf || !len)
{
return nullptr;
}
return d2i_ASN1_type_bytes(nullptr, &buf, len, type);
}
extern "C" int32_t CryptoNative_Asn1StringPrintEx(BIO* out, ASN1_STRING* str, Asn1StringPrintFlags flags)
{
return ASN1_STRING_print_ex(out, str, flags);
}
|
; A276878: Sums-complement of the Beatty sequence for 2*Pi.
; 1,2,3,4,5,8,9,10,11,14,15,16,17,20,21,22,23,24,27,28,29,30,33,34,35,36,39,40,41,42,45,46,47,48,49,52,53,54,55,58,59,60,61,64,65,66,67,68,71,72,73,74,77,78,79,80,83,84,85,86,89,90,91,92,93,96
mov $1,2
mov $2,$0
mul $2,7
div $2,5
mov $3,$2
div $3,6
mul $1,$3
add $1,1
add $1,$0
|
.target "6502"
.format "nes"
.setting "NESMapper", 0
.setting "NESVerticalMirroring", true
.setting "ShowLabelsAfterCompiling", true
.setting "ShowLocalLabelsAfterCompiling", true
.setting "LaunchCommand", "c:\\emulation\\fceux.exe {0}"
.setting "DebugCommand", "c:\\emulation\\fceux.exe {0}"
.segment "RAM"
.org $0000 ;;start variables at ram location 0
joypad1 .ds 1 ;button states for the current frame
joypad1_old .ds 1 ;last frame's button states
joypad1_pressed .ds 1 ;current frame's off_to_on transitions
sleeping .ds 1 ;main program sets this and waits for the NMI to clear it. Ensures the main program is run only once per frame.
; for more information, see Disch's document: http://nesdevhandbook.googlepages.com/theframe.html
needdraw .ds 1 ;drawing flag.
dbuffer_index .ds 1 ;current position in the drawing buffer
ptr1 .ds 2 ;a pointer
sound_ptr .ds 2
sound_ptr2 .ds 2
current_song .ds 1
.include "drums_sound_engine_vars.6502.asm"
.bank 0, 16, $8000, "NES_PRG0"
.segment "SOUND_CODE"
.org $8000 ;we have two 16k PRG banks now. We will stick our sound engine in the first one, which starts at $8000.
.include "drums_sound_engine.6502.asm"
.bank 1, 16, $C000, "NES_PRG1"
.segment "MAIN_CODE"
.org $C000
irq:
rti
NMI:
pha ;save registers
txa
pha
tya
pha
;do sprite DMA
;update palettes if needed
;draw stuff on the screen
lda needdraw
beq @drawing_done ;if drawing flag is clear, skip drawing
lda $2002 ;else, draw
jsr draw_dbuffer
lda #$00 ;finished drawing, so clear drawing flag
sta needdraw
@drawing_done:
lda #$00
sta $2005
sta $2005 ;set scroll
jsr sound_play_frame ;run our sound engine after all drawing code is done.
;this ensures our sound engine gets run once per frame.
lda #$00
sta sleeping ;wake up the main program
pla ;restore registers
tay
pla
tax
pla
rti
RESET:
sei
cld
ldx #$FF
txs
inx
vblankwait1:
bit $2002
bpl vblankwait1
clearmem:
lda #$00
sta $0000, x
sta $0100, x
sta $0300, x
sta $0400, x
sta $0500, x
sta $0600, x
sta $0700, x
lda #$FE
sta $0200, x
inx
bne clearmem
vblankwait2:
bit $2002
bpl vblankwait2
;set a couple palette colors. This demo only uses two
lda $2002 ;reset PPU HI/LO latch
lda #$3F
sta $2006
lda #$00
sta $2006 ;palette data starts at $3F00
lda #$0F ;black
sta $2007
lda #$30 ;white
sta $2007
jsr draw_background
;Enable sound channels
jsr sound_init
lda #$01
sta current_song
;jsr sound_load
lda #$88
sta $2000 ;enable NMIs
lda #$18
sta $2001 ;turn PPU on
forever:
inc sleeping ;go to sleep (wait for NMI).
@loop:
lda sleeping
bne @loop ;wait for NMI to clear the sleeping flag and wake us up
;when NMI wakes us up, handle input, fill the drawing buffer and go back to sleep
jsr read_joypad
jsr handle_input
jsr prepare_dbuffer
jmp forever ;go back to sleep
;----------------------------
; read_joypad will capture the current button state and store it in joypad1.
; Off-to-on transitions will be stored in joypad1_pressed
read_joypad:
lda joypad1
sta joypad1_old ;save last frame's joypad button states
lda #$01
sta $4016
lda #$00
sta $4016
ldx #$08
@loop:
lda $4016
lsr a
rol joypad1 ;A, B, select, start, up, down, left, right
dex
bne @loop
lda joypad1_old ;what was pressed last frame. EOR to flip all the bits to find ...
eor #$FF ;what was not pressed last frame
and joypad1 ;what is pressed this frame
sta joypad1_pressed ;stores off-to-on transitions
rts
;---------------------
; handle_input will perform actions based on input:
; up - play current song
; down - stop playing the song
; left - cycle down a song
; right - cycle up a song
handle_input:
lda joypad1_pressed
and #$0F ;check d-pad only
beq @done
@check_up:
and #$08 ;up
beq @check_down
lda current_song
jsr sound_load
@check_down:
lda joypad1_pressed
and #$04 ;down
beq @check_left
lda #$00
jsr sound_load
@check_left:
lda joypad1_pressed
and #$02 ;left
beq @check_right
jsr song_down
@check_right:
lda joypad1_pressed
and #$01 ;right
beq @done
jsr song_up
@done:
rts
;--------------------
; song_down will move selection down a song. Song 1 wraps around to last song
song_down:
dec current_song
lda current_song
bne @done
lda #NUM_SONGS-1 ;last song. We wrapped from Song 1
sta current_song
@done:
rts
;----------------------
; song_up will move selection up a song. Last song will wrap to song 1
song_up:
inc current_song
lda current_song
cmp #NUM_SONGS ;did we move past the last song?
bne @done ;if not, no problem
lda #$01 ;but if we did, wrap around to song 1
sta current_song
@done:
rts
;-------------------------------
; prepare_dbuffer fills the drawing buffer with the text strings we need
prepare_dbuffer:
;write either "playing" or "not playing" to the dbuffer
lda stream_status
ora stream_status+1
ora stream_status+2
ora stream_status+3
ora stream_status+4
ora stream_status+5
and #$01
beq @sound_not_playing ;if all streams disabled, write "NOT PLAYING" on the screen
lda sound_disable_flag
bne @sound_not_playing ;if the disable flag is set, we want to write "NOT PLAYING" too
@sound_playing:
lda #<text_playing ;set ptr1 to point to beginning of text string
sta ptr1
lda #>text_playing
sta ptr1+1
jmp @dbuffer
@sound_not_playing:
lda #<text_not_playing
sta ptr1
lda #>text_not_playing
sta ptr1+1
@dbuffer:
lda #$21 ;target PPU address. add_to_dbuffer expects the HI byte in A and the LO byte in Y
ldy #$0B
jsr add_to_dbuffer
jsr song_num_to_dbuffer
lda #$01
sta needdraw ;set drawing flag so the NMI knows to draw
rts
;-------------------------
; add_to_dbuffer will convert a text string into a dbuffer string and add it to the drawing buffer.
; add_to_dbuffer expects:
; HI byte of the target PPU address in A,
; LO byte of the target PPU address in Y
; pointer to the source text string in ptr1
; dbuffer string format:
; byte 0: length of data (ie, length of the text string)
; byte 1-2: target PPU address (HI byte first)
; byte 3-n: bytes to copy
; Note: dbuffer starts at $0100. This is the stack page. The
; stack counts backwards from $1FF, and this program is small enough that there
; will never be a conflcit. But for larger programs, watch out.
add_to_dbuffer:
ldx dbuffer_index
sta $0101, x ;write target PPU address to dbuffer
tya
sta $0102, x
ldy #$00
@loop:
lda (ptr1), y
cmp #$FF
beq @done
sta $0103, x ;copy the text string to dbuffer,
iny
inx
bne @loop
@done:
ldx dbuffer_index
tya
sta $0100, x ;store string length at the beginning of the string header
clc
adc dbuffer_index
adc #$03
sta dbuffer_index ;update buffer index. new index = old index + 3-byte header + string length
tax
lda #$00
sta $0100, x ;stick a 0 on the end to terminate dbuffer.
rts
;----------------------------------------------
; song_num_to_dbuffer tells the drawing buffer to write the currently selected song number on the screen.
song_num_to_dbuffer:
ldx dbuffer_index
lda #$01 ;write one byte
sta $0100, x
lda #$21 ;destination PPU $214A
sta $0101, x
lda #$4A
sta $0102, x
lda current_song ;which byte to write
sta $0103, x
lda #$00 ;terminate the dbuffer with 0
sta $0104,x
txa ;update our index
clc
adc #$04
sta dbuffer_index
rts
;------------------------
; draw_dbuffer will write the contents of the drawing buffer to the PPU
; dbuffer is made up of a series of drawing strings. dbuffer is 0-terminated.
; See add_to_dbuffer for drawing string format.
draw_dbuffer:
ldy #$00
@header_loop:
lda $0100, y
beq @done ;if 0, we are at the end of the dbuffer, so quit
tax ;else this is how many bytes we want to copy to the PPU
iny
lda $0100, y ;set the target PPU address
sta $2006
iny
lda $0100, y
sta $2006
iny
@copy_loop:
lda $0100, y ;copy the contents of the drawing string to PPU
sta $2007
iny
dex
bne @copy_loop
beq @header_loop ;when we finish copying, see if there is another drawing string.
@done:
ldy #$00
sty dbuffer_index ;reset index and "empty" the dbuffer by sticking a zero in the first position
sty $0100
rts
;----------------------------
; draw_background will draw some background strings on the screen
; this hard-coded routine is called only once in RESET
draw_background:
lda #$21
sta $2006
lda #$04
sta $2006
ldy #$00
@loop:
lda text_sound, y
bmi @sound_done
sta $2007
iny
bne @loop
@sound_done:
lda #$21
sta $2006
lda #$44
sta $2006
ldy #$00
@loop2:
lda text_song, y
bmi @done
sta $2007
iny
bne @loop2
@done:
rts
;these are our text strings. They are all terminated by $FF
text_song:
.byte $22, $1E, $1D, $16, $0D, $FF ;"SONG:"
text_sound:
.byte $22, $1E, $24, $1D, $13, $0D, $FF ;"SOUND:"
text_not_playing:
.byte $1D, $1E, $23, $00 ;"NOT "
text_playing:
.byte $1F, $1B, $10, $28, $18, $1D, $16, $00, $00, $00, $00, $FF ;"PLAYING "
;---- vectors
.org $FFFA ;first of the three vectors starts here
.w NMI ;when an NMI happens (once per frame if enabled) the
;processor will jump to the label NMI:
.w RESET ;when the processor first turns on or is reset, it will jump
;to the label RESET:
.w irq ;external interrupt IRQ is not used in this tutorial
.bank 3, 8, $0000, "NES_CHR0"
.segment "TILES"
.org $0000
.incbin "drums.chr" |
PROGRAM_SIZE equ 7; константа, определяющая размер программы (плохая идея, но пока так)
DATA_SEG equ 0x60; сегмент данных, куда загружаем наш код
STACK_SEG equ 0x7E0; сегмент для стека
use16
org 0x7c00
section .text
start:
mov ax, DATA_SEG ; сегмент куда пишем
mov es, ax
mov bx, 0; адрес куда пишем
mov ch, 0; дорожка 0
mov cl, 2 ; начиная с сектора 2(нумерация с одного)
mov dl, 0x80; номер диска
mov dh, 0; номер головки(нумерация с нуля)
mov ah, 2; номер функции
mov al, PROGRAM_SIZE;считать n секторов
int 0x13
jnc .no_error
; если что-то пошло не так
mov al, '!'
mov ah, 0x0E; номер функции BIOS
mov bh, 0; страница видеопамяти
int 0x10; выводим символ
jmp $
.no_error:
; настраиваем сегменты
mov ax, DATA_SEG; сегмент данных
mov ds, ax
mov es, ax
mov ax, STACK_SEG
mov ss, ax; не забываем про сегмент стека
jmp DATA_SEG:0; прыгаем на только что загруженный код
finish:
times 0x1FE-finish+start db 0
db 0x55, 0xAA; сигнатура загрузочного сектора
|
LI A, 0x1
LI A, 0x0
LI X, 0
LI Y, 11
JALR
NOP
NOP
NOP
LI A, 0xbb
HLT
LI A, 0xaa
MOV X, G
MOV Y, H
JMP
NOP
NOP
NOP
HLT |
.intel_syntax noprefix
.test_case_enter:
LEA R14, [R14 + 12] # instrumentation
MFENCE # instrumentation
.test_case_main:
.test_case_main.entry:
JMP .bb0
.bb0:
CMOVNL ECX, ECX
AND RBX, 0b0111111000000 # instrumentation
ADD RBX, R14 # instrumentation
ADC dword ptr [RBX], -67100032
NOT RAX
JP .bb1
JMP .test_case_main.exit
.bb1:
AND RBX, 1048197274
ADD AX, 5229
AND RCX, 0b0111111000000 # instrumentation
ADD RCX, R14 # instrumentation
LOCK ADC dword ptr [RCX], 115
{load} ADD RCX, RCX
{load} REX OR AL, AL
.test_case_main.exit:
.test_case_exit:
LEA R14, [R14 - 12] # instrumentation
MFENCE # instrumentation
|
#include <pqxx/internal/callgate.hxx>
namespace pqxx
{
class connection;
class errorhandler;
} // namespace pqxx
namespace pqxx::internal::gate
{
class PQXX_PRIVATE connection_errorhandler : callgate<connection>
{
friend class pqxx::errorhandler;
connection_errorhandler(reference x) : super(x) {}
void register_errorhandler(errorhandler *h)
{
home().register_errorhandler(h);
}
void unregister_errorhandler(errorhandler *h)
{
home().unregister_errorhandler(h);
}
};
} // namespace pqxx::internal::gate
|
/* autogenerated by dtc, do not edit */
#define OF_DT_HEADER 0xd00dfeed
#define OF_DT_BEGIN_NODE 0x1
#define OF_DT_END_NODE 0x2
#define OF_DT_PROP 0x3
#define OF_DT_END 0x9
.globl dt_blob_start
dt_blob_start:
_dt_blob_start:
.globl dt_header
dt_header:
_dt_header:
.long OF_DT_HEADER /* magic */
.long _dt_blob_end - _dt_blob_start /* totalsize */
.long _dt_struct_start - _dt_blob_start /* off_dt_struct */
.long _dt_strings_start - _dt_blob_start /* off_dt_strings */
.long _dt_reserve_map - _dt_blob_start /* off_dt_strings */
.long 16 /* version */
.long 16 /* last_comp_version */
.long 0 /*boot_cpuid_phys*/
.long _dt_strings_end - _dt_strings_start /* size_dt_strings */
.balign 8
.globl dt_reserve_map
dt_reserve_map:
_dt_reserve_map:
/* Memory reserve map from source file */
.long 0x10000000
.long 0x00000000
.long 0x00000000
.long 0x02000000
.long 0x20000000
.long 0x00000000
.long 0x01000000
.long 0x00000000
.long 0x00000000
.long 0x00000000
.long 0x00000000
.long 0x00000014
.long 0, 0
.long 0, 0
.globl dt_struct_start
dt_struct_start:
_dt_struct_start:
.long OF_DT_BEGIN_NODE
.string ""
.balign 4
.long OF_DT_PROP
.long 0xc
.long 0x0
.long 0x4d79426f
.long 0x6172644e
.long 0x616d6500
.balign 4
.long OF_DT_PROP
.long 0x1e
.long 0x6
.long 0x4d79426f
.long 0x6172644e
.long 0x616d6500
.long 0x4d79426f
.long 0x61726446
.long 0x616d696c
.long 0x794e616d
.short 0x6500
.balign 4
.long OF_DT_PROP
.long 0x4
.long 0x11
.long 0x2
.balign 4
.long OF_DT_PROP
.long 0x4
.long 0x20
.long 0x2
.balign 4
.long OF_DT_BEGIN_NODE
.string "cpus"
.balign 4
.long OF_DT_PROP
.long 0x4
.long 0x2c
.long 0x1
.balign 4
.long OF_DT_PROP
.long 0x4
.long 0x11
.long 0x1
.balign 4
.long OF_DT_PROP
.long 0x4
.long 0x20
.long 0x0
.balign 4
.long OF_DT_BEGIN_NODE
.string "PowerPC,970@0"
.balign 4
.long OF_DT_PROP
.long 0xc
.long 0x3a
.long 0x506f7765
.long 0x7250432c
.long 0x39373000
.balign 4
.long OF_DT_PROP
.long 0x4
.long 0x3f
.long 0x63707500
.balign 4
.long OF_DT_PROP
.long 0x4
.long 0x4b
.long 0x0
.balign 4
.long OF_DT_PROP
.long 0x4
.long 0x4f
.long 0x5f5e1000
.balign 4
.long OF_DT_PROP
.long 0x4
.long 0x5f
.long 0x1fca055
.balign 4
.long OF_DT_PROP
.long 0x0
.long 0x72
.balign 4
.long OF_DT_PROP
.long 0x4
.long 0x81
.long 0x10000
.balign 4
.long OF_DT_PROP
.long 0x4
.long 0x8e
.long 0x8000
.balign 4
.long OF_DT_END_NODE
.long OF_DT_BEGIN_NODE
.string "PowerPC,970@1"
.balign 4
.long OF_DT_PROP
.long 0xc
.long 0x3a
.long 0x506f7765
.long 0x7250432c
.long 0x39373000
.balign 4
.long OF_DT_PROP
.long 0x4
.long 0x3f
.long 0x63707500
.balign 4
.long OF_DT_PROP
.long 0x4
.long 0x4b
.long 0x1
.balign 4
.long OF_DT_PROP
.long 0x4
.long 0x4f
.long 0x5f5e1000
.balign 4
.long OF_DT_PROP
.long 0x4
.long 0x5f
.long 0x1fca055
.balign 4
.long OF_DT_PROP
.long 0x4
.long 0x81
.long 0x10000
.balign 4
.long OF_DT_PROP
.long 0x4
.long 0x8e
.long 0x8000
.balign 4
.long OF_DT_END_NODE
.long OF_DT_END_NODE
.long OF_DT_BEGIN_NODE
.string "randomnode"
.balign 4
.long OF_DT_PROP
.long 0x13
.long 0x9b
.long 0xff007374
.long 0x75666673
.long 0x74756666
.long 0x909090a
.short 0xa0a
.byte 0x0
.balign 4
.long OF_DT_PROP
.long 0x9
.long 0xa2
.long 0xa0b0c0d
.long 0xdeeaadbe
.byte 0xef
.balign 4
.long OF_DT_PROP
.long 0x4
.long 0xa7
.long 0x2
.balign 4
.long OF_DT_PROP
.long 0x14
.long 0xab
.long 0x61626300
.long 0x12340000
.long 0xa
.long 0xb
.long 0xc
.balign 4
.long OF_DT_END_NODE
.long OF_DT_BEGIN_NODE
.string "memory@0"
.balign 4
.long OF_DT_PROP
.long 0x7
.long 0x3f
.long 0x6d656d6f
.short 0x7279
.byte 0x0
.balign 4
.globl memreg
memreg:
.long OF_DT_PROP
.long 0x10
.long 0x4b
.long 0x0
.long 0x0
.long 0x0
.long 0x20000000
.balign 4
.long OF_DT_PROP
.long 0x4
.long 0x2c
.long 0x2
.balign 4
.long OF_DT_END_NODE
.long OF_DT_BEGIN_NODE
.string "chosen"
.balign 4
.long OF_DT_PROP
.long 0xf
.long 0xb1
.long 0x726f6f74
.long 0x3d2f6465
.long 0x762f7364
.short 0x6132
.byte 0x0
.balign 4
.long OF_DT_PROP
.long 0x4
.long 0xba
.long 0x600
.balign 4
.long OF_DT_END_NODE
.long OF_DT_END_NODE
.long OF_DT_END
.globl dt_struct_end
dt_struct_end:
_dt_struct_end:
.globl dt_strings_start
dt_strings_start:
_dt_strings_start:
.string "model"
.string "compatible"
.string "#address-cells"
.string "#size-cells"
.string "linux,phandle"
.string "name"
.string "device_type"
.string "reg"
.string "clock-frequency"
.string "timebase-frequency"
.string "linux,boot-cpu"
.string "i-cache-size"
.string "d-cache-size"
.string "string"
.string "blob"
.string "ref"
.string "mixed"
.string "bootargs"
.string "linux,platform"
.globl dt_strings_end
dt_strings_end:
_dt_strings_end:
.globl dt_blob_end
dt_blob_end:
_dt_blob_end:
|
; A007067: Nearest integer to n*tau.
; 0,2,3,5,6,8,10,11,13,15,16,18,19,21,23,24,26,28,29,31,32,34,36,37,39,40,42,44,45,47,49,50,52,53,55,57,58,60,61,63,65,66,68,70,71,73,74,76,78,79,81,83,84,86,87,89,91,92,94,95,97,99,100,102,104,105,107,108,110,112,113,115,116,118,120,121,123,125,126,128,129,131,133,134,136,138,139,141,142,144,146,147,149,150,152,154,155,157,159,160
mov $1,$0
seq $1,198082 ; Ceiling(n*Sqrt(5)).
add $1,$0
div $1,2
mov $0,$1
|
; GAMEPLAY {{{
cm_main_goto_gameplay:
%cm_submenu("Gameplay", cm_submenu_gameplay)
cm_submenu_gameplay:
dw cm_gameplay_skip_triforce
dw cm_gameplay_sanctuary
dw cm_gameplay_disable_beams
dw cm_gameplay_lit_rooms
dw cm_gameplay_fast_moving_walls
dw cm_gameplay_quickswap
dw cm_gameplay_probes
dw cm_gameplay_bonk_items
dw cm_gameplay_shutoffbg1
dw cm_gameplay_shutoffbg2
dw cm_gameplay_oob
dw !menu_end
%cm_header("GAMEPLAY")
cm_gameplay_skip_triforce:
%cm_toggle("Skip Triforce", !ram_skip_triforce_toggle)
cm_gameplay_sanctuary:
%cm_toggle("Sanc heart", !ram_sanctuary_heart)
cm_gameplay_disable_beams:
%cm_toggle("Disable beams", !disable_beams)
cm_gameplay_probes:
%cm_toggle("Visible probes", !ram_probe_toggle)
cm_gameplay_bonk_items:
%cm_toggle("See bonk items", !ram_bonk_items_toggle)
cm_gameplay_lit_rooms:
%cm_toggle_jsr("Lit rooms", !ram_lit_rooms_toggle)
.toggle
LDA !ram_lit_rooms_toggle : ORA $1B : BEQ .leaveon
LDA #$10 : STA $99
.leaveon
RTS
cm_gameplay_fast_moving_walls:
%cm_toggle("Fast walls", !ram_fast_moving_walls)
cm_gameplay_quickswap:
%cm_toggle("Item quickswap", !ram_quickswap)
cm_gameplay_shutoffbg1:
%cm_toggle_bit("Disable BG1", !disabled_layers, #$01)
cm_gameplay_shutoffbg2:
%cm_toggle_bit("Disable BG2", !disabled_layers, #$02)
cm_gameplay_oob:
%cm_toggle("OoB mode", !lowram_oob_toggle)
; }}} |
<%
from pwnlib.shellcraft.aarch64.linux import syscall
%>
<%page args=""/>
<%docstring>
Invokes the syscall getpgrp. See 'man 2 getpgrp' for more information.
Arguments:
</%docstring>
${syscall('SYS_getpgrp')}
|
/*=============================================================================
Copyright (c) 2017 Paul Fultz II
test.hpp
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 GUARD_TEST_H
#define GUARD_TEST_H
#include <type_traits>
#include <tuple>
#include <iostream>
#include <functional>
#include <vector>
#include <memory>
#include <boost/hof/detail/forward.hpp>
#ifndef BOOST_HOF_HAS_STATIC_TEST_CHECK
#if (defined(__GNUC__) && !defined (__clang__) && __GNUC__ == 4 && __GNUC_MINOR__ < 7) || defined(_MSC_VER)
#define BOOST_HOF_HAS_STATIC_TEST_CHECK 0
#else
#define BOOST_HOF_HAS_STATIC_TEST_CHECK 1
#endif
#endif
#define BOOST_HOF_PP_CAT(x, y) BOOST_HOF_PP_PRIMITIVE_CAT(x, y)
#define BOOST_HOF_PP_PRIMITIVE_CAT(x, y) x ## y
namespace boost { namespace hof { namespace test {
typedef std::function<void()> test_case;
static std::vector<test_case> test_cases;
struct auto_register
{
auto_register(test_case tc)
{
test_cases.push_back(tc);
}
};
#define BOOST_HOF_DETAIL_TEST_CASE(name) \
struct name \
{ void operator()() const; }; \
static boost::hof::test::auto_register BOOST_HOF_PP_CAT(name, _register) = boost::hof::test::auto_register(name()); \
void name::operator()() const
template<class T>
T bare(const T&);
template<class T>
inline void unused(T&&) {}
}}} // namespace boost::hof
#if defined(__GNUC__) && !defined (__clang__) && __GNUC__ == 4 && __GNUC_MINOR__ < 7
#define BOOST_HOF_STATIC_AUTO constexpr auto
#else
#define BOOST_HOF_STATIC_AUTO const constexpr auto
#endif
#define STATIC_ASSERT_SAME(...) static_assert(std::is_same<__VA_ARGS__>::value, "Types are not the same")
#if defined(__GNUC__) && !defined (__clang__) && __GNUC__ == 4 && __GNUC_MINOR__ < 7
#define STATIC_ASSERT_MOVE_ONLY(T)
#else
#define STATIC_ASSERT_MOVE_ONLY(T) static_assert(!std::is_copy_constructible<T>::value && std::is_move_constructible<T>::value, "Not movable")
#endif
#if defined(__GNUC__) && !defined (__clang__) && __GNUC__ == 4 && __GNUC_MINOR__ < 7
#define STATIC_ASSERT_NOT_DEFAULT_CONSTRUCTIBLE(T)
#else
#define STATIC_ASSERT_NOT_DEFAULT_CONSTRUCTIBLE(T) static_assert(!std::is_default_constructible<T>::value, "Default constructible")
#endif
#define STATIC_ASSERT_EMPTY(x) static_assert(std::is_empty<decltype(boost::hof::test::bare(x))>::value, "Not empty");
#define BOOST_HOF_TEST_CASE() BOOST_HOF_DETAIL_TEST_CASE(BOOST_HOF_PP_CAT(test_, __LINE__))
#define BOOST_HOF_STATIC_TEST_CASE() struct BOOST_HOF_PP_CAT(test_, __LINE__)
#define BOOST_HOF_TEST_TEMPLATE(...) typedef std::integral_constant<int, sizeof(__VA_ARGS__)> BOOST_HOF_PP_CAT(test_template_, __LINE__)
#define BOOST_HOF_TEST_CHECK(...) if (!(__VA_ARGS__)) std::cout << "***** FAILED *****: " << #__VA_ARGS__ << "@" << __FILE__ << ": " << __LINE__ << std::endl
#define BOOST_HOF_STRINGIZE(...) #__VA_ARGS__
#if BOOST_HOF_HAS_STATIC_TEST_CHECK
#define BOOST_HOF_STATIC_TEST_CHECK(...) static_assert(__VA_ARGS__, BOOST_HOF_STRINGIZE(__VA_ARGS__))
#else
#define BOOST_HOF_STATIC_TEST_CHECK(...)
#endif
#ifndef BOOST_HOF_HAS_CONSTEXPR_TUPLE
#define BOOST_HOF_HAS_CONSTEXPR_TUPLE BOOST_HOF_HAS_STD_14
#endif
struct binary_class
{
template<class T, class U>
constexpr T operator()(T x, U y) const noexcept
{
return x+y;
}
};
struct mutable_class
{
template<class F>
struct result;
template<class F, class T, class U>
struct result<F(T&, U)>
{
typedef T type;
};
template<class T, class U>
T operator()(T & x, U y) const
{
return x+=y;
}
};
struct unary_class
{
template<class T>
constexpr T&& operator()(T&& x) const noexcept
{
return boost::hof::forward<T>(x);
}
};
struct void_class
{
template<class T>
void operator()(T) const
{
}
};
struct mono_class
{
constexpr int operator()(int x) const
{
return x+1;
}
};
struct tuple_class
{
// Note: Taking the tuple by value causes the compiler to ICE on gcc 4.7
// when called in a constexpr context.
template<class T>
constexpr int operator()(const T& t) const
{
return std::get<0>(t) + 1;
}
};
template<class R>
struct explicit_class
{
template<class T>
R operator()(T x)
{
return static_cast<R>(x);
}
};
struct move_class
{
std::unique_ptr<int> i;
move_class() : i(new int(0))
{}
template<class T, class U>
constexpr T operator()(T x, U y) const
{
return x+y+*i;
}
};
int main()
{
for(const auto& tc: boost::hof::test::test_cases) tc();
return 0;
}
#endif
|
; A213194: First inverse function (numbers of rows) for pairing function A211377.
; 1,1,1,2,2,3,1,1,2,2,3,3,4,4,5,1,1,2,2,3,3,4,4,5,5,6,6,7,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,14,14,15,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,14,14,15,15,16,16,17,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,14,14,15,15,16,16,17,17,18,18,19,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,14,14,15,15,16,16,17,17,18,18,19,19,20,20,21,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10
add $0,1
lpb $0,1
sub $0,1
mov $4,$0
trn $0,$3
add $3,4
div $4,2
lpe
mov $2,$4
add $2,10
mul $2,16
mov $0,$2
add $0,2
mov $1,$0
sub $1,162
div $1,16
add $1,1
|
/*
* aes_crypt.c
*
* Created on: 2013-7-17
* Author: zhouzhijie
*/
//#include "aes_crypt.h"
#include <string.h>
#include <stdlib.h>
#include <openssl/aes.h>
#include <time.h>
#define AES_KEY_LEN 16
#define AES_KEY_BITSET_LEN 128
int aes_cbc_encrypt_time_check(const unsigned char* pKey, unsigned int uiKeyLen
, const unsigned char* pInput, unsigned int uiInputLen
, unsigned char** ppOutput, unsigned int* pOutputLen)
{
unsigned char keyBuf[AES_KEY_LEN] = {0};
unsigned char iv[AES_KEY_LEN];
AES_KEY aesKey;
int ret;
unsigned int uiPaddingLen;
unsigned int uiTotalLen;
if(pKey == NULL || uiKeyLen == 0 || pInput == NULL || uiInputLen == 0
|| pOutputLen == NULL || ppOutput == NULL)
return -1;
memcpy(keyBuf, pKey, (uiKeyLen > AES_KEY_LEN) ? AES_KEY_LEN : uiKeyLen);
memcpy(iv, keyBuf, AES_KEY_LEN);
ret = AES_set_encrypt_key(keyBuf, AES_KEY_BITSET_LEN, &aesKey);
if(ret != 0) return -2;
//second from 2018.1.1 0:0:0
unsigned int timestamp = (unsigned int)time(NULL) - 1514736000;
//hours from 2018.1.1 0:0:0
unsigned int hours = timestamp / 3600;
uiInputLen += 4;
//padding
uiPaddingLen = AES_KEY_LEN - (uiInputLen % AES_KEY_LEN);
uiTotalLen = uiInputLen + uiPaddingLen;
unsigned char *pData = (unsigned char*)malloc(sizeof(unsigned char) * uiTotalLen);
unsigned short int si = 1;
if ((si & 0xFF) == 1) { //small end
memcpy(pData, &hours, 4);
} else { //big end
unsigned char byte0 = (hours & 0xFF);
pData[0] = byte0;
unsigned char byte1 = (hours & 0xFF00) >> 8;
pData[1] = byte1;
unsigned char byte2 = (hours & 0xFF0000) >> 16;
pData[2] = byte2;
unsigned char byte3 = (hours & 0xFF000000) >> 24;
pData[3] = byte3;
}
memcpy(pData + 4, pInput, uiInputLen - 4);
if(uiPaddingLen > 0) memset(pData+uiInputLen, uiPaddingLen, uiPaddingLen);
*pOutputLen = uiTotalLen;
*ppOutput = (unsigned char*)malloc(uiTotalLen);
memset(*ppOutput, 0, uiTotalLen);
AES_cbc_encrypt(pData, *ppOutput, uiTotalLen, &aesKey, iv, AES_ENCRYPT);
free(pData);
pData = NULL;
return 0;
}
int aes_cbc_decrypt_time_check(const unsigned char* pKey, unsigned int uiKeyLen
, const unsigned char* pInput, unsigned int uiInputLen
, unsigned char** ppOutput, unsigned int* pOutputLen, bool checkTime)
{
unsigned char keyBuf[AES_KEY_LEN] = {0};
unsigned char iv[AES_KEY_LEN];
AES_KEY aesKey;
int ret;
int uiPaddingLen;
if(pKey == NULL || uiKeyLen == 0 || pInput == NULL || uiInputLen == 0 || pOutputLen == NULL
|| (uiInputLen%AES_KEY_LEN) != 0 || ppOutput == NULL)
return -1;
memcpy(keyBuf, pKey, (uiKeyLen > AES_KEY_LEN) ? AES_KEY_LEN : uiKeyLen);
memcpy(iv, keyBuf, AES_KEY_LEN);
ret = AES_set_decrypt_key(keyBuf, AES_KEY_BITSET_LEN, &aesKey);
if(ret != 0) { return -2; }
unsigned char *pBuf = (unsigned char *)malloc(uiInputLen);
memset(pBuf, 0, uiInputLen);
AES_cbc_encrypt(pInput, pBuf, uiInputLen, &aesKey, iv, AES_DECRYPT);
uiPaddingLen = (pBuf)[uiInputLen - 1];
if(uiPaddingLen > AES_KEY_LEN || uiPaddingLen <= 0) {
free(pBuf);
ppOutput = NULL;
*pOutputLen = 0;
return -3;
}
unsigned int *phours = (unsigned int *)pBuf;
unsigned short int si = 1;
if ((si & 0xFF) == 0) { //大端
unsigned int hours = 0;
hours += (hours & 0xFF) << 24;
hours += (hours & 0xFF00) << 8;
hours += (hours & 0xFF0000) >> 8;
hours += (hours & 0xFF000000) >> 24;
}
//2018.1.1 0:0:0 以来的小时数
if (checkTime) {
unsigned int curts = ((unsigned int)time(NULL) - 1514736000) / 3600;
if (((curts > *phours) && (curts - *phours > 24)) ||
((*phours > curts) && (*phours - curts > 24))) {
free(pBuf);
ppOutput = NULL;
*pOutputLen = 0;
return -4;
}
}
*pOutputLen = uiInputLen - uiPaddingLen - 4;
*ppOutput = (unsigned char* )malloc(*pOutputLen + 1);
memset(*ppOutput, 0, *pOutputLen + 1);
memcpy(*ppOutput, pBuf + 4, *pOutputLen);
free(pBuf);
return 0;
}
int aes_cbc_encrypt(const unsigned char* pKey, unsigned int uiKeyLen
, const unsigned char* pInput, unsigned int uiInputLen
, unsigned char** ppOutput, unsigned int* pOutputLen)
{
unsigned char keyBuf[AES_KEY_LEN] = {0};
unsigned char iv[AES_KEY_LEN];
AES_KEY aesKey;
int ret;
unsigned int uiPaddingLen;
unsigned int uiTotalLen;
unsigned char* pData;
if(pKey == NULL || uiKeyLen == 0 || pInput == NULL || uiInputLen == 0
|| pOutputLen == NULL || ppOutput == NULL)
return -1;
memcpy(keyBuf, pKey, (uiKeyLen > AES_KEY_LEN) ? AES_KEY_LEN : uiKeyLen);
memcpy(iv, keyBuf, AES_KEY_LEN);
ret = AES_set_encrypt_key(keyBuf, AES_KEY_BITSET_LEN, &aesKey);
if(ret != 0) return -2;
//padding
uiPaddingLen = AES_KEY_LEN - (uiInputLen % AES_KEY_LEN);
uiTotalLen = uiInputLen + uiPaddingLen;
pData = (unsigned char* )malloc(uiTotalLen);
memcpy(pData, pInput, uiInputLen);
if(uiPaddingLen > 0) memset(pData+uiInputLen, uiPaddingLen, uiPaddingLen);
*pOutputLen = uiTotalLen;
*ppOutput = (unsigned char* )malloc(uiTotalLen);
memset(*ppOutput, 0, uiTotalLen);
AES_cbc_encrypt(pData, *ppOutput, uiTotalLen, &aesKey, iv, AES_ENCRYPT);
free(pData);
return 0;
}
int aes_cbc_decrypt(const unsigned char* pKey, unsigned int uiKeyLen
, const unsigned char* pInput, unsigned int uiInputLen
, unsigned char** ppOutput, unsigned int* pOutputLen)
{
unsigned char keyBuf[AES_KEY_LEN] = {0};
unsigned char iv[AES_KEY_LEN];
AES_KEY aesKey;
int ret;
int uiPaddingLen;
if(pKey == NULL || uiKeyLen == 0 || pInput == NULL || uiInputLen == 0 || pOutputLen == NULL
|| (uiInputLen%AES_KEY_LEN) != 0 || ppOutput == NULL)
return -1;
memcpy(keyBuf, pKey, (uiKeyLen > AES_KEY_LEN) ? AES_KEY_LEN : uiKeyLen);
memcpy(iv, keyBuf, AES_KEY_LEN);
ret = AES_set_decrypt_key(keyBuf, AES_KEY_BITSET_LEN, &aesKey);
if(ret != 0) { return -2; }
*ppOutput = (unsigned char* )malloc(uiInputLen);
memset(*ppOutput, 0, uiInputLen);
AES_cbc_encrypt(pInput, *ppOutput, uiInputLen, &aesKey, iv, AES_DECRYPT);
uiPaddingLen = (*ppOutput)[uiInputLen - 1];
if(uiPaddingLen > AES_KEY_LEN || uiPaddingLen <= 0) {
free(*ppOutput);
ppOutput = NULL;
return -3;
}
*pOutputLen = uiInputLen - uiPaddingLen;
return 0;
}
int aes_ecb_encrypt(const unsigned char* pKey, unsigned int uiKeyLen
, const unsigned char* pInput, unsigned int uiInputLen, int bFinal
, unsigned char** ppOutput, unsigned int* pOutputLen)
{
unsigned char keyBuf[AES_KEY_LEN] = {0};
AES_KEY aesKey;
int ret;
unsigned int uiPaddingLen;
unsigned int uiTotalLen;
unsigned char* pData;
unsigned int uiDone;
unsigned char* pcInput;
unsigned char* pcOutput;
if(pKey == NULL || uiKeyLen == 0 || pInput == NULL || uiInputLen == 0 || pOutputLen == NULL
|| (bFinal==0 && (uiInputLen%AES_KEY_LEN) != 0) || ppOutput == NULL)
return -1;
memcpy(keyBuf, pKey, (uiKeyLen > AES_KEY_LEN) ? AES_KEY_LEN : uiKeyLen);
ret = AES_set_encrypt_key(keyBuf, AES_KEY_BITSET_LEN, &aesKey);
if(ret != 0) { return -2;}
//padding
uiPaddingLen = (bFinal!=0) ? (AES_KEY_LEN - (uiInputLen % AES_KEY_LEN)) : 0;
uiTotalLen = uiInputLen + uiPaddingLen;
pData = (unsigned char* )malloc(uiTotalLen);
memcpy(pData, pInput, uiInputLen);
if(uiPaddingLen > 0) memset(pData+uiInputLen, uiPaddingLen, uiPaddingLen);
*ppOutput = (unsigned char* )malloc(uiTotalLen);
memset(*ppOutput, 0, uiTotalLen);
uiDone = 0;
pcInput = pData;
pcOutput = *ppOutput;
while(uiDone < uiTotalLen) {
AES_ecb_encrypt(pcInput, pcOutput, &aesKey, AES_ENCRYPT);
pcInput += AES_KEY_LEN;
pcOutput += AES_KEY_LEN;
uiDone += AES_KEY_LEN;
}
*pOutputLen = uiTotalLen;
free(pData);
return 0;
}
int aes_ecb_decrypt(const unsigned char* pKey, unsigned int uiKeyLen
, const unsigned char* pInput, unsigned int uiInputLen, int bFinal
, unsigned char** ppOutput, unsigned int* pOutputLen)
{
unsigned char keyBuf[AES_KEY_LEN] = {0};
AES_KEY aesKey;
unsigned int uiDone;
const unsigned char* pcInput;
unsigned char* pcOutput;
unsigned int uiPaddingLen;
int ret;
if(pKey == NULL || uiKeyLen == 0 || pInput == NULL || uiInputLen == 0 || pOutputLen == NULL
|| (uiInputLen%AES_KEY_LEN) != 0 || ppOutput == NULL)
return -1;
memcpy(keyBuf, pKey, (uiKeyLen > AES_KEY_LEN) ? AES_KEY_LEN : uiKeyLen);
ret = AES_set_decrypt_key(keyBuf, AES_KEY_BITSET_LEN, &aesKey);
if(ret != 0) { return -2;}
*ppOutput = (unsigned char* )malloc(uiInputLen);
memset(*ppOutput, 0, uiInputLen);
uiDone = 0;
pcInput = pInput;
pcOutput = *ppOutput;
while(uiDone < uiInputLen) {
AES_ecb_encrypt(pcInput, pcOutput, &aesKey, AES_DECRYPT);
pcInput += AES_KEY_LEN;
pcOutput += AES_KEY_LEN;
uiDone += AES_KEY_LEN;
}
if(bFinal != 0)
{
uiPaddingLen = (*ppOutput)[uiInputLen - 1];
if(uiPaddingLen > AES_KEY_LEN || uiPaddingLen <= 0) {
free(*ppOutput);
ppOutput = NULL;
return -3;
}
*pOutputLen = uiInputLen - uiPaddingLen;
}
else
*pOutputLen = uiInputLen;
return 0;
}
|
#include"../localedef.h"
namespace fast_io_i18n
{
namespace
{
inline constexpr std::size_t numeric_grouping_storage[]{3};
inline constexpr lc_all lc_all_global{.identification={.name=tsc("az_AZ"),.encoding=tsc(FAST_IO_LOCALE_ENCODING),.title=tsc("Azeri language locale for Azerbaijan (latin)"),.source=tsc("fast_io"),.address=tsc("https://gitee.com/qabeowjbtkwb/fast_io\t\t;\t\thttps://github.com/cppfastio/fast_io"),.contact=tsc("Pablo Saratxaga\t\t;\t\tfast_io"),.email=tsc("pablo@mandrakesoft.com;euloanty@live.com"),.tel=tsc(""),.fax=tsc(""),.language=tsc("Azerbaijani"),.territory=tsc("Azerbaijan"),.revision=tsc("0.4"),.date=tsc("2001-01-26")},.monetary={.int_curr_symbol=tsc("AZN "),.currency_symbol=tsc("₼"),.mon_decimal_point=tsc("."),.mon_thousands_sep=tsc(" "),.mon_grouping={numeric_grouping_storage,1},.positive_sign=tsc(""),.negative_sign=tsc("-"),.int_frac_digits=2,.frac_digits=2,.p_cs_precedes=0,.p_sep_by_space=1,.n_cs_precedes=0,.n_sep_by_space=1,.p_sign_posn=1,.n_sign_posn=1},.numeric={.decimal_point=tsc(","),.thousands_sep=tsc("."),.grouping={numeric_grouping_storage,1}},.time={.abday={tsc("baz"),tsc("ber"),tsc("çax"),tsc("çər"),tsc("cax"),tsc("cüm"),tsc("şnb")},.day={tsc("bazar günü"),tsc("bazar ertəsi"),tsc("çərşənbə axşamı"),tsc("çərşənbə"),tsc("cümə axşamı"),tsc("cümə"),tsc("şənbə")},.abmon={tsc("Yan"),tsc("Fev"),tsc("Mar"),tsc("Apr"),tsc("May"),tsc("İyn"),tsc("İyl"),tsc("Avq"),tsc("Sen"),tsc("Okt"),tsc("Noy"),tsc("Dek")},.mon={tsc("yanvar"),tsc("fevral"),tsc("mart"),tsc("aprel"),tsc("may"),tsc("iyun"),tsc("iyul"),tsc("avqust"),tsc("sentyabr"),tsc("oktyabr"),tsc("noyabr"),tsc("dekabr")},.d_t_fmt=tsc("%A, %d %B %Y %T"),.d_fmt=tsc("%d.%m.%Y"),.t_fmt=tsc("%T"),.t_fmt_ampm=tsc(""),.date_fmt=tsc("%A, %d %B %Y %T %Z"),.am_pm={tsc(""),tsc("")},.week={7,19971130,1},.first_weekday=2},.messages={.yesexpr=tsc("^[+1bBhH]"),.noexpr=tsc("^[-0YyNn]"),.yesstr=tsc("hə"),.nostr=tsc("yox")},.paper={.width=210,.height=297},.telephone={.tel_int_fmt=tsc("+%c %a %l"),.int_select=tsc("00"),.int_prefix=tsc("994")},.name={.name_fmt=tsc("???")},.address={.postal_fmt=tsc("???"),.country_name=tsc("Azərbaycan"),.country_ab2=tsc("AZ"),.country_ab3=tsc("AZE"),.country_num=31,.country_car=tsc("AZ"),.lang_name=tsc("azərbaycan"),.lang_ab=tsc("az"),.lang_term=tsc("aze"),.lang_lib=tsc("aze")},.measurement={.measurement=1}};
inline constexpr wlc_all wlc_all_global{.identification={.name=tsc(L"az_AZ"),.encoding=tsc(FAST_IO_LOCALE_LENCODING),.title=tsc(L"Azeri language locale for Azerbaijan (latin)"),.source=tsc(L"fast_io"),.address=tsc(L"https://gitee.com/qabeowjbtkwb/fast_io\t\t;\t\thttps://github.com/cppfastio/fast_io"),.contact=tsc(L"Pablo Saratxaga\t\t;\t\tfast_io"),.email=tsc(L"pablo@mandrakesoft.com;euloanty@live.com"),.tel=tsc(L""),.fax=tsc(L""),.language=tsc(L"Azerbaijani"),.territory=tsc(L"Azerbaijan"),.revision=tsc(L"0.4"),.date=tsc(L"2001-01-26")},.monetary={.int_curr_symbol=tsc(L"AZN "),.currency_symbol=tsc(L"₼"),.mon_decimal_point=tsc(L"."),.mon_thousands_sep=tsc(L" "),.mon_grouping={numeric_grouping_storage,1},.positive_sign=tsc(L""),.negative_sign=tsc(L"-"),.int_frac_digits=2,.frac_digits=2,.p_cs_precedes=0,.p_sep_by_space=1,.n_cs_precedes=0,.n_sep_by_space=1,.p_sign_posn=1,.n_sign_posn=1},.numeric={.decimal_point=tsc(L","),.thousands_sep=tsc(L"."),.grouping={numeric_grouping_storage,1}},.time={.abday={tsc(L"baz"),tsc(L"ber"),tsc(L"çax"),tsc(L"çər"),tsc(L"cax"),tsc(L"cüm"),tsc(L"şnb")},.day={tsc(L"bazar günü"),tsc(L"bazar ertəsi"),tsc(L"çərşənbə axşamı"),tsc(L"çərşənbə"),tsc(L"cümə axşamı"),tsc(L"cümə"),tsc(L"şənbə")},.abmon={tsc(L"Yan"),tsc(L"Fev"),tsc(L"Mar"),tsc(L"Apr"),tsc(L"May"),tsc(L"İyn"),tsc(L"İyl"),tsc(L"Avq"),tsc(L"Sen"),tsc(L"Okt"),tsc(L"Noy"),tsc(L"Dek")},.mon={tsc(L"yanvar"),tsc(L"fevral"),tsc(L"mart"),tsc(L"aprel"),tsc(L"may"),tsc(L"iyun"),tsc(L"iyul"),tsc(L"avqust"),tsc(L"sentyabr"),tsc(L"oktyabr"),tsc(L"noyabr"),tsc(L"dekabr")},.d_t_fmt=tsc(L"%A, %d %B %Y %T"),.d_fmt=tsc(L"%d.%m.%Y"),.t_fmt=tsc(L"%T"),.t_fmt_ampm=tsc(L""),.date_fmt=tsc(L"%A, %d %B %Y %T %Z"),.am_pm={tsc(L""),tsc(L"")},.week={7,19971130,1},.first_weekday=2},.messages={.yesexpr=tsc(L"^[+1bBhH]"),.noexpr=tsc(L"^[-0YyNn]"),.yesstr=tsc(L"hə"),.nostr=tsc(L"yox")},.paper={.width=210,.height=297},.telephone={.tel_int_fmt=tsc(L"+%c %a %l"),.int_select=tsc(L"00"),.int_prefix=tsc(L"994")},.name={.name_fmt=tsc(L"???")},.address={.postal_fmt=tsc(L"???"),.country_name=tsc(L"Azərbaycan"),.country_ab2=tsc(L"AZ"),.country_ab3=tsc(L"AZE"),.country_num=31,.country_car=tsc(L"AZ"),.lang_name=tsc(L"azərbaycan"),.lang_ab=tsc(L"az"),.lang_term=tsc(L"aze"),.lang_lib=tsc(L"aze")},.measurement={.measurement=1}};
inline constexpr u8lc_all u8lc_all_global{.identification={.name=tsc(u8"az_AZ"),.encoding=tsc(FAST_IO_LOCALE_u8ENCODING),.title=tsc(u8"Azeri language locale for Azerbaijan (latin)"),.source=tsc(u8"fast_io"),.address=tsc(u8"https://gitee.com/qabeowjbtkwb/fast_io\t\t;\t\thttps://github.com/cppfastio/fast_io"),.contact=tsc(u8"Pablo Saratxaga\t\t;\t\tfast_io"),.email=tsc(u8"pablo@mandrakesoft.com;euloanty@live.com"),.tel=tsc(u8""),.fax=tsc(u8""),.language=tsc(u8"Azerbaijani"),.territory=tsc(u8"Azerbaijan"),.revision=tsc(u8"0.4"),.date=tsc(u8"2001-01-26")},.monetary={.int_curr_symbol=tsc(u8"AZN "),.currency_symbol=tsc(u8"₼"),.mon_decimal_point=tsc(u8"."),.mon_thousands_sep=tsc(u8" "),.mon_grouping={numeric_grouping_storage,1},.positive_sign=tsc(u8""),.negative_sign=tsc(u8"-"),.int_frac_digits=2,.frac_digits=2,.p_cs_precedes=0,.p_sep_by_space=1,.n_cs_precedes=0,.n_sep_by_space=1,.p_sign_posn=1,.n_sign_posn=1},.numeric={.decimal_point=tsc(u8","),.thousands_sep=tsc(u8"."),.grouping={numeric_grouping_storage,1}},.time={.abday={tsc(u8"baz"),tsc(u8"ber"),tsc(u8"çax"),tsc(u8"çər"),tsc(u8"cax"),tsc(u8"cüm"),tsc(u8"şnb")},.day={tsc(u8"bazar günü"),tsc(u8"bazar ertəsi"),tsc(u8"çərşənbə axşamı"),tsc(u8"çərşənbə"),tsc(u8"cümə axşamı"),tsc(u8"cümə"),tsc(u8"şənbə")},.abmon={tsc(u8"Yan"),tsc(u8"Fev"),tsc(u8"Mar"),tsc(u8"Apr"),tsc(u8"May"),tsc(u8"İyn"),tsc(u8"İyl"),tsc(u8"Avq"),tsc(u8"Sen"),tsc(u8"Okt"),tsc(u8"Noy"),tsc(u8"Dek")},.mon={tsc(u8"yanvar"),tsc(u8"fevral"),tsc(u8"mart"),tsc(u8"aprel"),tsc(u8"may"),tsc(u8"iyun"),tsc(u8"iyul"),tsc(u8"avqust"),tsc(u8"sentyabr"),tsc(u8"oktyabr"),tsc(u8"noyabr"),tsc(u8"dekabr")},.d_t_fmt=tsc(u8"%A, %d %B %Y %T"),.d_fmt=tsc(u8"%d.%m.%Y"),.t_fmt=tsc(u8"%T"),.t_fmt_ampm=tsc(u8""),.date_fmt=tsc(u8"%A, %d %B %Y %T %Z"),.am_pm={tsc(u8""),tsc(u8"")},.week={7,19971130,1},.first_weekday=2},.messages={.yesexpr=tsc(u8"^[+1bBhH]"),.noexpr=tsc(u8"^[-0YyNn]"),.yesstr=tsc(u8"hə"),.nostr=tsc(u8"yox")},.paper={.width=210,.height=297},.telephone={.tel_int_fmt=tsc(u8"+%c %a %l"),.int_select=tsc(u8"00"),.int_prefix=tsc(u8"994")},.name={.name_fmt=tsc(u8"???")},.address={.postal_fmt=tsc(u8"???"),.country_name=tsc(u8"Azərbaycan"),.country_ab2=tsc(u8"AZ"),.country_ab3=tsc(u8"AZE"),.country_num=31,.country_car=tsc(u8"AZ"),.lang_name=tsc(u8"azərbaycan"),.lang_ab=tsc(u8"az"),.lang_term=tsc(u8"aze"),.lang_lib=tsc(u8"aze")},.measurement={.measurement=1}};
inline constexpr u16lc_all u16lc_all_global{.identification={.name=tsc(u"az_AZ"),.encoding=tsc(FAST_IO_LOCALE_uENCODING),.title=tsc(u"Azeri language locale for Azerbaijan (latin)"),.source=tsc(u"fast_io"),.address=tsc(u"https://gitee.com/qabeowjbtkwb/fast_io\t\t;\t\thttps://github.com/cppfastio/fast_io"),.contact=tsc(u"Pablo Saratxaga\t\t;\t\tfast_io"),.email=tsc(u"pablo@mandrakesoft.com;euloanty@live.com"),.tel=tsc(u""),.fax=tsc(u""),.language=tsc(u"Azerbaijani"),.territory=tsc(u"Azerbaijan"),.revision=tsc(u"0.4"),.date=tsc(u"2001-01-26")},.monetary={.int_curr_symbol=tsc(u"AZN "),.currency_symbol=tsc(u"₼"),.mon_decimal_point=tsc(u"."),.mon_thousands_sep=tsc(u" "),.mon_grouping={numeric_grouping_storage,1},.positive_sign=tsc(u""),.negative_sign=tsc(u"-"),.int_frac_digits=2,.frac_digits=2,.p_cs_precedes=0,.p_sep_by_space=1,.n_cs_precedes=0,.n_sep_by_space=1,.p_sign_posn=1,.n_sign_posn=1},.numeric={.decimal_point=tsc(u","),.thousands_sep=tsc(u"."),.grouping={numeric_grouping_storage,1}},.time={.abday={tsc(u"baz"),tsc(u"ber"),tsc(u"çax"),tsc(u"çər"),tsc(u"cax"),tsc(u"cüm"),tsc(u"şnb")},.day={tsc(u"bazar günü"),tsc(u"bazar ertəsi"),tsc(u"çərşənbə axşamı"),tsc(u"çərşənbə"),tsc(u"cümə axşamı"),tsc(u"cümə"),tsc(u"şənbə")},.abmon={tsc(u"Yan"),tsc(u"Fev"),tsc(u"Mar"),tsc(u"Apr"),tsc(u"May"),tsc(u"İyn"),tsc(u"İyl"),tsc(u"Avq"),tsc(u"Sen"),tsc(u"Okt"),tsc(u"Noy"),tsc(u"Dek")},.mon={tsc(u"yanvar"),tsc(u"fevral"),tsc(u"mart"),tsc(u"aprel"),tsc(u"may"),tsc(u"iyun"),tsc(u"iyul"),tsc(u"avqust"),tsc(u"sentyabr"),tsc(u"oktyabr"),tsc(u"noyabr"),tsc(u"dekabr")},.d_t_fmt=tsc(u"%A, %d %B %Y %T"),.d_fmt=tsc(u"%d.%m.%Y"),.t_fmt=tsc(u"%T"),.t_fmt_ampm=tsc(u""),.date_fmt=tsc(u"%A, %d %B %Y %T %Z"),.am_pm={tsc(u""),tsc(u"")},.week={7,19971130,1},.first_weekday=2},.messages={.yesexpr=tsc(u"^[+1bBhH]"),.noexpr=tsc(u"^[-0YyNn]"),.yesstr=tsc(u"hə"),.nostr=tsc(u"yox")},.paper={.width=210,.height=297},.telephone={.tel_int_fmt=tsc(u"+%c %a %l"),.int_select=tsc(u"00"),.int_prefix=tsc(u"994")},.name={.name_fmt=tsc(u"???")},.address={.postal_fmt=tsc(u"???"),.country_name=tsc(u"Azərbaycan"),.country_ab2=tsc(u"AZ"),.country_ab3=tsc(u"AZE"),.country_num=31,.country_car=tsc(u"AZ"),.lang_name=tsc(u"azərbaycan"),.lang_ab=tsc(u"az"),.lang_term=tsc(u"aze"),.lang_lib=tsc(u"aze")},.measurement={.measurement=1}};
inline constexpr u32lc_all u32lc_all_global{.identification={.name=tsc(U"az_AZ"),.encoding=tsc(FAST_IO_LOCALE_UENCODING),.title=tsc(U"Azeri language locale for Azerbaijan (latin)"),.source=tsc(U"fast_io"),.address=tsc(U"https://gitee.com/qabeowjbtkwb/fast_io\t\t;\t\thttps://github.com/cppfastio/fast_io"),.contact=tsc(U"Pablo Saratxaga\t\t;\t\tfast_io"),.email=tsc(U"pablo@mandrakesoft.com;euloanty@live.com"),.tel=tsc(U""),.fax=tsc(U""),.language=tsc(U"Azerbaijani"),.territory=tsc(U"Azerbaijan"),.revision=tsc(U"0.4"),.date=tsc(U"2001-01-26")},.monetary={.int_curr_symbol=tsc(U"AZN "),.currency_symbol=tsc(U"₼"),.mon_decimal_point=tsc(U"."),.mon_thousands_sep=tsc(U" "),.mon_grouping={numeric_grouping_storage,1},.positive_sign=tsc(U""),.negative_sign=tsc(U"-"),.int_frac_digits=2,.frac_digits=2,.p_cs_precedes=0,.p_sep_by_space=1,.n_cs_precedes=0,.n_sep_by_space=1,.p_sign_posn=1,.n_sign_posn=1},.numeric={.decimal_point=tsc(U","),.thousands_sep=tsc(U"."),.grouping={numeric_grouping_storage,1}},.time={.abday={tsc(U"baz"),tsc(U"ber"),tsc(U"çax"),tsc(U"çər"),tsc(U"cax"),tsc(U"cüm"),tsc(U"şnb")},.day={tsc(U"bazar günü"),tsc(U"bazar ertəsi"),tsc(U"çərşənbə axşamı"),tsc(U"çərşənbə"),tsc(U"cümə axşamı"),tsc(U"cümə"),tsc(U"şənbə")},.abmon={tsc(U"Yan"),tsc(U"Fev"),tsc(U"Mar"),tsc(U"Apr"),tsc(U"May"),tsc(U"İyn"),tsc(U"İyl"),tsc(U"Avq"),tsc(U"Sen"),tsc(U"Okt"),tsc(U"Noy"),tsc(U"Dek")},.mon={tsc(U"yanvar"),tsc(U"fevral"),tsc(U"mart"),tsc(U"aprel"),tsc(U"may"),tsc(U"iyun"),tsc(U"iyul"),tsc(U"avqust"),tsc(U"sentyabr"),tsc(U"oktyabr"),tsc(U"noyabr"),tsc(U"dekabr")},.d_t_fmt=tsc(U"%A, %d %B %Y %T"),.d_fmt=tsc(U"%d.%m.%Y"),.t_fmt=tsc(U"%T"),.t_fmt_ampm=tsc(U""),.date_fmt=tsc(U"%A, %d %B %Y %T %Z"),.am_pm={tsc(U""),tsc(U"")},.week={7,19971130,1},.first_weekday=2},.messages={.yesexpr=tsc(U"^[+1bBhH]"),.noexpr=tsc(U"^[-0YyNn]"),.yesstr=tsc(U"hə"),.nostr=tsc(U"yox")},.paper={.width=210,.height=297},.telephone={.tel_int_fmt=tsc(U"+%c %a %l"),.int_select=tsc(U"00"),.int_prefix=tsc(U"994")},.name={.name_fmt=tsc(U"???")},.address={.postal_fmt=tsc(U"???"),.country_name=tsc(U"Azərbaycan"),.country_ab2=tsc(U"AZ"),.country_ab3=tsc(U"AZE"),.country_num=31,.country_car=tsc(U"AZ"),.lang_name=tsc(U"azərbaycan"),.lang_ab=tsc(U"az"),.lang_term=tsc(U"aze"),.lang_lib=tsc(U"aze")},.measurement={.measurement=1}};
}
}
#include"../main.h" |
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#ifndef msr_air_copter_sim_CommonStructs_hpp
#define msr_air_copter_sim_CommonStructs_hpp
#include "common/Common.hpp"
#include <ostream>
namespace msr { namespace airlib {
//velocity
struct Twist {
Vector3r linear, angular;
Twist()
{}
Twist(const Vector3r& linear_val, const Vector3r& angular_val)
: linear(linear_val), angular(angular_val)
{
}
static const Twist zero()
{
static const Twist zero_twist(Vector3r::Zero(), Vector3r::Zero());
return zero_twist;
}
};
//force & torque
struct Wrench {
Vector3r force, torque;
Wrench()
{}
Wrench(const Vector3r& force_val, const Vector3r& torque_val)
: force(force_val), torque(torque_val)
{
}
//support basic arithmatic
Wrench operator+(const Wrench& other)
{
Wrench result;
result.force = this->force + other.force;
result.torque = this->torque + other.torque;
return result;
}
Wrench operator+=(const Wrench& other)
{
force += other.force;
torque += other.torque;
return *this;
}
Wrench operator-(const Wrench& other)
{
Wrench result;
result.force = this->force - other.force;
result.torque = this->torque - other.torque;
return result;
}
Wrench operator-=(const Wrench& other)
{
force -= other.force;
torque -= other.torque;
return *this;
}
static const Wrench zero()
{
static const Wrench zero_wrench(Vector3r::Zero(), Vector3r::Zero());
return zero_wrench;
}
};
struct Accelerations {
Vector3r linear;
Vector3r angular;
Accelerations()
{}
Accelerations(const Vector3r& linear_val, const Vector3r& angular_val)
: linear(linear_val), angular(angular_val)
{
}
static const Accelerations zero()
{
static const Accelerations zero_accelerations(Vector3r::Zero(), Vector3r::Zero());
return zero_accelerations;
}
};
struct PoseWithCovariance {
VectorMath::Pose pose;
vector<real_T> covariance; //36 elements, 6x6 matrix
PoseWithCovariance()
: covariance(36, 0)
{}
};
struct PowerSupply {
vector<real_T> voltage, current;
};
struct TwistWithCovariance {
Twist twist;
vector<real_T> covariance; //36 elements, 6x6 matrix
TwistWithCovariance()
: covariance(36, 0)
{}
};
struct Joystick {
vector<float> axes;
vector<int> buttons;
};
struct Odometry {
PoseWithCovariance pose;
TwistWithCovariance twist;
};
struct GeoPoint {
double latitude = 0, longitude = 0;
float altitude = 0;
GeoPoint()
{}
GeoPoint(double latitude_val, double longitude_val, float altitude_val)
{
set(latitude_val, longitude_val, altitude_val);
}
void set(double latitude_val, double longitude_val, float altitude_val)
{
latitude = latitude_val, longitude = longitude_val; altitude = altitude_val;
}
friend std::ostream& operator<<(std::ostream &os, GeoPoint const &g) {
return os << "[" << g.latitude << ", " << g.longitude << ", " << g.altitude << "]";
}
std::string to_string()
{
return std::to_string(latitude) + string(", ") + std::to_string(longitude) + string(", ") + std::to_string(altitude);
}
};
struct CollisionInfo {
bool has_collided = false;
int collison_count = 0;
Vector3r normal = Vector3r::Zero();
Vector3r impact_point = Vector3r::Zero();
Vector3r position = Vector3r::Zero();
real_T penetration_depth = 0;
};
struct GeoPose {
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
Quaternionr orientation;
GeoPoint position;
};
}} //namespace
#endif
|
/*
* Copyright (C) 2018 The Android Open Source Project
*
* 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 <filament/Camera.h>
#include <filament/Color.h>
#include <filament/IndexBuffer.h>
#include <filament/RenderableManager.h>
#include <filament/LightManager.h>
#include <filament/Texture.h>
#include <filament/VertexBuffer.h>
#include <filament/View.h>
#include <emscripten.h>
#include <emscripten/bind.h>
using namespace emscripten;
using namespace filament;
EMSCRIPTEN_BINDINGS(jsenums) {
enum_<RgbType>("RgbType")
.value("sRGB", RgbType::sRGB)
.value("LINEAR", RgbType::LINEAR);
enum_<RgbaType>("RgbaType")
.value("sRGB", RgbaType::sRGB)
.value("LINEAR", RgbaType::LINEAR)
.value("PREMULTIPLIED_sRGB", RgbaType::PREMULTIPLIED_sRGB)
.value("PREMULTIPLIED_LINEAR", RgbaType::PREMULTIPLIED_LINEAR);
enum_<VertexAttribute>("VertexAttribute")
.value("POSITION", POSITION)
.value("TANGENTS", TANGENTS)
.value("COLOR", COLOR)
.value("UV0", UV0)
.value("UV1", UV1)
.value("BONE_INDICES", BONE_INDICES)
.value("BONE_WEIGHTS", BONE_WEIGHTS);
enum_<VertexBuffer::AttributeType>("VertexBuffer$AttributeType")
.value("BYTE", VertexBuffer::AttributeType::BYTE)
.value("BYTE2", VertexBuffer::AttributeType::BYTE2)
.value("BYTE3", VertexBuffer::AttributeType::BYTE3)
.value("BYTE4", VertexBuffer::AttributeType::BYTE4)
.value("UBYTE", VertexBuffer::AttributeType::UBYTE)
.value("UBYTE2", VertexBuffer::AttributeType::UBYTE2)
.value("UBYTE3", VertexBuffer::AttributeType::UBYTE3)
.value("UBYTE4", VertexBuffer::AttributeType::UBYTE4)
.value("SHORT", VertexBuffer::AttributeType::SHORT)
.value("SHORT2", VertexBuffer::AttributeType::SHORT2)
.value("SHORT3", VertexBuffer::AttributeType::SHORT3)
.value("SHORT4", VertexBuffer::AttributeType::SHORT4)
.value("USHORT", VertexBuffer::AttributeType::USHORT)
.value("USHORT2", VertexBuffer::AttributeType::USHORT2)
.value("USHORT3", VertexBuffer::AttributeType::USHORT3)
.value("USHORT4", VertexBuffer::AttributeType::USHORT4)
.value("INT", VertexBuffer::AttributeType::INT)
.value("UINT", VertexBuffer::AttributeType::UINT)
.value("FLOAT", VertexBuffer::AttributeType::FLOAT)
.value("FLOAT2", VertexBuffer::AttributeType::FLOAT2)
.value("FLOAT3", VertexBuffer::AttributeType::FLOAT3)
.value("FLOAT4", VertexBuffer::AttributeType::FLOAT4)
.value("HALF", VertexBuffer::AttributeType::HALF)
.value("HALF2", VertexBuffer::AttributeType::HALF2)
.value("HALF3", VertexBuffer::AttributeType::HALF3)
.value("HALF4", VertexBuffer::AttributeType::HALF4);
enum_<IndexBuffer::IndexType>("IndexBuffer$IndexType")
.value("USHORT", IndexBuffer::IndexType::USHORT)
.value("UINT", IndexBuffer::IndexType::UINT);
enum_<LightManager::Type>("LightManager$Type")
.value("SUN", LightManager::Type::SUN)
.value("DIRECTIONAL", LightManager::Type::DIRECTIONAL)
.value("POINT", LightManager::Type::POINT)
.value("FOCUSED_SPOT", LightManager::Type::FOCUSED_SPOT)
.value("SPOT", LightManager::Type::SPOT);
enum_<RenderableManager::PrimitiveType>("RenderableManager$PrimitiveType")
.value("POINTS", RenderableManager::PrimitiveType::POINTS)
.value("LINES", RenderableManager::PrimitiveType::LINES)
.value("TRIANGLES", RenderableManager::PrimitiveType::TRIANGLES)
.value("NONE", RenderableManager::PrimitiveType::NONE);
enum_<View::AntiAliasing>("View$AntiAliasing")
.value("NONE", View::AntiAliasing::NONE)
.value("FXAA", View::AntiAliasing::FXAA);
enum_<View::DepthPrepass>("View$DepthPrepass")
.value("DEFAULT", View::DepthPrepass::DEFAULT)
.value("DISABLED", View::DepthPrepass::DISABLED)
.value("ENABLED", View::DepthPrepass::ENABLED);
enum_<Camera::Projection>("Camera$Projection")
.value("PERSPECTIVE", Camera::Projection::PERSPECTIVE)
.value("ORTHO", Camera::Projection::ORTHO);
enum_<Camera::Fov>("Camera$Fov")
.value("VERTICAL", Camera::Fov::VERTICAL)
.value("HORIZONTAL", Camera::Fov::HORIZONTAL);
enum_<Frustum::Plane>("Frustum$Plane")
.value("LEFT", Frustum::Plane::LEFT)
.value("RIGHT", Frustum::Plane::RIGHT)
.value("BOTTOM", Frustum::Plane::BOTTOM)
.value("TOP", Frustum::Plane::TOP)
.value("FAR", Frustum::Plane::FAR)
.value("NEAR", Frustum::Plane::NEAR);
enum_<Texture::Sampler>("Texture$Sampler") // aka driver::SamplerType
.value("SAMPLER_2D", Texture::Sampler::SAMPLER_2D)
.value("SAMPLER_CUBEMAP", Texture::Sampler::SAMPLER_CUBEMAP)
.value("SAMPLER_EXTERNAL", Texture::Sampler::SAMPLER_EXTERNAL);
enum_<Texture::InternalFormat>("Texture$InternalFormat") // aka driver::TextureFormat
.value("R8", Texture::InternalFormat::R8)
.value("R8_SNORM", Texture::InternalFormat::R8_SNORM)
.value("R8UI", Texture::InternalFormat::R8UI)
.value("R8I", Texture::InternalFormat::R8I)
.value("STENCIL8", Texture::InternalFormat::STENCIL8)
.value("R16F", Texture::InternalFormat::R16F)
.value("R16UI", Texture::InternalFormat::R16UI)
.value("R16I", Texture::InternalFormat::R16I)
.value("RG8", Texture::InternalFormat::RG8)
.value("RG8_SNORM", Texture::InternalFormat::RG8_SNORM)
.value("RG8UI", Texture::InternalFormat::RG8UI)
.value("RG8I", Texture::InternalFormat::RG8I)
.value("RGB565", Texture::InternalFormat::RGB565)
.value("RGB9_E5", Texture::InternalFormat::RGB9_E5)
.value("RGB5_A1", Texture::InternalFormat::RGB5_A1)
.value("RGBA4", Texture::InternalFormat::RGBA4)
.value("DEPTH16", Texture::InternalFormat::DEPTH16)
.value("RGB8", Texture::InternalFormat::RGB8)
.value("SRGB8", Texture::InternalFormat::SRGB8)
.value("RGB8_SNORM", Texture::InternalFormat::RGB8_SNORM)
.value("RGB8UI", Texture::InternalFormat::RGB8UI)
.value("RGB8I", Texture::InternalFormat::RGB8I)
.value("DEPTH24", Texture::InternalFormat::DEPTH24)
.value("R32F", Texture::InternalFormat::R32F)
.value("R32UI", Texture::InternalFormat::R32UI)
.value("R32I", Texture::InternalFormat::R32I)
.value("RG16F", Texture::InternalFormat::RG16F)
.value("RG16UI", Texture::InternalFormat::RG16UI)
.value("RG16I", Texture::InternalFormat::RG16I)
.value("R11F_G11F_B10F", Texture::InternalFormat::R11F_G11F_B10F)
.value("RGBA8", Texture::InternalFormat::RGBA8)
.value("SRGB8_A8", Texture::InternalFormat::SRGB8_A8)
.value("RGBA8_SNORM", Texture::InternalFormat::RGBA8_SNORM)
.value("UNUSED", Texture::InternalFormat::UNUSED)
.value("RGB10_A2", Texture::InternalFormat::RGB10_A2)
.value("RGBA8UI", Texture::InternalFormat::RGBA8UI)
.value("RGBA8I", Texture::InternalFormat::RGBA8I)
.value("DEPTH32F", Texture::InternalFormat::DEPTH32F)
.value("DEPTH24_STENCIL8", Texture::InternalFormat::DEPTH24_STENCIL8)
.value("DEPTH32F_STENCIL8", Texture::InternalFormat::DEPTH32F_STENCIL8)
.value("RGB16F", Texture::InternalFormat::RGB16F)
.value("RGB16UI", Texture::InternalFormat::RGB16UI)
.value("RGB16I", Texture::InternalFormat::RGB16I)
.value("RG32F", Texture::InternalFormat::RG32F)
.value("RG32UI", Texture::InternalFormat::RG32UI)
.value("RG32I", Texture::InternalFormat::RG32I)
.value("RGBA16F", Texture::InternalFormat::RGBA16F)
.value("RGBA16UI", Texture::InternalFormat::RGBA16UI)
.value("RGBA16I", Texture::InternalFormat::RGBA16I)
.value("RGB32F", Texture::InternalFormat::RGB32F)
.value("RGB32UI", Texture::InternalFormat::RGB32UI)
.value("RGB32I", Texture::InternalFormat::RGB32I)
.value("RGBA32F", Texture::InternalFormat::RGBA32F)
.value("RGBA32UI", Texture::InternalFormat::RGBA32UI)
.value("RGBA32I", Texture::InternalFormat::RGBA32I)
.value("EAC_R11", Texture::InternalFormat::EAC_R11)
.value("EAC_R11_SIGNED", Texture::InternalFormat::EAC_R11_SIGNED)
.value("EAC_RG11", Texture::InternalFormat::EAC_RG11)
.value("EAC_RG11_SIGNED", Texture::InternalFormat::EAC_RG11_SIGNED)
.value("ETC2_RGB8", Texture::InternalFormat::ETC2_RGB8)
.value("ETC2_SRGB8", Texture::InternalFormat::ETC2_SRGB8)
.value("ETC2_RGB8_A1", Texture::InternalFormat::ETC2_RGB8_A1)
.value("ETC2_SRGB8_A1", Texture::InternalFormat::ETC2_SRGB8_A1)
.value("ETC2_EAC_RGBA8", Texture::InternalFormat::ETC2_EAC_RGBA8)
.value("ETC2_EAC_SRGBA8", Texture::InternalFormat::ETC2_EAC_SRGBA8)
.value("DXT1_RGB", Texture::InternalFormat::DXT1_RGB)
.value("DXT1_RGBA", Texture::InternalFormat::DXT1_RGBA)
.value("DXT3_RGBA", Texture::InternalFormat::DXT3_RGBA)
.value("DXT5_RGBA", Texture::InternalFormat::DXT5_RGBA)
.value("RGBA_ASTC_4x4", Texture::InternalFormat::RGBA_ASTC_4x4)
.value("RGBA_ASTC_5x4", Texture::InternalFormat::RGBA_ASTC_5x4)
.value("RGBA_ASTC_5x5", Texture::InternalFormat::RGBA_ASTC_5x5)
.value("RGBA_ASTC_6x5", Texture::InternalFormat::RGBA_ASTC_6x5)
.value("RGBA_ASTC_6x6", Texture::InternalFormat::RGBA_ASTC_6x6)
.value("RGBA_ASTC_8x5", Texture::InternalFormat::RGBA_ASTC_8x5)
.value("RGBA_ASTC_8x6", Texture::InternalFormat::RGBA_ASTC_8x6)
.value("RGBA_ASTC_8x8", Texture::InternalFormat::RGBA_ASTC_8x8)
.value("RGBA_ASTC_10x5", Texture::InternalFormat::RGBA_ASTC_10x5)
.value("RGBA_ASTC_10x6", Texture::InternalFormat::RGBA_ASTC_10x6)
.value("RGBA_ASTC_10x8", Texture::InternalFormat::RGBA_ASTC_10x8)
.value("RGBA_ASTC_10x10", Texture::InternalFormat::RGBA_ASTC_10x10)
.value("RGBA_ASTC_12x10", Texture::InternalFormat::RGBA_ASTC_12x10)
.value("RGBA_ASTC_12x12", Texture::InternalFormat::RGBA_ASTC_12x12)
.value("SRGB8_ALPHA8_ASTC_4x4", Texture::InternalFormat::SRGB8_ALPHA8_ASTC_4x4)
.value("SRGB8_ALPHA8_ASTC_5x4", Texture::InternalFormat::SRGB8_ALPHA8_ASTC_5x4)
.value("SRGB8_ALPHA8_ASTC_5x5", Texture::InternalFormat::SRGB8_ALPHA8_ASTC_5x5)
.value("SRGB8_ALPHA8_ASTC_6x5", Texture::InternalFormat::SRGB8_ALPHA8_ASTC_6x5)
.value("SRGB8_ALPHA8_ASTC_6x6", Texture::InternalFormat::SRGB8_ALPHA8_ASTC_6x6)
.value("SRGB8_ALPHA8_ASTC_8x5", Texture::InternalFormat::SRGB8_ALPHA8_ASTC_8x5)
.value("SRGB8_ALPHA8_ASTC_8x6", Texture::InternalFormat::SRGB8_ALPHA8_ASTC_8x6)
.value("SRGB8_ALPHA8_ASTC_8x8", Texture::InternalFormat::SRGB8_ALPHA8_ASTC_8x8)
.value("SRGB8_ALPHA8_ASTC_10x5", Texture::InternalFormat::SRGB8_ALPHA8_ASTC_10x5)
.value("SRGB8_ALPHA8_ASTC_10x6", Texture::InternalFormat::SRGB8_ALPHA8_ASTC_10x6)
.value("SRGB8_ALPHA8_ASTC_10x8", Texture::InternalFormat::SRGB8_ALPHA8_ASTC_10x8)
.value("SRGB8_ALPHA8_ASTC_10x10", Texture::InternalFormat::SRGB8_ALPHA8_ASTC_10x10)
.value("SRGB8_ALPHA8_ASTC_12x10", Texture::InternalFormat::SRGB8_ALPHA8_ASTC_12x10)
.value("SRGB8_ALPHA8_ASTC_12x12", Texture::InternalFormat::SRGB8_ALPHA8_ASTC_12x12);
enum_<Texture::Usage>("Texture$Usage") // aka driver::TextureUsage
.value("DEFAULT", Texture::Usage::DEFAULT)
.value("COLOR_ATTACHMENT", Texture::Usage::COLOR_ATTACHMENT)
.value("DEPTH_ATTACHMENT", Texture::Usage::DEPTH_ATTACHMENT);
enum_<driver::PixelDataFormat>("PixelDataFormat")
.value("R", driver::PixelDataFormat::R)
.value("R_INTEGER", driver::PixelDataFormat::R_INTEGER)
.value("RG", driver::PixelDataFormat::RG)
.value("RG_INTEGER", driver::PixelDataFormat::RG_INTEGER)
.value("RGB", driver::PixelDataFormat::RGB)
.value("RGB_INTEGER", driver::PixelDataFormat::RGB_INTEGER)
.value("RGBA", driver::PixelDataFormat::RGBA)
.value("RGBA_INTEGER", driver::PixelDataFormat::RGBA_INTEGER)
.value("RGBM", driver::PixelDataFormat::RGBM)
.value("DEPTH_COMPONENT", driver::PixelDataFormat::DEPTH_COMPONENT)
.value("DEPTH_STENCIL", driver::PixelDataFormat::DEPTH_STENCIL)
.value("ALPHA", driver::PixelDataFormat::ALPHA);
enum_<driver::PixelDataType>("PixelDataType")
.value("UBYTE", driver::PixelDataType::UBYTE)
.value("BYTE", driver::PixelDataType::BYTE)
.value("USHORT", driver::PixelDataType::USHORT)
.value("SHORT", driver::PixelDataType::SHORT)
.value("UINT", driver::PixelDataType::UINT)
.value("INT", driver::PixelDataType::INT)
.value("HALF", driver::PixelDataType::HALF)
.value("FLOAT", driver::PixelDataType::FLOAT);
enum_<driver::CompressedPixelDataType>("CompressedPixelDataType")
.value("EAC_R11", driver::CompressedPixelDataType::EAC_R11)
.value("EAC_R11_SIGNED", driver::CompressedPixelDataType::EAC_R11_SIGNED)
.value("EAC_RG11", driver::CompressedPixelDataType::EAC_RG11)
.value("EAC_RG11_SIGNED", driver::CompressedPixelDataType::EAC_RG11_SIGNED)
.value("ETC2_RGB8", driver::CompressedPixelDataType::ETC2_RGB8)
.value("ETC2_SRGB8", driver::CompressedPixelDataType::ETC2_SRGB8)
.value("ETC2_RGB8_A1", driver::CompressedPixelDataType::ETC2_RGB8_A1)
.value("ETC2_SRGB8_A1", driver::CompressedPixelDataType::ETC2_SRGB8_A1)
.value("ETC2_EAC_RGBA8", driver::CompressedPixelDataType::ETC2_EAC_RGBA8)
.value("ETC2_EAC_SRGBA8", driver::CompressedPixelDataType::ETC2_EAC_SRGBA8)
.value("DXT1_RGB", driver::CompressedPixelDataType::DXT1_RGB)
.value("DXT1_RGBA", driver::CompressedPixelDataType::DXT1_RGBA)
.value("DXT3_RGBA", driver::CompressedPixelDataType::DXT3_RGBA)
.value("DXT5_RGBA", driver::CompressedPixelDataType::DXT5_RGBA)
.value("RGBA_ASTC_4x4", driver::CompressedPixelDataType::RGBA_ASTC_4x4)
.value("RGBA_ASTC_5x4", driver::CompressedPixelDataType::RGBA_ASTC_5x4)
.value("RGBA_ASTC_5x5", driver::CompressedPixelDataType::RGBA_ASTC_5x5)
.value("RGBA_ASTC_6x5", driver::CompressedPixelDataType::RGBA_ASTC_6x5)
.value("RGBA_ASTC_6x6", driver::CompressedPixelDataType::RGBA_ASTC_6x6)
.value("RGBA_ASTC_8x5", driver::CompressedPixelDataType::RGBA_ASTC_8x5)
.value("RGBA_ASTC_8x6", driver::CompressedPixelDataType::RGBA_ASTC_8x6)
.value("RGBA_ASTC_8x8", driver::CompressedPixelDataType::RGBA_ASTC_8x8)
.value("RGBA_ASTC_10x5", driver::CompressedPixelDataType::RGBA_ASTC_10x5)
.value("RGBA_ASTC_10x6", driver::CompressedPixelDataType::RGBA_ASTC_10x6)
.value("RGBA_ASTC_10x8", driver::CompressedPixelDataType::RGBA_ASTC_10x8)
.value("RGBA_ASTC_10x10", driver::CompressedPixelDataType::RGBA_ASTC_10x10)
.value("RGBA_ASTC_12x10", driver::CompressedPixelDataType::RGBA_ASTC_12x10)
.value("RGBA_ASTC_12x12", driver::CompressedPixelDataType::RGBA_ASTC_12x12)
.value("SRGB8_ALPHA8_ASTC_4x4", driver::CompressedPixelDataType::SRGB8_ALPHA8_ASTC_4x4)
.value("SRGB8_ALPHA8_ASTC_5x4", driver::CompressedPixelDataType::SRGB8_ALPHA8_ASTC_5x4)
.value("SRGB8_ALPHA8_ASTC_5x5", driver::CompressedPixelDataType::SRGB8_ALPHA8_ASTC_5x5)
.value("SRGB8_ALPHA8_ASTC_6x5", driver::CompressedPixelDataType::SRGB8_ALPHA8_ASTC_6x5)
.value("SRGB8_ALPHA8_ASTC_6x6", driver::CompressedPixelDataType::SRGB8_ALPHA8_ASTC_6x6)
.value("SRGB8_ALPHA8_ASTC_8x5", driver::CompressedPixelDataType::SRGB8_ALPHA8_ASTC_8x5)
.value("SRGB8_ALPHA8_ASTC_8x6", driver::CompressedPixelDataType::SRGB8_ALPHA8_ASTC_8x6)
.value("SRGB8_ALPHA8_ASTC_8x8", driver::CompressedPixelDataType::SRGB8_ALPHA8_ASTC_8x8)
.value("SRGB8_ALPHA8_ASTC_10x5", driver::CompressedPixelDataType::SRGB8_ALPHA8_ASTC_10x5)
.value("SRGB8_ALPHA8_ASTC_10x6", driver::CompressedPixelDataType::SRGB8_ALPHA8_ASTC_10x6)
.value("SRGB8_ALPHA8_ASTC_10x8", driver::CompressedPixelDataType::SRGB8_ALPHA8_ASTC_10x8)
.value("SRGB8_ALPHA8_ASTC_10x10", driver::CompressedPixelDataType::SRGB8_ALPHA8_ASTC_10x10)
.value("SRGB8_ALPHA8_ASTC_12x10", driver::CompressedPixelDataType::SRGB8_ALPHA8_ASTC_12x10)
.value("SRGB8_ALPHA8_ASTC_12x12", driver::CompressedPixelDataType::SRGB8_ALPHA8_ASTC_12x12);
enum_<driver::SamplerWrapMode>("WrapMode")
.value("CLAMP_TO_EDGE", driver::SamplerWrapMode::CLAMP_TO_EDGE)
.value("REPEAT", driver::SamplerWrapMode::REPEAT)
.value("MIRRORED_REPEAT", driver::SamplerWrapMode::MIRRORED_REPEAT);
enum_<driver::SamplerMinFilter>("MinFilter")
.value("NEAREST", driver::SamplerMinFilter::NEAREST)
.value("LINEAR", driver::SamplerMinFilter::LINEAR)
.value("NEAREST_MIPMAP_NEAREST", driver::SamplerMinFilter::NEAREST_MIPMAP_NEAREST)
.value("LINEAR_MIPMAP_NEAREST", driver::SamplerMinFilter::LINEAR_MIPMAP_NEAREST)
.value("NEAREST_MIPMAP_LINEAR", driver::SamplerMinFilter::NEAREST_MIPMAP_LINEAR)
.value("LINEAR_MIPMAP_LINEAR", driver::SamplerMinFilter::LINEAR_MIPMAP_LINEAR);
enum_<driver::SamplerMagFilter>("MagFilter")
.value("NEAREST", driver::SamplerMagFilter::NEAREST)
.value("LINEAR", driver::SamplerMagFilter::LINEAR);
}
|
; A155579: Recursive sequence (n+1)*a(n) = 3*(3*n-2)*a(n-1).
; Submitted by Christian Krause
; 2,3,12,63,378,2457,16848,120042,880308,6602310,50417640,390736710,3065780340,24307258410,194458067280,1567818167445,12726994535730,103937122041795,853378475711580,7040372424620535,58334514375427290,485237096850145185,4050674895444690240,33924402249349280760,284964978894533958384,2400281937611651418696,20269047473165056424544,171563008969289941879176,1455327593325700886285424,12370284543268457533426104,105346939336221702865306176,898741076212141402569643314,7680151014903753803776951956
add $0,1
seq $0,4989 ; a(n) = (3^n/n!) * Product_{k=0..n-1} (3*k - 2).
mul $0,-1
div $0,3
|
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Copyright (c) GeoWorks 1992 -- All Rights Reserved
PROJECT: PC GEOS
MODULE:
FILE: trSmallGet.asm
AUTHOR: John Wedgwood, Feb 12, 1992
ROUTINES:
Name Description
---- -----------
REVISION HISTORY:
Name Date Description
---- ---- -----------
John 2/12/92 Initial revision
DESCRIPTION:
Code for getting information about regions in small objects.
$Id: trSmallGet.asm,v 1.1 97/04/07 11:21:50 newdeal Exp $
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
TextRegion segment resource
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SmallRegionGetTopLine
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Get the top line of a region in a small object.
CALLED BY: TR_GetTopLine via CallRegionHandlers
PASS: *ds:si = Instance
cx = Region
RETURN: bx.di = Top line
DESTROYED: nothing
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
jcw 2/12/92 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
SmallRegionGetTopLine proc near
EC < call ECSmallCheckRegionNumber >
clrdw bxdi ; The first line is always 0
ret
SmallRegionGetTopLine endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SmallRegionGetStartOffset
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Get the starting offset of a region in a small object.
CALLED BY: TR_GetStartOffset via CallRegionHandlers
PASS: *ds:si = Instance
cx = Region
RETURN: dx.ax = Starting offset
DESTROYED: nothing
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
jcw 2/12/92 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
SmallRegionGetStartOffset proc near
EC < call ECSmallCheckRegionNumber >
clrdw dxax ; The start offset is always 0
ret
SmallRegionGetStartOffset endp
TextRegion ends
|
/*
* Copyright (c) 2012-2013 ARM Limited
* All rights reserved.
*
* The license below extends only to copyright in the software and shall
* not be construed as granting a license to any other intellectual
* property including but not limited to intellectual property relating
* to a hardware implementation of the functionality of the software
* licensed hereunder. You may use the software subject to the license
* terms below provided that you ensure that this notice is replicated
* unmodified and in its entirety in all distributions of the software,
* modified or unmodified, in source code or in binary form.
*
* Copyright (c) 2009 Advanced Micro Devices, Inc.
* Copyright (c) 2011 Mark D. Hill and David A. Wood
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met: redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer;
* redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution;
* neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __MEM_RUBY_SYSTEM_RUBYPORT_HH__
#define __MEM_RUBY_SYSTEM_RUBYPORT_HH__
#include <cassert>
#include <string>
#include "mem/protocol/RequestStatus.hh"
#include "mem/ruby/buffers/MessageBuffer.hh"
#include "mem/ruby/system/System.hh"
#include "mem/mem_object.hh"
#include "mem/tport.hh"
#include "params/RubyPort.hh"
class AbstractController;
class RubyPort : public MemObject
{
public:
class MemMasterPort : public QueuedMasterPort
{
private:
MasterPacketQueue queue;
public:
MemMasterPort(const std::string &_name, RubyPort *_port);
protected:
bool recvTimingResp(PacketPtr pkt);
void recvRangeChange() {}
};
class MemSlavePort : public QueuedSlavePort
{
private:
SlavePacketQueue queue;
RubySystem* ruby_system;
bool access_phys_mem;
public:
MemSlavePort(const std::string &_name, RubyPort *_port,
RubySystem*_system, bool _access_phys_mem, PortID id);
void hitCallback(PacketPtr pkt);
void evictionCallback(const Address& address);
protected:
bool recvTimingReq(PacketPtr pkt);
Tick recvAtomic(PacketPtr pkt)
{ panic("RubyPort::MemSlavePort::recvAtomic() not implemented!\n"); }
void recvFunctional(PacketPtr pkt);
AddrRangeList getAddrRanges() const
{ AddrRangeList ranges; return ranges; }
private:
bool isPhysMemAddress(Addr addr) const;
};
class PioMasterPort : public QueuedMasterPort
{
private:
MasterPacketQueue queue;
public:
PioMasterPort(const std::string &_name, RubyPort *_port);
protected:
bool recvTimingResp(PacketPtr pkt);
void recvRangeChange();
};
class PioSlavePort : public QueuedSlavePort
{
private:
SlavePacketQueue queue;
public:
PioSlavePort(const std::string &_name, RubyPort *_port);
protected:
bool recvTimingReq(PacketPtr pkt);
Tick recvAtomic(PacketPtr pkt)
{ panic("recvAtomic not supported with ruby!"); }
void recvFunctional(PacketPtr pkt)
{ panic("recvFunctional should never be called on pio slave port!"); }
AddrRangeList getAddrRanges() const;
};
struct SenderState : public Packet::SenderState
{
MemSlavePort *port;
SenderState(MemSlavePort * _port) : port(_port)
{}
};
typedef RubyPortParams Params;
RubyPort(const Params *p);
virtual ~RubyPort() {}
void init();
BaseMasterPort &getMasterPort(const std::string &if_name,
PortID idx = InvalidPortID);
BaseSlavePort &getSlavePort(const std::string &if_name,
PortID idx = InvalidPortID);
virtual RequestStatus makeRequest(PacketPtr pkt) = 0;
virtual int outstandingCount() const = 0;
virtual bool isDeadlockEventScheduled() const = 0;
virtual void descheduleDeadlockEvent() = 0;
//
// Called by the controller to give the sequencer a pointer.
// A pointer to the controller is needed for atomic support.
//
void setController(AbstractController* _cntrl) { m_controller = _cntrl; }
uint32_t getId() { return m_version; }
unsigned int drain(DrainManager *dm);
protected:
void ruby_hit_callback(PacketPtr pkt);
void testDrainComplete();
void ruby_eviction_callback(const Address& address);
/**
* Called by the PIO port when receiving a timing response.
*
* @param pkt Response packet
* @param master_port_id Port id of the PIO port
*
* @return Whether successfully sent
*/
bool recvTimingResp(PacketPtr pkt, PortID master_port_id);
uint32_t m_version;
AbstractController* m_controller;
MessageBuffer* m_mandatory_q_ptr;
bool m_usingRubyTester;
private:
void addToRetryList(MemSlavePort * port)
{
assert(std::find(retryList.begin(), retryList.end(), port) ==
retryList.end());
retryList.push_back(port);
}
unsigned int getChildDrainCount(DrainManager *dm);
PioMasterPort pioMasterPort;
PioSlavePort pioSlavePort;
MemMasterPort memMasterPort;
MemSlavePort memSlavePort;
unsigned int gotAddrRanges;
/** Vector of M5 Ports attached to this Ruby port. */
typedef std::vector<MemSlavePort *>::iterator CpuPortIter;
std::vector<MemSlavePort *> slave_ports;
std::vector<PioMasterPort *> master_ports;
DrainManager *drainManager;
System* system;
//
// Based on similar code in the M5 bus. Stores pointers to those ports
// that should be called when the Sequencer becomes available after a stall.
//
std::vector<MemSlavePort *> retryList;
bool access_phys_mem;
};
#endif // __MEM_RUBY_SYSTEM_RUBYPORT_HH__
|
; A098610: a(n) = 10^n + (-1)^n.
; 2,9,101,999,10001,99999,1000001,9999999,100000001,999999999,10000000001,99999999999,1000000000001,9999999999999,100000000000001,999999999999999,10000000000000001,99999999999999999,1000000000000000001,9999999999999999999,100000000000000000001,999999999999999999999,10000000000000000000001,99999999999999999999999,1000000000000000000000001,9999999999999999999999999,100000000000000000000000001,999999999999999999999999999,10000000000000000000000000001,99999999999999999999999999999,1000000000000000000000000000001,9999999999999999999999999999999,100000000000000000000000000000001,999999999999999999999999999999999,10000000000000000000000000000000001,99999999999999999999999999999999999
mov $1,10
pow $1,$0
mod $0,2
sub $1,$0
sub $1,$0
add $1,1
mov $0,$1
|
// 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 "chrome/browser/extensions/api/storage/settings_storage_quota_enforcer.h"
#include "base/bind.h"
#include "base/json/json_writer.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop.h"
#include "base/metrics/histogram.h"
#include "chrome/common/extensions/api/extension_api.h"
#include "extensions/common/error_utils.h"
namespace extensions {
namespace {
const char* kQuotaExceededError = "* quota exceeded.";
// Resources there are a quota for.
enum Resource {
QUOTA_BYTES,
QUOTA_BYTES_PER_ITEM,
MAX_ITEMS
};
// Allocates a setting in a record of total and per-setting usage.
void Allocate(
const std::string& key,
const Value& value,
size_t* used_total,
std::map<std::string, size_t>* used_per_setting) {
// Calculate the setting size based on its JSON serialization size.
// TODO(kalman): Does this work with different encodings?
// TODO(kalman): This is duplicating work that the leveldb delegate
// implementation is about to do, and it would be nice to avoid this.
std::string value_as_json;
base::JSONWriter::Write(&value, &value_as_json);
size_t new_size = key.size() + value_as_json.size();
size_t existing_size = (*used_per_setting)[key];
*used_total += (new_size - existing_size);
(*used_per_setting)[key] = new_size;
}
// Frees the allocation of a setting in a record of total and per-setting usage.
void Free(
size_t* used_total,
std::map<std::string, size_t>* used_per_setting,
const std::string& key) {
*used_total -= (*used_per_setting)[key];
used_per_setting->erase(key);
}
// Returns an error result and logs the quota exceeded to UMA.
ValueStore::WriteResult QuotaExceededFor(Resource resource) {
std::string name;
switch (resource) {
case QUOTA_BYTES:
name = "QUOTA_BYTES";
UMA_HISTOGRAM_COUNTS_100(
"Extensions.SettingsQuotaExceeded.TotalBytes", 1);
break;
case QUOTA_BYTES_PER_ITEM:
name = "QUOTA_BYTES_PER_ITEM";
UMA_HISTOGRAM_COUNTS_100(
"Extensions.SettingsQuotaExceeded.BytesPerSetting", 1);
break;
case MAX_ITEMS:
name = "MAX_ITEMS";
UMA_HISTOGRAM_COUNTS_100(
"Extensions.SettingsQuotaExceeded.KeyCount", 1);
break;
default:
NOTREACHED();
}
return ValueStore::MakeWriteResult(
ErrorUtils::FormatErrorMessage(kQuotaExceededError, name));
}
} // namespace
SettingsStorageQuotaEnforcer::SettingsStorageQuotaEnforcer(
const Limits& limits, ValueStore* delegate)
: limits_(limits), delegate_(delegate), used_total_(0) {
ReadResult maybe_settings = delegate_->Get();
if (maybe_settings->HasError()) {
LOG(WARNING) << "Failed to get initial settings for quota: " <<
maybe_settings->error();
return;
}
for (DictionaryValue::Iterator it(*maybe_settings->settings().get());
!it.IsAtEnd(); it.Advance()) {
Allocate(it.key(), it.value(), &used_total_, &used_per_setting_);
}
}
SettingsStorageQuotaEnforcer::~SettingsStorageQuotaEnforcer() {}
size_t SettingsStorageQuotaEnforcer::GetBytesInUse(const std::string& key) {
std::map<std::string, size_t>::iterator maybe_used =
used_per_setting_.find(key);
return maybe_used == used_per_setting_.end() ? 0u : maybe_used->second;
}
size_t SettingsStorageQuotaEnforcer::GetBytesInUse(
const std::vector<std::string>& keys) {
size_t used = 0;
for (std::vector<std::string>::const_iterator it = keys.begin();
it != keys.end(); ++it) {
used += GetBytesInUse(*it);
}
return used;
}
size_t SettingsStorageQuotaEnforcer::GetBytesInUse() {
// All ValueStore implementations rely on GetBytesInUse being
// implemented here.
return used_total_;
}
ValueStore::ReadResult SettingsStorageQuotaEnforcer::Get(
const std::string& key) {
return delegate_->Get(key);
}
ValueStore::ReadResult SettingsStorageQuotaEnforcer::Get(
const std::vector<std::string>& keys) {
return delegate_->Get(keys);
}
ValueStore::ReadResult SettingsStorageQuotaEnforcer::Get() {
return delegate_->Get();
}
ValueStore::WriteResult SettingsStorageQuotaEnforcer::Set(
WriteOptions options, const std::string& key, const Value& value) {
size_t new_used_total = used_total_;
std::map<std::string, size_t> new_used_per_setting = used_per_setting_;
Allocate(key, value, &new_used_total, &new_used_per_setting);
if (!(options & IGNORE_QUOTA)) {
if (new_used_total > limits_.quota_bytes) {
return QuotaExceededFor(QUOTA_BYTES);
}
if (new_used_per_setting[key] > limits_.quota_bytes_per_item) {
return QuotaExceededFor(QUOTA_BYTES_PER_ITEM);
}
if (new_used_per_setting.size() > limits_.max_items) {
return QuotaExceededFor(MAX_ITEMS);
}
}
WriteResult result = delegate_->Set(options, key, value);
if (result->HasError()) {
return result.Pass();
}
used_total_ = new_used_total;
used_per_setting_.swap(new_used_per_setting);
return result.Pass();
}
ValueStore::WriteResult SettingsStorageQuotaEnforcer::Set(
WriteOptions options, const DictionaryValue& values) {
size_t new_used_total = used_total_;
std::map<std::string, size_t> new_used_per_setting = used_per_setting_;
for (DictionaryValue::Iterator it(values); !it.IsAtEnd(); it.Advance()) {
Allocate(it.key(), it.value(), &new_used_total, &new_used_per_setting);
if (!(options & IGNORE_QUOTA) &&
new_used_per_setting[it.key()] > limits_.quota_bytes_per_item) {
return QuotaExceededFor(QUOTA_BYTES_PER_ITEM);
}
}
if (!(options & IGNORE_QUOTA)) {
if (new_used_total > limits_.quota_bytes) {
return QuotaExceededFor(QUOTA_BYTES);
}
if (new_used_per_setting.size() > limits_.max_items) {
return QuotaExceededFor(MAX_ITEMS);
}
}
WriteResult result = delegate_->Set(options, values);
if (result->HasError()) {
return result.Pass();
}
used_total_ = new_used_total;
used_per_setting_ = new_used_per_setting;
return result.Pass();
}
ValueStore::WriteResult SettingsStorageQuotaEnforcer::Remove(
const std::string& key) {
WriteResult result = delegate_->Remove(key);
if (result->HasError()) {
return result.Pass();
}
Free(&used_total_, &used_per_setting_, key);
return result.Pass();
}
ValueStore::WriteResult SettingsStorageQuotaEnforcer::Remove(
const std::vector<std::string>& keys) {
WriteResult result = delegate_->Remove(keys);
if (result->HasError()) {
return result.Pass();
}
for (std::vector<std::string>::const_iterator it = keys.begin();
it != keys.end(); ++it) {
Free(&used_total_, &used_per_setting_, *it);
}
return result.Pass();
}
ValueStore::WriteResult SettingsStorageQuotaEnforcer::Clear() {
WriteResult result = delegate_->Clear();
if (result->HasError()) {
return result.Pass();
}
while (!used_per_setting_.empty()) {
Free(&used_total_, &used_per_setting_, used_per_setting_.begin()->first);
}
return result.Pass();
}
} // namespace extensions
|
/****************************************************************************
Copyright (c) 2013-2014 Chukong Technologies Inc.
http://www.cocos2d-x.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 "2d/CCNodeGrid.h"
#include "2d/CCGrid.h"
#include "renderer/CCRenderer.h"
NS_CC_BEGIN
NodeGrid* NodeGrid::create()
{
NodeGrid * ret = new (std::nothrow) NodeGrid();
if (ret && ret->init())
{
ret->autorelease();
}
else
{
CC_SAFE_DELETE(ret);
}
return ret;
}
NodeGrid* NodeGrid::create(const cocos2d::Rect &rect)
{
NodeGrid* ret = NodeGrid::create();
if (ret) {
ret->setGridRect(rect);
}
return ret;
}
NodeGrid::NodeGrid()
: _gridTarget(nullptr)
, _nodeGrid(nullptr)
, _gridRect(Rect::ZERO)
{
}
void NodeGrid::setTarget(Node* target)
{
#if CC_ENABLE_GC_FOR_NATIVE_OBJECTS
auto sEngine = ScriptEngineManager::getInstance()->getScriptEngine();
if (sEngine)
{
if (_gridTarget)
sEngine->releaseScriptObject(this, _gridTarget);
if (target)
sEngine->retainScriptObject(this, target);
}
#endif // CC_ENABLE_GC_FOR_NATIVE_OBJECTS
CC_SAFE_RELEASE(_gridTarget);
CC_SAFE_RETAIN(target);
_gridTarget = target;
}
NodeGrid::~NodeGrid()
{
CC_SAFE_RELEASE(_nodeGrid);
CC_SAFE_RELEASE(_gridTarget);
}
void NodeGrid::onGridBeginDraw()
{
if (_nodeGrid && _nodeGrid->isActive())
{
_nodeGrid->beforeDraw();
}
}
void NodeGrid::onGridEndDraw()
{
if(_nodeGrid && _nodeGrid->isActive())
{
_nodeGrid->afterDraw(this);
}
}
void NodeGrid::visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags)
{
// quick return if not visible. children won't be drawn.
if (!_visible)
{
return;
}
bool dirty = (parentFlags & FLAGS_TRANSFORM_DIRTY) || _transformUpdated;
if(dirty)
_modelViewTransform = this->transform(parentTransform);
_transformUpdated = false;
_groupCommand.init(_globalZOrder);
renderer->addCommand(&_groupCommand);
renderer->pushGroup(_groupCommand.getRenderQueueID());
// IMPORTANT:
// To ease the migration to v3.0, we still support the Mat4 stack,
// but it is deprecated and your code should not rely on it
Director* director = Director::getInstance();
CCASSERT(nullptr != director, "Director is null when setting matrix stack");
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform);
Director::Projection beforeProjectionType = Director::Projection::DEFAULT;
if(_nodeGrid && _nodeGrid->isActive())
{
beforeProjectionType = Director::getInstance()->getProjection();
_nodeGrid->set2DProjection();
}
_gridBeginCommand.init(_globalZOrder);
_gridBeginCommand.func = CC_CALLBACK_0(NodeGrid::onGridBeginDraw, this);
renderer->addCommand(&_gridBeginCommand);
if(_gridTarget)
{
_gridTarget->visit(renderer, _modelViewTransform, dirty);
}
int i = 0;
bool visibleByCamera = isVisitableByVisitingCamera();
if(!_children.empty())
{
sortAllChildren();
// draw children zOrder < 0
for( ; i < _children.size(); i++ )
{
auto node = _children.at(i);
if ( node && node->getLocalZOrder() < 0 )
node->visit(renderer, _modelViewTransform, dirty);
else
break;
}
// self draw,currently we have nothing to draw on NodeGrid, so there is no need to add render command
if (visibleByCamera)
this->draw(renderer, _modelViewTransform, dirty);
for(auto it=_children.cbegin()+i; it != _children.cend(); ++it) {
(*it)->visit(renderer, _modelViewTransform, dirty);
}
}
else if (visibleByCamera)
{
this->draw(renderer, _modelViewTransform, dirty);
}
// FIX ME: Why need to set _orderOfArrival to 0??
// Please refer to https://github.com/cocos2d/cocos2d-x/pull/6920
// setOrderOfArrival(0);
if(_nodeGrid && _nodeGrid->isActive())
{
// restore projection
director->setProjection(beforeProjectionType);
}
_gridEndCommand.init(_globalZOrder);
_gridEndCommand.func = CC_CALLBACK_0(NodeGrid::onGridEndDraw, this);
renderer->addCommand(&_gridEndCommand);
renderer->popGroup();
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
}
void NodeGrid::setGrid(GridBase *grid)
{
CC_SAFE_RELEASE(_nodeGrid);
CC_SAFE_RETAIN(grid);
_nodeGrid = grid;
}
NS_CC_END
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.