text stringlengths 1 1.05M |
|---|
###############################################################################
# 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.
###############################################################################
.text
.p2align 4, 0x90
.globl _p8_GCMreduce
_p8_GCMreduce:
push %ebp
mov %esp, %ebp
push %esi
push %edi
movl (8)(%ebp), %esi
movdqu (%esi), %xmm3
movdqu (16)(%esi), %xmm6
movl (12)(%ebp), %esi
movdqu %xmm3, %xmm4
movdqu %xmm6, %xmm5
pslld $(1), %xmm3
pslld $(1), %xmm6
psrld $(31), %xmm4
psrld $(31), %xmm5
palignr $(12), %xmm4, %xmm5
pslldq $(4), %xmm4
por %xmm4, %xmm3
por %xmm5, %xmm6
movdqu %xmm3, %xmm0
movdqu %xmm3, %xmm1
movdqu %xmm3, %xmm2
pslld $(31), %xmm0
pslld $(30), %xmm1
pslld $(25), %xmm2
pxor %xmm1, %xmm0
pxor %xmm2, %xmm0
movdqu %xmm0, %xmm1
pslldq $(12), %xmm0
pxor %xmm0, %xmm3
movdqu %xmm3, %xmm2
movdqu %xmm3, %xmm4
movdqu %xmm3, %xmm5
psrldq $(4), %xmm1
psrld $(1), %xmm2
psrld $(2), %xmm4
psrld $(7), %xmm5
pxor %xmm4, %xmm2
pxor %xmm5, %xmm2
pxor %xmm1, %xmm2
pxor %xmm2, %xmm3
pxor %xmm3, %xmm6
movdqu %xmm6, (%esi)
pop %edi
pop %esi
pop %ebp
ret
|
////////////////////////////////////////////////////////////////////////////////
/// DISCLAIMER
///
/// Copyright 2016 by EMC Corporation, 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.
///
/// Copyright holder is EMC Corporation
///
/// @author Andrey Abramov
/// @author Vasiliy Nabatchikov
////////////////////////////////////////////////////////////////////////////////
#ifndef IRESEARCH_RANGE_QUERY_H
#define IRESEARCH_RANGE_QUERY_H
#include <map>
#include <unordered_map>
#include "filter.hpp"
#include "cost.hpp"
#include "utils/bitset.hpp"
#include "utils/string.hpp"
NS_ROOT
struct term_reader;
//////////////////////////////////////////////////////////////////////////////
/// @class range_state
/// @brief cached per reader range state
//////////////////////////////////////////////////////////////////////////////
struct range_state : private util::noncopyable {
range_state() = default;
range_state(range_state&& rhs) NOEXCEPT {
*this = std::move(rhs);
}
range_state& operator=(range_state&& other) NOEXCEPT {
if (this == &other) {
return *this;
}
reader = std::move(other.reader);
min_term = std::move(other.min_term);
min_cookie = std::move(other.min_cookie);
estimation = std::move(other.estimation);
count = std::move(other.count);
scored_states = std::move(other.scored_states);
unscored_docs = std::move(other.unscored_docs);
other.reader = nullptr;
other.count = 0;
other.estimation = 0;
return *this;
}
const term_reader* reader{}; // reader using for iterate over the terms
bstring min_term; // minimum term to start from
seek_term_iterator::seek_cookie::ptr min_cookie; // cookie corresponding to the start term
cost::cost_t estimation{}; // per-segment query estimation
size_t count{}; // number of terms to process from start term
// scored states/stats by their offset in range_state (i.e. offset from min_term)
// range_query::execute(...) expects an orderd map
std::map<size_t, bstring> scored_states;
// matching doc_ids that may have been skipped while collecting statistics and should not be scored by the disjunction
bitset unscored_docs;
}; // reader_state
//////////////////////////////////////////////////////////////////////////////
/// @brief object to collect and track a limited number of scorers
//////////////////////////////////////////////////////////////////////////////
class limited_sample_scorer {
public:
limited_sample_scorer(size_t scored_terms_limit);
void collect(
size_t priority, // priority of this entry, lowest priority removed first
size_t scored_state_id, // state identifier used for querying of attributes
irs::range_state& scored_state, // state containing this scored term
const irs::sub_reader& reader, // segment reader for the current term
const seek_term_iterator& term_itr // term-iterator positioned at the current term
);
void score(const index_reader& index, const order::prepared& order);
private:
//////////////////////////////////////////////////////////////////////////////
/// @brief a representation of a term cookie with its asociated range_state
//////////////////////////////////////////////////////////////////////////////
struct scored_term_state_t {
seek_term_iterator::cookie_ptr cookie; // term offset cache
irs::range_state& state; // state containing this scored term
size_t state_offset;
const irs::sub_reader& sub_reader; // segment reader for the current term
bstring term; // actual term value this state is for
scored_term_state_t(
const irs::sub_reader& sr,
irs::range_state& scored_state,
size_t scored_state_offset,
const seek_term_iterator& term_itr
):
cookie(term_itr.cookie()),
state(scored_state),
state_offset(scored_state_offset),
sub_reader(sr),
term(term_itr.value()) {
}
};
typedef std::multimap<size_t, scored_term_state_t> scored_term_states_t;
scored_term_states_t scored_states_;
size_t scored_terms_limit_;
};
//////////////////////////////////////////////////////////////////////////////
/// @class range_query
/// @brief compiled query suitable for filters with continious range of terms
/// like "by_range" or "by_prefix".
//////////////////////////////////////////////////////////////////////////////
class range_query : public filter::prepared {
public:
typedef states_cache<range_state> states_t;
DECLARE_SHARED_PTR(range_query);
explicit range_query(states_t&& states, boost_t boost)
: prepared(boost), states_(std::move(states)) {
}
virtual doc_iterator::ptr execute(
const sub_reader& rdr,
const order::prepared& ord,
const attribute_view& /*ctx*/) const override;
private:
states_t states_;
}; // range_query
NS_END // ROOT
#endif // IRESEARCH_RANGE_QUERY_H
|
; A027611: Denominator of n * n-th harmonic number.
; Submitted by Jon Maiga
; 1,1,2,3,12,10,20,35,280,252,2520,2310,27720,25740,24024,45045,720720,680680,4084080,3879876,739024,235144,5173168,14872858,356948592,343219800,2974571600,2868336900,80313433200,77636318760,2329089562800,4512611027925,4375865239200,386105756400,375074163360,364655436600,13127595717600,12782132672400,12454385680800,12143026038780,485721041551200,474156254847600,2844937529085600,30583078437670200,29903454472388640,29253379375162800,1345655451257488800,1317620962689624450,63245806209101973600
mov $2,$0
seq $0,2805 ; Denominators of harmonic numbers H(n) = Sum_{i=1..n} 1/i.
mov $1,$0
add $2,1
gcd $1,$2
div $0,$1
|
; A227541: a(n) = floor(13*n^2/4).
; 0,3,13,29,52,81,117,159,208,263,325,393,468,549,637,731,832,939,1053,1173,1300,1433,1573,1719,1872,2031,2197,2369,2548,2733,2925,3123,3328,3539,3757,3981,4212,4449,4693,4943,5200,5463,5733,6009,6292,6581,6877,7179,7488,7803,8125,8453,8788,9129,9477,9831,10192,10559,10933,11313,11700,12093,12493,12899,13312,13731,14157,14589,15028,15473,15925,16383,16848,17319,17797,18281,18772,19269,19773,20283,20800,21323,21853,22389,22932,23481,24037,24599,25168,25743,26325,26913,27508,28109,28717,29331,29952,30579,31213,31853,32500,33153,33813,34479,35152,35831,36517,37209,37908,38613,39325,40043,40768,41499,42237,42981,43732,44489,45253,46023,46800,47583,48373,49169,49972,50781,51597,52419,53248,54083,54925,55773,56628,57489,58357,59231,60112,60999,61893,62793,63700,64613,65533,66459,67392,68331,69277,70229,71188,72153,73125,74103,75088,76079,77077,78081,79092,80109,81133,82163,83200,84243,85293,86349,87412,88481,89557,90639,91728,92823,93925,95033,96148,97269,98397,99531,100672,101819,102973,104133,105300,106473,107653,108839,110032,111231,112437,113649,114868,116093,117325,118563,119808,121059,122317,123581,124852,126129,127413,128703,130000,131303,132613,133929,135252,136581,137917,139259,140608,141963,143325,144693,146068,147449,148837,150231,151632,153039,154453,155873,157300,158733,160173,161619,163072,164531,165997,167469,168948,170433,171925,173423,174928,176439,177957,179481,181012,182549,184093,185643,187200,188763,190333,191909,193492,195081,196677,198279,199888,201503
pow $0,2
mov $1,13
mul $1,$0
div $1,4
|
; *********************************************************************************
; *********************************************************************************
;
; File: screen_layer2.asm
; Purpose: Layer 2 console interface, sprites enabled, no shadow.
; Date : 5th January 2019
; Author: paul@robsons.org.uk
;
; *********************************************************************************
; *********************************************************************************
; *********************************************************************************
;
; Clear Layer 2 Display.
;
; *********************************************************************************
GFXInitialiseLayer2:
push af
push bc
push de
db $ED,$91,$15,$3 ; Disable LowRes but enable Sprites
ld e,2 ; 3 banks to erase
L2PClear:
ld a,e ; put bank number in bits 6/7
rrc a
rrc a
or 2+1 ; shadow on, visible, enable write paging
ld bc,$123B ; out to layer 2 port
out (c),a
ld hl,$4000 ; erase the bank to $00
L2PClearBank: ; assume default palette :)
dec hl
ld (hl),$00
ld a,h
or l
jr nz,L2PClearBank
dec e
jp p,L2PClear
xor a
out ($FE),a
pop de
pop bc
pop af
ld hl,$1820 ; still 32 x 24
ld de,GFXPrintCharacterLayer2
ret
;
; Print Character E, colour D, position HL
;
GFXPrintCharacterLayer2:
push af
push bc
push de
push hl
push ix
ld b,e ; save A temporarily
ld a,b
and $7F
cp 32
jr c,__L2Exit ; check char in range
ld a,h
cp 3
jr nc,__L2Exit ; check position in range
ld a,b
push af
xor a ; convert colour in C to palette index
bit 0,d ; (assumes standard palette)
jr z,__L2Not1
or $03
__L2Not1:
bit 2,d
jr z,__L2Not2
or $1C
__L2Not2:
bit 1,d
jr z,__L2Not3
or $C0
__L2Not3:
ld c,a ; C is foreground
ld b,0 ; B is xor flipper, initially zero
pop af ; restore char
push hl
bit 7,a ; adjust background bit on bit 7
jr z,__L2NotCursor
ld b,$FF ; light grey is cursor
__L2NotCursor:
and $7F ; offset from space
sub $20
ld l,a ; put into HL
ld h,0
add hl,hl ; x 8
add hl,hl
add hl,hl
push hl ; transfer to IX
pop ix
pop hl
push bc ; add the font base to it.
ld bc,(SIFontBase)
add ix,bc
pop bc
;
; figure out the correct bank.
;
push bc
ld a,h ; this is the page number.
rrc a
rrc a
and $C0 ; in bits 6 & 7
or $03 ; shadow on, visible, enable write pagin.
ld bc,$123B ; out to layer 2 port
out (c),a
pop bc
;
; now figure out position in bank
;
ex de,hl
ld l,e
ld h,0
add hl,hl
add hl,hl
add hl,hl
sla h
sla h
sla h
ld e,8 ; do 8 rows
__L2Outer:
push hl ; save start
ld d,8 ; do 8 columns
ld a,(ix+0) ; get the bit pattern
xor b ; maybe flip it ?
inc ix
__L2Loop:
ld (hl),0 ; background
add a,a ; shift pattern left
jr nc,__L2NotSet
ld (hl),c ; if MSB was set, overwrite with fgr
__L2NotSet:
inc hl
dec d ; do a row
jr nz, __L2Loop
pop hl ; restore, go 256 bytes down.
inc h
dec e ; do 8 rows
jr nz,__L2Outer
__L2Exit:
pop ix
pop hl
pop de
pop bc
pop af
ret
|
###############################################################################
# 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
.globl n8_ARCFourProcessData
.type n8_ARCFourProcessData, @function
n8_ARCFourProcessData:
push %rbx
push %rbp
movslq %edx, %r8
test %r8, %r8
mov %rcx, %rbp
jz .Lquitgas_1
movzbq (4)(%rbp), %rax
movzbq (8)(%rbp), %rbx
lea (12)(%rbp), %rbp
add $(1), %rax
movzbq %al, %rax
movzbq (%rbp,%rax,4), %rcx
.p2align 4, 0x90
.Lmain_loopgas_1:
add %rcx, %rbx
movzbq %bl, %rbx
add $(1), %rdi
add $(1), %rsi
movzbq (%rbp,%rbx,4), %rdx
movl %ecx, (%rbp,%rbx,4)
add %rdx, %rcx
movzbq %cl, %rcx
movl %edx, (%rbp,%rax,4)
movb (%rbp,%rcx,4), %dl
add $(1), %rax
movzbq %al, %rax
xorb (-1)(%rdi), %dl
sub $(1), %r8
movzbq (%rbp,%rax,4), %rcx
movb %dl, (-1)(%rsi)
jne .Lmain_loopgas_1
lea (-12)(%rbp), %rbp
sub $(1), %rax
movzbq %al, %rax
movl %eax, (4)(%rbp)
movl %ebx, (8)(%rbp)
.Lquitgas_1:
pop %rbp
pop %rbx
ret
.Lfe1:
.size n8_ARCFourProcessData, .Lfe1-(n8_ARCFourProcessData)
|
/*
* This file is a part of the open source stm32plus library.
* Copyright (c) 2011,2012 Andy Brown <www.andybrown.me.uk>
* Please see website for licensing terms.
*/
.global ErrorPixels
.global ErrorPixelsSize
ErrorPixels:
.incbin "error.jpg"
ErrorPixelsSize=.-ErrorPixels
|
; A208114: Number of n X 4 0..1 arrays avoiding 0 0 0 and 0 1 0 horizontally and 0 0 1 and 0 1 1 vertically.
; 9,81,225,625,1225,2401,3969,6561,9801,14641,20449,28561,38025,50625,65025,83521,104329,130321,159201,194481,233289,279841,330625,390625,455625,531441,613089,707281,808201,923521,1046529,1185921,1334025
mov $1,2
add $1,$0
add $0,6
pow $1,2
mov $2,1
mov $3,2
lpb $0
mov $0,1
add $1,$2
div $1,$3
bin $1,2
lpe
mul $1,3
sub $1,3
div $1,3
mul $1,8
add $1,9
|
; A134751: Hankel transform of expansion of (1/(1-x^2))c(x/(1-x^2)), where c(x) is the g.f. of A000108.
; 1,2,8,32,256,4096,65536,2097152,134217728,8589934592,1099511627776,281474976710656,72057594037927936,36893488147419103232,37778931862957161709568,38685626227668133590597632
add $0,1
pow $0,2
div $0,3
mov $1,2
pow $1,$0
mov $0,$1
|
//
// Created by duhieub on 11/17/17.
//
#ifndef EXISTENZIA_CLIENT_HPP
#define EXISTENZIA_CLIENT_HPP
/**
* \file Client.hpp
* \brief Typedef the socket Client as an int
* \author Edouard.P
* \version 0.1
* \date 17 novembre 2017
* \namespace xzia
* \struct Client
*/
namespace xzia
{
using Client = int;
}
#endif //EXISTENZIA_CLIENT_HPP
|
keep TOOLS
****************************************************************
* ChemiGS *
****************************************************************
* A Drawing Program for Chemical Structures *
* (c) 1992-93 by Urs Hochstrasser *
* Buendtenweg 6 *
* 5105 AUENSTEIN (SWITZERLAND) *
****************************************************************
* Module TOOLS
****************************************************************
*
* USES ...
*
mcopy tools.macros
copy equates.asm
****************************************************************
*
* SUBROUTINES
*
CrossCursor start
using Globals
move4 gCrossCur,gEditCursor
rts
MarqueeCursor entry
move4 gMarqueeCur,gEditCursor
rts
HandCursor entry
move4 gHandCur,gEditCursor
rts
TextCursor entry
move4 gTextCur,gEditCursor
rts
EraseCursor entry
move4 gEraseCur,gEditCursor
rts
ArrowCursor entry
move4 gArrowCur,gEditCursor
AdjustCursor entry
brl pastname procedure name to be displayed
dc i2'$7771' by GSBug...
dw 'AdjustCursor'
pastname anop
lda newCursor
sta oldCursor
stz newCursor
ph4 #0
~FrontWindow
pl4 theWindow
cmp4 theWindow,gDataWin
beq x0 Edit Win not in front
brl l2
x0 ph4 #0
~GetContentRgn gDataWin
pl4 contentRgn
pha
~PtInRgn #gMainEvt+owhere,contentRgn
* ~PtInRect #gMainEvt+owhere,#myRect
pla
beq l2 Cursor not in edit window
~StartDrawing gDataWin
move4 gMainEvt+owhere,myPoint ***new
~GlobalToLocal #myPoint ***new
pha
~PtInRect #myPoint,#gContentRect
pla
beq l2
inc newCursor
~SetOrigin #0,#0
l2 anop
lda oldCursor
cmp newCursor
beq exit
lda newCursor
beq l3
~SetCursor gEditCursor
bra exit
l3 ~InitCursor
exit anop
rts
contentRgn ds 4
oldCursor ds 2
newCursor entry
ds 2
theWindow ds 4
myPoint ds 4
myRect dc i2'20,20,220,120'
end
*********************************************************************
* Tool handlers
*
doHand start
using Globals
using TransData
rts
doErase entry
rts
doSingleB entry
~MoveTo xx,yy
~LineTo xx2,yy2
rts
doDoubleB entry
jsr MakeMatrix
move4 #doubleBData+2,0
ldx doubleBData
dloop stx count
~BlockMove 0,#px,#8
jsr TransForm
~MoveTo pxx,pyy
add4 0,#8
~BlockMove 0,#px,#8
jsr TransForm
~LineTo pxx,pyy
add4 0,#8
ldx count
dbne x,dloop
rts
doHatchB entry
jsr MakeMatrix
move4 #hatchData+2,0
ldx hatchData
hloop stx count
* ~BlockMove 0,#px,#8
ldy #0 *
hloop2 lda [0],y *
sta px,y *
iny * Special Agent Cooper
iny *
cpy #8 *
bcc hloop2 *
jsr TransForm
~MoveTo pxx,pyy
add4 0,#8
~BlockMove 0,#px,#8
jsr TransForm
~LineTo pxx,pyy
add4 0,#8
ldx count
dbne x,hloop
rts
doWedgeB entry a somewhat different procedure...
jsr MakeMatrix
move4 #wedgeBData+2,0
~BlockMove 0,#px,#8
jsr TransForm
ph4 #0
~OpenPoly
pl4 myPoly
~MoveTo pxx,pyy
add4 0,#8
ldx wedgeBData
dwloop stx count
~BlockMove 0,#px,#8
jsr TransForm
~LineTo pxx,pyy
add4 0,#8
ldx count
dbne x,dwloop
~ClosePoly
~PaintPoly myPoly
~FramePoly myPoly
rts
myPoly ds 4
doCycloPropane entry
jsr MarqueeCursor
rts
doCycloPentane entry
jsr MarqueeCursor
rts
doCycloHexane entry
jsr MarqueeCursor
rts
doBenzene entry
jsr MarqueeCursor
rts
doSeat entry
jsr MarqueeCursor
rts
doMarquee entry
jsr dragRect
rts
doText entry
lda fTextFlag
beq firstTime
* test jsr EndText save old LE-text before making new
firstTime anop
lda #1
sta fTextFlag
ph4 #0
~LoadResource #kPicResID,#kToolPicID
pl4 toolBar
* _SetField LEditH,#$c8,#KeyFilter,#4
* bra gaga
_Deref LEditH,LEditPtr **** new
lda LEditPtr *
sta <0 *
lda LEditPtr+2 *
sta <2 *
ldy #$c8 *
lda #<KeyFilter *
sta [0],y *
iny *
iny *
lda #^KeyFilter *
sta [0],y *
_Unlock LeditH **** end new
ph4 #0 *
~NewHandle #2,gMyID,#0,#0 *
pl4 outH **** new end
gaga anop
lda gDataWin
ldx gDataWin+2
jsr GrowClip
~SysBeep
~ShowControl LEditH
~DrawPicture toolBar,#destRect
* lda gDataWin
* ldx gDataWin+2
* jsr ShrinkClip
*** Get Text from Loc, if necessary...
*** Edit text...
exit rts
toolBar ds 4
destRect dc i2'0,0,17,640'
LEditPtr ds 4
textLen ds 2 ***TEST
theText dc h'0A4375534F84' ***TEST
dc h'A53548824F' ***TEST
doDottedB entry
jsr MakeMatrix
move4 #dottedBData+2,0
ldx dottedBData
dtloop stx count
~BlockMove 0,#px,#8
jsr TransForm
~MoveTo pxx,pyy
add4 0,#8
~BlockMove 0,#px,#8
jsr TransForm
~LineTo pxx,pyy
add4 0,#8
ldx count
dbne x,dtloop
rts
doTripleB entry
jsr MakeMatrix
move4 #tripleBData+2,0
ldx tripleBData
tloop stx count
~BlockMove 0,#px,#8
jsr TransForm
~MoveTo pxx,pyy
add4 0,#8
~BlockMove 0,#px,#8
jsr TransForm
~LineTo pxx,pyy
add4 0,#8
ldx count
dbne x,tloop
rts
doWHatch entry
jsr MakeMatrix
move4 #wHatchData+2,0
ldx wHatchData
whloop stx count
~BlockMove 0,#px,#8
jsr TransForm
~MoveTo pxx,pyy
add4 0,#8
~BlockMove 0,#px,#8
jsr TransForm
~LineTo pxx,pyy
add4 0,#8
ldx count
dbne x,whloop
rts
doCChain entry in fact, it's a modified double bond
jsr MakeMatrix
move4 #cchainData+2,0
ldx cchainData
ccloop stx count
~BlockMove 0,#px,#8
jsr TransForm
~MoveTo pxx,pyy
add4 0,#8
~BlockMove 0,#px,#8
jsr TransForm
~LineTo pxx,pyy
add4 0,#8
ldx count
dbne x,ccloop
rts
doCycloButane entry
jsr MarqueeCursor
rts
doCycloPentane2 entry
jsr MarqueeCursor
rts
doBenzene2 entry
jsr MarqueeCursor
rts
doWheeland entry
jsr MarqueeCursor
rts
doBasin entry
jsr MarqueeCursor
rts
end
* -----------------------------------------------------------------------*
EndText start
using Globals
lda fTextFlag
beq exit
stz fTextFlag
lda gDataWin
ldx gDataWin+2
jsr GrowClip
~HideControl LEditH
~ShowControl TBarH
~DrawOneCtl TBarH
**************************** hier noch was zu tun: Text retten und so
* lda gDataWin
* ldx gDataWin+2
* jsr ShrinkClip
exit rts
end
StoreData start
using Globals
stz fSaved indicate change to file
ph4 #0
~NewHandle #segSize,gMyID,#0,#0
pl4 gNewLink
~PtrToHand #NewSegment,gNewLink,#segSize
move4 gNewLink,sLink
lda gToolID
sta sCMD
~GetPenSize #penSize
move4 penSize,sPenSize
add2 yy,gYoffset *** even more recent!
add2 yy2,gYoffset *** Doc -> Window
add2 xx,gXoffset ***
add2 xx2,gXoffset ***
~PtrToHand #TheSegment,gLink,#segSize
move4 gNewLink,gLink
rts
penSize ds 4
end
DoTXEdit start ;AtomText click handler
using globals
move4 gTheText,theHandle
ph4 #0
~GetHandleSize theHandle
pl4 hLen
~HandToPtr theHandle,TheText,hLen
lda txLink check for last item in list
ora txLink+2
* beq newTXItem
lda txLen
and #$FF
sta tLen
~LESetText #txString,tLen,LERecHndl ;noch zu bilden...
rts
theHandle ds 4
hLen ds 4
tLen ds 2
LERecHndl ds 4
end
doDataWin start
using Globals
~SetPenSize gPenSize+2,gPenSize
move4 gMainEvt+owhere,myPoint
move4 gMainEvt+owhere,myPoint2 *** New Ruler Stuff
~GlobalToLocal #myPoint2
lda myPoint2
cmp #18 ruler heigth
bcs content
* jsr HandleRuler in WINDOWS
jmp tdExit *** end ruler stuff
content anop
* stz fShift
* lda gMainEvt+omodifiers
* and #shiftKey
* beq l4
* inc fShift
*l4 anop
pha
~FindControl #gTaskDa2,#gMainEvt+owhere+2,#gmainEvt+owhwere,gDataWin
pl2 gTaskDa3
lda gTaskDa3
* and #$FFFF
beq okContent
jsr doControls
brl exit2
okContent anop
~StartDrawing gDataWin
~SetPenSize #2,#1
~GlobalToLocal #myPoint
lda myY
ldx myX
jsr gridIt 'grid' the point
sta yy
stx xx
*------------------------------------------------------------------------*
* Tool Dispatch code
*
lda gToolID
bne l7
jsr doHand
brl exit
l7 cmp #1
bne l8
jsr doErase
brl exit
l8 cmp #11
bne l9
jsr doMarquee
brl exit
l9 cmp #12
bne l10
jsr doText
brl exit
l10 cmp #6
bcs l1
jsr dragLine
bcs l11
brl exit
l11 lda gToolID
asl a
tax
jsr (toolTable,x)
jsr StoreData
tdExit rts
l1 cmp #11
bcs l2
bra exit
l2 cmp #17
bcc l3
bra exit
l3 jsr dragLine
bcc exit
lda gToolID
sec
sbc #11
asl a
tax
jsr (toolTable2,x)
jsr StoreData
exit ~SetOrigin #0,#0
exit2 rts
gridIt anop
pha
txa
lsr a
lsr a
ldy fShift half grid if SHIFT pressed
bne g1
lsr a
lsr a
asl a
asl a
g1 asl a
asl a
tax
pla
lsr a
ldy fShift
bne g2
lsr a
lsr a
asl a
asl a
g2 asl a
rts
temp ds 2
dragLine entry
~SetPenMode #notXOR
~MoveTo xx,yy
move4 point2,oldPoint
~GetMouse #point2
lda y2
ldx x2
jsr gridIt
sta yy2
stx xx2
~LineTo xx2,yy2
drLoop lda point2
cmp oldPoint
bne dr1
lda point2+2
cmp oldPoint+2
beq dr2
dr1 ~LineTo xx,yy
~LineTo xx2,yy2
dr2 pha
~StillDown #0
pla
beq dr3
move4 point2,oldPoint oldPoint = point2
~GetMouse #point2
lda y2
ldx x2
jsr gridIt
sta yy2
stx xx2
brl drLoop
dr3 ~LineTo xx,yy
~SetPenMode #modeCopy
lda xx test, if p1=p2
cmp xx2 equal: clear carry (nothing to do
bne dr4 any more!)
lda yy
cmp yy2
bne dr4
clc equal!
bra dr5
dr4 sec not equal
dr5 rts
dragRect entry
~SetPenMode #notXOR
move4 myY,myRect
move4 #0,myrect+4
move4 myY,oldRect
move4 #0,oldRect+4
move4 myRect+4,oldRect+4
~GetMouse #myRect+4
~FrameRect #myRect
drRLoop lda myRect+4
cmp oldRect+4
bne drR1
lda myRect+6
cmp oldRect+6
beq drR2
drR1 ~FrameRect #oldRect
~FrameRect #myRect
drR2 pha
~StillDown #0
pla
beq drR3
move4 myRect+4,oldRect+4 oldPoint = point2
~GetMouse #myRect+4
brl drRLoop
drR3 ~FrameRect #myRect
~SetPenMode #modeCopy
rts
myRect ds 8
oldRect ds 8
toolTable entry
*---------------------------------------------
dc i2'doHand' 0
dc i2'doErase' 1
dc i2'doSingleB' 2
dc i2'doDoubleB' 3
dc i2'doHatchB' 4
dc i2'doWedgeB' 5
* --------------------------------------------
toolTable2 entry
dc i2'doMarquee' 11
dc i2'doText' 12
dc i2'doDottedB' 13
dc i2'doTripleB' 14
dc i2'doWHatch' 15
dc i2'doCChain' 16
myPoint anop
myY ds 2
myX ds 2
point2 anop
y2 ds 2
x2 ds 2
myPoint2 anop
ds 4
oldPoint ds 4
fShift ds 2
end
doControls start
using Globals
~SysBeep
rts
end
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/public/browser/resource_dispatcher_host.h"
#include <utility>
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/run_loop.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "content/browser/download/download_manager_impl.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/resource_dispatcher_host_delegate.h"
#include "content/public/browser/resource_request_info.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/url_constants.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/content_browser_test.h"
#include "content/public/test/content_browser_test_utils.h"
#include "content/public/test/test_navigation_observer.h"
#include "content/public/test/test_utils.h"
#include "content/shell/browser/shell.h"
#include "content/shell/browser/shell_content_browser_client.h"
#include "content/shell/browser/shell_network_delegate.h"
#include "net/base/net_errors.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/test/embedded_test_server/http_request.h"
#include "net/test/embedded_test_server/http_response.h"
#include "net/test/url_request/url_request_failed_job.h"
#include "net/test/url_request/url_request_mock_http_job.h"
#include "net/url_request/url_request.h"
#include "url/gurl.h"
using base::ASCIIToUTF16;
namespace content {
class ResourceDispatcherHostBrowserTest : public ContentBrowserTest,
public DownloadManager::Observer {
public:
ResourceDispatcherHostBrowserTest() : got_downloads_(false) {}
protected:
void SetUpOnMainThread() override {
base::FilePath path = GetTestFilePath("", "");
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::Bind(
&net::URLRequestMockHTTPJob::AddUrlHandlers, path,
make_scoped_refptr(content::BrowserThread::GetBlockingPool())));
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::Bind(&net::URLRequestFailedJob::AddUrlHandler));
}
void OnDownloadCreated(DownloadManager* manager,
DownloadItem* item) override {
if (!got_downloads_)
got_downloads_ = !!manager->InProgressCount();
}
void CheckTitleTest(const GURL& url,
const std::string& expected_title) {
base::string16 expected_title16(ASCIIToUTF16(expected_title));
TitleWatcher title_watcher(shell()->web_contents(), expected_title16);
NavigateToURL(shell(), url);
EXPECT_EQ(expected_title16, title_watcher.WaitAndGetTitle());
}
bool GetPopupTitle(const GURL& url, base::string16* title) {
NavigateToURL(shell(), url);
ShellAddedObserver new_shell_observer;
// Create dynamic popup.
if (!ExecuteScript(shell(), "OpenPopup();"))
return false;
Shell* new_shell = new_shell_observer.GetShell();
*title = new_shell->web_contents()->GetTitle();
return true;
}
std::string GetCookies(const GURL& url) {
return content::GetCookies(
shell()->web_contents()->GetBrowserContext(), url);
}
bool got_downloads() const { return got_downloads_; }
private:
bool got_downloads_;
};
// Test title for content created by javascript window.open().
// See http://crbug.com/5988
IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, DynamicTitle1) {
ASSERT_TRUE(embedded_test_server()->Start());
GURL url(embedded_test_server()->GetURL("/dynamic1.html"));
base::string16 title;
ASSERT_TRUE(GetPopupTitle(url, &title));
EXPECT_TRUE(base::StartsWith(title, ASCIIToUTF16("My Popup Title"),
base::CompareCase::SENSITIVE))
<< "Actual title: " << title;
}
// Test title for content created by javascript window.open().
// See http://crbug.com/5988
IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, DynamicTitle2) {
ASSERT_TRUE(embedded_test_server()->Start());
GURL url(embedded_test_server()->GetURL("/dynamic2.html"));
base::string16 title;
ASSERT_TRUE(GetPopupTitle(url, &title));
EXPECT_TRUE(base::StartsWith(title, ASCIIToUTF16("My Dynamic Title"),
base::CompareCase::SENSITIVE))
<< "Actual title: " << title;
}
IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest,
SniffHTMLWithNoContentType) {
CheckTitleTest(
net::URLRequestMockHTTPJob::GetMockUrl("content-sniffer-test0.html"),
"Content Sniffer Test 0");
}
IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest,
RespectNoSniffDirective) {
CheckTitleTest(net::URLRequestMockHTTPJob::GetMockUrl("nosniff-test.html"),
"mock.http/nosniff-test.html");
}
IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest,
DoNotSniffHTMLFromTextPlain) {
CheckTitleTest(
net::URLRequestMockHTTPJob::GetMockUrl("content-sniffer-test1.html"),
"mock.http/content-sniffer-test1.html");
}
IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest,
DoNotSniffHTMLFromImageGIF) {
CheckTitleTest(
net::URLRequestMockHTTPJob::GetMockUrl("content-sniffer-test2.html"),
"mock.http/content-sniffer-test2.html");
}
IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest,
SniffNoContentTypeNoData) {
// Make sure no downloads start.
BrowserContext::GetDownloadManager(
shell()->web_contents()->GetBrowserContext())->AddObserver(this);
CheckTitleTest(
net::URLRequestMockHTTPJob::GetMockUrl("content-sniffer-test3.html"),
"Content Sniffer Test 3");
EXPECT_EQ(1u, Shell::windows().size());
ASSERT_FALSE(got_downloads());
}
IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest,
ContentDispositionEmpty) {
CheckTitleTest(
net::URLRequestMockHTTPJob::GetMockUrl("content-disposition-empty.html"),
"success");
}
IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest,
ContentDispositionInline) {
CheckTitleTest(
net::URLRequestMockHTTPJob::GetMockUrl("content-disposition-inline.html"),
"success");
}
// Test for bug #1091358.
IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, SyncXMLHttpRequest) {
ASSERT_TRUE(embedded_test_server()->Start());
NavigateToURL(
shell(), embedded_test_server()->GetURL("/sync_xmlhttprequest.html"));
// Let's check the XMLHttpRequest ran successfully.
bool success = false;
EXPECT_TRUE(ExecuteScriptAndExtractBool(
shell(), "window.domAutomationController.send(DidSyncRequestSucceed());",
&success));
EXPECT_TRUE(success);
}
// If this flakes, use http://crbug.com/62776.
IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest,
SyncXMLHttpRequest_Disallowed) {
ASSERT_TRUE(embedded_test_server()->Start());
NavigateToURL(
shell(),
embedded_test_server()->GetURL("/sync_xmlhttprequest_disallowed.html"));
// Let's check the XMLHttpRequest ran successfully.
bool success = false;
EXPECT_TRUE(ExecuteScriptAndExtractBool(
shell(), "window.domAutomationController.send(DidSucceed());", &success));
EXPECT_TRUE(success);
}
// Test for bug #1159553 -- A synchronous xhr (whose content-type is
// downloadable) would trigger download and hang the renderer process,
// if executed while navigating to a new page.
// Disabled on Mac: see http://crbug.com/56264
#if defined(OS_MACOSX)
#define MAYBE_SyncXMLHttpRequest_DuringUnload \
DISABLED_SyncXMLHttpRequest_DuringUnload
#else
#define MAYBE_SyncXMLHttpRequest_DuringUnload SyncXMLHttpRequest_DuringUnload
#endif
IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest,
MAYBE_SyncXMLHttpRequest_DuringUnload) {
ASSERT_TRUE(embedded_test_server()->Start());
BrowserContext::GetDownloadManager(
shell()->web_contents()->GetBrowserContext())->AddObserver(this);
CheckTitleTest(
embedded_test_server()->GetURL("/sync_xmlhttprequest_during_unload.html"),
"sync xhr on unload");
// Navigate to a new page, to dispatch unload event and trigger xhr.
// (the bug would make this step hang the renderer).
CheckTitleTest(
embedded_test_server()->GetURL("/title2.html"), "Title Of Awesomeness");
ASSERT_FALSE(got_downloads());
}
// Flaky everywhere. http://crbug.com/130404
// Tests that onunload is run for cross-site requests. (Bug 1114994)
IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest,
DISABLED_CrossSiteOnunloadCookie) {
ASSERT_TRUE(embedded_test_server()->Start());
GURL url = embedded_test_server()->GetURL("/onunload_cookie.html");
CheckTitleTest(url, "set cookie on unload");
// Navigate to a new cross-site page, to dispatch unload event and set the
// cookie.
CheckTitleTest(
net::URLRequestMockHTTPJob::GetMockUrl("content-sniffer-test0.html"),
"Content Sniffer Test 0");
// Check that the cookie was set.
EXPECT_EQ("onunloadCookie=foo", GetCookies(url));
}
// If this flakes, use http://crbug.com/130404
// Tests that onunload is run for cross-site requests to URLs that complete
// without network loads (e.g., about:blank, data URLs).
IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest,
DISABLED_CrossSiteImmediateLoadOnunloadCookie) {
ASSERT_TRUE(embedded_test_server()->Start());
GURL url = embedded_test_server()->GetURL("/onunload_cookie.html");
CheckTitleTest(url, "set cookie on unload");
// Navigate to a cross-site page that loads immediately without making a
// network request. The unload event should still be run.
NavigateToURL(shell(), GURL(url::kAboutBlankURL));
// Check that the cookie was set.
EXPECT_EQ("onunloadCookie=foo", GetCookies(url));
}
namespace {
// Handles |request| by serving a redirect response.
std::unique_ptr<net::test_server::HttpResponse> NoContentResponseHandler(
const std::string& path,
const net::test_server::HttpRequest& request) {
if (!base::StartsWith(path, request.relative_url,
base::CompareCase::SENSITIVE))
return std::unique_ptr<net::test_server::HttpResponse>();
std::unique_ptr<net::test_server::BasicHttpResponse> http_response(
new net::test_server::BasicHttpResponse);
http_response->set_code(net::HTTP_NO_CONTENT);
return std::move(http_response);
}
} // namespace
// Tests that the unload handler is not run for 204 responses.
// If this flakes use http://crbug.com/80596.
IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest,
CrossSiteNoUnloadOn204) {
ASSERT_TRUE(embedded_test_server()->Start());
// Start with a URL that sets a cookie in its unload handler.
GURL url = embedded_test_server()->GetURL("/onunload_cookie.html");
CheckTitleTest(url, "set cookie on unload");
// Navigate to a cross-site URL that returns a 204 No Content response.
const char kNoContentPath[] = "/nocontent";
embedded_test_server()->RegisterRequestHandler(
base::Bind(&NoContentResponseHandler, kNoContentPath));
NavigateToURL(shell(), embedded_test_server()->GetURL(kNoContentPath));
// Check that the unload cookie was not set.
EXPECT_EQ("", GetCookies(url));
}
// Tests that the onbeforeunload and onunload logic is short-circuited if the
// old renderer is gone. In that case, we don't want to wait for the old
// renderer to run the handlers.
// We need to disable this on Mac because the crash causes the OS CrashReporter
// process to kick in to analyze the poor dead renderer. Unfortunately, if the
// app isn't stripped of debug symbols, this takes about five minutes to
// complete and isn't conducive to quick turnarounds. As we don't currently
// strip the app on the build bots, this is bad times.
#if defined(OS_MACOSX)
#define MAYBE_CrossSiteAfterCrash DISABLED_CrossSiteAfterCrash
#else
#define MAYBE_CrossSiteAfterCrash CrossSiteAfterCrash
#endif
IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest,
MAYBE_CrossSiteAfterCrash) {
// Make sure we have a live process before trying to kill it.
NavigateToURL(shell(), GURL("about:blank"));
// Cause the renderer to crash.
RenderProcessHostWatcher crash_observer(
shell()->web_contents(),
RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT);
NavigateToURL(shell(), GURL(kChromeUICrashURL));
// Wait for browser to notice the renderer crash.
crash_observer.Wait();
// Navigate to a new cross-site page. The browser should not wait around for
// the old renderer's on{before}unload handlers to run.
CheckTitleTest(
net::URLRequestMockHTTPJob::GetMockUrl("content-sniffer-test0.html"),
"Content Sniffer Test 0");
}
// Tests that cross-site navigations work when the new page does not go through
// the BufferedEventHandler (e.g., non-http{s} URLs). (Bug 1225872)
IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest,
CrossSiteNavigationNonBuffered) {
// Start with an HTTP page.
CheckTitleTest(
net::URLRequestMockHTTPJob::GetMockUrl("content-sniffer-test0.html"),
"Content Sniffer Test 0");
// Now load a file:// page, which does not use the BufferedEventHandler.
// Make sure that the page loads and displays a title, and doesn't get stuck.
GURL url = GetTestUrl("", "title2.html");
CheckTitleTest(url, "Title Of Awesomeness");
}
// Flaky everywhere. http://crbug.com/130404
// Tests that a cross-site navigation to an error page (resulting in the link
// doctor page) still runs the onunload handler and can support navigations
// away from the link doctor page. (Bug 1235537)
IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest,
DISABLED_CrossSiteNavigationErrorPage) {
ASSERT_TRUE(embedded_test_server()->Start());
GURL url(embedded_test_server()->GetURL("/onunload_cookie.html"));
CheckTitleTest(url, "set cookie on unload");
// Navigate to a new cross-site URL that results in an error.
// TODO(creis): If this causes crashes or hangs, it might be for the same
// reason as ErrorPageTest::DNSError. See bug 1199491 and
// http://crbug.com/22877.
GURL failed_url = net::URLRequestFailedJob::GetMockHttpUrl(
net::ERR_NAME_NOT_RESOLVED);
NavigateToURL(shell(), failed_url);
EXPECT_NE(ASCIIToUTF16("set cookie on unload"),
shell()->web_contents()->GetTitle());
// Check that the cookie was set, meaning that the onunload handler ran.
EXPECT_EQ("onunloadCookie=foo", GetCookies(url));
// Check that renderer-initiated navigations still work. In a previous bug,
// the ResourceDispatcherHost would think that such navigations were
// cross-site, because we didn't clean up from the previous request. Since
// WebContentsImpl was in the NORMAL state, it would ignore the attempt to run
// the onunload handler, and the navigation would fail. We can't test by
// redirecting to javascript:window.location='someURL', since javascript:
// URLs are prohibited by policy from interacting with sensitive chrome
// pages of which the error page is one. Instead, use automation to kick
// off the navigation, and wait to see that the tab loads.
base::string16 expected_title16(ASCIIToUTF16("Title Of Awesomeness"));
TitleWatcher title_watcher(shell()->web_contents(), expected_title16);
bool success;
GURL test_url(embedded_test_server()->GetURL("/title2.html"));
std::string redirect_script = "window.location='" +
test_url.possibly_invalid_spec() + "';" +
"window.domAutomationController.send(true);";
EXPECT_TRUE(ExecuteScriptAndExtractBool(shell(), redirect_script, &success));
EXPECT_EQ(expected_title16, title_watcher.WaitAndGetTitle());
}
IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest,
CrossSiteNavigationErrorPage2) {
ASSERT_TRUE(embedded_test_server()->Start());
GURL url(embedded_test_server()->GetURL("/title2.html"));
CheckTitleTest(url, "Title Of Awesomeness");
// Navigate to a new cross-site URL that results in an error.
// TODO(creis): If this causes crashes or hangs, it might be for the same
// reason as ErrorPageTest::DNSError. See bug 1199491 and
// http://crbug.com/22877.
GURL failed_url = net::URLRequestFailedJob::GetMockHttpUrl(
net::ERR_NAME_NOT_RESOLVED);
NavigateToURL(shell(), failed_url);
EXPECT_NE(ASCIIToUTF16("Title Of Awesomeness"),
shell()->web_contents()->GetTitle());
// Repeat navigation. We are testing that this completes.
NavigateToURL(shell(), failed_url);
EXPECT_NE(ASCIIToUTF16("Title Of Awesomeness"),
shell()->web_contents()->GetTitle());
}
IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest,
CrossOriginRedirectBlocked) {
// We expect the following URL requests from this test:
// 1- http://mock.http/cross-origin-redirect-blocked.html
// 2- http://mock.http/redirect-to-title2.html
// 3- http://mock.http/title2.html
//
// If the redirect in #2 were not blocked, we'd also see a request
// for http://mock.http:4000/title2.html, and the title would be different.
CheckTitleTest(net::URLRequestMockHTTPJob::GetMockUrl(
"cross-origin-redirect-blocked.html"),
"Title Of More Awesomeness");
}
// Tests that ResourceRequestInfoImpl is updated correctly on failed
// requests, to prevent calling Read on a request that has already failed.
// See bug 40250.
IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest,
CrossSiteFailedRequest) {
// Visit another URL first to trigger a cross-site navigation.
NavigateToURL(shell(), GetTestUrl("", "simple_page.html"));
// Visit a URL that fails without calling ResourceDispatcherHost::Read.
GURL broken_url("chrome://theme");
NavigateToURL(shell(), broken_url);
}
namespace {
std::unique_ptr<net::test_server::HttpResponse> HandleRedirectRequest(
const std::string& request_path,
const net::test_server::HttpRequest& request) {
if (!base::StartsWith(request.relative_url, request_path,
base::CompareCase::SENSITIVE))
return std::unique_ptr<net::test_server::HttpResponse>();
std::unique_ptr<net::test_server::BasicHttpResponse> http_response(
new net::test_server::BasicHttpResponse);
http_response->set_code(net::HTTP_FOUND);
http_response->AddCustomHeader(
"Location", request.relative_url.substr(request_path.length()));
return std::move(http_response);
}
} // namespace
// Test that we update the cookie policy URLs correctly when transferring
// navigations.
IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, CookiePolicy) {
ASSERT_TRUE(embedded_test_server()->Start());
embedded_test_server()->RegisterRequestHandler(
base::Bind(&HandleRedirectRequest, "/redirect?"));
std::string set_cookie_url(base::StringPrintf(
"http://localhost:%u/set_cookie.html", embedded_test_server()->port()));
GURL url(embedded_test_server()->GetURL("/redirect?" + set_cookie_url));
ShellContentBrowserClient::SetSwapProcessesForRedirect(true);
ShellNetworkDelegate::SetAcceptAllCookies(false);
CheckTitleTest(url, "cookie set");
}
class PageTransitionResourceDispatcherHostDelegate
: public ResourceDispatcherHostDelegate {
public:
PageTransitionResourceDispatcherHostDelegate(GURL watch_url)
: watch_url_(watch_url) {}
// ResourceDispatcherHostDelegate implementation:
void RequestBeginning(net::URLRequest* request,
ResourceContext* resource_context,
AppCacheService* appcache_service,
ResourceType resource_type,
ScopedVector<ResourceThrottle>* throttles) override {
if (request->url() == watch_url_) {
const ResourceRequestInfo* info =
ResourceRequestInfo::ForRequest(request);
page_transition_ = info->GetPageTransition();
}
}
ui::PageTransition page_transition() { return page_transition_; }
private:
GURL watch_url_;
ui::PageTransition page_transition_;
};
// Test that ui::PAGE_TRANSITION_CLIENT_REDIRECT is correctly set
// when encountering a meta refresh tag.
IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest,
PageTransitionClientRedirect) {
ASSERT_TRUE(embedded_test_server()->Start());
PageTransitionResourceDispatcherHostDelegate delegate(
embedded_test_server()->GetURL("/title1.html"));
ResourceDispatcherHost::Get()->SetDelegate(&delegate);
NavigateToURLBlockUntilNavigationsComplete(
shell(),
embedded_test_server()->GetURL("/client_redirect.html"),
2);
EXPECT_TRUE(
delegate.page_transition() & ui::PAGE_TRANSITION_CLIENT_REDIRECT);
}
namespace {
// Checks whether the given urls are requested, and that IsUsingLofi() returns
// the appropriate value when the Lo-Fi state is set.
class LoFiModeResourceDispatcherHostDelegate
: public ResourceDispatcherHostDelegate {
public:
LoFiModeResourceDispatcherHostDelegate(const GURL& main_frame_url,
const GURL& subresource_url,
const GURL& iframe_url)
: main_frame_url_(main_frame_url),
subresource_url_(subresource_url),
iframe_url_(iframe_url),
main_frame_url_seen_(false),
subresource_url_seen_(false),
iframe_url_seen_(false),
use_lofi_(false),
should_enable_lofi_mode_called_(false) {}
~LoFiModeResourceDispatcherHostDelegate() override {}
// ResourceDispatcherHostDelegate implementation:
void RequestBeginning(net::URLRequest* request,
ResourceContext* resource_context,
AppCacheService* appcache_service,
ResourceType resource_type,
ScopedVector<ResourceThrottle>* throttles) override {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request);
if (request->url() != main_frame_url_ && request->url() != subresource_url_
&& request->url() != iframe_url_)
return;
if (request->url() == main_frame_url_) {
EXPECT_FALSE(main_frame_url_seen_);
main_frame_url_seen_ = true;
} else if (request->url() == subresource_url_) {
EXPECT_TRUE(main_frame_url_seen_);
EXPECT_FALSE(subresource_url_seen_);
subresource_url_seen_ = true;
} else if (request->url() == iframe_url_) {
EXPECT_TRUE(main_frame_url_seen_);
EXPECT_FALSE(iframe_url_seen_);
iframe_url_seen_ = true;
}
EXPECT_EQ(use_lofi_, info->IsUsingLoFi());
}
void SetDelegate() {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
ResourceDispatcherHost::Get()->SetDelegate(this);
}
bool ShouldEnableLoFiMode(
const net::URLRequest& request,
content::ResourceContext* resource_context) override {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
EXPECT_FALSE(should_enable_lofi_mode_called_);
should_enable_lofi_mode_called_ = true;
EXPECT_EQ(main_frame_url_, request.url());
return use_lofi_;
}
void Reset(bool use_lofi) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
main_frame_url_seen_ = false;
subresource_url_seen_ = false;
iframe_url_seen_ = false;
use_lofi_ = use_lofi;
should_enable_lofi_mode_called_ = false;
}
void CheckResourcesRequested(bool should_enable_lofi_mode_called) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
EXPECT_EQ(should_enable_lofi_mode_called, should_enable_lofi_mode_called_);
EXPECT_TRUE(main_frame_url_seen_);
EXPECT_TRUE(subresource_url_seen_);
EXPECT_TRUE(iframe_url_seen_);
}
private:
const GURL main_frame_url_;
const GURL subresource_url_;
const GURL iframe_url_;
bool main_frame_url_seen_;
bool subresource_url_seen_;
bool iframe_url_seen_;
bool use_lofi_;
bool should_enable_lofi_mode_called_;
DISALLOW_COPY_AND_ASSIGN(LoFiModeResourceDispatcherHostDelegate);
};
} // namespace
class LoFiResourceDispatcherHostBrowserTest : public ContentBrowserTest {
public:
~LoFiResourceDispatcherHostBrowserTest() override {}
protected:
void SetUpOnMainThread() override {
ContentBrowserTest::SetUpOnMainThread();
ASSERT_TRUE(embedded_test_server()->Start());
delegate_.reset(new LoFiModeResourceDispatcherHostDelegate(
embedded_test_server()->GetURL("/page_with_iframe.html"),
embedded_test_server()->GetURL("/image.jpg"),
embedded_test_server()->GetURL("/title1.html")));
content::BrowserThread::PostTask(
content::BrowserThread::IO,
FROM_HERE,
base::Bind(&LoFiModeResourceDispatcherHostDelegate::SetDelegate,
base::Unretained(delegate_.get())));
}
void Reset(bool use_lofi) {
content::BrowserThread::PostTask(
content::BrowserThread::IO, FROM_HERE,
base::Bind(&LoFiModeResourceDispatcherHostDelegate::Reset,
base::Unretained(delegate_.get()), use_lofi));
}
void CheckResourcesRequested(
bool should_enable_lofi_mode_called) {
content::BrowserThread::PostTask(
content::BrowserThread::IO, FROM_HERE,
base::Bind(
&LoFiModeResourceDispatcherHostDelegate::CheckResourcesRequested,
base::Unretained(delegate_.get()), should_enable_lofi_mode_called));
}
private:
std::unique_ptr<LoFiModeResourceDispatcherHostDelegate> delegate_;
};
// Test that navigating with ShouldEnableLoFiMode returning true fetches the
// resources with LOFI_ON.
IN_PROC_BROWSER_TEST_F(LoFiResourceDispatcherHostBrowserTest,
ShouldEnableLoFiModeOn) {
// Navigate with ShouldEnableLoFiMode returning true.
Reset(true);
NavigateToURLBlockUntilNavigationsComplete(
shell(), embedded_test_server()->GetURL("/page_with_iframe.html"), 1);
CheckResourcesRequested(true);
}
// Test that navigating with ShouldEnableLoFiMode returning false fetches the
// resources with LOFI_OFF.
IN_PROC_BROWSER_TEST_F(LoFiResourceDispatcherHostBrowserTest,
ShouldEnableLoFiModeOff) {
// Navigate with ShouldEnableLoFiMode returning false.
NavigateToURLBlockUntilNavigationsComplete(
shell(), embedded_test_server()->GetURL("/page_with_iframe.html"), 1);
CheckResourcesRequested(true);
}
// Test that reloading calls ShouldEnableLoFiMode again and changes the Lo-Fi
// state.
IN_PROC_BROWSER_TEST_F(LoFiResourceDispatcherHostBrowserTest,
ShouldEnableLoFiModeReload) {
// Navigate with ShouldEnableLoFiMode returning false.
NavigateToURLBlockUntilNavigationsComplete(
shell(), embedded_test_server()->GetURL("/page_with_iframe.html"), 1);
CheckResourcesRequested(true);
// Reload. ShouldEnableLoFiMode should be called.
Reset(true);
ReloadBlockUntilNavigationsComplete(shell(), 1);
CheckResourcesRequested(true);
}
// Test that navigating backwards calls ShouldEnableLoFiMode again and changes
// the Lo-Fi state.
IN_PROC_BROWSER_TEST_F(LoFiResourceDispatcherHostBrowserTest,
ShouldEnableLoFiModeNavigateBackThenForward) {
// Navigate with ShouldEnableLoFiMode returning false.
NavigateToURLBlockUntilNavigationsComplete(
shell(), embedded_test_server()->GetURL("/page_with_iframe.html"), 1);
CheckResourcesRequested(true);
// Go to a different page.
NavigateToURLBlockUntilNavigationsComplete(shell(), GURL("about:blank"), 1);
// Go back with ShouldEnableLoFiMode returning true.
Reset(true);
TestNavigationObserver tab_observer(shell()->web_contents(), 1);
shell()->GoBackOrForward(-1);
tab_observer.Wait();
CheckResourcesRequested(true);
}
// Test that reloading with Lo-Fi disabled doesn't call ShouldEnableLoFiMode and
// already has LOFI_OFF.
IN_PROC_BROWSER_TEST_F(LoFiResourceDispatcherHostBrowserTest,
ShouldEnableLoFiModeReloadDisableLoFi) {
// Navigate with ShouldEnableLoFiMode returning true.
Reset(true);
NavigateToURLBlockUntilNavigationsComplete(
shell(), embedded_test_server()->GetURL("/page_with_iframe.html"), 1);
CheckResourcesRequested(true);
// Reload with Lo-Fi disabled.
Reset(false);
TestNavigationObserver tab_observer(shell()->web_contents(), 1);
shell()->web_contents()->GetController().ReloadDisableLoFi(true);
tab_observer.Wait();
CheckResourcesRequested(false);
}
namespace {
struct RequestDataForDelegate {
const GURL url;
const GURL first_party;
const url::Origin initiator;
RequestDataForDelegate(const GURL& url,
const GURL& first_party,
const url::Origin initiator)
: url(url), first_party(first_party), initiator(initiator) {}
};
// Captures calls to 'RequestBeginning' and records the URL, first-party for
// cookies, and initiator.
class RequestDataResourceDispatcherHostDelegate
: public ResourceDispatcherHostDelegate {
public:
RequestDataResourceDispatcherHostDelegate() {}
const ScopedVector<RequestDataForDelegate>& data() { return requests_; }
// ResourceDispatcherHostDelegate implementation:
void RequestBeginning(net::URLRequest* request,
ResourceContext* resource_context,
AppCacheService* appcache_service,
ResourceType resource_type,
ScopedVector<ResourceThrottle>* throttles) override {
requests_.push_back(new RequestDataForDelegate(
request->url(), request->first_party_for_cookies(),
request->initiator()));
}
void SetDelegate() { ResourceDispatcherHost::Get()->SetDelegate(this); }
private:
ScopedVector<RequestDataForDelegate> requests_;
DISALLOW_COPY_AND_ASSIGN(RequestDataResourceDispatcherHostDelegate);
};
const GURL kURLWithUniqueOrigin("data:,");
} // namespace
class RequestDataResourceDispatcherHostBrowserTest : public ContentBrowserTest {
public:
~RequestDataResourceDispatcherHostBrowserTest() override {}
protected:
void SetUpOnMainThread() override {
ContentBrowserTest::SetUpOnMainThread();
ASSERT_TRUE(embedded_test_server()->Start());
delegate_.reset(new RequestDataResourceDispatcherHostDelegate());
content::BrowserThread::PostTask(
content::BrowserThread::IO, FROM_HERE,
base::Bind(&RequestDataResourceDispatcherHostDelegate::SetDelegate,
base::Unretained(delegate_.get())));
}
protected:
std::unique_ptr<RequestDataResourceDispatcherHostDelegate> delegate_;
};
IN_PROC_BROWSER_TEST_F(RequestDataResourceDispatcherHostBrowserTest, Basic) {
GURL top_url(embedded_test_server()->GetURL("/simple_page.html"));
url::Origin top_origin(top_url);
NavigateToURLBlockUntilNavigationsComplete(shell(), top_url, 1);
EXPECT_EQ(1u, delegate_->data().size());
// User-initiated top-level navigations have a first-party and initiator that
// matches the URL to which they navigate.
EXPECT_EQ(top_url, delegate_->data()[0]->url);
EXPECT_EQ(top_url, delegate_->data()[0]->first_party);
EXPECT_EQ(top_origin, delegate_->data()[0]->initiator);
}
IN_PROC_BROWSER_TEST_F(RequestDataResourceDispatcherHostBrowserTest,
SameOriginNested) {
GURL top_url(embedded_test_server()->GetURL("/page_with_iframe.html"));
GURL image_url(embedded_test_server()->GetURL("/image.jpg"));
GURL nested_url(embedded_test_server()->GetURL("/title1.html"));
url::Origin top_origin(top_url);
NavigateToURLBlockUntilNavigationsComplete(shell(), top_url, 1);
EXPECT_EQ(3u, delegate_->data().size());
// User-initiated top-level navigations have a first-party and initiator that
// matches the URL to which they navigate.
EXPECT_EQ(top_url, delegate_->data()[0]->url);
EXPECT_EQ(top_url, delegate_->data()[0]->first_party);
EXPECT_EQ(top_origin, delegate_->data()[0]->initiator);
// Subresource requests have a first-party and initiator that matches the
// document in which they're embedded.
EXPECT_EQ(image_url, delegate_->data()[1]->url);
EXPECT_EQ(top_url, delegate_->data()[1]->first_party);
EXPECT_EQ(top_origin, delegate_->data()[1]->initiator);
// Same-origin nested frames have a first-party and initiator that matches
// the document in which they're embedded.
EXPECT_EQ(nested_url, delegate_->data()[2]->url);
EXPECT_EQ(top_url, delegate_->data()[2]->first_party);
EXPECT_EQ(top_origin, delegate_->data()[2]->initiator);
}
IN_PROC_BROWSER_TEST_F(RequestDataResourceDispatcherHostBrowserTest,
SameOriginAuxiliary) {
GURL top_url(embedded_test_server()->GetURL("/simple_links.html"));
GURL auxiliary_url(embedded_test_server()->GetURL("/title2.html"));
url::Origin top_origin(top_url);
NavigateToURLBlockUntilNavigationsComplete(shell(), top_url, 1);
ShellAddedObserver new_shell_observer;
bool success = false;
EXPECT_TRUE(ExecuteScriptAndExtractBool(
shell(),
"window.domAutomationController.send(clickSameSiteNewWindowLink());",
&success));
EXPECT_TRUE(success);
Shell* new_shell = new_shell_observer.GetShell();
WaitForLoadStop(new_shell->web_contents());
EXPECT_EQ(2u, delegate_->data().size());
// User-initiated top-level navigations have a first-party and initiator that
// matches the URL to which they navigate, even if they fail to load.
EXPECT_EQ(top_url, delegate_->data()[0]->url);
EXPECT_EQ(top_url, delegate_->data()[0]->first_party);
EXPECT_EQ(top_origin, delegate_->data()[0]->initiator);
// Auxiliary navigations have a first-party that matches the URL to which they
// navigate, and an initiator that matches the document that triggered them.
EXPECT_EQ(auxiliary_url, delegate_->data()[1]->url);
EXPECT_EQ(auxiliary_url, delegate_->data()[1]->first_party);
EXPECT_EQ(top_origin, delegate_->data()[1]->initiator);
}
IN_PROC_BROWSER_TEST_F(RequestDataResourceDispatcherHostBrowserTest,
CrossOriginAuxiliary) {
GURL top_url(embedded_test_server()->GetURL("/simple_links.html"));
GURL auxiliary_url(embedded_test_server()->GetURL("foo.com", "/title2.html"));
url::Origin top_origin(top_url);
NavigateToURLBlockUntilNavigationsComplete(shell(), top_url, 1);
const char kReplacePortNumber[] =
"window.domAutomationController.send(setPortNumber(%d));";
uint16_t port_number = embedded_test_server()->port();
bool success = false;
EXPECT_TRUE(ExecuteScriptAndExtractBool(
shell(), base::StringPrintf(kReplacePortNumber, port_number), &success));
success = false;
ShellAddedObserver new_shell_observer;
success = false;
EXPECT_TRUE(ExecuteScriptAndExtractBool(
shell(),
"window.domAutomationController.send(clickCrossSiteNewWindowLink());",
&success));
EXPECT_TRUE(success);
Shell* new_shell = new_shell_observer.GetShell();
WaitForLoadStop(new_shell->web_contents());
EXPECT_EQ(2u, delegate_->data().size());
// User-initiated top-level navigations have a first-party and initiator that
// matches the URL to which they navigate, even if they fail to load.
EXPECT_EQ(top_url, delegate_->data()[0]->url);
EXPECT_EQ(top_url, delegate_->data()[0]->first_party);
EXPECT_EQ(top_origin, delegate_->data()[0]->initiator);
// Auxiliary navigations have a first-party that matches the URL to which they
// navigate, and an initiator that matches the document that triggered them.
EXPECT_EQ(auxiliary_url, delegate_->data()[1]->url);
EXPECT_EQ(auxiliary_url, delegate_->data()[1]->first_party);
EXPECT_EQ(top_origin, delegate_->data()[1]->initiator);
}
IN_PROC_BROWSER_TEST_F(RequestDataResourceDispatcherHostBrowserTest,
FailedNavigation) {
// Navigating to this URL will fail, as we haven't taught the host resolver
// about 'a.com'.
GURL top_url(embedded_test_server()->GetURL("a.com", "/simple_page.html"));
url::Origin top_origin(top_url);
NavigateToURLBlockUntilNavigationsComplete(shell(), top_url, 1);
EXPECT_EQ(1u, delegate_->data().size());
// User-initiated top-level navigations have a first-party and initiator that
// matches the URL to which they navigate, even if they fail to load.
EXPECT_EQ(top_url, delegate_->data()[0]->url);
EXPECT_EQ(top_url, delegate_->data()[0]->first_party);
EXPECT_EQ(top_origin, delegate_->data()[0]->initiator);
}
IN_PROC_BROWSER_TEST_F(RequestDataResourceDispatcherHostBrowserTest,
CrossOriginNested) {
host_resolver()->AddRule("*", "127.0.0.1");
GURL top_url(embedded_test_server()->GetURL(
"a.com", "/cross_site_iframe_factory.html?a(b)"));
GURL top_js_url(
embedded_test_server()->GetURL("a.com", "/tree_parser_util.js"));
GURL nested_url(embedded_test_server()->GetURL(
"b.com", "/cross_site_iframe_factory.html?b()"));
GURL nested_js_url(
embedded_test_server()->GetURL("b.com", "/tree_parser_util.js"));
url::Origin top_origin(top_url);
url::Origin nested_origin(nested_url);
NavigateToURLBlockUntilNavigationsComplete(shell(), top_url, 1);
EXPECT_EQ(4u, delegate_->data().size());
// User-initiated top-level navigations have a first-party and initiator that
// matches the URL to which they navigate.
EXPECT_EQ(top_url, delegate_->data()[0]->url);
EXPECT_EQ(top_url, delegate_->data()[0]->first_party);
EXPECT_EQ(top_origin, delegate_->data()[0]->initiator);
EXPECT_EQ(top_js_url, delegate_->data()[1]->url);
EXPECT_EQ(top_url, delegate_->data()[1]->first_party);
EXPECT_EQ(top_origin, delegate_->data()[1]->initiator);
// Cross-origin frames have a first-party and initiator that matches the URL
// in which they're embedded.
EXPECT_EQ(nested_url, delegate_->data()[2]->url);
EXPECT_EQ(top_url, delegate_->data()[2]->first_party);
EXPECT_EQ(top_origin, delegate_->data()[2]->initiator);
// Cross-origin subresource requests have a unique first-party, and an
// initiator that matches the document in which they're embedded.
EXPECT_EQ(nested_js_url, delegate_->data()[3]->url);
EXPECT_EQ(kURLWithUniqueOrigin, delegate_->data()[3]->first_party);
EXPECT_EQ(nested_origin, delegate_->data()[3]->initiator);
}
} // namespace content
|
// Copyright (c) 2011-2014 The Bitcoin developers
// Copyright (c) 2014-2015 The Dash developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "addresstablemodel.h"
#include "guiutil.h"
#include "walletmodel.h"
#include "base58.h"
#include "wallet.h"
#include <QFont>
#include <QDebug>
const QString AddressTableModel::Send = "S";
const QString AddressTableModel::Receive = "R";
struct AddressTableEntry
{
enum Type {
Sending,
Receiving,
Hidden /* QSortFilterProxyModel will filter these out */
};
Type type;
QString label;
QString address;
AddressTableEntry() {}
AddressTableEntry(Type type, const QString &label, const QString &address):
type(type), label(label), address(address) {}
};
struct AddressTableEntryLessThan
{
bool operator()(const AddressTableEntry &a, const AddressTableEntry &b) const
{
return a.address < b.address;
}
bool operator()(const AddressTableEntry &a, const QString &b) const
{
return a.address < b;
}
bool operator()(const QString &a, const AddressTableEntry &b) const
{
return a < b.address;
}
};
/* Determine address type from address purpose */
static AddressTableEntry::Type translateTransactionType(const QString &strPurpose, bool isMine)
{
AddressTableEntry::Type addressType = AddressTableEntry::Hidden;
// "refund" addresses aren't shown, and change addresses aren't in mapAddressBook at all.
if (strPurpose == "send")
addressType = AddressTableEntry::Sending;
else if (strPurpose == "receive")
addressType = AddressTableEntry::Receiving;
else if (strPurpose == "unknown" || strPurpose == "") // if purpose not set, guess
addressType = (isMine ? AddressTableEntry::Receiving : AddressTableEntry::Sending);
return addressType;
}
// Private implementation
class AddressTablePriv
{
public:
CWallet *wallet;
QList<AddressTableEntry> cachedAddressTable;
AddressTableModel *parent;
AddressTablePriv(CWallet *wallet, AddressTableModel *parent):
wallet(wallet), parent(parent) {}
void refreshAddressTable()
{
cachedAddressTable.clear();
{
LOCK(wallet->cs_wallet);
BOOST_FOREACH(const PAIRTYPE(CTxDestination, CAddressBookData)& item, wallet->mapAddressBook)
{
const CBitcoinAddress& address = item.first;
bool fMine = IsMine(*wallet, address.Get());
AddressTableEntry::Type addressType = translateTransactionType(
QString::fromStdString(item.second.purpose), fMine);
const std::string& strName = item.second.name;
cachedAddressTable.append(AddressTableEntry(addressType,
QString::fromStdString(strName),
QString::fromStdString(address.ToString())));
}
}
// qLowerBound() and qUpperBound() require our cachedAddressTable list to be sorted in asc order
// Even though the map is already sorted this re-sorting step is needed because the originating map
// is sorted by binary address, not by base58() address.
qSort(cachedAddressTable.begin(), cachedAddressTable.end(), AddressTableEntryLessThan());
}
void updateEntry(const QString &address, const QString &label, bool isMine, const QString &purpose, int status)
{
// Find address / label in model
QList<AddressTableEntry>::iterator lower = qLowerBound(
cachedAddressTable.begin(), cachedAddressTable.end(), address, AddressTableEntryLessThan());
QList<AddressTableEntry>::iterator upper = qUpperBound(
cachedAddressTable.begin(), cachedAddressTable.end(), address, AddressTableEntryLessThan());
int lowerIndex = (lower - cachedAddressTable.begin());
int upperIndex = (upper - cachedAddressTable.begin());
bool inModel = (lower != upper);
AddressTableEntry::Type newEntryType = translateTransactionType(purpose, isMine);
switch(status)
{
case CT_NEW:
if(inModel)
{
qWarning() << "AddressTablePriv::updateEntry : Warning: Got CT_NEW, but entry is already in model";
break;
}
parent->beginInsertRows(QModelIndex(), lowerIndex, lowerIndex);
cachedAddressTable.insert(lowerIndex, AddressTableEntry(newEntryType, label, address));
parent->endInsertRows();
break;
case CT_UPDATED:
if(!inModel)
{
qWarning() << "AddressTablePriv::updateEntry : Warning: Got CT_UPDATED, but entry is not in model";
break;
}
lower->type = newEntryType;
lower->label = label;
parent->emitDataChanged(lowerIndex);
break;
case CT_DELETED:
if(!inModel)
{
qWarning() << "AddressTablePriv::updateEntry : Warning: Got CT_DELETED, but entry is not in model";
break;
}
parent->beginRemoveRows(QModelIndex(), lowerIndex, upperIndex-1);
cachedAddressTable.erase(lower, upper);
parent->endRemoveRows();
break;
}
}
int size()
{
return cachedAddressTable.size();
}
AddressTableEntry *index(int idx)
{
if(idx >= 0 && idx < cachedAddressTable.size())
{
return &cachedAddressTable[idx];
}
else
{
return 0;
}
}
};
AddressTableModel::AddressTableModel(CWallet *wallet, WalletModel *parent) :
QAbstractTableModel(parent),walletModel(parent),wallet(wallet),priv(0)
{
columns << tr("Label") << tr("Address");
priv = new AddressTablePriv(wallet, this);
priv->refreshAddressTable();
}
AddressTableModel::~AddressTableModel()
{
delete priv;
}
int AddressTableModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return priv->size();
}
int AddressTableModel::columnCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return columns.length();
}
QVariant AddressTableModel::data(const QModelIndex &index, int role) const
{
if(!index.isValid())
return QVariant();
AddressTableEntry *rec = static_cast<AddressTableEntry*>(index.internalPointer());
if(role == Qt::DisplayRole || role == Qt::EditRole)
{
switch(index.column())
{
case Label:
if(rec->label.isEmpty() && role == Qt::DisplayRole)
{
return tr("(no label)");
}
else
{
return rec->label;
}
case Address:
return rec->address;
}
}
else if (role == Qt::FontRole)
{
QFont font;
if(index.column() == Address)
{
font = GUIUtil::bitcoinAddressFont();
}
return font;
}
else if (role == TypeRole)
{
switch(rec->type)
{
case AddressTableEntry::Sending:
return Send;
case AddressTableEntry::Receiving:
return Receive;
default: break;
}
}
return QVariant();
}
bool AddressTableModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if(!index.isValid())
return false;
AddressTableEntry *rec = static_cast<AddressTableEntry*>(index.internalPointer());
std::string strPurpose = (rec->type == AddressTableEntry::Sending ? "send" : "receive");
editStatus = OK;
if(role == Qt::EditRole)
{
LOCK(wallet->cs_wallet); /* For SetAddressBook / DelAddressBook */
CTxDestination curAddress = CBitcoinAddress(rec->address.toStdString()).Get();
if(index.column() == Label)
{
// Do nothing, if old label == new label
if(rec->label == value.toString())
{
editStatus = NO_CHANGES;
return false;
}
wallet->SetAddressBook(curAddress, value.toString().toStdString(), strPurpose);
} else if(index.column() == Address) {
CTxDestination newAddress = CBitcoinAddress(value.toString().toStdString()).Get();
// Refuse to set invalid address, set error status and return false
if(boost::get<CNoDestination>(&newAddress))
{
editStatus = INVALID_ADDRESS;
return false;
}
// Do nothing, if old address == new address
else if(newAddress == curAddress)
{
editStatus = NO_CHANGES;
return false;
}
// Check for duplicate addresses to prevent accidental deletion of addresses, if you try
// to paste an existing address over another address (with a different label)
else if(wallet->mapAddressBook.count(newAddress))
{
editStatus = DUPLICATE_ADDRESS;
return false;
}
// Double-check that we're not overwriting a receiving address
else if(rec->type == AddressTableEntry::Sending)
{
// Remove old entry
wallet->DelAddressBook(curAddress);
// Add new entry with new address
wallet->SetAddressBook(newAddress, rec->label.toStdString(), strPurpose);
}
}
return true;
}
return false;
}
QVariant AddressTableModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if(orientation == Qt::Horizontal)
{
if(role == Qt::DisplayRole && section < columns.size())
{
return columns[section];
}
}
return QVariant();
}
Qt::ItemFlags AddressTableModel::flags(const QModelIndex &index) const
{
if(!index.isValid())
return 0;
AddressTableEntry *rec = static_cast<AddressTableEntry*>(index.internalPointer());
Qt::ItemFlags retval = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
// Can edit address and label for sending addresses,
// and only label for receiving addresses.
if(rec->type == AddressTableEntry::Sending ||
(rec->type == AddressTableEntry::Receiving && index.column()==Label))
{
retval |= Qt::ItemIsEditable;
}
return retval;
}
QModelIndex AddressTableModel::index(int row, int column, const QModelIndex &parent) const
{
Q_UNUSED(parent);
AddressTableEntry *data = priv->index(row);
if(data)
{
return createIndex(row, column, priv->index(row));
}
else
{
return QModelIndex();
}
}
void AddressTableModel::updateEntry(const QString &address,
const QString &label, bool isMine, const QString &purpose, int status)
{
// Update address book model from Dash core
priv->updateEntry(address, label, isMine, purpose, status);
}
QString AddressTableModel::addRow(const QString &type, const QString &label, const QString &address)
{
std::string strLabel = label.toStdString();
std::string strAddress = address.toStdString();
editStatus = OK;
if(type == Send)
{
if(!walletModel->validateAddress(address))
{
editStatus = INVALID_ADDRESS;
return QString();
}
// Check for duplicate addresses
{
LOCK(wallet->cs_wallet);
if(wallet->mapAddressBook.count(CBitcoinAddress(strAddress).Get()))
{
editStatus = DUPLICATE_ADDRESS;
return QString();
}
}
}
else if(type == Receive)
{
// Generate a new address to associate with given label
CPubKey newKey;
if(!wallet->GetKeyFromPool(newKey))
{
WalletModel::UnlockContext ctx(walletModel->requestUnlock(true));
if(!ctx.isValid())
{
// Unlock wallet failed or was cancelled
editStatus = WALLET_UNLOCK_FAILURE;
return QString();
}
if(!wallet->GetKeyFromPool(newKey))
{
editStatus = KEY_GENERATION_FAILURE;
return QString();
}
}
strAddress = CBitcoinAddress(newKey.GetID()).ToString();
}
else
{
return QString();
}
// Add entry
{
LOCK(wallet->cs_wallet);
wallet->SetAddressBook(CBitcoinAddress(strAddress).Get(), strLabel,
(type == Send ? "send" : "receive"));
}
return QString::fromStdString(strAddress);
}
bool AddressTableModel::removeRows(int row, int count, const QModelIndex &parent)
{
Q_UNUSED(parent);
AddressTableEntry *rec = priv->index(row);
if(count != 1 || !rec || rec->type == AddressTableEntry::Receiving)
{
// Can only remove one row at a time, and cannot remove rows not in model.
// Also refuse to remove receiving addresses.
return false;
}
{
LOCK(wallet->cs_wallet);
wallet->DelAddressBook(CBitcoinAddress(rec->address.toStdString()).Get());
}
return true;
}
/* Look up label for address in address book, if not found return empty string.
*/
QString AddressTableModel::labelForAddress(const QString &address) const
{
{
LOCK(wallet->cs_wallet);
CBitcoinAddress address_parsed(address.toStdString());
std::map<CTxDestination, CAddressBookData>::iterator mi = wallet->mapAddressBook.find(address_parsed.Get());
if (mi != wallet->mapAddressBook.end())
{
return QString::fromStdString(mi->second.name);
}
}
return QString();
}
static CKeyID getKeyID(const QString &addr)
{
string strAddress = addr.toStdString();
CBitcoinAddress address;
if (!address.SetString(strAddress))
throw std::runtime_error("Invalid Surcoin address");
CKeyID keyID;
address.GetKeyID(keyID);
return keyID;
}
QString AddressTableModel::pubkeyForAddress(const QString &addr) const
{
CKeyID keyID;
keyID = getKeyID(addr);
CPubKey vchPubKeyOut;
if (!wallet->GetPubKey(keyID, vchPubKeyOut))
throw std::runtime_error(
"Public key for address " + addr.toStdString()
+ " is not known");
std::string s_pubkey = HexStr(vchPubKeyOut);
return QString::fromStdString(s_pubkey);
}
QString AddressTableModel::privkeyForAddress(const QString &addr) const
{
CKeyID keyID;
keyID = getKeyID(addr);
CKey vchSecret;
bool gotKey = false;
WalletModel::EncryptionStatus encStatus = walletModel->getEncryptionStatus();
// check if wallet encrypted
if(encStatus == walletModel->Locked || encStatus == walletModel->UnlockedForAnonymizationOnly)
{
WalletModel::UnlockContext ctx(walletModel->requestUnlock(true));
if(ctx.isValid())
gotKey = wallet->GetKey(keyID, vchSecret);
} else {
gotKey = wallet->GetKey(keyID, vchSecret);
}
if (!gotKey)
throw std::runtime_error("Private key for address "+addr.toStdString()+" is not known");
return QString::fromStdString(CBitcoinSecret(vchSecret).ToString());
}
int AddressTableModel::lookupAddress(const QString &address) const
{
QModelIndexList lst = match(index(0, Address, QModelIndex()),
Qt::EditRole, address, 1, Qt::MatchExactly);
if(lst.isEmpty())
{
return -1;
}
else
{
return lst.at(0).row();
}
}
void AddressTableModel::emitDataChanged(int idx)
{
emit dataChanged(index(idx, 0, QModelIndex()), index(idx, columns.length()-1, QModelIndex()));
}
|
;------------------------------------------------------------------------------
;
; EnableInterrupts() for ARM
;
; Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>
; Portions copyright (c) 2008 - 2009, Apple Inc. 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.
;
;------------------------------------------------------------------------------
EXPORT EnableInterrupts
AREA Interrupt_enable, CODE, READONLY
;/**
; Enables CPU interrupts.
;
;**/
;VOID
;EFIAPI
;EnableInterrupts (
; VOID
; );
;
EnableInterrupts
MRS R0,CPSR
BIC R0,R0,#0x80 ;Enable IRQ interrupts
MSR CPSR_c,R0
BX LR
END
|
user/_wc: file format elf64-littleriscv
Disassembly of section .text:
0000000000000000 <wc>:
char buf[512];
void
wc(int fd, char *name)
{
0: 7119 addi sp,sp,-128
2: fc86 sd ra,120(sp)
4: f8a2 sd s0,112(sp)
6: f4a6 sd s1,104(sp)
8: f0ca sd s2,96(sp)
a: ecce sd s3,88(sp)
c: e8d2 sd s4,80(sp)
e: e4d6 sd s5,72(sp)
10: e0da sd s6,64(sp)
12: fc5e sd s7,56(sp)
14: f862 sd s8,48(sp)
16: f466 sd s9,40(sp)
18: f06a sd s10,32(sp)
1a: ec6e sd s11,24(sp)
1c: 0100 addi s0,sp,128
1e: f8a43423 sd a0,-120(s0)
22: f8b43023 sd a1,-128(s0)
int i, n;
int l, w, c, inword;
l = w = c = 0;
inword = 0;
26: 4981 li s3,0
l = w = c = 0;
28: 4c81 li s9,0
2a: 4c01 li s8,0
2c: 4b81 li s7,0
2e: 00001d97 auipc s11,0x1
32: 983d8d93 addi s11,s11,-1661 # 9b1 <buf+0x1>
while((n = read(fd, buf, sizeof(buf))) > 0){
for(i=0; i<n; i++){
c++;
if(buf[i] == '\n')
36: 4aa9 li s5,10
l++;
if(strchr(" \r\t\n\v", buf[i]))
38: 00001a17 auipc s4,0x1
3c: 908a0a13 addi s4,s4,-1784 # 940 <malloc+0xe6>
inword = 0;
40: 4b01 li s6,0
while((n = read(fd, buf, sizeof(buf))) > 0){
42: a805 j 72 <wc+0x72>
if(strchr(" \r\t\n\v", buf[i]))
44: 8552 mv a0,s4
46: 00000097 auipc ra,0x0
4a: 1e8080e7 jalr 488(ra) # 22e <strchr>
4e: c919 beqz a0,64 <wc+0x64>
inword = 0;
50: 89da mv s3,s6
for(i=0; i<n; i++){
52: 0485 addi s1,s1,1
54: 01248d63 beq s1,s2,6e <wc+0x6e>
if(buf[i] == '\n')
58: 0004c583 lbu a1,0(s1)
5c: ff5594e3 bne a1,s5,44 <wc+0x44>
l++;
60: 2b85 addiw s7,s7,1
62: b7cd j 44 <wc+0x44>
else if(!inword){
64: fe0997e3 bnez s3,52 <wc+0x52>
w++;
68: 2c05 addiw s8,s8,1
inword = 1;
6a: 4985 li s3,1
6c: b7dd j 52 <wc+0x52>
6e: 01ac8cbb addw s9,s9,s10
while((n = read(fd, buf, sizeof(buf))) > 0){
72: 20000613 li a2,512
76: 00001597 auipc a1,0x1
7a: 93a58593 addi a1,a1,-1734 # 9b0 <buf>
7e: f8843503 ld a0,-120(s0)
82: 00000097 auipc ra,0x0
86: 3a2080e7 jalr 930(ra) # 424 <read>
8a: 00a05f63 blez a0,a8 <wc+0xa8>
for(i=0; i<n; i++){
8e: 00001497 auipc s1,0x1
92: 92248493 addi s1,s1,-1758 # 9b0 <buf>
96: 00050d1b sext.w s10,a0
9a: fff5091b addiw s2,a0,-1
9e: 1902 slli s2,s2,0x20
a0: 02095913 srli s2,s2,0x20
a4: 996e add s2,s2,s11
a6: bf4d j 58 <wc+0x58>
}
}
}
if(n < 0){
a8: 02054e63 bltz a0,e4 <wc+0xe4>
printf("wc: read error\n");
exit(1);
}
printf("%d %d %d %s\n", l, w, c, name);
ac: f8043703 ld a4,-128(s0)
b0: 86e6 mv a3,s9
b2: 8662 mv a2,s8
b4: 85de mv a1,s7
b6: 00001517 auipc a0,0x1
ba: 8a250513 addi a0,a0,-1886 # 958 <malloc+0xfe>
be: 00000097 auipc ra,0x0
c2: 6de080e7 jalr 1758(ra) # 79c <printf>
}
c6: 70e6 ld ra,120(sp)
c8: 7446 ld s0,112(sp)
ca: 74a6 ld s1,104(sp)
cc: 7906 ld s2,96(sp)
ce: 69e6 ld s3,88(sp)
d0: 6a46 ld s4,80(sp)
d2: 6aa6 ld s5,72(sp)
d4: 6b06 ld s6,64(sp)
d6: 7be2 ld s7,56(sp)
d8: 7c42 ld s8,48(sp)
da: 7ca2 ld s9,40(sp)
dc: 7d02 ld s10,32(sp)
de: 6de2 ld s11,24(sp)
e0: 6109 addi sp,sp,128
e2: 8082 ret
printf("wc: read error\n");
e4: 00001517 auipc a0,0x1
e8: 86450513 addi a0,a0,-1948 # 948 <malloc+0xee>
ec: 00000097 auipc ra,0x0
f0: 6b0080e7 jalr 1712(ra) # 79c <printf>
exit(1);
f4: 4505 li a0,1
f6: 00000097 auipc ra,0x0
fa: 316080e7 jalr 790(ra) # 40c <exit>
00000000000000fe <main>:
int
main(int argc, char *argv[])
{
fe: 7179 addi sp,sp,-48
100: f406 sd ra,40(sp)
102: f022 sd s0,32(sp)
104: ec26 sd s1,24(sp)
106: e84a sd s2,16(sp)
108: e44e sd s3,8(sp)
10a: e052 sd s4,0(sp)
10c: 1800 addi s0,sp,48
int fd, i;
if(argc <= 1){
10e: 4785 li a5,1
110: 04a7d763 bge a5,a0,15e <main+0x60>
114: 00858493 addi s1,a1,8
118: ffe5099b addiw s3,a0,-2
11c: 1982 slli s3,s3,0x20
11e: 0209d993 srli s3,s3,0x20
122: 098e slli s3,s3,0x3
124: 05c1 addi a1,a1,16
126: 99ae add s3,s3,a1
wc(0, "");
exit(0);
}
for(i = 1; i < argc; i++){
if((fd = open(argv[i], 0)) < 0){
128: 4581 li a1,0
12a: 6088 ld a0,0(s1)
12c: 00000097 auipc ra,0x0
130: 320080e7 jalr 800(ra) # 44c <open>
134: 892a mv s2,a0
136: 04054263 bltz a0,17a <main+0x7c>
printf("wc: cannot open %s\n", argv[i]);
exit(1);
}
wc(fd, argv[i]);
13a: 608c ld a1,0(s1)
13c: 00000097 auipc ra,0x0
140: ec4080e7 jalr -316(ra) # 0 <wc>
close(fd);
144: 854a mv a0,s2
146: 00000097 auipc ra,0x0
14a: 2ee080e7 jalr 750(ra) # 434 <close>
for(i = 1; i < argc; i++){
14e: 04a1 addi s1,s1,8
150: fd349ce3 bne s1,s3,128 <main+0x2a>
}
exit(0);
154: 4501 li a0,0
156: 00000097 auipc ra,0x0
15a: 2b6080e7 jalr 694(ra) # 40c <exit>
wc(0, "");
15e: 00001597 auipc a1,0x1
162: 80a58593 addi a1,a1,-2038 # 968 <malloc+0x10e>
166: 4501 li a0,0
168: 00000097 auipc ra,0x0
16c: e98080e7 jalr -360(ra) # 0 <wc>
exit(0);
170: 4501 li a0,0
172: 00000097 auipc ra,0x0
176: 29a080e7 jalr 666(ra) # 40c <exit>
printf("wc: cannot open %s\n", argv[i]);
17a: 608c ld a1,0(s1)
17c: 00000517 auipc a0,0x0
180: 7f450513 addi a0,a0,2036 # 970 <malloc+0x116>
184: 00000097 auipc ra,0x0
188: 618080e7 jalr 1560(ra) # 79c <printf>
exit(1);
18c: 4505 li a0,1
18e: 00000097 auipc ra,0x0
192: 27e080e7 jalr 638(ra) # 40c <exit>
0000000000000196 <strcpy>:
#include "kernel/fcntl.h"
#include "user/user.h"
char*
strcpy(char *s, const char *t)
{
196: 1141 addi sp,sp,-16
198: e422 sd s0,8(sp)
19a: 0800 addi s0,sp,16
char *os;
os = s;
while((*s++ = *t++) != 0)
19c: 87aa mv a5,a0
19e: 0585 addi a1,a1,1
1a0: 0785 addi a5,a5,1
1a2: fff5c703 lbu a4,-1(a1)
1a6: fee78fa3 sb a4,-1(a5)
1aa: fb75 bnez a4,19e <strcpy+0x8>
;
return os;
}
1ac: 6422 ld s0,8(sp)
1ae: 0141 addi sp,sp,16
1b0: 8082 ret
00000000000001b2 <strcmp>:
int
strcmp(const char *p, const char *q)
{
1b2: 1141 addi sp,sp,-16
1b4: e422 sd s0,8(sp)
1b6: 0800 addi s0,sp,16
while(*p && *p == *q)
1b8: 00054783 lbu a5,0(a0)
1bc: cb91 beqz a5,1d0 <strcmp+0x1e>
1be: 0005c703 lbu a4,0(a1)
1c2: 00f71763 bne a4,a5,1d0 <strcmp+0x1e>
p++, q++;
1c6: 0505 addi a0,a0,1
1c8: 0585 addi a1,a1,1
while(*p && *p == *q)
1ca: 00054783 lbu a5,0(a0)
1ce: fbe5 bnez a5,1be <strcmp+0xc>
return (uchar)*p - (uchar)*q;
1d0: 0005c503 lbu a0,0(a1)
}
1d4: 40a7853b subw a0,a5,a0
1d8: 6422 ld s0,8(sp)
1da: 0141 addi sp,sp,16
1dc: 8082 ret
00000000000001de <strlen>:
uint
strlen(const char *s)
{
1de: 1141 addi sp,sp,-16
1e0: e422 sd s0,8(sp)
1e2: 0800 addi s0,sp,16
int n;
for(n = 0; s[n]; n++)
1e4: 00054783 lbu a5,0(a0)
1e8: cf91 beqz a5,204 <strlen+0x26>
1ea: 0505 addi a0,a0,1
1ec: 87aa mv a5,a0
1ee: 4685 li a3,1
1f0: 9e89 subw a3,a3,a0
1f2: 00f6853b addw a0,a3,a5
1f6: 0785 addi a5,a5,1
1f8: fff7c703 lbu a4,-1(a5)
1fc: fb7d bnez a4,1f2 <strlen+0x14>
;
return n;
}
1fe: 6422 ld s0,8(sp)
200: 0141 addi sp,sp,16
202: 8082 ret
for(n = 0; s[n]; n++)
204: 4501 li a0,0
206: bfe5 j 1fe <strlen+0x20>
0000000000000208 <memset>:
void*
memset(void *dst, int c, uint n)
{
208: 1141 addi sp,sp,-16
20a: e422 sd s0,8(sp)
20c: 0800 addi s0,sp,16
char *cdst = (char *) dst;
int i;
for(i = 0; i < n; i++){
20e: ce09 beqz a2,228 <memset+0x20>
210: 87aa mv a5,a0
212: fff6071b addiw a4,a2,-1
216: 1702 slli a4,a4,0x20
218: 9301 srli a4,a4,0x20
21a: 0705 addi a4,a4,1
21c: 972a add a4,a4,a0
cdst[i] = c;
21e: 00b78023 sb a1,0(a5)
for(i = 0; i < n; i++){
222: 0785 addi a5,a5,1
224: fee79de3 bne a5,a4,21e <memset+0x16>
}
return dst;
}
228: 6422 ld s0,8(sp)
22a: 0141 addi sp,sp,16
22c: 8082 ret
000000000000022e <strchr>:
char*
strchr(const char *s, char c)
{
22e: 1141 addi sp,sp,-16
230: e422 sd s0,8(sp)
232: 0800 addi s0,sp,16
for(; *s; s++)
234: 00054783 lbu a5,0(a0)
238: cb99 beqz a5,24e <strchr+0x20>
if(*s == c)
23a: 00f58763 beq a1,a5,248 <strchr+0x1a>
for(; *s; s++)
23e: 0505 addi a0,a0,1
240: 00054783 lbu a5,0(a0)
244: fbfd bnez a5,23a <strchr+0xc>
return (char*)s;
return 0;
246: 4501 li a0,0
}
248: 6422 ld s0,8(sp)
24a: 0141 addi sp,sp,16
24c: 8082 ret
return 0;
24e: 4501 li a0,0
250: bfe5 j 248 <strchr+0x1a>
0000000000000252 <gets>:
char*
gets(char *buf, int max)
{
252: 711d addi sp,sp,-96
254: ec86 sd ra,88(sp)
256: e8a2 sd s0,80(sp)
258: e4a6 sd s1,72(sp)
25a: e0ca sd s2,64(sp)
25c: fc4e sd s3,56(sp)
25e: f852 sd s4,48(sp)
260: f456 sd s5,40(sp)
262: f05a sd s6,32(sp)
264: ec5e sd s7,24(sp)
266: 1080 addi s0,sp,96
268: 8baa mv s7,a0
26a: 8a2e mv s4,a1
int i, cc;
char c;
for(i=0; i+1 < max; ){
26c: 892a mv s2,a0
26e: 4481 li s1,0
cc = read(0, &c, 1);
if(cc < 1)
break;
buf[i++] = c;
if(c == '\n' || c == '\r')
270: 4aa9 li s5,10
272: 4b35 li s6,13
for(i=0; i+1 < max; ){
274: 89a6 mv s3,s1
276: 2485 addiw s1,s1,1
278: 0344d863 bge s1,s4,2a8 <gets+0x56>
cc = read(0, &c, 1);
27c: 4605 li a2,1
27e: faf40593 addi a1,s0,-81
282: 4501 li a0,0
284: 00000097 auipc ra,0x0
288: 1a0080e7 jalr 416(ra) # 424 <read>
if(cc < 1)
28c: 00a05e63 blez a0,2a8 <gets+0x56>
buf[i++] = c;
290: faf44783 lbu a5,-81(s0)
294: 00f90023 sb a5,0(s2)
if(c == '\n' || c == '\r')
298: 01578763 beq a5,s5,2a6 <gets+0x54>
29c: 0905 addi s2,s2,1
29e: fd679be3 bne a5,s6,274 <gets+0x22>
for(i=0; i+1 < max; ){
2a2: 89a6 mv s3,s1
2a4: a011 j 2a8 <gets+0x56>
2a6: 89a6 mv s3,s1
break;
}
buf[i] = '\0';
2a8: 99de add s3,s3,s7
2aa: 00098023 sb zero,0(s3)
return buf;
}
2ae: 855e mv a0,s7
2b0: 60e6 ld ra,88(sp)
2b2: 6446 ld s0,80(sp)
2b4: 64a6 ld s1,72(sp)
2b6: 6906 ld s2,64(sp)
2b8: 79e2 ld s3,56(sp)
2ba: 7a42 ld s4,48(sp)
2bc: 7aa2 ld s5,40(sp)
2be: 7b02 ld s6,32(sp)
2c0: 6be2 ld s7,24(sp)
2c2: 6125 addi sp,sp,96
2c4: 8082 ret
00000000000002c6 <stat>:
int
stat(const char *n, struct stat *st)
{
2c6: 1101 addi sp,sp,-32
2c8: ec06 sd ra,24(sp)
2ca: e822 sd s0,16(sp)
2cc: e426 sd s1,8(sp)
2ce: e04a sd s2,0(sp)
2d0: 1000 addi s0,sp,32
2d2: 892e mv s2,a1
int fd;
int r;
fd = open(n, O_RDONLY);
2d4: 4581 li a1,0
2d6: 00000097 auipc ra,0x0
2da: 176080e7 jalr 374(ra) # 44c <open>
if(fd < 0)
2de: 02054563 bltz a0,308 <stat+0x42>
2e2: 84aa mv s1,a0
return -1;
r = fstat(fd, st);
2e4: 85ca mv a1,s2
2e6: 00000097 auipc ra,0x0
2ea: 17e080e7 jalr 382(ra) # 464 <fstat>
2ee: 892a mv s2,a0
close(fd);
2f0: 8526 mv a0,s1
2f2: 00000097 auipc ra,0x0
2f6: 142080e7 jalr 322(ra) # 434 <close>
return r;
}
2fa: 854a mv a0,s2
2fc: 60e2 ld ra,24(sp)
2fe: 6442 ld s0,16(sp)
300: 64a2 ld s1,8(sp)
302: 6902 ld s2,0(sp)
304: 6105 addi sp,sp,32
306: 8082 ret
return -1;
308: 597d li s2,-1
30a: bfc5 j 2fa <stat+0x34>
000000000000030c <atoi>:
int
atoi(const char *s)
{
30c: 1141 addi sp,sp,-16
30e: e422 sd s0,8(sp)
310: 0800 addi s0,sp,16
int n;
n = 0;
while('0' <= *s && *s <= '9')
312: 00054603 lbu a2,0(a0)
316: fd06079b addiw a5,a2,-48
31a: 0ff7f793 andi a5,a5,255
31e: 4725 li a4,9
320: 02f76963 bltu a4,a5,352 <atoi+0x46>
324: 86aa mv a3,a0
n = 0;
326: 4501 li a0,0
while('0' <= *s && *s <= '9')
328: 45a5 li a1,9
n = n*10 + *s++ - '0';
32a: 0685 addi a3,a3,1
32c: 0025179b slliw a5,a0,0x2
330: 9fa9 addw a5,a5,a0
332: 0017979b slliw a5,a5,0x1
336: 9fb1 addw a5,a5,a2
338: fd07851b addiw a0,a5,-48
while('0' <= *s && *s <= '9')
33c: 0006c603 lbu a2,0(a3)
340: fd06071b addiw a4,a2,-48
344: 0ff77713 andi a4,a4,255
348: fee5f1e3 bgeu a1,a4,32a <atoi+0x1e>
return n;
}
34c: 6422 ld s0,8(sp)
34e: 0141 addi sp,sp,16
350: 8082 ret
n = 0;
352: 4501 li a0,0
354: bfe5 j 34c <atoi+0x40>
0000000000000356 <memmove>:
void*
memmove(void *vdst, const void *vsrc, int n)
{
356: 1141 addi sp,sp,-16
358: e422 sd s0,8(sp)
35a: 0800 addi s0,sp,16
char *dst;
const char *src;
dst = vdst;
src = vsrc;
if (src > dst) {
35c: 02b57663 bgeu a0,a1,388 <memmove+0x32>
while(n-- > 0)
360: 02c05163 blez a2,382 <memmove+0x2c>
364: fff6079b addiw a5,a2,-1
368: 1782 slli a5,a5,0x20
36a: 9381 srli a5,a5,0x20
36c: 0785 addi a5,a5,1
36e: 97aa add a5,a5,a0
dst = vdst;
370: 872a mv a4,a0
*dst++ = *src++;
372: 0585 addi a1,a1,1
374: 0705 addi a4,a4,1
376: fff5c683 lbu a3,-1(a1)
37a: fed70fa3 sb a3,-1(a4)
while(n-- > 0)
37e: fee79ae3 bne a5,a4,372 <memmove+0x1c>
src += n;
while(n-- > 0)
*--dst = *--src;
}
return vdst;
}
382: 6422 ld s0,8(sp)
384: 0141 addi sp,sp,16
386: 8082 ret
dst += n;
388: 00c50733 add a4,a0,a2
src += n;
38c: 95b2 add a1,a1,a2
while(n-- > 0)
38e: fec05ae3 blez a2,382 <memmove+0x2c>
392: fff6079b addiw a5,a2,-1
396: 1782 slli a5,a5,0x20
398: 9381 srli a5,a5,0x20
39a: fff7c793 not a5,a5
39e: 97ba add a5,a5,a4
*--dst = *--src;
3a0: 15fd addi a1,a1,-1
3a2: 177d addi a4,a4,-1
3a4: 0005c683 lbu a3,0(a1)
3a8: 00d70023 sb a3,0(a4)
while(n-- > 0)
3ac: fee79ae3 bne a5,a4,3a0 <memmove+0x4a>
3b0: bfc9 j 382 <memmove+0x2c>
00000000000003b2 <memcmp>:
int
memcmp(const void *s1, const void *s2, uint n)
{
3b2: 1141 addi sp,sp,-16
3b4: e422 sd s0,8(sp)
3b6: 0800 addi s0,sp,16
const char *p1 = s1, *p2 = s2;
while (n-- > 0) {
3b8: ca05 beqz a2,3e8 <memcmp+0x36>
3ba: fff6069b addiw a3,a2,-1
3be: 1682 slli a3,a3,0x20
3c0: 9281 srli a3,a3,0x20
3c2: 0685 addi a3,a3,1
3c4: 96aa add a3,a3,a0
if (*p1 != *p2) {
3c6: 00054783 lbu a5,0(a0)
3ca: 0005c703 lbu a4,0(a1)
3ce: 00e79863 bne a5,a4,3de <memcmp+0x2c>
return *p1 - *p2;
}
p1++;
3d2: 0505 addi a0,a0,1
p2++;
3d4: 0585 addi a1,a1,1
while (n-- > 0) {
3d6: fed518e3 bne a0,a3,3c6 <memcmp+0x14>
}
return 0;
3da: 4501 li a0,0
3dc: a019 j 3e2 <memcmp+0x30>
return *p1 - *p2;
3de: 40e7853b subw a0,a5,a4
}
3e2: 6422 ld s0,8(sp)
3e4: 0141 addi sp,sp,16
3e6: 8082 ret
return 0;
3e8: 4501 li a0,0
3ea: bfe5 j 3e2 <memcmp+0x30>
00000000000003ec <memcpy>:
void *
memcpy(void *dst, const void *src, uint n)
{
3ec: 1141 addi sp,sp,-16
3ee: e406 sd ra,8(sp)
3f0: e022 sd s0,0(sp)
3f2: 0800 addi s0,sp,16
return memmove(dst, src, n);
3f4: 00000097 auipc ra,0x0
3f8: f62080e7 jalr -158(ra) # 356 <memmove>
}
3fc: 60a2 ld ra,8(sp)
3fe: 6402 ld s0,0(sp)
400: 0141 addi sp,sp,16
402: 8082 ret
0000000000000404 <fork>:
# generated by usys.pl - do not edit
#include "kernel/syscall.h"
.global fork
fork:
li a7, SYS_fork
404: 4885 li a7,1
ecall
406: 00000073 ecall
ret
40a: 8082 ret
000000000000040c <exit>:
.global exit
exit:
li a7, SYS_exit
40c: 4889 li a7,2
ecall
40e: 00000073 ecall
ret
412: 8082 ret
0000000000000414 <wait>:
.global wait
wait:
li a7, SYS_wait
414: 488d li a7,3
ecall
416: 00000073 ecall
ret
41a: 8082 ret
000000000000041c <pipe>:
.global pipe
pipe:
li a7, SYS_pipe
41c: 4891 li a7,4
ecall
41e: 00000073 ecall
ret
422: 8082 ret
0000000000000424 <read>:
.global read
read:
li a7, SYS_read
424: 4895 li a7,5
ecall
426: 00000073 ecall
ret
42a: 8082 ret
000000000000042c <write>:
.global write
write:
li a7, SYS_write
42c: 48c1 li a7,16
ecall
42e: 00000073 ecall
ret
432: 8082 ret
0000000000000434 <close>:
.global close
close:
li a7, SYS_close
434: 48d5 li a7,21
ecall
436: 00000073 ecall
ret
43a: 8082 ret
000000000000043c <kill>:
.global kill
kill:
li a7, SYS_kill
43c: 4899 li a7,6
ecall
43e: 00000073 ecall
ret
442: 8082 ret
0000000000000444 <exec>:
.global exec
exec:
li a7, SYS_exec
444: 489d li a7,7
ecall
446: 00000073 ecall
ret
44a: 8082 ret
000000000000044c <open>:
.global open
open:
li a7, SYS_open
44c: 48bd li a7,15
ecall
44e: 00000073 ecall
ret
452: 8082 ret
0000000000000454 <mknod>:
.global mknod
mknod:
li a7, SYS_mknod
454: 48c5 li a7,17
ecall
456: 00000073 ecall
ret
45a: 8082 ret
000000000000045c <unlink>:
.global unlink
unlink:
li a7, SYS_unlink
45c: 48c9 li a7,18
ecall
45e: 00000073 ecall
ret
462: 8082 ret
0000000000000464 <fstat>:
.global fstat
fstat:
li a7, SYS_fstat
464: 48a1 li a7,8
ecall
466: 00000073 ecall
ret
46a: 8082 ret
000000000000046c <link>:
.global link
link:
li a7, SYS_link
46c: 48cd li a7,19
ecall
46e: 00000073 ecall
ret
472: 8082 ret
0000000000000474 <mkdir>:
.global mkdir
mkdir:
li a7, SYS_mkdir
474: 48d1 li a7,20
ecall
476: 00000073 ecall
ret
47a: 8082 ret
000000000000047c <chdir>:
.global chdir
chdir:
li a7, SYS_chdir
47c: 48a5 li a7,9
ecall
47e: 00000073 ecall
ret
482: 8082 ret
0000000000000484 <dup>:
.global dup
dup:
li a7, SYS_dup
484: 48a9 li a7,10
ecall
486: 00000073 ecall
ret
48a: 8082 ret
000000000000048c <getpid>:
.global getpid
getpid:
li a7, SYS_getpid
48c: 48ad li a7,11
ecall
48e: 00000073 ecall
ret
492: 8082 ret
0000000000000494 <sbrk>:
.global sbrk
sbrk:
li a7, SYS_sbrk
494: 48b1 li a7,12
ecall
496: 00000073 ecall
ret
49a: 8082 ret
000000000000049c <sleep>:
.global sleep
sleep:
li a7, SYS_sleep
49c: 48b5 li a7,13
ecall
49e: 00000073 ecall
ret
4a2: 8082 ret
00000000000004a4 <uptime>:
.global uptime
uptime:
li a7, SYS_uptime
4a4: 48b9 li a7,14
ecall
4a6: 00000073 ecall
ret
4aa: 8082 ret
00000000000004ac <trace>:
.global trace
trace:
li a7, SYS_trace
4ac: 48d9 li a7,22
ecall
4ae: 00000073 ecall
ret
4b2: 8082 ret
00000000000004b4 <waitx>:
.global waitx
waitx:
li a7, SYS_waitx
4b4: 48dd li a7,23
ecall
4b6: 00000073 ecall
ret
4ba: 8082 ret
00000000000004bc <set_priority>:
.global set_priority
set_priority:
li a7, SYS_set_priority
4bc: 48e1 li a7,24
ecall
4be: 00000073 ecall
ret
4c2: 8082 ret
00000000000004c4 <putc>:
static char digits[] = "0123456789ABCDEF";
static void
putc(int fd, char c)
{
4c4: 1101 addi sp,sp,-32
4c6: ec06 sd ra,24(sp)
4c8: e822 sd s0,16(sp)
4ca: 1000 addi s0,sp,32
4cc: feb407a3 sb a1,-17(s0)
write(fd, &c, 1);
4d0: 4605 li a2,1
4d2: fef40593 addi a1,s0,-17
4d6: 00000097 auipc ra,0x0
4da: f56080e7 jalr -170(ra) # 42c <write>
}
4de: 60e2 ld ra,24(sp)
4e0: 6442 ld s0,16(sp)
4e2: 6105 addi sp,sp,32
4e4: 8082 ret
00000000000004e6 <printint>:
static void
printint(int fd, int xx, int base, int sgn)
{
4e6: 7139 addi sp,sp,-64
4e8: fc06 sd ra,56(sp)
4ea: f822 sd s0,48(sp)
4ec: f426 sd s1,40(sp)
4ee: f04a sd s2,32(sp)
4f0: ec4e sd s3,24(sp)
4f2: 0080 addi s0,sp,64
4f4: 84aa mv s1,a0
char buf[16];
int i, neg;
uint x;
neg = 0;
if(sgn && xx < 0){
4f6: c299 beqz a3,4fc <printint+0x16>
4f8: 0805c863 bltz a1,588 <printint+0xa2>
neg = 1;
x = -xx;
} else {
x = xx;
4fc: 2581 sext.w a1,a1
neg = 0;
4fe: 4881 li a7,0
500: fc040693 addi a3,s0,-64
}
i = 0;
504: 4701 li a4,0
do{
buf[i++] = digits[x % base];
506: 2601 sext.w a2,a2
508: 00000517 auipc a0,0x0
50c: 48850513 addi a0,a0,1160 # 990 <digits>
510: 883a mv a6,a4
512: 2705 addiw a4,a4,1
514: 02c5f7bb remuw a5,a1,a2
518: 1782 slli a5,a5,0x20
51a: 9381 srli a5,a5,0x20
51c: 97aa add a5,a5,a0
51e: 0007c783 lbu a5,0(a5)
522: 00f68023 sb a5,0(a3)
}while((x /= base) != 0);
526: 0005879b sext.w a5,a1
52a: 02c5d5bb divuw a1,a1,a2
52e: 0685 addi a3,a3,1
530: fec7f0e3 bgeu a5,a2,510 <printint+0x2a>
if(neg)
534: 00088b63 beqz a7,54a <printint+0x64>
buf[i++] = '-';
538: fd040793 addi a5,s0,-48
53c: 973e add a4,a4,a5
53e: 02d00793 li a5,45
542: fef70823 sb a5,-16(a4)
546: 0028071b addiw a4,a6,2
while(--i >= 0)
54a: 02e05863 blez a4,57a <printint+0x94>
54e: fc040793 addi a5,s0,-64
552: 00e78933 add s2,a5,a4
556: fff78993 addi s3,a5,-1
55a: 99ba add s3,s3,a4
55c: 377d addiw a4,a4,-1
55e: 1702 slli a4,a4,0x20
560: 9301 srli a4,a4,0x20
562: 40e989b3 sub s3,s3,a4
putc(fd, buf[i]);
566: fff94583 lbu a1,-1(s2)
56a: 8526 mv a0,s1
56c: 00000097 auipc ra,0x0
570: f58080e7 jalr -168(ra) # 4c4 <putc>
while(--i >= 0)
574: 197d addi s2,s2,-1
576: ff3918e3 bne s2,s3,566 <printint+0x80>
}
57a: 70e2 ld ra,56(sp)
57c: 7442 ld s0,48(sp)
57e: 74a2 ld s1,40(sp)
580: 7902 ld s2,32(sp)
582: 69e2 ld s3,24(sp)
584: 6121 addi sp,sp,64
586: 8082 ret
x = -xx;
588: 40b005bb negw a1,a1
neg = 1;
58c: 4885 li a7,1
x = -xx;
58e: bf8d j 500 <printint+0x1a>
0000000000000590 <vprintf>:
}
// Print to the given fd. Only understands %d, %x, %p, %s.
void
vprintf(int fd, const char *fmt, va_list ap)
{
590: 7119 addi sp,sp,-128
592: fc86 sd ra,120(sp)
594: f8a2 sd s0,112(sp)
596: f4a6 sd s1,104(sp)
598: f0ca sd s2,96(sp)
59a: ecce sd s3,88(sp)
59c: e8d2 sd s4,80(sp)
59e: e4d6 sd s5,72(sp)
5a0: e0da sd s6,64(sp)
5a2: fc5e sd s7,56(sp)
5a4: f862 sd s8,48(sp)
5a6: f466 sd s9,40(sp)
5a8: f06a sd s10,32(sp)
5aa: ec6e sd s11,24(sp)
5ac: 0100 addi s0,sp,128
char *s;
int c, i, state;
state = 0;
for(i = 0; fmt[i]; i++){
5ae: 0005c903 lbu s2,0(a1)
5b2: 18090f63 beqz s2,750 <vprintf+0x1c0>
5b6: 8aaa mv s5,a0
5b8: 8b32 mv s6,a2
5ba: 00158493 addi s1,a1,1
state = 0;
5be: 4981 li s3,0
if(c == '%'){
state = '%';
} else {
putc(fd, c);
}
} else if(state == '%'){
5c0: 02500a13 li s4,37
if(c == 'd'){
5c4: 06400c13 li s8,100
printint(fd, va_arg(ap, int), 10, 1);
} else if(c == 'l') {
5c8: 06c00c93 li s9,108
printint(fd, va_arg(ap, uint64), 10, 0);
} else if(c == 'x') {
5cc: 07800d13 li s10,120
printint(fd, va_arg(ap, int), 16, 0);
} else if(c == 'p') {
5d0: 07000d93 li s11,112
putc(fd, digits[x >> (sizeof(uint64) * 8 - 4)]);
5d4: 00000b97 auipc s7,0x0
5d8: 3bcb8b93 addi s7,s7,956 # 990 <digits>
5dc: a839 j 5fa <vprintf+0x6a>
putc(fd, c);
5de: 85ca mv a1,s2
5e0: 8556 mv a0,s5
5e2: 00000097 auipc ra,0x0
5e6: ee2080e7 jalr -286(ra) # 4c4 <putc>
5ea: a019 j 5f0 <vprintf+0x60>
} else if(state == '%'){
5ec: 01498f63 beq s3,s4,60a <vprintf+0x7a>
for(i = 0; fmt[i]; i++){
5f0: 0485 addi s1,s1,1
5f2: fff4c903 lbu s2,-1(s1)
5f6: 14090d63 beqz s2,750 <vprintf+0x1c0>
c = fmt[i] & 0xff;
5fa: 0009079b sext.w a5,s2
if(state == 0){
5fe: fe0997e3 bnez s3,5ec <vprintf+0x5c>
if(c == '%'){
602: fd479ee3 bne a5,s4,5de <vprintf+0x4e>
state = '%';
606: 89be mv s3,a5
608: b7e5 j 5f0 <vprintf+0x60>
if(c == 'd'){
60a: 05878063 beq a5,s8,64a <vprintf+0xba>
} else if(c == 'l') {
60e: 05978c63 beq a5,s9,666 <vprintf+0xd6>
} else if(c == 'x') {
612: 07a78863 beq a5,s10,682 <vprintf+0xf2>
} else if(c == 'p') {
616: 09b78463 beq a5,s11,69e <vprintf+0x10e>
printptr(fd, va_arg(ap, uint64));
} else if(c == 's'){
61a: 07300713 li a4,115
61e: 0ce78663 beq a5,a4,6ea <vprintf+0x15a>
s = "(null)";
while(*s != 0){
putc(fd, *s);
s++;
}
} else if(c == 'c'){
622: 06300713 li a4,99
626: 0ee78e63 beq a5,a4,722 <vprintf+0x192>
putc(fd, va_arg(ap, uint));
} else if(c == '%'){
62a: 11478863 beq a5,s4,73a <vprintf+0x1aa>
putc(fd, c);
} else {
// Unknown % sequence. Print it to draw attention.
putc(fd, '%');
62e: 85d2 mv a1,s4
630: 8556 mv a0,s5
632: 00000097 auipc ra,0x0
636: e92080e7 jalr -366(ra) # 4c4 <putc>
putc(fd, c);
63a: 85ca mv a1,s2
63c: 8556 mv a0,s5
63e: 00000097 auipc ra,0x0
642: e86080e7 jalr -378(ra) # 4c4 <putc>
}
state = 0;
646: 4981 li s3,0
648: b765 j 5f0 <vprintf+0x60>
printint(fd, va_arg(ap, int), 10, 1);
64a: 008b0913 addi s2,s6,8
64e: 4685 li a3,1
650: 4629 li a2,10
652: 000b2583 lw a1,0(s6)
656: 8556 mv a0,s5
658: 00000097 auipc ra,0x0
65c: e8e080e7 jalr -370(ra) # 4e6 <printint>
660: 8b4a mv s6,s2
state = 0;
662: 4981 li s3,0
664: b771 j 5f0 <vprintf+0x60>
printint(fd, va_arg(ap, uint64), 10, 0);
666: 008b0913 addi s2,s6,8
66a: 4681 li a3,0
66c: 4629 li a2,10
66e: 000b2583 lw a1,0(s6)
672: 8556 mv a0,s5
674: 00000097 auipc ra,0x0
678: e72080e7 jalr -398(ra) # 4e6 <printint>
67c: 8b4a mv s6,s2
state = 0;
67e: 4981 li s3,0
680: bf85 j 5f0 <vprintf+0x60>
printint(fd, va_arg(ap, int), 16, 0);
682: 008b0913 addi s2,s6,8
686: 4681 li a3,0
688: 4641 li a2,16
68a: 000b2583 lw a1,0(s6)
68e: 8556 mv a0,s5
690: 00000097 auipc ra,0x0
694: e56080e7 jalr -426(ra) # 4e6 <printint>
698: 8b4a mv s6,s2
state = 0;
69a: 4981 li s3,0
69c: bf91 j 5f0 <vprintf+0x60>
printptr(fd, va_arg(ap, uint64));
69e: 008b0793 addi a5,s6,8
6a2: f8f43423 sd a5,-120(s0)
6a6: 000b3983 ld s3,0(s6)
putc(fd, '0');
6aa: 03000593 li a1,48
6ae: 8556 mv a0,s5
6b0: 00000097 auipc ra,0x0
6b4: e14080e7 jalr -492(ra) # 4c4 <putc>
putc(fd, 'x');
6b8: 85ea mv a1,s10
6ba: 8556 mv a0,s5
6bc: 00000097 auipc ra,0x0
6c0: e08080e7 jalr -504(ra) # 4c4 <putc>
6c4: 4941 li s2,16
putc(fd, digits[x >> (sizeof(uint64) * 8 - 4)]);
6c6: 03c9d793 srli a5,s3,0x3c
6ca: 97de add a5,a5,s7
6cc: 0007c583 lbu a1,0(a5)
6d0: 8556 mv a0,s5
6d2: 00000097 auipc ra,0x0
6d6: df2080e7 jalr -526(ra) # 4c4 <putc>
for (i = 0; i < (sizeof(uint64) * 2); i++, x <<= 4)
6da: 0992 slli s3,s3,0x4
6dc: 397d addiw s2,s2,-1
6de: fe0914e3 bnez s2,6c6 <vprintf+0x136>
printptr(fd, va_arg(ap, uint64));
6e2: f8843b03 ld s6,-120(s0)
state = 0;
6e6: 4981 li s3,0
6e8: b721 j 5f0 <vprintf+0x60>
s = va_arg(ap, char*);
6ea: 008b0993 addi s3,s6,8
6ee: 000b3903 ld s2,0(s6)
if(s == 0)
6f2: 02090163 beqz s2,714 <vprintf+0x184>
while(*s != 0){
6f6: 00094583 lbu a1,0(s2)
6fa: c9a1 beqz a1,74a <vprintf+0x1ba>
putc(fd, *s);
6fc: 8556 mv a0,s5
6fe: 00000097 auipc ra,0x0
702: dc6080e7 jalr -570(ra) # 4c4 <putc>
s++;
706: 0905 addi s2,s2,1
while(*s != 0){
708: 00094583 lbu a1,0(s2)
70c: f9e5 bnez a1,6fc <vprintf+0x16c>
s = va_arg(ap, char*);
70e: 8b4e mv s6,s3
state = 0;
710: 4981 li s3,0
712: bdf9 j 5f0 <vprintf+0x60>
s = "(null)";
714: 00000917 auipc s2,0x0
718: 27490913 addi s2,s2,628 # 988 <malloc+0x12e>
while(*s != 0){
71c: 02800593 li a1,40
720: bff1 j 6fc <vprintf+0x16c>
putc(fd, va_arg(ap, uint));
722: 008b0913 addi s2,s6,8
726: 000b4583 lbu a1,0(s6)
72a: 8556 mv a0,s5
72c: 00000097 auipc ra,0x0
730: d98080e7 jalr -616(ra) # 4c4 <putc>
734: 8b4a mv s6,s2
state = 0;
736: 4981 li s3,0
738: bd65 j 5f0 <vprintf+0x60>
putc(fd, c);
73a: 85d2 mv a1,s4
73c: 8556 mv a0,s5
73e: 00000097 auipc ra,0x0
742: d86080e7 jalr -634(ra) # 4c4 <putc>
state = 0;
746: 4981 li s3,0
748: b565 j 5f0 <vprintf+0x60>
s = va_arg(ap, char*);
74a: 8b4e mv s6,s3
state = 0;
74c: 4981 li s3,0
74e: b54d j 5f0 <vprintf+0x60>
}
}
}
750: 70e6 ld ra,120(sp)
752: 7446 ld s0,112(sp)
754: 74a6 ld s1,104(sp)
756: 7906 ld s2,96(sp)
758: 69e6 ld s3,88(sp)
75a: 6a46 ld s4,80(sp)
75c: 6aa6 ld s5,72(sp)
75e: 6b06 ld s6,64(sp)
760: 7be2 ld s7,56(sp)
762: 7c42 ld s8,48(sp)
764: 7ca2 ld s9,40(sp)
766: 7d02 ld s10,32(sp)
768: 6de2 ld s11,24(sp)
76a: 6109 addi sp,sp,128
76c: 8082 ret
000000000000076e <fprintf>:
void
fprintf(int fd, const char *fmt, ...)
{
76e: 715d addi sp,sp,-80
770: ec06 sd ra,24(sp)
772: e822 sd s0,16(sp)
774: 1000 addi s0,sp,32
776: e010 sd a2,0(s0)
778: e414 sd a3,8(s0)
77a: e818 sd a4,16(s0)
77c: ec1c sd a5,24(s0)
77e: 03043023 sd a6,32(s0)
782: 03143423 sd a7,40(s0)
va_list ap;
va_start(ap, fmt);
786: fe843423 sd s0,-24(s0)
vprintf(fd, fmt, ap);
78a: 8622 mv a2,s0
78c: 00000097 auipc ra,0x0
790: e04080e7 jalr -508(ra) # 590 <vprintf>
}
794: 60e2 ld ra,24(sp)
796: 6442 ld s0,16(sp)
798: 6161 addi sp,sp,80
79a: 8082 ret
000000000000079c <printf>:
void
printf(const char *fmt, ...)
{
79c: 711d addi sp,sp,-96
79e: ec06 sd ra,24(sp)
7a0: e822 sd s0,16(sp)
7a2: 1000 addi s0,sp,32
7a4: e40c sd a1,8(s0)
7a6: e810 sd a2,16(s0)
7a8: ec14 sd a3,24(s0)
7aa: f018 sd a4,32(s0)
7ac: f41c sd a5,40(s0)
7ae: 03043823 sd a6,48(s0)
7b2: 03143c23 sd a7,56(s0)
va_list ap;
va_start(ap, fmt);
7b6: 00840613 addi a2,s0,8
7ba: fec43423 sd a2,-24(s0)
vprintf(1, fmt, ap);
7be: 85aa mv a1,a0
7c0: 4505 li a0,1
7c2: 00000097 auipc ra,0x0
7c6: dce080e7 jalr -562(ra) # 590 <vprintf>
}
7ca: 60e2 ld ra,24(sp)
7cc: 6442 ld s0,16(sp)
7ce: 6125 addi sp,sp,96
7d0: 8082 ret
00000000000007d2 <free>:
static Header base;
static Header *freep;
void
free(void *ap)
{
7d2: 1141 addi sp,sp,-16
7d4: e422 sd s0,8(sp)
7d6: 0800 addi s0,sp,16
Header *bp, *p;
bp = (Header*)ap - 1;
7d8: ff050693 addi a3,a0,-16
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
7dc: 00000797 auipc a5,0x0
7e0: 1cc7b783 ld a5,460(a5) # 9a8 <freep>
7e4: a805 j 814 <free+0x42>
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;
7e6: 4618 lw a4,8(a2)
7e8: 9db9 addw a1,a1,a4
7ea: feb52c23 sw a1,-8(a0)
bp->s.ptr = p->s.ptr->s.ptr;
7ee: 6398 ld a4,0(a5)
7f0: 6318 ld a4,0(a4)
7f2: fee53823 sd a4,-16(a0)
7f6: a091 j 83a <free+0x68>
} else
bp->s.ptr = p->s.ptr;
if(p + p->s.size == bp){
p->s.size += bp->s.size;
7f8: ff852703 lw a4,-8(a0)
7fc: 9e39 addw a2,a2,a4
7fe: c790 sw a2,8(a5)
p->s.ptr = bp->s.ptr;
800: ff053703 ld a4,-16(a0)
804: e398 sd a4,0(a5)
806: a099 j 84c <free+0x7a>
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
808: 6398 ld a4,0(a5)
80a: 00e7e463 bltu a5,a4,812 <free+0x40>
80e: 00e6ea63 bltu a3,a4,822 <free+0x50>
{
812: 87ba mv a5,a4
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
814: fed7fae3 bgeu a5,a3,808 <free+0x36>
818: 6398 ld a4,0(a5)
81a: 00e6e463 bltu a3,a4,822 <free+0x50>
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
81e: fee7eae3 bltu a5,a4,812 <free+0x40>
if(bp + bp->s.size == p->s.ptr){
822: ff852583 lw a1,-8(a0)
826: 6390 ld a2,0(a5)
828: 02059713 slli a4,a1,0x20
82c: 9301 srli a4,a4,0x20
82e: 0712 slli a4,a4,0x4
830: 9736 add a4,a4,a3
832: fae60ae3 beq a2,a4,7e6 <free+0x14>
bp->s.ptr = p->s.ptr;
836: fec53823 sd a2,-16(a0)
if(p + p->s.size == bp){
83a: 4790 lw a2,8(a5)
83c: 02061713 slli a4,a2,0x20
840: 9301 srli a4,a4,0x20
842: 0712 slli a4,a4,0x4
844: 973e add a4,a4,a5
846: fae689e3 beq a3,a4,7f8 <free+0x26>
} else
p->s.ptr = bp;
84a: e394 sd a3,0(a5)
freep = p;
84c: 00000717 auipc a4,0x0
850: 14f73e23 sd a5,348(a4) # 9a8 <freep>
}
854: 6422 ld s0,8(sp)
856: 0141 addi sp,sp,16
858: 8082 ret
000000000000085a <malloc>:
return freep;
}
void*
malloc(uint nbytes)
{
85a: 7139 addi sp,sp,-64
85c: fc06 sd ra,56(sp)
85e: f822 sd s0,48(sp)
860: f426 sd s1,40(sp)
862: f04a sd s2,32(sp)
864: ec4e sd s3,24(sp)
866: e852 sd s4,16(sp)
868: e456 sd s5,8(sp)
86a: e05a sd s6,0(sp)
86c: 0080 addi s0,sp,64
Header *p, *prevp;
uint nunits;
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
86e: 02051493 slli s1,a0,0x20
872: 9081 srli s1,s1,0x20
874: 04bd addi s1,s1,15
876: 8091 srli s1,s1,0x4
878: 0014899b addiw s3,s1,1
87c: 0485 addi s1,s1,1
if((prevp = freep) == 0){
87e: 00000517 auipc a0,0x0
882: 12a53503 ld a0,298(a0) # 9a8 <freep>
886: c515 beqz a0,8b2 <malloc+0x58>
base.s.ptr = freep = prevp = &base;
base.s.size = 0;
}
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
888: 611c ld a5,0(a0)
if(p->s.size >= nunits){
88a: 4798 lw a4,8(a5)
88c: 02977f63 bgeu a4,s1,8ca <malloc+0x70>
890: 8a4e mv s4,s3
892: 0009871b sext.w a4,s3
896: 6685 lui a3,0x1
898: 00d77363 bgeu a4,a3,89e <malloc+0x44>
89c: 6a05 lui s4,0x1
89e: 000a0b1b sext.w s6,s4
p = sbrk(nu * sizeof(Header));
8a2: 004a1a1b slliw s4,s4,0x4
p->s.size = nunits;
}
freep = prevp;
return (void*)(p + 1);
}
if(p == freep)
8a6: 00000917 auipc s2,0x0
8aa: 10290913 addi s2,s2,258 # 9a8 <freep>
if(p == (char*)-1)
8ae: 5afd li s5,-1
8b0: a88d j 922 <malloc+0xc8>
base.s.ptr = freep = prevp = &base;
8b2: 00000797 auipc a5,0x0
8b6: 2fe78793 addi a5,a5,766 # bb0 <base>
8ba: 00000717 auipc a4,0x0
8be: 0ef73723 sd a5,238(a4) # 9a8 <freep>
8c2: e39c sd a5,0(a5)
base.s.size = 0;
8c4: 0007a423 sw zero,8(a5)
if(p->s.size >= nunits){
8c8: b7e1 j 890 <malloc+0x36>
if(p->s.size == nunits)
8ca: 02e48b63 beq s1,a4,900 <malloc+0xa6>
p->s.size -= nunits;
8ce: 4137073b subw a4,a4,s3
8d2: c798 sw a4,8(a5)
p += p->s.size;
8d4: 1702 slli a4,a4,0x20
8d6: 9301 srli a4,a4,0x20
8d8: 0712 slli a4,a4,0x4
8da: 97ba add a5,a5,a4
p->s.size = nunits;
8dc: 0137a423 sw s3,8(a5)
freep = prevp;
8e0: 00000717 auipc a4,0x0
8e4: 0ca73423 sd a0,200(a4) # 9a8 <freep>
return (void*)(p + 1);
8e8: 01078513 addi a0,a5,16
if((p = morecore(nunits)) == 0)
return 0;
}
}
8ec: 70e2 ld ra,56(sp)
8ee: 7442 ld s0,48(sp)
8f0: 74a2 ld s1,40(sp)
8f2: 7902 ld s2,32(sp)
8f4: 69e2 ld s3,24(sp)
8f6: 6a42 ld s4,16(sp)
8f8: 6aa2 ld s5,8(sp)
8fa: 6b02 ld s6,0(sp)
8fc: 6121 addi sp,sp,64
8fe: 8082 ret
prevp->s.ptr = p->s.ptr;
900: 6398 ld a4,0(a5)
902: e118 sd a4,0(a0)
904: bff1 j 8e0 <malloc+0x86>
hp->s.size = nu;
906: 01652423 sw s6,8(a0)
free((void*)(hp + 1));
90a: 0541 addi a0,a0,16
90c: 00000097 auipc ra,0x0
910: ec6080e7 jalr -314(ra) # 7d2 <free>
return freep;
914: 00093503 ld a0,0(s2)
if((p = morecore(nunits)) == 0)
918: d971 beqz a0,8ec <malloc+0x92>
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
91a: 611c ld a5,0(a0)
if(p->s.size >= nunits){
91c: 4798 lw a4,8(a5)
91e: fa9776e3 bgeu a4,s1,8ca <malloc+0x70>
if(p == freep)
922: 00093703 ld a4,0(s2)
926: 853e mv a0,a5
928: fef719e3 bne a4,a5,91a <malloc+0xc0>
p = sbrk(nu * sizeof(Header));
92c: 8552 mv a0,s4
92e: 00000097 auipc ra,0x0
932: b66080e7 jalr -1178(ra) # 494 <sbrk>
if(p == (char*)-1)
936: fd5518e3 bne a0,s5,906 <malloc+0xac>
return 0;
93a: 4501 li a0,0
93c: bf45 j 8ec <malloc+0x92>
|
#include "pch.h"
#include "libCloudundancy/Components/SubPrograms/CopyFilesToMultipleFoldersSubProgram.h"
#include "libCloudundancy/ValueTypes/CloudundancyArgs.h"
#include "libCloudundancyTests/Components/FileSystem/MetalMock/CloudundancyFileCopierMock.h"
TESTS(CopyFileToFilesToMultipleFoldersSubProgramTests)
AFACT(DefaultConstructor_NewsComponents)
AFACT(Run_SetsArgs_CallsCopyFileToFilesAndFoldersToMultipleDestinationFolders_Returns0)
EVIDENCE
CopyFileToFilesToMultipleFoldersSubProgram _copyFilesToMultipleFoldersSubProgram;
// Base Constant Components
Utils::ConsoleMock* _consoleMock = nullptr;
// Constant Components
CloudundancyFileCopierMock* _cloudundancyFileCopierMock = nullptr;
STARTUP
{
// Base Constant Components
_copyFilesToMultipleFoldersSubProgram._console.reset(_consoleMock = new Utils::ConsoleMock);
// Constant Components
_copyFilesToMultipleFoldersSubProgram._cloudundancyFileCopier.reset(_cloudundancyFileCopierMock = new CloudundancyFileCopierMock);
}
TEST(DefaultConstructor_NewsComponents)
{
CopyFileToFilesToMultipleFoldersSubProgram copyFilesAndFoldersToMultipleFoldersSubProgram;
DELETE_TO_ASSERT_NEWED(copyFilesAndFoldersToMultipleFoldersSubProgram._cloudundancyFileCopier);
}
TEST(Run_SetsArgs_CallsCopyFileToFilesAndFoldersToMultipleDestinationFolders_Returns0)
{
_cloudundancyFileCopierMock->CopyFileToFilesAndFoldersToMultipleDestinationFoldersMock.Expect();
_consoleMock->WriteLineColorMock.Expect();
const CloudundancyArgs args = ZenUnit::Random<CloudundancyArgs>();
//
const int exitCode = _copyFilesToMultipleFoldersSubProgram.Run(args);
//
METALMOCKTHEN(_cloudundancyFileCopierMock->CopyFileToFilesAndFoldersToMultipleDestinationFoldersMock.CalledOnceWith(
args.iniFilePath, args.deleteDestinationFoldersFirst)).Then(
METALMOCKTHEN(_consoleMock->WriteLineColorMock.CalledOnceWith(
"\n[Cloudundancy] OverallBackupResult: Successfully copied all [SourceFilesAndFolders] to all [DestinationFolders]",
Color::Green)));
IS_ZERO(exitCode);
}
RUN_TESTS(CopyFileToFilesToMultipleFoldersSubProgramTests)
|
.code
GetCountAsm proc
mov rax, 0
ret
GetCountAsm endp
end |
;*****************************************************************************
;* x86inc.asm
;*****************************************************************************
;* Copyright (C) 2005-2008 x264 project
;*
;* Authors: Loren Merritt <lorenm@u.washington.edu>
;* Anton Mitrofanov <BugMaster@narod.ru>
;*
;* Permission to use, copy, modify, and/or 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.
;*****************************************************************************
; This is a header file for the x264ASM assembly language, which uses
; NASM/YASM syntax combined with a large number of macros to provide easy
; abstraction between different calling conventions (x86_32, win64, linux64).
; It also has various other useful features to simplify writing the kind of
; DSP functions that are most often used in x264.
; Unlike the rest of x264, this file is available under an ISC license, as it
; has significant usefulness outside of x264 and we want it to be available
; to the largest audience possible. Of course, if you modify it for your own
; purposes to add a new feature, we strongly encourage contributing a patch
; as this feature might be useful for others as well. Send patches or ideas
; to x264-devel@videolan.org .
%define program_name x264
%ifdef ARCH_X86_64
%ifidn __OUTPUT_FORMAT__,win32
%define WIN64
%else
%define UNIX64
%endif
%endif
%ifdef PREFIX
%define mangle(x) _ %+ x
%else
%define mangle(x) x
%endif
; FIXME: All of the 64bit asm functions that take a stride as an argument
; via register, assume that the high dword of that register is filled with 0.
; This is true in practice (since we never do any 64bit arithmetic on strides,
; and x264's strides are all positive), but is not guaranteed by the ABI.
; Name of the .rodata section.
; Kludge: Something on OS X fails to align .rodata even given an align attribute,
; so use a different read-only section.
%macro SECTION_RODATA 0-1 16
%ifidn __OUTPUT_FORMAT__,macho64
SECTION .text align=%1
%elifidn __OUTPUT_FORMAT__,macho
SECTION .text align=%1
fakegot:
%else
SECTION .rodata align=%1
%endif
%endmacro
%ifdef WIN64
%define PIC
%elifndef ARCH_X86_64
; x86_32 doesn't require PIC.
; Some distros prefer shared objects to be PIC, but nothing breaks if
; the code contains a few textrels, so we'll skip that complexity.
%undef PIC
%endif
%ifdef PIC
default rel
%endif
; Macros to eliminate most code duplication between x86_32 and x86_64:
; Currently this works only for leaf functions which load all their arguments
; into registers at the start, and make no other use of the stack. Luckily that
; covers most of x264's asm.
; PROLOGUE:
; %1 = number of arguments. loads them from stack if needed.
; %2 = number of registers used. pushes callee-saved regs if needed.
; %3 = number of xmm registers used. pushes callee-saved xmm regs if needed.
; %4 = list of names to define to registers
; PROLOGUE can also be invoked by adding the same options to cglobal
; e.g.
; cglobal foo, 2,3,0, dst, src, tmp
; declares a function (foo), taking two args (dst and src) and one local variable (tmp)
; TODO Some functions can use some args directly from the stack. If they're the
; last args then you can just not declare them, but if they're in the middle
; we need more flexible macro.
; RET:
; Pops anything that was pushed by PROLOGUE
; REP_RET:
; Same, but if it doesn't pop anything it becomes a 2-byte ret, for athlons
; which are slow when a normal ret follows a branch.
; registers:
; rN and rNq are the native-size register holding function argument N
; rNd, rNw, rNb are dword, word, and byte size
; rNm is the original location of arg N (a register or on the stack), dword
; rNmp is native size
%macro DECLARE_REG 6
%define r%1q %2
%define r%1d %3
%define r%1w %4
%define r%1b %5
%define r%1m %6
%ifid %6 ; i.e. it's a register
%define r%1mp %2
%elifdef ARCH_X86_64 ; memory
%define r%1mp qword %6
%else
%define r%1mp dword %6
%endif
%define r%1 %2
%endmacro
%macro DECLARE_REG_SIZE 2
%define r%1q r%1
%define e%1q r%1
%define r%1d e%1
%define e%1d e%1
%define r%1w %1
%define e%1w %1
%define r%1b %2
%define e%1b %2
%ifndef ARCH_X86_64
%define r%1 e%1
%endif
%endmacro
DECLARE_REG_SIZE ax, al
DECLARE_REG_SIZE bx, bl
DECLARE_REG_SIZE cx, cl
DECLARE_REG_SIZE dx, dl
DECLARE_REG_SIZE si, sil
DECLARE_REG_SIZE di, dil
DECLARE_REG_SIZE bp, bpl
; t# defines for when per-arch register allocation is more complex than just function arguments
%macro DECLARE_REG_TMP 1-*
%assign %%i 0
%rep %0
CAT_XDEFINE t, %%i, r%1
%assign %%i %%i+1
%rotate 1
%endrep
%endmacro
%macro DECLARE_REG_TMP_SIZE 0-*
%rep %0
%define t%1q t%1 %+ q
%define t%1d t%1 %+ d
%define t%1w t%1 %+ w
%define t%1b t%1 %+ b
%rotate 1
%endrep
%endmacro
DECLARE_REG_TMP_SIZE 0,1,2,3,4,5,6,7,8,9
%ifdef ARCH_X86_64
%define gprsize 8
%else
%define gprsize 4
%endif
%macro PUSH 1
push %1
%assign stack_offset stack_offset+gprsize
%endmacro
%macro POP 1
pop %1
%assign stack_offset stack_offset-gprsize
%endmacro
%macro SUB 2
sub %1, %2
%ifidn %1, rsp
%assign stack_offset stack_offset+(%2)
%endif
%endmacro
%macro ADD 2
add %1, %2
%ifidn %1, rsp
%assign stack_offset stack_offset-(%2)
%endif
%endmacro
%macro movifnidn 2
%ifnidn %1, %2
mov %1, %2
%endif
%endmacro
%macro movsxdifnidn 2
%ifnidn %1, %2
movsxd %1, %2
%endif
%endmacro
%macro ASSERT 1
%if (%1) == 0
%error assert failed
%endif
%endmacro
%macro DEFINE_ARGS 0-*
%ifdef n_arg_names
%assign %%i 0
%rep n_arg_names
CAT_UNDEF arg_name %+ %%i, q
CAT_UNDEF arg_name %+ %%i, d
CAT_UNDEF arg_name %+ %%i, w
CAT_UNDEF arg_name %+ %%i, b
CAT_UNDEF arg_name %+ %%i, m
CAT_UNDEF arg_name, %%i
%assign %%i %%i+1
%endrep
%endif
%assign %%i 0
%rep %0
%xdefine %1q r %+ %%i %+ q
%xdefine %1d r %+ %%i %+ d
%xdefine %1w r %+ %%i %+ w
%xdefine %1b r %+ %%i %+ b
%xdefine %1m r %+ %%i %+ m
CAT_XDEFINE arg_name, %%i, %1
%assign %%i %%i+1
%rotate 1
%endrep
%assign n_arg_names %%i
%endmacro
%ifdef WIN64 ; Windows x64 ;=================================================
DECLARE_REG 0, rcx, ecx, cx, cl, ecx
DECLARE_REG 1, rdx, edx, dx, dl, edx
DECLARE_REG 2, r8, r8d, r8w, r8b, r8d
DECLARE_REG 3, r9, r9d, r9w, r9b, r9d
DECLARE_REG 4, rdi, edi, di, dil, [rsp + stack_offset + 40]
DECLARE_REG 5, rsi, esi, si, sil, [rsp + stack_offset + 48]
DECLARE_REG 6, rax, eax, ax, al, [rsp + stack_offset + 56]
%define r7m [rsp + stack_offset + 64]
%define r8m [rsp + stack_offset + 72]
%macro LOAD_IF_USED 2 ; reg_id, number_of_args
%if %1 < %2
mov r%1, [rsp + stack_offset + 8 + %1*8]
%endif
%endmacro
%macro PROLOGUE 2-4+ 0 ; #args, #regs, #xmm_regs, arg_names...
ASSERT %2 >= %1
%assign regs_used %2
ASSERT regs_used <= 7
%if regs_used > 4
push r4
push r5
%assign stack_offset stack_offset+16
%endif
WIN64_SPILL_XMM %3
LOAD_IF_USED 4, %1
LOAD_IF_USED 5, %1
LOAD_IF_USED 6, %1
DEFINE_ARGS %4
%endmacro
%macro WIN64_SPILL_XMM 1
%assign xmm_regs_used %1
ASSERT xmm_regs_used <= 16
%if xmm_regs_used > 6
sub rsp, (xmm_regs_used-6)*16+16
%assign stack_offset stack_offset+(xmm_regs_used-6)*16+16
%assign %%i xmm_regs_used
%rep (xmm_regs_used-6)
%assign %%i %%i-1
movdqa [rsp + (%%i-6)*16+8], xmm %+ %%i
%endrep
%endif
%endmacro
%macro WIN64_RESTORE_XMM_INTERNAL 1
%if xmm_regs_used > 6
%assign %%i xmm_regs_used
%rep (xmm_regs_used-6)
%assign %%i %%i-1
movdqa xmm %+ %%i, [%1 + (%%i-6)*16+8]
%endrep
add %1, (xmm_regs_used-6)*16+16
%endif
%endmacro
%macro WIN64_RESTORE_XMM 1
WIN64_RESTORE_XMM_INTERNAL %1
%assign stack_offset stack_offset-(xmm_regs_used-6)*16+16
%assign xmm_regs_used 0
%endmacro
%macro RET 0
WIN64_RESTORE_XMM_INTERNAL rsp
%if regs_used > 4
pop r5
pop r4
%endif
ret
%endmacro
%macro REP_RET 0
%if regs_used > 4 || xmm_regs_used > 6
RET
%else
rep ret
%endif
%endmacro
%elifdef ARCH_X86_64 ; *nix x64 ;=============================================
DECLARE_REG 0, rdi, edi, di, dil, edi
DECLARE_REG 1, rsi, esi, si, sil, esi
DECLARE_REG 2, rdx, edx, dx, dl, edx
DECLARE_REG 3, rcx, ecx, cx, cl, ecx
DECLARE_REG 4, r8, r8d, r8w, r8b, r8d
DECLARE_REG 5, r9, r9d, r9w, r9b, r9d
DECLARE_REG 6, rax, eax, ax, al, [rsp + stack_offset + 8]
%define r7m [rsp + stack_offset + 16]
%define r8m [rsp + stack_offset + 24]
%macro LOAD_IF_USED 2 ; reg_id, number_of_args
%if %1 < %2
mov r%1, [rsp - 40 + %1*8]
%endif
%endmacro
%macro PROLOGUE 2-4+ ; #args, #regs, #xmm_regs, arg_names...
ASSERT %2 >= %1
ASSERT %2 <= 7
LOAD_IF_USED 6, %1
DEFINE_ARGS %4
%endmacro
%macro RET 0
ret
%endmacro
%macro REP_RET 0
rep ret
%endmacro
%else ; X86_32 ;==============================================================
DECLARE_REG 0, eax, eax, ax, al, [esp + stack_offset + 4]
DECLARE_REG 1, ecx, ecx, cx, cl, [esp + stack_offset + 8]
DECLARE_REG 2, edx, edx, dx, dl, [esp + stack_offset + 12]
DECLARE_REG 3, ebx, ebx, bx, bl, [esp + stack_offset + 16]
DECLARE_REG 4, esi, esi, si, null, [esp + stack_offset + 20]
DECLARE_REG 5, edi, edi, di, null, [esp + stack_offset + 24]
DECLARE_REG 6, ebp, ebp, bp, null, [esp + stack_offset + 28]
%define r7m [esp + stack_offset + 32]
%define r8m [esp + stack_offset + 36]
%define rsp esp
%macro PUSH_IF_USED 1 ; reg_id
%if %1 < regs_used
push r%1
%assign stack_offset stack_offset+4
%endif
%endmacro
%macro POP_IF_USED 1 ; reg_id
%if %1 < regs_used
pop r%1
%endif
%endmacro
%macro LOAD_IF_USED 2 ; reg_id, number_of_args
%if %1 < %2
mov r%1, [esp + stack_offset + 4 + %1*4]
%endif
%endmacro
%macro PROLOGUE 2-4+ ; #args, #regs, #xmm_regs, arg_names...
ASSERT %2 >= %1
%assign regs_used %2
ASSERT regs_used <= 7
PUSH_IF_USED 3
PUSH_IF_USED 4
PUSH_IF_USED 5
PUSH_IF_USED 6
LOAD_IF_USED 0, %1
LOAD_IF_USED 1, %1
LOAD_IF_USED 2, %1
LOAD_IF_USED 3, %1
LOAD_IF_USED 4, %1
LOAD_IF_USED 5, %1
LOAD_IF_USED 6, %1
DEFINE_ARGS %4
%endmacro
%macro RET 0
POP_IF_USED 6
POP_IF_USED 5
POP_IF_USED 4
POP_IF_USED 3
ret
%endmacro
%macro REP_RET 0
%if regs_used > 3
RET
%else
rep ret
%endif
%endmacro
%endif ;======================================================================
%ifndef WIN64
%macro WIN64_SPILL_XMM 1
%endmacro
%macro WIN64_RESTORE_XMM 1
%endmacro
%endif
;=============================================================================
; arch-independent part
;=============================================================================
%assign function_align 16
; Symbol prefix for C linkage
%macro cglobal 1-2+
%xdefine %1 mangle(program_name %+ _ %+ %1)
%xdefine %1.skip_prologue %1 %+ .skip_prologue
%ifidn __OUTPUT_FORMAT__,elf
global %1:function hidden
%else
global %1
%endif
align function_align
%1:
RESET_MM_PERMUTATION ; not really needed, but makes disassembly somewhat nicer
%assign stack_offset 0
%if %0 > 1
PROLOGUE %2
%endif
%endmacro
%macro cextern 1
%xdefine %1 mangle(program_name %+ _ %+ %1)
extern %1
%endmacro
;like cextern, but without the prefix
%macro cextern_naked 1
%xdefine %1 mangle(%1)
extern %1
%endmacro
%macro const 2+
%xdefine %1 mangle(program_name %+ _ %+ %1)
global %1
%1: %2
%endmacro
; This is needed for ELF, otherwise the GNU linker assumes the stack is
; executable by default.
%ifidn __OUTPUT_FORMAT__,elf
SECTION .note.GNU-stack noalloc noexec nowrite progbits
%endif
; merge mmx and sse*
%macro CAT_XDEFINE 3
%xdefine %1%2 %3
%endmacro
%macro CAT_UNDEF 2
%undef %1%2
%endmacro
%macro INIT_MMX 0
%define RESET_MM_PERMUTATION INIT_MMX
%define mmsize 8
%define num_mmregs 8
%define mova movq
%define movu movq
%define movh movd
%define movnta movntq
%assign %%i 0
%rep 8
CAT_XDEFINE m, %%i, mm %+ %%i
CAT_XDEFINE nmm, %%i, %%i
%assign %%i %%i+1
%endrep
%rep 8
CAT_UNDEF m, %%i
CAT_UNDEF nmm, %%i
%assign %%i %%i+1
%endrep
%endmacro
%macro INIT_XMM 0
%define RESET_MM_PERMUTATION INIT_XMM
%define mmsize 16
%define num_mmregs 8
%ifdef ARCH_X86_64
%define num_mmregs 16
%endif
%define mova movdqa
%define movu movdqu
%define movh movq
%define movnta movntdq
%assign %%i 0
%rep num_mmregs
CAT_XDEFINE m, %%i, xmm %+ %%i
CAT_XDEFINE nxmm, %%i, %%i
%assign %%i %%i+1
%endrep
%endmacro
INIT_MMX
; I often want to use macros that permute their arguments. e.g. there's no
; efficient way to implement butterfly or transpose or dct without swapping some
; arguments.
;
; I would like to not have to manually keep track of the permutations:
; If I insert a permutation in the middle of a function, it should automatically
; change everything that follows. For more complex macros I may also have multiple
; implementations, e.g. the SSE2 and SSSE3 versions may have different permutations.
;
; Hence these macros. Insert a PERMUTE or some SWAPs at the end of a macro that
; permutes its arguments. It's equivalent to exchanging the contents of the
; registers, except that this way you exchange the register names instead, so it
; doesn't cost any cycles.
%macro PERMUTE 2-* ; takes a list of pairs to swap
%rep %0/2
%xdefine tmp%2 m%2
%xdefine ntmp%2 nm%2
%rotate 2
%endrep
%rep %0/2
%xdefine m%1 tmp%2
%xdefine nm%1 ntmp%2
%undef tmp%2
%undef ntmp%2
%rotate 2
%endrep
%endmacro
%macro SWAP 2-* ; swaps a single chain (sometimes more concise than pairs)
%rep %0-1
%ifdef m%1
%xdefine tmp m%1
%xdefine m%1 m%2
%xdefine m%2 tmp
CAT_XDEFINE n, m%1, %1
CAT_XDEFINE n, m%2, %2
%else
; If we were called as "SWAP m0,m1" rather than "SWAP 0,1" infer the original numbers here.
; Be careful using this mode in nested macros though, as in some cases there may be
; other copies of m# that have already been dereferenced and don't get updated correctly.
%xdefine %%n1 n %+ %1
%xdefine %%n2 n %+ %2
%xdefine tmp m %+ %%n1
CAT_XDEFINE m, %%n1, m %+ %%n2
CAT_XDEFINE m, %%n2, tmp
CAT_XDEFINE n, m %+ %%n1, %%n1
CAT_XDEFINE n, m %+ %%n2, %%n2
%endif
%undef tmp
%rotate 1
%endrep
%endmacro
; If SAVE_MM_PERMUTATION is placed at the end of a function and given the
; function name, then any later calls to that function will automatically
; load the permutation, so values can be returned in mmregs.
%macro SAVE_MM_PERMUTATION 1 ; name to save as
%assign %%i 0
%rep num_mmregs
CAT_XDEFINE %1_m, %%i, m %+ %%i
%assign %%i %%i+1
%endrep
%endmacro
%macro LOAD_MM_PERMUTATION 1 ; name to load from
%assign %%i 0
%rep num_mmregs
CAT_XDEFINE m, %%i, %1_m %+ %%i
CAT_XDEFINE n, m %+ %%i, %%i
%assign %%i %%i+1
%endrep
%endmacro
%macro call 1
call %1
%ifdef %1_m0
LOAD_MM_PERMUTATION %1
%endif
%endmacro
; Substitutions that reduce instruction size but are functionally equivalent
%macro add 2
%ifnum %2
%if %2==128
sub %1, -128
%else
add %1, %2
%endif
%else
add %1, %2
%endif
%endmacro
%macro sub 2
%ifnum %2
%if %2==128
add %1, -128
%else
sub %1, %2
%endif
%else
sub %1, %2
%endif
%endmacro
|
/* mbedtls library by Mariano Goluboff
*/
#include "mbedtls.h"
int mbedtls_default_rng(void *data, unsigned char *output, size_t len)
{
while (len >= 4)
{
*((uint32_t *)output) = HAL_RNG_GetRandomNumber();
output += 4;
len -= 4;
}
while (len-- > 0)
{
*output++ = HAL_RNG_GetRandomNumber();
}
return 0;
}
static void mbedtls_debug(void *ctx, int level,
const char *file, int line,
const char *str)
{
Log.trace("%s:%04d: %s", file, line, str);
}
Mbedtls::Mbedtls()
{
}
int Mbedtls::init(const char *rootCaPem, const size_t rootCaPemSize,
const char *clientCertPem, const size_t clientCertPemSize,
const char *clientKeyPem, const size_t clientKeyPemSize)
{
// https://tls.mbed.org/module-level-design-ssl-tls
int ret;
mbedtls_ssl_init(&ssl);
mbedtls_ssl_config_init(&conf);
if ((ret = mbedtls_ssl_setup(&ssl, &conf)) != 0)
{
return ret;
}
mbedtls_ssl_conf_rng(&conf, mbedtls_default_rng, nullptr);
mbedtls_ssl_conf_dbg(&conf, mbedtls_debug, this);
//mbedtls_debug_set_threshold(3);
mbedtls_x509_crt_init(&cacert);
if ((ret = mbedtls_ssl_config_defaults(&conf, MBEDTLS_SSL_IS_CLIENT,
MBEDTLS_SSL_TRANSPORT_STREAM, MBEDTLS_SSL_PRESET_DEFAULT)) != 0)
{
return ret;
}
if ((ret = mbedtls_x509_crt_parse(&cacert, (const unsigned char *)rootCaPem, rootCaPemSize)) != 0)
{
Log.info(" failed\n ! mbedtls_x509_crt_parse returned -0x%x\n\n", -ret);
return ret;
}
mbedtls_ssl_conf_ca_chain(&conf, &cacert, nullptr);
if (clientCertPem != NULL && clientKeyPem != NULL) {
mbedtls_ssl_conf_own_cert(&conf, &clicert, &pkey);
}
mbedtls_ssl_conf_min_version(&conf, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3);
mbedtls_ssl_set_bio(&ssl, this, &Mbedtls::f_send, &Mbedtls::f_recv, nullptr);
_connected = false;
return 0;
}
int Mbedtls::f_send(void *ctx, const unsigned char *buf, size_t len)
{
Mbedtls *sock = (Mbedtls *)ctx;
if (!sock->client.status())
{
return -1;
}
int ret = sock->client.write(buf, len);
if (ret == 0)
{
return MBEDTLS_ERR_SSL_WANT_WRITE;
}
sock->client.flush();
return ret;
}
int Mbedtls::f_recv(void *ctx, unsigned char *buf, size_t len)
{
Mbedtls *sock = (Mbedtls *)ctx;
if (!sock->client.status())
{
return -1;
}
if (sock->client.available() == 0)
{
return MBEDTLS_ERR_SSL_WANT_READ;
}
int ret = sock->client.read(buf, len);
if (ret == 0)
{
return MBEDTLS_ERR_SSL_WANT_READ;
}
return ret;
}
void Mbedtls::close()
{
mbedtls_x509_crt_free(&cacert);
//mbedtls_x509_crt_free(&clicert);
//mbedtls_pk_free(&pkey);
mbedtls_ssl_config_free(&conf);
mbedtls_ssl_free(&ssl);
client.stop();
_connected = false;
};
int Mbedtls::connect(char *domain, uint16_t port)
{
int ret;
if (!client.connect(domain, port))
{
Log.info("Could not connect to server : %s", domain);
return -1;
}
if ((ret = mbedtls_ssl_set_hostname(&ssl, domain)) != 0)
{
return ret;
}
return handshake();
}
int Mbedtls::connect(uint8_t *ip, uint16_t port)
{
int ret;
char buffer[16];
sprintf(buffer, "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
if (!client.connect(ip, port))
{
return -1;
}
if ((ret = mbedtls_ssl_set_hostname(&ssl, buffer)) != 0)
{
return ret;
}
return handshake();
}
int Mbedtls::handshake()
{
int ret = -1;
do
{
while (ssl.state != MBEDTLS_SSL_HANDSHAKE_OVER)
{
ret = mbedtls_ssl_handshake_client_step(&ssl);
if (ret != 0)
break;
}
} while (ret == MBEDTLS_ERR_SSL_WANT_READ || ret == MBEDTLS_ERR_SSL_WANT_WRITE);
mbedtls_x509_crt_free(&cacert);
//mbedtls_x509_crt_free(&clicert);
//mbedtls_pk_free(&pkey);
if (ssl.state == MBEDTLS_SSL_HANDSHAKE_OVER)
{
_connected = true;
return 0;
}
return ret;
}
int Mbedtls::write(unsigned char *buf, size_t len, uint16_t timeout)
{
if (!_connected) return -1;
long int _timeout = millis();
size_t offset = 0;
int ret;
do
{
ret = mbedtls_ssl_write(&ssl, buf+offset, len-offset);
if (ret <= 0)
{
switch (ret)
{
case MBEDTLS_ERR_SSL_WANT_READ:
case MBEDTLS_ERR_SSL_WANT_WRITE:
case MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS:
case MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS:
delay(100);
break;
default:
close();
}
} else {
offset+=ret;
_timeout = millis();
}
} while ((ret > 0 && offset < len) ||
((ret == MBEDTLS_ERR_SSL_WANT_READ ||
ret == MBEDTLS_ERR_SSL_WANT_WRITE ||
ret == MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS ||
ret == MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS) &&
(millis() - _timeout) < timeout));
return ret;
}
int Mbedtls::read(unsigned char *buf, size_t len, uint16_t timeout)
{
if (!_connected) return -1;
long int _timeout = millis();
size_t offset = 0;
int ret;
do
{
ret = mbedtls_ssl_read(&ssl, buf+offset, len-offset);
if (ret <= 0)
{
switch (ret)
{
case MBEDTLS_ERR_SSL_WANT_READ:
case MBEDTLS_ERR_SSL_WANT_WRITE:
case MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS:
case MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS:
delay(100);
break;
case MBEDTLS_ERR_SSL_CLIENT_RECONNECT: // This can only happen server-side
default:
close();
}
} else {
offset+=ret;
_timeout = millis();
}
} while (
( ret > 0 && offset < len) ||
((ret == MBEDTLS_ERR_SSL_WANT_READ ||
ret == MBEDTLS_ERR_SSL_WANT_WRITE ||
ret == MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS ||
ret == MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS) &&
(millis() - _timeout) < timeout )
);
return (offset > 0) ? offset : ret;
} |
/* We simply call the root header file "App.h", giving you uWS::App and uWS::SSLApp */
#include "App.h"
/* This is a simple WebSocket echo server example.
* You may compile it with "WITH_OPENSSL=1 make" or with "make" */
int main() {
/* ws->getUserData returns one of these */
struct PerSocketData {
/* Fill with user data */
};
/* Keep in mind that uWS::SSLApp({options}) is the same as uWS::App() when compiled without SSL support.
* You may swap to using uWS:App() if you don't need SSL */
uWS::SSLApp({
/* There are example certificates in uWebSockets.js repo */
.key_file_name = "../misc/key.pem",
.cert_file_name = "../misc/cert.pem",
.passphrase = "1234"
}).ws<PerSocketData>("/*", {
/* Settings */
.compression = uWS::DEDICATED_COMPRESSOR_4KB,
.maxPayloadLength = 100 * 1024 * 1024,
.idleTimeout = 16,
.maxBackpressure = 100 * 1024 * 1024,
.closeOnBackpressureLimit = false,
.resetIdleTimeoutOnSend = false,
.sendPingsAutomatically = true,
/* Handlers */
.upgrade = nullptr,
.open = [](auto */*ws*/) {
/* Open event here, you may access ws->getUserData() which points to a PerSocketData struct */
},
.message = [](auto *ws, std::string_view message, uWS::OpCode opCode) {
ws->send(message, opCode, true);
},
.drain = [](auto */*ws*/) {
/* Check ws->getBufferedAmount() here */
},
.ping = [](auto */*ws*/, std::string_view) {
/* Not implemented yet */
},
.pong = [](auto */*ws*/, std::string_view) {
/* Not implemented yet */
},
.close = [](auto */*ws*/, int /*code*/, std::string_view /*message*/) {
/* You may access ws->getUserData() here */
}
}).listen(9001, [](auto *listen_socket) {
if (listen_socket) {
std::cout << "Listening on port " << 9001 << std::endl;
}
}).run();
}
|
; ===============================================================
; Jan 2014
; ===============================================================
;
; void clearerr_unlocked(FILE *stream)
;
; Clear the EOF and error indicators for the stream.
;
; ===============================================================
INCLUDE "config_private.inc"
SECTION code_clib
SECTION code_stdio
PUBLIC asm_clearerr_unlocked
PUBLIC asm1_clearerr_unlocked
EXTERN error_znc
asm_clearerr_unlocked:
; enter : ix = FILE *
;
; exit : ix = FILE *
;
; success
;
; hl = 0
; carry reset
;
; fail if lock could not be acquired
;
; hl = -1
; carry set, errno set
;
; uses : af, hl
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
IF __CLIB_OPT_STDIO & $01
EXTERN __stdio_verify_valid
call __stdio_verify_valid
ret c
ENDIF
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
asm1_clearerr_unlocked:
ld a,(ix+3)
and $e7 ; clear eof and err bits
ld (ix+3),a
jp error_znc
|
#include "p16f873.inc"
c1 equ 0x20 ; for delays
c2 equ 0x21 ; for delays
LCDTemp equ 0x22 ; Yo keep LCD data tempararily
LCDPORT equ PORTB
LCDTRIS equ TRISB
button_pressed equ 0x25 ; to store the pressed button
KEYPORT equ PORTC
KEYTRIS equ TRISC
org 0x00
goto Main
Main:
call LCD_Init
call Key_Init
movlw 'E'
call LCD_char
movlw 'N'
call LCD_char
movlw 'T'
call LCD_char
movlw 'E'
call LCD_char
movlw 'R'
call LCD_char
movlw ' '
call LCD_char
movlw 'P'
call LCD_char
movlw 'A'
call LCD_char
movlw 'S'
call LCD_char
movlw 'S'
call LCD_char
movlw 'W'
call LCD_char
movlw 'O'
call LCD_char
movlw 'R'
call LCD_char
movlw 'D'
call LCD_char
movlw b'11000000' ;Goto 2nd row
call LCD_Ins
movlw b'00001111' ; Turn on Display/Cursor
call LCD_Ins
;call Delay
;movlw b'00000001' ; Clear display
;call LCD_Ins
l
call Key_Check
movf button_pressed,0
call LCD_char
call Delay5
goto l
;LCD routines...........
LCD_Init: ; initialize LED to 4 bit mode
bsf STATUS, 5 ; select bank 1
movlw b'00000000' ; LCDPORT Outputs
movwf LCDTRIS ; Change PortB to output
bcf STATUS, 5 ; select bank 0
call Delay5 ; Wait 15 msecs
call Delay5
call Delay5
movlw b'00110000' ; Send the Reset Instruction
movwf LCDPORT
call Pulse_e ; Pulse LCD_E
call Delay5 ; Delay 5ms
call Pulse_e ; Pulse LCD_E
call Delay2 ; Delay of 2ms
call Pulse_e ; Pulse LCD_E
call Delay2 ; Delay of 2ms
movlw 0x020 ; Send the Data Length Specification
movwf LCDPORT
call Pulse_e ; Pulse LCD_E
call Delay2 ; Delay of 2ms
movlw b'00101000' ; Set Interface Length
call LCD_Ins
movlw b'00010000' ; Turn Off Display
call LCD_Ins
movlw b'00000001' ; Clear Display RAM
call LCD_Ins
movlw b'00000110' ; Set Cursor Movement
call LCD_Ins
movlw b'00001100' ; Turn on Display/Cursor
call LCD_Ins
movlw b'00000001' ; Clear LCD
call LCD_Ins
return ;
LCD_Ins: ;Send the Instruction to the LCD
movwf LCDTemp ; Save the Value
andlw b'11110000' ; High Nibble first
movwf LCDPORT
bcf LCDPORT,2
call Pulse_e
swapf LCDTemp, 0 ; Low Nibble Second
andlw b'11110000'
movwf LCDPORT
bcf LCDPORT,2
call Pulse_e
call Delay2 ; wait 2 ms
return ;
LCD_char: ; Send the Character to the LCD
movwf LCDTemp ; Save the Value
andlw 0xF0 ; High Nibble first
movwf LCDPORT
bsf LCDPORT,2
call Pulse_e ;
swapf LCDTemp, 0 ; Low Nibble Second
andlw 0xF0
movwf LCDPORT
bsf LCDPORT,2
call Pulse_e
call Delay2
nop
return
Pulse_e: ;LCD Enable pulse to write data from LCDPORT into LCD module.
bsf LCDPORT,3
nop
bcf LCDPORT,3
nop
return
;Keypad routines.............
Key_Init: ; initalize keypad
bsf STATUS,5 ;select bank 1
movlw b'11110000' ;0-4 outputs,5-7 inputs.
movwf KEYTRIS
bcf STATUS,5 ;select bank0
clrf button_pressed ;clear the button
return
Key_Check: ; check what button has been pressed
movlw 'X'
movwf button_pressed
bsf KEYPORT, 0 ; scan the first column of keys
btfsc KEYPORT, 4 ;
movlw '7' ; 7 is pressed.
btfsc KEYPORT, 5 ;
movlw '4' ; 4 is pressed.
btfsc KEYPORT, 6 ;
movlw '1' ; 1 is pressed.
btfsc KEYPORT, 7 ;
movlw '*' ; * is pressed.
bcf KEYPORT, 0 ; take first column low.
bsf KEYPORT, 1 ; scan the second column of keys
btfsc KEYPORT, 4 ;
movlw '8' ; 8 is pressed.
btfsc KEYPORT, 5 ;
movlw '5' ; 5 is pressed.
btfsc KEYPORT, 6 ;
movlw '2' ; 2 is pressed.
btfsc KEYPORT, 7 ;
movlw '0' ; 0 is pressed.
bcf KEYPORT, 1 ; take second column low.
bsf KEYPORT, 2 ; scan the third column of keys
btfsc KEYPORT, 4 ;
movlw '9' ; 9 is pressed.
btfsc KEYPORT, 5 ;
movlw '6' ; 6 is pressed.
btfsc KEYPORT, 6 ;
movlw '3' ; 3 is pressed.
btfsc KEYPORT, 7 ;
movlw '#' ; 1 is pressed.
bcf KEYPORT, 2 ; take rhird column low.
bsf KEYPORT, 3 ; scan the last column of keys
btfsc KEYPORT, 4 ;
movlw 'A' ; A is pressed.
btfsc KEYPORT, 5 ;
movlw 'B' ; B is pressed.
btfsc KEYPORT, 6 ;
movlw 'C' ; C is pressed.
btfsc KEYPORT, 7 ;
movlw 'D' ; D is pressed.
bcf KEYPORT, 3 ; take last column low.
movwf button_pressed
movlw 'X'
subwf button_pressed,0
btfsc STATUS,Z
goto Key_Check
;
return
; Delay routines........
Delay5: ;5ms
movlw d'2'
movwf c1
goto Delay
Delay: ;0.7s
decfsz c1,1
goto Delay
decfsz c2,1
goto Delay
return
Delay2: ;2ms
decfsz c1,1
goto Delay2
return
end |
#include <iterator>
#include "MultiPaneSpectralSample.hpp"
#include "MultiPaneSampleData.hpp"
#include "WCESpectralAveraging.hpp"
#include "WCECommon.hpp"
using namespace SpectralAveraging;
using namespace FenestrationCommon;
namespace MultiLayerOptics {
CMultiPaneSpectralSample::CMultiPaneSpectralSample( const std::shared_ptr< CSpectralSampleData >& t_SampleData,
const std::shared_ptr< CSeries >& t_SourceData ) : CSpectralSample( t_SampleData, t_SourceData ) {
}
double CMultiPaneSpectralSample::getLayerAbsorbedEnergy( double const minLambda, double const maxLambda,
size_t const Index ) {
double aEnergy = 0;
calculateState();
if ( Index > m_AbsorbedLayersSource.size() ) {
throw std::runtime_error( "Index for glazing layer absorptance is out of range." );
}
aEnergy = m_AbsorbedLayersSource[ Index - 1 ]->sum( minLambda, maxLambda );
return aEnergy;
}
double CMultiPaneSpectralSample::getLayerAbsorptance( double const minLambda, double const maxLambda,
size_t const Index ) {
calculateState();
double absorbedEnergy = getLayerAbsorbedEnergy( minLambda, maxLambda, Index );
double incomingEnergy = m_IncomingSource->sum( minLambda, maxLambda );
return absorbedEnergy / incomingEnergy;
}
void CMultiPaneSpectralSample::calculateProperties() {
if ( !m_StateCalculated ) {
CSpectralSample::calculateProperties();
if ( std::dynamic_pointer_cast< CMultiPaneSampleData >( m_SampleData ) != NULL ) {
std::shared_ptr< CMultiPaneSampleData > aSample = std::dynamic_pointer_cast< CMultiPaneSampleData >( m_SampleData );
size_t numOfLayers = aSample->numberOfLayers();
for ( size_t i = 0; i < numOfLayers; ++i ) {
std::shared_ptr< CSeries > layerAbsorbed = aSample->getLayerAbsorptances( i + 1 );
integrateAndAppendAbsorptances( layerAbsorbed );
}
}
else {
// Perspective is always from front side when using in MultiLayerOptics. Flipping flag should be used
// when putting layer in IGU
std::shared_ptr< CSeries > layerAbsorbed = m_SampleData->properties( SampleData::AbsF );
integrateAndAppendAbsorptances( layerAbsorbed );
}
m_StateCalculated = true;
}
}
void CMultiPaneSpectralSample::integrateAndAppendAbsorptances( const std::shared_ptr< CSeries >& t_Absorptances ) {
std::shared_ptr< CSeries > aAbs = t_Absorptances;
if ( m_WavelengthSet != WavelengthSet::Data ) {
aAbs = aAbs->interpolate( m_Wavelengths );
}
aAbs = aAbs->mMult( *m_IncomingSource );
aAbs = aAbs->integrate( m_IntegrationType, m_NormalizationCoefficient );
m_AbsorbedLayersSource.push_back( aAbs );
}
void CMultiPaneSpectralSample::reset() {
CSpectralSample::reset();
m_AbsorbedLayersSource.clear();
}
}
|
_kill: file format elf32-i386
Disassembly of section .text:
00000000 <main>:
#include "stat.h"
#include "user.h"
int
main(int argc, char **argv)
{
0: f3 0f 1e fb endbr32
4: 8d 4c 24 04 lea 0x4(%esp),%ecx
8: 83 e4 f0 and $0xfffffff0,%esp
b: ff 71 fc pushl -0x4(%ecx)
e: 55 push %ebp
f: 89 e5 mov %esp,%ebp
11: 56 push %esi
12: 53 push %ebx
13: 51 push %ecx
14: 83 ec 0c sub $0xc,%esp
17: 8b 01 mov (%ecx),%eax
19: 8b 51 04 mov 0x4(%ecx),%edx
int i;
if(argc < 2){
1c: 83 f8 01 cmp $0x1,%eax
1f: 7e 30 jle 51 <main+0x51>
21: 8d 5a 04 lea 0x4(%edx),%ebx
24: 8d 34 82 lea (%edx,%eax,4),%esi
27: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
2e: 66 90 xchg %ax,%ax
printf(2, "usage: kill pid...\n");
exit();
}
for(i=1; i<argc; i++)
kill(atoi(argv[i]));
30: 83 ec 0c sub $0xc,%esp
33: ff 33 pushl (%ebx)
35: 83 c3 04 add $0x4,%ebx
38: e8 23 02 00 00 call 260 <atoi>
3d: 89 04 24 mov %eax,(%esp)
40: e8 be 02 00 00 call 303 <kill>
for(i=1; i<argc; i++)
45: 83 c4 10 add $0x10,%esp
48: 39 f3 cmp %esi,%ebx
4a: 75 e4 jne 30 <main+0x30>
exit();
4c: e8 82 02 00 00 call 2d3 <exit>
printf(2, "usage: kill pid...\n");
51: 50 push %eax
52: 50 push %eax
53: 68 a8 07 00 00 push $0x7a8
58: 6a 02 push $0x2
5a: e8 e1 03 00 00 call 440 <printf>
exit();
5f: e8 6f 02 00 00 call 2d3 <exit>
64: 66 90 xchg %ax,%ax
66: 66 90 xchg %ax,%ax
68: 66 90 xchg %ax,%ax
6a: 66 90 xchg %ax,%ax
6c: 66 90 xchg %ax,%ax
6e: 66 90 xchg %ax,%ax
00000070 <strcpy>:
#include "user.h"
#include "x86.h"
char*
strcpy(char *s, const char *t)
{
70: f3 0f 1e fb endbr32
74: 55 push %ebp
char *os;
os = s;
while((*s++ = *t++) != 0)
75: 31 c0 xor %eax,%eax
{
77: 89 e5 mov %esp,%ebp
79: 53 push %ebx
7a: 8b 4d 08 mov 0x8(%ebp),%ecx
7d: 8b 5d 0c mov 0xc(%ebp),%ebx
while((*s++ = *t++) != 0)
80: 0f b6 14 03 movzbl (%ebx,%eax,1),%edx
84: 88 14 01 mov %dl,(%ecx,%eax,1)
87: 83 c0 01 add $0x1,%eax
8a: 84 d2 test %dl,%dl
8c: 75 f2 jne 80 <strcpy+0x10>
;
return os;
}
8e: 89 c8 mov %ecx,%eax
90: 5b pop %ebx
91: 5d pop %ebp
92: c3 ret
93: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
9a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
000000a0 <strcmp>:
int
strcmp(const char *p, const char *q)
{
a0: f3 0f 1e fb endbr32
a4: 55 push %ebp
a5: 89 e5 mov %esp,%ebp
a7: 53 push %ebx
a8: 8b 4d 08 mov 0x8(%ebp),%ecx
ab: 8b 55 0c mov 0xc(%ebp),%edx
while(*p && *p == *q)
ae: 0f b6 01 movzbl (%ecx),%eax
b1: 0f b6 1a movzbl (%edx),%ebx
b4: 84 c0 test %al,%al
b6: 75 19 jne d1 <strcmp+0x31>
b8: eb 26 jmp e0 <strcmp+0x40>
ba: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
c0: 0f b6 41 01 movzbl 0x1(%ecx),%eax
p++, q++;
c4: 83 c1 01 add $0x1,%ecx
c7: 83 c2 01 add $0x1,%edx
while(*p && *p == *q)
ca: 0f b6 1a movzbl (%edx),%ebx
cd: 84 c0 test %al,%al
cf: 74 0f je e0 <strcmp+0x40>
d1: 38 d8 cmp %bl,%al
d3: 74 eb je c0 <strcmp+0x20>
return (uchar)*p - (uchar)*q;
d5: 29 d8 sub %ebx,%eax
}
d7: 5b pop %ebx
d8: 5d pop %ebp
d9: c3 ret
da: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
e0: 31 c0 xor %eax,%eax
return (uchar)*p - (uchar)*q;
e2: 29 d8 sub %ebx,%eax
}
e4: 5b pop %ebx
e5: 5d pop %ebp
e6: c3 ret
e7: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
ee: 66 90 xchg %ax,%ax
000000f0 <strlen>:
uint
strlen(const char *s)
{
f0: f3 0f 1e fb endbr32
f4: 55 push %ebp
f5: 89 e5 mov %esp,%ebp
f7: 8b 55 08 mov 0x8(%ebp),%edx
int n;
for(n = 0; s[n]; n++)
fa: 80 3a 00 cmpb $0x0,(%edx)
fd: 74 21 je 120 <strlen+0x30>
ff: 31 c0 xor %eax,%eax
101: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
108: 83 c0 01 add $0x1,%eax
10b: 80 3c 02 00 cmpb $0x0,(%edx,%eax,1)
10f: 89 c1 mov %eax,%ecx
111: 75 f5 jne 108 <strlen+0x18>
;
return n;
}
113: 89 c8 mov %ecx,%eax
115: 5d pop %ebp
116: c3 ret
117: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
11e: 66 90 xchg %ax,%ax
for(n = 0; s[n]; n++)
120: 31 c9 xor %ecx,%ecx
}
122: 5d pop %ebp
123: 89 c8 mov %ecx,%eax
125: c3 ret
126: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
12d: 8d 76 00 lea 0x0(%esi),%esi
00000130 <memset>:
void*
memset(void *dst, int c, uint n)
{
130: f3 0f 1e fb endbr32
134: 55 push %ebp
135: 89 e5 mov %esp,%ebp
137: 57 push %edi
138: 8b 55 08 mov 0x8(%ebp),%edx
}
static inline void
stosb(void *addr, int data, int cnt)
{
asm volatile("cld; rep stosb" :
13b: 8b 4d 10 mov 0x10(%ebp),%ecx
13e: 8b 45 0c mov 0xc(%ebp),%eax
141: 89 d7 mov %edx,%edi
143: fc cld
144: f3 aa rep stos %al,%es:(%edi)
stosb(dst, c, n);
return dst;
}
146: 89 d0 mov %edx,%eax
148: 5f pop %edi
149: 5d pop %ebp
14a: c3 ret
14b: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
14f: 90 nop
00000150 <strchr>:
char*
strchr(const char *s, char c)
{
150: f3 0f 1e fb endbr32
154: 55 push %ebp
155: 89 e5 mov %esp,%ebp
157: 8b 45 08 mov 0x8(%ebp),%eax
15a: 0f b6 4d 0c movzbl 0xc(%ebp),%ecx
for(; *s; s++)
15e: 0f b6 10 movzbl (%eax),%edx
161: 84 d2 test %dl,%dl
163: 75 16 jne 17b <strchr+0x2b>
165: eb 21 jmp 188 <strchr+0x38>
167: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
16e: 66 90 xchg %ax,%ax
170: 0f b6 50 01 movzbl 0x1(%eax),%edx
174: 83 c0 01 add $0x1,%eax
177: 84 d2 test %dl,%dl
179: 74 0d je 188 <strchr+0x38>
if(*s == c)
17b: 38 d1 cmp %dl,%cl
17d: 75 f1 jne 170 <strchr+0x20>
return (char*)s;
return 0;
}
17f: 5d pop %ebp
180: c3 ret
181: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
return 0;
188: 31 c0 xor %eax,%eax
}
18a: 5d pop %ebp
18b: c3 ret
18c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
00000190 <gets>:
char*
gets(char *buf, int max)
{
190: f3 0f 1e fb endbr32
194: 55 push %ebp
195: 89 e5 mov %esp,%ebp
197: 57 push %edi
198: 56 push %esi
int i, cc;
char c;
for(i=0; i+1 < max; ){
199: 31 f6 xor %esi,%esi
{
19b: 53 push %ebx
19c: 89 f3 mov %esi,%ebx
19e: 83 ec 1c sub $0x1c,%esp
1a1: 8b 7d 08 mov 0x8(%ebp),%edi
for(i=0; i+1 < max; ){
1a4: eb 33 jmp 1d9 <gets+0x49>
1a6: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
1ad: 8d 76 00 lea 0x0(%esi),%esi
cc = read(0, &c, 1);
1b0: 83 ec 04 sub $0x4,%esp
1b3: 8d 45 e7 lea -0x19(%ebp),%eax
1b6: 6a 01 push $0x1
1b8: 50 push %eax
1b9: 6a 00 push $0x0
1bb: e8 2b 01 00 00 call 2eb <read>
if(cc < 1)
1c0: 83 c4 10 add $0x10,%esp
1c3: 85 c0 test %eax,%eax
1c5: 7e 1c jle 1e3 <gets+0x53>
break;
buf[i++] = c;
1c7: 0f b6 45 e7 movzbl -0x19(%ebp),%eax
1cb: 83 c7 01 add $0x1,%edi
1ce: 88 47 ff mov %al,-0x1(%edi)
if(c == '\n' || c == '\r')
1d1: 3c 0a cmp $0xa,%al
1d3: 74 23 je 1f8 <gets+0x68>
1d5: 3c 0d cmp $0xd,%al
1d7: 74 1f je 1f8 <gets+0x68>
for(i=0; i+1 < max; ){
1d9: 83 c3 01 add $0x1,%ebx
1dc: 89 fe mov %edi,%esi
1de: 3b 5d 0c cmp 0xc(%ebp),%ebx
1e1: 7c cd jl 1b0 <gets+0x20>
1e3: 89 f3 mov %esi,%ebx
break;
}
buf[i] = '\0';
return buf;
}
1e5: 8b 45 08 mov 0x8(%ebp),%eax
buf[i] = '\0';
1e8: c6 03 00 movb $0x0,(%ebx)
}
1eb: 8d 65 f4 lea -0xc(%ebp),%esp
1ee: 5b pop %ebx
1ef: 5e pop %esi
1f0: 5f pop %edi
1f1: 5d pop %ebp
1f2: c3 ret
1f3: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
1f7: 90 nop
1f8: 8b 75 08 mov 0x8(%ebp),%esi
1fb: 8b 45 08 mov 0x8(%ebp),%eax
1fe: 01 de add %ebx,%esi
200: 89 f3 mov %esi,%ebx
buf[i] = '\0';
202: c6 03 00 movb $0x0,(%ebx)
}
205: 8d 65 f4 lea -0xc(%ebp),%esp
208: 5b pop %ebx
209: 5e pop %esi
20a: 5f pop %edi
20b: 5d pop %ebp
20c: c3 ret
20d: 8d 76 00 lea 0x0(%esi),%esi
00000210 <stat>:
int
stat(const char *n, struct stat *st)
{
210: f3 0f 1e fb endbr32
214: 55 push %ebp
215: 89 e5 mov %esp,%ebp
217: 56 push %esi
218: 53 push %ebx
int fd;
int r;
fd = open(n, O_RDONLY);
219: 83 ec 08 sub $0x8,%esp
21c: 6a 00 push $0x0
21e: ff 75 08 pushl 0x8(%ebp)
221: e8 ed 00 00 00 call 313 <open>
if(fd < 0)
226: 83 c4 10 add $0x10,%esp
229: 85 c0 test %eax,%eax
22b: 78 2b js 258 <stat+0x48>
return -1;
r = fstat(fd, st);
22d: 83 ec 08 sub $0x8,%esp
230: ff 75 0c pushl 0xc(%ebp)
233: 89 c3 mov %eax,%ebx
235: 50 push %eax
236: e8 f0 00 00 00 call 32b <fstat>
close(fd);
23b: 89 1c 24 mov %ebx,(%esp)
r = fstat(fd, st);
23e: 89 c6 mov %eax,%esi
close(fd);
240: e8 b6 00 00 00 call 2fb <close>
return r;
245: 83 c4 10 add $0x10,%esp
}
248: 8d 65 f8 lea -0x8(%ebp),%esp
24b: 89 f0 mov %esi,%eax
24d: 5b pop %ebx
24e: 5e pop %esi
24f: 5d pop %ebp
250: c3 ret
251: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
return -1;
258: be ff ff ff ff mov $0xffffffff,%esi
25d: eb e9 jmp 248 <stat+0x38>
25f: 90 nop
00000260 <atoi>:
int
atoi(const char *s)
{
260: f3 0f 1e fb endbr32
264: 55 push %ebp
265: 89 e5 mov %esp,%ebp
267: 53 push %ebx
268: 8b 55 08 mov 0x8(%ebp),%edx
int n;
n = 0;
while('0' <= *s && *s <= '9')
26b: 0f be 02 movsbl (%edx),%eax
26e: 8d 48 d0 lea -0x30(%eax),%ecx
271: 80 f9 09 cmp $0x9,%cl
n = 0;
274: b9 00 00 00 00 mov $0x0,%ecx
while('0' <= *s && *s <= '9')
279: 77 1a ja 295 <atoi+0x35>
27b: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
27f: 90 nop
n = n*10 + *s++ - '0';
280: 83 c2 01 add $0x1,%edx
283: 8d 0c 89 lea (%ecx,%ecx,4),%ecx
286: 8d 4c 48 d0 lea -0x30(%eax,%ecx,2),%ecx
while('0' <= *s && *s <= '9')
28a: 0f be 02 movsbl (%edx),%eax
28d: 8d 58 d0 lea -0x30(%eax),%ebx
290: 80 fb 09 cmp $0x9,%bl
293: 76 eb jbe 280 <atoi+0x20>
return n;
}
295: 89 c8 mov %ecx,%eax
297: 5b pop %ebx
298: 5d pop %ebp
299: c3 ret
29a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
000002a0 <memmove>:
void*
memmove(void *vdst, const void *vsrc, int n)
{
2a0: f3 0f 1e fb endbr32
2a4: 55 push %ebp
2a5: 89 e5 mov %esp,%ebp
2a7: 57 push %edi
2a8: 8b 45 10 mov 0x10(%ebp),%eax
2ab: 8b 55 08 mov 0x8(%ebp),%edx
2ae: 56 push %esi
2af: 8b 75 0c mov 0xc(%ebp),%esi
char *dst;
const char *src;
dst = vdst;
src = vsrc;
while(n-- > 0)
2b2: 85 c0 test %eax,%eax
2b4: 7e 0f jle 2c5 <memmove+0x25>
2b6: 01 d0 add %edx,%eax
dst = vdst;
2b8: 89 d7 mov %edx,%edi
2ba: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
*dst++ = *src++;
2c0: a4 movsb %ds:(%esi),%es:(%edi)
while(n-- > 0)
2c1: 39 f8 cmp %edi,%eax
2c3: 75 fb jne 2c0 <memmove+0x20>
return vdst;
}
2c5: 5e pop %esi
2c6: 89 d0 mov %edx,%eax
2c8: 5f pop %edi
2c9: 5d pop %ebp
2ca: c3 ret
000002cb <fork>:
name: \
movl $SYS_ ## name, %eax; \
int $T_SYSCALL; \
ret
SYSCALL(fork)
2cb: b8 01 00 00 00 mov $0x1,%eax
2d0: cd 40 int $0x40
2d2: c3 ret
000002d3 <exit>:
SYSCALL(exit)
2d3: b8 02 00 00 00 mov $0x2,%eax
2d8: cd 40 int $0x40
2da: c3 ret
000002db <wait>:
SYSCALL(wait)
2db: b8 03 00 00 00 mov $0x3,%eax
2e0: cd 40 int $0x40
2e2: c3 ret
000002e3 <pipe>:
SYSCALL(pipe)
2e3: b8 04 00 00 00 mov $0x4,%eax
2e8: cd 40 int $0x40
2ea: c3 ret
000002eb <read>:
SYSCALL(read)
2eb: b8 05 00 00 00 mov $0x5,%eax
2f0: cd 40 int $0x40
2f2: c3 ret
000002f3 <write>:
SYSCALL(write)
2f3: b8 10 00 00 00 mov $0x10,%eax
2f8: cd 40 int $0x40
2fa: c3 ret
000002fb <close>:
SYSCALL(close)
2fb: b8 15 00 00 00 mov $0x15,%eax
300: cd 40 int $0x40
302: c3 ret
00000303 <kill>:
SYSCALL(kill)
303: b8 06 00 00 00 mov $0x6,%eax
308: cd 40 int $0x40
30a: c3 ret
0000030b <exec>:
SYSCALL(exec)
30b: b8 07 00 00 00 mov $0x7,%eax
310: cd 40 int $0x40
312: c3 ret
00000313 <open>:
SYSCALL(open)
313: b8 0f 00 00 00 mov $0xf,%eax
318: cd 40 int $0x40
31a: c3 ret
0000031b <mknod>:
SYSCALL(mknod)
31b: b8 11 00 00 00 mov $0x11,%eax
320: cd 40 int $0x40
322: c3 ret
00000323 <unlink>:
SYSCALL(unlink)
323: b8 12 00 00 00 mov $0x12,%eax
328: cd 40 int $0x40
32a: c3 ret
0000032b <fstat>:
SYSCALL(fstat)
32b: b8 08 00 00 00 mov $0x8,%eax
330: cd 40 int $0x40
332: c3 ret
00000333 <link>:
SYSCALL(link)
333: b8 13 00 00 00 mov $0x13,%eax
338: cd 40 int $0x40
33a: c3 ret
0000033b <mkdir>:
SYSCALL(mkdir)
33b: b8 14 00 00 00 mov $0x14,%eax
340: cd 40 int $0x40
342: c3 ret
00000343 <chdir>:
SYSCALL(chdir)
343: b8 09 00 00 00 mov $0x9,%eax
348: cd 40 int $0x40
34a: c3 ret
0000034b <dup>:
SYSCALL(dup)
34b: b8 0a 00 00 00 mov $0xa,%eax
350: cd 40 int $0x40
352: c3 ret
00000353 <getpid>:
SYSCALL(getpid)
353: b8 0b 00 00 00 mov $0xb,%eax
358: cd 40 int $0x40
35a: c3 ret
0000035b <sbrk>:
SYSCALL(sbrk)
35b: b8 0c 00 00 00 mov $0xc,%eax
360: cd 40 int $0x40
362: c3 ret
00000363 <sleep>:
SYSCALL(sleep)
363: b8 0d 00 00 00 mov $0xd,%eax
368: cd 40 int $0x40
36a: c3 ret
0000036b <uptime>:
SYSCALL(uptime)
36b: b8 0e 00 00 00 mov $0xe,%eax
370: cd 40 int $0x40
372: c3 ret
00000373 <waitx>:
//my insert begins
SYSCALL(waitx)
373: b8 16 00 00 00 mov $0x16,%eax
378: cd 40 int $0x40
37a: c3 ret
0000037b <psinfo>:
SYSCALL(psinfo)
37b: b8 17 00 00 00 mov $0x17,%eax
380: cd 40 int $0x40
382: c3 ret
00000383 <set_priority>:
SYSCALL(set_priority)
383: b8 18 00 00 00 mov $0x18,%eax
388: cd 40 int $0x40
38a: c3 ret
38b: 66 90 xchg %ax,%ax
38d: 66 90 xchg %ax,%ax
38f: 90 nop
00000390 <printint>:
write(fd, &c, 1);
}
static void
printint(int fd, int xx, int base, int sgn)
{
390: 55 push %ebp
391: 89 e5 mov %esp,%ebp
393: 57 push %edi
394: 56 push %esi
395: 53 push %ebx
396: 83 ec 3c sub $0x3c,%esp
399: 89 4d c4 mov %ecx,-0x3c(%ebp)
uint x;
neg = 0;
if(sgn && xx < 0){
neg = 1;
x = -xx;
39c: 89 d1 mov %edx,%ecx
{
39e: 89 45 b8 mov %eax,-0x48(%ebp)
if(sgn && xx < 0){
3a1: 85 d2 test %edx,%edx
3a3: 0f 89 7f 00 00 00 jns 428 <printint+0x98>
3a9: f6 45 08 01 testb $0x1,0x8(%ebp)
3ad: 74 79 je 428 <printint+0x98>
neg = 1;
3af: c7 45 bc 01 00 00 00 movl $0x1,-0x44(%ebp)
x = -xx;
3b6: f7 d9 neg %ecx
} else {
x = xx;
}
i = 0;
3b8: 31 db xor %ebx,%ebx
3ba: 8d 75 d7 lea -0x29(%ebp),%esi
3bd: 8d 76 00 lea 0x0(%esi),%esi
do{
buf[i++] = digits[x % base];
3c0: 89 c8 mov %ecx,%eax
3c2: 31 d2 xor %edx,%edx
3c4: 89 cf mov %ecx,%edi
3c6: f7 75 c4 divl -0x3c(%ebp)
3c9: 0f b6 92 c4 07 00 00 movzbl 0x7c4(%edx),%edx
3d0: 89 45 c0 mov %eax,-0x40(%ebp)
3d3: 89 d8 mov %ebx,%eax
3d5: 8d 5b 01 lea 0x1(%ebx),%ebx
}while((x /= base) != 0);
3d8: 8b 4d c0 mov -0x40(%ebp),%ecx
buf[i++] = digits[x % base];
3db: 88 14 1e mov %dl,(%esi,%ebx,1)
}while((x /= base) != 0);
3de: 39 7d c4 cmp %edi,-0x3c(%ebp)
3e1: 76 dd jbe 3c0 <printint+0x30>
if(neg)
3e3: 8b 4d bc mov -0x44(%ebp),%ecx
3e6: 85 c9 test %ecx,%ecx
3e8: 74 0c je 3f6 <printint+0x66>
buf[i++] = '-';
3ea: c6 44 1d d8 2d movb $0x2d,-0x28(%ebp,%ebx,1)
buf[i++] = digits[x % base];
3ef: 89 d8 mov %ebx,%eax
buf[i++] = '-';
3f1: ba 2d 00 00 00 mov $0x2d,%edx
while(--i >= 0)
3f6: 8b 7d b8 mov -0x48(%ebp),%edi
3f9: 8d 5c 05 d7 lea -0x29(%ebp,%eax,1),%ebx
3fd: eb 07 jmp 406 <printint+0x76>
3ff: 90 nop
400: 0f b6 13 movzbl (%ebx),%edx
403: 83 eb 01 sub $0x1,%ebx
write(fd, &c, 1);
406: 83 ec 04 sub $0x4,%esp
409: 88 55 d7 mov %dl,-0x29(%ebp)
40c: 6a 01 push $0x1
40e: 56 push %esi
40f: 57 push %edi
410: e8 de fe ff ff call 2f3 <write>
while(--i >= 0)
415: 83 c4 10 add $0x10,%esp
418: 39 de cmp %ebx,%esi
41a: 75 e4 jne 400 <printint+0x70>
putc(fd, buf[i]);
}
41c: 8d 65 f4 lea -0xc(%ebp),%esp
41f: 5b pop %ebx
420: 5e pop %esi
421: 5f pop %edi
422: 5d pop %ebp
423: c3 ret
424: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
neg = 0;
428: c7 45 bc 00 00 00 00 movl $0x0,-0x44(%ebp)
42f: eb 87 jmp 3b8 <printint+0x28>
431: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
438: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
43f: 90 nop
00000440 <printf>:
// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, const char *fmt, ...)
{
440: f3 0f 1e fb endbr32
444: 55 push %ebp
445: 89 e5 mov %esp,%ebp
447: 57 push %edi
448: 56 push %esi
449: 53 push %ebx
44a: 83 ec 2c sub $0x2c,%esp
int c, i, state;
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
44d: 8b 75 0c mov 0xc(%ebp),%esi
450: 0f b6 1e movzbl (%esi),%ebx
453: 84 db test %bl,%bl
455: 0f 84 b4 00 00 00 je 50f <printf+0xcf>
ap = (uint*)(void*)&fmt + 1;
45b: 8d 45 10 lea 0x10(%ebp),%eax
45e: 83 c6 01 add $0x1,%esi
write(fd, &c, 1);
461: 8d 7d e7 lea -0x19(%ebp),%edi
state = 0;
464: 31 d2 xor %edx,%edx
ap = (uint*)(void*)&fmt + 1;
466: 89 45 d0 mov %eax,-0x30(%ebp)
469: eb 33 jmp 49e <printf+0x5e>
46b: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
46f: 90 nop
470: 89 55 d4 mov %edx,-0x2c(%ebp)
c = fmt[i] & 0xff;
if(state == 0){
if(c == '%'){
state = '%';
473: ba 25 00 00 00 mov $0x25,%edx
if(c == '%'){
478: 83 f8 25 cmp $0x25,%eax
47b: 74 17 je 494 <printf+0x54>
write(fd, &c, 1);
47d: 83 ec 04 sub $0x4,%esp
480: 88 5d e7 mov %bl,-0x19(%ebp)
483: 6a 01 push $0x1
485: 57 push %edi
486: ff 75 08 pushl 0x8(%ebp)
489: e8 65 fe ff ff call 2f3 <write>
48e: 8b 55 d4 mov -0x2c(%ebp),%edx
} else {
putc(fd, c);
491: 83 c4 10 add $0x10,%esp
for(i = 0; fmt[i]; i++){
494: 0f b6 1e movzbl (%esi),%ebx
497: 83 c6 01 add $0x1,%esi
49a: 84 db test %bl,%bl
49c: 74 71 je 50f <printf+0xcf>
c = fmt[i] & 0xff;
49e: 0f be cb movsbl %bl,%ecx
4a1: 0f b6 c3 movzbl %bl,%eax
if(state == 0){
4a4: 85 d2 test %edx,%edx
4a6: 74 c8 je 470 <printf+0x30>
}
} else if(state == '%'){
4a8: 83 fa 25 cmp $0x25,%edx
4ab: 75 e7 jne 494 <printf+0x54>
if(c == 'd'){
4ad: 83 f8 64 cmp $0x64,%eax
4b0: 0f 84 9a 00 00 00 je 550 <printf+0x110>
printint(fd, *ap, 10, 1);
ap++;
} else if(c == 'x' || c == 'p'){
4b6: 81 e1 f7 00 00 00 and $0xf7,%ecx
4bc: 83 f9 70 cmp $0x70,%ecx
4bf: 74 5f je 520 <printf+0xe0>
printint(fd, *ap, 16, 0);
ap++;
} else if(c == 's'){
4c1: 83 f8 73 cmp $0x73,%eax
4c4: 0f 84 d6 00 00 00 je 5a0 <printf+0x160>
s = "(null)";
while(*s != 0){
putc(fd, *s);
s++;
}
} else if(c == 'c'){
4ca: 83 f8 63 cmp $0x63,%eax
4cd: 0f 84 8d 00 00 00 je 560 <printf+0x120>
putc(fd, *ap);
ap++;
} else if(c == '%'){
4d3: 83 f8 25 cmp $0x25,%eax
4d6: 0f 84 b4 00 00 00 je 590 <printf+0x150>
write(fd, &c, 1);
4dc: 83 ec 04 sub $0x4,%esp
4df: c6 45 e7 25 movb $0x25,-0x19(%ebp)
4e3: 6a 01 push $0x1
4e5: 57 push %edi
4e6: ff 75 08 pushl 0x8(%ebp)
4e9: e8 05 fe ff ff call 2f3 <write>
putc(fd, c);
} else {
// Unknown % sequence. Print it to draw attention.
putc(fd, '%');
putc(fd, c);
4ee: 88 5d e7 mov %bl,-0x19(%ebp)
write(fd, &c, 1);
4f1: 83 c4 0c add $0xc,%esp
4f4: 6a 01 push $0x1
4f6: 83 c6 01 add $0x1,%esi
4f9: 57 push %edi
4fa: ff 75 08 pushl 0x8(%ebp)
4fd: e8 f1 fd ff ff call 2f3 <write>
for(i = 0; fmt[i]; i++){
502: 0f b6 5e ff movzbl -0x1(%esi),%ebx
putc(fd, c);
506: 83 c4 10 add $0x10,%esp
}
state = 0;
509: 31 d2 xor %edx,%edx
for(i = 0; fmt[i]; i++){
50b: 84 db test %bl,%bl
50d: 75 8f jne 49e <printf+0x5e>
}
}
}
50f: 8d 65 f4 lea -0xc(%ebp),%esp
512: 5b pop %ebx
513: 5e pop %esi
514: 5f pop %edi
515: 5d pop %ebp
516: c3 ret
517: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
51e: 66 90 xchg %ax,%ax
printint(fd, *ap, 16, 0);
520: 83 ec 0c sub $0xc,%esp
523: b9 10 00 00 00 mov $0x10,%ecx
528: 6a 00 push $0x0
52a: 8b 5d d0 mov -0x30(%ebp),%ebx
52d: 8b 45 08 mov 0x8(%ebp),%eax
530: 8b 13 mov (%ebx),%edx
532: e8 59 fe ff ff call 390 <printint>
ap++;
537: 89 d8 mov %ebx,%eax
539: 83 c4 10 add $0x10,%esp
state = 0;
53c: 31 d2 xor %edx,%edx
ap++;
53e: 83 c0 04 add $0x4,%eax
541: 89 45 d0 mov %eax,-0x30(%ebp)
544: e9 4b ff ff ff jmp 494 <printf+0x54>
549: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
printint(fd, *ap, 10, 1);
550: 83 ec 0c sub $0xc,%esp
553: b9 0a 00 00 00 mov $0xa,%ecx
558: 6a 01 push $0x1
55a: eb ce jmp 52a <printf+0xea>
55c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
putc(fd, *ap);
560: 8b 5d d0 mov -0x30(%ebp),%ebx
write(fd, &c, 1);
563: 83 ec 04 sub $0x4,%esp
putc(fd, *ap);
566: 8b 03 mov (%ebx),%eax
write(fd, &c, 1);
568: 6a 01 push $0x1
ap++;
56a: 83 c3 04 add $0x4,%ebx
write(fd, &c, 1);
56d: 57 push %edi
56e: ff 75 08 pushl 0x8(%ebp)
putc(fd, *ap);
571: 88 45 e7 mov %al,-0x19(%ebp)
write(fd, &c, 1);
574: e8 7a fd ff ff call 2f3 <write>
ap++;
579: 89 5d d0 mov %ebx,-0x30(%ebp)
57c: 83 c4 10 add $0x10,%esp
state = 0;
57f: 31 d2 xor %edx,%edx
581: e9 0e ff ff ff jmp 494 <printf+0x54>
586: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
58d: 8d 76 00 lea 0x0(%esi),%esi
putc(fd, c);
590: 88 5d e7 mov %bl,-0x19(%ebp)
write(fd, &c, 1);
593: 83 ec 04 sub $0x4,%esp
596: e9 59 ff ff ff jmp 4f4 <printf+0xb4>
59b: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
59f: 90 nop
s = (char*)*ap;
5a0: 8b 45 d0 mov -0x30(%ebp),%eax
5a3: 8b 18 mov (%eax),%ebx
ap++;
5a5: 83 c0 04 add $0x4,%eax
5a8: 89 45 d0 mov %eax,-0x30(%ebp)
if(s == 0)
5ab: 85 db test %ebx,%ebx
5ad: 74 17 je 5c6 <printf+0x186>
while(*s != 0){
5af: 0f b6 03 movzbl (%ebx),%eax
state = 0;
5b2: 31 d2 xor %edx,%edx
while(*s != 0){
5b4: 84 c0 test %al,%al
5b6: 0f 84 d8 fe ff ff je 494 <printf+0x54>
5bc: 89 75 d4 mov %esi,-0x2c(%ebp)
5bf: 89 de mov %ebx,%esi
5c1: 8b 5d 08 mov 0x8(%ebp),%ebx
5c4: eb 1a jmp 5e0 <printf+0x1a0>
s = "(null)";
5c6: bb bc 07 00 00 mov $0x7bc,%ebx
while(*s != 0){
5cb: 89 75 d4 mov %esi,-0x2c(%ebp)
5ce: b8 28 00 00 00 mov $0x28,%eax
5d3: 89 de mov %ebx,%esi
5d5: 8b 5d 08 mov 0x8(%ebp),%ebx
5d8: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
5df: 90 nop
write(fd, &c, 1);
5e0: 83 ec 04 sub $0x4,%esp
s++;
5e3: 83 c6 01 add $0x1,%esi
5e6: 88 45 e7 mov %al,-0x19(%ebp)
write(fd, &c, 1);
5e9: 6a 01 push $0x1
5eb: 57 push %edi
5ec: 53 push %ebx
5ed: e8 01 fd ff ff call 2f3 <write>
while(*s != 0){
5f2: 0f b6 06 movzbl (%esi),%eax
5f5: 83 c4 10 add $0x10,%esp
5f8: 84 c0 test %al,%al
5fa: 75 e4 jne 5e0 <printf+0x1a0>
5fc: 8b 75 d4 mov -0x2c(%ebp),%esi
state = 0;
5ff: 31 d2 xor %edx,%edx
601: e9 8e fe ff ff jmp 494 <printf+0x54>
606: 66 90 xchg %ax,%ax
608: 66 90 xchg %ax,%ax
60a: 66 90 xchg %ax,%ax
60c: 66 90 xchg %ax,%ax
60e: 66 90 xchg %ax,%ax
00000610 <free>:
static Header base;
static Header *freep;
void
free(void *ap)
{
610: f3 0f 1e fb endbr32
614: 55 push %ebp
Header *bp, *p;
bp = (Header*)ap - 1;
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
615: a1 74 0a 00 00 mov 0xa74,%eax
{
61a: 89 e5 mov %esp,%ebp
61c: 57 push %edi
61d: 56 push %esi
61e: 53 push %ebx
61f: 8b 5d 08 mov 0x8(%ebp),%ebx
622: 8b 10 mov (%eax),%edx
bp = (Header*)ap - 1;
624: 8d 4b f8 lea -0x8(%ebx),%ecx
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
627: 39 c8 cmp %ecx,%eax
629: 73 15 jae 640 <free+0x30>
62b: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
62f: 90 nop
630: 39 d1 cmp %edx,%ecx
632: 72 14 jb 648 <free+0x38>
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
634: 39 d0 cmp %edx,%eax
636: 73 10 jae 648 <free+0x38>
{
638: 89 d0 mov %edx,%eax
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
63a: 8b 10 mov (%eax),%edx
63c: 39 c8 cmp %ecx,%eax
63e: 72 f0 jb 630 <free+0x20>
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
640: 39 d0 cmp %edx,%eax
642: 72 f4 jb 638 <free+0x28>
644: 39 d1 cmp %edx,%ecx
646: 73 f0 jae 638 <free+0x28>
break;
if(bp + bp->s.size == p->s.ptr){
648: 8b 73 fc mov -0x4(%ebx),%esi
64b: 8d 3c f1 lea (%ecx,%esi,8),%edi
64e: 39 fa cmp %edi,%edx
650: 74 1e je 670 <free+0x60>
bp->s.size += p->s.ptr->s.size;
bp->s.ptr = p->s.ptr->s.ptr;
} else
bp->s.ptr = p->s.ptr;
652: 89 53 f8 mov %edx,-0x8(%ebx)
if(p + p->s.size == bp){
655: 8b 50 04 mov 0x4(%eax),%edx
658: 8d 34 d0 lea (%eax,%edx,8),%esi
65b: 39 f1 cmp %esi,%ecx
65d: 74 28 je 687 <free+0x77>
p->s.size += bp->s.size;
p->s.ptr = bp->s.ptr;
} else
p->s.ptr = bp;
65f: 89 08 mov %ecx,(%eax)
freep = p;
}
661: 5b pop %ebx
freep = p;
662: a3 74 0a 00 00 mov %eax,0xa74
}
667: 5e pop %esi
668: 5f pop %edi
669: 5d pop %ebp
66a: c3 ret
66b: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
66f: 90 nop
bp->s.size += p->s.ptr->s.size;
670: 03 72 04 add 0x4(%edx),%esi
673: 89 73 fc mov %esi,-0x4(%ebx)
bp->s.ptr = p->s.ptr->s.ptr;
676: 8b 10 mov (%eax),%edx
678: 8b 12 mov (%edx),%edx
67a: 89 53 f8 mov %edx,-0x8(%ebx)
if(p + p->s.size == bp){
67d: 8b 50 04 mov 0x4(%eax),%edx
680: 8d 34 d0 lea (%eax,%edx,8),%esi
683: 39 f1 cmp %esi,%ecx
685: 75 d8 jne 65f <free+0x4f>
p->s.size += bp->s.size;
687: 03 53 fc add -0x4(%ebx),%edx
freep = p;
68a: a3 74 0a 00 00 mov %eax,0xa74
p->s.size += bp->s.size;
68f: 89 50 04 mov %edx,0x4(%eax)
p->s.ptr = bp->s.ptr;
692: 8b 53 f8 mov -0x8(%ebx),%edx
695: 89 10 mov %edx,(%eax)
}
697: 5b pop %ebx
698: 5e pop %esi
699: 5f pop %edi
69a: 5d pop %ebp
69b: c3 ret
69c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
000006a0 <malloc>:
return freep;
}
void*
malloc(uint nbytes)
{
6a0: f3 0f 1e fb endbr32
6a4: 55 push %ebp
6a5: 89 e5 mov %esp,%ebp
6a7: 57 push %edi
6a8: 56 push %esi
6a9: 53 push %ebx
6aa: 83 ec 1c sub $0x1c,%esp
Header *p, *prevp;
uint nunits;
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
6ad: 8b 45 08 mov 0x8(%ebp),%eax
if((prevp = freep) == 0){
6b0: 8b 3d 74 0a 00 00 mov 0xa74,%edi
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
6b6: 8d 70 07 lea 0x7(%eax),%esi
6b9: c1 ee 03 shr $0x3,%esi
6bc: 83 c6 01 add $0x1,%esi
if((prevp = freep) == 0){
6bf: 85 ff test %edi,%edi
6c1: 0f 84 a9 00 00 00 je 770 <malloc+0xd0>
base.s.ptr = freep = prevp = &base;
base.s.size = 0;
}
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
6c7: 8b 07 mov (%edi),%eax
if(p->s.size >= nunits){
6c9: 8b 48 04 mov 0x4(%eax),%ecx
6cc: 39 f1 cmp %esi,%ecx
6ce: 73 6d jae 73d <malloc+0x9d>
6d0: 81 fe 00 10 00 00 cmp $0x1000,%esi
6d6: bb 00 10 00 00 mov $0x1000,%ebx
6db: 0f 43 de cmovae %esi,%ebx
p = sbrk(nu * sizeof(Header));
6de: 8d 0c dd 00 00 00 00 lea 0x0(,%ebx,8),%ecx
6e5: 89 4d e4 mov %ecx,-0x1c(%ebp)
6e8: eb 17 jmp 701 <malloc+0x61>
6ea: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
6f0: 8b 10 mov (%eax),%edx
if(p->s.size >= nunits){
6f2: 8b 4a 04 mov 0x4(%edx),%ecx
6f5: 39 f1 cmp %esi,%ecx
6f7: 73 4f jae 748 <malloc+0xa8>
6f9: 8b 3d 74 0a 00 00 mov 0xa74,%edi
6ff: 89 d0 mov %edx,%eax
p->s.size = nunits;
}
freep = prevp;
return (void*)(p + 1);
}
if(p == freep)
701: 39 c7 cmp %eax,%edi
703: 75 eb jne 6f0 <malloc+0x50>
p = sbrk(nu * sizeof(Header));
705: 83 ec 0c sub $0xc,%esp
708: ff 75 e4 pushl -0x1c(%ebp)
70b: e8 4b fc ff ff call 35b <sbrk>
if(p == (char*)-1)
710: 83 c4 10 add $0x10,%esp
713: 83 f8 ff cmp $0xffffffff,%eax
716: 74 1b je 733 <malloc+0x93>
hp->s.size = nu;
718: 89 58 04 mov %ebx,0x4(%eax)
free((void*)(hp + 1));
71b: 83 ec 0c sub $0xc,%esp
71e: 83 c0 08 add $0x8,%eax
721: 50 push %eax
722: e8 e9 fe ff ff call 610 <free>
return freep;
727: a1 74 0a 00 00 mov 0xa74,%eax
if((p = morecore(nunits)) == 0)
72c: 83 c4 10 add $0x10,%esp
72f: 85 c0 test %eax,%eax
731: 75 bd jne 6f0 <malloc+0x50>
return 0;
}
}
733: 8d 65 f4 lea -0xc(%ebp),%esp
return 0;
736: 31 c0 xor %eax,%eax
}
738: 5b pop %ebx
739: 5e pop %esi
73a: 5f pop %edi
73b: 5d pop %ebp
73c: c3 ret
if(p->s.size >= nunits){
73d: 89 c2 mov %eax,%edx
73f: 89 f8 mov %edi,%eax
741: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
if(p->s.size == nunits)
748: 39 ce cmp %ecx,%esi
74a: 74 54 je 7a0 <malloc+0x100>
p->s.size -= nunits;
74c: 29 f1 sub %esi,%ecx
74e: 89 4a 04 mov %ecx,0x4(%edx)
p += p->s.size;
751: 8d 14 ca lea (%edx,%ecx,8),%edx
p->s.size = nunits;
754: 89 72 04 mov %esi,0x4(%edx)
freep = prevp;
757: a3 74 0a 00 00 mov %eax,0xa74
}
75c: 8d 65 f4 lea -0xc(%ebp),%esp
return (void*)(p + 1);
75f: 8d 42 08 lea 0x8(%edx),%eax
}
762: 5b pop %ebx
763: 5e pop %esi
764: 5f pop %edi
765: 5d pop %ebp
766: c3 ret
767: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
76e: 66 90 xchg %ax,%ax
base.s.ptr = freep = prevp = &base;
770: c7 05 74 0a 00 00 78 movl $0xa78,0xa74
777: 0a 00 00
base.s.size = 0;
77a: bf 78 0a 00 00 mov $0xa78,%edi
base.s.ptr = freep = prevp = &base;
77f: c7 05 78 0a 00 00 78 movl $0xa78,0xa78
786: 0a 00 00
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
789: 89 f8 mov %edi,%eax
base.s.size = 0;
78b: c7 05 7c 0a 00 00 00 movl $0x0,0xa7c
792: 00 00 00
if(p->s.size >= nunits){
795: e9 36 ff ff ff jmp 6d0 <malloc+0x30>
79a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
prevp->s.ptr = p->s.ptr;
7a0: 8b 0a mov (%edx),%ecx
7a2: 89 08 mov %ecx,(%eax)
7a4: eb b1 jmp 757 <malloc+0xb7>
|
// Copyright 2018 Google 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 "tink/signature/signature_pem_keyset_reader.h"
#include <cstddef>
#include <memory>
#include <random>
#include <string>
#include <utility>
#include "absl/memory/memory.h"
#include "absl/status/status.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
#include "tink/internal/ec_util.h"
#include "tink/internal/rsa_util.h"
#include "tink/keyset_reader.h"
#include "tink/signature/ecdsa_verify_key_manager.h"
#include "tink/signature/rsa_ssa_pkcs1_sign_key_manager.h"
#include "tink/signature/rsa_ssa_pkcs1_verify_key_manager.h"
#include "tink/signature/rsa_ssa_pss_sign_key_manager.h"
#include "tink/signature/rsa_ssa_pss_verify_key_manager.h"
#include "tink/subtle/pem_parser_boringssl.h"
#include "tink/util/enums.h"
#include "tink/util/keyset_util.h"
#include "tink/util/secret_data.h"
#include "tink/util/status.h"
#include "tink/util/statusor.h"
#include "proto/common.pb.h"
#include "proto/ecdsa.pb.h"
#include "proto/rsa_ssa_pkcs1.pb.h"
#include "proto/rsa_ssa_pss.pb.h"
#include "proto/tink.pb.h"
namespace crypto {
namespace tink {
using ::google::crypto::tink::EcdsaParams;
using ::google::crypto::tink::EcdsaPublicKey;
using ::google::crypto::tink::EcdsaSignatureEncoding;
using ::google::crypto::tink::EllipticCurveType;
using ::google::crypto::tink::EncryptedKeyset;
using ::google::crypto::tink::HashType;
using ::google::crypto::tink::KeyData;
using ::google::crypto::tink::Keyset;
using ::google::crypto::tink::KeyStatusType;
using ::google::crypto::tink::OutputPrefixType;
using ::google::crypto::tink::RsaSsaPkcs1PrivateKey;
using ::google::crypto::tink::RsaSsaPkcs1PublicKey;
using ::google::crypto::tink::RsaSsaPssParams;
using ::google::crypto::tink::RsaSsaPssPrivateKey;
using ::google::crypto::tink::RsaSsaPssPublicKey;
namespace {
// Sets the parameters for an RSASSA-PSS key `parameters` given the PEM
// parameters `pem_parameters`.
util::Status SetRsaSsaPssParameters(const PemKeyParams& pem_parameters,
RsaSsaPssParams* parameters) {
if (parameters == nullptr) {
return util::Status(absl::StatusCode::kInvalidArgument,
"Null parameters provided");
}
parameters->set_mgf1_hash(pem_parameters.hash_type);
parameters->set_sig_hash(pem_parameters.hash_type);
auto salt_len_or = util::Enums::HashLength(pem_parameters.hash_type);
if (!salt_len_or.ok()) return salt_len_or.status();
parameters->set_salt_length(salt_len_or.value());
return util::OkStatus();
}
// Sets the parameters for an ECDSA key `parameters` given the PEM
// parameters `pem_parameters`.
util::Status SetEcdsaParameters(const PemKeyParams& pem_parameters,
EcdsaParams* parameters) {
if (parameters == nullptr) {
return util::Status(absl::StatusCode::kInvalidArgument,
"Null parameters provided");
}
if (pem_parameters.hash_type != HashType::SHA256 ||
pem_parameters.key_size_in_bits != 256) {
return util::Status(
absl::StatusCode::kInvalidArgument,
"Only NIST_P256 ECDSA supported. Parameters should contain "
"SHA256 and 256 bit key size.");
}
parameters->set_hash_type(pem_parameters.hash_type);
parameters->set_curve(EllipticCurveType::NIST_P256);
switch (pem_parameters.algorithm) {
case PemAlgorithm::ECDSA_IEEE: {
parameters->set_encoding(
google::crypto::tink::EcdsaSignatureEncoding::IEEE_P1363);
break;
}
case PemAlgorithm::ECDSA_DER: {
parameters->set_encoding(
google::crypto::tink::EcdsaSignatureEncoding::DER);
break;
}
default: {
return util::Status(
absl::StatusCode::kInvalidArgument,
"Only ECDSA supported. The algorithm parameter should be "
"ECDSA_IEEE or ECDSA_DER.");
}
}
return util::OkStatus();
}
// Creates a new Keyset::Key with ID `key_id`. The key has key data
// `key_data`, key type `key_type`, and key material type
// `key_material_type`.
Keyset::Key NewKeysetKey(uint32_t key_id, absl::string_view key_type,
const KeyData::KeyMaterialType& key_material_type,
const std::string& key_data) {
Keyset::Key key;
// Populate KeyData for the new key.
key.set_key_id(key_id);
key.set_status(KeyStatusType::ENABLED);
// PEM keys don't add any prefix to signatures
key.set_output_prefix_type(OutputPrefixType::RAW);
KeyData* key_data_proto = key.mutable_key_data();
key_data_proto->set_type_url(key_type.data(), key_type.size());
key_data_proto->set_value(key_data);
key_data_proto->set_key_material_type(key_material_type);
return key;
}
// Construct a new RSASSA-PSS key proto from a subtle RSA private key
// `private_key_subtle`; the key is assigned version `key_version` and
// key paramters `parameters`.
util::StatusOr<RsaSsaPssPrivateKey> NewRsaSsaPrivateKey(
const internal::RsaPrivateKey& private_key_subtle, uint32_t key_version,
const PemKeyParams& parameters) {
RsaSsaPssPrivateKey private_key_proto;
// RSA Private key parameters.
private_key_proto.set_version(key_version);
private_key_proto.set_d(
std::string(util::SecretDataAsStringView(private_key_subtle.d)));
private_key_proto.set_p(
std::string(util::SecretDataAsStringView(private_key_subtle.p)));
private_key_proto.set_q(
std::string(util::SecretDataAsStringView(private_key_subtle.q)));
private_key_proto.set_dp(
std::string(util::SecretDataAsStringView(private_key_subtle.dp)));
private_key_proto.set_dq(
std::string(util::SecretDataAsStringView(private_key_subtle.dq)));
private_key_proto.set_crt(
std::string(util::SecretDataAsStringView(private_key_subtle.crt)));
// Inner RSA public key.
RsaSsaPssPublicKey* public_key_proto = private_key_proto.mutable_public_key();
public_key_proto->set_version(key_version);
public_key_proto->set_n(private_key_subtle.n);
public_key_proto->set_e(private_key_subtle.e);
// RSASSA-PSS public key parameters.
auto set_parameter_status =
SetRsaSsaPssParameters(parameters, public_key_proto->mutable_params());
if (!set_parameter_status.ok()) {
return set_parameter_status;
}
return private_key_proto;
}
// Construct a new RSASSA-PKCS1 key proto from a subtle RSA private key
// `private_key_subtle`; the key is assigned version `key_version` and
// key paramters `parameters`.
RsaSsaPkcs1PrivateKey NewRsaSsaPkcs1PrivateKey(
const internal::RsaPrivateKey& private_key_subtle, uint32_t key_version,
const PemKeyParams& parameters) {
RsaSsaPkcs1PrivateKey private_key_proto;
// RSA Private key parameters.
private_key_proto.set_version(key_version);
private_key_proto.set_d(
std::string(util::SecretDataAsStringView(private_key_subtle.d)));
private_key_proto.set_p(
std::string(util::SecretDataAsStringView(private_key_subtle.p)));
private_key_proto.set_q(
std::string(util::SecretDataAsStringView(private_key_subtle.q)));
private_key_proto.set_dp(
std::string(util::SecretDataAsStringView(private_key_subtle.dp)));
private_key_proto.set_dq(
std::string(util::SecretDataAsStringView(private_key_subtle.dq)));
private_key_proto.set_crt(
std::string(util::SecretDataAsStringView(private_key_subtle.crt)));
// Inner RSA Public key parameters.
RsaSsaPkcs1PublicKey* public_key_proto =
private_key_proto.mutable_public_key();
public_key_proto->set_version(key_version);
public_key_proto->set_n(private_key_subtle.n);
public_key_proto->set_e(private_key_subtle.e);
// RSASSA-PKCS1 Public key parameters.
public_key_proto->mutable_params()->set_hash_type(parameters.hash_type);
return private_key_proto;
}
// Adds the PEM-encoded private key `pem_key` to `keyset`.
util::Status AddRsaSsaPrivateKey(const PemKey& pem_key, Keyset* keyset) {
// Try to parse the PEM RSA private key.
auto private_key_subtle_or =
subtle::PemParser::ParseRsaPrivateKey(pem_key.serialized_key);
if (!private_key_subtle_or.ok()) return private_key_subtle_or.status();
std::unique_ptr<internal::RsaPrivateKey> private_key_subtle =
std::move(private_key_subtle_or).value();
size_t modulus_size = private_key_subtle->n.length() * 8;
if (pem_key.parameters.key_size_in_bits != modulus_size) {
return util::Status(
absl::StatusCode::kInvalidArgument,
absl::StrCat("Invalid RSA Key modulus size; found: ", modulus_size,
", expected: ", pem_key.parameters.key_size_in_bits));
}
switch (pem_key.parameters.algorithm) {
case PemAlgorithm::RSASSA_PSS: {
RsaSsaPssSignKeyManager key_manager;
auto private_key_proto_or = NewRsaSsaPrivateKey(
*private_key_subtle, key_manager.get_version(), pem_key.parameters);
if (!private_key_proto_or.ok()) return private_key_proto_or.status();
RsaSsaPssPrivateKey private_key_proto = private_key_proto_or.value();
// Validate the key.
auto key_validation_status = key_manager.ValidateKey(private_key_proto);
if (!key_validation_status.ok()) return key_validation_status;
*keyset->add_key() =
NewKeysetKey(GenerateUnusedKeyId(*keyset), key_manager.get_key_type(),
key_manager.key_material_type(),
private_key_proto.SerializeAsString());
break;
}
case PemAlgorithm::RSASSA_PKCS1: {
RsaSsaPkcs1SignKeyManager key_manager;
RsaSsaPkcs1PrivateKey private_key_proto = NewRsaSsaPkcs1PrivateKey(
*private_key_subtle, key_manager.get_version(), pem_key.parameters);
// Validate the key.
auto key_validation_status = key_manager.ValidateKey(private_key_proto);
if (!key_validation_status.ok()) return key_validation_status;
*keyset->add_key() =
NewKeysetKey(GenerateUnusedKeyId(*keyset), key_manager.get_key_type(),
key_manager.key_material_type(),
private_key_proto.SerializeAsString());
break;
}
default:
return util::Status(
absl::StatusCode::kInvalidArgument,
absl::StrCat("Invalid RSA algorithm ", pem_key.parameters.algorithm));
}
return util::OkStatus();
}
// Parses a given PEM-encoded ECDSA public key `pem_key`, and adds it to the
// keyset `keyset`.
util::Status AddEcdsaPublicKey(const PemKey& pem_key, Keyset* keyset) {
// Parse the PEM string into a ECDSA public key.
auto public_key_subtle_or =
subtle::PemParser::ParseEcPublicKey(pem_key.serialized_key);
if (!public_key_subtle_or.ok()) return public_key_subtle_or.status();
std::unique_ptr<internal::EcKey> public_key_subtle =
std::move(public_key_subtle_or).value();
EcdsaPublicKey ecdsa_key;
EcdsaVerifyKeyManager key_manager;
// ECDSA Public Key Parameters
ecdsa_key.set_x(public_key_subtle->pub_x);
ecdsa_key.set_y(public_key_subtle->pub_y);
auto set_parameter_status =
SetEcdsaParameters(pem_key.parameters, ecdsa_key.mutable_params());
if (!set_parameter_status.ok()) return set_parameter_status;
ecdsa_key.set_version(key_manager.get_version());
// Validate the key.
auto key_validation_status = key_manager.ValidateKey(ecdsa_key);
if (!key_validation_status.ok()) return key_validation_status;
*keyset->add_key() = NewKeysetKey(
GenerateUnusedKeyId(*keyset), key_manager.get_key_type(),
key_manager.key_material_type(), ecdsa_key.SerializeAsString());
return util::OkStatus();
}
// Parses a given PEM-encoded RSA public key `pem_key`, and adds it to the
// keyset `keyset`.
util::Status AddRsaSsaPublicKey(const PemKey& pem_key, Keyset* keyset) {
// Parse the PEM string into a RSA public key.
auto public_key_subtle_or =
subtle::PemParser::ParseRsaPublicKey(pem_key.serialized_key);
if (!public_key_subtle_or.ok()) return public_key_subtle_or.status();
std::unique_ptr<internal::RsaPublicKey> public_key_subtle =
std::move(public_key_subtle_or).value();
// Check key length is as expected.
size_t modulus_size = public_key_subtle->n.length() * 8;
if (pem_key.parameters.key_size_in_bits != modulus_size) {
return util::Status(
absl::StatusCode::kInvalidArgument,
absl::StrCat("Invalid RSA Key modulus size; found ", modulus_size,
", expected ", pem_key.parameters.key_size_in_bits));
}
switch (pem_key.parameters.algorithm) {
case PemAlgorithm::RSASSA_PSS: {
RsaSsaPssPublicKey public_key_proto;
RsaSsaPssVerifyKeyManager key_manager;
// RSA Public key paramters.
public_key_proto.set_e(public_key_subtle->e);
public_key_proto.set_n(public_key_subtle->n);
// RSASSA-PSS Public key parameters.
auto set_parameter_status = SetRsaSsaPssParameters(
pem_key.parameters, public_key_proto.mutable_params());
if (!set_parameter_status.ok()) return set_parameter_status;
public_key_proto.set_version(key_manager.get_version());
// Validate the key.
auto key_validation_status = key_manager.ValidateKey(public_key_proto);
if (!key_validation_status.ok()) return key_validation_status;
*keyset->add_key() =
NewKeysetKey(GenerateUnusedKeyId(*keyset), key_manager.get_key_type(),
key_manager.key_material_type(),
public_key_proto.SerializeAsString());
break;
}
case PemAlgorithm::RSASSA_PKCS1: {
RsaSsaPkcs1PublicKey public_key_proto;
RsaSsaPkcs1VerifyKeyManager key_manager;
// RSA Public key paramters.
public_key_proto.set_e(public_key_subtle->e);
public_key_proto.set_n(public_key_subtle->n);
// RSASSA-PKCS1 Public key parameters.
public_key_proto.mutable_params()->set_hash_type(
pem_key.parameters.hash_type);
public_key_proto.set_version(key_manager.get_version());
// Validate the key.
auto key_validation_status = key_manager.ValidateKey(public_key_proto);
if (!key_validation_status.ok()) return key_validation_status;
*keyset->add_key() =
NewKeysetKey(GenerateUnusedKeyId(*keyset), key_manager.get_key_type(),
key_manager.key_material_type(),
public_key_proto.SerializeAsString());
break;
}
default:
return util::Status(
absl::StatusCode::kInvalidArgument,
absl::StrCat("Invalid RSA algorithm ", pem_key.parameters.algorithm));
}
return util::OkStatus();
}
} // namespace
void SignaturePemKeysetReaderBuilder::Add(const PemKey& pem_serialized_key) {
pem_serialized_keys_.push_back(pem_serialized_key);
}
util::StatusOr<std::unique_ptr<KeysetReader>>
SignaturePemKeysetReaderBuilder::Build() {
if (pem_serialized_keys_.empty()) {
return util::Status(absl::StatusCode::kInvalidArgument,
"Empty array of PEM-encoded keys");
}
switch (pem_reader_type_) {
case PUBLIC_KEY_SIGN: {
return absl::WrapUnique<KeysetReader>(
new PublicKeySignPemKeysetReader(pem_serialized_keys_));
}
case PUBLIC_KEY_VERIFY: {
return absl::WrapUnique<KeysetReader>(
new PublicKeyVerifyPemKeysetReader(pem_serialized_keys_));
}
}
return util::Status(absl::StatusCode::kInvalidArgument,
"Unknown pem_reader_type_");
}
util::StatusOr<std::unique_ptr<Keyset>> PublicKeySignPemKeysetReader::Read() {
if (pem_serialized_keys_.empty()) {
return util::Status(absl::StatusCode::kInvalidArgument,
"Empty array of PEM-encoded keys");
}
auto keyset = absl::make_unique<Keyset>();
for (const PemKey& pem_key : pem_serialized_keys_) {
// Parse and add the new key to the keyset.
switch (pem_key.parameters.key_type) {
case PemKeyType::PEM_RSA: {
auto add_rsassa_pss_status = AddRsaSsaPrivateKey(pem_key, keyset.get());
if (!add_rsassa_pss_status.ok()) return add_rsassa_pss_status;
break;
}
default:
return util::Status(absl::StatusCode::kUnimplemented,
"EC Keys Parsing unimplemented");
}
}
// Set the 1st key as primary.
keyset->set_primary_key_id(keyset->key(0).key_id());
return std::move(keyset);
}
util::StatusOr<std::unique_ptr<Keyset>> PublicKeyVerifyPemKeysetReader::Read() {
if (pem_serialized_keys_.empty()) {
return util::Status(absl::StatusCode::kInvalidArgument,
"Empty array of PEM-encoded keys");
}
auto keyset = absl::make_unique<Keyset>();
for (const PemKey& pem_key : pem_serialized_keys_) {
// Parse and add the new key to the keyset.
switch (pem_key.parameters.key_type) {
case PemKeyType::PEM_RSA: {
auto add_rsassa_pss_status = AddRsaSsaPublicKey(pem_key, keyset.get());
if (!add_rsassa_pss_status.ok()) return add_rsassa_pss_status;
break;
}
case PemKeyType::PEM_EC:
auto add_ecdsa_status = AddEcdsaPublicKey(pem_key, keyset.get());
if (!add_ecdsa_status.ok()) return add_ecdsa_status;
}
}
// Set the 1st key as primary.
keyset->set_primary_key_id(keyset->key(0).key_id());
return std::move(keyset);
}
util::StatusOr<std::unique_ptr<EncryptedKeyset>>
SignaturePemKeysetReader::ReadEncrypted() {
return util::Status(absl::StatusCode::kUnimplemented,
"Reading Encrypted PEM is not supported");
}
} // namespace tink
} // namespace crypto
|
; void adt_ListDelete(struct adt_List *list, void *delete)
; CALLER linkage for function pointers
PUBLIC adt_ListDelete
EXTERN adt_ListDelete_callee
EXTERN ASMDISP_ADT_LISTDELETE_CALLEE
.adt_ListDelete
pop bc
pop de
pop hl
push hl
push de
push bc
jp adt_ListDelete_callee + ASMDISP_ADT_LISTDELETE_CALLEE
|
; A127617: Number of walks from (0,0) to (n,n) in the region 0 <= x-y <= 3 with the steps (1,0), (0, 1), (2,0) and (0,2).
; Submitted by Christian Krause
; 1,1,5,22,92,395,1684,7189,30685,130973,559038,2386160,10184931,43472696,185556025,792015257,3380586357,14429474710,61589830404,262886022219,1122085581740,4789437042413,20442921249973,87257234103245,372443097062686,1589711867161816,6785422633755395,28962456197097392,123621462397330097,527657801577826225,2252220206480568549,9613230095928399574,41032485460946363820,175140389473864400203,747557835711701250308,3190827195330390080005,13619519058036458928141,58132668432710865284861
mul $0,2
mov $2,1
lpb $0
sub $0,1
add $5,$1
mov $1,$3
mov $3,2
sub $4,$5
sub $3,$4
mov $4,$2
mov $2,$3
add $5,$4
mov $3,$5
sub $4,2
lpe
mov $0,$4
add $0,1
|
;
; Copyright (c) 2010 The WebM project authors. All Rights Reserved.
;
; Use of this source code is governed by a BSD-style license
; that can be found in the LICENSE file in the root of the source
; tree. An additional intellectual property rights grant can be found
; in the file PATENTS. All contributing project authors may
; be found in the AUTHORS file in the root of the source tree.
;
%include "vpx_ports/x86_abi_support.asm"
%macro STACK_FRAME_CREATE_X3 0
%if ABI_IS_32BIT
%define src_ptr rsi
%define src_stride rax
%define ref_ptr rdi
%define ref_stride rdx
%define end_ptr rcx
%define ret_var rbx
%define result_ptr arg(4)
%define max_err arg(4)
push rbp
mov rbp, rsp
push rsi
push rdi
push rbx
mov rsi, arg(0) ; src_ptr
mov rdi, arg(2) ; ref_ptr
movsxd rax, dword ptr arg(1) ; src_stride
movsxd rdx, dword ptr arg(3) ; ref_stride
%else
%ifidn __OUTPUT_FORMAT__,x64
%define src_ptr rcx
%define src_stride rdx
%define ref_ptr r8
%define ref_stride r9
%define end_ptr r10
%define ret_var r11
%define result_ptr [rsp+8+4*8]
%define max_err [rsp+8+4*8]
%else
%define src_ptr rdi
%define src_stride rsi
%define ref_ptr rdx
%define ref_stride rcx
%define end_ptr r9
%define ret_var r10
%define result_ptr r8
%define max_err r8
%endif
%endif
%endmacro
%macro STACK_FRAME_DESTROY_X3 0
%define src_ptr
%define src_stride
%define ref_ptr
%define ref_stride
%define end_ptr
%define ret_var
%define result_ptr
%define max_err
%if ABI_IS_32BIT
pop rbx
pop rdi
pop rsi
pop rbp
%else
%ifidn __OUTPUT_FORMAT__,x64
%endif
%endif
ret
%endmacro
%macro STACK_FRAME_CREATE_X4 0
%if ABI_IS_32BIT
%define src_ptr rsi
%define src_stride rax
%define r0_ptr rcx
%define r1_ptr rdx
%define r2_ptr rbx
%define r3_ptr rdi
%define ref_stride rbp
%define result_ptr arg(4)
push rbp
mov rbp, rsp
push rsi
push rdi
push rbx
push rbp
mov rdi, arg(2) ; ref_ptr_base
LOAD_X4_ADDRESSES rdi, rcx, rdx, rax, rdi
mov rsi, arg(0) ; src_ptr
movsxd rbx, dword ptr arg(1) ; src_stride
movsxd rbp, dword ptr arg(3) ; ref_stride
xchg rbx, rax
%else
%ifidn __OUTPUT_FORMAT__,x64
%define src_ptr rcx
%define src_stride rdx
%define r0_ptr rsi
%define r1_ptr r10
%define r2_ptr r11
%define r3_ptr r8
%define ref_stride r9
%define result_ptr [rsp+16+4*8]
push rsi
LOAD_X4_ADDRESSES r8, r0_ptr, r1_ptr, r2_ptr, r3_ptr
%else
%define src_ptr rdi
%define src_stride rsi
%define r0_ptr r9
%define r1_ptr r10
%define r2_ptr r11
%define r3_ptr rdx
%define ref_stride rcx
%define result_ptr r8
LOAD_X4_ADDRESSES rdx, r0_ptr, r1_ptr, r2_ptr, r3_ptr
%endif
%endif
%endmacro
%macro STACK_FRAME_DESTROY_X4 0
%define src_ptr
%define src_stride
%define r0_ptr
%define r1_ptr
%define r2_ptr
%define r3_ptr
%define ref_stride
%define result_ptr
%if ABI_IS_32BIT
pop rbx
pop rdi
pop rsi
pop rbp
%else
%ifidn __OUTPUT_FORMAT__,x64
pop rsi
%endif
%endif
ret
%endmacro
%macro PROCESS_16X2X3 5
%if %1==0
movdqa xmm0, XMMWORD PTR [%2]
lddqu xmm5, XMMWORD PTR [%3]
lddqu xmm6, XMMWORD PTR [%3+1]
lddqu xmm7, XMMWORD PTR [%3+2]
psadbw xmm5, xmm0
psadbw xmm6, xmm0
psadbw xmm7, xmm0
%else
movdqa xmm0, XMMWORD PTR [%2]
lddqu xmm1, XMMWORD PTR [%3]
lddqu xmm2, XMMWORD PTR [%3+1]
lddqu xmm3, XMMWORD PTR [%3+2]
psadbw xmm1, xmm0
psadbw xmm2, xmm0
psadbw xmm3, xmm0
paddw xmm5, xmm1
paddw xmm6, xmm2
paddw xmm7, xmm3
%endif
movdqa xmm0, XMMWORD PTR [%2+%4]
lddqu xmm1, XMMWORD PTR [%3+%5]
lddqu xmm2, XMMWORD PTR [%3+%5+1]
lddqu xmm3, XMMWORD PTR [%3+%5+2]
%if %1==0 || %1==1
lea %2, [%2+%4*2]
lea %3, [%3+%5*2]
%endif
psadbw xmm1, xmm0
psadbw xmm2, xmm0
psadbw xmm3, xmm0
paddw xmm5, xmm1
paddw xmm6, xmm2
paddw xmm7, xmm3
%endmacro
%macro PROCESS_8X2X3 5
%if %1==0
movq mm0, QWORD PTR [%2]
movq mm5, QWORD PTR [%3]
movq mm6, QWORD PTR [%3+1]
movq mm7, QWORD PTR [%3+2]
psadbw mm5, mm0
psadbw mm6, mm0
psadbw mm7, mm0
%else
movq mm0, QWORD PTR [%2]
movq mm1, QWORD PTR [%3]
movq mm2, QWORD PTR [%3+1]
movq mm3, QWORD PTR [%3+2]
psadbw mm1, mm0
psadbw mm2, mm0
psadbw mm3, mm0
paddw mm5, mm1
paddw mm6, mm2
paddw mm7, mm3
%endif
movq mm0, QWORD PTR [%2+%4]
movq mm1, QWORD PTR [%3+%5]
movq mm2, QWORD PTR [%3+%5+1]
movq mm3, QWORD PTR [%3+%5+2]
%if %1==0 || %1==1
lea %2, [%2+%4*2]
lea %3, [%3+%5*2]
%endif
psadbw mm1, mm0
psadbw mm2, mm0
psadbw mm3, mm0
paddw mm5, mm1
paddw mm6, mm2
paddw mm7, mm3
%endmacro
%macro LOAD_X4_ADDRESSES 5
mov %2, [%1+REG_SZ_BYTES*0]
mov %3, [%1+REG_SZ_BYTES*1]
mov %4, [%1+REG_SZ_BYTES*2]
mov %5, [%1+REG_SZ_BYTES*3]
%endmacro
%macro PROCESS_16X2X4 8
%if %1==0
movdqa xmm0, XMMWORD PTR [%2]
lddqu xmm4, XMMWORD PTR [%3]
lddqu xmm5, XMMWORD PTR [%4]
lddqu xmm6, XMMWORD PTR [%5]
lddqu xmm7, XMMWORD PTR [%6]
psadbw xmm4, xmm0
psadbw xmm5, xmm0
psadbw xmm6, xmm0
psadbw xmm7, xmm0
%else
movdqa xmm0, XMMWORD PTR [%2]
lddqu xmm1, XMMWORD PTR [%3]
lddqu xmm2, XMMWORD PTR [%4]
lddqu xmm3, XMMWORD PTR [%5]
psadbw xmm1, xmm0
psadbw xmm2, xmm0
psadbw xmm3, xmm0
paddw xmm4, xmm1
lddqu xmm1, XMMWORD PTR [%6]
paddw xmm5, xmm2
paddw xmm6, xmm3
psadbw xmm1, xmm0
paddw xmm7, xmm1
%endif
movdqa xmm0, XMMWORD PTR [%2+%7]
lddqu xmm1, XMMWORD PTR [%3+%8]
lddqu xmm2, XMMWORD PTR [%4+%8]
lddqu xmm3, XMMWORD PTR [%5+%8]
psadbw xmm1, xmm0
psadbw xmm2, xmm0
psadbw xmm3, xmm0
paddw xmm4, xmm1
lddqu xmm1, XMMWORD PTR [%6+%8]
paddw xmm5, xmm2
paddw xmm6, xmm3
%if %1==0 || %1==1
lea %2, [%2+%7*2]
lea %3, [%3+%8*2]
lea %4, [%4+%8*2]
lea %5, [%5+%8*2]
lea %6, [%6+%8*2]
%endif
psadbw xmm1, xmm0
paddw xmm7, xmm1
%endmacro
%macro PROCESS_8X2X4 8
%if %1==0
movq mm0, QWORD PTR [%2]
movq mm4, QWORD PTR [%3]
movq mm5, QWORD PTR [%4]
movq mm6, QWORD PTR [%5]
movq mm7, QWORD PTR [%6]
psadbw mm4, mm0
psadbw mm5, mm0
psadbw mm6, mm0
psadbw mm7, mm0
%else
movq mm0, QWORD PTR [%2]
movq mm1, QWORD PTR [%3]
movq mm2, QWORD PTR [%4]
movq mm3, QWORD PTR [%5]
psadbw mm1, mm0
psadbw mm2, mm0
psadbw mm3, mm0
paddw mm4, mm1
movq mm1, QWORD PTR [%6]
paddw mm5, mm2
paddw mm6, mm3
psadbw mm1, mm0
paddw mm7, mm1
%endif
movq mm0, QWORD PTR [%2+%7]
movq mm1, QWORD PTR [%3+%8]
movq mm2, QWORD PTR [%4+%8]
movq mm3, QWORD PTR [%5+%8]
psadbw mm1, mm0
psadbw mm2, mm0
psadbw mm3, mm0
paddw mm4, mm1
movq mm1, QWORD PTR [%6+%8]
paddw mm5, mm2
paddw mm6, mm3
%if %1==0 || %1==1
lea %2, [%2+%7*2]
lea %3, [%3+%8*2]
lea %4, [%4+%8*2]
lea %5, [%5+%8*2]
lea %6, [%6+%8*2]
%endif
psadbw mm1, mm0
paddw mm7, mm1
%endmacro
;void int vp8_sad16x16x3_sse3(
; unsigned char *src_ptr,
; int src_stride,
; unsigned char *ref_ptr,
; int ref_stride,
; int *results)
global sym(vp8_sad16x16x3_sse3)
sym(vp8_sad16x16x3_sse3):
STACK_FRAME_CREATE_X3
PROCESS_16X2X3 0, src_ptr, ref_ptr, src_stride, ref_stride
PROCESS_16X2X3 1, src_ptr, ref_ptr, src_stride, ref_stride
PROCESS_16X2X3 1, src_ptr, ref_ptr, src_stride, ref_stride
PROCESS_16X2X3 1, src_ptr, ref_ptr, src_stride, ref_stride
PROCESS_16X2X3 1, src_ptr, ref_ptr, src_stride, ref_stride
PROCESS_16X2X3 1, src_ptr, ref_ptr, src_stride, ref_stride
PROCESS_16X2X3 1, src_ptr, ref_ptr, src_stride, ref_stride
PROCESS_16X2X3 2, src_ptr, ref_ptr, src_stride, ref_stride
mov rcx, result_ptr
movq xmm0, xmm5
psrldq xmm5, 8
paddw xmm0, xmm5
movd [rcx], xmm0
;-
movq xmm0, xmm6
psrldq xmm6, 8
paddw xmm0, xmm6
movd [rcx+4], xmm0
;-
movq xmm0, xmm7
psrldq xmm7, 8
paddw xmm0, xmm7
movd [rcx+8], xmm0
STACK_FRAME_DESTROY_X3
;void int vp8_sad16x8x3_sse3(
; unsigned char *src_ptr,
; int src_stride,
; unsigned char *ref_ptr,
; int ref_stride,
; int *results)
global sym(vp8_sad16x8x3_sse3)
sym(vp8_sad16x8x3_sse3):
STACK_FRAME_CREATE_X3
PROCESS_16X2X3 0, src_ptr, ref_ptr, src_stride, ref_stride
PROCESS_16X2X3 1, src_ptr, ref_ptr, src_stride, ref_stride
PROCESS_16X2X3 1, src_ptr, ref_ptr, src_stride, ref_stride
PROCESS_16X2X3 2, src_ptr, ref_ptr, src_stride, ref_stride
mov rcx, result_ptr
movq xmm0, xmm5
psrldq xmm5, 8
paddw xmm0, xmm5
movd [rcx], xmm0
;-
movq xmm0, xmm6
psrldq xmm6, 8
paddw xmm0, xmm6
movd [rcx+4], xmm0
;-
movq xmm0, xmm7
psrldq xmm7, 8
paddw xmm0, xmm7
movd [rcx+8], xmm0
STACK_FRAME_DESTROY_X3
;void int vp8_sad8x16x3_sse3(
; unsigned char *src_ptr,
; int src_stride,
; unsigned char *ref_ptr,
; int ref_stride,
; int *results)
global sym(vp8_sad8x16x3_sse3)
sym(vp8_sad8x16x3_sse3):
STACK_FRAME_CREATE_X3
PROCESS_8X2X3 0, src_ptr, ref_ptr, src_stride, ref_stride
PROCESS_8X2X3 1, src_ptr, ref_ptr, src_stride, ref_stride
PROCESS_8X2X3 1, src_ptr, ref_ptr, src_stride, ref_stride
PROCESS_8X2X3 1, src_ptr, ref_ptr, src_stride, ref_stride
PROCESS_8X2X3 1, src_ptr, ref_ptr, src_stride, ref_stride
PROCESS_8X2X3 1, src_ptr, ref_ptr, src_stride, ref_stride
PROCESS_8X2X3 1, src_ptr, ref_ptr, src_stride, ref_stride
PROCESS_8X2X3 2, src_ptr, ref_ptr, src_stride, ref_stride
mov rcx, result_ptr
punpckldq mm5, mm6
movq [rcx], mm5
movd [rcx+8], mm7
STACK_FRAME_DESTROY_X3
;void int vp8_sad8x8x3_sse3(
; unsigned char *src_ptr,
; int src_stride,
; unsigned char *ref_ptr,
; int ref_stride,
; int *results)
global sym(vp8_sad8x8x3_sse3)
sym(vp8_sad8x8x3_sse3):
STACK_FRAME_CREATE_X3
PROCESS_8X2X3 0, src_ptr, ref_ptr, src_stride, ref_stride
PROCESS_8X2X3 1, src_ptr, ref_ptr, src_stride, ref_stride
PROCESS_8X2X3 1, src_ptr, ref_ptr, src_stride, ref_stride
PROCESS_8X2X3 2, src_ptr, ref_ptr, src_stride, ref_stride
mov rcx, result_ptr
punpckldq mm5, mm6
movq [rcx], mm5
movd [rcx+8], mm7
STACK_FRAME_DESTROY_X3
;void int vp8_sad4x4x3_sse3(
; unsigned char *src_ptr,
; int src_stride,
; unsigned char *ref_ptr,
; int ref_stride,
; int *results)
global sym(vp8_sad4x4x3_sse3)
sym(vp8_sad4x4x3_sse3):
STACK_FRAME_CREATE_X3
movd mm0, DWORD PTR [src_ptr]
movd mm1, DWORD PTR [ref_ptr]
movd mm2, DWORD PTR [src_ptr+src_stride]
movd mm3, DWORD PTR [ref_ptr+ref_stride]
punpcklbw mm0, mm2
punpcklbw mm1, mm3
movd mm4, DWORD PTR [ref_ptr+1]
movd mm5, DWORD PTR [ref_ptr+2]
movd mm2, DWORD PTR [ref_ptr+ref_stride+1]
movd mm3, DWORD PTR [ref_ptr+ref_stride+2]
psadbw mm1, mm0
punpcklbw mm4, mm2
punpcklbw mm5, mm3
psadbw mm4, mm0
psadbw mm5, mm0
lea src_ptr, [src_ptr+src_stride*2]
lea ref_ptr, [ref_ptr+ref_stride*2]
movd mm0, DWORD PTR [src_ptr]
movd mm2, DWORD PTR [ref_ptr]
movd mm3, DWORD PTR [src_ptr+src_stride]
movd mm6, DWORD PTR [ref_ptr+ref_stride]
punpcklbw mm0, mm3
punpcklbw mm2, mm6
movd mm3, DWORD PTR [ref_ptr+1]
movd mm7, DWORD PTR [ref_ptr+2]
psadbw mm2, mm0
paddw mm1, mm2
movd mm2, DWORD PTR [ref_ptr+ref_stride+1]
movd mm6, DWORD PTR [ref_ptr+ref_stride+2]
punpcklbw mm3, mm2
punpcklbw mm7, mm6
psadbw mm3, mm0
psadbw mm7, mm0
paddw mm3, mm4
paddw mm7, mm5
mov rcx, result_ptr
punpckldq mm1, mm3
movq [rcx], mm1
movd [rcx+8], mm7
STACK_FRAME_DESTROY_X3
;unsigned int vp8_sad16x16_sse3(
; unsigned char *src_ptr,
; int src_stride,
; unsigned char *ref_ptr,
; int ref_stride,
; int max_err)
;%define lddqu movdqu
global sym(vp8_sad16x16_sse3)
sym(vp8_sad16x16_sse3):
STACK_FRAME_CREATE_X3
mov end_ptr, 4
pxor xmm7, xmm7
.vp8_sad16x16_sse3_loop:
movdqa xmm0, XMMWORD PTR [src_ptr]
movdqu xmm1, XMMWORD PTR [ref_ptr]
movdqa xmm2, XMMWORD PTR [src_ptr+src_stride]
movdqu xmm3, XMMWORD PTR [ref_ptr+ref_stride]
lea src_ptr, [src_ptr+src_stride*2]
lea ref_ptr, [ref_ptr+ref_stride*2]
movdqa xmm4, XMMWORD PTR [src_ptr]
movdqu xmm5, XMMWORD PTR [ref_ptr]
movdqa xmm6, XMMWORD PTR [src_ptr+src_stride]
psadbw xmm0, xmm1
movdqu xmm1, XMMWORD PTR [ref_ptr+ref_stride]
psadbw xmm2, xmm3
psadbw xmm4, xmm5
psadbw xmm6, xmm1
lea src_ptr, [src_ptr+src_stride*2]
lea ref_ptr, [ref_ptr+ref_stride*2]
paddw xmm7, xmm0
paddw xmm7, xmm2
paddw xmm7, xmm4
paddw xmm7, xmm6
sub end_ptr, 1
jne .vp8_sad16x16_sse3_loop
movq xmm0, xmm7
psrldq xmm7, 8
paddw xmm0, xmm7
movq rax, xmm0
STACK_FRAME_DESTROY_X3
;void vp8_sad16x16x4d_sse3(
; unsigned char *src_ptr,
; int src_stride,
; unsigned char *ref_ptr_base,
; int ref_stride,
; int *results)
global sym(vp8_sad16x16x4d_sse3)
sym(vp8_sad16x16x4d_sse3):
STACK_FRAME_CREATE_X4
PROCESS_16X2X4 0, src_ptr, r0_ptr, r1_ptr, r2_ptr, r3_ptr, src_stride, ref_stride
PROCESS_16X2X4 1, src_ptr, r0_ptr, r1_ptr, r2_ptr, r3_ptr, src_stride, ref_stride
PROCESS_16X2X4 1, src_ptr, r0_ptr, r1_ptr, r2_ptr, r3_ptr, src_stride, ref_stride
PROCESS_16X2X4 1, src_ptr, r0_ptr, r1_ptr, r2_ptr, r3_ptr, src_stride, ref_stride
PROCESS_16X2X4 1, src_ptr, r0_ptr, r1_ptr, r2_ptr, r3_ptr, src_stride, ref_stride
PROCESS_16X2X4 1, src_ptr, r0_ptr, r1_ptr, r2_ptr, r3_ptr, src_stride, ref_stride
PROCESS_16X2X4 1, src_ptr, r0_ptr, r1_ptr, r2_ptr, r3_ptr, src_stride, ref_stride
PROCESS_16X2X4 2, src_ptr, r0_ptr, r1_ptr, r2_ptr, r3_ptr, src_stride, ref_stride
%if ABI_IS_32BIT
pop rbp
%endif
mov rcx, result_ptr
movq xmm0, xmm4
psrldq xmm4, 8
paddw xmm0, xmm4
movd [rcx], xmm0
;-
movq xmm0, xmm5
psrldq xmm5, 8
paddw xmm0, xmm5
movd [rcx+4], xmm0
;-
movq xmm0, xmm6
psrldq xmm6, 8
paddw xmm0, xmm6
movd [rcx+8], xmm0
;-
movq xmm0, xmm7
psrldq xmm7, 8
paddw xmm0, xmm7
movd [rcx+12], xmm0
STACK_FRAME_DESTROY_X4
;void vp8_sad16x8x4d_sse3(
; unsigned char *src_ptr,
; int src_stride,
; unsigned char *ref_ptr_base,
; int ref_stride,
; int *results)
global sym(vp8_sad16x8x4d_sse3)
sym(vp8_sad16x8x4d_sse3):
STACK_FRAME_CREATE_X4
PROCESS_16X2X4 0, src_ptr, r0_ptr, r1_ptr, r2_ptr, r3_ptr, src_stride, ref_stride
PROCESS_16X2X4 1, src_ptr, r0_ptr, r1_ptr, r2_ptr, r3_ptr, src_stride, ref_stride
PROCESS_16X2X4 1, src_ptr, r0_ptr, r1_ptr, r2_ptr, r3_ptr, src_stride, ref_stride
PROCESS_16X2X4 2, src_ptr, r0_ptr, r1_ptr, r2_ptr, r3_ptr, src_stride, ref_stride
%if ABI_IS_32BIT
pop rbp
%endif
mov rcx, result_ptr
movq xmm0, xmm4
psrldq xmm4, 8
paddw xmm0, xmm4
movd [rcx], xmm0
;-
movq xmm0, xmm5
psrldq xmm5, 8
paddw xmm0, xmm5
movd [rcx+4], xmm0
;-
movq xmm0, xmm6
psrldq xmm6, 8
paddw xmm0, xmm6
movd [rcx+8], xmm0
;-
movq xmm0, xmm7
psrldq xmm7, 8
paddw xmm0, xmm7
movd [rcx+12], xmm0
STACK_FRAME_DESTROY_X4
;void int vp8_sad8x16x4d_sse3(
; unsigned char *src_ptr,
; int src_stride,
; unsigned char *ref_ptr,
; int ref_stride,
; int *results)
global sym(vp8_sad8x16x4d_sse3)
sym(vp8_sad8x16x4d_sse3):
STACK_FRAME_CREATE_X4
PROCESS_8X2X4 0, src_ptr, r0_ptr, r1_ptr, r2_ptr, r3_ptr, src_stride, ref_stride
PROCESS_8X2X4 1, src_ptr, r0_ptr, r1_ptr, r2_ptr, r3_ptr, src_stride, ref_stride
PROCESS_8X2X4 1, src_ptr, r0_ptr, r1_ptr, r2_ptr, r3_ptr, src_stride, ref_stride
PROCESS_8X2X4 1, src_ptr, r0_ptr, r1_ptr, r2_ptr, r3_ptr, src_stride, ref_stride
PROCESS_8X2X4 1, src_ptr, r0_ptr, r1_ptr, r2_ptr, r3_ptr, src_stride, ref_stride
PROCESS_8X2X4 1, src_ptr, r0_ptr, r1_ptr, r2_ptr, r3_ptr, src_stride, ref_stride
PROCESS_8X2X4 1, src_ptr, r0_ptr, r1_ptr, r2_ptr, r3_ptr, src_stride, ref_stride
PROCESS_8X2X4 2, src_ptr, r0_ptr, r1_ptr, r2_ptr, r3_ptr, src_stride, ref_stride
%if ABI_IS_32BIT
pop rbp
%endif
mov rcx, result_ptr
punpckldq mm4, mm5
punpckldq mm6, mm7
movq [rcx], mm4
movq [rcx+8], mm6
STACK_FRAME_DESTROY_X4
;void int vp8_sad8x8x4d_sse3(
; unsigned char *src_ptr,
; int src_stride,
; unsigned char *ref_ptr,
; int ref_stride,
; int *results)
global sym(vp8_sad8x8x4d_sse3)
sym(vp8_sad8x8x4d_sse3):
STACK_FRAME_CREATE_X4
PROCESS_8X2X4 0, src_ptr, r0_ptr, r1_ptr, r2_ptr, r3_ptr, src_stride, ref_stride
PROCESS_8X2X4 1, src_ptr, r0_ptr, r1_ptr, r2_ptr, r3_ptr, src_stride, ref_stride
PROCESS_8X2X4 1, src_ptr, r0_ptr, r1_ptr, r2_ptr, r3_ptr, src_stride, ref_stride
PROCESS_8X2X4 2, src_ptr, r0_ptr, r1_ptr, r2_ptr, r3_ptr, src_stride, ref_stride
%if ABI_IS_32BIT
pop rbp
%endif
mov rcx, result_ptr
punpckldq mm4, mm5
punpckldq mm6, mm7
movq [rcx], mm4
movq [rcx+8], mm6
STACK_FRAME_DESTROY_X4
;void int vp8_sad4x4x4d_sse3(
; unsigned char *src_ptr,
; int src_stride,
; unsigned char *ref_ptr,
; int ref_stride,
; int *results)
global sym(vp8_sad4x4x4d_sse3)
sym(vp8_sad4x4x4d_sse3):
STACK_FRAME_CREATE_X4
movd mm0, DWORD PTR [src_ptr]
movd mm1, DWORD PTR [r0_ptr]
movd mm2, DWORD PTR [src_ptr+src_stride]
movd mm3, DWORD PTR [r0_ptr+ref_stride]
punpcklbw mm0, mm2
punpcklbw mm1, mm3
movd mm4, DWORD PTR [r1_ptr]
movd mm5, DWORD PTR [r2_ptr]
movd mm6, DWORD PTR [r3_ptr]
movd mm2, DWORD PTR [r1_ptr+ref_stride]
movd mm3, DWORD PTR [r2_ptr+ref_stride]
movd mm7, DWORD PTR [r3_ptr+ref_stride]
psadbw mm1, mm0
punpcklbw mm4, mm2
punpcklbw mm5, mm3
punpcklbw mm6, mm7
psadbw mm4, mm0
psadbw mm5, mm0
psadbw mm6, mm0
lea src_ptr, [src_ptr+src_stride*2]
lea r0_ptr, [r0_ptr+ref_stride*2]
lea r1_ptr, [r1_ptr+ref_stride*2]
lea r2_ptr, [r2_ptr+ref_stride*2]
lea r3_ptr, [r3_ptr+ref_stride*2]
movd mm0, DWORD PTR [src_ptr]
movd mm2, DWORD PTR [r0_ptr]
movd mm3, DWORD PTR [src_ptr+src_stride]
movd mm7, DWORD PTR [r0_ptr+ref_stride]
punpcklbw mm0, mm3
punpcklbw mm2, mm7
movd mm3, DWORD PTR [r1_ptr]
movd mm7, DWORD PTR [r2_ptr]
psadbw mm2, mm0
%if ABI_IS_32BIT
mov rax, rbp
pop rbp
%define ref_stride rax
%endif
mov rsi, result_ptr
paddw mm1, mm2
movd [rsi], mm1
movd mm2, DWORD PTR [r1_ptr+ref_stride]
movd mm1, DWORD PTR [r2_ptr+ref_stride]
punpcklbw mm3, mm2
punpcklbw mm7, mm1
psadbw mm3, mm0
psadbw mm7, mm0
movd mm2, DWORD PTR [r3_ptr]
movd mm1, DWORD PTR [r3_ptr+ref_stride]
paddw mm3, mm4
paddw mm7, mm5
movd [rsi+4], mm3
punpcklbw mm2, mm1
movd [rsi+8], mm7
psadbw mm2, mm0
paddw mm2, mm6
movd [rsi+12], mm2
STACK_FRAME_DESTROY_X4
|
; A108741: Member r=100 of the family of Chebyshev sequences S_r(n) defined in A092184.
; 0,1,100,9801,960400,94109401,9221760900,903638458801,88547347201600,8676736387298001,850231618608002500,83314021887196947001,8163923913326692803600,799981229484128697805801,78389996565531285692164900,7681419682192581869134354401,752700738858307491889474566400
seq $0,87799 ; a(n) = 10*a(n-1) - a(n-2), starting with a(0) = 2 and a(1) = 10.
pow $0,2
div $0,96
|
; A004775: Numbers k such that the binary expansion of k does not end in 011.
; 0,1,2,3,4,5,6,7,8,9,10,12,13,14,15,16,17,18,20,21,22,23,24,25,26,28,29,30,31,32,33,34,36,37,38,39,40,41,42,44,45,46,47,48,49,50,52,53,54,55,56,57,58,60,61,62,63,64,65,66,68,69,70,71,72,73,74,76,77,78,79,80,81,82,84,85,86,87,88,89,90,92,93,94,95,96,97,98,100,101,102,103,104,105,106,108,109,110,111,112,113,114,116,117,118,119,120,121,122,124,125,126,127,128,129,130,132,133,134,135,136,137,138,140,141,142,143,144,145,146,148,149,150,151,152,153,154,156,157,158,159,160,161,162,164,165,166,167,168,169,170,172,173,174,175,176,177,178,180,181,182,183,184,185,186,188,189,190,191,192,193,194,196,197,198,199,200,201,202,204,205,206,207,208,209,210,212,213,214,215,216,217,218,220,221,222,223,224,225,226,228,229,230,231,232,233,234,236,237,238,239,240,241,242,244,245,246,247,248,249,250,252,253,254,255,256,257,258,260,261,262,263,264,265,266,268,269,270,271,272,273,274,276,277,278,279,280,281,282,284
mov $1,$0
sub $0,4
div $0,7
add $1,$0
|
; #########################################################################
;
; blit.asm - Assembly file for EECS205 Assignment 3
;
;
; #########################################################################
.586
.MODEL FLAT,STDCALL
.STACK 4096
option casemap :none ; case sensitive
include stars.inc
include lines.inc
include trig.inc
include blit.inc
include game.inc
;; Prototypes for helpers in trig.asm
FixedMultiply PROTO STDCALL a:FXPT, b:FXPT
FixedSubtract PROTO STDCALL a:FXPT, b:FXPT
FixedAdd PROTO STDCALL a:FXPT, b:FXPT
.DATA
ONE_HALF = 00008000h ;; One half as a fixed point
SAVE DWORD 5 ;; Save location for esp
BSAVE DWORD 5 ;; Save location for ebp
;; Those last two comments sound insane, I know. See my comment in RotateBlit
.CODE
;; Helper function: Converts an integer to an FXPT
ToFixedPoint PROC USES ebx a:SDWORD
mov eax, a
mov ebx, 080000000h
and ebx, eax ;; ebx contains only the sign bit
shl eax, 16 ;; eax is now moved into only containing the lower 16 bits as an integer FXPT value
cmp ebx, 080000000h
jne DONE ;; If the sign bit was unset, we're done
;; If the sign bit was set, we need to make sure it is set in the result
or eax, 080000000h
;; Fallthrough
DONE:
ret
ToFixedPoint ENDP
;; Helper function: Converts an FXPT to an SDWORD
FromFixedPoint PROC a:FXPT
mov eax, a
sar eax, 16 ;; Preserve sign of eax
ret
FromFixedPoint ENDP
;; Helper function: Convert an index into a 2D array into a 1D index
Index2D PROC x:DWORD, y:DWORD, xWidth:DWORD
mov eax, y
imul eax, xWidth
add eax, x
ret
Index2D ENDP
DrawPixel PROC USES eax ebx x:DWORD, y:DWORD, color:DWORD
;; Check for x out of range
cmp x, SCREEN_WIDTH-1
ja ERROR ;; Unsigned compare means that negatives (sign bit set) are treated as very large numbers
;; Check for y out of range
cmp y, SCREEN_HEIGHT-1
ja ERROR ;; Unsigned compare means that negatives (sign bit set) are treated as very large numbers
;; First, the address to write to
mov ebx, ScreenBitsPtr ;; Pointer arithmetic inbound
add ebx, x ;; Add offset into column
imul eax, y, 640 ;; Compute offset for number of rows
add ebx, eax ;; Add offset into pointer
;; Now, we get the color
;; We've been passed /a/ color...
;; But it's a DWORD, and we need a byte. We're going to take the lowest one.
mov eax, color ;; Evil register byte-level "hacking"
;; al now contains our color byte. Told you it was evil...
;; Finally, move the color into the screen buffer at the computed position
mov BYTE PTR [ebx], al
ERROR: ;; Just return on error...
;; Technically, we should signal an error somehow, but I don't want to overwrite eax for a return value, and I am /not/ gonna touch implementing exceptions.
ret ; Don't delete this line!!!
DrawPixel ENDP
;; Bitmap with zero rotation
BasicBlit PROC USES eax ebx ecx edx esi edi ptrBitmap:PTR EECS205BITMAP , xcenter:DWORD, ycenter:DWORD
LOCAL halfwidth:SDWORD, halfheight:SDWORD, dstWidth:DWORD, dstX:DWORD, dstY:DWORD
;; Use a register for faster lookup
mov esi, ptrBitmap
;; Fill in local variables
;; halfwidth
mov eax, (EECS205BITMAP PTR [esi]).dwWidth
shr eax, 1
mov halfwidth, eax
;; halfheight
mov eax, (EECS205BITMAP PTR [esi]).dwHeight
shr eax, 1
mov halfheight, eax
;; dstWidth
mov eax, (EECS205BITMAP PTR [esi]).dwWidth
add eax, (EECS205BITMAP PTR [esi]).dwHeight
mov dstWidth, eax
;; For loops
;; These are in the wrong order for proper cache coherency. But oh well
;; Outer loop initializer
mov dstX, eax
neg dstX
OUTER: ;; Outer loop condition
mov eax, dstX
cmp eax, dstWidth
jge DONE
;; Inner loop initializer
mov eax, dstWidth
neg eax
mov dstY, eax
INNER: ;; Inner loop condition
mov eax, dstY
cmp eax, dstWidth
jge OINCR ;; Jump to outer loop increment
;; Inner loop
;; Big condition chain on whether to draw
;; If any of the conditions are false (since they are all AND'd together), skip to the inner increment (IINCR)
;; If dstX<0, do not draw
mov edx, dstX
cmp edx, 0
jl IINCR
;; if dstX>=bitmap width, do not draw
cmp edx, (EECS205BITMAP PTR [esi]).dwWidth
jge IINCR
;; If dstY<0, do not draw
mov ebx, dstY
cmp ebx, 0
jl IINCR
;; IF dstY>=bitmap height, do not draw
cmp ebx, (EECS205BITMAP PTR [esi]).dwHeight
jge IINCR
;; If (xcenter+dstX-halfwidth)<0, do not draw
mov eax, xcenter
add eax, dstX
sub eax, halfwidth
cmp eax, 0
jl IINCR
;; IF (xcenter+dstX-halfwidth)>=639, do not draw
cmp eax, SCREEN_WIDTH-1
jge IINCR
;; If (ycenter+dstY-halfheight)<0, do not draw
mov eax, ycenter
add eax, dstY
sub eax, halfheight
cmp eax, 0
jl IINCR
;; If (ycenter+dstY-halfheight)>=479, do not draw
cmp eax, SCREEN_HEIGHT-1
jge IINCR
;; If the target pixel is not transparent
INVOKE Index2D, dstX, dstY, (EECS205BITMAP PTR [esi]).dwWidth
;; eax holds the proper index into the array of pixels
mov ecx, (EECS205BITMAP PTR [esi]).lpBytes
mov al, BYTE PTR [ecx+eax] ;; al holds the bitmap pixel
cmp al, (EECS205BITMAP PTR [esi]).bTransparent
je IINCR
;; If we're here, then we're allowed to draw
;; We'll use ebx for x coordinate, and edx for y coordinate
;; al holds our color value
;; Compute x coordinate
mov ebx, xcenter
add ebx, dstX
sub ebx, halfwidth
;; Compute y coordinate
mov edx, ycenter
add edx, dstY
sub edx, halfheight
;; Now draw
INVOKE DrawPixel, ebx, edx, al
;; Fallthrough to the increment
IINCR: ;; Inner increment
inc dstY
jmp INNER
OINCR: ;; Outer increment
inc dstX
jmp OUTER
DONE: ;; Exiting the outer loop is just returning from the function
ret
BasicBlit ENDP
;; Bitmap with 180 degrees of rotation
UpsideDownBlit PROC USES eax ebx ecx edx esi edi ptrBitmap:PTR EECS205BITMAP , xcenter:DWORD, ycenter:DWORD
LOCAL halfwidth:SDWORD, halfheight:SDWORD, dstWidth:DWORD, dstX:DWORD, dstY:DWORD
;; Use a register for faster lookup
mov esi, ptrBitmap
;; Fill in local variables
;; halfwidth
mov eax, (EECS205BITMAP PTR [esi]).dwWidth
shr eax, 1
mov halfwidth, eax
;; halfheight
mov eax, (EECS205BITMAP PTR [esi]).dwHeight
shr eax, 1
mov halfheight, eax
;; dstWidth
mov eax, (EECS205BITMAP PTR [esi]).dwWidth
add eax, (EECS205BITMAP PTR [esi]).dwHeight
mov dstWidth, eax
;; For loops
;; These are in the wrong order for proper cache coherency. But oh well
;; Outer loop initializer
mov dstX, eax
neg dstX
OUTER: ;; Outer loop condition
mov eax, dstX
cmp eax, dstWidth
jge DONE
;; Inner loop initializer
mov eax, dstWidth
neg eax
mov dstY, eax
INNER: ;; Inner loop condition
mov eax, dstY
cmp eax, dstWidth
jge OINCR ;; Jump to outer loop increment
;; Inner loop
;; Big condition chain on whether to draw
;; If any of the conditions are false (since they are all AND'd together), skip to the inner increment (IINCR)
;; If dstX<0, do not draw
mov edx, dstX
cmp edx, 0
jl IINCR
;; if dstX>=bitmap width, do not draw
cmp edx, (EECS205BITMAP PTR [esi]).dwWidth
jge IINCR
;; If dstY<0, do not draw
mov ebx, dstY
cmp ebx, 0
jl IINCR
;; IF dstY>=bitmap height, do not draw
cmp ebx, (EECS205BITMAP PTR [esi]).dwHeight
jge IINCR
;; If (xcenter+dstX-halfwidth)<0, do not draw
mov eax, xcenter
add eax, dstX
sub eax, halfwidth
cmp eax, 0
jl IINCR
;; IF (xcenter+dstX-halfwidth)>=639, do not draw
cmp eax, SCREEN_WIDTH-1
jge IINCR
;; If (ycenter+dstY-halfheight)<0, do not draw
mov eax, ycenter
add eax, dstY
sub eax, halfheight
cmp eax, 0
jl IINCR
;; If (ycenter+dstY-halfheight)>=479, do not draw
cmp eax, SCREEN_HEIGHT-1
jge IINCR
;; If the target pixel is not transparent
INVOKE Index2D, dstX, dstY, (EECS205BITMAP PTR [esi]).dwWidth
;; eax holds the proper index into the array of pixels
mov ecx, (EECS205BITMAP PTR [esi]).lpBytes
mov al, BYTE PTR [ecx+eax] ;; al holds the bitmap pixel
cmp al, (EECS205BITMAP PTR [esi]).bTransparent
je IINCR
;; If we're here, then we're allowed to draw
;; We'll use ebx for x coordinate, and edx for y coordinate
;; al holds our color value
;; Compute x coordinate
mov ebx, xcenter
sub ebx, dstX
add ebx, halfwidth
;; Compute y coordinate
mov edx, ycenter
sub edx, dstY
add edx, halfheight
;; Now draw
INVOKE DrawPixel, ebx, edx, al
;; Fallthrough to the increment
IINCR: ;; Inner increment
inc dstY
jmp INNER
OINCR: ;; Outer increment
inc dstX
jmp OUTER
DONE: ;; Exiting the outer loop is just returning from the function
ret
UpsideDownBlit ENDP
;; Bitmap with 90 degrees of rotation
LeftBlit PROC USES eax ebx ecx edx esi edi ptrBitmap:PTR EECS205BITMAP , xcenter:DWORD, ycenter:DWORD
LOCAL halfwidth:SDWORD, halfheight:SDWORD, dstWidth:DWORD, dstX:DWORD, dstY:DWORD
;; Use a register for faster lookup
mov esi, ptrBitmap
;; Fill in local variables
;; halfwidth
mov eax, (EECS205BITMAP PTR [esi]).dwWidth
shr eax, 1
mov halfwidth, eax
;; halfheight
mov eax, (EECS205BITMAP PTR [esi]).dwHeight
shr eax, 1
mov halfheight, eax
;; dstWidth
mov eax, (EECS205BITMAP PTR [esi]).dwWidth
add eax, (EECS205BITMAP PTR [esi]).dwHeight
mov dstWidth, eax
;; For loops
;; These are in the wrong order for proper cache coherency. But oh well
;; Outer loop initializer
mov dstX, eax
neg dstX
OUTER: ;; Outer loop condition
mov eax, dstX
cmp eax, dstWidth
jge DONE
;; Inner loop initializer
mov eax, dstWidth
neg eax
mov dstY, eax
INNER: ;; Inner loop condition
mov eax, dstY
cmp eax, dstWidth
jge OINCR ;; Jump to outer loop increment
;; Inner loop
;; Big condition chain on whether to draw
;; If any of the conditions are false (since they are all AND'd together), skip to the inner increment (IINCR)
;; If dstX<0, do not draw
mov edx, dstX
cmp edx, 0
jl IINCR
;; if dstX>=bitmap width, do not draw
cmp edx, (EECS205BITMAP PTR [esi]).dwWidth
jge IINCR
;; If dstY<0, do not draw
mov ebx, dstY
cmp ebx, 0
jl IINCR
;; IF dstY>=bitmap height, do not draw
cmp ebx, (EECS205BITMAP PTR [esi]).dwHeight
jge IINCR
;; If (xcenter+dstX-halfwidth)<0, do not draw
mov eax, xcenter
add eax, dstX
sub eax, halfwidth
cmp eax, 0
jl IINCR
;; IF (xcenter+dstX-halfwidth)>=639, do not draw
cmp eax, SCREEN_WIDTH-1
jge IINCR
;; If (ycenter+dstY-halfheight)<0, do not draw
mov eax, ycenter
add eax, dstY
sub eax, halfheight
cmp eax, 0
jl IINCR
;; If (ycenter+dstY-halfheight)>=479, do not draw
cmp eax, SCREEN_HEIGHT-1
jge IINCR
;; If the target pixel is not transparent
INVOKE Index2D, dstX, dstY, (EECS205BITMAP PTR [esi]).dwWidth
;; eax holds the proper index into the array of pixels
mov ecx, (EECS205BITMAP PTR [esi]).lpBytes
mov al, BYTE PTR [ecx+eax] ;; al holds the bitmap pixel
cmp al, (EECS205BITMAP PTR [esi]).bTransparent
je IINCR
;; If we're here, then we're allowed to draw
;; We'll use ebx for x coordinate, and edx for y coordinate
;; al holds our color value
;; Compute x coordinate
mov ebx, xcenter
add ebx, dstY
sub ebx, halfheight
;; Compute y coordinate
mov edx, ycenter
sub edx, dstX
add edx, halfwidth
;; Now draw
INVOKE DrawPixel, ebx, edx, al
;; Fallthrough to the increment
IINCR: ;; Inner increment
inc dstY
jmp INNER
OINCR: ;; Outer increment
inc dstX
jmp OUTER
DONE: ;; Exiting the outer loop is just returning from the function
ret
LeftBlit ENDP
;; Bitmap with 270 degrees of rotation
RightBlit PROC USES eax ebx ecx edx esi edi ptrBitmap:PTR EECS205BITMAP , xcenter:DWORD, ycenter:DWORD
LOCAL halfwidth:SDWORD, halfheight:SDWORD, dstWidth:DWORD, dstX:DWORD, dstY:DWORD
;; Use a register for faster lookup
mov esi, ptrBitmap
;; Fill in local variables
;; halfwidth
mov eax, (EECS205BITMAP PTR [esi]).dwWidth
shr eax, 1
mov halfwidth, eax
;; halfheight
mov eax, (EECS205BITMAP PTR [esi]).dwHeight
shr eax, 1
mov halfheight, eax
;; dstWidth
mov eax, (EECS205BITMAP PTR [esi]).dwWidth
add eax, (EECS205BITMAP PTR [esi]).dwHeight
mov dstWidth, eax
;; For loops
;; These are in the wrong order for proper cache coherency. But oh well
;; Outer loop initializer
mov dstX, eax
neg dstX
OUTER: ;; Outer loop condition
mov eax, dstX
cmp eax, dstWidth
jge DONE
;; Inner loop initializer
mov eax, dstWidth
neg eax
mov dstY, eax
INNER: ;; Inner loop condition
mov eax, dstY
cmp eax, dstWidth
jge OINCR ;; Jump to outer loop increment
;; Inner loop
;; Big condition chain on whether to draw
;; If any of the conditions are false (since they are all AND'd together), skip to the inner increment (IINCR)
;; If dstX<0, do not draw
mov edx, dstX
cmp edx, 0
jl IINCR
;; if dstX>=bitmap width, do not draw
cmp edx, (EECS205BITMAP PTR [esi]).dwWidth
jge IINCR
;; If dstY<0, do not draw
mov ebx, dstY
cmp ebx, 0
jl IINCR
;; IF dstY>=bitmap height, do not draw
cmp ebx, (EECS205BITMAP PTR [esi]).dwHeight
jge IINCR
;; If (xcenter+dstX-halfwidth)<0, do not draw
mov eax, xcenter
add eax, dstX
sub eax, halfwidth
cmp eax, 0
jl IINCR
;; IF (xcenter+dstX-halfwidth)>=639, do not draw
cmp eax, SCREEN_WIDTH-1
jge IINCR
;; If (ycenter+dstY-halfheight)<0, do not draw
mov eax, ycenter
add eax, dstY
sub eax, halfheight
cmp eax, 0
jl IINCR
;; If (ycenter+dstY-halfheight)>=479, do not draw
cmp eax, SCREEN_HEIGHT-1
jge IINCR
;; If the target pixel is not transparent
INVOKE Index2D, dstX, dstY, (EECS205BITMAP PTR [esi]).dwWidth
;; eax holds the proper index into the array of pixels
mov ecx, (EECS205BITMAP PTR [esi]).lpBytes
mov al, BYTE PTR [ecx+eax] ;; al holds the bitmap pixel
cmp al, (EECS205BITMAP PTR [esi]).bTransparent
je IINCR
;; If we're here, then we're allowed to draw
;; We'll use ebx for x coordinate, and edx for y coordinate
;; al holds our color value
;; Compute x coordinate
mov ebx, xcenter
sub ebx, dstY
add ebx, halfheight
;; Compute y coordinate
mov edx, ycenter
add edx, dstX
sub edx, halfwidth
;; Now draw
INVOKE DrawPixel, ebx, edx, al
;; Fallthrough to the increment
IINCR: ;; Inner increment
inc dstY
jmp INNER
OINCR: ;; Outer increment
inc dstX
jmp OUTER
DONE: ;; Exiting the outer loop is just returning from the function
ret
RightBlit ENDP
;; Bitmap with arbitrary rotation
RotateBlit PROC uses eax ebx ecx edx esi lpBmp:PTR EECS205BITMAP, xcenter:DWORD, ycenter:DWORD, angle:FXPT
LOCAL cosa:FXPT, sina:FXPT, shiftX:SDWORD, shiftY:SDWORD, dstWidth:DWORD, dstX:DWORD, dstY:DWORD
;; FOR SOME UNGODLY REASON...
;; This function messes up esp and/or ebp.
;; In such a way that actually running the draw code twice hangs forever on the second time. Probably because it returns to the wrong address.
;; I can't figure out why. It's probably not a good thing.
;; But I can remove the worst of the symptoms, by saving the values here and restoring them before return
;; .... Yeah, I dunno either
mov edi, OFFSET SAVE
mov [edi], esp
mov edi, OFFSET BSAVE
mov [edi], ebp
;; Slight optimization: Use BasicBlit for about zero rotation
;; This avoids a lot of slow fixed point math
cmp angle, EPSILON
jg SKIP0
cmp angle, -EPSILON
jl SKIP0
INVOKE BasicBlit, lpBmp, xcenter, ycenter
jmp DONE
SKIP0:
;; Use UpsideDownBlit for about-half rotations
cmp angle, 205887+EPSILON
jg SKIP1
cmp angle, 205887-EPSILON
jl SKIP1
INVOKE UpsideDownBlit, lpBmp, xcenter, ycenter
jmp DONE
SKIP1:
;; Use LeftBlit for about one-quarter rotations
cmp angle, 102943+EPSILON
jg SKIP2
cmp angle, 102943-EPSILON
jl SKIP2
INVOKE LeftBlit, lpBmp, xcenter, ycenter
jmp DONE
SKIP2:
;; Use RightBlit for about three-quarter rotations
cmp angle, 308831+EPSILON
jg SKIP3
cmp angle, 308831-EPSILON
jl SKIP3
INVOKE RightBlit, lpBmp, xcenter, ycenter
jmp DONE
SKIP3:
;; Okay, this part is weird.
;; I admit it. I have no excuse, only an explanation.
;; When I got RotateBlit working, the star rotated in the opposite direction of the arrow key.
;; I wasn't sure if that was correct behavior - It's what happens when the local coordinate system of the star is rotated in the correct direction....
;; But I disliked it.
;; So, I've implemented this fix. I distort the coordinate system again
;; I add PI_HALF (this is that constant's value)
;; Then swap sin and cos
;; This results in rotation in the correct direction (because it's occurring on a flipped coordinate system)
;; With the angles offset so that the star starts in the correct orientation
INVOKE FixedAdd, angle, 102943
mov angle, eax
;; Yeah, I know, it's silly.
;; But you know what they say: If it looks stupid, but it works....
;; It's probably stupid.
;; But!
;; It works.
;; This assignment is going to be four days late in an hour, sue me.
;; Fill in local variables
INVOKE FixedSin, angle
mov cosa, eax
INVOKE FixedCos, angle
mov sina, eax
;; Use a register for faster lookup
mov esi, lpBmp
;; Compute shiftX
mov eax, (EECS205BITMAP PTR [esi]).dwWidth
INVOKE ToFixedPoint, eax
INVOKE FixedMultiply, eax, cosa
INVOKE FixedMultiply, eax, ONE_HALF
mov shiftX, eax ;; First part of the shiftX expression
mov eax, (EECS205BITMAP PTR [esi]).dwHeight
INVOKE ToFixedPoint, eax
INVOKE FixedMultiply, eax, sina
INVOKE FixedMultiply, eax, ONE_HALF
INVOKE FixedSubtract, shiftX, eax ;; shiftX is now complete....
INVOKE FromFixedPoint, eax ;; But it needs to be an integer
mov shiftX, eax ;; Now, it's correct.
;; Similar code for shiftY
mov eax, (EECS205BITMAP PTR [esi]).dwHeight
INVOKE ToFixedPoint, eax
INVOKE FixedMultiply, eax, cosa
INVOKE FixedMultiply, eax, ONE_HALF
mov shiftY, eax ;; First part of the shiftY expression
mov eax, (EECS205BITMAP PTR [esi]).dwWidth
INVOKE ToFixedPoint, eax
INVOKE FixedMultiply, eax, sina
INVOKE FixedMultiply, eax, ONE_HALF
INVOKE FixedAdd, shiftY, eax ;; shiftY is now complete...
INVOKE FromFixedPoint, eax ;; But it needs to be an integer
mov shiftY, eax ;; Now, it's correct.
;; Now compute dstWidth
mov eax, (EECS205BITMAP PTR [esi]).dwWidth
add eax, (EECS205BITMAP PTR [esi]).dwHeight
mov dstWidth, eax
;; For loops
;; These are in the wrong order for proper cache coherency. But oh well
;; Outer loop initializer
mov dstX, eax
neg dstX
OUTER: ;; Outer loop condition
mov eax, dstX
cmp eax, dstWidth
jge DONE
;; Inner loop initializer
mov eax, dstWidth
neg eax
mov dstY, eax
INNER: ;; Inner loop condition
mov eax, dstY
cmp eax, dstWidth
jge OINCR ;; Jump to outer loop increment
;; Inner loop
;; First, srcX
mov eax, dstX ;; edx will be srcX, but eax will be used to compute it.
INVOKE ToFixedPoint, eax
INVOKE FixedMultiply, eax, cosa
mov ebx, eax ;; Temporarily use ebx for storage
mov eax, dstY
INVOKE ToFixedPoint, eax
INVOKE FixedMultiply, eax, sina
INVOKE FixedAdd, ebx, eax ;; eax now holds srcX
INVOKE FromFixedPoint, eax
mov edx, eax ;; Move srcX into place
;; Now, srcY
mov eax, dstY ;; Even though ebx will be dstY, use eax for calculations
INVOKE ToFixedPoint, eax
INVOKE FixedMultiply, eax, cosa
mov ebx, eax
mov eax, dstX
INVOKE ToFixedPoint, eax
INVOKE FixedMultiply, eax, sina
INVOKE FixedSubtract, ebx, eax
INVOKE FromFixedPoint, eax
mov ebx, eax ;; ebx now holds srcY
;; Big condition chain on whether to draw
;; If any of the conditions are false (since they are all AND'd together), skip to the inner increment (IINCR)
;; If srcX<0, do not draw
cmp edx, 0
jl IINCR
;; if srcX>=bitmap width, do not draw
cmp edx, (EECS205BITMAP PTR [esi]).dwWidth
jge IINCR
;; If srcY<0, do not draw
cmp ebx, 0
jl IINCR
;; IF srcY>=bitmap height, do not draw
cmp ebx, (EECS205BITMAP PTR [esi]).dwHeight
jge IINCR
;; If (xcenter+dstX-shiftX)<0, do not draw
mov eax, xcenter
add eax, dstX
sub eax, shiftX
cmp eax, 0
jl IINCR
;; IF (xcenter+dstX-shiftX)>=639, do not draw
cmp eax, SCREEN_WIDTH-1
jge IINCR
;; If (ycenter+dstY-shiftY)<0, do not draw
mov eax, ycenter
add eax, dstY
sub eax, shiftY
cmp eax, 0
jl IINCR
;; If (ycenter+dstY-shiftY)>=479, do not draw
cmp eax, SCREEN_HEIGHT-1
jge IINCR
;; If the target pixel is not transparent
INVOKE Index2D, edx, ebx, (EECS205BITMAP PTR [esi]).dwWidth
;; eax holds the proper index into the array of pixels
mov ecx, (EECS205BITMAP PTR [esi]).lpBytes
mov al, BYTE PTR [ecx+eax] ;; al holds the bitmap pixel
cmp al, (EECS205BITMAP PTR [esi]).bTransparent
je IINCR
;; If we're here, then we're allowed to draw
;; We'll use ebx for x coordinate, and edx for y coordinate
;; (they're unused now)
;; al holds our color value
;; Compute x coordinate
mov ebx, xcenter
add ebx, dstX
sub ebx, shiftX
;; Compute y coordinate
mov edx, ycenter
add edx, dstY
sub edx, shiftY
;; Now draw
INVOKE DrawPixel, ebx, edx, al
;; Fallthrough to the increment
IINCR: ;; Inner increment
inc dstY
jmp INNER
OINCR: ;; Outer increment
inc dstX
jmp OUTER
DONE: ;; Exiting the outer loop is same as returning
;; Restore esp and ebp
;; See above for why that's not as stupid as it sounds (is?)
mov edi, OFFSET SAVE
mov esp, [edi]
mov edi, OFFSET BSAVE
mov ebp, [edi]
ret ; Don't delete this line!!!
RotateBlit ENDP
END
|
.code
BackupEdit proc uses esi edi,lpFileName:DWORD,Backup:DWORD
LOCAL buffer[MAX_PATH]:BYTE
LOCAL buffer2[MAX_PATH]:BYTE
LOCAL BackupPath[MAX_PATH]:BYTE
LOCAL dotpos:DWORD
mov esi,lpData
lea esi,[esi].ADDINDATA.MainFile
.if !nBackup || !byte ptr [esi]
ret
.endif
invoke lstrcpy,addr BackupPath,esi
lea esi,BackupPath
invoke lstrlen,esi
.while eax
.if byte ptr [esi+eax]=='\'
mov byte ptr [esi+eax],0
.break
.endif
dec eax
.endw
invoke lstrcat,addr BackupPath,addr szBak
mov esi,lpFileName
invoke lstrlen,esi
.while eax && byte ptr [esi+eax]!='\'
.if byte ptr [esi+eax]=='.'
lea edx,[esi+eax]
mov dotpos,edx
.endif
dec eax
.endw
lea esi,[esi+eax]
lea edi,buffer2
@@:
cmp esi,dotpos
je @f
mov al,[esi]
or al,al
je @f
mov [edi],al
inc esi
inc edi
cmp al,'\'
jne @b
lea edi,buffer2
jmp @b
@@:
mov byte ptr [edi],0
invoke lstrcpy,addr buffer,addr BackupPath
invoke lstrcat,addr buffer,addr buffer2
invoke lstrlen,addr buffer
lea edi,buffer
add edi,eax
.if Backup==1
mov al,'('
mov [edi],al
inc edi
mov al,'1'
mov [edi],al
inc edi
mov al,')'
mov [edi],al
inc edi
.else
mov al,[edi-2]
inc al
mov [edi-2],al
.endif
@@:
mov al,[esi]
mov [edi],al
inc esi
inc edi
or al,al
jne @b
mov eax,Backup
.if eax<nBackup
invoke GetFileAttributes,addr buffer
.if eax!=INVALID_HANDLE_VALUE
;File exist
mov eax,Backup
inc eax
invoke BackupEdit,addr buffer,eax
.endif
.endif
;Rename file
invoke CopyFile,lpFileName,addr buffer,FALSE
ret
BackupEdit endp
|
/*
* Copyright (C) 2020 ~ 2021 Uniontech Software Technology Co., Ltd.
*
* Author: zhangsheng<zhangsheng@uniontech.com>
*
* Maintainer: max-lv<lvwujun@uniontech.com>
* lanxuesong<lanxuesong@uniontech.com>
* xushitong<xushitong@uniontech.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "testa.h"
#include "message.h"
#include <sys/types.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <QDebug>
static const QString MsgId = "test_id";
TestA::TestA(QObject *parent)
: QObject (parent)
{
}
void TestA::sync()
{
message::Sender sender(MsgId);
auto ret = sender.send(1, 2, 3);
qDebug() << ret.r << ret.v;
// QMap<QString, QVariant> map;
// map["a"] = 11;
// map["b"] = 22;
// message::Sender sender(MsgId);
// auto v = sender.send(map, 5, "123", 123, 2);
// sender.send("fe");
// QVariantList list;
// list << "aaa" << 5 << 2.58;
// sender.send(list);
// QString teststr("asasfwegger");
// const QString &ref = teststr;
// sender.send(ref);
// sender.post(5, "123", 123, 2);
// sender.post("fe");
// sender.post(list);
// pid_t fd = fork();
// if (fd == 0) {
// qDebug() << "child";
// } else if (fd > 0) {
// } else {
// abort();
// }
// int status;
// waitpid(-1, &status, WNOHANG);
}
void TestA::async()
{
message::Sender sender(MsgId);
auto future = sender.asyncSend(1, 2, 3);
future.waitForFinished();
auto ret = future.result();
qDebug() << ret.r << ret.v;
}
|
BITS 32
switch_structure:
.sig dd 0x70BBCAFE
.returnaddr dd 0x0
.previousstack dd 0x0
.interrupt dw 0x0
.eax_reg dd 0x0
.ebx_reg dd 0x0
.edx_reg dd 0x0
.ecx_reg dd 0x0
.esi_reg dd 0x0
.edi_reg dd 0x0
.es_reg dw 0x0
.gs_reg dw 0x0
.fs_reg dw 0x0
.jump dd entry
entry:
BITS 32
nop
;jmp .protectedmode
;;; dropping to realmode
lgdt [GDT16.pointer]
jmp 0x8:.return_realmode
.protectedmode:
mov ax, DATA32_SEG
mov ds, ax
mov es, ax
mov ss, ax
mov gs, ax
mov fs, ax
ret
BITS 16
.return_realmode:
;;; drop back to real mode (remapping the PIC, reset CPU to realmode)
nop
cli
mov ax,0x0010
mov ds,ax
mov es,ax
mov fs,ax
mov gs,ax
mov ss,ax
mov ax,0x03FF
mov word [IDT16_n],ax
xor ax,ax
mov word [IDT16_n+2],ax
mov word [IDT16_n+4],ax
mov eax,cr0
and eax,0x7FFFFFFE
mov cr0,eax
jmp 0:.complete_realmode
.complete_realmode:
nop
lidt [IDT16_n]
xor ax,ax
mov ds,ax
mov es,ax
mov fs,ax
mov gs,ax
mov ss,ax
;;; return to text mode
push eax
push ebx
push ecx
push edx
push esi
push edi
push es
mov ax,word [switch_structure.es_reg]
mov es,ax
mov eax,dword [switch_structure.eax_reg]
mov ebx,dword [switch_structure.ebx_reg]
mov ecx,dword [switch_structure.ecx_reg]
mov edx,dword [switch_structure.edx_reg]
mov edi,dword [switch_structure.edi_reg]
mov esi,dword [switch_structure.esi_reg]
cmp word [switch_structure.interrupt],0x10
je .int0x10
cmp word [switch_structure.interrupt],0x12
je .int0x12
cmp word [switch_structure.interrupt],0x13
je .int0x13
cmp word [switch_structure.interrupt],0x15
je .int0x15
cmp word [switch_structure.interrupt],0x16
je .int0x16
.int0x10:
int 0x10
jmp .exit_interrupt
.int0x12:
int 0x12
jmp .exit_interrupt
.int0x13:
int 0x13
jmp .exit_interrupt
.int0x15:
int 0x15
jmp .exit_interrupt
.int0x16:
int 0x16
jmp .exit_interrupt
.exit_interrupt:
pop es
pop edi
pop esi
pop edx
pop ecx
pop ebx
pop eax
;
; clear Segments before we move to protected mode
mov ax,0x0
mov ds,ax
mov es,ax
mov fs,ax
mov gs,ax
cli
;; Setting up GDTR for Protected mode
lgdt [GDT32.pointer] ; load the gdt table
mov eax, cr0
or eax,0x1 ; set the protected mode bit on special CPU reg cr0
mov cr0, eax
jmp CODE32_SEG:entry.protectedmode ; long jump to the code segment
IDT16_n:
dq 0
dq 0
GDT16:
.entry:
dq 0x0
.code:
dw 0xFFFF
dw 0x0
db 0x0
db 10011010b
db 00001111b
db 0x0
.data:
dw 0xFFFF
dw 0x0
db 0x0
db 10010010b
db 00001111b
db 0x0
.END:
.pointer:
dw GDT16.END - GDT16
dd GDT16
CODE16_SEG equ GDT16.code - GDT16.entry
DATA16_SEG equ GDT16.data - GDT16.entry
BITS 32
cli
hlt
dw 0xAA55
dw 0x55AA
|
.global s_prepare_buffers
s_prepare_buffers:
push %r15
push %r8
push %r9
push %rbp
push %rcx
push %rdi
push %rsi
lea addresses_WT_ht+0x437b, %rsi
lea addresses_UC_ht+0xd189, %rdi
nop
nop
nop
nop
cmp %r15, %r15
mov $56, %rcx
rep movsb
nop
add %r9, %r9
lea addresses_D_ht+0x1aafb, %rsi
lea addresses_normal_ht+0x19a7b, %rdi
nop
add %r8, %r8
mov $17, %rcx
rep movsb
dec %r15
lea addresses_WT_ht+0xccc, %rdi
nop
nop
add %rbp, %rbp
mov (%rdi), %r15w
nop
nop
nop
nop
nop
dec %rcx
lea addresses_WT_ht+0xb6fb, %r9
nop
nop
xor %rdi, %rdi
mov (%r9), %r8d
nop
nop
nop
and $21240, %rbp
lea addresses_normal_ht+0x13cfb, %rbp
and %r15, %r15
movb $0x61, (%rbp)
nop
nop
sub %r15, %r15
lea addresses_D_ht+0xe3fb, %rdi
nop
nop
and %r9, %r9
and $0xffffffffffffffc0, %rdi
vmovaps (%rdi), %ymm2
vextracti128 $0, %ymm2, %xmm2
vpextrq $0, %xmm2, %rbp
sub %r8, %r8
lea addresses_normal_ht+0x1cdfb, %rsi
nop
nop
and %r8, %r8
vmovups (%rsi), %ymm6
vextracti128 $1, %ymm6, %xmm6
vpextrq $1, %xmm6, %rdi
nop
nop
nop
add %rdi, %rdi
lea addresses_UC_ht+0xc37b, %rbp
nop
nop
nop
nop
and %rcx, %rcx
mov (%rbp), %rsi
nop
nop
nop
add $56310, %r8
lea addresses_WT_ht+0xafb, %r8
nop
nop
nop
add %r9, %r9
mov $0x6162636465666768, %r15
movq %r15, %xmm2
and $0xffffffffffffffc0, %r8
vmovaps %ymm2, (%r8)
add %rsi, %rsi
lea addresses_normal_ht+0x28ab, %rsi
lea addresses_D_ht+0x1af5b, %rdi
nop
nop
and %r15, %r15
mov $36, %rcx
rep movsb
nop
nop
nop
nop
nop
xor %rdi, %rdi
lea addresses_A_ht+0x12eab, %r9
nop
nop
nop
add %rcx, %rcx
mov (%r9), %rsi
nop
nop
nop
nop
xor %r8, %r8
lea addresses_A_ht+0x108fb, %r8
nop
sub $52882, %rsi
and $0xffffffffffffffc0, %r8
movntdqa (%r8), %xmm3
vpextrq $1, %xmm3, %r15
add %r8, %r8
pop %rsi
pop %rdi
pop %rcx
pop %rbp
pop %r9
pop %r8
pop %r15
ret
.global s_faulty_load
s_faulty_load:
push %r10
push %r14
push %r9
push %rax
push %rbp
push %rbx
push %rdx
// Store
lea addresses_RW+0x150fb, %rbp
cmp %rbx, %rbx
movl $0x51525354, (%rbp)
nop
nop
nop
nop
nop
and $45229, %rdx
// Faulty Load
lea addresses_RW+0x150fb, %rbx
clflush (%rbx)
nop
nop
nop
nop
xor %r14, %r14
movb (%rbx), %r10b
lea oracles, %r9
and $0xff, %r10
shlq $12, %r10
mov (%r9,%r10,1), %r10
pop %rdx
pop %rbx
pop %rbp
pop %rax
pop %r9
pop %r14
pop %r10
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'type': 'addresses_RW', 'AVXalign': False, 'congruent': 0, 'size': 16, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_RW', 'AVXalign': False, 'congruent': 0, 'size': 4, 'same': True, 'NT': False}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'type': 'addresses_RW', 'AVXalign': False, 'congruent': 0, 'size': 1, 'same': True, 'NT': False}}
<gen_prepare_buffer>
{'OP': 'REPM', 'src': {'type': 'addresses_WT_ht', 'congruent': 7, 'same': True}, 'dst': {'type': 'addresses_UC_ht', 'congruent': 1, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_D_ht', 'congruent': 7, 'same': False}, 'dst': {'type': 'addresses_normal_ht', 'congruent': 6, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_WT_ht', 'AVXalign': False, 'congruent': 0, 'size': 2, 'same': False, 'NT': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_WT_ht', 'AVXalign': True, 'congruent': 9, 'size': 4, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_normal_ht', 'AVXalign': False, 'congruent': 9, 'size': 1, 'same': False, 'NT': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_D_ht', 'AVXalign': True, 'congruent': 8, 'size': 32, 'same': False, 'NT': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_normal_ht', 'AVXalign': False, 'congruent': 6, 'size': 32, 'same': False, 'NT': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_UC_ht', 'AVXalign': False, 'congruent': 4, 'size': 8, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'AVXalign': True, 'congruent': 8, 'size': 32, 'same': False, 'NT': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_normal_ht', 'congruent': 4, 'same': False}, 'dst': {'type': 'addresses_D_ht', 'congruent': 5, 'same': True}}
{'OP': 'LOAD', 'src': {'type': 'addresses_A_ht', 'AVXalign': False, 'congruent': 4, 'size': 8, 'same': False, 'NT': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_A_ht', 'AVXalign': False, 'congruent': 11, 'size': 16, 'same': False, 'NT': True}}
{'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
*/
|
TITLE THTHUNKS.ASM
PAGE ,132
;
; WOW v1.0
;
; Copyright (c) 1991-1992, Microsoft Corporation
;
; THTHUNKS.ASM
; Thunks in 16-bit space to route Windows API calls to WOW32
;
; History:
;
; 09-Nov-1992 Dave Hart (davehart)
; Adapted from mvdm\wow16\kernel31\kthunks.asm for ToolHelp
;
; 02-Apr-1991 Matt Felton (mattfe)
; Created.
;
ifndef WINDEBUG
KDEBUG = 0
WDEBUG = 0
else
KDEBUG = 1
WDEBUG = 1
endif
.286p
.xlist
include cmacros.inc
include wow.inc
include wowth.inc
.list
externFP WOW16Call
sBegin CODE
assumes CS,CODE
assumes DS,NOTHING
assumes ES,NOTHING
; Kernel API thunks
ToolHelpThunk ClassFirst
ToolHelpThunk ClassNext
sEnd CODE
end
|
;
; Copyright (c) 2016, Linaro Limited
; All rights reserved.
; SPDX-License-Identifier: BSD-2-Clause-Patent
;
EXPORT InternalMemCompareGuid
THUMB
AREA CompareGuid, CODE, READONLY, CODEALIGN, ALIGN=5
InternalMemCompareGuid
push {r4, lr}
ldr r2, [r0]
ldr r3, [r0, #4]
ldr r4, [r0, #8]
ldr r0, [r0, #12]
cbz r1, L1
ldr ip, [r1]
ldr lr, [r1, #4]
cmp r2, ip
it eq
cmpeq r3, lr
beq L0
movs r0, #0
pop {r4, pc}
L0
ldr r2, [r1, #8]
ldr r3, [r1, #12]
cmp r4, r2
it eq
cmpeq r0, r3
bne L2
movs r0, #1
pop {r4, pc}
L1
orrs r2, r2, r3
orrs r4, r4, r0
movs r0, #1
orrs r2, r2, r4
L2
it ne
movne r0, #0
pop {r4, pc}
END
|
; --------------------------------------
; Test JP.
;
; --------------------------------------
Start:
mvi a,'\n'
out 3
mvi a,'\r'
out 3
mvi a,'1' ; '1' first jump.
out 3
; --------------------------------------
mvi a,1100001b
;mvi a,0
ANI SIORDR
ANI 0FFH ;Non-zero?
JZ INPCK1
ORI 0FFH ;Set sign flag
INPCK1:
JP Jumped ; if P=1, jump (PC <- adr)
; --------------------------------------
mov b,a
mvi a,'N' ; Not jumped.
out 3
mvi a,'\n'
out 3
mvi a,'\r'
out 3
hlt
; --------------------------------------
jmp Start
; --------------------------------------
Jumped:
mvi a,'J' ; 'S' for Success.
out 3
mvi a,'\n'
out 3
mvi a,'\r'
out 3
hlt ; Program output before the HLT, is: "123S".
; --------------------------------------
jmp Start
; --------------------------------------
SIORDR EQU 01H ;RCV READY MASK
end
; --------------------------------------
; Successful run:
Needs work:
- Number of errors = 1
- List Error Messages:
-- 12: mvi a, 1100001b
-- -- Error3, INVALID, Opcode: a, 11010011 + p1|1100001b|
+ End of list.
;
; --------------------------------------
|
DATA SEGMENT
NUM1 DW 6
NUM2 DW 8
HCF DW ?
LCM DW ?
ENDS
CODE SEGMENT
ASSUME DS:DATA CS:CODE
START:
MOV AX,DATA
MOV DS,AX
MOV AX,NUM1
MOV BX,NUM2
WHILE:MOV DX,0
MOV CX,BX
DIV BX
MOV BX,DX
MOV AX,CX
CMP BX,0
JNE WHILE
MOV HCF,AX
MOV CX,AX
MOV AX,NUM1
MOV BX,NUM2
MUL BX
DIV CX
MOV LCM,AX
MOV AH,4CH
INT 21H
ENDS
END START
|
.global s_prepare_buffers
s_prepare_buffers:
push %r11
push %r13
push %r15
push %r9
push %rbx
push %rcx
push %rdi
push %rsi
lea addresses_normal_ht+0x8526, %r15
nop
nop
add $12842, %r13
mov (%r15), %r9w
nop
nop
nop
dec %rcx
lea addresses_WC_ht+0x19a26, %r9
nop
dec %rdi
mov (%r9), %r15w
nop
nop
nop
nop
nop
inc %rcx
lea addresses_normal_ht+0x11f26, %rsi
lea addresses_normal_ht+0x13c07, %rdi
nop
inc %r11
mov $19, %rcx
rep movsw
nop
nop
add %r11, %r11
lea addresses_D_ht+0x1b366, %r13
nop
nop
nop
sub %rsi, %rsi
movl $0x61626364, (%r13)
nop
nop
and $37740, %r11
lea addresses_A_ht+0x19dee, %rdi
nop
add $63064, %r13
mov $0x6162636465666768, %r9
movq %r9, %xmm7
and $0xffffffffffffffc0, %rdi
vmovntdq %ymm7, (%rdi)
nop
nop
nop
nop
sub %r15, %r15
lea addresses_D_ht+0x1e788, %rsi
lea addresses_D_ht+0x16c56, %rdi
nop
nop
nop
nop
nop
sub $42160, %r15
mov $60, %rcx
rep movsq
nop
and $51981, %r13
lea addresses_D_ht+0x19b26, %rsi
lea addresses_WC_ht+0xef26, %rdi
clflush (%rsi)
clflush (%rdi)
nop
nop
nop
nop
nop
and %rbx, %rbx
mov $18, %rcx
rep movsb
nop
nop
nop
nop
add %rdi, %rdi
lea addresses_A_ht+0x5926, %rdi
nop
nop
nop
add $62862, %r9
movups (%rdi), %xmm6
vpextrq $1, %xmm6, %rcx
and %rbx, %rbx
lea addresses_normal_ht+0xf91a, %rsi
lea addresses_normal_ht+0x145a6, %rdi
clflush (%rdi)
nop
nop
nop
xor %r9, %r9
mov $77, %rcx
rep movsl
sub %rsi, %rsi
lea addresses_UC_ht+0x89c6, %rsi
nop
nop
nop
nop
xor $36324, %rdi
movb $0x61, (%rsi)
nop
nop
nop
nop
nop
cmp $44247, %r13
lea addresses_A_ht+0xa36e, %r13
clflush (%r13)
nop
nop
nop
nop
nop
cmp $21752, %rdi
mov (%r13), %r15d
nop
nop
add $56734, %r15
lea addresses_WC_ht+0xd126, %rbx
nop
nop
nop
dec %r9
movups (%rbx), %xmm0
vpextrq $1, %xmm0, %r11
nop
nop
nop
dec %rbx
lea addresses_A_ht+0x25a6, %rdi
nop
nop
nop
nop
add $41104, %r15
movw $0x6162, (%rdi)
nop
nop
sub $63320, %r11
lea addresses_normal_ht+0xcf26, %rsi
lea addresses_WC_ht+0xb526, %rdi
nop
nop
and %r11, %r11
mov $80, %rcx
rep movsb
and %r11, %r11
lea addresses_UC_ht+0x13926, %rbx
cmp $9532, %rsi
movups (%rbx), %xmm1
vpextrq $1, %xmm1, %rcx
nop
nop
nop
nop
nop
cmp %rsi, %rsi
pop %rsi
pop %rdi
pop %rcx
pop %rbx
pop %r9
pop %r15
pop %r13
pop %r11
ret
.global s_faulty_load
s_faulty_load:
push %r11
push %r12
push %r15
push %r9
push %rax
push %rbp
// Store
mov $0x182, %r11
nop
nop
nop
nop
nop
inc %r15
mov $0x5152535455565758, %r9
movq %r9, (%r11)
nop
nop
nop
add $36324, %r11
// Faulty Load
lea addresses_D+0x3126, %r11
nop
nop
nop
and $6367, %rax
mov (%r11), %r15d
lea oracles, %r9
and $0xff, %r15
shlq $12, %r15
mov (%r9,%r15,1), %r15
pop %rbp
pop %rax
pop %r9
pop %r15
pop %r12
pop %r11
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 4, 'type': 'addresses_D', 'congruent': 0}}
{'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 8, 'type': 'addresses_P', 'congruent': 2}, 'OP': 'STOR'}
[Faulty Load]
{'OP': 'LOAD', 'src': {'same': True, 'NT': False, 'AVXalign': False, 'size': 4, 'type': 'addresses_D', 'congruent': 0}}
<gen_prepare_buffer>
{'OP': 'LOAD', 'src': {'same': True, 'NT': False, 'AVXalign': False, 'size': 2, 'type': 'addresses_normal_ht', 'congruent': 7}}
{'OP': 'LOAD', 'src': {'same': False, 'NT': True, 'AVXalign': False, 'size': 2, 'type': 'addresses_WC_ht', 'congruent': 8}}
{'dst': {'same': True, 'congruent': 0, 'type': 'addresses_normal_ht'}, 'OP': 'REPM', 'src': {'same': False, 'congruent': 7, 'type': 'addresses_normal_ht'}}
{'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 4, 'type': 'addresses_D_ht', 'congruent': 6}, 'OP': 'STOR'}
{'dst': {'same': False, 'NT': True, 'AVXalign': False, 'size': 32, 'type': 'addresses_A_ht', 'congruent': 3}, 'OP': 'STOR'}
{'dst': {'same': True, 'congruent': 4, 'type': 'addresses_D_ht'}, 'OP': 'REPM', 'src': {'same': False, 'congruent': 0, 'type': 'addresses_D_ht'}}
{'dst': {'same': True, 'congruent': 8, 'type': 'addresses_WC_ht'}, 'OP': 'REPM', 'src': {'same': False, 'congruent': 9, 'type': 'addresses_D_ht'}}
{'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 16, 'type': 'addresses_A_ht', 'congruent': 11}}
{'dst': {'same': False, 'congruent': 7, 'type': 'addresses_normal_ht'}, 'OP': 'REPM', 'src': {'same': False, 'congruent': 0, 'type': 'addresses_normal_ht'}}
{'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 1, 'type': 'addresses_UC_ht', 'congruent': 4}, 'OP': 'STOR'}
{'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 4, 'type': 'addresses_A_ht', 'congruent': 2}}
{'OP': 'LOAD', 'src': {'same': True, 'NT': False, 'AVXalign': False, 'size': 16, 'type': 'addresses_WC_ht', 'congruent': 10}}
{'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 2, 'type': 'addresses_A_ht', 'congruent': 7}, 'OP': 'STOR'}
{'dst': {'same': False, 'congruent': 10, 'type': 'addresses_WC_ht'}, 'OP': 'REPM', 'src': {'same': False, 'congruent': 9, 'type': 'addresses_normal_ht'}}
{'OP': 'LOAD', 'src': {'same': True, 'NT': False, 'AVXalign': False, 'size': 16, 'type': 'addresses_UC_ht', 'congruent': 11}}
{'36': 21829}
36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36
*/
|
/* Copyright (c) 1998 Slingshot Game Technology
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.
*/
// PositioningWindow.cpp : implementation file
//
#include "stdafx.h"
#include "terrain.h"
#include "PositioningWindow.h"
#include "TerrainDoc.h"
#include "ChildFrm.h"
#include "ToolPalette.h"
const int POSITIONING_WINDOW_SIZE = 400;
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// PositioningWindow
IMPLEMENT_DYNCREATE(PositioningWindow, CScrollView)
PositioningWindow::PositioningWindow()
{
ViewCenterX = 0;
ViewCenterZ = 0;
}
PositioningWindow::~PositioningWindow()
{
}
BEGIN_MESSAGE_MAP(PositioningWindow, CScrollView)
//{{AFX_MSG_MAP(PositioningWindow)
ON_WM_LBUTTONDOWN()
ON_WM_MOUSEMOVE()
ON_WM_CANCELMODE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// PositioningWindow drawing
void PositioningWindow::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
// CSize sizeTotal;
// // TODO: calculate the total size of this view
// sizeTotal.cx = sizeTotal.cy = 100;
// SetScrollSizes(MM_TEXT, sizeTotal);
// OnUpdate(CView* sender, LPARAM lHint, CObject* pHint);
}
void PositioningWindow::OnDraw(CDC* pDC)
{
// CDocument* pDoc = GetDocument();
// TODO: add draw code here
// Draw the outline of the terrain boundaries.
DrawBox(pDC, 0, 0, POSITIONING_WINDOW_SIZE, POSITIONING_WINDOW_SIZE, RGB(0, 0, 0));
// Draw the view center.
int x = (ViewCenterX * POSITIONING_WINDOW_SIZE) / GetDocument()->GetXSize();
int y = (ViewCenterZ * POSITIONING_WINDOW_SIZE) / GetDocument()->GetZSize();
pDC->SetPixel(x, y, RGB(0, 0, 200));
pDC->SetPixel(x+1, y, RGB(0, 0, 200));
pDC->SetPixel(x, y+1, RGB(0, 0, 200));
pDC->SetPixel(x-1, y, RGB(0, 0, 200));
pDC->SetPixel(x, y-1, RGB(0, 0, 200));
}
CTerrainDoc* PositioningWindow::GetDocument()
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTerrainDoc)));
return (CTerrainDoc*)m_pDocument;
}
CChildFrame* PositioningWindow::GetFrame()
// Gets our frame. You can use the frame to get pointers to the various
// views and the tool palette.
{
return dynamic_cast<CChildFrame*>(GetParent()->GetParent()->GetParent());
}
int PositioningWindow::GetViewXOrigin()
// Returns the x-location (in world coordinates) of the left edge of
// the main terrain view.
{
CChildFrame* frame = GetFrame();
if (frame == NULL) return 0;
ToolPalette* palette = frame->GetToolPalette();
if (palette == NULL) return 0;
int x = ViewCenterX - (/* half width of view window in w.c.*/ 50 << palette->GetZoomLevel());
if (x < 0) x = 0;
return x;
}
int PositioningWindow::GetViewZOrigin()
// Returns the z-location (in world coordinates) of the left edge of
// the main terrain view.
{
CChildFrame* frame = GetFrame();
if (frame == NULL) return 0;
ToolPalette* palette = frame->GetToolPalette();
if (palette == NULL) return 0;
int z = ViewCenterZ - (/* half height of view window in w.c.*/ 50 << palette->GetZoomLevel());
if (z < 0) z = 0;
return z;
}
/////////////////////////////////////////////////////////////////////////////
// PositioningWindow diagnostics
#ifdef _DEBUG
void PositioningWindow::AssertValid() const
{
CScrollView::AssertValid();
}
void PositioningWindow::Dump(CDumpContext& dc) const
{
CScrollView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// PositioningWindow message handlers
void PositioningWindow::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
// Called when document changes.
{
// int ZoomLevel = GetFrame()->GetToolPalette()->GetZoomLevel();
// int XSize = (((GetDocument()->GetXSize() - 1) * BlockPixels) >> ZoomLevel) + 1;
// int YSize = (((GetDocument()->GetZSize() - 1) * BlockPixels) >> ZoomLevel) + 1;
int XSize = POSITIONING_WINDOW_SIZE;
int YSize = POSITIONING_WINDOW_SIZE;
SetScrollSizes(MM_TEXT, CSize(XSize, YSize));
// Call the base class.
CScrollView::OnUpdate(pSender, lHint, pHint);
}
void PositioningWindow::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
// CScrollView::OnLButtonDown(nFlags, point);
point += GetDeviceScrollPosition();
// Convert from window coords to world coords.
ViewCenterX = point.x * GetDocument()->GetXSize() / POSITIONING_WINDOW_SIZE;
ViewCenterZ = point.y * GetDocument()->GetZSize() / POSITIONING_WINDOW_SIZE;
// Tell the view to update.
GetDocument()->UpdateAllViews(NULL);
}
void PositioningWindow::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
// CScrollView::OnMouseMove(nFlags, point);
if (nFlags & MK_LBUTTON) {
point += GetDeviceScrollPosition();
// Convert from window coords to world coords.
ViewCenterX = point.x * GetDocument()->GetXSize() / POSITIONING_WINDOW_SIZE;
ViewCenterZ = point.y * GetDocument()->GetZSize() / POSITIONING_WINDOW_SIZE;
// Tell the view to update.
GetDocument()->UpdateAllViews(NULL);
}
}
void PositioningWindow::OnCancelMode()
{
CScrollView::OnCancelMode();
// TODO: Add your message handler code here
}
|
###############################################################################
# Copyright 2019 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
Lpoly:
.quad 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFF00000000, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFEFFFFFFFF
LRR:
.quad 0x200000003, 0x2ffffffff, 0x100000001, 0x400000002
LOne:
.long 1,1,1,1,1,1,1,1
LTwo:
.long 2,2,2,2,2,2,2,2
LThree:
.long 3,3,3,3,3,3,3,3
.p2align 4, 0x90
.globl n8_sm2_mul_by_2
.type n8_sm2_mul_by_2, @function
n8_sm2_mul_by_2:
push %r12
push %r13
xor %r13, %r13
movq (%rsi), %r8
movq (8)(%rsi), %r9
movq (16)(%rsi), %r10
movq (24)(%rsi), %r11
shld $(1), %r11, %r13
shld $(1), %r10, %r11
shld $(1), %r9, %r10
shld $(1), %r8, %r9
shl $(1), %r8
mov %r8, %rax
mov %r9, %rdx
mov %r10, %rcx
mov %r11, %r12
subq Lpoly+0(%rip), %rax
sbbq Lpoly+8(%rip), %rdx
sbbq Lpoly+16(%rip), %rcx
sbbq Lpoly+24(%rip), %r12
sbb $(0), %r13
cmove %rax, %r8
cmove %rdx, %r9
cmove %rcx, %r10
cmove %r12, %r11
movq %r8, (%rdi)
movq %r9, (8)(%rdi)
movq %r10, (16)(%rdi)
movq %r11, (24)(%rdi)
pop %r13
pop %r12
ret
.Lfe1:
.size n8_sm2_mul_by_2, .Lfe1-(n8_sm2_mul_by_2)
.p2align 4, 0x90
.globl n8_sm2_div_by_2
.type n8_sm2_div_by_2, @function
n8_sm2_div_by_2:
push %r12
push %r13
push %r14
movq (%rsi), %r8
movq (8)(%rsi), %r9
movq (16)(%rsi), %r10
movq (24)(%rsi), %r11
xor %r13, %r13
xor %r14, %r14
mov %r8, %rax
mov %r9, %rdx
mov %r10, %rcx
mov %r11, %r12
addq Lpoly+0(%rip), %rax
adcq Lpoly+8(%rip), %rdx
adcq Lpoly+16(%rip), %rcx
adcq Lpoly+24(%rip), %r12
adc $(0), %r13
test $(1), %r8
cmovne %rax, %r8
cmovne %rdx, %r9
cmovne %rcx, %r10
cmovne %r12, %r11
cmovne %r13, %r14
shrd $(1), %r9, %r8
shrd $(1), %r10, %r9
shrd $(1), %r11, %r10
shrd $(1), %r14, %r11
movq %r8, (%rdi)
movq %r9, (8)(%rdi)
movq %r10, (16)(%rdi)
movq %r11, (24)(%rdi)
pop %r14
pop %r13
pop %r12
ret
.Lfe2:
.size n8_sm2_div_by_2, .Lfe2-(n8_sm2_div_by_2)
.p2align 4, 0x90
.globl n8_sm2_mul_by_3
.type n8_sm2_mul_by_3, @function
n8_sm2_mul_by_3:
push %r12
push %r13
xor %r13, %r13
movq (%rsi), %r8
movq (8)(%rsi), %r9
movq (16)(%rsi), %r10
movq (24)(%rsi), %r11
shld $(1), %r11, %r13
shld $(1), %r10, %r11
shld $(1), %r9, %r10
shld $(1), %r8, %r9
shl $(1), %r8
mov %r8, %rax
mov %r9, %rdx
mov %r10, %rcx
mov %r11, %r12
subq Lpoly+0(%rip), %rax
sbbq Lpoly+8(%rip), %rdx
sbbq Lpoly+16(%rip), %rcx
sbbq Lpoly+24(%rip), %r12
sbb $(0), %r13
cmove %rax, %r8
cmove %rdx, %r9
cmove %rcx, %r10
cmove %r12, %r11
xor %r13, %r13
addq (%rsi), %r8
adcq (8)(%rsi), %r9
adcq (16)(%rsi), %r10
adcq (24)(%rsi), %r11
adc $(0), %r13
mov %r8, %rax
mov %r9, %rdx
mov %r10, %rcx
mov %r11, %r12
subq Lpoly+0(%rip), %rax
sbbq Lpoly+8(%rip), %rdx
sbbq Lpoly+16(%rip), %rcx
sbbq Lpoly+24(%rip), %r12
sbb $(0), %r13
cmove %rax, %r8
cmove %rdx, %r9
cmove %rcx, %r10
cmove %r12, %r11
movq %r8, (%rdi)
movq %r9, (8)(%rdi)
movq %r10, (16)(%rdi)
movq %r11, (24)(%rdi)
pop %r13
pop %r12
ret
.Lfe3:
.size n8_sm2_mul_by_3, .Lfe3-(n8_sm2_mul_by_3)
.p2align 4, 0x90
.globl n8_sm2_add
.type n8_sm2_add, @function
n8_sm2_add:
push %r12
push %r13
xor %r13, %r13
movq (%rsi), %r8
movq (8)(%rsi), %r9
movq (16)(%rsi), %r10
movq (24)(%rsi), %r11
addq (%rdx), %r8
adcq (8)(%rdx), %r9
adcq (16)(%rdx), %r10
adcq (24)(%rdx), %r11
adc $(0), %r13
mov %r8, %rax
mov %r9, %rdx
mov %r10, %rcx
mov %r11, %r12
subq Lpoly+0(%rip), %rax
sbbq Lpoly+8(%rip), %rdx
sbbq Lpoly+16(%rip), %rcx
sbbq Lpoly+24(%rip), %r12
sbb $(0), %r13
cmove %rax, %r8
cmove %rdx, %r9
cmove %rcx, %r10
cmove %r12, %r11
movq %r8, (%rdi)
movq %r9, (8)(%rdi)
movq %r10, (16)(%rdi)
movq %r11, (24)(%rdi)
pop %r13
pop %r12
ret
.Lfe4:
.size n8_sm2_add, .Lfe4-(n8_sm2_add)
.p2align 4, 0x90
.globl n8_sm2_sub
.type n8_sm2_sub, @function
n8_sm2_sub:
push %r12
push %r13
xor %r13, %r13
movq (%rsi), %r8
movq (8)(%rsi), %r9
movq (16)(%rsi), %r10
movq (24)(%rsi), %r11
subq (%rdx), %r8
sbbq (8)(%rdx), %r9
sbbq (16)(%rdx), %r10
sbbq (24)(%rdx), %r11
sbb $(0), %r13
mov %r8, %rax
mov %r9, %rdx
mov %r10, %rcx
mov %r11, %r12
addq Lpoly+0(%rip), %rax
adcq Lpoly+8(%rip), %rdx
adcq Lpoly+16(%rip), %rcx
adcq Lpoly+24(%rip), %r12
test %r13, %r13
cmovne %rax, %r8
cmovne %rdx, %r9
cmovne %rcx, %r10
cmovne %r12, %r11
movq %r8, (%rdi)
movq %r9, (8)(%rdi)
movq %r10, (16)(%rdi)
movq %r11, (24)(%rdi)
pop %r13
pop %r12
ret
.Lfe5:
.size n8_sm2_sub, .Lfe5-(n8_sm2_sub)
.p2align 4, 0x90
.globl n8_sm2_neg
.type n8_sm2_neg, @function
n8_sm2_neg:
push %r12
push %r13
xor %r13, %r13
xor %r8, %r8
xor %r9, %r9
xor %r10, %r10
xor %r11, %r11
subq (%rsi), %r8
sbbq (8)(%rsi), %r9
sbbq (16)(%rsi), %r10
sbbq (24)(%rsi), %r11
sbb $(0), %r13
mov %r8, %rax
mov %r9, %rdx
mov %r10, %rcx
mov %r11, %r12
addq Lpoly+0(%rip), %rax
adcq Lpoly+8(%rip), %rdx
adcq Lpoly+16(%rip), %rcx
adcq Lpoly+24(%rip), %r12
test %r13, %r13
cmovne %rax, %r8
cmovne %rdx, %r9
cmovne %rcx, %r10
cmovne %r12, %r11
movq %r8, (%rdi)
movq %r9, (8)(%rdi)
movq %r10, (16)(%rdi)
movq %r11, (24)(%rdi)
pop %r13
pop %r12
ret
.Lfe6:
.size n8_sm2_neg, .Lfe6-(n8_sm2_neg)
.p2align 4, 0x90
sm2_mmull:
xor %r13, %r13
movq (%rbx), %rax
mulq (%rsi)
mov %rax, %r8
mov %rdx, %r9
movq (%rbx), %rax
mulq (8)(%rsi)
add %rax, %r9
adc $(0), %rdx
mov %rdx, %r10
movq (%rbx), %rax
mulq (16)(%rsi)
add %rax, %r10
adc $(0), %rdx
mov %rdx, %r11
movq (%rbx), %rax
mulq (24)(%rsi)
add %rax, %r11
adc $(0), %rdx
mov %rdx, %r12
mov %r8, %r14
shl $(32), %r14
mov %r8, %r15
shr $(32), %r15
mov %r8, %rcx
mov %r8, %rax
xor %rbp, %rbp
xor %rdx, %rdx
sub %r14, %rcx
sbb %r15, %rbp
sbb %r14, %rdx
sbb %r15, %rax
add %rcx, %r9
adc %rbp, %r10
adc %rdx, %r11
adc %rax, %r12
adc $(0), %r13
xor %r8, %r8
movq (8)(%rbx), %rax
mulq (%rsi)
add %rax, %r9
adc $(0), %rdx
mov %rdx, %rcx
movq (8)(%rbx), %rax
mulq (8)(%rsi)
add %rcx, %r10
adc $(0), %rdx
add %rax, %r10
adc $(0), %rdx
mov %rdx, %rcx
movq (8)(%rbx), %rax
mulq (16)(%rsi)
add %rcx, %r11
adc $(0), %rdx
add %rax, %r11
adc $(0), %rdx
mov %rdx, %rcx
movq (8)(%rbx), %rax
mulq (24)(%rsi)
add %rcx, %r12
adc $(0), %rdx
add %rax, %r12
adc %rdx, %r13
adc $(0), %r8
mov %r9, %r14
shl $(32), %r14
mov %r9, %r15
shr $(32), %r15
mov %r9, %rcx
mov %r9, %rax
xor %rbp, %rbp
xor %rdx, %rdx
sub %r14, %rcx
sbb %r15, %rbp
sbb %r14, %rdx
sbb %r15, %rax
add %rcx, %r10
adc %rbp, %r11
adc %rdx, %r12
adc %rax, %r13
adc $(0), %r8
xor %r9, %r9
movq (16)(%rbx), %rax
mulq (%rsi)
add %rax, %r10
adc $(0), %rdx
mov %rdx, %rcx
movq (16)(%rbx), %rax
mulq (8)(%rsi)
add %rcx, %r11
adc $(0), %rdx
add %rax, %r11
adc $(0), %rdx
mov %rdx, %rcx
movq (16)(%rbx), %rax
mulq (16)(%rsi)
add %rcx, %r12
adc $(0), %rdx
add %rax, %r12
adc $(0), %rdx
mov %rdx, %rcx
movq (16)(%rbx), %rax
mulq (24)(%rsi)
add %rcx, %r13
adc $(0), %rdx
add %rax, %r13
adc %rdx, %r8
adc $(0), %r9
mov %r10, %r14
shl $(32), %r14
mov %r10, %r15
shr $(32), %r15
mov %r10, %rcx
mov %r10, %rax
xor %rbp, %rbp
xor %rdx, %rdx
sub %r14, %rcx
sbb %r15, %rbp
sbb %r14, %rdx
sbb %r15, %rax
add %rcx, %r11
adc %rbp, %r12
adc %rdx, %r13
adc %rax, %r8
adc $(0), %r9
xor %r10, %r10
movq (24)(%rbx), %rax
mulq (%rsi)
add %rax, %r11
adc $(0), %rdx
mov %rdx, %rcx
movq (24)(%rbx), %rax
mulq (8)(%rsi)
add %rcx, %r12
adc $(0), %rdx
add %rax, %r12
adc $(0), %rdx
mov %rdx, %rcx
movq (24)(%rbx), %rax
mulq (16)(%rsi)
add %rcx, %r13
adc $(0), %rdx
add %rax, %r13
adc $(0), %rdx
mov %rdx, %rcx
movq (24)(%rbx), %rax
mulq (24)(%rsi)
add %rcx, %r8
adc $(0), %rdx
add %rax, %r8
adc %rdx, %r9
adc $(0), %r10
mov %r11, %r14
shl $(32), %r14
mov %r11, %r15
shr $(32), %r15
mov %r11, %rcx
mov %r11, %rax
xor %rbp, %rbp
xor %rdx, %rdx
sub %r14, %rcx
sbb %r15, %rbp
sbb %r14, %rdx
sbb %r15, %rax
add %rcx, %r12
adc %rbp, %r13
adc %rdx, %r8
adc %rax, %r9
adc $(0), %r10
xor %r11, %r11
movq Lpoly+0(%rip), %rcx
movq Lpoly+8(%rip), %rbp
movq Lpoly+16(%rip), %rbx
movq Lpoly+24(%rip), %rdx
mov %r12, %rax
mov %r13, %r11
mov %r8, %r14
mov %r9, %r15
sub %rcx, %rax
sbb %rbp, %r11
sbb %rbx, %r14
sbb %rdx, %r15
sbb $(0), %r10
cmovnc %rax, %r12
cmovnc %r11, %r13
cmovnc %r14, %r8
cmovnc %r15, %r9
movq %r12, (%rdi)
movq %r13, (8)(%rdi)
movq %r8, (16)(%rdi)
movq %r9, (24)(%rdi)
ret
.p2align 4, 0x90
.globl n8_sm2_mul_montl
.type n8_sm2_mul_montl, @function
n8_sm2_mul_montl:
push %rbp
push %rbx
push %r12
push %r13
push %r14
push %r15
mov %rdx, %rbx
call sm2_mmull
pop %r15
pop %r14
pop %r13
pop %r12
pop %rbx
pop %rbp
ret
.Lfe7:
.size n8_sm2_mul_montl, .Lfe7-(n8_sm2_mul_montl)
.p2align 4, 0x90
.globl n8_sm2_to_mont
.type n8_sm2_to_mont, @function
n8_sm2_to_mont:
push %rbp
push %rbx
push %r12
push %r13
push %r14
push %r15
lea LRR(%rip), %rbx
call sm2_mmull
pop %r15
pop %r14
pop %r13
pop %r12
pop %rbx
pop %rbp
ret
.Lfe8:
.size n8_sm2_to_mont, .Lfe8-(n8_sm2_to_mont)
.p2align 4, 0x90
.globl n8_sm2_sqr_montl
.type n8_sm2_sqr_montl, @function
n8_sm2_sqr_montl:
push %rbp
push %rbx
push %r12
push %r13
push %r14
push %r15
movq (%rsi), %rbx
movq (8)(%rsi), %rax
mul %rbx
mov %rax, %r9
mov %rdx, %r10
movq (16)(%rsi), %rax
mul %rbx
add %rax, %r10
adc $(0), %rdx
mov %rdx, %r11
movq (24)(%rsi), %rax
mul %rbx
add %rax, %r11
adc $(0), %rdx
mov %rdx, %r12
movq (8)(%rsi), %rbx
movq (16)(%rsi), %rax
mul %rbx
add %rax, %r11
adc $(0), %rdx
mov %rdx, %rbp
movq (24)(%rsi), %rax
mul %rbx
add %rax, %r12
adc $(0), %rdx
add %rbp, %r12
adc $(0), %rdx
mov %rdx, %r13
movq (16)(%rsi), %rbx
movq (24)(%rsi), %rax
mul %rbx
add %rax, %r13
adc $(0), %rdx
mov %rdx, %r14
xor %r15, %r15
shld $(1), %r14, %r15
shld $(1), %r13, %r14
shld $(1), %r12, %r13
shld $(1), %r11, %r12
shld $(1), %r10, %r11
shld $(1), %r9, %r10
shl $(1), %r9
movq (%rsi), %rax
mul %rax
mov %rax, %r8
add %rdx, %r9
adc $(0), %r10
movq (8)(%rsi), %rax
mul %rax
add %rax, %r10
adc %rdx, %r11
adc $(0), %r12
movq (16)(%rsi), %rax
mul %rax
add %rax, %r12
adc %rdx, %r13
adc $(0), %r14
movq (24)(%rsi), %rax
mul %rax
add %rax, %r14
adc %rdx, %r15
mov %r8, %rax
mov %r8, %rcx
mov %r8, %rdx
xor %rbp, %rbp
xor %rbx, %rbx
shl $(32), %r8
shr $(32), %rax
sub %r8, %rcx
sbb %rax, %rbp
sbb %r8, %rbx
sbb %rax, %rdx
xor %r8, %r8
add %rcx, %r9
adc %rbp, %r10
adc %rbx, %r11
adc %rdx, %r12
adc $(0), %r8
mov %r9, %rax
mov %r9, %rcx
mov %r9, %rdx
xor %rbp, %rbp
xor %rbx, %rbx
shl $(32), %r9
shr $(32), %rax
sub %r9, %rcx
sbb %rax, %rbp
sbb %r9, %rbx
sbb %rax, %rdx
xor %r9, %r9
add %rcx, %r10
adc %rbp, %r11
adc %rbx, %r12
adc %rdx, %r13
adc $(0), %r9
add %r8, %r13
adc $(0), %r9
mov %r10, %rax
mov %r10, %rcx
mov %r10, %rdx
xor %rbp, %rbp
xor %rbx, %rbx
shl $(32), %r10
shr $(32), %rax
sub %r10, %rcx
sbb %rax, %rbp
sbb %r10, %rbx
sbb %rax, %rdx
xor %r10, %r10
add %rcx, %r11
adc %rbp, %r12
adc %rbx, %r13
adc %rdx, %r14
adc $(0), %r10
add %r9, %r14
adc $(0), %r10
mov %r11, %rax
mov %r11, %rcx
mov %r11, %rdx
xor %rbp, %rbp
xor %rbx, %rbx
shl $(32), %r11
shr $(32), %rax
sub %r11, %rcx
sbb %rax, %rbp
sbb %r11, %rbx
sbb %rax, %rdx
xor %r11, %r11
add %rcx, %r12
adc %rbp, %r13
adc %rbx, %r14
adc %rdx, %r15
adc $(0), %r11
add %r10, %r15
adc $(0), %r11
movq Lpoly+0(%rip), %rcx
movq Lpoly+8(%rip), %rbp
movq Lpoly+16(%rip), %rbx
movq Lpoly+24(%rip), %rdx
mov %r12, %rax
mov %r13, %r8
mov %r14, %r9
mov %r15, %r10
sub %rcx, %rax
sbb %rbp, %r8
sbb %rbx, %r9
sbb %rdx, %r10
sbb $(0), %r11
cmovnc %rax, %r12
cmovnc %r8, %r13
cmovnc %r9, %r14
cmovnc %r10, %r15
movq %r12, (%rdi)
movq %r13, (8)(%rdi)
movq %r14, (16)(%rdi)
movq %r15, (24)(%rdi)
pop %r15
pop %r14
pop %r13
pop %r12
pop %rbx
pop %rbp
ret
.Lfe9:
.size n8_sm2_sqr_montl, .Lfe9-(n8_sm2_sqr_montl)
.p2align 4, 0x90
.globl n8_sm2_mont_back
.type n8_sm2_mont_back, @function
n8_sm2_mont_back:
push %rbp
push %rbx
push %r12
push %r13
push %r14
push %r15
movq (%rsi), %r10
movq (8)(%rsi), %r11
movq (16)(%rsi), %r12
movq (24)(%rsi), %r13
xor %r8, %r8
xor %r9, %r9
mov %r10, %r14
shl $(32), %r14
mov %r10, %r15
shr $(32), %r15
mov %r10, %rcx
mov %r10, %rax
xor %rbp, %rbp
xor %rdx, %rdx
sub %r14, %rcx
sbb %r15, %rbp
sbb %r14, %rdx
sbb %r15, %rax
add %rcx, %r11
adc %rbp, %r12
adc %rdx, %r13
adc %rax, %r8
adc $(0), %r9
xor %r10, %r10
mov %r11, %r14
shl $(32), %r14
mov %r11, %r15
shr $(32), %r15
mov %r11, %rcx
mov %r11, %rax
xor %rbp, %rbp
xor %rdx, %rdx
sub %r14, %rcx
sbb %r15, %rbp
sbb %r14, %rdx
sbb %r15, %rax
add %rcx, %r12
adc %rbp, %r13
adc %rdx, %r8
adc %rax, %r9
adc $(0), %r10
xor %r11, %r11
mov %r12, %r14
shl $(32), %r14
mov %r12, %r15
shr $(32), %r15
mov %r12, %rcx
mov %r12, %rax
xor %rbp, %rbp
xor %rdx, %rdx
sub %r14, %rcx
sbb %r15, %rbp
sbb %r14, %rdx
sbb %r15, %rax
add %rcx, %r13
adc %rbp, %r8
adc %rdx, %r9
adc %rax, %r10
adc $(0), %r11
xor %r12, %r12
mov %r13, %r14
shl $(32), %r14
mov %r13, %r15
shr $(32), %r15
mov %r13, %rcx
mov %r13, %rax
xor %rbp, %rbp
xor %rdx, %rdx
sub %r14, %rcx
sbb %r15, %rbp
sbb %r14, %rdx
sbb %r15, %rax
add %rcx, %r8
adc %rbp, %r9
adc %rdx, %r10
adc %rax, %r11
adc $(0), %r12
xor %r13, %r13
mov %r8, %rcx
mov %r9, %rbp
mov %r10, %rbx
mov %r11, %rdx
subq Lpoly+0(%rip), %rcx
sbbq Lpoly+8(%rip), %rbp
sbbq Lpoly+16(%rip), %rbx
sbbq Lpoly+24(%rip), %rdx
sbb $(0), %r12
cmovnc %rcx, %r8
cmovnc %rbp, %r9
cmovnc %rbx, %r10
cmovnc %rdx, %r11
movq %r8, (%rdi)
movq %r9, (8)(%rdi)
movq %r10, (16)(%rdi)
movq %r11, (24)(%rdi)
pop %r15
pop %r14
pop %r13
pop %r12
pop %rbx
pop %rbp
ret
.Lfe10:
.size n8_sm2_mont_back, .Lfe10-(n8_sm2_mont_back)
.p2align 4, 0x90
.globl n8_sm2_select_pp_w5
.type n8_sm2_select_pp_w5, @function
n8_sm2_select_pp_w5:
push %r12
push %r13
movdqa LOne(%rip), %xmm0
movdqa %xmm0, %xmm8
movd %edx, %xmm1
pshufd $(0), %xmm1, %xmm1
pxor %xmm2, %xmm2
pxor %xmm3, %xmm3
pxor %xmm4, %xmm4
pxor %xmm5, %xmm5
pxor %xmm6, %xmm6
pxor %xmm7, %xmm7
mov $(16), %rcx
.Lselect_loop_sse_w5gas_11:
movdqa %xmm8, %xmm15
pcmpeqd %xmm1, %xmm15
paddd %xmm0, %xmm8
movdqa (%rsi), %xmm9
movdqa (16)(%rsi), %xmm10
movdqa (32)(%rsi), %xmm11
movdqa (48)(%rsi), %xmm12
movdqa (64)(%rsi), %xmm13
movdqa (80)(%rsi), %xmm14
add $(96), %rsi
pand %xmm15, %xmm9
pand %xmm15, %xmm10
pand %xmm15, %xmm11
pand %xmm15, %xmm12
pand %xmm15, %xmm13
pand %xmm15, %xmm14
por %xmm9, %xmm2
por %xmm10, %xmm3
por %xmm11, %xmm4
por %xmm12, %xmm5
por %xmm13, %xmm6
por %xmm14, %xmm7
dec %rcx
jnz .Lselect_loop_sse_w5gas_11
movdqu %xmm2, (%rdi)
movdqu %xmm3, (16)(%rdi)
movdqu %xmm4, (32)(%rdi)
movdqu %xmm5, (48)(%rdi)
movdqu %xmm6, (64)(%rdi)
movdqu %xmm7, (80)(%rdi)
pop %r13
pop %r12
ret
.Lfe11:
.size n8_sm2_select_pp_w5, .Lfe11-(n8_sm2_select_pp_w5)
.p2align 4, 0x90
.globl n8_sm2_select_ap_w7
.type n8_sm2_select_ap_w7, @function
n8_sm2_select_ap_w7:
push %r12
push %r13
movdqa LOne(%rip), %xmm0
pxor %xmm2, %xmm2
pxor %xmm3, %xmm3
pxor %xmm4, %xmm4
pxor %xmm5, %xmm5
movdqa %xmm0, %xmm8
movd %edx, %xmm1
pshufd $(0), %xmm1, %xmm1
mov $(64), %rcx
.Lselect_loop_sse_w7gas_12:
movdqa %xmm8, %xmm15
pcmpeqd %xmm1, %xmm15
paddd %xmm0, %xmm8
movdqa (%rsi), %xmm9
movdqa (16)(%rsi), %xmm10
movdqa (32)(%rsi), %xmm11
movdqa (48)(%rsi), %xmm12
add $(64), %rsi
pand %xmm15, %xmm9
pand %xmm15, %xmm10
pand %xmm15, %xmm11
pand %xmm15, %xmm12
por %xmm9, %xmm2
por %xmm10, %xmm3
por %xmm11, %xmm4
por %xmm12, %xmm5
dec %rcx
jnz .Lselect_loop_sse_w7gas_12
movdqu %xmm2, (%rdi)
movdqu %xmm3, (16)(%rdi)
movdqu %xmm4, (32)(%rdi)
movdqu %xmm5, (48)(%rdi)
pop %r13
pop %r12
ret
.Lfe12:
.size n8_sm2_select_ap_w7, .Lfe12-(n8_sm2_select_ap_w7)
|
; Z88 Small C+ Run Time Library
; Long functions
;
; feilipu 10/2021
SECTION code_clib
SECTION code_l_sccz80
PUBLIC l_long_mod
EXTERN l_long_div_u_0, l_long_neg_mhl
;remainder = primary % secondary
;enter with secondary (divisor) in dehl, primary (dividend | quotient) on stack
;exit with remainder in dehl
.l_long_mod
ld a,d ;check for divide by zero
or e
or h
or l ;clear Carry to quotient
jr Z, divide_by_zero
push de ;put secondary (divisor) on stack
push hl
ld bc,0 ;establish remainder on stack
push bc
push bc
ld c,d ;sign of divisor
ld de,sp+13 ;sign of dividend
ld a,(de)
ld b,a
push bc ;save sign info
ld de,sp+12 ;dividend
ex de,hl
or a,a ;test sign of dividend
call M,l_long_neg_mhl ;take absolute value of dividend
ld de,sp+6 ;divisor
ex de,hl
ld a,c ;sign of divisor
or a,a ;test sign of divisor
call M,l_long_neg_mhl ;take absolute value of divisor
call l_long_div_u_0 ;unsigned division
;tidy up with remainder to dehl
; C standard requires that the result of division satisfy
; a = (a/b)*b + a%b
; remainder takes sign of the dividend
pop af ;restore sign info
ld de,sp+0 ;remainder
ex de,hl
or a,a ;test sign of dividend
call M,l_long_neg_mhl ;negate remainder if dividend was negative
ld de,sp+8 ;get return from stack
ld hl,(de)
ld de,sp+12 ;place return on stack
ld (de),hl
ld de,sp+0 ;get remainder LSW
ld hl,(de)
ld bc,hl ;remainder LSW
ld de,sp+2 ;get remainder MSW
ld hl,(de)
ld de,sp+12 ;point to return again
ex de,hl ;remainder MSW <> return sp
ld sp,hl ;remove stacked parameters
ld hl,bc ;remainder LSW
ret
.divide_by_zero
pop bc ;pop return
pop hl ;pop dividend
pop de
push bc ;replace return
ld de,0 ;return ZERO
ld hl,de
ret
|
; A077957: Powers of 2 alternating with zeros.
; 1,0,2,0,4,0,8,0,16,0,32,0,64,0,128,0,256,0,512,0,1024,0,2048,0,4096,0,8192,0,16384,0,32768,0,65536,0,131072,0,262144,0,524288,0,1048576,0,2097152,0,4194304,0,8388608,0,16777216,0,33554432,0,67108864,0,134217728,0,268435456,0,536870912,0,1073741824,0,2147483648,0,4294967296,0,8589934592,0,17179869184,0,34359738368,0,68719476736,0,137438953472,0,274877906944,0,549755813888,0,1099511627776,0,2199023255552,0,4398046511104,0,8796093022208,0,17592186044416,0,35184372088832,0,70368744177664,0,140737488355328,0,281474976710656,0,562949953421312,0
mov $1,$0
div $0,2
sub $2,$1
gcd $1,2
pow $1,$0
mod $2,2
add $1,$2
mov $0,$1
|
; A188868: Number of nX3 binary arrays without the pattern 0 0 0 antidiagonally or horizontally
; Submitted by Jon Maiga
; 7,49,316,2032,13045,83737,537496,3450100,22145617,142149013,912430732,5856740200,37593435373,241305971377,1548902653984,9942146967292,63816977822953,409630502531629,2629349654724052,16877355480293296,108332920840868677,695370892176643849,4463469404621882536,28650263262579489412,183901246004989296385,1180431327008430481477,7576991173540391799196,48635438530257663646840,312182742048150296315677,2003848785532593985236193,12862370062279499473070512,82561401246178478201500300
add $0,1
lpb $0
sub $0,1
add $3,4
add $1,$3
add $1,$3
mul $4,2
add $4,2
mov $2,$4
add $4,$3
add $4,$1
add $2,$4
mov $3,$2
lpe
mov $0,$2
div $0,8
mul $0,3
add $0,1
|
Route17Mons:
db $19
db 26,DODUO ;day
db 27,PONYTA
db 27,DODUO
db 28,ROCKRUFF ;day
db 28,SKARMORY
db 30,PONYTA
db 29,FEAROW ;day
db 28,MILTANK
db 32,PONYTA
db 29,DODRIO
db $00
|
#include "Trampoline.h"
#include <cassert>
#include <functional>
#include <utility>
#include <nan.h>
namespace NodeGLSLCompiler {
static void trampolineAfterClose( uv_handle_t* handle ) {
delete reinterpret_cast<uv_async_t*>( handle );
}
static void trampolineCallback( uv_async_t* async ) {
auto task = static_cast< std::function<void()>* >( async->data );
async->data = nullptr;
if ( *task ) {
(*task)();
}
delete task;
uv_close( reinterpret_cast<uv_handle_t*>( async ), trampolineAfterClose );
}
Trampoline::Trampoline( uv_loop_t* loop ) : _async( new uv_async_t ) {
uv_async_init( loop, _async, trampolineCallback );
}
Trampoline::~Trampoline() {
assert( _async == nullptr );
}
void Trampoline::bounce( std::function<void()>&& task ) {
assert( _async );
_async->data = new std::function<void()>( std::move( task ) );
auto async = _async;
_async = nullptr;
uv_async_send( async );
}
} // namespace
|
include xlibproc.inc
include Wintab.inc
PROC_TEMPLATE WTMgrDefContextEx, 3, Wintab, -, 206
|
#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;
typedef long long i64;
typedef unsigned int u32;
typedef vector<int> IV;
typedef IV::const_iterator IVci;
#define cFor(t,v,c) for(t::const_iterator v=c.begin(); v != c.end(); v++)
// I/O
#define BUF 65536
struct Reader {
char buf[BUF]; char b; int bi, bz;
Reader() { bi=bz=0; read(); }
void read() {
if (bi==bz) { bi=0; bz = fread(buf, 1, BUF, stdin); }
b = bz ? buf[bi++] : 0; }
void skip() { while (b > 0 && b <= 32) read(); }
u32 next_u32() {
u32 v = 0; for (skip(); b > 32; read()) v = v*10 + b-48; return v; }
};
// Number Theory
#define IsComp(n) (_c[n>>6]&(1<<((n>>1)&31)))
#define SetComp(n) _c[n>>6]|=(1<<((n>>1)&31))
namespace Num
{
const int MAX = 1000003; // includes one prime over 10^6
const int LMT = 1001; // sqrt(MAX)
int _c[(MAX>>6)+1];
IV primes;
void primeSieve() {
for (int i = 3; i <= LMT; i += 2)
if (!IsComp(i)) for (int j = i*i; j <= MAX; j+=i+i) SetComp(j);
primes.push_back(2);
for (int i=3; i <= MAX; i+=2) if (!IsComp(i)) primes.push_back(i);
}
}
using namespace Num;
int main()
{
primeSieve();
Reader rr;
int T = rr.next_u32();
int ncase = 1;
while (T--) {
int n = rr.next_u32();
IV ns;
while (n--) {
int x = rr.next_u32();
ns.push_back(x);
}
sort(ns.begin(), ns.end());
i64 xukha = 0;
IVci p = primes.begin();
cFor (IV, num, ns) {
while (*num >= *p) p++;
xukha += *p;
}
printf("Case %d: %lld Xukha\n", ncase++, xukha);
}
return 0;
}
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <stddef.h>
#include <stdint.h>
#include <memory>
#include "base/bind.h"
#include "base/callback_helpers.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_task_runner_handle.h"
#include "build/chromeos_buildflags.h"
#include "extensions/browser/api/device_permissions_prompt.h"
#include "extensions/browser/api/hid/hid_device_manager.h"
#include "extensions/shell/browser/shell_extensions_api_client.h"
#include "extensions/shell/test/shell_apitest.h"
#include "extensions/test/extension_test_message_listener.h"
#include "services/device/public/cpp/hid/fake_hid_manager.h"
#include "services/device/public/cpp/hid/hid_report_descriptor.h"
#include "services/device/public/mojom/hid.mojom.h"
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "chromeos/dbus/permission_broker/fake_permission_broker_client.h"
#endif // BUILDFLAG(IS_CHROMEOS_ASH)
namespace extensions {
namespace {
using ::base::ThreadTaskRunnerHandle;
using ::device::FakeHidManager;
using ::device::HidReportDescriptor;
const char* const kTestDeviceGuids[] = {"A", "B", "C", "D", "E"};
const char* const kTestPhysicalDeviceIds[] = {"1", "2", "3", "4", "5"};
// These report descriptors define two devices with 8-byte input, output and
// feature reports. The first implements usage page 0xFF00 and has a single
// report without and ID. The second implements usage page 0xFF01 and has a
// single report with ID 1.
const uint8_t kReportDescriptor[] = {
0x06, 0x00, 0xFF, // Usage Page (Vendor Defined 0xFF00)
0x08, // Usage
0xA1, 0x01, // Collection (Application)
0x15, 0x00, // Logical Minimum (0)
0x26, 0xFF, 0x00, // Logical Maximum (255)
0x75, 0x08, // Report Size (8)
0x95, 0x08, // Report Count (8)
0x08, // Usage
0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,
// No Null Position)
0x08, // Usage
0x91, 0x02, // Output (Data,Var,Abs,No Wrap,Linear,Preferred State,
// No Null Position,Non-volatile)
0x08, // Usage
0xB1, 0x02, // Feature (Data,Var,Abs,No Wrap,Linear,Preferred
// State,No Null Position,Non-volatile)
0xC0, // End Collection
};
const uint8_t kReportDescriptorWithIDs[] = {
0x06, 0x01, 0xFF, // Usage Page (Vendor Defined 0xFF01)
0x08, // Usage
0xA1, 0x01, // Collection (Application)
0x15, 0x00, // Logical Minimum (0)
0x26, 0xFF, 0x00, // Logical Maximum (255)
0x85, 0x01, // Report ID (1)
0x75, 0x08, // Report Size (8)
0x95, 0x08, // Report Count (8)
0x08, // Usage
0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,
// No Null Position)
0x08, // Usage
0x91, 0x02, // Output (Data,Var,Abs,No Wrap,Linear,Preferred State,
// No Null Position,Non-volatile)
0x08, // Usage
0xB1, 0x02, // Feature (Data,Var,Abs,No Wrap,Linear,Preferred
// State,No Null Position,Non-volatile)
0xC0, // End Collection
};
// Device IDs for the device granted permission by the manifest.
constexpr uint16_t kTestVendorId = 0x18D1;
constexpr uint16_t kTestProductId = 0x58F0;
} // namespace
class TestDevicePermissionsPrompt
: public DevicePermissionsPrompt,
public DevicePermissionsPrompt::Prompt::Observer {
public:
explicit TestDevicePermissionsPrompt(content::WebContents* web_contents)
: DevicePermissionsPrompt(web_contents) {}
~TestDevicePermissionsPrompt() override { prompt()->SetObserver(nullptr); }
void ShowDialog() override { prompt()->SetObserver(this); }
void OnDevicesInitialized() override {
if (prompt()->multiple()) {
for (size_t i = 0; i < prompt()->GetDeviceCount(); ++i) {
prompt()->GrantDevicePermission(i);
}
prompt()->Dismissed();
} else {
for (size_t i = 0; i < prompt()->GetDeviceCount(); ++i) {
// Always choose the device whose serial number is "A".
if (prompt()->GetDeviceSerialNumber(i) == u"A") {
prompt()->GrantDevicePermission(i);
prompt()->Dismissed();
return;
}
}
}
}
void OnDeviceAdded(size_t index, const std::u16string& device_name) override {
}
void OnDeviceRemoved(size_t index,
const std::u16string& device_name) override {}
};
class TestExtensionsAPIClient : public ShellExtensionsAPIClient {
public:
TestExtensionsAPIClient() : ShellExtensionsAPIClient() {}
std::unique_ptr<DevicePermissionsPrompt> CreateDevicePermissionsPrompt(
content::WebContents* web_contents) const override {
return std::make_unique<TestDevicePermissionsPrompt>(web_contents);
}
};
class HidApiTest : public ShellApiTest {
public:
HidApiTest() {
#if BUILDFLAG(IS_CHROMEOS_ASH)
// Required for DevicePermissionsPrompt:
chromeos::PermissionBrokerClient::InitializeFake();
#endif
// Because Device Service also runs in this process (browser process), we
// can set our binder to intercept requests for HidManager interface to it.
fake_hid_manager_ = std::make_unique<FakeHidManager>();
auto binder = base::BindRepeating(
&FakeHidManager::Bind, base::Unretained(fake_hid_manager_.get()));
HidDeviceManager::OverrideHidManagerBinderForTesting(binder);
DevicePermissionsPrompt::OverrideHidManagerBinderForTesting(binder);
}
~HidApiTest() override {
HidDeviceManager::OverrideHidManagerBinderForTesting(base::NullCallback());
#if BUILDFLAG(IS_CHROMEOS_ASH)
chromeos::PermissionBrokerClient::Shutdown();
#endif
}
void SetUpOnMainThread() override {
ShellApiTest::SetUpOnMainThread();
AddDevice(kTestDeviceGuids[0], kTestPhysicalDeviceIds[0], kTestVendorId,
kTestProductId, false, "A");
AddDevice(kTestDeviceGuids[1], kTestPhysicalDeviceIds[1], kTestVendorId,
kTestProductId, true, "B");
AddDevice(kTestDeviceGuids[2], kTestPhysicalDeviceIds[2], kTestVendorId,
kTestProductId + 1, false, "C");
}
void AddDevice(const std::string& device_guid,
const std::string& physical_device_id,
int vendor_id,
int product_id,
bool report_id,
std::string serial_number) {
std::vector<uint8_t> report_descriptor;
if (report_id) {
report_descriptor.insert(
report_descriptor.begin(), kReportDescriptorWithIDs,
kReportDescriptorWithIDs + sizeof(kReportDescriptorWithIDs));
} else {
report_descriptor.insert(report_descriptor.begin(), kReportDescriptor,
kReportDescriptor + sizeof(kReportDescriptor));
}
std::vector<device::mojom::HidCollectionInfoPtr> collections;
bool has_report_id;
size_t max_input_report_size;
size_t max_output_report_size;
size_t max_feature_report_size;
HidReportDescriptor descriptor_parser(report_descriptor);
descriptor_parser.GetDetails(
&collections, &has_report_id, &max_input_report_size,
&max_output_report_size, &max_feature_report_size);
auto device = device::mojom::HidDeviceInfo::New(
device_guid, physical_device_id, vendor_id, product_id, "Test Device",
serial_number, device::mojom::HidBusType::kHIDBusTypeUSB,
report_descriptor, std::move(collections), has_report_id,
max_input_report_size, max_output_report_size, max_feature_report_size,
/*device_path=*/"",
/*protected_input_report_ids=*/std::vector<uint8_t>{},
/*protected_output_report_ids=*/std::vector<uint8_t>{},
/*protected_feature_report_ids=*/std::vector<uint8_t>{});
fake_hid_manager_->AddDevice(std::move(device));
}
FakeHidManager* GetFakeHidManager() { return fake_hid_manager_.get(); }
protected:
std::unique_ptr<FakeHidManager> fake_hid_manager_;
};
IN_PROC_BROWSER_TEST_F(HidApiTest, HidApp) {
ASSERT_TRUE(RunAppTest("api_test/hid/api")) << message_;
}
IN_PROC_BROWSER_TEST_F(HidApiTest, OnDeviceAdded) {
ExtensionTestMessageListener load_listener("loaded", false);
ExtensionTestMessageListener result_listener("success", false);
result_listener.set_failure_message("failure");
ASSERT_TRUE(LoadApp("api_test/hid/add_event"));
ASSERT_TRUE(load_listener.WaitUntilSatisfied());
// Add a blocked device first so that the test will fail if a notification is
// received.
AddDevice(kTestDeviceGuids[3], kTestPhysicalDeviceIds[3], kTestVendorId,
kTestProductId + 1, false, "A");
AddDevice(kTestDeviceGuids[4], kTestPhysicalDeviceIds[4], kTestVendorId,
kTestProductId, false, "A");
ASSERT_TRUE(result_listener.WaitUntilSatisfied());
EXPECT_EQ("success", result_listener.message());
}
IN_PROC_BROWSER_TEST_F(HidApiTest, OnDeviceRemoved) {
ExtensionTestMessageListener load_listener("loaded", false);
ExtensionTestMessageListener result_listener("success", false);
result_listener.set_failure_message("failure");
ASSERT_TRUE(LoadApp("api_test/hid/remove_event"));
ASSERT_TRUE(load_listener.WaitUntilSatisfied());
// Device C was not returned by chrome.hid.getDevices, the app will not get
// a notification.
GetFakeHidManager()->RemoveDevice(kTestDeviceGuids[2]);
// Device A was returned, the app will get a notification.
GetFakeHidManager()->RemoveDevice(kTestDeviceGuids[0]);
ASSERT_TRUE(result_listener.WaitUntilSatisfied());
EXPECT_EQ("success", result_listener.message());
}
IN_PROC_BROWSER_TEST_F(HidApiTest, GetUserSelectedDevices) {
ExtensionTestMessageListener open_listener("opened_device", false);
TestExtensionsAPIClient test_api_client;
ASSERT_TRUE(LoadApp("api_test/hid/get_user_selected_devices"));
ASSERT_TRUE(open_listener.WaitUntilSatisfied());
ExtensionTestMessageListener remove_listener("removed", false);
GetFakeHidManager()->RemoveDevice(kTestDeviceGuids[0]);
ASSERT_TRUE(remove_listener.WaitUntilSatisfied());
ExtensionTestMessageListener add_listener("added", false);
AddDevice(kTestDeviceGuids[0], kTestPhysicalDeviceIds[0], kTestVendorId,
kTestProductId, true, "A");
ASSERT_TRUE(add_listener.WaitUntilSatisfied());
}
namespace {
device::mojom::HidDeviceInfoPtr CreateDeviceWithOneCollection(
const std::string& guid) {
auto device_info = device::mojom::HidDeviceInfo::New();
device_info->guid = guid;
device_info->vendor_id = kTestVendorId;
device_info->product_id = kTestProductId;
auto collection = device::mojom::HidCollectionInfo::New();
collection->usage =
device::mojom::HidUsageAndPage::New(1, device::mojom::kPageVendor);
device_info->collections.push_back(std::move(collection));
return device_info;
}
device::mojom::HidDeviceInfoPtr CreateDeviceWithTwoCollections(
const std::string guid) {
auto device_info = CreateDeviceWithOneCollection(guid);
auto collection = device::mojom::HidCollectionInfo::New();
collection->usage =
device::mojom::HidUsageAndPage::New(2, device::mojom::kPageVendor);
collection->output_reports.push_back(
device::mojom::HidReportDescription::New());
device_info->collections.push_back(std::move(collection));
return device_info;
}
} // namespace
IN_PROC_BROWSER_TEST_F(HidApiTest, DeviceAddedChangedRemoved) {
constexpr char kTestGuid[] = "guid";
ExtensionTestMessageListener load_listener("loaded", false);
ExtensionTestMessageListener add_listener("added", true);
ExtensionTestMessageListener change_listener("changed", false);
ExtensionTestMessageListener result_listener("success", false);
result_listener.set_failure_message("failure");
ASSERT_TRUE(LoadApp("api_test/hid/add_change_remove"));
ASSERT_TRUE(load_listener.WaitUntilSatisfied());
// Add a device with one collection.
GetFakeHidManager()->AddDevice(CreateDeviceWithOneCollection(kTestGuid));
ASSERT_TRUE(add_listener.WaitUntilSatisfied());
// Update the device info to add a second collection. No event is generated,
// so we will reply to the |add_listener| to signal to the test that the
// change is complete.
GetFakeHidManager()->ChangeDevice(CreateDeviceWithTwoCollections(kTestGuid));
add_listener.Reply("device info updated");
ASSERT_TRUE(change_listener.WaitUntilSatisfied());
// Remove the device.
GetFakeHidManager()->RemoveDevice(kTestGuid);
ASSERT_TRUE(result_listener.WaitUntilSatisfied());
EXPECT_EQ("success", result_listener.message());
}
} // namespace extensions
|
#include <uWS/uWS.h>
#include <iostream>
#include "json.hpp"
#include <math.h>
#include "FusionEKF.h"
#include "tools.h"
using namespace std;
// for convenience
using json = nlohmann::json;
// Checks if the SocketIO event has JSON data.
// If there is data the JSON object in string format will be returned,
// else the empty string "" will be returned.
std::string hasData(std::string s) {
auto found_null = s.find("null");
auto b1 = s.find_first_of("[");
auto b2 = s.find_first_of("]");
if (found_null != std::string::npos) {
return "";
}
else if (b1 != std::string::npos && b2 != std::string::npos) {
return s.substr(b1, b2 - b1 + 1);
}
return "";
}
int main()
{
uWS::Hub h;
// Create a Kalman Filter instance
FusionEKF fusionEKF;
// used to compute the RMSE later
Tools tools;
vector<VectorXd> estimations;
vector<VectorXd> ground_truth;
h.onMessage([&fusionEKF,&tools,&estimations,&ground_truth](uWS::WebSocket<uWS::SERVER> ws, char *data, size_t length, uWS::OpCode opCode) {
// "42" at the start of the message means there's a websocket message event.
// The 4 signifies a websocket message
// The 2 signifies a websocket event
if (length && length > 2 && data[0] == '4' && data[1] == '2')
{
auto s = hasData(std::string(data));
if (s != "") {
auto j = json::parse(s);
std::string event = j[0].get<std::string>();
if (event == "telemetry") {
// j[1] is the data JSON object
string sensor_measurment = j[1]["sensor_measurement"];
MeasurementPackage meas_package;
istringstream iss(sensor_measurment);
long long timestamp;
// reads first element from the current line
string sensor_type;
iss >> sensor_type;
if (sensor_type.compare("L") == 0) {
meas_package.sensor_type_ = MeasurementPackage::LASER;
meas_package.raw_measurements_ = VectorXd(2);
float px;
float py;
iss >> px;
iss >> py;
meas_package.raw_measurements_ << px, py;
iss >> timestamp;
meas_package.timestamp_ = timestamp;
} else if (sensor_type.compare("R") == 0) {
meas_package.sensor_type_ = MeasurementPackage::RADAR;
meas_package.raw_measurements_ = VectorXd(3);
float ro;
float theta;
float ro_dot;
iss >> ro;
iss >> theta;
iss >> ro_dot;
meas_package.raw_measurements_ << ro,theta, ro_dot;
iss >> timestamp;
meas_package.timestamp_ = timestamp;
}
float x_gt;
float y_gt;
float vx_gt;
float vy_gt;
iss >> x_gt;
iss >> y_gt;
iss >> vx_gt;
iss >> vy_gt;
VectorXd gt_values(4);
gt_values(0) = x_gt;
gt_values(1) = y_gt;
gt_values(2) = vx_gt;
gt_values(3) = vy_gt;
ground_truth.push_back(gt_values);
//Call ProcessMeasurment(meas_package) for Kalman filter
fusionEKF.ProcessMeasurement(meas_package);
//Push the current estimated x,y positon from the Kalman filter's state vector
VectorXd estimate(4);
double p_x = fusionEKF.ekf_.x_(0);
double p_y = fusionEKF.ekf_.x_(1);
double v1 = fusionEKF.ekf_.x_(2);
double v2 = fusionEKF.ekf_.x_(3);
estimate(0) = p_x;
estimate(1) = p_y;
estimate(2) = v1;
estimate(3) = v2;
estimations.push_back(estimate);
VectorXd RMSE = tools.CalculateRMSE(estimations, ground_truth);
json msgJson;
msgJson["estimate_x"] = p_x;
msgJson["estimate_y"] = p_y;
msgJson["rmse_x"] = RMSE(0);
msgJson["rmse_y"] = RMSE(1);
msgJson["rmse_vx"] = RMSE(2);
msgJson["rmse_vy"] = RMSE(3);
auto msg = "42[\"estimate_marker\"," + msgJson.dump() + "]";
// std::cout << msg << std::endl;
ws.send(msg.data(), msg.length(), uWS::OpCode::TEXT);
}
} else {
std::string msg = "42[\"manual\",{}]";
ws.send(msg.data(), msg.length(), uWS::OpCode::TEXT);
}
}
});
// We don't need this since we're not using HTTP but if it's removed the program
// doesn't compile :-(
h.onHttpRequest([](uWS::HttpResponse *res, uWS::HttpRequest req, char *data, size_t, size_t) {
const std::string s = "<h1>Hello world!</h1>";
if (req.getUrl().valueLength == 1)
{
res->end(s.data(), s.length());
}
else
{
// i guess this should be done more gracefully?
res->end(nullptr, 0);
}
});
h.onConnection([&h](uWS::WebSocket<uWS::SERVER> ws, uWS::HttpRequest req) {
std::cout << "Connected!!!" << std::endl;
});
h.onDisconnection([&h](uWS::WebSocket<uWS::SERVER> ws, int code, char *message, size_t length) {
ws.close();
std::cout << "Disconnected" << std::endl;
});
int port = 4567;
if (h.listen(port))
{
std::cout << "Listening to port " << port << std::endl;
}
else
{
std::cerr << "Failed to listen to port" << std::endl;
return -1;
}
h.run();
}
|
; A221175: a(0)=-5, a(1)=6; thereafter a(n) = 2*a(n-1) + a(n-2).
; Submitted by Jon Maiga
; -5,6,7,20,47,114,275,664,1603,3870,9343,22556,54455,131466,317387,766240,1849867,4465974,10781815,26029604,62841023,151711650,366264323,884240296,2134744915,5153730126,12442205167,30038140460,72518486087,175075112634,422668711355,1020412535344,2463493782043,5947400099430,14358293980903,34663988061236,83686270103375,202036528267986,487759326639347,1177555181546680,2842869689732707,6863294561012094,16569458811756895,40002212184525884,96573883180808663,233149978546143210,562873840273095083
mov $1,1
mov $2,11
lpb $0
sub $0,1
mov $3,$2
mov $2,$1
mul $1,2
add $1,$3
lpe
sub $1,$2
mov $0,$1
div $0,2
|
; ===============================================================
; Feb 2014
; ===============================================================
;
; size_t w_vector_insert(w_vector_t *v, size_t idx, void *item)
;
; Insert item before vector.array[idx], returns index of
; word inserted.
;
; ===============================================================
SECTION code_clib
SECTION code_adt_w_vector
PUBLIC asm_w_vector_insert
EXTERN asm_b_vector_insert_block, error_mc
asm_w_vector_insert:
; enter : hl = vector *
; de = item
; bc = idx
;
; exit : success
;
; de = & vector.data[idx
; hl = idx of word inserted
; carry reset
;
; fail
;
; hl = -1
; carry set, errno set
;
; uses : af, bc, de, hl
push bc ; save idx
sla c
rl b
jp c, error_mc - 1
push de ; save item
ld de,2
call asm_b_vector_insert_block
pop de ; de = item
jp c, error_mc - 1 ; if insert error
ld (hl),e
inc hl
ld (hl),d ; write inserted word
dec hl
ex de,hl
pop hl ; hl = idx
ret
|
; A011195: a(n) = n*(n+1)*(2*n+1)*(3*n+1)/6.
; 0,4,35,140,390,880,1729,3080,5100,7980,11935,17204,24050,32760,43645,57040,73304,92820,115995,143260,175070,211904,254265,302680,357700,419900,489879,568260,655690,752840,860405,979104,1109680,1252900,1409555,1580460,1766454,1968400,2187185,2423720,2678940,2953804,3249295,3566420,3906210,4269720,4658029,5072240,5513480,5982900,6481675,7011004,7572110,8166240,8794665,9458680,10159604,10898780,11677575,12497380,13359610,14265704,15217125,16215360,17261920,18358340,19506179,20707020,21962470,23274160,24643745,26072904,27563340,29116780,30734975,32419700,34172754,35995960,37891165,39860240,41905080,44027604,46229755,48513500,50880830,53333760,55874329,58504600,61226660,64042620,66954615,69964804,73075370,76288520,79606485,83031520,86565904,90211940,93971955,97848300,101843350,105959504,110199185,114564840,119058940,123683980,128442479,133336980,138370050,143544280,148862285,154326704,159940200,165705460,171625195,177702140,183939054,190338720,196903945,203637560,210542420,217621404,224877415,232313380,239932250,247737000,255730629,263916160,272296640,280875140,289654755,298638604,307829830,317231600,326847105,336679560,346732204,357008300,367511135,378244020,389210290,400413304,411856445,423543120,435476760,447660820,460098779,472794140,485750430,498971200,512460025,526220504,540256260,554570940,569168215,584051780,599225354,614692680,630457525,646523680,662894960,679575204,696568275,713878060,731508470,749463440,767746929,786362920,805315420,824608460,844246095,864232404,884571490,905267480,926324525,947746800,969538504,991703860,1014247115,1037172540,1060484430,1084187104,1108284905,1132782200,1157683380,1182992860,1208715079,1234854500,1261415610,1288402920,1315820965,1343674304,1371967520,1400705220,1429892035,1459532620,1489631654,1520193840,1551223905,1582726600,1614706700,1647169004,1680118335,1713559540,1747497490,1781937080,1816883229,1852340880,1888315000,1924810580,1961832635,1999386204,2037476350,2076108160,2115286745,2155017240,2195304804,2236154620,2277571895,2319561860,2362129770,2405280904,2449020565,2493354080,2538286800,2583824100,2629971379,2676734060,2724117590,2772127440,2820769105,2870048104,2919969980,2970540300,3021764655,3073648660,3126197954,3179418200,3233315085,3287894320,3343161640,3399122804,3455783595,3513149820,3571227310,3630021920,3689539529,3749786040,3810767380,3872489500
mov $2,$0
mov $7,$0
lpb $0
add $1,$0
sub $0,1
add $4,$2
add $1,$4
add $2,2
lpe
mov $5,$7
mov $8,$7
lpb $5
sub $5,1
add $6,$8
lpe
mov $5,$7
mov $8,$6
mov $6,0
lpb $5
sub $5,1
add $6,$8
lpe
mov $3,1
mov $8,$6
lpb $3
add $1,$8
sub $3,1
lpe
mov $5,$7
mov $6,0
lpb $5
sub $5,1
add $6,$8
lpe
mov $3,1
mov $8,$6
lpb $3
add $1,$8
sub $3,1
lpe
|
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#include <aws/workmail/model/UntagResourceResult.h>
#include <aws/core/utils/json/JsonSerializer.h>
#include <aws/core/AmazonWebServiceResult.h>
#include <aws/core/utils/StringUtils.h>
#include <aws/core/utils/UnreferencedParam.h>
#include <utility>
using namespace Aws::WorkMail::Model;
using namespace Aws::Utils::Json;
using namespace Aws::Utils;
using namespace Aws;
UntagResourceResult::UntagResourceResult()
{
}
UntagResourceResult::UntagResourceResult(const Aws::AmazonWebServiceResult<JsonValue>& result)
{
*this = result;
}
UntagResourceResult& UntagResourceResult::operator =(const Aws::AmazonWebServiceResult<JsonValue>& result)
{
AWS_UNREFERENCED_PARAM(result);
return *this;
}
|
; Disk drive controls
; Disk commands:
; 1: Read disk name
; 2: Write disk name
; 3: Read disk serial
; 4: Read disk sector
; 5: Write disk sector
; 6: Clear sector buffer
dvar DISKADDR,8,,,
bind_disk:
lda var_DISKADDR
mmu $00
rts
dcode BINDDISK,8,F_HIDDEN,
jsr bind_disk
nxt
dword DISKCMD,7,,
.wp BINDDISK
.lit $82
.wp BUS_POKEBYTE
.wp TICK
.wp EXIT
dword SAVE,4,,
.wp BINDDISK
.wp ZERO
SAVE_loop:
.wp TOR
.wp RFETCH ; i
.lit $80
.wp BUS_POKE
.lit $0500
.wp RFETCH
.lit $80
.wp UMUL
.wp ADD
.wp BUS_GETWIN
.lit $80
.wp MEMCPY
.lit 5
.wp DISKCMD
.wp FROMR ; i
.wp INCR ; i+1
.wp DUP ; i i
.wp HERE
.lit $0500
.wp SUB
.lit $80
.wp UDIV ; i i max
.wp LE ; i cond
.zbranch SAVE_end ; i
.branch SAVE_loop
SAVE_end:
.wp DROP
.wp EXIT
.ifcflag disk_ext
BLKBUF_INT: db 0,0
dword BLKBUF,6,,
.lit BLKBUF_INT
.wp PEEK
.zbranch BLKBUF_allot
.lit BLKBUF_INT
.wp PEEK
.wp EXIT
BLKBUF_allot:
.lit 1024
.wp ALLOT
.wp DUP
.lit BLKBUF_INT
.wp POKE
.wp EXIT
dvar BLKNO,5,,,
dvar BLKINT,6,F_HIDDEN,,_F_TRUE
dword CLDRBUF,7,F_HIDDEN,
.lit 6
.wp DISKCMD
.wp EXIT
dword DISKNAME",9,,SET_DISKNAME
.wp CLDRBUF
.lit $22
.wp PARSE ; addr len
.wp TWODUP
.wp BUS_GETWIN
.wp SWAP
.wp MEMCPY
.lit 2
.wp DISKCMD
.wp EXIT
dword BLOCK,5,,
.wp BLKNO
.wp POKE
.wp REVERT
.wp EXIT
dword REVERT,6,, ; get 8 sectors (128 * 8 = 1024) into the buffer
.wp BINDDISK
.wp BLKNO
.wp PEEK
.lit 8
.wp MUL ; origin
.lit 0
REVERT_loop:
.wp TOR
.wp RFETCH ; origin i
.wp OVER ; origin i origin
.wp ADD ; origin current-sector
.lit $80
.wp BUS_POKE ; origin
.lit 4
.wp DISKCMD
.wp BUS_GETWIN ; origin c-origin
.wp RFETCH
.lit 128
.wp UMUL
.wp BLKBUF
.wp ADD
.lit 128 ; origin c-origin c-target c-length
.wp MEMCPY ; origin
.wp FROMR ; origin i
.wp INCR ; origin i+1
.wp DUP ; origin i i
.lit 8
.wp LT ; origin i cond
.zbranch REVERT_end ; origin i
.branch REVERT_loop
REVERT_end:
.wp TWODROP
.wp EXIT
dword FLUSH,5,,
.wp BINDDISK
.wp BLKNO
.wp PEEK
.lit 8
.wp MUL ; origin
.wp ZERO
FLUSH_loop:
.wp TOR
.wp RFETCH ; origin i
.wp OVER ; origin i origin
.wp ADD ; origin current-sector
.lit $80
.wp BUS_POKE ; origin
.wp BUS_GETWIN ; origin c-origin
.wp RFETCH
.lit 128
.wp UMUL
.wp BLKBUF
.wp ADD
.wp SWAP
.lit 128 ; origin c-origin c-target c-length
.wp MEMCPY ; origin
.lit 5
.wp DISKCMD
.wp FROMR ; origin i
.wp INCR ; origin i+1
.wp DUP ; origin i i
.lit 8
.wp LT ; origin i cond
.zbranch FLUSH_end ; origin i
.branch FLUSH_loop
FLUSH_end:
.wp TWODROP
.wp EXIT
dword LIST,4,,
.wp CR
.lit 0
LIST_loop:
.wp TOR
.wp RFETCH
.lit 2
.wp PRINT_UNUM_ALIGN
.wp SPACE
.wp BLKBUF
.wp RFETCH
.lit 64
.wp MUL
.wp ADD
.lit 64
.wp TYPE
.wp CR
.wp FROMR
.wp INCR
.wp DUP
.lit 16
.wp EQU
.zbranch LIST_loop
.wp DROP
.wp EXIT
dword WIPE,4,,
.wp BL
.wp BLKBUF
.lit 1024
.wp FILL
.wp EXIT
dconst BLKSIZE,7,F_HIDDEN,,128
dword BLKCEIL,7,F_HIDDEN,
.wp DECR
.wp BLKSIZE
.wp UDIV
.wp INCR
.wp BLKSIZE
.wp UMUL
.wp EXIT
dword PP,2,,
.wp BL ; ln bl
.wp BLKBUF ; ln bl blkbuf
.wp ROT ; bl blkbuf ln
.lit 64
.wp UMUL ; bl blkbuf offset
.wp ADD ; bl pos
.wp TUCK ; pos bl pos
.lit 64
.wp FILL ; pos
.lit $FF
.wp PARSE ; pos addr len
.wp ROT ; addr len pos
.wp SWAP ; addr pos len
.lit 64
.wp MIN
.wp MEMCPY
.wp EXIT
dword LOAD,4,, ; ( blockid -- )
.wp BLKNO
.wp PEEK
.wp TOR
.wp BLOCK
.lit 0
LOAD_loop:
.wp TOR
.wp RFETCH
.lit 64
.wp UMUL
.wp BLKBUF
.wp ADD
.lit 64
.wp INTERPRET
.wp FROMR
.wp INCR
.wp DUP
.lit 16
.wp LT
.zbranch LOAD_end
.branch LOAD_loop
LOAD_end:
.wp DROP
.wp FROMR
.wp BLOCK
.wp EXIT
.endif |
;; =============================================================================
;; ATA read sectors (LBA mode)
;;
;; Modification/rewrite of code found at osdev:
;; http://wiki.osdev.org/ATA_read/write_sectors#Read_in_LBA_mode
;; Licence: ...assumed to be in public domain
;; @param EAX Logical Block Address of sector
;; @param CL Number of sectors to read
;; @param EDI The address of buffer to put data obtained from disk
;; @return None
;; =============================================================================
ata_lba_read:
pusha
and eax, 0x0FFFFFFF
mov ebx, eax ; Save LBA in RBX
mov edx, 0x01F6 ; Port to send drive and bit 24 - 27 of LBA
shr eax, 24 ; Get bit 24 - 27 in al
or al, 11100000b ; Set bit 6 in al for LBA mode
out dx, al
mov edx, 0x01F2 ; Port to send number of sectors
mov al, cl ; Get number of sectors from CL
out dx, al
mov edx, 0x1F3 ; Port to send bit 0 - 7 of LBA
mov eax, ebx ; Get LBA from EBX
out dx, al
mov edx, 0x1F4 ; Port to send bit 8 - 15 of LBA
mov eax, ebx ; Get LBA from EBX
shr eax, 8 ; Get bit 8 - 15 in AL
out dx, al
mov edx, 0x1F5 ; Port to send bit 16 - 23 of LBA
mov eax, ebx ; Get LBA from EBX
shr eax, 16 ; Get bit 16 - 23 in AL
out dx, al
mov edx, 0x1F7 ; Command port
mov al, 0x20 ; Read with retry.
out dx, al
;; Check for errors
in al,dx
.drive_buffering:
in al, dx
test al, 8 ; the sector buffer requires servicing.
jz .drive_buffering ; until the sector buffer is ready.
test al, 64 ; Drive executing command
jz .drive_buffering
test al, 6
jnz .drive_buffering
test al,1 ; There was an error
jz .fetch_data
;; There was a read error...
mov eax,0x00BADBAD
cli
hlt
.fetch_data:
mov bl, cl ; read CL sectors
mov dx, 0x1F0 ; Data port, in and out
;;xor bx, bx
;;mul bx
mov cx, 256 ; CX is counter for INSW
rep insw ; read in to [EDI]
in al, dx
in al, dx
in al, dx
in al, dx
popa
ret
|
; A199030: 10*11^n-1.
; 9,109,1209,13309,146409,1610509,17715609,194871709,2143588809,23579476909,259374246009,2853116706109,31384283767209,345227121439309,3797498335832409,41772481694156509,459497298635721609,5054470284992937709,55599173134922314809,611590904484145462909,6727499949325600092009,74002499442581601012109,814027493868397611133209,8954302432552373722465309,98497326758076110947118409,1083470594338837220418302509,11918176537727209424601327609,131099941914999303670614603709,1442099361064992340376760640809,15863092971714915744144367048909,174494022688864073185588037538009,1919434249577504805041468412918109,21113776745352552855456152542099209,232251544198878081410017677963091309
mov $1,11
pow $1,$0
mul $1,10
sub $1,1
mov $0,$1
|
VDC_0 .equ $0000
VDC_1 .equ $0001
VDC_2 .equ $0002
VDC_3 .equ $0003
VDC1_0 .equ VDC_0
VDC1_1 .equ VDC_1
VDC1_2 .equ VDC_2
VDC1_3 .equ VDC_3
VDC2_0 .equ $0010
VDC2_1 .equ $0011
VDC2_2 .equ $0012
VDC2_3 .equ $0013
VPC_0 .equ $0008
VPC_1 .equ $0009
VPC_2 .equ $000A
VPC_3 .equ $000B
VPC_4 .equ $000C
VPC_5 .equ $000D
VPC_6 .equ $000E
VPC_7 .equ $000F
VCE_0 .equ $0400
VCE_1 .equ $0401
VCE_2 .equ $0402
VCE_3 .equ $0403
VCE_4 .equ $0404
VCE_5 .equ $0405
VCE_6 .equ $0406
VCE_7 .equ $0407
INT_DIS_REG .equ $1402
IO_PAD .equ $1000
charDataBank .equ $01
spXYDataBank .equ $02
spBankDataBank .equ $22
spNoDataBank .equ $23
spDataBank .equ $24
stageBank .equ $29
;----------------------------
jcc .macro
bcs .jp\@
jmp \1
.jp\@
.endm
;----------------------------
jeq .macro
bne .jp\@
jmp \1
.jp\@
.endm
;----------------------------
add .macro
;\1 = \2 + \3
;\1 = \1 + \2
.if (\# = 3)
clc
lda \2
adc \3
sta \1
.else
.if (\# = 2)
clc
lda \1
adc \2
sta \1
.else
clc
adc \1
.endif
.endif
.endm
;----------------------------
sub .macro
;\1 = \2 - \3
;\1 = \1 - \2
.if (\# = 3)
sec
lda \2
sbc \3
sta \1
.else
.if (\# = 2)
sec
lda \1
sbc \2
sta \1
else
sec
sbc \1
.endif
.endif
.endm
;----------------------------
addw .macro
;\1 = \2 + \3
;\1 = \1 + \2
.if (\# = 3)
clc
lda \2
adc \3
sta \1
lda \2+1
adc \3+1
sta \1+1
.else
clc
lda \1
adc \2
sta \1
lda \1+1
adc \2+1
sta \1+1
.endif
.endm
;----------------------------
subw .macro
;\1 = \2 - \3
;\1 = \1 - \2
.if (\# = 3)
sec
lda \2
sbc \3
sta \1
lda \2+1
sbc \3+1
sta \1+1
.else
sec
lda \1
sbc \2
sta \1
lda \1+1
sbc \2+1
sta \1+1
.endif
.endm
;----------------------------
addq .macro
;\1 = \2 + \3
;\1 = \1 + \2
.if (\# = 3)
clc
lda \2
adc \3
sta \1
lda \2+1
adc \3+1
sta \1+1
lda \2+2
adc \3+2
sta \1+2
lda \2+3
adc \3+3
sta \1+3
.else
clc
lda \1
adc \2
sta \1
lda \1+1
adc \2+1
sta \1+1
lda \1+2
adc \2+2
sta \1+2
lda \1+3
adc \2+3
sta \1+3
.endif
.endm
;----------------------------
subq .macro
;\1 = \2 - \3
;\1 = \1 - \2
.if (\# = 3)
sec
lda \2
sbc \3
sta \1
lda \2+1
sbc \3+1
sta \1+1
lda \2+2
sbc \3+2
sta \1+2
lda \2+3
sbc \3+3
sta \1+3
.else
sec
lda \1
sbc \2
sta \1
lda \1+1
sbc \2+1
sta \1+1
lda \1+2
sbc \2+2
sta \1+2
lda \1+3
sbc \2+3
sta \1+3
.endif
.endm
;----------------------------
mov .macro
;\1 = \2
lda \2
sta \1
.endm
;----------------------------
movw .macro
;\1 = \2
lda \2
sta \1
lda \2+1
sta \1+1
.endm
;----------------------------
movq .macro
;\1 = \2
lda \2
sta \1
lda \2+1
sta \1+1
lda \2+2
sta \1+2
lda \2+3
sta \1+3
.endm
.zp
;///////////////////////////////////////////////
.org $2000
;-----------------------------------------------
spDataWorkX .ds 2
spDataWorkY .ds 2
spDataWorkBGX .ds 1
spDataWorkBGY .ds 1
spDataWorkNo .ds 2
spDataWorkAttr .ds 2
spDataAddr .ds 2
spDataAddrWork .ds 2
spDataCount .ds 1
spCharWorkAddr .ds 2
bgDataWorkAddr .ds 2
screenAngle .ds 1
screenAngle2 .ds 1
vsyncFlag .ds 1
bgCenterSpXPoint .ds 1
bgCenterSpX .ds 1
bgCenterX .ds 1
bgCenterSpYPoint .ds 1
bgCenterSpY .ds 1
bgCenterY .ds 1
bgCenterSpXAdjust .ds 1
bgCenterSpYAdjust .ds 1
bgCenterSpXPointLast .ds 1
bgCenterSpXLast .ds 1
bgCenterXLast .ds 1
bgCenterSpYPointLast .ds 1
bgCenterSpYLast .ds 1
bgCenterYLast .ds 1
bgCalcCenterSpX .ds 1
bgCalcCenterX .ds 1
bgCalcCenterSpY .ds 1
bgCalcCenterY .ds 1
angleCheckWork .ds 1
bgBank .ds 1
hitFlag .ds 1
scrollWork .ds 1
bgCenterMovement .ds 2
ballSpeed .ds 2
ballSpeedWork .ds 2
setBgWork .ds 2
;---------------------
;LDRU SsBA
padlast .ds 1
padnow .ds 1
padstate .ds 1
;---------------------
vdpstatus .ds 1
;---------------------
mul16a .ds 2
mul16b .ds 2
mul16c .ds 2
mul16d .ds 2
;---------------------
puthexaddr .ds 2
puthexdata .ds 1
;---------------------
rotationAngle .ds 1
rotationX .ds 2
rotationY .ds 2
rotationAnsX .ds 4
rotationAnsY .ds 4
.bss
;///////////////////////////////////////////////
.org $2100
;stack area
;-----------------------------------------------
;///////////////////////////////////////////////
.org $2200
;-----------------------------------------------
spAttrWork .ds 32
hitWorkNo .ds 32
hitWorkSpX .ds 32
hitWorkSpY .ds 32
hitWorkX .ds 1
hitWorkFlag .ds 8
tiafunc .ds 8
tiifunc .ds 8
;///////////////////////////////////////////////
.code
.bank 0
.org $E000
;----------------------------
main:
;initialize
jsr initializeVdp
jsr setCharData
;++++++++++++++++++++++++++++
;set tiafunc tiifunc
lda #$E3; tia
sta tiafunc
lda #$73; tii
sta tiifunc
lda #$60; rts
sta tiafunc+7
sta tiifunc+7
;++++++++++++++++++++++++++++
;set bg0 char
stz VPC_6 ;reg6 select VDC#1
st0 #$00 ;VRAM $0000
st1 #$00
st2 #$00
st0 #$02
ldy #4 * 32
.setBg0Loop2:
st1 #$01
st2 #$01
dey
bne .setBg0Loop2
ldy #30 - 4 * 2
.setBg0Loop0:
clx
.setBg0Loop1:
lda bg0data,x
sta VDC1_2
st2 #$01
inx
cpx #32
bne .setBg0Loop1
dey
bne .setBg0Loop0
ldy #4 * 32
.setBg0Loop3:
st1 #$01
st2 #$01
dey
bne .setBg0Loop3
;++++++++++++++++++++++++++++
;set bg1 char
lda #$01
sta VPC_6 ;reg6 select VDC#2
st0 #$00 ;VRAM $0000
st1 #$00
st2 #$00
st0 #$02
ldx #4
lda #LOW(bg1data)
sta <setBgWork
lda #HIGH(bg1data)
sta <setBgWork+1
.setBg1Loop0:
cly
.setBg1Loop1:
lda [setBgWork], y
sta VDC2_2
st2 #$01
iny
bne .setBg1Loop1
inc <setBgWork+1
dex
bne .setBg1Loop0
;++++++++++++++++++++++++++++
;set sp ball char
stz VPC_6 ;reg6 select VDC#1
st0 #$00 ;VRAM $0500
st1 #$00
st2 #$05
st0 #$02
tia spballdata, VDC1_2, 128
;++++++++++++++++++++++++++++
;initialize data
lda #128
sta <screenAngle
lda #5
sta <bgCenterX
lda #24
sta <bgCenterY
lda #6
sta <bgCenterSpX
lda #6
sta <bgCenterSpY
stz bgCenterSpXPoint
stz bgCenterSpYPoint
stz <bgCenterMovement
stz <bgCenterMovement+1
stz <ballSpeed
stz <ballSpeed+1
lda #stageBank
sta <bgBank
stz <scrollWork
;++++++++++++++++++++++++++++
;clear vsync flag
rmb7 <vsyncFlag
cli
;++++++++++++++++++++++++++++
.mainloop:
;wait vsync
bbs7 <vsyncFlag, .mainloop
;++++++++++++++++++++++++++++
;check pad rotation
bbs5 <padnow, .checkPadLeft
bbs7 <padnow, .checkPadRight
bra .checkPadEnd
.checkPadLeft:
inc <screenAngle
inc <screenAngle
bra .checkPadEnd
.checkPadRight:
dec <screenAngle
dec <screenAngle
.checkPadEnd:
lda <screenAngle
eor #$80
sta <screenAngle2
;++++++++++++++++++++++++++++
;move down
stz <bgCenterMovement
lda #1
sta <bgCenterMovement+1
lda <ballSpeed+1
sta <ballSpeedWork+1
.moveDownLoop0:
beq .moveDownJump0
jsr moveDown
beq .moveDownJump1
bcs .moveDownJump1
dec <ballSpeedWork+1
bra .moveDownLoop0
.moveDownJump0:
lda <ballSpeed
sta <bgCenterMovement
stz <bgCenterMovement+1
jsr moveDown
beq .moveDownJump1
bcs .moveDownJump1
bra .moveDownJump2
.moveDownJump1:
stz <ballSpeed
stz <ballSpeed+1
.moveDownJump2:
;++++++++++++++++++++++++++++
;angle bgCenter put
ldx #0
ldy #2
lda <screenAngle
jsr puthex
ldx #0
ldy #3
lda <bgCenterX
jsr puthex
ldx #2
ldy #3
lda <bgCenterSpX
jsr puthex
ldx #6
ldy #3
lda <bgCenterY
jsr puthex
ldx #8
ldy #3
lda <bgCenterSpY
jsr puthex
;++++++++++++++++++++++++++++
;set center adjust
lda <screenAngle2
sta <rotationAngle
stz <rotationX
mov <rotationX+1 ,<bgCenterSpX
stz <rotationY
mov <rotationY+1, <bgCenterSpY
jsr rotationProc
mov <bgCenterSpXAdjust, <rotationAnsX+2
mov <bgCenterSpYAdjust, <rotationAnsY+2
;++++++++++++++++++++++++++++
;set sp char data
stz VPC_6 ;reg6 select VDC#1
st0 #$00 ;VRAM $4000
st1 #$00
st2 #$40
st0 #$02
lda #$01
sta VPC_6 ;reg6 select VDC#2
st0 #$00 ;VRAM $4000
st1 #$00
st2 #$40
st0 #$02
;++++++++++++++++++++++++++++
;sp bank data
lda #spBankDataBank
tam #$02 ;Set $4000
stz <spCharWorkAddr
lda <screenAngle2
lsr a
ror <spCharWorkAddr
lsr a
ror <spCharWorkAddr
lsr a
ror <spCharWorkAddr
ora #$40
sta <spCharWorkAddr+1
cly
.setSpCharLoop0:
lda [spCharWorkAddr], y
cmp #$FF
beq .setSpCharEnd
add #spDataBank
tam #$03 ;Set $6000
iny
lda [spCharWorkAddr], y
sta tiafunc+1
iny
lda [spCharWorkAddr], y
ora #$60
sta tiafunc+2
iny
lda #LOW(VDC1_2)
sta tiafunc+3
lda #HIGH(VDC1_2)
sta tiafunc+4
lda #$80
sta tiafunc+5
lda #$00
sta tiafunc+6
jsr tiafunc
lda #LOW(VDC2_2)
sta tiafunc+3
lda #HIGH(VDC2_2)
sta tiafunc+4
jsr tiafunc
iny
cpy #$20
bne .setSpCharLoop0
.setSpCharEnd:
;++++++++++++++++++++++++++++
;set sp xy data
lda <screenAngle2
lsr a
lsr a
lsr a
add #spXYDataBank
tam #$02 ;Set $4000
lda <screenAngle2
and #$07
asl a
asl a
ora #$40
stz <spDataAddrWork
sta <spDataAddrWork+1
;++++++++++++++++++++++++++++
;sp attr data
lda #spNoDataBank
tam #$03 ;Set $6000
stz tiifunc+1
lda <screenAngle2
lsr a
ror tiifunc+1
lsr a
ror tiifunc+1
lsr a
ror tiifunc+1
ora #$60
sta tiifunc+2
lda #LOW(spAttrWork)
sta tiifunc+3
lda #HIGH(spAttrWork)
sta tiifunc+4
lda #$20
sta tiifunc+5
lda #$00
sta tiifunc+6
jsr tiifunc
;++++++++++++++++++++++++++++
;SP LEFT
stz VPC_6 ;reg6 select VDC#1
;center ball
st0 #$00 ;VRAM $0400
st1 #$00
st2 #$04
st0 #$02
st1 #120 + 64 - 8
st2 #$00
st1 #128 + 32 - 8
st2 #$00
st1 #$28
st2 #$00
st1 #$00
st2 #$00
lda <spDataAddrWork ;Set SPXYDATA LEFT ADDR
sta <spDataAddr
lda <spDataAddrWork+1
sta <spDataAddr+1
lda #63
sta <spDataCount
;SpData 256(angles) * 128(data) * 4(bytes)[spx,spy,bgx,bgy] * 2(left and right) = 256K
cly
.spLDataLoop0:
lda [spDataAddr], y
cmp #$FF
jeq .spLDataJump3
.spLDataJump5:
sta <spDataWorkX
stz <spDataWorkX+1
iny
lda [spDataAddr], y
sta <spDataWorkY
stz <spDataWorkY+1
iny
lda [spDataAddr], y
add <bgCenterX
sta <spDataWorkBGX
iny
lda [spDataAddr], y
add <bgCenterY
sta <spDataWorkBGY
iny
bne .spLDataJump0
inc <spDataAddr+1
.spLDataJump0:
;check bg
mov <bgCalcCenterX, <spDataWorkBGX
mov <bgCalcCenterY, <spDataWorkBGY
jsr getBgData
beq .spLDataLoop0
dec a
asl a
tax
;sp x
lda <spDataWorkX
sub bgCenterSpXAdjust
cmp #8*8+1
bcc .spLDataLoop0
sta <spDataWorkX
lda <spDataWorkX
add #32
sta <spDataWorkX
bcc .spLDataJump1
inc <spDataWorkX+1
.spLDataJump1:
;sp y
lda <spDataWorkY
sub bgCenterSpYAdjust
cmp #8*26
bcs .spLDataLoop0
sta <spDataWorkY
lda <spDataWorkY
add #64
sta <spDataWorkY
bcc .spLDataJump2
inc <spDataWorkY+1
.spLDataJump2:
lda <spDataWorkY
sta VDC1_2
lda <spDataWorkY+1
sta VDC1_3
lda <spDataWorkX
sta VDC1_2
lda <spDataWorkX+1
sta VDC1_3
lda spAttrWork, x ;No
sta VDC1_2
lda #$02
sta VDC1_3
lda spAttrWork+1, x ;ATTR
stz VDC1_2
sta VDC1_3
dec <spDataCount
beq .spLDataJump4
jmp .spLDataLoop0
.spLDataJump3:
.spLDataJump4:
;put left sp count
ldx #0
ldy #5
lda <spDataCount
jsr puthex
;++++++++++++++++++++++++++++
;SP RIGHT
lda #$01
sta VPC_6 ;reg6 select VDC#2
st0 #$00 ;VRAM $0404
st1 #$04
st2 #$04
st0 #$02
lda <spDataAddrWork ;Set SPXYDATA RIGHT ADDR
sta <spDataAddr
lda <spDataAddrWork+1
ora #$02
sta <spDataAddr+1
lda #63
sta <spDataCount
cly
.spRDataLoop0:
lda [spDataAddr], y
cmp #$FF
jeq .spRDataJump3
.spRDataJump5:
sta <spDataWorkX
stz <spDataWorkX+1
iny
lda [spDataAddr], y
sta <spDataWorkY
stz <spDataWorkY+1
iny
lda [spDataAddr], y
add <bgCenterX
sta <spDataWorkBGX
iny
lda [spDataAddr], y
add <bgCenterY
sta <spDataWorkBGY
iny
bne .spRDataJump0
inc <spDataAddr+1
.spRDataJump0:
;check bg
mov <bgCalcCenterX, <spDataWorkBGX
mov <bgCalcCenterY, <spDataWorkBGY
jsr getBgData
beq .spRDataLoop0
dec a
asl a
tax
;sp x
lda <spDataWorkX
sub bgCenterSpXAdjust
cmp #8*22
bcs .spRDataLoop0
sta <spDataWorkX
lda <spDataWorkX
add #32
sta <spDataWorkX
bcc .spRDataJump1
inc <spDataWorkX+1
.spRDataJump1:
;sp y
lda <spDataWorkY
sub bgCenterSpYAdjust
cmp #8*26
bcs .spRDataLoop0
sta <spDataWorkY
lda <spDataWorkY
add #64
sta <spDataWorkY
bcc .spRDataJump2
inc <spDataWorkY+1
.spRDataJump2:
lda <spDataWorkY
sta VDC2_2
lda <spDataWorkY+1
sta VDC2_3
lda <spDataWorkX
sta VDC2_2
lda <spDataWorkX+1
sta VDC2_3
lda spAttrWork, x ;No
sta VDC2_2
lda #$02
sta VDC2_3
lda #$80 ;ATTR
sta VDC2_2
lda spAttrWork+1, x ;ATTR
sta VDC2_3
dec <spDataCount
beq .spRDataJump4
jmp .spRDataLoop0
.spRDataJump3:
.spRDataJump4:
;put right sp count
ldx #4
ldy #5
lda <spDataCount
jsr puthex
;++++++++++++++++++++++++++++
;SATB DMA set
stz VPC_6 ;reg6 select VDC#1
st0 #$13
st1 #$00
st2 #$04
lda #$01
sta VPC_6 ;reg6 select VDC#2
st0 #$13
st1 #$00
st2 #$04
;++++++++++++++++++++++++++++
;set vsync flag
smb7 <vsyncFlag
;++++++++++++++++++++++++++++
;add movement
lda <ballSpeed+1
cmp #2
beq .addMovementJump
inc <ballSpeed
inc <ballSpeed
bne .addMovementJump
inc <ballSpeed+1
.addMovementJump:
;++++++++++++++++++++++++++++
;jump mainloop
jmp .mainloop
;----------------------------
setCharData:
;CHAR set to vram
lda #charDataBank
tam #$02
;vram address $1000
stz VPC_6 ;reg6 select VDC#1
st0 #$00
st1 #$00
st2 #$10
st0 #$02
tia $4000, VDC1_2, $2000
lda #$01
sta VPC_6 ;reg6 select VDC#2
st0 #$00
st1 #$00
st2 #$10
st0 #$02
tia $4000, VDC2_2, $2000
rts
;----------------------------
initializeVdp:
;reset wait
cly
.resetWaitloop0:
clx
.resetWaitloop1:
dex
bne .resetWaitloop1
dey
bne .resetWaitloop0
;set vdp
lda VDC1_0
lda VDC2_0
vdpdataloop: lda vdpdata, y
cmp #$FF
beq vdpdataend
sta VDC1_0
sta VDC2_0
iny
lda vdpdata, y
sta VDC1_2
sta VDC2_2
iny
lda vdpdata, y
sta VDC1_3
sta VDC2_3
iny
bra vdpdataloop
vdpdataend:
;set vpc
lda #$33
sta VPC_0 ;reg0
sta VPC_1 ;reg1
stz VPC_2 ;reg2
stz VPC_3 ;reg3
stz VPC_4 ;reg4
stz VPC_5 ;reg5
stz VPC_6 ;reg6 select VDC#1
;disable interrupts TIQD IRQ2D
lda #$05
sta INT_DIS_REG
;262Line VCE Clock 5MHz
lda #$04
sta VCE_0
;set palette
stz VCE_2
stz VCE_3
tia bgpalettedata, VCE_4, $20
stz VCE_2
lda #$01
sta VCE_3
tia sppalettedata, VCE_4, $20
;clear BG
lda #$02
stz VDC1_0
stz VDC1_2
stz VDC1_3
sta VDC1_0
stz VDC2_0
stz VDC2_2
stz VDC2_3
sta VDC2_0
ldy #4
lda #$01
.clearBGLoop0:
clx
.clearBGLoop1:
stz VDC1_2
sta VDC1_3
stz VDC2_2
sta VDC2_3
dex
bne .clearBGLoop1
dey
bne .clearBGLoop0
;screen on
;VDC#1
;bg sp vsync
;+1
st0 #$05
st1 #$C8
st2 #$00
;VDC#2
;bg sp
;+1
lda #$05
sta VDC2_0
lda #$C0
sta VDC2_2
stz VDC2_3
rts
;----------------------------
moveDown:
;move down
movw <bgCenterSpXPointLast, <bgCenterSpXPoint
mov <bgCenterXLast, <bgCenterX
movw <bgCenterSpYPointLast, <bgCenterSpYPoint
mov <bgCenterYLast, <bgCenterY
lda <screenAngle
;hit check2C2
jsr hitCheck2C2
jcc .hitCheckEnd
;---------------------------
.hitCheckJumpTOP:
lda hitWorkFlag
beq .hitCheckJumpTOP_RIGHT
cmp #$08
jeq .hitCheckJumpTOP_LEFT1
.hitCheckJumpTOP1:
cmp #$01
beq .hitCheckJumpTOP_RIGHT1
lda <screenAngle
ldx #0
jsr angleCheck2C
beq .hitCheckJumpTOP0
jsr hitCheck2C2
.hitCheckJumpTOP0:
jmp .hitCheckEnd
;---------------------------
.hitCheckJumpTOP_RIGHT:
lda hitWorkFlag+1
beq .hitCheckJumpRIGHT
.hitCheckJumpTOP_RIGHT1:
lda <screenAngle
ldx #224
jsr angleCheck2C2
beq .hitCheckJumpTOP_RIGHT0
jsr hitCheck2C2
.hitCheckJumpTOP_RIGHT0:
jmp .hitCheckEnd
;---------------------------
.hitCheckJumpRIGHT:
lda hitWorkFlag+2
beq .hitCheckJumpBOTTOM_RIGHT
cmp #$08
beq .hitCheckJumpTOP_RIGHT1
cmp #$01
beq .hitCheckJumpBOTTOM_RIGHT1
lda <screenAngle
ldx #192
jsr angleCheck2C
beq .hitCheckJumpRIGHT0
jsr hitCheck2C2
.hitCheckJumpRIGHT0:
jmp .hitCheckEnd
;---------------------------
.hitCheckJumpBOTTOM_RIGHT:
lda hitWorkFlag+3
beq .hitCheckJumpBOTTOM
.hitCheckJumpBOTTOM_RIGHT1:
lda <screenAngle
ldx #160
jsr angleCheck2C2
beq .hitCheckJumpBOTTOM_RIGHT0
jsr hitCheck2C2
.hitCheckJumpBOTTOM_RIGHT0:
bra .hitCheckEnd
;---------------------------
.hitCheckJumpBOTTOM:
lda hitWorkFlag+4
beq .hitCheckJumpBOTTOM_LEFT
cmp #$08
beq .hitCheckJumpBOTTOM_LEFT1
cmp #$01
beq .hitCheckJumpBOTTOM_RIGHT1
lda <screenAngle
ldx #128
jsr angleCheck2C
beq .hitCheckJumpBOTTOM0
jsr hitCheck2C2
.hitCheckJumpBOTTOM0:
bra .hitCheckEnd
;---------------------------
.hitCheckJumpBOTTOM_LEFT:
lda hitWorkFlag+5
beq .hitCheckJumpLEFT
.hitCheckJumpBOTTOM_LEFT1:
lda <screenAngle
ldx #96
jsr angleCheck2C2
beq .hitCheckJumpBOTTOM_LEFT0
jsr hitCheck2C2
.hitCheckJumpBOTTOM_LEFT0:
bra .hitCheckEnd
;---------------------------
.hitCheckJumpLEFT:
lda hitWorkFlag+6
beq .hitCheckJumpTOP_LEFT
cmp #$08
beq .hitCheckJumpTOP_LEFT1
cmp #$01
beq .hitCheckJumpBOTTOM_LEFT1
lda <screenAngle
ldx #64
jsr angleCheck2C
beq .hitCheckJumpLEFT0
jsr hitCheck2C2
.hitCheckJumpLEFT0:
bra .hitCheckEnd
;---------------------------
.hitCheckJumpTOP_LEFT:
lda hitWorkFlag+7
beq .hitCheckEnd
.hitCheckJumpTOP_LEFT1:
lda <screenAngle
ldx #32
jsr angleCheck2C2
beq .hitCheckJumpTOP_LEFT0
jsr hitCheck2C2
.hitCheckJumpTOP_LEFT0:
;---------------------------
.hitCheckEnd:
rts
;----------------------------
angleCheck2C2:
;reg A:angle
;reg X:base angle
stx <angleCheckWork
sub <angleCheckWork
add #128
cmp #128
php
bcc .angleCheck2C2Jump0
txa
sub #224
add #64
bra .angleCheck2C2Jump1
.angleCheck2C2Jump0:
txa
sub #224
add #128
.angleCheck2C2Jump1:
plp
rts
;----------------------------
angleCheck2C:
;reg A:angle
;reg X:base angle
stx <angleCheckWork
sub <angleCheckWork
add #128
cmp #128
php
bcc .angleCheck2CJump0
txa
add #64
bra .angleCheck2CJump1
.angleCheck2CJump0:
txa
add #192
.angleCheck2CJump1:
plp
rts
;----------------------------
hitCheck2C2:
pha
movw <bgCenterSpXPoint, <bgCenterSpXPointLast
mov <bgCenterX, <bgCenterXLast
movw <bgCenterSpYPoint, <bgCenterSpYPointLast
mov <bgCenterY, <bgCenterYLast
pla
jsr calcMoveCenter2
jsr hitCheck2C
bcc .hitCheck2C2End
movw <bgCenterSpXPoint, <bgCenterSpXPointLast
mov <bgCenterX, <bgCenterXLast
movw <bgCenterSpYPoint, <bgCenterSpYPointLast
mov <bgCenterY, <bgCenterYLast
sec
.hitCheck2C2End:
lda #1
rts
;----------------------------
hitCheck2C:
;hit check
;multi hit check 28point
rmb7 <hitFlag
clx
.hitCheck2BLoop:
movw <bgCalcCenterSpX, <bgCenterSpX
movw <bgCalcCenterSpY, <bgCenterSpY
lda hitdatax2, x
ldy hitdatay2, x
phx
tax
jsr calcCenterSp
plx
lda <bgCalcCenterSpX
sta hitWorkSpX, x
lda <bgCalcCenterSpY
sta hitWorkSpY, x
jsr getBgData
sta hitWorkNo, x
beq .hitCheck2BJump0
smb7 <hitFlag
.hitCheck2BJump0:
inx
cpx #28
bne .hitCheck2BLoop
;0~3 TOP
ldx #0
ldy #4
jsr hitCheck2CSub
sta hitWorkFlag
;4~6 TOP RIGHT
ldx #4
ldy #3
jsr hitCheck2CSub
sta hitWorkFlag+1
;7~10 RIGHT
ldx #7
ldy #4
jsr hitCheck2CSub
sta hitWorkFlag+2
;11~13 BOTTOM RIGHT
ldx #11
ldy #3
jsr hitCheck2CSub
sta hitWorkFlag+3
;14~17 BOTTOM
ldx #14
ldy #4
jsr hitCheck2CSub
sta hitWorkFlag+4
;18~20 BOTTOM LEFT
ldx #18
ldy #3
jsr hitCheck2CSub
sta hitWorkFlag+5
;21~24 LEFT
ldx #21
ldy #4
jsr hitCheck2CSub
sta hitWorkFlag+6
;25~27 TOP LEFT
ldx #25
ldy #3
jsr hitCheck2CSub
sta hitWorkFlag+7
lda <hitFlag
rol a
rts
;----------------------------
hitCheck2CSub:
cla
.hitCheck2CSubLoop:
tst #$FF, hitWorkNo, x
beq .hitCheck2CSubJump0
sec
rol a
bra .hitCheck2CSubJump1
.hitCheck2CSubJump0:
clc
rol a
.hitCheck2CSubJump1:
inx
dey
bne .hitCheck2CSubLoop
rts
;----------------------------
getBgData:
;in bgCalcCenterX
; bgCalcCenterY
; bgBank
;use bgDataWorkAddr
; $6000 Bank
;out 0:set zero, not 0:clear zero
lda <bgCalcCenterY
lsr a
lsr a
lsr a
lsr a
lsr a
add <bgBank
tam #$03 ;Set $6000
lda <bgCalcCenterY
and #$1F
ora #$60
sta <bgDataWorkAddr+1
lda <bgCalcCenterX
sta <bgDataWorkAddr
lda [bgDataWorkAddr]
rts
;----------------------------
calcMoveCenter2:
;in regA angle
; bgCenterX:bgCenterSpX:bgCenterSpXPoint
; bgCenterY:bgCenterSpY:bgCenterSpYPoint
; bgCenterMovement
;out bgCenterX:bgCenterSpX:bgCenterSpXPoint
; bgCenterY:bgCenterSpY:bgCenterSpYPoint
tax
movw <mul16a, <bgCenterMovement
lda sindatalow, x
sta <mul16b
lda sindatahigh, x
sta <mul16b+1
jsr smul16
subw <bgCenterSpXPoint, <mul16c+1
bpl .calcMoveCenter2Jump0
lda #11
sta <bgCenterSpX
dec <bgCenterX
bra .calcMoveCenter2Jump1
.calcMoveCenter2Jump0:
cmp #12
bne .calcMoveCenter2Jump1
stz <bgCenterSpX
inc <bgCenterX
.calcMoveCenter2Jump1:
movw <mul16a, <bgCenterMovement
lda cosdatalow, x
sta <mul16b
lda cosdatahigh, x
sta <mul16b+1
jsr smul16
subw <bgCenterSpYPoint, <mul16c+1
bpl .calcMoveCenter2Jump2
lda #11
sta <bgCenterSpY
dec <bgCenterY
bra .calcMoveCenter2Jump3
.calcMoveCenter2Jump2:
cmp #12
bne .calcMoveCenter2Jump3
stz <bgCenterSpY
inc <bgCenterY
.calcMoveCenter2Jump3:
rts
;----------------------------
calcCenterSp:
;in regX(-11 ~ 11)
; regY(-11 ~ 11)
; bgCalcCenterX:bgCalcCenterSpX
; bgCalcCenterY:bgCalcCenterSpY
;out bgCalcCenterX:bgCalcCenterSpX + regX(-11 ~ 11)
; bgCalcCenterY:bgCalcCenterSpY + regY(-11 ~ 11)
txa
add <bgCalcCenterSpX
sta <bgCalcCenterSpX
bpl .calcCenterSpJump0
add #12
sta <bgCalcCenterSpX
dec <bgCalcCenterX
bra .calcCenterSpJump1
.calcCenterSpJump0:
sub #12
bmi .calcCenterSpJump1
sta <bgCalcCenterSpX
inc <bgCalcCenterX
.calcCenterSpJump1:
tya
add <bgCalcCenterSpY
sta <bgCalcCenterSpY
bpl .calcCenterSpJump2
add #12
sta <bgCalcCenterSpY
dec <bgCalcCenterY
bra .calcCenterSpJump3
.calcCenterSpJump2:
sub #12
bmi .calcCenterSpJump3
sta <bgCalcCenterSpY
inc <bgCalcCenterY
.calcCenterSpJump3:
rts
;----------------------------
rotationProc:
;rotationAngle
;rotationX -> rotationAnsX
;rotationY -> rotationAnsY
;X=xcosA-ysinA process
;xcosA
movw <mul16a, <rotationX
ldx <rotationAngle
lda cosdatalow,x
sta <mul16b
lda cosdatahigh,x
sta <mul16b+1
jsr smul16
movq <rotationAnsX, <mul16c
;ysinA
movw <mul16a, <rotationY
ldx <rotationAngle
lda sindatalow,x
sta <mul16b
lda sindatahigh,x
sta <mul16b+1
jsr smul16
;xcosA-ysinA
subq <rotationAnsX, <mul16c
;Y=xsinA+ycosA process
;xsinA
movw <mul16a, <rotationX
ldx <rotationAngle
lda sindatalow,x
sta <mul16b
lda sindatahigh,x
sta <mul16b+1
jsr smul16
movq <rotationAnsY, <mul16c
;ycosA
movw <mul16a, <rotationY
ldx <rotationAngle
lda cosdatalow,x
sta <mul16b
lda cosdatahigh,x
sta <mul16b+1
jsr smul16
;xsinA+ycosA
addq <rotationAnsY, <mul16c
rts
;----------------------------
smul16:
;mul16d:mul16c = mul16a * mul16b
;a eor b sign
lda <mul16a+1
eor <mul16b+1
pha
;a sign
bbr7 <mul16a+1, .smul16jp00
;a neg
sec
lda <mul16a
eor #$FF
adc #0
sta <mul16a
lda <mul16a+1
eor #$FF
adc #0
sta <mul16a+1
.smul16jp00:
;b sign
bbr7 <mul16b+1, .smul16jp01
;b neg
sec
lda <mul16b
eor #$FF
adc #0
sta <mul16b
lda <mul16b+1
eor #$FF
adc #0
sta <mul16b+1
.smul16jp01:
jsr umul16
;anser sign
pla
and #$80
beq .smul16jp02
;anser neg
sec
lda <mul16c
eor #$FF
adc #0
sta <mul16c
lda <mul16c+1
eor #$FF
adc #0
sta <mul16c+1
lda <mul16d
eor #$FF
adc #0
sta <mul16d
lda <mul16d+1
eor #$FF
adc #0
sta <mul16d+1
.smul16jp02:
rts
;----------------------------
umul16:
;mul16d:mul16c = mul16a * mul16b
lda <mul16a+1
ora <mul16b+1
bne .umul16jp02
jsr umul8
;clear d
stz <mul16d
stz <mul16d+1
rts
.umul16jp02:
;push x y
phx
phy
;b to d
lda <mul16b
sta <mul16d
lda <mul16b+1
sta <mul16d+1
;set counter
ldy #16
.umul16jp04:
;clear c
stz <mul16c
stz <mul16c+1
;umul16 loop
.umul16jp00:
;left shift c and d
asl <mul16c
rol <mul16c+1
rol <mul16d
rol <mul16d+1
bcc .umul16jp01
;add a to c
ldx #LOW(mul16c)
clc
set
adc <mul16a
inx
set
adc <mul16a+1
bcc .umul16jp01
;inc d
inc <mul16d
bne .umul16jp01
inc <mul16d+1
.umul16jp01:
dey
bne .umul16jp00
;pull y x
ply
plx
rts
;----------------------------
umul8:
;mul16c = mul16a * mul16b (8bit * 8bit)
;push x y
phx
phy
;b to c
lda <mul16b
sta <mul16c+1
;clear a
cla
;set counter
ldy #8
;umul8 loop
.umul8jp00:
;left shift a
asl a
rol <mul16c+1
bcc .umul8jp01
;add a to c
clc
adc <mul16a
bcc .umul8jp01
;inc c
inc <mul16c+1
.umul8jp01:
dey
bne .umul8jp00
sta <mul16c
;pull y x
ply
plx
rts
;----------------------------
numtochar:
;in A Register $0 to $F
;out A Register '0'-'9'($30-$39) 'A'-'Z'($41-$5A)
cmp #10
bcs .numtochar000
ora #$30
rts
.numtochar000:
adc #$41-10-1
rts
;----------------------------
puthex:
pha
phx
phy
sta <puthexdata
stz <puthexaddr
sty <puthexaddr+1
lsr <puthexaddr+1
ror <puthexaddr
lsr <puthexaddr+1
ror <puthexaddr
lsr <puthexaddr+1
ror <puthexaddr
txa
ora <puthexaddr
sta <puthexaddr
lda <puthexdata
lsr a
lsr a
lsr a
lsr a
jsr numtochar
tax
lda <puthexdata
and #$0F
jsr numtochar
stz VDC1_0
ldy <puthexaddr
sty VDC1_2
ldy <puthexaddr+1
sty VDC1_3
ldy #$02
sty VDC1_0
stx VDC1_2
ldy #$01
sty VDC1_3
sta VDC1_2
sty VDC1_3
ply
plx
pla
rts
;----------------------------
getpaddata:
lda <padnow
sta <padlast
lda #$01
sta IO_PAD
lda #$03
sta IO_PAD
lda #$01
sta IO_PAD
lda IO_PAD
asl a
asl a
asl a
asl a
sta <padnow
lda #$00
sta IO_PAD
lda IO_PAD
and #$0F
ora <padnow
eor #$FF
sta <padnow
lda <padlast
eor #$FF
and <padnow
sta <padstate
;get pad data end
rts
;----------------------------
_reset:
;reset process
;disable interrupts
sei
;select the 7.16 MHz clock
csh
;clear the decimal flag
cld
;initialize the stack pointer
ldx #$FF
txs
;I/O page0
lda #$FF
tam #$00
;RAM page1
lda #$F8
tam #$01
;Clear RAM
stz $2000
tii $2000, $2001, 32767
;jump main
jmp main
;----------------------------
_irq1:
;IRQ1 interrupt process
;ACK interrupt
lda VDC1_0
sta <vdpstatus
lda VDC2_0
jsr getpaddata
bbr7 <vsyncFlag, .irq1End
;VDC#1 section
stz VPC_6 ;reg6 select VDC#1
st0 #$07 ;scrollx
st1 #$00
st2 #$00
st0 #$08 ;scrolly
st1 #$00
st2 #$00
;clear SATB
st0 #$00 ;set SATB addr
st1 #$00
st2 #$04
st0 #$02 ;VRAM clear
st1 #$00
st2 #$00
st0 #$10 ;set DMA src
st1 #$00
st2 #$04
st0 #$11 ;set DMA dist
st1 #$01
st2 #$04
st0 #$12 ;set DMA count 255WORD
st1 #$FF
st2 #$00
;VDC#2 section
lda #$01
sta VPC_6 ;reg6 select VDC#2
lda <scrollWork
st0 #$07 ;scrollx
sta VDC2_2
st2 #$00
st0 #$08 ;scrolly
sta VDC2_2
st2 #$00
;clear SATB
st0 #$00 ;set SATB addr
st1 #$00
st2 #$04
st0 #$02 ;VRAM clear
st1 #$00
st2 #$00
st0 #$10 ;set DMA src
st1 #$00
st2 #$04
st0 #$11 ;set DMA dist
st1 #$01
st2 #$04
st0 #$12 ;set DMA count 255WORD
st1 #$FF
st2 #$00
inc <scrollWork
rmb7 <vsyncFlag
.irq1End:
rti
;----------------------------
_irq2:
_timer:
_nmi:
;IRQ2 TIMER NMI interrupt process
rti
;----------------------------
bg0data:
.db $01, $01, $01, $01, $01, $01, $01, $01, $01, $01, $00, $00, $00, $00, $00, $00,\
$00, $00, $00, $00, $00, $00, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01
;----------------------------
bg1data:
.db $04, $05, $06, $07, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02,\ ;line 0
$02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02
.db $08, $09, $0A, $0B, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02,\ ;line 1
$02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02
.db $0C, $0D, $0E, $0F, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02,\ ;line 2
$02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02
.db $10, $11, $12, $13, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02,\ ;line 3
$02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02
.db $02, $02, $02, $02, $02, $02, $04, $05, $06, $07, $02, $02, $02, $02, $02, $02,\ ;line 0
$02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02
.db $02, $02, $02, $02, $02, $02, $08, $09, $0A, $0B, $02, $02, $02, $02, $02, $02,\ ;line 1
$02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02
.db $02, $02, $02, $02, $02, $02, $0C, $0D, $0E, $0F, $02, $02, $02, $02, $02, $02,\ ;line 2
$02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02
.db $02, $02, $02, $02, $02, $02, $10, $11, $12, $13, $02, $02, $02, $02, $02, $02,\ ;line 3
$02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02
.db $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02,\ ;line 0
$04, $05, $06, $07, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02
.db $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02,\ ;line 1
$08, $09, $0A, $0B, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02
.db $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02,\ ;line 2
$0C, $0D, $0E, $0F, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02
.db $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02,\ ;line 3
$10, $11, $12, $13, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02
.db $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02,\ ;line 0
$02, $02, $02, $02, $02, $02, $04, $05, $06, $07, $02, $02, $02, $02, $02, $02
.db $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02,\ ;line 1
$02, $02, $02, $02, $02, $02, $08, $09, $0A, $0B, $02, $02, $02, $02, $02, $02
.db $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02,\ ;line 2
$02, $02, $02, $02, $02, $02, $0C, $0D, $0E, $0F, $02, $02, $02, $02, $02, $02
.db $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02,\ ;line 3
$02, $02, $02, $02, $02, $02, $10, $11, $12, $13, $02, $02, $02, $02, $02, $02
.db $14, $15, $16, $17, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02,\ ;line 0
$02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02
.db $18, $19, $1A, $1B, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02,\ ;line 1
$02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02
.db $1C, $1D, $1E, $1F, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02,\ ;line 2
$02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02
.db $3C, $3D, $3E, $3F, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02,\ ;line 3
$02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02
.db $02, $02, $02, $02, $02, $02, $14, $15, $16, $17, $02, $02, $02, $02, $02, $02,\ ;line 0
$02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02
.db $02, $02, $02, $02, $02, $02, $18, $19, $1A, $1B, $02, $02, $02, $02, $02, $02,\ ;line 1
$02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02
.db $02, $02, $02, $02, $02, $02, $1C, $1D, $1E, $1F, $02, $02, $02, $02, $02, $02,\ ;line 2
$02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02
.db $02, $02, $02, $02, $02, $02, $3C, $3D, $3E, $3F, $02, $02, $02, $02, $02, $02,\ ;line 3
$02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02
.db $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02,\ ;line 0
$14, $15, $16, $17, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02
.db $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02,\ ;line 1
$18, $19, $1A, $1B, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02
.db $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02,\ ;line 2
$1C, $1D, $1E, $1F, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02
.db $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02,\ ;line 3
$3C, $3D, $3E, $3F, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02
.db $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02,\ ;line 0
$02, $02, $02, $02, $02, $02, $14, $15, $16, $17, $02, $02, $02, $02, $02, $02
.db $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02,\ ;line 1
$02, $02, $02, $02, $02, $02, $18, $19, $1A, $1B, $02, $02, $02, $02, $02, $02
.db $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02,\ ;line 2
$02, $02, $02, $02, $02, $02, $1C, $1D, $1E, $1F, $02, $02, $02, $02, $02, $02
.db $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02,\ ;line 3
$02, $02, $02, $02, $02, $02, $3C, $3D, $3E, $3F, $02, $02, $02, $02, $02, $02
;----------------------------
vdpdata:
.db $05, $00, $00 ;screen off +1
.db $0A, $02, $02 ;HSW $02 HDS $02
.db $0B, $1F, $04 ;HDW $1F HDE $04
.db $0C, $02, $0D ;VSW $02 VDS $0D
.db $0D, $EF, $00 ;VDW $00EF
.db $0E, $03, $00 ;VCR $03
.db $07, $00, $00 ;scrollx 0
.db $08, $00, $00 ;scrolly 0
.db $09, $00, $00 ;32x32
.db $FF ;end
;----------------------------
bgpalettedata:
.dw $0000, $0020, $0100, $0120, $0004, $0024, $0104, $0124,\
$01B6, $0038, $01C0, $01F8, $0007, $003F, $01C7, $01FF
;----------------------------
sppalettedata:
.dw $0000, $0020, $0100, $0120, $0004, $0024, $0104, $0124,\
$01B6, $0038, $01C0, $01F8, $0007, $003F, $01C7, $01FF
;----------------------------
spballdata:
.dw $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000,\
$0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000
.dw $0000, $0000, $03C0, $0FF0, $1FF8, $1FF8, $3FFC, $3FFC,\
$3FFC, $3FFC, $1FF8, $1FF8, $0FF0, $03C0, $0000, $0000
.dw $0000, $0000, $03C0, $0FF0, $1E78, $1E78, $3FFC, $3FFC,\
$3FFC, $3FFC, $1FF8, $1FF8, $0FF0, $03C0, $0000, $0000
.dw $0000, $0000, $0000, $07E0, $0E70, $0E70, $1FF8, $1FF8,\
$1998, $1998, $0FF0, $0FF0, $07E0, $0000, $0000, $0000
;----------------------------
hitdatax2:
.db $FE, $FF, $00, $01 ;0~3 TOP
.db $02, $03, $04 ;4~6 TOP RIGHT
.db $05, $05, $05, $05 ;7~10 RIGHT
.db $04, $03, $02 ;11~13 BOTTOM RIGHT
.db $FE, $FF, $00, $01 ;14~17 BOTTOM
.db $FB, $FC, $FD ;18~20 BOTTOM LEFT
.db $FA, $FA, $FA, $FA ;21~24 LEFT
.db $FD, $FC, $FB ;25~27 TOP LEFT
;----------------------------
hitdatay2:
.db $FA, $FA, $FA, $FA ;0~3 TOP
.db $FB, $FC, $FD ;4~6 TOP RIGHT
.db $FE, $FF, $00, $01 ;7~10 RIGHT
.db $02, $03, $04 ;11~13 BOTTOM RIGHT
.db $05, $05, $05, $05 ;14~17 BOTTOM
.db $02, $03, $04 ;18~20 BOTTOM LEFT
.db $FE, $FF, $00, $01 ;21~24 LEFT
.db $FB, $FC, $FD ;25~27 TOP LEFT
;----------------------------
sindatalow:
.db $00, $06, $0D, $13, $19, $1F, $26, $2C, $32, $38, $3E, $44, $4A, $50, $56, $5C,\
$62, $68, $6D, $73, $79, $7E, $84, $89, $8E, $93, $98, $9D, $A2, $A7, $AC, $B1,\
$B5, $B9, $BE, $C2, $C6, $CA, $CE, $D1, $D5, $D8, $DC, $DF, $E2, $E5, $E7, $EA,\
$ED, $EF, $F1, $F3, $F5, $F7, $F8, $FA, $FB, $FC, $FD, $FE, $FF, $FF, $00, $00,\
$00, $00, $00, $FF, $FF, $FE, $FD, $FC, $FB, $FA, $F8, $F7, $F5, $F3, $F1, $EF,\
$ED, $EA, $E7, $E5, $E2, $DF, $DC, $D8, $D5, $D1, $CE, $CA, $C6, $C2, $BE, $B9,\
$B5, $B1, $AC, $A7, $A2, $9D, $98, $93, $8E, $89, $84, $7E, $79, $73, $6D, $68,\
$62, $5C, $56, $50, $4A, $44, $3E, $38, $32, $2C, $26, $1F, $19, $13, $0D, $06,\
$00, $FA, $F3, $ED, $E7, $E1, $DA, $D4, $CE, $C8, $C2, $BC, $B6, $B0, $AA, $A4,\
$9E, $98, $93, $8D, $87, $82, $7C, $77, $72, $6D, $68, $63, $5E, $59, $54, $4F,\
$4B, $47, $42, $3E, $3A, $36, $32, $2F, $2B, $28, $24, $21, $1E, $1B, $19, $16,\
$13, $11, $0F, $0D, $0B, $09, $08, $06, $05, $04, $03, $02, $01, $01, $00, $00,\
$00, $00, $00, $01, $01, $02, $03, $04, $05, $06, $08, $09, $0B, $0D, $0F, $11,\
$13, $16, $19, $1B, $1E, $21, $24, $28, $2B, $2F, $32, $36, $3A, $3E, $42, $47,\
$4B, $4F, $54, $59, $5E, $63, $68, $6D, $72, $77, $7C, $82, $87, $8D, $93, $98,\
$9E, $A4, $AA, $B0, $B6, $BC, $C2, $C8, $CE, $D4, $DA, $E1, $E7, $ED, $F3, $FA
;----------------------------
sindatahigh:
.db $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00,\
$00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00,\
$00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00,\
$00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $01, $01,\
$01, $01, $01, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00,\
$00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00,\
$00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00,\
$00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00,\
$00, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF,\
$FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF,\
$FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF,\
$FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF,\
$FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF,\
$FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF,\
$FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF,\
$FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF
;----------------------------
cosdatalow:
.db $00, $00, $00, $FF, $FF, $FE, $FD, $FC, $FB, $FA, $F8, $F7, $F5, $F3, $F1, $EF,\
$ED, $EA, $E7, $E5, $E2, $DF, $DC, $D8, $D5, $D1, $CE, $CA, $C6, $C2, $BE, $B9,\
$B5, $B1, $AC, $A7, $A2, $9D, $98, $93, $8E, $89, $84, $7E, $79, $73, $6D, $68,\
$62, $5C, $56, $50, $4A, $44, $3E, $38, $32, $2C, $26, $1F, $19, $13, $0D, $06,\
$00, $FA, $F3, $ED, $E7, $E1, $DA, $D4, $CE, $C8, $C2, $BC, $B6, $B0, $AA, $A4,\
$9E, $98, $93, $8D, $87, $82, $7C, $77, $72, $6D, $68, $63, $5E, $59, $54, $4F,\
$4B, $47, $42, $3E, $3A, $36, $32, $2F, $2B, $28, $24, $21, $1E, $1B, $19, $16,\
$13, $11, $0F, $0D, $0B, $09, $08, $06, $05, $04, $03, $02, $01, $01, $00, $00,\
$00, $00, $00, $01, $01, $02, $03, $04, $05, $06, $08, $09, $0B, $0D, $0F, $11,\
$13, $16, $19, $1B, $1E, $21, $24, $28, $2B, $2F, $32, $36, $3A, $3E, $42, $47,\
$4B, $4F, $54, $59, $5E, $63, $68, $6D, $72, $77, $7C, $82, $87, $8D, $93, $98,\
$9E, $A4, $AA, $B0, $B6, $BC, $C2, $C8, $CE, $D4, $DA, $E1, $E7, $ED, $F3, $FA,\
$00, $06, $0D, $13, $19, $1F, $26, $2C, $32, $38, $3E, $44, $4A, $50, $56, $5C,\
$62, $68, $6D, $73, $79, $7E, $84, $89, $8E, $93, $98, $9D, $A2, $A7, $AC, $B1,\
$B5, $B9, $BE, $C2, $C6, $CA, $CE, $D1, $D5, $D8, $DC, $DF, $E2, $E5, $E7, $EA,\
$ED, $EF, $F1, $F3, $F5, $F7, $F8, $FA, $FB, $FC, $FD, $FE, $FF, $FF, $00, $00
;----------------------------
cosdatahigh:
.db $01, $01, $01, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00,\
$00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00,\
$00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00,\
$00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00,\
$00, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF,\
$FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF,\
$FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF,\
$FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF,\
$FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF,\
$FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF,\
$FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF,\
$FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF,\
$00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00,\
$00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00,\
$00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00,\
$00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $01, $01
;----------------------------
;interrupt vectors
.org $FFF6
.dw _irq2
.dw _irq1
.dw _timer
.dw _nmi
.dw _reset
;////////////////////////////
.bank 1
INCBIN "char.dat" ; 8K 1 $01
INCBIN "spxy.dat" ;256K 2~33 $02~$21 SPXY and BGXY ([spx:1byte, spy:1byte, bgx:1byte, bgy:1byte] * 128data * 256angle * 2left and right)
INCBIN "spbank.dat" ; 8K 34 $22 SP number bank and address ([bank:2byte, address:2byte] * 8pattern * 256angle)
INCBIN "spno.dat" ; 8K 35 $23 BG number convert to SP number and attribute ([SP number:1byte, attribute:1byte] * 16pattern * 256angle)
INCBIN "sp00_00_3F.dat" ; 8K 36 $24 normal block 0-63 angle
INCBIN "sp01_00_3F.dat" ; 8K 37 $25 cross block 0-63 angle
INCBIN "sp02_00_3F.dat" ; 8K 38 $26 up arrow block 0-63 angle
INCBIN "sp03_00_3F.dat" ; 8K 39 $27 right arrow block 0-63 angle
INCBIN "sp03_00_3F.dat" ; 8K 40 $28 padding
INCBIN "stage0.dat" ; 64K 41~48 $29~$30 stage0 data
|
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Copyright (c) Berkeley Softworks 1990 -- All Rights Reserved
PROJECT: PC GEOS
MODULE: Print Drivers
FILE: textSendFont10121517Prop.asm
AUTHOR: Dave Durran
ROUTINES:
Name Description
---- -----------
REVISION HISTORY:
Name Date Description
---- ---- -----------
Dave 3/21/92 Initial revision from epson24Styles.asm
Dave 8/92 Obsolesced by the print style run routines
OBSOLETE: DO NOT USE!
DC_ESCRIPTION:
$Id: textSendFont10121517Prop.asm,v 1.1 97/04/18 11:49:58 newdeal Exp $
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
PrintSendFont
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Send the right stuff to set the font in the printer
CALLED BY: INTERNAL
PrintSetFont
PASS: es - PState segment
RETURN: carry - set if some communications error
DESTROYED: nothing
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
none
REVISION HISTORY:
Name Date Description
---- ---- -----------
Jim 01/90 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
PrintSendFont proc near
uses si
.enter
mov si, offset cs:pr_codes_SetProportional
cmp es:[PS_curFont].FE_fontID, FID_PRINTER_PROP_SERIF
je sendTheFont
mov si, offset cs:pr_codes_Set12Pitch ; check the next one
cmp es:[PS_curFont].FE_fontID, FID_PRINTER_12CPI ; chk ass
je sendTheFont
mov si, offset cs:pr_codes_Set15Pitch ; check the next one
cmp es:[PS_curFont].FE_fontID, FID_PRINTER_15CPI ; chk ass
je sendTheFont
mov si, offset cs:pr_codes_Set10Pitch ; assume it's 10CPI
cmp es:[PS_curFont].FE_fontID, FID_PRINTER_10CPI ; chk ass
je sendTheFont
; it must be one of the condensed ones, so set condensed mode
; first set the appropriate font
mov si, offset cs:pr_codes_Set10Pitch ; assume it's 17CPI
cmp es:[PS_curFont].FE_fontID, FID_PRINTER_17CPI ; chk ass
je setCondensedFont
mov si, offset cs:pr_codes_Set12Pitch ; assume it's 20CPI
setCondensedFont:
call SendCodeOut ; set it at printer
jc exit
or es:[PS_xtraStyleInfo], mask PMF_FORCE_CONDENSED
or es:[PS_asciiStyle], mask PTS_CONDENSED ; set condensed
call SetCondensed
jmp exit
sendTheFont:
call SendCodeOut ; set it at printer
exit:
.leave
ret
PrintSendFont endp
|
;
; jdcolext.asm - colorspace conversion (SSE2)
;
; Copyright 2009, 2012 Pierre Ossman <ossman@cendio.se> for Cendio AB
; Copyright (C) 2012, D. R. Commander.
;
; Based on the x86 SIMD extension for IJG JPEG library
; Copyright (C) 1999-2006, MIYASAKA Masaru.
; For conditions of distribution and use, see copyright notice in jsimdext.inc
;
; This file should be assembled with NASM (Netwide Assembler),
; can *not* be assembled with Microsoft's MASM or any compatible
; assembler (including Borland's Turbo Assembler).
; NASM is available from http://nasm.sourceforge.net/ or
; http://sourceforge.net/project/showfiles.php?group_id=6208
;
; [TAB8]
%include "jcolsamp.inc"
; --------------------------------------------------------------------------
;
; Convert some rows of samples to the output colorspace.
;
; GLOBAL(void)
; jsimd_ycc_rgb_convert_sse2 (JDIMENSION out_width,
; JSAMPIMAGE input_buf, JDIMENSION input_row,
; JSAMPARRAY output_buf, int num_rows)
;
%define out_width(b) (b)+8 ; JDIMENSION out_width
%define input_buf(b) (b)+12 ; JSAMPIMAGE input_buf
%define input_row(b) (b)+16 ; JDIMENSION input_row
%define output_buf(b) (b)+20 ; JSAMPARRAY output_buf
%define num_rows(b) (b)+24 ; int num_rows
%define original_ebp ebp+0
%define wk(i) ebp-(WK_NUM-(i))*SIZEOF_XMMWORD ; xmmword wk[WK_NUM]
%define WK_NUM 2
%define gotptr wk(0)-SIZEOF_POINTER ; void * gotptr
align 16
global EXTN(jsimd_ycc_rgb_convert_sse2) PRIVATE
EXTN(jsimd_ycc_rgb_convert_sse2):
push ebp
mov eax,esp ; eax = original ebp
sub esp, byte 4
and esp, byte (-SIZEOF_XMMWORD) ; align to 128 bits
mov [esp],eax
mov ebp,esp ; ebp = aligned ebp
lea esp, [wk(0)]
pushpic eax ; make a room for GOT address
push ebx
; push ecx ; need not be preserved
; push edx ; need not be preserved
push esi
push edi
get_GOT ebx ; get GOT address
movpic POINTER [gotptr], ebx ; save GOT address
mov ecx, JDIMENSION [out_width(eax)] ; num_cols
test ecx,ecx
jz near .return
push ecx
mov edi, JSAMPIMAGE [input_buf(eax)]
mov ecx, JDIMENSION [input_row(eax)]
mov esi, JSAMPARRAY [edi+0*SIZEOF_JSAMPARRAY]
mov ebx, JSAMPARRAY [edi+1*SIZEOF_JSAMPARRAY]
mov edx, JSAMPARRAY [edi+2*SIZEOF_JSAMPARRAY]
lea esi, [esi+ecx*SIZEOF_JSAMPROW]
lea ebx, [ebx+ecx*SIZEOF_JSAMPROW]
lea edx, [edx+ecx*SIZEOF_JSAMPROW]
pop ecx
mov edi, JSAMPARRAY [output_buf(eax)]
mov eax, INT [num_rows(eax)]
test eax,eax
jle near .return
alignx 16,7
.rowloop:
push eax
push edi
push edx
push ebx
push esi
push ecx ; col
mov esi, JSAMPROW [esi] ; inptr0
mov ebx, JSAMPROW [ebx] ; inptr1
mov edx, JSAMPROW [edx] ; inptr2
mov edi, JSAMPROW [edi] ; outptr
movpic eax, POINTER [gotptr] ; load GOT address (eax)
alignx 16,7
.columnloop:
movdqa xmm5, XMMWORD [ebx] ; xmm5=Cb(0123456789ABCDEF)
movdqa xmm1, XMMWORD [edx] ; xmm1=Cr(0123456789ABCDEF)
pcmpeqw xmm4,xmm4
pcmpeqw xmm7,xmm7
psrlw xmm4,BYTE_BIT
psllw xmm7,7 ; xmm7={0xFF80 0xFF80 0xFF80 0xFF80 ..}
movdqa xmm0,xmm4 ; xmm0=xmm4={0xFF 0x00 0xFF 0x00 ..}
pand xmm4,xmm5 ; xmm4=Cb(02468ACE)=CbE
psrlw xmm5,BYTE_BIT ; xmm5=Cb(13579BDF)=CbO
pand xmm0,xmm1 ; xmm0=Cr(02468ACE)=CrE
psrlw xmm1,BYTE_BIT ; xmm1=Cr(13579BDF)=CrO
paddw xmm4,xmm7
paddw xmm5,xmm7
paddw xmm0,xmm7
paddw xmm1,xmm7
; (Original)
; R = Y + 1.40200 * Cr
; G = Y - 0.34414 * Cb - 0.71414 * Cr
; B = Y + 1.77200 * Cb
;
; (This implementation)
; R = Y + 0.40200 * Cr + Cr
; G = Y - 0.34414 * Cb + 0.28586 * Cr - Cr
; B = Y - 0.22800 * Cb + Cb + Cb
movdqa xmm2,xmm4 ; xmm2=CbE
movdqa xmm3,xmm5 ; xmm3=CbO
paddw xmm4,xmm4 ; xmm4=2*CbE
paddw xmm5,xmm5 ; xmm5=2*CbO
movdqa xmm6,xmm0 ; xmm6=CrE
movdqa xmm7,xmm1 ; xmm7=CrO
paddw xmm0,xmm0 ; xmm0=2*CrE
paddw xmm1,xmm1 ; xmm1=2*CrO
pmulhw xmm4,[GOTOFF(eax,PW_MF0228)] ; xmm4=(2*CbE * -FIX(0.22800))
pmulhw xmm5,[GOTOFF(eax,PW_MF0228)] ; xmm5=(2*CbO * -FIX(0.22800))
pmulhw xmm0,[GOTOFF(eax,PW_F0402)] ; xmm0=(2*CrE * FIX(0.40200))
pmulhw xmm1,[GOTOFF(eax,PW_F0402)] ; xmm1=(2*CrO * FIX(0.40200))
paddw xmm4,[GOTOFF(eax,PW_ONE)]
paddw xmm5,[GOTOFF(eax,PW_ONE)]
psraw xmm4,1 ; xmm4=(CbE * -FIX(0.22800))
psraw xmm5,1 ; xmm5=(CbO * -FIX(0.22800))
paddw xmm0,[GOTOFF(eax,PW_ONE)]
paddw xmm1,[GOTOFF(eax,PW_ONE)]
psraw xmm0,1 ; xmm0=(CrE * FIX(0.40200))
psraw xmm1,1 ; xmm1=(CrO * FIX(0.40200))
paddw xmm4,xmm2
paddw xmm5,xmm3
paddw xmm4,xmm2 ; xmm4=(CbE * FIX(1.77200))=(B-Y)E
paddw xmm5,xmm3 ; xmm5=(CbO * FIX(1.77200))=(B-Y)O
paddw xmm0,xmm6 ; xmm0=(CrE * FIX(1.40200))=(R-Y)E
paddw xmm1,xmm7 ; xmm1=(CrO * FIX(1.40200))=(R-Y)O
movdqa XMMWORD [wk(0)], xmm4 ; wk(0)=(B-Y)E
movdqa XMMWORD [wk(1)], xmm5 ; wk(1)=(B-Y)O
movdqa xmm4,xmm2
movdqa xmm5,xmm3
punpcklwd xmm2,xmm6
punpckhwd xmm4,xmm6
pmaddwd xmm2,[GOTOFF(eax,PW_MF0344_F0285)]
pmaddwd xmm4,[GOTOFF(eax,PW_MF0344_F0285)]
punpcklwd xmm3,xmm7
punpckhwd xmm5,xmm7
pmaddwd xmm3,[GOTOFF(eax,PW_MF0344_F0285)]
pmaddwd xmm5,[GOTOFF(eax,PW_MF0344_F0285)]
paddd xmm2,[GOTOFF(eax,PD_ONEHALF)]
paddd xmm4,[GOTOFF(eax,PD_ONEHALF)]
psrad xmm2,SCALEBITS
psrad xmm4,SCALEBITS
paddd xmm3,[GOTOFF(eax,PD_ONEHALF)]
paddd xmm5,[GOTOFF(eax,PD_ONEHALF)]
psrad xmm3,SCALEBITS
psrad xmm5,SCALEBITS
packssdw xmm2,xmm4 ; xmm2=CbE*-FIX(0.344)+CrE*FIX(0.285)
packssdw xmm3,xmm5 ; xmm3=CbO*-FIX(0.344)+CrO*FIX(0.285)
psubw xmm2,xmm6 ; xmm2=CbE*-FIX(0.344)+CrE*-FIX(0.714)=(G-Y)E
psubw xmm3,xmm7 ; xmm3=CbO*-FIX(0.344)+CrO*-FIX(0.714)=(G-Y)O
movdqa xmm5, XMMWORD [esi] ; xmm5=Y(0123456789ABCDEF)
pcmpeqw xmm4,xmm4
psrlw xmm4,BYTE_BIT ; xmm4={0xFF 0x00 0xFF 0x00 ..}
pand xmm4,xmm5 ; xmm4=Y(02468ACE)=YE
psrlw xmm5,BYTE_BIT ; xmm5=Y(13579BDF)=YO
paddw xmm0,xmm4 ; xmm0=((R-Y)E+YE)=RE=R(02468ACE)
paddw xmm1,xmm5 ; xmm1=((R-Y)O+YO)=RO=R(13579BDF)
packuswb xmm0,xmm0 ; xmm0=R(02468ACE********)
packuswb xmm1,xmm1 ; xmm1=R(13579BDF********)
paddw xmm2,xmm4 ; xmm2=((G-Y)E+YE)=GE=G(02468ACE)
paddw xmm3,xmm5 ; xmm3=((G-Y)O+YO)=GO=G(13579BDF)
packuswb xmm2,xmm2 ; xmm2=G(02468ACE********)
packuswb xmm3,xmm3 ; xmm3=G(13579BDF********)
paddw xmm4, XMMWORD [wk(0)] ; xmm4=(YE+(B-Y)E)=BE=B(02468ACE)
paddw xmm5, XMMWORD [wk(1)] ; xmm5=(YO+(B-Y)O)=BO=B(13579BDF)
packuswb xmm4,xmm4 ; xmm4=B(02468ACE********)
packuswb xmm5,xmm5 ; xmm5=B(13579BDF********)
%if RGB_PIXELSIZE == 3 ; ---------------
; xmmA=(00 02 04 06 08 0A 0C 0E **), xmmB=(01 03 05 07 09 0B 0D 0F **)
; xmmC=(10 12 14 16 18 1A 1C 1E **), xmmD=(11 13 15 17 19 1B 1D 1F **)
; xmmE=(20 22 24 26 28 2A 2C 2E **), xmmF=(21 23 25 27 29 2B 2D 2F **)
; xmmG=(** ** ** ** ** ** ** ** **), xmmH=(** ** ** ** ** ** ** ** **)
punpcklbw xmmA,xmmC ; xmmA=(00 10 02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E)
punpcklbw xmmE,xmmB ; xmmE=(20 01 22 03 24 05 26 07 28 09 2A 0B 2C 0D 2E 0F)
punpcklbw xmmD,xmmF ; xmmD=(11 21 13 23 15 25 17 27 19 29 1B 2B 1D 2D 1F 2F)
movdqa xmmG,xmmA
movdqa xmmH,xmmA
punpcklwd xmmA,xmmE ; xmmA=(00 10 20 01 02 12 22 03 04 14 24 05 06 16 26 07)
punpckhwd xmmG,xmmE ; xmmG=(08 18 28 09 0A 1A 2A 0B 0C 1C 2C 0D 0E 1E 2E 0F)
psrldq xmmH,2 ; xmmH=(02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E -- --)
psrldq xmmE,2 ; xmmE=(22 03 24 05 26 07 28 09 2A 0B 2C 0D 2E 0F -- --)
movdqa xmmC,xmmD
movdqa xmmB,xmmD
punpcklwd xmmD,xmmH ; xmmD=(11 21 02 12 13 23 04 14 15 25 06 16 17 27 08 18)
punpckhwd xmmC,xmmH ; xmmC=(19 29 0A 1A 1B 2B 0C 1C 1D 2D 0E 1E 1F 2F -- --)
psrldq xmmB,2 ; xmmB=(13 23 15 25 17 27 19 29 1B 2B 1D 2D 1F 2F -- --)
movdqa xmmF,xmmE
punpcklwd xmmE,xmmB ; xmmE=(22 03 13 23 24 05 15 25 26 07 17 27 28 09 19 29)
punpckhwd xmmF,xmmB ; xmmF=(2A 0B 1B 2B 2C 0D 1D 2D 2E 0F 1F 2F -- -- -- --)
pshufd xmmH,xmmA,0x4E; xmmH=(04 14 24 05 06 16 26 07 00 10 20 01 02 12 22 03)
movdqa xmmB,xmmE
punpckldq xmmA,xmmD ; xmmA=(00 10 20 01 11 21 02 12 02 12 22 03 13 23 04 14)
punpckldq xmmE,xmmH ; xmmE=(22 03 13 23 04 14 24 05 24 05 15 25 06 16 26 07)
punpckhdq xmmD,xmmB ; xmmD=(15 25 06 16 26 07 17 27 17 27 08 18 28 09 19 29)
pshufd xmmH,xmmG,0x4E; xmmH=(0C 1C 2C 0D 0E 1E 2E 0F 08 18 28 09 0A 1A 2A 0B)
movdqa xmmB,xmmF
punpckldq xmmG,xmmC ; xmmG=(08 18 28 09 19 29 0A 1A 0A 1A 2A 0B 1B 2B 0C 1C)
punpckldq xmmF,xmmH ; xmmF=(2A 0B 1B 2B 0C 1C 2C 0D 2C 0D 1D 2D 0E 1E 2E 0F)
punpckhdq xmmC,xmmB ; xmmC=(1D 2D 0E 1E 2E 0F 1F 2F 1F 2F -- -- -- -- -- --)
punpcklqdq xmmA,xmmE ; xmmA=(00 10 20 01 11 21 02 12 22 03 13 23 04 14 24 05)
punpcklqdq xmmD,xmmG ; xmmD=(15 25 06 16 26 07 17 27 08 18 28 09 19 29 0A 1A)
punpcklqdq xmmF,xmmC ; xmmF=(2A 0B 1B 2B 0C 1C 2C 0D 1D 2D 0E 1E 2E 0F 1F 2F)
cmp ecx, byte SIZEOF_XMMWORD
jb short .column_st32
test edi, SIZEOF_XMMWORD-1
jnz short .out1
; --(aligned)-------------------
movntdq XMMWORD [edi+0*SIZEOF_XMMWORD], xmmA
movntdq XMMWORD [edi+1*SIZEOF_XMMWORD], xmmD
movntdq XMMWORD [edi+2*SIZEOF_XMMWORD], xmmF
jmp short .out0
.out1: ; --(unaligned)-----------------
movdqu XMMWORD [edi+0*SIZEOF_XMMWORD], xmmA
movdqu XMMWORD [edi+1*SIZEOF_XMMWORD], xmmD
movdqu XMMWORD [edi+2*SIZEOF_XMMWORD], xmmF
.out0:
add edi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD ; outptr
sub ecx, byte SIZEOF_XMMWORD
jz near .nextrow
add esi, byte SIZEOF_XMMWORD ; inptr0
add ebx, byte SIZEOF_XMMWORD ; inptr1
add edx, byte SIZEOF_XMMWORD ; inptr2
jmp near .columnloop
alignx 16,7
.column_st32:
lea ecx, [ecx+ecx*2] ; imul ecx, RGB_PIXELSIZE
cmp ecx, byte 2*SIZEOF_XMMWORD
jb short .column_st16
movdqu XMMWORD [edi+0*SIZEOF_XMMWORD], xmmA
movdqu XMMWORD [edi+1*SIZEOF_XMMWORD], xmmD
add edi, byte 2*SIZEOF_XMMWORD ; outptr
movdqa xmmA,xmmF
sub ecx, byte 2*SIZEOF_XMMWORD
jmp short .column_st15
.column_st16:
cmp ecx, byte SIZEOF_XMMWORD
jb short .column_st15
movdqu XMMWORD [edi+0*SIZEOF_XMMWORD], xmmA
add edi, byte SIZEOF_XMMWORD ; outptr
movdqa xmmA,xmmD
sub ecx, byte SIZEOF_XMMWORD
.column_st15:
; Store the lower 8 bytes of xmmA to the output when it has enough
; space.
cmp ecx, byte SIZEOF_MMWORD
jb short .column_st7
movq XMM_MMWORD [edi], xmmA
add edi, byte SIZEOF_MMWORD
sub ecx, byte SIZEOF_MMWORD
psrldq xmmA, SIZEOF_MMWORD
.column_st7:
; Store the lower 4 bytes of xmmA to the output when it has enough
; space.
cmp ecx, byte SIZEOF_DWORD
jb short .column_st3
movd XMM_DWORD [edi], xmmA
add edi, byte SIZEOF_DWORD
sub ecx, byte SIZEOF_DWORD
psrldq xmmA, SIZEOF_DWORD
.column_st3:
; Store the lower 2 bytes of eax to the output when it has enough
; space.
movd eax, xmmA
cmp ecx, byte SIZEOF_WORD
jb short .column_st1
mov WORD [edi], ax
add edi, byte SIZEOF_WORD
sub ecx, byte SIZEOF_WORD
shr eax, 16
.column_st1:
; Store the lower 1 byte of eax to the output when it has enough
; space.
test ecx, ecx
jz short .nextrow
mov BYTE [edi], al
%else ; RGB_PIXELSIZE == 4 ; -----------
%ifdef RGBX_FILLER_0XFF
pcmpeqb xmm6,xmm6 ; xmm6=XE=X(02468ACE********)
pcmpeqb xmm7,xmm7 ; xmm7=XO=X(13579BDF********)
%else
pxor xmm6,xmm6 ; xmm6=XE=X(02468ACE********)
pxor xmm7,xmm7 ; xmm7=XO=X(13579BDF********)
%endif
; xmmA=(00 02 04 06 08 0A 0C 0E **), xmmB=(01 03 05 07 09 0B 0D 0F **)
; xmmC=(10 12 14 16 18 1A 1C 1E **), xmmD=(11 13 15 17 19 1B 1D 1F **)
; xmmE=(20 22 24 26 28 2A 2C 2E **), xmmF=(21 23 25 27 29 2B 2D 2F **)
; xmmG=(30 32 34 36 38 3A 3C 3E **), xmmH=(31 33 35 37 39 3B 3D 3F **)
punpcklbw xmmA,xmmC ; xmmA=(00 10 02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E)
punpcklbw xmmE,xmmG ; xmmE=(20 30 22 32 24 34 26 36 28 38 2A 3A 2C 3C 2E 3E)
punpcklbw xmmB,xmmD ; xmmB=(01 11 03 13 05 15 07 17 09 19 0B 1B 0D 1D 0F 1F)
punpcklbw xmmF,xmmH ; xmmF=(21 31 23 33 25 35 27 37 29 39 2B 3B 2D 3D 2F 3F)
movdqa xmmC,xmmA
punpcklwd xmmA,xmmE ; xmmA=(00 10 20 30 02 12 22 32 04 14 24 34 06 16 26 36)
punpckhwd xmmC,xmmE ; xmmC=(08 18 28 38 0A 1A 2A 3A 0C 1C 2C 3C 0E 1E 2E 3E)
movdqa xmmG,xmmB
punpcklwd xmmB,xmmF ; xmmB=(01 11 21 31 03 13 23 33 05 15 25 35 07 17 27 37)
punpckhwd xmmG,xmmF ; xmmG=(09 19 29 39 0B 1B 2B 3B 0D 1D 2D 3D 0F 1F 2F 3F)
movdqa xmmD,xmmA
punpckldq xmmA,xmmB ; xmmA=(00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33)
punpckhdq xmmD,xmmB ; xmmD=(04 14 24 34 05 15 25 35 06 16 26 36 07 17 27 37)
movdqa xmmH,xmmC
punpckldq xmmC,xmmG ; xmmC=(08 18 28 38 09 19 29 39 0A 1A 2A 3A 0B 1B 2B 3B)
punpckhdq xmmH,xmmG ; xmmH=(0C 1C 2C 3C 0D 1D 2D 3D 0E 1E 2E 3E 0F 1F 2F 3F)
cmp ecx, byte SIZEOF_XMMWORD
jb short .column_st32
test edi, SIZEOF_XMMWORD-1
jnz short .out1
; --(aligned)-------------------
movntdq XMMWORD [edi+0*SIZEOF_XMMWORD], xmmA
movntdq XMMWORD [edi+1*SIZEOF_XMMWORD], xmmD
movntdq XMMWORD [edi+2*SIZEOF_XMMWORD], xmmC
movntdq XMMWORD [edi+3*SIZEOF_XMMWORD], xmmH
jmp short .out0
.out1: ; --(unaligned)-----------------
movdqu XMMWORD [edi+0*SIZEOF_XMMWORD], xmmA
movdqu XMMWORD [edi+1*SIZEOF_XMMWORD], xmmD
movdqu XMMWORD [edi+2*SIZEOF_XMMWORD], xmmC
movdqu XMMWORD [edi+3*SIZEOF_XMMWORD], xmmH
.out0:
add edi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD ; outptr
sub ecx, byte SIZEOF_XMMWORD
jz near .nextrow
add esi, byte SIZEOF_XMMWORD ; inptr0
add ebx, byte SIZEOF_XMMWORD ; inptr1
add edx, byte SIZEOF_XMMWORD ; inptr2
jmp near .columnloop
alignx 16,7
.column_st32:
cmp ecx, byte SIZEOF_XMMWORD/2
jb short .column_st16
movdqu XMMWORD [edi+0*SIZEOF_XMMWORD], xmmA
movdqu XMMWORD [edi+1*SIZEOF_XMMWORD], xmmD
add edi, byte 2*SIZEOF_XMMWORD ; outptr
movdqa xmmA,xmmC
movdqa xmmD,xmmH
sub ecx, byte SIZEOF_XMMWORD/2
.column_st16:
cmp ecx, byte SIZEOF_XMMWORD/4
jb short .column_st15
movdqu XMMWORD [edi+0*SIZEOF_XMMWORD], xmmA
add edi, byte SIZEOF_XMMWORD ; outptr
movdqa xmmA,xmmD
sub ecx, byte SIZEOF_XMMWORD/4
.column_st15:
; Store two pixels (8 bytes) of xmmA to the output when it has enough
; space.
cmp ecx, byte SIZEOF_XMMWORD/8
jb short .column_st7
movq XMM_MMWORD [edi], xmmA
add edi, byte SIZEOF_XMMWORD/8*4
sub ecx, byte SIZEOF_XMMWORD/8
psrldq xmmA, SIZEOF_XMMWORD/8*4
.column_st7:
; Store one pixel (4 bytes) of xmmA to the output when it has enough
; space.
test ecx, ecx
jz short .nextrow
movd XMM_DWORD [edi], xmmA
%endif ; RGB_PIXELSIZE ; ---------------
alignx 16,7
.nextrow:
pop ecx
pop esi
pop ebx
pop edx
pop edi
pop eax
add esi, byte SIZEOF_JSAMPROW
add ebx, byte SIZEOF_JSAMPROW
add edx, byte SIZEOF_JSAMPROW
add edi, byte SIZEOF_JSAMPROW ; output_buf
dec eax ; num_rows
jg near .rowloop
sfence ; flush the write buffer
.return:
pop edi
pop esi
; pop edx ; need not be preserved
; pop ecx ; need not be preserved
pop ebx
mov esp,ebp ; esp <- aligned ebp
pop esp ; esp <- original ebp
pop ebp
ret
; For some reason, the OS X linker does not honor the request to align the
; segment unless we do this.
align 16
|
; A061279: a(n) = Sum_{k >= 0} 2^k * binomial(k+2,n-2*k).
; Submitted by Jamie Morken(s2)
; 1,2,3,6,10,18,32,56,100,176,312,552,976,1728,3056,5408,9568,16928,29952,52992,93760,165888,293504,519296,918784,1625600,2876160,5088768,9003520,15929856,28184576,49866752,88228864,156102656
mov $2,1
mov $4,2
lpb $0
sub $0,1
mov $3,1
add $3,$1
add $1,$3
add $4,$1
mov $1,$2
mov $2,$4
mov $4,$3
mul $4,2
lpe
mov $0,$2
div $0,2
add $0,1
|
; A345211: Numbers with the same number of odd / even, refactorable divisors.
; 2,4,6,10,14,18,20,22,26,28,30,34,38,42,44,46,50,52,54,58,62,66,68,70,74,76,78,82,86,90,92,94,98,100,102,106,110,114,116,118,122,124,126,130,134,138,140,142,146,148,150,154,158,162,164,166,170,172,174,178,182,186,188
add $0,1
seq $0,141259 ; a(n) == {0,1,3,4,5,7,9,11} mod 12; n>0.
sub $0,2
mul $0,2
|
// Copyright 2021, Autonomous Space Robotics Lab (ASRL)
//
// 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.
/**
* \file run_alignment.inl
* \brief
* \details
*
* \author Autonomous Space Robotics Lab (ASRL)
*/
#pragma once
#include <vtr_pose_graph/relaxation/run_alignment.hpp>
//#include <vtr_pose_graph/relaxation/privileged_frame.hpp>
//#include <vtr_pose_graph/evaluator/accumulators.hpp>
namespace vtr {
namespace pose_graph {
#if 0
/////////////////////////////////////////////////////////////////////////////
/// @brief Constructor; automatically initializes vertices to tree expansion
/////////////////////////////////////////////////////////////////////////////
template <class G>
RunAlignment<G>::RunAlignment(const GraphPtr& graph) : graph_(graph) {
for (auto&& run : graph_->runs()) {
if (!run.second->isManual()) {
_buildRun(run.second);
}
}
}
/////////////////////////////////////////////////////////////////////////////
/// @brief Internal function to expand a single run
/////////////////////////////////////////////////////////////////////////////
template <class G>
void RunAlignment<G>::_buildRun(const RunPtr& run) {
if (run->vertices().size() == 0 || run->edges(Spatial).size() == 0) {
LOG(WARNING) << "Skipping run " << run->id()
<< " due to lack of vertices/edges";
return;
}
using namespace steam::se3;
StateMapType states;
VertexId root = VertexId::Invalid();
// Start with any cached transforms, and make one of those vertices the root
// for (auto &&it: run->vertices()) {
// if (it.second->hasTransform()) {
// states.emplace(it.first, TransformStateVar::Ptr(new
// TransformStateVar(it.second->T()))); if (!root.isSet()) root =
// it.first;
// }
// }
// If no transforms were previously set, find the first vertex with a spatial
// edge to be the root
if (!root.isSet()) {
for (auto&& it : run->vertices()) {
if (it.second->spatialEdges().size() > 0) {
root = it.first;
break;
}
}
// A disconnected run should never happen, so we need to be loud about this
if (!root.isSet()) {
LOG(FATAL) << "Run " << run->id()
<< " has no connection to the rest of the graph!!! (you done "
"broke the graph)";
return;
}
// Get the spatial edge and the corresponding privileged vertex
auto edge = graph_->at(*graph_->at(root)->spatialEdges().begin());
auto v = graph_->at(*graph_->at(root)->spatialNeighbours().begin());
// If it doens't have a transform, something is really busted :/
TransformType T_v(true);
if (v->hasTransform()) {
T_v = v->T();
} else {
LOG(FATAL) << "A privileged vertex didn't have a cached transform... Did "
"this graph come from VT&R 2.0?";
}
// Account for edge direction swapping
TransformType T_init(true);
if (edge->from() == root) {
T_init = edge->T().inverse() * T_v;
} else {
T_init = edge->T() * T_v;
}
// Ensure the root vertex has a state
states.emplace(root, TransformStateVar::Ptr(new TransformStateVar(T_init)));
}
// If we didn't have transforms for all of the states, generate the rest by
// expansion
if (states.size() < run->vertices().size()) {
// Forward pass from root to end
auto it = ++run->vertices().find(root);
VertexId last = root;
for (; it != run->vertices().end(); ++it) {
VertexId vid = it->first;
if (states.find(vid) != states.end()) {
last = vid;
continue;
}
auto e = run->at(EdgeIdType(last, vid, Temporal));
states.emplace(vid, TransformStateVar::Ptr(new TransformStateVar(
e->T() * states.at(last)->getValue())));
last = vid;
}
// Reverse pass from root to beginning
auto jt = std::reverse_iterator<decltype(it)>(run->vertices().find(root));
last = root;
for (; jt != run->vertices().rend(); ++jt) {
VertexId vid = jt->first;
if (states.find(vid) != states.end()) {
last = vid;
continue;
}
auto e = run->at(EdgeIdType(vid, last, Temporal));
states.emplace(vid, TransformStateVar::Ptr(new TransformStateVar(
e->T().inverse() * states.at(last)->getValue())));
last = vid;
}
}
// If the run isn't a linear chain, something is very wrong
if (states.size() < run->vertices().size()) {
LOG(FATAL) << "Run was not temporally connected!!";
}
// Populate the global state map with the states from this run
stateMap_.emplace(run->id(), states);
}
/////////////////////////////////////////////////////////////////////////////
/// @brief Lock a state variable
/////////////////////////////////////////////////////////////////////////////
template <class G>
void RunAlignment<G>::setLock(const VertexIdType& v, bool locked) {
stateMap_.at(v.majorId()).at(v)->setLock(locked);
}
/////////////////////////////////////////////////////////////////////////////
/// @brief Lock a vector of state variables
/////////////////////////////////////////////////////////////////////////////
template <class G>
void RunAlignment<G>::setLock(const std::vector<VertexIdType>& v, bool locked) {
for (auto&& it : v) {
stateMap_.at(it.majorId()).at(it)->setLock(locked);
}
}
/////////////////////////////////////////////////////////////////////////////
/// @brief Build the run-to-run cost terms
/////////////////////////////////////////////////////////////////////////////
template <class G>
void RunAlignment<G>::buildCostTerms(const Matrix6d& cov,
const LossFuncPtr& lossFunc) {
using namespace steam;
ModelGen model(cov);
// Loop through all runs separately
for (auto&& rt : stateMap_) {
CostTermPtr costs(new ParallelizedCostTermCollection());
auto prev = rt.second.begin();
auto first = rt.second.begin()->first;
// For each vertex (state variable) add cost terms
for (auto it = rt.second.begin(); it != rt.second.end(); ++it) {
// One cost term per temporal edge, unless both are locked
if (it->first != first && !it->second->isLocked() &&
!prev->second->isLocked()) {
auto edge = graph_->at(prev->first, it->first);
TransformErrorEval::Ptr errorFunc(
new TransformErrorEval(edge->T(), it->second, prev->second));
WeightedLeastSqCostTerm<6, 6>::Ptr cost(
new WeightedLeastSqCostTerm<6, 6>(errorFunc, model(edge->T()),
lossFunc));
costs->add(cost);
}
prev = it;
// Don't add cost terms to locked state variables, as they won't be in the
// problem
if (it->second->isLocked()) continue;
// One cost term for each spatial neighbour
for (auto&& jt : graph_->at(it->first)->spatialNeighbours()) {
// ...But only if the neighbour is actually in the graph and has a
// transform
if (graph_->contains(jt) && graph_->at(jt)->hasTransform()) {
auto T_v_w = graph_->at(jt)->T();
auto edge = graph_->at(it->first, jt);
// Handle edge inversion if necessary
if (edge->from() == it->first) {
T_v_w = edge->T().inverse() * T_v_w;
} else {
T_v_w = edge->T() * T_v_w;
}
// Add a spatial edge constraint between this run vertex and it's
// localized neighbour
se3::TransformEvaluator::Ptr eval(
new se3::TransformStateEvaluator(it->second));
TransformErrorEval::Ptr errorFunc(
new TransformErrorEval(T_v_w, eval));
WeightedLeastSqCostTerm<6, 6>::Ptr cost(
new WeightedLeastSqCostTerm<6, 6>(errorFunc, model(T_v_w),
lossFunc));
costs->add(cost);
}
}
}
costTerms_.emplace(rt.first, costs);
}
}
/////////////////////////////////////////////////////////////////////////////
/// @brief Solve the optimization problem using a given solver
/////////////////////////////////////////////////////////////////////////////
template <class G>
template <class Solver>
void RunAlignment<G>::optimize(const typename Solver::Params& params) {
if (params.maxIterations == 0) {
LOG(INFO) << "Graph optimization skipped since maxIterations==0.";
return;
}
// Each run is a separate problem because they are disjoint when conditioned
// on the privileged runs
for (auto&& rt : stateMap_) {
// Only add unlocked states or STEAM complains
steam::OptimizationProblem problem;
for (auto&& it : rt.second) {
if (!it.second->isLocked()) problem.addStateVariable(it.second);
}
problem.addCostTerm(costTerms_.at(rt.first));
LOG(DEBUG) << "Optimizing run " << rt.first << " with "
<< problem.getStateVariables().size() << "/" << rt.second.size()
<< " states and " << problem.getNumberOfCostTerms()
<< " terms...";
// Ensure the problem isn't empty, or STEAM also complains
if (problem.getStateVariables().size() == 0 ||
problem.getNumberOfCostTerms() == 0) {
LOG(INFO) << "Attempted relaxation on an empty/locked run (" << rt.first
<< ")... Result: 0 cost; perfect 5/7!";
continue;
}
Solver s(&problem, params);
try {
s.optimize();
} catch (const steam::unsuccessful_step& e) {
LOG(INFO) << "Unsuccessful step for run " << rt.first
<< " (maybe the stored initial guess is good?)";
} catch (const steam::decomp_failure& e) {
LOG(INFO) << "Dcomp failure for fun " << rt.first
<< " (was the run floating?)";
}
}
}
/////////////////////////////////////////////////////////////////////////////
/// @brief Get a transform by vertex ID
/////////////////////////////////////////////////////////////////////////////
template <class G>
const lgmath::se3::Transformation& RunAlignment<G>::at(
const VertexIdType& v) const {
return stateMap_.at(v.majorId()).at(v)->getValue();
}
/////////////////////////////////////////////////////////////////////////////
/// @brief Apply the optimization to the graph
/////////////////////////////////////////////////////////////////////////////
template <class G>
void RunAlignment<G>::apply() const {
for (auto&& rt : stateMap_) {
for (auto&& it : rt.second) {
graph_->at(it.first)->setTransform(it.second->getValue());
}
}
}
/////////////////////////////////////////////////////////////////////////////
/// @brief Get the transform between two vertex IDs
/////////////////////////////////////////////////////////////////////////////
template <class G>
lgmath::se3::Transformation RunAlignment<G>::T_ab(
const VertexIdType& v_a, const VertexIdType& v_b) const {
return stateMap_.at(v_a.majorId()).at(v_a)->getValue() /
stateMap_.at(v_b.majorId()).at(v_b)->getValue();
}
/////////////////////////////////////////////////////////////////////////////
/// @brief Apply the optimization to the graph
/////////////////////////////////////////////////////////////////////////////
template <class G>
void RunAlignment<G>::applyEdge() const {
for (auto it = graph_->beginEdge(), ite = graph_->endEdge(); it != ite;
++it) {
if (stateMap_.find(it->from().majorId()) != stateMap_.end() &&
stateMap_.find(it->to().majorId()) != stateMap_.end()) {
graph_->at(it->id())->setTransform(this->T_ab(it->from(), it->to()));
}
}
}
#endif
} // namespace pose_graph
} // namespace vtr
|
;================================================================================
; Dark World Spawn Location Fix & Master Sword Grove Fix
;--------------------------------------------------------------------------------
DarkWorldSaveFix:
LDA.b #$70 : PHA : PLB ; thing we wrote over - data bank change
JSL.l MasterSwordFollowerClear
JSL.l StatSaveCounter
RTL
;--------------------------------------------------------------------------------
DoWorldFix:
LDA InvertedMode : BEQ +
JMP DoWorldFix_Inverted
+
LDA.l Bugfix_MirrorlessSQToLW : BEQ .skip_mirror_check
LDA $7EF353 : AND #$02 : BEQ .noMirror ; check if we have the mirror
.skip_mirror_check ; alt entrance point
LDA $7EF3C5 : CMP.b #$03 : !BLT .aga1Alive ; check if agahnim 1 is alive
BRA .done
.noMirror
.aga1Alive
LDA #$00 : STA $7EF3CA ; set flag to light world
LDA $7EF3CC : CMP #$07 : BNE + : LDA.b #$08 : STA $7EF3CC : + ; convert frog to dwarf
.done
RTL
;--------------------------------------------------------------------------------
SetDeathWorldChecked:
LDA InvertedMode : BEQ +
JMP SetDeathWorldChecked_Inverted
+
LDA $1B : BEQ .outdoors
LDA $040C : CMP #$FF : BNE .dungeon
LDA $A0 : BNE ++
LDA $A1 : BNE ++ ; Prevent cheesing your way to top of pyramid by bombing yourself at High stakes chest game.
LDA GanonPyramidRespawn : BNE .pyramid ; if flag is set, force respawn at pyramid on death to ganon
++
.outdoors
JMP DoWorldFix
.dungeon
LDA Bugfix_PreAgaDWDungeonDeathToFakeDW : BNE .done ; if the bugfix is enabled, we do nothing on death in dungeon
JMP DoWorldFix_skip_mirror_check
.pyramid
LDA #$40 : STA $7EF3CA ; set flag to dark world
LDA $7EF3CC : CMP #$08 : BNE + : LDA.b #$07 : STA $7EF3CC : + ; convert dwarf to frog
.done
RTL
;================================================================================
DoWorldFix_Inverted:
LDA.l Bugfix_MirrorlessSQToLW : BEQ .skip_mirror_check
LDA $7EF353 : AND #$02 : BEQ .noMirror ; check if we have the mirror
.skip_mirror_check ; alt entrance point
LDA $7EF3C5 : CMP.b #$03 : !BLT .aga1Alive ; check if agahnim 1 is alive
BRA .done
.noMirror
.aga1Alive
LDA #$40 : STA $7EF3CA ; set flag to dark world
LDA $7EF3CC
CMP #$07 : BEQ .clear ; clear frog
CMP #$08 : BEQ .clear ; clear dwarf - consider flute implications
BRA .done
.clear
LDA.b #$00 : STA $7EF3CC ; clear follower
.done
RTL
;--------------------------------------------------------------------------------
SetDeathWorldChecked_Inverted:
LDA $1B : BEQ .outdoors
LDA $040C : CMP #$FF : BNE .dungeon
LDA $A0 : BNE ++
LDA $A1 : BNE ++ ; Prevent cheesing your way to top of castle by bombing yourself at High stakes chest game.
LDA GanonPyramidRespawn : BNE .castle ; if flag is set, force respawn at pyramid on death to ganon
++
.outdoors
JMP DoWorldFix
.dungeon
LDA Bugfix_PreAgaDWDungeonDeathToFakeDW : BNE .done ; if the bugfix is enabled, we do nothing on death in dungeon
JMP DoWorldFix_Inverted_skip_mirror_check
.castle
LDA #$00 : STA $7EF3CA ; set flag to dark world
LDA $7EF3CC : CMP #$07 : BNE + : LDA.b #$08 : STA $7EF3CC : + ; convert frog to dwarf
.done
RTL
;================================================================================
;--------------------------------------------------------------------------------
FakeWorldFix:
LDA FixFakeWorld : BEQ +
LDA $8A : AND.b #$40 : STA $7EF3CA
+
RTL
;--------------------------------------------------------------------------------
MasterSwordFollowerClear:
LDA $7EF3CC
CMP #$0E : BEQ .clear ; clear master sword follower
RTL
.clear
LDA.b #$00 : STA $7EF3CC ; clear follower
RTL
;--------------------------------------------------------------------------------
FixAgahnimFollowers:
LDA.b #$00 : STA $7EF3CC ; clear follower
JSL PrepDungeonExit ; thing we wrote over
RTL
;--------------------------------------------------------------------------------
macro FillToMinimum(base,filler,compare)
LDA.l <compare> : !SUB.l <base> : !BLT ?done
STA.l <filler>
?done:
endmacro
macro SetMinimum(base,compare)
LDA.l <compare> : !SUB.l <base> : !BLT ?done
LDA.l <compare> : STA.l <base>
?done:
endmacro
RefreshRainAmmo:
LDA $7EF3C5 : CMP.b #$01 : BEQ + : RTL : + ; check if we're in rain state
.rain
LDA $7EF3C8
+ CMP.b #$03 : BNE + ; Uncle
%FillToMinimum($7EF36E,$7EF373,RainDeathRefillMagic_Uncle)
%FillToMinimum($7EF343,$7EF375,RainDeathRefillBombs_Uncle)
%FillToMinimum($7EF377,$7EF376,RainDeathRefillArrows_Uncle)
%SetMinimum($7EF38B,RainDeathRefillKeys_Uncle)
BRL .done
+ CMP.b #$02 : BNE + ; Cell
%FillToMinimum($7EF36E,$7EF373,RainDeathRefillMagic_Cell)
%FillToMinimum($7EF343,$7EF375,RainDeathRefillBombs_Cell)
%FillToMinimum($7EF377,$7EF376,RainDeathRefillArrows_Cell)
%SetMinimum($7EF38B,RainDeathRefillKeys_Cell)
BRA .done
+ CMP.b #$04 : BNE + ; Mantle
%FillToMinimum($7EF36E,$7EF373,RainDeathRefillMagic_Mantle)
%FillToMinimum($7EF343,$7EF375,RainDeathRefillBombs_Mantle)
%FillToMinimum($7EF377,$7EF376,RainDeathRefillArrows_Mantle)
%SetMinimum($7EF38B,RainDeathRefillKeys_Mantle)
+
.done
RTL
;--------------------------------------------------------------------------------
!INFINITE_ARROWS = "$7F50C8"
!INFINITE_BOMBS = "$7F50C9"
!INFINITE_MAGIC = "$7F50CA"
SetEscapeAssist:
LDA $7EF3C5 : CMP.b #$01 : BNE .notrain ; check if we're in rain state
.rain
LDA.l EscapeAssist
BIT.b #$04 : BEQ + : STA !INFINITE_MAGIC : +
BIT.b #$02 : BEQ + : STA !INFINITE_BOMBS : +
BIT.b #$01 : BEQ + : STA !INFINITE_ARROWS : +
BRA ++
.notrain
LDA.l EscapeAssist : BIT.b #$04 : BEQ + : LDA.b #$00 : STA !INFINITE_MAGIC : +
LDA.l EscapeAssist : BIT.b #$02 : BEQ + : LDA.b #$00 : STA !INFINITE_BOMBS : +
LDA.l EscapeAssist : BIT.b #$01 : BEQ + : LDA.b #$00 : STA !INFINITE_ARROWS : +
++
RTL
;--------------------------------------------------------------------------------
SetSilverBowMode:
LDA SilverArrowsUseRestriction : BEQ + ; fix bow type for restricted arrow mode
LDA $7EF340 : CMP.b #$3 : !BLT +
!SUB.b #$02 : STA $7EF340
+
RTL
;================================================================================
|
; A113854: a(n) = sum(2^(A047240(i)-1), i=1..n).
; 1,3,35,99,227,2275,6371,14563,145635,407779,932067,9320675,26097891,59652323,596523235,1670265059,3817748707,38177487075,106896963811,244335917283,2443359172835,6841405683939,15637498706147,156374987061475,437849963772131,1000799917193443
mov $25,$0
mov $27,$0
add $27,1
lpb $27,1
clr $0,25
mov $0,$25
sub $27,1
sub $0,$27
mov $22,$0
mov $24,$0
add $24,1
lpb $24,1
clr $0,22
mov $0,$22
trn $24,1
sub $0,$24
mov $19,$0
mov $21,$0
add $21,1
lpb $21,1
mov $0,$19
trn $21,1
sub $0,$21
mov $15,$0
mov $17,2
lpb $17,1
mov $0,$15
sub $17,1
add $0,$17
sub $0,1
mov $11,$0
mov $13,2
lpb $13,1
mov $0,$11
sub $13,1
add $0,$13
trn $0,1
add $0,2
mul $0,2
mov $9,1
lpb $0,1
mov $4,1
mov $5,$0
sub $5,1
mov $6,$0
mov $0,1
mul $9,3
mod $6,$9
add $6,10
mov $8,2
mov $9,$6
sub $9,6
mov $2,$9
lpe
add $2,$4
add $5,$2
pow $8,$5
mov $1,$8
mov $14,$13
lpb $14,1
mov $12,$1
sub $14,1
lpe
lpe
lpb $11,1
mov $11,0
sub $12,$1
lpe
mov $1,$12
mov $18,$17
lpb $18,1
mov $16,$1
sub $18,1
lpe
lpe
lpb $15,1
mov $15,0
sub $16,$1
lpe
mov $1,$16
div $1,512
add $20,$1
lpe
add $23,$20
lpe
add $26,$23
lpe
mov $1,$26
|
//===--- FrontendTool.cpp - Swift Compiler Frontend -----------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
///
/// \file
/// \brief This is the entry point to the swift -frontend functionality, which
/// implements the core compiler functionality along with a number of additional
/// tools for demonstration and testing purposes.
///
/// This is separate from the rest of libFrontend to reduce the dependencies
/// required by that library.
///
//===----------------------------------------------------------------------===//
#include "swift/FrontendTool/FrontendTool.h"
#include "ImportedModules.h"
#include "ReferenceDependencies.h"
#include "TBD.h"
#include "swift/Strings.h"
#include "swift/Subsystems.h"
#include "swift/AST/ASTScope.h"
#include "swift/AST/DiagnosticsFrontend.h"
#include "swift/AST/DiagnosticsSema.h"
#include "swift/AST/GenericSignatureBuilder.h"
#include "swift/AST/IRGenOptions.h"
#include "swift/AST/ASTMangler.h"
#include "swift/AST/ReferencedNameTracker.h"
#include "swift/AST/TypeRefinementContext.h"
#include "swift/Basic/Dwarf.h"
#include "swift/Basic/Edit.h"
#include "swift/Basic/FileSystem.h"
#include "swift/Basic/JSONSerialization.h"
#include "swift/Basic/LLVMContext.h"
#include "swift/Basic/SourceManager.h"
#include "swift/Basic/Statistic.h"
#include "swift/Basic/Timer.h"
#include "swift/Basic/UUID.h"
#include "swift/Frontend/DiagnosticVerifier.h"
#include "swift/Frontend/Frontend.h"
#include "swift/Frontend/PrintingDiagnosticConsumer.h"
#include "swift/Frontend/SerializedDiagnosticConsumer.h"
#include "swift/Immediate/Immediate.h"
#include "swift/Index/IndexRecord.h"
#include "swift/Option/Options.h"
#include "swift/Migrator/FixitFilter.h"
#include "swift/Migrator/Migrator.h"
#include "swift/PrintAsObjC/PrintAsObjC.h"
#include "swift/Serialization/SerializationOptions.h"
#include "swift/Serialization/SerializedModuleLoader.h"
#include "swift/SILOptimizer/PassManager/Passes.h"
#include "swift/Syntax/Serialization/SyntaxSerialization.h"
#include "swift/Syntax/SyntaxNodes.h"
// FIXME: We're just using CompilerInstance::createOutputFile.
// This API should be sunk down to LLVM.
#include "clang/Frontend/CompilerInstance.h"
#include "clang/AST/ASTContext.h"
#include "clang/APINotes/Types.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/IRReader/IRReader.h"
#include "llvm/Option/Option.h"
#include "llvm/Option/OptTable.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Support/Timer.h"
#include "llvm/Support/YAMLTraits.h"
#include "llvm/Target/TargetMachine.h"
#include <deque>
#include <memory>
#include <unordered_set>
#if !defined(_MSC_VER) && !defined(__MINGW32__)
#include <unistd.h>
#else
#include <io.h>
#endif
using namespace swift;
static std::string displayName(StringRef MainExecutablePath) {
std::string Name = llvm::sys::path::stem(MainExecutablePath);
Name += " -frontend";
return Name;
}
/// Emits a Make-style dependencies file.
static bool emitMakeDependencies(DiagnosticEngine &diags,
DependencyTracker &depTracker,
const FrontendOptions &opts,
const InputFile &input) {
std::error_code EC;
llvm::raw_fd_ostream out(
opts.InputsAndOutputs.supplementaryOutputs().DependenciesFilePath, EC,
llvm::sys::fs::F_None);
if (out.has_error() || EC) {
diags.diagnose(
SourceLoc(), diag::error_opening_output,
opts.InputsAndOutputs.supplementaryOutputs().DependenciesFilePath,
EC.message());
out.clear_error();
return true;
}
// Declare a helper for escaping file names for use in Makefiles.
llvm::SmallString<256> pathBuf;
auto escape = [&](StringRef raw) -> StringRef {
pathBuf.clear();
static const char badChars[] = " $#:\n";
size_t prev = 0;
for (auto index = raw.find_first_of(badChars); index != StringRef::npos;
index = raw.find_first_of(badChars, index+1)) {
pathBuf.append(raw.slice(prev, index));
if (raw[index] == '$')
pathBuf.push_back('$');
else
pathBuf.push_back('\\');
prev = index;
}
pathBuf.append(raw.substr(prev));
return pathBuf;
};
// FIXME: Xcode can't currently handle multiple targets in a single
// dependency line.
opts.forAllOutputPaths(input, [&](StringRef targetName) {
out << escape(targetName) << " :";
// First include all other files in the module. Make-style dependencies
// need to be conservative!
for (auto const &path :
reversePathSortedFilenames(opts.InputsAndOutputs.getInputFilenames()))
out << ' ' << escape(path);
// Then print dependencies we've picked up during compilation.
for (auto const &path :
reversePathSortedFilenames(depTracker.getDependencies()))
out << ' ' << escape(path);
out << '\n';
});
return false;
}
static bool emitMakeDependencies(DiagnosticEngine &diags,
DependencyTracker &depTracker,
const FrontendOptions &opts) {
bool hadError = false;
opts.InputsAndOutputs.forEachInputProducingSupplementaryOutput(
[&](const InputFile &f) -> void {
hadError = emitMakeDependencies(diags, depTracker, opts, f) || hadError;
});
return hadError;
}
namespace {
struct LoadedModuleTraceFormat {
std::string Name;
std::string Arch;
std::vector<std::string> SwiftModules;
};
}
namespace swift {
namespace json {
template <> struct ObjectTraits<LoadedModuleTraceFormat> {
static void mapping(Output &out, LoadedModuleTraceFormat &contents) {
out.mapRequired("name", contents.Name);
out.mapRequired("arch", contents.Arch);
out.mapRequired("swiftmodules", contents.SwiftModules);
}
};
}
}
static bool emitLoadedModuleTraceIfNeeded(ASTContext &ctxt,
DependencyTracker *depTracker,
const FrontendOptions &opts) {
if (opts.InputsAndOutputs.supplementaryOutputs()
.LoadedModuleTracePath.empty())
return false;
std::error_code EC;
llvm::raw_fd_ostream out(
opts.InputsAndOutputs.supplementaryOutputs().LoadedModuleTracePath, EC,
llvm::sys::fs::F_Append);
if (out.has_error() || EC) {
ctxt.Diags.diagnose(
SourceLoc(), diag::error_opening_output,
opts.InputsAndOutputs.supplementaryOutputs().LoadedModuleTracePath,
EC.message());
out.clear_error();
return true;
}
llvm::SmallVector<std::string, 16> swiftModules;
// Canonicalise all the paths by opening them.
for (auto &dep : depTracker->getDependencies()) {
llvm::SmallString<256> buffer;
StringRef realPath;
int FD;
// FIXME: appropriate error handling
if (llvm::sys::fs::openFileForRead(dep, FD, &buffer)) {
// Couldn't open the file now, so let's just assume the old path was
// canonical (enough).
realPath = dep;
} else {
realPath = buffer.str();
// Not much we can do about failing to close.
(void)close(FD);
}
// Decide if this is a swiftmodule based on the extension of the raw
// dependency path, as the true file may have a different one.
auto ext = llvm::sys::path::extension(dep);
if (ext.startswith(".") &&
ext.drop_front() == SERIALIZED_MODULE_EXTENSION) {
swiftModules.push_back(realPath);
}
}
LoadedModuleTraceFormat trace = {
/*name=*/opts.ModuleName,
/*arch=*/ctxt.LangOpts.Target.getArchName(),
/*swiftmodules=*/reversePathSortedFilenames(swiftModules)};
// raw_fd_ostream is unbuffered, and we may have multiple processes writing,
// so first write the whole thing into memory and dump out that buffer to the
// file.
std::string stringBuffer;
{
llvm::raw_string_ostream memoryBuffer(stringBuffer);
json::Output jsonOutput(memoryBuffer, /*PrettyPrint=*/false);
json::jsonize(jsonOutput, trace, /*Required=*/true);
}
stringBuffer += "\n";
out << stringBuffer;
return true;
}
/// Gets an output stream for the provided output filename, or diagnoses to the
/// provided AST Context and returns null if there was an error getting the
/// stream.
static std::unique_ptr<llvm::raw_fd_ostream>
getFileOutputStream(StringRef OutputFilename, ASTContext &Ctx) {
std::error_code errorCode;
auto os = llvm::make_unique<llvm::raw_fd_ostream>(
OutputFilename, errorCode, llvm::sys::fs::F_None);
if (errorCode) {
Ctx.Diags.diagnose(SourceLoc(), diag::error_opening_output,
OutputFilename, errorCode.message());
return nullptr;
}
return os;
}
/// Writes the Syntax tree to the given file
static bool emitSyntax(SourceFile *SF, LangOptions &LangOpts,
SourceManager &SM, StringRef OutputFilename) {
auto bufferID = SF->getBufferID();
assert(bufferID && "frontend should have a buffer ID "
"for the main source file");
auto os = getFileOutputStream(OutputFilename, SF->getASTContext());
if (!os) return true;
json::Output jsonOut(*os);
auto Root = SF->getSyntaxRoot().getRaw();
jsonOut << *Root;
*os << "\n";
return false;
}
/// Writes SIL out to the given file.
static bool writeSIL(SILModule &SM, ModuleDecl *M, bool EmitVerboseSIL,
StringRef OutputFilename, bool SortSIL) {
auto OS = getFileOutputStream(OutputFilename, M->getASTContext());
if (!OS) return true;
SM.print(*OS, EmitVerboseSIL, M, SortSIL);
return false;
}
static bool writeSIL(SILModule &SM, const PrimarySpecificPaths &PSPs,
CompilerInstance &Instance,
CompilerInvocation &Invocation) {
const FrontendOptions &opts = Invocation.getFrontendOptions();
return writeSIL(SM, Instance.getMainModule(), opts.EmitVerboseSIL,
PSPs.OutputFilename, opts.EmitSortedSIL);
}
static bool printAsObjCIfNeeded(const std::string &outputPath, ModuleDecl *M,
StringRef bridgingHeader, bool moduleIsPublic) {
using namespace llvm::sys;
if (outputPath.empty())
return false;
clang::CompilerInstance Clang;
std::string tmpFilePath;
std::error_code EC;
std::unique_ptr<llvm::raw_pwrite_stream> out =
Clang.createOutputFile(outputPath, EC,
/*Binary=*/false,
/*RemoveFileOnSignal=*/true,
/*BaseInput=*/"",
path::extension(outputPath),
/*UseTemporary=*/true,
/*CreateMissingDirectories=*/false,
/*ResultPathName=*/nullptr,
&tmpFilePath);
if (!out) {
M->getASTContext().Diags.diagnose(SourceLoc(), diag::error_opening_output,
tmpFilePath, EC.message());
return true;
}
auto requiredAccess = moduleIsPublic ? AccessLevel::Public
: AccessLevel::Internal;
bool hadError = printAsObjC(*out, M, bridgingHeader, requiredAccess);
out->flush();
EC = swift::moveFileIfDifferent(tmpFilePath, outputPath);
if (EC) {
M->getASTContext().Diags.diagnose(SourceLoc(), diag::error_opening_output,
outputPath, EC.message());
return true;
}
return hadError;
}
/// Returns the OutputKind for the given Action.
static IRGenOutputKind getOutputKind(FrontendOptions::ActionType Action) {
switch (Action) {
case FrontendOptions::ActionType::EmitIR:
return IRGenOutputKind::LLVMAssembly;
case FrontendOptions::ActionType::EmitBC:
return IRGenOutputKind::LLVMBitcode;
case FrontendOptions::ActionType::EmitAssembly:
return IRGenOutputKind::NativeAssembly;
case FrontendOptions::ActionType::EmitObject:
return IRGenOutputKind::ObjectFile;
case FrontendOptions::ActionType::Immediate:
return IRGenOutputKind::Module;
default:
llvm_unreachable("Unknown ActionType which requires IRGen");
return IRGenOutputKind::ObjectFile;
}
}
namespace {
/// If there is an error with fixits it writes the fixits as edits in json
/// format.
class JSONFixitWriter
: public DiagnosticConsumer, public migrator::FixitFilter {
std::string FixitsOutputPath;
std::unique_ptr<llvm::raw_ostream> OSPtr;
bool FixitAll;
std::vector<SingleEdit> AllEdits;
public:
JSONFixitWriter(std::string fixitsOutputPath,
const DiagnosticOptions &DiagOpts)
: FixitsOutputPath(fixitsOutputPath),
FixitAll(DiagOpts.FixitCodeForAllDiagnostics) {}
private:
void handleDiagnostic(SourceManager &SM, SourceLoc Loc,
DiagnosticKind Kind,
StringRef FormatString,
ArrayRef<DiagnosticArgument> FormatArgs,
const DiagnosticInfo &Info) override {
if (!(FixitAll || shouldTakeFixit(Kind, Info)))
return;
for (const auto &Fix : Info.FixIts) {
AllEdits.push_back({SM, Fix.getRange(), Fix.getText()});
}
}
bool finishProcessing() override {
std::error_code EC;
std::unique_ptr<llvm::raw_fd_ostream> OS;
OS.reset(new llvm::raw_fd_ostream(FixitsOutputPath,
EC,
llvm::sys::fs::F_None));
if (EC) {
// Create a temporary diagnostics engine to print the error to stderr.
SourceManager dummyMgr;
DiagnosticEngine DE(dummyMgr);
PrintingDiagnosticConsumer PDC;
DE.addConsumer(PDC);
DE.diagnose(SourceLoc(), diag::cannot_open_file,
FixitsOutputPath, EC.message());
return true;
}
swift::writeEditsInJson(llvm::makeArrayRef(AllEdits), *OS);
return false;
}
};
} // anonymous namespace
// This is a separate function so that it shows up in stack traces.
LLVM_ATTRIBUTE_NOINLINE
static void debugFailWithAssertion() {
// Per the user's request, this assertion should always fail in
// builds with assertions enabled.
// This should not be converted to llvm_unreachable, as those are
// treated as optimization hints in builds where they turn into
// __builtin_unreachable().
assert((0) && "This is an assertion!");
}
// This is a separate function so that it shows up in stack traces.
LLVM_ATTRIBUTE_NOINLINE
static void debugFailWithCrash() {
LLVM_BUILTIN_TRAP;
}
/// \return true on error.
static bool emitIndexDataIfNeeded(SourceFile *PrimarySourceFile,
const CompilerInvocation &Invocation,
CompilerInstance &Instance);
static void countStatsOfSourceFile(UnifiedStatsReporter &Stats,
CompilerInstance &Instance,
SourceFile *SF) {
auto &C = Stats.getFrontendCounters();
auto &SM = Instance.getSourceMgr();
C.NumDecls += SF->Decls.size();
C.NumLocalTypeDecls += SF->LocalTypeDecls.size();
C.NumObjCMethods += SF->ObjCMethods.size();
C.NumInfixOperators += SF->InfixOperators.size();
C.NumPostfixOperators += SF->PostfixOperators.size();
C.NumPrefixOperators += SF->PrefixOperators.size();
C.NumPrecedenceGroups += SF->PrecedenceGroups.size();
C.NumUsedConformances += SF->getUsedConformances().size();
auto bufID = SF->getBufferID();
if (bufID.hasValue()) {
C.NumSourceLines +=
SM.getEntireTextForBuffer(bufID.getValue()).count('\n');
}
}
static void countStatsPostSema(UnifiedStatsReporter &Stats,
CompilerInstance& Instance) {
auto &C = Stats.getFrontendCounters();
auto &SM = Instance.getSourceMgr();
C.NumSourceBuffers = SM.getLLVMSourceMgr().getNumBuffers();
C.NumLinkLibraries = Instance.getLinkLibraries().size();
auto const &AST = Instance.getASTContext();
C.NumLoadedModules = AST.LoadedModules.size();
C.NumImportedExternalDefinitions = AST.ExternalDefinitions.size();
C.NumASTBytesAllocated = AST.getAllocator().getBytesAllocated();
if (auto *D = Instance.getDependencyTracker()) {
C.NumDependencies = D->getDependencies().size();
}
for (auto SF : Instance.getPrimarySourceFiles()) {
if (auto *R = SF->getReferencedNameTracker()) {
C.NumReferencedTopLevelNames += R->getTopLevelNames().size();
C.NumReferencedDynamicNames += R->getDynamicLookupNames().size();
C.NumReferencedMemberNames += R->getUsedMembers().size();
}
}
if (!Instance.getPrimarySourceFiles().empty()) {
for (auto SF : Instance.getPrimarySourceFiles())
countStatsOfSourceFile(Stats, Instance, SF);
} else if (auto *M = Instance.getMainModule()) {
// No primary source file, but a main module; this is WMO-mode
for (auto *F : M->getFiles()) {
if (auto *SF = dyn_cast<SourceFile>(F)) {
countStatsOfSourceFile(Stats, Instance, SF);
}
}
}
}
static void countStatsPostSILGen(UnifiedStatsReporter &Stats,
const SILModule& Module) {
auto &C = Stats.getFrontendCounters();
// FIXME: calculate these in constant time, via the dense maps.
C.NumSILGenFunctions = Module.getFunctionList().size();
C.NumSILGenVtables = Module.getVTableList().size();
C.NumSILGenWitnessTables = Module.getWitnessTableList().size();
C.NumSILGenDefaultWitnessTables = Module.getDefaultWitnessTableList().size();
C.NumSILGenGlobalVariables = Module.getSILGlobalList().size();
}
static void countStatsPostSILOpt(UnifiedStatsReporter &Stats,
const SILModule& Module) {
auto &C = Stats.getFrontendCounters();
// FIXME: calculate these in constant time, via the dense maps.
C.NumSILOptFunctions = Module.getFunctionList().size();
C.NumSILOptVtables = Module.getVTableList().size();
C.NumSILOptWitnessTables = Module.getWitnessTableList().size();
C.NumSILOptDefaultWitnessTables = Module.getDefaultWitnessTableList().size();
C.NumSILOptGlobalVariables = Module.getSILGlobalList().size();
}
static std::unique_ptr<llvm::raw_fd_ostream>
createOptRecordFile(StringRef Filename, DiagnosticEngine &DE) {
if (Filename.empty())
return nullptr;
std::error_code EC;
auto File = llvm::make_unique<llvm::raw_fd_ostream>(Filename, EC,
llvm::sys::fs::F_None);
if (EC) {
DE.diagnose(SourceLoc(), diag::cannot_open_file, Filename, EC.message());
return nullptr;
}
return File;
}
struct PostSILGenInputs {
std::unique_ptr<SILModule> TheSILModule;
bool ASTGuaranteedToCorrespondToSIL;
ModuleOrSourceFile ModuleOrPrimarySourceFile;
PrimarySpecificPaths PSPs;
};
static bool precompileBridgingHeader(CompilerInvocation &Invocation,
CompilerInstance &Instance) {
auto clangImporter = static_cast<ClangImporter *>(
Instance.getASTContext().getClangModuleLoader());
auto &ImporterOpts = Invocation.getClangImporterOptions();
auto &PCHOutDir = ImporterOpts.PrecompiledHeaderOutputDir;
if (!PCHOutDir.empty()) {
ImporterOpts.BridgingHeader =
Invocation.getFrontendOptions()
.InputsAndOutputs.getFilenameOfFirstInput();
// Create or validate a persistent PCH.
auto SwiftPCHHash = Invocation.getPCHHash();
auto PCH = clangImporter->getOrCreatePCH(ImporterOpts, SwiftPCHHash);
return !PCH.hasValue();
}
return clangImporter->emitBridgingPCH(
Invocation.getFrontendOptions()
.InputsAndOutputs.getFilenameOfFirstInput(),
Invocation.getFrontendOptions()
.InputsAndOutputs.getSingleOutputFilename());
}
static bool compileLLVMIR(CompilerInvocation &Invocation,
CompilerInstance &Instance,
UnifiedStatsReporter *Stats) {
auto &LLVMContext = getGlobalLLVMContext();
// Load in bitcode file.
assert(Invocation.getFrontendOptions().InputsAndOutputs.hasSingleInput() &&
"We expect a single input for bitcode input!");
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> FileBufOrErr =
llvm::MemoryBuffer::getFileOrSTDIN(
Invocation.getFrontendOptions()
.InputsAndOutputs.getFilenameOfFirstInput());
if (!FileBufOrErr) {
Instance.getASTContext().Diags.diagnose(
SourceLoc(), diag::error_open_input_file,
Invocation.getFrontendOptions()
.InputsAndOutputs.getFilenameOfFirstInput(),
FileBufOrErr.getError().message());
return true;
}
llvm::MemoryBuffer *MainFile = FileBufOrErr.get().get();
llvm::SMDiagnostic Err;
std::unique_ptr<llvm::Module> Module =
llvm::parseIR(MainFile->getMemBufferRef(), Err, LLVMContext);
if (!Module) {
// TODO: Translate from the diagnostic info to the SourceManager location
// if available.
Instance.getASTContext().Diags.diagnose(
SourceLoc(), diag::error_parse_input_file,
Invocation.getFrontendOptions()
.InputsAndOutputs.getFilenameOfFirstInput(),
Err.getMessage());
return true;
}
IRGenOptions &IRGenOpts = Invocation.getIRGenOptions();
// TODO: remove once the frontend understands what action it should perform
IRGenOpts.OutputKind =
getOutputKind(Invocation.getFrontendOptions().RequestedAction);
return performLLVM(IRGenOpts, Instance.getASTContext(), Module.get(),
Invocation.getFrontendOptions()
.InputsAndOutputs.getSingleOutputFilename(),
Stats);
}
static void verifyGenericSignaturesIfNeeded(CompilerInvocation &Invocation,
ASTContext &Context) {
auto verifyGenericSignaturesInModule =
Invocation.getFrontendOptions().VerifyGenericSignaturesInModule;
if (verifyGenericSignaturesInModule.empty())
return;
if (auto module = Context.getModuleByName(verifyGenericSignaturesInModule))
GenericSignatureBuilder::verifyGenericSignaturesInModule(module);
}
static void dumpOneScopeMapLocation(unsigned bufferID,
std::pair<unsigned, unsigned> lineColumn,
SourceManager &sourceMgr, ASTScope &scope) {
SourceLoc loc =
sourceMgr.getLocForLineCol(bufferID, lineColumn.first, lineColumn.second);
if (loc.isInvalid())
return;
llvm::errs() << "***Scope at " << lineColumn.first << ":" << lineColumn.second
<< "***\n";
auto locScope = scope.findInnermostEnclosingScope(loc);
locScope->print(llvm::errs(), 0, false, false);
// Dump the AST context, too.
if (auto dc = locScope->getDeclContext()) {
dc->printContext(llvm::errs());
}
// Grab the local bindings introduced by this scope.
auto localBindings = locScope->getLocalBindings();
if (!localBindings.empty()) {
llvm::errs() << "Local bindings: ";
interleave(localBindings.begin(), localBindings.end(),
[&](ValueDecl *value) { llvm::errs() << value->getFullName(); },
[&]() { llvm::errs() << " "; });
llvm::errs() << "\n";
}
}
static void dumpAndPrintScopeMap(CompilerInvocation &Invocation,
CompilerInstance &Instance, SourceFile *SF) {
ASTScope &scope = SF->getScope();
if (Invocation.getFrontendOptions().DumpScopeMapLocations.empty()) {
scope.expandAll();
} else if (auto bufferID = SF->getBufferID()) {
SourceManager &sourceMgr = Instance.getSourceMgr();
// Probe each of the locations, and dump what we find.
for (auto lineColumn :
Invocation.getFrontendOptions().DumpScopeMapLocations)
dumpOneScopeMapLocation(*bufferID, lineColumn, sourceMgr, scope);
llvm::errs() << "***Complete scope map***\n";
}
// Print the resulting map.
scope.print(llvm::errs());
}
static SourceFile *getPrimaryOrMainSourceFile(CompilerInvocation &Invocation,
CompilerInstance &Instance) {
SourceFile *SF = Instance.getPrimarySourceFile();
if (!SF) {
SourceFileKind Kind = Invocation.getSourceFileKind();
SF = &Instance.getMainModule()->getMainSourceFile(Kind);
}
return SF;
}
/// We may have been told to dump the AST (either after parsing or
/// type-checking, which is already differentiated in
/// CompilerInstance::performSema()), so dump or print the main source file and
/// return.
static Optional<bool> dumpASTIfNeeded(CompilerInvocation &Invocation,
CompilerInstance &Instance) {
FrontendOptions &opts = Invocation.getFrontendOptions();
FrontendOptions::ActionType Action = opts.RequestedAction;
ASTContext &Context = Instance.getASTContext();
switch (Action) {
default:
return None;
case FrontendOptions::ActionType::PrintAST:
getPrimaryOrMainSourceFile(Invocation, Instance)
->print(llvm::outs(), PrintOptions::printEverything());
break;
case FrontendOptions::ActionType::DumpScopeMaps:
dumpAndPrintScopeMap(Invocation, Instance,
getPrimaryOrMainSourceFile(Invocation, Instance));
break;
case FrontendOptions::ActionType::DumpTypeRefinementContexts:
getPrimaryOrMainSourceFile(Invocation, Instance)
->getTypeRefinementContext()
->dump(llvm::errs(), Context.SourceMgr);
break;
case FrontendOptions::ActionType::DumpInterfaceHash:
getPrimaryOrMainSourceFile(Invocation, Instance)
->dumpInterfaceHash(llvm::errs());
break;
case FrontendOptions::ActionType::EmitSyntax:
emitSyntax(getPrimaryOrMainSourceFile(Invocation, Instance),
Invocation.getLangOptions(), Instance.getSourceMgr(),
opts.InputsAndOutputs.getSingleOutputFilename());
break;
case FrontendOptions::ActionType::DumpParse:
case FrontendOptions::ActionType::DumpAST:
getPrimaryOrMainSourceFile(Invocation, Instance)->dump();
break;
case FrontendOptions::ActionType::EmitImportedModules:
emitImportedModules(Context, Instance.getMainModule(), opts);
break;
}
return Context.hadError();
}
static void emitReferenceDependenciesForAllPrimaryInputsIfNeeded(
CompilerInvocation &Invocation, CompilerInstance &Instance) {
if (Invocation.getFrontendOptions()
.InputsAndOutputs.supplementaryOutputs()
.ReferenceDependenciesFilePath.empty())
return;
if (Instance.getPrimarySourceFiles().empty()) {
Instance.getASTContext().Diags.diagnose(
SourceLoc(), diag::emit_reference_dependencies_without_primary_file);
return;
}
for (auto *SF : Instance.getPrimarySourceFiles()) {
std::string referenceDependenciesFilePath =
Invocation.getPrimarySpecificPathsForSourceFile(*SF)
.SupplementaryOutputs.ReferenceDependenciesFilePath;
emitReferenceDependenciesIfNeeded(Instance.getASTContext().Diags, SF,
*Instance.getDependencyTracker(),
referenceDependenciesFilePath);
}
}
static bool writeTBDIfNeeded(CompilerInvocation &Invocation,
CompilerInstance &Instance) {
StringRef TBDPath = Invocation.getFrontendOptions()
.InputsAndOutputs.supplementaryOutputs()
.TBDPath;
if (TBDPath.empty())
return false;
auto installName = Invocation.getFrontendOptions().TBDInstallName.empty()
? "lib" + Invocation.getModuleName().str() + ".dylib"
: Invocation.getFrontendOptions().TBDInstallName;
return writeTBD(Instance.getMainModule(),
Invocation.getSILOptions().hasMultipleIGMs(), TBDPath,
installName);
}
static std::deque<PostSILGenInputs>
generateSILModules(CompilerInvocation &Invocation, CompilerInstance &Instance) {
auto mod = Instance.getMainModule();
if (auto SM = Instance.takeSILModule()) {
std::deque<PostSILGenInputs> PSGIs;
const PrimarySpecificPaths PSPs =
Instance.getPrimarySpecificPathsForAtMostOnePrimary();
PSGIs.push_back(PostSILGenInputs{std::move(SM), false, mod, PSPs});
return PSGIs;
}
SILOptions &SILOpts = Invocation.getSILOptions();
FrontendOptions &opts = Invocation.getFrontendOptions();
auto fileIsSIB = [](const FileUnit *File) -> bool {
auto SASTF = dyn_cast<SerializedASTFile>(File);
return SASTF && SASTF->isSIB();
};
if (!opts.InputsAndOutputs.hasPrimaryInputs()) {
// If there are no primary inputs the compiler is in WMO mode and builds one
// SILModule for the entire module.
auto SM = performSILGeneration(mod, SILOpts, true);
std::deque<PostSILGenInputs> PSGIs;
const PrimarySpecificPaths PSPs =
Instance.getPrimarySpecificPathsForWholeModuleOptimizationMode();
PSGIs.push_back(PostSILGenInputs{
std::move(SM), llvm::none_of(mod->getFiles(), fileIsSIB), mod, PSPs});
return PSGIs;
}
// If there are primary source files, build a separate SILModule for
// each source file, and run the remaining SILOpt-Serialize-IRGen-LLVM
// once for each such input.
if (auto *PrimaryFile = Instance.getPrimarySourceFile()) {
auto SM = performSILGeneration(*PrimaryFile, SILOpts, None);
std::deque<PostSILGenInputs> PSGIs;
const PrimarySpecificPaths PSPs =
Instance.getPrimarySpecificPathsForSourceFile(*PrimaryFile);
PSGIs.push_back(PostSILGenInputs{std::move(SM), true, PrimaryFile, PSPs});
return PSGIs;
}
// If there are primary inputs but no primary _source files_, there might be
// a primary serialized input.
std::deque<PostSILGenInputs> PSGIs;
for (FileUnit *fileUnit : mod->getFiles()) {
if (auto SASTF = dyn_cast<SerializedASTFile>(fileUnit))
if (Invocation.getFrontendOptions().InputsAndOutputs.isInputPrimary(
SASTF->getFilename())) {
assert(PSGIs.empty() && "Can only handle one primary AST input");
auto SM = performSILGeneration(*SASTF, SILOpts, None);
const PrimarySpecificPaths PSPs =
Instance.getPrimarySpecificPathsForPrimary(SASTF->getFilename());
PSGIs.push_back(
PostSILGenInputs{std::move(SM), !fileIsSIB(SASTF), mod, PSPs});
}
}
return PSGIs;
}
static bool performCompileStepsPostSILGen(
CompilerInstance &Instance, CompilerInvocation &Invocation,
std::unique_ptr<SILModule> SM, bool astGuaranteedToCorrespondToSIL,
ModuleOrSourceFile MSF, const PrimarySpecificPaths &PSPs,
bool moduleIsPublic, int &ReturnValue, FrontendObserver *observer,
UnifiedStatsReporter *Stats);
/// Performs the compile requested by the user.
/// \param Instance Will be reset after performIRGeneration when the verifier
/// mode is NoVerify and there were no errors.
/// \returns true on error
static bool performCompile(CompilerInstance &Instance,
CompilerInvocation &Invocation,
ArrayRef<const char *> Args,
int &ReturnValue,
FrontendObserver *observer,
UnifiedStatsReporter *Stats) {
FrontendOptions opts = Invocation.getFrontendOptions();
FrontendOptions::ActionType Action = opts.RequestedAction;
if (Action == FrontendOptions::ActionType::EmitSyntax) {
Instance.getASTContext().LangOpts.BuildSyntaxTree = true;
Instance.getASTContext().LangOpts.VerifySyntaxTree = true;
}
// We've been asked to precompile a bridging header; we want to
// avoid touching any other inputs and just parse, emit and exit.
if (Action == FrontendOptions::ActionType::EmitPCH)
return precompileBridgingHeader(Invocation, Instance);
if (Invocation.getInputKind() == InputFileKind::IFK_LLVM_IR)
return compileLLVMIR(Invocation, Instance, Stats);
if (FrontendOptions::shouldActionOnlyParse(Action))
Instance.performParseOnly();
else
Instance.performSema();
if (Action == FrontendOptions::ActionType::Parse)
return Instance.getASTContext().hadError();
if (observer)
observer->performedSemanticAnalysis(Instance);
if (Stats)
countStatsPostSema(*Stats, Instance);
{
FrontendOptions::DebugCrashMode CrashMode = opts.CrashMode;
if (CrashMode == FrontendOptions::DebugCrashMode::AssertAfterParse)
debugFailWithAssertion();
else if (CrashMode == FrontendOptions::DebugCrashMode::CrashAfterParse)
debugFailWithCrash();
}
ASTContext &Context = Instance.getASTContext();
verifyGenericSignaturesIfNeeded(Invocation, Context);
(void)migrator::updateCodeAndEmitRemapIfNeeded(&Instance, Invocation);
if (Action == FrontendOptions::ActionType::REPL) {
runREPL(Instance, ProcessCmdLine(Args.begin(), Args.end()),
Invocation.getParseStdlib());
return Context.hadError();
}
if (auto r = dumpASTIfNeeded(Invocation, Instance))
return *r;
// If we were asked to print Clang stats, do so.
if (opts.PrintClangStats && Context.getClangModuleLoader())
Context.getClangModuleLoader()->printStatistics();
if (!opts.InputsAndOutputs.supplementaryOutputs()
.DependenciesFilePath.empty())
(void)emitMakeDependencies(Context.Diags, *Instance.getDependencyTracker(),
opts);
emitReferenceDependenciesForAllPrimaryInputsIfNeeded(Invocation, Instance);
(void)emitLoadedModuleTraceIfNeeded(Context, Instance.getDependencyTracker(),
opts);
if (Context.hadError()) {
// Emit the index store data even if there were compiler errors.
(void)emitIndexDataIfNeeded(Instance.getPrimarySourceFile(), Invocation,
Instance);
return true;
}
// FIXME: This is still a lousy approximation of whether the module file will
// be externally consumed.
bool moduleIsPublic =
!Instance.getMainModule()->hasEntryPoint() &&
opts.ImplicitObjCHeaderPath.empty() &&
!Context.LangOpts.EnableAppExtensionRestrictions;
// We've just been told to perform a typecheck, so we can return now.
if (Action == FrontendOptions::ActionType::Typecheck) {
const bool hadPrintAsObjCError = printAsObjCIfNeeded(
opts.InputsAndOutputs.supplementaryOutputs().ObjCHeaderOutputPath,
Instance.getMainModule(), opts.ImplicitObjCHeaderPath, moduleIsPublic);
const bool hadEmitIndexDataError = emitIndexDataIfNeeded(
Instance.getPrimarySourceFile(), Invocation, Instance);
return hadPrintAsObjCError || hadEmitIndexDataError || Context.hadError();
}
if (writeTBDIfNeeded(Invocation, Instance))
return true;
assert(Action >= FrontendOptions::ActionType::EmitSILGen &&
"All actions not requiring SILGen must have been handled!");
std::deque<PostSILGenInputs> PSGIs = generateSILModules(Invocation, Instance);
while (!PSGIs.empty()) {
auto PSGI = std::move(PSGIs.front());
PSGIs.pop_front();
if (performCompileStepsPostSILGen(Instance, Invocation,
std::move(PSGI.TheSILModule),
PSGI.ASTGuaranteedToCorrespondToSIL,
PSGI.ModuleOrPrimarySourceFile,
PSGI.PSPs,
moduleIsPublic,
ReturnValue, observer, Stats))
return true;
}
return false;
}
/// If we are asked to link all, link all.
static void linkAllIfNeeded(const CompilerInvocation &Invocation,
SILModule *SM) {
if (Invocation.getSILOptions().LinkMode == SILOptions::LinkAll)
performSILLinking(SM, true);
}
/// Perform "stable" optimizations that are invariant across compiler versions.
static bool performMandatorySILPasses(CompilerInvocation &Invocation,
SILModule *SM,
FrontendObserver *observer) {
if (Invocation.getFrontendOptions().RequestedAction ==
FrontendOptions::ActionType::MergeModules) {
// Don't run diagnostic passes at all.
} else if (!Invocation.getDiagnosticOptions().SkipDiagnosticPasses) {
if (runSILDiagnosticPasses(*SM))
return true;
if (observer) {
observer->performedSILDiagnostics(*SM);
}
} else {
// Even if we are not supposed to run the diagnostic passes, we still need
// to run the ownership evaluator.
if (runSILOwnershipEliminatorPass(*SM))
return true;
}
linkAllIfNeeded(Invocation, SM);
if (Invocation.getSILOptions().MergePartialModules)
SM->linkAllFromCurrentModule();
return false;
}
static SerializationOptions
computeSerializationOptions(const CompilerInvocation &Invocation,
const SupplementaryOutputPaths &outs,
bool moduleIsPublic) {
const FrontendOptions &opts = Invocation.getFrontendOptions();
SerializationOptions serializationOpts;
serializationOpts.OutputPath = outs.ModuleOutputPath.c_str();
serializationOpts.DocOutputPath = outs.ModuleDocOutputPath.c_str();
serializationOpts.GroupInfoPath = opts.GroupInfoPath.c_str();
if (opts.SerializeBridgingHeader)
serializationOpts.ImportedHeader = opts.ImplicitObjCHeaderPath;
serializationOpts.ModuleLinkName = opts.ModuleLinkName;
serializationOpts.ExtraClangOptions =
Invocation.getClangImporterOptions().ExtraArgs;
serializationOpts.EnableNestedTypeLookupTable =
opts.EnableSerializationNestedTypeLookupTable;
if (!Invocation.getIRGenOptions().ForceLoadSymbolName.empty())
serializationOpts.AutolinkForceLoad = true;
// Options contain information about the developer's computer,
// so only serialize them if the module isn't going to be shipped to
// the public.
serializationOpts.SerializeOptionsForDebugging =
!moduleIsPublic || opts.AlwaysSerializeDebuggingOptions;
return serializationOpts;
}
/// Perform SIL optimization passes if optimizations haven't been disabled.
/// These may change across compiler versions.
static void performSILOptimizations(CompilerInvocation &Invocation,
SILModule *SM) {
SharedTimer timer("SIL optimization");
if (Invocation.getFrontendOptions().RequestedAction ==
FrontendOptions::ActionType::MergeModules ||
!Invocation.getSILOptions().shouldOptimize()) {
runSILPassesForOnone(*SM);
return;
}
runSILOptPreparePasses(*SM);
StringRef CustomPipelinePath =
Invocation.getSILOptions().ExternalPassPipelineFilename;
if (!CustomPipelinePath.empty()) {
runSILOptimizationPassesWithFileSpecification(*SM, CustomPipelinePath);
} else {
runSILOptimizationPasses(*SM);
}
}
/// Get the main source file's private discriminator and attach it to
/// the compile unit's flags.
static void setPrivateDiscriminatorIfNeeded(IRGenOptions &IRGenOpts,
ModuleOrSourceFile MSF) {
if (IRGenOpts.DebugInfoKind == IRGenDebugInfoKind::None ||
!MSF.is<SourceFile *>())
return;
Identifier PD = MSF.get<SourceFile *>()->getPrivateDiscriminator();
if (!PD.empty())
IRGenOpts.DWARFDebugFlags += (" -private-discriminator " + PD.str()).str();
}
static bool serializeSIB(SILModule *SM, const PrimarySpecificPaths &PSPs,
ASTContext &Context, ModuleOrSourceFile MSF) {
const std::string &moduleOutputPath =
PSPs.SupplementaryOutputs.ModuleOutputPath;
assert(!moduleOutputPath.empty() && "must have an output path");
SerializationOptions serializationOpts;
serializationOpts.OutputPath = moduleOutputPath.c_str();
serializationOpts.SerializeAllSIL = true;
serializationOpts.IsSIB = true;
serialize(MSF, serializationOpts, SM);
return Context.hadError();
}
static void generateIR(IRGenOptions &IRGenOpts, std::unique_ptr<SILModule> SM,
const PrimarySpecificPaths &PSPs,
StringRef OutputFilename, ModuleOrSourceFile MSF,
std::unique_ptr<llvm::Module> &IRModule,
llvm::GlobalVariable *&HashGlobal,
ArrayRef<std::string> parallelOutputFilenames) {
// FIXME: We shouldn't need to use the global context here, but
// something is persisting across calls to performIRGeneration.
auto &LLVMContext = getGlobalLLVMContext();
IRModule = MSF.is<SourceFile *>()
? performIRGeneration(IRGenOpts, *MSF.get<SourceFile *>(),
std::move(SM), OutputFilename, PSPs,
LLVMContext, 0, &HashGlobal)
: performIRGeneration(IRGenOpts, MSF.get<ModuleDecl *>(),
std::move(SM), OutputFilename, PSPs,
LLVMContext, parallelOutputFilenames,
&HashGlobal);
}
static bool processCommandLineAndRunImmediately(CompilerInvocation &Invocation,
CompilerInstance &Instance,
std::unique_ptr<SILModule> SM,
ModuleOrSourceFile MSF,
FrontendObserver *observer,
int &ReturnValue) {
FrontendOptions &opts = Invocation.getFrontendOptions();
assert(!MSF.is<SourceFile *>() && "-i doesn't work in -primary-file mode");
IRGenOptions &IRGenOpts = Invocation.getIRGenOptions();
IRGenOpts.UseJIT = true;
IRGenOpts.DebugInfoKind = IRGenDebugInfoKind::Normal;
const ProcessCmdLine &CmdLine =
ProcessCmdLine(opts.ImmediateArgv.begin(), opts.ImmediateArgv.end());
Instance.setSILModule(std::move(SM));
if (observer)
observer->aboutToRunImmediately(Instance);
ReturnValue =
RunImmediately(Instance, CmdLine, IRGenOpts, Invocation.getSILOptions());
return Instance.getASTContext().hadError();
}
static bool validateTBDIfNeeded(CompilerInvocation &Invocation,
ModuleOrSourceFile MSF,
bool astGuaranteedToCorrespondToSIL,
llvm::Module &IRModule) {
if (!astGuaranteedToCorrespondToSIL ||
!inputFileKindCanHaveTBDValidated(Invocation.getInputKind()))
return false;
const auto mode = Invocation.getFrontendOptions().ValidateTBDAgainstIR;
// Ensure all cases are covered by using a switch here.
switch (mode) {
case FrontendOptions::TBDValidationMode::None:
return false;
case FrontendOptions::TBDValidationMode::All:
case FrontendOptions::TBDValidationMode::MissingFromTBD:
break;
}
const auto hasMultipleIGMs = Invocation.getSILOptions().hasMultipleIGMs();
const bool allSymbols = mode == FrontendOptions::TBDValidationMode::All;
return MSF.is<SourceFile *>() ? validateTBD(MSF.get<SourceFile *>(), IRModule,
hasMultipleIGMs, allSymbols)
: validateTBD(MSF.get<ModuleDecl *>(), IRModule,
hasMultipleIGMs, allSymbols);
}
static bool generateCode(CompilerInvocation &Invocation,
CompilerInstance &Instance, std::string OutputFilename,
llvm::Module *IRModule,
llvm::GlobalVariable *HashGlobal,
UnifiedStatsReporter *Stats) {
std::unique_ptr<llvm::TargetMachine> TargetMachine = createTargetMachine(
Invocation.getIRGenOptions(), Instance.getASTContext());
version::Version EffectiveLanguageVersion =
Instance.getASTContext().LangOpts.EffectiveLanguageVersion;
if (!Stats) {
// Free up some compiler resources now that we have an IRModule.
Instance.freeSILModule();
// If there are multiple primary inputs it is too soon to free
// the ASTContext, etc.. OTOH, if this compilation generates code for > 1
// primary input, then freeing it after processing the last primary is
// unlikely to reduce the peak heap size. So, only optimize the
// single-primary-case (or WMO).
if (!Invocation.getFrontendOptions()
.InputsAndOutputs.hasMultiplePrimaryInputs())
Instance.freeASTContext();
}
// Now that we have a single IR Module, hand it over to performLLVM.
return performLLVM(Invocation.getIRGenOptions(), &Instance.getDiags(),
nullptr, HashGlobal, IRModule, TargetMachine.get(),
EffectiveLanguageVersion, OutputFilename, Stats);
}
static bool performCompileStepsPostSILGen(
CompilerInstance &Instance, CompilerInvocation &Invocation,
std::unique_ptr<SILModule> SM, bool astGuaranteedToCorrespondToSIL,
ModuleOrSourceFile MSF, const PrimarySpecificPaths &PSPs,
bool moduleIsPublic, int &ReturnValue, FrontendObserver *observer,
UnifiedStatsReporter *Stats) {
FrontendOptions opts = Invocation.getFrontendOptions();
FrontendOptions::ActionType Action = opts.RequestedAction;
ASTContext &Context = Instance.getASTContext();
SILOptions &SILOpts = Invocation.getSILOptions();
IRGenOptions &IRGenOpts = Invocation.getIRGenOptions();
if (observer)
observer->performedSILGeneration(*SM);
if (Stats)
countStatsPostSILGen(*Stats, *SM);
// We've been told to emit SIL after SILGen, so write it now.
if (Action == FrontendOptions::ActionType::EmitSILGen) {
linkAllIfNeeded(Invocation, SM.get());
return writeSIL(*SM, PSPs, Instance, Invocation);
}
if (Action == FrontendOptions::ActionType::EmitSIBGen) {
linkAllIfNeeded(Invocation, SM.get());
serializeSIB(SM.get(), PSPs, Instance.getASTContext(), MSF);
return Context.hadError();
}
std::unique_ptr<llvm::raw_fd_ostream> OptRecordFile =
createOptRecordFile(SILOpts.OptRecordFile, Instance.getDiags());
if (OptRecordFile)
SM->setOptRecordStream(llvm::make_unique<llvm::yaml::Output>(
*OptRecordFile, &Instance.getSourceMgr()),
std::move(OptRecordFile));
if (performMandatorySILPasses(Invocation, SM.get(), observer))
return true;
{
SharedTimer timer("SIL verification, pre-optimization");
SM->verify();
}
// This is the action to be used to serialize SILModule.
// It may be invoked multiple times, but it will perform
// serialization only once. The serialization may either happen
// after high-level optimizations or after all optimizations are
// done, depending on the compiler setting.
auto SerializeSILModuleAction = [&]() {
const SupplementaryOutputPaths &outs = PSPs.SupplementaryOutputs;
if (outs.ModuleOutputPath.empty())
return;
SerializationOptions serializationOpts =
computeSerializationOptions(Invocation, outs, moduleIsPublic);
serialize(MSF, serializationOpts, SM.get());
};
// Set the serialization action, so that the SIL module
// can be serialized at any moment, e.g. during the optimization pipeline.
SM->setSerializeSILAction(SerializeSILModuleAction);
performSILOptimizations(Invocation, SM.get());
if (observer)
observer->performedSILOptimization(*SM);
if (Stats)
countStatsPostSILOpt(*Stats, *SM);
{
SharedTimer timer("SIL verification, post-optimization");
SM->verify();
}
performSILInstCountIfNeeded(&*SM);
setPrivateDiscriminatorIfNeeded(IRGenOpts, MSF);
(void)printAsObjCIfNeeded(PSPs.SupplementaryOutputs.ObjCHeaderOutputPath,
Instance.getMainModule(),
opts.ImplicitObjCHeaderPath, moduleIsPublic);
if (Action == FrontendOptions::ActionType::EmitSIB)
return serializeSIB(SM.get(), PSPs, Instance.getASTContext(), MSF);
const bool haveModulePath =
!PSPs.SupplementaryOutputs.ModuleOutputPath.empty() ||
!PSPs.SupplementaryOutputs.ModuleDocOutputPath.empty();
if (haveModulePath && !SM->isSerialized())
SM->serialize();
if (haveModulePath) {
if (Action == FrontendOptions::ActionType::MergeModules ||
Action == FrontendOptions::ActionType::EmitModuleOnly) {
// What if MSF is a module?
// emitIndexDataIfNeeded already handles that case;
// it'll index everything.
return emitIndexDataIfNeeded(MSF.dyn_cast<SourceFile *>(), Invocation,
Instance) ||
Context.hadError();
}
}
assert(Action >= FrontendOptions::ActionType::EmitSIL &&
"All actions not requiring SILPasses must have been handled!");
// We've been told to write canonical SIL, so write it now.
if (Action == FrontendOptions::ActionType::EmitSIL)
return writeSIL(*SM, PSPs, Instance, Invocation);
assert(Action >= FrontendOptions::ActionType::Immediate &&
"All actions not requiring IRGen must have been handled!");
assert(Action != FrontendOptions::ActionType::REPL &&
"REPL mode must be handled immediately after Instance->performSema()");
// Check if we had any errors; if we did, don't proceed to IRGen.
if (Context.hadError())
return true;
runSILLoweringPasses(*SM);
// TODO: remove once the frontend understands what action it should perform
IRGenOpts.OutputKind = getOutputKind(Action);
if (Action == FrontendOptions::ActionType::Immediate)
return processCommandLineAndRunImmediately(
Invocation, Instance, std::move(SM), MSF, observer, ReturnValue);
StringRef OutputFilename = PSPs.OutputFilename;
std::vector<std::string> ParallelOutputFilenames = Invocation.getFrontendOptions().InputsAndOutputs.copyOutputFilenames();
std::unique_ptr<llvm::Module> IRModule;
llvm::GlobalVariable *HashGlobal;
generateIR(
IRGenOpts, std::move(SM), PSPs, OutputFilename, MSF, IRModule, HashGlobal,
ParallelOutputFilenames);
// Walk the AST for indexing after IR generation. Walking it before seems
// to cause miscompilation issues.
if (emitIndexDataIfNeeded(MSF.dyn_cast<SourceFile *>(), Invocation, Instance))
return true;
// Just because we had an AST error it doesn't mean we can't performLLVM.
bool HadError = Instance.getASTContext().hadError();
// If the AST Context has no errors but no IRModule is available,
// parallelIRGen happened correctly, since parallel IRGen produces multiple
// modules.
if (!IRModule)
return HadError;
if (validateTBDIfNeeded(Invocation, MSF, astGuaranteedToCorrespondToSIL,
*IRModule))
return true;
return generateCode(Invocation, Instance, OutputFilename, IRModule.get(),
HashGlobal, Stats) ||
HadError;
}
static bool emitIndexDataIfNeeded(SourceFile *PrimarySourceFile,
const CompilerInvocation &Invocation,
CompilerInstance &Instance) {
const FrontendOptions &opts = Invocation.getFrontendOptions();
if (opts.IndexStorePath.empty())
return false;
// FIXME: provide index unit token(s) explicitly and only use output file
// paths as a fallback.
bool isDebugCompilation;
switch (Invocation.getSILOptions().OptMode) {
case OptimizationMode::NotSet:
case OptimizationMode::NoOptimization:
isDebugCompilation = true;
break;
case OptimizationMode::ForSpeed:
case OptimizationMode::ForSize:
isDebugCompilation = false;
break;
}
if (PrimarySourceFile) {
if (index::indexAndRecord(
PrimarySourceFile, opts.InputsAndOutputs.getSingleOutputFilename(),
opts.IndexStorePath, opts.IndexSystemModules, isDebugCompilation,
Invocation.getTargetTriple(), *Instance.getDependencyTracker())) {
return true;
}
} else {
StringRef moduleToken =
opts.InputsAndOutputs.supplementaryOutputs().ModuleOutputPath;
if (moduleToken.empty())
moduleToken = opts.InputsAndOutputs.getSingleOutputFilename();
if (index::indexAndRecord(Instance.getMainModule(), opts.InputsAndOutputs.copyOutputFilenames(),
moduleToken, opts.IndexStorePath,
opts.IndexSystemModules,
isDebugCompilation, Invocation.getTargetTriple(),
*Instance.getDependencyTracker())) {
return true;
}
}
return false;
}
/// Returns true if an error occurred.
static bool dumpAPI(ModuleDecl *Mod, StringRef OutDir) {
using namespace llvm::sys;
auto getOutPath = [&](SourceFile *SF) -> std::string {
SmallString<256> Path = OutDir;
StringRef Filename = SF->getFilename();
path::append(Path, path::filename(Filename));
return Path.str();
};
std::unordered_set<std::string> Filenames;
auto dumpFile = [&](SourceFile *SF) -> bool {
SmallString<512> TempBuf;
llvm::raw_svector_ostream TempOS(TempBuf);
PrintOptions PO = PrintOptions::printInterface();
PO.PrintOriginalSourceText = true;
PO.Indent = 2;
PO.PrintAccess = false;
PO.SkipUnderscoredStdlibProtocols = true;
SF->print(TempOS, PO);
if (TempOS.str().trim().empty())
return false; // nothing to show.
std::string OutPath = getOutPath(SF);
bool WasInserted = Filenames.insert(OutPath).second;
if (!WasInserted) {
llvm::errs() << "multiple source files ended up with the same dump API "
"filename to write to: " << OutPath << '\n';
return true;
}
std::error_code EC;
llvm::raw_fd_ostream OS(OutPath, EC, fs::OpenFlags::F_RW);
if (EC) {
llvm::errs() << "error opening file '" << OutPath << "': "
<< EC.message() << '\n';
return true;
}
OS << TempOS.str();
return false;
};
std::error_code EC = fs::create_directories(OutDir);
if (EC) {
llvm::errs() << "error creating directory '" << OutDir << "': "
<< EC.message() << '\n';
return true;
}
for (auto *FU : Mod->getFiles()) {
if (auto *SF = dyn_cast<SourceFile>(FU))
if (dumpFile(SF))
return true;
}
return false;
}
static StringRef
silOptModeArgStr(OptimizationMode mode) {
switch (mode) {
case OptimizationMode::ForSpeed:
return "O";
case OptimizationMode::ForSize:
return "Osize";
default:
return "Onone";
}
}
static std::unique_ptr<UnifiedStatsReporter>
computeStatsReporter(const CompilerInvocation &Invocation, CompilerInstance *Instance) {
const std::string &StatsOutputDir =
Invocation.getFrontendOptions().StatsOutputDir;
std::unique_ptr<UnifiedStatsReporter> StatsReporter;
if (StatsOutputDir.empty())
return std::unique_ptr<UnifiedStatsReporter>();
auto &FEOpts = Invocation.getFrontendOptions();
auto &LangOpts = Invocation.getLangOptions();
auto &SILOpts = Invocation.getSILOptions();
std::string InputName =
FEOpts.InputsAndOutputs.getStatsFileMangledInputName();
StringRef OptType = silOptModeArgStr(SILOpts.OptMode);
StringRef OutFile =
FEOpts.InputsAndOutputs.lastInputProducingOutput().outputFilename();
StringRef OutputType = llvm::sys::path::extension(OutFile);
std::string TripleName = LangOpts.Target.normalize();
auto Trace = Invocation.getFrontendOptions().TraceStats;
auto ProfileEvents = Invocation.getFrontendOptions().ProfileEvents;
auto ProfileEntities = Invocation.getFrontendOptions().ProfileEntities;
SourceManager *SM = &Instance->getSourceMgr();
clang::SourceManager *CSM = nullptr;
if (auto *clangImporter = static_cast<ClangImporter *>(
Instance->getASTContext().getClangModuleLoader())) {
CSM = &clangImporter->getClangASTContext().getSourceManager();
}
return llvm::make_unique<UnifiedStatsReporter>(
"swift-frontend", FEOpts.ModuleName, InputName, TripleName, OutputType,
OptType, StatsOutputDir, SM, CSM, Trace,
ProfileEvents, ProfileEntities);
}
int swift::performFrontend(ArrayRef<const char *> Args,
const char *Argv0, void *MainAddr,
FrontendObserver *observer) {
llvm::InitializeAllTargets();
llvm::InitializeAllTargetMCs();
llvm::InitializeAllAsmPrinters();
llvm::InitializeAllAsmParsers();
PrintingDiagnosticConsumer PDC;
// Hopefully we won't trigger any LLVM-level fatal errors, but if we do try
// to route them through our usual textual diagnostics before crashing.
//
// Unfortunately it's not really safe to do anything else, since very
// low-level operations in LLVM can trigger fatal errors.
auto diagnoseFatalError = [&PDC](const std::string &reason, bool shouldCrash){
static const std::string *recursiveFatalError = nullptr;
if (recursiveFatalError) {
// Report the /original/ error through LLVM's default handler, not
// whatever we encountered.
llvm::remove_fatal_error_handler();
llvm::report_fatal_error(*recursiveFatalError, shouldCrash);
}
recursiveFatalError = &reason;
SourceManager dummyMgr;
PDC.handleDiagnostic(dummyMgr, SourceLoc(), DiagnosticKind::Error,
"fatal error encountered during compilation; please "
"file a bug report with your project and the crash "
"log", {},
DiagnosticInfo());
PDC.handleDiagnostic(dummyMgr, SourceLoc(), DiagnosticKind::Note, reason,
{}, DiagnosticInfo());
if (shouldCrash)
abort();
};
llvm::ScopedFatalErrorHandler handler([](void *rawCallback,
const std::string &reason,
bool shouldCrash) {
auto *callback = static_cast<decltype(&diagnoseFatalError)>(rawCallback);
(*callback)(reason, shouldCrash);
}, &diagnoseFatalError);
std::unique_ptr<CompilerInstance> Instance =
llvm::make_unique<CompilerInstance>();
Instance->addDiagnosticConsumer(&PDC);
struct FinishDiagProcessingCheckRAII {
bool CalledFinishDiagProcessing = false;
~FinishDiagProcessingCheckRAII() {
assert(CalledFinishDiagProcessing && "returned from the function "
"without calling finishDiagProcessing");
}
} FinishDiagProcessingCheckRAII;
auto finishDiagProcessing = [&](int retValue) -> int {
FinishDiagProcessingCheckRAII.CalledFinishDiagProcessing = true;
bool err = Instance->getDiags().finishProcessing();
return retValue ? retValue : err;
};
if (Args.empty()) {
Instance->getDiags().diagnose(SourceLoc(), diag::error_no_frontend_args);
return finishDiagProcessing(1);
}
CompilerInvocation Invocation;
std::string MainExecutablePath = llvm::sys::fs::getMainExecutable(Argv0,
MainAddr);
Invocation.setMainExecutablePath(MainExecutablePath);
SmallString<128> workingDirectory;
llvm::sys::fs::current_path(workingDirectory);
// Parse arguments.
if (Invocation.parseArgs(Args, Instance->getDiags(), workingDirectory)) {
return finishDiagProcessing(1);
}
// Setting DWARF Version depend on platform
IRGenOptions &IRGenOpts = Invocation.getIRGenOptions();
IRGenOpts.DWARFVersion = swift::DWARFVersion;
// The compiler invocation is now fully configured; notify our observer.
if (observer) {
observer->parsedArgs(Invocation);
}
if (Invocation.getFrontendOptions().PrintHelp ||
Invocation.getFrontendOptions().PrintHelpHidden) {
unsigned IncludedFlagsBitmask = options::FrontendOption;
unsigned ExcludedFlagsBitmask =
Invocation.getFrontendOptions().PrintHelpHidden ? 0 :
llvm::opt::HelpHidden;
std::unique_ptr<llvm::opt::OptTable> Options(createSwiftOptTable());
Options->PrintHelp(llvm::outs(), displayName(MainExecutablePath).c_str(),
"Swift frontend", IncludedFlagsBitmask,
ExcludedFlagsBitmask);
return finishDiagProcessing(0);
}
if (Invocation.getFrontendOptions().RequestedAction ==
FrontendOptions::ActionType::NoneAction) {
Instance->getDiags().diagnose(SourceLoc(),
diag::error_missing_frontend_action);
return finishDiagProcessing(1);
}
// Because the serialized diagnostics consumer is initialized here,
// diagnostics emitted above, within CompilerInvocation::parseArgs, are never
// serialized. This is a non-issue because, in nearly all cases, frontend
// arguments are generated by the driver, not directly by a user. The driver
// is responsible for emitting diagnostics for its own errors. See SR-2683
// for details.
std::unique_ptr<DiagnosticConsumer> SerializedConsumer;
{
const std::string &SerializedDiagnosticsPath =
Invocation.getFrontendOptions()
.InputsAndOutputs.supplementaryOutputs()
.SerializedDiagnosticsPath;
if (!SerializedDiagnosticsPath.empty()) {
SerializedConsumer.reset(
serialized_diagnostics::createConsumer(SerializedDiagnosticsPath));
Instance->addDiagnosticConsumer(SerializedConsumer.get());
}
}
std::unique_ptr<DiagnosticConsumer> FixitsConsumer;
{
const std::string &FixitsOutputPath =
Invocation.getFrontendOptions().FixitsOutputPath;
if (!FixitsOutputPath.empty()) {
FixitsConsumer.reset(new JSONFixitWriter(FixitsOutputPath,
Invocation.getDiagnosticOptions()));
Instance->addDiagnosticConsumer(FixitsConsumer.get());
}
}
if (Invocation.getDiagnosticOptions().UseColor)
PDC.forceColors();
if (Invocation.getFrontendOptions().DebugTimeCompilation)
SharedTimer::enableCompilationTimers();
if (Invocation.getFrontendOptions().PrintStats) {
llvm::EnableStatistics();
}
const DiagnosticOptions &diagOpts = Invocation.getDiagnosticOptions();
if (diagOpts.VerifyMode != DiagnosticOptions::NoVerify) {
enableDiagnosticVerifier(Instance->getSourceMgr());
}
DependencyTracker depTracker;
if (!Invocation.getFrontendOptions()
.InputsAndOutputs.supplementaryOutputs()
.DependenciesFilePath.empty() ||
!Invocation.getFrontendOptions()
.InputsAndOutputs.supplementaryOutputs()
.ReferenceDependenciesFilePath.empty() ||
!Invocation.getFrontendOptions().IndexStorePath.empty() ||
!Invocation.getFrontendOptions()
.InputsAndOutputs.supplementaryOutputs()
.LoadedModuleTracePath.empty()) {
Instance->setDependencyTracker(&depTracker);
}
if (Instance->setup(Invocation)) {
return finishDiagProcessing(1);
}
std::unique_ptr<UnifiedStatsReporter> StatsReporter =
computeStatsReporter(Invocation, Instance.get());
if (StatsReporter) {
// Install stats-reporter somewhere visible for subsystems that
// need to bump counters as they work, rather than measure
// accumulated work on completion (mostly: TypeChecker).
Instance->getASTContext().Stats = StatsReporter.get();
}
// The compiler instance has been configured; notify our observer.
if (observer) {
observer->configuredCompiler(*Instance);
}
int ReturnValue = 0;
bool HadError =
performCompile(*Instance, Invocation, Args, ReturnValue, observer,
StatsReporter.get());
if (!HadError) {
Mangle::printManglingStats();
}
if (!HadError && !Invocation.getFrontendOptions().DumpAPIPath.empty()) {
HadError = dumpAPI(Instance->getMainModule(),
Invocation.getFrontendOptions().DumpAPIPath);
}
if (diagOpts.VerifyMode != DiagnosticOptions::NoVerify) {
HadError = verifyDiagnostics(
Instance->getSourceMgr(),
Instance->getInputBufferIDs(),
diagOpts.VerifyMode == DiagnosticOptions::VerifyAndApplyFixes,
diagOpts.VerifyIgnoreUnknown);
DiagnosticEngine &diags = Instance->getDiags();
if (diags.hasFatalErrorOccurred() &&
!Invocation.getDiagnosticOptions().ShowDiagnosticsAfterFatalError) {
diags.resetHadAnyError();
diags.diagnose(SourceLoc(), diag::verify_encountered_fatal);
HadError = true;
}
}
auto r = finishDiagProcessing(HadError ? 1 : ReturnValue);
if (StatsReporter)
StatsReporter->noteCurrentProcessExitStatus(r);
return r;
}
void FrontendObserver::parsedArgs(CompilerInvocation &invocation) {}
void FrontendObserver::configuredCompiler(CompilerInstance &instance) {}
void FrontendObserver::performedSemanticAnalysis(CompilerInstance &instance) {}
void FrontendObserver::performedSILGeneration(SILModule &module) {}
void FrontendObserver::performedSILDiagnostics(SILModule &module) {}
void FrontendObserver::performedSILOptimization(SILModule &module) {}
void FrontendObserver::aboutToRunImmediately(CompilerInstance &instance) {}
|
Sound6E_MechaSonicBuzz_Header:
smpsHeaderStartSong 2
smpsHeaderVoice Sound6E_MechaSonicBuzz_Voices
smpsHeaderTempoSFX $01
smpsHeaderChanSFX $02
smpsHeaderSFXChannel cFM5, Sound6E_MechaSonicBuzz_FM5, $00, $00
smpsHeaderSFXChannel cPSG3, Sound6E_MechaSonicBuzz_PSG3, $00, $00
; FM5 Data
Sound6E_MechaSonicBuzz_FM5:
smpsSetvoice $00
dc.b nA5, $24, smpsNoAttack
Sound6E_MechaSonicBuzz_Loop00:
dc.b nA5, $04, smpsNoAttack
smpsAlterVol $04
smpsLoop $00, $08, Sound6E_MechaSonicBuzz_Loop00
smpsStop
; PSG3 Data
Sound6E_MechaSonicBuzz_PSG3:
smpsPSGform $E7
dc.b nBb5, $44
smpsStop
Sound6E_MechaSonicBuzz_Voices:
; Voice $00
; $33
; $00, $00, $10, $31, $1F, $1E, $1D, $0E, $00, $1D, $0C, $00
; $00, $01, $00, $00, $0F, $0F, $0F, $0F, $08, $07, $06, $80
smpsVcAlgorithm $03
smpsVcFeedback $06
smpsVcUnusedBits $00
smpsVcDetune $03, $01, $00, $00
smpsVcCoarseFreq $01, $00, $00, $00
smpsVcRateScale $00, $00, $00, $00
smpsVcAttackRate $0E, $1D, $1E, $1F
smpsVcAmpMod $00, $00, $00, $00
smpsVcDecayRate1 $00, $0C, $1D, $00
smpsVcDecayRate2 $00, $00, $01, $00
smpsVcDecayLevel $00, $00, $00, $00
smpsVcReleaseRate $0F, $0F, $0F, $0F
smpsVcTotalLevel $00, $06, $07, $08
|
; ================================================================
; DevSound variable definitions
; ================================================================
if !def(incDSVars)
incDSVars set 1
SECTION "DevSound variables",WRAM0
DSVarsStart:
FadeType ds 1
InitVarsStart:
FadeTimer ds 1
GlobalVolume ds 1
GlobalSpeed1 ds 1
GlobalSpeed2 ds 1
GlobalTimer ds 1
TickCount ds 1
SyncTick ds 1
SoundEnabled ds 1
CH1Enabled ds 1
CH2Enabled ds 1
CH3Enabled ds 1
CH4Enabled ds 1
CH1IsResting ds 1
CH2IsResting ds 1
CH3IsResting ds 1
CH4IsResting ds 1
CH1Ptr ds 2
CH1VolPtr ds 2
CH1PulsePtr ds 2
CH1ArpPtr ds 2
CH1VibPtr ds 2
CH1VolPos ds 1
CH1VolLoop ds 1
CH1PulsePos ds 1
CH1ArpPos ds 1
CH1VibPos ds 1
CH1VibDelay ds 1
CH1LoopPtr ds 2
CH1RepeatPtr ds 2
CH1RetPtr ds 2
CH1LoopCount ds 1
CH1Tick ds 1
CH1Reset ds 1
CH1Note ds 1
CH1NoteBackup ds 1
CH1Transpose ds 1
CH1FreqOffset ds 1
CH1TempFreq ds 2
CH1PortaType ds 1
CH1PortaSpeed ds 1
CH1Vol ds 1
CH1ChanVol ds 1
CH1Pan ds 1
CH1Sweep ds 1
CH1NoteCount ds 1
CH1InsMode ds 1
CH1Ins1 ds 1
CH1Ins2 ds 1
CH1DoRepeat ds 1
CH1RepeatCount ds 1
CH1MontyMode ds 1
CH1MontyTimer ds 1
CH1MontyFreq ds 2
CH2Ptr ds 2
CH2VolPtr ds 2
CH2PulsePtr ds 2
CH2ArpPtr ds 2
CH2VibPtr ds 2
CH2VolPos ds 1
CH2VolLoop ds 1
CH2PulsePos ds 1
CH2ArpPos ds 1
CH2VibPos ds 1
CH2VibDelay ds 1
CH2LoopPtr ds 2
CH2RepeatPtr ds 2
CH2RetPtr ds 2
CH2LoopCount ds 1
CH2Tick ds 1
CH2Reset ds 1
CH2Note ds 1
CH2NoteBackup ds 1
CH2Transpose ds 1
CH2FreqOffset ds 1
CH2TempFreq ds 2
CH2PortaType ds 1
CH2PortaSpeed ds 1
CH2Vol ds 1
CH2ChanVol ds 1
CH2Pan ds 1
CH2NoteCount ds 1
CH2InsMode ds 1
CH2Ins1 ds 1
CH2Ins2 ds 1
CH2DoRepeat ds 1
CH2RepeatCount ds 1
CH2MontyMode ds 1
CH2MontyTimer ds 1
CH2MontyFreq ds 2
CH3Ptr ds 2
CH3VolPtr ds 2
CH3WavePtr ds 2
CH3ArpPtr ds 2
CH3VibPtr ds 2
CH3VolPos ds 1
CH3WavePos ds 1
CH3ArpPos ds 1
CH3VibPos ds 1
CH3VibDelay ds 1
CH3LoopPtr ds 2
CH3RepeatPtr ds 2
CH3RetPtr ds 2
CH3LoopCount ds 1
CH3Tick ds 1
CH3Reset ds 1
CH3Note ds 1
CH3NoteBackup ds 1
CH3Transpose ds 1
CH3FreqOffset ds 1
CH3TempFreq ds 2
CH3PortaType ds 1
CH3PortaSpeed ds 1
CH3Vol ds 1
CH3ChanVol ds 1
CH3ComputedVol ds 1
CH3Wave ds 1
CH3Pan ds 1
CH3NoteCount ds 1
CH3InsMode ds 1
CH3Ins1 ds 1
CH3Ins2 ds 1
CH3DoRepeat ds 1
CH3RepeatCount ds 1
CH3MontyMode ds 1
CH3MontyTimer ds 1
CH3MontyFreq ds 2
CH4Ptr ds 2
CH4VolPtr ds 2
if !def(DisableDeflehacks)
CH4WavePtr ds 2
endc
CH4NoisePtr ds 2
CH4VolPos ds 1
CH4VolLoop ds 1
if !def(DisableDeflehacks)
CH4WavePos ds 1
endc
CH4NoisePos ds 1
CH4LoopPtr ds 2
CH4RepeatPtr ds 2
CH4RetPtr ds 2
CH4LoopCount ds 1
CH4Mode ds 1
CH4ModeBackup ds 1
CH4Tick ds 1
CH4Reset ds 1
CH4Transpose ds 1
CH4Vol ds 1
CH4Wave ds 1
CH4ChanVol ds 1
CH4Pan ds 1
CH4NoteCount ds 1
CH4InsMode ds 1
CH4Ins1 ds 1
CH4Ins2 ds 1
CH4DoRepeat ds 1
CH4RepeatCount ds 1
CH4MontyMode ds 1
CH4MontyTimer ds 1
CH4MontyFreq ds 2
DSVarsEnd
DSBufVars
ComputedWaveBuffer ds 16
WaveBuffer ds 16
WavePos ds 1
WaveBufUpdateFlag ds 1
PWMEnabled ds 1
PWMVol ds 1
PWMSpeed ds 1
PWMTimer ds 1
PWMDir ds 1
RandomizerEnabled ds 1
RandomizerTimer ds 1
RandomizerSpeed ds 1
arp_Buffer ds 8
DSBufVarsEnd
if !def(SimpleEchoBuffer)
CH1DoEcho ds 1
CH2DoEcho ds 1
CH3DoEcho ds 1
CH1EchoBuffer ds 64
CH2EchoBuffer ds 64
CH3EchoBuffer ds 64
EchoPos ds 1
CH1EchoDelay ds 1
CH2EchoDelay ds 1
CH3EchoDelay ds 1
CH1NotePlayed ds 1
CH2NotePlayed ds 1
CH3NotePlayed ds 1
else
CH1DoEcho ds 1
CH2DoEcho ds 1
CH3DoEcho ds 1
CH1EchoBuffer ds 3
CH2EchoBuffer ds 3
CH3EchoBuffer ds 3
EchoPos ds 1
CH1NotePlayed ds 1
CH2NotePlayed ds 1
CH3NotePlayed ds 1
endc
endc
|
;Read 3 two-digit numbers and print the second largest number among them.
section .data
msg1 : db 'Enter first digit of first number :'
l1 : equ $-msg1
msg2 : db 'Enter second digit of first number :'
l2 : equ $-msg2
msg3 : db 'Enter first digit of second number :'
l3 : equ $-msg3
msg4 : db 'Enter second digit of second number :'
l4 : equ $-msg4
msg5 : db 'Enter first digit of third number :'
l5 : equ $-msg5
msg6 : db 'Enter second digit of third number :'
l6 : equ $-msg6
msg7 : db ' ', 10
l7 : equ $-msg7
section .bss
d1 : resb 1
d2 : resb 1
d3 : resb 1
d4 : resb 1
d5 : resb 1
d6 : resb 1
n1 : resb 1
n2 : resb 1
n3 : resb 1
ans1 : resb 1
ans2 : resb 1
junk : resb 1
junk1 : resb 1
junk2 : resb 1
junk3 : resb 1
junk4 : resb 1
junk5 : resb 1
section .text
global _start:
_start:
mov eax, 4
mov ebx, 1
mov ecx, msg1
mov edx, l1
int 80h
mov eax, 3
mov ebx, 0
mov ecx, d1
mov edx, 1
int 80h
mov eax, 3
mov ebx, 0
mov ecx, junk
mov edx, 1
int 80h
mov eax, 4
mov ebx, 1
mov ecx, msg2
mov edx, l2
int 80h
mov eax, 3
mov ebx, 0
mov ecx, d2
mov edx, 1
int 80h
mov eax, 3
mov ebx, 0
mov ecx, junk1
mov edx, 1
int 80h
;First number calculation
mov al, byte[d1]
sub al, 30h
mov bl, 10
mov ah, 0;
mul bl;ax=al*bl
mov bx, word[d2]
sub bx, 30h
add ax, bx
mov [n1], ax;n1=d1*10+d2
mov eax, 4
mov ebx, 1
mov ecx, msg3
mov edx, l3
int 80h
mov eax, 3
mov ebx, 0
mov ecx, d3
mov edx, 1
int 80h
mov eax, 3
mov ebx, 0
mov ecx, junk2
mov edx, 1
int 80h
mov eax, 4
mov ebx, 1
mov ecx, msg4
mov edx, l4
int 80h
mov eax, 3
mov ebx, 0
mov ecx, d4
mov edx, 1
int 80h
mov eax, 3
mov ebx, 0
mov ecx, junk3
mov edx, 1
int 80h
;Second number calculation
mov al, byte[d3]
sub al, 30h
mov bl, 10
mov ah, 0
mul bl
mov bx, word[d4]
sub bx, 30h
add ax, bx
mov [n2], ax;n2
mov eax, 4
mov ebx, 1
mov ecx, msg5
mov edx, l5
int 80h
mov eax, 3
mov ebx, 0
mov ecx, d5
mov edx, 1
int 80h
mov eax, 3
mov ebx, 0
mov ecx, junk4
mov edx, 1
int 80h
mov eax, 4
mov ebx, 1
mov ecx, msg6
mov edx, l6
int 80h
mov eax, 3
mov ebx, 0
mov ecx, d6
mov edx, 1
int 80h
;Third number calculation
mov al, byte[d5]
sub al, 30h
mov bl, 10
mov ah, 0
mul bl
mov bx, word[d6]
sub bx, 30h
add ax, bx
mov [n3], ax;n2
;x,y,z if(x>y){ if(x<z) x else }
mov al,[n1]
cmp al,[n2]
ja if1
mov al,[n1]
cmp al,[n3]
ja if4
mov al,[n2]
cmp al,[n3]
jb if5
mov ax,word[n3]
jmp fin
if5:
mov ax,word[n2]
jmp fin
if4:
mov ax,word[n1]
jmp fin
if1:
mov al,[n1]
cmp al,[n3]
jb if2
mov al,[n2]
cmp al,[n3]
ja if3
mov ax,word[n3]
jmp fin
if3:
mov ax,word[n2]
jmp fin
if2:
mov ax,word[n1]
jmp fin
fin:
mov bl, 10
mov ah, 0
div bl
mov byte[ans1], al
mov byte[ans2], ah
add byte[ans1], 30h
add byte[ans2], 30h
mov eax, 4
mov ebx, 1
mov ecx, ans1
mov edx, 1
int 80h
mov eax, 4
mov ebx, 1
mov ecx, ans2
mov edx, 1
int 80h
mov eax, 1
mov ebx, 0
int 80h
|
.byte $01 ; Unknown purpose
.byte OBJ_GOOMBA, $1A, $12
.byte OBJ_GREENTROOPA, $18, $19
.byte OBJ_CFIRE_GOOMBAPIPE_L, $10, $19
.byte OBJ_CFIRE_GOOMBAPIPE_R, $13, $19
.byte OBJ_REDTROOPA, $2D, $13
.byte OBJ_CFIRE_GOOMBAPIPE_L, $34, $12
.byte OBJ_CFIRE_GOOMBAPIPE_R, $37, $12
.byte OBJ_ENDLEVELCARD, $58, $15
.byte $FF ; Terminator
|
; Z88 Small C+ Run Time Library
; Long functions
;
; feilipu 10/2021
SECTION code_clib
SECTION code_l_sccz80
PUBLIC l_long_mult
EXTERN l_mult_0
EXTERN l_mult_ulong_0
;result = primary * secondary
;enter with secondary in dehl, primary on stack
;exit with product in dehl
.l_long_mult
push de ;put secondary on stack
push hl
ld bc,hl ;secondary LSW
ld de,sp+6 ;primary LSW offset
ld hl,(de)
ex de,hl
call l_mult_ulong_0 ;dehl = de * bc
push hl ;result LSW
push de ;partial result MSW
ld de,sp+4 ;secondary LSW offset
ld hl,(de)
ld bc,hl
ld de,sp+12 ;primary MSW offset
ld hl,(de)
ex de,hl
call l_mult_0 ;hl = de * bc
pop bc ;partial result MSW
add hl,bc
push hl
ld de,sp+6 ;secondary MSW offset
ld hl,(de)
ld bc,hl
ld de,sp+10 ;primary LSW offset
ld hl,(de)
ex de,hl
call l_mult_0 ;hl = de * bc
pop bc ;partial result MSW
add hl,bc ;result MSW
push hl
ld de,sp+8 ;get return from stack
ld hl,(de)
ld de,sp+12 ;place return on stack
ld (de),hl
pop hl ;result MSW
pop bc ;result LSW
ld de,sp+8 ;point to return again
ex de,hl ;result MSW <> return sp
ld sp,hl ;remove stacked parameters
ld hl,bc ;result LSW
ret
|
%ifdef CONFIG
{
"RegData": {
"R15": "0x1A"
},
"MemoryRegions": {
"0x100000000": "4096"
}
}
%endif
%macro cfmerge 0
; Get CF
sbb r14, r14
and r14, 1
; Merge in to results
shl r15, 1
or r15, r14
%endmacro
mov rdx, 0xe0000000
mov rax, 0xFFFFFFFF80000000
mov [rdx + 8 * 0], rax
mov [rdx + 8 * 1], rax
mov [rdx + 8 * 2], rax
mov rax, 0x01
mov [rdx + 8 * 3], eax
mov rax, 0x0
mov [rdx + 8 * 3 + 4], eax
xor r15, r15 ; Will contain our results
; Test and set
mov r13, 1
btc word [rdx], r13w
cfmerge
; Ensure it is set
mov r13, 1
bt word [rdx], r13w
cfmerge
mov r13, 32
btc dword [rdx], r13d
cfmerge
bt dword [rdx], r13d
cfmerge
mov r13, 64 * 3
btc qword [rdx], r13
cfmerge
mov r13, 64 * 3
bt qword [rdx], r13
cfmerge
hlt
|
;; @file
; This is the assembly code for transferring to control to OS S3 waking vector
; for IA32 platform
;
; Copyright (c) 2013-2015 Intel Corporation.
;
; SPDX-License-Identifier: BSD-2-Clause-Patent
.586P
.model flat,C
.code
;-----------------------------------------
;VOID
;AsmTransferControl (
; IN UINT32 S3WakingVector,
; IN UINT32 AcpiLowMemoryBase
; );
;-----------------------------------------
AsmTransferControl PROC
; S3WakingVector :DWORD
; AcpiLowMemoryBase :DWORD
push ebp
mov ebp, esp
lea eax, @F
push 28h ; CS
push eax
mov ecx, [ebp + 8]
shrd ebx, ecx, 20
and ecx, 0fh
mov bx, cx
mov @jmp_addr, ebx
retf
@@:
DB 0b8h, 30h, 0 ; mov ax, 30h as selector
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
mov eax, cr0 ; Get control register 0
DB 66h
DB 83h, 0e0h, 0feh ; and eax, 0fffffffeh ; Clear PE bit (bit #0)
DB 0fh, 22h, 0c0h ; mov cr0, eax ; Activate real mode
DB 0eah ; jmp far @jmp_addr
@jmp_addr DD ?
AsmTransferControl ENDP
END
|
; A228229: Recurrence a(n) = n*(n + 1)*a(n-1) + 1 with a(0) = 1.
; Submitted by Jamie Morken(s2)
; 1,3,19,229,4581,137431,5772103,323237769,23273119369,2094580743211,230403881753211,30413312391423853,4744476733062121069,863494765417306034559,181333900737634267257391,43520136177032224141773841,11837477040152764966562484753
add $0,1
mov $2,1
lpb $0
mul $2,$0
sub $0,1
mul $2,$0
add $1,$2
lpe
mov $0,$1
add $0,1
|
/***************************************************************************\
UI_setup.cpp
Dave Power (x4373)
setup screen stuff for FreeFalcon
\***************************************************************************/
#include "falclib.h"
#include "chandler.h"
#include "userids.h"
#include "PlayerOp.h"
#include "sim/include/stdhdr.h"
#include "uicomms.h"
#include "Graphics/Include/render3d.h"
#include "Graphics/Include/renderow.h"
#include "Graphics/Include/drawBSP.h"
#include "Graphics/Include/matrix.h"
#include "Graphics/Include/TexBank.h"
#include "Graphics/Include/TerrTex.h"
#include "Graphics/Include/FarTex.h"
#include "objectiv.h"
#include "cbsplist.h"
#include "c3dview.h"
#include "ui_setup.h"
#include "Graphics/Include/RViewPnt.h"
#include <tchar.h>
#include "f4find.h"
#include "sim/include/inpFunc.h"
#include "dispopts.h"
#include "logbook.h"
#include "sim/include/sinput.h"
#include "sim/include/simio.h"
#include "cmusic.h"
#include "dispcfg.h"
#include "Graphics/Include/draw2d.h"
#include "falcsess.h"
#include "Graphics/Include/tod.h"
//JAM 21Nov03
#include "Weather.h"
#include "Campaign/include/Cmpclass.h"
//JAM
extern int STPLoaded;
extern C_Handler *gMainHandler;
extern C_Parser *gMainParser;
extern char **KeyDescrips;
extern C_3dViewer *SetupViewer;
extern RViewPoint *tmpVpoint;
extern ObjectPos *Objects;
extern FeaturePos *Features;
extern Drawable2D *Smoke;
int GraphicSettingMult = 1;
//M.N.
//int skycolortime;
//extern int NumberOfSkyColors;
//extern SkyColorDataType* skycolor;
long Cluster = 8001;
int ready = FALSE;
//JOYCAPS S_joycaps;
MMRESULT S_joyret;
F4CSECTIONHANDLE* SetupCritSection = NULL;
float JoyScale;
float RudderScale;
float ThrottleScale;
RECT Rudder;
RECT Throttle;
int Calibrated = FALSE;
//defined in this file
static void HookupSetupControls(long ID);
void STPSetupControls(void);
void SetupRadioCB(long ID, short hittype, C_Base *control);
//defined in another file
void CloseWindowCB(long ID, short hittype, C_Base *control);
void UI_Help_Guide_CB(long ID, short hittype, C_Base *ctrl);
void GenericTimerCB(long ID, short hittype, C_Base *control);
void OpenLogBookCB(long ID, short hittype, C_Base *control);
BOOL AddWordWrapTextToWindow(C_Window *win, short *x, short *y, short startcol, short endcol, COLORREF color, _TCHAR *str, long Client = 0);
void INFOSetupControls(void);
void CheckFlyButton(void);
//SimTab.cpp
int GetRealism(C_Window *win);
int SetRealism(C_Window *win);
void SimControlCB(long ID, short hittype, C_Base *control);
void SetSkillCB(long ID, short hittype, C_Base *control);
void TurbulenceCB(long ID, short hittype, C_Base *control); //JAM 06Nov03
//ControlsTab.cpp
SIM_INT CalibrateFile(void);
SIM_INT Calibrate(void);
void InitKeyDescrips(void);
void CleanupKeys(void);
void RefreshJoystickCB(long ID, short hittype, C_Base *control);
BOOL KeystrokeCB(unsigned char DKScanCode, unsigned char Ascii, unsigned char ShiftStates, long RepeatCount);
void CalibrateCB(long ID, short hittype, C_Base *control);
BOOL SaveKeyMapList(char *filename);
int UpdateKeyMapList(char *fname, int flag);
void StopCalibrating(C_Base *control);
void SetKeyDefaultCB(long ID, short hittype, C_Base *control);
int CreateKeyMapList(char *filename);
void SaveKeyButtonCB(long ID, short hittype, C_Base *control);
void LoadKeyButtonCB(long ID, short hittype, C_Base *control);
void ControllerSelectCB(long ID, short hittype, C_Base *control);
void BuildControllerList(C_ListBox *lbox);
void HideKeyStatusLines(C_Window *win);
void RecenterJoystickCB(long ID, short hittype, C_Base *control);
void AdvancedControlCB(long ID, short hittype, C_Base *control); // Retro 31Dec2003
void AdvancedControlApplyCB(long ID, short hittype, C_Base *control); // Retro 31Dec2003
void AdvancedControlOKCB(long ID, short hittype, C_Base *control); // Retro 31Dec2003
void AdvancedControlCancelCB(long ID, short hittype, C_Base *control); // Retro 31Dec2003
void SetJoystickAndPOVSymbols(const bool, C_Base *control);
void SetThrottleAndRudderBars(C_Base *control);
void SetABDetentCB(long ID, short hittype, C_Base *control);
//GraphicsTab.cpp
void STPMoveRendererCB(C_Window *win);
void STPViewTimerCB(long ID, short hittype, C_Base *control);
void STPDisplayCB(long ID, short hittype, C_Base *control);
void SfxLevelCB(long ID, short hittype, C_Base *control);
void RenderViewCB(long ID, short hittype, C_Base *control);
void ChangeViewpointCB(long ID, short hittype, C_Base *control);
//void GouraudCB(long ID,short hittype,C_Base *control);
void HazingCB(long ID, short hittype, C_Base *control);
//void AlphaBlendCB(long ID,short hittype,C_Base *control);
void RealWeatherShadowsCB(long ID, short hittype, C_Base *control); //JAM 07Dec03
void BilinearFilterCB(long ID, short hittype, C_Base *control);
//void ObjectTextureCB(long ID,short hittype,C_Base *control);
void BuildingDetailCB(long ID, short hittype, C_Base *control);
void ObjectDetailCB(long ID, short hittype, C_Base *control);
void VehicleSizeCB(long ID, short hittype, C_Base *control);
void TerrainDetailCB(long ID, short hittype, C_Base *control);
//void TextureDistanceCB(long ID,short hittype,C_Base *control);
void VideoCardCB(long ID, short hittype, C_Base *control);
void VideoDriverCB(long ID, short hittype, C_Base *control);
void ResolutionCB(long ID, short hittype, C_Base *control);
void BuildVideoCardList(C_ListBox *lbox);
void DisableEnableDrivers(C_ListBox *lbox);
void DisableEnableResolutions(C_ListBox *lbox);
void BuildVideoDriverList(C_ListBox *lbox);
void GraphicsDefaultsCB(long ID, short hittype, C_Base *control);
void ScalingCB(long ID, short hittype, C_Base *control);
void BuildResolutionList(C_ListBox *lbox);
void PlayerBubbleCB(long ID, short hittype, C_Base *control);
void AdvancedCB(long ID, short hittype, C_Base *control);
void SetAdvanced();
void AdvancedGameCB(long ID, short hittype, C_Base *control);
void SubTitleCB(long ID, short hittype, C_Base *control); // Retro 25Dec2003
void SeasonCB(long ID, short hittype, C_Base *control); //THW 2004-01-17
//JAM 21Nov03
void RealWeatherCB(long ID, short hittype, C_Base *control);
// M.N.
//void SkyColorCB(long ID,short hittype,C_Base *control);
//void SetSkyColor();
//void SelectSkyColorCB(long ID,short hittype,C_Base *control);
//void SkyColTimeCB(long ID,short hittype,C_Base *control);
// Player radio voice turn on/off via UI
void TogglePlayerVoiceCB(long ID, short hittype, C_Base *control);
void ToggleUICommsCB(long ID, short hittype, C_Base *control);
//SoundTab.cpp
void InitSoundSetup();
void TestButtonCB(long ID, short hittype, C_Base *control);
void SoundSliderCB(long ID, short hittype, C_Base *control);
void PlayVoicesCB(long ID, short hittype, C_Base *control);
RECT AxisValueBox = { 0 };
float AxisValueBoxHScale;
float AxisValueBoxWScale;
void LoadSetupWindows()
{
long ID = 0;
int size = 0;
C_Button *ctrl = NULL;
C_Window *win = NULL;
C_TimerHook *tmr = NULL;
C_Line *line = NULL;
C_Bitmap *bmap = NULL;
UI95_RECT client;
//if setup is already loaded, we only need to make sure all the control
//settings are up to date
if (STPLoaded)
{
STPSetupControls();
if (KeyVar.NeedUpdate)
{
UpdateKeyMapList(PlayerOptions.keyfile, 1);
KeyVar.NeedUpdate = FALSE;
}
return;
}
//Do basic UI setup of window
if (_LOAD_ART_RESOURCES_)
gMainParser->LoadImageList("st_res.lst");
else
gMainParser->LoadImageList("st_art.lst");
gMainParser->LoadSoundList("st_snd.lst");
gMainParser->LoadWindowList("st_scf.lst"); // Modified by M.N. - add art/art1024 by LoadWindowList
ID = gMainParser->GetFirstWindowLoaded();
while (ID)
{
//Hookup the callbacks
HookupSetupControls(ID);
ID = gMainParser->GetNextWindowLoaded();
}
win = gMainHandler->FindWindow(SETUP_WIN);
if (win not_eq NULL)
{
//timer to update joystick bmp on controls tab
tmr = new C_TimerHook;
tmr->Setup(C_DONT_CARE, C_TYPE_TIMER);
tmr->SetUpdateCallback(GenericTimerCB);
tmr->SetRefreshCallback(RefreshJoystickCB);
tmr->SetUserNumber(_UI95_TIMER_DELAY_, 1); // Timer activates every 80 mseconds (Only when this window is open)
tmr->SetCluster(8004);
win->AddControl(tmr);
//timer to update the view position on graphics tab
tmr = new C_TimerHook;
tmr->Setup(C_DONT_CARE, C_TYPE_TIMER);
tmr->SetUpdateCallback(GenericTimerCB);
tmr->SetRefreshCallback(ChangeViewpointCB);
tmr->SetUserNumber(_UI95_TIMER_DELAY_, 1); // Timer activates every 80 mseconds (Only when this window is open)
tmr->SetCluster(8002);
win->AddControl(tmr);
//timer to generate new radio message calls on sound tab
tmr = new C_TimerHook;
tmr->Setup(C_DONT_CARE, C_TYPE_TIMER);
tmr->SetUpdateCallback(GenericTimerCB);
tmr->SetRefreshCallback(PlayVoicesCB);
tmr->SetUserNumber(_UI95_TIMER_DELAY_, 100); // Timer activates every 8 seconds (Only when this window is open)
tmr->SetCluster(8003);
win->AddControl(tmr);
//make sure sim tab is selected the first time in
ctrl = (C_Button *)win->FindControl(SIM_TAB);
SetupRadioCB(SETUP_WIN, C_TYPE_LMOUSEUP, ctrl);
bmap = (C_Bitmap *)win->FindControl(JOY_INDICATOR);
if (bmap not_eq NULL)
{
size = bmap->GetH() + 1;
}
//use joystick.dat to calibrate joystick
//Calibration.calibrated = CalibrateFile();
client = win->GetClientArea(1);
//setup scale for manipulating joystick control on controls tab
//if(Calibration.calibrated)
JoyScale = (float)(client.right - client.left - size) / 2.0F;
//else
//JoyScale = (float)(client.right - client.left - size)/65536.0F;
#if 0 // Retro 17Jan2004
//setup scale for manipulating rudder control on controls tab
line = (C_Line *)win->FindControl(RUDDER);
if (line not_eq NULL)
{
if ( not IO.AnalogIsUsed(AXIS_YAW)) // Retro 31Dec2003
line->SetColor(RGB(130, 130, 130)); //grey
//if(Calibration.calibrated)
RudderScale = (line->GetH()) / 2.0F;
//else
//RudderScale = (line->GetH() )/65536.0F;
Rudder.left = line->GetX();
Rudder.right = line->GetX() + line->GetW();
Rudder.top = line->GetY();
Rudder.bottom = line->GetY() + line->GetH();
}
//setup scale for manipulating throttle control on controls tab
line = (C_Line *)win->FindControl(THROTTLE);
if (line not_eq NULL)
{
if ( not IO.AnalogIsUsed(AXIS_THROTTLE)) // Retro 31Dec2003
line->SetColor(RGB(130, 130, 130)); //grey
//if(Calibration.calibrated)
ThrottleScale = (float)line->GetH();
//else
//ThrottleScale = (line->GetH())/65536.0F;
Throttle.left = line->GetX();
Throttle.right = line->GetX() + line->GetW();
Throttle.top = line->GetY();
Throttle.bottom = line->GetY() + line->GetH();
}
#else
// Retro 17Jan2004 - now caters to both throttle axis
//setup scale for manipulating rudder control on controls tab
line = (C_Line *)win->FindControl(RUDDER);
if (line not_eq NULL)
{
RudderScale = (line->GetH()) / 2.0F;
Rudder.left = line->GetX();
Rudder.right = line->GetX() + line->GetW();
Rudder.top = line->GetY();
Rudder.bottom = line->GetY() + line->GetH();
}
//setup scale for manipulating throttle control on controls tab
line = (C_Line *)win->FindControl(THROTTLE);
if (line not_eq NULL)
{
ThrottleScale = (float)line->GetH();
Throttle.left = line->GetX();
Throttle.right = line->GetX() + line->GetW();
Throttle.top = line->GetY();
Throttle.bottom = line->GetY() + line->GetH();
// looks strange but works (the function needs a control on the controller-sheet)
// this function activates/deactivates the bars bases on availability
SetThrottleAndRudderBars(line);
}
#endif
// Retro 27Mar2004 - a bar to show the value of an analogue axis
// ..actually there are about 20+ of these, but I use the coords of one, the
// others are (or rather: should be) aligned to this one
C_Window* win2 = gMainHandler->FindWindow(SETUP_CONTROL_ADVANCED_WIN);
if ( not win2) return;
C_Line* line = (C_Line *)win2->FindControl(SETUP_ADVANCED_THROTTLE_VAL);
if (line not_eq NULL)
{
AxisValueBox.left = line->GetX();
AxisValueBox.right = line->GetX() + line->GetW();
AxisValueBox.top = line->GetY();
AxisValueBox.bottom = line->GetY() + line->GetH();
AxisValueBoxHScale = (float)line->GetH();
AxisValueBoxWScale = (float)line->GetW();
}
else
{
ShiAssert(false);
}
// Retro end
}
InitKeyDescrips();
//set all the controls to their correct positions according to the saved options file
STPSetupControls();
CreateKeyMapList(PlayerOptions.keyfile);
STPLoaded++;
}//LoadSetupWindows
void SetupOpenLogBookCB(long ID, short hittype, C_Base *control)
{
if (hittype not_eq C_TYPE_LMOUSEUP)
return;
InitSoundSetup();
OpenLogBookCB(ID, hittype, control);
}
///this function sets up all the controls according to the values stored
///in the PlayerOptions structure
void STPSetupControls(void)
{
C_Window *win;
C_Button *button;
C_Text *text;
C_ListBox *lbox;
C_Slider *slider;
C_EditBox *ebox;
win = gMainHandler->FindWindow(SETUP_WIN);
if (win == NULL)
return;
lbox = (C_ListBox *)win->FindControl(SET_FLTMOD);
if (lbox not_eq NULL)
{
if (PlayerOptions.GetFlightModelType() == FMAccurate)
lbox->SetValue(SET_FLTMOD_1);
else
lbox->SetValue(SET_FLTMOD_2);
lbox->Refresh();
}
lbox = (C_ListBox *)win->FindControl(SET_RADAR);
if (lbox not_eq NULL)
{
switch (PlayerOptions.GetAvionicsType())
{
// M.N. full realism mode added
case ATRealisticAV:
lbox->SetValue(SET_RADAR_0);
break;
case ATRealistic:
lbox->SetValue(SET_RADAR_1);
break;
case ATSimplified:
lbox->SetValue(SET_RADAR_2);
break;
case ATEasy:
lbox->SetValue(SET_RADAR_3);
break;
}
lbox->Refresh();
}
lbox = (C_ListBox *)win->FindControl(SET_WEAPEFF);
if (lbox not_eq NULL)
{
switch (PlayerOptions.GetWeaponEffectiveness())
{
case WEAccurate:
lbox->SetValue(SET_WEAPEFF_1);
break;
case WEEnhanced:
lbox->SetValue(SET_WEAPEFF_2);
break;
case WEExaggerated:
lbox->SetValue(SET_WEAPEFF_3);
break;
}
lbox->Refresh();
}
lbox = (C_ListBox *)win->FindControl(SET_AUTOPILOT);
if (lbox not_eq NULL)
{
switch (PlayerOptions.GetAutopilotMode())
{
case APNormal:
lbox->SetValue(SET_AUTO_1);
break;
case APEnhanced:
lbox->SetValue(SET_AUTO_2);
break;
case APIntelligent:
lbox->SetValue(SET_AUTO_3);
break;
}
lbox->Refresh();
}
lbox = (C_ListBox *)win->FindControl(SET_REFUELING);
if (lbox not_eq NULL)
{
switch (PlayerOptions.GetRefuelingMode())
{
case ARRealistic:
lbox->SetValue(SET_REFUEL_1);
break;
case ARModerated:
lbox->SetValue(SET_REFUEL_2);
break;
case ARSimplistic:
lbox->SetValue(SET_REFUEL_3);
break;
}
lbox->Refresh();
}
lbox = (C_ListBox *)win->FindControl(SET_PADLOCK);
if (lbox not_eq NULL)
{
switch (PlayerOptions.GetPadlockMode())
{
case PDDisabled:
lbox->SetValue(SET_PADLOCK_4);
break;
case PDRealistic:
lbox->SetValue(SET_PADLOCK_1);
break;
case PDEnhanced:
lbox->SetValue(SET_PADLOCK_2);
break;
//case PDSuper:
// lbox->SetValue(SET_PADLOCK_3);
// break;
}
lbox->Refresh();
}
lbox = (C_ListBox *)win->FindControl(SET_CANOPY_CUE);
if (lbox not_eq NULL)
{
switch (PlayerOptions.GetVisualCueMode())
{
case VCNone:
lbox->SetValue(CUE_NONE);
break;
case VCLiftLine:
lbox->SetValue(CUE_LIFT_LINE);
break;
case VCReflection:
lbox->SetValue(CUE_REFLECTION_MAP);
break;
case VCBoth:
lbox->SetValue(CUE_BOTH);
break;
}
lbox->Refresh();
}
lbox = (C_ListBox *)win->FindControl(SET_VIDEO_DRIVER);
if (lbox not_eq NULL)
{
BuildVideoDriverList(lbox);
DisableEnableDrivers(lbox);
lbox->SetValue(DisplayOptions.DispVideoDriver + 1);
lbox->Refresh();
}
lbox = (C_ListBox *)win->FindControl(SET_VIDEO_CARD);
if (lbox not_eq NULL)
{
BuildVideoCardList(lbox);
lbox->SetValue(DisplayOptions.DispVideoCard + 1);
lbox->Refresh();
}
lbox = (C_ListBox *)win->FindControl(SET_RESOLUTION);
if (lbox not_eq NULL)
{
BuildResolutionList(lbox);
#if 1
// OW
// Handled in BuildResolutionList
DeviceManager::DDDriverInfo *pDI = FalconDisplay.devmgr.GetDriver(DisplayOptions.DispVideoDriver);
if (pDI)
{
int nIndex = pDI->FindDisplayMode(DisplayOptions.DispWidth, DisplayOptions.DispHeight, DisplayOptions.DispDepth);
lbox->SetValue(nIndex not_eq -1 ? nIndex : 0);
}
#else
DisableEnableResolutions(lbox);
lbox->SetValue(DisplayOptions.DispWidth);
lbox->Refresh();
#endif
}
//JAM 20Nov03
lbox = (C_ListBox *)win->FindControl(SETUP_REALWEATHER);
if (lbox not_eq NULL)
{
if (TheCampaign.InMainUI)
{
lbox->RemoveAllItems();
lbox->AddItem(70208, C_TYPE_ITEM, "Sunny");
lbox->AddItem(70209, C_TYPE_ITEM, "Fair");
lbox->AddItem(70210, C_TYPE_ITEM, "Poor");
lbox->AddItem(70211, C_TYPE_ITEM, "Inclement");
lbox->SetValue(PlayerOptions.weatherCondition + 70207);
lbox->Refresh();
}
else if (((WeatherClass *)realWeather)->lockedCondition)
{
lbox->RemoveAllItems();
lbox->AddItem(70212, C_TYPE_ITEM, "Locked");
lbox->AddItem(70213, C_TYPE_ITEM, "Unlock");
lbox->Refresh();
}
}
//JAM
/*
//THW 2004-01-18
lbox=(C_ListBox *)win->FindControl(SETUP_SEASON);
if(lbox not_eq NULL)
{
lbox->SetValue(PlayerOptions.Season+70313);
lbox->Refresh();
}
//THW
*/
button = (C_Button *)win->FindControl(SET_LOGBOOK);
if (button not_eq NULL)
{
button->SetText(0, UI_logbk.Callsign());
button->Refresh();
}
button = (C_Button *)win->FindControl(SET_ORDNANCE);
if (button not_eq NULL)
{
if (PlayerOptions.UnlimitedAmmo())
button->SetState(C_STATE_1);
else
button->SetState(C_STATE_0);
button->Refresh();
}
button = (C_Button *)win->FindControl(SET_FUEL);
if (button not_eq NULL)
{
if (PlayerOptions.UnlimitedFuel())
button->SetState(C_STATE_1);
else
button->SetState(C_STATE_0);
button->Refresh();
}
button = (C_Button *)win->FindControl(SET_CHAFFLARES);
if (button not_eq NULL)
{
if (PlayerOptions.UnlimitedChaff())
button->SetState(C_STATE_1);
else
button->SetState(C_STATE_0);
button->Refresh();
}
button = (C_Button *)win->FindControl(SET_COLLISIONS);
if (button not_eq NULL)
{
if (PlayerOptions.CollisionsOn())
button->SetState(C_STATE_0);
else
button->SetState(C_STATE_1);
button->Refresh();
}
button = (C_Button *)win->FindControl(SET_BLACKOUT);
if (button not_eq NULL)
{
if (PlayerOptions.BlackoutOn())
button->SetState(C_STATE_0);
else
button->SetState(C_STATE_1);
button->Refresh();
}
button = (C_Button *)win->FindControl(SET_IDTAGS);
if (button not_eq NULL)
{
if (PlayerOptions.NameTagsOn())
button->SetState(C_STATE_1);
else
button->SetState(C_STATE_0);
button->Refresh();
}
button = (C_Button *)win->FindControl(SET_BULLSEYE_CALLS);
if (button not_eq NULL)
{
if (PlayerOptions.BullseyeOn())
button->SetState(C_STATE_1);
else
button->SetState(C_STATE_0);
button->Refresh();
}
button = (C_Button *)win->FindControl(SET_INVULNERABILITY); //should be SET_INVULNERABLITY
if (button not_eq NULL)
{
if (PlayerOptions.InvulnerableOn())
button->SetState(C_STATE_1);
else
button->SetState(C_STATE_0);
button->Refresh();
}
// Retro 25Dec2003
button = (C_Button *)win->FindControl(SETUP_SIM_INFOBAR);
if (button not_eq NULL)
{
if (PlayerOptions.getInfoBar())
button->SetState(C_STATE_1);
else
button->SetState(C_STATE_0);
button->Refresh();
}
button = (C_Button *)win->FindControl(SETUP_SIM_SUBTITLES);
if (button not_eq NULL)
{
if (PlayerOptions.getSubtitles())
button->SetState(C_STATE_1);
else
button->SetState(C_STATE_0);
button->Refresh();
}
// ..ends
ebox = (C_EditBox *)win->FindControl(ACMI_FILE_SIZE);
if (ebox)
{
ebox->SetInteger(PlayerOptions.AcmiFileSize());
ebox->Refresh();
}
button = (C_Button *)win->FindControl(AUTO_SCALE);
if (button not_eq NULL)
{
if (PlayerOptions.ObjectDynScalingOn())
button->SetState(C_STATE_1);
else
button->SetState(C_STATE_0);
button->Refresh();
}
button = (C_Button *)win->FindControl(GOUROUD); //GOUROUD
if (button not_eq NULL)
{
if (PlayerOptions.GouraudOn())
button->SetState(C_STATE_1);
else
button->SetState(C_STATE_0);
button->Refresh();
}
button = (C_Button *)win->FindControl(HAZING);
if (button not_eq NULL)
{
if (PlayerOptions.HazingOn())
button->SetState(C_STATE_1);
else
button->SetState(C_STATE_0);
button->Refresh();
}
//JAM 07Dec03
button = (C_Button *)win->FindControl(SETUP_REALWEATHER_SHADOWS);
if (button not_eq NULL)
{
if (PlayerOptions.ShadowsOn())
button->SetState(C_STATE_1);
else
button->SetState(C_STATE_0);
button->Refresh();
}
button = (C_Button *)win->FindControl(SETUP_SPECULAR_LIGHTING);
if (button not_eq NULL)
{
if (DisplayOptions.bSpecularLighting)
button->SetState(C_STATE_1);
else
button->SetState(C_STATE_0);
button->Refresh();
}
/* button=(C_Button *)win->FindControl(OBJECT_TEXTURES);
if(button not_eq NULL)
{
if(PlayerOptions.ObjectTexturesOn())
button->SetState(C_STATE_1);
else
button->SetState(C_STATE_0);
button->Refresh();
}
*/
// M.N.
button = (C_Button *)win->FindControl(PLAYERVOICE);
if (button not_eq NULL)
{
if (PlayerOptions.PlayerRadioVoice)
button->SetState(C_STATE_1);
else
button->SetState(C_STATE_0);
button->Refresh();
}
button = (C_Button *)win->FindControl(UICOMMS);
if (button not_eq NULL)
{
if (PlayerOptions.UIComms)
button->SetState(C_STATE_1);
else
button->SetState(C_STATE_0);
button->Refresh();
}
text = (C_Text *)win->FindControl(CAL_TEXT);
if (text not_eq NULL)
text->SetText("");
InitSoundSetup();
slider = (C_Slider *)win->FindControl(OBJECT_DETAIL);
if (slider not_eq NULL)
{
ebox = (C_EditBox *)win->FindControl(OBJECT_DETAIL_READOUT);
if (ebox)
{
PlayerOptions.ObjDetailLevel = min(PlayerOptions.ObjDetailLevel, 2.0F * GraphicSettingMult);
ebox->SetInteger(FloatToInt32((PlayerOptions.ObjDetailLevel - .5f) / .25f + 1.5f));
ebox->Refresh();
slider->SetSteps(static_cast<short>(6 * GraphicSettingMult));
slider->SetUserNumber(0, OBJECT_DETAIL_READOUT);
}
slider->SetSliderPos(FloatToInt32((slider->GetSliderMax() - slider->GetSliderMin()) * (PlayerOptions.ObjDetailLevel - 0.5f) / (1.5f * GraphicSettingMult)));
}
slider = (C_Slider *)win->FindControl(SFX_LEVEL);
if (slider not_eq NULL)
{
ebox = (C_EditBox *)win->FindControl(SFX_LEVEL_READOUT);
if (ebox)
{
ebox->SetInteger(FloatToInt32(PlayerOptions.SfxLevel));
ebox->Refresh();
slider->SetUserNumber(0, SFX_LEVEL_READOUT);
}
slider->SetSliderPos(FloatToInt32((slider->GetSliderMax() - slider->GetSliderMin()) * (PlayerOptions.SfxLevel - 1.0F) / 4.0f));
}
slider = (C_Slider *)win->FindControl(DISAGG_LEVEL);
if (slider not_eq NULL)
{
ebox = (C_EditBox *)win->FindControl(DISAGG_LEVEL_READOUT);
if (ebox)
{
ebox->SetInteger(PlayerOptions.BldDeaggLevel + 1);
ebox->Refresh();
slider->SetUserNumber(0, DISAGG_LEVEL_READOUT);
}
slider->SetSliderPos((slider->GetSliderMax() - slider->GetSliderMin())*PlayerOptions.ObjDeaggLevel / 100);
}
slider = (C_Slider *)win->FindControl(VEHICLE_SIZE);
if (slider not_eq NULL)
{
slider->SetSliderPos(FloatToInt32((slider->GetSliderMax() - slider->GetSliderMin()) * (PlayerOptions.ObjMagnification - 1.0F) / 4.0F));
ebox = (C_EditBox *)win->FindControl(VEHICLE_SIZE_READOUT);
if (ebox)
{
ebox->SetInteger(FloatToInt32(PlayerOptions.ObjMagnification));
ebox->Refresh();
slider->SetUserNumber(0, VEHICLE_SIZE_READOUT);
}
}
/* slider=(C_Slider *)win->FindControl(TEXTURE_DISTANCE);
if(slider not_eq NULL)
{
ebox = (C_EditBox *)win->FindControl(TEX_DISTANCE_READOUT);
if(ebox)
{
ebox->SetInteger(PlayerOptions.DispTextureLevel + 1);
ebox->Refresh();
slider->SetUserNumber(0,TEX_DISTANCE_READOUT);
}
slider->SetSliderPos((slider->GetSliderMax()-slider->GetSliderMin())*(PlayerOptions.DispTextureLevel)/4);
}
*/
slider = (C_Slider *)win->FindControl(PLAYER_BUBBLE_SLIDER);
if (slider not_eq NULL)
{
ebox = (C_EditBox *)win->FindControl(PLAYER_BUBBLE_READOUT);
if (ebox)
{
PlayerOptions.PlayerBubble = min(PlayerOptions.PlayerBubble, 2.0F * GraphicSettingMult);
ebox->SetInteger(FloatToInt32((PlayerOptions.PlayerBubble - .5f) * 4.0F + 1.5F));
ebox->Refresh();
slider->SetSteps(static_cast<short>(6 * GraphicSettingMult));
slider->SetUserNumber(0, PLAYER_BUBBLE_READOUT);
}
slider->SetSliderPos(FloatToInt32((slider->GetSliderMax() - slider->GetSliderMin()) * (PlayerOptions.PlayerBubble - 0.5f) / (1.5f * GraphicSettingMult)));
}
slider = (C_Slider *)win->FindControl(TERRAIN_DETAIL);
if (slider not_eq NULL)
{
int step;
step = (slider->GetSliderMax() - slider->GetSliderMin()) / (6 * GraphicSettingMult);
slider->SetSteps(static_cast<short>(6 * GraphicSettingMult));
if (PlayerOptions.DispTerrainDist > 40)
slider->SetSliderPos(FloatToInt32(step * (2 + (PlayerOptions.DispTerrainDist - 40.0F) / 10.0F)));
else
slider->SetSliderPos((2 - PlayerOptions.DispMaxTerrainLevel)*step);
ebox = (C_EditBox *)win->FindControl(TEX_DETAIL_READOUT);
if (ebox)
{
ebox->SetInteger(FloatToInt32(((float)slider->GetSliderPos() / (slider->GetSliderMax() - slider->GetSliderMin())) * 6.0F * GraphicSettingMult + 1.5F));
ebox->Refresh();
slider->SetUserNumber(0, TEX_DETAIL_READOUT);
}
}
//ControlsTab
lbox = (C_ListBox *)win->FindControl(JOYSTICK_SELECT); //JOYSTICK_SELECT
if (lbox)
{
BuildControllerList(lbox);
extern AxisMapping AxisMap; // Retro 31Dec2003
lbox->SetValue(AxisMap.FlightControlDevice + 1); // Retro 31Dec2003
lbox->Refresh();
}
//if (S_joycaps.wCaps bitand JOYCAPS_HASZ)
if (IO.AnalogIsUsed(AXIS_THROTTLE)) // Retro 31Dec2003
{
button = (C_Button *)win->FindControl(THROTTLE_CHECK);
if (button not_eq NULL)
{
button->SetFlagBitOn(C_BIT_INVISIBLE);
button->SetState(C_STATE_1);
button->Refresh();
}
}
if (IO.AnalogIsUsed(AXIS_YAW)) // Retro 31Dec2003
{
button = (C_Button *)win->FindControl(RUDDER_CHECK);
if (button not_eq NULL)
{
button->SetFlagBitOn(C_BIT_INVISIBLE);
button->SetState(C_STATE_1);
button->Refresh();
}
}
SetRealism(win);
/* // M.N. Sky Color Stuff
#if 0
win=gMainHandler->FindWindow(SETUP_SKY_WIN);
if ( not win)
return;
lbox = (C_ListBox *) win->FindControl(SETUP_SKY_COLOR);
if (lbox)
{
lbox->SetValue(PlayerOptions.skycol);
lbox->Refresh();
}
#else
win=gMainHandler->FindWindow(SETUP_SKY_WIN);
if( not win) return;
lbox=(C_ListBox *)win->FindControl(SETUP_SKY_COLOR);
if (lbox)
{
for (int i = 0; i < NumberOfSkyColors; i++)
{
lbox->AddItem(i+1,C_TYPE_ITEM,skycolor[i].name);
}
lbox->SetValue(PlayerOptions.skycol);
lbox->Refresh();
}
#endif
*/
SetAdvanced();
// SetSkyColor();
if ( not SetupCritSection)
SetupCritSection = F4CreateCriticalSection("SetupCrit");
KeyVar.EditKey = FALSE;
}//SetupControls
void SetupRadioCB(long, short hittype, C_Base *control)
{
int i;
C_Button *button;
if (hittype not_eq C_TYPE_LMOUSEUP)
return;
/*
if(Calibration.calibrating)
{
StopCalibrating(control);
}*/
ready = FALSE;
if (SetupViewer)
{
F4EnterCriticalSection(SetupCritSection);
RViewPoint *viewpt;
viewpt = SetupViewer->GetVP();
viewpt->RemoveObject(Smoke);
delete Smoke;
Smoke = NULL;
SetupViewer->Cleanup();
delete SetupViewer;
SetupViewer = NULL;
F4LeaveCriticalSection(SetupCritSection);
button = (C_Button *)control->Parent_->FindControl(RENDER);
if (button not_eq NULL)
{
button->SetState(C_STATE_0);
}
}
InitSoundSetup();
i = 1;
while (control->GetUserNumber(i))
{
control->Parent_->HideCluster(control->GetUserNumber(i));
i++;
}
control->Parent_->UnHideCluster(control->GetUserNumber(0));
control->Parent_->RefreshWindow();
Cluster = control->GetUserNumber(0);
// Retro 31Dec2003
// haha.. ok almost no difference to the old one..
if (control->GetUserNumber(0) == 8004)
{
int hasPOV = FALSE;
extern AxisMapping AxisMap;
if ((gTotalJoy) and (AxisMap.FlightControlDevice not_eq -1))
{
DIDEVCAPS devcaps;
devcaps.dwSize = sizeof(DIDEVCAPS);
ShiAssert(FALSE == F4IsBadReadPtr(gpDIDevice[AxisMap.FlightControlDevice], sizeof * gpDIDevice[AxisMap.FlightControlDevice])); // JPO CTD
if (gpDIDevice[AxisMap.FlightControlDevice])
{
gpDIDevice[AxisMap.FlightControlDevice]->GetCapabilities(&devcaps);
if (devcaps.dwPOVs > 0)
hasPOV = TRUE;
}
}
HideKeyStatusLines(control->Parent_);
const int POVSymbols[] = { LEFT_HAT, RIGHT_HAT, CENTER_HAT, UP_HAT, DOWN_HAT };
const int POVSymbolCount = sizeof(POVSymbols) / sizeof(int);
for (int i = 0; i < POVSymbolCount; i++)
{
button = (C_Button *)control->Parent_->FindControl(POVSymbols[i]);
if (button not_eq NULL)
{
if ( not hasPOV)
button->SetFlagBitOn(C_BIT_INVISIBLE);
else
button->SetFlagBitOff(C_BIT_INVISIBLE);
button->Refresh();
}
}
}
}//SetupRadioCallback
//JAM 13Oct03
void RestartCB(long, short hittype, C_Base *control)
{
if (hittype not_eq C_TYPE_LMOUSEUP)
return;
PostMessage(gMainHandler->GetAppWnd(), FM_EXIT_GAME, 0, 0);
}
//JAM
static void SaveValues(void)
{
C_Window *win;
C_Button *button;
C_Text *text;
C_ListBox *lbox;
C_Slider *slider;
C_EditBox *ebox;
win = gMainHandler->FindWindow(SETUP_WIN);
if (win == NULL)
return;
lbox = (C_ListBox *)win->FindControl(SET_FLTMOD);
if (lbox not_eq NULL)
{
if ((lbox->GetTextID()) == SET_FLTMOD_1)
PlayerOptions.SimFlightModel = FMAccurate;
else
PlayerOptions.SimFlightModel = FMSimplified;
lbox->Refresh();
}
lbox = (C_ListBox *)win->FindControl(SET_RADAR);
if (lbox not_eq NULL)
{
switch (lbox->GetTextID())
{
// M.N. full realism mode added
case SET_RADAR_0:
PlayerOptions.SimAvionicsType = ATRealisticAV;
break;
case SET_RADAR_1:
PlayerOptions.SimAvionicsType = ATRealistic;
break;
case SET_RADAR_2:
PlayerOptions.SimAvionicsType = ATSimplified;
break;
case SET_RADAR_3:
PlayerOptions.SimAvionicsType = ATEasy;
break;
}
lbox->Refresh();
}
lbox = (C_ListBox *)win->FindControl(SET_WEAPEFF);
if (lbox not_eq NULL)
{
switch (lbox->GetTextID())
{
case SET_WEAPEFF_1:
PlayerOptions.SimWeaponEffect = WEAccurate;
break;
case SET_WEAPEFF_2:
PlayerOptions.SimWeaponEffect = WEEnhanced;
break;
case SET_WEAPEFF_3:
PlayerOptions.SimWeaponEffect = WEExaggerated;
break;
}
lbox->Refresh();
}
lbox = (C_ListBox *)win->FindControl(SET_AUTOPILOT);
if (lbox not_eq NULL)
{
switch (lbox->GetTextID())
{
case SET_AUTO_1:
PlayerOptions.SimAutopilotType = APNormal;
break;
case SET_AUTO_2:
PlayerOptions.SimAutopilotType = APEnhanced;
break;
case SET_AUTO_3:
PlayerOptions.SimAutopilotType = APIntelligent;
break;
}
lbox->Refresh();
}
lbox = (C_ListBox *)win->FindControl(SET_PADLOCK);
if (lbox not_eq NULL)
{
switch (lbox->GetTextID())
{
case SET_PADLOCK_4:
PlayerOptions.SimPadlockMode = PDDisabled;
break;
case SET_PADLOCK_1:
PlayerOptions.SimPadlockMode = PDRealistic;
break;
case SET_PADLOCK_2:
PlayerOptions.SimPadlockMode = PDEnhanced;
break;
//case SET_PADLOCK_3:
// PlayerOptions.SimPadlockMode = PDSuper;
// break;
}
lbox->Refresh();
}
lbox = (C_ListBox *)win->FindControl(SET_REFUELING);
if (lbox not_eq NULL)
{
switch (lbox->GetTextID())
{
case SET_REFUEL_1:
PlayerOptions.SimAirRefuelingMode = ARRealistic;
break;
case SET_REFUEL_2:
PlayerOptions.SimAirRefuelingMode = ARModerated;
break;
case SET_REFUEL_3:
PlayerOptions.SimAirRefuelingMode = ARSimplistic;
break;
}
lbox->Refresh();
}
lbox = (C_ListBox *)win->FindControl(SET_CANOPY_CUE);
if (lbox not_eq NULL)
{
switch (lbox->GetTextID())
{
case CUE_NONE:
PlayerOptions.SimVisualCueMode = VCNone;
break;
case CUE_LIFT_LINE:
PlayerOptions.SimVisualCueMode = VCLiftLine;
break;
case CUE_REFLECTION_MAP:
PlayerOptions.SimVisualCueMode = VCReflection;
break;
case CUE_BOTH:
PlayerOptions.SimVisualCueMode = VCBoth;
break;
}
lbox->Refresh();
}
lbox = (C_ListBox *)win->FindControl(SET_VIDEO_CARD);
if (lbox not_eq NULL)
{
DisplayOptions.DispVideoCard = static_cast<uchar>(lbox->GetTextID() - 1);
lbox->Refresh();
}
lbox = (C_ListBox *)win->FindControl(SET_VIDEO_DRIVER);
if (lbox not_eq NULL)
{
DisplayOptions.DispVideoDriver = static_cast<uchar>(lbox->GetTextID() - 1);
lbox->Refresh();
}
lbox = (C_ListBox *)win->FindControl(SET_RESOLUTION);
if (lbox not_eq NULL)
{
// OW
#if 1
UINT nWidth, nHeight, nDepth;
FalconDisplay.devmgr.GetMode(DisplayOptions.DispVideoDriver, DisplayOptions.DispVideoCard, lbox->GetTextID(),
&nWidth, &nHeight, &nDepth);
DisplayOptions.DispWidth = nWidth;
DisplayOptions.DispHeight = nHeight;
DisplayOptions.DispDepth = nDepth;
ShiAssert(DisplayOptions.DispWidth <= 1600);
FalconDisplay.SetSimMode(DisplayOptions.DispWidth, DisplayOptions.DispHeight, DisplayOptions.DispDepth); // OW
#else
DisplayOptions.DispWidth = static_cast<short>(lbox->GetTextID());
DisplayOptions.DispHeight = static_cast<ushort>(FloatToInt32(lbox->GetTextID() * 0.75F));
ShiAssert(DisplayOptions.DispWidth <= 1600);
FalconDisplay.SetSimMode(DisplayOptions.DispWidth, DisplayOptions.DispHeight, DisplayOptions.DispDepth); // OW
#endif
lbox->Refresh();
}
//JAM 20Nov03
if (TheCampaign.InMainUI)
{
lbox = (C_ListBox *)win->FindControl(SETUP_REALWEATHER);
if (lbox not_eq NULL)
{
PlayerOptions.weatherCondition = lbox->GetTextID() - 70207;
((WeatherClass *)realWeather)->UpdateCondition(PlayerOptions.weatherCondition, true);
((WeatherClass *)realWeather)->Init(true);
}
}
//JAM
//THW 2004-01-17
/* lbox=(C_ListBox *)win->FindControl(SETUP_SEASON);
if(lbox not_eq NULL)
{
//PlayerOptions.Season = lbox->GetTextID()-70312;
lbox->Refresh();
}
//THW
*/
button = (C_Button *)win->FindControl(SET_ORDNANCE);
if (button not_eq NULL)
{
if (button->GetState() == C_STATE_1)
PlayerOptions.SetSimFlag(SIM_UNLIMITED_AMMO);
else
PlayerOptions.ClearSimFlag(SIM_UNLIMITED_AMMO);
}
button = (C_Button *)win->FindControl(SET_FUEL);
if (button not_eq NULL)
{
if (button->GetState() == C_STATE_1)
PlayerOptions.SetSimFlag(SIM_UNLIMITED_FUEL);
else
PlayerOptions.ClearSimFlag(SIM_UNLIMITED_FUEL);
}
button = (C_Button *)win->FindControl(SET_CHAFFLARES);
if (button not_eq NULL)
{
if (button->GetState() == C_STATE_1)
PlayerOptions.SetSimFlag(SIM_UNLIMITED_CHAFF);
else
PlayerOptions.ClearSimFlag(SIM_UNLIMITED_CHAFF);
}
button = (C_Button *)win->FindControl(SET_COLLISIONS);
if (button not_eq NULL)
{
if (button->GetState() == C_STATE_1)
PlayerOptions.SetSimFlag(SIM_NO_COLLISIONS);
else
PlayerOptions.ClearSimFlag(SIM_NO_COLLISIONS);
}
button = (C_Button *)win->FindControl(SET_BLACKOUT);
if (button not_eq NULL)
{
if (button->GetState() == C_STATE_1)
PlayerOptions.SetSimFlag(SIM_NO_BLACKOUT);
else
PlayerOptions.ClearSimFlag(SIM_NO_BLACKOUT);
}
button = (C_Button *)win->FindControl(SET_IDTAGS);
if (button not_eq NULL)
{
if (button->GetState() == C_STATE_1)
PlayerOptions.SetSimFlag(SIM_NAMETAGS);
else
PlayerOptions.ClearSimFlag(SIM_NAMETAGS);
}
button = (C_Button *)win->FindControl(SET_BULLSEYE_CALLS);
if (button not_eq NULL)
{
if (button->GetState() == C_STATE_1)
PlayerOptions.SetSimFlag(SIM_BULLSEYE_CALLS);
else
PlayerOptions.ClearSimFlag(SIM_BULLSEYE_CALLS);
}
button = (C_Button *)win->FindControl(SET_INVULNERABILITY); //should be SET_INVULNERABLITY
if (button not_eq NULL)
{
if (button->GetState() == C_STATE_1)
PlayerOptions.SetSimFlag(SIM_INVULNERABLE);
else
PlayerOptions.ClearSimFlag(SIM_INVULNERABLE);
}
// Retro 25Dec2003
button = (C_Button *)win->FindControl(SETUP_SIM_INFOBAR);
if (button not_eq NULL)
{
if (button->GetState() == C_STATE_1)
PlayerOptions.SetInfoBar(true);
else
PlayerOptions.SetInfoBar(false);
}
// ..ends
ebox = (C_EditBox *)win->FindControl(ACMI_FILE_SIZE);
if (ebox)
{
PlayerOptions.ACMIFileSize = ebox->GetInteger();
}
button = (C_Button *)win->FindControl(AUTO_SCALE);
if (button not_eq NULL)
{
if (button->GetState() == C_STATE_1)
PlayerOptions.SetObjFlag(DISP_OBJ_DYN_SCALING);
else
PlayerOptions.ClearObjFlag(DISP_OBJ_DYN_SCALING);
}
button = (C_Button *)win->FindControl(GOUROUD); //GOUROUD
if (button not_eq NULL)
{
if (button->GetState() == C_STATE_1)
PlayerOptions.SetDispFlag(DISP_GOURAUD);
else
PlayerOptions.ClearDispFlag(DISP_GOURAUD);
}
button = (C_Button *)win->FindControl(HAZING);
if (button not_eq NULL)
{
if (button->GetState() == C_STATE_1)
PlayerOptions.SetDispFlag(DISP_HAZING);
else
PlayerOptions.ClearDispFlag(DISP_HAZING);
}
//JAM 07Dec03
button = (C_Button *)win->FindControl(SETUP_REALWEATHER_SHADOWS);
if (button not_eq NULL)
{
if (button->GetState() == C_STATE_1)
PlayerOptions.SetDispFlag(DISP_SHADOWS);
else
PlayerOptions.ClearDispFlag(DISP_SHADOWS);
}
button = (C_Button *)win->FindControl(SETUP_SPECULAR_LIGHTING);
if (button not_eq NULL)
{
if (button->GetState() == C_STATE_1)
DisplayOptions.bSpecularLighting = TRUE;
else
DisplayOptions.bSpecularLighting = FALSE;
}
/* button=(C_Button *)win->FindControl(BILINEAR_FILTERING);
if(button not_eq NULL)
{
if(button->GetState() == C_STATE_1)
PlayerOptions.SetDispFlag(DISP_BILINEAR);
else
PlayerOptions.ClearDispFlag(DISP_BILINEAR);
}
*/
/* button=(C_Button *)win->FindControl(OBJECT_TEXTURES);
if(button not_eq NULL)
{
if(button->GetState() == C_STATE_1)
PlayerOptions.ObjFlags or_eq DISP_OBJ_TEXTURES;
else
PlayerOptions.ObjFlags and_eq compl DISP_OBJ_TEXTURES;
}
*/
slider = (C_Slider *)win->FindControl(OBJECT_DETAIL);
if (slider not_eq NULL)
{
PlayerOptions.ObjDetailLevel = ((float)slider->GetSliderPos() / (slider->GetSliderMax() - slider->GetSliderMin()) * 1.5f * GraphicSettingMult + 0.5f);
}
slider = (C_Slider *)win->FindControl(SFX_LEVEL);
if (slider not_eq NULL)
{
PlayerOptions.SfxLevel = ((float)slider->GetSliderPos() / (slider->GetSliderMax() - slider->GetSliderMin()) * 4.0f + 1.0F);
}
slider = (C_Slider *)win->FindControl(PLAYER_BUBBLE_SLIDER);
if (slider not_eq NULL)
{
PlayerOptions.PlayerBubble = ((float)slider->GetSliderPos() / (slider->GetSliderMax() - slider->GetSliderMin()) * 1.5f * GraphicSettingMult + 0.5f);
FalconLocalSession->SetBubbleRatio(PlayerOptions.PlayerBubble);
}
slider = (C_Slider *)win->FindControl(DISAGG_LEVEL);
if (slider not_eq NULL)
{
PlayerOptions.BldDeaggLevel = FloatToInt32((float)slider->GetSliderPos() / (slider->GetSliderMax() - slider->GetSliderMin()) * 5 + 0.5F);
PlayerOptions.ObjDeaggLevel = FloatToInt32((float)slider->GetSliderPos() / (slider->GetSliderMax() - slider->GetSliderMin()) * 100 + 0.5F);
}
slider = (C_Slider *)win->FindControl(VEHICLE_SIZE);
if (slider not_eq NULL)
{
PlayerOptions.ObjMagnification = static_cast<float>(FloatToInt32((float)slider->GetSliderPos() / (float)(slider->GetSliderMax() - slider->GetSliderMin()) * 4.0F + 1.0F));
}
/* slider=(C_Slider *)win->FindControl(TEXTURE_DISTANCE);
if(slider not_eq NULL)
{
PlayerOptions.DispTextureLevel = FloatToInt32((float)slider->GetSliderPos()/(slider->GetSliderMax()-slider->GetSliderMin()) * 4.0F + 0.5F);
}
*/
slider = (C_Slider *)win->FindControl(TERRAIN_DETAIL);
if (slider not_eq NULL)
{
int step;
step = (slider->GetSliderMax() - slider->GetSliderMin()) / (6 * GraphicSettingMult);
if (slider->GetSliderPos() > 2 * step)
{
PlayerOptions.DispTerrainDist = (40.0f + (((float)slider->GetSliderPos()) / step - 2) * 10.0f);
PlayerOptions.DispMaxTerrainLevel = 0;
}
else
{
PlayerOptions.DispTerrainDist = 40.0f;
PlayerOptions.DispMaxTerrainLevel = FloatToInt32(max(0.0F, 2.0F - slider->GetSliderPos() / step) + 0.5F);
}
}
text = (C_Text *)win->FindControl(CAL_TEXT);
if (text not_eq NULL)
text->SetText("");
button = (C_Button *) win->FindControl(PLAYERVOICE);
if (button) PlayerOptions.PlayerRadioVoice = (button->GetState() == C_STATE_1);
button = (C_Button *) win->FindControl(UICOMMS);
if (button) PlayerOptions.UIComms = (button->GetState() == C_STATE_1);
double pos, range;
int volume, i;
for (i = 0; i < 17; i += 2)
{
slider = (C_Slider *)win->FindControl(ENGINE_VOLUME + i);
if (slider)
{
pos = slider->GetSliderPos();
range = slider->GetSliderMax() - slider->GetSliderMin();
pos = (1.0F - pos / range);
volume = (int)(pos * pos * (SND_RNG));
PlayerOptions.GroupVol[i / 2] = volume;
F4SetGroupVolume(i / 2, volume);
}
}
PlayerOptions.Realism = GetRealism(win) / 100.0f;
win = gMainHandler->FindWindow(SETUP_ADVANCED_WIN);
if ( not win) return;
//JAM 28Oct03
button = (C_Button *)win->FindControl(SETUP_ADVANCED_ANISOTROPIC_FILTERING);
if (button) DisplayOptions.bAnisotropicFiltering = button->GetState() == C_STATE_1;
button = (C_Button *)win->FindControl(SETUP_ADVANCED_RENDER_2DCOCKPIT);
if (button) DisplayOptions.bRender2DCockpit = button->GetState() == C_STATE_1;
button = (C_Button *)win->FindControl(SETUP_ADVANCED_SCREEN_COORD_BIAS_FIX);
if (button) DisplayOptions.bScreenCoordinateBiasFix = button->GetState() == C_STATE_1; //Wombat778 4-01-04
// button = (C_Button *)win->FindControl(SETUP_ADVANCED_SPECULAR_LIGHTING);
// if(button) DisplayOptions.bSpecularLighting = button->GetState() == C_STATE_1;
button = (C_Button *)win->FindControl(SETUP_ADVANCED_LINEAR_MIPMAP_FILTERING);
if (button) DisplayOptions.bLinearMipFiltering = button->GetState() == C_STATE_1;
button = (C_Button *)win->FindControl(SETUP_ADVANCED_MIPMAPPING);
if (button) DisplayOptions.bMipmapping = button->GetState() == C_STATE_1;
button = (C_Button *) win->FindControl(SETUP_ADVANCED_RENDER_TO_TEXTURE);
if (button) DisplayOptions.bRender2Texture = button->GetState() == C_STATE_1;
//========================================
// FRB - Force Z-Buffering
DisplayOptions.bZBuffering = TRUE;
// FRB - Force Specular Lighting
// DisplayOptions.bSpecularLighting = TRUE;
// DDS textures only
// DisplayOptions.m_texMode = TEX_MODE_DDS;
//========================================
PlayerOptions.SaveOptions();
DisplayOptions.SaveOptions();
SaveKeyMapList(PlayerOptions.keyfile);
win = gMainHandler->FindWindow(INFO_WIN);
if (win)
{
INFOSetupControls();
}
}//SaveValues
void ShutdownSetup()
{
if (Objects)
{
delete [] Objects;
Objects = NULL;
}
if (Features)
{
delete [] Features;
Features = NULL;
}
if (SetupViewer)
{
ready = FALSE;
F4EnterCriticalSection(SetupCritSection);
RViewPoint *viewpt;
viewpt = SetupViewer->GetVP();
viewpt->RemoveObject(Smoke);
delete Smoke;
Smoke = NULL;
SetupViewer->Cleanup();
delete SetupViewer;
SetupViewer = NULL;
F4LeaveCriticalSection(SetupCritSection);
}
if (tmpVpoint)
{
tmpVpoint->Cleanup();
tmpVpoint = NULL;
}
F4EnterCriticalSection(SetupCritSection);
F4LeaveCriticalSection(SetupCritSection);
if (SetupCritSection)
{
F4DestroyCriticalSection(SetupCritSection);
SetupCritSection = NULL;
}
}
void CloseSetupWindowCB(long ID, short hittype, C_Base *control)
{
C_Button *button;
if (hittype not_eq C_TYPE_LMOUSEUP)
return;
ShutdownSetup();
PlayerOptions.LoadOptions();
InitSoundSetup();
/*
if(Calibration.calibrating)
StopCalibrating(control);*/
button = (C_Button *)control->Parent_->FindControl(RENDER);
if (button not_eq NULL)
{
button->SetState(C_STATE_0);
}
UpdateKeyMapList(PlayerOptions.keyfile, USE_FILENAME);
CloseWindowCB(ID, hittype, control);
}//CloseSetupWindowCB
//JAM 27Oct03
void DoSyncWindowCB(long ID, short hittype, C_Base *control)
{
// C_Window *win;
/*
if(hittype not_eq C_TYPE_LMOUSEUP)
return;
if( DisplayOptions.m_texMode == DisplayOptionsClass::TEX_MODE_DDS )
{
TheTextureBank.FlushHandles();
TheTextureBank.RestoreTexturePool();
TheTerrTextures.FlushHandles();
TheFarTextures.FlushHandles();
win = gMainHandler->FindWindow(SYNC_WIN);
if( win )
{
gMainHandler->ShowWindow(win);
gMainHandler->WindowToFront(win);
}
TheTextureBank.SyncDDSTextures();
TheTerrTextures.SyncDDSTextures();
TheFarTextures.SyncDDSTextures();
TheTerrTextures.FlushHandles();
TheFarTextures.FlushHandles();
// gMainHandler->HideWindow(win);
}
*/
}
//JAM
void SetupOkCB(long ID, short hittype, C_Base *control)
{
C_Button *button;
if (hittype not_eq C_TYPE_LMOUSEUP)
return;
SaveValues();
InitSoundSetup();
CheckFlyButton();
ShutdownSetup();
/*
if(Calibration.calibrating)
StopCalibrating(control);*/
button = (C_Button *)control->Parent_->FindControl(RENDER);
if (button not_eq NULL)
{
button->SetState(C_STATE_0);
}
CloseWindowCB(ID, hittype, control);
}//SetupOkCB
//JAM 28Oct03
void AApplySetupCB(long ID, short hittype, C_Base *control)
{
if (hittype not_eq C_TYPE_LMOUSEUP)
return;
SaveValues();
CloseWindowCB(ID, hittype, control);
}
//JAM
void ApplySetupCB(long, short hittype, C_Base *)
{
if (hittype not_eq C_TYPE_LMOUSEUP)
return;
SaveValues();
CheckFlyButton();
}//ApplySetupCB
void CancelSetupCB(long ID, short hittype, C_Base *control)
{
C_Button *button;
if (hittype not_eq C_TYPE_LMOUSEUP)
return;
ShutdownSetup();
PlayerOptions.LoadOptions();
InitSoundSetup();
/*
if(Calibration.calibrating)
StopCalibrating(control);*/
button = (C_Button *)control->Parent_->FindControl(RENDER);
if (button not_eq NULL)
{
button->SetState(C_STATE_0);
}
UpdateKeyMapList(PlayerOptions.keyfile, USE_FILENAME);
CloseWindowCB(ID, hittype, control);
} //CancelSetupCB
static void HookupSetupControls(long ID)
{
C_Window *win;
C_Button *button;
C_Slider *slider;
C_ListBox *listbox;
win = gMainHandler->FindWindow(ID);
if (win == NULL)
return;
// Help GUIDE thing
button = (C_Button*)win->FindControl(UI_HELP_GUIDE);
if (button)
button->SetCallback(UI_Help_Guide_CB);
// Hook up IDs here
// Hook up Close Button
button = (C_Button *)win->FindControl(CLOSE_WINDOW);
if (button not_eq NULL)
button->SetCallback(CloseSetupWindowCB);
//JAM 24Oct03
// button=(C_Button *)win->FindControl(DO_SYNC);
// if(button not_eq NULL)
// button->SetCallback(DoSyncWindowCB);
button = (C_Button *)win->FindControl(OK);
if (button not_eq NULL)
button->SetCallback(SetupOkCB);
button = (C_Button *)win->FindControl(APPLY);
if (button not_eq NULL)
button->SetCallback(ApplySetupCB);
button = (C_Button *)win->FindControl(CANCEL);
if (button not_eq NULL)
button->SetCallback(CancelSetupCB);
button = (C_Button *)win->FindControl(SET_LOGBOOK);
if (button not_eq NULL)
button->SetCallback(SetupOpenLogBookCB);
button = (C_Button *)win->FindControl(SIM_TAB);
if (button not_eq NULL)
button->SetCallback(SetupRadioCB);
button = (C_Button *)win->FindControl(GRAPHICS_TAB);
if (button not_eq NULL)
button->SetCallback(SetupRadioCB);
button = (C_Button *)win->FindControl(SOUND_TAB);
if (button not_eq NULL)
button->SetCallback(SetupRadioCB);
button = (C_Button *)win->FindControl(CONTROLLERS_TAB);
if (button not_eq NULL)
button->SetCallback(SetupRadioCB);
//Sim Tab
listbox = (C_ListBox *)win->FindControl(SET_SKILL);
if (listbox not_eq NULL)
listbox->SetCallback(SetSkillCB);
listbox = (C_ListBox *)win->FindControl(SET_FLTMOD);
if (listbox not_eq NULL)
listbox->SetCallback(SimControlCB);
listbox = (C_ListBox *)win->FindControl(SET_RADAR);
if (listbox not_eq NULL)
listbox->SetCallback(SimControlCB);
listbox = (C_ListBox *)win->FindControl(SET_WEAPEFF);
if (listbox not_eq NULL)
listbox->SetCallback(SimControlCB);
listbox = (C_ListBox *)win->FindControl(SET_AUTOPILOT);
if (listbox not_eq NULL)
listbox->SetCallback(SimControlCB);
listbox = (C_ListBox *)win->FindControl(SET_REFUELING);
if (listbox not_eq NULL)
listbox->SetCallback(SimControlCB);
listbox = (C_ListBox *)win->FindControl(SET_PADLOCK);
if (listbox not_eq NULL)
listbox->SetCallback(SimControlCB);
button = (C_Button *)win->FindControl(SET_INVULNERABILITY);
if (button not_eq NULL)
button->SetCallback(SimControlCB);
button = (C_Button *)win->FindControl(SET_FUEL);
if (button not_eq NULL)
button->SetCallback(SimControlCB);
button = (C_Button *)win->FindControl(SET_CHAFFLARES);
if (button not_eq NULL)
button->SetCallback(SimControlCB);
button = (C_Button *)win->FindControl(SET_COLLISIONS);
if (button not_eq NULL)
button->SetCallback(SimControlCB);
button = (C_Button *)win->FindControl(SET_BLACKOUT);
if (button not_eq NULL)
button->SetCallback(SimControlCB);
button = (C_Button *)win->FindControl(SET_IDTAGS);
if (button not_eq NULL)
button->SetCallback(SimControlCB);
//Controllers Tab
//button=(C_Button *)win->FindControl(SET_DEFAULTS);
//if(button not_eq NULL)
// button->SetCallback(SetKeyDefaultCB);
button = (C_Button *)win->FindControl(CALIBRATE);
if (button not_eq NULL)
button->SetCallback(RecenterJoystickCB);
button = (C_Button *)win->FindControl(SET_AB_DETENT);
if (button not_eq NULL)
button->SetCallback(SetABDetentCB);
button = (C_Button *)win->FindControl(KEYMAP_SAVE);
if (button not_eq NULL)
button->SetCallback(SaveKeyButtonCB);
button = (C_Button *)win->FindControl(KEYMAP_LOAD);
if (button not_eq NULL)
button->SetCallback(LoadKeyButtonCB);
win->SetKBCallback(KeystrokeCB);
listbox = (C_ListBox *)win->FindControl(70137);//JOYSTICK_SELECT
if (listbox not_eq NULL)
listbox->SetCallback(ControllerSelectCB);
// Retro 31Dec2003 - callback function for the new advanced controls button
button = (C_Button *)win->FindControl(SETUP_CONTROL_ADVANCED);
if (button not_eq NULL)
button->SetCallback(AdvancedControlCB);
//Sound Tab
button = (C_Button*)win->FindControl(ENGINE_SND);
if (button)
button->SetCallback(TestButtonCB);
button = (C_Button*)win->FindControl(SIDEWINDER_SND);
if (button)
button->SetCallback(TestButtonCB);
button = (C_Button*)win->FindControl(RWR_SND);
if (button)
button->SetCallback(TestButtonCB);
button = (C_Button*)win->FindControl(COCKPIT_SND);
if (button)
button->SetCallback(TestButtonCB);
button = (C_Button*)win->FindControl(COM1_SND);
if (button)
button->SetCallback(TestButtonCB);
button = (C_Button*)win->FindControl(COM2_SND);
if (button)
button->SetCallback(TestButtonCB);
button = (C_Button*)win->FindControl(SOUNDFX_SND);
if (button)
button->SetCallback(TestButtonCB);
button = (C_Button*)win->FindControl(UISOUNDFX_SND);
if (button)
button->SetCallback(TestButtonCB);
// M.N.
button = (C_Button *)win->FindControl(PLAYERVOICE);
if (button not_eq NULL)
button->SetCallback(TogglePlayerVoiceCB);
button = (C_Button *)win->FindControl(UICOMMS);
if (button not_eq NULL)
button->SetCallback(ToggleUICommsCB);
slider = (C_Slider*)win->FindControl(ENGINE_VOLUME);
if (slider)
slider->SetCallback(SoundSliderCB);
slider = (C_Slider*)win->FindControl(SIDEWINDER_VOLUME);
if (slider)
slider->SetCallback(SoundSliderCB);
slider = (C_Slider*)win->FindControl(RWR_VOLUME);
if (slider)
slider->SetCallback(SoundSliderCB);
slider = (C_Slider*)win->FindControl(COCKPIT_VOLUME);
if (slider)
slider->SetCallback(SoundSliderCB);
slider = (C_Slider*)win->FindControl(COM1_VOLUME);
if (slider)
slider->SetCallback(SoundSliderCB);
slider = (C_Slider*)win->FindControl(COM2_VOLUME);
if (slider)
slider->SetCallback(SoundSliderCB);
slider = (C_Slider*)win->FindControl(SOUNDFX_VOLUME);
if (slider)
slider->SetCallback(SoundSliderCB);
slider = (C_Slider*)win->FindControl(UISOUNDFX_VOLUME);
if (slider)
slider->SetCallback(SoundSliderCB);
slider = (C_Slider*)win->FindControl(MUSIC_VOLUME);
if (slider)
slider->SetCallback(SoundSliderCB);
slider = (C_Slider*)win->FindControl(MASTER_VOLUME);
if (slider)
slider->SetCallback(SoundSliderCB);
//Graphics Tab
if (ID == SETUP_WIN)
{
C_TimerHook *tmr;
tmr = new C_TimerHook;
tmr->Setup(C_DONT_CARE, C_TYPE_NORMAL);
tmr->SetClient(2);
tmr->SetXY(win->ClientArea_[2].left, win->ClientArea_[2].top);
tmr->SetW(win->ClientArea_[2].right - win->ClientArea_[2].left);
tmr->SetH(win->ClientArea_[2].bottom - win->ClientArea_[2].top);
tmr->SetUpdateCallback(STPViewTimerCB);
tmr->SetDrawCallback(STPDisplayCB);
tmr->SetFlagBitOff(C_BIT_TIMER);
tmr->SetCluster(8002);
// tmr->SetUserNumber(1,2);
tmr->SetReady(1);
win->AddControl(tmr);
win->SetDragCallback(STPMoveRendererCB);
}
listbox = (C_ListBox *)win->FindControl(SET_VIDEO_CARD);
if (listbox not_eq NULL)
listbox->SetCallback(VideoCardCB);
listbox = (C_ListBox *)win->FindControl(SET_VIDEO_DRIVER);
if (listbox not_eq NULL)
listbox->SetCallback(VideoDriverCB);
listbox = (C_ListBox *)win->FindControl(SET_RESOLUTION);
if (listbox not_eq NULL)
listbox->SetCallback(ResolutionCB);
//JAM 20Nov03
listbox = (C_ListBox *)win->FindControl(SETUP_REALWEATHER);
if (listbox not_eq NULL)
listbox->SetCallback(RealWeatherCB);
//JAM
/*
//THW 2004-01-17
listbox = (C_ListBox *)win->FindControl(SETUP_SEASON);
if(listbox not_eq NULL)
listbox->SetCallback(SeasonCB);
//THW
*/
button = (C_Button *)win->FindControl(SET_GRAPHICS_DEFAULTS);
if (button not_eq NULL)
{
button->SetCallback(GraphicsDefaultsCB);
}
// OW
button = (C_Button *)win->FindControl(SET_GRAPHICS_ADVANCED);
if (button not_eq NULL)
{
button->SetCallback(AdvancedCB);
}
// JPO
button = (C_Button *)win->FindControl(ADVANCED_GAME_OPTIONS);
if (button not_eq NULL)
{
button->SetCallback(AdvancedGameCB);
}
// M.N.
/* button=(C_Button *)win->FindControl(SET_SKY_COLOR);
if(button not_eq NULL)
{
button->SetCallback(SkyColorCB);
}
*/
button = (C_Button *)win->FindControl(RENDER);
if (button not_eq NULL)
{
button->SetCallback(RenderViewCB);
}
button = (C_Button *)win->FindControl(AUTO_SCALE);
if (button not_eq NULL)
{
button->SetCallback(ScalingCB);
}
// Retro 25Dec2003
button = (C_Button*)win->FindControl(SETUP_SIM_SUBTITLES);
if (button not_eq NULL)
{
button->SetCallback(SubTitleCB);
}
// ..ends
/* button=(C_Button *)win->FindControl(70136);//GOUROUD
if(button not_eq NULL)
{
button->SetCallback(GouraudCB);
}
*/
button = (C_Button *)win->FindControl(HAZING);
if (button not_eq NULL)
{
button->SetCallback(HazingCB);
}
button = (C_Button *)win->FindControl(SETUP_REALWEATHER_SHADOWS);
if (button not_eq NULL)
{
button->SetCallback(RealWeatherShadowsCB);
}
/*
button=(C_Button *)win->FindControl(BILINEAR_FILTERING);
if(button not_eq NULL)
{
button->SetCallback(BilinearFilterCB);
}
*/
/* button=(C_Button *)win->FindControl(OBJECT_TEXTURES);
if(button not_eq NULL)
{
button->SetCallback(ObjectTextureCB);
}
*/
slider = (C_Slider *)win->FindControl(DISAGG_LEVEL);
if (slider not_eq NULL)
{
slider->SetCallback(BuildingDetailCB);
}
slider = (C_Slider *)win->FindControl(OBJECT_DETAIL);
if (slider not_eq NULL)
{
slider->SetCallback(ObjectDetailCB);
}
slider = (C_Slider *)win->FindControl(PLAYER_BUBBLE_SLIDER);
if (slider not_eq NULL)
{
slider->SetCallback(PlayerBubbleCB);
}
slider = (C_Slider *)win->FindControl(VEHICLE_SIZE);
if (slider not_eq NULL)
{
slider->SetCallback(VehicleSizeCB);
}
slider = (C_Slider *)win->FindControl(TERRAIN_DETAIL);
if (slider not_eq NULL)
{
slider->SetCallback(TerrainDetailCB);
}
/* slider=(C_Slider *)win->FindControl(TEXTURE_DISTANCE);
if(slider not_eq NULL)
{
slider->SetCallback(TextureDistanceCB);
}
*/
slider = (C_Slider *)win->FindControl(SFX_LEVEL);
if (slider not_eq NULL)
{
slider->SetCallback(SfxLevelCB);
}
// OW new stuff
win = gMainHandler->FindWindow(SETUP_ADVANCED_WIN);
if ( not win) return;
// disable parent notification for close and cancel button
button = (C_Button *)win->FindControl(AAPPLY);
if (button) button->SetCallback(AApplySetupCB);
button = (C_Button *)win->FindControl(CANCEL);
if (button) button->SetCallback(CloseWindowCB);
// OW end of new stuff
// M.N. SkyColor stuff
/* win = gMainHandler->FindWindow(SETUP_SKY_WIN);
if( not win) return;
// disable parent notification for close and cancel button
listbox=(C_ListBox *)win->FindControl(SETUP_SKY_COLOR);
if(listbox) listbox->SetCallback(SelectSkyColorCB);
button=(C_Button *)win->FindControl(CANCEL);
if(button) button->SetCallback(CloseWindowCB);
button=(C_Button *)win->FindControl(SKY_COLOR_TIME_1);
if(button) button->SetCallback(SkyColTimeCB);
button=(C_Button *)win->FindControl(SKY_COLOR_TIME_2);
if(button) button->SetCallback(SkyColTimeCB);
button=(C_Button *)win->FindControl(SKY_COLOR_TIME_3);
if(button) button->SetCallback(SkyColTimeCB);
button=(C_Button *)win->FindControl(SKY_COLOR_TIME_4);
if(button) button->SetCallback(SkyColTimeCB);
// M.N. end SkyColor stuff
*/
// disable parent notification for close and cancel button
button = (C_Button *)win->FindControl(CANCEL);
if (button) button->SetCallback(CloseWindowCB);
}
//HookupSetupControls
|
.MODEL SMALL
.STACK 100H
.DATA
X DB "YES$"
Y DB "NO$"
O DB 0DH,0AH,"OUTPUT: $"
MSG1 DB 'INPUT: $'
SUM DB 0
.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX
MOV AX,@DATA
MOV DS,AX
LEA DX,MSG1
MOV AH,9
INT 21H
XOR CX,CX
AND AX,0
MOV AX,0
PUSH AX
MOREINPUT:
MOV AH,1
INT 21H
CMP AL,0DH
JE BREAKTHELOOP
SUB AL,30H
ADD SUM,AL
AND AH,0
AND BX,0
MOV BL,AL
AND AX,0
POP AX
MOV CX,10
MUL CX
ADD AX,BX
PUSH AX
JMP MOREINPUT
BREAKTHELOOP:
AND AX,0
POP BX
MOV AX,BX
DIV SUM
CMP AH,0
JE OUTPUT_X
LEA DX,O
MOV AH,9
INT 21H
LEA DX,Y
MOV AH,9
INT 21H
JMP EXIT
OUTPUT_X:
LEA DX,O
MOV AH,9
INT 21H
LEA DX,X
MOV AH,9
INT 21H
EXIT:
MOV AH,4CH
INT 21H
END MAIN
|
; A248232: Numbers k such that A248231(k+1) = A248231(k).
; 1,4,8,11,15,18,22,25,28,32,35,39,42,46,49,52,56,59,63,66,69,73,76,80,83,87,90,93,97,100,104,107,110,114,117,121,124,128,131,134,138,141,145,148,151,155,158,162,165,168,172,175,179,182,186,189,192,196,199,203,206,209,213,216,220,223,227,230,233,237,240,244,247,250,254,257,261,264,268,271,274,278,281,285,288,291,295,298,302,305,308,312,315,319,322,326,329,332,336,339,343,346,349,353,356,360,363,367,370,373,377,380,384,387,390,394,397,401,404,407,411,414,418,421,425,428,431,435,438,442,445,448,452,455,459,462,466,469,472,476,479,483,486,489,493,496,500,503,507,510,513,517,520,524,527,530,534,537,541,544,547,551,554,558,561,565,568,571,575,578,582,585,588,592,595,599,602,606,609,612,616,619,623,626,629,633,636,640,643,646,650,653,657,660,664,667,670,674,677,681,684,687,691,694,698,701,705,708,711,715,718,722,725,728,732,735,739,742,746,749,752,756,759,763,766,769,773,776,780,783,786,790,793,797,800,804,807,810,814,817,821,824,827,831,834,838,841,845,848,851
mov $14,$0
mov $16,$0
add $16,1
lpb $16,1
mov $0,$14
sub $16,1
sub $0,$16
mov $10,$0
mov $12,2
lpb $12,1
clr $0,10
mov $0,$10
sub $12,1
add $0,$12
sub $0,1
mov $2,$0
pow $2,2
mov $3,$0
mov $7,$0
lpb $2,1
lpb $4,1
mov $0,2
mov $4,$3
mul $4,2
sub $2,$4
add $3,1
lpe
add $4,$0
add $0,1
trn $2,1
trn $4,4
add $4,2
lpe
mov $1,$3
add $1,$7
mov $13,$12
lpb $13,1
mov $11,$1
sub $13,1
lpe
lpe
lpb $10,1
mov $10,0
sub $11,$1
lpe
mov $1,$11
add $1,1
add $15,$1
lpe
mov $1,$15
|
; A016793: a(n) = (3*n + 2)^5.
; 32,3125,32768,161051,537824,1419857,3200000,6436343,11881376,20511149,33554432,52521875,79235168,115856201,164916224,229345007,312500000,418195493,550731776,714924299,916132832,1160290625,1453933568,1804229351,2219006624,2706784157,3276800000,3939040643,4704270176,5584059449,6590815232,7737809375,9039207968,10510100501,12166529024,14025517307,16105100000,18424351793,21003416576,23863536599,27027081632,30517578125,34359738368,38579489651,43204003424,48261724457,53782400000,59797108943
mul $0,3
add $0,2
pow $0,5
|
; A060432: Partial sums of A002024.
; 1,3,5,8,11,14,18,22,26,30,35,40,45,50,55,61,67,73,79,85,91,98,105,112,119,126,133,140,148,156,164,172,180,188,196,204,213,222,231,240,249,258,267,276,285,295,305,315,325,335,345,355,365,375,385,396,407,418,429,440,451,462,473,484,495,506,518,530,542,554,566,578,590,602,614,626,638,650,663,676,689,702,715,728,741,754,767,780,793,806,819,833,847,861,875,889,903,917,931,945,959,973,987,1001,1015,1030,1045,1060,1075,1090,1105,1120,1135,1150,1165,1180,1195,1210,1225,1240,1256,1272,1288,1304,1320,1336,1352,1368,1384,1400,1416,1432,1448,1464,1480,1496,1513,1530,1547,1564,1581,1598,1615,1632,1649,1666,1683,1700,1717,1734,1751,1768,1785,1803,1821,1839,1857,1875,1893,1911,1929,1947,1965,1983,2001,2019,2037,2055,2073,2091,2109,2128,2147,2166,2185,2204,2223,2242,2261,2280,2299,2318,2337,2356,2375,2394,2413,2432,2451,2470,2490,2510,2530,2550,2570,2590,2610,2630,2650,2670,2690,2710,2730,2750,2770,2790,2810,2830,2850,2870,2891,2912,2933,2954,2975,2996,3017,3038,3059,3080,3101,3122,3143,3164,3185,3206,3227,3248,3269,3290,3311,3333,3355,3377,3399,3421,3443,3465,3487,3509,3531,3553,3575,3597,3619,3641,3663,3685,3707,3729
add $0,1
lpb $0
add $1,$0
add $2,1
trn $0,$2
lpe
|
; A213370: a(n) = n AND 2*n, where AND is the bitwise AND operator.
; Coded manually 2021-04-21 by Simon Strandgaard, https://github.com/neoneye
; 0,0,0,2,0,0,4,6,0,0,0,2,8,8,12,14,0,0,0,2,0,0,4,6,16,16,16,18,24,24,28,30,0,0,0,2,0,0,4,6,0,0,0,2,8,8,12,14,32,32,32,34,32,32,36,38,48,48,48,50,56,56,60,62,0,0,0,2,0,0,4,6,0,0,0,2,8,8,12,14,0,0,0,2,0,0,4,6,16,16,16,18,24,24,28,30,64,64,64,66,64,64,68,70,64,64,64,66,72,72,76,78,96,96,96,98,96,96,100,102,112,112,112,114,120,120,124,126,0,0,0,2,0,0,4,6,0,0,0,2,8,8,12,14,0,0,0,2,0,0,4,6,16,16,16,18,24,24,28,30,0,0,0,2,0,0,4,6,0,0,0,2,8,8,12,14,32,32,32,34,32,32,36,38,48,48,48,50,56,56,60,62,128,128,128,130,128,128,132,134,128,128,128,130,136,136,140,142,128,128,128,130,128,128,132,134,144,144,144,146,152,152,156,158,192,192,192,194,192,192,196,198,192,192,192,194,200,200,204,206,224,224,224,226,224,224,228,230,240,240
mul $0,2 ; Now $0 holds n*2.
mov $2,1 ; Inital scale factor
lpb $0
; Do bitwise AND with the lowest bit
mov $3,$0
div $0,2 ; Remove the lowest bit from n
mul $3,$0
mod $3,2
; Now $3 holds BIT1($0) & BIT0($0)
; Scale up the bit, and add to result
mul $3,$2
add $1,$3
mul $2,2 ; Double the scale factor. Example: 1,2,4,8,16,32
lpe
mov $0,$1
|
/******************************************************************************
*
* Project: ADAGUC Server
* Purpose: ADAGUC OGC Server
* Author: Maarten Plieger, plieger "at" knmi.nl
* Date: 2013-06-01
*
******************************************************************************
*
* Copyright 2013, Royal Netherlands Meteorological Institute (KNMI)
*
* 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.
*
******************************************************************************/
/*
*
* http://datagenetics.com/blog/august32013/index.html
*
*/
#include "CAreaMapper.h"
const char *CAreaMapper::className = "CAreaMapper";
void CAreaMapper::init(CDataSource *dataSource, CDrawImage *drawImage, int tileWidth, int tileHeight) {
this->dataSource = dataSource;
this->drawImage = drawImage;
dfTileWidth = double(tileWidth);
dfTileHeight = double(tileHeight);
for (int k = 0; k < 4; k++) {
dfSourceBBOX[k] = dataSource->dfBBOX[k];
dfImageBBOX[k] = dataSource->dfBBOX[k];
}
/* Look whether BBOX was swapped in y dir */
if (dataSource->dfBBOX[3] < dataSource->dfBBOX[1]) {
dfSourceBBOX[1] = dataSource->dfBBOX[3];
dfSourceBBOX[3] = dataSource->dfBBOX[1];
}
/* Look whether BBOX was swapped in x dir */
if (dataSource->dfBBOX[2] < dataSource->dfBBOX[0]) {
dfSourceBBOX[0] = dataSource->dfBBOX[2];
dfSourceBBOX[2] = dataSource->dfBBOX[0];
}
debug = false;
if (dataSource->cfgLayer->TileSettings.size() == 1) {
if (dataSource->cfgLayer->TileSettings[0]->attr.debug.equals("true")) {
debug = true;
}
}
CStyleConfiguration *styleConfiguration = dataSource->getStyle();
dfNodataValue = dataSource->getDataObject(0)->dfNodataValue;
legendValueRange = styleConfiguration->hasLegendValueRange;
legendLowerRange = styleConfiguration->legendLowerRange;
legendUpperRange = styleConfiguration->legendUpperRange;
hasNodataValue = dataSource->getDataObject(0)->hasNodataValue;
width = dataSource->dWidth;
height = dataSource->dHeight;
legendLog = styleConfiguration->legendLog;
if (legendLog > 0) {
legendLogAsLog = log10(legendLog);
} else {
legendLogAsLog = 0;
}
legendScale = styleConfiguration->legendScale;
legendOffset = styleConfiguration->legendOffset;
internalWidth = width;
internalHeight = height;
}
int CAreaMapper::drawTile(double *x_corners, double *y_corners, int &dDestX, int &dDestY) {
CDFType dataType = dataSource->getDataObject(0)->cdfVariable->getType();
void *data = dataSource->getDataObject(0)->cdfVariable->data;
switch (dataType) {
case CDF_CHAR:
return myDrawRawTile((const char *)data, x_corners, y_corners, dDestX, dDestY);
break;
case CDF_BYTE:
return myDrawRawTile((const char *)data, x_corners, y_corners, dDestX, dDestY);
break;
case CDF_UBYTE:
return myDrawRawTile((const unsigned char *)data, x_corners, y_corners, dDestX, dDestY);
break;
case CDF_SHORT:
return myDrawRawTile((const short *)data, x_corners, y_corners, dDestX, dDestY);
break;
case CDF_USHORT:
return myDrawRawTile((const ushort *)data, x_corners, y_corners, dDestX, dDestY);
break;
case CDF_INT:
return myDrawRawTile((const int *)data, x_corners, y_corners, dDestX, dDestY);
break;
case CDF_UINT:
return myDrawRawTile((const uint *)data, x_corners, y_corners, dDestX, dDestY);
break;
case CDF_FLOAT:
return myDrawRawTile((const float *)data, x_corners, y_corners, dDestX, dDestY);
break;
case CDF_DOUBLE:
return myDrawRawTile((const double *)data, x_corners, y_corners, dDestX, dDestY);
break;
}
return 1;
}
template <class T> int CAreaMapper::myDrawRawTile(const T *data, double *x_corners, double *y_corners, int &dDestX, int &dDestY) {
int imageWidth = drawImage->getWidth();
int imageHeight = drawImage->getHeight();
int k;
for (k = 0; k < 4; k++) {
if (fabs(x_corners[k] - x_corners[0]) >= fabs(dfSourceBBOX[2] - dfSourceBBOX[0])) break;
}
if (k == 4) {
for (k = 0; k < 4; k++) {
if (x_corners[k] > dfSourceBBOX[0] && x_corners[k] < dfSourceBBOX[2]) break;
}
if (k == 4) {
return __LINE__;
}
}
for (k = 0; k < 4; k++) {
if (fabs(y_corners[k] - y_corners[0]) >= fabs(dfSourceBBOX[3] - dfSourceBBOX[1])) break;
}
if (k == 4) {
for (k = 0; k < 4; k++) {
if (y_corners[k] > dfSourceBBOX[1] && y_corners[k] < dfSourceBBOX[3]) break;
}
if (k == 4) {
return __LINE__;
}
}
bool isNodata = false;
T val;
T nodataValue = (T)dfNodataValue;
size_t imgpointer;
double destBoxTL[2] = {x_corners[3], y_corners[3]};
double destBoxTR[2] = {x_corners[0], y_corners[0]};
double destBoxBL[2] = {x_corners[2], y_corners[2]};
double destBoxBR[2] = {x_corners[1], y_corners[1]};
double sourceBBOXWidth = dfImageBBOX[2] - dfImageBBOX[0];
double sourceBBOXHeight = dfImageBBOX[1] - dfImageBBOX[3];
double sourceWidth = double(width);
double sourceHeight = double(height);
double destPXTL[2] = {((destBoxTL[0] - dfImageBBOX[0]) / sourceBBOXWidth) * sourceWidth, ((destBoxTL[1] - dfImageBBOX[3]) / sourceBBOXHeight) * sourceHeight};
double destPXTR[2] = {((destBoxTR[0] - dfImageBBOX[0]) / sourceBBOXWidth) * sourceWidth, ((destBoxTR[1] - dfImageBBOX[3]) / sourceBBOXHeight) * sourceHeight};
double destPXBL[2] = {((destBoxBL[0] - dfImageBBOX[0]) / sourceBBOXWidth) * sourceWidth, ((destBoxBL[1] - dfImageBBOX[3]) / sourceBBOXHeight) * sourceHeight};
double destPXBR[2] = {((destBoxBR[0] - dfImageBBOX[0]) / sourceBBOXWidth) * sourceWidth, ((destBoxBR[1] - dfImageBBOX[3]) / sourceBBOXHeight) * sourceHeight};
for (double dstpixel_y = 0.5; dstpixel_y < dfTileHeight + 0.5; dstpixel_y++) {
/* Calculate left and right ribs of source image, leftLineY and rightLineY follow the ribs according to dstpixel_y */
double leftLineA = (destPXBL[0] - destPXTL[0]) / (destPXBL[1] - destPXTL[1]); /* RC coefficient of left rib, (X2-X1)/(Y2-Y1) by (X = AY + B) */
double leftLineB = destPXTL[0] - destPXTL[1] * leftLineA; /* X1 - Y1 * RC */
double leftLineY = (dstpixel_y / (dfTileHeight)) * (destPXBL[1] - destPXTL[1]) + destPXTL[1]; /* 0 - dfTileHeight --> 0 - 1 --> destPXTL[1] - destPXBL[1]*/
double leftLineX = leftLineY * leftLineA + leftLineB;
double rightLineA = (destPXBR[0] - destPXTR[0]) / (destPXBR[1] - destPXTR[1]); /* RC coefficient of right rib, (X2-X1)/(Y2-Y1) */
double rightLineB = destPXTR[0] - destPXTR[1] * rightLineA; /* X1 - Y1 * RC */
double rightLineY = (dstpixel_y / (dfTileHeight)) * (destPXBR[1] - destPXTR[1]) + destPXTR[1]; /* 0 - dfTileHeight --> 0 - 1 --> destPXTL[1] - destPXBL[1] */
double rightLineX = rightLineY * rightLineA + rightLineB;
/* Now calculate points from leftLineX, leftLineY to rightLineX, rightLineY */
double lineA = (rightLineY - leftLineY) / (rightLineX - leftLineX); /* RC coefficient of top rib (Y= AX + B)*/
double lineB = leftLineY - leftLineX * lineA;
for (double dstpixel_x = 0.5; dstpixel_x < dfTileWidth + 0.5; dstpixel_x++) {
double dfSourceSampleX = (dstpixel_x / (dfTileWidth)) * (rightLineX - leftLineX) + leftLineX;
double dfSourceSampleY = dfSourceSampleX * lineA + lineB;
int sourceSampleX = floor(dfSourceSampleX);
int sourceSampleY = floor(dfSourceSampleY);
int destPixelX = dstpixel_x + dDestX;
int destPixelY = dstpixel_y + dDestY;
if (sourceSampleX >= 0 && sourceSampleX < width && sourceSampleY >= 0 && sourceSampleY < height && destPixelX >= 0 && destPixelY >= 0 && destPixelX < imageWidth && destPixelY < imageHeight) {
imgpointer = sourceSampleX + (sourceSampleY)*width;
val = data[imgpointer];
isNodata = false;
if (hasNodataValue) {
if (val == nodataValue) isNodata = true;
}
if (!(val == val)) isNodata = true;
if (!isNodata)
if (legendValueRange)
if (val < legendLowerRange || val > legendUpperRange) isNodata = true;
if (!isNodata) {
if (legendLog != 0) {
if (val > 0) {
val = (T)(log10(val) / legendLogAsLog);
} else
val = (T)(-legendOffset);
}
int pcolorind = (int)(val * legendScale + legendOffset);
if (pcolorind >= 239)
pcolorind = 239;
else if (pcolorind <= 0)
pcolorind = 0;
drawImage->setPixelIndexed(destPixelX, dstpixel_y + dDestY, pcolorind);
}
if (debug) {
bool draw = false;
bool draw2 = false;
if (sourceSampleX == 0 || sourceSampleX == width - 1 || sourceSampleY == 0 || sourceSampleY == height - 1) {
draw = true;
}
if ((sourceSampleX == 10 || sourceSampleX == width - 10) && sourceSampleY > 10 && sourceSampleY < height - 10) {
draw2 = true;
}
if ((sourceSampleY == 10 || sourceSampleY == width - 10) && sourceSampleX > 10 && sourceSampleX < width - 10) {
draw2 = true;
}
if (draw) {
drawImage->setPixelIndexed(destPixelX, destPixelY, 249);
}
if (draw2) {
drawImage->setPixelIndexed(destPixelX, destPixelY, 244);
}
}
}
}
}
return 0;
}
|
/*=========================================================================
Program: Visualization Toolkit
Module: TestOrthoPlanes.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkSmartPointer.h"
#include "vtkActor.h"
#include "vtkCamera.h"
#include "vtkCellPicker.h"
#include "vtkCommand.h"
#include "vtkImageActor.h"
#include "vtkImageMapToColors.h"
#include "vtkImageOrthoPlanes.h"
#include "vtkImagePlaneWidget.h"
#include "vtkImageReader.h"
#include "vtkInteractorEventRecorder.h"
#include "vtkLookupTable.h"
#include "vtkOutlineFilter.h"
#include "vtkPolyDataMapper.h"
#include "vtkProperty.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkVolume16Reader.h"
#include "vtkImageData.h"
#include "vtkTestUtilities.h"
static char IOPeventLog[] =
"# StreamVersion 1\n"
"CharEvent 179 195 0 0 98 1 i\n"
"MiddleButtonPressEvent 179 195 0 0 0 0 i\n"
"MouseMoveEvent 179 190 0 0 0 0 i\n"
"MouseMoveEvent 179 185 0 0 0 0 i\n"
"MouseMoveEvent 179 180 0 0 0 0 i\n"
"MouseMoveEvent 179 175 0 0 0 0 i\n"
"MouseMoveEvent 179 170 0 0 0 0 i\n"
"MouseMoveEvent 179 165 0 0 0 0 i\n"
"MouseMoveEvent 179 160 0 0 0 0 i\n"
"MouseMoveEvent 179 155 0 0 0 0 i\n"
"MouseMoveEvent 179 150 0 0 0 0 i\n"
"MouseMoveEvent 179 145 0 0 0 0 i\n"
"MouseMoveEvent 179 140 0 0 0 0 i\n"
"MouseMoveEvent 179 135 0 0 0 0 i\n"
"MiddleButtonReleaseEvent 179 135 0 0 0 0 i\n"
"RightButtonPressEvent 179 135 0 0 0 0 i\n"
"MouseMoveEvent 180 135 0 0 0 0 i\n"
"MouseMoveEvent 181 136 0 0 0 0 i\n"
"MouseMoveEvent 181 137 0 0 0 0 i\n"
"MouseMoveEvent 181 138 0 0 0 0 i\n"
"MouseMoveEvent 181 139 0 0 0 0 i\n"
"MouseMoveEvent 181 140 0 0 0 0 i\n"
"MouseMoveEvent 180 140 0 0 0 0 i\n"
"MouseMoveEvent 175 135 0 0 0 0 i\n"
"MouseMoveEvent 170 130 0 0 0 0 i\n"
"MouseMoveEvent 165 130 0 0 0 0 i\n"
"MouseMoveEvent 160 130 0 0 0 0 i\n"
"MouseMoveEvent 155 125 0 0 0 0 i\n"
"MouseMoveEvent 150 120 0 0 0 0 i\n"
"MouseMoveEvent 145 115 0 0 0 0 i\n"
"MouseMoveEvent 140 110 0 0 0 0 i\n"
"RightButtonReleaseEvent 140 110 0 0 0 0 i\n"
"MouseMoveEvent 135 120 0 0 0 0 i\n"
"MouseMoveEvent 130 135 0 0 0 0 i\n"
"MouseMoveEvent 125 170 0 0 0 0 i\n"
"MouseMoveEvent 120 180 0 0 0 0 i\n"
"MouseMoveEvent 115 190 0 0 0 0 i\n"
"MouseMoveEvent 110 200 0 0 0 0 i\n"
"MouseMoveEvent 106 218 0 0 0 0 i\n"
"LeftButtonPressEvent 106 218 0 0 0 0 i\n"
"MouseMoveEvent 107 219 0 0 0 0 i\n"
"MouseMoveEvent 110 218 0 0 0 0 i\n"
"MouseMoveEvent 114 216 0 0 0 0 i\n"
"MouseMoveEvent 118 214 0 0 0 0 i\n"
"MouseMoveEvent 123 213 0 0 0 0 i\n"
"MouseMoveEvent 128 212 0 0 0 0 i\n"
"MouseMoveEvent 132 210 0 0 0 0 i\n"
"MouseMoveEvent 138 207 0 0 0 0 i\n"
"MouseMoveEvent 144 205 0 0 0 0 i\n"
"MouseMoveEvent 150 203 0 0 0 0 i\n"
"MouseMoveEvent 157 201 0 0 0 0 i\n"
"MouseMoveEvent 164 200 0 0 0 0 i\n"
"MouseMoveEvent 168 198 0 0 0 0 i\n"
"MouseMoveEvent 176 196 0 0 0 0 i\n"
"MouseMoveEvent 183 194 0 0 0 0 i\n"
"MouseMoveEvent 190 192 0 0 0 0 i\n"
"MouseMoveEvent 197 190 0 0 0 0 i\n"
"MouseMoveEvent 199 189 0 0 0 0 i\n"
"MouseMoveEvent 204 189 0 0 0 0 i\n"
"MouseMoveEvent 206 189 0 0 0 0 i\n"
"MouseMoveEvent 209 188 0 0 0 0 i\n"
"MouseMoveEvent 211 187 0 0 0 0 i\n"
"LeftButtonReleaseEvent 211 187 0 0 0 0 i\n"
"MouseMoveEvent 259 183 0 0 0 0 i\n"
"KeyPressEvent 259 183 -128 0 0 1 Control_L\n"
"MiddleButtonPressEvent 259 183 8 0 0 0 Control_L\n"
"MouseMoveEvent 261 183 8 0 0 0 Control_L\n"
"MouseMoveEvent 263 182 8 0 0 0 Control_L\n"
"MouseMoveEvent 266 181 8 0 0 0 Control_L\n"
"MouseMoveEvent 268 180 8 0 0 0 Control_L\n"
"MouseMoveEvent 270 179 8 0 0 0 Control_L\n"
"MouseMoveEvent 273 178 8 0 0 0 Control_L\n"
"MouseMoveEvent 276 177 8 0 0 0 Control_L\n"
"MouseMoveEvent 279 176 8 0 0 0 Control_L\n"
"MouseMoveEvent 282 175 8 0 0 0 Control_L\n"
"MouseMoveEvent 287 174 8 0 0 0 Control_L\n"
"MouseMoveEvent 286 173 8 0 0 0 Control_L\n"
"MouseMoveEvent 284 173 8 0 0 0 Control_L\n"
"MouseMoveEvent 281 174 8 0 0 0 Control_L\n"
"MouseMoveEvent 277 175 8 0 0 0 Control_L\n"
"MouseMoveEvent 274 176 8 0 0 0 Control_L\n"
"MouseMoveEvent 269 177 8 0 0 0 Control_L\n"
"MouseMoveEvent 267 177 8 0 0 0 Control_L\n"
"KeyReleaseEvent 267 177 0 0 0 1 Control_L\n"
"MiddleButtonReleaseEvent 267 177 0 0 0 0 Control_L\n"
"MouseMoveEvent 240 229 0 0 0 0 Control_L\n"
"KeyPressEvent 240 229 -128 0 0 1 Control_L\n"
"MiddleButtonPressEvent 240 229 8 0 0 0 Control_L\n"
"MouseMoveEvent 240 230 8 0 0 0 Control_L\n"
"MouseMoveEvent 240 235 8 0 0 0 Control_L\n"
"MouseMoveEvent 240 240 8 0 0 0 Control_L\n"
"MouseMoveEvent 240 245 8 0 0 0 Control_L\n"
"MouseMoveEvent 240 250 8 0 0 0 Control_L\n"
"MouseMoveEvent 241 255 8 0 0 0 Control_L\n"
"MouseMoveEvent 242 260 8 0 0 0 Control_L\n"
"MouseMoveEvent 242 265 8 0 0 0 Control_L\n"
"MouseMoveEvent 242 260 8 0 0 0 Control_L\n"
"MouseMoveEvent 242 255 8 0 0 0 Control_L\n"
"MouseMoveEvent 242 250 8 0 0 0 Control_L\n"
"MouseMoveEvent 242 245 8 0 0 0 Control_L\n"
"MouseMoveEvent 242 240 8 0 0 0 Control_L\n"
"MouseMoveEvent 241 238 8 0 0 0 Control_L\n"
"KeyReleaseEvent 241 238 0 0 0 1 Control_L\n"
"MiddleButtonReleaseEvent 241 238 0 0 0 0 Control_L\n"
"MouseMoveEvent 103 250 0 0 0 0 Control_L\n"
"KeyPressEvent 103 250 -128 0 0 1 Control_L\n"
"MiddleButtonPressEvent 103 250 8 0 0 0 Control_L\n"
"MouseMoveEvent 100 250 8 0 0 0 Control_L\n"
"MouseMoveEvent 97 251 8 0 0 0 Control_L\n"
"MouseMoveEvent 94 251 8 0 0 0 Control_L\n"
"MouseMoveEvent 91 252 8 0 0 0 Control_L\n"
"MouseMoveEvent 90 253 8 0 0 0 Control_L\n"
"MouseMoveEvent 85 253 8 0 0 0 Control_L\n"
"MouseMoveEvent 80 253 8 0 0 0 Control_L\n"
"MouseMoveEvent 85 253 8 0 0 0 Control_L\n"
"KeyReleaseEvent 85 253 0 0 0 1 Control_L\n"
"MiddleButtonReleaseEvent 85 253 0 0 0 0 Control_L\n"
"MouseMoveEvent 228 88 0 0 0 0 Control_L\n"
"KeyPressEvent 228 88 -128 0 0 1 Control_L\n"
"MiddleButtonPressEvent 228 88 8 0 0 0 Control_L\n"
"MouseMoveEvent 228 86 8 0 0 0 Control_L\n"
"MouseMoveEvent 227 83 8 0 0 0 Control_L\n"
"MouseMoveEvent 226 83 8 0 0 0 Control_L\n"
"MouseMoveEvent 225 80 8 0 0 0 Control_L\n"
"MouseMoveEvent 225 75 8 0 0 0 Control_L\n"
"MouseMoveEvent 224 70 8 0 0 0 Control_L\n"
"MouseMoveEvent 223 70 8 0 0 0 Control_L\n"
"MouseMoveEvent 223 75 8 0 0 0 Control_L\n"
"MouseMoveEvent 222 80 8 0 0 0 Control_L\n"
"MouseMoveEvent 222 85 8 0 0 0 Control_L\n"
"MouseMoveEvent 222 90 8 0 0 0 Control_L\n"
"KeyReleaseEvent 222 93 0 0 0 1 Control_L\n"
"MiddleButtonReleaseEvent 222 93 0 0 0 0 Control_L\n"
"MouseMoveEvent 260 76 0 0 0 0 Control_L\n"
"KeyPressEvent 260 76 -128 0 0 1 Control_L\n"
"MiddleButtonPressEvent 260 76 8 0 0 0 Control_L\n"
"MouseMoveEvent 260 75 8 0 0 0 Control_L\n"
"MouseMoveEvent 261 72 8 0 0 0 Control_L\n"
"MouseMoveEvent 262 69 8 0 0 0 Control_L\n"
"MouseMoveEvent 263 67 8 0 0 0 Control_L\n"
"MouseMoveEvent 263 65 8 0 0 0 Control_L\n"
"MouseMoveEvent 264 63 8 0 0 0 Control_L\n"
"MouseMoveEvent 265 61 8 0 0 0 Control_L\n"
"MouseMoveEvent 266 60 8 0 0 0 Control_L\n"
"MouseMoveEvent 266 55 8 0 0 0 Control_L\n"
"MouseMoveEvent 267 53 8 0 0 0 Control_L\n"
"KeyReleaseEvent 267 53 0 0 0 1 Control_L\n"
"MiddleButtonReleaseEvent 267 53 0 0 0 0 Control_L\n"
"MouseMoveEvent 278 226 0 0 0 0 Control_L\n"
"KeyPressEvent 278 226 -128 0 0 1 Control_L\n"
"MiddleButtonPressEvent 278 226 8 0 0 0 Control_L\n"
"MouseMoveEvent 278 227 8 0 0 0 Control_L\n"
"MouseMoveEvent 278 230 8 0 0 0 Control_L\n"
"MouseMoveEvent 280 232 8 0 0 0 Control_L\n"
"MouseMoveEvent 282 234 8 0 0 0 Control_L\n"
"MouseMoveEvent 284 237 8 0 0 0 Control_L\n"
"MouseMoveEvent 286 239 8 0 0 0 Control_L\n"
"MouseMoveEvent 287 242 8 0 0 0 Control_L\n"
"MouseMoveEvent 290 245 8 0 0 0 Control_L\n"
"MouseMoveEvent 292 247 8 0 0 0 Control_L\n"
"MouseMoveEvent 293 249 8 0 0 0 Control_L\n"
"KeyReleaseEvent 283 249 0 0 0 1 Control_L\n"
"MiddleButtonReleaseEvent 293 249 0 0 0 0 Control_L\n"
"MouseMoveEvent 93 286 0 0 0 0 Control_L\n"
"KeyPressEvent 93 286 -128 0 0 1 Control_L\n"
"MiddleButtonPressEvent 93 286 8 0 0 0 Control_L\n"
"MouseMoveEvent 92 288 8 0 0 0 Control_L\n"
"MouseMoveEvent 90 290 8 0 0 0 Control_L\n"
"MouseMoveEvent 87 292 8 0 0 0 Control_L\n"
"MouseMoveEvent 84 295 8 0 0 0 Control_L\n"
"MouseMoveEvent 82 297 8 0 0 0 Control_L\n"
"MouseMoveEvent 80 298 8 0 0 0 Control_L\n"
"MouseMoveEvent 78 300 8 0 0 0 Control_L\n"
"KeyReleaseEvent 78 300 0 0 0 1 Control_L\n"
"MiddleButtonReleaseEvent 78 300 0 0 0 0 Control_L\n"
"MouseMoveEvent 198 194 0 0 0 0 Control_L\n"
"KeyPressEvent 198 194 -128 0 0 1 Control_L\n"
"MiddleButtonPressEvent 198 194 8 0 0 0 Control_L\n"
"MouseMoveEvent 196 194 8 0 0 0 Control_L\n"
"MouseMoveEvent 191 192 8 0 0 0 Control_L\n"
"MouseMoveEvent 185 189 8 0 0 0 Control_L\n"
"MouseMoveEvent 182 187 8 0 0 0 Control_L\n"
"MouseMoveEvent 180 186 8 0 0 0 Control_L\n"
"MouseMoveEvent 178 185 8 0 0 0 Control_L\n"
"MouseMoveEvent 177 180 8 0 0 0 Control_L\n"
"MouseMoveEvent 178 179 8 0 0 0 Control_L\n"
"MouseMoveEvent 179 178 8 0 0 0 Control_L\n"
"MouseMoveEvent 179 177 8 0 0 0 Control_L\n"
"MouseMoveEvent 182 176 8 0 0 0 Control_L\n"
"MouseMoveEvent 187 175 8 0 0 0 Control_L\n"
"MouseMoveEvent 190 177 8 0 0 0 Control_L\n"
"MouseMoveEvent 190 179 8 0 0 0 Control_L\n"
"KeyReleaseEvent 190 179 0 0 0 1 Control_L\n"
"MiddleButtonReleaseEvent 190 179 0 0 0 0 Control_L\n"
"KeyPressEvent 190 179 0 -128 0 1 Shift_L\n"
"MiddleButtonPressEvent 190 179 0 4 0 0 Shift_L\n"
"MouseMoveEvent 190 180 0 4 0 0 Shift_L\n"
"MouseMoveEvent 190 185 0 4 0 0 Shift_L\n"
"MouseMoveEvent 190 190 0 4 0 0 Shift_L\n"
"MouseMoveEvent 191 194 0 4 0 0 Shift_L\n"
"MouseMoveEvent 192 200 0 4 0 0 Shift_L\n"
"MouseMoveEvent 192 206 0 4 0 0 Shift_L\n"
"MouseMoveEvent 193 213 0 4 0 0 Shift_L\n"
"MouseMoveEvent 193 209 0 4 0 0 Shift_L\n"
"MouseMoveEvent 193 206 0 4 0 0 Shift_L\n"
"MouseMoveEvent 193 200 0 4 0 0 Shift_L\n"
"MouseMoveEvent 193 196 0 4 0 0 Shift_L\n"
"MouseMoveEvent 193 190 0 4 0 0 Shift_L\n"
"MouseMoveEvent 194 185 0 4 0 0 Shift_L\n"
"MouseMoveEvent 196 180 0 4 0 0 Shift_L\n"
"MouseMoveEvent 197 175 0 4 0 0 Shift_L\n"
"MouseMoveEvent 198 172 0 4 0 0 Shift_L\n"
"KeyReleaseEvent 198 172 0 0 0 1 Shift_L\n"
"MiddleButtonReleaseEvent 198 172 0 0 0 0 Shift_L\n"
"MouseMoveEvent 267 172 0 0 0 0 Shift_L\n"
"MiddleButtonPressEvent 267 172 0 0 0 0 Shift_L\n"
"MouseMoveEvent 264 171 0 0 0 0 Shift_L\n"
"MouseMoveEvent 260 171 0 0 0 0 Shift_L\n"
"MouseMoveEvent 255 171 0 0 0 0 Shift_L\n"
"MouseMoveEvent 250 171 0 0 0 0 Shift_L\n"
"MouseMoveEvent 245 172 0 0 0 0 Shift_L\n"
"MiddleButtonReleaseEvent 245 172 0 0 0 0 Shift_L\n"
"MouseMoveEvent 203 65 0 0 0 0 Shift_L\n"
"MiddleButtonPressEvent 203 65 0 0 0 0 Shift_L\n"
"MouseMoveEvent 200 65 0 0 0 0 Shift_L\n"
"MouseMoveEvent 195 66 0 0 0 0 Shift_L\n"
"MouseMoveEvent 193 67 0 0 0 0 Shift_L\n"
"MouseMoveEvent 190 68 0 0 0 0 Shift_L\n"
"MouseMoveEvent 184 71 0 0 0 0 Shift_L\n"
"MouseMoveEvent 180 73 0 0 0 0 Shift_L\n"
"MouseMoveEvent 178 74 0 0 0 0 Shift_L\n"
"MouseMoveEvent 176 75 0 0 0 0 Shift_L\n"
"MouseMoveEvent 175 76 0 0 0 0 Shift_L\n"
"MouseMoveEvent 174 77 0 0 0 0 Shift_L\n"
"MouseMoveEvent 173 78 0 0 0 0 Shift_L\n"
"MouseMoveEvent 172 79 0 0 0 0 Shift_L\n"
"MouseMoveEvent 170 80 0 0 0 0 Shift_L\n"
"MouseMoveEvent 169 81 0 0 0 0 Shift_L\n"
"MouseMoveEvent 168 82 0 0 0 0 Shift_L\n"
"MouseMoveEvent 167 83 0 0 0 0 Shift_L\n"
"MouseMoveEvent 166 84 0 0 0 0 Shift_L\n"
"MouseMoveEvent 164 84 0 0 0 0 Shift_L\n"
"MouseMoveEvent 163 85 0 0 0 0 Shift_L\n"
"MouseMoveEvent 162 86 0 0 0 0 Shift_L\n"
"MouseMoveEvent 160 86 0 0 0 0 Shift_L\n"
"MouseMoveEvent 158 87 0 0 0 0 Shift_L\n"
"MiddleButtonReleaseEvent 158 87 0 0 0 0 Shift_L\n"
"MouseMoveEvent 95 251 0 0 0 0 Shift_L\n"
"MiddleButtonPressEvent 95 251 0 0 0 0 Shift_L\n"
"MouseMoveEvent 90 251 0 0 0 0 Shift_L\n"
"MouseMoveEvent 85 252 0 0 0 0 Shift_L\n"
"MouseMoveEvent 80 252 0 0 0 0 Shift_L\n"
"MouseMoveEvent 75 252 0 0 0 0 Shift_L\n"
"MouseMoveEvent 70 252 0 0 0 0 Shift_L\n"
"MouseMoveEvent 65 251 0 0 0 0 Shift_L\n"
"MiddleButtonReleaseEvent 65 251 0 0 0 0 Shift_L\n"
"MouseMoveEvent 133 281 0 0 0 0 Shift_L\n"
"MiddleButtonPressEvent 133 281 0 0 0 0 Shift_L\n"
"MouseMoveEvent 130 280 0 0 0 0 Shift_L\n"
"MouseMoveEvent 125 277 0 0 0 0 Shift_L\n"
"MouseMoveEvent 120 274 0 0 0 0 Shift_L\n"
"MouseMoveEvent 115 270 0 0 0 0 Shift_L\n"
"MouseMoveEvent 113 267 0 0 0 0 Shift_L\n"
"MouseMoveEvent 110 265 0 0 0 0 Shift_L\n"
"MiddleButtonReleaseEvent 110 265 0 0 0 0 Shift_L\n"
"MouseMoveEvent 99 286 0 0 0 0 Shift_L\n"
"MiddleButtonPressEvent 99 286 0 0 0 0 Shift_L\n"
"MouseMoveEvent 100 287 0 0 0 0 Shift_L\n"
"MouseMoveEvent 105 289 0 0 0 0 Shift_L\n"
"MouseMoveEvent 110 290 0 0 0 0 Shift_L\n"
"MouseMoveEvent 115 290 0 0 0 0 Shift_L\n"
"MouseMoveEvent 120 290 0 0 0 0 Shift_L\n"
"MouseMoveEvent 125 285 0 0 0 0 Shift_L\n"
"MouseMoveEvent 129 281 0 0 0 0 Shift_L\n"
"MouseMoveEvent 130 279 0 0 0 0 Shift_L\n"
"MouseMoveEvent 128 281 0 0 0 0 Shift_L\n"
"MouseMoveEvent 126 282 0 0 0 0 Shift_L\n"
"MouseMoveEvent 123 283 0 0 0 0 Shift_L\n"
"MouseMoveEvent 120 284 0 0 0 0 Shift_L\n"
"MouseMoveEvent 115 285 0 0 0 0 Shift_L\n"
"MouseMoveEvent 110 286 0 0 0 0 Shift_L\n"
"MouseMoveEvent 106 286 0 0 0 0 Shift_L\n"
"MouseMoveEvent 102 286 0 0 0 0 Shift_L\n"
"MouseMoveEvent 99 285 0 0 0 0 Shift_L\n"
"MouseMoveEvent 95 283 0 0 0 0 Shift_L\n"
"MouseMoveEvent 92 281 0 0 0 0 Shift_L\n"
"MouseMoveEvent 89 279 0 0 0 0 Shift_L\n"
"MouseMoveEvent 88 276 0 0 0 0 Shift_L\n"
"MouseMoveEvent 86 274 0 0 0 0 Shift_L\n"
"MiddleButtonReleaseEvent 86 274 0 0 0 0 Shift_L\n"
;
//----------------------------------------------------------------------------
class vtkOrthoPlanesCallback : public vtkCommand
{
public:
static vtkOrthoPlanesCallback *New()
{ return new vtkOrthoPlanesCallback; }
void Execute( vtkObject *caller, unsigned long vtkNotUsed( event ),
void *callData )
{
vtkImagePlaneWidget* self =
reinterpret_cast< vtkImagePlaneWidget* >( caller );
if(!self) return;
double* wl = static_cast<double*>( callData );
if ( self == this->WidgetX )
{
this->WidgetY->SetWindowLevel(wl[0],wl[1],1);
this->WidgetZ->SetWindowLevel(wl[0],wl[1],1);
}
else if( self == this->WidgetY )
{
this->WidgetX->SetWindowLevel(wl[0],wl[1],1);
this->WidgetZ->SetWindowLevel(wl[0],wl[1],1);
}
else if (self == this->WidgetZ)
{
this->WidgetX->SetWindowLevel(wl[0],wl[1],1);
this->WidgetY->SetWindowLevel(wl[0],wl[1],1);
}
}
vtkOrthoPlanesCallback():WidgetX( 0 ), WidgetY( 0 ), WidgetZ ( 0 ) {}
vtkImagePlaneWidget* WidgetX;
vtkImagePlaneWidget* WidgetY;
vtkImagePlaneWidget* WidgetZ;
};
int TestOrthoPlanes( int argc, char *argv[] )
{
char* fname = vtkTestUtilities::ExpandDataFileName(argc, argv, "Data/headsq/quarter");
vtkSmartPointer<vtkVolume16Reader> v16 =
vtkSmartPointer<vtkVolume16Reader>::New();
v16->SetDataDimensions( 64, 64);
v16->SetDataByteOrderToLittleEndian();
v16->SetImageRange( 1, 93);
v16->SetDataSpacing( 3.2, 3.2, 1.5);
v16->SetFilePrefix( fname );
v16->SetDataMask( 0x7fff);
v16->Update();
delete[] fname;
vtkSmartPointer<vtkOutlineFilter> outline =
vtkSmartPointer<vtkOutlineFilter>::New();
outline->SetInputConnection(v16->GetOutputPort());
vtkSmartPointer<vtkPolyDataMapper> outlineMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
outlineMapper->SetInputConnection(outline->GetOutputPort());
vtkSmartPointer<vtkActor> outlineActor =
vtkSmartPointer<vtkActor>::New();
outlineActor->SetMapper( outlineMapper);
vtkSmartPointer<vtkRenderer> ren1 =
vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderer> ren2 =
vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renWin =
vtkSmartPointer<vtkRenderWindow>::New();
renWin->SetMultiSamples(0);
renWin->AddRenderer(ren2);
renWin->AddRenderer(ren1);
vtkSmartPointer<vtkRenderWindowInteractor> iren =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
iren->SetRenderWindow(renWin);
vtkSmartPointer<vtkCellPicker> picker =
vtkSmartPointer<vtkCellPicker>::New();
picker->SetTolerance(0.005);
vtkSmartPointer<vtkProperty> ipwProp =
vtkSmartPointer<vtkProperty>::New();
//assign default props to the ipw's texture plane actor
vtkSmartPointer<vtkImagePlaneWidget> planeWidgetX =
vtkSmartPointer<vtkImagePlaneWidget>::New();
planeWidgetX->SetInteractor( iren);
planeWidgetX->SetKeyPressActivationValue('x');
planeWidgetX->SetPicker(picker);
planeWidgetX->RestrictPlaneToVolumeOn();
planeWidgetX->GetPlaneProperty()->SetColor(1,0,0);
planeWidgetX->SetTexturePlaneProperty(ipwProp);
planeWidgetX->TextureInterpolateOff();
planeWidgetX->SetResliceInterpolateToNearestNeighbour();
planeWidgetX->SetInput(v16->GetOutput());
planeWidgetX->SetPlaneOrientationToXAxes();
planeWidgetX->SetSliceIndex(32);
planeWidgetX->DisplayTextOn();
planeWidgetX->On();
planeWidgetX->InteractionOff();
planeWidgetX->InteractionOn();
vtkSmartPointer<vtkImagePlaneWidget> planeWidgetY =
vtkSmartPointer<vtkImagePlaneWidget>::New();
planeWidgetY->SetInteractor( iren);
planeWidgetY->SetKeyPressActivationValue('y');
planeWidgetY->SetPicker(picker);
planeWidgetY->GetPlaneProperty()->SetColor(1,1,0);
planeWidgetY->SetTexturePlaneProperty(ipwProp);
planeWidgetY->TextureInterpolateOn();
planeWidgetY->SetResliceInterpolateToLinear();
planeWidgetY->SetInput(v16->GetOutput());
planeWidgetY->SetPlaneOrientationToYAxes();
planeWidgetY->SetSlicePosition(102.4);
planeWidgetY->SetLookupTable( planeWidgetX->GetLookupTable());
planeWidgetY->DisplayTextOff();
planeWidgetY->UpdatePlacement();
planeWidgetY->On();
vtkSmartPointer<vtkImagePlaneWidget> planeWidgetZ =
vtkSmartPointer<vtkImagePlaneWidget>::New();
planeWidgetZ->SetInteractor( iren);
planeWidgetZ->SetKeyPressActivationValue('z');
planeWidgetZ->SetPicker(picker);
planeWidgetZ->GetPlaneProperty()->SetColor(0,0,1);
planeWidgetZ->SetTexturePlaneProperty(ipwProp);
planeWidgetZ->TextureInterpolateOn();
planeWidgetZ->SetResliceInterpolateToCubic();
planeWidgetZ->SetInput(v16->GetOutput());
planeWidgetZ->SetPlaneOrientationToZAxes();
planeWidgetZ->SetSliceIndex(25);
planeWidgetZ->SetLookupTable( planeWidgetX->GetLookupTable());
planeWidgetZ->DisplayTextOn();
planeWidgetZ->On();
vtkSmartPointer<vtkImageOrthoPlanes> orthoPlanes =
vtkSmartPointer<vtkImageOrthoPlanes>::New();
orthoPlanes->SetPlane(0, planeWidgetX);
orthoPlanes->SetPlane(1, planeWidgetY);
orthoPlanes->SetPlane(2, planeWidgetZ);
orthoPlanes->ResetPlanes();
vtkSmartPointer<vtkOrthoPlanesCallback> cbk =
vtkSmartPointer<vtkOrthoPlanesCallback>::New();
cbk->WidgetX = planeWidgetX;
cbk->WidgetY = planeWidgetY;
cbk->WidgetZ = planeWidgetZ;
planeWidgetX->AddObserver( vtkCommand::EndWindowLevelEvent, cbk );
planeWidgetY->AddObserver( vtkCommand::EndWindowLevelEvent, cbk );
planeWidgetZ->AddObserver( vtkCommand::EndWindowLevelEvent, cbk );
double wl[2];
planeWidgetZ->GetWindowLevel(wl);
// Add a 2D image to test the GetReslice method
//
vtkSmartPointer<vtkImageMapToColors> colorMap =
vtkSmartPointer<vtkImageMapToColors>::New();
colorMap->PassAlphaToOutputOff();
colorMap->SetActiveComponent(0);
colorMap->SetOutputFormatToLuminance();
colorMap->SetInput(planeWidgetZ->GetResliceOutput());
colorMap->SetLookupTable(planeWidgetX->GetLookupTable());
vtkSmartPointer<vtkImageActor> imageActor =
vtkSmartPointer<vtkImageActor>::New();
imageActor->PickableOff();
imageActor->SetInput(colorMap->GetOutput());
// Add the actors
//
ren1->AddActor( outlineActor);
ren2->AddActor( imageActor);
ren1->SetBackground( 0.1, 0.1, 0.2);
ren2->SetBackground( 0.2, 0.1, 0.2);
renWin->SetSize( 600, 350);
ren1->SetViewport(0,0,0.58333,1);
ren2->SetViewport(0.58333,0,1,1);
// Set the actors' postions
//
renWin->Render();
iren->SetEventPosition( 175,175);
iren->SetKeyCode('r');
iren->InvokeEvent(vtkCommand::CharEvent,NULL);
iren->SetEventPosition( 475,175);
iren->SetKeyCode('r');
iren->InvokeEvent(vtkCommand::CharEvent,NULL);
renWin->Render();
ren1->GetActiveCamera()->Elevation(110);
ren1->GetActiveCamera()->SetViewUp(0, 0, -1);
ren1->GetActiveCamera()->Azimuth(45);
ren1->GetActiveCamera()->Dolly(1.15);
ren1->ResetCameraClippingRange();
// Playback recorded events
//
vtkSmartPointer<vtkInteractorEventRecorder> recorder =
vtkSmartPointer<vtkInteractorEventRecorder>::New();
recorder->SetInteractor(iren);
recorder->ReadFromInputStringOn();
recorder->SetInputString(IOPeventLog);
// Interact with data
// Render the image
//
iren->Initialize();
renWin->Render();
// Test SetKeyPressActivationValue for one of the widgets
//
iren->SetKeyCode('z');
iren->InvokeEvent(vtkCommand::CharEvent,NULL);
iren->SetKeyCode('z');
iren->InvokeEvent(vtkCommand::CharEvent,NULL);
recorder->Play();
// Remove the observers so we can go interactive. Without this the "-I"
// testing option fails.
recorder->Off();
iren->Start();
return EXIT_SUCCESS;
}
|
<%
from pwnlib.shellcraft.aarch64.linux import syscall
%>
<%page args="file, mode"/>
<%docstring>
Invokes the syscall creat. See 'man 2 creat' for more information.
Arguments:
file(char): file
mode(mode_t): mode
</%docstring>
${syscall('SYS_creat', file, mode)}
|
;
; This is just a quick hack I put together to demonstate how to write
; bootsector code. All it does is print the initial values of the registers
; and then hang. I didn't really comment anything, but it's very simple so
; it shouldn't be difficult to understand.
;
; I used MASM 6.1 ( but TASM may work??? ) to assemble it, like this
;
; ML /AT BOOTSEC.ASM ( /AT for COM file )
;
;
; It should then create BOOTSEC.COM that is 512 bytes long. Write this file
; to Sector 1, Track 0, Head 0 of your A drive using your favorite Disk
; Editor, and reboot. Note that this will make the disk in A unreadable
; by DOS( you'll need to reformat the disk after you're done ).
;
; The daring( or stupid? ) among you will write this code to Sector 0,
; Track 0, Head 0 of your C Drive. The code still works( because I tried
; it ). However, I recommend you save a copy of your parition table before
; you try this or you'll be recontructing your partition table by hand.
;
; Oh yeah, if this code causes your computer to explode it's not my fault.
; And feel free to do whatever you want with this code, i don't care.
;
;
; Here's a quick summary of what the BIOS does when booting up.
;
; 1) Loads Sector 1, Track 0, Head 0 of the boot drive( A or C ) to
; absolute address 07C00h-07DFFh
;
; 2) Checks the 16 bit word at absolute address 07DFEh for AA55h. This is
; the boot signature and is used by the BIOS to ensure that the sector
; contains a value bootsector.
;
; If this signature isn't present, the BIOS will display a message like
; "Operating System Not Found"
;
; 4) Loads DL with
; 00h if the boot sector was loaded from drive A,
; 80h if the boot sector was loaded from drive C
;
; This way, the bootsector can determine which drive it was booted from.
;
; 5) Jumps to 0000:7C00h, which is the start of the bootsector
;
;
; Send yer comments to mjvines@undergrad.math.uwaterloo.ca
;
;
.386 ; There are a couple 386+ opcodes. Who has a 286 anymore anyways?
_text SEGMENT PUBLIC USE16
assume CS:_text, DS:_text
org 0h
CRLF MACRO
mov ax, 0E0Dh
xor bx, bx
int 10h
mov al, 0Ah
int 10h
ENDM
PRINT MACRO var
pop dx
mov di, var
call printreg
mov ax, 0E20h
xor bx, bx
int 10h
ENDM
EntryPoint:
push sp
push ss
call NextLine ; get original IP+5 on the STACK
NextLine:
push cs
push es
push ds
push bp
push di
push si
push dx
push cx
push bx
push ax
; print a pretty message
mov ax, 1301h
mov bx, 0007h
mov cx, 23
mov dh, 10
mov dl, 1
push cs
pop es
mov bp, String
int 10h
CRLF
CRLF
; print the values of all the registers
PRINT _AX
PRINT _BX
PRINT _CX
PRINT _DX
CRLF
PRINT _SI
PRINT _DI
PRINT _BP
CRLF
PRINT _DS
PRINT _ES
CRLF
PRINT _CS
pop ax
sub ax, 5 ; ajust IP back five
push ax
PRINT _IP
PRINT _SS
PRINT _SP
CRLF
; make a little beep
mov ax, 0E07h
int 10h
; nothing else to do, so hang
hang:
jmp hang
; Big messy procedure that prints a three character string pointed to
; by DS:DI followed by the 16 bit hexidecimal number in DX.
printreg:
mov ah, 0Eh
xor bx, bx
mov al, byte ptr [di]
int 10h
mov al, byte ptr [di+1]
int 10h
mov al, byte ptr [di+2]
int 10h
xchg dl, dh
rol dl, 4
rol dh, 4
xor bx, bx
mov ah, 0Eh
mov cx, 4
ploop:
mov al, dl
and al, 0Fh
shr dx, 4
add al, '0'
cmp al, '9'
jbe nochange
add al, 'A' - '9'-1
nochange:
int 10h
loop ploop
RET
; Data Section.
;
; Notice that all the data pointers must have 7C00h added to it. This is
; because the bootsector is loaded to 0000:7C00h, so the base offset is
; 7C00h. However, the assembler thinks that the base offset is 0000h,
; so the 7C00h's are required to "fix-up" the base offest.
;
; Yes, there are many better ways of getting around this, but it's my code
; and I can do what I want! What's that about my attitude?
;
String = $ + 7C00h
db "initial register values"
_AX = $ + 7C00h
db "AX="
_BX = $ + 7C00h
db "BX="
_CX = $ + 7C00h
db "CX="
_DX = $ + 7C00h
db "DX="
_SI = $ + 7C00h
db "SI="
_DI = $ + 7C00h
db "DI="
_BP = $ + 7C00h
db "BP="
_SP = $ + 7C00h
db "SP="
_IP = $ + 7C00h
db "IP="
_CS = $ + 7C00h
db "CS="
_DS = $ + 7C00h
db "DS="
_ES = $ + 7C00h
db "ES="
_SS = $ + 7C00h
db "SS="
ORG 510 ; Make the file 512 bytes long
DW 0AA55h ; Add the boot signature
_text ENDS
END EntryPoint
|
/***
* ==++==
*
* Copyright (c) Microsoft Corporation. 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.
*
* ==--==
* =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
*
* HTTP Library: Oauth 2.0
*
* For the latest on this and related APIs, please see http://casablanca.codeplex.com.
*
* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
****/
#include "stdafx.h"
using web::http::client::http_client;
using web::http::oauth2::details::oauth2_strings;
using web::http::details::mime_types;
using utility::conversions::to_utf8string;
// Expose base64 conversion for arbitrary buffer.
extern utility::string_t _to_base64(const unsigned char *ptr, size_t size);
namespace web { namespace http { namespace oauth2
{
namespace details
{
#define _OAUTH2_STRINGS
#define DAT(a_, b_) const oauth2_string oauth2_strings::a_(_XPLATSTR(b_));
#include "cpprest/details/http_constants.dat"
#undef _OAUTH2_STRINGS
#undef DAT
} // namespace web::http::oauth2::details
namespace experimental
{
utility::string_t oauth2_config::build_authorization_uri(bool generate_state)
{
const utility::string_t response_type((implicit_grant()) ? oauth2_strings::token : oauth2_strings::code);
uri_builder ub(auth_endpoint());
ub.append_query(oauth2_strings::response_type, response_type);
ub.append_query(oauth2_strings::client_id, client_key());
ub.append_query(oauth2_strings::redirect_uri, redirect_uri());
if (generate_state)
{
m_state = m_state_generator.generate();
}
ub.append_query(oauth2_strings::state, state());
if (!scope().empty())
{
ub.append_query(oauth2_strings::scope, scope());
}
return ub.to_string();
}
pplx::task<void> oauth2_config::token_from_redirected_uri(const web::http::uri& redirected_uri)
{
auto query = uri::split_query((implicit_grant()) ? redirected_uri.fragment() : redirected_uri.query());
auto state_param = query.find(oauth2_strings::state);
if (state_param == query.end())
{
return pplx::task_from_exception<void>(oauth2_exception(U("parameter 'state' missing from redirected URI.")));
}
if (state() != state_param->second)
{
utility::ostringstream_t err;
err << U("redirected URI parameter 'state'='") << state_param->second
<< U("' does not match state='") << state() << U("'.");
return pplx::task_from_exception<void>(oauth2_exception(err.str()));
}
auto code_param = query.find(oauth2_strings::code);
if (code_param != query.end())
{
return token_from_code(code_param->second);
}
// NOTE: The redirected URI contains access token only in the implicit grant.
// The implicit grant never passes a refresh token.
auto token_param = query.find(oauth2_strings::access_token);
if (token_param == query.end())
{
return pplx::task_from_exception<void>(oauth2_exception(U("either 'code' or 'access_token' parameter must be in the redirected URI.")));
}
set_token(token_param->second);
return pplx::task_from_result();
}
pplx::task<void> oauth2_config::_request_token(uri_builder& request_body_ub)
{
http_request request;
request.set_method(methods::POST);
request.set_request_uri(utility::string_t());
if (!scope().empty())
{
request_body_ub.append_query(oauth2_strings::scope, uri::encode_data_string(scope()), false);
}
if (http_basic_auth())
{
// Build HTTP Basic authorization header.
const std::string creds_utf8(to_utf8string(
uri::encode_data_string(client_key()) + U(":") + uri::encode_data_string(client_secret())));
request.headers().add(header_names::authorization, U("Basic ")
+ _to_base64(reinterpret_cast<const unsigned char*>(creds_utf8.data()), creds_utf8.size()));
}
else
{
// Add credentials to query as-is.
request_body_ub.append_query(oauth2_strings::client_id, uri::encode_data_string(client_key()), false);
request_body_ub.append_query(oauth2_strings::client_secret, uri::encode_data_string(client_secret()), false);
}
request.set_body(request_body_ub.query(), mime_types::application_x_www_form_urlencoded);
http_client token_client(token_endpoint());
return token_client.request(request)
.then([](http_response resp)
{
return resp.extract_json();
})
.then([this](json::value json_resp) -> void
{
set_token(_parse_token_from_json(json_resp));
});
}
oauth2_token oauth2_config::_parse_token_from_json(const json::value& token_json)
{
oauth2_token result;
if (token_json.has_field(oauth2_strings::access_token))
{
result.set_access_token(token_json.at(oauth2_strings::access_token).as_string());
}
else
{
throw oauth2_exception(U("response json contains no 'access_token': ") + token_json.serialize());
}
if (token_json.has_field(oauth2_strings::token_type))
{
result.set_token_type(token_json.at(oauth2_strings::token_type).as_string());
}
else
{
// Some services don't return 'token_type' while it's required by OAuth 2.0 spec:
// http://tools.ietf.org/html/rfc6749#section-5.1
// As workaround we act as if 'token_type=bearer' was received.
result.set_token_type(oauth2_strings::bearer);
}
if (!utility::details::str_icmp(result.token_type(), oauth2_strings::bearer))
{
throw oauth2_exception(U("only 'token_type=bearer' access tokens are currently supported: ") + token_json.serialize());
}
if (token_json.has_field(oauth2_strings::refresh_token))
{
result.set_refresh_token(token_json.at(oauth2_strings::refresh_token).as_string());
}
else
{
// Do nothing. Preserves the old refresh token.
}
if (token_json.has_field(oauth2_strings::expires_in))
{
result.set_expires_in(token_json.at(oauth2_strings::expires_in).as_number().to_int64());
}
else
{
result.set_expires_in(oauth2_token::undefined_expiration);
}
if (token_json.has_field(oauth2_strings::scope))
{
// The authorization server may return different scope from the one requested.
// This however doesn't necessarily mean the token authorization scope is different.
// See: http://tools.ietf.org/html/rfc6749#section-3.3
result.set_scope(token_json.at(oauth2_strings::scope).as_string());
}
else
{
// Use the requested scope() if no scope parameter was returned.
result.set_scope(scope());
}
return result;
}
}}}} // namespace web::http::oauth2::experimental
|
#include <cstdint>
#include "LedBoardChain.h"
#include "esp_log.h"
#if CONFIG_LOG_DEFAULT_LEVEL >= 4
#include <iomanip>
#include <sstream>
#endif
static char tag[] = "LedBoardChain";
using namespace lamp;
LedBoardChain::LedBoardChain(SPI* spi, int pinInt) {
_spi = spi;
_ready = true;
// TODO
// addISRHandler
// setInterruptType PIO_INTR_NEGEDGE
// interruptEnable
}
void LedBoardChain::addKeyframe(KeyFrame keyframe) {
_frames.push(keyframe);
if(_ready && !_frames.empty()) transferNextKeyframe();
}
void LedBoardChain::transferNextKeyframe() {
auto f = _frames.front();
_frames.pop();
int cnt = f.frame.size();
int dur = (f.duration.count() * FRAMERATE) / 1000;
int cmdLen = (cnt * 6) + 2;
int bufferLen = cmdLen + 2;
ESP_LOGD(tag, "Building message for animation of %d leds in %d frames. Total length: %d bytes.", cnt, dur, bufferLen);
uint8_t buffer[bufferLen];
buffer[0] = ((uint8_t)Command::SendFrame << 3) + ((cmdLen & 2047) >> 8);
buffer[1] = cmdLen;
buffer[2] = ((uint8_t)f.type << 2) + ((dur & 1023) >> 8);
buffer[3] = dur;
for (int i = 0; i < cnt; ++i) {
auto led = f.frame[i];
buffer[i * 6 + 4] = led.r >> 4;
buffer[i * 6 + 5] = ((led.r & 15) << 4) + (led.g >> 8);
buffer[i * 6 + 6] = led.g;
buffer[i * 6 + 7] = led.b >> 4;
buffer[i * 6 + 8] = ((led.b & 15) << 4) + (led.w >> 8);
buffer[i * 6 + 9] = led.w;
}
#if CONFIG_LOG_DEFAULT_LEVEL >= 4
ostringstream dbg;
dbg << endl;
for (int i = 0; i < bufferLen; ++i) {
dbg << hex << setw(2) << setfill('0') <<
static_cast<unsigned int>(buffer[i]) << ' ';
if ((i + 1) % 8 == 0) {
dbg << endl;
}
}
ESP_LOGD(tag, "%s", dbg.str().c_str());
#endif
_spi->transfer(buffer, bufferLen);
} |
; A057854: Non-Lucas numbers: the complement of A000032.
; Submitted by Jon Maiga
; 5,6,8,9,10,12,13,14,15,16,17,19,20,21,22,23,24,25,26,27,28,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,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
mov $3,$0
add $0,1
mov $2,$3
lpb $0
mov $1,$0
add $0,$2
add $3,1
sub $0,$3
trn $0,1
mov $2,$1
sub $2,1
sub $3,1
add $3,$1
add $3,1
sub $3,$1
lpe
mov $0,$3
add $0,4
|
/*
* Copyright (c) 2011-2021, The DART development contributors
* All rights reserved.
*
* The list of contributors can be found at:
* https://github.com/dartsim/dart/blob/main/LICENSE
*
* This file is provided under the following "BSD-style" License:
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef DART_GUI_OSG_TRACKBALLMANIPULATOR_HPP_
#define DART_GUI_OSG_TRACKBALLMANIPULATOR_HPP_
#include <osgGA/OrbitManipulator>
namespace dart {
namespace gui {
namespace osg {
#define DART_META_Object(library, name) \
::osg::Object* cloneType() const override \
{ \
return new name(); \
} \
::osg::Object* clone(const ::osg::CopyOp& copyop) const override \
{ \
return new name(*this, copyop); \
} \
bool isSameKindAs(const ::osg::Object* obj) const override \
{ \
return dynamic_cast<const name*>(obj) != NULL; \
} \
const char* libraryName() const override \
{ \
return #library; \
} \
const char* className() const override \
{ \
return #name; \
}
// TODO(JS): Copied from osg/Object. Due to the namespace conflict between osg
// and dart::gui::osg, we need to explicitly specify the root namespace osg as
// ::osg
class OSGGA_EXPORT TrackballManipulator : public ::osgGA::OrbitManipulator
{
public:
/// Constructor
TrackballManipulator(int flags = DEFAULT_SETTINGS);
/// Copy-constructor
TrackballManipulator(
const TrackballManipulator& tm,
const ::osg::CopyOp& copyOp = ::osg::CopyOp::SHALLOW_COPY);
/// Destructor
virtual ~TrackballManipulator();
/// Overriding behavior of left mouse button
bool performMovementLeftMouseButton(
const double eventTimeDelta, const double dx, const double dy) override;
/// Overriding behavior of right mouse button
bool performMovementRightMouseButton(
const double eventTimeDelta, const double dx, const double dy) override;
DART_META_Object(dart - gui - osg, TrackballManipulator)
// TODO(MXG): Consider applying the META macros to every dart::gui::osg Node
};
} // namespace osg
} // namespace gui
} // namespace dart
#endif // DART_GUI_OSG_TRACKBALLMANIPULATOR_HPP_
|
; A122219: Period 9: repeat 5, 4, 5, 4, 3, 4, 5, 4, 5.
; 5,4,5,4,3,4,5,4,5,5,4,5,4,3,4,5,4,5,5,4,5,4,3,4,5,4,5,5,4,5,4,3,4,5,4,5,5,4,5,4,3,4,5,4,5,5,4,5,4,3,4,5,4,5,5,4,5,4,3,4,5,4,5,5,4,5,4,3,4,5,4,5,5,4,5,4,3,4,5,4,5,5,4,5,4,3,4,5,4,5,5,4,5,4,3,4,5,4,5,5
mod $0,9
add $0,2
mod $0,6
sub $0,1
mod $0,2
add $0,4
|
#include <bits/stdc++.h>
#define forn(i,n) for (int i = 0; i < int(n); ++i)
using namespace std;
typedef long long ll;
typedef long double ld;
ll gcd(ll a, ll b) {
while (a && b)
if (a >= b)
a %= b;
else
b %= a;
return a ^ b;
}
ll mul(ll, ll, ll);
ll binpow(ll a, ll deg, ll mod) {
ll res = 1;
while (deg) {
if (deg % 2)
res = mul(res, a, mod);
deg /= 2;
a = mul(a, a, mod);
}
return res;
}
mt19937 rr(random_device{}());
//BEGIN_CODE
//WARNING: only mod <= 1e18
ll mul(ll a, ll b, ll mod) {
ll res = a * b - (ll(ld(a) * ld(b) / ld(mod)) * mod);
while (res < 0)
res += mod;
while (res >= mod)
res -= mod;
return res;
}
bool millerRabinTest(ll n, ll a) {
if (gcd(n, a) > 1)
return false;
ll x = n - 1;
int l = 0;
while (x % 2 == 0) {
x /= 2;
++l;
}
ll c = binpow(a, x, n);
for (int i = 0; i < l; ++i) {
ll nx = mul(c, c, n);
if (nx == 1) {
if (c != 1 && c != n - 1)
return false;
else
return true;
}
c = nx;
}
return c == 1;
}
bool isPrime(ll n) {
if (n == 1)
return false;
if (n % 2 == 0)
return n == 2;
// < 2^32: 2, 7, 61
// < 3e18: 2, 3, 5, 7, 11, 13, 17, 19, 23
// < 2^64: 2, 325, 9375, 28178, 450775, 9780504, 1795265022
for (ll a = 2; a < min<ll>(8, n); ++a)
if (!millerRabinTest(n, a))
return false;
return true;
}
//WARNING: p is not sorted
void factorize(ll x, vector<ll> &p) {
if (x == 1)
return;
if (isPrime(x)) {
p.push_back(x);
return;
}
for (ll d: {2, 3, 5})
if (x % d == 0) {
p.push_back(d);
factorize(x / d, p);
return;
}
while (true) {
ll x1 = rr() % (x - 1) + 1;
ll x2 = (mul(x1, x1, x) + 1) % x;
int i1 = 1, i2 = 2;
while (true) {
ll c = (x1 + x - x2) % x;
if (c == 0)
break;
ll g = gcd(c, x);
if (g > 1) {
factorize(g, p);
factorize(x / g, p);
return;
}
if (i1 * 2 == i2) {
i1 *= 2;
x1 = x2;
}
++i2;
x2 = (mul(x2, x2, x) + 1) % x;
}
}
}
//END_CODE
bool isPrimeSlow(int x) {
for (int i = 2; i * i <= x; ++i)
if (x % i == 0)
return false;
return x != 1;
}
void test() {
forn (i, 100000) {
if (i == 0)
continue;
assert(isPrime(i) == isPrimeSlow(i));
vector<ll> p;
factorize(i, p);
ll prod = 1;
for (ll x: p) {
assert(x > 1);
assert(isPrimeSlow(x));
prod *= x;
}
assert(prod == i);
}
}
int main() {
test();
}
|
; A016767: a(n) = (3*n)^3.
; 0,27,216,729,1728,3375,5832,9261,13824,19683,27000,35937,46656,59319,74088,91125,110592,132651,157464,185193,216000,250047,287496,328509,373248,421875,474552,531441,592704,658503,729000,804357,884736,970299,1061208,1157625,1259712,1367631,1481544,1601613,1728000,1860867,2000376,2146689,2299968,2460375,2628072,2803221,2985984,3176523,3375000,3581577,3796416,4019679,4251528,4492125,4741632,5000211,5268024,5545233,5832000,6128487,6434856,6751269,7077888,7414875,7762392,8120601,8489664,8869743,9261000,9663597,10077696,10503459,10941048,11390625,11852352,12326391,12812904,13312053,13824000,14348907,14886936,15438249,16003008,16581375,17173512,17779581,18399744,19034163,19683000,20346417,21024576,21717639,22425768,23149125,23887872,24642171,25412184,26198073,27000000,27818127,28652616,29503629,30371328,31255875,32157432,33076161,34012224,34965783,35937000,36926037,37933056,38958219,40001688,41063625,42144192,43243551,44361864,45499293,46656000,47832147,49027896,50243409,51478848,52734375,54010152,55306341,56623104,57960603,59319000,60698457,62099136,63521199,64964808,66430125,67917312,69426531,70957944,72511713,74088000,75686967,77308776,78953589,80621568,82312875,84027672,85766121,87528384,89314623,91125000,92959677,94818816,96702579,98611128,100544625,102503232,104487111,106496424,108531333,110592000,112678587,114791256,116930169,119095488,121287375,123505992,125751501,128024064,130323843,132651000,135005697,137388096,139798359,142236648,144703125,147197952,149721291,152273304,154854153,157464000,160103007,162771336,165469149,168196608,170953875,173741112,176558481,179406144,182284263,185193000,188132517,191102976,194104539,197137368,200201625,203297472,206425071,209584584,212776173,216000000,219256227,222545016,225866529,229220928,232608375,236029032,239483061,242970624,246491883,250047000,253636137,257259456,260917119,264609288,268336125,272097792,275894451,279726264,283593393,287496000,291434247,295408296,299418309,303464448,307546875,311665752,315821241,320013504,324242703,328509000,332812557,337153536,341532099,345948408,350402625,354894912,359425431,363994344,368601813,373248000,377933067,382657176,387420489,392223168,397065375,401947272,406869021,411830784,416832723
mul $0,3
mov $1,$0
pow $1,3
|
// @HEADER
// ************************************************************************
//
// Rapid Optimization Library (ROL) Package
// Copyright (2014) Sandia Corporation
//
// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
// license for use of this work by or on behalf of the U.S. Government.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the Corporation nor the names of the
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "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 SANDIA CORPORATION OR THE
// 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.
//
// Questions? Contact lead developers:
// Drew Kouri (dpkouri@sandia.gov) and
// Denis Ridzal (dridzal@sandia.gov)
//
// ************************************************************************
// @HEADER
#ifndef ROL_SANDIARULES2_HPP
#define ROL_SANDIARULES2_HPP
# include <fstream>
# include <string>
# include <cstdlib>
# include <iomanip>
# include <iostream>
# include <cmath>
# include <ctime>
# include "ROL_SandiaRules.hpp"
namespace ROL {
class SandiaRules2 : public SandiaRules {
public:
SandiaRules2(void) {};
void ccn_points ( int n, int dim, double x[] );
void ccn_weights ( int n, int dim, double w[] );
void clenshaw_curtis_points ( int n, int dim, double x[] );
void clenshaw_curtis_weights ( int n, int dim, double w[] );
void fejer2_points ( int n, int dim, double x[] );
void fejer2_weights ( int n, int dim, double w[] );
void gen_hermite_points ( int n, int dim, double x[] );
void gen_hermite_weights ( int n, int dim, double w[] );
void gen_laguerre_points ( int n, int dim, double x[] );
void gen_laguerre_weights ( int n, int dim, double w[] );
void hcc_points ( int n, int dim, double x[] );
void hcc_weights ( int n, int dim, double w[] );
void hce_points ( int n, int dim, double x[] );
void hce_weights ( int n, int dim, double w[] );
void hermite_genz_keister_points ( int n, int dim, double x[] );
void hermite_genz_keister_weights ( int n, int dim, double w[] );
void hermite_points ( int n, int dim, double x[] );
void hermite_weights ( int n, int dim, double w[] );
void jacobi_points ( int n, int dim, double x[] );
void jacobi_weights ( int n, int dim, double w[] );
void laguerre_points ( int n, int dim, double x[] );
void laguerre_weights ( int n, int dim, double w[] );
void legendre_points ( int n, int dim, double x[] );
void legendre_weights ( int n, int dim, double w[] );
void ncc_points ( int n, int dim, double x[] );
void ncc_weights ( int n, int dim, double w[] );
void nco_points ( int n, int dim, double x[] );
void nco_weights ( int n, int dim, double w[] );
double parameter ( int dim, int offset );
void patterson_points ( int n, int dim, double x[] );
void patterson_weights ( int n, int dim, double w[] );
}; // class SandiaRules2
} // namespace ROL
#include "ROL_SandiaRules2Def.hpp"
#endif
|
.global s_prepare_buffers
s_prepare_buffers:
push %r10
push %r11
push %r12
push %r15
push %r8
push %rcx
push %rsi
lea addresses_A_ht+0x1e695, %rcx
clflush (%rcx)
nop
sub %r8, %r8
mov (%rcx), %rsi
nop
nop
nop
nop
add %r12, %r12
lea addresses_normal_ht+0x1e8d5, %r11
nop
nop
add $51668, %r10
vmovups (%r11), %ymm2
vextracti128 $0, %ymm2, %xmm2
vpextrq $0, %xmm2, %r15
nop
cmp $19418, %r15
lea addresses_WT_ht+0x1d955, %r10
nop
nop
nop
nop
nop
sub %r15, %r15
movl $0x61626364, (%r10)
nop
nop
nop
nop
sub %r10, %r10
pop %rsi
pop %rcx
pop %r8
pop %r15
pop %r12
pop %r11
pop %r10
ret
.global s_faulty_load
s_faulty_load:
push %r10
push %r11
push %r12
push %r13
push %r9
push %rcx
push %rdi
push %rdx
push %rsi
// Store
lea addresses_WC+0x18355, %r11
nop
nop
nop
nop
nop
sub %r12, %r12
mov $0x5152535455565758, %rdx
movq %rdx, %xmm5
vmovups %ymm5, (%r11)
nop
nop
nop
nop
dec %r11
// REPMOV
lea addresses_UC+0x755, %rsi
lea addresses_D+0x6ffd, %rdi
nop
nop
nop
xor %rdx, %rdx
mov $54, %rcx
rep movsq
nop
nop
nop
nop
nop
xor %rsi, %rsi
// Load
lea addresses_UC+0x3b55, %r9
nop
nop
nop
nop
nop
cmp $43705, %r11
mov (%r9), %rdi
nop
nop
nop
xor $11041, %r12
// REPMOV
lea addresses_UC+0x1c855, %rsi
lea addresses_UC+0x1d255, %rdi
nop
nop
nop
and $41391, %rdx
mov $103, %rcx
rep movsl
nop
xor $35958, %r13
// Store
lea addresses_WC+0x1ca55, %r13
nop
nop
add %rdx, %rdx
movb $0x51, (%r13)
cmp $58832, %r11
// Store
lea addresses_D+0x1f1d5, %rdi
nop
nop
add %r9, %r9
movl $0x51525354, (%rdi)
nop
nop
nop
dec %r13
// Faulty Load
lea addresses_UC+0x3b55, %rdx
add %r11, %r11
movb (%rdx), %r13b
lea oracles, %rdx
and $0xff, %r13
shlq $12, %r13
mov (%rdx,%r13,1), %r13
pop %rsi
pop %rdx
pop %rdi
pop %rcx
pop %r9
pop %r13
pop %r12
pop %r11
pop %r10
ret
/*
<gen_faulty_load>
[REF]
{'src': {'type': 'addresses_UC', 'same': False, 'size': 2, 'congruent': 0, 'NT': False, 'AVXalign': True}, 'OP': 'LOAD'}
{'dst': {'type': 'addresses_WC', 'same': False, 'size': 32, 'congruent': 11, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'}
{'src': {'type': 'addresses_UC', 'congruent': 10, 'same': False}, 'dst': {'type': 'addresses_D', 'congruent': 1, 'same': False}, 'OP': 'REPM'}
{'src': {'type': 'addresses_UC', 'same': True, 'size': 8, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'}
{'src': {'type': 'addresses_UC', 'congruent': 6, 'same': False}, 'dst': {'type': 'addresses_UC', 'congruent': 8, 'same': False}, 'OP': 'REPM'}
{'dst': {'type': 'addresses_WC', 'same': False, 'size': 1, 'congruent': 8, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'}
{'dst': {'type': 'addresses_D', 'same': False, 'size': 4, 'congruent': 1, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'}
[Faulty Load]
{'src': {'type': 'addresses_UC', 'same': True, 'size': 1, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'src': {'type': 'addresses_A_ht', 'same': False, 'size': 8, 'congruent': 5, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'}
{'src': {'type': 'addresses_normal_ht', 'same': False, 'size': 32, 'congruent': 5, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'}
{'dst': {'type': 'addresses_WT_ht', 'same': False, 'size': 4, 'congruent': 9, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'}
{'37': 21829}
37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37
*/
|
/*
* FreeRTOS Kernel V10.3.0
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* 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.
*
* http://www.FreeRTOS.org
* http://aws.amazon.com/freertos
*
* 1 tab == 4 spaces!
*/
SECTION intvec:CODE:ROOT(2)
ARM
EXTERN pxISRFunction
EXTERN FreeRTOS_Tick_Handler
EXTERN FreeRTOS_IRQ_Handler
EXTERN vCMT_1_Channel_0_ISR
EXTERN vCMT_1_Channel_1_ISR
EXTERN r_scifa2_txif2_interrupt
EXTERN r_scifa2_rxif2_interrupt
EXTERN r_scifa2_drif2_interrupt
EXTERN r_scifa2_brif2_interrupt
PUBLIC FreeRTOS_Tick_Handler_Entry
PUBLIC vCMT_1_Channel_0_ISR_Entry
PUBLIC vCMT_1_Channel_1_ISR_Entry
PUBLIC r_scifa2_txif2_interrupt_entry
PUBLIC r_scifa2_rxif2_interrupt_entry
PUBLIC r_scifa2_drif2_interrupt_entry
PUBLIC r_scifa2_brif2_interrupt_entry
FreeRTOS_Tick_Handler_Entry:
/* Save used registers (probably not necessary). */
PUSH {r0-r1}
/* Save the address of the C portion of this handler in pxISRFunction. */
LDR r0, =pxISRFunction
LDR R1, =FreeRTOS_Tick_Handler
STR R1, [r0]
/* Restore used registers then branch to the FreeRTOS IRQ handler. */
POP {r0-r1}
B FreeRTOS_IRQ_Handler
/*-----------------------------------------------------------*/
vCMT_1_Channel_0_ISR_Entry:
/* Save used registers (probably not necessary). */
PUSH {r0-r1}
/* Save the address of the C portion of this handler in pxISRFunction. */
LDR r0, =pxISRFunction
LDR R1, =vCMT_1_Channel_0_ISR
STR R1, [r0]
/* Restore used registers then branch to the FreeRTOS IRQ handler. */
POP {r0-r1}
B FreeRTOS_IRQ_Handler
/*-----------------------------------------------------------*/
vCMT_1_Channel_1_ISR_Entry:
/* Save used registers (probably not necessary). */
PUSH {r0-r1}
/* Save the address of the C portion of this handler in pxISRFunction. */
LDR r0, =pxISRFunction
LDR R1, =vCMT_1_Channel_1_ISR
STR R1, [r0]
/* Restore used registers then branch to the FreeRTOS IRQ handler. */
POP {r0-r1}
B FreeRTOS_IRQ_Handler
/*-----------------------------------------------------------*/
r_scifa2_txif2_interrupt_entry:
/* Save used registers (probably not necessary). */
PUSH {r0-r1}
/* Save the address of the C portion of this handler in pxISRFunction. */
LDR r0, =pxISRFunction
LDR R1, =r_scifa2_txif2_interrupt
STR R1, [r0]
/* Restore used registers then branch to the FreeRTOS IRQ handler. */
POP {r0-r1}
B FreeRTOS_IRQ_Handler
/*-----------------------------------------------------------*/
r_scifa2_rxif2_interrupt_entry:
/* Save used registers (probably not necessary). */
PUSH {r0-r1}
/* Save the address of the C portion of this handler in pxISRFunction. */
LDR r0, =pxISRFunction
LDR R1, =r_scifa2_rxif2_interrupt
STR R1, [r0]
/* Restore used registers then branch to the FreeRTOS IRQ handler. */
POP {r0-r1}
B FreeRTOS_IRQ_Handler
/*-----------------------------------------------------------*/
r_scifa2_drif2_interrupt_entry:
/* Save used registers (probably not necessary). */
PUSH {r0-r1}
/* Save the address of the C portion of this handler in pxISRFunction. */
LDR r0, =pxISRFunction
LDR R1, =r_scifa2_drif2_interrupt
STR R1, [r0]
/* Restore used registers then branch to the FreeRTOS IRQ handler. */
POP {r0-r1}
B FreeRTOS_IRQ_Handler
/*-----------------------------------------------------------*/
r_scifa2_brif2_interrupt_entry:
/* Save used registers (probably not necessary). */
PUSH {r0-r1}
/* Save the address of the C portion of this handler in pxISRFunction. */
LDR r0, =pxISRFunction
LDR R1, =r_scifa2_brif2_interrupt
STR R1, [r0]
/* Restore used registers then branch to the FreeRTOS IRQ handler. */
POP {r0-r1}
B FreeRTOS_IRQ_Handler
END
|
;
; file: first.asm
; First assembly program. This program asks for two integers as
; input and prints out their sum.
;
; To create executable:
; Using djgpp:
; nasm -f coff -d COFF_TYPE first.asm
; gcc -o first first.o driver.c asm_io.o
;
; Using Borland C/C++
; nasm -f obj -d OBJ_TYPE first.asm
; bcc32 first.obj driver.c asm_io.obj
%include "asm_io.inc"
;
; initialized data is put in the .data segment
;
segment .data
;
; These labels refer to strings used for output
;
prompt1 db "Enter a number: ", 0 ; don't forget nul terminator
prompt2 db "Enter another number: ", 0
outmsg1 db "You entered ", 0
outmsg2 db " and ", 0
outmsg3 db ", the sum of these is ", 0
;
; uninitialized data is put in the .bss segment
;
segment .bss
;
; These labels refer to double words used to store the inputs
;
input1 resd 1
input2 resd 1
;
; code is put in the .text segment
;
segment .text
global asm_main
asm_main:
enter 0,0 ; setup routine
pusha
mov eax, prompt1 ; print out prompt
call print_string
call read_int ; read integer
mov [input1], eax ; store into input1
mov eax, prompt2 ; print out prompt
call print_string
call read_int ; read integer
mov [input2], eax ; store into input2
mov eax, [input1] ; eax = dword at input1
add eax, [input2] ; eax += dword at input2
mov ebx, eax ; ebx = eax
dump_regs 1
dump_mem 2, outmsg1, 1
;
; next print out result message as series of steps
;
mov eax, outmsg1
call print_string ; print out first message
mov eax, [input1]
call print_int ; print out input1
mov eax, outmsg2
call print_string ; print out second message
mov eax, [input2]
call print_int ; print out input2
mov eax, outmsg3
call print_string ; print out third message
mov eax, ebx
call print_int ; print out sum (ebx)
call print_nl ; print new-line
popa
mov eax, 0 ; return back to C
leave
ret
|
; A113742: Generalized Mancala solitaire (A002491); to get n-th term, start with n and successively round up to next 5 multiples of n-1, n-2, ..., 1, for n>=1.
; 1,6,16,30,48,72,102,132,168,210,258,318,360,418,492,540,622,714,780,870,972,1054,1174,1260,1392,1488,1590,1714,1848,2022,2118,2292,2398,2580,2718,2878,3054,3234,3360,3570,3754,3948,4114,4318,4498,4710,4932
mov $1,1
mov $2,$0
mov $4,1
lpb $2
mov $3,$2
lpb $4
add $1,1
trn $4,$3
lpe
add $5,2
lpb $5
sub $1,1
sub $5,$5
lpe
add $1,5
sub $2,1
mov $4,$1
lpe
|
.global s_prepare_buffers
s_prepare_buffers:
push %r14
push %r15
push %r9
push %rbx
push %rcx
push %rdi
push %rdx
push %rsi
lea addresses_D_ht+0x1c36c, %rsi
lea addresses_normal_ht+0xf5fc, %rdi
nop
nop
cmp $33402, %r15
mov $102, %rcx
rep movsq
nop
nop
add %rbx, %rbx
lea addresses_D_ht+0x12754, %r9
nop
nop
nop
add $36506, %r14
movw $0x6162, (%r9)
nop
nop
nop
nop
nop
cmp %rbx, %rbx
lea addresses_normal_ht+0xb9d0, %r14
nop
nop
nop
nop
nop
dec %r15
movb (%r14), %r9b
nop
nop
add %rcx, %rcx
lea addresses_UC_ht+0xdeec, %rdi
nop
nop
nop
nop
xor $9931, %r15
mov (%rdi), %cx
nop
nop
nop
nop
nop
and %rdi, %rdi
lea addresses_WT_ht+0x12f6c, %rcx
nop
nop
nop
nop
sub %rdi, %rdi
movl $0x61626364, (%rcx)
nop
nop
cmp %rcx, %rcx
lea addresses_WC_ht+0x19cec, %rsi
lea addresses_UC_ht+0x546c, %rdi
dec %r9
mov $49, %rcx
rep movsl
inc %r14
lea addresses_WT_ht+0x79ec, %r14
nop
nop
nop
nop
sub $36780, %r15
mov $0x6162636465666768, %rbx
movq %rbx, %xmm4
vmovups %ymm4, (%r14)
add $43835, %r14
lea addresses_A_ht+0x1c12c, %r15
nop
nop
nop
nop
nop
cmp $6089, %r9
mov (%r15), %edi
nop
nop
and $42760, %rsi
lea addresses_UC_ht+0x9c98, %rsi
lea addresses_WT_ht+0x1d1a0, %rdi
sub %rdx, %rdx
mov $6, %rcx
rep movsw
nop
nop
nop
xor $28561, %r15
lea addresses_WT_ht+0x776c, %rsi
lea addresses_UC_ht+0x158ac, %rdi
nop
nop
cmp %r15, %r15
mov $21, %rcx
rep movsb
nop
nop
nop
nop
and %rcx, %rcx
lea addresses_UC_ht+0x12f6c, %rbx
nop
inc %rcx
mov $0x6162636465666768, %rdi
movq %rdi, %xmm6
and $0xffffffffffffffc0, %rbx
movntdq %xmm6, (%rbx)
nop
nop
nop
nop
nop
sub %rsi, %rsi
lea addresses_UC_ht+0x276c, %r15
xor %rbx, %rbx
movl $0x61626364, (%r15)
nop
nop
inc %rbx
lea addresses_D_ht+0xa36c, %rdi
nop
nop
xor %rdx, %rdx
mov (%rdi), %r9w
nop
and $29041, %rsi
pop %rsi
pop %rdx
pop %rdi
pop %rcx
pop %rbx
pop %r9
pop %r15
pop %r14
ret
.global s_faulty_load
s_faulty_load:
push %r10
push %r12
push %r15
push %rbp
push %rbx
push %rcx
push %rdi
// Store
lea addresses_WT+0x1b4ac, %rbp
clflush (%rbp)
nop
nop
nop
and %rcx, %rcx
movl $0x51525354, (%rbp)
nop
nop
nop
nop
xor $29195, %r12
// Store
lea addresses_WT+0xa630, %r10
nop
nop
nop
nop
sub $52164, %r15
movl $0x51525354, (%r10)
dec %rbp
// Store
lea addresses_A+0x18260, %rdi
sub $8564, %r15
movw $0x5152, (%rdi)
nop
and %rbx, %rbx
// Store
mov $0x4ce, %rbx
cmp $30663, %rdi
movb $0x51, (%rbx)
nop
nop
nop
cmp %rcx, %rcx
// Faulty Load
lea addresses_D+0x876c, %rdi
nop
sub $52438, %rcx
mov (%rdi), %rbx
lea oracles, %r10
and $0xff, %rbx
shlq $12, %rbx
mov (%r10,%rbx,1), %rbx
pop %rdi
pop %rcx
pop %rbx
pop %rbp
pop %r15
pop %r12
pop %r10
ret
/*
<gen_faulty_load>
[REF]
{'src': {'type': 'addresses_D', 'AVXalign': False, 'size': 8, 'NT': False, 'same': False, 'congruent': 0}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'type': 'addresses_WT', 'AVXalign': False, 'size': 4, 'NT': False, 'same': False, 'congruent': 2}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WT', 'AVXalign': True, 'size': 4, 'NT': True, 'same': False, 'congruent': 2}}
{'OP': 'STOR', 'dst': {'type': 'addresses_A', 'AVXalign': False, 'size': 2, 'NT': False, 'same': False, 'congruent': 2}}
{'OP': 'STOR', 'dst': {'type': 'addresses_P', 'AVXalign': False, 'size': 1, 'NT': False, 'same': False, 'congruent': 1}}
[Faulty Load]
{'src': {'type': 'addresses_D', 'AVXalign': False, 'size': 8, 'NT': True, 'same': True, 'congruent': 0}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'src': {'type': 'addresses_D_ht', 'congruent': 10, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_normal_ht', 'congruent': 4, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_D_ht', 'AVXalign': False, 'size': 2, 'NT': False, 'same': False, 'congruent': 2}}
{'src': {'type': 'addresses_normal_ht', 'AVXalign': False, 'size': 1, 'NT': False, 'same': False, 'congruent': 2}, 'OP': 'LOAD'}
{'src': {'type': 'addresses_UC_ht', 'AVXalign': False, 'size': 2, 'NT': False, 'same': False, 'congruent': 4}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'AVXalign': False, 'size': 4, 'NT': False, 'same': False, 'congruent': 11}}
{'src': {'type': 'addresses_WC_ht', 'congruent': 4, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_UC_ht', 'congruent': 7, 'same': True}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'AVXalign': False, 'size': 32, 'NT': False, 'same': True, 'congruent': 7}}
{'src': {'type': 'addresses_A_ht', 'AVXalign': False, 'size': 4, 'NT': False, 'same': False, 'congruent': 5}, 'OP': 'LOAD'}
{'src': {'type': 'addresses_UC_ht', 'congruent': 2, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_WT_ht', 'congruent': 1, 'same': False}}
{'src': {'type': 'addresses_WT_ht', 'congruent': 11, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_UC_ht', 'congruent': 5, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_UC_ht', 'AVXalign': False, 'size': 16, 'NT': True, 'same': False, 'congruent': 10}}
{'OP': 'STOR', 'dst': {'type': 'addresses_UC_ht', 'AVXalign': False, 'size': 4, 'NT': False, 'same': False, 'congruent': 11}}
{'src': {'type': 'addresses_D_ht', 'AVXalign': False, 'size': 2, 'NT': False, 'same': False, 'congruent': 9}, 'OP': 'LOAD'}
{'36': 21829}
36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36
*/
|
SECTION code_clib
PUBLIC aplib_depack
PUBLIC _aplib_depack
;==============================================================
; aplib_depack(unsigned char *src, unsigned char *dest)
;==============================================================
; Uncompresses data previously compressed with apLib
;==============================================================
.aplib_depack
._aplib_depack
ld hl, 2
add hl, sp
ld e, (hl) ; Destination address
inc hl
ld d, (hl)
inc hl
ld a, (hl) ; Source address
inc hl
ld h, (hl)
ld l, a
jp depack
; Usage:
;
; .include this file in your code
; somewhere after that, an aPLibMemoryStruct called aPLibMemory must be defined somewhere in RAM
; ie. "aPLibMemory instanceof aPLibMemoryStruct" inside a .ramsection or .enum
;
; Then do
;
; ld hl,<source address>
; ld de,<destination address>
; call depack
;
; In my tests, depack() used a maximum of 12 bytes of stack, but this may vary with different data.
; This file is using WLA-DX syntax quite heavily, you'd better use it too...
;.struct aPLibMemoryStruct
;bits db
;byte db ; not directly referenced, assumed to come after bits
;LWM db
;R0 dw
;.endst
; Reader's note:
; The structure of the code has been arranged such that the entry point is in the middle -
; this is so it can use jr to branch out to the various subsections to save a few bytes,
; but it makes it somewhat harder to read. "depack" is the entry point and "aploop" is
; the main loop.
; Subsections which are only referenced by calls are defined in separate .sections to enable
; better code packing in the output (more finely divided blobs).
; More optimisations may be possible; in general, size optimisations are favoured over speed.
.ap_getbit
push bc
ld bc,(aPLibMemory_bits)
rrc c
jr nc,ap_getbit_continue
ld b,(hl)
inc hl
.ap_getbit_continue
ld a,c
and b
ld (aPLibMemory_bits),bc
pop bc
ret
.ap_getbitbc ;doubles BC and adds the read bit
sla c
rl b
call ap_getbit
ret z
inc bc
ret
.ap_getgamma
ld bc,1
.ap_getgammaloop
call ap_getbitbc
call ap_getbit
jr nz,ap_getgammaloop
ret
.apbranch2
;use a gamma code * 256 for offset, another gamma code for length
call ap_getgamma
dec bc
dec bc
ld a,(aPLibMemory_LWM)
or a
jr nz,ap_not_LWM
;bc = 2? ; Maxim: I think he means 0
ld a,b
or c
jr nz,ap_not_zero_gamma
;if gamma code is 2, use old R0 offset, and a new gamma code for length
call ap_getgamma
push hl
ld h,d
ld l,e
push bc
ld bc,(aPLibMemory_R0)
sbc hl,bc
pop bc
ldir
pop hl
jr ap_finishup
.ap_not_zero_gamma
dec bc
.ap_not_LWM
;do I even need this code? ; Maxim: seems so, it's broken without it
;bc=bc*256+(hl), lazy 16bit way
ld b,c
ld c,(hl)
inc hl
ld (aPLibMemory_R0),bc
push bc
call ap_getgamma
ex (sp),hl
;bc = len, hl=offs
push de
ex de,hl
;some comparison junk for some reason
; Maxim: optimised to use add instead of sbc
ld hl,-32000
add hl,de
jr nc,skip1
inc bc
.skip1
ld hl,-1280
add hl,de
jr nc,skip2
inc bc
.skip2
ld hl,-128
add hl,de
jr c,skip3
inc bc
inc bc
.skip3
;bc = len, de = offs, hl=junk
pop hl
push hl
or a
sbc hl,de
pop de
;hl=dest-offs, bc=len, de = dest
ldir
pop hl
.ap_finishup
ld a,1
ld (aPLibMemory_LWM),a
jr aploop
.apbranch1 ; Maxim: moved this one closer to where it's jumped from to allow jr to work and save 2 bytes
ldi
xor a
ld (aPLibMemory_LWM),a
jr aploop
.depack
;hl = source
;de = dest
ldi
xor a
ld (aPLibMemory_LWM),a
inc a
ld (aPLibMemory_bits),a
.aploop
call ap_getbit
jr z, apbranch1
call ap_getbit
jr z, apbranch2
call ap_getbit
jr z, apbranch3
;LWM = 0
xor a
ld (aPLibMemory_LWM),a
;get an offset
ld bc,0
call ap_getbitbc
call ap_getbitbc
call ap_getbitbc
call ap_getbitbc
ld a,b
or c
jr nz,apbranch4
; xor a ;write a 0 ; Maxim: a is zero already (just failed nz test), optimise this line away
ld (de),a
inc de
jr aploop
.apbranch4
ex de,hl ;write a previous bit (1-15 away from dest)
push hl
sbc hl,bc
ld a,(hl)
pop hl
ld (hl),a
inc hl
ex de,hl
jr aploop
.apbranch3
;use 7 bit offset, length = 2 or 3
;if a zero is encountered here, it's EOF
ld c,(hl)
inc hl
rr c
ret z
ld b,2
jr nc,ap_dont_inc_b
inc b
.ap_dont_inc_b
;LWM = 1
ld a,1
ld (aPLibMemory_LWM),a
push hl
ld a,b
ld b,0
;R0 = c
ld (aPLibMemory_R0),bc
ld h,d
ld l,e
or a
sbc hl,bc
ld c,a
ldir
pop hl
jr aploop
SECTION bss_crt
aPLibMemory_bits: defb 0 ;apLib support variable
aPLibMemory_byte: defb 0 ;apLib support variable
aPLibMemory_LWM: defb 0 ;apLib support variable
aPLibMemory_R0: defw 0 ;apLib support variable
|
global start
section .text
bits 32
start:
; print `OK` to screen
mov dword [0xb8000], 0x2f4b2f4f
hlt
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.